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,393 @@
|
|
|
1
|
+
// Export: a ⋯ button in each design artboard's header opens the shared menu
|
|
2
|
+
// (canvas-menu.js) with the export items only: Export as PNG and at 2× (the
|
|
3
|
+
// browser's own tab capture, cropped to the artboard), Export as PDF (the print
|
|
4
|
+
// dialog) and Download HTML (the artboard file as written). PNG contacts no
|
|
5
|
+
// server; PDF and HTML only read the artboard file from the canvas server (a GET).
|
|
6
|
+
// Nothing is uploaded and nothing is written under design/. The system board gets no menu.
|
|
7
|
+
// canvas-boards.js asks for the button when it builds a board (boardMenuButton).
|
|
8
|
+
// Results and failures show on the status line and the toast (canvas-ui.js).
|
|
9
|
+
|
|
10
|
+
// Every string the export shows, in English; canvas-i18n-es.js has the Spanish. Artboard titles and file names stay as written.
|
|
11
|
+
const TEXT = Object.freeze({
|
|
12
|
+
button: (title) => `More actions for ${title}`,
|
|
13
|
+
menu: (title) => `${title} actions`,
|
|
14
|
+
png: "Export as PNG",
|
|
15
|
+
png2x: "Export as PNG at 2×",
|
|
16
|
+
pdf: "Export as PDF",
|
|
17
|
+
html: "Download HTML",
|
|
18
|
+
frameTitle: (title) => `${title} artboard`,
|
|
19
|
+
choose: "Choose this canvas tab in the browser's capture selector. Choosing another tab or screen may export the wrong content.",
|
|
20
|
+
failed: (reason) => `Could not export the artboard. ${reason} Use your browser's screenshot tool instead.`,
|
|
21
|
+
unavailable: "Tab capture is not available in this browser.",
|
|
22
|
+
sharedScreen: "You shared a screen, not this tab, so the artboard cannot be cropped from it.",
|
|
23
|
+
sharedOther: (surface) => `You shared a ${surface}, not this tab, so the artboard cannot be cropped from it.`,
|
|
24
|
+
window: (width, height) => `The artboard needs a browser window of at least ${width} × ${height} px. Make the window bigger or use full screen (F11), then try again.`,
|
|
25
|
+
noFrame: "The captured frame has no dimensions.",
|
|
26
|
+
noPng: "PNG export is not available.",
|
|
27
|
+
encode: "Could not encode the PNG.",
|
|
28
|
+
denied: "Capture was denied or failed.",
|
|
29
|
+
stopped: "Sharing stopped before the artboard was captured.",
|
|
30
|
+
gone: "The artboard is no longer in the design.",
|
|
31
|
+
changed: "The artboard was reloaded or closed during the capture.",
|
|
32
|
+
done: "Exported PNG.",
|
|
33
|
+
doneUpscaled: "Exported PNG at 2× (upscaled).",
|
|
34
|
+
downloadFailed: (reason) => `Could not download the artboard (${reason}). Open it from design/ in your project instead.`,
|
|
35
|
+
printFailed: (reason) => `Could not print the artboard (${reason}). Open it from design/ in your project instead.`,
|
|
36
|
+
error: "error",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Every PNG export starts the artboard at Desktop, its own size.
|
|
40
|
+
const DESKTOP = Object.freeze({ kind: "desktop" });
|
|
41
|
+
|
|
42
|
+
// The characters the server escapes in the inspector tag's base, and how (escapeHtml in lib/design-canvas-server.ts).
|
|
43
|
+
const HTML_ESCAPES = Object.freeze({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" });
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The inspector tag the server injects into every artboard served under `base` (inspectorTag and injectInspector in
|
|
47
|
+
* lib/design-canvas-server.ts): Download HTML removes it. tests/design-canvas-export.test.ts serves the
|
|
48
|
+
* artboard through the server's own injection, so the two cannot drift apart silently.
|
|
49
|
+
*/
|
|
50
|
+
function inspectorTag(base) {
|
|
51
|
+
return `<script src="${base.replace(/[&<>"']/g, (char) => HTML_ESCAPES[char])}assets/inspector.js"></script>`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// How long a PNG export waits for the capture to paint a new frame; sharing that stopped paints none.
|
|
55
|
+
const FRAME_WAIT_MS = 500;
|
|
56
|
+
|
|
57
|
+
export function init(ctx) {
|
|
58
|
+
const { win, doc, els, store, api, ui, actions } = ctx;
|
|
59
|
+
const { state } = store;
|
|
60
|
+
const T = ctx.i18n.text("export", TEXT);
|
|
61
|
+
// Each board's ⋯ button, so an export can give the keyboard focus back to the current board's.
|
|
62
|
+
const buttons = new WeakMap();
|
|
63
|
+
// True while a PNG export runs: a second one would share its body class, its view restore and its capture.
|
|
64
|
+
let exporting = false;
|
|
65
|
+
|
|
66
|
+
/** The ⋯ button of a design artboard's header, wired to its menu. */
|
|
67
|
+
function boardMenuButton(board) {
|
|
68
|
+
const button = doc.createElement("button");
|
|
69
|
+
buttons.set(board, button);
|
|
70
|
+
button.type = "button";
|
|
71
|
+
button.className = "gd-menu-button";
|
|
72
|
+
labelButton(board, button);
|
|
73
|
+
button.setAttribute("aria-haspopup", "menu");
|
|
74
|
+
button.setAttribute("aria-expanded", "false");
|
|
75
|
+
button.setAttribute("aria-controls", els.menu.id);
|
|
76
|
+
button.append(actions.icon("i-more", "gd-i gd-i-s"));
|
|
77
|
+
actions.wireMenu(button, (last) => actions.showMenu(button, menuActions(board), T.menu(board.artboard.title), last));
|
|
78
|
+
return button;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The ⋯ button's name, in the current language. */
|
|
82
|
+
function labelButton(board, button) {
|
|
83
|
+
button.setAttribute("aria-label", T.button(board.artboard.title));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A new language: each ⋯ button's name, in place; the menu is built when it opens, so it opens in the language shown. */
|
|
87
|
+
function relabel() {
|
|
88
|
+
for (const board of state.boards) {
|
|
89
|
+
const button = buttons.get(board);
|
|
90
|
+
if (button) labelButton(board, button);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** What the menu offers for one artboard, in order: the exports only. */
|
|
95
|
+
function menuActions(board) {
|
|
96
|
+
return [
|
|
97
|
+
{ label: T.png, icon: "i-image", run: () => exportArtboard(board, 1) },
|
|
98
|
+
{ label: T.png2x, icon: "i-image", run: () => exportArtboard(board, 2) },
|
|
99
|
+
{ label: T.pdf, icon: "i-file", run: () => exportPdf(board) },
|
|
100
|
+
{ label: T.html, icon: "i-download", run: () => downloadHtml(board) },
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Closes the open menu when it is an artboard's: its button moved (a pan or zoom) or is gone (a reload). */
|
|
105
|
+
function closeBoardMenu() {
|
|
106
|
+
if (state.menu && state.menu.button.classList.contains("gd-menu-button")) actions.closeMenu(false);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** One sentence, ending with its period. */
|
|
110
|
+
const sentence = (text) => (/[.!?]$/.test(text) ? text : `${text}.`);
|
|
111
|
+
|
|
112
|
+
function reportFailure(text) {
|
|
113
|
+
ui.setStatus(text, true);
|
|
114
|
+
ui.showToast(text, true);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function nextPaint() {
|
|
118
|
+
return new Promise((resolve) => win.requestAnimationFrame(() => win.requestAnimationFrame(resolve)));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The next frame the capture paints, or FRAME_WAIT_MS at most: a capture whose sharing stopped paints none. */
|
|
122
|
+
function nextVideoFrame(video) {
|
|
123
|
+
const frame = new Promise((resolve) => (video.requestVideoFrameCallback ? video.requestVideoFrameCallback(() => resolve()) : win.setTimeout(resolve, 100)));
|
|
124
|
+
return Promise.race([frame, new Promise((resolve) => win.setTimeout(resolve, FRAME_WAIT_MS))]);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Rejects with T.stopped once the shared video ends (the browser's Stop sharing, a closed tab):
|
|
129
|
+
* nothing paints after that, so no wait of the export may outlive it.
|
|
130
|
+
*/
|
|
131
|
+
function sharingEnded(stream) {
|
|
132
|
+
const ended = new Promise((_resolve, reject) => {
|
|
133
|
+
for (const track of stream.getVideoTracks()) track.addEventListener("ended", () => reject(new Error(T.stopped)), { once: true });
|
|
134
|
+
});
|
|
135
|
+
// Ending after the export finished concerns nobody.
|
|
136
|
+
ended.catch(() => {});
|
|
137
|
+
return ended;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The board that stands for `board` now: a design.json reload builds new board objects, so the same
|
|
142
|
+
* artboard file (or the system board) is looked up again; null when it is gone.
|
|
143
|
+
*/
|
|
144
|
+
function currentBoard(board) {
|
|
145
|
+
if (!board) return null;
|
|
146
|
+
if (board.system) return state.systemBoard;
|
|
147
|
+
return state.boards.find((candidate) => candidate.slug === board.slug && candidate.artboard.file === board.artboard.file) ?? null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Downloads `url` as `name` through a temporary link, then releases the URL. */
|
|
151
|
+
function download(url, name) {
|
|
152
|
+
try {
|
|
153
|
+
const link = doc.createElement("a");
|
|
154
|
+
link.href = url;
|
|
155
|
+
link.download = name;
|
|
156
|
+
link.click();
|
|
157
|
+
} finally { win.URL.revokeObjectURL(url); }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The artboard file's name without its folder (and, with `bare`, without its extension). */
|
|
161
|
+
function fileName(board, bare = false) {
|
|
162
|
+
const name = board.artboard.file.split("/").pop();
|
|
163
|
+
return bare ? name.replace(/\.[^.]+$/, "") : name;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Exports the artboard as a PNG from the browser's tab capture, without sending pixels to the server.
|
|
168
|
+
* For one frame the canvas hides its chrome and puts the artboard at its own size at 100% in the window's
|
|
169
|
+
* top left; then it restores the focus, the screen size and the view it had, and puts the keyboard focus
|
|
170
|
+
* back on the artboard's ⋯ button. A design.json reload while the browser asks for the capture replaces
|
|
171
|
+
* the board objects: both the export and the restore follow the current ones; a reload (the design's or the
|
|
172
|
+
* artboard frame's own) or a close while the frame is being grabbed fails the export instead, and an artboard
|
|
173
|
+
* left meanwhile (Back, Shift+Esc) is not reopened, even across a reload. A second request while one runs is
|
|
174
|
+
* ignored, a viewport resized meanwhile gets the view a resize gives (refit or recentered), not the old one, and
|
|
175
|
+
* another design shown meanwhile keeps its own view.
|
|
176
|
+
*/
|
|
177
|
+
async function exportArtboard(chosen, scale) {
|
|
178
|
+
if (!win.navigator?.mediaDevices?.getDisplayMedia) {
|
|
179
|
+
reportFailure(T.failed(T.unavailable));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Synchronous, so the capture below still starts from the menu activation.
|
|
183
|
+
if (exporting) return;
|
|
184
|
+
exporting = true;
|
|
185
|
+
// Not a confirm dialog: the browser lets the capture start only for a few seconds after the click.
|
|
186
|
+
ui.setStatus(T.choose, false);
|
|
187
|
+
let stream = null;
|
|
188
|
+
// The board whose inspector highlight was cleared for the capture.
|
|
189
|
+
let cleared = null;
|
|
190
|
+
const previous = { slug: state.slug, focus: state.focus, size: state.size, view: { zoom: state.zoom, x: state.x, y: state.y, fitted: state.fitted } };
|
|
191
|
+
const viewport = els.viewport.getBoundingClientRect();
|
|
192
|
+
const viewportSize = { width: viewport.width, height: viewport.height };
|
|
193
|
+
try {
|
|
194
|
+
// This call must happen directly from the menu activation, before any asynchronous work.
|
|
195
|
+
stream = await win.navigator.mediaDevices.getDisplayMedia({ video: { displaySurface: "browser" }, audio: false, preferCurrentTab: true });
|
|
196
|
+
const ended = sharingEnded(stream);
|
|
197
|
+
// Every wait below ends early, and the export fails, once sharing stops.
|
|
198
|
+
const live = (promise) => Promise.race([ended, promise]);
|
|
199
|
+
// Some systems (such as Linux on Wayland) only offer windows or screens; their frame is not this tab's viewport.
|
|
200
|
+
const surface = stream.getVideoTracks?.()[0]?.getSettings?.().displaySurface;
|
|
201
|
+
if (surface && surface !== "browser") throw new Error(surface === "monitor" ? T.sharedScreen : T.sharedOther(surface));
|
|
202
|
+
// A stream that is already inactive will send no ended event.
|
|
203
|
+
if (stream.getVideoTracks().some((track) => track.readyState === "ended")) throw new Error(T.stopped);
|
|
204
|
+
const board = currentBoard(chosen);
|
|
205
|
+
if (!board) throw new Error(T.gone);
|
|
206
|
+
if (state.focus !== board) actions.enterFocus(board);
|
|
207
|
+
if (state.size.kind !== DESKTOP.kind) {
|
|
208
|
+
store.setFocus({ size: DESKTOP });
|
|
209
|
+
actions.centerFocus();
|
|
210
|
+
}
|
|
211
|
+
// The viewport covers the window without the canvas chrome. Its size changes, so focus mode may center
|
|
212
|
+
// the artboard again once (the viewport's resize observer): wait for that before placing it.
|
|
213
|
+
doc.body.classList.add("gd-exporting");
|
|
214
|
+
// The inspector draws a selected comment's outline and, in comment mode, the hovered element's outline
|
|
215
|
+
// inside the artboard, out of the chrome's reach: comment mode is off there until the export ends.
|
|
216
|
+
board.frame.contentWindow?.postMessage({ type: "gd:clear" }, "*");
|
|
217
|
+
board.frame.contentWindow?.postMessage({ type: "gd:mode", enabled: false }, "*");
|
|
218
|
+
cleared = board;
|
|
219
|
+
// An artboard file change reloads this frame in place (same board object, new src): see the check below.
|
|
220
|
+
const source = board.frame.src;
|
|
221
|
+
await live(nextPaint());
|
|
222
|
+
// Desktop fills the window (canvas-layout S8); the image is the artboard at its own size, at the top left.
|
|
223
|
+
actions.setFrameSize(board, board.artboard.width, board.artboard.height);
|
|
224
|
+
store.setView({ zoom: 1, x: 0, y: 0 });
|
|
225
|
+
actions.applyView();
|
|
226
|
+
await live(nextPaint());
|
|
227
|
+
const start = board.frame.getBoundingClientRect();
|
|
228
|
+
store.setView({ x: state.x - start.left, y: state.y - start.top });
|
|
229
|
+
actions.applyView();
|
|
230
|
+
await live(nextPaint());
|
|
231
|
+
const rect = board.frame.getBoundingClientRect();
|
|
232
|
+
if (rect.width <= 0 || rect.height <= 0 || rect.left < 0 || rect.top < 0 || rect.left + rect.width > win.innerWidth || rect.top + rect.height > win.innerHeight) {
|
|
233
|
+
throw new Error(T.window(Math.ceil(rect.width), Math.ceil(rect.height)));
|
|
234
|
+
}
|
|
235
|
+
const video = doc.createElement("video");
|
|
236
|
+
video.srcObject = stream;
|
|
237
|
+
video.muted = true;
|
|
238
|
+
await live(video.play());
|
|
239
|
+
// The first frame can predate the layout above; wait for frames painted after it.
|
|
240
|
+
await live(nextVideoFrame(video));
|
|
241
|
+
await live(nextVideoFrame(video));
|
|
242
|
+
// A reload (of the design or of the artboard's own frame) or a close during the waits moved or repainted
|
|
243
|
+
// the artboard away from the rectangle measured above.
|
|
244
|
+
if (currentBoard(board) !== board || state.focus !== board || board.frame.src !== source) throw new Error(T.changed);
|
|
245
|
+
const sx = video.videoWidth / win.innerWidth;
|
|
246
|
+
const sy = video.videoHeight / win.innerHeight;
|
|
247
|
+
if (!Number.isFinite(sx) || !Number.isFinite(sy) || sx <= 0 || sy <= 0) throw new Error(T.noFrame);
|
|
248
|
+
const canvas = doc.createElement("canvas");
|
|
249
|
+
canvas.width = Math.round(rect.width * scale);
|
|
250
|
+
canvas.height = Math.round(rect.height * scale);
|
|
251
|
+
const context = canvas.getContext("2d");
|
|
252
|
+
if (!context) throw new Error(T.noPng);
|
|
253
|
+
context.drawImage(video, rect.left * sx, rect.top * sy, rect.width * sx, rect.height * sy, 0, 0, canvas.width, canvas.height);
|
|
254
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
255
|
+
stream = null;
|
|
256
|
+
const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"));
|
|
257
|
+
if (!blob) throw new Error(T.encode);
|
|
258
|
+
download(win.URL.createObjectURL(blob), `${fileName(board, true)}${scale === 2 ? "@2x" : ""}.png`);
|
|
259
|
+
const done = scale === 2 && (sx < 2 || sy < 2) ? T.doneUpscaled : T.done;
|
|
260
|
+
ui.setStatus(done, false);
|
|
261
|
+
ui.showToast(done, false);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
reportFailure(T.failed(sentence(error?.message || T.denied)));
|
|
264
|
+
} finally {
|
|
265
|
+
exporting = false;
|
|
266
|
+
stream?.getTracks().forEach((track) => track.stop());
|
|
267
|
+
doc.body.classList.remove("gd-exporting");
|
|
268
|
+
// Left with Back or Shift+Esc during the capture: the artboard stays closed, with the view leaving gave.
|
|
269
|
+
// A design.json reload keeps focus on the same file (with a new board object), so no focus while the
|
|
270
|
+
// artboard is still in the design means it was left, whether a reload came before or after.
|
|
271
|
+
const left = Boolean(cleared) && !state.focus && currentBoard(cleared) !== null;
|
|
272
|
+
// The artboard that was open, as it is now; when a reload removed it, the canvas leaves focus mode.
|
|
273
|
+
const reopen = left ? null : currentBoard(previous.focus);
|
|
274
|
+
if (!reopen && state.focus) actions.exitFocus();
|
|
275
|
+
else if (reopen && state.focus !== reopen) actions.enterFocus(reopen);
|
|
276
|
+
if (reopen && state.focus === reopen) {
|
|
277
|
+
store.setFocus({ size: previous.size });
|
|
278
|
+
actions.centerFocus();
|
|
279
|
+
}
|
|
280
|
+
// A focus view without its artboard would leave the overview pointing at nothing, and another design
|
|
281
|
+
// shown meanwhile keeps the view it got (its fit), not this design's.
|
|
282
|
+
if (!left && (reopen || !previous.focus) && state.slug === previous.slug) {
|
|
283
|
+
store.setView(previous.view);
|
|
284
|
+
actions.applyView();
|
|
285
|
+
}
|
|
286
|
+
// The window changed size meanwhile (while the browser asked for the capture, say): the view from before
|
|
287
|
+
// would stay stale until the next resize, so do what a resize does (refit the overview, recenter focus).
|
|
288
|
+
const now = els.viewport.getBoundingClientRect();
|
|
289
|
+
if (now.width !== viewportSize.width || now.height !== viewportSize.height) actions.viewportResized();
|
|
290
|
+
// Comment mode comes back in the artboard, then the selected comment's outline when it is on this
|
|
291
|
+
// artboard, as canvas-comments.js shows it. A reload sent its own mode to the board that replaced it.
|
|
292
|
+
const active = state.comments.find((comment) => comment.id === state.activeId);
|
|
293
|
+
if (cleared && currentBoard(cleared) === cleared) {
|
|
294
|
+
actions.sendMode(cleared);
|
|
295
|
+
if (active?.file === cleared.artboard.file) cleared.frame.contentWindow?.postMessage({ type: "gd:highlight", id: active.id }, "*");
|
|
296
|
+
}
|
|
297
|
+
const board = currentBoard(chosen);
|
|
298
|
+
if (board) buttons.get(board)?.focus();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Ends the PDF export in progress (its container, page rule and listener), or null.
|
|
303
|
+
let endPrint = null;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Prints the artboard alone, at its own size, from this page (artboards are sandboxed without modals, so
|
|
307
|
+
* they cannot print themselves): the browser's print dialog saves it as PDF. The frame and the check below
|
|
308
|
+
* read the artboard file from the canvas server; nothing is uploaded.
|
|
309
|
+
* The file is read first: a frame also loads the server's error page, which must not be printed.
|
|
310
|
+
*/
|
|
311
|
+
async function exportPdf(board) {
|
|
312
|
+
endPrint?.();
|
|
313
|
+
const { width, height, title, file } = board.artboard;
|
|
314
|
+
const holder = doc.createElement("div");
|
|
315
|
+
holder.className = "gd-print";
|
|
316
|
+
const frame = doc.createElement("iframe");
|
|
317
|
+
frame.setAttribute("sandbox", "allow-scripts");
|
|
318
|
+
frame.setAttribute("referrerpolicy", "no-referrer");
|
|
319
|
+
frame.title = T.frameTitle(title);
|
|
320
|
+
frame.style.width = `${width}px`;
|
|
321
|
+
frame.style.height = `${height}px`;
|
|
322
|
+
holder.append(frame);
|
|
323
|
+
doc.body.append(holder);
|
|
324
|
+
doc.body.classList.add("gd-printing");
|
|
325
|
+
const page = setPrintPage(width, height);
|
|
326
|
+
const done = () => {
|
|
327
|
+
if (endPrint !== done) return;
|
|
328
|
+
endPrint = null;
|
|
329
|
+
win.removeEventListener("afterprint", done);
|
|
330
|
+
page?.();
|
|
331
|
+
holder.remove();
|
|
332
|
+
doc.body.classList.remove("gd-printing");
|
|
333
|
+
};
|
|
334
|
+
endPrint = done;
|
|
335
|
+
win.addEventListener("afterprint", done, { once: true });
|
|
336
|
+
const url = api.fileUrl(board.slug, file);
|
|
337
|
+
try {
|
|
338
|
+
const response = await win.fetch(url, { cache: "no-store" });
|
|
339
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
340
|
+
} catch (error) {
|
|
341
|
+
// A newer export replaced this one meanwhile: its failure concerns nobody.
|
|
342
|
+
if (endPrint !== done) return;
|
|
343
|
+
done();
|
|
344
|
+
reportFailure(T.printFailed(error?.message || T.error));
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (endPrint !== done) return;
|
|
348
|
+
// Attached only now: some browsers (Firefox before 148) fire the empty frame's about:blank load after its
|
|
349
|
+
// insertion, which would print a blank page. Setting src right after cancels that pending load.
|
|
350
|
+
frame.addEventListener("load", () => {
|
|
351
|
+
try {
|
|
352
|
+
win.print();
|
|
353
|
+
} catch (error) {
|
|
354
|
+
// No dialog opened, so no afterprint will come.
|
|
355
|
+
done();
|
|
356
|
+
reportFailure(T.printFailed(error?.message || T.error));
|
|
357
|
+
}
|
|
358
|
+
}, { once: true });
|
|
359
|
+
frame.setAttribute("src", url);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** One page the artboard's size (canvas.css sets no margin); returns how to remove it, or null where the browser gives no CSSOM. */
|
|
363
|
+
function setPrintPage(width, height) {
|
|
364
|
+
const sheet = [...(doc.styleSheets ?? [])].find((candidate) => /canvas\.css(\?|$)/.test(candidate.href ?? ""));
|
|
365
|
+
if (!sheet?.insertRule) return null;
|
|
366
|
+
try {
|
|
367
|
+
const index = sheet.insertRule(`@page { size: ${width}px ${height}px; }`, sheet.cssRules.length);
|
|
368
|
+
return () => { if (sheet.cssRules[index]) sheet.deleteRule(index); };
|
|
369
|
+
} catch {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Saves the artboard file as written, read from the canvas server (nothing is uploaded): the server injects the
|
|
376
|
+
* inspector into every artboard, so remove that tag again.
|
|
377
|
+
*/
|
|
378
|
+
async function downloadHtml(board) {
|
|
379
|
+
try {
|
|
380
|
+
const response = await win.fetch(api.fileUrl(board.slug, board.artboard.file), { cache: "no-store" });
|
|
381
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
382
|
+
const served = await response.text();
|
|
383
|
+
const tag = inspectorTag(api.base);
|
|
384
|
+
const at = served.lastIndexOf(tag);
|
|
385
|
+
const html = at === -1 ? served : served.slice(0, at) + served.slice(at + tag.length);
|
|
386
|
+
download(win.URL.createObjectURL(new win.Blob([html], { type: "text/html" })), fileName(board));
|
|
387
|
+
} catch (error) {
|
|
388
|
+
reportFailure(T.downloadFailed(error?.message || T.error));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return { boardMenuButton, closeBoardMenu, relabel };
|
|
393
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Navigation and focus modes: the shield hover, activating a board, focus mode at
|
|
2
|
+
// 100% with centerFocus, and the Back to canvas button. The focused artboard's frame
|
|
3
|
+
// has the screen size canvas-sizes.js gives it (focusSize), and All sizes lays its size frames
|
|
4
|
+
// out below the artboard's label (layoutSizes).
|
|
5
|
+
|
|
6
|
+
// canvas-layout S5: an open artboard keeps 8 px from the viewport's edges, and 48 px below it for the
|
|
7
|
+
// floating "Back to canvas" button (32 px high, 8 px from the bottom).
|
|
8
|
+
const FOCUS_MARGIN = 8;
|
|
9
|
+
const BACK_SPACE = 48;
|
|
10
|
+
// Every focus session starts at Desktop.
|
|
11
|
+
const DESKTOP = Object.freeze({ kind: "desktop" });
|
|
12
|
+
|
|
13
|
+
// The mode chip in the top bar, in English; canvas-i18n-es.js has the Spanish.
|
|
14
|
+
const TEXT = Object.freeze({
|
|
15
|
+
navigating: "Navigating",
|
|
16
|
+
using: (title) => `Using: ${title} · Shift+Esc to exit`,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function init(ctx) {
|
|
20
|
+
const { els, store, actions } = ctx;
|
|
21
|
+
const { state } = store;
|
|
22
|
+
const T = ctx.i18n.text("focus", TEXT);
|
|
23
|
+
|
|
24
|
+
function allBoards() {
|
|
25
|
+
return state.systemBoard ? [state.systemBoard, ...state.boards] : state.boards;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function boardOfShield(shield) {
|
|
29
|
+
return allBoards().find((board) => board.shield === shield) ?? null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A viewport point in the artboard's own CSS pixels. */
|
|
33
|
+
function framePoint(board, clientX, clientY) {
|
|
34
|
+
const rect = board.frame.getBoundingClientRect();
|
|
35
|
+
const scale = rect.width / board.viewWidth || 1;
|
|
36
|
+
return { x: (clientX - rect.left) / scale, y: (clientY - rect.top) / scale };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function activateBoard(board, clientX, clientY) {
|
|
40
|
+
// A board a reload replaced since the press is no longer on the canvas.
|
|
41
|
+
if (!allBoards().includes(board)) return;
|
|
42
|
+
if (!state.commenting) enterFocus(board);
|
|
43
|
+
else if (!board.system) board.frame.contentWindow?.postMessage({ type: "gd:pick-at", ...framePoint(board, clientX, clientY) }, "*");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function setHoverBoard(board) {
|
|
47
|
+
if (state.hoverBoard && state.hoverBoard !== board) state.hoverBoard.frame.contentWindow?.postMessage({ type: "gd:hover-at", x: null, y: null }, "*");
|
|
48
|
+
store.setHover(board);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Comment mode in navigation: the shield routes the hover to the inspector so it can outline the element. */
|
|
52
|
+
function hoverAt(event) {
|
|
53
|
+
if (!state.commenting || state.focus) return setHoverBoard(null);
|
|
54
|
+
// The token inspector's panel floats over the canvas: the pointer on it keeps the hovered element.
|
|
55
|
+
if (els.inspector.contains(event.target)) return;
|
|
56
|
+
const shield = event.target.closest(".gd-shield");
|
|
57
|
+
const board = shield ? boardOfShield(shield) : null;
|
|
58
|
+
setHoverBoard(board && !board.system ? board : null);
|
|
59
|
+
if (state.hoverBoard) state.hoverBoard.frame.contentWindow?.postMessage({ type: "gd:hover-at", ...framePoint(board, event.clientX, event.clientY) }, "*");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A board's frame or one of its size frames (canvas-sizes.js): focused with its artboard. */
|
|
63
|
+
function sendFocus(surface) {
|
|
64
|
+
surface.frame.contentWindow?.postMessage({ type: "gd:focus", enabled: actions.ownerOf(surface) === state.focus }, "*");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The artboard's visible size: its manifest size, or the focused screen size, its height
|
|
69
|
+
* clipped to the viewport while that is taller. A report of horizontal overflow belongs to
|
|
70
|
+
* one width, so a new width clears it until the page reports again; any new size starts a new
|
|
71
|
+
* generation, so a pick the page made at the old one is refused (canvas-sizes.js resized).
|
|
72
|
+
*/
|
|
73
|
+
function setFrameSize(board, width, height) {
|
|
74
|
+
const changed = board.viewWidth !== width || board.viewHeight !== height;
|
|
75
|
+
if (board.viewWidth !== width) {
|
|
76
|
+
board.viewWidth = width;
|
|
77
|
+
board.frame.style.width = `${width}px`;
|
|
78
|
+
actions.setOverflow(board, null);
|
|
79
|
+
}
|
|
80
|
+
board.viewHeight = height;
|
|
81
|
+
board.frame.style.height = `${height}px`;
|
|
82
|
+
if (changed) actions.resized(board);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The width a focused artboard has beside the margins: Desktop fills it (canvas-layout S8). */
|
|
86
|
+
function focusRoom() {
|
|
87
|
+
return Math.floor(els.viewport.getBoundingClientRect().width - FOCUS_MARGIN * 2);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 100% zoom with the focused artboard centered at its screen size and its label (Implement
|
|
92
|
+
* this) in view. A wider artboard keeps its real width and is drawn smaller to fit the
|
|
93
|
+
* viewport (the zoom says how much), since the canvas cannot pan in focus mode.
|
|
94
|
+
* A taller artboard is top-aligned and its frame is clipped to the viewport, so it
|
|
95
|
+
* scrolls inside like a browser window instead of leaving its bottom out of reach.
|
|
96
|
+
* All sizes keeps the label at 100% at the top left and fits the size frames below it.
|
|
97
|
+
*/
|
|
98
|
+
function centerFocus(options) {
|
|
99
|
+
const board = state.focus;
|
|
100
|
+
if (!board) return;
|
|
101
|
+
// The artboard moves under the token inspector's panel (a layout change, a resize): it would sit misplaced. A
|
|
102
|
+
// language switch (`keepInspector`) moves it only by a label's height, so the panel is placed again instead.
|
|
103
|
+
const keep = Boolean(options) && options.keepInspector === true;
|
|
104
|
+
if (!keep) actions.hideInspector();
|
|
105
|
+
const viewport = els.viewport.getBoundingClientRect();
|
|
106
|
+
const { width, height } = actions.focusSize(board);
|
|
107
|
+
// The label above the frame wraps at the frame's width: apply the width before measuring it.
|
|
108
|
+
setFrameSize(board, width, board.viewHeight);
|
|
109
|
+
// Layout offsets inside the world ignore its transform, so re-centering is idempotent
|
|
110
|
+
// (a scaled bounding rect carries sub-pixel error that shifted the board by 1 px). The artboard
|
|
111
|
+
// sits where the layout put it, and its frame box below its label, inside it.
|
|
112
|
+
const box = board.frame.parentElement;
|
|
113
|
+
const left = board.wrapper.offsetLeft + box.offsetLeft;
|
|
114
|
+
const top = board.wrapper.offsetTop + box.offsetTop;
|
|
115
|
+
const labelSpace = box.offsetTop;
|
|
116
|
+
const all = state.size.kind === "all";
|
|
117
|
+
// Screen pixels per artboard pixel: 1 when it fits beside the margins.
|
|
118
|
+
const zoom = all ? 1 : Math.min(1, (viewport.width - FOCUS_MARGIN * 2) / width);
|
|
119
|
+
const minTop = FOCUS_MARGIN + labelSpace * zoom;
|
|
120
|
+
const available = viewport.height - minTop - BACK_SPACE;
|
|
121
|
+
const tall = all || height * zoom > available;
|
|
122
|
+
setFrameSize(board, width, tall ? Math.max(120, Math.floor(available / zoom)) : height);
|
|
123
|
+
store.setView({
|
|
124
|
+
zoom,
|
|
125
|
+
x: Math.round(!all && width * zoom + FOCUS_MARGIN * 2 <= viewport.width ? (viewport.width - width * zoom) / 2 - left * zoom : FOCUS_MARGIN - left * zoom),
|
|
126
|
+
y: Math.round((tall ? minTop : Math.max(minTop, (viewport.height - height * zoom) / 2)) - top * zoom),
|
|
127
|
+
});
|
|
128
|
+
actions.applyView();
|
|
129
|
+
// The size frames sit a margin below the label, beside the margins and above the Back to canvas band.
|
|
130
|
+
actions.layoutSizes(board, { top: minTop + FOCUS_MARGIN, side: FOCUS_MARGIN, bottom: BACK_SPACE, width: viewport.width, height: viewport.height });
|
|
131
|
+
actions.renderDevice();
|
|
132
|
+
if (keep) actions.placeInspector();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Shields, hidden and inert boards, toolbar controls and the mode label follow state.focus. */
|
|
136
|
+
function applyFocusState() {
|
|
137
|
+
const focused = state.focus;
|
|
138
|
+
els.viewport.classList.toggle("gd-focused", Boolean(focused));
|
|
139
|
+
for (const board of allBoards()) {
|
|
140
|
+
const active = board === focused;
|
|
141
|
+
board.wrapper.classList.toggle("gd-focus-board", active);
|
|
142
|
+
board.wrapper.inert = Boolean(focused) && !active;
|
|
143
|
+
board.shield.hidden = active;
|
|
144
|
+
if (!active) {
|
|
145
|
+
// Leaving focus mode, or focusing another artboard, restores the manifest size and drops the size frames.
|
|
146
|
+
if (board.viewWidth !== board.artboard.width || board.viewHeight !== board.artboard.height) setFrameSize(board, board.artboard.width, board.artboard.height);
|
|
147
|
+
actions.removeSizeFrames(board);
|
|
148
|
+
}
|
|
149
|
+
actions.renderOverflow(board);
|
|
150
|
+
actions.surfacesOf(board).forEach(sendFocus);
|
|
151
|
+
}
|
|
152
|
+
// The device menu belongs to the artboard it opened on.
|
|
153
|
+
actions.closeDeviceMenu();
|
|
154
|
+
actions.renderDevice();
|
|
155
|
+
for (const control of [els.zoomOut, els.zoomIn, els.fit]) control.disabled = Boolean(focused);
|
|
156
|
+
// The rail's Overview sits under Compare: a reload while it is open must not turn it back on.
|
|
157
|
+
els.railFit.disabled = Boolean(focused || state.compare);
|
|
158
|
+
els.design.disabled = Boolean(focused) || state.designCount === 0;
|
|
159
|
+
els.back.hidden = !focused;
|
|
160
|
+
renderNavMode();
|
|
161
|
+
els.navMode.classList.toggle("gd-using", Boolean(focused));
|
|
162
|
+
actions.renderArrange();
|
|
163
|
+
actions.renderMinimap();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The mode chip: navigating, or the artboard in use. */
|
|
167
|
+
function renderNavMode() {
|
|
168
|
+
els.navMode.textContent = state.focus ? T.using(state.focus.artboard.title) : T.navigating;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function enterFocus(board) {
|
|
172
|
+
if (state.focus === board) return;
|
|
173
|
+
if (!state.focus) {
|
|
174
|
+
// Desktop fills the viewport's width at 100%; hiding the panel gains room for it.
|
|
175
|
+
store.setFocus({ savedView: { zoom: state.zoom, x: state.x, y: state.y }, savedPanel: !els.panel.hidden });
|
|
176
|
+
actions.setPanel(false);
|
|
177
|
+
}
|
|
178
|
+
actions.closePopover();
|
|
179
|
+
setHoverBoard(null);
|
|
180
|
+
actions.selectBoard(null);
|
|
181
|
+
store.setFocus({ focus: board, size: DESKTOP });
|
|
182
|
+
centerFocus();
|
|
183
|
+
applyFocusState();
|
|
184
|
+
board.frame.focus();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function exitFocus() {
|
|
188
|
+
if (!state.focus) return;
|
|
189
|
+
actions.closePopover();
|
|
190
|
+
store.setFocus({ focus: null, size: DESKTOP });
|
|
191
|
+
if (state.savedPanel !== null) actions.setPanel(state.savedPanel);
|
|
192
|
+
store.setFocus({ savedPanel: null });
|
|
193
|
+
if (state.savedView) store.setView(state.savedView);
|
|
194
|
+
store.setFocus({ savedView: null });
|
|
195
|
+
actions.applyView();
|
|
196
|
+
applyFocusState();
|
|
197
|
+
els.viewport.focus();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
els.back.addEventListener("click", exitFocus);
|
|
201
|
+
|
|
202
|
+
return { allBoards, boardOfShield, activateBoard, setHoverBoard, hoverAt, sendFocus, setFrameSize, focusRoom, centerFocus, applyFocusState, enterFocus, exitFocus, relabel: renderNavMode };
|
|
203
|
+
}
|