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.
Files changed (365) hide show
  1. package/README.md +55 -44
  2. package/assets/agents/gentle-ai-explore.md +3 -3
  3. package/assets/agents/gentle-ai-verify.md +20 -6
  4. package/assets/agents/gentle-ai-worker.md +6 -6
  5. package/assets/agents/jd-judge-a.md +1 -3
  6. package/assets/agents/jd-judge-b.md +1 -3
  7. package/assets/agents/review-readability.md +1 -5
  8. package/assets/agents/review-reliability.md +1 -5
  9. package/assets/agents/review-resilience.md +1 -5
  10. package/assets/agents/review-risk.md +1 -5
  11. package/assets/design-canvas/canvas-api.js +45 -0
  12. package/assets/design-canvas/canvas-boards.js +456 -0
  13. package/assets/design-canvas/canvas-boot.js +217 -0
  14. package/assets/design-canvas/canvas-checks.js +491 -0
  15. package/assets/design-canvas/canvas-comments.js +315 -0
  16. package/assets/design-canvas/canvas-compare.js +159 -0
  17. package/assets/design-canvas/canvas-events.js +75 -0
  18. package/assets/design-canvas/canvas-export.js +393 -0
  19. package/assets/design-canvas/canvas-focus.js +203 -0
  20. package/assets/design-canvas/canvas-handoffs.js +150 -0
  21. package/assets/design-canvas/canvas-i18n-es.js +392 -0
  22. package/assets/design-canvas/canvas-i18n.js +108 -0
  23. package/assets/design-canvas/canvas-layout.js +526 -0
  24. package/assets/design-canvas/canvas-menu.js +213 -0
  25. package/assets/design-canvas/canvas-messages.js +86 -0
  26. package/assets/design-canvas/canvas-minimap.js +163 -0
  27. package/assets/design-canvas/canvas-parts.js +401 -0
  28. package/assets/design-canvas/canvas-popover.js +234 -0
  29. package/assets/design-canvas/canvas-rail.js +348 -0
  30. package/assets/design-canvas/canvas-sizes.js +524 -0
  31. package/assets/design-canvas/canvas-store.js +164 -0
  32. package/assets/design-canvas/canvas-tokens.js +674 -0
  33. package/assets/design-canvas/canvas-ui.js +24 -0
  34. package/assets/design-canvas/canvas-view.js +184 -0
  35. package/assets/design-canvas/canvas.css +746 -15
  36. package/assets/design-canvas/canvas.js +2 -1506
  37. package/assets/design-canvas/index.html +117 -36
  38. package/assets/design-canvas/inspector.js +546 -16
  39. package/assets/install-wizard/wizard.js +5 -1
  40. package/assets/migrations/agent-body-history.json +24 -0
  41. package/assets/orchestrator-delegation-reference.md +8 -14
  42. package/assets/orchestrator-delegation.md +4 -4
  43. package/assets/orchestrator-full-delegation-card.md +4 -5
  44. package/assets/orchestrator-full-delegation.md +8 -8
  45. package/assets/orchestrator-memory.md +2 -2
  46. package/assets/orchestrator-prompts.md +1 -1
  47. package/assets/orchestrator-quota-recovery.md +5 -0
  48. package/assets/orchestrator-skills.md +13 -12
  49. package/assets/orchestrator-tracking.md +10 -14
  50. package/assets/orchestrator-verification.md +10 -8
  51. package/assets/orchestrator-writer.md +4 -4
  52. package/assets/orchestrator.md +18 -22
  53. package/bin/gentle-shell.mjs +128 -9
  54. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  55. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
  56. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
  60. package/docs/assets/brand/sponsor-banner.svg +60 -0
  61. package/docs/bundled-install.md +14 -6
  62. package/docs/delegated-verification.md +18 -2
  63. package/docs/desktop-rpc.md +1253 -0
  64. package/docs/gentle-agents-activity.md +26 -0
  65. package/docs/gentle-shell.md +39 -16
  66. package/docs/install-wizard.md +30 -21
  67. package/docs/odd-preparation-continuity.md +24 -0
  68. package/docs/permission-modes.md +9 -1
  69. package/docs/prompt-budget.md +12 -0
  70. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  71. package/docs/readme-reference.md +76 -24
  72. package/docs/review-coordinator.md +29 -9
  73. package/docs/review-delivery-preflight.md +22 -0
  74. package/docs/work-continuity.md +11 -1
  75. package/extensions/ask-user-question.ts +2 -2
  76. package/extensions/child-context.ts +21 -7
  77. package/extensions/gentle-agents.ts +234 -33
  78. package/extensions/gentle-ai.ts +576 -135
  79. package/extensions/gentle-design.ts +69 -3
  80. package/extensions/gentle-desktop-rpc.ts +143 -0
  81. package/extensions/gentle-guide.ts +3 -0
  82. package/extensions/gentle-shell.ts +105 -52
  83. package/extensions/gentle-todo.ts +48 -25
  84. package/extensions/skill-registry.ts +248 -223
  85. package/lib/agent-assets.ts +30 -6
  86. package/lib/agent-tool-overlay.ts +117 -0
  87. package/lib/agents-config.ts +47 -6
  88. package/lib/agents-message-delivery.ts +17 -0
  89. package/lib/agents-messaging.ts +8 -2
  90. package/lib/agents-protocol.ts +15 -0
  91. package/lib/agents-report-cap.ts +115 -0
  92. package/lib/agents-runner.ts +91 -6
  93. package/lib/agents-session-transport.ts +17 -1
  94. package/lib/background-jobs-tools.ts +9 -4
  95. package/lib/bounded-writer-admission.ts +184 -31
  96. package/lib/child-context-files.ts +21 -6
  97. package/lib/codemode-renderer.ts +1 -0
  98. package/lib/delivery-conflict-markers.ts +349 -0
  99. package/lib/design-canvas-assets.ts +36 -0
  100. package/lib/design-canvas-server.ts +241 -23
  101. package/lib/design-comments.ts +94 -4
  102. package/lib/design-handoffs.ts +2 -1
  103. package/lib/design-layout.ts +125 -0
  104. package/lib/design-parts.ts +281 -0
  105. package/lib/design-system-tokens.ts +111 -0
  106. package/lib/desktop-agents-service.ts +294 -0
  107. package/lib/desktop-design-service.ts +233 -0
  108. package/lib/desktop-jobs-service.ts +263 -0
  109. package/lib/desktop-rpc-agents.ts +294 -0
  110. package/lib/desktop-rpc-config.ts +731 -0
  111. package/lib/desktop-rpc-design.ts +138 -0
  112. package/lib/desktop-rpc-jobs.ts +181 -0
  113. package/lib/desktop-rpc-permissions.ts +177 -0
  114. package/lib/desktop-rpc-profiles.ts +196 -0
  115. package/lib/desktop-rpc-usage.ts +229 -0
  116. package/lib/desktop-rpc.ts +225 -0
  117. package/lib/desktop-usage-service.ts +310 -0
  118. package/lib/destructive-command-guard.ts +188 -13
  119. package/lib/gentle-ai-renderer.ts +13 -1
  120. package/lib/gentle-design.ts +201 -14
  121. package/lib/gentle-shell-bundled.ts +100 -9
  122. package/lib/hidden-tools.ts +35 -0
  123. package/lib/inprocess-reviewer.ts +96 -12
  124. package/lib/model-fallback-policy.ts +9 -0
  125. package/lib/model-routing-authority.ts +9 -0
  126. package/lib/nan-provider.ts +42 -28
  127. package/lib/native-review-cli.ts +79 -4
  128. package/lib/orchestrator-discovery.ts +39 -2
  129. package/lib/reply-language-anchor.ts +27 -2
  130. package/lib/request-context-placement.ts +53 -0
  131. package/lib/review-candidate-view.ts +11 -1
  132. package/lib/review-continuation-registry.ts +17 -0
  133. package/lib/review-coordinator.ts +252 -8
  134. package/lib/review-delivery-preflight.ts +85 -0
  135. package/lib/review-host-relay.ts +5 -1
  136. package/lib/review-integration-v2.ts +56 -3
  137. package/lib/reviewer-stream.ts +87 -0
  138. package/lib/shell-prompt.ts +16 -3
  139. package/lib/shell-usage.ts +10 -0
  140. package/lib/vim-editor-adapter.ts +9 -2
  141. package/lib/writer-batch-admission.ts +55 -0
  142. package/lib/yolo-session-policy.ts +6 -1
  143. package/package.json +2 -2
  144. package/prompts/skill-creation.md +1 -10
  145. package/runtime/design-canvas-assets.mjs +37 -0
  146. package/runtime/gentle-shell-bundled.mjs +100 -9
  147. package/runtime/native-review-cli.mjs +79 -4
  148. package/runtime/review-integration-v2.mjs +56 -3
  149. package/scripts/bootstrap.cmd +2 -2
  150. package/scripts/bootstrap.sh +41 -4
  151. package/scripts/build-full-delegation-card.mjs +4 -0
  152. package/scripts/build-runtime-modules.mjs +1 -0
  153. package/scripts/gentle-ai-installer.mjs +10 -10
  154. package/scripts/gentle-ai-proxy.mjs +1 -1
  155. package/scripts/installer-downloads.mjs +34 -8
  156. package/scripts/installer-preflight.mjs +28 -17
  157. package/scripts/installer-probes.mjs +25 -5
  158. package/scripts/installer-server.mjs +38 -9
  159. package/scripts/installer-windows.mjs +2 -2
  160. package/scripts/pi-update.mjs +166 -27
  161. package/scripts/prepare-verifier.mjs +107 -0
  162. package/scripts/update-agent-body-history.mjs +55 -8
  163. package/scripts/verify-package-files.mjs +40 -19
  164. package/skills/branch-pr/SKILL.md +16 -16
  165. package/skills/comment-writer/SKILL.md +1 -1
  166. package/skills/design/SKILL.md +6 -6
  167. package/skills/gentle-ai/SKILL.md +5 -5
  168. package/skills/judgment-day/SKILL.md +2 -2
  169. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  170. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  171. package/skills/skill-improver/SKILL.md +2 -2
  172. package/skills/skill-registry/SKILL.md +11 -13
  173. package/skills/tui-design/SKILL.md +1 -1
  174. package/skills/work-unit-commits/SKILL.md +5 -5
  175. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  176. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  177. package/tests/agent-tool-overlay.test.ts +89 -0
  178. package/tests/agents-config.test.ts +10 -1
  179. package/tests/agents-message-delivery.test.ts +36 -0
  180. package/tests/agents-queries.test.ts +144 -4
  181. package/tests/agents-report-cap.test.ts +126 -0
  182. package/tests/agents-runner.test.ts +37 -1
  183. package/tests/agents-session-transport.test.ts +34 -0
  184. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  185. package/tests/append-system-prompt-route.test.ts +10 -2
  186. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  187. package/tests/artifact-language.test.ts +1 -1
  188. package/tests/ask-user-question.test.ts +2 -1
  189. package/tests/audit-leftovers-contract.test.ts +51 -0
  190. package/tests/bounded-stop-contract.test.ts +9 -1
  191. package/tests/branch-pr-skill.test.ts +10 -1
  192. package/tests/bundled-install.test.ts +1 -1
  193. package/tests/child-context-files.test.ts +64 -8
  194. package/tests/child-skills-catalog.test.ts +56 -0
  195. package/tests/codemode-rendering.test.ts +4 -1
  196. package/tests/delegate-for-reason-contract.test.ts +30 -8
  197. package/tests/delivery-conflict-markers.test.ts +348 -0
  198. package/tests/design-canvas-all-sizes.test.ts +631 -0
  199. package/tests/design-canvas-allowlist.test.ts +32 -0
  200. package/tests/design-canvas-assets.test.ts +11 -878
  201. package/tests/design-canvas-boards.test.ts +77 -0
  202. package/tests/design-canvas-checks.test.ts +655 -0
  203. package/tests/design-canvas-compare.test.ts +79 -0
  204. package/tests/design-canvas-events.test.ts +59 -0
  205. package/tests/design-canvas-export.test.ts +1168 -0
  206. package/tests/design-canvas-focus.test.ts +113 -0
  207. package/tests/design-canvas-handoffs.test.ts +59 -0
  208. package/tests/design-canvas-i18n-review.test.ts +513 -0
  209. package/tests/design-canvas-i18n-views.test.ts +259 -0
  210. package/tests/design-canvas-i18n.test.ts +526 -0
  211. package/tests/design-canvas-inspector.test.ts +937 -0
  212. package/tests/design-canvas-layout.test.ts +1222 -0
  213. package/tests/design-canvas-minimap.test.ts +413 -0
  214. package/tests/design-canvas-modules.test.ts +90 -0
  215. package/tests/design-canvas-parts.test.ts +721 -0
  216. package/tests/design-canvas-rail.test.ts +799 -0
  217. package/tests/design-canvas-server.test.ts +855 -17
  218. package/tests/design-canvas-sizes.test.ts +548 -0
  219. package/tests/design-canvas-store.test.ts +180 -0
  220. package/tests/design-canvas-tokens.test.ts +965 -0
  221. package/tests/design-canvas-view.test.ts +299 -0
  222. package/tests/design-comments.test.ts +201 -1
  223. package/tests/design-handoffs.test.ts +20 -0
  224. package/tests/design-layout.test.ts +100 -0
  225. package/tests/design-parts.test.ts +260 -0
  226. package/tests/design-system-tokens.test.ts +215 -0
  227. package/tests/desktop-rpc-agents.test.ts +893 -0
  228. package/tests/desktop-rpc-config.test.ts +1452 -0
  229. package/tests/desktop-rpc-design.test.ts +662 -0
  230. package/tests/desktop-rpc-jobs.test.ts +796 -0
  231. package/tests/desktop-rpc-permissions.test.ts +311 -0
  232. package/tests/desktop-rpc-profiles.test.ts +140 -0
  233. package/tests/desktop-rpc-safety.test.ts +119 -0
  234. package/tests/desktop-rpc-usage.test.ts +697 -0
  235. package/tests/desktop-rpc.test.ts +252 -0
  236. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  237. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  238. package/tests/engram-safety.test.ts +111 -0
  239. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  240. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  241. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
  242. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  243. package/tests/full-delegation-closure.test.ts +29 -0
  244. package/tests/gentle-agents.test.ts +329 -4
  245. package/tests/gentle-ai-binary.test.ts +1 -1
  246. package/tests/gentle-ai-child-guards.test.ts +1 -0
  247. package/tests/gentle-ai-installer.test.ts +52 -51
  248. package/tests/gentle-ai-renderer.test.ts +36 -2
  249. package/tests/gentle-ai.test.ts +121 -6
  250. package/tests/gentle-design.test.ts +365 -1
  251. package/tests/gentle-shell-bundled.test.ts +91 -5
  252. package/tests/gentle-shell-launcher.test.ts +1 -1
  253. package/tests/gentle-shell.test.ts +118 -87
  254. package/tests/gentle-todo.test.ts +32 -9
  255. package/tests/hidden-tools.test.ts +188 -0
  256. package/tests/independent-recovery-delivery.test.ts +19 -5
  257. package/tests/inprocess-reviewer.test.ts +73 -0
  258. package/tests/install-wizard.test.ts +27 -1
  259. package/tests/installer-downloads.test.ts +30 -1
  260. package/tests/installer-posix-bootstrap.test.ts +114 -13
  261. package/tests/installer-preflight.test.ts +49 -1
  262. package/tests/installer-probes.test.ts +146 -0
  263. package/tests/installer-server.test.ts +203 -4
  264. package/tests/installer-windows-bootstrap.test.ts +19 -1
  265. package/tests/judgment-day-severity-admission.test.ts +46 -0
  266. package/tests/lazy-module-contradictions-contract.test.ts +158 -0
  267. package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
  268. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  269. package/tests/model-fallback-policy.test.ts +26 -7
  270. package/tests/nan-provider-runtime.test.ts +17 -3
  271. package/tests/nan-provider.test.ts +111 -56
  272. package/tests/native-review-capability-contract.test.ts +11 -1
  273. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  274. package/tests/native-review-parity.test.ts +24 -5
  275. package/tests/native-review-refusal-identity.test.ts +25 -0
  276. package/tests/no-self-pause-contract.test.ts +11 -3
  277. package/tests/odd-integration.test.ts +11 -3
  278. package/tests/odd-routing-contract.test.ts +80 -28
  279. package/tests/orchestrator-budget.test.ts +30 -5
  280. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  281. package/tests/orchestrator-delegation-mode.test.ts +2 -1
  282. package/tests/orchestrator-discovery.test.ts +28 -0
  283. package/tests/orchestrator-prompt-budget.test.ts +11 -2
  284. package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
  285. package/tests/orchestrator-rdd-ownership.test.ts +2 -1
  286. package/tests/orchestrator-work-search.test.ts +4 -2
  287. package/tests/package-files.test.ts +25 -1
  288. package/tests/package-manifest.test.ts +11 -10
  289. package/tests/parallel-reason-contract.test.ts +6 -3
  290. package/tests/permission-allowlist.test.ts +200 -30
  291. package/tests/persona-neutral-voseo.test.ts +4 -4
  292. package/tests/persona-reply-language.test.ts +1 -1
  293. package/tests/persona-single-channel.test.ts +13 -5
  294. package/tests/pi-update-launcher.test.ts +17 -7
  295. package/tests/pi-update-source.test.ts +113 -6
  296. package/tests/pi-update.test.ts +294 -19
  297. package/tests/pnpm-workspace-policy.test.ts +47 -0
  298. package/tests/primary-context-files.test.ts +233 -0
  299. package/tests/primary-context-three-files.test.ts +174 -0
  300. package/tests/provider-defect-handoff.test.ts +9 -2
  301. package/tests/rdd-aware-verification-contract.test.ts +1 -1
  302. package/tests/rdd-status-line.test.ts +94 -1
  303. package/tests/reply-language-anchor-placement.test.ts +184 -0
  304. package/tests/reply-language-anchor.test.ts +17 -1
  305. package/tests/request-context-append-only.test.ts +218 -0
  306. package/tests/request-context-placement.test.ts +148 -0
  307. package/tests/review-agent-end-preflight.test.ts +79 -1
  308. package/tests/review-candidate-view.test.ts +65 -0
  309. package/tests/review-continuation-registry.test.ts +31 -0
  310. package/tests/review-contract-prompt.test.ts +1 -1
  311. package/tests/review-controller.test.ts +2 -1
  312. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  313. package/tests/review-coordinator-findings.test.ts +206 -0
  314. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  315. package/tests/review-coordinator.test.ts +271 -4
  316. package/tests/review-delivery-preflight.test.ts +462 -0
  317. package/tests/review-due-compaction.test.ts +31 -0
  318. package/tests/review-due-public-boundary.test.ts +26 -0
  319. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  320. package/tests/review-json-arguments.test.ts +41 -2
  321. package/tests/review-ledger-contract.test.ts +19 -40
  322. package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
  323. package/tests/review-one-call-findings.test.ts +131 -0
  324. package/tests/review-one-call-followups.test.ts +308 -0
  325. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  326. package/tests/review-one-call.test.ts +452 -0
  327. package/tests/review-relay-transport-agent.test.ts +28 -1
  328. package/tests/review-reviewer-evidence.test.ts +41 -1
  329. package/tests/review-risk-assessment.test.ts +52 -5
  330. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  331. package/tests/review-session-standing-permission-controller.test.ts +32 -2
  332. package/tests/review-tool-prose-budget.test.ts +1 -0
  333. package/tests/reviewer-stream.test.ts +149 -0
  334. package/tests/session-profile-extension.test.ts +2 -2
  335. package/tests/shell-prompt.test.ts +17 -0
  336. package/tests/shell-usage.test.ts +59 -10
  337. package/tests/skill-contradictions-contract.test.ts +122 -0
  338. package/tests/skill-registry-watcher.test.ts +216 -2
  339. package/tests/skill-registry.test.ts +929 -306
  340. package/tests/support/design-canvas-dom.ts +369 -0
  341. package/tests/support/review-coordinator-runtime.ts +212 -17
  342. package/tests/task-size-routing-contract.test.ts +42 -11
  343. package/tests/test-strength-contract.test.ts +2 -1
  344. package/tests/todo-request-append-only.test.ts +214 -0
  345. package/tests/tool-batching-contract.test.ts +3 -1
  346. package/tests/update-agent-body-history.test.ts +138 -0
  347. package/tests/verification-tiers-contract.test.ts +229 -0
  348. package/tests/verifier-preparation.test.ts +229 -0
  349. package/tests/verify-agent-contract.test.ts +20 -2
  350. package/tests/verify-first-launch-contract.test.ts +87 -11
  351. package/tests/vim-editor-adapter.test.ts +2 -2
  352. package/tests/work-continuity-contract.test.ts +54 -11
  353. package/tests/writer-admission-messages.test.ts +232 -0
  354. package/tests/writer-batch-admission.test.ts +66 -0
  355. package/tests/writer-edit-surface-scope.test.ts +52 -20
  356. package/tests/writer-feature-document-admission.test.ts +184 -0
  357. package/tests/yolo-mode.test.ts +39 -0
  358. package/skills/_shared/review-ledger-contract.md +0 -106
  359. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
  360. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
  361. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
  362. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  363. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
  364. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
  365. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -0,0 +1,524 @@
1
+ // Screen sizes in focus mode: the top bar's device button and its menu (Phone,
2
+ // Tablet, Desktop, All sizes and a custom width), and the size each one gives the focused
3
+ // artboard's frame (focusSize, which canvas-focus.js centers). A size resizes the
4
+ // frame in place, so the design's own media queries respond; nothing reloads.
5
+ // The size lives in the store (setFocus), and the menu is the shared one
6
+ // (canvas-menu.js) with its own element, #gd-device-menu.
7
+ //
8
+ // All sizes shows the focused artboard at Phone, Tablet and as designed at once: a real iframe per
9
+ // size ("size frame") at its true width, scaled together outside the world. A board and its size
10
+ // frames are its "surfaces": each takes picks, shows pins, reports overflow and records the size a
11
+ // comment was made at (viewportOf), so the other modules handle a size frame as they handle a board.
12
+ // This module owns the board fields it changes in place (canvas-store.js): board.sizeFrames,
13
+ // board.sizesView, board.overflow and board.generation, and each size frame's own rects and overflow. The other
14
+ // modules change a frame's overflow only through setOverflow, and its generation only through resized.
15
+ //
16
+ // A frame's generation counts the sizes it has had. The canvas tells the frame's page (gd:size) when it loads and
17
+ // whenever the frame changes size, and the page tags each pick with the generation it heard last: a pick made before
18
+ // a resize, whose reply arrives after it, carries an older one and is refused (canvas-messages.js), so a comment is
19
+ // never sent with a size it was not made at. The same message tells the page that the canvas dropped its overflow
20
+ // report, so the page reports again even when its answer did not change.
21
+
22
+ // Every string the sizes show, in English; canvas-i18n-es.js has the Spanish. Artboard titles stay as written.
23
+ const TEXT = Object.freeze({
24
+ group: "Preview size",
25
+ phone: "Phone",
26
+ tablet: "Tablet",
27
+ desktop: "Desktop",
28
+ all: "All sizes",
29
+ allTitle: "All sizes: Phone, Tablet and the artboard as designed, side by side",
30
+ designed: "As designed",
31
+ custom: "Custom",
32
+ customAria: "Custom width in pixels",
33
+ customGroup: "Custom width",
34
+ error: (min, max) => `Enter a whole number from ${min} to ${max} (px).`,
35
+ itemTitle: (name, width, height) => `${name} ${width} × ${height}`,
36
+ button: (size) => `Preview size: ${size}`,
37
+ buttonTitle: "Preview size of the open artboard",
38
+ buttonOff: "Open an artboard to choose its preview size",
39
+ frameAria: (name, width, height) => `${name} ${width} by ${height}`,
40
+ frameTitle: (title, name, width, height) => `${title} artboard at ${name} ${width} × ${height}`,
41
+ designedTitle: (title, width, height) => `${title} artboard as designed, ${width} × ${height}`,
42
+ scale: (percent) => `· ${percent}%`,
43
+ overflow: "Overflows",
44
+ overflowNote: (width) => `Content is wider than ${width} px, so part of it is cut off or needs sideways scrolling at this size.`,
45
+ madeAt: (label) => `Made at ${label}`,
46
+ });
47
+
48
+ // Phone and Tablet are fixed sizes; Desktop fills the viewport beside the focus margins, never
49
+ // narrower than the artboard was designed (canvas-layout S8), at the artboard's manifest height.
50
+ const SIZE_PRESETS = [
51
+ { kind: "phone", width: 390, height: 844 },
52
+ { kind: "tablet", width: 820, height: 1180 },
53
+ { kind: "desktop" },
54
+ ];
55
+ // The custom width: whole CSS px in this range, with the manifest height.
56
+ const CUSTOM_WIDTH = { min: 240, max: 2560 };
57
+ // The device button wears the icon of the size it shows (canvas-layout S6).
58
+ const SIZE_ICONS = { phone: "i-phone", tablet: "i-tablet", desktop: "i-monitor", all: "i-devices", custom: "i-width" };
59
+ // All sizes' third frame is the artboard at its own size in design.json, not a device: it wears the artboard frame icon.
60
+ const DESIGNED_ICON = "i-fit";
61
+ // What comments.json accepts for the size a comment was made at (lib/design-comments.ts).
62
+ const VIEWPORT_LIMITS = { minWidth: 240, maxWidth: 4096, minHeight: 1, maxHeight: 20000 };
63
+ // All sizes: the gap between the frames, the band each label takes above its frame, and the smallest scale.
64
+ const SIZES_GAP = 20;
65
+ const SIZES_HEAD = 28;
66
+ const MIN_SIZES_SCALE = 0.05;
67
+
68
+ export function init(ctx) {
69
+ const { doc, els, store, actions } = ctx;
70
+ const { state } = store;
71
+ const T = ctx.i18n.text("sizes", TEXT);
72
+
73
+ const nameOf = (kind) => T[kind] ?? T.desktop;
74
+ const dims = (size) => `${size.width} × ${size.height}`;
75
+
76
+ /** Desktop: the viewport's whole width at 100%, never narrower than the artboard was designed. */
77
+ function desktopSize(board) {
78
+ return { width: Math.max(board.artboard.width, actions.focusRoom()), height: board.artboard.height };
79
+ }
80
+
81
+ function presetSize(board, preset) {
82
+ return preset.kind === "desktop" ? desktopSize(board) : { width: preset.width, height: preset.height };
83
+ }
84
+
85
+ /** The artboard's own size in design.json. */
86
+ function manifestSize(board) {
87
+ return { width: board.artboard.width, height: board.artboard.height };
88
+ }
89
+
90
+ /**
91
+ * What the focused size means for `board`: its frame's width and height before the viewport clips a tall one.
92
+ * All sizes keeps the artboard's own frame (hidden behind the size frames) at its manifest size.
93
+ */
94
+ function focusSize(board) {
95
+ const size = state.size;
96
+ if (size.kind === "custom") return { width: size.width, height: board.artboard.height };
97
+ if (size.kind === "all") return manifestSize(board);
98
+ return presetSize(board, SIZE_PRESETS.find((preset) => preset.kind === size.kind) ?? SIZE_PRESETS[2]);
99
+ }
100
+
101
+ /** The board's own frame, then the size frames All sizes adds: every one takes picks and shows pins the same way. */
102
+ function surfacesOf(board) {
103
+ return board.sizeFrames.length > 0 ? [board, ...board.sizeFrames] : [board];
104
+ }
105
+
106
+ /** The artboard a frame belongs to: a board is its own, a size frame names its board. */
107
+ function ownerOf(surface) {
108
+ return surface.board ?? surface;
109
+ }
110
+
111
+ /**
112
+ * The device button: the icon and short name of the focused size and its width × height.
113
+ * Outside focus mode it is off: the sizes act on an open artboard only (canvas-layout S6).
114
+ */
115
+ function renderDevice() {
116
+ const board = state.focus;
117
+ const kind = board && SIZE_ICONS[state.size.kind] ? state.size.kind : "desktop";
118
+ const name = nameOf(kind);
119
+ // All sizes has no one size to name.
120
+ const size = board && kind !== "all" ? dims(focusSize(board)) : "";
121
+ els.deviceIcon.setAttribute("href", `#${SIZE_ICONS[kind]}`);
122
+ els.deviceName.textContent = name;
123
+ els.deviceSize.textContent = size;
124
+ els.device.disabled = !board;
125
+ els.device.title = board ? T.buttonTitle : T.buttonOff;
126
+ els.device.setAttribute("aria-label", T.button(size ? `${name} ${size}` : name));
127
+ }
128
+
129
+ /** A span with a class and text. */
130
+ function chip(className, text) {
131
+ const span = doc.createElement("span");
132
+ span.className = className;
133
+ span.textContent = text;
134
+ return span;
135
+ }
136
+
137
+ /** One radio item of the device menu: icon, name, its size for the focused artboard (none for All sizes) and a check when it is the current one. */
138
+ function deviceItem(kind, title, size) {
139
+ const item = doc.createElement("button");
140
+ item.type = "button";
141
+ item.className = "gd-menu-item gd-device-item";
142
+ item.setAttribute("role", "menuitemradio");
143
+ item.setAttribute("aria-checked", String(state.size.kind === kind));
144
+ item.setAttribute("tabindex", "-1");
145
+ item.dataset.size = kind;
146
+ item.title = title;
147
+ item.append(actions.icon(SIZE_ICONS[kind], "gd-i gd-i-s"), chip("gd-menu-label", nameOf(kind)));
148
+ if (size) item.append(chip("gd-device-dim", dims(size)));
149
+ item.append(actions.icon("i-check", "gd-i gd-i-s gd-device-check"));
150
+ item.addEventListener("click", () => chooseDeviceItem(item));
151
+ return item;
152
+ }
153
+
154
+ function presetItem(board, preset) {
155
+ const size = presetSize(board, preset);
156
+ return deviceItem(preset.kind, T.itemTitle(nameOf(preset.kind), size.width, size.height), size);
157
+ }
158
+
159
+ // The open menu's width field and its error line; null while the device menu is closed.
160
+ let custom = null;
161
+
162
+ /**
163
+ * The device menu, built when it opens: Phone, Tablet, Desktop and All sizes as radio items, then the
164
+ * custom width field. The arrows reach the field as the last entry; inside it the other keys stay with the field.
165
+ */
166
+ function openDeviceMenu(last) {
167
+ const board = state.focus;
168
+ if (!board) return;
169
+ const items = [...SIZE_PRESETS.map((preset) => presetItem(board, preset)), deviceItem("all", T.allTitle, null)];
170
+ const separator = doc.createElement("div");
171
+ separator.className = "gd-menu-separator";
172
+ separator.setAttribute("role", "separator");
173
+ const row = doc.createElement("label");
174
+ row.className = "gd-device-custom";
175
+ row.classList.toggle("gd-selected", state.size.kind === "custom");
176
+ const input = doc.createElement("input");
177
+ input.type = "number";
178
+ // A name keeps the browser from flagging an anonymous form field.
179
+ input.name = "gd-custom-width";
180
+ input.className = "gd-device-input";
181
+ input.setAttribute("aria-label", T.customAria);
182
+ input.setAttribute("min", String(CUSTOM_WIDTH.min));
183
+ input.setAttribute("max", String(CUSTOM_WIDTH.max));
184
+ input.setAttribute("step", "1");
185
+ input.setAttribute("inputmode", "numeric");
186
+ input.value = state.size.kind === "custom" ? String(state.size.width) : "";
187
+ const unit = chip("gd-device-unit", "px");
188
+ unit.setAttribute("aria-hidden", "true");
189
+ row.append(actions.icon(SIZE_ICONS.custom, "gd-i gd-i-s"), chip("gd-device-custom-label", T.custom), input, unit);
190
+ const error = doc.createElement("p");
191
+ error.className = "gd-device-error";
192
+ error.setAttribute("role", "alert");
193
+ error.hidden = true;
194
+ input.addEventListener("keydown", (event) => {
195
+ if (event.key !== "Enter") return;
196
+ event.preventDefault();
197
+ applyCustomWidth();
198
+ });
199
+ custom = { input, error };
200
+ // A menu owns only items, separators and groups: the field and its error sit in a named group, so screen readers in
201
+ // menu mode still reach and announce them.
202
+ const group = doc.createElement("div");
203
+ group.className = "gd-device-custom-group";
204
+ group.setAttribute("role", "group");
205
+ group.setAttribute("aria-label", T.customGroup);
206
+ group.append(row, error);
207
+ actions.openMenu(els.device, els.deviceMenu, [...items, separator, group], [...items, input], T.group, last ? input : items[0]);
208
+ }
209
+
210
+ const deviceMenuOpen = () => Boolean(state.menu && state.menu.root === els.deviceMenu);
211
+
212
+ /** Closes the device menu when it is the open one (focus goes back to the button when it was inside). */
213
+ function closeDeviceMenu(refocus = false) {
214
+ if (deviceMenuOpen()) actions.closeMenu(refocus);
215
+ }
216
+
217
+ function chooseDeviceItem(item) {
218
+ // The field is an entry of the arrow keys, not a choice: Enter in it applies the width.
219
+ if (!deviceMenuOpen() || !item.dataset.size) return;
220
+ closeDeviceMenu(true);
221
+ setSize({ kind: item.dataset.size });
222
+ }
223
+
224
+ /** The custom width: whole px from 240 to 2560; anything else keeps the menu open with the error under the field. */
225
+ function applyCustomWidth() {
226
+ if (!deviceMenuOpen() || !custom) return;
227
+ const { input, error } = custom;
228
+ const text = String(input.value).trim();
229
+ const width = Number(text);
230
+ if (!/^\d+$/.test(text) || width < CUSTOM_WIDTH.min || width > CUSTOM_WIDTH.max) {
231
+ input.setAttribute("aria-invalid", "true");
232
+ error.textContent = T.error(CUSTOM_WIDTH.min, CUSTOM_WIDTH.max);
233
+ error.hidden = false;
234
+ return;
235
+ }
236
+ input.removeAttribute("aria-invalid");
237
+ error.hidden = true;
238
+ closeDeviceMenu(true);
239
+ setSize({ kind: "custom", width });
240
+ }
241
+
242
+ /** Gives the focused artboard a size; a bad custom width never gets here (the field refuses it). */
243
+ function setSize(size) {
244
+ if (!state.focus) return;
245
+ actions.closePopover();
246
+ // A check's ring was drawn for the frame at its old size.
247
+ actions.clearMark();
248
+ store.setFocus({ size: Object.freeze(size) });
249
+ // centerFocus lays the frames out for the size (layoutSizes): All sizes adds its frames, another size removes them.
250
+ actions.centerFocus();
251
+ }
252
+
253
+ // ---- All sizes: a frame per size, registered like the board's own frame
254
+
255
+ /**
256
+ * The sizes All sizes shows: Phone and Tablet, and the artboard as designed, at its own size in design.json
257
+ * (L12: labelled by what it is, never Desktop; side by side, nothing fills the window).
258
+ */
259
+ function allSizes(board) {
260
+ return SIZE_PRESETS.map((preset) => (preset.kind === "desktop" ? { kind: "designed", ...manifestSize(board) } : { kind: preset.kind, ...presetSize(board, preset) }));
261
+ }
262
+
263
+ /**
264
+ * Brings `board`'s size frames in line with the focused size, from canvas-focus.js's centerFocus: the
265
+ * focused board in All sizes gets them, laid out in `box` (the viewport's size, the margins kept free
266
+ * and the top below the artboard's label); any other loses them. Its own chip follows the size.
267
+ */
268
+ function layoutSizes(board, box) {
269
+ if (state.focus === board && state.size.kind === "all") {
270
+ if (!board.sizesView) createSizeFrames(board);
271
+ placeSizeFrames(board, box);
272
+ } else removeSizeFrames(board);
273
+ renderOverflow(board);
274
+ }
275
+
276
+ /** A real iframe per size at its true width (so the design's media queries apply), shown outside the world. */
277
+ function createSizeFrames(board) {
278
+ const view = doc.createElement("div");
279
+ view.className = "gd-sizes-all";
280
+ view.classList.toggle("gd-commenting", state.commenting && !board.system);
281
+ view.setAttribute("role", "group");
282
+ board.sizeFrames = allSizes(board).map((size) => createSizeFrame(board, size));
283
+ view.append(...board.sizeFrames.map((surface) => surface.root));
284
+ board.sizesView = view;
285
+ labelSizesView(board);
286
+ board.wrapper.classList.add("gd-all-sizes");
287
+ els.viewport.append(view);
288
+ }
289
+
290
+ function createSizeFrame(board, { kind, width, height }) {
291
+ const root = doc.createElement("section");
292
+ root.className = "gd-size-frame";
293
+ const head = doc.createElement("div");
294
+ head.className = "gd-size-head";
295
+ const scaleLabel = chip("gd-size-scale", "");
296
+ const nameLabel = chip("gd-size-name", "");
297
+ const designed = kind === "designed";
298
+ head.append(actions.icon(designed ? DESIGNED_ICON : SIZE_ICONS[kind], "gd-i gd-i-s"), nameLabel, chip("gd-size-dim", dims({ width, height })), scaleLabel);
299
+ const scaled = doc.createElement("div");
300
+ scaled.className = "gd-size-scaled";
301
+ const stage = doc.createElement("div");
302
+ stage.className = "gd-size-stage";
303
+ stage.style.width = `${width}px`;
304
+ stage.style.height = `${height}px`;
305
+ const frame = doc.createElement("iframe");
306
+ frame.className = "gd-size-iframe";
307
+ frame.setAttribute("sandbox", "allow-scripts");
308
+ frame.setAttribute("referrerpolicy", "no-referrer");
309
+ frame.style.width = `${width}px`;
310
+ frame.style.height = `${height}px`;
311
+ const pins = doc.createElement("div");
312
+ pins.className = "gd-pins";
313
+ const flag = overflowFlag();
314
+ stage.append(frame, pins);
315
+ scaled.append(stage, flag);
316
+ root.append(head, scaled);
317
+ // rects and overflow: null until this frame's page reports them (canvas-messages.js). A size frame never
318
+ // changes size, so its generation stays 0.
319
+ const surface = { board, kind, width, height, viewWidth: width, viewHeight: height, frame, pins, flag, rects: null, overflow: null, generation: 0, root, head, scaled, stage, scaleLabel, nameLabel, scale: null };
320
+ labelSizeFrame(surface);
321
+ frame.addEventListener("load", () => surfaceLoaded(surface));
322
+ frame.src = actions.boardUrl(board);
323
+ return surface;
324
+ }
325
+
326
+ /** A size frame's own text in the current language: its name, its label and its frame's title. */
327
+ function labelSizeFrame(surface) {
328
+ const { board, kind, width, height } = surface;
329
+ const name = nameOf(kind);
330
+ surface.root.setAttribute("aria-label", T.frameAria(name, width, height));
331
+ surface.nameLabel.textContent = name;
332
+ surface.frame.title = kind === "designed" ? T.designedTitle(board.artboard.title, width, height) : T.frameTitle(board.artboard.title, name, width, height);
333
+ }
334
+
335
+ /** All sizes' group name, and each frame's scale and header title once it has a scale (placeSizeFrames). */
336
+ function labelSizesView(board) {
337
+ board.sizesView.setAttribute("aria-label", T.all);
338
+ for (const surface of board.sizeFrames) {
339
+ if (surface.scale === null) continue;
340
+ surface.scaleLabel.textContent = T.scale(Math.round(surface.scale * 100));
341
+ surface.head.title = `${nameOf(surface.kind)} ${dims(surface)} ${surface.scaleLabel.textContent}`;
342
+ }
343
+ }
344
+
345
+ /**
346
+ * Drops `board`'s size frames. A comment box open on one of them closes first, while that frame still
347
+ * shows, so it clears its outline and no later Cancel reaches a removed frame (an export, for one,
348
+ * leaves All sizes without setSize).
349
+ */
350
+ function removeSizeFrames(board) {
351
+ board.wrapper.classList.remove("gd-all-sizes");
352
+ if (!board.sizesView) return;
353
+ if (state.pick && board.sizeFrames.includes(state.pick.surface)) actions.closePopover();
354
+ board.sizesView.remove();
355
+ board.sizesView = null;
356
+ board.sizeFrames = [];
357
+ // The token inspector's panel and a check's ring go with their frame.
358
+ actions.hideGoneInspector();
359
+ actions.clearMark(board);
360
+ }
361
+
362
+ /**
363
+ * One scale for the frames: small enough that they fit side by side under the label and above Back to canvas.
364
+ * Each frame is as wide as its scaled iframe, so a label longer than that ends in an ellipsis (canvas.css) and
365
+ * keeps its full text in a title; the room leaves half a pixel per frame for rounding the sizes.
366
+ */
367
+ function placeSizeFrames(board, box) {
368
+ const view = board.sizesView;
369
+ const frames = board.sizeFrames;
370
+ view.style.left = `${box.side}px`;
371
+ view.style.right = `${box.side}px`;
372
+ view.style.top = `${box.top}px`;
373
+ view.style.bottom = `${box.bottom}px`;
374
+ const availableWidth = box.width - box.side * 2 - SIZES_GAP * (frames.length - 1) - frames.length / 2;
375
+ const availableHeight = box.height - box.top - box.bottom - SIZES_HEAD - 0.5;
376
+ const totalWidth = frames.reduce((sum, surface) => sum + surface.width, 0);
377
+ const tallest = Math.max(...frames.map((surface) => surface.height));
378
+ const scale = Math.max(MIN_SIZES_SCALE, Math.min(1, availableWidth / totalWidth, availableHeight / tallest));
379
+ for (const surface of frames) {
380
+ const width = `${Math.round(surface.width * scale)}px`;
381
+ surface.root.style.width = width;
382
+ surface.scaled.style.width = width;
383
+ surface.scaled.style.height = `${Math.round(surface.height * scale)}px`;
384
+ surface.stage.style.transform = `scale(${scale})`;
385
+ // Pins keep their size at any scale, as in the world.
386
+ surface.stage.style.setProperty("--gd-inv-zoom", String(1 / scale));
387
+ surface.scale = scale;
388
+ }
389
+ labelSizesView(board);
390
+ }
391
+
392
+ /**
393
+ * A frame (the board's own or a size frame) finished loading: it knows nothing yet, so tell it the state.
394
+ * Its page may have reported overflow before this load event (a resource that loaded first) and, keeping
395
+ * unchanged answers to itself, would not report it again: gd:size, sent after the chip is cleared, asks for a
396
+ * fresh report, so the chip follows the page that now shows, after a reload or a navigation to another page.
397
+ */
398
+ function surfaceLoaded(surface) {
399
+ // First, so the frame's last messages stay the state below: a ring on this artboard goes, its own frame checks itself.
400
+ actions.checksLoaded(surface);
401
+ surface.rects = null;
402
+ setOverflow(surface, null);
403
+ sendSize(surface);
404
+ actions.sendMode(surface);
405
+ actions.sendFocus(surface);
406
+ if (!ownerOf(surface).system) actions.sendPins(surface);
407
+ }
408
+
409
+ /** Tells the frame's page its size generation; it tags its picks with it and reports its overflow afresh. */
410
+ function sendSize(surface) {
411
+ surface.frame.contentWindow?.postMessage({ type: "gd:size", generation: surface.generation }, "*");
412
+ }
413
+
414
+ /** The frame changed size: a pick its page made before it hears so belongs to the old size. */
415
+ function resized(surface) {
416
+ surface.generation += 1;
417
+ sendSize(surface);
418
+ }
419
+
420
+ // ---- the Overflows chip
421
+
422
+ /** The "Overflows" chip of one frame, hidden until its page reports content wider than the frame (renderOverflow). */
423
+ function overflowFlag() {
424
+ const flag = doc.createElement("span");
425
+ flag.className = "gd-overflow-flag";
426
+ flag.hidden = true;
427
+ flag.append(chip("gd-overflow-text", ""), chip("gd-visually-hidden", ""));
428
+ labelOverflow(flag);
429
+ return flag;
430
+ }
431
+
432
+ /** The chip's own word, in the current language; its note follows the report (renderOverflow). */
433
+ function labelOverflow(flag) {
434
+ flag.children[0].textContent = T.overflow;
435
+ }
436
+
437
+ /**
438
+ * What a frame's page last reported: `{ scrollWidth }` while its content is wider than the frame, null when it
439
+ * fits or has not reported for this width. The one way any module changes surface.overflow; the chip follows.
440
+ */
441
+ function setOverflow(surface, overflow) {
442
+ surface.overflow = overflow;
443
+ renderOverflow(surface);
444
+ }
445
+
446
+ /**
447
+ * Shown while the page last reported content wider than this frame (setOverflow).
448
+ * The artboard's own frame shows it only at a single focused size; in All sizes each size frame has its own.
449
+ */
450
+ function renderOverflow(surface) {
451
+ const board = ownerOf(surface);
452
+ const shown = Boolean(surface.overflow) && (surface !== board || (state.focus === board && state.size.kind !== "all"));
453
+ surface.flag.hidden = !shown;
454
+ if (!shown) return;
455
+ const note = T.overflowNote(surface.viewWidth);
456
+ surface.flag.title = note;
457
+ surface.flag.children[1].textContent = note;
458
+ }
459
+
460
+ // ---- the size a comment was made at
461
+
462
+ /**
463
+ * The size a pick was made at, for the comment: the focused Phone, Tablet or custom width, or the picked size
464
+ * frame of All sizes. Null at the artboard's own size (nothing to record), at Desktop (L12: it fills the window,
465
+ * so its width is the window's, not a size of the design) and when comments.json would refuse it.
466
+ */
467
+ function viewportOf(surface) {
468
+ const board = ownerOf(surface);
469
+ let size;
470
+ if (surface !== board) size = { width: surface.width, height: surface.height };
471
+ else if (state.focus === board && state.size.kind !== "all" && state.size.kind !== "desktop") size = focusSize(board);
472
+ else return null;
473
+ if (size.width === board.artboard.width && size.height === board.artboard.height) return null;
474
+ const { minWidth, maxWidth, minHeight, maxHeight } = VIEWPORT_LIMITS;
475
+ const fits = size.width >= minWidth && size.width <= maxWidth && size.height >= minHeight && size.height <= maxHeight;
476
+ return fits && Number.isInteger(size.width) && Number.isInteger(size.height) ? { width: size.width, height: size.height } : null;
477
+ }
478
+
479
+ /** `Phone 390 × 844`, `Tablet 820 × 1180` or `<w> × <h>`: the preset's name only for its exact size. */
480
+ function describeViewport(viewport) {
481
+ const preset = SIZE_PRESETS.find((candidate) => candidate.width === viewport.width && candidate.height === viewport.height);
482
+ return preset ? `${nameOf(preset.kind)} ${dims(viewport)}` : dims(viewport);
483
+ }
484
+
485
+ /** The comment card's chip naming the size the comment was made at, or null for one made at the artboard's own size. */
486
+ function viewportChip(viewport) {
487
+ if (!viewport || typeof viewport !== "object" || !Number.isInteger(viewport.width) || !Number.isInteger(viewport.height)) return null;
488
+ const label = describeViewport(viewport);
489
+ const element = chip("gd-comment-viewport", label);
490
+ element.title = T.madeAt(label);
491
+ return element;
492
+ }
493
+
494
+ /** The device button opens its menu like Settings (click, arrows, Esc); boot() runs it once every module is ready. */
495
+ function startSizes() {
496
+ renderDevice();
497
+ actions.wireMenu(els.device, openDeviceMenu);
498
+ }
499
+
500
+ els.deviceMenu.addEventListener("keydown", (event) => {
501
+ if (!deviceMenuOpen() || !custom) return;
502
+ // In the width field typing, Home, End, Space and Enter stay with it (applyCustomWidth).
503
+ if (event.target === custom.input && !["ArrowDown", "ArrowUp", "Escape", "Tab"].includes(event.key)) return;
504
+ actions.menuKeydown(event, state.menu.items, actions.closeMenu, chooseDeviceItem);
505
+ });
506
+
507
+ /**
508
+ * A new language: the device button, and every frame's text built once, in place (no frame reloads): All sizes' labels
509
+ * and each Overflows chip with its note. The device menu is built when it opens, so it opens in the language shown.
510
+ */
511
+ function relabel() {
512
+ renderDevice();
513
+ for (const board of actions.allBoards()) {
514
+ if (board.sizesView) labelSizesView(board);
515
+ for (const surface of surfacesOf(board)) {
516
+ if (surface !== board) labelSizeFrame(surface);
517
+ labelOverflow(surface.flag);
518
+ renderOverflow(surface);
519
+ }
520
+ }
521
+ }
522
+
523
+ return { relabel, focusSize, surfacesOf, ownerOf, renderDevice, closeDeviceMenu, startSizes, layoutSizes, removeSizeFrames, surfaceLoaded, resized, overflowFlag, setOverflow, renderOverflow, viewportOf, viewportChip };
524
+ }