Compare commits
No commits in common. "d696189a2ea1c9727e451d6f94ab30ea62f3b114" and "e9e53341b3d361b2716f4627b90e3e1cd11b1486" have entirely different histories.
d696189a2e
...
e9e53341b3
22
.github/workflows/kuhy-credit-drift.yml
vendored
@ -1,22 +0,0 @@
|
||||
name: kuhy_credit drift
|
||||
|
||||
# Not path-filtered, like palette-drift: the sources live outside kuhy_credit/
|
||||
# (the M1 art, web_ui's tokens.css), so an edit there must be able to fail it.
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
drift:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: kuhy_credit
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with: { python-version: "3.15.2" }
|
||||
- name: Every stack's generated file matches credit.json, the art and the tokens
|
||||
run: python3 -m generator.generate --check
|
||||
96
.github/workflows/kuhy-credit-tests.yml
vendored
@ -1,96 +0,0 @@
|
||||
name: kuhy_credit tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths: ['kuhy_credit/**', 'flutter_web_drive/**', '.github/workflows/kuhy-credit-tests.yml']
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths: ['kuhy_credit/**', 'flutter_web_drive/**', '.github/workflows/kuhy-credit-tests.yml']
|
||||
|
||||
env:
|
||||
GODOT_VERSION: "4.7.2"
|
||||
|
||||
jobs:
|
||||
python:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: kuhy_credit
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with: { python-version: "3.15.2" }
|
||||
- name: Install the package, pytest and a virtual X display
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y xvfb python3-tk
|
||||
pip install -r requirements-dev.txt && pip install --no-deps -e .
|
||||
- name: Lint
|
||||
run: ruff check . && ruff format --check .
|
||||
- name: Tests, Tk E2E and the drift check, 100% branch coverage
|
||||
run: xvfb-run -a -s "-screen 0 1600x1200x24" python -m pytest -q
|
||||
|
||||
web:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: kuhy_credit/web
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: pnpm/action-setup@v4
|
||||
with: { version: 12 }
|
||||
- uses: actions/setup-node@v4
|
||||
with: { node-version: "26.13.1" }
|
||||
- uses: actions/setup-python@v5
|
||||
with: { python-version: "3.15.2" }
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm lint
|
||||
- name: Unit tests, 100% coverage
|
||||
run: pnpm coverage
|
||||
- name: E2E in headless Chrome (window.open stubbed)
|
||||
working-directory: .
|
||||
env: { CHROMIUM: google-chrome }
|
||||
run: |
|
||||
pip install -r flutter_web_drive/requirements.txt
|
||||
python3 kuhy_credit/e2e/web_e2e.py
|
||||
|
||||
flutter:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: kuhy_credit/flutter
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: subosito/flutter-action@v2
|
||||
with: { channel: stable }
|
||||
- uses: actions/setup-python@v5
|
||||
with: { python-version: "3.15.2" }
|
||||
- run: flutter pub get
|
||||
- run: flutter analyze
|
||||
- name: Widget tests, 100% line coverage
|
||||
run: flutter test --coverage && ../../scripts/check_coverage.sh coverage/lcov.info 100
|
||||
- name: Example web build + E2E in headless Chrome (window.open stubbed)
|
||||
env: { CHROMIUM: google-chrome }
|
||||
run: |
|
||||
(cd example && flutter pub get && flutter analyze && flutter build web --release)
|
||||
pip install -r ../../flutter_web_drive/requirements.txt
|
||||
python3 ../e2e/flutter_web_e2e.py
|
||||
|
||||
godot:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with: { python-version: "3.15.2" }
|
||||
- name: Install Godot
|
||||
run: |
|
||||
curl -fsSL -o godot.zip "https://github.com/godotengine/godot/releases/download/${GODOT_VERSION}-stable/Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip"
|
||||
unzip -q godot.zip
|
||||
chmod +x "Godot_v${GODOT_VERSION}-stable_linux.x86_64"
|
||||
sudo mv "Godot_v${GODOT_VERSION}-stable_linux.x86_64" /usr/local/bin/godot
|
||||
rm godot.zip
|
||||
- name: Lint (gdlint, gdformat)
|
||||
run: pip install -r godot_dev_tools/requirements-dev.txt && kuhy_credit/godot/lint.sh
|
||||
- name: GUT unit tests + demo E2E (GUT fetched at its pinned tag)
|
||||
env: { KUHY_CREDIT_GODOT_TIMEOUT: "50" }
|
||||
run: kuhy_credit/godot/test.sh
|
||||
@ -4,9 +4,6 @@ Monorepo of shared gates and libraries (app_errors, dep_freshness, file_length,
|
||||
repo_contract, coverage_gaps, crdt-sync, gatelock, freedays, sickdays, earned_time, music_theory, game_recording,
|
||||
flutter_web_drive (headless Flutter-web E2E driver + MCP), ...).
|
||||
`godot_dev_tools/` is a Godot addon (GDScript): `godot_dev_tools/test.sh` runs its GUT tests.
|
||||
`kuhy_credit/` is the shared "Created by kuhy" credit, one implementation per stack (web, Flutter,
|
||||
Godot, Tk, terminal) generated from `kuhy_credit/credit.json`; `kuhy_credit/README.md` lists each
|
||||
stack's test and E2E command, `python -m generator.generate --check` (from `kuhy_credit/`) the drift check.
|
||||
Python packages with a root-level `<pkg>/tests` run with `PYTHONPATH=.`;
|
||||
subprojects with their own `pyproject.toml` run via `scripts/run_subproject_tests.sh <dir>`.
|
||||
`scripts/check_repo_contract.sh` is the REAL shared gate (not a shim): never
|
||||
|
||||
6
kuhy_credit/.gitignore
vendored
@ -1,6 +0,0 @@
|
||||
# Tool output, never committed.
|
||||
web/node_modules/
|
||||
web/coverage/
|
||||
flutter/.dart_tool/
|
||||
flutter/coverage/
|
||||
flutter/example/.dart_tool/
|
||||
@ -1,141 +0,0 @@
|
||||
# kuhy_credit
|
||||
|
||||
One "Created by kuhy" credit for every kuhy repo. The user sees the M1 logo. A
|
||||
click or tap opens a small panel with the logo and the words "Created by kuhy".
|
||||
A click or tap on the panel opens https://kuhy.duckdns.org in the system
|
||||
browser. Escape, a click outside the panel and a second logo click close it.
|
||||
Nothing loads over the network and nothing opens without a click.
|
||||
|
||||
## Where the data lives
|
||||
|
||||
- `credit.json` holds the URL, the text and the paths of the two sources it
|
||||
reads: the M1 art (`unified-design-system/logo/final/kuhy.svg`) and the
|
||||
design tokens (`web_ui/src/tokens.css`).
|
||||
- `generator/generate.py` writes each stack's data file from those sources.
|
||||
Never edit a generated file by hand:
|
||||
|
||||
| Stack | Generated file |
|
||||
| -------- | ----------------------------------------- |
|
||||
| python | `kuhy_credit/_data.py` |
|
||||
| web | `web/src/credit-data.js` |
|
||||
| flutter | `flutter/lib/src/credit_data.g.dart` |
|
||||
| godot | `godot/addons/kuhy_credit/credit_data.gd` |
|
||||
| terminal | `terminal/kuhy-credit.sh` |
|
||||
|
||||
- `python -m generator.generate --check` (from `kuhy_credit/`) fails and names
|
||||
every stack whose file differs from the sources. CI runs it on every push.
|
||||
|
||||
## Decisions (change them here if you disagree)
|
||||
|
||||
- Placement: web footer, Flutter about screen, Godot main-menu corner. The
|
||||
panel opens above the logo, aligned to its end edge; each stack has a
|
||||
"below" and a "start" option.
|
||||
- Lockers and gate windows get no credit. The Tk widget ships but no locker
|
||||
uses it.
|
||||
- Distribution: a git dependency pinned to the tag `kuhy-credit-v<version>`
|
||||
(version in `pyproject.toml`, `web/package.json` and
|
||||
`flutter/pubspec.yaml`, kept equal). Never copy the files into a repo by hand.
|
||||
|
||||
## Web (plain HTML, Astro, React/Vite)
|
||||
|
||||
```jsonc
|
||||
// package.json
|
||||
"@kuhyx/kuhy-credit": "github:kuhyx/utils#kuhy-credit-v0.1.0&path:kuhy_credit/web"
|
||||
```
|
||||
|
||||
```html
|
||||
<script type="module">import "@kuhyx/kuhy-credit";</script>
|
||||
<footer><kuhy-credit></kuhy-credit></footer>
|
||||
```
|
||||
|
||||
In Astro, put the same `import` in a `<script>` tag of the layout. In React
|
||||
19, call `import "@kuhyx/kuhy-credit";` once and render `<kuhy-credit />`;
|
||||
the `.d.ts` adds the JSX type. Attributes: `placement="below"`,
|
||||
`align="start"`, `theme="light|dark"` (default: follow the page). The size
|
||||
comes from `--kuhy-credit-size` (default 48px). Colours come from the page's
|
||||
`tokens.css` variables when they exist, else from the generated token values.
|
||||
|
||||
Demo: `python3 -m http.server -d . 8765` from the repo root, then open
|
||||
http://127.0.0.1:8765/kuhy_credit/web/demo/index.html (`?theme=light` forces
|
||||
the light theme).
|
||||
|
||||
## Flutter (Android and web)
|
||||
|
||||
```yaml
|
||||
dependencies:
|
||||
kuhy_credit:
|
||||
git:
|
||||
url: https://github.com/kuhyx/utils
|
||||
ref: kuhy-credit-v0.1.0
|
||||
path: kuhy_credit/flutter
|
||||
```
|
||||
|
||||
```dart
|
||||
import 'package:kuhy_credit/kuhy_credit.dart';
|
||||
|
||||
const KuhyCredit() // e.g. at the bottom of the about screen
|
||||
```
|
||||
|
||||
The widget opens the site with `url_launcher` (a new tab on web, the browser
|
||||
app on Android). Back closes an open panel. Demo: `flutter/example`.
|
||||
|
||||
## Godot 4.7
|
||||
|
||||
```bash
|
||||
cache="$(mktemp -d)"
|
||||
git clone --depth 1 --branch kuhy-credit-v0.1.0 https://github.com/kuhyx/utils "$cache"
|
||||
cp -r "$cache/kuhy_credit/godot/addons/kuhy_credit" addons/
|
||||
```
|
||||
|
||||
```gdscript
|
||||
var credit: Control = preload("res://addons/kuhy_credit/kuhy_credit.tscn").instantiate()
|
||||
credit.light = false # true on a light menu
|
||||
$MainMenu.add_child(credit) # then place it in a corner
|
||||
```
|
||||
|
||||
The script opens the site with `OS.shell_open`. Demo:
|
||||
`godot --path kuhy_credit/godot` (`-- --light` for the light theme).
|
||||
|
||||
## Python / Tkinter
|
||||
|
||||
```bash
|
||||
pip install "kuhy-credit @ git+https://github.com/kuhyx/utils@kuhy-credit-v0.1.0#subdirectory=kuhy_credit"
|
||||
```
|
||||
|
||||
```python
|
||||
from kuhy_credit.tk import KuhyCredit
|
||||
|
||||
KuhyCredit(root, theme="dark").place(relx=1, rely=1, x=-16, y=-16, anchor="se")
|
||||
```
|
||||
|
||||
The widget opens the site with `webbrowser` (a new tab). Tk has no rounded
|
||||
corners and no accessibility tree, so those two parts of the design do not
|
||||
apply there. Demo: `python -m kuhy_credit.demo [--light]`.
|
||||
|
||||
## Terminal programs
|
||||
|
||||
```bash
|
||||
kuhy-credit # after the pip install above
|
||||
bash kuhy_credit/terminal/kuhy-credit.sh # no Python needed
|
||||
```
|
||||
|
||||
```python
|
||||
from kuhy_credit import credit_line
|
||||
|
||||
print(credit_line()) # Created by kuhy https://kuhy.duckdns.org
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
| Stack | Command (from `kuhy_credit/`) |
|
||||
| --------------- | --------------------------------------------------------------- |
|
||||
| python + drift | `xvfb-run -a python -m pytest` (100% branch coverage) |
|
||||
| web | `cd web && pnpm install && pnpm coverage` (100%) |
|
||||
| web E2E | `PYTHONPATH=.. python3 e2e/web_e2e.py` |
|
||||
| flutter | `cd flutter && flutter test --coverage` (100% lines) |
|
||||
| flutter web E2E | build `flutter/example` for web, then `python3 e2e/flutter_web_e2e.py` |
|
||||
| godot + E2E | `godot/test.sh` (GUT; `tests/test_demo_e2e.gd` is the E2E) |
|
||||
| Tk E2E | part of the pytest run: `tests/test_tk_e2e.py` |
|
||||
|
||||
Every E2E clicks the logo, then the panel, and checks the URL the stubbed
|
||||
browser launch received.
|
||||
@ -1,6 +0,0 @@
|
||||
{
|
||||
"url": "https://kuhy.duckdns.org",
|
||||
"text": "Created by kuhy",
|
||||
"logo": "unified-design-system/logo/final/kuhy.svg",
|
||||
"tokens": "web_ui/src/tokens.css"
|
||||
}
|
||||
@ -1,151 +0,0 @@
|
||||
"""Headless chromium + a loopback file server, driven over CDP.
|
||||
|
||||
Shared by the web and Flutter-web E2Es. The browser never has a window and
|
||||
never touches kuhy's display; window.open is replaced before any page script
|
||||
runs, so "opening the website" only records the URL.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(REPO))
|
||||
|
||||
from flutter_web_drive import cdp # noqa: E402
|
||||
|
||||
CREDIT = json.loads((REPO / "kuhy_credit/credit.json").read_text())
|
||||
|
||||
STUB = """
|
||||
window.__opened = [];
|
||||
window.open = (url) => { window.__opened.push(String(url)); return null; };
|
||||
"""
|
||||
|
||||
|
||||
def free_port() -> int:
|
||||
with socket.socket() as s:
|
||||
s.bind(("127.0.0.1", 0))
|
||||
return int(s.getsockname()[1])
|
||||
|
||||
|
||||
def chromium() -> str:
|
||||
for cand in (os.environ.get("CHROMIUM", ""), "/usr/bin/chromium", "google-chrome", "chromium"):
|
||||
if cand and shutil.which(cand):
|
||||
return cand
|
||||
raise SystemExit("no chromium found (set CHROMIUM)")
|
||||
|
||||
|
||||
def wait_for(probe, what: str, timeout: float = 20.0) -> Any:
|
||||
end = time.monotonic() + timeout
|
||||
while time.monotonic() < end:
|
||||
with contextlib.suppress(Exception):
|
||||
got = probe()
|
||||
if got:
|
||||
return got
|
||||
time.sleep(0.1)
|
||||
raise AssertionError(f"timed out waiting for {what}")
|
||||
|
||||
|
||||
class Page:
|
||||
"""One CDP page with mouse/keyboard helpers."""
|
||||
|
||||
def __init__(self, sess: cdp.Session) -> None:
|
||||
self.s = sess
|
||||
|
||||
def eval(self, expr: str) -> Any:
|
||||
return self.s.evaluate(expr)
|
||||
|
||||
def click(self, x: float, y: float) -> None:
|
||||
for kind in ("mousePressed", "mouseReleased"):
|
||||
self.s.call(
|
||||
"Input.dispatchMouseEvent", type=kind, x=x, y=y, button="left", clickCount=1
|
||||
)
|
||||
time.sleep(0.15)
|
||||
|
||||
def key(self, key: str, code: str, vk: int, text: str = "", *, repeat: bool = False) -> None:
|
||||
"""Press and release one key; ``text`` makes Enter/Space activate."""
|
||||
extra: dict[str, object] = {"text": text} if text else {}
|
||||
if repeat:
|
||||
extra["autoRepeat"] = True
|
||||
self.s.call(
|
||||
"Input.dispatchKeyEvent",
|
||||
type="keyDown" if text else "rawKeyDown",
|
||||
key=key,
|
||||
code=code,
|
||||
windowsVirtualKeyCode=vk,
|
||||
**extra,
|
||||
)
|
||||
self.s.call(
|
||||
"Input.dispatchKeyEvent", type="keyUp", key=key, code=code, windowsVirtualKeyCode=vk
|
||||
)
|
||||
time.sleep(0.15)
|
||||
|
||||
def opened(self) -> list[str]:
|
||||
return list(self.eval("window.__opened"))
|
||||
|
||||
def shot(self, path: Path) -> None:
|
||||
data = self.s.call("Page.captureScreenshot", format="png")["data"]
|
||||
path.write_bytes(base64.b64decode(data))
|
||||
|
||||
def foreign_requests(self) -> list[str]:
|
||||
urls = [
|
||||
e["params"]["request"]["url"]
|
||||
for e in self.s.drain(0.3)
|
||||
if e.get("method") == "Network.requestWillBeSent"
|
||||
]
|
||||
return [u for u in urls if not u.startswith(("http://127.0.0.1", "data:", "blob:"))]
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def session(serve_dir: Path, size: str = "900,600") -> Iterator[tuple[Page, int]]:
|
||||
"""Serve ``serve_dir`` on loopback and attach to a fresh headless chromium."""
|
||||
http_port, cdp_port = free_port(), free_port()
|
||||
profile = tempfile.mkdtemp(prefix="kc-e2e-")
|
||||
server = subprocess.Popen(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"http.server",
|
||||
str(http_port),
|
||||
"-b",
|
||||
"127.0.0.1",
|
||||
"-d",
|
||||
str(serve_dir),
|
||||
],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
browser = subprocess.Popen(
|
||||
[chromium(), "--headless=new", f"--remote-debugging-port={cdp_port}",
|
||||
"--remote-debugging-address=127.0.0.1", f"--user-data-dir={profile}",
|
||||
"--disable-extensions", "--no-first-run", "--no-default-browser-check",
|
||||
"--password-store=basic", "--mute-audio", "--hide-scrollbars",
|
||||
"--enable-unsafe-swiftshader", f"--window-size={size}", "about:blank"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
) # fmt: skip
|
||||
try:
|
||||
sess = wait_for(lambda: cdp.connect(cdp_port), "chromium CDP")
|
||||
sess.call("Page.enable")
|
||||
sess.call("Network.enable")
|
||||
sess.call("Page.addScriptToEvaluateOnNewDocument", source=STUB)
|
||||
yield Page(sess), http_port
|
||||
sess.close()
|
||||
finally:
|
||||
browser.terminate()
|
||||
server.terminate()
|
||||
browser.wait(10)
|
||||
server.wait(10)
|
||||
shutil.rmtree(profile, ignore_errors=True)
|
||||
@ -1,72 +0,0 @@
|
||||
"""Flutter-web E2E: the built example app in headless chromium, real clicks.
|
||||
|
||||
(cd kuhy_credit/flutter/example && flutter build web --release)
|
||||
python3 kuhy_credit/e2e/flutter_web_e2e.py [shots_dir]
|
||||
|
||||
The logo and the panel are found through Flutter's semantics DOM (both are
|
||||
named "Created by kuhy": the logo is the button, the panel the link). Passes
|
||||
when the logo click shows the panel, the panel click "opens" the URL
|
||||
(window.open stubbed, which url_launcher_web calls) and the panel is gone.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from browser import CREDIT, REPO, Page, session, wait_for
|
||||
|
||||
BUILD = REPO / "kuhy_credit/flutter/example/build/web"
|
||||
FIND = """(() => {
|
||||
const want = %s;
|
||||
const el = [...document.querySelectorAll('flt-semantics, a, [role]')].find(e =>
|
||||
(e.getAttribute('aria-label') || e.textContent || '').trim() === %s &&
|
||||
(want === 'button' ? e.getAttribute('role') === 'button'
|
||||
: e.tagName === 'A' || e.getAttribute('role') === 'link'));
|
||||
if (!el) return null;
|
||||
const r = el.getBoundingClientRect();
|
||||
return r.width > 0 ? [r.x + r.width / 2, r.y + r.height / 2] : null;
|
||||
})()"""
|
||||
|
||||
|
||||
def find(page: Page, role: str) -> tuple[float, float] | None:
|
||||
text = repr(CREDIT["text"]).replace("'", '"')
|
||||
return page.eval(FIND % (f'"{role}"', text))
|
||||
|
||||
|
||||
def main() -> int:
|
||||
shots = Path(sys.argv[1]) if len(sys.argv) > 1 else None
|
||||
if not (BUILD / "index.html").is_file():
|
||||
raise SystemExit(f"no web build at {BUILD}: run flutter build web first")
|
||||
with session(BUILD) as (page, port):
|
||||
page.s.call("Page.navigate", url=f"http://127.0.0.1:{port}/index.html")
|
||||
logo = wait_for(lambda: find(page, "button"), "the logo in the semantics tree", 40)
|
||||
assert find(page, "link") is None, "panel visible before any click"
|
||||
if shots:
|
||||
page.shot(shots / "flutter-web-closed.png")
|
||||
page.click(*logo)
|
||||
panel = wait_for(lambda: find(page, "link"), "the panel after the logo click")
|
||||
time.sleep(0.3)
|
||||
if shots:
|
||||
page.shot(shots / "flutter-web-open.png")
|
||||
assert page.opened() == [], "the logo click opened the site"
|
||||
page.click(*panel)
|
||||
wait_for(page.opened, "window.open after the panel click")
|
||||
assert page.opened() == [CREDIT["url"]], page.opened()
|
||||
wait_for(lambda: find(page, "link") is None, "the panel to close")
|
||||
page.click(*logo)
|
||||
wait_for(lambda: find(page, "link"), "reopen")
|
||||
page.click(*logo)
|
||||
wait_for(lambda: find(page, "link") is None, "second logo click to close")
|
||||
page.click(*logo)
|
||||
wait_for(lambda: find(page, "link"), "reopen")
|
||||
page.click(20, 20)
|
||||
wait_for(lambda: find(page, "link") is None, "outside click to close")
|
||||
assert page.opened() == [CREDIT["url"]], "a close path opened the site"
|
||||
print(f"flutter web e2e: two clicks opened {CREDIT['url']}; close paths pass")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@ -1,83 +0,0 @@
|
||||
"""Web E2E: the <kuhy-credit> demo page in headless chromium, real input events.
|
||||
|
||||
PYTHONPATH=<repo> python3 kuhy_credit/e2e/web_e2e.py [shots_dir]
|
||||
|
||||
Passes when: only the logo shows; a logo click opens the panel; a panel click
|
||||
"opens" CREDIT url (window.open stubbed) and closes it; Escape, an outside
|
||||
click and a second logo click each close it without opening anything; Tab +
|
||||
Enter reach and open it; the page made no request off loopback.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from browser import CREDIT, REPO, Page, session, wait_for
|
||||
|
||||
HOST = "document.querySelector('kuhy-credit')"
|
||||
|
||||
|
||||
def centre(page: Page, part: str) -> tuple[float, float]:
|
||||
r = page.eval(f"(() => {{ const r = {HOST}.shadowRoot.querySelector('{part}').getBoundingClientRect();"
|
||||
" return [r.x + r.width / 2, r.y + r.height / 2]; })()") # fmt: skip
|
||||
return r[0], r[1]
|
||||
|
||||
|
||||
def is_open(page: Page) -> bool:
|
||||
return bool(page.eval(f"{HOST}.open"))
|
||||
|
||||
|
||||
def run(page: Page, port: int, theme: str, shots: Path | None) -> None:
|
||||
url = f"http://127.0.0.1:{port}/kuhy_credit/web/demo/index.html?theme={theme}"
|
||||
page.s.call("Page.navigate", url=url)
|
||||
wait_for(
|
||||
lambda: page.eval(
|
||||
f"!!{HOST} && !!customElements.get('kuhy-credit') && !!{HOST}.shadowRoot"
|
||||
),
|
||||
"element",
|
||||
)
|
||||
assert not is_open(page), "panel visible before any click"
|
||||
assert page.eval(f"{HOST}.shadowRoot.querySelector('button').textContent.trim()") == ""
|
||||
if shots:
|
||||
page.shot(shots / f"web-{theme}-closed.png")
|
||||
page.click(*centre(page, "button"))
|
||||
assert is_open(page), "logo click did not open the panel"
|
||||
assert page.eval(f"{HOST}.shadowRoot.querySelector('a').textContent.trim()") == CREDIT["text"]
|
||||
if shots:
|
||||
page.shot(shots / f"web-{theme}-open.png")
|
||||
page.click(*centre(page, "a"))
|
||||
assert page.opened() == [CREDIT["url"]], page.opened()
|
||||
assert not is_open(page), "panel stayed open after opening the site"
|
||||
|
||||
for name, close in (
|
||||
("escape", lambda: page.key("Escape", "Escape", 27)),
|
||||
("outside", lambda: page.click(20, 20)),
|
||||
("second logo click", lambda: page.click(*centre(page, "button"))),
|
||||
):
|
||||
page.click(*centre(page, "button"))
|
||||
assert is_open(page), f"reopen before {name}"
|
||||
close()
|
||||
assert not is_open(page), f"{name} did not close the panel"
|
||||
page.click(20, 20)
|
||||
page.key("Tab", "Tab", 9)
|
||||
page.key("Enter", "Enter", 13, "\r")
|
||||
assert is_open(page), "Tab + Enter did not open the panel"
|
||||
page.key("Enter", "Enter", 13, "\r", repeat=True)
|
||||
assert page.opened() == [CREDIT["url"]], "holding Enter opened the site"
|
||||
assert page.opened() == [CREDIT["url"]], "a close path opened the site"
|
||||
foreign = page.foreign_requests()
|
||||
assert not foreign, f"network requests off loopback: {foreign}"
|
||||
|
||||
|
||||
def main() -> int:
|
||||
shots = Path(sys.argv[1]) if len(sys.argv) > 1 else None
|
||||
with session(REPO) as (page, port):
|
||||
for theme in ("dark", "light"):
|
||||
run(page, port, theme, shots)
|
||||
print(f"web e2e: two clicks opened {CREDIT['url']}; all close paths pass")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@ -1,38 +0,0 @@
|
||||
include: package:very_good_analysis/analysis_options.yaml
|
||||
|
||||
analyzer:
|
||||
language:
|
||||
strict-casts: true
|
||||
strict-inference: true
|
||||
strict-raw-types: true
|
||||
errors:
|
||||
# Promote key lints to errors so they fail CI, not just warn.
|
||||
missing_required_param: error
|
||||
unnecessary_null_comparison: error
|
||||
dead_code: error
|
||||
invalid_annotation_target: error
|
||||
exclude:
|
||||
- build/**
|
||||
- example/**
|
||||
- "**/*.g.dart"
|
||||
- "**/*.freezed.dart"
|
||||
- android/**
|
||||
- ios/**
|
||||
- web/**
|
||||
- windows/**
|
||||
- macos/**
|
||||
- linux/**
|
||||
|
||||
linter:
|
||||
rules:
|
||||
# very_good_analysis enables most rules; add extras it doesn't include.
|
||||
always_use_package_imports: true
|
||||
avoid_print: true
|
||||
avoid_relative_lib_imports: true
|
||||
cancel_subscriptions: true
|
||||
close_sinks: true
|
||||
comment_references: false # conflicts with typical Flutter API docs style
|
||||
directives_ordering: true
|
||||
lines_longer_than_80_chars: true
|
||||
public_member_api_docs: true
|
||||
unawaited_futures: true
|
||||
48
kuhy_credit/flutter/example/.gitignore
vendored
@ -1,48 +0,0 @@
|
||||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.build/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
.swiftpm/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
**/doc/api/
|
||||
**/ios/Flutter/.last_build_id
|
||||
.dart_tool/
|
||||
.flutter-plugins-dependencies
|
||||
.pub-cache/
|
||||
.pub/
|
||||
/build/
|
||||
/coverage/
|
||||
|
||||
# Symbolication related
|
||||
app.*.symbols
|
||||
|
||||
# Obfuscation related
|
||||
app.*.map.json
|
||||
|
||||
# Android Studio will place build artifacts here
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
|
||||
# Widget Preview related
|
||||
.widget_preview/
|
||||
@ -1,33 +0,0 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: "ab2912035e160d9cad6306df307576da6128ebdb"
|
||||
channel: "stable"
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: ab2912035e160d9cad6306df307576da6128ebdb
|
||||
base_revision: ab2912035e160d9cad6306df307576da6128ebdb
|
||||
- platform: android
|
||||
create_revision: ab2912035e160d9cad6306df307576da6128ebdb
|
||||
base_revision: ab2912035e160d9cad6306df307576da6128ebdb
|
||||
- platform: web
|
||||
create_revision: ab2912035e160d9cad6306df307576da6128ebdb
|
||||
base_revision: ab2912035e160d9cad6306df307576da6128ebdb
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
@ -1,6 +0,0 @@
|
||||
analyzer:
|
||||
exclude:
|
||||
- build/**
|
||||
- android/**
|
||||
- web/**
|
||||
include: package:very_good_analysis/analysis_options.yaml
|
||||
14
kuhy_credit/flutter/example/android/.gitignore
vendored
@ -1,14 +0,0 @@
|
||||
gradle-wrapper.jar
|
||||
/.gradle
|
||||
/captures/
|
||||
/gradlew
|
||||
/gradlew.bat
|
||||
/local.properties
|
||||
GeneratedPluginRegistrant.java
|
||||
.cxx/
|
||||
|
||||
# Remember to never publicly share your keystore.
|
||||
# See https://flutter.dev/to/reference-keystore
|
||||
key.properties
|
||||
**/*.keystore
|
||||
**/*.jks
|
||||
@ -1,49 +0,0 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
id("dev.flutter.flutter-gradle-plugin")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.kuhy.kuhy_credit_example"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
ndkVersion = flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId = "com.kuhy.kuhy_credit_example"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||
minSdk = flutter.minSdkVersion
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
// Uses the version code from pubspec.yaml. When using split APKs, 1000 * ABI_VERSION
|
||||
// is added automatically by Flutter. (https://developer.android.com/studio/build/configure-apk-splits#configure-APK-versions)
|
||||
// You can force using the value of versionCode by specifying the `-P force-version-code-ignoring-abi=true`
|
||||
// flag during build.
|
||||
versionCode = flutter.versionCode
|
||||
versionName = flutter.versionName
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig = signingConfigs.getByName("debug")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||||
}
|
||||
}
|
||||
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
@ -1,45 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application
|
||||
android:label="Credit"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:taskAffinity=""
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
to determine the Window background behind the Flutter UI. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
/>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
||||
|
||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
||||
@ -1,5 +0,0 @@
|
||||
package com.kuhy.kuhy_credit_example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity : FlutterActivity()
|
||||
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="?android:colorBackground" />
|
||||
|
||||
<!-- You can insert your own image assets here -->
|
||||
<!-- <item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@mipmap/launch_image" />
|
||||
</item> -->
|
||||
</layer-list>
|
||||
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@android:color/white" />
|
||||
|
||||
<!-- You can insert your own image assets here -->
|
||||
<!-- <item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@mipmap/launch_image" />
|
||||
</item> -->
|
||||
</layer-list>
|
||||
|
Before Width: | Height: | Size: 544 B |
|
Before Width: | Height: | Size: 442 B |
|
Before Width: | Height: | Size: 721 B |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
the Flutter engine draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
the Flutter engine draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
@ -1,7 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
@ -1,24 +0,0 @@
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
val newBuildDir: Directory =
|
||||
rootProject.layout.buildDirectory
|
||||
.dir("../../build")
|
||||
.get()
|
||||
rootProject.layout.buildDirectory.value(newBuildDir)
|
||||
|
||||
subprojects {
|
||||
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
|
||||
project.layout.buildDirectory.value(newSubprojectBuildDir)
|
||||
}
|
||||
subprojects {
|
||||
project.evaluationDependsOn(":app")
|
||||
}
|
||||
|
||||
tasks.register<Delete>("clean") {
|
||||
delete(rootProject.layout.buildDirectory)
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
|
||||
android.useAndroidX=true
|
||||
# This newDsl flag was added by the Flutter template
|
||||
android.newDsl=false
|
||||
# This builtInKotlin flag was added by the Flutter template
|
||||
android.builtInKotlin=false
|
||||
@ -1,5 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-all.zip
|
||||
@ -1,26 +0,0 @@
|
||||
pluginManagement {
|
||||
val flutterSdkPath =
|
||||
run {
|
||||
val properties = java.util.Properties()
|
||||
file("local.properties").inputStream().use { properties.load(it) }
|
||||
val flutterSdkPath = properties.getProperty("flutter.sdk")
|
||||
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
|
||||
flutterSdkPath
|
||||
}
|
||||
|
||||
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
|
||||
id("com.android.application") version "9.3.1" apply false
|
||||
id("org.jetbrains.kotlin.android") version "2.4.20" apply false
|
||||
}
|
||||
|
||||
include(":app")
|
||||
@ -1,40 +0,0 @@
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:kuhy_credit/kuhy_credit.dart';
|
||||
|
||||
/// Demo: an empty token-coloured screen with the credit in the bottom-right
|
||||
/// corner, the spot an app's about screen would give it.
|
||||
void main() {
|
||||
// Builds the semantics tree on web too, so screen readers and the E2E
|
||||
// find the logo by its name.
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
SemanticsBinding.instance.ensureSemantics();
|
||||
runApp(const CreditDemo());
|
||||
}
|
||||
|
||||
/// The demo app.
|
||||
class CreditDemo extends StatelessWidget {
|
||||
/// Creates the demo.
|
||||
const CreditDemo({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dark = MediaQuery.platformBrightnessOf(context) == Brightness.dark;
|
||||
return WidgetsApp(
|
||||
color: Color(dark ? kDarkBg : kLightBg),
|
||||
pageRouteBuilder: <T>(settings, builder) => PageRouteBuilder<T>(
|
||||
settings: settings,
|
||||
pageBuilder: (context, _, _) => builder(context),
|
||||
),
|
||||
home: ColoredBox(
|
||||
color: Color(dark ? kDarkBg : kLightBg),
|
||||
child: const SafeArea(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Padding(padding: EdgeInsets.all(16), child: KuhyCredit()),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,297 +0,0 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
sha256: e2eb0491ba5ddb6177742d2da23904574082139b07c1e33b8503b9f46f3e1a37
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.13.1"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: boolean_selector
|
||||
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: characters
|
||||
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: clock
|
||||
sha256: e51d50bca3217c9a9fa2b41a30e4a38971133f5f9ec7a3d57bae095007f1d28e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.3"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.19.1"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fake_async
|
||||
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.3"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
kuhy_credit:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.1.0"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "11.0.2"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_flutter_testing
|
||||
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.10"
|
||||
leak_tracker_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_testing
|
||||
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
listen:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: listen
|
||||
sha256: "47501a08016a43fcad79252439d723f50f14f88fa7bfd8a177e0a417e5c9e1f2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: "31bd099b47c10cd1aeb55146a2d46ce0277630ecef3f7dae54ad7873f36696cd"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.20"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.13.0"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "307249ce4ff29d58a18e97f6345f539382eb9c9c29ecda628900f31de0443dd9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.19.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path
|
||||
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: plugin_platform_interface
|
||||
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.8"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.10.2"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: "277654b3034d17ac6f9f1cb5595db011b1d5d41e8806866db28e0abaa101c490"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.12.2"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: string_scanner
|
||||
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: term_glyph
|
||||
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.2"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "0a10344e901e5b2e63819567951cb6a06673ed6b84f40462188ff5a0c41f371f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.14"
|
||||
url_launcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: e8cc955c97e06df9879140a1fe301f3d493f01b7c62dec7f46834be31d7e9fda
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.3"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
sha256: b8073b1e5173d63afe1a18985a75896d72f759d3bc1817eb1ae8d26e8527cceb
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.35"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_ios
|
||||
sha256: "8faa1aab294f1ab4040b43660c887b0418d5fa4f0cffef76a484e6aa1092eb4a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.4.2"
|
||||
url_launcher_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_linux
|
||||
sha256: "10f86fef4c2c43563fa6c211ff9cf757adf4d3ab762c56bd430664a947d70cd0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.3"
|
||||
url_launcher_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_macos
|
||||
sha256: "5e835a3b869c2d70325349c81c5a45c28e20791265b67b2669da6b08c5cd5201"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.6"
|
||||
url_launcher_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_platform_interface
|
||||
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
sha256: "85c81589622fbc87c1c683aaea164d3604a7777495a79d91e39ffcdec39ddb34"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_windows
|
||||
sha256: "6c5ad3f22cd4c38e089b81963b3cd7bb83b111b2df5dce008bb066162f42e429"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.6"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: "92b9910f66ed1057fd4da7b040ae7c74cafacf885bdc81be496928d5049b032d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
very_good_analysis:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: very_good_analysis
|
||||
sha256: "0bd5eb8d6be76aa0d71e70cbdae6cac8f784f761170568e3c2214a6948c7f6d3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "11.0.0"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "89b11d62e1040ee681af3b4f1c97a803ecbf010c6e8b9c5896ee5b08c3bf7b78"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "15.4.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: e119e82ac4795c7925103b7cf3768191f33941b99e7ccffbd6c645201d9f606b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
sdks:
|
||||
dart: ">=3.13.0 <4.0.0"
|
||||
flutter: ">=3.44.0"
|
||||
@ -1,18 +0,0 @@
|
||||
name: kuhy_credit_example
|
||||
description: Click-through demo of the kuhy_credit widget (Android + web).
|
||||
publish_to: 'none'
|
||||
version: 0.1.0
|
||||
|
||||
environment:
|
||||
sdk: ^3.12.2
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
kuhy_credit:
|
||||
path: ..
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
very_good_analysis: ^11.0.0
|
||||
|
Before Width: | Height: | Size: 917 B |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 20 KiB |
@ -1,58 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
If you are serving your web app in a path other than the root, change the
|
||||
href value below to reflect the base path you are serving from.
|
||||
|
||||
The path provided below has to start and end with a slash "/" in order for
|
||||
it to work correctly.
|
||||
|
||||
For more details:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
||||
|
||||
This is a placeholder for base href that will be replaced by the value of
|
||||
the `--base-href` argument provided to `flutter build`.
|
||||
-->
|
||||
<base href="$FLUTTER_BASE_HREF">
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
||||
<meta name="description" content="A new Flutter project.">
|
||||
|
||||
<!--
|
||||
Uncomment the tag below to lay the app out underneath the parts of the
|
||||
screen that the device obstructs, such as a display cutout, the rounded
|
||||
corners of the screen, or a home indicator.
|
||||
|
||||
Without it, the browser keeps the app clear of them, and `SafeArea` and
|
||||
`MediaQuery.paddingOf` report no padding. With it, the app covers the whole
|
||||
screen, and it is up to the app to keep its own content out of the way,
|
||||
which is what `SafeArea` is for.
|
||||
-->
|
||||
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover"> -->
|
||||
|
||||
<!-- iOS meta tags & icons -->
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="apple-mobile-web-app-title" content="kuhy_credit_example">
|
||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
||||
|
||||
<!-- Favicon -->
|
||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
||||
|
||||
<title>kuhy_credit_example</title>
|
||||
<link rel="manifest" href="manifest.json">
|
||||
</head>
|
||||
<body>
|
||||
<!--
|
||||
You can customize the "flutter_bootstrap.js" script.
|
||||
This is useful to provide a custom configuration to the Flutter loader
|
||||
or to give the user feedback during the initialization process.
|
||||
|
||||
For more details:
|
||||
* https://docs.flutter.dev/platform-integration/web/initialization
|
||||
-->
|
||||
<script src="flutter_bootstrap.js" async></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,35 +0,0 @@
|
||||
{
|
||||
"name": "kuhy_credit_example",
|
||||
"short_name": "kuhy_credit_example",
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"background_color": "#0175C2",
|
||||
"theme_color": "#0175C2",
|
||||
"description": "A new Flutter project.",
|
||||
"orientation": "portrait-primary",
|
||||
"prefer_related_applications": false,
|
||||
"icons": [
|
||||
{
|
||||
"src": "icons/Icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-maskable-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
},
|
||||
{
|
||||
"src": "icons/Icon-maskable-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
/// The shared kuhy logo credit.
|
||||
library;
|
||||
|
||||
export 'src/credit_data.g.dart';
|
||||
export 'src/kuhy_credit.dart';
|
||||
@ -1,141 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND (generated by kuhy_credit/generator/generate.py; DO NOT EDIT).
|
||||
// ignore_for_file: public_member_api_docs
|
||||
|
||||
const String kCreditUrl = "https://kuhy.duckdns.org";
|
||||
const String kCreditText = "Created by kuhy";
|
||||
const double kLogoSize = 512;
|
||||
const int kLogoField = 0xFF211D1B;
|
||||
const List<(int, List<double>)> kLogoShapes = [
|
||||
(
|
||||
0xFFB8862E,
|
||||
<double>[
|
||||
232.45, 126.71, 235.4, 121.83, 236.86, 117.46, 237.16, 113.16, 236.11,
|
||||
108.55, 233.71, 104.34, 230.14, 100.74, 225.62, 97.95, 220.41, 96.16,
|
||||
214.75, 95.51, 208.86, 96.11, 202.89, 97.96, 196.97, 101.02, 191.8,
|
||||
104.61, 186.14, 109.43, 168.83, 127.05, 163.79, 131.69, 158.86,
|
||||
135.08, 156.85, 135.91, 155.0, 136.26, 153.32, 136.1, 151.51, 135.26,
|
||||
150.17, 134.03, 148.74, 131.95, 146.53, 126.68, 142.68, 113.58,
|
||||
140.39, 107.28, 137.47, 101.8, 134.17, 98.03, 131.62, 96.28, 129.3,
|
||||
95.34, 126.82, 94.91, 124.22, 94.99, 121.55, 95.59, 118.85, 96.69,
|
||||
116.18, 98.26, 113.59, 100.29, 110.67, 103.26, 108.46, 106.12, 104.82,
|
||||
112.71, 103.46, 116.33, 102.26, 120.85, 101.33, 129.4, 101.51, 134.83,
|
||||
102.18, 140.16, 107.16, 161.56, 107.92, 166.59, 108.16, 170.93,
|
||||
107.96, 175.3, 107.23, 180.39, 103.3, 196.89, 102.03, 203.6, 101.44,
|
||||
209.71, 101.57, 215.83, 102.56, 221.84, 104.46, 227.54, 106.85,
|
||||
232.14, 110.3, 236.77, 113.3, 239.71, 117.11, 242.44, 120.52, 244.13,
|
||||
124.51, 245.27, 128.36, 245.46, 131.44, 244.86, 134.25, 243.55, 137.1,
|
||||
241.19, 138.84, 238.98, 140.33, 236.37, 142.79, 229.46, 144.26, 222.2,
|
||||
146.91, 203.45, 149.0, 195.46, 150.82, 191.74, 152.78, 189.39, 155.06,
|
||||
187.98, 157.64, 187.54, 160.46, 188.07, 163.46, 189.54, 166.57,
|
||||
191.89, 170.18, 195.54, 176.49, 203.82, 187.93, 221.96, 192.91,
|
||||
229.15, 198.18, 235.26, 203.3, 239.57, 207.07, 241.74, 210.4, 243.03,
|
||||
213.78, 243.76, 217.74, 243.92, 221.07, 243.47, 224.8, 242.29, 228.25,
|
||||
240.44, 230.89, 238.38, 233.17, 235.92, 235.02, 233.11, 236.37, 230.0,
|
||||
237.18, 226.63, 237.42, 223.07, 237.07, 219.35, 236.13, 215.54, 234.6,
|
||||
211.66, 230.9, 205.16, 225.43, 198.15, 219.02, 191.41, 205.04, 178.08,
|
||||
200.57, 173.11, 197.35, 167.98, 196.49, 165.31, 196.29, 163.13,
|
||||
196.57, 160.98, 197.54, 158.44, 199.16, 155.9, 201.39, 153.37, 206.78,
|
||||
148.63, 224.45, 135.06, 228.82, 130.95,
|
||||
],
|
||||
),
|
||||
(
|
||||
0xFFB8862E,
|
||||
<double>[
|
||||
439.15, 304.62, 441.35, 299.45, 442.51, 294.18, 442.42, 288.99,
|
||||
441.16, 284.54, 438.79, 280.56, 435.43, 277.23, 431.27, 274.73,
|
||||
426.09, 273.1, 421.13, 272.75, 416.7, 273.37, 412.03, 275.08, 407.76,
|
||||
277.8, 404.33, 280.97, 400.93, 285.13, 391.39, 300.46, 387.52, 305.61,
|
||||
384.97, 308.13, 382.62, 309.84, 379.82, 311.14, 377.32, 311.67,
|
||||
374.44, 311.56, 371.59, 310.69, 368.84, 309.1, 366.22, 306.86, 361.68,
|
||||
301.2, 353.72, 288.2, 349.9, 282.87, 345.1, 278.03, 339.97, 274.81,
|
||||
336.22, 273.46, 332.8, 272.84, 328.82, 272.8, 324.89, 273.46, 321.18,
|
||||
274.78, 317.81, 276.73, 314.92, 279.23, 312.64, 282.19, 311.36,
|
||||
284.65, 310.49, 287.28, 310.02, 290.04, 309.96, 292.87, 310.28,
|
||||
295.74, 311.1, 299.1, 313.73, 305.2, 316.79, 310.09, 321.01, 315.47,
|
||||
337.3, 332.65, 344.34, 340.99, 350.25, 349.71, 354.13, 357.71, 356.15,
|
||||
364.64, 356.94, 371.76, 356.69, 378.61, 354.92, 395.62, 354.93,
|
||||
400.36, 355.46, 405.02, 356.78, 409.97, 358.95, 414.48, 361.98,
|
||||
418.37, 365.77, 421.42, 369.24, 423.14, 372.98, 424.16, 376.83,
|
||||
424.43, 380.67, 423.95, 384.34, 422.72, 387.71, 420.81, 390.68,
|
||||
418.27, 393.42, 414.79, 394.87, 412.17, 396.16, 408.88, 397.04, 405.4,
|
||||
397.53, 401.79, 397.58, 394.42, 395.86, 378.48, 395.63, 371.63,
|
||||
396.54, 364.05, 398.85, 356.69, 402.9, 348.74, 408.61, 340.49, 415.36,
|
||||
332.56, 431.64, 315.37, 435.86, 309.98,
|
||||
],
|
||||
),
|
||||
(
|
||||
0xFFECEAE9,
|
||||
<double>[
|
||||
272.87, 180.5, 273.78, 191.15, 275.43, 199.68, 277.93, 207.24, 281.46,
|
||||
214.32, 286.01, 220.83, 291.97, 227.15, 298.81, 232.68, 306.29,
|
||||
237.38, 314.83, 241.44, 323.65, 244.37, 331.97, 245.96, 340.33,
|
||||
246.39, 348.69, 245.62, 356.98, 243.7, 365.74, 240.46, 374.17, 236.11,
|
||||
379.85, 232.38, 385.15, 228.16, 389.95, 223.48, 393.76, 218.86,
|
||||
397.03, 213.89, 399.73, 208.6, 401.84, 203.03, 403.53, 196.59, 404.61,
|
||||
189.99, 405.3, 181.99, 405.89, 159.12, 407.09, 137.35, 407.21, 129.01,
|
||||
406.69, 121.27, 405.6, 115.09, 403.79, 109.27, 401.53, 104.61, 398.24,
|
||||
100.21, 394.25, 96.96, 389.72, 95.06, 385.41, 94.63, 381.04, 95.41,
|
||||
376.28, 97.71, 371.95, 101.35, 368.3, 106.12, 366.03, 110.43, 364.13,
|
||||
115.78, 363.07, 120.69, 362.53, 126.4, 362.58, 131.38, 363.12, 136.95,
|
||||
366.62, 155.29, 367.54, 162.94, 367.32, 171.38, 366.55, 176.01, 365.5,
|
||||
179.98, 363.26, 185.87, 360.61, 190.86, 357.41, 195.43, 353.74,
|
||||
199.38, 349.69, 202.52, 345.92, 204.46, 342.02, 205.56, 338.06,
|
||||
205.77, 334.12, 205.08, 330.28, 203.52, 326.61, 201.16, 322.73,
|
||||
197.62, 319.27, 193.35, 316.32, 188.55, 313.95, 183.43, 312.21,
|
||||
178.16, 310.8, 170.23, 310.73, 162.45, 311.59, 155.45, 315.0, 137.8,
|
||||
315.74, 128.01, 315.47, 123.01, 314.68, 118.04, 313.31, 113.22,
|
||||
311.38, 108.68, 308.91, 104.56, 305.95, 101.0, 302.59, 98.14, 298.95,
|
||||
96.07, 295.15, 94.89, 291.33, 94.64, 287.61, 95.31, 284.11, 96.89,
|
||||
281.8, 98.52, 279.7, 100.54, 277.81, 102.91, 275.86, 106.15, 273.2,
|
||||
112.94, 271.66, 120.41, 271.11, 126.72, 271.03, 133.73, 272.32,
|
||||
158.32,
|
||||
],
|
||||
),
|
||||
(
|
||||
0xFFECEAE9,
|
||||
<double>[
|
||||
142.5, 408.93, 144.93, 412.86, 148.33, 416.82, 151.62, 419.58, 155.73,
|
||||
421.94, 159.96, 423.33, 164.11, 423.69, 168.0, 423.04, 171.46, 421.41,
|
||||
173.61, 419.69, 175.81, 417.09, 177.3, 414.53, 178.71, 411.07, 180.34,
|
||||
403.92, 181.9, 389.45, 182.76, 384.3, 184.38, 379.06, 186.6, 375.03,
|
||||
188.42, 372.84, 190.56, 370.93, 193.02, 369.3, 196.36, 367.72, 203.33,
|
||||
365.93, 207.41, 365.55, 211.54, 365.59, 218.2, 366.61, 224.14, 368.79,
|
||||
226.71, 370.32, 228.97, 372.13, 232.2, 376.09, 234.21, 380.29, 235.51,
|
||||
385.06, 237.68, 403.4, 239.06, 409.98, 241.43, 415.72, 243.06, 418.13,
|
||||
244.99, 420.16, 247.7, 422.03, 250.76, 423.22, 254.12, 423.7, 257.08,
|
||||
423.52, 260.7, 422.61, 263.71, 421.29, 267.19, 419.06, 269.9, 416.7,
|
||||
273.71, 412.09, 276.7, 406.63, 278.73, 400.57, 279.77, 394.13, 279.87,
|
||||
387.57, 279.19, 381.08, 277.76, 374.06, 273.42, 357.39, 272.7, 353.01,
|
||||
272.43, 348.73, 272.65, 344.45, 273.45, 339.45, 277.62, 323.51,
|
||||
278.95, 317.31, 279.71, 311.68, 279.93, 306.77, 279.2, 298.62, 277.23,
|
||||
291.66, 274.04, 285.39, 269.78, 280.17, 267.06, 277.83, 263.57,
|
||||
275.63, 260.56, 274.33, 256.94, 273.46, 253.99, 273.3, 250.64, 273.8,
|
||||
248.07, 274.77, 245.32, 276.56, 243.34, 278.53, 241.66, 280.88, 239.2,
|
||||
286.54, 237.66, 293.75, 235.48, 312.08, 233.95, 317.39, 231.82, 321.5,
|
||||
230.08, 323.74, 228.0, 325.7, 225.6, 327.39, 222.9, 328.79, 216.76,
|
||||
330.71, 209.32, 331.48, 201.85, 330.81, 198.02, 329.85, 195.07,
|
||||
328.73, 192.39, 327.32, 190.0, 325.62, 187.94, 323.64, 186.21, 321.39,
|
||||
184.11, 317.26, 182.6, 311.93, 180.42, 293.59, 179.04, 287.01, 177.76,
|
||||
283.44, 176.37, 280.76, 174.68, 278.43, 172.69, 276.48, 169.92,
|
||||
274.72, 167.34, 273.77, 163.98, 273.3, 161.03, 273.48, 157.4, 274.38,
|
||||
154.4, 275.7, 150.92, 277.93, 148.21, 280.29, 143.97, 285.54, 141.1,
|
||||
291.09, 139.19, 297.22, 138.23, 304.49, 138.34, 311.05, 139.18, 317.5,
|
||||
144.55, 338.96, 145.64, 347.04, 145.57, 351.31, 144.91, 356.27,
|
||||
139.77, 376.54, 138.77, 382.07, 138.23, 387.76, 138.29, 393.51,
|
||||
139.06, 399.17, 140.59, 404.59,
|
||||
],
|
||||
),
|
||||
];
|
||||
const int kDarkBg = 0xFF211D1B;
|
||||
const int kLightBg = 0xFFF6F4F3;
|
||||
const int kDarkSurface = 0xFF2B2624;
|
||||
const int kDarkBorder = 0xFF463E3A;
|
||||
const int kDarkText = 0xFFECEAE9;
|
||||
const int kLightSurface = 0xFFFCFBFB;
|
||||
const int kLightBorder = 0xFFE0DAD7;
|
||||
const int kLightText = 0xFF211D1B;
|
||||
const int kFocus = 0xFFB8862E;
|
||||
const double kRadius = 12;
|
||||
const double kSpaceSm = 8;
|
||||
const double kSpaceMd = 16;
|
||||
const double kTextBody = 16;
|
||||
@ -1,234 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:kuhy_credit/src/credit_data.g.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
part 'kuhy_credit_logo.dart';
|
||||
|
||||
/// Opens [uri] in the system browser: a new tab on web, the browser app on
|
||||
/// Android.
|
||||
Future<void> openInBrowser(Uri uri) async {
|
||||
await launchUrl(
|
||||
uri,
|
||||
mode: LaunchMode.externalApplication,
|
||||
webOnlyWindowName: '_blank',
|
||||
);
|
||||
}
|
||||
|
||||
/// The shared kuhy credit.
|
||||
///
|
||||
/// Shows the M1 logo. A tap (or Enter/Space) opens a small panel with the
|
||||
/// logo and the credit text; a tap on the panel opens the website through
|
||||
/// [launcher] and closes it. Escape, Back, a tap outside and a second logo
|
||||
/// tap close the panel. Colours follow the platform brightness.
|
||||
class KuhyCredit extends StatefulWidget {
|
||||
/// Creates the credit.
|
||||
const KuhyCredit({
|
||||
super.key,
|
||||
this.size = 48,
|
||||
this.below = false,
|
||||
this.alignStart = false,
|
||||
this.launcher = openInBrowser,
|
||||
});
|
||||
|
||||
/// Finds the logo button in tests.
|
||||
static const ValueKey<String> logoKey = ValueKey('kuhy_credit.logo');
|
||||
|
||||
/// Finds the open panel in tests.
|
||||
static const ValueKey<String> panelKey = ValueKey('kuhy_credit.panel');
|
||||
|
||||
/// Logo edge length in logical pixels.
|
||||
final double size;
|
||||
|
||||
/// Open the panel under the logo instead of above it.
|
||||
final bool below;
|
||||
|
||||
/// Align the panel's start edge with the logo instead of its end edge.
|
||||
final bool alignStart;
|
||||
|
||||
/// Opens the website; replace it to stub the browser in tests.
|
||||
final Future<void> Function(Uri uri) launcher;
|
||||
|
||||
@override
|
||||
State<KuhyCredit> createState() => _KuhyCreditState();
|
||||
}
|
||||
|
||||
class _KuhyCreditState extends State<KuhyCredit> {
|
||||
final _portal = OverlayPortalController();
|
||||
final _link = LayerLink();
|
||||
final _logoFocus = FocusNode();
|
||||
final _panelFocus = FocusNode();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_logoFocus.dispose();
|
||||
_panelFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _toggle() {
|
||||
if (_portal.isShowing) {
|
||||
_close();
|
||||
return;
|
||||
}
|
||||
setState(_portal.show);
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => _panelFocus.requestFocus(),
|
||||
);
|
||||
}
|
||||
|
||||
void _close() {
|
||||
if (_portal.isShowing) setState(_portal.hide);
|
||||
}
|
||||
|
||||
Future<void> _activate() async {
|
||||
_close();
|
||||
await widget.launcher(Uri.parse(kCreditUrl));
|
||||
}
|
||||
|
||||
KeyEventResult _onPanelKey(FocusNode _, KeyEvent event) {
|
||||
if (event is! KeyDownEvent) return KeyEventResult.ignored;
|
||||
final key = event.logicalKey;
|
||||
if (key == LogicalKeyboardKey.escape) {
|
||||
_close();
|
||||
_logoFocus.requestFocus();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key == LogicalKeyboardKey.enter || key == LogicalKeyboardKey.space) {
|
||||
unawaited(_activate());
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dark = MediaQuery.platformBrightnessOf(context) == Brightness.dark;
|
||||
final above = !widget.below;
|
||||
final end = !widget.alignStart;
|
||||
final logo = Semantics(
|
||||
button: true,
|
||||
expanded: _portal.isShowing,
|
||||
label: kCreditText,
|
||||
excludeSemantics: true,
|
||||
onTap: _toggle,
|
||||
child: FocusableActionDetector(
|
||||
focusNode: _logoFocus,
|
||||
mouseCursor: SystemMouseCursors.click,
|
||||
actions: {
|
||||
ActivateIntent: CallbackAction<ActivateIntent>(
|
||||
onInvoke: (_) => _toggle(),
|
||||
),
|
||||
},
|
||||
child: GestureDetector(
|
||||
key: KuhyCredit.logoKey,
|
||||
onTap: _toggle,
|
||||
child: _Logo(size: widget.size),
|
||||
),
|
||||
),
|
||||
);
|
||||
return PopScope(
|
||||
canPop: !_portal.isShowing,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop) _close();
|
||||
},
|
||||
child: TapRegion(
|
||||
groupId: this,
|
||||
onTapOutside: (_) => _close(),
|
||||
child: CompositedTransformTarget(
|
||||
link: _link,
|
||||
child: OverlayPortal(
|
||||
controller: _portal,
|
||||
overlayChildBuilder: (context) => CompositedTransformFollower(
|
||||
link: _link,
|
||||
targetAnchor: Alignment(end ? 1 : -1, above ? -1 : 1),
|
||||
followerAnchor: Alignment(end ? 1 : -1, above ? 1 : -1),
|
||||
offset: Offset(0, above ? -kSpaceSm : kSpaceSm),
|
||||
child: Align(
|
||||
alignment: Alignment(end ? 1 : -1, above ? 1 : -1),
|
||||
child: TapRegion(
|
||||
groupId: this,
|
||||
child: _Panel(
|
||||
dark: dark,
|
||||
size: widget.size,
|
||||
focusNode: _panelFocus,
|
||||
onKey: _onPanelKey,
|
||||
onTap: _activate,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: logo,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Panel extends StatelessWidget {
|
||||
const _Panel({
|
||||
required this.dark,
|
||||
required this.size,
|
||||
required this.focusNode,
|
||||
required this.onKey,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final bool dark;
|
||||
final double size;
|
||||
final FocusNode focusNode;
|
||||
final FocusOnKeyEventCallback onKey;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Semantics(
|
||||
link: true,
|
||||
label: kCreditText,
|
||||
excludeSemantics: true,
|
||||
onTap: onTap,
|
||||
child: Focus(
|
||||
focusNode: focusNode,
|
||||
onKeyEvent: onKey,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
key: KuhyCredit.panelKey,
|
||||
onTap: onTap,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Color(dark ? kDarkSurface : kLightSurface),
|
||||
border: Border.all(
|
||||
color: Color(dark ? kDarkBorder : kLightBorder),
|
||||
),
|
||||
borderRadius: BorderRadius.circular(kRadius),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(kSpaceMd),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: kSpaceSm,
|
||||
children: [
|
||||
_Logo(size: size),
|
||||
Text(
|
||||
kCreditText,
|
||||
textDirection: TextDirection.ltr,
|
||||
style: TextStyle(
|
||||
color: Color(dark ? kDarkText : kLightText),
|
||||
fontSize: kTextBody,
|
||||
decoration: TextDecoration.none,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
part of 'kuhy_credit.dart';
|
||||
|
||||
class _Logo extends StatelessWidget {
|
||||
const _Logo({required this.size});
|
||||
|
||||
final double size;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomPaint(size: Size.square(size), painter: const _LogoPainter());
|
||||
}
|
||||
}
|
||||
|
||||
class _LogoPainter extends CustomPainter {
|
||||
const _LogoPainter();
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
canvas
|
||||
..scale(size.width / kLogoSize)
|
||||
..drawRect(
|
||||
const Rect.fromLTWH(0, 0, kLogoSize, kLogoSize),
|
||||
Paint()..color = const Color(kLogoField),
|
||||
);
|
||||
for (final (fill, points) in kLogoShapes) {
|
||||
final path = Path()..moveTo(points[0], points[1]);
|
||||
for (var i = 2; i < points.length; i += 2) {
|
||||
path.lineTo(points[i], points[i + 1]);
|
||||
}
|
||||
canvas.drawPath(path..close(), Paint()..color = Color(fill));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_LogoPainter oldDelegate) => false;
|
||||
}
|
||||
@ -1,290 +0,0 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: async
|
||||
sha256: e2eb0491ba5ddb6177742d2da23904574082139b07c1e33b8503b9f46f3e1a37
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.13.1"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: boolean_selector
|
||||
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: characters
|
||||
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: clock
|
||||
sha256: e51d50bca3217c9a9fa2b41a30e4a38971133f5f9ec7a3d57bae095007f1d28e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.3"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.19.1"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fake_async
|
||||
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.3"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "11.0.2"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_flutter_testing
|
||||
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.10"
|
||||
leak_tracker_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_testing
|
||||
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
listen:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: listen
|
||||
sha256: "47501a08016a43fcad79252439d723f50f14f88fa7bfd8a177e0a417e5c9e1f2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: "31bd099b47c10cd1aeb55146a2d46ce0277630ecef3f7dae54ad7873f36696cd"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.20"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.13.0"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "307249ce4ff29d58a18e97f6345f539382eb9c9c29ecda628900f31de0443dd9"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.19.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path
|
||||
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
plugin_platform_interface:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: plugin_platform_interface
|
||||
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.8"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_span
|
||||
sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.10.2"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: "277654b3034d17ac6f9f1cb5595db011b1d5d41e8806866db28e0abaa101c490"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.12.2"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: string_scanner
|
||||
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: term_glyph
|
||||
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.2"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "0a10344e901e5b2e63819567951cb6a06673ed6b84f40462188ff5a0c41f371f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.14"
|
||||
url_launcher:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: e8cc955c97e06df9879140a1fe301f3d493f01b7c62dec7f46834be31d7e9fda
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.3"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
sha256: b8073b1e5173d63afe1a18985a75896d72f759d3bc1817eb1ae8d26e8527cceb
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.3.35"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_ios
|
||||
sha256: "8faa1aab294f1ab4040b43660c887b0418d5fa4f0cffef76a484e6aa1092eb4a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.4.2"
|
||||
url_launcher_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_linux
|
||||
sha256: "10f86fef4c2c43563fa6c211ff9cf757adf4d3ab762c56bd430664a947d70cd0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.3"
|
||||
url_launcher_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_macos
|
||||
sha256: "5e835a3b869c2d70325349c81c5a45c28e20791265b67b2669da6b08c5cd5201"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.6"
|
||||
url_launcher_platform_interface:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: url_launcher_platform_interface
|
||||
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
sha256: "85c81589622fbc87c1c683aaea164d3604a7777495a79d91e39ffcdec39ddb34"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_windows
|
||||
sha256: "6c5ad3f22cd4c38e089b81963b3cd7bb83b111b2df5dce008bb066162f42e429"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.6"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: fa49e1674cb84acb900141714e6c6e1f9ae099827c24d141430ff6819db4e1bc
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.4"
|
||||
very_good_analysis:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: very_good_analysis
|
||||
sha256: "0bd5eb8d6be76aa0d71e70cbdae6cac8f784f761170568e3c2214a6948c7f6d3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "11.0.0"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "89b11d62e1040ee681af3b4f1c97a803ecbf010c6e8b9c5896ee5b08c3bf7b78"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "15.4.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: e119e82ac4795c7925103b7cf3768191f33941b99e7ccffbd6c645201d9f606b
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
sdks:
|
||||
dart: ">=3.13.0 <4.0.0"
|
||||
flutter: ">=3.44.0"
|
||||
@ -1,21 +0,0 @@
|
||||
name: kuhy_credit
|
||||
description: >-
|
||||
The shared "Created by kuhy" credit: an M1 logo button that opens a small
|
||||
panel, whose tap opens kuhy.duckdns.org. Android and Flutter web.
|
||||
publish_to: 'none'
|
||||
version: 0.1.0
|
||||
|
||||
environment:
|
||||
sdk: ^3.12.2
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
url_launcher: 6.3.3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
plugin_platform_interface: 2.1.8
|
||||
url_launcher_platform_interface: 2.3.2
|
||||
very_good_analysis: ^11.0.0
|
||||
@ -1,235 +0,0 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:kuhy_credit/kuhy_credit.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
|
||||
|
||||
final Finder _logo = find.byKey(KuhyCredit.logoKey);
|
||||
final Finder _panel = find.byKey(KuhyCredit.panelKey);
|
||||
|
||||
Future<List<Uri>> _pump(
|
||||
WidgetTester tester, {
|
||||
Brightness brightness = Brightness.dark,
|
||||
bool below = false,
|
||||
bool alignStart = false,
|
||||
Alignment at = Alignment.bottomRight,
|
||||
}) async {
|
||||
final opened = <Uri>[];
|
||||
tester.platformDispatcher.platformBrightnessTestValue = brightness;
|
||||
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
|
||||
await tester.pumpWidget(
|
||||
WidgetsApp(
|
||||
color: const Color(kDarkBg),
|
||||
pageRouteBuilder: _route,
|
||||
home: Stack(
|
||||
children: [
|
||||
const Positioned(
|
||||
left: 0,
|
||||
top: 0,
|
||||
child: SizedBox(width: 40, height: 40),
|
||||
),
|
||||
Align(
|
||||
alignment: at,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: KuhyCredit(
|
||||
below: below,
|
||||
alignStart: alignStart,
|
||||
launcher: (uri) async => opened.add(uri),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
return opened;
|
||||
}
|
||||
|
||||
PageRoute<T> _route<T>(RouteSettings settings, WidgetBuilder builder) =>
|
||||
PageRouteBuilder<T>(
|
||||
settings: settings,
|
||||
pageBuilder: (context, _, _) => builder(context),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('shows only the logo, named for screen readers', (tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
final opened = await _pump(tester);
|
||||
expect(_logo, findsOneWidget);
|
||||
expect(_panel, findsNothing);
|
||||
expect(find.text(kCreditText), findsNothing);
|
||||
expect(find.bySemanticsLabel(kCreditText), findsOneWidget);
|
||||
expect(opened, isEmpty);
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets('logo tap opens the panel; panel tap opens the site', (
|
||||
tester,
|
||||
) async {
|
||||
final opened = await _pump(tester);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_panel, findsOneWidget);
|
||||
expect(find.text(kCreditText), findsOneWidget);
|
||||
expect(opened, isEmpty);
|
||||
await tester.tap(find.text(kCreditText));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, [Uri.parse(kCreditUrl)]);
|
||||
expect(_panel, findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('second logo tap closes and stays closed', (tester) async {
|
||||
final opened = await _pump(tester);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_panel, findsNothing);
|
||||
expect(opened, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('tap outside closes', (tester) async {
|
||||
final opened = await _pump(tester);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tapAt(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_panel, findsNothing);
|
||||
expect(opened, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('Escape closes and returns focus to the logo', (tester) async {
|
||||
final opened = await _pump(tester);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_panel, findsNothing);
|
||||
expect(opened, isEmpty);
|
||||
expect(
|
||||
Focus.of(tester.element(find.byKey(KuhyCredit.logoKey))).hasFocus,
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Back closes the panel instead of leaving the screen', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
final handled = await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(handled, isTrue);
|
||||
expect(_panel, findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('keyboard: Tab reaches the logo, Enter opens, Enter on panel '
|
||||
'opens the site', (tester) async {
|
||||
final opened = await _pump(tester);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_panel, findsOneWidget);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.space);
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, [Uri.parse(kCreditUrl)]);
|
||||
});
|
||||
|
||||
testWidgets('other keys leave the panel open', (tester) async {
|
||||
await _pump(tester);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.keyA);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_panel, findsOneWidget);
|
||||
});
|
||||
|
||||
for (final (brightness, surface, text) in [
|
||||
(Brightness.dark, kDarkSurface, kDarkText),
|
||||
(Brightness.light, kLightSurface, kLightText),
|
||||
]) {
|
||||
testWidgets('panel colours follow $brightness tokens', (tester) async {
|
||||
await _pump(tester, brightness: brightness);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
final box = tester.widget<DecoratedBox>(
|
||||
find.descendant(of: _panel, matching: find.byType(DecoratedBox)),
|
||||
);
|
||||
final deco = box.decoration as BoxDecoration;
|
||||
expect(deco.color, Color(surface));
|
||||
expect(deco.borderRadius, BorderRadius.circular(kRadius));
|
||||
final style = tester.widget<Text>(find.text(kCreditText)).style!;
|
||||
expect(style.color, Color(text));
|
||||
expect(style.fontSize, kTextBody);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('panel sits above and end-aligned by default', (tester) async {
|
||||
await _pump(tester);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
final panel = tester.getRect(_panel);
|
||||
final logo = tester.getRect(_logo);
|
||||
expect(panel.bottom, lessThan(logo.top));
|
||||
expect(panel.right, moreOrLessEquals(logo.right));
|
||||
});
|
||||
|
||||
testWidgets('below + alignStart puts it under, start-aligned', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, below: true, alignStart: true, at: Alignment.topLeft);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
final panel = tester.getRect(_panel);
|
||||
final logo = tester.getRect(_logo);
|
||||
expect(panel.top, greaterThan(logo.bottom));
|
||||
expect(panel.left, moreOrLessEquals(logo.left));
|
||||
});
|
||||
|
||||
testWidgets('the default launcher opens a new tab / external app', (
|
||||
tester,
|
||||
) async {
|
||||
final fake = _FakeLauncher();
|
||||
UrlLauncherPlatform.instance = fake;
|
||||
await tester.pumpWidget(
|
||||
WidgetsApp(
|
||||
color: const Color(kDarkBg),
|
||||
pageRouteBuilder: _route,
|
||||
home: const Center(child: KuhyCredit()),
|
||||
),
|
||||
);
|
||||
await tester.tap(_logo);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(kCreditText));
|
||||
await tester.pumpAndSettle();
|
||||
expect(fake.urls, [kCreditUrl]);
|
||||
expect(fake.options.single.mode, PreferredLaunchMode.externalApplication);
|
||||
expect(fake.options.single.webOnlyWindowName, '_blank');
|
||||
});
|
||||
|
||||
testWidgets('the logo painter draws and never repaints', (tester) async {
|
||||
await _pump(tester);
|
||||
final paint = tester.widget<CustomPaint>(
|
||||
find.descendant(of: _logo, matching: find.byType(CustomPaint)).first,
|
||||
);
|
||||
expect(paint.painter!.shouldRepaint(paint.painter!), isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeLauncher extends Fake
|
||||
with MockPlatformInterfaceMixin
|
||||
implements UrlLauncherPlatform {
|
||||
final urls = <String>[];
|
||||
final options = <LaunchOptions>[];
|
||||
|
||||
@override
|
||||
Future<bool> launchUrl(String url, LaunchOptions options) async {
|
||||
urls.add(url);
|
||||
this.options.add(options);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
"""Build-time generator: writes every stack's credit data from credit.json."""
|
||||
@ -1,170 +0,0 @@
|
||||
"""Render the shared credit data as source text for each stack.
|
||||
|
||||
Every emitter returns the full file. Long data (the SVG, the polygon points)
|
||||
is wrapped into short lines so each stack's linter accepts the file as is.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import shlex
|
||||
import textwrap
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from generator.svg import Logo
|
||||
from generator.tokens import Palette, Tokens
|
||||
|
||||
MARK = "generated by kuhy_credit/generator/generate.py; DO NOT EDIT"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Credit:
|
||||
"""Everything a stack needs: the words, the link, the art, the tokens."""
|
||||
|
||||
url: str
|
||||
text: str
|
||||
svg: str
|
||||
logo: Logo
|
||||
tokens: Tokens
|
||||
|
||||
|
||||
def _num(v: float) -> str:
|
||||
return f"{v:g}" if v != int(v) else f"{int(v)}.0"
|
||||
|
||||
|
||||
def _wrap(items: list[str], indent: str, width: int = 76) -> str:
|
||||
joined = ", ".join(items) + ","
|
||||
return textwrap.fill(joined, width, initial_indent=indent, subsequent_indent=indent)
|
||||
|
||||
|
||||
def _points(points: tuple[float, ...], indent: int) -> str:
|
||||
return _wrap([_num(p) for p in points], " " * indent)
|
||||
|
||||
|
||||
def _chunks(text: str, size: int = 60) -> list[str]:
|
||||
return [json.dumps(text[i : i + size]) for i in range(0, len(text), size)]
|
||||
|
||||
|
||||
def _gd_str(chunk: str) -> str:
|
||||
"""GDScript literal the way gdformat writes it: single quotes around '"'."""
|
||||
text = json.dumps(chunk)
|
||||
if '"' in chunk and "'" not in chunk:
|
||||
return "'" + text[1:-1].replace('\\"', '"') + "'"
|
||||
return text
|
||||
|
||||
|
||||
def _argb(hex_colour: str) -> str:
|
||||
return f"0xFF{hex_colour.lstrip('#').upper()}"
|
||||
|
||||
|
||||
def python(c: Credit) -> str:
|
||||
"""kuhy_credit/_data.py."""
|
||||
shapes = "".join(
|
||||
f' (\n "{s.fill}",\n (\n{_points(s.points, 12)}\n ),\n ),\n'
|
||||
for s in c.logo.shapes
|
||||
)
|
||||
|
||||
def pal(p: Palette) -> str:
|
||||
return (
|
||||
f'{{"bg": "{p.bg}", "surface": "{p.surface}", "border": "{p.border}", '
|
||||
f'"text": "{p.text}"}}'
|
||||
)
|
||||
|
||||
t = c.tokens
|
||||
return (
|
||||
f'"""The shared credit data ({MARK})."""\n\n'
|
||||
f"URL = {json.dumps(c.url)}\nTEXT = {json.dumps(c.text)}\n"
|
||||
f"LOGO_SIZE = {c.logo.size}\nLOGO_FIELD = {json.dumps(c.logo.field)}\n"
|
||||
f"LOGO_SHAPES: tuple[tuple[str, tuple[float, ...]], ...] = (\n{shapes})\n"
|
||||
f"DARK = {pal(t.dark)}\nLIGHT = {pal(t.light)}\n"
|
||||
f'FOCUS = "{t.focus}"\nRADIUS = {t.radius}\nSPACE_SM = {t.space_sm}\n'
|
||||
f"SPACE_MD = {t.space_md}\nTEXT_BODY = {t.text_body}\n"
|
||||
)
|
||||
|
||||
|
||||
def web(c: Credit) -> str:
|
||||
"""web/src/credit-data.js."""
|
||||
svg = "\n + ".join(_chunks(c.svg))
|
||||
t = c.tokens
|
||||
|
||||
def pal(p: Palette) -> str:
|
||||
return f'{{ bg: "{p.bg}", surface: "{p.surface}", border: "{p.border}", text: "{p.text}" }}'
|
||||
|
||||
return (
|
||||
f"// The shared credit data ({MARK}).\n"
|
||||
f"export const CREDIT_URL = {json.dumps(c.url)};\n"
|
||||
f"export const CREDIT_TEXT = {json.dumps(c.text)};\n"
|
||||
f"export const LOGO_SVG =\n {svg};\n"
|
||||
f"export const TOKENS = {{\n dark: {pal(t.dark)},\n light: {pal(t.light)},\n"
|
||||
f' focus: "{t.focus}",\n radius: {t.radius},\n spaceSm: {t.space_sm},\n'
|
||||
f" spaceMd: {t.space_md},\n textBody: {t.text_body},\n}};\n"
|
||||
)
|
||||
|
||||
|
||||
def flutter(c: Credit) -> str:
|
||||
"""flutter/lib/src/credit_data.g.dart."""
|
||||
shapes = "".join(
|
||||
f" (\n {_argb(s.fill)},\n <double>[\n{_points(s.points, 6)}\n ],\n ),\n"
|
||||
for s in c.logo.shapes
|
||||
)
|
||||
t = c.tokens
|
||||
return (
|
||||
f"// GENERATED CODE - DO NOT MODIFY BY HAND ({MARK}).\n"
|
||||
"// ignore_for_file: public_member_api_docs\n\n"
|
||||
f"const String kCreditUrl = {json.dumps(c.url)};\n"
|
||||
f"const String kCreditText = {json.dumps(c.text)};\n"
|
||||
f"const double kLogoSize = {c.logo.size};\n"
|
||||
f"const int kLogoField = {_argb(c.logo.field)};\n"
|
||||
f"const List<(int, List<double>)> kLogoShapes = [\n{shapes}];\n"
|
||||
f"const int kDarkBg = {_argb(t.dark.bg)};\n"
|
||||
f"const int kLightBg = {_argb(t.light.bg)};\n"
|
||||
f"const int kDarkSurface = {_argb(t.dark.surface)};\n"
|
||||
f"const int kDarkBorder = {_argb(t.dark.border)};\n"
|
||||
f"const int kDarkText = {_argb(t.dark.text)};\n"
|
||||
f"const int kLightSurface = {_argb(t.light.surface)};\n"
|
||||
f"const int kLightBorder = {_argb(t.light.border)};\n"
|
||||
f"const int kLightText = {_argb(t.light.text)};\n"
|
||||
f"const int kFocus = {_argb(t.focus)};\n"
|
||||
f"const double kRadius = {t.radius};\n"
|
||||
f"const double kSpaceSm = {t.space_sm};\n"
|
||||
f"const double kSpaceMd = {t.space_md};\n"
|
||||
f"const double kTextBody = {t.text_body};\n"
|
||||
)
|
||||
|
||||
|
||||
def godot(c: Credit) -> str:
|
||||
"""godot/addons/kuhy_credit/credit_data.gd."""
|
||||
svg = "\n\t+ ".join(_gd_str(c.svg[i : i + 60]) for i in range(0, len(c.svg), 60))
|
||||
t = c.tokens
|
||||
|
||||
def pal(p: Palette) -> str:
|
||||
return (
|
||||
f'{{\n\t"bg": Color("{p.bg}"),\n\t"surface": Color("{p.surface}"),'
|
||||
f'\n\t"border": Color("{p.border}"),\n\t"text": Color("{p.text}"),\n}}'
|
||||
)
|
||||
|
||||
return (
|
||||
f"## The shared credit data ({MARK}).\n"
|
||||
"extends RefCounted\n\n"
|
||||
f"const URL := {json.dumps(c.url)}\n"
|
||||
f"const TEXT := {json.dumps(c.text)}\n"
|
||||
f"const LOGO_SIZE := {c.logo.size}\n"
|
||||
f"const LOGO_SVG := (\n\t{svg}\n)\n"
|
||||
f"const DARK := {pal(t.dark)}\n"
|
||||
f"const LIGHT := {pal(t.light)}\n"
|
||||
f'const FOCUS := Color("{t.focus}")\n'
|
||||
f"const RADIUS := {t.radius}\nconst SPACE_SM := {t.space_sm}\n"
|
||||
f"const SPACE_MD := {t.space_md}\nconst TEXT_BODY := {t.text_body}\n"
|
||||
)
|
||||
|
||||
|
||||
def terminal(c: Credit) -> str:
|
||||
"""terminal/kuhy-credit.sh."""
|
||||
return (
|
||||
"#!/bin/bash\n"
|
||||
f"# Prints the one-line kuhy credit and opens nothing ({MARK}).\n"
|
||||
"set -euo pipefail\n"
|
||||
f"printf '%s %s\\n' {shlex.quote(c.text)} {shlex.quote(c.url)}\n"
|
||||
)
|
||||
@ -1,110 +0,0 @@
|
||||
"""Write, or check, every stack's generated credit data.
|
||||
|
||||
python -m generator.generate # rewrite all stacks
|
||||
python -m generator.generate --check # exit 1 and name each drifted stack
|
||||
|
||||
Reads kuhy_credit/credit.json (URL + text), the M1 art and tokens.css; the
|
||||
paths in credit.json are relative to the repo root (the credit dir's parent).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from generator import emit
|
||||
from generator.svg import parse_logo
|
||||
from generator.tokens import parse_tokens
|
||||
|
||||
CREDIT_DIR = Path(__file__).resolve().parents[1]
|
||||
|
||||
STACKS = {
|
||||
"python": "kuhy_credit/_data.py",
|
||||
"web": "web/src/credit-data.js",
|
||||
"flutter": "flutter/lib/src/credit_data.g.dart",
|
||||
"godot": "godot/addons/kuhy_credit/credit_data.gd",
|
||||
"terminal": "terminal/kuhy-credit.sh",
|
||||
}
|
||||
_EMITTERS = {
|
||||
"python": emit.python,
|
||||
"web": emit.web,
|
||||
"flutter": emit.flutter,
|
||||
"godot": emit.godot,
|
||||
"terminal": emit.terminal,
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Drift:
|
||||
"""A stack whose generated file differs from what the sources give."""
|
||||
|
||||
stack: str
|
||||
path: str
|
||||
|
||||
|
||||
def load(credit_dir: Path) -> emit.Credit:
|
||||
"""Read credit.json and the files it points at."""
|
||||
data = json.loads((credit_dir / "credit.json").read_text())
|
||||
root = credit_dir.parent
|
||||
svg = (root / data["logo"]).read_text()
|
||||
return emit.Credit(
|
||||
url=data["url"],
|
||||
text=data["text"],
|
||||
svg=svg,
|
||||
logo=parse_logo(svg),
|
||||
tokens=parse_tokens((root / data["tokens"]).read_text()),
|
||||
)
|
||||
|
||||
|
||||
def render(credit_dir: Path) -> dict[str, str]:
|
||||
"""Every stack's expected file content."""
|
||||
credit = load(credit_dir)
|
||||
return {stack: _EMITTERS[stack](credit) for stack in STACKS}
|
||||
|
||||
|
||||
def drift(credit_dir: Path) -> list[Drift]:
|
||||
"""Stacks whose file on disk is missing or differs from render()."""
|
||||
out = []
|
||||
for stack, text in render(credit_dir).items():
|
||||
path = credit_dir / STACKS[stack]
|
||||
if not path.is_file() or path.read_text() != text:
|
||||
out.append(Drift(stack, STACKS[stack]))
|
||||
return out
|
||||
|
||||
|
||||
def write(credit_dir: Path) -> None:
|
||||
"""Rewrite every stack's generated file."""
|
||||
for stack, text in render(credit_dir).items():
|
||||
path = credit_dir / STACKS[stack]
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(text)
|
||||
if stack == "terminal":
|
||||
path.chmod(0o755)
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
"""CLI entry point; returns the exit code."""
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--check", action="store_true", help="fail on drift, write nothing")
|
||||
parser.add_argument("--dir", type=Path, default=CREDIT_DIR, help="the kuhy_credit dir")
|
||||
args = parser.parse_args(argv)
|
||||
args.dir = args.dir.resolve()
|
||||
if not args.check:
|
||||
write(args.dir)
|
||||
print(f"wrote {len(STACKS)} stacks")
|
||||
return 0
|
||||
found = drift(args.dir)
|
||||
for d in found:
|
||||
print(f"drift: {d.stack} ({d.path}) differs from credit.json/logo/tokens")
|
||||
if found:
|
||||
print("fix: python -m generator.generate (from kuhy_credit/)")
|
||||
return 1
|
||||
print(f"all {len(STACKS)} stacks in sync")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@ -1,96 +0,0 @@
|
||||
"""Parse the M1 logo SVG into flat polygons every stack can draw.
|
||||
|
||||
The art is a square field rect plus filled paths built only from absolute
|
||||
M/L/Z commands. Each subpath becomes one polygon. The parser refuses anything
|
||||
else (curves, relative commands) and refuses subpaths whose bounding boxes
|
||||
overlap: an overlap could be a hole, which a plain polygon fill would paint
|
||||
over. If the art ever gains a hole, generation fails loudly instead of
|
||||
shipping a wrong logo.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
from dataclasses import dataclass
|
||||
|
||||
_NS = "{http://www.w3.org/2000/svg}"
|
||||
_TOKEN = re.compile(r"[A-Za-z]|-?(?:\d+(?:\.\d*)?|\.\d+)")
|
||||
_SEPARATORS = re.compile(r"[\s,]*")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Shape:
|
||||
"""One filled polygon: its colour and flat x, y, x, y, ... points."""
|
||||
|
||||
fill: str
|
||||
points: tuple[float, ...]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Logo:
|
||||
"""The logo as a square size, a field colour and polygons on top."""
|
||||
|
||||
size: int
|
||||
field: str
|
||||
shapes: tuple[Shape, ...]
|
||||
|
||||
|
||||
def _subpaths(d: str) -> list[list[float]]:
|
||||
"""Split path data into point lists, one per M ... Z subpath."""
|
||||
if _SEPARATORS.fullmatch(_TOKEN.sub(" ", d)) is None:
|
||||
msg = f"unparsed characters in path data: {_TOKEN.sub('', d)!r}"
|
||||
raise ValueError(msg)
|
||||
out: list[list[float]] = []
|
||||
current: list[float] = []
|
||||
for tok in _TOKEN.findall(d):
|
||||
if tok in {"M", "L"}:
|
||||
continue
|
||||
if tok == "Z":
|
||||
out.append(current)
|
||||
current = []
|
||||
elif tok[0].isalpha():
|
||||
msg = f"unsupported path command {tok!r}: only M, L and Z"
|
||||
raise ValueError(msg)
|
||||
else:
|
||||
current.append(float(tok))
|
||||
if current:
|
||||
msg = "path data ends without Z: an open subpath would be dropped"
|
||||
raise ValueError(msg)
|
||||
return out
|
||||
|
||||
|
||||
def _bbox(points: list[float]) -> tuple[float, float, float, float]:
|
||||
xs, ys = points[0::2], points[1::2]
|
||||
return min(xs), min(ys), max(xs), max(ys)
|
||||
|
||||
|
||||
def _check_disjoint(polys: list[list[float]]) -> None:
|
||||
boxes = [_bbox(p) for p in polys]
|
||||
for i, a in enumerate(boxes):
|
||||
for b in boxes[i + 1 :]:
|
||||
if a[0] < b[2] and b[0] < a[2] and a[1] < b[3] and b[1] < a[3]:
|
||||
msg = "logo subpaths overlap: a hole needs a real path renderer"
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
def parse_logo(text: str) -> Logo:
|
||||
"""Parse the SVG text into a :class:`Logo`."""
|
||||
root = ET.fromstring(text) # noqa: S314 - our own checked-in art
|
||||
if any("transform" in el.attrib for el in root.iter()):
|
||||
msg = "transform attributes are unsupported: bake them into the path data"
|
||||
raise ValueError(msg)
|
||||
size = int(float(root.attrib["viewBox"].split()[2]))
|
||||
field = next((r for r in root.iter(f"{_NS}rect") if r.get("id") == "field"), None)
|
||||
field = field if field is not None else root.find("rect[@id='field']")
|
||||
if field is None:
|
||||
msg = "logo has no rect id=field"
|
||||
raise ValueError(msg)
|
||||
shapes: list[Shape] = []
|
||||
polys: list[list[float]] = []
|
||||
for path in [*root.iter(f"{_NS}path"), *root.iter("path")]:
|
||||
for poly in _subpaths(path.attrib["d"]):
|
||||
shapes.append(Shape(path.attrib["fill"], tuple(poly)))
|
||||
polys.append(poly)
|
||||
_check_disjoint(polys)
|
||||
return Logo(size, field.attrib["fill"], tuple(shapes))
|
||||
@ -1,81 +0,0 @@
|
||||
"""Read the few design tokens the credit panel needs from tokens.css.
|
||||
|
||||
tokens.css is the web stack's copy of unified-design-system; palette_check
|
||||
already keeps it equal to the Dart and Tk copies, so reading this one file is
|
||||
reading the shared token set.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
_ROOT = re.compile(r"^:root\s*\{(.*?)^\}", re.DOTALL | re.MULTILINE)
|
||||
_LIGHT = re.compile(r"@media \(prefers-color-scheme: light\)\s*\{\s*:root\s*\{(.*?)\}", re.DOTALL)
|
||||
_VAR = re.compile(r"(--[a-z0-9-]+):\s*([^;]+);")
|
||||
_COMMENT = re.compile(r"/\*.*?\*/", re.DOTALL)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Palette:
|
||||
"""Page background and panel colours for one theme."""
|
||||
|
||||
bg: str
|
||||
surface: str
|
||||
border: str
|
||||
text: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Tokens:
|
||||
"""Both palettes plus the theme-free sizes, in px."""
|
||||
|
||||
dark: Palette
|
||||
light: Palette
|
||||
focus: str
|
||||
radius: int
|
||||
space_sm: int
|
||||
space_md: int
|
||||
text_body: int
|
||||
|
||||
|
||||
def _vars(block: str) -> dict[str, str]:
|
||||
return {k: v.strip() for k, v in _VAR.findall(block)}
|
||||
|
||||
|
||||
def _get(table: dict[str, str], name: str) -> str:
|
||||
if name not in table:
|
||||
msg = f"tokens.css has no {name}"
|
||||
raise ValueError(msg)
|
||||
return table[name]
|
||||
|
||||
|
||||
def _palette(table: dict[str, str]) -> Palette:
|
||||
return Palette(
|
||||
_get(table, "--bg"),
|
||||
_get(table, "--surface-1"),
|
||||
_get(table, "--border"),
|
||||
_get(table, "--text"),
|
||||
)
|
||||
|
||||
|
||||
def _px(table: dict[str, str], name: str) -> int:
|
||||
return int(_get(table, name).removesuffix("px"))
|
||||
|
||||
|
||||
def parse_tokens(css: str) -> Tokens:
|
||||
"""Parse the dark default and the light override out of tokens.css."""
|
||||
css = _COMMENT.sub("", css)
|
||||
root_match = _ROOT.search(css) or re.search(r":root\s*\{(.*?)\}", css, re.DOTALL)
|
||||
root = _vars(root_match.group(1)) if root_match else {}
|
||||
light_match = _LIGHT.search(css)
|
||||
light = {**root, **_vars(light_match.group(1) if light_match else "")}
|
||||
return Tokens(
|
||||
dark=_palette(root),
|
||||
light=_palette(light),
|
||||
focus=_get(root, "--focus-ring"),
|
||||
radius=_px(root, "--radius-md"),
|
||||
space_sm=_px(root, "--space-2"),
|
||||
space_md=_px(root, "--space-3"),
|
||||
text_body=_px(root, "--text-body"),
|
||||
)
|
||||
@ -1,4 +0,0 @@
|
||||
# gdlint: every check on, no rule disabled. The cap matches the shared 250-line gate.
|
||||
max-file-lines: 250
|
||||
max-line-length: 100
|
||||
disable: []
|
||||
3
kuhy_credit/godot/.gitignore
vendored
@ -1,3 +0,0 @@
|
||||
# fetched by test.sh at the pinned tag, never committed
|
||||
addons/gut/
|
||||
.godot/
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"dirs": ["res://tests/"],
|
||||
"include_subdirs": true,
|
||||
"prefix": "test_",
|
||||
"suffix": ".gd",
|
||||
"should_exit": true,
|
||||
"should_exit_on_success": true,
|
||||
"log_level": 1
|
||||
}
|
||||
@ -1,127 +0,0 @@
|
||||
## The shared credit data (generated by kuhy_credit/generator/generate.py; DO NOT EDIT).
|
||||
extends RefCounted
|
||||
|
||||
const URL := "https://kuhy.duckdns.org"
|
||||
const TEXT := "Created by kuhy"
|
||||
const LOGO_SIZE := 512
|
||||
const LOGO_SVG := (
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512'
|
||||
+ '" width="512" height="512">\n<rect id="field" width="512" hei'
|
||||
+ 'ght="512" fill="#211D1B"/>\n<path fill="#B8862E" fill-rule="e'
|
||||
+ 'venodd" d="M232.45 126.71L235.40 121.83L236.86 117.46L237.16'
|
||||
+ " 113.16L236.11 108.55L233.71 104.34L230.14 100.74L225.62 97."
|
||||
+ "95L220.41 96.16L214.75 95.51L208.86 96.11L202.89 97.96L196.9"
|
||||
+ "7 101.02L191.80 104.61L186.14 109.43L168.83 127.05L163.79 13"
|
||||
+ "1.69L158.86 135.08L156.85 135.91L155.00 136.26L153.32 136.10"
|
||||
+ "L151.51 135.26L150.17 134.03L148.74 131.95L146.53 126.68L142"
|
||||
+ ".68 113.58L140.39 107.28L137.47 101.80L134.17 98.03L131.62 9"
|
||||
+ "6.28L129.30 95.34L126.82 94.91L124.22 94.99L121.55 95.59L118"
|
||||
+ ".85 96.69L116.18 98.26L113.59 100.29L110.67 103.26L108.46 10"
|
||||
+ "6.12L104.82 112.71L103.46 116.33L102.26 120.85L101.33 129.40"
|
||||
+ "L101.51 134.83L102.18 140.16L107.16 161.56L107.92 166.59L108"
|
||||
+ ".16 170.93L107.96 175.30L107.23 180.39L103.30 196.89L102.03 "
|
||||
+ "203.60L101.44 209.71L101.57 215.83L102.56 221.84L104.46 227."
|
||||
+ "54L106.85 232.14L110.30 236.77L113.30 239.71L117.11 242.44L1"
|
||||
+ "20.52 244.13L124.51 245.27L128.36 245.46L131.44 244.86L134.2"
|
||||
+ "5 243.55L137.10 241.19L138.84 238.98L140.33 236.37L142.79 22"
|
||||
+ "9.46L144.26 222.20L146.91 203.45L149.00 195.46L150.82 191.74"
|
||||
+ "L152.78 189.39L155.06 187.98L157.64 187.54L160.46 188.07L163"
|
||||
+ ".46 189.54L166.57 191.89L170.18 195.54L176.49 203.82L187.93 "
|
||||
+ "221.96L192.91 229.15L198.18 235.26L203.30 239.57L207.07 241."
|
||||
+ "74L210.40 243.03L213.78 243.76L217.74 243.92L221.07 243.47L2"
|
||||
+ "24.80 242.29L228.25 240.44L230.89 238.38L233.17 235.92L235.0"
|
||||
+ "2 233.11L236.37 230.00L237.18 226.63L237.42 223.07L237.07 21"
|
||||
+ "9.35L236.13 215.54L234.60 211.66L230.90 205.16L225.43 198.15"
|
||||
+ "L219.02 191.41L205.04 178.08L200.57 173.11L197.35 167.98L196"
|
||||
+ ".49 165.31L196.29 163.13L196.57 160.98L197.54 158.44L199.16 "
|
||||
+ "155.90L201.39 153.37L206.78 148.63L224.45 135.06L228.82 130."
|
||||
+ "95ZM439.15 304.62L441.35 299.45L442.51 294.18L442.42 288.99L"
|
||||
+ "441.16 284.54L438.79 280.56L435.43 277.23L431.27 274.73L426."
|
||||
+ "09 273.10L421.13 272.75L416.70 273.37L412.03 275.08L407.76 2"
|
||||
+ "77.80L404.33 280.97L400.93 285.13L391.39 300.46L387.52 305.6"
|
||||
+ "1L384.97 308.13L382.62 309.84L379.82 311.14L377.32 311.67L37"
|
||||
+ "4.44 311.56L371.59 310.69L368.84 309.10L366.22 306.86L361.68"
|
||||
+ " 301.20L353.72 288.20L349.90 282.87L345.10 278.03L339.97 274"
|
||||
+ ".81L336.22 273.46L332.80 272.84L328.82 272.80L324.89 273.46L"
|
||||
+ "321.18 274.78L317.81 276.73L314.92 279.23L312.64 282.19L311."
|
||||
+ "36 284.65L310.49 287.28L310.02 290.04L309.96 292.87L310.28 2"
|
||||
+ "95.74L311.10 299.10L313.73 305.20L316.79 310.09L321.01 315.4"
|
||||
+ "7L337.30 332.65L344.34 340.99L350.25 349.71L354.13 357.71L35"
|
||||
+ "6.15 364.64L356.94 371.76L356.69 378.61L354.92 395.62L354.93"
|
||||
+ " 400.36L355.46 405.02L356.78 409.97L358.95 414.48L361.98 418"
|
||||
+ ".37L365.77 421.42L369.24 423.14L372.98 424.16L376.83 424.43L"
|
||||
+ "380.67 423.95L384.34 422.72L387.71 420.81L390.68 418.27L393."
|
||||
+ "42 414.79L394.87 412.17L396.16 408.88L397.04 405.40L397.53 4"
|
||||
+ "01.79L397.58 394.42L395.86 378.48L395.63 371.63L396.54 364.0"
|
||||
+ "5L398.85 356.69L402.90 348.74L408.61 340.49L415.36 332.56L43"
|
||||
+ '1.64 315.37L435.86 309.98Z"/>\n<path fill="#ECEAE9" fill-rule'
|
||||
+ '="evenodd" d="M272.87 180.50L273.78 191.15L275.43 199.68L277'
|
||||
+ ".93 207.24L281.46 214.32L286.01 220.83L291.97 227.15L298.81 "
|
||||
+ "232.68L306.29 237.38L314.83 241.44L323.65 244.37L331.97 245."
|
||||
+ "96L340.33 246.39L348.69 245.62L356.98 243.70L365.74 240.46L3"
|
||||
+ "74.17 236.11L379.85 232.38L385.15 228.16L389.95 223.48L393.7"
|
||||
+ "6 218.86L397.03 213.89L399.73 208.60L401.84 203.03L403.53 19"
|
||||
+ "6.59L404.61 189.99L405.30 181.99L405.89 159.12L407.09 137.35"
|
||||
+ "L407.21 129.01L406.69 121.27L405.60 115.09L403.79 109.27L401"
|
||||
+ ".53 104.61L398.24 100.21L394.25 96.96L389.72 95.06L385.41 94"
|
||||
+ ".63L381.04 95.41L376.28 97.71L371.95 101.35L368.30 106.12L36"
|
||||
+ "6.03 110.43L364.13 115.78L363.07 120.69L362.53 126.40L362.58"
|
||||
+ " 131.38L363.12 136.95L366.62 155.29L367.54 162.94L367.32 171"
|
||||
+ ".38L366.55 176.01L365.50 179.98L363.26 185.87L360.61 190.86L"
|
||||
+ "357.41 195.43L353.74 199.38L349.69 202.52L345.92 204.46L342."
|
||||
+ "02 205.56L338.06 205.77L334.12 205.08L330.28 203.52L326.61 2"
|
||||
+ "01.16L322.73 197.62L319.27 193.35L316.32 188.55L313.95 183.4"
|
||||
+ "3L312.21 178.16L310.80 170.23L310.73 162.45L311.59 155.45L31"
|
||||
+ "5.00 137.80L315.74 128.01L315.47 123.01L314.68 118.04L313.31"
|
||||
+ " 113.22L311.38 108.68L308.91 104.56L305.95 101.00L302.59 98."
|
||||
+ "14L298.95 96.07L295.15 94.89L291.33 94.64L287.61 95.31L284.1"
|
||||
+ "1 96.89L281.80 98.52L279.70 100.54L277.81 102.91L275.86 106."
|
||||
+ "15L273.20 112.94L271.66 120.41L271.11 126.72L271.03 133.73L2"
|
||||
+ "72.32 158.32ZM142.50 408.93L144.93 412.86L148.33 416.82L151."
|
||||
+ "62 419.58L155.73 421.94L159.96 423.33L164.11 423.69L168.00 4"
|
||||
+ "23.04L171.46 421.41L173.61 419.69L175.81 417.09L177.30 414.5"
|
||||
+ "3L178.71 411.07L180.34 403.92L181.90 389.45L182.76 384.30L18"
|
||||
+ "4.38 379.06L186.60 375.03L188.42 372.84L190.56 370.93L193.02"
|
||||
+ " 369.30L196.36 367.72L203.33 365.93L207.41 365.55L211.54 365"
|
||||
+ ".59L218.20 366.61L224.14 368.79L226.71 370.32L228.97 372.13L"
|
||||
+ "232.20 376.09L234.21 380.29L235.51 385.06L237.68 403.40L239."
|
||||
+ "06 409.98L241.43 415.72L243.06 418.13L244.99 420.16L247.70 4"
|
||||
+ "22.03L250.76 423.22L254.12 423.70L257.08 423.52L260.70 422.6"
|
||||
+ "1L263.71 421.29L267.19 419.06L269.90 416.70L273.71 412.09L27"
|
||||
+ "6.70 406.63L278.73 400.57L279.77 394.13L279.87 387.57L279.19"
|
||||
+ " 381.08L277.76 374.06L273.42 357.39L272.70 353.01L272.43 348"
|
||||
+ ".73L272.65 344.45L273.45 339.45L277.62 323.51L278.95 317.31L"
|
||||
+ "279.71 311.68L279.93 306.77L279.20 298.62L277.23 291.66L274."
|
||||
+ "04 285.39L269.78 280.17L267.06 277.83L263.57 275.63L260.56 2"
|
||||
+ "74.33L256.94 273.46L253.99 273.30L250.64 273.80L248.07 274.7"
|
||||
+ "7L245.32 276.56L243.34 278.53L241.66 280.88L239.20 286.54L23"
|
||||
+ "7.66 293.75L235.48 312.08L233.95 317.39L231.82 321.50L230.08"
|
||||
+ " 323.74L228.00 325.70L225.60 327.39L222.90 328.79L216.76 330"
|
||||
+ ".71L209.32 331.48L201.85 330.81L198.02 329.85L195.07 328.73L"
|
||||
+ "192.39 327.32L190.00 325.62L187.94 323.64L186.21 321.39L184."
|
||||
+ "11 317.26L182.60 311.93L180.42 293.59L179.04 287.01L177.76 2"
|
||||
+ "83.44L176.37 280.76L174.68 278.43L172.69 276.48L169.92 274.7"
|
||||
+ "2L167.34 273.77L163.98 273.30L161.03 273.48L157.40 274.38L15"
|
||||
+ "4.40 275.70L150.92 277.93L148.21 280.29L143.97 285.54L141.10"
|
||||
+ " 291.09L139.19 297.22L138.23 304.49L138.34 311.05L139.18 317"
|
||||
+ ".50L144.55 338.96L145.64 347.04L145.57 351.31L144.91 356.27L"
|
||||
+ "139.77 376.54L138.77 382.07L138.23 387.76L138.29 393.51L139."
|
||||
+ '06 399.17L140.59 404.59Z"/>\n</svg>\n'
|
||||
)
|
||||
const DARK := {
|
||||
"bg": Color("#211d1b"),
|
||||
"surface": Color("#2b2624"),
|
||||
"border": Color("#463e3a"),
|
||||
"text": Color("#eceae9"),
|
||||
}
|
||||
const LIGHT := {
|
||||
"bg": Color("#f6f4f3"),
|
||||
"surface": Color("#fcfbfb"),
|
||||
"border": Color("#e0dad7"),
|
||||
"text": Color("#211d1b"),
|
||||
}
|
||||
const FOCUS := Color("#b8862e")
|
||||
const RADIUS := 12
|
||||
const SPACE_SM := 8
|
||||
const SPACE_MD := 16
|
||||
const TEXT_BODY := 16
|
||||
@ -1 +0,0 @@
|
||||
uid://u31d1bclwg4t
|
||||
@ -1,153 +0,0 @@
|
||||
extends Control
|
||||
## The shared kuhy credit: an M1 logo button that opens a panel.
|
||||
##
|
||||
## A click or Enter on the logo opens a panel (logo + credit text); a
|
||||
## click or Enter on the panel opens the website through [member opener]
|
||||
## (default OS.shell_open) and closes it. Escape, a click anywhere else and a
|
||||
## second logo click close it. The logo is rasterised at runtime from the
|
||||
## inlined M1 SVG, so the addon needs no import step and loads nothing.
|
||||
|
||||
const CreditData = preload("credit_data.gd")
|
||||
|
||||
@export var logo_size := 48:
|
||||
set = _set_logo_size
|
||||
@export var placement_below := false
|
||||
@export var align_start := false
|
||||
@export var light := false:
|
||||
set = _set_light
|
||||
|
||||
## Called with the URL when the panel is activated.
|
||||
var opener: Callable
|
||||
var logo: TextureButton
|
||||
var panel: PanelContainer
|
||||
var panel_logo: TextureRect
|
||||
var label: Label
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
opener = _shell_open
|
||||
logo = TextureButton.new()
|
||||
logo.ignore_texture_size = true
|
||||
logo.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT_CENTERED
|
||||
logo.focus_mode = Control.FOCUS_ALL
|
||||
logo.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
logo.accessibility_name = CreditData.TEXT
|
||||
logo.pressed.connect(_toggle)
|
||||
add_child(logo)
|
||||
panel = PanelContainer.new()
|
||||
panel.visible = false
|
||||
panel.focus_mode = Control.FOCUS_ALL
|
||||
panel.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
panel.accessibility_name = CreditData.TEXT
|
||||
panel.gui_input.connect(_on_panel_input)
|
||||
var row := HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", CreditData.SPACE_SM)
|
||||
row.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
panel_logo = TextureRect.new()
|
||||
panel_logo.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
label = Label.new()
|
||||
label.text = CreditData.TEXT
|
||||
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
row.add_child(panel_logo)
|
||||
row.add_child(label)
|
||||
panel.add_child(row)
|
||||
add_child(panel)
|
||||
_set_logo_size(logo_size)
|
||||
_apply_theme()
|
||||
|
||||
|
||||
## True while the panel shows.
|
||||
func is_open() -> bool:
|
||||
return panel.visible
|
||||
|
||||
|
||||
## Hide the panel.
|
||||
func close() -> void:
|
||||
panel.visible = false
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not panel.visible:
|
||||
return
|
||||
if event is InputEventKey and event.pressed and event.keycode == KEY_ESCAPE:
|
||||
close()
|
||||
logo.grab_focus()
|
||||
get_viewport().set_input_as_handled()
|
||||
elif event is InputEventMouseButton and event.pressed:
|
||||
var at: Vector2 = event.position
|
||||
if not panel.get_global_rect().has_point(at) and not logo.get_global_rect().has_point(at):
|
||||
close()
|
||||
|
||||
|
||||
func _toggle() -> void:
|
||||
if panel.visible:
|
||||
close()
|
||||
return
|
||||
panel.reset_size()
|
||||
var box := panel.get_combined_minimum_size()
|
||||
var x := 0.0 if align_start else logo_size - box.x
|
||||
var y := logo_size + CreditData.SPACE_SM if placement_below else -box.y - CreditData.SPACE_SM
|
||||
panel.position = Vector2(x, y)
|
||||
panel.visible = true
|
||||
panel.grab_focus()
|
||||
|
||||
|
||||
func _on_panel_input(event: InputEvent) -> void:
|
||||
var clicked: bool = (
|
||||
event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT
|
||||
)
|
||||
if clicked or event.is_action_pressed("ui_accept"):
|
||||
accept_event()
|
||||
close()
|
||||
opener.call(CreditData.URL)
|
||||
|
||||
|
||||
## Scene/inspector values arrive after _init, so the size rebuilds here.
|
||||
func _set_logo_size(value: int) -> void:
|
||||
logo_size = value
|
||||
close()
|
||||
var texture := _logo_texture(value)
|
||||
var edge := Vector2(value, value)
|
||||
logo.texture_normal = texture
|
||||
logo.custom_minimum_size = edge
|
||||
logo.size = edge
|
||||
panel_logo.texture = texture
|
||||
custom_minimum_size = edge
|
||||
size = edge
|
||||
|
||||
|
||||
func _set_light(value: bool) -> void:
|
||||
light = value
|
||||
_apply_theme()
|
||||
|
||||
|
||||
func _apply_theme() -> void:
|
||||
var pal: Dictionary = CreditData.LIGHT if light else CreditData.DARK
|
||||
var box := StyleBoxFlat.new()
|
||||
box.bg_color = pal["surface"]
|
||||
box.border_color = pal["border"]
|
||||
box.set_border_width_all(1)
|
||||
box.set_corner_radius_all(CreditData.RADIUS)
|
||||
box.set_content_margin_all(CreditData.SPACE_MD)
|
||||
panel.add_theme_stylebox_override("panel", box)
|
||||
var ring := StyleBoxFlat.new()
|
||||
ring.draw_center = false
|
||||
ring.border_color = CreditData.FOCUS
|
||||
ring.set_border_width_all(2)
|
||||
ring.set_corner_radius_all(CreditData.RADIUS)
|
||||
ring.set_expand_margin_all(2)
|
||||
logo.add_theme_stylebox_override("focus", ring)
|
||||
panel.add_theme_stylebox_override("focus", ring)
|
||||
label.add_theme_color_override("font_color", pal["text"])
|
||||
label.add_theme_font_size_override("font_size", CreditData.TEXT_BODY)
|
||||
|
||||
|
||||
func _shell_open(url: String) -> void:
|
||||
OS.shell_open(url)
|
||||
|
||||
|
||||
static func _logo_texture(px: int) -> ImageTexture:
|
||||
var img := Image.new()
|
||||
img.load_svg_from_string(CreditData.LOGO_SVG, float(px) / CreditData.LOGO_SIZE)
|
||||
return ImageTexture.create_from_image(img)
|
||||
@ -1 +0,0 @@
|
||||
uid://oi22ee8n1yy3
|
||||
@ -1,6 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/kuhy_credit/kuhy_credit.gd" id="1"]
|
||||
|
||||
[node name="KuhyCredit" type="Control"]
|
||||
script = ExtResource("1")
|
||||
@ -1,27 +0,0 @@
|
||||
extends Control
|
||||
## Demo: a token-coloured screen with the credit in the bottom-right corner.
|
||||
## Run with `godot --path kuhy_credit/godot` (add `-- --light` for light).
|
||||
|
||||
const CreditData = preload("res://addons/kuhy_credit/credit_data.gd")
|
||||
const CreditScene = preload("res://addons/kuhy_credit/kuhy_credit.tscn")
|
||||
|
||||
var credit: Control
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var is_light := OS.get_cmdline_user_args().has("--light")
|
||||
var bg := ColorRect.new()
|
||||
bg.color = (CreditData.LIGHT if is_light else CreditData.DARK)["bg"]
|
||||
bg.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
add_child(bg)
|
||||
credit = CreditScene.instantiate()
|
||||
credit.light = is_light
|
||||
add_child(credit)
|
||||
_place()
|
||||
resized.connect(_place)
|
||||
|
||||
|
||||
func _place() -> void:
|
||||
var margin := float(CreditData.SPACE_MD)
|
||||
credit.position = size - credit.size - Vector2(margin, margin)
|
||||
@ -1 +0,0 @@
|
||||
uid://yyyduq0pwbr1
|
||||
@ -1,10 +0,0 @@
|
||||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://demo/demo.gd" id="1"]
|
||||
|
||||
[node name="Demo" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource("1")
|
||||
@ -1,33 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# Lint of the kuhy_credit addon, demo and tests: gdlint (.gdlintrc, every check on)
|
||||
# and gdformat --check. gdtoolkit is pinned in godot_dev_tools/requirements-dev.txt.
|
||||
# ============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
readonly HERE
|
||||
|
||||
main() {
|
||||
local tool files=()
|
||||
for tool in gdlint gdformat; do
|
||||
command -v "$tool" >/dev/null || {
|
||||
echo "Error: $tool not found (pip install -r godot_dev_tools/requirements-dev.txt)" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
mapfile -t files < <(find "$HERE/addons/kuhy_credit" "$HERE/demo" "$HERE/tests" -name '*.gd' -type f | sort)
|
||||
# One process per tool, not xargs -P: parallel gdtoolkit processes race to
|
||||
# create their grammar cache dir (os.makedirs EEXIST) on a cold cache and
|
||||
# report a file as unopenable.
|
||||
(cd "$HERE" && gdlint "${files[@]}" >/dev/null)
|
||||
gdformat --check "${files[@]}" >/dev/null 2>&1 || {
|
||||
gdformat --check "${files[@]}" 2>&1 | grep -v 'left unchanged' >&2 || true
|
||||
exit 1
|
||||
}
|
||||
echo "kuhy_credit godot lint: ${#files[@]} files ok"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@ -1,20 +0,0 @@
|
||||
; Stub host for the kuhy_credit addon: GUT loads it headless, and
|
||||
; demo/demo.tscn is the click-through demo. Games mount the addon folder.
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="kuhy_credit_test_host"
|
||||
config/features=PackedStringArray("4.7", "GL Compatibility")
|
||||
run/main_scene="res://demo/demo.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=640
|
||||
window/size/viewport_height=360
|
||||
|
||||
[rendering]
|
||||
|
||||
renderer/rendering_method="gl_compatibility"
|
||||
renderer/rendering_method.mobile="gl_compatibility"
|
||||
@ -1,116 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# GUT tests of the kuhy_credit addon against the stub host project in this
|
||||
# folder, headless and muted, one run under 60 s.
|
||||
# kuhy_credit/godot/test.sh the whole suite
|
||||
# kuhy_credit/godot/test.sh -gselect=test_kuhy_credit one file
|
||||
# GUT is fetched at the pinned tag into addons/gut (gitignored): no third-party
|
||||
# code is committed. user:// points at a throwaway folder,
|
||||
# so no test ever writes where a real game saves.
|
||||
# Fail closed: green only with exit 0, no SCRIPT ERROR, no failing test, at
|
||||
# least one test and tests == passing + pending. Prints one summary line.
|
||||
# ============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
readonly GUT_TAG="v9.7.1"
|
||||
# Wall-clock cap per godot call, only when set (CI sets 50). Locally godot is a
|
||||
# build-lock shim, and a cap around it would count the queue wait, not the run.
|
||||
readonly RUN_TIMEOUT="${KUHY_CREDIT_GODOT_TIMEOUT:-}"
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
readonly HERE
|
||||
TMP=""
|
||||
|
||||
cleanup() {
|
||||
[[ -z "$TMP" ]] || rm -rf "$TMP"
|
||||
}
|
||||
|
||||
# Fetches GUT at GUT_TAG into addons/gut unless that version is already there.
|
||||
ensure_gut() {
|
||||
local gut_dir="$HERE/addons/gut" tmp
|
||||
if [[ -f "$gut_dir/plugin.cfg" ]] && grep -q "\"${GUT_TAG#v}\"" "$gut_dir/plugin.cfg"; then
|
||||
return
|
||||
fi
|
||||
tmp="$(mktemp -d)"
|
||||
git -c advice.detachedHead=false clone -q --depth 1 --branch "$GUT_TAG" \
|
||||
https://github.com/bitwes/Gut "$tmp/gut"
|
||||
rm -rf "$gut_dir"
|
||||
mv "$tmp/gut/addons/gut" "$gut_dir"
|
||||
rm -rf "$tmp"
|
||||
}
|
||||
|
||||
# Value of a GUT totals row ("Tests 59", "Passing Tests 59"...), 0 when absent.
|
||||
total_of() {
|
||||
local row="$1" out="$2"
|
||||
awk -v row="$row" 'index($0, row) == 1 { v = $NF } END { print v + 0 }' <<<"$out"
|
||||
}
|
||||
|
||||
# Runs godot under the resource cap kuhy's machine has, else plainly.
|
||||
run_capped() {
|
||||
local capped="$HOME/.claude/scripts/capped.sh"
|
||||
if [[ -x "$capped" ]]; then
|
||||
"$capped" "$@"
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Runs godot "$@" capped, and under RUN_TIMEOUT when one is set.
|
||||
godot_run() {
|
||||
local cmd=(godot "$@")
|
||||
if [[ -n "$RUN_TIMEOUT" ]]; then
|
||||
cmd=(timeout -k 3 "$RUN_TIMEOUT" "${cmd[@]}")
|
||||
fi
|
||||
run_capped "${cmd[@]}"
|
||||
}
|
||||
|
||||
main() {
|
||||
command -v godot >/dev/null || {
|
||||
echo "Error: godot 4.7.2 not on PATH" >&2
|
||||
exit 1
|
||||
}
|
||||
ensure_gut
|
||||
TMP="$(mktemp -d)"
|
||||
trap cleanup EXIT
|
||||
export XDG_DATA_HOME="$TMP/xdg"
|
||||
# GUT's own class_names need a class cache before a script run.
|
||||
# Output goes to files, not $(...): the godot build-lock shim may hold a
|
||||
# child that keeps a command-substitution pipe open (a deadlock).
|
||||
godot_run --headless --path "$HERE" --import >"$TMP/import.log" 2>&1 || true
|
||||
local imported out code=0 start="$SECONDS"
|
||||
imported="$(<"$TMP/import.log")"
|
||||
godot_run --headless --audio-driver Dummy \
|
||||
--path "$HERE" -s addons/gut/gut_cmdln.gd -gexit "$@" >"$TMP/gut.log" 2>&1 || code=$?
|
||||
out="$(<"$TMP/gut.log")"
|
||||
local tests passing failing pending why="" declared
|
||||
# Every test_* function must run: a script that fails to parse is dropped
|
||||
# by GUT without a failure, so count what the files declare.
|
||||
declared="$(cat "$HERE"/tests/test_*.gd | grep -c '^func test_')"
|
||||
tests="$(total_of Tests "$out")"
|
||||
passing="$(total_of "Passing Tests" "$out")"
|
||||
failing="$(total_of "Failing Tests" "$out")"
|
||||
pending="$(total_of "Risky/Pending" "$out")"
|
||||
if [[ "$code" -eq 124 || "$code" -eq 137 || "$code" -eq 143 ]]; then
|
||||
why="timed out or killed after ${RUN_TIMEOUT}s (exit $code)"
|
||||
elif grep -qE 'SCRIPT ERROR|Failing Tests' <<<"$out$imported" || ((failing > 0)); then
|
||||
why="failing tests or a script error"
|
||||
elif ((code != 0)); then
|
||||
why="exit code $code"
|
||||
elif ((tests == 0)); then
|
||||
why="no tests ran"
|
||||
elif (($# == 0 && tests != declared)); then
|
||||
why="ran $tests tests but tests/ declares $declared (a script failed to load?)"
|
||||
elif ((tests != passing + pending)); then
|
||||
why="tests $tests != passing $passing + pending $pending"
|
||||
fi
|
||||
local line="$tests tests, $passing pass, $failing fail, $pending pending, $((SECONDS - start))s"
|
||||
if [[ -n "$why" ]]; then
|
||||
echo "$out" | tail -60 >&2
|
||||
echo "kuhy_credit godot: FAILED ($why; $line)" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "kuhy_credit godot: green ($line)"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@ -1,25 +0,0 @@
|
||||
extends GutTest
|
||||
## Base for tests that click. GUT's own full-window GUI sits on a CanvasLayer
|
||||
## above the scene and swallows pushed mouse events, so it is hidden while
|
||||
## these tests run. The headless window of the official Godot build is 64x64,
|
||||
## and a click outside the window is dropped, so the window takes the
|
||||
## project's 640x360 size for these tests.
|
||||
|
||||
const TEST_WINDOW := Vector2i(640, 360)
|
||||
|
||||
var _gut_layers: Array[Node] = []
|
||||
var _old_size: Vector2i
|
||||
|
||||
|
||||
func before_all() -> void:
|
||||
_old_size = get_window().size
|
||||
get_window().size = TEST_WINDOW
|
||||
_gut_layers = get_tree().root.find_children("GutLayer", "CanvasLayer", true, false)
|
||||
for layer in _gut_layers:
|
||||
layer.visible = false
|
||||
|
||||
|
||||
func after_all() -> void:
|
||||
for layer in _gut_layers:
|
||||
layer.visible = true
|
||||
get_window().size = _old_size
|
||||
@ -1 +0,0 @@
|
||||
uid://dj5wof521mjvp
|
||||
@ -1,26 +0,0 @@
|
||||
extends SceneTree
|
||||
## Screenshot helper (not a test): renders the demo closed and open, saves PNGs.
|
||||
## godot --path kuhy_credit/godot --rendering-driver opengl3 \
|
||||
## -s res://tests/shot.gd -- <out_dir> [--light]
|
||||
|
||||
const Demo = preload("res://demo/demo.tscn")
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
_run.call_deferred()
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
var args := OS.get_cmdline_user_args()
|
||||
var out: String = args[0]
|
||||
var theme := "light" if args.has("--light") else "dark"
|
||||
var demo: Control = Demo.instantiate()
|
||||
root.add_child(demo)
|
||||
for state in ["closed", "open"]:
|
||||
if state == "open":
|
||||
demo.credit.logo.pressed.emit()
|
||||
for _i in 5:
|
||||
await process_frame
|
||||
var img := root.get_texture().get_image()
|
||||
img.save_png(out.path_join("godot-%s-%s.png" % [theme, state]))
|
||||
quit()
|
||||
@ -1 +0,0 @@
|
||||
uid://c1xqry5othtbb
|
||||
@ -1,31 +0,0 @@
|
||||
extends "res://tests/click_test.gd"
|
||||
## E2E: the demo scene, two clicks through the viewport, the URL that would open.
|
||||
|
||||
const CreditData = preload("res://addons/kuhy_credit/credit_data.gd")
|
||||
const Demo = preload("res://demo/demo.tscn")
|
||||
|
||||
|
||||
func _click(at: Vector2) -> void:
|
||||
for pressed in [true, false]:
|
||||
var ev := InputEventMouseButton.new()
|
||||
ev.button_index = MOUSE_BUTTON_LEFT
|
||||
ev.pressed = pressed
|
||||
ev.position = at
|
||||
ev.global_position = at
|
||||
get_viewport().push_input(ev, true)
|
||||
await wait_process_frames(2)
|
||||
|
||||
|
||||
func test_two_clicks_open_the_website() -> void:
|
||||
var demo: Control = Demo.instantiate()
|
||||
add_child_autofree(demo)
|
||||
await wait_process_frames(2)
|
||||
var opened: Array[String] = []
|
||||
demo.credit.opener = func(url: String) -> void: opened.append(url)
|
||||
assert_false(demo.credit.is_open())
|
||||
await _click(demo.credit.logo.get_global_rect().get_center())
|
||||
assert_true(demo.credit.is_open())
|
||||
assert_eq(opened, [] as Array[String])
|
||||
await _click(demo.credit.panel.get_global_rect().get_center())
|
||||
assert_eq(opened, [CreditData.URL] as Array[String])
|
||||
assert_false(demo.credit.is_open())
|
||||
@ -1 +0,0 @@
|
||||
uid://do527xwgc25r5
|
||||
@ -1,166 +0,0 @@
|
||||
extends "res://tests/click_test.gd"
|
||||
## The credit control: logo -> panel -> URL, every close path, theme tokens.
|
||||
## Input goes through the viewport (push_input), as a real click would.
|
||||
|
||||
const CreditData = preload("res://addons/kuhy_credit/credit_data.gd")
|
||||
const Scene = preload("res://addons/kuhy_credit/kuhy_credit.tscn")
|
||||
|
||||
var credit: Control
|
||||
var opened: Array[String] = []
|
||||
|
||||
|
||||
func before_each() -> void:
|
||||
opened.clear()
|
||||
credit = Scene.instantiate()
|
||||
credit.opener = func(url: String) -> void: opened.append(url)
|
||||
credit.position = Vector2(500, 260)
|
||||
add_child_autofree(credit)
|
||||
await wait_process_frames(2)
|
||||
|
||||
|
||||
func _click_at(pos: Vector2) -> void:
|
||||
for pressed in [true, false]:
|
||||
var ev := InputEventMouseButton.new()
|
||||
ev.button_index = MOUSE_BUTTON_LEFT
|
||||
ev.pressed = pressed
|
||||
ev.position = pos
|
||||
ev.global_position = pos
|
||||
get_viewport().push_input(ev, true)
|
||||
await wait_process_frames(2)
|
||||
|
||||
|
||||
func _click(control: Control) -> void:
|
||||
await _click_at(control.get_global_rect().get_center())
|
||||
|
||||
|
||||
func _key(code: Key) -> void:
|
||||
for pressed in [true, false]:
|
||||
var ev := InputEventKey.new()
|
||||
ev.keycode = code
|
||||
ev.physical_keycode = code
|
||||
ev.pressed = pressed
|
||||
get_viewport().push_input(ev)
|
||||
await wait_process_frames(2)
|
||||
|
||||
|
||||
func test_shows_only_the_logo_at_start() -> void:
|
||||
assert_true(credit.logo.visible)
|
||||
assert_false(credit.panel.visible)
|
||||
assert_not_null(credit.logo.texture_normal)
|
||||
assert_eq(credit.logo.accessibility_name, CreditData.TEXT)
|
||||
assert_eq(opened, [] as Array[String])
|
||||
|
||||
|
||||
func test_logo_click_opens_panel_with_logo_and_text() -> void:
|
||||
await _click(credit.logo)
|
||||
assert_true(credit.is_open())
|
||||
assert_eq(credit.label.text, CreditData.TEXT)
|
||||
assert_not_null(credit.panel_logo.texture)
|
||||
assert_eq(opened, [] as Array[String])
|
||||
|
||||
|
||||
func test_panel_click_opens_the_url_and_closes() -> void:
|
||||
await _click(credit.logo)
|
||||
await _click(credit.label)
|
||||
assert_eq(opened, [CreditData.URL] as Array[String])
|
||||
assert_false(credit.is_open())
|
||||
|
||||
|
||||
func test_escape_closes_without_opening() -> void:
|
||||
await _click(credit.logo)
|
||||
await _key(KEY_ESCAPE)
|
||||
assert_false(credit.is_open())
|
||||
assert_true(credit.logo.has_focus())
|
||||
assert_eq(opened, [] as Array[String])
|
||||
|
||||
|
||||
func test_outside_click_closes() -> void:
|
||||
await _click(credit.logo)
|
||||
await _click_at(Vector2(10, 10))
|
||||
assert_false(credit.is_open())
|
||||
assert_eq(opened, [] as Array[String])
|
||||
|
||||
|
||||
func test_second_logo_click_closes_and_stays_closed() -> void:
|
||||
await _click(credit.logo)
|
||||
await _click(credit.logo)
|
||||
assert_false(credit.is_open())
|
||||
assert_eq(opened, [] as Array[String])
|
||||
|
||||
|
||||
func test_keyboard_reaches_and_opens() -> void:
|
||||
assert_eq(credit.logo.focus_mode, Control.FOCUS_ALL)
|
||||
credit.logo.grab_focus()
|
||||
await _key(KEY_ENTER)
|
||||
assert_true(credit.is_open())
|
||||
assert_true(credit.panel.has_focus())
|
||||
await _key(KEY_ENTER)
|
||||
assert_eq(opened, [CreditData.URL] as Array[String])
|
||||
|
||||
|
||||
func test_other_input_is_ignored() -> void:
|
||||
await _key(KEY_ESCAPE)
|
||||
await _click_at(Vector2(10, 10))
|
||||
assert_false(credit.is_open())
|
||||
await _click(credit.logo)
|
||||
await _key(KEY_A)
|
||||
assert_true(credit.is_open())
|
||||
|
||||
|
||||
func test_panel_sits_above_and_end_aligned_by_default() -> void:
|
||||
await _click(credit.logo)
|
||||
var p: Rect2 = credit.panel.get_global_rect()
|
||||
var l: Rect2 = credit.logo.get_global_rect()
|
||||
assert_lt(p.end.y, l.position.y)
|
||||
assert_almost_eq(p.end.x, l.end.x, 0.5)
|
||||
|
||||
|
||||
func test_below_and_start_placement() -> void:
|
||||
credit.placement_below = true
|
||||
credit.align_start = true
|
||||
await _click(credit.logo)
|
||||
var p: Rect2 = credit.panel.get_global_rect()
|
||||
var l: Rect2 = credit.logo.get_global_rect()
|
||||
assert_gt(p.position.y, l.end.y)
|
||||
assert_almost_eq(p.position.x, l.position.x, 0.5)
|
||||
|
||||
|
||||
func test_logo_size_set_after_init_resizes_and_anchors() -> void:
|
||||
credit.logo_size = 96
|
||||
assert_eq(credit.logo.size, Vector2(96, 96))
|
||||
assert_eq(credit.size, Vector2(96, 96))
|
||||
assert_eq(credit.logo.texture_normal.get_width(), 96)
|
||||
await _click(credit.logo)
|
||||
var p: Rect2 = credit.panel.get_global_rect()
|
||||
assert_almost_eq(p.end.x, credit.logo.get_global_rect().end.x, 0.5)
|
||||
|
||||
|
||||
func test_scene_values_apply_on_instantiate() -> void:
|
||||
var packed := PackedScene.new()
|
||||
var node: Control = Scene.instantiate()
|
||||
node.logo_size = 64
|
||||
node.placement_below = true
|
||||
packed.pack(node)
|
||||
node.free()
|
||||
var fresh: Control = packed.instantiate()
|
||||
add_child_autofree(fresh)
|
||||
assert_eq(fresh.logo.size, Vector2(64, 64))
|
||||
assert_true(fresh.placement_below)
|
||||
|
||||
|
||||
func test_theme_colours_come_from_tokens() -> void:
|
||||
var box: StyleBoxFlat = credit.panel.get_theme_stylebox("panel")
|
||||
assert_eq(box.bg_color, CreditData.DARK.surface)
|
||||
assert_eq(box.border_color, CreditData.DARK.border)
|
||||
assert_eq(box.corner_radius_top_left, CreditData.RADIUS)
|
||||
credit.light = true
|
||||
box = credit.panel.get_theme_stylebox("panel")
|
||||
assert_eq(box.bg_color, CreditData.LIGHT.surface)
|
||||
assert_eq(credit.label.get_theme_color("font_color"), CreditData.LIGHT.text)
|
||||
|
||||
|
||||
func test_default_opener_is_shell_open() -> void:
|
||||
var fresh: Control = Scene.instantiate()
|
||||
assert_true(fresh.opener.is_valid())
|
||||
assert_eq(fresh.opener.get_method(), &"_shell_open")
|
||||
fresh.free()
|
||||
@ -1 +0,0 @@
|
||||
uid://l314u8vgev8d
|
||||
@ -1,16 +0,0 @@
|
||||
"""The shared kuhy credit for Python programs.
|
||||
|
||||
``credit_line()`` is the terminal form; :mod:`kuhy_credit.tk` holds the
|
||||
Tkinter logo widget. The words and the link come from the generated
|
||||
``_data`` module, which comes from ``credit.json``.
|
||||
"""
|
||||
|
||||
from kuhy_credit._data import TEXT, URL
|
||||
|
||||
|
||||
def credit_line() -> str:
|
||||
"""The one-line credit for terminal programs: the text, then the URL."""
|
||||
return f"{TEXT} {URL}"
|
||||
|
||||
|
||||
__all__ = ["TEXT", "URL", "credit_line"]
|
||||
@ -1,141 +0,0 @@
|
||||
"""The shared credit data (generated by kuhy_credit/generator/generate.py; DO NOT EDIT)."""
|
||||
|
||||
URL = "https://kuhy.duckdns.org"
|
||||
TEXT = "Created by kuhy"
|
||||
LOGO_SIZE = 512
|
||||
LOGO_FIELD = "#211D1B"
|
||||
LOGO_SHAPES: tuple[tuple[str, tuple[float, ...]], ...] = (
|
||||
(
|
||||
"#B8862E",
|
||||
(
|
||||
232.45, 126.71, 235.4, 121.83, 236.86, 117.46, 237.16, 113.16,
|
||||
236.11, 108.55, 233.71, 104.34, 230.14, 100.74, 225.62, 97.95,
|
||||
220.41, 96.16, 214.75, 95.51, 208.86, 96.11, 202.89, 97.96,
|
||||
196.97, 101.02, 191.8, 104.61, 186.14, 109.43, 168.83, 127.05,
|
||||
163.79, 131.69, 158.86, 135.08, 156.85, 135.91, 155.0, 136.26,
|
||||
153.32, 136.1, 151.51, 135.26, 150.17, 134.03, 148.74, 131.95,
|
||||
146.53, 126.68, 142.68, 113.58, 140.39, 107.28, 137.47, 101.8,
|
||||
134.17, 98.03, 131.62, 96.28, 129.3, 95.34, 126.82, 94.91,
|
||||
124.22, 94.99, 121.55, 95.59, 118.85, 96.69, 116.18, 98.26,
|
||||
113.59, 100.29, 110.67, 103.26, 108.46, 106.12, 104.82, 112.71,
|
||||
103.46, 116.33, 102.26, 120.85, 101.33, 129.4, 101.51, 134.83,
|
||||
102.18, 140.16, 107.16, 161.56, 107.92, 166.59, 108.16, 170.93,
|
||||
107.96, 175.3, 107.23, 180.39, 103.3, 196.89, 102.03, 203.6,
|
||||
101.44, 209.71, 101.57, 215.83, 102.56, 221.84, 104.46, 227.54,
|
||||
106.85, 232.14, 110.3, 236.77, 113.3, 239.71, 117.11, 242.44,
|
||||
120.52, 244.13, 124.51, 245.27, 128.36, 245.46, 131.44, 244.86,
|
||||
134.25, 243.55, 137.1, 241.19, 138.84, 238.98, 140.33, 236.37,
|
||||
142.79, 229.46, 144.26, 222.2, 146.91, 203.45, 149.0, 195.46,
|
||||
150.82, 191.74, 152.78, 189.39, 155.06, 187.98, 157.64, 187.54,
|
||||
160.46, 188.07, 163.46, 189.54, 166.57, 191.89, 170.18, 195.54,
|
||||
176.49, 203.82, 187.93, 221.96, 192.91, 229.15, 198.18, 235.26,
|
||||
203.3, 239.57, 207.07, 241.74, 210.4, 243.03, 213.78, 243.76,
|
||||
217.74, 243.92, 221.07, 243.47, 224.8, 242.29, 228.25, 240.44,
|
||||
230.89, 238.38, 233.17, 235.92, 235.02, 233.11, 236.37, 230.0,
|
||||
237.18, 226.63, 237.42, 223.07, 237.07, 219.35, 236.13, 215.54,
|
||||
234.6, 211.66, 230.9, 205.16, 225.43, 198.15, 219.02, 191.41,
|
||||
205.04, 178.08, 200.57, 173.11, 197.35, 167.98, 196.49, 165.31,
|
||||
196.29, 163.13, 196.57, 160.98, 197.54, 158.44, 199.16, 155.9,
|
||||
201.39, 153.37, 206.78, 148.63, 224.45, 135.06, 228.82, 130.95,
|
||||
),
|
||||
),
|
||||
(
|
||||
"#B8862E",
|
||||
(
|
||||
439.15, 304.62, 441.35, 299.45, 442.51, 294.18, 442.42, 288.99,
|
||||
441.16, 284.54, 438.79, 280.56, 435.43, 277.23, 431.27, 274.73,
|
||||
426.09, 273.1, 421.13, 272.75, 416.7, 273.37, 412.03, 275.08,
|
||||
407.76, 277.8, 404.33, 280.97, 400.93, 285.13, 391.39, 300.46,
|
||||
387.52, 305.61, 384.97, 308.13, 382.62, 309.84, 379.82, 311.14,
|
||||
377.32, 311.67, 374.44, 311.56, 371.59, 310.69, 368.84, 309.1,
|
||||
366.22, 306.86, 361.68, 301.2, 353.72, 288.2, 349.9, 282.87,
|
||||
345.1, 278.03, 339.97, 274.81, 336.22, 273.46, 332.8, 272.84,
|
||||
328.82, 272.8, 324.89, 273.46, 321.18, 274.78, 317.81, 276.73,
|
||||
314.92, 279.23, 312.64, 282.19, 311.36, 284.65, 310.49, 287.28,
|
||||
310.02, 290.04, 309.96, 292.87, 310.28, 295.74, 311.1, 299.1,
|
||||
313.73, 305.2, 316.79, 310.09, 321.01, 315.47, 337.3, 332.65,
|
||||
344.34, 340.99, 350.25, 349.71, 354.13, 357.71, 356.15, 364.64,
|
||||
356.94, 371.76, 356.69, 378.61, 354.92, 395.62, 354.93, 400.36,
|
||||
355.46, 405.02, 356.78, 409.97, 358.95, 414.48, 361.98, 418.37,
|
||||
365.77, 421.42, 369.24, 423.14, 372.98, 424.16, 376.83, 424.43,
|
||||
380.67, 423.95, 384.34, 422.72, 387.71, 420.81, 390.68, 418.27,
|
||||
393.42, 414.79, 394.87, 412.17, 396.16, 408.88, 397.04, 405.4,
|
||||
397.53, 401.79, 397.58, 394.42, 395.86, 378.48, 395.63, 371.63,
|
||||
396.54, 364.05, 398.85, 356.69, 402.9, 348.74, 408.61, 340.49,
|
||||
415.36, 332.56, 431.64, 315.37, 435.86, 309.98,
|
||||
),
|
||||
),
|
||||
(
|
||||
"#ECEAE9",
|
||||
(
|
||||
272.87, 180.5, 273.78, 191.15, 275.43, 199.68, 277.93, 207.24,
|
||||
281.46, 214.32, 286.01, 220.83, 291.97, 227.15, 298.81, 232.68,
|
||||
306.29, 237.38, 314.83, 241.44, 323.65, 244.37, 331.97, 245.96,
|
||||
340.33, 246.39, 348.69, 245.62, 356.98, 243.7, 365.74, 240.46,
|
||||
374.17, 236.11, 379.85, 232.38, 385.15, 228.16, 389.95, 223.48,
|
||||
393.76, 218.86, 397.03, 213.89, 399.73, 208.6, 401.84, 203.03,
|
||||
403.53, 196.59, 404.61, 189.99, 405.3, 181.99, 405.89, 159.12,
|
||||
407.09, 137.35, 407.21, 129.01, 406.69, 121.27, 405.6, 115.09,
|
||||
403.79, 109.27, 401.53, 104.61, 398.24, 100.21, 394.25, 96.96,
|
||||
389.72, 95.06, 385.41, 94.63, 381.04, 95.41, 376.28, 97.71,
|
||||
371.95, 101.35, 368.3, 106.12, 366.03, 110.43, 364.13, 115.78,
|
||||
363.07, 120.69, 362.53, 126.4, 362.58, 131.38, 363.12, 136.95,
|
||||
366.62, 155.29, 367.54, 162.94, 367.32, 171.38, 366.55, 176.01,
|
||||
365.5, 179.98, 363.26, 185.87, 360.61, 190.86, 357.41, 195.43,
|
||||
353.74, 199.38, 349.69, 202.52, 345.92, 204.46, 342.02, 205.56,
|
||||
338.06, 205.77, 334.12, 205.08, 330.28, 203.52, 326.61, 201.16,
|
||||
322.73, 197.62, 319.27, 193.35, 316.32, 188.55, 313.95, 183.43,
|
||||
312.21, 178.16, 310.8, 170.23, 310.73, 162.45, 311.59, 155.45,
|
||||
315.0, 137.8, 315.74, 128.01, 315.47, 123.01, 314.68, 118.04,
|
||||
313.31, 113.22, 311.38, 108.68, 308.91, 104.56, 305.95, 101.0,
|
||||
302.59, 98.14, 298.95, 96.07, 295.15, 94.89, 291.33, 94.64,
|
||||
287.61, 95.31, 284.11, 96.89, 281.8, 98.52, 279.7, 100.54,
|
||||
277.81, 102.91, 275.86, 106.15, 273.2, 112.94, 271.66, 120.41,
|
||||
271.11, 126.72, 271.03, 133.73, 272.32, 158.32,
|
||||
),
|
||||
),
|
||||
(
|
||||
"#ECEAE9",
|
||||
(
|
||||
142.5, 408.93, 144.93, 412.86, 148.33, 416.82, 151.62, 419.58,
|
||||
155.73, 421.94, 159.96, 423.33, 164.11, 423.69, 168.0, 423.04,
|
||||
171.46, 421.41, 173.61, 419.69, 175.81, 417.09, 177.3, 414.53,
|
||||
178.71, 411.07, 180.34, 403.92, 181.9, 389.45, 182.76, 384.3,
|
||||
184.38, 379.06, 186.6, 375.03, 188.42, 372.84, 190.56, 370.93,
|
||||
193.02, 369.3, 196.36, 367.72, 203.33, 365.93, 207.41, 365.55,
|
||||
211.54, 365.59, 218.2, 366.61, 224.14, 368.79, 226.71, 370.32,
|
||||
228.97, 372.13, 232.2, 376.09, 234.21, 380.29, 235.51, 385.06,
|
||||
237.68, 403.4, 239.06, 409.98, 241.43, 415.72, 243.06, 418.13,
|
||||
244.99, 420.16, 247.7, 422.03, 250.76, 423.22, 254.12, 423.7,
|
||||
257.08, 423.52, 260.7, 422.61, 263.71, 421.29, 267.19, 419.06,
|
||||
269.9, 416.7, 273.71, 412.09, 276.7, 406.63, 278.73, 400.57,
|
||||
279.77, 394.13, 279.87, 387.57, 279.19, 381.08, 277.76, 374.06,
|
||||
273.42, 357.39, 272.7, 353.01, 272.43, 348.73, 272.65, 344.45,
|
||||
273.45, 339.45, 277.62, 323.51, 278.95, 317.31, 279.71, 311.68,
|
||||
279.93, 306.77, 279.2, 298.62, 277.23, 291.66, 274.04, 285.39,
|
||||
269.78, 280.17, 267.06, 277.83, 263.57, 275.63, 260.56, 274.33,
|
||||
256.94, 273.46, 253.99, 273.3, 250.64, 273.8, 248.07, 274.77,
|
||||
245.32, 276.56, 243.34, 278.53, 241.66, 280.88, 239.2, 286.54,
|
||||
237.66, 293.75, 235.48, 312.08, 233.95, 317.39, 231.82, 321.5,
|
||||
230.08, 323.74, 228.0, 325.7, 225.6, 327.39, 222.9, 328.79,
|
||||
216.76, 330.71, 209.32, 331.48, 201.85, 330.81, 198.02, 329.85,
|
||||
195.07, 328.73, 192.39, 327.32, 190.0, 325.62, 187.94, 323.64,
|
||||
186.21, 321.39, 184.11, 317.26, 182.6, 311.93, 180.42, 293.59,
|
||||
179.04, 287.01, 177.76, 283.44, 176.37, 280.76, 174.68, 278.43,
|
||||
172.69, 276.48, 169.92, 274.72, 167.34, 273.77, 163.98, 273.3,
|
||||
161.03, 273.48, 157.4, 274.38, 154.4, 275.7, 150.92, 277.93,
|
||||
148.21, 280.29, 143.97, 285.54, 141.1, 291.09, 139.19, 297.22,
|
||||
138.23, 304.49, 138.34, 311.05, 139.18, 317.5, 144.55, 338.96,
|
||||
145.64, 347.04, 145.57, 351.31, 144.91, 356.27, 139.77, 376.54,
|
||||
138.77, 382.07, 138.23, 387.76, 138.29, 393.51, 139.06, 399.17,
|
||||
140.59, 404.59,
|
||||
),
|
||||
),
|
||||
)
|
||||
DARK = {"bg": "#211d1b", "surface": "#2b2624", "border": "#463e3a", "text": "#eceae9"}
|
||||
LIGHT = {"bg": "#f6f4f3", "surface": "#fcfbfb", "border": "#e0dad7", "text": "#211d1b"}
|
||||
FOCUS = "#b8862e"
|
||||
RADIUS = 12
|
||||
SPACE_SM = 8
|
||||
SPACE_MD = 16
|
||||
TEXT_BODY = 16
|
||||
@ -1,40 +0,0 @@
|
||||
"""Tk demo: a gatelock-sized window with the credit in the bottom-right corner.
|
||||
|
||||
python -m kuhy_credit.demo [--light]
|
||||
|
||||
Nothing opens until you click the logo and then the panel.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import tkinter as tk
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from kuhy_credit._data import DARK, LIGHT, SPACE_MD
|
||||
from kuhy_credit.tk import KuhyCredit
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
|
||||
|
||||
def build(
|
||||
root: tk.Tk, *, theme: str = "dark", opener: Callable[[str], object] | None = None
|
||||
) -> KuhyCredit:
|
||||
"""Fill ``root`` with a themed demo window and return its credit."""
|
||||
root.geometry("640x400")
|
||||
root.configure(bg=(DARK if theme == "dark" else LIGHT)["bg"])
|
||||
credit = KuhyCredit(root, theme=theme, opener=opener)
|
||||
credit.place(relx=1.0, rely=1.0, x=-SPACE_MD, y=-SPACE_MD, anchor="se")
|
||||
return credit
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None, *, root: tk.Tk | None = None) -> int:
|
||||
"""Run the demo window; returns the exit code."""
|
||||
parser = argparse.ArgumentParser(description="kuhy credit Tk demo")
|
||||
parser.add_argument("--light", action="store_true", help="light theme")
|
||||
args = parser.parse_args(argv)
|
||||
win = root or tk.Tk()
|
||||
build(win, theme="light" if args.light else "dark")
|
||||
win.mainloop()
|
||||
return 0
|
||||
@ -1,9 +0,0 @@
|
||||
"""``kuhy-credit``: print the one-line credit. Opens nothing."""
|
||||
|
||||
from kuhy_credit import credit_line
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""Print the credit line; returns the exit code."""
|
||||
print(credit_line())
|
||||
return 0
|
||||
@ -1,163 +0,0 @@
|
||||
"""The Tkinter credit: an M1 logo button that opens a credit-text panel.
|
||||
|
||||
credit = KuhyCredit(parent) # a Canvas: pack/grid/place it
|
||||
credit.place(relx=1, rely=1, anchor="se")
|
||||
|
||||
A click, Enter or Space on the logo opens a small panel (logo + text) placed
|
||||
in the toplevel next to the logo. A click, Enter or Space on the panel opens
|
||||
the website through ``opener`` (default: a new browser tab) and closes it.
|
||||
Escape, a click anywhere else in the window and a second logo click close it.
|
||||
|
||||
Tk draws no rounded corners and exposes no accessibility tree, so the radius
|
||||
token and the accessible name have no Tk form; keyboard focus does.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
import webbrowser
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from kuhy_credit._data import (
|
||||
DARK,
|
||||
FOCUS,
|
||||
LIGHT,
|
||||
LOGO_FIELD,
|
||||
LOGO_SHAPES,
|
||||
LOGO_SIZE,
|
||||
SPACE_MD,
|
||||
SPACE_SM,
|
||||
TEXT,
|
||||
TEXT_BODY,
|
||||
URL,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Callable
|
||||
|
||||
_THEMES = {"dark": DARK, "light": LIGHT}
|
||||
_KEYS = ("<Return>", "<space>")
|
||||
|
||||
|
||||
def _draw_logo(canvas: tk.Canvas, size: int) -> None:
|
||||
"""Draw the field and every logo polygon, scaled to ``size`` px.
|
||||
|
||||
Canvas coordinates start at the outer edge, so the drawing is shifted
|
||||
past the focus ring; the field colour is also the canvas background.
|
||||
"""
|
||||
inset = int(canvas.cget("highlightthickness"))
|
||||
scale = size / LOGO_SIZE
|
||||
canvas.configure(bg=LOGO_FIELD)
|
||||
canvas.create_rectangle(inset, inset, inset + size, inset + size, fill=LOGO_FIELD, width=0)
|
||||
for fill, points in LOGO_SHAPES:
|
||||
coords = [inset + p * scale for p in points]
|
||||
canvas.create_polygon(coords, fill=fill, width=0)
|
||||
|
||||
|
||||
def _new_tab(url: str) -> None:
|
||||
webbrowser.open(url, new=2)
|
||||
|
||||
|
||||
class KuhyCredit(tk.Canvas):
|
||||
"""The logo button; owns the panel it opens."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
parent: tk.Misc,
|
||||
*,
|
||||
theme: str = "dark",
|
||||
size: int = 48,
|
||||
opener: Callable[[str], object] | None = None,
|
||||
) -> None:
|
||||
"""Build the logo in ``parent`` and the (hidden) panel in its toplevel."""
|
||||
if theme not in _THEMES:
|
||||
msg = f"theme must be one of {sorted(_THEMES)}, got {theme!r}"
|
||||
raise ValueError(msg)
|
||||
pal = _THEMES[theme]
|
||||
super().__init__(
|
||||
parent, width=size, height=size, highlightthickness=2, takefocus=1,
|
||||
highlightcolor=FOCUS, highlightbackground=pal["surface"], cursor="hand2",
|
||||
) # fmt: skip
|
||||
_draw_logo(self, size)
|
||||
self._open_url = opener or _new_tab
|
||||
self._top = self.winfo_toplevel()
|
||||
self.panel = tk.Frame(
|
||||
self._top, bg=pal["surface"], padx=SPACE_MD, pady=SPACE_MD, takefocus=1,
|
||||
highlightthickness=1, highlightbackground=pal["border"], highlightcolor=FOCUS,
|
||||
cursor="hand2",
|
||||
) # fmt: skip
|
||||
self.panel_logo = tk.Canvas(self.panel, width=size, height=size, highlightthickness=0)
|
||||
_draw_logo(self.panel_logo, size)
|
||||
self.panel_logo.pack(side="left")
|
||||
self.label = tk.Label(
|
||||
self.panel, text=TEXT, bg=pal["surface"], fg=pal["text"], font=("Arial", -TEXT_BODY)
|
||||
)
|
||||
self.label.pack(side="left", padx=(SPACE_SM, 0))
|
||||
self.is_open = False
|
||||
self.bind("<Button-1>", self._toggle)
|
||||
for widget in (self.panel, self.panel_logo, self.label):
|
||||
widget.bind("<Button-1>", self._activate)
|
||||
# A held key must not open the site: the press that opened the panel
|
||||
# stays "held" until released, and X autorepeat (a release and a press
|
||||
# with the same timestamp) does not count as a release.
|
||||
self._held = False
|
||||
self._released_at = -1
|
||||
for key in _KEYS:
|
||||
self.bind(key, self._key_toggle)
|
||||
self.panel.bind(key, self._key_activate)
|
||||
self.panel.bind(key.replace("<", "<KeyRelease-", 1), self._key_released)
|
||||
self._top.bind("<Escape>", self._escape, add="+")
|
||||
self._top.bind("<Button-1>", self._outside, add="+")
|
||||
|
||||
def open(self) -> None:
|
||||
"""Show the panel beside the logo, on the side with more room."""
|
||||
self._top.update_idletasks()
|
||||
lx = self.winfo_rootx() - self._top.winfo_rootx()
|
||||
ly = self.winfo_rooty() - self._top.winfo_rooty()
|
||||
lw, lh = self.winfo_width(), self.winfo_height()
|
||||
pw, ph = self.panel.winfo_reqwidth(), self.panel.winfo_reqheight()
|
||||
below = ly + lh / 2 < self._top.winfo_height() / 2
|
||||
y = ly + lh + SPACE_SM if below else ly - SPACE_SM - ph
|
||||
x = lx if lx + lw / 2 < self._top.winfo_width() / 2 else lx + lw - pw
|
||||
self.panel.place(x=max(0, x), y=max(0, y))
|
||||
self.panel.lift()
|
||||
self.panel.focus_set()
|
||||
self.is_open = True
|
||||
|
||||
def close(self) -> None:
|
||||
"""Hide the panel."""
|
||||
self.panel.place_forget()
|
||||
self.is_open = False
|
||||
|
||||
def _toggle(self, _event: tk.Event | None = None) -> None:
|
||||
if self.is_open:
|
||||
self.close()
|
||||
else:
|
||||
self.open()
|
||||
|
||||
def _key_toggle(self, event: tk.Event) -> None:
|
||||
self._held = True
|
||||
self._toggle(event)
|
||||
|
||||
def _key_released(self, event: tk.Event) -> None:
|
||||
self._held = False
|
||||
self._released_at = event.time
|
||||
|
||||
def _key_activate(self, event: tk.Event) -> None:
|
||||
if self._held or event.time == self._released_at:
|
||||
self._held = True
|
||||
return
|
||||
self._activate(event)
|
||||
|
||||
def _activate(self, _event: tk.Event | None = None) -> None:
|
||||
self.close()
|
||||
self._open_url(URL)
|
||||
|
||||
def _escape(self, _event: tk.Event | None = None) -> None:
|
||||
if self.is_open:
|
||||
self.close()
|
||||
self.focus_set()
|
||||
|
||||
def _outside(self, event: tk.Event) -> None:
|
||||
if self.is_open and event.widget not in (self, self.panel, self.panel_logo, self.label):
|
||||
self.close()
|
||||
@ -1,65 +0,0 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=61"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "kuhy-credit"
|
||||
version = "0.1.0"
|
||||
description = "The shared 'Created by kuhy' logo credit: Tkinter widget and terminal line"
|
||||
requires-python = ">=3.14"
|
||||
dependencies = [] # pure stdlib: tkinter and webbrowser ship with Python
|
||||
|
||||
[project.scripts]
|
||||
kuhy-credit = "kuhy_credit.terminal:main"
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
include = ["kuhy_credit*"]
|
||||
exclude = ["kuhy_credit.tests*"]
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py314"
|
||||
line-length = 100
|
||||
extend-exclude = ["web", "flutter", "godot"]
|
||||
|
||||
# The generated data file wraps itself; the formatter would explode it.
|
||||
[tool.ruff.format]
|
||||
exclude = ["kuhy_credit/_data.py"]
|
||||
|
||||
[tool.ruff.lint]
|
||||
select = ["ALL"]
|
||||
ignore = ["D203", "D213", "COM812", "ISC001", "S603", "S607", "CPY001"]
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"tests/*.py" = ["ANN", "ARG", "D", "TC", "PLC0415", "PLR2004", "S101", "SLF001", "E501"]
|
||||
"kuhy_credit/_data.py" = ["E501"]
|
||||
# E2E drivers: scripts that assert and print, not library code.
|
||||
"e2e/*.py" = ["ANN", "D", "TC", "E501", "EM", "INP001", "S101", "S603", "T201", "TRY003", "PLR2004"]
|
||||
# The generator and the terminal helper are CLIs: printing is their output.
|
||||
"generator/generate.py" = ["T201"]
|
||||
"kuhy_credit/terminal.py" = ["T201"]
|
||||
|
||||
[tool.ruff.lint.pydocstyle]
|
||||
convention = "google"
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
pythonpath = ["."]
|
||||
addopts = [
|
||||
"--strict-markers",
|
||||
"--strict-config",
|
||||
"-ra",
|
||||
"--cov=kuhy_credit",
|
||||
"--cov=generator",
|
||||
"--cov-branch",
|
||||
"--cov-report=term-missing",
|
||||
]
|
||||
filterwarnings = ["error"]
|
||||
|
||||
[tool.coverage.run]
|
||||
branch = true
|
||||
omit = ["*/tests/*"]
|
||||
|
||||
[tool.coverage.report]
|
||||
fail_under = 100
|
||||
show_missing = true
|
||||
exclude_lines = ["pragma: no cover", 'if __name__ == "__main__":', "if TYPE_CHECKING:"]
|
||||
@ -1,4 +0,0 @@
|
||||
# Exact pins, newest stable (shared dependency-freshness gate).
|
||||
pytest==9.2.0
|
||||
pytest-cov==7.1.0
|
||||
ruff==0.17.6
|
||||
@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Prints the one-line kuhy credit and opens nothing (generated by kuhy_credit/generator/generate.py; DO NOT EDIT).
|
||||
set -euo pipefail
|
||||
printf '%s %s\n' 'Created by kuhy' https://kuhy.duckdns.org
|
||||
@ -1,63 +0,0 @@
|
||||
"""A real Tk root per test, always on a private Xvfb display.
|
||||
|
||||
The session starts its own Xvfb and points DISPLAY at it, so a plain
|
||||
``pytest`` run never opens windows on the desktop it was started from.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tkinter as tk
|
||||
from collections.abc import Iterator
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def private_display() -> Iterator[None]:
|
||||
xvfb = shutil.which("Xvfb")
|
||||
if xvfb is None:
|
||||
pytest.exit("Xvfb is required (the Tk tests never use the real display)", 2)
|
||||
read, write = os.pipe()
|
||||
proc = subprocess.Popen(
|
||||
[xvfb, "-displayfd", str(write), "-screen", "0", "1600x1200x24", "-nolisten", "tcp"],
|
||||
pass_fds=(write,),
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
os.close(write)
|
||||
with os.fdopen(read) as fd:
|
||||
number = fd.readline().strip()
|
||||
old = os.environ.get("DISPLAY")
|
||||
os.environ["DISPLAY"] = f":{number}"
|
||||
yield
|
||||
if old is None:
|
||||
os.environ.pop("DISPLAY", None)
|
||||
else:
|
||||
os.environ["DISPLAY"] = old
|
||||
proc.terminate()
|
||||
proc.wait(10)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def root() -> Iterator[tk.Tk]:
|
||||
win = tk.Tk()
|
||||
win.geometry("480x320+0+0")
|
||||
yield win
|
||||
win.destroy()
|
||||
|
||||
|
||||
class Opener:
|
||||
"""Stands in for the browser launch: records URLs, opens nothing."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.urls: list[str] = []
|
||||
|
||||
def __call__(self, url: str) -> None:
|
||||
self.urls.append(url)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def opener() -> Opener:
|
||||
return Opener()
|
||||
@ -1,194 +0,0 @@
|
||||
"""Generator: SVG parsing, token parsing, emitters and the drift check."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from generator import generate, svg, tokens
|
||||
|
||||
CREDIT_DIR = Path(__file__).resolve().parents[1]
|
||||
REPO_ROOT = CREDIT_DIR.parent
|
||||
|
||||
|
||||
def test_logo_parses_into_disjoint_polygons() -> None:
|
||||
logo = svg.parse_logo((REPO_ROOT / "unified-design-system/logo/final/kuhy.svg").read_text())
|
||||
assert logo.size == 512
|
||||
assert logo.field == "#211D1B"
|
||||
assert [s.fill for s in logo.shapes] == ["#B8862E"] * 2 + ["#ECEAE9"] * 2
|
||||
assert all(len(s.points) >= 3 for s in logo.shapes)
|
||||
|
||||
|
||||
def test_overlapping_subpaths_are_rejected() -> None:
|
||||
doc = (
|
||||
'<svg viewBox="0 0 10 10"><rect id="field" fill="#000000"/>'
|
||||
'<path fill="#FFFFFF" d="M1 1L5 1L5 5ZM2 2L6 2L6 6Z"/></svg>'
|
||||
)
|
||||
with pytest.raises(ValueError, match="overlap"):
|
||||
svg.parse_logo(doc)
|
||||
|
||||
|
||||
def test_unsupported_path_command_is_rejected() -> None:
|
||||
doc = (
|
||||
'<svg viewBox="0 0 10 10"><rect id="field" fill="#000000"/>'
|
||||
'<path fill="#FFFFFF" d="M1 1C5 1 5 5 1 1Z"/></svg>'
|
||||
)
|
||||
with pytest.raises(ValueError, match="unsupported"):
|
||||
svg.parse_logo(doc)
|
||||
|
||||
|
||||
def test_missing_field_is_rejected() -> None:
|
||||
with pytest.raises(ValueError, match="field"):
|
||||
svg.parse_logo('<svg viewBox="0 0 10 10"></svg>')
|
||||
|
||||
|
||||
def test_tokens_read_dark_and_light_from_css() -> None:
|
||||
tok = tokens.parse_tokens((REPO_ROOT / "web_ui/src/tokens.css").read_text())
|
||||
assert (tok.dark.bg, tok.light.bg) == ("#211d1b", "#f6f4f3")
|
||||
assert tok.dark.surface == "#2b2624"
|
||||
assert tok.light.surface == "#fcfbfb"
|
||||
assert tok.dark.text == "#eceae9"
|
||||
assert tok.light.text == "#211d1b"
|
||||
assert tok.focus == "#b8862e"
|
||||
assert (tok.radius, tok.space_sm, tok.space_md, tok.text_body) == (12, 8, 16, 16)
|
||||
|
||||
|
||||
def test_missing_token_is_rejected() -> None:
|
||||
with pytest.raises(ValueError, match="--surface-1"):
|
||||
tokens.parse_tokens(":root { --bg: #000000; }")
|
||||
|
||||
|
||||
def test_every_generated_file_matches_the_sources() -> None:
|
||||
assert generate.drift(CREDIT_DIR) == []
|
||||
|
||||
|
||||
def test_main_check_passes_on_a_clean_tree(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
assert generate.main(["--check"]) == 0
|
||||
assert "in sync" in capsys.readouterr().out
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def copy(tmp_path: Path) -> Path:
|
||||
"""A throwaway copy of the repo bits the generator reads and writes."""
|
||||
root = tmp_path / "repo"
|
||||
for rel in ("unified-design-system/logo/final", "web_ui/src"):
|
||||
(root / rel).mkdir(parents=True)
|
||||
shutil.copy(
|
||||
REPO_ROOT / "unified-design-system/logo/final/kuhy.svg",
|
||||
root / "unified-design-system/logo/final",
|
||||
)
|
||||
shutil.copy(REPO_ROOT / "web_ui/src/tokens.css", root / "web_ui/src")
|
||||
(root / "kuhy_credit").mkdir()
|
||||
shutil.copy(CREDIT_DIR / "credit.json", root / "kuhy_credit")
|
||||
return root / "kuhy_credit"
|
||||
|
||||
|
||||
def test_write_then_check_round_trips(copy: Path) -> None:
|
||||
assert {d.stack for d in generate.drift(copy)} == set(generate.STACKS)
|
||||
generate.write(copy)
|
||||
assert generate.drift(copy) == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stack", sorted(generate.STACKS))
|
||||
def test_editing_one_stack_names_that_stack(
|
||||
copy: Path, stack: str, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
generate.write(copy)
|
||||
target = copy / generate.STACKS[stack]
|
||||
target.write_text(target.read_text().replace("https://kuhy.duckdns.org", "https://example.org"))
|
||||
assert [d.stack for d in generate.drift(copy)] == [stack]
|
||||
assert generate.main(["--check", "--dir", str(copy)]) == 1
|
||||
assert stack in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_changing_the_shared_url_drifts_every_stack(copy: Path) -> None:
|
||||
generate.write(copy)
|
||||
data = json.loads((copy / "credit.json").read_text())
|
||||
data["url"] = "https://example.org"
|
||||
(copy / "credit.json").write_text(json.dumps(data))
|
||||
assert {d.stack for d in generate.drift(copy)} == set(generate.STACKS)
|
||||
|
||||
|
||||
def test_main_writes_without_check(copy: Path, capsys: pytest.CaptureFixture[str]) -> None:
|
||||
assert generate.main(["--dir", str(copy)]) == 0
|
||||
assert "wrote" in capsys.readouterr().out
|
||||
assert generate.drift(copy) == []
|
||||
|
||||
|
||||
def test_css_without_root_is_rejected() -> None:
|
||||
with pytest.raises(ValueError, match="--bg"):
|
||||
tokens.parse_tokens("")
|
||||
|
||||
|
||||
def test_whole_numbers_keep_a_decimal_point() -> None:
|
||||
from generator import emit
|
||||
|
||||
assert emit._num(12.0) == "12.0"
|
||||
assert emit._num(12.5) == "12.5"
|
||||
|
||||
|
||||
HAND_WRITTEN = [
|
||||
"kuhy_credit/__init__.py",
|
||||
"kuhy_credit/tk.py",
|
||||
"kuhy_credit/demo.py",
|
||||
"web/src/kuhy-credit.js",
|
||||
"web/demo/index.html",
|
||||
"flutter/lib/src/kuhy_credit.dart",
|
||||
"flutter/lib/src/kuhy_credit_logo.dart",
|
||||
"flutter/example/lib/main.dart",
|
||||
"godot/addons/kuhy_credit/kuhy_credit.gd",
|
||||
"godot/demo/demo.gd",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("rel", HAND_WRITTEN)
|
||||
def test_hand_written_code_reads_the_constants(rel: str) -> None:
|
||||
"""Only generated files may spell out the URL or the words."""
|
||||
text = (CREDIT_DIR / rel).read_text()
|
||||
data = json.loads((CREDIT_DIR / "credit.json").read_text())
|
||||
assert data["url"] not in text
|
||||
assert data["text"] not in text
|
||||
|
||||
|
||||
def test_gdscript_strings_follow_gdformat_quoting() -> None:
|
||||
from generator import emit
|
||||
|
||||
assert emit._gd_str('a"b') == "'a\"b'"
|
||||
assert emit._gd_str("a'b\"") == '"a\'b\\""'
|
||||
assert emit._gd_str("plain") == '"plain"'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("d", "match"),
|
||||
[
|
||||
("M.5 0L100 0L100 100Z", None),
|
||||
("M0 0L100 0L100 100", "without Z"),
|
||||
("M0 0L100 0;L5 5Z", "unparsed"),
|
||||
],
|
||||
)
|
||||
def test_path_data_is_parsed_strictly(d: str, match: str | None) -> None:
|
||||
doc = f'<svg viewBox="0 0 10 10"><rect id="field" fill="#000000"/><path fill="#FFFFFF" d="{d}"/></svg>'
|
||||
if match is None:
|
||||
assert svg.parse_logo(doc).shapes[0].points[:2] == (0.5, 0.0)
|
||||
else:
|
||||
with pytest.raises(ValueError, match=match):
|
||||
svg.parse_logo(doc)
|
||||
|
||||
|
||||
def test_transforms_are_rejected() -> None:
|
||||
doc = (
|
||||
'<svg viewBox="0 0 10 10"><rect id="field" fill="#000000"/>'
|
||||
'<g transform="translate(5 5)"><path fill="#FFFFFF" d="M1 1L5 1L5 5Z"/></g></svg>'
|
||||
)
|
||||
with pytest.raises(ValueError, match="transform"):
|
||||
svg.parse_logo(doc)
|
||||
|
||||
|
||||
def test_relative_dir_resolves(
|
||||
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
monkeypatch.chdir(CREDIT_DIR)
|
||||
assert generate.main(["--check", "--dir", "."]) == 0
|
||||
@ -1,25 +0,0 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from kuhy_credit import TEXT, URL, credit_line, terminal
|
||||
|
||||
CREDIT_DIR = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_credit_line_is_text_then_url() -> None:
|
||||
assert credit_line() == "Created by kuhy https://kuhy.duckdns.org"
|
||||
assert (TEXT, URL) == ("Created by kuhy", "https://kuhy.duckdns.org")
|
||||
|
||||
|
||||
def test_main_prints_one_line(capsys: pytest.CaptureFixture[str]) -> None:
|
||||
assert terminal.main() == 0
|
||||
assert capsys.readouterr().out == "Created by kuhy https://kuhy.duckdns.org\n"
|
||||
|
||||
|
||||
def test_shell_helper_prints_the_same_line() -> None:
|
||||
out = subprocess.run(
|
||||
[str(CREDIT_DIR / "terminal/kuhy-credit.sh")], check=True, capture_output=True, text=True
|
||||
).stdout
|
||||
assert out == credit_line() + "\n"
|
||||
@ -1,182 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
import webbrowser
|
||||
|
||||
import pytest
|
||||
|
||||
from kuhy_credit import TEXT, URL
|
||||
from kuhy_credit import tk as credit_tk
|
||||
from kuhy_credit._data import DARK, LIGHT, LOGO_SHAPES
|
||||
|
||||
|
||||
def _make(root: tk.Tk, opener, *, theme: str = "dark", corner: str = "se") -> credit_tk.KuhyCredit:
|
||||
credit = credit_tk.KuhyCredit(root, theme=theme, opener=opener)
|
||||
rel = {"se": (1.0, 1.0), "nw": (0.0, 0.0)}[corner]
|
||||
credit.place(relx=rel[0], rely=rel[1], anchor=corner)
|
||||
root.update()
|
||||
return credit
|
||||
|
||||
|
||||
def _click(widget: tk.Misc) -> None:
|
||||
widget.event_generate("<Button-1>", x=2, y=2)
|
||||
widget.update()
|
||||
|
||||
|
||||
def test_logo_draws_field_and_every_shape(root, opener) -> None:
|
||||
credit = _make(root, opener)
|
||||
assert len(credit.find_all()) == 1 + len(LOGO_SHAPES)
|
||||
assert not credit.is_open
|
||||
|
||||
|
||||
def test_logo_click_opens_panel_with_logo_and_text(root, opener) -> None:
|
||||
credit = _make(root, opener)
|
||||
_click(credit)
|
||||
assert credit.is_open
|
||||
assert credit.panel.winfo_ismapped()
|
||||
assert credit.label.cget("text") == TEXT
|
||||
assert len(credit.panel_logo.find_all()) == 1 + len(LOGO_SHAPES)
|
||||
assert opener.urls == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target", ["panel", "label", "panel_logo"])
|
||||
def test_panel_click_opens_the_url_and_closes(root, opener, target: str) -> None:
|
||||
credit = _make(root, opener)
|
||||
_click(credit)
|
||||
_click(getattr(credit, target))
|
||||
assert opener.urls == [URL]
|
||||
assert not credit.is_open
|
||||
|
||||
|
||||
def test_escape_closes_without_opening(root, opener) -> None:
|
||||
credit = _make(root, opener)
|
||||
_click(credit)
|
||||
credit.panel.focus_force()
|
||||
root.update()
|
||||
credit.panel.event_generate("<Escape>")
|
||||
root.update()
|
||||
assert not credit.is_open
|
||||
assert opener.urls == []
|
||||
|
||||
|
||||
def test_outside_click_closes(root, opener) -> None:
|
||||
other = tk.Frame(root, width=50, height=50)
|
||||
other.place(x=200, y=100)
|
||||
credit = _make(root, opener)
|
||||
_click(credit)
|
||||
_click(other)
|
||||
assert not credit.is_open
|
||||
assert opener.urls == []
|
||||
|
||||
|
||||
def test_second_logo_click_closes_and_stays_closed(root, opener) -> None:
|
||||
credit = _make(root, opener)
|
||||
_click(credit)
|
||||
_click(credit)
|
||||
root.update()
|
||||
assert not credit.is_open
|
||||
assert opener.urls == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", ["<Return>", "<space>"])
|
||||
def test_keyboard_opens_panel_then_url(root, opener, key: str) -> None:
|
||||
credit = _make(root, opener)
|
||||
assert int(credit.cget("takefocus")) == 1
|
||||
assert root.tk_focusNext() is credit # Tab reaches the logo
|
||||
credit.focus_force()
|
||||
root.update()
|
||||
credit.event_generate(key)
|
||||
root.update()
|
||||
assert credit.is_open
|
||||
assert root.focus_get() is credit.panel
|
||||
credit.panel.event_generate(key.replace("<", "<KeyRelease-", 1), time=100)
|
||||
credit.panel.event_generate(key, time=400)
|
||||
root.update()
|
||||
assert opener.urls == [URL]
|
||||
|
||||
|
||||
def test_click_outside_when_closed_is_ignored(root, opener) -> None:
|
||||
credit = _make(root, opener)
|
||||
_click(root)
|
||||
assert not credit.is_open
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("theme", "pal"), [("dark", DARK), ("light", LIGHT)])
|
||||
def test_theme_colours_come_from_tokens(root, opener, theme: str, pal: dict) -> None:
|
||||
credit = _make(root, opener, theme=theme)
|
||||
assert credit.panel.cget("bg") == pal["surface"]
|
||||
assert credit.panel.cget("highlightbackground") == pal["border"]
|
||||
assert credit.label.cget("fg") == pal["text"]
|
||||
|
||||
|
||||
def test_unknown_theme_is_rejected(root, opener) -> None:
|
||||
with pytest.raises(ValueError, match="theme"):
|
||||
credit_tk.KuhyCredit(root, theme="blue", opener=opener)
|
||||
|
||||
|
||||
def test_panel_sits_above_a_bottom_right_logo(root, opener) -> None:
|
||||
credit = _make(root, opener, corner="se")
|
||||
_click(credit)
|
||||
assert credit.panel.winfo_y() < credit.winfo_y()
|
||||
assert credit.panel.winfo_x() + credit.panel.winfo_width() <= root.winfo_width()
|
||||
|
||||
|
||||
def test_panel_sits_below_a_top_left_logo(root, opener) -> None:
|
||||
credit = _make(root, opener, corner="nw")
|
||||
_click(credit)
|
||||
assert credit.panel.winfo_y() > credit.winfo_y()
|
||||
assert credit.panel.winfo_x() == credit.winfo_x()
|
||||
|
||||
|
||||
def test_default_opener_uses_a_new_browser_tab(monkeypatch: pytest.MonkeyPatch, root) -> None:
|
||||
seen = []
|
||||
monkeypatch.setattr(webbrowser, "open", lambda url, new=0: seen.append((url, new)))
|
||||
credit = _make(root, None)
|
||||
_click(credit)
|
||||
_click(credit.panel)
|
||||
assert seen == [(URL, 2)]
|
||||
|
||||
|
||||
def test_escape_when_closed_keeps_focus_where_it_is(root, opener) -> None:
|
||||
entry = tk.Entry(root)
|
||||
entry.place(x=10, y=10)
|
||||
_make(root, opener)
|
||||
entry.focus_force()
|
||||
root.update()
|
||||
entry.event_generate("<Escape>")
|
||||
root.update()
|
||||
assert root.focus_get() is entry
|
||||
|
||||
|
||||
def _key_at(widget: tk.Misc, kind: str, key: str, when: int) -> None:
|
||||
widget.event_generate(f"<{kind}-{key}>", time=when)
|
||||
widget.update()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"events",
|
||||
[
|
||||
[("KeyPress", 1000)], # repeat with no release between
|
||||
[("KeyRelease", 1000), ("KeyPress", 1000)], # X autorepeat pair
|
||||
],
|
||||
)
|
||||
def test_held_enter_never_opens_the_site(root, opener, events) -> None:
|
||||
credit = _make(root, opener)
|
||||
credit.focus_force()
|
||||
root.update()
|
||||
_key_at(credit, "KeyPress", "Return", 900)
|
||||
assert credit.is_open
|
||||
for kind, when in events:
|
||||
_key_at(root.focus_get(), kind, "Return", when)
|
||||
assert opener.urls == []
|
||||
assert credit.is_open
|
||||
|
||||
|
||||
def test_a_fresh_press_after_release_opens_the_site(root, opener) -> None:
|
||||
credit = _make(root, opener)
|
||||
credit.focus_force()
|
||||
root.update()
|
||||
_key_at(credit, "KeyPress", "Return", 900)
|
||||
_key_at(root.focus_get(), "KeyRelease", "Return", 1000)
|
||||
_key_at(root.focus_get(), "KeyPress", "Return", 1300)
|
||||
assert opener.urls == [URL]
|
||||
@ -1,50 +0,0 @@
|
||||
"""E2E: the demo window, two pointer clicks hit-tested at screen coordinates."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
|
||||
import pytest
|
||||
|
||||
from kuhy_credit import URL, demo
|
||||
|
||||
|
||||
def _click_at_centre_of(root: tk.Tk, widget: tk.Misc) -> None:
|
||||
"""Click whatever widget sits under the centre of ``widget`` on screen."""
|
||||
root.update()
|
||||
x = widget.winfo_rootx() + widget.winfo_width() // 2
|
||||
y = widget.winfo_rooty() + widget.winfo_height() // 2
|
||||
hit = root.winfo_containing(x, y)
|
||||
assert hit is not None
|
||||
hit.event_generate("<Button-1>", x=x - hit.winfo_rootx(), y=y - hit.winfo_rooty())
|
||||
root.update()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("theme", ["dark", "light"])
|
||||
def test_two_clicks_open_the_website(root, opener, theme: str) -> None:
|
||||
credit = demo.build(root, theme=theme, opener=opener)
|
||||
_click_at_centre_of(root, credit)
|
||||
assert credit.is_open
|
||||
assert opener.urls == []
|
||||
_click_at_centre_of(root, credit.label)
|
||||
assert opener.urls == [URL]
|
||||
assert not credit.is_open
|
||||
|
||||
|
||||
def test_main_runs_the_window(root, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(root, "mainloop", lambda: None)
|
||||
assert demo.main(["--light"], root=root) == 0
|
||||
assert demo.main([], root=root) == 0
|
||||
|
||||
|
||||
def test_main_creates_its_own_root(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
made = []
|
||||
|
||||
class FakeTk(tk.Tk):
|
||||
def mainloop(self, n: int = 0) -> None:
|
||||
made.append(self)
|
||||
self.destroy()
|
||||
|
||||
monkeypatch.setattr(tk, "Tk", FakeTk)
|
||||
assert demo.main([]) == 0
|
||||
assert len(made) == 1
|
||||
@ -1,21 +0,0 @@
|
||||
<!doctype html>
|
||||
<!-- Plain-HTML demo. Serve the repo root (python3 -m http.server -d ../../..)
|
||||
and open /kuhy_credit/web/demo/index.html; add ?theme=light or ?theme=dark
|
||||
to force a theme, otherwise it follows the system. -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>kuhy-credit demo</title>
|
||||
<link rel="stylesheet" href="/web_ui/src/tokens.css" />
|
||||
<style>
|
||||
html, body { height: 100%; margin: 0; background: var(--bg); }
|
||||
footer { position: fixed; right: var(--space-3); bottom: var(--space-3); }
|
||||
</style>
|
||||
<script type="module" src="../src/kuhy-credit.js"></script>
|
||||
<script type="module" src="./theme.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<footer><kuhy-credit></kuhy-credit></footer>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,8 +0,0 @@
|
||||
// ?theme=light|dark forces both the page tokens and the credit's theme.
|
||||
const theme = new URLSearchParams(location.search).get("theme");
|
||||
if (theme === "light" || theme === "dark") {
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
document.querySelector("kuhy-credit").setAttribute("theme", theme);
|
||||
const surface = { dark: "#211d1b", light: "#f6f4f3" }[theme];
|
||||
document.body.style.background = surface;
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
{
|
||||
"name": "@kuhyx/kuhy-credit",
|
||||
"version": "0.1.0",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
"description": "<kuhy-credit>: the shared 'Created by kuhy' logo credit as a dependency-free custom element.",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=24",
|
||||
"pnpm": ">=10"
|
||||
},
|
||||
"packageManager": "pnpm@12.21.0+sha512.66fd8278ee28935ce951792d34367ff3af5c432a2756445823029533835b8da529bbe0be5130afd56ed0713fb8789e47bad82d93bd5ae2fe54b15562d6276ef0",
|
||||
"files": [
|
||||
"src/kuhy-credit.js",
|
||||
"src/kuhy-credit.d.ts",
|
||||
"src/credit-data.js"
|
||||
],
|
||||
"main": "./src/kuhy-credit.js",
|
||||
"types": "./src/kuhy-credit.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/kuhy-credit.d.ts",
|
||||
"default": "./src/kuhy-credit.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "node --check src/kuhy-credit.js && node --check src/credit-data.js",
|
||||
"test": "vitest run",
|
||||
"coverage": "vitest run --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitest/coverage-v8": "5.1.1",
|
||||
"jsdom": "31.0.1",
|
||||
"vitest": "5.1.1"
|
||||
}
|
||||
}
|
||||
@ -1,115 +0,0 @@
|
||||
// The shared credit data (generated by kuhy_credit/generator/generate.py; DO NOT EDIT).
|
||||
export const CREDIT_URL = "https://kuhy.duckdns.org";
|
||||
export const CREDIT_TEXT = "Created by kuhy";
|
||||
export const LOGO_SVG =
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512"
|
||||
+ "\" width=\"512\" height=\"512\">\n<rect id=\"field\" width=\"512\" hei"
|
||||
+ "ght=\"512\" fill=\"#211D1B\"/>\n<path fill=\"#B8862E\" fill-rule=\"e"
|
||||
+ "venodd\" d=\"M232.45 126.71L235.40 121.83L236.86 117.46L237.16"
|
||||
+ " 113.16L236.11 108.55L233.71 104.34L230.14 100.74L225.62 97."
|
||||
+ "95L220.41 96.16L214.75 95.51L208.86 96.11L202.89 97.96L196.9"
|
||||
+ "7 101.02L191.80 104.61L186.14 109.43L168.83 127.05L163.79 13"
|
||||
+ "1.69L158.86 135.08L156.85 135.91L155.00 136.26L153.32 136.10"
|
||||
+ "L151.51 135.26L150.17 134.03L148.74 131.95L146.53 126.68L142"
|
||||
+ ".68 113.58L140.39 107.28L137.47 101.80L134.17 98.03L131.62 9"
|
||||
+ "6.28L129.30 95.34L126.82 94.91L124.22 94.99L121.55 95.59L118"
|
||||
+ ".85 96.69L116.18 98.26L113.59 100.29L110.67 103.26L108.46 10"
|
||||
+ "6.12L104.82 112.71L103.46 116.33L102.26 120.85L101.33 129.40"
|
||||
+ "L101.51 134.83L102.18 140.16L107.16 161.56L107.92 166.59L108"
|
||||
+ ".16 170.93L107.96 175.30L107.23 180.39L103.30 196.89L102.03 "
|
||||
+ "203.60L101.44 209.71L101.57 215.83L102.56 221.84L104.46 227."
|
||||
+ "54L106.85 232.14L110.30 236.77L113.30 239.71L117.11 242.44L1"
|
||||
+ "20.52 244.13L124.51 245.27L128.36 245.46L131.44 244.86L134.2"
|
||||
+ "5 243.55L137.10 241.19L138.84 238.98L140.33 236.37L142.79 22"
|
||||
+ "9.46L144.26 222.20L146.91 203.45L149.00 195.46L150.82 191.74"
|
||||
+ "L152.78 189.39L155.06 187.98L157.64 187.54L160.46 188.07L163"
|
||||
+ ".46 189.54L166.57 191.89L170.18 195.54L176.49 203.82L187.93 "
|
||||
+ "221.96L192.91 229.15L198.18 235.26L203.30 239.57L207.07 241."
|
||||
+ "74L210.40 243.03L213.78 243.76L217.74 243.92L221.07 243.47L2"
|
||||
+ "24.80 242.29L228.25 240.44L230.89 238.38L233.17 235.92L235.0"
|
||||
+ "2 233.11L236.37 230.00L237.18 226.63L237.42 223.07L237.07 21"
|
||||
+ "9.35L236.13 215.54L234.60 211.66L230.90 205.16L225.43 198.15"
|
||||
+ "L219.02 191.41L205.04 178.08L200.57 173.11L197.35 167.98L196"
|
||||
+ ".49 165.31L196.29 163.13L196.57 160.98L197.54 158.44L199.16 "
|
||||
+ "155.90L201.39 153.37L206.78 148.63L224.45 135.06L228.82 130."
|
||||
+ "95ZM439.15 304.62L441.35 299.45L442.51 294.18L442.42 288.99L"
|
||||
+ "441.16 284.54L438.79 280.56L435.43 277.23L431.27 274.73L426."
|
||||
+ "09 273.10L421.13 272.75L416.70 273.37L412.03 275.08L407.76 2"
|
||||
+ "77.80L404.33 280.97L400.93 285.13L391.39 300.46L387.52 305.6"
|
||||
+ "1L384.97 308.13L382.62 309.84L379.82 311.14L377.32 311.67L37"
|
||||
+ "4.44 311.56L371.59 310.69L368.84 309.10L366.22 306.86L361.68"
|
||||
+ " 301.20L353.72 288.20L349.90 282.87L345.10 278.03L339.97 274"
|
||||
+ ".81L336.22 273.46L332.80 272.84L328.82 272.80L324.89 273.46L"
|
||||
+ "321.18 274.78L317.81 276.73L314.92 279.23L312.64 282.19L311."
|
||||
+ "36 284.65L310.49 287.28L310.02 290.04L309.96 292.87L310.28 2"
|
||||
+ "95.74L311.10 299.10L313.73 305.20L316.79 310.09L321.01 315.4"
|
||||
+ "7L337.30 332.65L344.34 340.99L350.25 349.71L354.13 357.71L35"
|
||||
+ "6.15 364.64L356.94 371.76L356.69 378.61L354.92 395.62L354.93"
|
||||
+ " 400.36L355.46 405.02L356.78 409.97L358.95 414.48L361.98 418"
|
||||
+ ".37L365.77 421.42L369.24 423.14L372.98 424.16L376.83 424.43L"
|
||||
+ "380.67 423.95L384.34 422.72L387.71 420.81L390.68 418.27L393."
|
||||
+ "42 414.79L394.87 412.17L396.16 408.88L397.04 405.40L397.53 4"
|
||||
+ "01.79L397.58 394.42L395.86 378.48L395.63 371.63L396.54 364.0"
|
||||
+ "5L398.85 356.69L402.90 348.74L408.61 340.49L415.36 332.56L43"
|
||||
+ "1.64 315.37L435.86 309.98Z\"/>\n<path fill=\"#ECEAE9\" fill-rule"
|
||||
+ "=\"evenodd\" d=\"M272.87 180.50L273.78 191.15L275.43 199.68L277"
|
||||
+ ".93 207.24L281.46 214.32L286.01 220.83L291.97 227.15L298.81 "
|
||||
+ "232.68L306.29 237.38L314.83 241.44L323.65 244.37L331.97 245."
|
||||
+ "96L340.33 246.39L348.69 245.62L356.98 243.70L365.74 240.46L3"
|
||||
+ "74.17 236.11L379.85 232.38L385.15 228.16L389.95 223.48L393.7"
|
||||
+ "6 218.86L397.03 213.89L399.73 208.60L401.84 203.03L403.53 19"
|
||||
+ "6.59L404.61 189.99L405.30 181.99L405.89 159.12L407.09 137.35"
|
||||
+ "L407.21 129.01L406.69 121.27L405.60 115.09L403.79 109.27L401"
|
||||
+ ".53 104.61L398.24 100.21L394.25 96.96L389.72 95.06L385.41 94"
|
||||
+ ".63L381.04 95.41L376.28 97.71L371.95 101.35L368.30 106.12L36"
|
||||
+ "6.03 110.43L364.13 115.78L363.07 120.69L362.53 126.40L362.58"
|
||||
+ " 131.38L363.12 136.95L366.62 155.29L367.54 162.94L367.32 171"
|
||||
+ ".38L366.55 176.01L365.50 179.98L363.26 185.87L360.61 190.86L"
|
||||
+ "357.41 195.43L353.74 199.38L349.69 202.52L345.92 204.46L342."
|
||||
+ "02 205.56L338.06 205.77L334.12 205.08L330.28 203.52L326.61 2"
|
||||
+ "01.16L322.73 197.62L319.27 193.35L316.32 188.55L313.95 183.4"
|
||||
+ "3L312.21 178.16L310.80 170.23L310.73 162.45L311.59 155.45L31"
|
||||
+ "5.00 137.80L315.74 128.01L315.47 123.01L314.68 118.04L313.31"
|
||||
+ " 113.22L311.38 108.68L308.91 104.56L305.95 101.00L302.59 98."
|
||||
+ "14L298.95 96.07L295.15 94.89L291.33 94.64L287.61 95.31L284.1"
|
||||
+ "1 96.89L281.80 98.52L279.70 100.54L277.81 102.91L275.86 106."
|
||||
+ "15L273.20 112.94L271.66 120.41L271.11 126.72L271.03 133.73L2"
|
||||
+ "72.32 158.32ZM142.50 408.93L144.93 412.86L148.33 416.82L151."
|
||||
+ "62 419.58L155.73 421.94L159.96 423.33L164.11 423.69L168.00 4"
|
||||
+ "23.04L171.46 421.41L173.61 419.69L175.81 417.09L177.30 414.5"
|
||||
+ "3L178.71 411.07L180.34 403.92L181.90 389.45L182.76 384.30L18"
|
||||
+ "4.38 379.06L186.60 375.03L188.42 372.84L190.56 370.93L193.02"
|
||||
+ " 369.30L196.36 367.72L203.33 365.93L207.41 365.55L211.54 365"
|
||||
+ ".59L218.20 366.61L224.14 368.79L226.71 370.32L228.97 372.13L"
|
||||
+ "232.20 376.09L234.21 380.29L235.51 385.06L237.68 403.40L239."
|
||||
+ "06 409.98L241.43 415.72L243.06 418.13L244.99 420.16L247.70 4"
|
||||
+ "22.03L250.76 423.22L254.12 423.70L257.08 423.52L260.70 422.6"
|
||||
+ "1L263.71 421.29L267.19 419.06L269.90 416.70L273.71 412.09L27"
|
||||
+ "6.70 406.63L278.73 400.57L279.77 394.13L279.87 387.57L279.19"
|
||||
+ " 381.08L277.76 374.06L273.42 357.39L272.70 353.01L272.43 348"
|
||||
+ ".73L272.65 344.45L273.45 339.45L277.62 323.51L278.95 317.31L"
|
||||
+ "279.71 311.68L279.93 306.77L279.20 298.62L277.23 291.66L274."
|
||||
+ "04 285.39L269.78 280.17L267.06 277.83L263.57 275.63L260.56 2"
|
||||
+ "74.33L256.94 273.46L253.99 273.30L250.64 273.80L248.07 274.7"
|
||||
+ "7L245.32 276.56L243.34 278.53L241.66 280.88L239.20 286.54L23"
|
||||
+ "7.66 293.75L235.48 312.08L233.95 317.39L231.82 321.50L230.08"
|
||||
+ " 323.74L228.00 325.70L225.60 327.39L222.90 328.79L216.76 330"
|
||||
+ ".71L209.32 331.48L201.85 330.81L198.02 329.85L195.07 328.73L"
|
||||
+ "192.39 327.32L190.00 325.62L187.94 323.64L186.21 321.39L184."
|
||||
+ "11 317.26L182.60 311.93L180.42 293.59L179.04 287.01L177.76 2"
|
||||
+ "83.44L176.37 280.76L174.68 278.43L172.69 276.48L169.92 274.7"
|
||||
+ "2L167.34 273.77L163.98 273.30L161.03 273.48L157.40 274.38L15"
|
||||
+ "4.40 275.70L150.92 277.93L148.21 280.29L143.97 285.54L141.10"
|
||||
+ " 291.09L139.19 297.22L138.23 304.49L138.34 311.05L139.18 317"
|
||||
+ ".50L144.55 338.96L145.64 347.04L145.57 351.31L144.91 356.27L"
|
||||
+ "139.77 376.54L138.77 382.07L138.23 387.76L138.29 393.51L139."
|
||||
+ "06 399.17L140.59 404.59Z\"/>\n</svg>\n";
|
||||
export const TOKENS = {
|
||||
dark: { bg: "#211d1b", surface: "#2b2624", border: "#463e3a", text: "#eceae9" },
|
||||
light: { bg: "#f6f4f3", surface: "#fcfbfb", border: "#e0dad7", text: "#211d1b" },
|
||||
focus: "#b8862e",
|
||||
radius: 12,
|
||||
spaceSm: 8,
|
||||
spaceMd: 16,
|
||||
textBody: 16,
|
||||
};
|
||||
26
kuhy_credit/web/src/kuhy-credit.d.ts
vendored
@ -1,26 +0,0 @@
|
||||
/** `<kuhy-credit>`: the shared "Created by kuhy" logo credit. */
|
||||
export declare class KuhyCredit extends HTMLElement {
|
||||
/** True while the panel is showing. */
|
||||
readonly open: boolean;
|
||||
/** Hide the panel. */
|
||||
close(): void;
|
||||
}
|
||||
|
||||
/** Attributes the element reads. */
|
||||
export interface KuhyCreditAttributes {
|
||||
align?: "end" | "start";
|
||||
placement?: "above" | "below";
|
||||
theme?: "dark" | "light";
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"kuhy-credit": KuhyCredit;
|
||||
}
|
||||
// React 19 / Vite: <kuhy-credit /> in JSX.
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
"kuhy-credit": KuhyCreditAttributes & { class?: string; className?: string };
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,117 +0,0 @@
|
||||
/**
|
||||
* `<kuhy-credit>`: the shared kuhy credit, dependency-free.
|
||||
*
|
||||
* Shows only the M1 logo. Click/Enter/Space on it opens a small panel (logo +
|
||||
* the credit text); a click on the panel opens the website in a new tab.
|
||||
* Escape, a click anywhere else and a second logo click close the panel.
|
||||
* Nothing loads over the network: the logo is inlined from credit-data.js,
|
||||
* which the generator writes from kuhy_credit/credit.json and the M1 art.
|
||||
*
|
||||
* Attributes: `placement="above|below"` (default above), `align="end|start"`
|
||||
* (default end), `theme="light|dark"` (default: follow the page). Size via the
|
||||
* `--kuhy-credit-size` custom property (default 48px).
|
||||
*/
|
||||
import { CREDIT_TEXT, CREDIT_URL, LOGO_SVG, TOKENS } from "./credit-data.js";
|
||||
|
||||
const { dark, light } = TOKENS;
|
||||
const palette = (p, usePage) =>
|
||||
["surface", "border", "text"]
|
||||
.map((k) => {
|
||||
const page = { surface: "--surface-1", border: "--border", text: "--text" }[k];
|
||||
return `--kc-${k}: ${usePage ? `var(${page}, ${p[k]})` : p[k]};`;
|
||||
})
|
||||
.join(" ");
|
||||
|
||||
const STYLE = `
|
||||
:host { position: relative; display: inline-block; ${palette(dark, true)}
|
||||
--kc-size: var(--kuhy-credit-size, 48px); }
|
||||
@media (prefers-color-scheme: light) { :host { ${palette(light, true)} } }
|
||||
:host([theme="dark"]) { ${palette(dark, false)} }
|
||||
:host([theme="light"]) { ${palette(light, false)} }
|
||||
button, a { cursor: pointer; border-radius: var(--radius-sm, 8px); }
|
||||
button { display: block; padding: 0; border: 0; background: none;
|
||||
width: var(--kc-size); height: var(--kc-size); }
|
||||
svg { display: block; width: 100%; height: 100%; border-radius: inherit; }
|
||||
button:focus-visible, a:focus-visible {
|
||||
outline: 2px solid var(--focus-ring, ${TOKENS.focus}); outline-offset: 2px; }
|
||||
a { position: absolute; bottom: calc(100% + ${TOKENS.spaceSm}px); right: 0; z-index: 1000;
|
||||
display: flex; align-items: center; gap: ${TOKENS.spaceSm}px; padding: ${TOKENS.spaceMd}px;
|
||||
white-space: nowrap; text-decoration: none; color: var(--kc-text);
|
||||
background: var(--kc-surface); border: 1px solid var(--kc-border);
|
||||
border-radius: ${TOKENS.radius}px; box-shadow: var(--shadow-1, none);
|
||||
font: ${TOKENS.textBody}px/1.5 var(--font-sans, system-ui, sans-serif); }
|
||||
a[hidden] { display: none; }
|
||||
a svg { width: var(--kc-size); height: var(--kc-size); flex: none; }
|
||||
:host([placement="below"]) a { bottom: auto; top: calc(100% + ${TOKENS.spaceSm}px); }
|
||||
:host([align="start"]) a { right: auto; left: 0; }
|
||||
`;
|
||||
|
||||
export class KuhyCredit extends HTMLElement {
|
||||
#logo;
|
||||
#panel;
|
||||
#onDocClick = (event) => {
|
||||
if (this.open && !event.composedPath().includes(this)) this.close();
|
||||
};
|
||||
#onKey = (event) => {
|
||||
if (this.open && event.key === "Escape") {
|
||||
this.close();
|
||||
this.#logo.focus();
|
||||
}
|
||||
};
|
||||
|
||||
connectedCallback() {
|
||||
if (!this.shadowRoot) this.#build();
|
||||
document.addEventListener("click", this.#onDocClick);
|
||||
document.addEventListener("keydown", this.#onKey);
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
document.removeEventListener("click", this.#onDocClick);
|
||||
document.removeEventListener("keydown", this.#onKey);
|
||||
}
|
||||
|
||||
/** True while the panel is showing. */
|
||||
get open() {
|
||||
return !this.#panel.hidden;
|
||||
}
|
||||
|
||||
/** Hide the panel. */
|
||||
close() {
|
||||
this.#panel.hidden = true;
|
||||
this.#logo.setAttribute("aria-expanded", "false");
|
||||
}
|
||||
|
||||
#show() {
|
||||
this.#panel.hidden = false;
|
||||
this.#logo.setAttribute("aria-expanded", "true");
|
||||
this.#panel.focus();
|
||||
}
|
||||
|
||||
#build() {
|
||||
const root = this.attachShadow({ mode: "open" });
|
||||
root.innerHTML = `<style>${STYLE}</style>
|
||||
<button type="button" aria-expanded="false" aria-controls="panel"></button>
|
||||
<a id="panel" hidden target="_blank" rel="noopener noreferrer"><span></span></a>`;
|
||||
this.#logo = root.querySelector("button");
|
||||
this.#panel = root.querySelector("a");
|
||||
this.#logo.setAttribute("aria-label", CREDIT_TEXT);
|
||||
this.#logo.innerHTML = LOGO_SVG;
|
||||
this.#panel.href = CREDIT_URL;
|
||||
this.#panel.insertAdjacentHTML("afterbegin", LOGO_SVG);
|
||||
this.#panel.querySelector("span").textContent = CREDIT_TEXT;
|
||||
for (const svg of root.querySelectorAll("svg")) svg.setAttribute("aria-hidden", "true");
|
||||
this.#logo.addEventListener("click", () => (this.open ? this.close() : this.#show()));
|
||||
// Holding Enter on the logo opens the panel and focuses it; the key's
|
||||
// autorepeat must not then activate the link and open the site.
|
||||
this.#panel.addEventListener("keydown", (event) => {
|
||||
if (event.repeat && (event.key === "Enter" || event.key === " ")) event.preventDefault();
|
||||
});
|
||||
this.#panel.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
this.close();
|
||||
window.open(CREDIT_URL, "_blank", "noopener,noreferrer");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!customElements.get("kuhy-credit")) customElements.define("kuhy-credit", KuhyCredit);
|
||||
@ -1,148 +0,0 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { CREDIT_TEXT, CREDIT_URL, TOKENS } from "./credit-data.js";
|
||||
import { KuhyCredit } from "./kuhy-credit.js";
|
||||
|
||||
let host;
|
||||
let open;
|
||||
|
||||
const parts = () => ({
|
||||
logo: host.shadowRoot.querySelector("button"),
|
||||
panel: host.shadowRoot.querySelector("a"),
|
||||
});
|
||||
const click = (el) => el.dispatchEvent(new MouseEvent("click", { bubbles: true, composed: true, cancelable: true }));
|
||||
const key = (el, k) => el.dispatchEvent(new KeyboardEvent("keydown", { key: k, bubbles: true, composed: true }));
|
||||
|
||||
beforeEach(() => {
|
||||
open = vi.spyOn(window, "open").mockImplementation(() => null);
|
||||
host = document.createElement("kuhy-credit");
|
||||
document.body.append(host);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.replaceChildren();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("<kuhy-credit>", () => {
|
||||
it("registers once and shows only the logo", () => {
|
||||
expect(customElements.get("kuhy-credit")).toBe(KuhyCredit);
|
||||
const { logo, panel } = parts();
|
||||
expect(logo.querySelector("svg")).not.toBeNull();
|
||||
expect(logo.textContent.trim()).toBe("");
|
||||
expect(panel.hidden).toBe(true);
|
||||
expect(open).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("names the logo and the panel, and wires aria-expanded", () => {
|
||||
const { logo, panel } = parts();
|
||||
expect(logo.getAttribute("aria-label")).toBe(CREDIT_TEXT);
|
||||
expect(logo.getAttribute("aria-expanded")).toBe("false");
|
||||
expect(logo.getAttribute("aria-controls")).toBe(panel.id);
|
||||
expect(panel.textContent.trim()).toBe(CREDIT_TEXT);
|
||||
expect(panel.getAttribute("href")).toBe(CREDIT_URL);
|
||||
expect(panel.querySelector("svg").getAttribute("aria-hidden")).toBe("true");
|
||||
});
|
||||
|
||||
it("opens the panel on a logo click and the website on a panel click", () => {
|
||||
const { logo, panel } = parts();
|
||||
click(logo);
|
||||
expect(panel.hidden).toBe(false);
|
||||
expect(logo.getAttribute("aria-expanded")).toBe("true");
|
||||
expect(host.open).toBe(true);
|
||||
expect(open).not.toHaveBeenCalled();
|
||||
click(panel.querySelector("span"));
|
||||
expect(open).toHaveBeenCalledExactlyOnceWith(CREDIT_URL, "_blank", "noopener,noreferrer");
|
||||
expect(panel.hidden).toBe(true);
|
||||
});
|
||||
|
||||
it("closes on Escape and returns focus to the logo", () => {
|
||||
const { logo, panel } = parts();
|
||||
click(logo);
|
||||
key(document, "Escape");
|
||||
expect(panel.hidden).toBe(true);
|
||||
expect(host.shadowRoot.activeElement).toBe(logo);
|
||||
expect(open).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores a held (repeating) Enter or Space on the panel", () => {
|
||||
const { logo, panel } = parts();
|
||||
click(logo);
|
||||
for (const k of ["Enter", " "]) {
|
||||
const held = new KeyboardEvent("keydown", { key: k, repeat: true, bubbles: true, cancelable: true });
|
||||
panel.dispatchEvent(held);
|
||||
expect(held.defaultPrevented).toBe(true);
|
||||
}
|
||||
const fresh = new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true });
|
||||
panel.dispatchEvent(fresh);
|
||||
expect(fresh.defaultPrevented).toBe(false);
|
||||
const heldOther = new KeyboardEvent("keydown", { key: "a", repeat: true, bubbles: true, cancelable: true });
|
||||
panel.dispatchEvent(heldOther);
|
||||
expect(heldOther.defaultPrevented).toBe(false);
|
||||
});
|
||||
|
||||
it("ignores other keys and Escape while closed", () => {
|
||||
const { logo, panel } = parts();
|
||||
key(document, "Escape");
|
||||
click(logo);
|
||||
key(document, "Enter");
|
||||
expect(panel.hidden).toBe(false);
|
||||
});
|
||||
|
||||
it("closes on a click outside", () => {
|
||||
const { logo, panel } = parts();
|
||||
click(logo);
|
||||
click(document.body);
|
||||
expect(panel.hidden).toBe(true);
|
||||
expect(open).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores outside clicks while closed", () => {
|
||||
click(document.body);
|
||||
expect(parts().panel.hidden).toBe(true);
|
||||
});
|
||||
|
||||
it("closes on a second logo click and stays closed", () => {
|
||||
const { logo, panel } = parts();
|
||||
click(logo);
|
||||
click(logo);
|
||||
expect(panel.hidden).toBe(true);
|
||||
expect(open).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("focuses the panel link when it opens", () => {
|
||||
const { logo, panel } = parts();
|
||||
click(logo);
|
||||
expect(host.shadowRoot.activeElement).toBe(panel);
|
||||
});
|
||||
|
||||
it("stops listening once removed from the page", () => {
|
||||
const { logo, panel } = parts();
|
||||
click(logo);
|
||||
host.remove();
|
||||
click(document.body);
|
||||
expect(panel.hidden).toBe(false);
|
||||
});
|
||||
|
||||
it("does not redefine the element when loaded twice", async () => {
|
||||
const again = await import("./kuhy-credit.js?again");
|
||||
expect(customElements.get("kuhy-credit")).toBe(KuhyCredit);
|
||||
expect(again.KuhyCredit).not.toBe(KuhyCredit);
|
||||
});
|
||||
|
||||
it("builds its shadow DOM only once when re-attached", () => {
|
||||
host.remove();
|
||||
document.body.append(host);
|
||||
expect(host.shadowRoot.querySelectorAll("button")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("styles from the design tokens with dark and light fallbacks", () => {
|
||||
const css = host.shadowRoot.querySelector("style").textContent;
|
||||
for (const value of [TOKENS.dark.surface, TOKENS.light.surface, TOKENS.dark.text, TOKENS.light.text, TOKENS.focus]) {
|
||||
expect(css).toContain(value);
|
||||
}
|
||||
expect(css).toContain("var(--surface-1");
|
||||
expect(css).toContain("prefers-color-scheme: light");
|
||||
expect(css).toContain(`${TOKENS.radius}px`);
|
||||
});
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
include: ["src/kuhy-credit.js"],
|
||||
provider: "v8",
|
||||
thresholds: { branches: 100, functions: 100, lines: 100, statements: 100 },
|
||||
},
|
||||
environment: "jsdom",
|
||||
include: ["src/**/*.test.js"],
|
||||
},
|
||||
});
|
||||
@ -103,7 +103,6 @@ verify() {
|
||||
check_tag game-recording game_recording
|
||||
check_tag godot-dev-tools godot_dev_tools
|
||||
check_tag app-errors app_errors
|
||||
check_tag kuhy-credit kuhy_credit
|
||||
check_sickdays
|
||||
check_app_errors
|
||||
if [[ "$FAILED" -ne 0 ]]; then
|
||||
|
||||