@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.
- package/CHANGELOG.md +31 -0
- package/app/canvas/canvas-commands.ts +2 -10
- package/app/canvas/canvas-context.tsx +11 -2
- package/app/canvas/canvas-document.ts +5 -1
- package/app/canvas/canvas-keys.ts +1 -1
- package/app/canvas/canvas-model.ts +195 -20
- package/app/canvas/canvas-scene.ts +176 -171
- package/app/canvas/canvas-ui.ts +4 -11
- package/app/canvas/canvas.css +159 -179
- package/app/canvas/change-pictures.tsx +156 -0
- package/app/canvas/comment-drafts.ts +31 -0
- package/app/canvas/comment-layer.tsx +125 -71
- package/app/canvas/comments.tsx +38 -2
- package/app/canvas/element-picker.ts +20 -0
- package/app/canvas/engine/canvas-gestures.ts +15 -3
- package/app/canvas/engine/canvas-store.ts +5 -0
- package/app/canvas/engine/canvas-view.tsx +22 -5
- package/app/canvas/find-bar.tsx +57 -41
- package/app/canvas/flow-canvas.tsx +147 -272
- package/app/canvas/frame-copies.ts +14 -17
- package/app/canvas/frame-drops.ts +15 -7
- package/app/canvas/frame-inspector.ts +192 -41
- package/app/canvas/frame-node.tsx +123 -75
- package/app/canvas/frame-resize.tsx +321 -83
- package/app/canvas/insert-hint.tsx +5 -15
- package/app/canvas/inspect-layer.tsx +73 -19
- package/app/canvas/label-action.tsx +13 -2
- package/app/canvas/layout.ts +233 -98
- package/app/canvas/live-page.ts +5 -0
- package/app/canvas/new-frame.ts +10 -25
- package/app/canvas/note-placing.ts +55 -84
- package/app/canvas/picked-box.tsx +5 -0
- package/app/canvas/picks-menu.tsx +3 -9
- package/app/canvas/readable-colour.ts +52 -0
- package/app/canvas/request-node.tsx +19 -10
- package/app/canvas/scrolling-page.ts +45 -0
- package/app/canvas/section-node.tsx +36 -53
- package/app/canvas/settle.ts +21 -0
- package/app/canvas/snapping.ts +96 -8
- package/app/canvas/spec-frame.tsx +8 -5
- package/app/canvas/spot-pins.tsx +15 -3
- package/app/canvas/stack-frame.tsx +13 -57
- package/app/canvas/stack-model.ts +5 -0
- package/app/canvas/stack-toggle.tsx +89 -0
- package/app/canvas/styles-layer.tsx +23 -43
- package/app/canvas/text-layer.tsx +26 -10
- package/app/canvas/thread-focus.tsx +18 -1
- package/app/canvas/tool-cursors.ts +2 -2
- package/app/canvas/toolbar-parts.tsx +48 -8
- package/app/canvas/toolbar.tsx +12 -10
- package/app/canvas/use-canvas-clipboard.tsx +13 -5
- package/app/canvas/use-reveal.ts +86 -0
- package/app/editor/extensions.ts +2 -0
- package/app/editor/line-break-caret.ts +57 -0
- package/app/git/branch-panel.tsx +61 -20
- package/app/i18n/locales/en/messages.po +64 -17
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +64 -17
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/glyphs.tsx +2 -0
- package/app/live/studio-live.ts +29 -9
- package/app/pages/canvas.tsx +1 -1
- package/app/pages/commands-settings.tsx +70 -76
- package/app/pages/play-bar.tsx +6 -11
- package/app/pages/play.tsx +52 -33
- package/app/shell/feedback-form.tsx +29 -5
- package/app/ui/prompt-editor.tsx +2 -0
- package/app/ui/use-field-list.ts +90 -0
- package/dist/cli/commands/mcp.mjs +6 -4
- package/dist/cli/mcp-relay.mjs +10 -6
- package/dist/content/content.d.mts +26 -9
- package/dist/content/content.mjs +65 -8
- package/dist/content/screenshot.d.mts +2 -0
- package/dist/content/screenshot.mjs +3 -0
- package/dist/content/snapshot-client.d.mts +2 -0
- package/dist/content/snapshot-client.mjs +12 -1
- package/dist/inspector.js +96 -19
- package/dist/paste/paste.d.mts +5 -0
- package/dist/paste/paste.mjs +7 -2
- package/dist/server/agent-tools.d.mts +1 -0
- package/dist/server/agent-tools.mjs +4 -3
- package/dist/server/change-picture-store.d.mts +13 -0
- package/dist/server/change-picture-store.mjs +42 -0
- package/dist/server/change-pictures.d.mts +25 -0
- package/dist/server/change-pictures.mjs +104 -0
- package/dist/server/close-check.d.mts +11 -0
- package/dist/server/close-check.mjs +37 -5
- package/dist/server/comments/agent-actions.d.mts +8 -4
- package/dist/server/comments/agent-actions.mjs +16 -7
- package/dist/server/comments/close-tools.mjs +7 -5
- package/dist/server/comments/files.d.mts +5 -1
- package/dist/server/comments/hand-out.d.mts +1 -1
- package/dist/server/comments/hand-out.mjs +4 -1
- package/dist/server/comments/push.d.mts +19 -10
- package/dist/server/comments/push.mjs +45 -30
- package/dist/server/comments/studio-files.d.mts +14 -1
- package/dist/server/comments/studio-files.mjs +44 -31
- package/dist/server/comments/tools.d.mts +1 -1
- package/dist/server/comments/workspace.mjs +1 -0
- package/dist/server/dev-server.mjs +34 -0
- package/dist/server/own-copies.mjs +4 -23
- package/dist/server/requests.mjs +57 -3
- package/dist/server/response-budget.d.mts +2 -1
- package/dist/server/response-budget.mjs +4 -3
- package/dist/server/roster.d.mts +19 -8
- package/dist/server/roster.mjs +50 -22
- package/dist/server/studio-for.d.mts +7 -0
- package/dist/server/studio-for.mjs +23 -7
- package/dist/server/thread-forms.d.mts +3 -0
- package/dist/server/thread-forms.mjs +21 -1
- package/dist/server/tools/place-frame.d.mts +1 -0
- package/dist/server/tools/place-frame.mjs +33 -9
- package/dist/server/tools/result.mjs +2 -2
- package/dist/server/tools/snapshot.d.mts +1 -1
- package/dist/server/tools/snapshot.mjs +2 -1
- package/dist/server/tools/studio-context.d.mts +2 -1
- package/dist/server/tools/studio-context.mjs +2 -1
- package/dist/server/tools/watch.mjs +29 -12
- package/dist/server/work-groups.mjs +1 -1
- package/dist/shared/canvas-core.d.mts +39 -5
- package/dist/shared/canvas-core.mjs +60 -15
- package/dist/shared/canvas-file.d.mts +7 -4
- package/dist/shared/change-pictures-core.d.mts +6 -0
- package/dist/shared/change-pictures-core.mjs +5 -0
- package/dist/shared/page-looks.d.mts +12 -0
- package/dist/shared/page-looks.mjs +49 -0
- package/dist/shared/snapshot-clipboard.d.mts +6 -0
- package/dist/shared/studio-routes.d.mts +11 -0
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +114 -108
- package/package.json +4 -3
- package/src/cli/commands/mcp.ts +18 -8
- package/src/cli/mcp-relay.ts +13 -6
- package/src/content/content.ts +90 -16
- package/src/content/screenshot.ts +9 -1
- package/src/content/snapshot-client.ts +17 -0
- package/src/paste/paste.ts +18 -1
- package/src/server/agent-tools.ts +5 -4
- package/src/server/change-picture-store.ts +71 -0
- package/src/server/change-pictures.ts +244 -0
- package/src/server/close-check.ts +69 -6
- package/src/server/comments/agent-actions.ts +51 -12
- package/src/server/comments/close-tools.ts +20 -10
- package/src/server/comments/files.ts +10 -2
- package/src/server/comments/hand-out.ts +2 -2
- package/src/server/comments/push.ts +94 -46
- package/src/server/comments/studio-files.ts +77 -46
- package/src/server/comments/workspace.ts +1 -0
- package/src/server/dev-server.ts +70 -0
- package/src/server/own-copies.ts +5 -33
- package/src/server/requests.ts +84 -4
- package/src/server/response-budget.ts +5 -3
- package/src/server/roster.ts +78 -28
- package/src/server/studio-for.ts +32 -7
- package/src/server/thread-forms.ts +41 -1
- package/src/server/tools/place-frame.ts +71 -14
- package/src/server/tools/result.ts +2 -2
- package/src/server/tools/snapshot.ts +2 -1
- package/src/server/tools/studio-context.ts +24 -14
- package/src/server/tools/watch.ts +38 -13
- package/src/server/work-groups.ts +1 -1
- package/src/shared/canvas-core.ts +119 -27
- package/src/shared/canvas-file.ts +7 -4
- package/src/shared/change-pictures-core.ts +8 -0
- package/src/shared/page-looks.ts +133 -0
- package/src/shared/snapshot-clipboard.ts +6 -0
- package/src/shared/studio-routes.ts +7 -1
- package/templates/agents/dex-worker.md +9 -7
- package/templates/feedback-workflow.md +1 -1
- package/templates/methods/review.md +7 -6
- package/templates/rules/canvas-frames.md +8 -7
- package/templates/rules/canvas.md +10 -8
- package/templates/rules/prototypes.md +5 -3
- package/app/canvas/stack-node.tsx +0 -100
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexhq/canvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Dex Canvas: a prototyping environment for teams who design with agents and a design system. Start with `npm create dex@latest`.",
|
|
6
6
|
"bugs": {
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"!**/*.test.*",
|
|
24
24
|
"!**/*.bench.*",
|
|
25
25
|
"!src/testing",
|
|
26
|
-
"!app/testing"
|
|
26
|
+
"!app/testing",
|
|
27
|
+
"!**/__tests__"
|
|
27
28
|
],
|
|
28
29
|
"type": "module",
|
|
29
30
|
"typesVersions": {
|
|
@@ -127,7 +128,7 @@
|
|
|
127
128
|
"watch": "tsdown --watch",
|
|
128
129
|
"prepack": "bun run typecheck && tsdown --logLevel warn && bun ../extension/build.ts --out extension/dist",
|
|
129
130
|
"test": "vitest run --root ../.. --project studio-node --project studio-app",
|
|
130
|
-
"test:e2e": "node e2e/narrow-window.e2e.mjs && node e2e/space-pan.e2e.mjs && node e2e/middle-pan.e2e.mjs && node e2e/dialog-escape.e2e.mjs && node e2e/frame-keys.e2e.mjs && node e2e/file-drop.e2e.mjs && node e2e/pins-on-pictures.e2e.mjs && node e2e/capture-states.e2e.mjs && node e2e/view-loads-again.e2e.mjs && node e2e/zoom-in-shows-view.e2e.mjs && node e2e/text-keys.e2e.mjs && node e2e/quick-bar-focus.e2e.mjs && node e2e/frame-height.e2e.mjs",
|
|
131
|
+
"test:e2e": "node e2e/narrow-window.e2e.mjs && node e2e/space-pan.e2e.mjs && node e2e/middle-pan.e2e.mjs && node e2e/dialog-escape.e2e.mjs && node e2e/frame-keys.e2e.mjs && node e2e/file-drop.e2e.mjs && node e2e/pins-on-pictures.e2e.mjs && node e2e/capture-states.e2e.mjs && node e2e/view-loads-again.e2e.mjs && node e2e/zoom-in-shows-view.e2e.mjs && node e2e/text-keys.e2e.mjs && node e2e/quick-bar-focus.e2e.mjs && node e2e/frame-height.e2e.mjs && node e2e/tool-switch.e2e.mjs && node e2e/toolbar-targets.e2e.mjs && node e2e/line-break-caret.e2e.mjs && node e2e/capture-breakpoints.e2e.mjs",
|
|
131
132
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.build.json",
|
|
132
133
|
"clean": "rm -rf dist node_modules",
|
|
133
134
|
"i18n": "lingui extract --clean && lingui compile",
|
package/src/cli/commands/mcp.ts
CHANGED
|
@@ -60,18 +60,28 @@ export default defineCommand({
|
|
|
60
60
|
const root = await contentRoot(args.root);
|
|
61
61
|
|
|
62
62
|
// Loaded on demand: the MCP SDK is only needed by agents.
|
|
63
|
-
const [
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
const [
|
|
64
|
+
{ serveMcp },
|
|
65
|
+
{ canvasTools, studioOf },
|
|
66
|
+
{ commentsToPush },
|
|
67
|
+
{ pictureBefore },
|
|
68
|
+
] = await Promise.all([
|
|
69
|
+
import("../../server/studio-server.ts"),
|
|
70
|
+
import("../../server/agent-tools.ts"),
|
|
71
|
+
import("../../server/comments/push.ts"),
|
|
72
|
+
import("../../server/change-pictures.ts"),
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
const findStudio = studioOf(root);
|
|
69
76
|
|
|
70
77
|
await serveMcp(root, {
|
|
71
78
|
agent: args.agent,
|
|
72
|
-
push:
|
|
79
|
+
push: (content, threads, agentSession) =>
|
|
80
|
+
commentsToPush(content, threads, agentSession, {
|
|
81
|
+
pictureBefore: (found) => pictureBefore(content, found, findStudio),
|
|
82
|
+
}),
|
|
73
83
|
session,
|
|
74
|
-
tools: canvasTools(),
|
|
84
|
+
tools: canvasTools({ findStudio }),
|
|
75
85
|
});
|
|
76
86
|
},
|
|
77
87
|
});
|
package/src/cli/mcp-relay.ts
CHANGED
|
@@ -149,8 +149,16 @@ export function openRelay({
|
|
|
149
149
|
}: RelayOptions) {
|
|
150
150
|
/** The Dex the server in use is from. */
|
|
151
151
|
let running = first;
|
|
152
|
-
/** The Dex to move to. */
|
|
153
|
-
let
|
|
152
|
+
/** The Dex ready to move to, as the last look found it. */
|
|
153
|
+
let lastReady: string | undefined;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The Dex to move to: the one ready, unless it is the one running. Asked
|
|
157
|
+
* each time, never kept: a move changes which Dex runs.
|
|
158
|
+
*/
|
|
159
|
+
const wanted = (): string | undefined =>
|
|
160
|
+
lastReady !== undefined && lastReady !== running ? lastReady : undefined;
|
|
161
|
+
|
|
154
162
|
let retryAt = 0;
|
|
155
163
|
let moving = false;
|
|
156
164
|
/** The agent left: the server in use ends once any move has. */
|
|
@@ -369,7 +377,7 @@ export function openRelay({
|
|
|
369
377
|
|
|
370
378
|
/** Move now, when another Dex waits and nothing is open either way. */
|
|
371
379
|
function moveWhenQuiet() {
|
|
372
|
-
const to = wanted;
|
|
380
|
+
const to = wanted();
|
|
373
381
|
const quiet = open.size === 0 && owed.size === 0;
|
|
374
382
|
|
|
375
383
|
if (to === undefined || !hello || Date.now() < retryAt) {
|
|
@@ -409,9 +417,8 @@ export function openRelay({
|
|
|
409
417
|
* (mcp-handover.ts), also one that began since the last look.
|
|
410
418
|
*/
|
|
411
419
|
const check = () => {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const due = wanted !== undefined && !moving && Date.now() >= retryAt;
|
|
420
|
+
lastReady = ready();
|
|
421
|
+
const due = wanted() !== undefined && !moving && Date.now() >= retryAt;
|
|
415
422
|
|
|
416
423
|
if (due && open.size > 0) {
|
|
417
424
|
current.send(lineOf({ method: UPDATE_READY }));
|
package/src/content/content.ts
CHANGED
|
@@ -30,6 +30,7 @@ import { prepareState, studioState } from "../server/state.ts";
|
|
|
30
30
|
import { notRunning, studioFor } from "../server/studio-for.ts";
|
|
31
31
|
import { TWO_VERSIONS_LEAD } from "../shared/block-merge.ts";
|
|
32
32
|
import {
|
|
33
|
+
type AskedCell,
|
|
33
34
|
appendOwnFrame,
|
|
34
35
|
type CanvasPoint,
|
|
35
36
|
type Cell,
|
|
@@ -39,9 +40,12 @@ import {
|
|
|
39
40
|
placeViewInCell,
|
|
40
41
|
canvasFormProblems,
|
|
41
42
|
stackPiles,
|
|
43
|
+
parseFrameKey,
|
|
44
|
+
stepAsked,
|
|
42
45
|
uniqueId,
|
|
43
46
|
type Viewport,
|
|
44
47
|
viewOf,
|
|
48
|
+
whereInRow,
|
|
45
49
|
} from "../shared/canvas-core.ts";
|
|
46
50
|
import type { Canvas, Section, ViewFrame } from "../shared/canvas-file.ts";
|
|
47
51
|
import { isOneOf, isRecord, isText } from "../shared/checks.ts";
|
|
@@ -91,6 +95,7 @@ import {
|
|
|
91
95
|
type AgentAction,
|
|
92
96
|
agentChange,
|
|
93
97
|
describeThread,
|
|
98
|
+
targetFrameKey,
|
|
94
99
|
type ThreadChange,
|
|
95
100
|
} from "../shared/threads-core.ts";
|
|
96
101
|
import { withUnknownFields } from "../shared/unknown-fields.ts";
|
|
@@ -769,9 +774,9 @@ const rowBefore = <R extends { id: string }>(
|
|
|
769
774
|
};
|
|
770
775
|
|
|
771
776
|
/** A canvas and a cell on it. */
|
|
772
|
-
export interface CanvasCell {
|
|
777
|
+
export interface CanvasCell<C extends Omit<Cell, "step"> = Cell> {
|
|
773
778
|
canvas: Canvas;
|
|
774
|
-
cell:
|
|
779
|
+
cell: C;
|
|
775
780
|
}
|
|
776
781
|
|
|
777
782
|
/**
|
|
@@ -780,12 +785,12 @@ export interface CanvasCell {
|
|
|
780
785
|
* `newRow`). A new row in someone else's section goes where the cell asks
|
|
781
786
|
* (rowBefore): in the person's own row there, or one right below theirs.
|
|
782
787
|
*/
|
|
783
|
-
export function ownCell(
|
|
788
|
+
export function ownCell<C extends Omit<Cell, "step">>(
|
|
784
789
|
canvas: Canvas,
|
|
785
|
-
cell:
|
|
790
|
+
cell: C,
|
|
786
791
|
person: string,
|
|
787
792
|
{ newRow = false }: { newRow?: boolean } = {}
|
|
788
|
-
): CanvasCell {
|
|
793
|
+
): CanvasCell<C> {
|
|
789
794
|
const section = canvas.sections.find((entry) => entry.id === cell.section);
|
|
790
795
|
const row = section?.rows.find((entry) => entry.id === cell.row);
|
|
791
796
|
|
|
@@ -818,16 +823,82 @@ export function ownCell(
|
|
|
818
823
|
};
|
|
819
824
|
}
|
|
820
825
|
|
|
826
|
+
/**
|
|
827
|
+
* The key a frame is at now, found by its uid first, then its key
|
|
828
|
+
* (targetFrameKey); none when no one frame has it.
|
|
829
|
+
*/
|
|
830
|
+
export const frameKeyOn = (
|
|
831
|
+
canvas: Canvas,
|
|
832
|
+
target: { frame: string; uid?: string }
|
|
833
|
+
): string | undefined =>
|
|
834
|
+
targetFrameKey(
|
|
835
|
+
target,
|
|
836
|
+
canvasFrames(canvas).map(({ key, frame }) => ({ key, uid: frame.uid }))
|
|
837
|
+
);
|
|
838
|
+
|
|
839
|
+
/** The cell a frame is in now (frameKeyOn); none when it is gone. */
|
|
840
|
+
export function cellOfFrame(
|
|
841
|
+
canvas: Canvas,
|
|
842
|
+
target: { frame: string; uid?: string }
|
|
843
|
+
): Cell | undefined {
|
|
844
|
+
const key = frameKeyOn(canvas, target);
|
|
845
|
+
const where = key === undefined ? undefined : whereInRow(canvas, key);
|
|
846
|
+
|
|
847
|
+
if (!(key && where)) {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
const { section, row } = parseFrameKey(key);
|
|
852
|
+
|
|
853
|
+
return { section, row, step: where.step };
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* The cell asked for, before the person's own row is found: right of the
|
|
858
|
+
* frame `rightOf` names (its uid or key), where it is now; or, with no row,
|
|
859
|
+
* step or `above`, at the end of the section's first row, its main path.
|
|
860
|
+
*/
|
|
861
|
+
function cellWanted(
|
|
862
|
+
canvas: Canvas,
|
|
863
|
+
asked: AskedCell | { rightOf: string }
|
|
864
|
+
): AskedCell | { problem: string } {
|
|
865
|
+
if ("rightOf" in asked) {
|
|
866
|
+
const { rightOf } = asked;
|
|
867
|
+
const frame = cellOfFrame(canvas, { frame: rightOf, uid: rightOf });
|
|
868
|
+
|
|
869
|
+
if (!frame) {
|
|
870
|
+
return {
|
|
871
|
+
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.`,
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
return { section: frame.section, row: frame.row, after: frame.step };
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
const { above, row, step } = asked;
|
|
879
|
+
|
|
880
|
+
if (row !== undefined || step !== undefined || above !== undefined) {
|
|
881
|
+
return asked;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
const main = canvas.sections.find((each) => each.id === asked.section)
|
|
885
|
+
?.rows[0];
|
|
886
|
+
|
|
887
|
+
return main ? { ...asked, row: main.id } : asked;
|
|
888
|
+
}
|
|
889
|
+
|
|
821
890
|
/**
|
|
822
891
|
* Put a frame for a view in a cell of a prototype's canvas (placeViewInCell),
|
|
823
892
|
* reading and writing canvas.json in one turn, so agents placing frames at
|
|
824
|
-
* once never lose each other's
|
|
825
|
-
*
|
|
893
|
+
* once never lose each other's, and a frame asked for right of another
|
|
894
|
+
* (`rightOf`) or with no step (stepAsked) is placed by the canvas as it is
|
|
895
|
+
* then. A frame for the view already in the cell is kept. Returns its key,
|
|
896
|
+
* its uid and whether it was added, or { problems }.
|
|
826
897
|
*/
|
|
827
898
|
export function placeViewFrame(
|
|
828
899
|
{
|
|
829
900
|
slug,
|
|
830
|
-
cell,
|
|
901
|
+
cell: asked,
|
|
831
902
|
view,
|
|
832
903
|
viewport,
|
|
833
904
|
size,
|
|
@@ -835,7 +906,7 @@ export function placeViewFrame(
|
|
|
835
906
|
newRow,
|
|
836
907
|
stack,
|
|
837
908
|
}: {
|
|
838
|
-
cell:
|
|
909
|
+
cell: AskedCell | { rightOf: string };
|
|
839
910
|
/**
|
|
840
911
|
* In someone else's row, put it in a new row of the person's right
|
|
841
912
|
* below it, not the one they have there.
|
|
@@ -858,17 +929,20 @@ export function placeViewFrame(
|
|
|
858
929
|
> {
|
|
859
930
|
return queued(root, slug, async () => {
|
|
860
931
|
const saver = person;
|
|
932
|
+
const read = await readCanvas(slug, root);
|
|
933
|
+
const wanted = cellWanted(read, asked);
|
|
861
934
|
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
saver,
|
|
866
|
-
{ newRow }
|
|
867
|
-
);
|
|
935
|
+
if ("problem" in wanted) {
|
|
936
|
+
return { problems: [wanted.problem] };
|
|
937
|
+
}
|
|
868
938
|
|
|
939
|
+
const { canvas, cell: own } = ownCell(read, wanted, saver, { newRow });
|
|
940
|
+
// Moved into the person's own row: not left of the end of the one asked.
|
|
941
|
+
const past = own.row === wanted.row ? undefined : wanted.row;
|
|
942
|
+
const cell = { ...own, step: stepAsked(canvas, own, view, past) };
|
|
869
943
|
const { devices } = await loadDevices(root);
|
|
870
944
|
|
|
871
|
-
const placed = placeViewInCell(canvas,
|
|
945
|
+
const placed = placeViewInCell(canvas, cell, {
|
|
872
946
|
view,
|
|
873
947
|
viewport,
|
|
874
948
|
size,
|
|
@@ -8,6 +8,11 @@ import { existsSync } from "node:fs";
|
|
|
8
8
|
import type { Browser, BrowserType, Page, Request } from "playwright";
|
|
9
9
|
|
|
10
10
|
import { VIEWPORTS } from "../shared/canvas-core.ts";
|
|
11
|
+
import {
|
|
12
|
+
LOOKS_SELECTORS,
|
|
13
|
+
type PageLooks,
|
|
14
|
+
pageLooks,
|
|
15
|
+
} from "../shared/page-looks.ts";
|
|
11
16
|
import { VIEW_RENDERED } from "../shared/page-messages.ts";
|
|
12
17
|
import { viewInFrame } from "../shared/prototypes-core.ts";
|
|
13
18
|
import { XRAY_CSS } from "../shared/xray.ts";
|
|
@@ -398,6 +403,7 @@ async function settled(
|
|
|
398
403
|
/** A view's picture, and what looked wrong on its page. */
|
|
399
404
|
export interface ViewShot {
|
|
400
405
|
image: Buffer;
|
|
406
|
+
looks?: PageLooks;
|
|
401
407
|
/**
|
|
402
408
|
* What a picture hides: errors the page threw or logged, and a page wider
|
|
403
409
|
* than its viewport.
|
|
@@ -477,6 +483,8 @@ async function capture(
|
|
|
477
483
|
problems.push(`overflows horizontally by ${overflow}px`);
|
|
478
484
|
}
|
|
479
485
|
|
|
486
|
+
const looks = await page.evaluate(pageLooks, LOOKS_SELECTORS);
|
|
487
|
+
|
|
480
488
|
const image = await page.screenshot({
|
|
481
489
|
fullPage: true,
|
|
482
490
|
type,
|
|
@@ -484,7 +492,7 @@ async function capture(
|
|
|
484
492
|
});
|
|
485
493
|
|
|
486
494
|
// React renders twice in development: an error it logs comes twice.
|
|
487
|
-
return { image, problems: [...new Set(problems)] };
|
|
495
|
+
return { image, looks, problems: [...new Set(problems)] };
|
|
488
496
|
} finally {
|
|
489
497
|
await page.close();
|
|
490
498
|
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
/* oxlint-disable anti-slop/no-runtime-typeof, anti-slop/no-unknown-parameters -- parses the studio's answers and fetch's errors */
|
|
7
7
|
|
|
8
|
+
import { isRecord } from "../shared/checks.ts";
|
|
9
|
+
import type { PageLooks } from "../shared/page-looks.ts";
|
|
8
10
|
import type { ViewShot } from "./screenshot.ts";
|
|
9
11
|
|
|
10
12
|
/** One view to snapshot: its frame page, and how to show it. */
|
|
@@ -20,6 +22,7 @@ export interface SnapshotRequest {
|
|
|
20
22
|
/** What the studio answers with: the picture as base64, and its problems. */
|
|
21
23
|
export interface SnapshotBody {
|
|
22
24
|
image: string;
|
|
25
|
+
looks: PageLooks;
|
|
23
26
|
problems: string[];
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -65,9 +68,20 @@ const strings = (value: unknown): string[] =>
|
|
|
65
68
|
/** What the studio's answer may hold, each field still to be checked. */
|
|
66
69
|
interface Answer {
|
|
67
70
|
image?: unknown;
|
|
71
|
+
looks?: unknown;
|
|
68
72
|
problems?: unknown;
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
const looksIn = (value: unknown): PageLooks | undefined => {
|
|
76
|
+
if (!isRecord(value) || typeof value.blank !== "boolean") {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const { blank, error } = value;
|
|
81
|
+
|
|
82
|
+
return typeof error === "string" ? { blank, error } : { blank };
|
|
83
|
+
};
|
|
84
|
+
|
|
71
85
|
/** The studio's answer as JSON, or undefined when it is not. */
|
|
72
86
|
const json = (text: string): Answer | undefined => {
|
|
73
87
|
try {
|
|
@@ -114,8 +128,11 @@ export async function snapshotView(
|
|
|
114
128
|
);
|
|
115
129
|
}
|
|
116
130
|
|
|
131
|
+
const looks = looksIn(answer.looks);
|
|
132
|
+
|
|
117
133
|
return {
|
|
118
134
|
image: Buffer.from(answer.image, "base64"),
|
|
119
135
|
problems: strings(answer.problems),
|
|
136
|
+
...(looks && { looks }),
|
|
120
137
|
};
|
|
121
138
|
}
|
package/src/paste/paste.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// from Google Fonts (fonts.ts), so no page showing the view fetches them again.
|
|
8
8
|
|
|
9
9
|
import { MAX_SIDE } from "../content/capture.ts";
|
|
10
|
+
import { isRecord } from "../shared/checks.ts";
|
|
10
11
|
import {
|
|
11
12
|
PASTED_IMAGE_TYPES,
|
|
12
13
|
type PastedImage,
|
|
@@ -32,6 +33,11 @@ export interface Pasted {
|
|
|
32
33
|
from: PasteSource;
|
|
33
34
|
/** Images left grey or as links: they could not be brought. */
|
|
34
35
|
images: number;
|
|
36
|
+
/**
|
|
37
|
+
* Parts of an extension's snapshot its page's scripts sized: they keep
|
|
38
|
+
* that size, and won't reflow when the frame is resized.
|
|
39
|
+
*/
|
|
40
|
+
sizedByScripts?: number;
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
/**
|
|
@@ -83,7 +89,18 @@ const fetchFigmaImage = async (url: string): Promise<string> => {
|
|
|
83
89
|
|
|
84
90
|
const extensionPaste = (html: string): Pasted => {
|
|
85
91
|
try {
|
|
86
|
-
|
|
92
|
+
const snapshot = snapshotFrom(html);
|
|
93
|
+
// How many of its parts the page's scripts sized, as the extension
|
|
94
|
+
// counted: a whole number, or none.
|
|
95
|
+
const said = isRecord(snapshot) ? snapshot.sizedByScripts : undefined;
|
|
96
|
+
const sized = Number.isInteger(said) ? Number(said) : 0;
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
from: "extension",
|
|
100
|
+
captures: [snapshot],
|
|
101
|
+
images: 0,
|
|
102
|
+
...(sized > 0 && { sizedByScripts: sized }),
|
|
103
|
+
};
|
|
87
104
|
} catch (error) {
|
|
88
105
|
throw new PasteProblemError(
|
|
89
106
|
422,
|
|
@@ -28,14 +28,15 @@ export interface CanvasToolOptions {
|
|
|
28
28
|
findStudio?: () => Promise<StudioFor>;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export const studioOf = (root: string) => async (): Promise<StudioFor> =>
|
|
32
|
+
studioFor(await loadProject(root));
|
|
33
|
+
|
|
31
34
|
/** The canvas's tools, made for each session's server. */
|
|
32
35
|
export const canvasTools =
|
|
33
36
|
({ feedbackRelay, findStudio }: CanvasToolOptions = {}): ToolsFor =>
|
|
34
37
|
(setup) => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const studio =
|
|
38
|
-
findStudio ?? (async () => studioFor(await loadProject(setup.root)));
|
|
38
|
+
const studio = findStudio ?? studioOf(setup.root);
|
|
39
|
+
const context = openToolContext(setup, studio);
|
|
39
40
|
|
|
40
41
|
return [
|
|
41
42
|
...readingTools(context, setup.briefing),
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type KeptPictures,
|
|
3
|
+
MOMENTS,
|
|
4
|
+
type Moment,
|
|
5
|
+
} from "../shared/change-pictures-core.ts";
|
|
6
|
+
|
|
7
|
+
interface Kept {
|
|
8
|
+
at: number;
|
|
9
|
+
image: Buffer;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const MOST_PICTURE_BYTES = 200_000_000;
|
|
13
|
+
|
|
14
|
+
export interface ChangePictureStore {
|
|
15
|
+
drop: (id: string, moment: Moment) => void;
|
|
16
|
+
image: (id: string, moment: Moment) => Buffer | undefined;
|
|
17
|
+
keep: (id: string, moment: Moment, image: Buffer) => void;
|
|
18
|
+
kept: (id: string) => KeptPictures;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function changePictureStore({
|
|
22
|
+
mostBytes = MOST_PICTURE_BYTES,
|
|
23
|
+
}: {
|
|
24
|
+
mostBytes?: number;
|
|
25
|
+
} = {}): ChangePictureStore {
|
|
26
|
+
const comments = new Map<string, Map<Moment, Kept>>();
|
|
27
|
+
let bytes = 0;
|
|
28
|
+
let lastAt = 0;
|
|
29
|
+
|
|
30
|
+
const forget = (id: string, moment: Moment) => {
|
|
31
|
+
bytes -= comments.get(id)?.get(moment)?.image.length ?? 0;
|
|
32
|
+
comments.get(id)?.delete(moment);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const forgetOldest = () => {
|
|
36
|
+
for (const [oldest, pictures] of comments) {
|
|
37
|
+
if (bytes <= mostBytes) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const moment of pictures.keys()) {
|
|
42
|
+
forget(oldest, moment);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
comments.delete(oldest);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
drop: forget,
|
|
51
|
+
image: (id, moment) => comments.get(id)?.get(moment)?.image,
|
|
52
|
+
keep: (id, moment, image) => {
|
|
53
|
+
forget(id, moment);
|
|
54
|
+
lastAt = Math.max(Date.now(), lastAt + 1);
|
|
55
|
+
const pictures = comments.get(id) ?? new Map<Moment, Kept>();
|
|
56
|
+
pictures.set(moment, { at: lastAt, image });
|
|
57
|
+
bytes += image.length;
|
|
58
|
+
comments.delete(id);
|
|
59
|
+
comments.set(id, pictures);
|
|
60
|
+
forgetOldest();
|
|
61
|
+
},
|
|
62
|
+
kept: (id) =>
|
|
63
|
+
Object.fromEntries(
|
|
64
|
+
MOMENTS.flatMap((moment) => {
|
|
65
|
+
const kept = comments.get(id)?.get(moment);
|
|
66
|
+
|
|
67
|
+
return kept ? [[moment, kept.at]] : [];
|
|
68
|
+
})
|
|
69
|
+
),
|
|
70
|
+
};
|
|
71
|
+
}
|