gentle-pi 4.7.0 → 4.8.0
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 +55 -44
- package/assets/agents/gentle-ai-explore.md +3 -3
- package/assets/agents/gentle-ai-verify.md +20 -6
- package/assets/agents/gentle-ai-worker.md +6 -6
- package/assets/agents/jd-judge-a.md +1 -3
- package/assets/agents/jd-judge-b.md +1 -3
- package/assets/agents/review-readability.md +1 -5
- package/assets/agents/review-reliability.md +1 -5
- package/assets/agents/review-resilience.md +1 -5
- package/assets/agents/review-risk.md +1 -5
- package/assets/design-canvas/canvas-api.js +45 -0
- package/assets/design-canvas/canvas-boards.js +456 -0
- package/assets/design-canvas/canvas-boot.js +217 -0
- package/assets/design-canvas/canvas-checks.js +491 -0
- package/assets/design-canvas/canvas-comments.js +315 -0
- package/assets/design-canvas/canvas-compare.js +159 -0
- package/assets/design-canvas/canvas-events.js +75 -0
- package/assets/design-canvas/canvas-export.js +393 -0
- package/assets/design-canvas/canvas-focus.js +203 -0
- package/assets/design-canvas/canvas-handoffs.js +150 -0
- package/assets/design-canvas/canvas-i18n-es.js +392 -0
- package/assets/design-canvas/canvas-i18n.js +108 -0
- package/assets/design-canvas/canvas-layout.js +526 -0
- package/assets/design-canvas/canvas-menu.js +213 -0
- package/assets/design-canvas/canvas-messages.js +86 -0
- package/assets/design-canvas/canvas-minimap.js +163 -0
- package/assets/design-canvas/canvas-parts.js +401 -0
- package/assets/design-canvas/canvas-popover.js +234 -0
- package/assets/design-canvas/canvas-rail.js +348 -0
- package/assets/design-canvas/canvas-sizes.js +524 -0
- package/assets/design-canvas/canvas-store.js +164 -0
- package/assets/design-canvas/canvas-tokens.js +674 -0
- package/assets/design-canvas/canvas-ui.js +24 -0
- package/assets/design-canvas/canvas-view.js +184 -0
- package/assets/design-canvas/canvas.css +746 -15
- package/assets/design-canvas/canvas.js +2 -1506
- package/assets/design-canvas/index.html +117 -36
- package/assets/design-canvas/inspector.js +546 -16
- package/assets/install-wizard/wizard.js +5 -1
- package/assets/migrations/agent-body-history.json +24 -0
- package/assets/orchestrator-delegation-reference.md +8 -14
- package/assets/orchestrator-delegation.md +4 -4
- package/assets/orchestrator-full-delegation-card.md +4 -5
- package/assets/orchestrator-full-delegation.md +8 -8
- package/assets/orchestrator-memory.md +2 -2
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +13 -12
- package/assets/orchestrator-tracking.md +10 -14
- package/assets/orchestrator-verification.md +10 -8
- package/assets/orchestrator-writer.md +4 -4
- package/assets/orchestrator.md +18 -22
- package/bin/gentle-shell.mjs +128 -9
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/bundled-install.md +14 -6
- package/docs/delegated-verification.md +18 -2
- package/docs/desktop-rpc.md +1253 -0
- package/docs/gentle-agents-activity.md +26 -0
- package/docs/gentle-shell.md +39 -16
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +9 -1
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +76 -24
- package/docs/review-coordinator.md +29 -9
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/work-continuity.md +11 -1
- package/extensions/ask-user-question.ts +2 -2
- package/extensions/child-context.ts +21 -7
- package/extensions/gentle-agents.ts +234 -33
- package/extensions/gentle-ai.ts +576 -135
- package/extensions/gentle-design.ts +69 -3
- package/extensions/gentle-desktop-rpc.ts +143 -0
- package/extensions/gentle-guide.ts +3 -0
- package/extensions/gentle-shell.ts +105 -52
- package/extensions/gentle-todo.ts +48 -25
- package/extensions/skill-registry.ts +248 -223
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +47 -6
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +8 -2
- package/lib/agents-protocol.ts +15 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-runner.ts +91 -6
- package/lib/agents-session-transport.ts +17 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/bounded-writer-admission.ts +184 -31
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/delivery-conflict-markers.ts +349 -0
- package/lib/design-canvas-assets.ts +36 -0
- package/lib/design-canvas-server.ts +241 -23
- package/lib/design-comments.ts +94 -4
- package/lib/design-handoffs.ts +2 -1
- package/lib/design-layout.ts +125 -0
- package/lib/design-parts.ts +281 -0
- package/lib/design-system-tokens.ts +111 -0
- package/lib/desktop-agents-service.ts +294 -0
- package/lib/desktop-design-service.ts +233 -0
- package/lib/desktop-jobs-service.ts +263 -0
- package/lib/desktop-rpc-agents.ts +294 -0
- package/lib/desktop-rpc-config.ts +731 -0
- package/lib/desktop-rpc-design.ts +138 -0
- package/lib/desktop-rpc-jobs.ts +181 -0
- package/lib/desktop-rpc-permissions.ts +177 -0
- package/lib/desktop-rpc-profiles.ts +196 -0
- package/lib/desktop-rpc-usage.ts +229 -0
- package/lib/desktop-rpc.ts +225 -0
- package/lib/desktop-usage-service.ts +310 -0
- package/lib/destructive-command-guard.ts +188 -13
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +201 -14
- package/lib/gentle-shell-bundled.ts +100 -9
- package/lib/hidden-tools.ts +35 -0
- package/lib/inprocess-reviewer.ts +96 -12
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +9 -0
- package/lib/nan-provider.ts +42 -28
- package/lib/native-review-cli.ts +79 -4
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/reply-language-anchor.ts +27 -2
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +17 -0
- package/lib/review-coordinator.ts +252 -8
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +56 -3
- package/lib/reviewer-stream.ts +87 -0
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +6 -1
- package/package.json +2 -2
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +37 -0
- package/runtime/gentle-shell-bundled.mjs +100 -9
- package/runtime/native-review-cli.mjs +79 -4
- package/runtime/review-integration-v2.mjs +56 -3
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +4 -0
- package/scripts/build-runtime-modules.mjs +1 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/gentle-ai-proxy.mjs +1 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +28 -17
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-server.mjs +38 -9
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +40 -19
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +6 -6
- package/skills/gentle-ai/SKILL.md +5 -5
- package/skills/judgment-day/SKILL.md +2 -2
- package/skills/judgment-day/references/prompts-and-formats.md +1 -1
- package/skills/rdd-defect-workflow/SKILL.md +6 -6
- package/skills/skill-improver/SKILL.md +2 -2
- package/skills/skill-registry/SKILL.md +11 -13
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +5 -5
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
- package/tests/agent-tool-overlay.test.ts +89 -0
- package/tests/agents-config.test.ts +10 -1
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner.test.ts +37 -1
- package/tests/agents-session-transport.test.ts +34 -0
- package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
- package/tests/append-system-prompt-route.test.ts +10 -2
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-question.test.ts +2 -1
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/bounded-stop-contract.test.ts +9 -1
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bundled-install.test.ts +1 -1
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/delegate-for-reason-contract.test.ts +30 -8
- package/tests/delivery-conflict-markers.test.ts +348 -0
- package/tests/design-canvas-all-sizes.test.ts +631 -0
- package/tests/design-canvas-allowlist.test.ts +32 -0
- package/tests/design-canvas-assets.test.ts +11 -878
- package/tests/design-canvas-boards.test.ts +77 -0
- package/tests/design-canvas-checks.test.ts +655 -0
- package/tests/design-canvas-compare.test.ts +79 -0
- package/tests/design-canvas-events.test.ts +59 -0
- package/tests/design-canvas-export.test.ts +1168 -0
- package/tests/design-canvas-focus.test.ts +113 -0
- package/tests/design-canvas-handoffs.test.ts +59 -0
- package/tests/design-canvas-i18n-review.test.ts +513 -0
- package/tests/design-canvas-i18n-views.test.ts +259 -0
- package/tests/design-canvas-i18n.test.ts +526 -0
- package/tests/design-canvas-inspector.test.ts +937 -0
- package/tests/design-canvas-layout.test.ts +1222 -0
- package/tests/design-canvas-minimap.test.ts +413 -0
- package/tests/design-canvas-modules.test.ts +90 -0
- package/tests/design-canvas-parts.test.ts +721 -0
- package/tests/design-canvas-rail.test.ts +799 -0
- package/tests/design-canvas-server.test.ts +855 -17
- package/tests/design-canvas-sizes.test.ts +548 -0
- package/tests/design-canvas-store.test.ts +180 -0
- package/tests/design-canvas-tokens.test.ts +965 -0
- package/tests/design-canvas-view.test.ts +299 -0
- package/tests/design-comments.test.ts +201 -1
- package/tests/design-handoffs.test.ts +20 -0
- package/tests/design-layout.test.ts +100 -0
- package/tests/design-parts.test.ts +260 -0
- package/tests/design-system-tokens.test.ts +215 -0
- package/tests/desktop-rpc-agents.test.ts +893 -0
- package/tests/desktop-rpc-config.test.ts +1452 -0
- package/tests/desktop-rpc-design.test.ts +662 -0
- package/tests/desktop-rpc-jobs.test.ts +796 -0
- package/tests/desktop-rpc-permissions.test.ts +311 -0
- package/tests/desktop-rpc-profiles.test.ts +140 -0
- package/tests/desktop-rpc-safety.test.ts +119 -0
- package/tests/desktop-rpc-usage.test.ts +697 -0
- package/tests/desktop-rpc.test.ts +252 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/full-delegation-closure.test.ts +29 -0
- package/tests/gentle-agents.test.ts +329 -4
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +121 -6
- package/tests/gentle-design.test.ts +365 -1
- package/tests/gentle-shell-bundled.test.ts +91 -5
- package/tests/gentle-shell-launcher.test.ts +1 -1
- package/tests/gentle-shell.test.ts +118 -87
- package/tests/gentle-todo.test.ts +32 -9
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/independent-recovery-delivery.test.ts +19 -5
- package/tests/inprocess-reviewer.test.ts +73 -0
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +114 -13
- package/tests/installer-preflight.test.ts +49 -1
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-server.test.ts +203 -4
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/judgment-day-severity-admission.test.ts +46 -0
- package/tests/lazy-module-contradictions-contract.test.ts +158 -0
- package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
- package/tests/maintainer/pi-update-source.maintest.ts +48 -18
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-review-capability-contract.test.ts +11 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-parity.test.ts +24 -5
- package/tests/native-review-refusal-identity.test.ts +25 -0
- package/tests/no-self-pause-contract.test.ts +11 -3
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-contract.test.ts +80 -28
- package/tests/orchestrator-budget.test.ts +30 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +2 -1
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-prompt-budget.test.ts +11 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -1
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +11 -10
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +200 -30
- package/tests/persona-neutral-voseo.test.ts +4 -4
- package/tests/persona-reply-language.test.ts +1 -1
- package/tests/persona-single-channel.test.ts +13 -5
- package/tests/pi-update-launcher.test.ts +17 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-policy.test.ts +47 -0
- package/tests/primary-context-files.test.ts +233 -0
- package/tests/primary-context-three-files.test.ts +174 -0
- package/tests/provider-defect-handoff.test.ts +9 -2
- package/tests/rdd-aware-verification-contract.test.ts +1 -1
- package/tests/rdd-status-line.test.ts +94 -1
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +17 -1
- package/tests/request-context-append-only.test.ts +218 -0
- package/tests/request-context-placement.test.ts +148 -0
- package/tests/review-agent-end-preflight.test.ts +79 -1
- package/tests/review-candidate-view.test.ts +65 -0
- package/tests/review-continuation-registry.test.ts +31 -0
- package/tests/review-contract-prompt.test.ts +1 -1
- package/tests/review-controller.test.ts +2 -1
- package/tests/review-coordinator-correction-gate.test.ts +105 -0
- package/tests/review-coordinator-findings.test.ts +206 -0
- package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
- package/tests/review-coordinator.test.ts +271 -4
- package/tests/review-delivery-preflight.test.ts +462 -0
- package/tests/review-due-compaction.test.ts +31 -0
- package/tests/review-due-public-boundary.test.ts +26 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-json-arguments.test.ts +41 -2
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
- package/tests/review-one-call-findings.test.ts +131 -0
- package/tests/review-one-call-followups.test.ts +308 -0
- package/tests/review-one-call-reviewer-requests.test.ts +207 -0
- package/tests/review-one-call.test.ts +452 -0
- package/tests/review-relay-transport-agent.test.ts +28 -1
- package/tests/review-reviewer-evidence.test.ts +41 -1
- package/tests/review-risk-assessment.test.ts +52 -5
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +32 -2
- package/tests/review-tool-prose-budget.test.ts +1 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/session-profile-extension.test.ts +2 -2
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-usage.test.ts +59 -10
- package/tests/skill-contradictions-contract.test.ts +122 -0
- package/tests/skill-registry-watcher.test.ts +216 -2
- package/tests/skill-registry.test.ts +929 -306
- package/tests/support/design-canvas-dom.ts +369 -0
- package/tests/support/review-coordinator-runtime.ts +212 -17
- package/tests/task-size-routing-contract.test.ts +42 -11
- package/tests/test-strength-contract.test.ts +2 -1
- package/tests/todo-request-append-only.test.ts +214 -0
- package/tests/tool-batching-contract.test.ts +3 -1
- package/tests/update-agent-body-history.test.ts +138 -0
- package/tests/verification-tiers-contract.test.ts +229 -0
- package/tests/verifier-preparation.test.ts +229 -0
- package/tests/verify-agent-contract.test.ts +20 -2
- package/tests/verify-first-launch-contract.test.ts +87 -11
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +54 -11
- package/tests/writer-admission-messages.test.ts +232 -0
- package/tests/writer-batch-admission.test.ts +66 -0
- package/tests/writer-edit-surface-scope.test.ts +52 -20
- package/tests/writer-feature-document-admission.test.ts +184 -0
- package/tests/yolo-mode.test.ts +39 -0
- package/skills/_shared/review-ledger-contract.md +0 -106
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
// The token inspector. With Technical details on (a checkbox in the rail's Settings, off by
|
|
2
|
+
// default, saved in this browser), Comment mode shows a panel beside the frame of the element
|
|
3
|
+
// under the pointer: inspector.js measures it (gd:inspect) and this module compares its computed
|
|
4
|
+
// color, background, font, sizes, spacing and radius with the tokens of design/system.md, computes
|
|
5
|
+
// the WCAG contrast, and offers Ask the agent to fix (the comment box, prefilled) and Copy.
|
|
6
|
+
// While a panel shows, it follows another element only once the pointer rests on it (hover intent),
|
|
7
|
+
// so the pointer can cross the artboard to the panel's buttons; Esc in the panel closes it.
|
|
8
|
+
// These are heuristics: a background image or gradient leaves the background unknown, and the
|
|
9
|
+
// match uses computed values, not the CSS that produced them.
|
|
10
|
+
// The tokens and Technical details live in the store (setTokens, setTechnical); the element the
|
|
11
|
+
// panel shows, the one it may switch to, its timers and whether the pointer is on it are this
|
|
12
|
+
// module's own view state. The panel's words follow the canvas language (canvas-i18n-es.js); what Ask the agent
|
|
13
|
+
// to fix prefills (TEXT.session) stays English, since it is an instruction for the session.
|
|
14
|
+
|
|
15
|
+
const TEXT = Object.freeze({
|
|
16
|
+
labels: { color: "Color", background: "Background", contrast: "Contrast", font: "Font", size: "Size", lineHeight: "Line height", spacing: "Spacing", radius: "Radius" },
|
|
17
|
+
unreadable: "unreadable",
|
|
18
|
+
imageBackground: "image or gradient",
|
|
19
|
+
unknownBackground: "unknown background",
|
|
20
|
+
aa: "AA (4.5 : 1)",
|
|
21
|
+
aaLarge: "AA large text (3 : 1)",
|
|
22
|
+
needs: (needed) => `needs ${needed} : 1`,
|
|
23
|
+
needsLarge: (needed) => `needs ${needed} : 1 (large text)`,
|
|
24
|
+
ok: (text) => `✓ ${text}`,
|
|
25
|
+
bad: (text) => `⚠ ${text}`,
|
|
26
|
+
noToken: "no token",
|
|
27
|
+
nearest: (name) => `Nearest ${name}`,
|
|
28
|
+
ratio: (ratio) => `${ratio} : 1`,
|
|
29
|
+
px: (value) => `${value} px`,
|
|
30
|
+
weight: (value) => `weight ${value}`,
|
|
31
|
+
normal: "normal",
|
|
32
|
+
margin: (sides) => `margin ${sides}`,
|
|
33
|
+
padding: (sides) => `padding ${sides}`,
|
|
34
|
+
onScale: "on scale",
|
|
35
|
+
offScale: (value) => `${value} px off scale`,
|
|
36
|
+
radiusNoToken: (value) => `${value} px no token`,
|
|
37
|
+
none: "—",
|
|
38
|
+
noTokens: "No design/system.md tokens found, so values and contrast are shown without a comparison.",
|
|
39
|
+
// Why the server read no tokens from a design/system.md that exists (api/system/tokens `problem`).
|
|
40
|
+
problems: {
|
|
41
|
+
"too-large": "design/system.md is over 256 KB, so its tokens were not read: values and contrast are shown without a comparison.",
|
|
42
|
+
unreadable: "design/system.md could not be read, so values and contrast are shown without a comparison.",
|
|
43
|
+
},
|
|
44
|
+
nothingToFix: "Nothing is off the design system, so there is nothing to fix.",
|
|
45
|
+
copied: "Copied",
|
|
46
|
+
copyFailed: "Could not copy. Use Ask the agent to fix and copy the text from the comment box.",
|
|
47
|
+
// The comment Ask the agent to fix prefills: instructions for the session.
|
|
48
|
+
session: {
|
|
49
|
+
textColor: "Text color",
|
|
50
|
+
background: "Background",
|
|
51
|
+
fontSize: "Font size",
|
|
52
|
+
radius: "Border radius",
|
|
53
|
+
color: (label, hex, near) => `${label} ${hex} is not a token${near ? `; nearest is ${near.name} (${near.value})` : ""}.`,
|
|
54
|
+
length: (label, value, near) => `${label} ${value}px is not a token${near ? `; nearest is ${near.name} (${near.value})` : ""}.`,
|
|
55
|
+
contrast: (ratio, needed, large) => `Contrast ${ratio}:1 is below WCAG AA (${needed}:1 for ${large ? "large" : "normal"} text).`,
|
|
56
|
+
family: (first, names) => `Font family "${first}" is not a token (${names}).`,
|
|
57
|
+
spacing: (value, near) => `Spacing ${value}px is not on the token scale${near ? `; nearest is ${near.name} (${near.value})` : ""}.`,
|
|
58
|
+
fix: (selector, flags) => `Fix the values on ${selector} that are off the design system (design/system.md):\n${flags.map((flag) => `- ${flag}`).join("\n")}`,
|
|
59
|
+
nothing: (selector) => `Nothing is off the design system on ${selector}.`,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// "on" while Technical details is on in this browser; anything else (or nothing) is off.
|
|
64
|
+
const TECHNICAL_KEY = "gentle-design:technical";
|
|
65
|
+
const TOKEN_NAME = /^--[A-Za-z0-9_-]+$/;
|
|
66
|
+
const LIMITS = { tokens: 500, selector: 500, excerpt: 300, comment: 2000, label: 80, family: 300 };
|
|
67
|
+
// The panel's size before it is laid out, its gap to the frame and the viewport's edges, and how long it
|
|
68
|
+
// stays after the element is left (the pointer may be on its way to the buttons).
|
|
69
|
+
const INSPECTOR_WIDTH = 280;
|
|
70
|
+
const INSPECTOR_HEIGHT = 340;
|
|
71
|
+
const INSPECTOR_GAP = 12;
|
|
72
|
+
const HIDE_MS = 300;
|
|
73
|
+
// While a panel shows, how long the pointer must rest on another element before the panel follows it: quicker
|
|
74
|
+
// passes (the pointer crossing the artboard on its way to the panel) keep the element and the place.
|
|
75
|
+
const DWELL_MS = 250;
|
|
76
|
+
// Channels are whole numbers, so a token matches only when it is the same color; alpha tolerates hex rounding.
|
|
77
|
+
const ALPHA_EPSILON = 0.01;
|
|
78
|
+
const NEAR_ALPHA = 0.05;
|
|
79
|
+
const SIZE_EPSILON = 0.01;
|
|
80
|
+
// The root font size a rem token is converted with when a frame reports none (the browser default).
|
|
81
|
+
const ROOT_FONT_SIZE = 16;
|
|
82
|
+
|
|
83
|
+
// ---- comparing values with tokens (pure)
|
|
84
|
+
|
|
85
|
+
function parseTokenColor(value) {
|
|
86
|
+
const hex = /^#([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.exec(value.trim());
|
|
87
|
+
if (hex) {
|
|
88
|
+
const digits = hex[1].length <= 4 ? Array.from(hex[1], (digit) => digit + digit).join("") : hex[1];
|
|
89
|
+
const channel = (index) => Number.parseInt(digits.slice(index * 2, index * 2 + 2), 16);
|
|
90
|
+
return { r: channel(0), g: channel(1), b: channel(2), a: digits.length === 8 ? Math.round((channel(3) / 255) * 100) / 100 : 1 };
|
|
91
|
+
}
|
|
92
|
+
const rgb = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)$/.exec(value.trim());
|
|
93
|
+
if (rgb && [rgb[1], rgb[2], rgb[3]].every((channel) => Number(channel) <= 255)) return { r: Number(rgb[1]), g: Number(rgb[2]), b: Number(rgb[3]), a: rgb[4] === undefined ? 1 : Math.min(1, Number(rgb[4])) };
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A token like `8px` or `0.5rem`: its number and whether it is rem (converted per page, with its root font size), else null. */
|
|
98
|
+
function parseTokenLength(value) {
|
|
99
|
+
const match = /^(-?\d*\.?\d+)(px|rem)$/.exec(value.trim());
|
|
100
|
+
return match ? { size: Number(match[1]), rem: match[2] === "rem" } : null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The tokens by what they can be compared with: colors, font families, and lengths by purpose. Parsed once per load. */
|
|
104
|
+
function tokenKinds(tokens) {
|
|
105
|
+
const kinds = { color: [], family: [], radius: [], spacing: [], fontSize: [] };
|
|
106
|
+
for (const token of tokens) {
|
|
107
|
+
const color = parseTokenColor(token.value);
|
|
108
|
+
const length = color ? null : parseTokenLength(token.value);
|
|
109
|
+
if (color) kinds.color.push({ token, color });
|
|
110
|
+
else if (length !== null) {
|
|
111
|
+
if (token.group === "radius" || /radius/.test(token.name)) kinds.radius.push({ token, length });
|
|
112
|
+
else if (token.group === "spacing" || /(^|-)(space|spacing|gap|pad|padding|margin)(-|$)/.test(token.name)) kinds.spacing.push({ token, length });
|
|
113
|
+
else if (token.group === "font" || /font|text|type/.test(token.name)) kinds.fontSize.push({ token, length });
|
|
114
|
+
} else if ((token.group === "font" || /font|family/.test(token.name)) && /[a-zA-Z]/.test(token.value)) kinds.family.push({ token, families: familyList(token.value) });
|
|
115
|
+
}
|
|
116
|
+
return kinds;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function linearChannel(value) {
|
|
120
|
+
const unit = value / 255;
|
|
121
|
+
return unit <= 0.04045 ? unit / 12.92 : ((unit + 0.055) / 1.055) ** 2.4;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** WCAG relative luminance of an sRGB color. */
|
|
125
|
+
function luminance(color) {
|
|
126
|
+
return 0.2126 * linearChannel(color.r) + 0.7152 * linearChannel(color.g) + 0.0722 * linearChannel(color.b);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** WCAG contrast ratio, 1 to 21. */
|
|
130
|
+
function contrastRatio(a, b) {
|
|
131
|
+
const [high, low] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
132
|
+
return (high + 0.05) / (low + 0.05);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** OKLab coordinates, so distances follow perceived difference rather than sRGB channel values. */
|
|
136
|
+
function oklab(color) {
|
|
137
|
+
const r = linearChannel(color.r);
|
|
138
|
+
const g = linearChannel(color.g);
|
|
139
|
+
const b = linearChannel(color.b);
|
|
140
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
141
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
142
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
143
|
+
return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function colorDistance(a, b) {
|
|
147
|
+
const [x, y] = [oklab(a), oklab(b)];
|
|
148
|
+
return Math.hypot(x[0] - y[0], x[1] - y[1], x[2] - y[2]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const hex2 = (value) => Math.round(value).toString(16).padStart(2, "0");
|
|
152
|
+
const colorHex = (color) => `#${hex2(color.r)}${hex2(color.g)}${hex2(color.b)}${color.a !== undefined && color.a < 1 ? hex2(color.a * 255) : ""}`;
|
|
153
|
+
const fmt = (value) => String(Number(value.toFixed(2)));
|
|
154
|
+
/** Contrast shown to two decimals, never rounded up: 4.499 must not read as a pass. */
|
|
155
|
+
const fmtRatio = (ratio) => String(Math.floor(ratio * 100) / 100);
|
|
156
|
+
const sides = (values) => values.map(fmt).join(" ");
|
|
157
|
+
|
|
158
|
+
/** Families of a font stack, quotes stripped, split on commas outside quotes. */
|
|
159
|
+
function familyList(value) {
|
|
160
|
+
const families = [];
|
|
161
|
+
let current = "";
|
|
162
|
+
let quote = "";
|
|
163
|
+
for (const char of value) {
|
|
164
|
+
if (quote) {
|
|
165
|
+
if (char === quote) quote = "";
|
|
166
|
+
else current += char;
|
|
167
|
+
} else if (char === "\"" || char === "'") quote = char;
|
|
168
|
+
else if (char === ",") {
|
|
169
|
+
families.push(current);
|
|
170
|
+
current = "";
|
|
171
|
+
} else current += char;
|
|
172
|
+
}
|
|
173
|
+
families.push(current);
|
|
174
|
+
return families.map((family) => family.trim()).filter(Boolean);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const sameFamilies = (a, b) => a.length === b.length && a.every((family, index) => family.toLowerCase() === b[index].toLowerCase());
|
|
178
|
+
|
|
179
|
+
/** A length against the tokens of one kind, rem in px of the page's `root` font size: exact token names, else the nearest by numeric distance. */
|
|
180
|
+
function matchLength(px, candidates, root) {
|
|
181
|
+
const sized = candidates.map((candidate) => ({ token: candidate.token, px: candidate.length.size * (candidate.length.rem ? root : 1) }));
|
|
182
|
+
const exact = sized.filter((candidate) => Math.abs(candidate.px - px) < SIZE_EPSILON).map((candidate) => candidate.token);
|
|
183
|
+
if (exact.length > 0) return { exact, nearest: null };
|
|
184
|
+
let nearest = null;
|
|
185
|
+
for (const candidate of sized) if (!nearest || Math.abs(candidate.px - px) < Math.abs(nearest.px - px)) nearest = candidate;
|
|
186
|
+
return { exact: [], nearest: nearest ? nearest.token : null };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The token nearest `color` by OKLab distance among those of about its opacity, or null. */
|
|
190
|
+
function nearestColor(color, candidates) {
|
|
191
|
+
let nearest = null;
|
|
192
|
+
let best = Infinity;
|
|
193
|
+
for (const entry of candidates) {
|
|
194
|
+
if (Math.abs(entry.color.a - (color.a ?? 1)) > NEAR_ALPHA) continue;
|
|
195
|
+
const distance = colorDistance(color, entry.color);
|
|
196
|
+
if (distance < best) {
|
|
197
|
+
best = distance;
|
|
198
|
+
nearest = entry.token;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return nearest;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function init(ctx) {
|
|
205
|
+
const { win, doc, els, store, api, ui, actions } = ctx;
|
|
206
|
+
const { state } = store;
|
|
207
|
+
const { getJson, isFiniteNumber } = api;
|
|
208
|
+
const T = ctx.i18n.text("tokens", TEXT);
|
|
209
|
+
|
|
210
|
+
// The tokens parsed by kind, once per load (never per hover), and the latest load: an older reply landing last changes nothing.
|
|
211
|
+
let kinds = tokenKinds([]);
|
|
212
|
+
let tokenLoads = 0;
|
|
213
|
+
// Why the last read found no tokens in an existing design/system.md ("too-large", "unreadable"), else "".
|
|
214
|
+
let problem = "";
|
|
215
|
+
// The element the panel shows ({ surface, measure, flags, text, copy }) or null; the generation a pending hide
|
|
216
|
+
// belongs to (a newer element or a hide cancels it); the element the panel may switch to ({ surface, measure })
|
|
217
|
+
// or null, and the generation of that pending switch; whether the pointer is on the panel.
|
|
218
|
+
let inspect = null;
|
|
219
|
+
let generation = 0;
|
|
220
|
+
let pending = null;
|
|
221
|
+
let switches = 0;
|
|
222
|
+
let pointerOn = false;
|
|
223
|
+
|
|
224
|
+
// ---- tokens and Technical details
|
|
225
|
+
|
|
226
|
+
/** The tokens of design/system.md; a read that fails or answers no token list keeps the ones shown (never the status line). */
|
|
227
|
+
async function loadTokens() {
|
|
228
|
+
const load = ++tokenLoads;
|
|
229
|
+
let data = null;
|
|
230
|
+
try { data = await getJson("api/system/tokens"); } catch { data = null; }
|
|
231
|
+
if (load !== tokenLoads || !data || typeof data !== "object" || !Array.isArray(data.tokens)) return;
|
|
232
|
+
const tokens = data.tokens.slice(0, LIMITS.tokens)
|
|
233
|
+
.filter((token) => token && typeof token.name === "string" && TOKEN_NAME.test(token.name) && typeof token.value === "string" && token.value.length > 0)
|
|
234
|
+
.map((token) => ({ name: token.name, value: token.value, section: typeof token.section === "string" ? token.section : "", group: typeof token.group === "string" ? token.group : "other" }));
|
|
235
|
+
store.setTokens(tokens);
|
|
236
|
+
kinds = tokenKinds(state.tokens);
|
|
237
|
+
problem = typeof data.problem === "string" ? data.problem : "";
|
|
238
|
+
// An open panel compares with the new tokens at once, where it is.
|
|
239
|
+
if (inspect) renderInspector(inspect.surface, inspect.measure);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function storedTechnical() {
|
|
243
|
+
try {
|
|
244
|
+
return win.localStorage.getItem(TECHNICAL_KEY) === "on";
|
|
245
|
+
} catch {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Technical details on or off; saved in this browser when it can be (otherwise it holds for this page). */
|
|
251
|
+
function setTechnical(on) {
|
|
252
|
+
store.setTechnical(on);
|
|
253
|
+
try { win.localStorage.setItem(TECHNICAL_KEY, on ? "on" : "off"); } catch { /* storage may be unavailable */ }
|
|
254
|
+
// Every frame, All sizes frames included, measures only while it is on (gd:mode `inspect`).
|
|
255
|
+
actions.allBoards().flatMap(actions.surfacesOf).forEach(actions.sendMode);
|
|
256
|
+
if (!on) hideInspector();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Technical details as saved, and the first tokens read; boot() runs it once every module is ready. */
|
|
260
|
+
function startTokens() {
|
|
261
|
+
store.setTechnical(storedTechnical());
|
|
262
|
+
loadTokens().catch(() => {});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// ---- the panel's rows
|
|
266
|
+
|
|
267
|
+
function chip(className, text) {
|
|
268
|
+
const span = doc.createElement("span");
|
|
269
|
+
span.className = className;
|
|
270
|
+
span.textContent = text;
|
|
271
|
+
return span;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const code = (text) => chip("gd-inspector-code", text);
|
|
275
|
+
const near = (text) => chip("gd-inspector-near", text);
|
|
276
|
+
const okChip = (text) => chip("gd-inspector-ok", T.ok(text));
|
|
277
|
+
const badChip = (text) => chip("gd-inspector-bad", T.bad(text));
|
|
278
|
+
const names = (tokens) => tokens.map((token) => token.name).join(" / ");
|
|
279
|
+
|
|
280
|
+
function swatch(color) {
|
|
281
|
+
const box = chip("gd-inspector-swatch", "");
|
|
282
|
+
box.setAttribute("aria-hidden", "true");
|
|
283
|
+
box.style.background = color.a === undefined || color.a >= 1 ? `rgb(${color.r}, ${color.g}, ${color.b})` : `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})`;
|
|
284
|
+
return box;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function rowElement(label, nodes) {
|
|
288
|
+
const item = doc.createElement("div");
|
|
289
|
+
item.className = "gd-inspector-row";
|
|
290
|
+
const term = doc.createElement("dt");
|
|
291
|
+
term.className = "gd-inspector-label";
|
|
292
|
+
term.textContent = label;
|
|
293
|
+
const value = doc.createElement("dd");
|
|
294
|
+
value.className = "gd-inspector-value";
|
|
295
|
+
value.append(...nodes);
|
|
296
|
+
item.append(term, value);
|
|
297
|
+
return item;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** A color row: swatch and hex, the matching token(s), or ⚠ no token with the nearest one. */
|
|
301
|
+
function colorValue(color, flags, label) {
|
|
302
|
+
const nodes = [swatch(color), code(colorHex(color))];
|
|
303
|
+
if (kinds.color.length === 0) return nodes;
|
|
304
|
+
const same = kinds.color.filter((entry) => entry.color.r === color.r && entry.color.g === color.g && entry.color.b === color.b && Math.abs(entry.color.a - (color.a ?? 1)) < ALPHA_EPSILON);
|
|
305
|
+
if (same.length > 0) return [...nodes, okChip(names(same.map((entry) => entry.token)))];
|
|
306
|
+
nodes.push(badChip(T.noToken));
|
|
307
|
+
const nearest = nearestColor(color, kinds.color);
|
|
308
|
+
if (nearest) nodes.push(near(T.nearest(nearest.name)), code(nearest.value));
|
|
309
|
+
flags.push(T.session.color(label, colorHex(color), nearest));
|
|
310
|
+
return nodes;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** A px value against the tokens of one kind (rem in px of the page's `root` font size); no tokens of that kind means nothing to compare. */
|
|
314
|
+
function lengthValue(px, candidates, root, flags, label) {
|
|
315
|
+
const nodes = [code(T.px(fmt(px)))];
|
|
316
|
+
if (candidates.length === 0) return nodes;
|
|
317
|
+
const match = matchLength(px, candidates, root);
|
|
318
|
+
if (match.exact.length > 0) return [...nodes, okChip(names(match.exact))];
|
|
319
|
+
nodes.push(badChip(T.noToken));
|
|
320
|
+
if (match.nearest) nodes.push(near(T.nearest(match.nearest.name)), code(match.nearest.value));
|
|
321
|
+
flags.push(T.session.length(label, fmt(px), match.nearest));
|
|
322
|
+
return nodes;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function contrastValue(m, flags) {
|
|
326
|
+
const text = m.color;
|
|
327
|
+
const behind = m.background;
|
|
328
|
+
if (!m.hasText || !text) return [code(T.none)];
|
|
329
|
+
if (!behind) return [code(T.unknownBackground)];
|
|
330
|
+
// Translucent text is composited over its background first.
|
|
331
|
+
const shown = text.a < 1 ? { r: Math.round(text.r * text.a + behind.r * (1 - text.a)), g: Math.round(text.g * text.a + behind.g * (1 - text.a)), b: Math.round(text.b * text.a + behind.b * (1 - text.a)) } : text;
|
|
332
|
+
const ratio = fmtRatio(contrastRatio(shown, behind));
|
|
333
|
+
const large = m.fontSize >= 24 || (m.fontSize >= 18.66 && m.fontWeight >= 700);
|
|
334
|
+
const needed = large ? 3 : 4.5;
|
|
335
|
+
if (Number(ratio) >= needed) return [okChip(T.ratio(ratio)), near(large ? T.aaLarge : T.aa)];
|
|
336
|
+
flags.push(T.session.contrast(ratio, needed, large));
|
|
337
|
+
return [badChip(T.ratio(ratio)), near(large ? T.needsLarge(needed) : T.needs(needed))];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function familyValue(m, flags) {
|
|
341
|
+
const mine = familyList(m.fontFamily);
|
|
342
|
+
const first = mine[0] || T.none;
|
|
343
|
+
const nodes = [code(first)];
|
|
344
|
+
nodes[0].title = m.fontFamily;
|
|
345
|
+
if (kinds.family.length === 0) return nodes;
|
|
346
|
+
const exact = kinds.family.filter((entry) => sameFamilies(entry.families, mine));
|
|
347
|
+
const byFirst = exact.length > 0 ? exact : kinds.family.filter((entry) => mine.length > 0 && entry.families[0]?.toLowerCase() === mine[0].toLowerCase());
|
|
348
|
+
if (byFirst.length > 0) return [...nodes, okChip(names(byFirst.map((entry) => entry.token)))];
|
|
349
|
+
flags.push(T.session.family(first, kinds.family.map((entry) => entry.token.name).join(", ")));
|
|
350
|
+
return [...nodes, badChip(T.noToken)];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function spacingValue(m, flags) {
|
|
354
|
+
const nodes = [];
|
|
355
|
+
if (m.margin.some((value) => value !== 0)) nodes.push(code(T.margin(sides(m.margin))));
|
|
356
|
+
if (m.padding.some((value) => value !== 0)) nodes.push(code(T.padding(sides(m.padding))));
|
|
357
|
+
if (nodes.length === 0) return [code(T.none)];
|
|
358
|
+
if (kinds.spacing.length === 0) return nodes;
|
|
359
|
+
// A negative margin pulls by a step of the scale: its size is what is checked.
|
|
360
|
+
const values = [...new Set([...m.margin, ...m.padding].filter((value) => value !== 0))];
|
|
361
|
+
const off = values.map((value) => ({ value, match: matchLength(Math.abs(value), kinds.spacing, m.rootFontSize) })).filter((entry) => entry.match.exact.length === 0);
|
|
362
|
+
if (off.length === 0) nodes.push(okChip(T.onScale));
|
|
363
|
+
for (const { value, match } of off) {
|
|
364
|
+
nodes.push(badChip(T.offScale(fmt(value))));
|
|
365
|
+
if (match.nearest) nodes.push(near(T.nearest(match.nearest.name)), code(match.nearest.value));
|
|
366
|
+
flags.push(T.session.spacing(fmt(value), match.nearest));
|
|
367
|
+
}
|
|
368
|
+
return nodes;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function radiusValue(m, flags) {
|
|
372
|
+
const corners = m.radius;
|
|
373
|
+
if (corners.every((value) => value === 0)) return [code(T.none)];
|
|
374
|
+
if (corners.every((value) => value === corners[0])) return lengthValue(corners[0], kinds.radius, m.rootFontSize, flags, T.session.radius);
|
|
375
|
+
const nodes = [code(T.px(sides(corners)))];
|
|
376
|
+
if (kinds.radius.length === 0) return nodes;
|
|
377
|
+
for (const value of new Set(corners.filter((corner) => corner > 0))) {
|
|
378
|
+
const match = matchLength(value, kinds.radius, m.rootFontSize);
|
|
379
|
+
if (match.exact.length > 0) continue;
|
|
380
|
+
nodes.push(badChip(T.radiusNoToken(fmt(value))));
|
|
381
|
+
flags.push(T.session.length(T.session.radius, fmt(value), match.nearest));
|
|
382
|
+
}
|
|
383
|
+
return nodes;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The panel's rows for one measured element, the flagged values, the comment that asks to fix them, and the
|
|
388
|
+
* rows as plain text (`label: value`, one per line), which Copy copies after the element's label and selector.
|
|
389
|
+
*/
|
|
390
|
+
function describe(m) {
|
|
391
|
+
const flags = [];
|
|
392
|
+
const { labels } = T;
|
|
393
|
+
const lines = [];
|
|
394
|
+
const row = (label, nodes) => {
|
|
395
|
+
lines.push(`${label}: ${nodes.map((node) => node.textContent).filter(Boolean).join(" ")}`);
|
|
396
|
+
return rowElement(label, nodes);
|
|
397
|
+
};
|
|
398
|
+
const rows = [
|
|
399
|
+
row(labels.color, m.color ? colorValue(m.color, flags, T.session.textColor) : [code(T.unreadable)]),
|
|
400
|
+
row(labels.background, m.background ? colorValue(m.background, flags, T.session.background) : [code(T.imageBackground)]),
|
|
401
|
+
row(labels.contrast, contrastValue(m, flags)),
|
|
402
|
+
row(labels.font, familyValue(m, flags)),
|
|
403
|
+
row(labels.size, [...lengthValue(m.fontSize, kinds.fontSize, m.rootFontSize, flags, T.session.fontSize), near(T.weight(m.fontWeight))]),
|
|
404
|
+
row(labels.lineHeight, [code(m.lineHeight === null ? T.normal : T.px(fmt(m.lineHeight)))]),
|
|
405
|
+
row(labels.spacing, spacingValue(m, flags)),
|
|
406
|
+
row(labels.radius, radiusValue(m, flags)),
|
|
407
|
+
];
|
|
408
|
+
const text = flags.length > 0 ? T.session.fix(m.selector, flags) : T.session.nothing(m.selector);
|
|
409
|
+
return { rows, flags, text: text.slice(0, LIMITS.comment), lines };
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// ---- what an artboard reports (gd:inspect)
|
|
413
|
+
|
|
414
|
+
function finiteRgb(value, withAlpha) {
|
|
415
|
+
if (value === null) return null;
|
|
416
|
+
if (!value || typeof value !== "object") return undefined;
|
|
417
|
+
if (!["r", "g", "b"].every((key) => isFiniteNumber(value[key]) && value[key] >= 0 && value[key] <= 255)) return undefined;
|
|
418
|
+
if (!withAlpha) return { r: value.r, g: value.g, b: value.b };
|
|
419
|
+
return isFiniteNumber(value.a) && value.a >= 0 && value.a <= 1 ? { r: value.r, g: value.g, b: value.b, a: value.a } : undefined;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function fourNumbers(value) {
|
|
423
|
+
return Array.isArray(value) && value.length === 4 && value.every(isFiniteNumber) ? value.slice() : null;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** A measurement checked field by field (the page is the design's own code, not trusted); null when malformed. */
|
|
427
|
+
function readMeasure(raw) {
|
|
428
|
+
if (!raw || typeof raw !== "object") return null;
|
|
429
|
+
const selector = typeof raw.selector === "string" ? raw.selector.trim() : "";
|
|
430
|
+
const rect = raw.rect && typeof raw.rect === "object" ? raw.rect : null;
|
|
431
|
+
const color = finiteRgb(raw.color, true);
|
|
432
|
+
const background = finiteRgb(raw.background, false);
|
|
433
|
+
const margin = fourNumbers(raw.margin);
|
|
434
|
+
const padding = fourNumbers(raw.padding);
|
|
435
|
+
const radius = fourNumbers(raw.radius);
|
|
436
|
+
if (!selector || selector.length > LIMITS.selector || !rect || !["x", "y", "width", "height"].every((key) => isFiniteNumber(rect[key]))) return null;
|
|
437
|
+
if (color === undefined || background === undefined || !margin || !padding || !radius) return null;
|
|
438
|
+
if (!isFiniteNumber(raw.fontSize) || !isFiniteNumber(raw.fontWeight) || typeof raw.fontFamily !== "string" || (raw.lineHeight !== null && !isFiniteNumber(raw.lineHeight))) return null;
|
|
439
|
+
return {
|
|
440
|
+
selector,
|
|
441
|
+
label: typeof raw.label === "string" && raw.label ? raw.label.slice(0, LIMITS.label) : selector.slice(0, LIMITS.label),
|
|
442
|
+
text: typeof raw.text === "string" ? raw.text.slice(0, LIMITS.excerpt) : "",
|
|
443
|
+
hasText: raw.hasText === true,
|
|
444
|
+
rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
445
|
+
color, background, fontFamily: raw.fontFamily.slice(0, LIMITS.family), fontSize: raw.fontSize, fontWeight: raw.fontWeight, lineHeight: raw.lineHeight,
|
|
446
|
+
margin, padding, radius,
|
|
447
|
+
// A frame that reports no usable root font size converts rem at the browser default.
|
|
448
|
+
rootFontSize: isFiniteNumber(raw.rootFontSize) && raw.rootFontSize > 0 ? raw.rootFontSize : ROOT_FONT_SIZE,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Whether a report from `surface` may show the panel: only with Technical details on, in Comment mode, with the
|
|
454
|
+
* comment box closed, outside Compare, for a design artboard of the design shown (an old design's frames may still
|
|
455
|
+
* report while the new one loads) and, in focus mode, for the focused artboard's frames only.
|
|
456
|
+
*/
|
|
457
|
+
function accepts(surface) {
|
|
458
|
+
const board = actions.ownerOf(surface);
|
|
459
|
+
if (!state.technical || !state.commenting || !els.popover.hidden || state.compare || board.system || board.slug !== state.slug) return false;
|
|
460
|
+
return !state.focus || board === state.focus;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* A gd:inspect from `surface` (a board's frame or an All sizes frame, canvas-messages.js). The first panel shows at
|
|
465
|
+
* once, and its own element again (scrolled) re-places it at once; another element waits for the pointer to rest on
|
|
466
|
+
* it (waitToSwitch), and with the pointer on the panel nothing changes. `element` null: the pointer left that frame's
|
|
467
|
+
* page, so a switch waiting on it is off and the panel goes soon.
|
|
468
|
+
*/
|
|
469
|
+
function inspectFrom(surface, element) {
|
|
470
|
+
if (!accepts(surface)) return;
|
|
471
|
+
if (element === null) {
|
|
472
|
+
const waiting = Boolean(pending && pending.surface === surface);
|
|
473
|
+
if (waiting) cancelSwitch();
|
|
474
|
+
if (inspect && (waiting || inspect.surface === surface)) scheduleHide();
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const measure = readMeasure(element);
|
|
478
|
+
if (!measure || pointerOn) return;
|
|
479
|
+
if (!inspect || (inspect.surface === surface && inspect.measure.selector === measure.selector)) showInspector(surface, measure);
|
|
480
|
+
else waitToSwitch(surface, measure);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Another element while the panel shows: the pointer is on an element, so no hide; the switch comes after the rest.
|
|
485
|
+
* The rest counts from when the pointer reached that element: its re-measures (late loads, page changes) only
|
|
486
|
+
* refresh the values the switch will show, so they cannot hold the panel on the old element.
|
|
487
|
+
*/
|
|
488
|
+
function waitToSwitch(surface, measure) {
|
|
489
|
+
generation += 1;
|
|
490
|
+
if (pending && pending.surface === surface && pending.measure.selector === measure.selector) {
|
|
491
|
+
pending.measure = measure;
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
pending = { surface, measure };
|
|
495
|
+
const current = ++switches;
|
|
496
|
+
win.setTimeout(() => {
|
|
497
|
+
if (current !== switches || !pending) return;
|
|
498
|
+
const next = pending;
|
|
499
|
+
pending = null;
|
|
500
|
+
if (!pointerOn && accepts(next.surface)) showInspector(next.surface, next.measure);
|
|
501
|
+
}, DWELL_MS);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function cancelSwitch() {
|
|
505
|
+
switches += 1;
|
|
506
|
+
pending = null;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// ---- the panel
|
|
510
|
+
|
|
511
|
+
/** Beside the frame (right, else left), level with the element; below or above it when the frame leaves no room. */
|
|
512
|
+
function placeInspector(surface, rect) {
|
|
513
|
+
const viewport = els.viewport.getBoundingClientRect();
|
|
514
|
+
const box = surface.frame.getBoundingClientRect();
|
|
515
|
+
const scale = box.width / surface.viewWidth || 1;
|
|
516
|
+
const right = box.left + box.width;
|
|
517
|
+
const top = box.top + rect.y * scale;
|
|
518
|
+
const bottom = box.top + (rect.y + rect.height) * scale;
|
|
519
|
+
const width = els.inspector.offsetWidth || INSPECTOR_WIDTH;
|
|
520
|
+
const height = els.inspector.offsetHeight || INSPECTOR_HEIGHT;
|
|
521
|
+
const minX = viewport.left + INSPECTOR_GAP;
|
|
522
|
+
const maxX = viewport.left + viewport.width - width - INSPECTOR_GAP;
|
|
523
|
+
const minY = viewport.top + INSPECTOR_GAP;
|
|
524
|
+
const maxY = Math.max(minY, viewport.top + viewport.height - height - INSPECTOR_GAP);
|
|
525
|
+
const clamp = (value, low, high) => Math.min(Math.max(value, low), high);
|
|
526
|
+
let x;
|
|
527
|
+
let y = clamp(top, minY, maxY);
|
|
528
|
+
if (right + INSPECTOR_GAP <= maxX) x = right + INSPECTOR_GAP;
|
|
529
|
+
else if (box.left - INSPECTOR_GAP - width >= minX) x = box.left - INSPECTOR_GAP - width;
|
|
530
|
+
else {
|
|
531
|
+
x = clamp(box.left + rect.x * scale, minX, Math.max(minX, maxX));
|
|
532
|
+
y = clamp(bottom + 8 + height <= viewport.top + viewport.height - INSPECTOR_GAP ? bottom + 8 : top - 8 - height, minY, maxY);
|
|
533
|
+
}
|
|
534
|
+
els.inspector.style.left = `${x - viewport.left}px`;
|
|
535
|
+
els.inspector.style.top = `${y - viewport.top}px`;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function showInspector(surface, measure) {
|
|
539
|
+
// A new element cancels a pending hide and a pending switch.
|
|
540
|
+
generation += 1;
|
|
541
|
+
cancelSwitch();
|
|
542
|
+
renderInspector(surface, measure);
|
|
543
|
+
els.inspector.hidden = false;
|
|
544
|
+
placeInspector(surface, measure.rect);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** The panel's title, rows, note and Ask the agent to fix for `measure`, compared with the current tokens. */
|
|
548
|
+
function renderInspector(surface, measure) {
|
|
549
|
+
const result = describe(measure);
|
|
550
|
+
// Copy copies what the panel shows: the element, its selector and every row.
|
|
551
|
+
const copy = [measure.label, measure.selector, ...result.lines].join("\n");
|
|
552
|
+
inspect = { surface, measure, flags: result.flags, text: result.text, copy };
|
|
553
|
+
els.inspectorTitle.textContent = measure.label;
|
|
554
|
+
els.inspectorSelector.textContent = measure.selector;
|
|
555
|
+
els.inspectorSelector.title = measure.selector;
|
|
556
|
+
els.inspectorList.replaceChildren(...result.rows);
|
|
557
|
+
els.inspectorNote.textContent = Object.hasOwn(T.problems, problem) ? T.problems[problem] : T.noTokens;
|
|
558
|
+
els.inspectorNote.hidden = state.tokens.length > 0;
|
|
559
|
+
const nothing = result.flags.length === 0;
|
|
560
|
+
els.inspectorFix.disabled = nothing;
|
|
561
|
+
els.inspectorFix.title = nothing ? T.nothingToFix : "";
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Hides the panel: the comment box opens or closes (closePopover runs this first, so every path that closes it
|
|
566
|
+
* — focus mode ending, another size, Comment mode off, a pan — hides the panel too), Technical details goes off,
|
|
567
|
+
* another design shows, its frame goes (hideGoneInspector), the focused artboard is re-centered (centerFocus) or Esc
|
|
568
|
+
* is pressed in it. A pending switch ends with it. Keyboard focus in it goes back to the canvas.
|
|
569
|
+
*/
|
|
570
|
+
function hideInspector() {
|
|
571
|
+
generation += 1;
|
|
572
|
+
cancelSwitch();
|
|
573
|
+
pointerOn = false;
|
|
574
|
+
if (!inspect && els.inspector.hidden) return;
|
|
575
|
+
inspect = null;
|
|
576
|
+
const focused = els.inspector.contains(doc.activeElement);
|
|
577
|
+
els.inspector.hidden = true;
|
|
578
|
+
if (focused) (state.focus ? state.focus.frame : els.viewport).focus();
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** Hides the panel when the frame it is beside is gone (a design.json reload, All sizes frames removed); a switch to a gone frame is off. */
|
|
582
|
+
function hideGoneInspector() {
|
|
583
|
+
if (!inspect && !pending) return;
|
|
584
|
+
const surfaces = actions.allBoards().flatMap(actions.surfacesOf);
|
|
585
|
+
if (pending && !surfaces.includes(pending.surface)) cancelSwitch();
|
|
586
|
+
if (inspect && !surfaces.includes(inspect.surface)) hideInspector();
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** The element was left: the panel goes soon, unless the pointer or the keyboard is in it by then. */
|
|
590
|
+
function scheduleHide() {
|
|
591
|
+
const pending = ++generation;
|
|
592
|
+
win.setTimeout(() => {
|
|
593
|
+
if (pending !== generation || pointerOn || els.inspector.contains(doc.activeElement)) return;
|
|
594
|
+
hideInspector();
|
|
595
|
+
}, HIDE_MS);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// With the pointer on the panel nothing changes: a switch it passed on its way is off.
|
|
599
|
+
els.inspector.addEventListener("pointerenter", () => {
|
|
600
|
+
pointerOn = true;
|
|
601
|
+
cancelSwitch();
|
|
602
|
+
});
|
|
603
|
+
els.inspector.addEventListener("pointerleave", () => {
|
|
604
|
+
pointerOn = false;
|
|
605
|
+
if (inspect) scheduleHide();
|
|
606
|
+
});
|
|
607
|
+
// Keyboard focus leaving the panel (not to another of its buttons) lets it go like the pointer does (WCAG 1.4.13).
|
|
608
|
+
els.inspector.addEventListener("focusout", (event) => {
|
|
609
|
+
if (!inspect || pointerOn || els.inspector.contains(event.relatedTarget)) return;
|
|
610
|
+
scheduleHide();
|
|
611
|
+
});
|
|
612
|
+
// Esc closes only the panel (Comment mode stays on), focus back on the canvas.
|
|
613
|
+
els.inspector.addEventListener("keydown", (event) => {
|
|
614
|
+
if (event.key !== "Escape" || event.shiftKey) return;
|
|
615
|
+
event.preventDefault();
|
|
616
|
+
hideInspector();
|
|
617
|
+
});
|
|
618
|
+
// The panel is not part of the canvas: the wheel over it never pans or zooms.
|
|
619
|
+
els.inspector.addEventListener("wheel", (event) => event.stopPropagation());
|
|
620
|
+
|
|
621
|
+
els.inspectorFix.addEventListener("click", () => {
|
|
622
|
+
const current = inspect;
|
|
623
|
+
if (!current || current.flags.length === 0) return;
|
|
624
|
+
const { surface, measure, text } = current;
|
|
625
|
+
actions.openPopover(surface, { selector: measure.selector, excerpt: measure.text, rect: measure.rect });
|
|
626
|
+
els.text.value = text;
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
/** The Clipboard API, else the browser's copy command through a hidden text area. */
|
|
630
|
+
async function copyText(text) {
|
|
631
|
+
const clipboard = win.navigator && win.navigator.clipboard;
|
|
632
|
+
try {
|
|
633
|
+
if (clipboard && typeof clipboard.writeText === "function") {
|
|
634
|
+
await clipboard.writeText(text);
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
} catch { /* denied or unavailable: use the fallback */ }
|
|
638
|
+
const previous = doc.activeElement;
|
|
639
|
+
const area = doc.createElement("textarea");
|
|
640
|
+
area.value = text;
|
|
641
|
+
area.setAttribute("readonly", "");
|
|
642
|
+
area.className = "gd-visually-hidden";
|
|
643
|
+
doc.body.append(area);
|
|
644
|
+
try {
|
|
645
|
+
area.focus();
|
|
646
|
+
area.select?.();
|
|
647
|
+
return typeof doc.execCommand === "function" && doc.execCommand("copy") === true;
|
|
648
|
+
} catch {
|
|
649
|
+
return false;
|
|
650
|
+
} finally {
|
|
651
|
+
area.remove();
|
|
652
|
+
previous?.focus?.();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
els.inspectorCopy.addEventListener("click", async () => {
|
|
657
|
+
const current = inspect;
|
|
658
|
+
if (!current) return;
|
|
659
|
+
const ok = await copyText(current.copy);
|
|
660
|
+
ui.showToast(ok ? T.copied : T.copyFailed, !ok);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
/** A new language: an open panel's rows, note and tooltip, where it is. */
|
|
664
|
+
function relabel() {
|
|
665
|
+
if (inspect) renderInspector(inspect.surface, inspect.measure);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** The panel beside its element again, after the artboard moved (a language switch re-centers it). */
|
|
669
|
+
function placeInspectorAgain() {
|
|
670
|
+
if (inspect && !els.inspector.hidden) placeInspector(inspect.surface, inspect.measure.rect);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return { relabel, placeInspector: placeInspectorAgain, loadTokens, setTechnical, startTokens, inspectFrom, hideInspector, hideGoneInspector };
|
|
674
|
+
}
|