@dexhq/canvas 0.17.0 → 0.18.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 (174) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/app/canvas/canvas-commands.ts +2 -10
  3. package/app/canvas/canvas-context.tsx +11 -2
  4. package/app/canvas/canvas-document.ts +5 -1
  5. package/app/canvas/canvas-keys.ts +1 -1
  6. package/app/canvas/canvas-model.ts +195 -20
  7. package/app/canvas/canvas-scene.ts +176 -171
  8. package/app/canvas/canvas-ui.ts +4 -11
  9. package/app/canvas/canvas.css +159 -179
  10. package/app/canvas/change-pictures.tsx +156 -0
  11. package/app/canvas/comment-drafts.ts +31 -0
  12. package/app/canvas/comment-layer.tsx +125 -71
  13. package/app/canvas/comments.tsx +38 -2
  14. package/app/canvas/element-picker.ts +20 -0
  15. package/app/canvas/engine/canvas-gestures.ts +15 -3
  16. package/app/canvas/engine/canvas-store.ts +5 -0
  17. package/app/canvas/engine/canvas-view.tsx +22 -5
  18. package/app/canvas/find-bar.tsx +57 -41
  19. package/app/canvas/flow-canvas.tsx +147 -272
  20. package/app/canvas/frame-copies.ts +14 -17
  21. package/app/canvas/frame-drops.ts +15 -7
  22. package/app/canvas/frame-inspector.ts +192 -41
  23. package/app/canvas/frame-node.tsx +123 -75
  24. package/app/canvas/frame-resize.tsx +321 -83
  25. package/app/canvas/insert-hint.tsx +5 -15
  26. package/app/canvas/inspect-layer.tsx +73 -19
  27. package/app/canvas/label-action.tsx +13 -2
  28. package/app/canvas/layout.ts +233 -98
  29. package/app/canvas/live-page.ts +5 -0
  30. package/app/canvas/new-frame.ts +10 -25
  31. package/app/canvas/note-placing.ts +55 -84
  32. package/app/canvas/picked-box.tsx +5 -0
  33. package/app/canvas/picks-menu.tsx +3 -9
  34. package/app/canvas/readable-colour.ts +52 -0
  35. package/app/canvas/request-node.tsx +19 -10
  36. package/app/canvas/scrolling-page.ts +45 -0
  37. package/app/canvas/section-node.tsx +36 -53
  38. package/app/canvas/settle.ts +21 -0
  39. package/app/canvas/snapping.ts +96 -8
  40. package/app/canvas/spec-frame.tsx +8 -5
  41. package/app/canvas/spot-pins.tsx +15 -3
  42. package/app/canvas/stack-frame.tsx +13 -57
  43. package/app/canvas/stack-model.ts +5 -0
  44. package/app/canvas/stack-toggle.tsx +89 -0
  45. package/app/canvas/styles-layer.tsx +23 -43
  46. package/app/canvas/text-layer.tsx +26 -10
  47. package/app/canvas/thread-focus.tsx +18 -1
  48. package/app/canvas/tool-cursors.ts +2 -2
  49. package/app/canvas/toolbar-parts.tsx +48 -8
  50. package/app/canvas/toolbar.tsx +12 -10
  51. package/app/canvas/use-canvas-clipboard.tsx +13 -5
  52. package/app/canvas/use-reveal.ts +86 -0
  53. package/app/editor/extensions.ts +2 -0
  54. package/app/editor/line-break-caret.ts +57 -0
  55. package/app/git/branch-panel.tsx +61 -20
  56. package/app/i18n/locales/en/messages.po +64 -17
  57. package/app/i18n/locales/en/messages.ts +1 -1
  58. package/app/i18n/locales/pseudo/messages.po +64 -17
  59. package/app/i18n/locales/pseudo/messages.ts +1 -1
  60. package/app/icons/glyphs.tsx +2 -0
  61. package/app/live/studio-live.ts +29 -9
  62. package/app/pages/canvas.tsx +1 -1
  63. package/app/pages/commands-settings.tsx +70 -76
  64. package/app/pages/play-bar.tsx +6 -11
  65. package/app/pages/play.tsx +52 -33
  66. package/app/shell/feedback-form.tsx +29 -5
  67. package/app/ui/prompt-editor.tsx +2 -0
  68. package/app/ui/use-field-list.ts +90 -0
  69. package/dist/cli/commands/mcp.mjs +6 -4
  70. package/dist/cli/mcp-relay.mjs +10 -6
  71. package/dist/content/content.d.mts +26 -9
  72. package/dist/content/content.mjs +65 -8
  73. package/dist/content/screenshot.d.mts +2 -0
  74. package/dist/content/screenshot.mjs +3 -0
  75. package/dist/content/snapshot-client.d.mts +2 -0
  76. package/dist/content/snapshot-client.mjs +12 -1
  77. package/dist/inspector.js +96 -19
  78. package/dist/paste/paste.d.mts +5 -0
  79. package/dist/paste/paste.mjs +7 -2
  80. package/dist/server/agent-tools.d.mts +1 -0
  81. package/dist/server/agent-tools.mjs +4 -3
  82. package/dist/server/change-picture-store.d.mts +13 -0
  83. package/dist/server/change-picture-store.mjs +42 -0
  84. package/dist/server/change-pictures.d.mts +25 -0
  85. package/dist/server/change-pictures.mjs +104 -0
  86. package/dist/server/close-check.d.mts +11 -0
  87. package/dist/server/close-check.mjs +37 -5
  88. package/dist/server/comments/agent-actions.d.mts +8 -4
  89. package/dist/server/comments/agent-actions.mjs +16 -7
  90. package/dist/server/comments/close-tools.mjs +7 -5
  91. package/dist/server/comments/files.d.mts +5 -1
  92. package/dist/server/comments/hand-out.d.mts +1 -1
  93. package/dist/server/comments/hand-out.mjs +4 -1
  94. package/dist/server/comments/push.d.mts +19 -10
  95. package/dist/server/comments/push.mjs +45 -30
  96. package/dist/server/comments/studio-files.d.mts +14 -1
  97. package/dist/server/comments/studio-files.mjs +44 -31
  98. package/dist/server/comments/tools.d.mts +1 -1
  99. package/dist/server/comments/workspace.mjs +1 -0
  100. package/dist/server/dev-server.mjs +34 -0
  101. package/dist/server/own-copies.mjs +4 -23
  102. package/dist/server/requests.mjs +57 -3
  103. package/dist/server/response-budget.d.mts +2 -1
  104. package/dist/server/response-budget.mjs +4 -3
  105. package/dist/server/roster.d.mts +19 -8
  106. package/dist/server/roster.mjs +50 -22
  107. package/dist/server/studio-for.d.mts +7 -0
  108. package/dist/server/studio-for.mjs +23 -7
  109. package/dist/server/thread-forms.d.mts +3 -0
  110. package/dist/server/thread-forms.mjs +21 -1
  111. package/dist/server/tools/place-frame.d.mts +1 -0
  112. package/dist/server/tools/place-frame.mjs +33 -9
  113. package/dist/server/tools/result.mjs +2 -2
  114. package/dist/server/tools/snapshot.d.mts +1 -1
  115. package/dist/server/tools/snapshot.mjs +2 -1
  116. package/dist/server/tools/studio-context.d.mts +2 -1
  117. package/dist/server/tools/studio-context.mjs +2 -1
  118. package/dist/server/tools/watch.mjs +29 -12
  119. package/dist/server/work-groups.mjs +1 -1
  120. package/dist/shared/canvas-core.d.mts +39 -5
  121. package/dist/shared/canvas-core.mjs +60 -15
  122. package/dist/shared/canvas-file.d.mts +7 -4
  123. package/dist/shared/change-pictures-core.d.mts +6 -0
  124. package/dist/shared/change-pictures-core.mjs +5 -0
  125. package/dist/shared/page-looks.d.mts +12 -0
  126. package/dist/shared/page-looks.mjs +49 -0
  127. package/dist/shared/snapshot-clipboard.d.mts +6 -0
  128. package/dist/shared/studio-routes.d.mts +11 -0
  129. package/extension/dist/manifest.json +1 -1
  130. package/extension/dist/picker.js +114 -108
  131. package/package.json +4 -3
  132. package/src/cli/commands/mcp.ts +18 -8
  133. package/src/cli/mcp-relay.ts +13 -6
  134. package/src/content/content.ts +90 -16
  135. package/src/content/screenshot.ts +9 -1
  136. package/src/content/snapshot-client.ts +17 -0
  137. package/src/paste/paste.ts +18 -1
  138. package/src/server/agent-tools.ts +5 -4
  139. package/src/server/change-picture-store.ts +71 -0
  140. package/src/server/change-pictures.ts +244 -0
  141. package/src/server/close-check.ts +69 -6
  142. package/src/server/comments/agent-actions.ts +51 -12
  143. package/src/server/comments/close-tools.ts +20 -10
  144. package/src/server/comments/files.ts +10 -2
  145. package/src/server/comments/hand-out.ts +2 -2
  146. package/src/server/comments/push.ts +94 -46
  147. package/src/server/comments/studio-files.ts +77 -46
  148. package/src/server/comments/workspace.ts +1 -0
  149. package/src/server/dev-server.ts +70 -0
  150. package/src/server/own-copies.ts +5 -33
  151. package/src/server/requests.ts +84 -4
  152. package/src/server/response-budget.ts +5 -3
  153. package/src/server/roster.ts +78 -28
  154. package/src/server/studio-for.ts +32 -7
  155. package/src/server/thread-forms.ts +41 -1
  156. package/src/server/tools/place-frame.ts +71 -14
  157. package/src/server/tools/result.ts +2 -2
  158. package/src/server/tools/snapshot.ts +2 -1
  159. package/src/server/tools/studio-context.ts +24 -14
  160. package/src/server/tools/watch.ts +38 -13
  161. package/src/server/work-groups.ts +1 -1
  162. package/src/shared/canvas-core.ts +119 -27
  163. package/src/shared/canvas-file.ts +7 -4
  164. package/src/shared/change-pictures-core.ts +8 -0
  165. package/src/shared/page-looks.ts +133 -0
  166. package/src/shared/snapshot-clipboard.ts +6 -0
  167. package/src/shared/studio-routes.ts +7 -1
  168. package/templates/agents/dex-worker.md +9 -7
  169. package/templates/feedback-workflow.md +1 -1
  170. package/templates/methods/review.md +7 -6
  171. package/templates/rules/canvas-frames.md +8 -7
  172. package/templates/rules/canvas.md +10 -8
  173. package/templates/rules/prototypes.md +5 -3
  174. package/app/canvas/stack-node.tsx +0 -100
@@ -0,0 +1,90 @@
1
+ import {
2
+ type KeyboardEvent,
3
+ type MouseEvent,
4
+ useEffect,
5
+ useId,
6
+ useRef,
7
+ } from "react";
8
+
9
+ const ARROW_STEPS = new Map<string, 1 | -1>([
10
+ ["ArrowDown", 1],
11
+ ["ArrowUp", -1],
12
+ ]);
13
+
14
+ const isPlainKey = (event: KeyboardEvent<HTMLElement>) =>
15
+ !(
16
+ event.altKey ||
17
+ event.ctrlKey ||
18
+ event.metaKey ||
19
+ event.shiftKey ||
20
+ event.nativeEvent.isComposing
21
+ );
22
+
23
+ const keepFocusInField = (event: MouseEvent) => event.preventDefault();
24
+
25
+ const useListScrolledToActive = (activeId: string | undefined) => {
26
+ const listbox = useRef<HTMLDivElement>(null);
27
+
28
+ useEffect(() => {
29
+ if (activeId) {
30
+ listbox.current
31
+ ?.querySelector('[role="option"][aria-selected="true"]')
32
+ ?.scrollIntoView({ block: "nearest" });
33
+ }
34
+ }, [activeId]);
35
+
36
+ return listbox;
37
+ };
38
+
39
+ export const useFieldList = ({
40
+ active,
41
+ expanded,
42
+ onMove,
43
+ onPick,
44
+ }: {
45
+ active: number | undefined;
46
+ expanded: boolean;
47
+ onMove: (by: 1 | -1) => void;
48
+ onPick: (index: number) => void;
49
+ }) => {
50
+ const id = useId();
51
+ const optionId = (index: number) => `${id}-${index}`;
52
+
53
+ const activeId =
54
+ expanded && active !== undefined ? optionId(active) : undefined;
55
+
56
+ const listbox = useListScrolledToActive(activeId);
57
+
58
+ return {
59
+ field: {
60
+ "aria-activedescendant": activeId,
61
+ "aria-autocomplete": "list" as const,
62
+ "aria-controls": expanded ? id : undefined,
63
+ "aria-expanded": expanded,
64
+ role: "combobox",
65
+ },
66
+ group: (label: string) => ({ "aria-label": label, role: "group" }),
67
+ listbox: { id, ref: listbox, role: "listbox" },
68
+ moves: (event: KeyboardEvent<HTMLElement>) => {
69
+ const by = ARROW_STEPS.get(event.key);
70
+
71
+ if (by === undefined || !isPlainKey(event) || !expanded) {
72
+ return false;
73
+ }
74
+
75
+ event.preventDefault();
76
+ onMove(by);
77
+
78
+ return true;
79
+ },
80
+ option: (index: number) => ({
81
+ "aria-selected": index === active,
82
+ id: optionId(index),
83
+ onClick: () => onPick(index),
84
+ onMouseDown: keepFocusInField,
85
+ role: "option",
86
+ }),
87
+ };
88
+ };
89
+
90
+ export type FieldList = ReturnType<typeof useFieldList>;
@@ -37,16 +37,18 @@ var mcp_default = defineCommand({
37
37
  console.info = console.error;
38
38
  console.debug = console.error;
39
39
  const root = await contentRoot(args.root);
40
- const [{ serveMcp }, { canvasTools }, { commentsToPush }] = await Promise.all([
40
+ const [{ serveMcp }, { canvasTools, studioOf }, { commentsToPush }, { pictureBefore }] = await Promise.all([
41
41
  import("../../server/studio-server.mjs"),
42
42
  import("../../server/agent-tools.mjs"),
43
- import("../../server/comments/push.mjs")
43
+ import("../../server/comments/push.mjs"),
44
+ import("../../server/change-pictures.mjs")
44
45
  ]);
46
+ const findStudio = studioOf(root);
45
47
  await serveMcp(root, {
46
48
  agent: args.agent,
47
- push: commentsToPush,
49
+ push: (content, threads, agentSession) => commentsToPush(content, threads, agentSession, { pictureBefore: (found) => pictureBefore(content, found, findStudio) }),
48
50
  session,
49
- tools: canvasTools()
51
+ tools: canvasTools({ findStudio })
50
52
  });
51
53
  }
52
54
  });
@@ -48,8 +48,13 @@ const parse = (line) => {
48
48
  function openRelay({ checkMs = CHECK_MS, handoverMs = HANDOVER_MS, onMove, ready, retryMs = RETRY_MS, running: first, start, startMs = START_MS, toClient }) {
49
49
  /** The Dex the server in use is from. */
50
50
  let running = first;
51
- /** The Dex to move to. */
52
- let wanted;
51
+ /** The Dex ready to move to, as the last look found it. */
52
+ let lastReady;
53
+ /**
54
+ * The Dex to move to: the one ready, unless it is the one running. Asked
55
+ * each time, never kept: a move changes which Dex runs.
56
+ */
57
+ const wanted = () => lastReady !== void 0 && lastReady !== running ? lastReady : void 0;
53
58
  let retryAt = 0;
54
59
  let moving = false;
55
60
  /** The agent left: the server in use ends once any move has. */
@@ -186,7 +191,7 @@ function openRelay({ checkMs = CHECK_MS, handoverMs = HANDOVER_MS, onMove, ready
186
191
  };
187
192
  /** Move now, when another Dex waits and nothing is open either way. */
188
193
  function moveWhenQuiet() {
189
- const to = wanted;
194
+ const to = wanted();
190
195
  const quiet = open.size === 0 && owed.size === 0;
191
196
  if (to === void 0 || !hello || Date.now() < retryAt) return;
192
197
  if (moving || left || !quiet) return;
@@ -207,9 +212,8 @@ function openRelay({ checkMs = CHECK_MS, handoverMs = HANDOVER_MS, onMove, ready
207
212
  * (mcp-handover.ts), also one that began since the last look.
208
213
  */
209
214
  const check = () => {
210
- const now = ready();
211
- wanted = now !== void 0 && now !== running ? now : void 0;
212
- if (wanted !== void 0 && !moving && Date.now() >= retryAt && open.size > 0) current.send(lineOf({ method: UPDATE_READY }));
215
+ lastReady = ready();
216
+ if (wanted() !== void 0 && !moving && Date.now() >= retryAt && open.size > 0) current.send(lineOf({ method: UPDATE_READY }));
213
217
  moveWhenQuiet();
214
218
  };
215
219
  const checking = setInterval(check, checkMs);
@@ -1,4 +1,4 @@
1
- import { Cell, PageSize, Viewport } from "../shared/canvas-core.mjs";
1
+ import { AskedCell, Cell, PageSize, Viewport } from "../shared/canvas-core.mjs";
2
2
  import { ClosedStatus, PlacedElement, ThreadAudience, ThreadPoint, ThreadStatus } from "../shared/threads-core.mjs";
3
3
  import { ResolvedDesignSystem } from "../config/design-system.mjs";
4
4
  import { Canvas, ViewFrame } from "../shared/canvas-file.mjs";
@@ -153,9 +153,9 @@ interface CanvasSave {
153
153
  */
154
154
  export declare function writeCanvas(save: CanvasSave, root: string): Promise<SavedCanvas>;
155
155
  /** A canvas and a cell on it. */
156
- export interface CanvasCell {
156
+ export interface CanvasCell<C extends Omit<Cell, "step"> = Cell> {
157
157
  canvas: Canvas;
158
- cell: Cell;
158
+ cell: C;
159
159
  }
160
160
  /**
161
161
  * A cell the person may add to: theirs, or, in someone else's row, the same
@@ -163,17 +163,34 @@ export interface CanvasCell {
163
163
  * `newRow`). A new row in someone else's section goes where the cell asks
164
164
  * (rowBefore): in the person's own row there, or one right below theirs.
165
165
  */
166
- export declare function ownCell(canvas: Canvas, cell: Cell, person: string, { newRow }?: {
166
+ export declare function ownCell<C extends Omit<Cell, "step">>(canvas: Canvas, cell: C, person: string, { newRow }?: {
167
167
  newRow?: boolean;
168
- }): CanvasCell;
168
+ }): CanvasCell<C>;
169
+ /**
170
+ * The key a frame is at now, found by its uid first, then its key
171
+ * (targetFrameKey); none when no one frame has it.
172
+ */
173
+ export declare const frameKeyOn: (canvas: Canvas, target: {
174
+ frame: string;
175
+ uid?: string;
176
+ }) => string | undefined;
177
+ /** The cell a frame is in now (frameKeyOn); none when it is gone. */
178
+ export declare function cellOfFrame(canvas: Canvas, target: {
179
+ frame: string;
180
+ uid?: string;
181
+ }): Cell | undefined;
169
182
  /**
170
183
  * Put a frame for a view in a cell of a prototype's canvas (placeViewInCell),
171
184
  * reading and writing canvas.json in one turn, so agents placing frames at
172
- * once never lose each other's. A frame for the view already in the cell is
173
- * kept. Returns its key, its uid and whether it was added, or { problems }.
185
+ * once never lose each other's, and a frame asked for right of another
186
+ * (`rightOf`) or with no step (stepAsked) is placed by the canvas as it is
187
+ * then. A frame for the view already in the cell is kept. Returns its key,
188
+ * its uid and whether it was added, or { problems }.
174
189
  */
175
- export declare function placeViewFrame({ slug, cell, view, viewport, size, person, newRow, stack }: {
176
- cell: Cell;
190
+ export declare function placeViewFrame({ slug, cell: asked, view, viewport, size, person, newRow, stack }: {
191
+ cell: AskedCell | {
192
+ rightOf: string;
193
+ };
177
194
  /**
178
195
  * In someone else's row, put it in a new row of the person's right
179
196
  * below it, not the one they have there.
@@ -2,8 +2,8 @@ import { dexRunner, packageManager } from "../harness/src/connect/package-manage
2
2
  import { NOT_RECOGNISED, youOf } from "../shared/studio-routes.mjs";
3
3
  import { isOneOf, isRecord, isText } from "../shared/checks.mjs";
4
4
  import { PROTOTYPES_FOLDER, framePage, isSlug, newFileId, placeOf, prototypeFiles, prototypePage, slugify } from "../shared/prototypes-core.mjs";
5
- import { appendOwnFrame, canvasFormProblems, canvasFrames, canvasProblems, placeViewInCell, stackPiles, uniqueId, viewOf } from "../shared/canvas-core.mjs";
6
- import { agentChange, describeThread } from "../shared/threads-core.mjs";
5
+ import { appendOwnFrame, canvasFormProblems, canvasFrames, canvasProblems, parseFrameKey, placeViewInCell, stackPiles, stepAsked, uniqueId, viewOf, whereInRow } from "../shared/canvas-core.mjs";
6
+ import { agentChange, describeThread, targetFrameKey } from "../shared/threads-core.mjs";
7
7
  import { targetForPath } from "../shared/live-presence.mjs";
8
8
  import { prepareState, studioState } from "../server/state.mjs";
9
9
  import { openPresence } from "../server/presence.mjs";
@@ -325,17 +325,74 @@ function ownCell(canvas, cell, person, { newRow = false } = {}) {
325
325
  };
326
326
  }
327
327
  /**
328
+ * The key a frame is at now, found by its uid first, then its key
329
+ * (targetFrameKey); none when no one frame has it.
330
+ */
331
+ const frameKeyOn = (canvas, target) => targetFrameKey(target, canvasFrames(canvas).map(({ key, frame }) => ({
332
+ key,
333
+ uid: frame.uid
334
+ })));
335
+ /** The cell a frame is in now (frameKeyOn); none when it is gone. */
336
+ function cellOfFrame(canvas, target) {
337
+ const key = frameKeyOn(canvas, target);
338
+ const where = key === void 0 ? void 0 : whereInRow(canvas, key);
339
+ if (!(key && where)) return;
340
+ const { section, row } = parseFrameKey(key);
341
+ return {
342
+ section,
343
+ row,
344
+ step: where.step
345
+ };
346
+ }
347
+ /**
348
+ * The cell asked for, before the person's own row is found: right of the
349
+ * frame `rightOf` names (its uid or key), where it is now; or, with no row,
350
+ * step or `above`, at the end of the section's first row, its main path.
351
+ */
352
+ function cellWanted(canvas, asked) {
353
+ if ("rightOf" in asked) {
354
+ const { rightOf } = asked;
355
+ const frame = cellOfFrame(canvas, {
356
+ frame: rightOf,
357
+ uid: rightOf
358
+ });
359
+ if (!frame) return { problem: `No frame "${rightOf}" on the canvas, or more than one with that uid. Name it by its key ("section/row/frame") as canvas.json has it now.` };
360
+ return {
361
+ section: frame.section,
362
+ row: frame.row,
363
+ after: frame.step
364
+ };
365
+ }
366
+ const { above, row, step } = asked;
367
+ if (row !== void 0 || step !== void 0 || above !== void 0) return asked;
368
+ const main = canvas.sections.find((each) => each.id === asked.section)?.rows[0];
369
+ return main ? {
370
+ ...asked,
371
+ row: main.id
372
+ } : asked;
373
+ }
374
+ /**
328
375
  * Put a frame for a view in a cell of a prototype's canvas (placeViewInCell),
329
376
  * reading and writing canvas.json in one turn, so agents placing frames at
330
- * once never lose each other's. A frame for the view already in the cell is
331
- * kept. Returns its key, its uid and whether it was added, or { problems }.
377
+ * once never lose each other's, and a frame asked for right of another
378
+ * (`rightOf`) or with no step (stepAsked) is placed by the canvas as it is
379
+ * then. A frame for the view already in the cell is kept. Returns its key,
380
+ * its uid and whether it was added, or { problems }.
332
381
  */
333
- function placeViewFrame({ slug, cell, view, viewport, size, person, newRow, stack }, root) {
382
+ function placeViewFrame({ slug, cell: asked, view, viewport, size, person, newRow, stack }, root) {
334
383
  return queued(root, slug, async () => {
335
384
  const saver = person;
336
- const { canvas, cell: own } = ownCell(await readCanvas(slug, root), cell, saver, { newRow });
385
+ const read = await readCanvas(slug, root);
386
+ const wanted = cellWanted(read, asked);
387
+ if ("problem" in wanted) return { problems: [wanted.problem] };
388
+ const { canvas, cell: own } = ownCell(read, wanted, saver, { newRow });
389
+ const past = own.row === wanted.row ? void 0 : wanted.row;
390
+ const cell = {
391
+ ...own,
392
+ step: stepAsked(canvas, own, view, past)
393
+ };
337
394
  const { devices } = await loadDevices(root);
338
- const placed = placeViewInCell(canvas, own, {
395
+ const placed = placeViewInCell(canvas, cell, {
339
396
  view,
340
397
  viewport,
341
398
  size,
@@ -1401,4 +1458,4 @@ function createContentCommands({ content, port, designSystem, root: projectRoot
1401
1458
  };
1402
1459
  }
1403
1460
  //#endregion
1404
- export { STATUSES, addContributor, allowedPrefixes, canvasParts, changedFiles, check, checkStudio, contributorProblems, createContentCommands, createPrototype, createUntitledPrototype, currentPerson, deletePrototype, duplicatePrototype, framePageOf, git, githubAccountLogin, githubLogin, identify, identityFrom, joinCurrentPerson, knownFor, linkGithub, loadStudio, manifestProblems, outOfScope, ownCell, placeViewFrame, queued, readCanvas, readCanvasRevision, readPrototypePicks, removePick, savePick, scratchView, setPrototypeCover, setPrototypeStatus, setPrototypeTitle, snapshot, targetForFile, whoami, writeCanvas };
1461
+ export { STATUSES, addContributor, allowedPrefixes, canvasParts, cellOfFrame, changedFiles, check, checkStudio, contributorProblems, createContentCommands, createPrototype, createUntitledPrototype, currentPerson, deletePrototype, duplicatePrototype, frameKeyOn, framePageOf, git, githubAccountLogin, githubLogin, identify, identityFrom, joinCurrentPerson, knownFor, linkGithub, loadStudio, manifestProblems, outOfScope, ownCell, placeViewFrame, queued, readCanvas, readCanvasRevision, readPrototypePicks, removePick, savePick, scratchView, setPrototypeCover, setPrototypeStatus, setPrototypeTitle, snapshot, targetForFile, whoami, writeCanvas };
@@ -1,3 +1,4 @@
1
+ import { PageLooks } from "../shared/page-looks.mjs";
1
2
  import { Browser } from "playwright";
2
3
  //#region src/content/screenshot.d.ts
3
4
  /** A page's size in CSS pixels. */
@@ -41,6 +42,7 @@ export declare const shotViewport: ({ size, viewport }: Pick<ShotRequest, "size"
41
42
  /** A view's picture, and what looked wrong on its page. */
42
43
  export interface ViewShot {
43
44
  image: Buffer;
45
+ looks?: PageLooks;
44
46
  /**
45
47
  * What a picture hides: errors the page threw or logged, and a page wider
46
48
  * than its viewport.
@@ -2,6 +2,7 @@ import { viewInFrame } from "../shared/prototypes-core.mjs";
2
2
  import { VIEWPORTS } from "../shared/canvas-core.mjs";
3
3
  import { captureHeaders } from "./hosted-person.mjs";
4
4
  import { VIEW_RENDERED } from "../shared/page-messages.mjs";
5
+ import { LOOKS_SELECTORS, pageLooks } from "../shared/page-looks.mjs";
5
6
  import { XRAY_CSS } from "../shared/xray.mjs";
6
7
  import { existsSync } from "node:fs";
7
8
  //#region src/content/screenshot.ts
@@ -241,12 +242,14 @@ async function capture(site, { href, size, viewport, scheme, xray }, { scale, se
241
242
  await page.waitForTimeout(settle);
242
243
  const overflow = Number(await page.evaluate("document.documentElement.scrollWidth - window.innerWidth"));
243
244
  if (overflow > 0) problems.push(`overflows horizontally by ${overflow}px`);
245
+ const looks = await page.evaluate(pageLooks, LOOKS_SELECTORS);
244
246
  return {
245
247
  image: await page.screenshot({
246
248
  fullPage: true,
247
249
  type,
248
250
  ...type === "jpeg" && { quality: PICTURE_QUALITY }
249
251
  }),
252
+ looks,
250
253
  problems: [...new Set(problems)]
251
254
  };
252
255
  } finally {
@@ -1,3 +1,4 @@
1
+ import { PageLooks } from "../shared/page-looks.mjs";
1
2
  import { ViewShot } from "./screenshot.mjs";
2
3
  //#region src/content/snapshot-client.d.ts
3
4
  /** One view to snapshot: its frame page, and how to show it. */
@@ -12,6 +13,7 @@ export interface SnapshotRequest {
12
13
  /** What the studio answers with: the picture as base64, and its problems. */
13
14
  export interface SnapshotBody {
14
15
  image: string;
16
+ looks: PageLooks;
15
17
  problems: string[];
16
18
  }
17
19
  /** Why there is no snapshot: Dex is not running, or it said why not. */
@@ -1,3 +1,4 @@
1
+ import { isRecord } from "../shared/checks.mjs";
1
2
  //#region src/content/snapshot-client.ts
2
3
  /** Why there is no snapshot: Dex is not running, or it said why not. */
3
4
  var SnapshotError = class extends Error {
@@ -22,6 +23,14 @@ function unreachable(url, error) {
22
23
  return new SnapshotError(`Dex at ${url} could not be asked: ${cause?.message ?? error?.message ?? String(error)}`);
23
24
  }
24
25
  const strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
26
+ const looksIn = (value) => {
27
+ if (!isRecord(value) || typeof value.blank !== "boolean") return;
28
+ const { blank, error } = value;
29
+ return typeof error === "string" ? {
30
+ blank,
31
+ error
32
+ } : { blank };
33
+ };
25
34
  /** The studio's answer as JSON, or undefined when it is not. */
26
35
  const json = (text) => {
27
36
  try {
@@ -50,9 +59,11 @@ async function snapshotView(url, { href, scale = 1, scheme, viewport }) {
50
59
  const answer = json(text);
51
60
  if (!response.ok) throw new SnapshotError((strings(answer?.problems).join(" ") || text).slice(0, 400), response.status);
52
61
  if (typeof answer?.image !== "string") throw new SnapshotError(`Dex at ${url} answered without a picture: ${text.slice(0, 200)}`, response.status);
62
+ const looks = looksIn(answer.looks);
53
63
  return {
54
64
  image: Buffer.from(answer.image, "base64"),
55
- problems: strings(answer.problems)
65
+ problems: strings(answer.problems),
66
+ ...looks && { looks }
56
67
  };
57
68
  }
58
69
  //#endregion
package/dist/inspector.js CHANGED
@@ -149,22 +149,29 @@ function inside(element, skip, last) {
149
149
  if (reached) return reached;
150
150
  }
151
151
  }
152
+ const holds = (element, skip, wholePage) => element === element.ownerDocument.documentElement ? wholePage : !skip(element);
152
153
  /**
153
154
  * The element the inspector holds for one the pointer is over: it, or the
154
155
  * nearest element holding it that isn't passed over. None at the root.
155
156
  */
156
- const landOn = (element, skip) => {
157
- const root = element?.ownerDocument.documentElement;
158
- for (let at = element; at && at !== root; at = at.parentElement ?? void 0) if (!skip(at)) return at;
157
+ const landOn = (element, skip, wholePage = false) => {
158
+ for (let at = element; at; at = at.parentElement ?? void 0) if (holds(at, skip, wholePage)) return at;
159
159
  };
160
160
  /** The parent to step up to, noting `element` in `trail` to come back to. */
161
- const up = (element, trail, skip) => {
162
- const root = element.ownerDocument.documentElement;
163
- for (let parent = element.parentElement; parent && parent !== root; parent = parent.parentElement) if (!skip(parent)) {
161
+ const up = (element, trail, skip, wholePage) => {
162
+ for (let parent = element.parentElement; parent; parent = parent.parentElement) if (holds(parent, skip, wholePage)) {
164
163
  trail.push(element);
165
164
  return parent;
166
165
  }
167
166
  };
167
+ const top = (element, trail, skip, wholePage) => {
168
+ let at = element;
169
+ for (let next = up(at, [], skip, wholePage); next; next = up(at, [], skip, wholePage)) at = next;
170
+ if (at !== element) {
171
+ trail.push(element);
172
+ return at;
173
+ }
174
+ };
168
175
  /**
169
176
  * Back along `trail` while the way is still in `element`, else the first
170
177
  * element in it: a step across, or the page changing, leaves the way.
@@ -191,14 +198,45 @@ const across = (element, last, skip) => {
191
198
  }
192
199
  };
193
200
  /** Where a step from `element` goes; none when it goes nowhere. */
194
- const stepFrom = (element, step, trail, skip) => {
201
+ const stepFrom = (element, step, trail, skip, wholePage = false) => {
195
202
  switch (step) {
196
- case "up": return up(element, trail, skip);
203
+ case "up": return up(element, trail, skip, wholePage);
204
+ case "top": return top(element, trail, skip, wholePage);
197
205
  case "down": return down(element, trail, skip);
198
206
  default: return across(element, step === "previous", skip);
199
207
  }
200
208
  };
201
209
  //#endregion
210
+ //#region ../inspector/src/deep-select.ts
211
+ const isDeepSelect = ({ ctrlKey, metaKey }) => metaKey || ctrlKey;
212
+ const boxHolds = (element, x, y) => {
213
+ const { bottom, height, left, right, top, width } = element.getBoundingClientRect();
214
+ return width > 0 && height > 0 && x >= left && x <= right && y >= top && y <= bottom;
215
+ };
216
+ const elementsAtPoint = (page, x, y) => page.elementsFromPoint(x, y).filter((element) => boxHolds(element, x, y));
217
+ const areaOf = (element) => {
218
+ const { height, width } = element.getBoundingClientRect();
219
+ return width * height;
220
+ };
221
+ const depthOf = (element) => {
222
+ let depth = 0;
223
+ for (let at = element.parentElement; at; at = at.parentElement) depth += 1;
224
+ return depth;
225
+ };
226
+ const smallerThenDeeper = (a, b) => a.area - b.area || b.depth - a.depth;
227
+ const bestMatches = (topmostFirst, skip, wholePage) => {
228
+ const held = /* @__PURE__ */ new Set();
229
+ for (const element of topmostFirst) {
230
+ const landed = landOn(element, skip, wholePage);
231
+ if (landed && isSeen(landed)) held.add(landed);
232
+ }
233
+ return [...held].map((element) => ({
234
+ area: areaOf(element),
235
+ depth: depthOf(element),
236
+ element
237
+ })).toSorted(smallerThenDeeper).map(({ element }) => element);
238
+ };
239
+ //#endregion
202
240
  //#region ../inspector/src/inspector.ts
203
241
  const SKIP_NONE = () => false;
204
242
  /** The step each arrow key takes, in every tool. */
@@ -209,12 +247,28 @@ const STEP_KEYS = /* @__PURE__ */ new Map([
209
247
  ["ArrowUp", "up"]
210
248
  ]);
211
249
  /** The step a key takes: the arrows'; none for any other key. */
212
- const stepOf = (key) => STEP_KEYS.get(key);
213
- const inspector = ({ elementAt, skip = SKIP_NONE, start, onChange }) => {
250
+ const stepOf = ({ ctrlKey = false, key, metaKey = false }) => {
251
+ if (!(metaKey || ctrlKey)) return STEP_KEYS.get(key);
252
+ return key === "ArrowUp" ? "top" : void 0;
253
+ };
254
+ const sameElements = (a, b) => a.length === b.length && a.every((element, index) => element === b[index]);
255
+ const inspector = ({ elementAt, elementsAt, deep, wholePage = false, skip = SKIP_NONE, start, onChange }) => {
214
256
  let current;
215
257
  let chosen;
216
258
  let trail = [];
217
259
  let steered;
260
+ let lastDeepClick;
261
+ const asksDeep = (point) => deep?.(point) === true;
262
+ const plainAt = (point) => landOn(elementAt(point), skip, wholePage);
263
+ const bestMatchesAt = (point) => bestMatches(elementsAt?.(point) ?? [elementAt(point)].filter((element) => element !== void 0), skip, wholePage);
264
+ const tookAtSameSpot = (matches) => lastDeepClick && sameElements(matches, lastDeepClick.matches) ? lastDeepClick.took : void 0;
265
+ const outline = (under) => {
266
+ steered = void 0;
267
+ if (under === current) return;
268
+ current = under;
269
+ if (!chosen) trail = [];
270
+ onChange?.();
271
+ };
218
272
  /** The pointer is on what the keys stepped to, or stepped from. */
219
273
  const onSteered = (under) => steered !== void 0 && (under === steered.from || under !== void 0 && current?.contains(under) === true);
220
274
  return {
@@ -232,14 +286,37 @@ const inspector = ({ elementAt, skip = SKIP_NONE, start, onChange }) => {
232
286
  }
233
287
  return chosen;
234
288
  },
289
+ click: (point) => {
290
+ if (!asksDeep(point)) {
291
+ lastDeepClick = void 0;
292
+ const under = plainAt(point);
293
+ if (!onSteered(under)) outline(under);
294
+ return current;
295
+ }
296
+ const matches = bestMatchesAt(point);
297
+ const took = tookAtSameSpot(matches);
298
+ const next = took ? matches[(matches.indexOf(took) + 1) % matches.length] : matches[0];
299
+ lastDeepClick = next ? {
300
+ matches,
301
+ took: next
302
+ } : void 0;
303
+ outline(next);
304
+ return current;
305
+ },
235
306
  hover: (point) => {
236
- const under = point === void 0 ? void 0 : landOn(elementAt(point), skip);
237
- if (point !== void 0 && onSteered(under)) return;
238
- steered = void 0;
239
- if (under === current) return;
240
- current = under;
241
- if (!chosen) trail = [];
242
- onChange?.();
307
+ if (point === void 0) {
308
+ outline(void 0);
309
+ return;
310
+ }
311
+ let under;
312
+ if (asksDeep(point)) {
313
+ const matches = bestMatchesAt(point);
314
+ under = tookAtSameSpot(matches) ?? matches[0];
315
+ } else {
316
+ lastDeepClick = void 0;
317
+ under = plainAt(point);
318
+ }
319
+ if (!onSteered(under)) outline(under);
243
320
  },
244
321
  release: () => {
245
322
  const held = chosen !== void 0;
@@ -261,7 +338,7 @@ const inspector = ({ elementAt, skip = SKIP_NONE, start, onChange }) => {
261
338
  }
262
339
  return;
263
340
  }
264
- const to = stepFrom(from, step, trail, skip);
341
+ const to = stepFrom(from, step, trail, skip, wholePage);
265
342
  if (!to) return;
266
343
  if (chosen) chosen = to;
267
344
  else {
@@ -595,4 +672,4 @@ const readAnchor = (value) => {
595
672
  } : void 0;
596
673
  };
597
674
  //#endregion
598
- export { anchorOf, find, inspector, labelledWords, namingClasses, openersOf, readAnchor, stepOf, wordsOf };
675
+ export { anchorOf, elementsAtPoint, find, inspector, isDeepSelect, labelledWords, namingClasses, openersOf, readAnchor, stepOf, wordsOf };
@@ -6,6 +6,11 @@ export interface Pasted {
6
6
  from: PasteSource;
7
7
  /** Images left grey or as links: they could not be brought. */
8
8
  images: number;
9
+ /**
10
+ * Parts of an extension's snapshot its page's scripts sized: they keep
11
+ * that size, and won't reflow when the frame is resized.
12
+ */
13
+ sizedByScripts?: number;
9
14
  }
10
15
  /**
11
16
  * A paste that cannot be read: 400 when the clipboard holds no snapshot,
@@ -1,3 +1,4 @@
1
+ import { isRecord } from "../shared/checks.mjs";
1
2
  import { MAX_SIDE } from "../content/capture.mjs";
2
3
  import { isSnapshotClipboard, snapshotFrom } from "../shared/snapshot-clipboard.mjs";
3
4
  import { fontBringer } from "./fonts.mjs";
@@ -42,10 +43,14 @@ const fetchFigmaImage = async (url) => {
42
43
  };
43
44
  const extensionPaste = (html) => {
44
45
  try {
46
+ const snapshot = snapshotFrom(html);
47
+ const said = isRecord(snapshot) ? snapshot.sizedByScripts : void 0;
48
+ const sized = Number.isInteger(said) ? Number(said) : 0;
45
49
  return {
46
50
  from: "extension",
47
- captures: [snapshotFrom(html)],
48
- images: 0
51
+ captures: [snapshot],
52
+ images: 0,
53
+ ...sized > 0 && { sizedByScripts: sized }
49
54
  };
50
55
  } catch (error) {
51
56
  throw new PasteProblemError(422, `The snapshot could not be read: ${messageOf(error)}`);
@@ -12,6 +12,7 @@ export interface CanvasToolOptions {
12
12
  */
13
13
  findStudio?: () => Promise<StudioFor>;
14
14
  }
15
+ export declare const studioOf: (root: string) => () => Promise<StudioFor>;
15
16
  /** The canvas's tools, made for each session's server. */
16
17
  export declare const canvasTools: ({ feedbackRelay, findStudio }?: CanvasToolOptions) => ToolsFor;
17
18
  //#endregion
@@ -11,10 +11,11 @@ import { openToolContext } from "./tools/studio-context.mjs";
11
11
  import { threadsTool } from "./tools/thread-list.mjs";
12
12
  import { watchTool } from "./tools/watch.mjs";
13
13
  //#region src/server/agent-tools.ts
14
+ const studioOf = (root) => async () => studioFor(await loadProject(root));
14
15
  /** The canvas's tools, made for each session's server. */
15
16
  const canvasTools = ({ feedbackRelay, findStudio } = {}) => (setup) => {
16
- const context = openToolContext(setup);
17
- const studio = findStudio ?? (async () => studioFor(await loadProject(setup.root)));
17
+ const studio = findStudio ?? studioOf(setup.root);
18
+ const context = openToolContext(setup, studio);
18
19
  return [
19
20
  ...readingTools(context, setup.briefing),
20
21
  threadsTool(context),
@@ -28,4 +29,4 @@ const canvasTools = ({ feedbackRelay, findStudio } = {}) => (setup) => {
28
29
  ];
29
30
  };
30
31
  //#endregion
31
- export { canvasTools };
32
+ export { canvasTools, studioOf };
@@ -0,0 +1,13 @@
1
+ import { KeptPictures, Moment } from "../shared/change-pictures-core.mjs";
2
+ //#region src/server/change-picture-store.d.ts
3
+ export declare const MOST_PICTURE_BYTES = 200000000;
4
+ export interface ChangePictureStore {
5
+ drop: (id: string, moment: Moment) => void;
6
+ image: (id: string, moment: Moment) => Buffer | undefined;
7
+ keep: (id: string, moment: Moment, image: Buffer) => void;
8
+ kept: (id: string) => KeptPictures;
9
+ }
10
+ export declare function changePictureStore({ mostBytes }?: {
11
+ mostBytes?: number;
12
+ }): ChangePictureStore;
13
+ //#endregion