@skillcdn/console 0.4.7 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -14
- package/SKILLCDN.md +5 -3
- package/dist/agent-page.d.ts +44 -0
- package/dist/agent-page.d.ts.map +1 -0
- package/dist/agent-page.js +415 -0
- package/dist/agent-page.js.map +1 -0
- package/dist/agent-stream.d.ts +52 -0
- package/dist/agent-stream.d.ts.map +1 -0
- package/dist/agent-stream.js +155 -0
- package/dist/agent-stream.js.map +1 -0
- package/dist/api.d.ts +12 -6
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +11 -5
- package/dist/api.js.map +1 -1
- package/dist/avatar.d.ts +137 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +1216 -0
- package/dist/avatar.js.map +1 -0
- package/dist/charts.d.ts +103 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +182 -0
- package/dist/charts.js.map +1 -0
- package/dist/cli/cli.d.ts +39 -1
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +2424 -296
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command-words.d.ts +20 -0
- package/dist/cli/command-words.d.ts.map +1 -0
- package/dist/cli/command-words.js +51 -0
- package/dist/cli/command-words.js.map +1 -0
- package/dist/cli/credentials.d.ts +59 -5
- package/dist/cli/credentials.d.ts.map +1 -1
- package/dist/cli/credentials.js +128 -16
- package/dist/cli/credentials.js.map +1 -1
- package/dist/cli/directory.d.ts +19 -4
- package/dist/cli/directory.d.ts.map +1 -1
- package/dist/cli/directory.js +16 -8
- package/dist/cli/directory.js.map +1 -1
- package/dist/cli/format.d.ts +91 -8
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +386 -57
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts +13 -4
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +202 -62
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/main.js +94 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/pack.d.ts +69 -36
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +241 -188
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/plugin-check.d.ts +42 -0
- package/dist/cli/plugin-check.d.ts.map +1 -1
- package/dist/cli/plugin-check.js +221 -36
- package/dist/cli/plugin-check.js.map +1 -1
- package/dist/cli/plugin-cli.d.ts +6 -1
- package/dist/cli/plugin-cli.d.ts.map +1 -1
- package/dist/cli/plugin-cli.js +21 -4
- package/dist/cli/plugin-cli.js.map +1 -1
- package/dist/cli/plugin-main.js +1 -0
- package/dist/cli/plugin-main.js.map +1 -1
- package/dist/cli/runner-host.d.ts +36 -0
- package/dist/cli/runner-host.d.ts.map +1 -0
- package/dist/cli/runner-host.js +154 -0
- package/dist/cli/runner-host.js.map +1 -0
- package/dist/cli/serve.d.ts +33 -1
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +275 -6
- package/dist/cli/serve.js.map +1 -1
- package/dist/cli/setup-machine.d.ts +36 -0
- package/dist/cli/setup-machine.d.ts.map +1 -0
- package/dist/cli/setup-machine.js +109 -0
- package/dist/cli/setup-machine.js.map +1 -0
- package/dist/client.d.ts +189 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +192 -57
- package/dist/client.js.map +1 -1
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +2 -2
- package/dist/components/agent-page.d.ts +384 -0
- package/dist/components/agent-page.d.ts.map +1 -0
- package/dist/components/agent-page.js +985 -0
- package/dist/components/agent-page.js.map +1 -0
- package/dist/components/agents.d.ts +102 -0
- package/dist/components/agents.d.ts.map +1 -0
- package/dist/components/agents.js +246 -0
- package/dist/components/agents.js.map +1 -0
- package/dist/components/calendar.d.ts +17 -17
- package/dist/components/calendar.d.ts.map +1 -1
- package/dist/components/calendar.js +7 -2
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/charts.d.ts +157 -0
- package/dist/components/charts.d.ts.map +1 -0
- package/dist/components/charts.js +182 -0
- package/dist/components/charts.js.map +1 -0
- package/dist/components/comments.d.ts +2 -0
- package/dist/components/comments.d.ts.map +1 -1
- package/dist/components/comments.js +1 -1
- package/dist/components/comments.js.map +1 -1
- package/dist/components/connect.d.ts.map +1 -1
- package/dist/components/connect.js +7 -2
- package/dist/components/connect.js.map +1 -1
- package/dist/components/decision-form.d.ts +21 -0
- package/dist/components/decision-form.d.ts.map +1 -1
- package/dist/components/decision-form.js +20 -6
- package/dist/components/decision-form.js.map +1 -1
- package/dist/components/decision-list.d.ts +24 -0
- package/dist/components/decision-list.d.ts.map +1 -1
- package/dist/components/decision-list.js +54 -5
- package/dist/components/decision-list.js.map +1 -1
- package/dist/components/desk-records.d.ts +102 -0
- package/dist/components/desk-records.d.ts.map +1 -0
- package/dist/components/desk-records.js +221 -0
- package/dist/components/desk-records.js.map +1 -0
- package/dist/components/desk.d.ts +85 -0
- package/dist/components/desk.d.ts.map +1 -0
- package/dist/components/desk.js +135 -0
- package/dist/components/desk.js.map +1 -0
- package/dist/components/event-feed.d.ts.map +1 -1
- package/dist/components/event-feed.js +26 -1
- package/dist/components/event-feed.js.map +1 -1
- package/dist/components/home.d.ts +12 -1
- package/dist/components/home.d.ts.map +1 -1
- package/dist/components/home.js +175 -16
- package/dist/components/home.js.map +1 -1
- package/dist/components/my-decisions.d.ts +5 -0
- package/dist/components/my-decisions.d.ts.map +1 -1
- package/dist/components/my-decisions.js +3 -3
- package/dist/components/my-decisions.js.map +1 -1
- package/dist/components/people.d.ts +17 -0
- package/dist/components/people.d.ts.map +1 -1
- package/dist/components/people.js +55 -19
- package/dist/components/people.js.map +1 -1
- package/dist/components/picker.d.ts +2 -0
- package/dist/components/picker.d.ts.map +1 -1
- package/dist/components/picker.js +1 -1
- package/dist/components/picker.js.map +1 -1
- package/dist/components/pictures.d.ts +38 -10
- package/dist/components/pictures.d.ts.map +1 -1
- package/dist/components/pictures.js +195 -40
- package/dist/components/pictures.js.map +1 -1
- package/dist/components/plugin-events.d.ts +29 -0
- package/dist/components/plugin-events.d.ts.map +1 -0
- package/dist/components/plugin-events.js +139 -0
- package/dist/components/plugin-events.js.map +1 -0
- package/dist/components/plugin-frame.d.ts.map +1 -1
- package/dist/components/plugin-frame.js +14 -37
- package/dist/components/plugin-frame.js.map +1 -1
- package/dist/components/plugin-settings.d.ts.map +1 -1
- package/dist/components/plugin-settings.js +58 -7
- package/dist/components/plugin-settings.js.map +1 -1
- package/dist/components/projects.d.ts.map +1 -1
- package/dist/components/projects.js +30 -10
- package/dist/components/projects.js.map +1 -1
- package/dist/components/rules.d.ts +8 -10
- package/dist/components/rules.d.ts.map +1 -1
- package/dist/components/rules.js +36 -14
- package/dist/components/rules.js.map +1 -1
- package/dist/components/sessions.d.ts.map +1 -1
- package/dist/components/sessions.js +8 -4
- package/dist/components/sessions.js.map +1 -1
- package/dist/components/setup.d.ts +59 -0
- package/dist/components/setup.d.ts.map +1 -0
- package/dist/components/setup.js +93 -0
- package/dist/components/setup.js.map +1 -0
- package/dist/components/sign-in.js +1 -1
- package/dist/components/sign-in.js.map +1 -1
- package/dist/components/task-form.d.ts.map +1 -1
- package/dist/components/task-form.js +2 -2
- package/dist/components/task-form.js.map +1 -1
- package/dist/components/task-list.d.ts +7 -6
- package/dist/components/task-list.d.ts.map +1 -1
- package/dist/components/task-list.js.map +1 -1
- package/dist/components/task-view.d.ts +3 -0
- package/dist/components/task-view.d.ts.map +1 -1
- package/dist/components/task-view.js +1 -1
- package/dist/components/task-view.js.map +1 -1
- package/dist/components/ui.d.ts +78 -8
- package/dist/components/ui.d.ts.map +1 -1
- package/dist/components/ui.js +88 -9
- package/dist/components/ui.js.map +1 -1
- package/dist/components/work.d.ts +5 -5
- package/dist/components/work.d.ts.map +1 -1
- package/dist/components/work.js.map +1 -1
- package/dist/components/workspace.d.ts +17 -0
- package/dist/components/workspace.d.ts.map +1 -1
- package/dist/components/workspace.js +129 -2
- package/dist/components/workspace.js.map +1 -1
- package/dist/connect-page.d.ts.map +1 -1
- package/dist/connect-page.js +5 -2
- package/dist/connect-page.js.map +1 -1
- package/dist/console.css +7551 -4580
- package/dist/console.d.ts +20 -0
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +331 -57
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts +22 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +62 -34
- package/dist/data.js.map +1 -1
- package/dist/desk-page.d.ts +38 -0
- package/dist/desk-page.d.ts.map +1 -0
- package/dist/desk-page.js +184 -0
- package/dist/desk-page.js.map +1 -0
- package/dist/desk-records-page.d.ts +18 -0
- package/dist/desk-records-page.d.ts.map +1 -0
- package/dist/desk-records-page.js +130 -0
- package/dist/desk-records-page.js.map +1 -0
- package/dist/desk-records.d.ts +247 -0
- package/dist/desk-records.d.ts.map +1 -0
- package/dist/desk-records.js +543 -0
- package/dist/desk-records.js.map +1 -0
- package/dist/desk.d.ts +122 -0
- package/dist/desk.d.ts.map +1 -0
- package/dist/desk.js +211 -0
- package/dist/desk.js.map +1 -0
- package/dist/feed-stream.d.ts +39 -0
- package/dist/feed-stream.d.ts.map +1 -0
- package/dist/feed-stream.js +117 -0
- package/dist/feed-stream.js.map +1 -0
- package/dist/glances.d.ts +39 -0
- package/dist/glances.d.ts.map +1 -0
- package/dist/glances.js +94 -0
- package/dist/glances.js.map +1 -0
- package/dist/home-tiles.d.ts +69 -5
- package/dist/home-tiles.d.ts.map +1 -1
- package/dist/home-tiles.js +347 -9
- package/dist/home-tiles.js.map +1 -1
- package/dist/i18n/en.d.ts +773 -3
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +770 -9
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +736 -9
- package/dist/i18n/ko.js.map +1 -1
- package/dist/index.d.ts +19 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +67 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +67 -0
- package/dist/limits.js.map +1 -1
- package/dist/onboarding.d.ts +21 -0
- package/dist/onboarding.d.ts.map +1 -0
- package/dist/onboarding.js +43 -0
- package/dist/onboarding.js.map +1 -0
- package/dist/persona.d.ts +34 -0
- package/dist/persona.d.ts.map +1 -0
- package/dist/persona.js +71 -0
- package/dist/persona.js.map +1 -0
- package/dist/plugin/context.d.ts +42 -11
- package/dist/plugin/context.d.ts.map +1 -1
- package/dist/plugin/limits.d.ts +2 -0
- package/dist/plugin/limits.d.ts.map +1 -1
- package/dist/plugin/limits.js +2 -0
- package/dist/plugin/limits.js.map +1 -1
- package/dist/plugin/manifest.d.ts +13 -0
- package/dist/plugin/manifest.d.ts.map +1 -1
- package/dist/plugin/manifest.js +34 -4
- package/dist/plugin/manifest.js.map +1 -1
- package/dist/plugin/rest-schemas.d.ts +56 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -1
- package/dist/plugin/rest-schemas.js +42 -0
- package/dist/plugin/rest-schemas.js.map +1 -1
- package/dist/plugin/sandbox.d.ts.map +1 -1
- package/dist/plugin/sandbox.js +4 -1
- package/dist/plugin/sandbox.js.map +1 -1
- package/dist/plugin/testing.d.ts +6 -2
- package/dist/plugin/testing.d.ts.map +1 -1
- package/dist/plugin/testing.js +52 -10
- package/dist/plugin/testing.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/records.d.ts +283 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +543 -0
- package/dist/records.js.map +1 -0
- package/dist/router.d.ts +50 -3
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +78 -7
- package/dist/router.js.map +1 -1
- package/dist/routes.d.ts +12 -2
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +14 -1
- package/dist/routes.js.map +1 -1
- package/dist/rules.d.ts +30 -11
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +99 -42
- package/dist/rules.js.map +1 -1
- package/dist/runner/acp.d.ts +20 -0
- package/dist/runner/acp.d.ts.map +1 -0
- package/dist/runner/acp.js +1132 -0
- package/dist/runner/acp.js.map +1 -0
- package/dist/runner/claude.d.ts +13 -0
- package/dist/runner/claude.d.ts.map +1 -0
- package/dist/runner/claude.js +615 -0
- package/dist/runner/claude.js.map +1 -0
- package/dist/runner/codex.d.ts +19 -0
- package/dist/runner/codex.d.ts.map +1 -0
- package/dist/runner/codex.js +597 -0
- package/dist/runner/codex.js.map +1 -0
- package/dist/runner/config.d.ts +35 -0
- package/dist/runner/config.d.ts.map +1 -0
- package/dist/runner/config.js +74 -0
- package/dist/runner/config.js.map +1 -0
- package/dist/runner/desk.d.ts +81 -0
- package/dist/runner/desk.d.ts.map +1 -0
- package/dist/runner/desk.js +303 -0
- package/dist/runner/desk.js.map +1 -0
- package/dist/runner/launchd.d.ts +7 -0
- package/dist/runner/launchd.d.ts.map +1 -0
- package/dist/runner/launchd.js +78 -0
- package/dist/runner/launchd.js.map +1 -0
- package/dist/runner/message.d.ts +66 -0
- package/dist/runner/message.d.ts.map +1 -0
- package/dist/runner/message.js +181 -0
- package/dist/runner/message.js.map +1 -0
- package/dist/runner/modules.d.ts +13 -0
- package/dist/runner/modules.d.ts.map +1 -0
- package/dist/runner/modules.js +30 -0
- package/dist/runner/modules.js.map +1 -0
- package/dist/runner/process.d.ts +7 -0
- package/dist/runner/process.d.ts.map +1 -0
- package/dist/runner/process.js +65 -0
- package/dist/runner/process.js.map +1 -0
- package/dist/runner/redact.d.ts +48 -0
- package/dist/runner/redact.d.ts.map +1 -0
- package/dist/runner/redact.js +214 -0
- package/dist/runner/redact.js.map +1 -0
- package/dist/runner/registry.d.ts +37 -0
- package/dist/runner/registry.d.ts.map +1 -0
- package/dist/runner/registry.js +26 -0
- package/dist/runner/registry.js.map +1 -0
- package/dist/runner/runner.d.ts +130 -0
- package/dist/runner/runner.d.ts.map +1 -0
- package/dist/runner/runner.js +1551 -0
- package/dist/runner/runner.js.map +1 -0
- package/dist/runner/slack.d.ts +16 -0
- package/dist/runner/slack.d.ts.map +1 -0
- package/dist/runner/slack.js +157 -0
- package/dist/runner/slack.js.map +1 -0
- package/dist/runner/systemd-user.d.ts +7 -0
- package/dist/runner/systemd-user.d.ts.map +1 -0
- package/dist/runner/systemd-user.js +93 -0
- package/dist/runner/systemd-user.js.map +1 -0
- package/dist/runner/task-scheduler.d.ts +38 -0
- package/dist/runner/task-scheduler.d.ts.map +1 -0
- package/dist/runner/task-scheduler.js +216 -0
- package/dist/runner/task-scheduler.js.map +1 -0
- package/dist/runner/types.d.ts +315 -0
- package/dist/runner/types.d.ts.map +1 -0
- package/dist/runner/types.js +24 -0
- package/dist/runner/types.js.map +1 -0
- package/dist/runner.d.ts +18 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +20 -0
- package/dist/runner.js.map +1 -0
- package/dist/schemas.d.ts +6082 -1295
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +930 -31
- package/dist/schemas.js.map +1 -1
- package/dist/services.d.ts +110 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +305 -0
- package/dist/services.js.map +1 -0
- package/dist/setup-guide.d.ts +64 -0
- package/dist/setup-guide.d.ts.map +1 -0
- package/dist/setup-guide.js +256 -0
- package/dist/setup-guide.js.map +1 -0
- package/dist/setup-page.d.ts +6 -0
- package/dist/setup-page.d.ts.map +1 -0
- package/dist/setup-page.js +29 -0
- package/dist/setup-page.js.map +1 -0
- package/dist/sse.d.ts +15 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +73 -0
- package/dist/sse.js.map +1 -0
- package/dist/tab-title.d.ts +6 -0
- package/dist/tab-title.d.ts.map +1 -0
- package/dist/tab-title.js +22 -0
- package/dist/tab-title.js.map +1 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +3 -0
- package/dist/tokens.js.map +1 -1
- package/dist/use-action.d.ts +5 -2
- package/dist/use-action.d.ts.map +1 -1
- package/dist/use-action.js +6 -1
- package/dist/use-action.js.map +1 -1
- package/dist/vocabulary.d.ts +84 -4
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +115 -3
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +147 -41
- package/docs/specs/plugins.md +37 -27
- package/docs/specs/records.md +113 -0
- package/docs/specs/rest.md +155 -20
- package/docs/specs/runner.md +347 -0
- package/package.json +12 -3
- package/skills/building-a-console/SKILL.md +4 -4
- package/skills/building-a-console/references/configuring.md +1 -0
- package/skills/building-a-plugin/SKILL.md +7 -7
- package/skills/deploying-a-console/SKILL.md +4 -4
- package/skills/deploying-a-console/references/resources.md +48 -8
- package/skills/deploying-a-console/references/running-it-again.md +3 -2
- package/skills/keeping-a-desk/SKILL.md +133 -0
- package/skills/keeping-a-desk/collections.md +96 -0
- package/skills/planning-the-board/SKILL.md +14 -18
- package/skills/planning-the-board/references/a-task.md +2 -2
- package/skills/planning-the-board/references/project-rules.md +13 -14
- package/skills/planning-the-board/references/setting-up.md +22 -9
- package/skills/running-an-agent/SKILL.md +107 -0
- package/skills/running-an-agent/references/slack-app.md +61 -0
- package/skills/working-the-board/SKILL.md +66 -39
- package/skills/working-the-board/references/terms.md +9 -5
- package/skills/working-the-board/references/the-pack.md +14 -9
- package/skills/working-the-board/references/the-sentence.md +2 -2
- package/src/agent-page.tsx +1039 -0
- package/src/agent-stream.ts +199 -0
- package/src/api.ts +317 -2
- package/src/avatar.ts +1506 -0
- package/src/charts.ts +250 -0
- package/src/cli/cli.ts +3210 -503
- package/src/cli/command-words.ts +56 -0
- package/src/cli/credentials.ts +188 -16
- package/src/cli/directory.ts +28 -10
- package/src/cli/format.ts +470 -67
- package/src/cli/help.ts +233 -61
- package/src/cli/main.ts +89 -0
- package/src/cli/pack.ts +332 -263
- package/src/cli/plugin-check.ts +275 -34
- package/src/cli/plugin-cli.ts +28 -4
- package/src/cli/plugin-main.ts +1 -0
- package/src/cli/runner-host.ts +188 -0
- package/src/cli/serve.ts +320 -5
- package/src/cli/setup-machine.ts +153 -0
- package/src/client.ts +711 -126
- package/src/compat.ts +2 -2
- package/src/components/agent-page.tsx +1946 -0
- package/src/components/agents.tsx +638 -0
- package/src/components/calendar.tsx +74 -53
- package/src/components/charts.tsx +680 -0
- package/src/components/comments.tsx +3 -0
- package/src/components/connect.tsx +37 -2
- package/src/components/decision-form.tsx +89 -51
- package/src/components/decision-list.tsx +140 -4
- package/src/components/desk-records.tsx +724 -0
- package/src/components/desk.tsx +471 -0
- package/src/components/event-feed.tsx +30 -1
- package/src/components/home.tsx +353 -12
- package/src/components/my-decisions.tsx +8 -2
- package/src/components/people.tsx +300 -203
- package/src/components/picker.tsx +3 -1
- package/src/components/pictures.tsx +256 -44
- package/src/components/plugin-events.ts +159 -0
- package/src/components/plugin-frame.tsx +14 -38
- package/src/components/plugin-settings.tsx +178 -22
- package/src/components/projects.tsx +33 -15
- package/src/components/rules.tsx +96 -36
- package/src/components/sessions.tsx +7 -4
- package/src/components/setup.tsx +252 -0
- package/src/components/sign-in.tsx +1 -1
- package/src/components/task-form.tsx +11 -2
- package/src/components/task-list.tsx +7 -6
- package/src/components/task-view.tsx +4 -0
- package/src/components/ui.tsx +169 -25
- package/src/components/work.tsx +9 -9
- package/src/components/workspace.tsx +345 -4
- package/src/connect-page.tsx +15 -2
- package/src/console.tsx +657 -83
- package/src/data.ts +109 -43
- package/src/desk-page.tsx +332 -0
- package/src/desk-records-page.tsx +256 -0
- package/src/desk-records.ts +808 -0
- package/src/desk.ts +329 -0
- package/src/feed-stream.ts +144 -0
- package/src/glances.ts +132 -0
- package/src/home-tiles.ts +411 -9
- package/src/i18n/en.ts +828 -10
- package/src/i18n/ko.ts +792 -10
- package/src/index.ts +172 -3
- package/src/limits.ts +67 -0
- package/src/onboarding.ts +84 -0
- package/src/persona.ts +100 -0
- package/src/plugin/context.ts +55 -12
- package/src/plugin/limits.ts +2 -0
- package/src/plugin/manifest.ts +42 -3
- package/src/plugin/rest-schemas.ts +46 -0
- package/src/plugin/sandbox.ts +4 -1
- package/src/plugin/testing.ts +63 -12
- package/src/plugin.ts +2 -0
- package/src/records.ts +702 -0
- package/src/router.ts +120 -10
- package/src/routes.ts +17 -1
- package/src/rules.ts +109 -44
- package/src/runner/acp.ts +1267 -0
- package/src/runner/claude.ts +695 -0
- package/src/runner/codex.ts +691 -0
- package/src/runner/config.ts +97 -0
- package/src/runner/desk.ts +377 -0
- package/src/runner/launchd.ts +86 -0
- package/src/runner/message.ts +232 -0
- package/src/runner/modules.ts +30 -0
- package/src/runner/process.ts +72 -0
- package/src/runner/redact.ts +242 -0
- package/src/runner/registry.ts +67 -0
- package/src/runner/runner.ts +1879 -0
- package/src/runner/slack.ts +180 -0
- package/src/runner/systemd-user.ts +103 -0
- package/src/runner/task-scheduler.ts +236 -0
- package/src/runner/types.ts +334 -0
- package/src/runner.ts +110 -0
- package/src/schemas.ts +1183 -30
- package/src/services.ts +424 -0
- package/src/setup-guide.ts +336 -0
- package/src/setup-page.tsx +46 -0
- package/src/sse.ts +84 -0
- package/src/styles/README.md +111 -0
- package/src/styles/base.css +130 -0
- package/src/styles/console.css +85 -7095
- package/src/styles/drawn-by-pages.json +256 -0
- package/src/styles/pages/agents.css +1195 -0
- package/src/styles/pages/board.css +380 -0
- package/src/styles/pages/calendar.css +214 -0
- package/src/styles/pages/connect.css +182 -0
- package/src/styles/pages/decisions.css +370 -0
- package/src/styles/pages/desk.css +126 -0
- package/src/styles/pages/documents.css +273 -0
- package/src/styles/pages/feed.css +118 -0
- package/src/styles/pages/home.css +718 -0
- package/src/styles/pages/people.css +90 -0
- package/src/styles/pages/plugins.css +212 -0
- package/src/styles/pages/roadmap.css +377 -0
- package/src/styles/pages/settings.css +171 -0
- package/src/styles/pages/shell.css +208 -0
- package/src/styles/pages/sign-in.css +178 -0
- package/src/styles/pages/task.css +108 -0
- package/src/styles/pages/thread.css +331 -0
- package/src/styles/pages/work.css +68 -0
- package/src/styles/parts/avatar.css +82 -0
- package/src/styles/parts/badge.css +227 -0
- package/src/styles/parts/bars.css +80 -0
- package/src/styles/parts/button.css +99 -0
- package/src/styles/parts/calendar.css +547 -0
- package/src/styles/parts/callout.css +41 -0
- package/src/styles/parts/category.css +8 -0
- package/src/styles/parts/chart.css +173 -0
- package/src/styles/parts/chip.css +90 -0
- package/src/styles/parts/code.css +48 -0
- package/src/styles/parts/count.css +27 -0
- package/src/styles/parts/crumbs.css +61 -0
- package/src/styles/parts/detail.css +110 -0
- package/src/styles/parts/empty.css +21 -0
- package/src/styles/parts/eyebrow.css +9 -0
- package/src/styles/parts/facts.css +147 -0
- package/src/styles/parts/figures.css +65 -0
- package/src/styles/parts/files.css +38 -0
- package/src/styles/parts/filters.css +42 -0
- package/src/styles/parts/form.css +109 -0
- package/src/styles/parts/frame.css +45 -0
- package/src/styles/parts/input.css +243 -0
- package/src/styles/parts/legend.css +48 -0
- package/src/styles/parts/links.css +37 -0
- package/src/styles/parts/mark.css +79 -0
- package/src/styles/parts/menu.css +147 -0
- package/src/styles/parts/page.css +174 -0
- package/src/styles/parts/pager.css +19 -0
- package/src/styles/parts/panel.css +33 -0
- package/src/styles/parts/person.css +257 -0
- package/src/styles/parts/picker.css +185 -0
- package/src/styles/parts/progress.css +25 -0
- package/src/styles/parts/prose.css +128 -0
- package/src/styles/parts/rows.css +63 -0
- package/src/styles/parts/series.css +32 -0
- package/src/styles/parts/settings.css +101 -0
- package/src/styles/parts/share.css +25 -0
- package/src/styles/parts/spark.css +23 -0
- package/src/styles/parts/spinner.css +29 -0
- package/src/styles/parts/stat.css +69 -0
- package/src/styles/parts/steps.css +68 -0
- package/src/styles/parts/tabs.css +175 -0
- package/src/styles/parts/text.css +61 -0
- package/src/styles/parts/toggle.css +71 -0
- package/src/styles/parts/workers.css +37 -0
- package/src/styles/tokens.css +295 -0
- package/src/tab-title.ts +25 -0
- package/src/tokens.ts +3 -0
- package/src/use-action.ts +7 -2
- package/src/vocabulary.ts +151 -3
- package/template/desk-web/README.md +8 -0
- package/template/desk-web/index.html +13 -0
- package/template/desk-web/package.json +25 -0
- package/template/desk-web/src/main.tsx +24 -0
- package/template/desk-web/src/page.tsx +51 -0
- package/template/desk-web/tsconfig.json +16 -0
- package/template/desk-web/vite.config.ts +15 -0
package/src/avatar.ts
ADDED
|
@@ -0,0 +1,1506 @@
|
|
|
1
|
+
// An agent account's avatar (ADR-0084, ADR-0097, ADR-0102): a small planet, flat and of two tones.
|
|
2
|
+
// A body, what lies on its surface, the ramp of colours both are drawn in, and one thing beside
|
|
3
|
+
// it or nothing, on a graphite ground with a few faint squares strewn over it. Its parts are
|
|
4
|
+
// a few numbers, each a place in a set, and this module draws the picture from them wherever it
|
|
5
|
+
// is shown and writes it out as a picture file where one is needed. Nothing drawn is kept: a
|
|
6
|
+
// person object carries the parts, some seventy bytes, and whoever shows the picture draws it.
|
|
7
|
+
//
|
|
8
|
+
// A set is data: outlines in a square of a hundred units a side, each filled in two tones, the
|
|
9
|
+
// lighter left of a line down it and the darker right. The module fills them itself, by how much
|
|
10
|
+
// of each pixel an outline covers, with no renderer of anyone else's, in the browser and in the
|
|
11
|
+
// command alike, and the same parts give the same pixels on every machine: nothing here is
|
|
12
|
+
// computed with a function a runtime may round its own way (no sine of the runtime's, no
|
|
13
|
+
// exponential), only with sums, products and square roots. The sine a curve is laid out with is
|
|
14
|
+
// a series written here.
|
|
15
|
+
//
|
|
16
|
+
// A released set never changes: a new look is a new version, and an avatar keeps the version it
|
|
17
|
+
// was made with. What is added to this file is a set, never a change to one.
|
|
18
|
+
|
|
19
|
+
import type { RestAvatarParts } from "./schemas.js";
|
|
20
|
+
|
|
21
|
+
/** A colour: red, green and blue, each from 0 to 255. */
|
|
22
|
+
export type AvatarColor = readonly [number, number, number];
|
|
23
|
+
|
|
24
|
+
/** A corner of an outline: across and down, in the picture's own units, from its top left. */
|
|
25
|
+
export type AvatarPoint = readonly [number, number];
|
|
26
|
+
|
|
27
|
+
/** A closed outline, its corners in turn. A curve is as many short sides as it takes. */
|
|
28
|
+
export type AvatarOutline = readonly AvatarPoint[];
|
|
29
|
+
|
|
30
|
+
/** A ramp: the tones of one colour from the lightest to the darkest, each as `#rrggbb`. */
|
|
31
|
+
export interface AvatarRamp {
|
|
32
|
+
readonly tones: readonly string[];
|
|
33
|
+
/** The place in the set of the ramp that goes with this one: what stands beside a body of it is drawn in that. */
|
|
34
|
+
readonly partner: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* One thing drawn: outlines filled together, in two tones of a ramp, the lighter left of the
|
|
39
|
+
* line at `split` and the next darker right of it. Outlines that run the same way round add up
|
|
40
|
+
* to one shape, and one that runs the other way round cuts a hole in what it lies in, as the
|
|
41
|
+
* inner oval of a ring does.
|
|
42
|
+
*/
|
|
43
|
+
export interface AvatarShape {
|
|
44
|
+
readonly outlines: readonly AvatarOutline[];
|
|
45
|
+
/** The place in the ramp of the tone left of the line; right of it, the next. */
|
|
46
|
+
readonly tone: number;
|
|
47
|
+
/** Two colours of the shape's own in place of the ramp's, left and right, each as `#rrggbb`. */
|
|
48
|
+
readonly colors?: readonly [string, string] | undefined;
|
|
49
|
+
/** Where the two tones meet, across; the middle where left out. */
|
|
50
|
+
readonly split?: number | undefined;
|
|
51
|
+
/** How much of the shape covers what is behind it, from 0 to 1; all of it where left out. */
|
|
52
|
+
readonly opacity?: number | undefined;
|
|
53
|
+
/** A line of the ground's colour round the shape, this wide, half of it outside: the shape stands off what it lies over. */
|
|
54
|
+
readonly gap?: number | undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Shapes drawn together: turned about the middle of the picture, and cut to its upper or its lower half where it says so. */
|
|
58
|
+
export interface AvatarLayer {
|
|
59
|
+
readonly shapes: readonly AvatarShape[];
|
|
60
|
+
/** Degrees the shapes are turned by, clockwise as the picture is looked at. */
|
|
61
|
+
readonly turn?: number | undefined;
|
|
62
|
+
/** The half of the picture the shapes are kept to, as they lie before they are turned. */
|
|
63
|
+
readonly half?: "upper" | "lower" | undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A body: its outlines, filled as a shape's are, and what is drawn behind it in its own ramp, an atmosphere say. */
|
|
67
|
+
export interface AvatarBody {
|
|
68
|
+
readonly outlines: readonly AvatarOutline[];
|
|
69
|
+
readonly behind?: readonly AvatarShape[] | undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A surface: the tone the whole body has, and what lies on it, cut to the body. */
|
|
73
|
+
export interface AvatarSurface {
|
|
74
|
+
readonly tone: number;
|
|
75
|
+
readonly shapes: readonly AvatarShape[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** What stands beside a body, in the ramp that goes with the body's: what of it is behind the body, and what before it. */
|
|
79
|
+
export interface AvatarAccent {
|
|
80
|
+
readonly behind: readonly AvatarLayer[];
|
|
81
|
+
readonly before: readonly AvatarLayer[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A set: its version, and the choices of each part. The first accent is nothing, by convention,
|
|
86
|
+
* and is rolled more often than any other.
|
|
87
|
+
*/
|
|
88
|
+
export interface AvatarSet {
|
|
89
|
+
readonly version: number;
|
|
90
|
+
/** The colours the picture is filled with behind everything, each as `#rrggbb`. */
|
|
91
|
+
readonly grounds: readonly string[];
|
|
92
|
+
/** The colours of the faint squares strewn over the ground. */
|
|
93
|
+
readonly confetti: readonly string[];
|
|
94
|
+
readonly ramps: readonly AvatarRamp[];
|
|
95
|
+
readonly bodies: readonly AvatarBody[];
|
|
96
|
+
readonly surfaces: readonly AvatarSurface[];
|
|
97
|
+
readonly accents: readonly AvatarAccent[];
|
|
98
|
+
/**
|
|
99
|
+
* How much larger than its outlines are written a planet is drawn, at every size and never past
|
|
100
|
+
* what stands beside it leaves room for; as written where the set says nothing (ADR-0099).
|
|
101
|
+
*/
|
|
102
|
+
readonly fill?: number | undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The side of the square a set's outlines are written in. */
|
|
106
|
+
export const AVATAR_BOX = 100;
|
|
107
|
+
/** The largest picture file the module writes, in pixels a side (ADR-0084). */
|
|
108
|
+
export const MAX_AVATAR_PIXELS = 1024;
|
|
109
|
+
/**
|
|
110
|
+
* Under this many pixels a side a picture has no squares on its ground: they would be specks. A
|
|
111
|
+
* page draws a picture at about twice the size it shows it, so this is a picture shown under 48
|
|
112
|
+
* pixels.
|
|
113
|
+
*/
|
|
114
|
+
export const AVATAR_PLAIN_UNDER = 96;
|
|
115
|
+
/**
|
|
116
|
+
* Under this many pixels a side, a picture shown in a line of text or among a task's workers,
|
|
117
|
+
* the planet is drawn closer: as large as what stands beside it leaves room for, up to
|
|
118
|
+
* `AVATAR_CLOSE_MOST` times what its set writes, or what the set's own `fill` says where that is
|
|
119
|
+
* more (ADR-0099).
|
|
120
|
+
*/
|
|
121
|
+
export const AVATAR_CLOSE_UNDER = 64;
|
|
122
|
+
export const AVATAR_CLOSE_MOST = 1.1;
|
|
123
|
+
/** The most a set may ask its planet to be drawn larger by. */
|
|
124
|
+
export const AVATAR_FILL_MOST = 1.5;
|
|
125
|
+
|
|
126
|
+
// Numbers
|
|
127
|
+
|
|
128
|
+
const clamp = (value: number, low = 0, high = 1): number => Math.min(Math.max(value, low), high);
|
|
129
|
+
const length = (x: number, y: number): number => Math.sqrt(x * x + y * y);
|
|
130
|
+
/** A number that is one, or nothing a drawing can use. */
|
|
131
|
+
const finite = (value: unknown): value is number =>
|
|
132
|
+
typeof value === "number" && Number.isFinite(value);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The sine of an angle in degrees, by its series: sums and products alone, so that every machine
|
|
136
|
+
* lays a curve out through the same points. Good to the last place a number keeps.
|
|
137
|
+
*/
|
|
138
|
+
function sine(degrees: number): number {
|
|
139
|
+
let turn = degrees % 360;
|
|
140
|
+
if (turn > 180) {
|
|
141
|
+
turn -= 360;
|
|
142
|
+
} else if (turn < -180) {
|
|
143
|
+
turn += 360;
|
|
144
|
+
}
|
|
145
|
+
// The sine of what is left of a half turn is the same: the series is asked of a quarter turn at most.
|
|
146
|
+
if (turn > 90) {
|
|
147
|
+
turn = 180 - turn;
|
|
148
|
+
} else if (turn < -90) {
|
|
149
|
+
turn = -180 - turn;
|
|
150
|
+
}
|
|
151
|
+
const x = (turn * Math.PI) / 180;
|
|
152
|
+
const s = x * x;
|
|
153
|
+
let sum = 1;
|
|
154
|
+
for (let term = 20; term >= 2; term -= 2) {
|
|
155
|
+
sum = 1 - (s / (term * (term + 1))) * sum;
|
|
156
|
+
}
|
|
157
|
+
return x * sum;
|
|
158
|
+
}
|
|
159
|
+
const cosine = (degrees: number): number => sine(degrees + 90);
|
|
160
|
+
|
|
161
|
+
// Colours
|
|
162
|
+
|
|
163
|
+
const BLACK: AvatarColor = [0, 0, 0];
|
|
164
|
+
|
|
165
|
+
/** A colour written `#rrggbb` as its three numbers; black where it is not written so. */
|
|
166
|
+
function colorOf(hex: unknown): AvatarColor {
|
|
167
|
+
if (typeof hex !== "string" || !/^#[0-9a-fA-F]{6}$/.test(hex)) {
|
|
168
|
+
return BLACK;
|
|
169
|
+
}
|
|
170
|
+
const read = (at: number): number => Number.parseInt(hex.slice(at, at + 2), 16);
|
|
171
|
+
return [read(1), read(3), read(5)];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Outlines: what the first set is written with. Every one runs the same way round, so that
|
|
175
|
+
// outlines laid over one another add up to one shape; `hole` turns one the other way.
|
|
176
|
+
|
|
177
|
+
/** How many sides a curve of this radius is drawn with: enough that the largest picture shows none. */
|
|
178
|
+
function sidesOf(radius: number): number {
|
|
179
|
+
return 4 * Math.ceil(clamp(radius * 4, 48, 192) / 4);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** An oval by its middle and its two radii. */
|
|
183
|
+
function oval(cx: number, cy: number, rx: number, ry: number): AvatarOutline {
|
|
184
|
+
const sides = sidesOf(Math.max(rx, ry));
|
|
185
|
+
const points: AvatarPoint[] = [];
|
|
186
|
+
for (let side = 0; side < sides; side += 1) {
|
|
187
|
+
const at = (360 * side) / sides;
|
|
188
|
+
points.push([cx + rx * cosine(at), cy + ry * sine(at)]);
|
|
189
|
+
}
|
|
190
|
+
return points;
|
|
191
|
+
}
|
|
192
|
+
const disc = (cx: number, cy: number, radius: number): AvatarOutline =>
|
|
193
|
+
oval(cx, cy, radius, radius);
|
|
194
|
+
|
|
195
|
+
/** A rectangle by its top left and its sides, its corners rounded by `radius`, which is half a side at most. */
|
|
196
|
+
function slab(x: number, y: number, w: number, h: number, radius: number): AvatarOutline {
|
|
197
|
+
const r = Math.min(radius, w / 2, h / 2);
|
|
198
|
+
const steps = sidesOf(r) / 4;
|
|
199
|
+
const points: AvatarPoint[] = [];
|
|
200
|
+
const corner = (cx: number, cy: number, from: number): void => {
|
|
201
|
+
for (let step = 0; step <= steps; step += 1) {
|
|
202
|
+
const at = from + (90 * step) / steps;
|
|
203
|
+
points.push([cx + r * cosine(at), cy + r * sine(at)]);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
corner(x + w - r, y + r, -90);
|
|
207
|
+
corner(x + w - r, y + h - r, 0);
|
|
208
|
+
corner(x + r, y + h - r, 90);
|
|
209
|
+
corner(x + r, y + r, 180);
|
|
210
|
+
return points;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** An outline run the other way round: a hole in the outline it lies in. */
|
|
214
|
+
const hole = (outline: AvatarOutline): AvatarOutline => [...outline].reverse();
|
|
215
|
+
|
|
216
|
+
/** A place written with two digits after the point, as the set was drawn. */
|
|
217
|
+
const two = (value: number): number => Math.round(value * 100) / 100;
|
|
218
|
+
|
|
219
|
+
/** How a band's edge runs: straight where it has no height, else a wave of this height, or a zigzag. */
|
|
220
|
+
interface Edge {
|
|
221
|
+
readonly height?: number;
|
|
222
|
+
readonly shift?: number;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* A band across the whole picture, from `top` down to `bottom`, each edge straight, a wave or a
|
|
227
|
+
* zigzag `length` long from crest to crest. An edge is a line through points a step apart, two
|
|
228
|
+
* units for a wave and half its length for a zigzag, as the set was drawn.
|
|
229
|
+
*/
|
|
230
|
+
function band(
|
|
231
|
+
top: number,
|
|
232
|
+
bottom: number,
|
|
233
|
+
upper: Edge = {},
|
|
234
|
+
lower: Edge = {},
|
|
235
|
+
wave: { readonly length?: number; readonly zigzag?: boolean } = {},
|
|
236
|
+
): AvatarOutline {
|
|
237
|
+
const long = wave.length ?? 26;
|
|
238
|
+
const zigzag = wave.zigzag === true;
|
|
239
|
+
const lift = (x: number, shift: number): number => {
|
|
240
|
+
const t = (x + shift) / long;
|
|
241
|
+
return zigzag ? 2 * Math.abs(2 * (t - Math.floor(t + 0.5))) - 1 : sine(360 * t);
|
|
242
|
+
};
|
|
243
|
+
const step = zigzag ? long / 2 : 2;
|
|
244
|
+
const points: AvatarPoint[] = [];
|
|
245
|
+
for (let x = -4; x <= 104; x += step) {
|
|
246
|
+
points.push([two(x), two(top + (upper.height ?? 0) * lift(x, upper.shift ?? 0))]);
|
|
247
|
+
}
|
|
248
|
+
for (let x = 104; x >= -4; x -= step) {
|
|
249
|
+
points.push([two(x), two(bottom + (lower.height ?? 0) * lift(x, lower.shift ?? 0))]);
|
|
250
|
+
}
|
|
251
|
+
return points;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** A band that runs from the upper right to the lower left, between two lines `from` and `to` along the edges. */
|
|
255
|
+
const slant = (from: number, to: number): AvatarOutline => [
|
|
256
|
+
[from + 10, -10],
|
|
257
|
+
[to + 10, -10],
|
|
258
|
+
[-10, to + 10],
|
|
259
|
+
[-10, from + 10],
|
|
260
|
+
];
|
|
261
|
+
|
|
262
|
+
/** A star of four points, its sides drawn in towards its middle. */
|
|
263
|
+
function sparkle(x: number, y: number, size: number): AvatarOutline {
|
|
264
|
+
const pull = size * 0.16;
|
|
265
|
+
const tips: readonly AvatarPoint[] = [
|
|
266
|
+
[x, y - size],
|
|
267
|
+
[x + size, y],
|
|
268
|
+
[x, y + size],
|
|
269
|
+
[x - size, y],
|
|
270
|
+
];
|
|
271
|
+
const pulls: readonly AvatarPoint[] = [
|
|
272
|
+
[x + pull, y - pull],
|
|
273
|
+
[x + pull, y + pull],
|
|
274
|
+
[x - pull, y + pull],
|
|
275
|
+
[x - pull, y - pull],
|
|
276
|
+
];
|
|
277
|
+
const steps = 16;
|
|
278
|
+
const points: AvatarPoint[] = [];
|
|
279
|
+
for (let side = 0; side < 4; side += 1) {
|
|
280
|
+
const from = tips[side] ?? [x, y];
|
|
281
|
+
const by = pulls[side] ?? [x, y];
|
|
282
|
+
const to = tips[(side + 1) % 4] ?? [x, y];
|
|
283
|
+
for (let step = 0; step < steps; step += 1) {
|
|
284
|
+
const t = step / steps;
|
|
285
|
+
const a = (1 - t) * (1 - t);
|
|
286
|
+
const b = 2 * (1 - t) * t;
|
|
287
|
+
const c = t * t;
|
|
288
|
+
points.push([a * from[0] + b * by[0] + c * to[0], a * from[1] + b * by[1] + c * to[1]]);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return points;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// The first set
|
|
295
|
+
|
|
296
|
+
const ramp = (tones: string, partner: number): AvatarRamp => ({ tones: tones.split(" "), partner });
|
|
297
|
+
const of = (outline: AvatarOutline, tone: number): AvatarShape => ({ outlines: [outline], tone });
|
|
298
|
+
|
|
299
|
+
/** The rim of the lumpy body: where each bump sits, in degrees round the middle, and its radius. */
|
|
300
|
+
const BUMPS: readonly AvatarPoint[] = [
|
|
301
|
+
[-78, 5.2],
|
|
302
|
+
[-30, 4.4],
|
|
303
|
+
[12, 5],
|
|
304
|
+
[58, 4.2],
|
|
305
|
+
[104, 5.4],
|
|
306
|
+
[150, 4.6],
|
|
307
|
+
[196, 5],
|
|
308
|
+
[240, 4.2],
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
/** A ring: an oval with an oval cut out of it. */
|
|
312
|
+
const RING: readonly AvatarOutline[] = [oval(50, 50, 40, 11), hole(oval(50, 50, 32, 8))];
|
|
313
|
+
/** The line of an orbit: an oval with one a little smaller cut out of it. */
|
|
314
|
+
const ORBIT: readonly AvatarOutline[] = [oval(50, 50, 42.4, 13.4), hole(oval(50, 50, 39.6, 10.9))];
|
|
315
|
+
/** The white of a polar cap, and its shade. */
|
|
316
|
+
const ICE: readonly [string, string] = ["#ffffff", "#ebe4f1"];
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The first set: four bodies, ten surfaces and eighteen ramps of five tones, each with the ramp
|
|
320
|
+
* that goes with it, on one ground, with one of five things beside the body or none.
|
|
321
|
+
*/
|
|
322
|
+
export const AVATAR_SET_1: AvatarSet = {
|
|
323
|
+
version: 1,
|
|
324
|
+
// The set is drawn with air round its planet; on a page a tile reads better a little fuller.
|
|
325
|
+
fill: 1.05,
|
|
326
|
+
// A graphite ground, calm and of no hue, so that no ramp sinks into it as a blue would into a
|
|
327
|
+
// blue; and squares three fifths of the way from it to the bright colours they once were, seen
|
|
328
|
+
// as stars at the half they are laid at, and never louder than the planet (ADR-0102).
|
|
329
|
+
grounds: ["#51525c"],
|
|
330
|
+
confetti: ["#b9a14d", "#b98a56", "#6d86be", "#6366b0", "#9d9cae", "#adaab5"],
|
|
331
|
+
ramps: [
|
|
332
|
+
// Sunset, butter, gold, peach, terracotta, rose.
|
|
333
|
+
ramp("#ffd643 #ffb052 #ff8a5b #ff3d5a #d6264a", 7),
|
|
334
|
+
ramp("#fff4d6 #ffe08a #ffc25c #ff9f4a #f07a3a", 9),
|
|
335
|
+
ramp("#fff0b3 #ffd95a #f5b82e #d6911b #a86a10", 10),
|
|
336
|
+
ramp("#ffe3d3 #ffc4a8 #ff9f80 #f2735a #d9533f", 13),
|
|
337
|
+
ramp("#ffd2b8 #ffa77a #ff8a5b #e8613f #c24e33", 12),
|
|
338
|
+
ramp("#ffd6e4 #ffb3c7 #ff8fb3 #ff5c8a #d6336c", 11),
|
|
339
|
+
// Berry, violet, lavender, indigo, denim, ocean. Denim stands a step lighter than a navy
|
|
340
|
+
// would, so that it does not sink into the graphite ground (ADR-0102).
|
|
341
|
+
ramp("#ffd0f0 #f59ad8 #e05fbf #b83a9e #8c2479", 1),
|
|
342
|
+
ramp("#eadcff #cdb0ff #a77cf5 #8556de #6638bd", 1),
|
|
343
|
+
ramp("#fff3f2 #ebe4f1 #d0cde4 #a4a7cc #8a8db8", 0),
|
|
344
|
+
ramp("#9cb8ff #6f8cf5 #4f5fe0 #3a3fb8 #2a2f99", 1),
|
|
345
|
+
ramp("#d3dcf5 #a9b8e6 #8296d2 #6479bd #4c60a3", 2),
|
|
346
|
+
ramp("#c7e2ff #9cc4ff #7fa8ff #6f74e8 #5257c9", 0),
|
|
347
|
+
// Aqua, teal, mint, leaf, stone, graphite.
|
|
348
|
+
ramp("#d8fbff #a6f0ff #5fd0f0 #2aa7d6 #1b7bb3", 5),
|
|
349
|
+
ramp("#bff5ec #7fe3d3 #3fc4b3 #1f9a8d #127066", 3),
|
|
350
|
+
ramp("#5ef0b8 #22e3a5 #1cb2b2 #137f80 #0e5f60", 0),
|
|
351
|
+
ramp("#d9f7a0 #a8e070 #6cc46a #3f9e58 #2a7a45", 7),
|
|
352
|
+
ramp("#f6f1ea #e9e1d4 #d4c8b6 #b8a993 #998a74", 14),
|
|
353
|
+
ramp("#f2f3f5 #d9dce2 #b4b9c4 #8a909e #5f6573", 0),
|
|
354
|
+
],
|
|
355
|
+
bodies: [
|
|
356
|
+
// A disc.
|
|
357
|
+
{ outlines: [disc(50, 50, 27)] },
|
|
358
|
+
// A smaller disc.
|
|
359
|
+
{ outlines: [disc(50, 50, 24)] },
|
|
360
|
+
// A lumpy one: a disc with small round bumps on its rim.
|
|
361
|
+
{
|
|
362
|
+
outlines: [
|
|
363
|
+
disc(50, 50, 24.5),
|
|
364
|
+
...BUMPS.map(([at, radius]) => disc(50 + 23.5 * cosine(at), 50 + 23.5 * sine(at), radius)),
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
// One with an atmosphere: a disc, and a faint larger one behind it.
|
|
368
|
+
{
|
|
369
|
+
outlines: [disc(50, 50, 24.5)],
|
|
370
|
+
behind: [{ outlines: [disc(50, 50, 29)], tone: 0, opacity: 0.2 }],
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
surfaces: [
|
|
374
|
+
// Straight bands.
|
|
375
|
+
{
|
|
376
|
+
tone: 0,
|
|
377
|
+
shapes: [
|
|
378
|
+
of(band(-10, 30.7), 1),
|
|
379
|
+
of(band(38.4, 46.1), 1),
|
|
380
|
+
of(band(53.9, 61.6), 1),
|
|
381
|
+
of(band(69.3, 110), 1),
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
// Wavy bands.
|
|
385
|
+
{
|
|
386
|
+
tone: 1,
|
|
387
|
+
shapes: [
|
|
388
|
+
of(band(-10, 31.5), 2),
|
|
389
|
+
of(band(40.5, 54, { height: 2.4, shift: 6 }), 0),
|
|
390
|
+
of(band(67, 110, { height: 2.4, shift: 19 }), 2),
|
|
391
|
+
],
|
|
392
|
+
},
|
|
393
|
+
// Zigzag bands.
|
|
394
|
+
{
|
|
395
|
+
tone: 1,
|
|
396
|
+
shapes: [
|
|
397
|
+
of(band(-10, 33, {}, { height: 3 }, { length: 13, zigzag: true }), 2),
|
|
398
|
+
of(band(44, 56, { height: 3 }, { height: 3 }, { length: 13, zigzag: true }), 0),
|
|
399
|
+
of(band(67, 110, { height: 3 }, {}, { length: 13, zigzag: true }), 2),
|
|
400
|
+
],
|
|
401
|
+
},
|
|
402
|
+
// Tilted bands.
|
|
403
|
+
{ tone: 1, shapes: [of(slant(68, 80), 2), of(slant(92, 104), 0), of(slant(116, 128), 2)] },
|
|
404
|
+
// The eye of a storm.
|
|
405
|
+
{
|
|
406
|
+
tone: 0,
|
|
407
|
+
shapes: [
|
|
408
|
+
of(band(-10, 31), 1),
|
|
409
|
+
of(band(69, 110), 1),
|
|
410
|
+
of(band(46.5, 53.5), 1),
|
|
411
|
+
of(oval(50, 50, 15.5, 9.5), 1),
|
|
412
|
+
of(oval(50, 50, 8.5, 5), 0),
|
|
413
|
+
],
|
|
414
|
+
},
|
|
415
|
+
// A great spot.
|
|
416
|
+
{
|
|
417
|
+
tone: 1,
|
|
418
|
+
shapes: [
|
|
419
|
+
of(band(-10, 34, {}, { height: 1.8, shift: 4 }), 2),
|
|
420
|
+
of(band(43, 49), 0),
|
|
421
|
+
of(band(64, 110, { height: 1.8, shift: 9 }), 2),
|
|
422
|
+
of(slab(53, 51.5, 14, 8, 4), 2),
|
|
423
|
+
],
|
|
424
|
+
},
|
|
425
|
+
// Continents.
|
|
426
|
+
{
|
|
427
|
+
tone: 0,
|
|
428
|
+
shapes: [
|
|
429
|
+
of(slab(38, 31, 70, 12, 6), 1),
|
|
430
|
+
of(slab(-20, 47, 74, 11, 5.5), 1),
|
|
431
|
+
of(band(67, 110), 1),
|
|
432
|
+
],
|
|
433
|
+
},
|
|
434
|
+
// Craters.
|
|
435
|
+
{
|
|
436
|
+
tone: 1,
|
|
437
|
+
shapes: [
|
|
438
|
+
of(disc(38, 40, 6.2), 2),
|
|
439
|
+
of(disc(38, 40, 3), 3),
|
|
440
|
+
of(disc(63, 45, 4.6), 2),
|
|
441
|
+
of(disc(42, 63, 5.2), 2),
|
|
442
|
+
of(slab(53, 31, 3.4, 3.4, 0.4), 2),
|
|
443
|
+
of(slab(30, 54, 3, 3, 0.4), 2),
|
|
444
|
+
of(slab(58, 57, 3, 3, 0.4), 2),
|
|
445
|
+
of(disc(50, 80, 7.5), 2),
|
|
446
|
+
],
|
|
447
|
+
},
|
|
448
|
+
// Polar caps.
|
|
449
|
+
{
|
|
450
|
+
tone: 1,
|
|
451
|
+
shapes: [
|
|
452
|
+
{ outlines: [band(-10, 32, {}, { height: 1.6, shift: 4 })], tone: 0, colors: ICE },
|
|
453
|
+
{ outlines: [band(70, 110, { height: 1.6, shift: 12 })], tone: 0, colors: ICE },
|
|
454
|
+
of(disc(40, 52, 4.4), 2),
|
|
455
|
+
of(slab(54, 47, 16, 3.4, 1.7), 2),
|
|
456
|
+
],
|
|
457
|
+
},
|
|
458
|
+
// Day and night.
|
|
459
|
+
{ tone: 0, shapes: [of(disc(64, 40, 27), 1), of(disc(70, 34, 10), 2)] },
|
|
460
|
+
],
|
|
461
|
+
accents: [
|
|
462
|
+
{ behind: [], before: [] },
|
|
463
|
+
// A ring: all of it behind the body, and its lower half before it.
|
|
464
|
+
{
|
|
465
|
+
behind: [{ turn: -14, shapes: [{ outlines: RING, tone: 1 }] }],
|
|
466
|
+
before: [{ turn: -14, half: "lower", shapes: [{ outlines: RING, tone: 1 }] }],
|
|
467
|
+
},
|
|
468
|
+
// An orbit: a faint line round the body, and a small moon on it.
|
|
469
|
+
{
|
|
470
|
+
behind: [
|
|
471
|
+
{
|
|
472
|
+
turn: -18,
|
|
473
|
+
half: "upper",
|
|
474
|
+
shapes: [{ outlines: ORBIT, tone: 1, opacity: 0.55 }],
|
|
475
|
+
},
|
|
476
|
+
],
|
|
477
|
+
before: [
|
|
478
|
+
{
|
|
479
|
+
turn: -18,
|
|
480
|
+
half: "lower",
|
|
481
|
+
shapes: [{ outlines: ORBIT, tone: 1, opacity: 0.55 }],
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
turn: -18,
|
|
485
|
+
shapes: [{ outlines: [disc(89.5, 54.4, 3.6)], tone: 1, split: 89.5, gap: 2 }],
|
|
486
|
+
},
|
|
487
|
+
],
|
|
488
|
+
},
|
|
489
|
+
// A moon.
|
|
490
|
+
{
|
|
491
|
+
behind: [],
|
|
492
|
+
before: [{ shapes: [{ outlines: [disc(74.5, 27.5, 9.4)], tone: 1, split: 74.5, gap: 3 }] }],
|
|
493
|
+
},
|
|
494
|
+
// Two moons.
|
|
495
|
+
{
|
|
496
|
+
behind: [],
|
|
497
|
+
before: [
|
|
498
|
+
{
|
|
499
|
+
shapes: [
|
|
500
|
+
{ outlines: [disc(75, 26, 7.6)], tone: 1, split: 75, gap: 2.8 },
|
|
501
|
+
{ outlines: [disc(24, 75, 5.2)], tone: 0, split: 24, gap: 2.4 },
|
|
502
|
+
],
|
|
503
|
+
},
|
|
504
|
+
],
|
|
505
|
+
},
|
|
506
|
+
// A sparkle, and a smaller one.
|
|
507
|
+
{
|
|
508
|
+
behind: [],
|
|
509
|
+
before: [
|
|
510
|
+
{
|
|
511
|
+
shapes: [
|
|
512
|
+
{ outlines: [sparkle(76, 23, 9)], tone: 0, split: 76, gap: 2.4 },
|
|
513
|
+
{ outlines: [sparkle(85, 36, 4)], tone: 1, split: 85 },
|
|
514
|
+
],
|
|
515
|
+
},
|
|
516
|
+
],
|
|
517
|
+
},
|
|
518
|
+
],
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
/** The sets the package ships, the oldest first; an avatar names the one it was made with. */
|
|
522
|
+
export const AVATAR_SETS: readonly AvatarSet[] = [AVATAR_SET_1];
|
|
523
|
+
|
|
524
|
+
/** The set an avatar was made with, among `sets`; the newest where they hold none of its version. */
|
|
525
|
+
export function avatarSetOf(
|
|
526
|
+
parts: Pick<RestAvatarParts, "set">,
|
|
527
|
+
sets: readonly AvatarSet[] = AVATAR_SETS,
|
|
528
|
+
): AvatarSet {
|
|
529
|
+
const found = sets.find((set) => set.version === parts.set) ?? sets[sets.length - 1];
|
|
530
|
+
if (found === undefined) {
|
|
531
|
+
throw new Error("no set to draw an avatar from");
|
|
532
|
+
}
|
|
533
|
+
return found;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** What a set holds where it should hold a list: the list, or nothing. */
|
|
537
|
+
const listOf = <T>(value: readonly T[] | undefined): readonly T[] =>
|
|
538
|
+
Array.isArray(value) ? value : [];
|
|
539
|
+
|
|
540
|
+
/** A thing of a set that is one, or nothing: a set of one's own may hold anything. */
|
|
541
|
+
const thing = <T extends object>(value: T | undefined): T | undefined =>
|
|
542
|
+
typeof value === "object" && value !== null ? value : undefined;
|
|
543
|
+
|
|
544
|
+
/** The things of a list of a set; what in it is none is left out. */
|
|
545
|
+
const thingsOf = <T extends object>(value: readonly T[] | undefined): readonly T[] =>
|
|
546
|
+
listOf(value).filter((one) => thing(one) !== undefined);
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* The choice an index names, counted round the end: an index a set does not have still draws,
|
|
550
|
+
* and what is no index at all names the first.
|
|
551
|
+
*/
|
|
552
|
+
function choiceOf<T>(choices: readonly T[] | undefined, index: unknown): T | undefined {
|
|
553
|
+
const list = listOf(choices);
|
|
554
|
+
return list.length === 0
|
|
555
|
+
? undefined
|
|
556
|
+
: list[finite(index) ? Math.abs(Math.trunc(index)) % list.length : 0];
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// Filling: how much of each pixel an outline covers.
|
|
560
|
+
|
|
561
|
+
/** An outline as the filling takes it: across and down in turn, in one list. */
|
|
562
|
+
type Path = number[];
|
|
563
|
+
|
|
564
|
+
/** The most a place may be from the picture, in its own units: what is further is nobody's set, and is brought back. */
|
|
565
|
+
const FAR = 1e4;
|
|
566
|
+
/**
|
|
567
|
+
* The most corners one picture is drawn from, some ten times what the first set's fullest
|
|
568
|
+
* picture has: an outline that would take it past that is left out, so that a set of one's own
|
|
569
|
+
* with an outline of any length draws in a time that has a bound.
|
|
570
|
+
*/
|
|
571
|
+
const MOST_CORNERS = 20_000;
|
|
572
|
+
|
|
573
|
+
/** An outline of a set as a path; what in it is no place of a picture is left out. */
|
|
574
|
+
function pathOf(outline: AvatarOutline): Path {
|
|
575
|
+
const path: Path = [];
|
|
576
|
+
if (!Array.isArray(outline)) {
|
|
577
|
+
return path;
|
|
578
|
+
}
|
|
579
|
+
for (const point of outline) {
|
|
580
|
+
const x = Array.isArray(point) ? point[0] : undefined;
|
|
581
|
+
const y = Array.isArray(point) ? point[1] : undefined;
|
|
582
|
+
if (finite(x) && finite(y)) {
|
|
583
|
+
path.push(clamp(x, -FAR, FAR), clamp(y, -FAR, FAR));
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return path;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** What of a path lies where `a * x + b * y` is `c` at most: the path cut along a line. */
|
|
590
|
+
function cut(path: Path, a: number, b: number, c: number): Path {
|
|
591
|
+
const out: Path = [];
|
|
592
|
+
const corners = path.length / 2;
|
|
593
|
+
if (corners < 3) {
|
|
594
|
+
return out;
|
|
595
|
+
}
|
|
596
|
+
let px = path[path.length - 2] ?? 0;
|
|
597
|
+
let py = path[path.length - 1] ?? 0;
|
|
598
|
+
let pd = a * px + b * py - c;
|
|
599
|
+
for (let corner = 0; corner < corners; corner += 1) {
|
|
600
|
+
const x = path[corner * 2] ?? 0;
|
|
601
|
+
const y = path[corner * 2 + 1] ?? 0;
|
|
602
|
+
const d = a * x + b * y - c;
|
|
603
|
+
if (d <= 0 !== pd <= 0) {
|
|
604
|
+
const t = pd / (pd - d);
|
|
605
|
+
out.push(px + (x - px) * t, py + (y - py) * t);
|
|
606
|
+
}
|
|
607
|
+
if (d <= 0) {
|
|
608
|
+
out.push(x, y);
|
|
609
|
+
}
|
|
610
|
+
px = x;
|
|
611
|
+
py = y;
|
|
612
|
+
pd = d;
|
|
613
|
+
}
|
|
614
|
+
return out;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/** Twice the area a path goes round, its sign saying which way. */
|
|
618
|
+
function turnOf(path: Path): number {
|
|
619
|
+
let area = 0;
|
|
620
|
+
const corners = path.length / 2;
|
|
621
|
+
let px = path[path.length - 2] ?? 0;
|
|
622
|
+
let py = path[path.length - 1] ?? 0;
|
|
623
|
+
for (let corner = 0; corner < corners; corner += 1) {
|
|
624
|
+
const x = path[corner * 2] ?? 0;
|
|
625
|
+
const y = path[corner * 2 + 1] ?? 0;
|
|
626
|
+
area += px * y - x * py;
|
|
627
|
+
px = x;
|
|
628
|
+
py = y;
|
|
629
|
+
}
|
|
630
|
+
return area;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** How long a join of two sides may reach past their corner, in line widths, before it is cut off flat. */
|
|
634
|
+
const JOIN_LIMIT = 4;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* The line `width` wide along an outline, as paths that all run one way round: a piece for each
|
|
638
|
+
* side, and at each corner a piece that fills the outer side of the turn, pointed where the
|
|
639
|
+
* turn is gentle and cut off flat where it is sharp.
|
|
640
|
+
*/
|
|
641
|
+
function lineAlong(path: Path, width: number): Path[] {
|
|
642
|
+
const pieces: Path[] = [];
|
|
643
|
+
const corners = path.length / 2;
|
|
644
|
+
const half = width / 2;
|
|
645
|
+
if (corners < 2 || !(half > 0)) {
|
|
646
|
+
return pieces;
|
|
647
|
+
}
|
|
648
|
+
const piece = (points: Path): void => {
|
|
649
|
+
const turn = turnOf(points);
|
|
650
|
+
if (turn === 0) {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
if (turn < 0) {
|
|
654
|
+
const back: Path = [];
|
|
655
|
+
for (let at = points.length - 2; at >= 0; at -= 2) {
|
|
656
|
+
back.push(points[at] ?? 0, points[at + 1] ?? 0);
|
|
657
|
+
}
|
|
658
|
+
pieces.push(back);
|
|
659
|
+
} else {
|
|
660
|
+
pieces.push(points);
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
/** The sides that have a length, each with the way it runs. */
|
|
664
|
+
const sides: { x: number; y: number; dx: number; dy: number; tx: number; ty: number }[] = [];
|
|
665
|
+
for (let corner = 0; corner < corners; corner += 1) {
|
|
666
|
+
const x = path[corner * 2] ?? 0;
|
|
667
|
+
const y = path[corner * 2 + 1] ?? 0;
|
|
668
|
+
const tx = path[((corner + 1) % corners) * 2] ?? 0;
|
|
669
|
+
const ty = path[((corner + 1) % corners) * 2 + 1] ?? 0;
|
|
670
|
+
const long = length(tx - x, ty - y);
|
|
671
|
+
if (long > 0) {
|
|
672
|
+
sides.push({ x, y, dx: (tx - x) / long, dy: (ty - y) / long, tx, ty });
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
for (const [at, side] of sides.entries()) {
|
|
676
|
+
// Across the side, to its left as it runs.
|
|
677
|
+
const nx = -side.dy * half;
|
|
678
|
+
const ny = side.dx * half;
|
|
679
|
+
piece([
|
|
680
|
+
side.x + nx,
|
|
681
|
+
side.y + ny,
|
|
682
|
+
side.tx + nx,
|
|
683
|
+
side.ty + ny,
|
|
684
|
+
side.tx - nx,
|
|
685
|
+
side.ty - ny,
|
|
686
|
+
side.x - nx,
|
|
687
|
+
side.y - ny,
|
|
688
|
+
]);
|
|
689
|
+
const next = sides[(at + 1) % sides.length];
|
|
690
|
+
if (next === undefined || next === side) {
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
693
|
+
const cross = side.dx * next.dy - side.dy * next.dx;
|
|
694
|
+
if (cross === 0) {
|
|
695
|
+
continue;
|
|
696
|
+
}
|
|
697
|
+
// The outer side of the turn is the one away from where it turns to.
|
|
698
|
+
const out = cross > 0 ? -1 : 1;
|
|
699
|
+
const ax = side.tx + out * nx;
|
|
700
|
+
const ay = side.ty + out * ny;
|
|
701
|
+
const bx = side.tx + out * -next.dy * half;
|
|
702
|
+
const by = side.ty + out * next.dx * half;
|
|
703
|
+
const along = 1 + side.dx * next.dx + side.dy * next.dy;
|
|
704
|
+
if (along >= 2 / (JOIN_LIMIT * JOIN_LIMIT)) {
|
|
705
|
+
const reach = (out * half) / along;
|
|
706
|
+
piece([
|
|
707
|
+
side.tx,
|
|
708
|
+
side.ty,
|
|
709
|
+
ax,
|
|
710
|
+
ay,
|
|
711
|
+
side.tx + (-side.dy - next.dy) * reach,
|
|
712
|
+
side.ty + (side.dx + next.dx) * reach,
|
|
713
|
+
bx,
|
|
714
|
+
by,
|
|
715
|
+
]);
|
|
716
|
+
} else {
|
|
717
|
+
piece([side.tx, side.ty, ax, ay, bx, by]);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return pieces;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/** Where a place of a set is in the picture's pixels: turned about the middle, drawn larger about it, and scaled. */
|
|
724
|
+
interface Placing {
|
|
725
|
+
readonly cos: number;
|
|
726
|
+
readonly sin: number;
|
|
727
|
+
readonly zoom: number;
|
|
728
|
+
readonly scale: number;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function placed(path: Path, placing: Placing): Path {
|
|
732
|
+
const middle = AVATAR_BOX / 2;
|
|
733
|
+
const out: Path = new Array<number>(path.length);
|
|
734
|
+
for (let at = 0; at < path.length; at += 2) {
|
|
735
|
+
const x = (path[at] ?? 0) - middle;
|
|
736
|
+
const y = (path[at + 1] ?? 0) - middle;
|
|
737
|
+
out[at] = (middle + (x * placing.cos - y * placing.sin) * placing.zoom) * placing.scale;
|
|
738
|
+
out[at + 1] = (middle + (x * placing.sin + y * placing.cos) * placing.zoom) * placing.scale;
|
|
739
|
+
}
|
|
740
|
+
return out;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/** A part of the picture, in pixels: what is filled is cut to it. */
|
|
744
|
+
interface Frame {
|
|
745
|
+
readonly left: number;
|
|
746
|
+
readonly top: number;
|
|
747
|
+
readonly right: number;
|
|
748
|
+
readonly bottom: number;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/** The rows and the columns something was filled in, so that only they are gone over. */
|
|
752
|
+
interface Reach {
|
|
753
|
+
left: number;
|
|
754
|
+
top: number;
|
|
755
|
+
right: number;
|
|
756
|
+
bottom: number;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Adds a path to the sums its pixels are covered by: for each row a side crosses, how much of
|
|
761
|
+
* each pixel lies to the right of it, signed by the way the side runs. Summed along a row, they
|
|
762
|
+
* say how much of each pixel the path goes round, and how often.
|
|
763
|
+
*/
|
|
764
|
+
function trace(sums: Float32Array, stride: number, path: Path, frame: Frame, reach: Reach): void {
|
|
765
|
+
let cutPath = cut(path, -1, 0, -frame.left);
|
|
766
|
+
cutPath = cut(cutPath, 1, 0, frame.right);
|
|
767
|
+
cutPath = cut(cutPath, 0, -1, -frame.top);
|
|
768
|
+
cutPath = cut(cutPath, 0, 1, frame.bottom);
|
|
769
|
+
const corners = cutPath.length / 2;
|
|
770
|
+
if (corners < 3) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
let px = cutPath[cutPath.length - 2] ?? 0;
|
|
774
|
+
let py = cutPath[cutPath.length - 1] ?? 0;
|
|
775
|
+
for (let corner = 0; corner < corners; corner += 1) {
|
|
776
|
+
const cx = cutPath[corner * 2] ?? 0;
|
|
777
|
+
const cy = cutPath[corner * 2 + 1] ?? 0;
|
|
778
|
+
let x0 = px;
|
|
779
|
+
let y0 = py;
|
|
780
|
+
let x1 = cx;
|
|
781
|
+
let y1 = cy;
|
|
782
|
+
px = cx;
|
|
783
|
+
py = cy;
|
|
784
|
+
if (y0 === y1) {
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
let way = 1;
|
|
788
|
+
if (y0 > y1) {
|
|
789
|
+
way = -1;
|
|
790
|
+
[x0, y0, x1, y1] = [x1, y1, x0, y0];
|
|
791
|
+
}
|
|
792
|
+
const slope = (x1 - x0) / (y1 - y0);
|
|
793
|
+
let x = x0;
|
|
794
|
+
const first = Math.floor(y0);
|
|
795
|
+
const last = Math.ceil(y1);
|
|
796
|
+
reach.top = Math.min(reach.top, first);
|
|
797
|
+
reach.bottom = Math.max(reach.bottom, last);
|
|
798
|
+
for (let row = first; row < last; row += 1) {
|
|
799
|
+
const tall = Math.min(row + 1, y1) - Math.max(row, y0);
|
|
800
|
+
const after = x + slope * tall;
|
|
801
|
+
const share = tall * way;
|
|
802
|
+
const from = Math.min(x, after);
|
|
803
|
+
const to = Math.max(x, after);
|
|
804
|
+
const start = Math.floor(from);
|
|
805
|
+
const end = Math.ceil(to);
|
|
806
|
+
const base = row * stride;
|
|
807
|
+
reach.left = Math.min(reach.left, start);
|
|
808
|
+
reach.right = Math.max(reach.right, end + 1);
|
|
809
|
+
if (end <= start + 1) {
|
|
810
|
+
const across = 0.5 * (x + after) - start;
|
|
811
|
+
sums[base + start] = (sums[base + start] ?? 0) + share - share * across;
|
|
812
|
+
sums[base + start + 1] = (sums[base + start + 1] ?? 0) + share * across;
|
|
813
|
+
} else {
|
|
814
|
+
const each = 1 / (to - from);
|
|
815
|
+
const inFirst = from - start;
|
|
816
|
+
const firstArea = 0.5 * each * (1 - inFirst) * (1 - inFirst);
|
|
817
|
+
const inLast = to - end + 1;
|
|
818
|
+
const lastArea = 0.5 * each * inLast * inLast;
|
|
819
|
+
sums[base + start] = (sums[base + start] ?? 0) + share * firstArea;
|
|
820
|
+
if (end === start + 2) {
|
|
821
|
+
sums[base + start + 1] =
|
|
822
|
+
(sums[base + start + 1] ?? 0) + share * (1 - firstArea - lastArea);
|
|
823
|
+
} else {
|
|
824
|
+
const second = each * (1.5 - inFirst);
|
|
825
|
+
sums[base + start + 1] = (sums[base + start + 1] ?? 0) + share * (second - firstArea);
|
|
826
|
+
for (let column = start + 2; column < end - 1; column += 1) {
|
|
827
|
+
sums[base + column] = (sums[base + column] ?? 0) + share * each;
|
|
828
|
+
}
|
|
829
|
+
const before = second + (end - start - 3) * each;
|
|
830
|
+
sums[base + end - 1] = (sums[base + end - 1] ?? 0) + share * (1 - before - lastArea);
|
|
831
|
+
}
|
|
832
|
+
sums[base + end] = (sums[base + end] ?? 0) + share * lastArea;
|
|
833
|
+
}
|
|
834
|
+
x = after;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* How much of a pixel is filled, from how much of it the outlines go round: once is all of it,
|
|
841
|
+
* more is no more, and what an outline goes round the other way is taken off.
|
|
842
|
+
*/
|
|
843
|
+
const filled = (round: number): number => Math.min(1, Math.abs(round));
|
|
844
|
+
|
|
845
|
+
/** What a picture is drawn on: its pixels, and the sums a shape is filled through, kept to be used again. */
|
|
846
|
+
interface Sheet {
|
|
847
|
+
readonly side: number;
|
|
848
|
+
readonly stride: number;
|
|
849
|
+
/** Red, green and blue of each pixel, row after row. */
|
|
850
|
+
readonly pixels: Float32Array;
|
|
851
|
+
/** The sums of a whole shape, and of what of it lies left of its line. */
|
|
852
|
+
readonly whole: Float32Array;
|
|
853
|
+
readonly left: Float32Array;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
function sheetOf(side: number): Sheet {
|
|
857
|
+
const stride = side + 2;
|
|
858
|
+
return {
|
|
859
|
+
side,
|
|
860
|
+
stride,
|
|
861
|
+
pixels: new Float32Array(side * side * 3),
|
|
862
|
+
whole: new Float32Array(stride * side),
|
|
863
|
+
left: new Float32Array(stride * side),
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
const emptyReach = (): Reach => ({
|
|
868
|
+
left: Infinity,
|
|
869
|
+
top: Infinity,
|
|
870
|
+
right: -Infinity,
|
|
871
|
+
bottom: -Infinity,
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Fills paths on `target`, in one colour left of a line and another right of it: `leftPaths` is
|
|
876
|
+
* what of the shape lies left. Where `through` is given, only as much of each pixel is filled as
|
|
877
|
+
* it says. Every pixel is given its two colours at once, by how much of it each covers, so that
|
|
878
|
+
* no line of what is behind shows where they meet.
|
|
879
|
+
*/
|
|
880
|
+
function fill(
|
|
881
|
+
sheet: Sheet,
|
|
882
|
+
target: Float32Array,
|
|
883
|
+
frame: Frame,
|
|
884
|
+
paths: readonly Path[],
|
|
885
|
+
leftPaths: readonly Path[] | undefined,
|
|
886
|
+
leftColor: AvatarColor,
|
|
887
|
+
rightColor: AvatarColor,
|
|
888
|
+
opacity: number,
|
|
889
|
+
through?: Float32Array,
|
|
890
|
+
): void {
|
|
891
|
+
const { side, stride, whole, left } = sheet;
|
|
892
|
+
const reach = emptyReach();
|
|
893
|
+
for (const path of paths) {
|
|
894
|
+
trace(whole, stride, path, frame, reach);
|
|
895
|
+
}
|
|
896
|
+
if (leftPaths !== undefined) {
|
|
897
|
+
const unused = emptyReach();
|
|
898
|
+
for (const path of leftPaths) {
|
|
899
|
+
trace(left, stride, path, frame, unused);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
if (reach.top >= reach.bottom) {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
const firstRow = Math.max(0, reach.top);
|
|
906
|
+
const lastRow = Math.min(side, reach.bottom);
|
|
907
|
+
const firstColumn = Math.max(0, reach.left);
|
|
908
|
+
const lastColumn = Math.min(side + 1, reach.right);
|
|
909
|
+
for (let row = firstRow; row < lastRow; row += 1) {
|
|
910
|
+
let round = 0;
|
|
911
|
+
let roundLeft = 0;
|
|
912
|
+
for (let column = firstColumn; column <= lastColumn; column += 1) {
|
|
913
|
+
const at = row * stride + column;
|
|
914
|
+
round += whole[at] ?? 0;
|
|
915
|
+
whole[at] = 0;
|
|
916
|
+
if (leftPaths !== undefined) {
|
|
917
|
+
roundLeft += left[at] ?? 0;
|
|
918
|
+
left[at] = 0;
|
|
919
|
+
}
|
|
920
|
+
if (column >= side) {
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
const all = filled(round);
|
|
924
|
+
if (all <= 0) {
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
const cell = row * side + column;
|
|
928
|
+
const share = opacity * (through === undefined ? 1 : (through[cell] ?? 0));
|
|
929
|
+
const onLeft = leftPaths === undefined ? 0 : Math.min(all, filled(roundLeft));
|
|
930
|
+
const a = onLeft * share;
|
|
931
|
+
const b = (all - onLeft) * share;
|
|
932
|
+
const pixel = cell * 3;
|
|
933
|
+
const keep = 1 - a - b;
|
|
934
|
+
target[pixel] = (target[pixel] ?? 0) * keep + leftColor[0] * a + rightColor[0] * b;
|
|
935
|
+
target[pixel + 1] = (target[pixel + 1] ?? 0) * keep + leftColor[1] * a + rightColor[1] * b;
|
|
936
|
+
target[pixel + 2] = (target[pixel + 2] ?? 0) * keep + leftColor[2] * a + rightColor[2] * b;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** How much of each pixel paths cover, written into `mask`, and the pixels they reach. */
|
|
942
|
+
function cover(sheet: Sheet, mask: Float32Array, paths: readonly Path[]): Reach {
|
|
943
|
+
const { side, stride, whole } = sheet;
|
|
944
|
+
const reach = emptyReach();
|
|
945
|
+
const frame: Frame = { left: 0, top: 0, right: side, bottom: side };
|
|
946
|
+
for (const path of paths) {
|
|
947
|
+
trace(whole, stride, path, frame, reach);
|
|
948
|
+
}
|
|
949
|
+
if (reach.top >= reach.bottom) {
|
|
950
|
+
return reach;
|
|
951
|
+
}
|
|
952
|
+
const lastColumn = Math.min(side + 1, reach.right);
|
|
953
|
+
for (let row = Math.max(0, reach.top); row < Math.min(side, reach.bottom); row += 1) {
|
|
954
|
+
let round = 0;
|
|
955
|
+
for (let column = Math.max(0, reach.left); column <= lastColumn; column += 1) {
|
|
956
|
+
const at = row * stride + column;
|
|
957
|
+
round += whole[at] ?? 0;
|
|
958
|
+
whole[at] = 0;
|
|
959
|
+
if (column < side) {
|
|
960
|
+
mask[row * side + column] = filled(round);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return reach;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/** The ramp a shape is drawn in when the set has none: greys. */
|
|
968
|
+
const NO_RAMP: AvatarRamp = {
|
|
969
|
+
tones: ["#eeeeee", "#cccccc", "#aaaaaa", "#888888", "#666666"],
|
|
970
|
+
partner: 0,
|
|
971
|
+
};
|
|
972
|
+
const NO_GROUND = "#51525c";
|
|
973
|
+
|
|
974
|
+
/** The two colours of a shape: its own, or two tones of the ramp it is drawn in, the last tone twice where there is none after it. */
|
|
975
|
+
function tonesOf(shape: AvatarShape, ramp: AvatarRamp): readonly [AvatarColor, AvatarColor] {
|
|
976
|
+
if (Array.isArray(shape.colors)) {
|
|
977
|
+
return [colorOf(shape.colors[0]), colorOf(shape.colors[1])];
|
|
978
|
+
}
|
|
979
|
+
const tones = Array.isArray(ramp.tones) ? ramp.tones : [];
|
|
980
|
+
const at = finite(shape.tone) ? clamp(Math.trunc(shape.tone), 0, tones.length - 1) : 0;
|
|
981
|
+
return [colorOf(tones[at]), colorOf(tones[Math.min(at + 1, tones.length - 1)])];
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/** The numbers the squares on the ground are strewn by: the same seed, the same squares. */
|
|
985
|
+
function strewn(seed: number): () => number {
|
|
986
|
+
let state = 0;
|
|
987
|
+
for (const letter of String(seed)) {
|
|
988
|
+
state = (state * 31 + letter.charCodeAt(0)) >>> 0;
|
|
989
|
+
}
|
|
990
|
+
state = state || 1;
|
|
991
|
+
return () => {
|
|
992
|
+
state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
|
|
993
|
+
return state / 4294967296;
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* The side of a square on the ground, where its middle is taken to be from its corner, how far
|
|
999
|
+
* from the middle of the picture the squares keep, and how far from one another.
|
|
1000
|
+
*/
|
|
1001
|
+
const SQUARE = 3.4;
|
|
1002
|
+
const SQUARE_MIDDLE = 1.8;
|
|
1003
|
+
const SQUARES_KEEP_OFF = 37;
|
|
1004
|
+
const SQUARES_APART = 11;
|
|
1005
|
+
|
|
1006
|
+
/** The squares on the ground: six to eight, clear of the planet and of one another, each with its colour. */
|
|
1007
|
+
function squaresOf(
|
|
1008
|
+
seed: number,
|
|
1009
|
+
colors: readonly string[],
|
|
1010
|
+
): { x: number; y: number; color: AvatarColor }[] {
|
|
1011
|
+
const next = strewn(seed);
|
|
1012
|
+
const wanted = 6 + Math.floor(next() * 3);
|
|
1013
|
+
const places: AvatarPoint[] = [];
|
|
1014
|
+
const middle = AVATAR_BOX / 2;
|
|
1015
|
+
for (let tries = 0; places.length < wanted && tries < 400; tries += 1) {
|
|
1016
|
+
const x = 5 + next() * 87;
|
|
1017
|
+
const y = 5 + next() * 87;
|
|
1018
|
+
if (length(x + SQUARE_MIDDLE - middle, y + SQUARE_MIDDLE - middle) < SQUARES_KEEP_OFF) {
|
|
1019
|
+
continue;
|
|
1020
|
+
}
|
|
1021
|
+
if (places.some(([px, py]) => length(px - x, py - y) < SQUARES_APART)) {
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
places.push([x, y]);
|
|
1025
|
+
}
|
|
1026
|
+
return places.map(([x, y]) => ({
|
|
1027
|
+
x: two(x),
|
|
1028
|
+
y: two(y),
|
|
1029
|
+
color: colorOf(colors.length === 0 ? undefined : colors[Math.floor(next() * colors.length)]),
|
|
1030
|
+
}));
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/** How wide the line of the ground round a shape is: none where it names none, and no wider than the picture. */
|
|
1034
|
+
const gapOf = (shape: AvatarShape): number =>
|
|
1035
|
+
finite(shape.gap) ? clamp(shape.gap, 0, AVATAR_BOX) : 0;
|
|
1036
|
+
|
|
1037
|
+
/** How far a layer's shapes reach from the middle of the picture, across or down, once turned. */
|
|
1038
|
+
function reachOf(shapes: readonly AvatarShape[], turn: number): number {
|
|
1039
|
+
const middle = AVATAR_BOX / 2;
|
|
1040
|
+
const cos = cosine(turn);
|
|
1041
|
+
const sin = sine(turn);
|
|
1042
|
+
let far = 0;
|
|
1043
|
+
for (const shape of shapes) {
|
|
1044
|
+
const margin = gapOf(shape) / 2;
|
|
1045
|
+
for (const outline of listOf(shape.outlines)) {
|
|
1046
|
+
const path = pathOf(outline);
|
|
1047
|
+
for (let at = 0; at < path.length; at += 2) {
|
|
1048
|
+
const x = (path[at] ?? 0) - middle;
|
|
1049
|
+
const y = (path[at + 1] ?? 0) - middle;
|
|
1050
|
+
far = Math.max(
|
|
1051
|
+
far,
|
|
1052
|
+
Math.abs(x * cos - y * sin) + margin,
|
|
1053
|
+
Math.abs(x * sin + y * cos) + margin,
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return far;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
/** How much of the picture's half a planet drawn larger may reach, with what stands beside it. */
|
|
1062
|
+
const CLOSE_REACH = 0.94;
|
|
1063
|
+
|
|
1064
|
+
/** The picture an avatar's parts name, `side` pixels a side: red, green and blue of each pixel. */
|
|
1065
|
+
function drawn(parts: RestAvatarParts, side: number, sets: readonly AvatarSet[]): Float32Array {
|
|
1066
|
+
const set = avatarSetOf(parts, sets);
|
|
1067
|
+
const own = thing(choiceOf(set.ramps, parts.palette)) ?? NO_RAMP;
|
|
1068
|
+
const partner = thing(choiceOf(set.ramps, own.partner)) ?? own;
|
|
1069
|
+
const body = thing(choiceOf(set.bodies, parts.form));
|
|
1070
|
+
const surface = thing(choiceOf(set.surfaces, parts.material)) ?? { tone: 0, shapes: [] };
|
|
1071
|
+
const accent = thing(choiceOf(set.accents, parts.accent)) ?? { behind: [], before: [] };
|
|
1072
|
+
const ground = colorOf(choiceOf(set.grounds, parts.ground) ?? NO_GROUND);
|
|
1073
|
+
const middle = AVATAR_BOX / 2;
|
|
1074
|
+
const scale = side / AVATAR_BOX;
|
|
1075
|
+
|
|
1076
|
+
const sheet = sheetOf(side);
|
|
1077
|
+
const { pixels } = sheet;
|
|
1078
|
+
for (let at = 0; at < pixels.length; at += 3) {
|
|
1079
|
+
pixels[at] = ground[0];
|
|
1080
|
+
pixels[at + 1] = ground[1];
|
|
1081
|
+
pixels[at + 2] = ground[2];
|
|
1082
|
+
}
|
|
1083
|
+
const all: Frame = { left: 0, top: 0, right: side, bottom: side };
|
|
1084
|
+
let corners = MOST_CORNERS;
|
|
1085
|
+
/** An outline as a path, while the picture has corners left for it. */
|
|
1086
|
+
const pathIn = (outline: AvatarOutline): Path => {
|
|
1087
|
+
const path = pathOf(outline);
|
|
1088
|
+
if (path.length / 2 > corners) {
|
|
1089
|
+
return [];
|
|
1090
|
+
}
|
|
1091
|
+
corners -= path.length / 2;
|
|
1092
|
+
return path;
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
// The squares on the ground, faint, which a small picture has no room for.
|
|
1096
|
+
if (side >= AVATAR_PLAIN_UNDER) {
|
|
1097
|
+
const flat: Placing = { cos: 1, sin: 0, zoom: 1, scale };
|
|
1098
|
+
for (const square of squaresOf(
|
|
1099
|
+
Math.abs(Math.trunc(finite(parts.vein) ? parts.vein : 0)),
|
|
1100
|
+
listOf(set.confetti),
|
|
1101
|
+
)) {
|
|
1102
|
+
const path: Path = [
|
|
1103
|
+
square.x,
|
|
1104
|
+
square.y,
|
|
1105
|
+
square.x + SQUARE,
|
|
1106
|
+
square.y,
|
|
1107
|
+
square.x + SQUARE,
|
|
1108
|
+
square.y + SQUARE,
|
|
1109
|
+
square.x,
|
|
1110
|
+
square.y + SQUARE,
|
|
1111
|
+
];
|
|
1112
|
+
fill(sheet, pixels, all, [placed(path, flat)], undefined, square.color, square.color, 0.5);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// The planet is drawn as much larger as its set asks, and that of a small picture closer
|
|
1117
|
+
// still: never past what stands beside it leaves room for.
|
|
1118
|
+
const fuller = finite(set.fill) ? clamp(set.fill, 1, AVATAR_FILL_MOST) : 1;
|
|
1119
|
+
const most = side < AVATAR_CLOSE_UNDER ? Math.max(fuller, AVATAR_CLOSE_MOST) : fuller;
|
|
1120
|
+
let zoom = 1;
|
|
1121
|
+
if (most > 1) {
|
|
1122
|
+
let far = reachOf(
|
|
1123
|
+
[{ outlines: listOf(body?.outlines), tone: 0 }, ...thingsOf(body?.behind)],
|
|
1124
|
+
0,
|
|
1125
|
+
);
|
|
1126
|
+
for (const layer of [...thingsOf(accent.behind), ...thingsOf(accent.before)]) {
|
|
1127
|
+
far = Math.max(far, reachOf(thingsOf(layer.shapes), finite(layer.turn) ? layer.turn : 0));
|
|
1128
|
+
}
|
|
1129
|
+
zoom = far > 0 ? clamp((middle * CLOSE_REACH) / far, 1, most) : 1;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/** One shape, in its ramp, as its layer is turned and cut. */
|
|
1133
|
+
const shapeOn = (
|
|
1134
|
+
target: Float32Array,
|
|
1135
|
+
frame: Frame,
|
|
1136
|
+
shape: AvatarShape,
|
|
1137
|
+
inRamp: AvatarRamp,
|
|
1138
|
+
layer: { readonly turn?: number | undefined; readonly half?: "upper" | "lower" | undefined },
|
|
1139
|
+
through?: Float32Array,
|
|
1140
|
+
): void => {
|
|
1141
|
+
const turn = finite(layer.turn) ? layer.turn : 0;
|
|
1142
|
+
const placing: Placing = { cos: cosine(turn), sin: sine(turn), zoom, scale };
|
|
1143
|
+
const split = finite(shape.split) ? shape.split : middle;
|
|
1144
|
+
const opacity = finite(shape.opacity) ? clamp(shape.opacity) : 1;
|
|
1145
|
+
const outlines = listOf(shape.outlines).map(pathIn);
|
|
1146
|
+
const gap = gapOf(shape);
|
|
1147
|
+
if (gap > 0) {
|
|
1148
|
+
const line = outlines.flatMap((path) => lineAlong(path, gap));
|
|
1149
|
+
fill(
|
|
1150
|
+
sheet,
|
|
1151
|
+
target,
|
|
1152
|
+
frame,
|
|
1153
|
+
line.map((path) => placed(path, placing)),
|
|
1154
|
+
undefined,
|
|
1155
|
+
ground,
|
|
1156
|
+
ground,
|
|
1157
|
+
1,
|
|
1158
|
+
through,
|
|
1159
|
+
);
|
|
1160
|
+
}
|
|
1161
|
+
const kept = outlines.map((path) =>
|
|
1162
|
+
layer.half === "upper"
|
|
1163
|
+
? cut(path, 0, 1, middle)
|
|
1164
|
+
: layer.half === "lower"
|
|
1165
|
+
? cut(path, 0, -1, -middle)
|
|
1166
|
+
: path,
|
|
1167
|
+
);
|
|
1168
|
+
const [lighter, darker] = tonesOf(shape, inRamp);
|
|
1169
|
+
fill(
|
|
1170
|
+
sheet,
|
|
1171
|
+
target,
|
|
1172
|
+
frame,
|
|
1173
|
+
kept.map((path) => placed(path, placing)),
|
|
1174
|
+
kept.map((path) => placed(cut(path, 1, 0, split), placing)),
|
|
1175
|
+
lighter,
|
|
1176
|
+
darker,
|
|
1177
|
+
opacity,
|
|
1178
|
+
through,
|
|
1179
|
+
);
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
for (const shape of thingsOf(body?.behind)) {
|
|
1183
|
+
shapeOn(pixels, all, shape, own, {});
|
|
1184
|
+
}
|
|
1185
|
+
for (const layer of thingsOf(accent.behind)) {
|
|
1186
|
+
for (const shape of thingsOf(layer.shapes)) {
|
|
1187
|
+
shapeOn(pixels, all, shape, partner, layer);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// The body: its surface is drawn whole on a sheet of its own, and put on the picture through
|
|
1192
|
+
// the body's outline, so that the body's edge is smoothed once.
|
|
1193
|
+
if (body !== undefined) {
|
|
1194
|
+
const still: Placing = { cos: 1, sin: 0, zoom, scale };
|
|
1195
|
+
const mask = new Float32Array(side * side);
|
|
1196
|
+
const reach = cover(
|
|
1197
|
+
sheet,
|
|
1198
|
+
mask,
|
|
1199
|
+
listOf(body.outlines).map((outline) => placed(pathIn(outline), still)),
|
|
1200
|
+
);
|
|
1201
|
+
if (reach.top < reach.bottom) {
|
|
1202
|
+
const within: Frame = {
|
|
1203
|
+
left: Math.max(0, reach.left - 1),
|
|
1204
|
+
top: Math.max(0, reach.top - 1),
|
|
1205
|
+
right: Math.min(side, reach.right + 1),
|
|
1206
|
+
bottom: Math.min(side, reach.bottom + 1),
|
|
1207
|
+
};
|
|
1208
|
+
const skin = new Float32Array(side * side * 3);
|
|
1209
|
+
const everywhere: AvatarOutline = [
|
|
1210
|
+
[-AVATAR_BOX, -AVATAR_BOX],
|
|
1211
|
+
[2 * AVATAR_BOX, -AVATAR_BOX],
|
|
1212
|
+
[2 * AVATAR_BOX, 2 * AVATAR_BOX],
|
|
1213
|
+
[-AVATAR_BOX, 2 * AVATAR_BOX],
|
|
1214
|
+
];
|
|
1215
|
+
shapeOn(
|
|
1216
|
+
skin,
|
|
1217
|
+
within,
|
|
1218
|
+
{ outlines: [everywhere], tone: finite(surface.tone) ? surface.tone : 0 },
|
|
1219
|
+
own,
|
|
1220
|
+
{},
|
|
1221
|
+
);
|
|
1222
|
+
for (const shape of thingsOf(surface.shapes)) {
|
|
1223
|
+
shapeOn(skin, within, shape, own, {});
|
|
1224
|
+
}
|
|
1225
|
+
for (let row = within.top; row < within.bottom; row += 1) {
|
|
1226
|
+
for (let column = within.left; column < within.right; column += 1) {
|
|
1227
|
+
const cell = row * side + column;
|
|
1228
|
+
const share = mask[cell] ?? 0;
|
|
1229
|
+
if (share <= 0) {
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
const pixel = cell * 3;
|
|
1233
|
+
for (let color = 0; color < 3; color += 1) {
|
|
1234
|
+
const under = pixels[pixel + color] ?? 0;
|
|
1235
|
+
pixels[pixel + color] = under + ((skin[pixel + color] ?? 0) - under) * share;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
for (const layer of thingsOf(accent.before)) {
|
|
1243
|
+
for (const shape of thingsOf(layer.shapes)) {
|
|
1244
|
+
shapeOn(pixels, all, shape, partner, layer);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
return pixels;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/** The size a picture is drawn at: a whole number of pixels, from 16 to the most the module writes. */
|
|
1251
|
+
function pixelsOf(size: number): number {
|
|
1252
|
+
const whole = Math.trunc(size);
|
|
1253
|
+
if (!Number.isFinite(whole) || whole < 16 || whole > MAX_AVATAR_PIXELS) {
|
|
1254
|
+
throw new RangeError(`an avatar is drawn from 16 to ${MAX_AVATAR_PIXELS} pixels a side`);
|
|
1255
|
+
}
|
|
1256
|
+
return whole;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* The avatar as pixels, `size` a side: three bytes each, red, green and blue, row after row from
|
|
1261
|
+
* the top. The same parts give the same bytes wherever they are drawn.
|
|
1262
|
+
*/
|
|
1263
|
+
export function avatarPixels(
|
|
1264
|
+
parts: RestAvatarParts,
|
|
1265
|
+
size: number,
|
|
1266
|
+
sets: readonly AvatarSet[] = AVATAR_SETS,
|
|
1267
|
+
): Uint8Array {
|
|
1268
|
+
const side = pixelsOf(size);
|
|
1269
|
+
const colors = drawn(parts, side, sets);
|
|
1270
|
+
const pixels = new Uint8Array(side * side * 3);
|
|
1271
|
+
for (let at = 0; at < pixels.length; at += 1) {
|
|
1272
|
+
// A typed array keeps a byte: what is above 255 or under 0 is brought back first.
|
|
1273
|
+
pixels[at] = Math.round(clamp(colors[at] ?? 0, 0, 255));
|
|
1274
|
+
}
|
|
1275
|
+
return pixels;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* The avatar as the rows a PNG file compresses: each row of pixels after the byte that says it
|
|
1280
|
+
* is filtered in no way. What comes back from a zlib deflate of these is `pngFile`'s to wrap.
|
|
1281
|
+
*/
|
|
1282
|
+
export function avatarScanlines(
|
|
1283
|
+
parts: RestAvatarParts,
|
|
1284
|
+
size: number,
|
|
1285
|
+
sets: readonly AvatarSet[] = AVATAR_SETS,
|
|
1286
|
+
): Uint8Array {
|
|
1287
|
+
const side = pixelsOf(size);
|
|
1288
|
+
const pixels = avatarPixels(parts, side, sets);
|
|
1289
|
+
const row = side * 3;
|
|
1290
|
+
const lines = new Uint8Array(side * (row + 1));
|
|
1291
|
+
for (let y = 0; y < side; y += 1) {
|
|
1292
|
+
lines.set(pixels.subarray(y * row, (y + 1) * row), y * (row + 1) + 1);
|
|
1293
|
+
}
|
|
1294
|
+
return lines;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
/** The checksum a PNG file keeps of each of its chunks. */
|
|
1298
|
+
const CRC_TABLE = Uint32Array.from({ length: 256 }, (_, index) => {
|
|
1299
|
+
let value = index;
|
|
1300
|
+
for (let bit = 0; bit < 8; bit += 1) {
|
|
1301
|
+
value = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
|
|
1302
|
+
}
|
|
1303
|
+
return value >>> 0;
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
function crc32(bytes: Uint8Array): number {
|
|
1307
|
+
let crc = 0xffffffff;
|
|
1308
|
+
for (const byte of bytes) {
|
|
1309
|
+
crc = (CRC_TABLE[(crc ^ byte) & 0xff] ?? 0) ^ (crc >>> 8);
|
|
1310
|
+
}
|
|
1311
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
/** One chunk of a PNG file: its length, its name, its bytes and their checksum. */
|
|
1315
|
+
function chunk(name: string, data: Uint8Array): Uint8Array {
|
|
1316
|
+
const out = new Uint8Array(12 + data.length);
|
|
1317
|
+
const view = new DataView(out.buffer);
|
|
1318
|
+
view.setUint32(0, data.length);
|
|
1319
|
+
for (let i = 0; i < 4; i += 1) {
|
|
1320
|
+
out[4 + i] = name.charCodeAt(i);
|
|
1321
|
+
}
|
|
1322
|
+
out.set(data, 8);
|
|
1323
|
+
view.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
|
|
1324
|
+
return out;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* A PNG file of `size` pixels a side, of eight bits a colour and no transparency, from its rows
|
|
1329
|
+
* already compressed: `deflated` is the zlib stream of `avatarScanlines`, which the runtime
|
|
1330
|
+
* makes (`deflateSync` of `node:zlib`, a `CompressionStream("deflate")` in a browser).
|
|
1331
|
+
*/
|
|
1332
|
+
export function pngFile(size: number, deflated: Uint8Array): Uint8Array {
|
|
1333
|
+
const side = pixelsOf(size);
|
|
1334
|
+
const header = new Uint8Array(13);
|
|
1335
|
+
const view = new DataView(header.buffer);
|
|
1336
|
+
view.setUint32(0, side);
|
|
1337
|
+
view.setUint32(4, side);
|
|
1338
|
+
header[8] = 8; // bits a sample
|
|
1339
|
+
header[9] = 2; // red, green and blue
|
|
1340
|
+
const parts = [
|
|
1341
|
+
Uint8Array.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
1342
|
+
chunk("IHDR", header),
|
|
1343
|
+
chunk("IDAT", deflated),
|
|
1344
|
+
chunk("IEND", new Uint8Array(0)),
|
|
1345
|
+
];
|
|
1346
|
+
const file = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
1347
|
+
let at = 0;
|
|
1348
|
+
for (const part of parts) {
|
|
1349
|
+
file.set(part, at);
|
|
1350
|
+
at += part.length;
|
|
1351
|
+
}
|
|
1352
|
+
return file;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/** The most bytes one block of a zlib stream holds unpacked. */
|
|
1356
|
+
const STORED_BLOCK = 65_535;
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* Bytes as a zlib stream that packs nothing: each block says its length and holds the bytes as
|
|
1360
|
+
* they are. Larger than a packed one, and written here, at once, with no help of a runtime: what
|
|
1361
|
+
* a picture shown on a page wants, where waiting for a compressor would leave a gap.
|
|
1362
|
+
*/
|
|
1363
|
+
function stored(bytes: Uint8Array): Uint8Array {
|
|
1364
|
+
const blocks = Math.max(1, Math.ceil(bytes.length / STORED_BLOCK));
|
|
1365
|
+
const out = new Uint8Array(2 + blocks * 5 + bytes.length + 4);
|
|
1366
|
+
out[0] = 0x78;
|
|
1367
|
+
out[1] = 0x01;
|
|
1368
|
+
let at = 2;
|
|
1369
|
+
for (let block = 0; block < blocks; block += 1) {
|
|
1370
|
+
const from = block * STORED_BLOCK;
|
|
1371
|
+
const held = Math.min(STORED_BLOCK, bytes.length - from);
|
|
1372
|
+
out[at] = block === blocks - 1 ? 1 : 0;
|
|
1373
|
+
out[at + 1] = held & 0xff;
|
|
1374
|
+
out[at + 2] = held >>> 8;
|
|
1375
|
+
out[at + 3] = ~held & 0xff;
|
|
1376
|
+
out[at + 4] = (~held >>> 8) & 0xff;
|
|
1377
|
+
out.set(bytes.subarray(from, from + held), at + 5);
|
|
1378
|
+
at += 5 + held;
|
|
1379
|
+
}
|
|
1380
|
+
// The checksum of a zlib stream, of what it holds unpacked.
|
|
1381
|
+
let low = 1;
|
|
1382
|
+
let high = 0;
|
|
1383
|
+
for (const byte of bytes) {
|
|
1384
|
+
low = (low + byte) % 65_521;
|
|
1385
|
+
high = (high + low) % 65_521;
|
|
1386
|
+
}
|
|
1387
|
+
out[at] = high >>> 8;
|
|
1388
|
+
out[at + 1] = high & 0xff;
|
|
1389
|
+
out[at + 2] = low >>> 8;
|
|
1390
|
+
out[at + 3] = low & 0xff;
|
|
1391
|
+
return out;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
1395
|
+
|
|
1396
|
+
/** Bytes in base64, as an address of a picture holds them. */
|
|
1397
|
+
function base64(bytes: Uint8Array): string {
|
|
1398
|
+
const out: string[] = [];
|
|
1399
|
+
let line = "";
|
|
1400
|
+
for (let at = 0; at < bytes.length; at += 3) {
|
|
1401
|
+
const a = bytes[at] ?? 0;
|
|
1402
|
+
const b = bytes[at + 1] ?? 0;
|
|
1403
|
+
const c = bytes[at + 2] ?? 0;
|
|
1404
|
+
line += BASE64.charAt(a >>> 2) + BASE64.charAt(((a & 3) << 4) | (b >>> 4));
|
|
1405
|
+
line += at + 1 < bytes.length ? BASE64.charAt(((b & 15) << 2) | (c >>> 6)) : "=";
|
|
1406
|
+
line += at + 2 < bytes.length ? BASE64.charAt(c & 63) : "=";
|
|
1407
|
+
if (line.length >= 8192) {
|
|
1408
|
+
out.push(line);
|
|
1409
|
+
line = "";
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
out.push(line);
|
|
1413
|
+
return out.join("");
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/** How many pictures are kept drawn for the pages, the ones asked for longest ago let go first. */
|
|
1417
|
+
const KEPT_PICTURES = 256;
|
|
1418
|
+
const kept = new WeakMap<readonly AvatarSet[], Map<string, string>>();
|
|
1419
|
+
|
|
1420
|
+
/**
|
|
1421
|
+
* The avatar as the address of a picture, `data:image/png;base64,…`, `size` pixels a side: what a
|
|
1422
|
+
* page gives an `img`. Drawn at once and kept, so that a picture shown in many places, or shown
|
|
1423
|
+
* again, is drawn once. The file inside is a whole PNG, larger than a packed one.
|
|
1424
|
+
*/
|
|
1425
|
+
export function avatarDataUrl(
|
|
1426
|
+
parts: RestAvatarParts,
|
|
1427
|
+
size: number,
|
|
1428
|
+
sets: readonly AvatarSet[] = AVATAR_SETS,
|
|
1429
|
+
): string {
|
|
1430
|
+
const side = pixelsOf(size);
|
|
1431
|
+
let pictures = kept.get(sets);
|
|
1432
|
+
if (pictures === undefined) {
|
|
1433
|
+
pictures = new Map();
|
|
1434
|
+
kept.set(sets, pictures);
|
|
1435
|
+
}
|
|
1436
|
+
const key = [
|
|
1437
|
+
side,
|
|
1438
|
+
parts.set,
|
|
1439
|
+
parts.palette,
|
|
1440
|
+
parts.ground,
|
|
1441
|
+
parts.form,
|
|
1442
|
+
parts.material,
|
|
1443
|
+
parts.accent,
|
|
1444
|
+
parts.vein,
|
|
1445
|
+
].join(".");
|
|
1446
|
+
const found = pictures.get(key);
|
|
1447
|
+
if (found !== undefined) {
|
|
1448
|
+
return found;
|
|
1449
|
+
}
|
|
1450
|
+
const address = `data:image/png;base64,${base64(pngFile(side, stored(avatarScanlines(parts, side, sets))))}`;
|
|
1451
|
+
if (pictures.size >= KEPT_PICTURES) {
|
|
1452
|
+
const oldest = pictures.keys().next();
|
|
1453
|
+
if (oldest.done !== true) {
|
|
1454
|
+
pictures.delete(oldest.value);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
pictures.set(key, address);
|
|
1458
|
+
return address;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/** Numbers from a seed: the same seed gives the same numbers, each from 0 up to but not 1. */
|
|
1462
|
+
export function seededNumbers(seed: string): () => number {
|
|
1463
|
+
// A hash of the text for a start, then a generator of 32 bits; neither is for secrets.
|
|
1464
|
+
let start = 1779033703 ^ seed.length;
|
|
1465
|
+
for (let i = 0; i < seed.length; i += 1) {
|
|
1466
|
+
start = Math.imul(start ^ seed.charCodeAt(i), 3432918353);
|
|
1467
|
+
start = (start << 13) | (start >>> 19);
|
|
1468
|
+
}
|
|
1469
|
+
let state = start >>> 0;
|
|
1470
|
+
return () => {
|
|
1471
|
+
state = (state + 0x6d2b79f5) >>> 0;
|
|
1472
|
+
let next = state;
|
|
1473
|
+
next = Math.imul(next ^ (next >>> 15), next | 1);
|
|
1474
|
+
next ^= next + Math.imul(next ^ (next >>> 7), next | 61);
|
|
1475
|
+
return ((next ^ (next >>> 14)) >>> 0) / 4294967296;
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
/** How many ways the squares on a ground may be strewn: the seed of one is a byte. */
|
|
1480
|
+
export const AVATAR_VEINS = 256;
|
|
1481
|
+
|
|
1482
|
+
/**
|
|
1483
|
+
* The parts a seed gives, of the newest of `sets`: the same seed, the same avatar. A body, a
|
|
1484
|
+
* surface and a ramp are rolled alike; nothing stands beside the body a little less than half
|
|
1485
|
+
* the time, and the other accents share the rest.
|
|
1486
|
+
*/
|
|
1487
|
+
export function rollAvatar(
|
|
1488
|
+
seed: string,
|
|
1489
|
+
sets: readonly AvatarSet[] = AVATAR_SETS,
|
|
1490
|
+
): RestAvatarParts {
|
|
1491
|
+
const set = avatarSetOf({ set: Number.MAX_SAFE_INTEGER }, sets);
|
|
1492
|
+
const next = seededNumbers(`avatar:${seed}`);
|
|
1493
|
+
const pick = (choices: number): number => (choices <= 0 ? 0 : Math.floor(next() * choices));
|
|
1494
|
+
/** One of the choices after the first, or the first, which is rolled `often` of the time. */
|
|
1495
|
+
const perhaps = (choices: number, often: number): number =>
|
|
1496
|
+
choices <= 1 || next() < often ? 0 : 1 + pick(choices - 1);
|
|
1497
|
+
return {
|
|
1498
|
+
set: set.version,
|
|
1499
|
+
palette: pick(listOf(set.ramps).length),
|
|
1500
|
+
ground: pick(listOf(set.grounds).length),
|
|
1501
|
+
form: pick(listOf(set.bodies).length),
|
|
1502
|
+
material: pick(listOf(set.surfaces).length),
|
|
1503
|
+
accent: perhaps(listOf(set.accents).length, 0.45),
|
|
1504
|
+
vein: pick(AVATAR_VEINS),
|
|
1505
|
+
};
|
|
1506
|
+
}
|