@pairdraw/core 0.22.1 → 0.22.2

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 (36) hide show
  1. package/dist/canvas/images/previews.d.ts +1 -1
  2. package/dist/canvas/index.d.ts +2 -1
  3. package/dist/canvas/overlays/presence.d.ts +16 -1
  4. package/dist/canvas/overlays/presence.d.ts.map +1 -1
  5. package/dist/canvas/overlays/presence.js +90 -3
  6. package/dist/canvas/overlays/presence.js.map +1 -1
  7. package/dist/canvas/renderer/picture.d.ts +4 -1
  8. package/dist/canvas/renderer/picture.d.ts.map +1 -1
  9. package/dist/canvas/renderer/picture.js +13 -1
  10. package/dist/canvas/renderer/picture.js.map +1 -1
  11. package/dist/canvas/renderer/transient-previews.d.ts +9 -1
  12. package/dist/canvas/renderer/transient-previews.d.ts.map +1 -1
  13. package/dist/canvas/renderer/transient-previews.js +29 -3
  14. package/dist/canvas/renderer/transient-previews.js.map +1 -1
  15. package/dist/canvas/renderer/types.d.ts +11 -0
  16. package/dist/canvas/renderer/types.d.ts.map +1 -1
  17. package/dist/canvas/renderer.d.ts +1 -1
  18. package/dist/design-jsx/preview/picture.d.ts +4 -0
  19. package/dist/design-jsx/preview/picture.d.ts.map +1 -1
  20. package/dist/design-jsx/preview/picture.js +13 -1
  21. package/dist/design-jsx/preview/picture.js.map +1 -1
  22. package/dist/design-jsx/preview/stage.d.ts +2 -0
  23. package/dist/design-jsx/preview/stage.d.ts.map +1 -1
  24. package/dist/design-jsx/preview/stage.js +11 -2
  25. package/dist/design-jsx/preview/stage.js.map +1 -1
  26. package/dist/editor/bridges/undo.d.ts +1 -1
  27. package/dist/editor/create.d.ts +1 -1
  28. package/dist/figma-api/reactions.d.ts +4 -4
  29. package/package.json +9 -9
  30. package/src/canvas/index.ts +1 -0
  31. package/src/canvas/overlays/presence.ts +114 -13
  32. package/src/canvas/renderer/picture.ts +17 -0
  33. package/src/canvas/renderer/transient-previews.ts +38 -4
  34. package/src/canvas/renderer/types.ts +8 -0
  35. package/src/design-jsx/preview/picture.ts +27 -1
  36. package/src/design-jsx/preview/stage.ts +11 -3
@@ -5,7 +5,7 @@ import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
5
5
  * images. Kept per document and image count, since the renderer asks on every frame.
6
6
  */
7
7
  declare function needsImagePreviews(graph: SceneGraph): boolean;
8
- declare function previewEdge(node: Pick<SceneNode, 'width' | 'height'>, zoom: number, dpr?: number): 1024 | 256 | 128 | 512 | 2048;
8
+ declare function previewEdge(node: Pick<SceneNode, 'width' | 'height'>, zoom: number, dpr?: number): 256 | 128 | 1024 | 512 | 2048;
9
9
  interface ImagePreview {
10
10
  bytes: Uint8Array<ArrayBuffer>;
11
11
  originalWidth: number;
@@ -6,6 +6,7 @@ import { VectorFlattenProps, flattenNodesToVectorProps } from "./flatten.js";
6
6
  import { OutlinePiece, OutlinedLayer, canOutlineStroke, layersToOutline, outlineStrokeLayer } from "./outline-stroke.js";
7
7
  import { GuideScreenSegment, GuideViewport, distanceToGuideSegment, getGuideScreenSegment } from "./guides/geometry.js";
8
8
  import { computeGuideRedline } from "./guides/redlines.js";
9
+ import { TransientCanvasPreview } from "./renderer/transient-previews.js";
9
10
  import { GuideHit, hitTestGuides } from "./guides/hit-test.js";
10
11
  import { canvasLabelForeground } from "./labels/color.js";
11
12
  import { ImagePreview, ImagePreviewDecoder } from "./images/previews.js";
@@ -15,4 +16,4 @@ import { withFigExportRuntime } from "./text/shape.js";
15
16
  import { DrawnFontAxes, DrawnFontAxis, drawnFontAxes } from "./text/font-families.js";
16
17
  import { PresenceCursor, RenderOverlays, RenderedPlayScene, RulerTheme, SelectionTheme } from "./renderer/types.js";
17
18
  import { SkiaRenderer } from "./renderer.js";
18
- export { type CachedComponent, type CachedSection, type ColorSpaceContext, type DesignIssueHighlight, type DesignIssueSeverity, type DrawnFontAxes, type DrawnFontAxis, type FloatTargetContext, type GuideHit, type GuideOverlayState, type GuidePreview, type GuideScreenSegment, type GuideSelection, type GuideViewport, type ImagePreview, type ImagePreviewDecoder, LabelCache, type OutlinePiece, type OutlinedLayer, type PlacedStatusLabel, type PresenceCursor, type RenderOverlays, type RenderedPlayScene, type RulerTheme, type SelectionTheme, SkiaRenderer, type VectorFlattenProps, canMakeBooleanSourceNode, canMakeBooleanSourcePath, canOutlineStroke, canvasLabelForeground, computeGuideRedline, distanceToGuideSegment, drawnFontAxes, flattenNodesToVectorProps, getGuideScreenSegment, hasFloatRenderTarget, hitTestGuides, hitTestStatusLabels, isHardwareRenderer, isSoftwareRenderer, layersToOutline, nodeHasVisibleStroke, outlineStrokeLayer, rendererName, supportsFloatRenderTarget, withFigExportRuntime };
19
+ export { type CachedComponent, type CachedSection, type ColorSpaceContext, type DesignIssueHighlight, type DesignIssueSeverity, type DrawnFontAxes, type DrawnFontAxis, type FloatTargetContext, type GuideHit, type GuideOverlayState, type GuidePreview, type GuideScreenSegment, type GuideSelection, type GuideViewport, type ImagePreview, type ImagePreviewDecoder, LabelCache, type OutlinePiece, type OutlinedLayer, type PlacedStatusLabel, type PresenceCursor, type RenderOverlays, type RenderedPlayScene, type RulerTheme, type SelectionTheme, SkiaRenderer, type TransientCanvasPreview, type VectorFlattenProps, canMakeBooleanSourceNode, canMakeBooleanSourcePath, canOutlineStroke, canvasLabelForeground, computeGuideRedline, distanceToGuideSegment, drawnFontAxes, flattenNodesToVectorProps, getGuideScreenSegment, hasFloatRenderTarget, hitTestGuides, hitTestStatusLabels, isHardwareRenderer, isSoftwareRenderer, layersToOutline, nodeHasVisibleStroke, outlineStrokeLayer, rendererName, supportsFloatRenderTarget, withFigExportRuntime };
@@ -3,8 +3,23 @@ import { SkiaRenderer } from "../renderer.js";
3
3
  import { Canvas } from "canvaskit-wasm";
4
4
  import { SceneGraph } from "@pairdraw/scene-graph";
5
5
  //#region src/canvas/overlays/presence.d.ts
6
+ /** What a cursor's focus outline showed, so a newer element fades the old one out. */
7
+ interface FocusTransition {
8
+ current: Rect | null;
9
+ previous: Rect | null;
10
+ /** When the previous outline was replaced. */
11
+ since: number;
12
+ }
13
+ declare const NO_FOCUS: FocusTransition;
14
+ /** Move the outline to `focus`, keeping the one it replaces for its fade. */
15
+ declare function nextFocus(state: FocusTransition, focus: Rect | undefined, now: number): FocusTransition;
16
+ /** The outline to draw now: the current one, pulsing, and the replaced one fading out. */
17
+ declare function focusOutlines(state: FocusTransition, pulse: boolean | undefined, now: number): Array<{
18
+ rect: Rect;
19
+ alpha: number;
20
+ }>;
6
21
  /** Cursors of people and agents in screen space, with outlines of what they selected. */
7
22
  declare function drawPresenceCursors(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph, cursors?: PresenceCursor[]): void;
8
23
  //#endregion
9
- export { drawPresenceCursors };
24
+ export { FocusTransition, NO_FOCUS, drawPresenceCursors, focusOutlines, nextFocus };
10
25
  //# sourceMappingURL=presence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"presence.d.ts","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"mappings":";;;;;;iBAuKgB,oBACd,GAAG,cACH,QAAQ,QACR,OAAO,YACP,UAAU"}
1
+ {"version":3,"file":"presence.d.ts","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"mappings":";;;;;;UA4BiB;EACf,SAAS;EACT,UAAU;;EAEV;;cAGW,UAAU;;iBAoBP,UACd,OAAO,iBACP,OAAO,kBACP,cACC;;iBAOa,cACd,OAAO,iBACP,4BACA,cACC;EAAQ,MAAM;EAAM;;;iBAiMP,oBACd,GAAG,cACH,QAAQ,QACR,OAAO,YACP,UAAU"}
@@ -11,15 +11,97 @@ const LABEL_OFFSET_Y = 20;
11
11
  const LABEL_MAX_WIDTH = 160;
12
12
  /** The provider mark before an agent's name, and the gap after it. */
13
13
  const LABEL_LOGO_SIZE = 9;
14
+ /** The newest outline's soft pulse, and how long a replaced one takes to fade. */
15
+ const FOCUS_PULSE_MS = 1200;
16
+ const FOCUS_FADE_MS = 200;
17
+ /** One sheen across what a finished preview built. */
18
+ const SHEEN_MS = 400;
14
19
  /** Decoded once per logo byte array; the app keeps one array per provider, so this is tiny. */
15
20
  const labelLogoImages = /* @__PURE__ */ new WeakMap();
21
+ const NO_FOCUS = {
22
+ current: null,
23
+ previous: null,
24
+ since: 0
25
+ };
26
+ /** Draw a world-space rectangle in the overlay's screen coordinates. */
27
+ function drawWorldRect(r, canvas, rect, paint) {
28
+ canvas.drawRect(r.ck.XYWHRect(rect.x * r.zoom + r.panX, rect.y * r.zoom + r.panY, rect.width * r.zoom, rect.height * r.zoom), paint);
29
+ }
30
+ function sameRect(a, b) {
31
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
32
+ }
33
+ /** Move the outline to `focus`, keeping the one it replaces for its fade. */
34
+ function nextFocus(state, focus, now) {
35
+ if (!focus) return NO_FOCUS;
36
+ if (state.current && sameRect(state.current, focus)) return state;
37
+ return {
38
+ current: focus,
39
+ previous: state.current,
40
+ since: now
41
+ };
42
+ }
43
+ /** The outline to draw now: the current one, pulsing, and the replaced one fading out. */
44
+ function focusOutlines(state, pulse, now) {
45
+ const outlines = [];
46
+ const age = now - state.since;
47
+ if (pulse && state.previous && age < FOCUS_FADE_MS) outlines.push({
48
+ rect: state.previous,
49
+ alpha: .75 * (1 - age / FOCUS_FADE_MS)
50
+ });
51
+ if (state.current) {
52
+ const alpha = pulse ? .35 + .65 * (.5 + .5 * Math.sin(now / FOCUS_PULSE_MS * 2 * Math.PI)) : .75;
53
+ outlines.push({
54
+ rect: state.current,
55
+ alpha
56
+ });
57
+ }
58
+ return outlines;
59
+ }
60
+ /** Each canvas keeps its own focus transitions, so two documents' agents never collide. */
61
+ const focusHistories = /* @__PURE__ */ new WeakMap();
62
+ function focusHistoryFor(r) {
63
+ const existing = focusHistories.get(r);
64
+ if (existing) return existing;
65
+ const history = /* @__PURE__ */ new Map();
66
+ focusHistories.set(r, history);
67
+ return history;
68
+ }
69
+ /** The element being written, pulsing in the accent color, and the one it replaced fading out. */
70
+ function drawFocus(r, canvas, cursor) {
71
+ if (cursor.kind !== "agent") return;
72
+ const key = cursor.id ?? cursor.name;
73
+ const history = focusHistoryFor(r);
74
+ const now = performance.now();
75
+ const state = nextFocus(history.get(key) ?? NO_FOCUS, cursor.focus, now);
76
+ if (state === NO_FOCUS) history.delete(key);
77
+ else history.set(key, state);
78
+ const { r: red, g, b } = cursor.color;
79
+ r.auxStroke.setStrokeWidth(2);
80
+ r.auxStroke.setPathEffect(null);
81
+ for (const { rect, alpha } of focusOutlines(state, cursor.pulse, now)) {
82
+ if (alpha <= 0) continue;
83
+ r.auxStroke.setColor(r.ck.Color4f(red, g, b, alpha));
84
+ drawWorldRect(r, canvas, rect, r.auxStroke);
85
+ }
86
+ }
87
+ /** One soft pass of light across what a finished preview built. */
88
+ function drawSheen(r, canvas, cursor) {
89
+ if (!cursor.sheen) return;
90
+ const age = performance.now() - cursor.sheen.at;
91
+ if (age < 0 || age >= SHEEN_MS) return;
92
+ const { rect } = cursor.sheen;
93
+ r.auxFill.setColor(r.ck.Color4f(1, 1, 1, .07 * Math.sin(age / SHEEN_MS * Math.PI)));
94
+ drawWorldRect(r, canvas, rect, r.auxFill);
95
+ }
16
96
  function drawSelection(r, canvas, graph, cursor) {
97
+ drawSheen(r, canvas, cursor);
98
+ drawFocus(r, canvas, cursor);
17
99
  if (!cursor.selection?.length && !cursor.outline?.length) return;
18
100
  const { r: red, g, b } = cursor.color;
19
101
  r.auxStroke.setColor(r.ck.Color4f(red, g, b, .6));
20
102
  r.auxStroke.setStrokeWidth(1.5);
21
103
  r.auxStroke.setPathEffect(null);
22
- for (const rect of cursor.outline ?? []) canvas.drawRect(r.ck.XYWHRect(rect.x * r.zoom + r.panX, rect.y * r.zoom + r.panY, rect.width * r.zoom, rect.height * r.zoom), r.auxStroke);
104
+ for (const rect of cursor.outline ?? []) drawWorldRect(r, canvas, rect, r.auxStroke);
23
105
  for (const nodeId of cursor.selection ?? []) {
24
106
  const node = graph.getNode(nodeId);
25
107
  if (!node) continue;
@@ -88,10 +170,11 @@ function drawLabel(r, canvas, x, y, cursor) {
88
170
  const agent = cursor.kind === "agent";
89
171
  const logo = agent ? labelLogo(r, cursor.logo) : null;
90
172
  const badge = logo ? 12 : 0;
173
+ const label = cursor.status ? `${cursor.name} ${cursor.status}` : cursor.name;
91
174
  const pillX = x + LABEL_OFFSET_X - LABEL_PADDING_X;
92
175
  const pillY = y + LABEL_OFFSET_Y - LABEL_FONT_SIZE - LABEL_PADDING_Y + 2;
93
176
  const pillHeight = 14;
94
- r.labelParagraphCache.use(r.ck, provider, cursor.name, LABEL_FONT_SIZE, LABEL_MAX_WIDTH, agent ? color : r.ck.WHITE, r.fontGeneration, ({ paragraph, metrics }) => {
177
+ r.labelParagraphCache.use(r.ck, provider, label, LABEL_FONT_SIZE, LABEL_MAX_WIDTH, agent ? color : r.ck.WHITE, r.fontGeneration, ({ paragraph, metrics }) => {
95
178
  const pill = r.ck.RRectXY(r.ck.XYWHRect(pillX, pillY, badge + metrics.width + 8, pillHeight), 4, 4);
96
179
  r.auxFill.setColor(agent ? r.ck.WHITE : color);
97
180
  canvas.drawRRect(pill, r.auxFill);
@@ -110,15 +193,19 @@ function drawLabel(r, canvas, x, y, cursor) {
110
193
  }
111
194
  /** Cursors of people and agents in screen space, with outlines of what they selected. */
112
195
  function drawPresenceCursors(r, canvas, graph, cursors) {
196
+ const history = focusHistoryFor(r);
197
+ const drawn = /* @__PURE__ */ new Set();
113
198
  for (const cursor of cursors ?? []) {
199
+ drawn.add(cursor.id ?? cursor.name);
114
200
  const x = cursor.x * r.zoom + r.panX;
115
201
  const y = cursor.y * r.zoom + r.panY;
116
202
  drawSelection(r, canvas, graph, cursor);
117
203
  drawArrow(r, canvas, x, y, cursor);
118
204
  drawLabel(r, canvas, x, y, cursor);
119
205
  }
206
+ for (const key of history.keys()) if (!drawn.has(key)) history.delete(key);
120
207
  }
121
208
  //#endregion
122
- export { drawPresenceCursors };
209
+ export { NO_FOCUS, drawPresenceCursors, focusOutlines, nextFocus };
123
210
 
124
211
  //# sourceMappingURL=presence.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"presence.js","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"sourcesContent":["import type { Canvas, Image } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport type { PresenceCursor, SkiaRenderer } from '#core/canvas/renderer'\n\nconst CURSOR_SIZE = 9\nconst LABEL_PADDING_X = 4\nconst LABEL_PADDING_Y = 2\nconst LABEL_FONT_SIZE = 10\nconst LABEL_OFFSET_X = 12\nconst LABEL_OFFSET_Y = 20\n/** Longer names end with an ellipsis. */\nconst LABEL_MAX_WIDTH = 160\n/** The provider mark before an agent's name, and the gap after it. */\nconst LABEL_LOGO_SIZE = 9\nconst LABEL_LOGO_GAP = 3\n\n/** Decoded once per logo byte array; the app keeps one array per provider, so this is tiny. */\nconst labelLogoImages = new WeakMap<Uint8Array, Image | null>()\n\nfunction drawSelection(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph, cursor: PresenceCursor) {\n if (!cursor.selection?.length && !cursor.outline?.length) return\n const { r: red, g, b } = cursor.color\n r.auxStroke.setColor(r.ck.Color4f(red, g, b, 0.6))\n r.auxStroke.setStrokeWidth(1.5)\n r.auxStroke.setPathEffect(null)\n // Outlines of what is not a layer yet, such as JSX an agent is still streaming.\n for (const rect of cursor.outline ?? []) {\n canvas.drawRect(\n r.ck.XYWHRect(\n rect.x * r.zoom + r.panX,\n rect.y * r.zoom + r.panY,\n rect.width * r.zoom,\n rect.height * r.zoom\n ),\n r.auxStroke\n )\n }\n for (const nodeId of cursor.selection ?? []) {\n const node = graph.getNode(nodeId)\n if (!node) continue\n // Map the corners through the node's world matrix, as the shape is rendered, so the\n // box tracks rotation, flips, and parent transforms.\n const corners = Matrix.mapPoints(getWorldMatrix(node, graph), [\n 0,\n 0,\n node.width,\n 0,\n node.width,\n node.height,\n 0,\n node.height\n ])\n const box = new r.ck.PathBuilder()\n box.moveTo(corners[0] * r.zoom + r.panX, corners[1] * r.zoom + r.panY)\n for (let i = 2; i < corners.length; i += 2) {\n box.lineTo(corners[i] * r.zoom + r.panX, corners[i + 1] * r.zoom + r.panY)\n }\n box.close()\n const path = box.detachAndDelete()\n canvas.drawPath(path, r.auxStroke)\n path.delete()\n }\n}\n\nfunction arrowPath(r: SkiaRenderer, x: number, y: number) {\n const S = CURSOR_SIZE\n const builder = new r.ck.PathBuilder()\n builder.moveTo(x, y)\n builder.lineTo(x, y + S * 1.35)\n builder.lineTo(x + S * 0.38, y + S * 1.0)\n builder.lineTo(x + S * 0.72, y + S * 1.5)\n builder.lineTo(x + S * 0.92, y + S * 1.38)\n builder.lineTo(x + S * 0.58, y + S * 0.88)\n builder.lineTo(x + S * 1.0, y + S * 0.82)\n builder.close()\n return builder.detachAndDelete()\n}\n\n/** The pointer, filled with a person's color, or for an agent its owner's, and outlined in white. */\nfunction drawArrow(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const path = arrowPath(r, x, y)\n r.auxStroke.setColor(r.ck.WHITE)\n r.auxStroke.setStrokeWidth(2)\n r.auxStroke.setPathEffect(null)\n canvas.drawPath(path, r.auxStroke)\n const { r: red, g, b } = cursor.color\n r.auxFill.setColor(r.ck.Color4f(red, g, b, 1))\n canvas.drawPath(path, r.auxFill)\n path.delete()\n}\n\n/** The provider's mark decoded for the canvas, or null while none is available. */\nfunction labelLogo(r: SkiaRenderer, bytes: Uint8Array | undefined): Image | null {\n if (!bytes) return null\n const cached = labelLogoImages.get(bytes)\n if (cached !== undefined) return cached\n const image = r.ck.MakeImageFromEncoded(bytes)\n labelLogoImages.set(bytes, image)\n return image\n}\n\n/**\n * A name pill: filled for people; for agents outlined in the owner's color, with the\n * provider's real mark before the name when the app supplied one.\n */\nfunction drawLabel(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const provider = r.fontProvider\n if (!cursor.name || !provider) return\n const { r: red, g, b } = cursor.color\n const color = r.ck.Color4f(red, g, b, 1)\n const agent = cursor.kind === 'agent'\n const logo = agent ? labelLogo(r, cursor.logo) : null\n const badge = logo ? LABEL_LOGO_SIZE + LABEL_LOGO_GAP : 0\n const pillX = x + LABEL_OFFSET_X - LABEL_PADDING_X\n const pillY = y + LABEL_OFFSET_Y - LABEL_FONT_SIZE - LABEL_PADDING_Y + 2\n const pillHeight = LABEL_FONT_SIZE + LABEL_PADDING_Y * 2\n // Shaped like other canvas labels: kerning, fallback fonts, and RTL names.\n r.labelParagraphCache.use(\n r.ck,\n provider,\n cursor.name,\n LABEL_FONT_SIZE,\n LABEL_MAX_WIDTH,\n agent ? color : r.ck.WHITE,\n r.fontGeneration,\n ({ paragraph, metrics }) => {\n const pill = r.ck.RRectXY(\n r.ck.XYWHRect(pillX, pillY, badge + metrics.width + LABEL_PADDING_X * 2, pillHeight),\n 4,\n 4\n )\n r.auxFill.setColor(agent ? r.ck.WHITE : color)\n canvas.drawRRect(pill, r.auxFill)\n if (agent) {\n r.auxStroke.setColor(color)\n r.auxStroke.setStrokeWidth(1)\n r.auxStroke.setPathEffect(null)\n canvas.drawRRect(pill, r.auxStroke)\n if (logo) {\n r.auxFill.setColor(r.ck.Color4f(1, 1, 1, 1))\n canvas.drawImageRect(\n logo,\n r.ck.XYWHRect(0, 0, logo.width(), logo.height()),\n r.ck.XYWHRect(\n pillX + LABEL_PADDING_X,\n pillY + (pillHeight - LABEL_LOGO_SIZE) / 2,\n LABEL_LOGO_SIZE,\n LABEL_LOGO_SIZE\n ),\n r.auxFill\n )\n }\n }\n canvas.drawParagraph(\n paragraph,\n pillX + LABEL_PADDING_X + badge,\n pillY + (pillHeight - metrics.height) / 2\n )\n }\n )\n}\n\n/** Cursors of people and agents in screen space, with outlines of what they selected. */\nexport function drawPresenceCursors(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n cursors?: PresenceCursor[]\n): void {\n for (const cursor of cursors ?? []) {\n const x = cursor.x * r.zoom + r.panX\n const y = cursor.y * r.zoom + r.panY\n drawSelection(r, canvas, graph, cursor)\n drawArrow(r, canvas, x, y, cursor)\n drawLabel(r, canvas, x, y, cursor)\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"presence.js","names":[],"sources":["../../../src/canvas/overlays/presence.ts"],"sourcesContent":["import type { Canvas, Image, Paint } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport type { PresenceCursor, SkiaRenderer } from '#core/canvas/renderer'\n\nconst CURSOR_SIZE = 9\nconst LABEL_PADDING_X = 4\nconst LABEL_PADDING_Y = 2\nconst LABEL_FONT_SIZE = 10\nconst LABEL_OFFSET_X = 12\nconst LABEL_OFFSET_Y = 20\n/** Longer names end with an ellipsis. */\nconst LABEL_MAX_WIDTH = 160\n/** The provider mark before an agent's name, and the gap after it. */\nconst LABEL_LOGO_SIZE = 9\nconst LABEL_LOGO_GAP = 3\n/** The newest outline's soft pulse, and how long a replaced one takes to fade. */\nconst FOCUS_PULSE_MS = 1200\nconst FOCUS_FADE_MS = 200\n/** One sheen across what a finished preview built. */\nconst SHEEN_MS = 400\n\n/** Decoded once per logo byte array; the app keeps one array per provider, so this is tiny. */\nconst labelLogoImages = new WeakMap<Uint8Array, Image | null>()\n/** What a cursor's focus outline showed, so a newer element fades the old one out. */\nexport interface FocusTransition {\n current: Rect | null\n previous: Rect | null\n /** When the previous outline was replaced. */\n since: number\n}\n\nexport const NO_FOCUS: FocusTransition = { current: null, previous: null, since: 0 }\n\n/** Draw a world-space rectangle in the overlay's screen coordinates. */\nfunction drawWorldRect(r: SkiaRenderer, canvas: Canvas, rect: Rect, paint: Paint) {\n canvas.drawRect(\n r.ck.XYWHRect(\n rect.x * r.zoom + r.panX,\n rect.y * r.zoom + r.panY,\n rect.width * r.zoom,\n rect.height * r.zoom\n ),\n paint\n )\n}\n\nfunction sameRect(a: Rect, b: Rect): boolean {\n return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height\n}\n\n/** Move the outline to `focus`, keeping the one it replaces for its fade. */\nexport function nextFocus(\n state: FocusTransition,\n focus: Rect | undefined,\n now: number\n): FocusTransition {\n if (!focus) return NO_FOCUS\n if (state.current && sameRect(state.current, focus)) return state\n return { current: focus, previous: state.current, since: now }\n}\n\n/** The outline to draw now: the current one, pulsing, and the replaced one fading out. */\nexport function focusOutlines(\n state: FocusTransition,\n pulse: boolean | undefined,\n now: number\n): Array<{ rect: Rect; alpha: number }> {\n const outlines: Array<{ rect: Rect; alpha: number }> = []\n const age = now - state.since\n if (pulse && state.previous && age < FOCUS_FADE_MS) {\n outlines.push({ rect: state.previous, alpha: 0.75 * (1 - age / FOCUS_FADE_MS) })\n }\n if (state.current) {\n const alpha = pulse\n ? 0.35 + 0.65 * (0.5 + 0.5 * Math.sin((now / FOCUS_PULSE_MS) * 2 * Math.PI))\n : 0.75\n outlines.push({ rect: state.current, alpha })\n }\n return outlines\n}\n\n/** Each canvas keeps its own focus transitions, so two documents' agents never collide. */\nconst focusHistories = new WeakMap<SkiaRenderer, Map<string, FocusTransition>>()\n\nfunction focusHistoryFor(r: SkiaRenderer): Map<string, FocusTransition> {\n const existing = focusHistories.get(r)\n if (existing) return existing\n const history = new Map<string, FocusTransition>()\n focusHistories.set(r, history)\n return history\n}\n\n/** The element being written, pulsing in the accent color, and the one it replaced fading out. */\nfunction drawFocus(r: SkiaRenderer, canvas: Canvas, cursor: PresenceCursor) {\n if (cursor.kind !== 'agent') return\n const key = cursor.id ?? cursor.name\n const history = focusHistoryFor(r)\n const now = performance.now()\n const state = nextFocus(history.get(key) ?? NO_FOCUS, cursor.focus, now)\n if (state === NO_FOCUS) history.delete(key)\n else history.set(key, state)\n const { r: red, g, b } = cursor.color\n r.auxStroke.setStrokeWidth(2)\n r.auxStroke.setPathEffect(null)\n for (const { rect, alpha } of focusOutlines(state, cursor.pulse, now)) {\n if (alpha <= 0) continue\n r.auxStroke.setColor(r.ck.Color4f(red, g, b, alpha))\n drawWorldRect(r, canvas, rect, r.auxStroke)\n }\n}\n\n/** One soft pass of light across what a finished preview built. */\nfunction drawSheen(r: SkiaRenderer, canvas: Canvas, cursor: PresenceCursor) {\n if (!cursor.sheen) return\n const age = performance.now() - cursor.sheen.at\n if (age < 0 || age >= SHEEN_MS) return\n const { rect } = cursor.sheen\n r.auxFill.setColor(r.ck.Color4f(1, 1, 1, 0.07 * Math.sin((age / SHEEN_MS) * Math.PI)))\n drawWorldRect(r, canvas, rect, r.auxFill)\n}\n\nfunction drawSelection(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph, cursor: PresenceCursor) {\n drawSheen(r, canvas, cursor)\n drawFocus(r, canvas, cursor)\n if (!cursor.selection?.length && !cursor.outline?.length) return\n const { r: red, g, b } = cursor.color\n r.auxStroke.setColor(r.ck.Color4f(red, g, b, 0.6))\n r.auxStroke.setStrokeWidth(1.5)\n r.auxStroke.setPathEffect(null)\n // Outlines of what is not a layer yet, such as JSX an agent is still streaming.\n for (const rect of cursor.outline ?? []) drawWorldRect(r, canvas, rect, r.auxStroke)\n for (const nodeId of cursor.selection ?? []) {\n const node = graph.getNode(nodeId)\n if (!node) continue\n // Map the corners through the node's world matrix, as the shape is rendered, so the\n // box tracks rotation, flips, and parent transforms.\n const corners = Matrix.mapPoints(getWorldMatrix(node, graph), [\n 0,\n 0,\n node.width,\n 0,\n node.width,\n node.height,\n 0,\n node.height\n ])\n const box = new r.ck.PathBuilder()\n box.moveTo(corners[0] * r.zoom + r.panX, corners[1] * r.zoom + r.panY)\n for (let i = 2; i < corners.length; i += 2) {\n box.lineTo(corners[i] * r.zoom + r.panX, corners[i + 1] * r.zoom + r.panY)\n }\n box.close()\n const path = box.detachAndDelete()\n canvas.drawPath(path, r.auxStroke)\n path.delete()\n }\n}\n\nfunction arrowPath(r: SkiaRenderer, x: number, y: number) {\n const S = CURSOR_SIZE\n const builder = new r.ck.PathBuilder()\n builder.moveTo(x, y)\n builder.lineTo(x, y + S * 1.35)\n builder.lineTo(x + S * 0.38, y + S * 1.0)\n builder.lineTo(x + S * 0.72, y + S * 1.5)\n builder.lineTo(x + S * 0.92, y + S * 1.38)\n builder.lineTo(x + S * 0.58, y + S * 0.88)\n builder.lineTo(x + S * 1.0, y + S * 0.82)\n builder.close()\n return builder.detachAndDelete()\n}\n\n/** The pointer, filled with a person's color, or for an agent its owner's, and outlined in white. */\nfunction drawArrow(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const path = arrowPath(r, x, y)\n r.auxStroke.setColor(r.ck.WHITE)\n r.auxStroke.setStrokeWidth(2)\n r.auxStroke.setPathEffect(null)\n canvas.drawPath(path, r.auxStroke)\n const { r: red, g, b } = cursor.color\n r.auxFill.setColor(r.ck.Color4f(red, g, b, 1))\n canvas.drawPath(path, r.auxFill)\n path.delete()\n}\n\n/** The provider's mark decoded for the canvas, or null while none is available. */\nfunction labelLogo(r: SkiaRenderer, bytes: Uint8Array | undefined): Image | null {\n if (!bytes) return null\n const cached = labelLogoImages.get(bytes)\n if (cached !== undefined) return cached\n const image = r.ck.MakeImageFromEncoded(bytes)\n labelLogoImages.set(bytes, image)\n return image\n}\n\n/**\n * A name pill: filled for people; for agents outlined in the owner's color, with the\n * provider's real mark before the name when the app supplied one.\n */\nfunction drawLabel(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor: PresenceCursor) {\n const provider = r.fontProvider\n if (!cursor.name || !provider) return\n const { r: red, g, b } = cursor.color\n const color = r.ck.Color4f(red, g, b, 1)\n const agent = cursor.kind === 'agent'\n const logo = agent ? labelLogo(r, cursor.logo) : null\n const badge = logo ? LABEL_LOGO_SIZE + LABEL_LOGO_GAP : 0\n // The status climbs through its dots while the agent rests; the name stays first.\n const label = cursor.status ? `${cursor.name} ${cursor.status}` : cursor.name\n const pillX = x + LABEL_OFFSET_X - LABEL_PADDING_X\n const pillY = y + LABEL_OFFSET_Y - LABEL_FONT_SIZE - LABEL_PADDING_Y + 2\n const pillHeight = LABEL_FONT_SIZE + LABEL_PADDING_Y * 2\n // Shaped like other canvas labels: kerning, fallback fonts, and RTL names.\n r.labelParagraphCache.use(\n r.ck,\n provider,\n label,\n LABEL_FONT_SIZE,\n LABEL_MAX_WIDTH,\n agent ? color : r.ck.WHITE,\n r.fontGeneration,\n ({ paragraph, metrics }) => {\n const pill = r.ck.RRectXY(\n r.ck.XYWHRect(pillX, pillY, badge + metrics.width + LABEL_PADDING_X * 2, pillHeight),\n 4,\n 4\n )\n r.auxFill.setColor(agent ? r.ck.WHITE : color)\n canvas.drawRRect(pill, r.auxFill)\n if (agent) {\n r.auxStroke.setColor(color)\n r.auxStroke.setStrokeWidth(1)\n r.auxStroke.setPathEffect(null)\n canvas.drawRRect(pill, r.auxStroke)\n if (logo) {\n r.auxFill.setColor(r.ck.Color4f(1, 1, 1, 1))\n canvas.drawImageRect(\n logo,\n r.ck.XYWHRect(0, 0, logo.width(), logo.height()),\n r.ck.XYWHRect(\n pillX + LABEL_PADDING_X,\n pillY + (pillHeight - LABEL_LOGO_SIZE) / 2,\n LABEL_LOGO_SIZE,\n LABEL_LOGO_SIZE\n ),\n r.auxFill\n )\n }\n }\n canvas.drawParagraph(\n paragraph,\n pillX + LABEL_PADDING_X + badge,\n pillY + (pillHeight - metrics.height) / 2\n )\n }\n )\n}\n\n/** Cursors of people and agents in screen space, with outlines of what they selected. */\nexport function drawPresenceCursors(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n cursors?: PresenceCursor[]\n): void {\n const history = focusHistoryFor(r)\n const drawn = new Set<string>()\n for (const cursor of cursors ?? []) {\n drawn.add(cursor.id ?? cursor.name)\n const x = cursor.x * r.zoom + r.panX\n const y = cursor.y * r.zoom + r.panY\n drawSelection(r, canvas, graph, cursor)\n drawArrow(r, canvas, x, y, cursor)\n drawLabel(r, canvas, x, y, cursor)\n }\n // A cursor no longer drawn (an agent at rest) leaves no outline to flash on its return.\n for (const key of history.keys()) if (!drawn.has(key)) history.delete(key)\n}\n"],"mappings":"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"}
@@ -1,11 +1,14 @@
1
1
  import { SkiaRenderer } from "../renderer.js";
2
2
  import { Canvas, SkPicture } from "canvaskit-wasm";
3
3
  import { VisualBounds } from "@pairdraw/scene-graph/geometry";
4
+ import { SceneGraph } from "@pairdraw/scene-graph";
4
5
  //#region src/canvas/renderer/picture.d.ts
5
6
  /** Run `draw` with the renderer's culling viewport set to world-space `bounds`. */
6
7
  declare function withWorldViewport<T>(r: SkiaRenderer, bounds: VisualBounds, draw: () => T): T;
8
+ /** Record one node, its children included, into a picture of world-space `bounds`. */
9
+ declare function recordNodePicture(r: SkiaRenderer, graph: SceneGraph, nodeId: string, bounds: VisualBounds, signal?: AbortSignal): SkPicture;
7
10
  /** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */
8
11
  declare function recordWorldPicture(r: SkiaRenderer, bounds: VisualBounds, draw: (canvas: Canvas) => void): SkPicture;
9
12
  //#endregion
10
- export { recordWorldPicture, withWorldViewport };
13
+ export { recordNodePicture, recordWorldPicture, withWorldViewport };
11
14
  //# sourceMappingURL=picture.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"picture.d.ts","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"mappings":";;;;;iBAOgB,kBAAkB,GAAG,GAAG,cAAc,QAAQ,cAAc,YAAY,IAAI;;iBAgB5E,mBACd,GAAG,cACH,QAAQ,cACR,OAAO,QAAQ,kBACd"}
1
+ {"version":3,"file":"picture.d.ts","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"mappings":";;;;;;iBAQgB,kBAAkB,GAAG,GAAG,cAAc,QAAQ,cAAc,YAAY,IAAI;;iBAgB5E,kBACd,GAAG,cACH,OAAO,YACP,gBACA,QAAQ,cACR,SAAS,cACR;;iBAUa,mBACd,GAAG,cACH,QAAQ,cACR,OAAO,QAAQ,kBACd"}
@@ -14,6 +14,18 @@ function withWorldViewport(r, bounds, draw) {
14
14
  r.worldViewport = previous;
15
15
  }
16
16
  }
17
+ /** Record one node, its children included, into a picture of world-space `bounds`. */
18
+ function recordNodePicture(r, graph, nodeId, bounds, signal) {
19
+ return recordWorldPicture(r, bounds, (canvas) => {
20
+ signal?.throwIfAborted();
21
+ const parentId = graph.getNode(nodeId)?.parentId;
22
+ const parent = parentId ? graph.getAbsolutePosition(parentId) : {
23
+ x: 0,
24
+ y: 0
25
+ };
26
+ r.renderNode(canvas, graph, nodeId, {}, parent.x, parent.y);
27
+ });
28
+ }
17
29
  /** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */
18
30
  function recordWorldPicture(r, bounds, draw) {
19
31
  const recorder = new r.ck.PictureRecorder();
@@ -26,6 +38,6 @@ function recordWorldPicture(r, bounds, draw) {
26
38
  }
27
39
  }
28
40
  //#endregion
29
- export { recordWorldPicture, withWorldViewport };
41
+ export { recordNodePicture, recordWorldPicture, withWorldViewport };
30
42
 
31
43
  //# sourceMappingURL=picture.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"picture.js","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { VisualBounds } from '@pairdraw/scene-graph/geometry'\n\nimport type { SkiaRenderer } from '#core/canvas/renderer'\n\n/** Run `draw` with the renderer's culling viewport set to world-space `bounds`. */\nexport function withWorldViewport<T>(r: SkiaRenderer, bounds: VisualBounds, draw: () => T): T {\n const previous = r.worldViewport\n r.worldViewport = {\n x: bounds.minX,\n y: bounds.minY,\n w: bounds.maxX - bounds.minX,\n h: bounds.maxY - bounds.minY\n }\n try {\n return draw()\n } finally {\n r.worldViewport = previous\n }\n}\n\n/** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */\nexport function recordWorldPicture(\n r: SkiaRenderer,\n bounds: VisualBounds,\n draw: (canvas: Canvas) => void\n): SkPicture {\n const recorder = new r.ck.PictureRecorder()\n try {\n const canvas = recorder.beginRecording(\n r.ck.LTRBRect(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY)\n )\n withWorldViewport(r, bounds, () => draw(canvas))\n return recorder.finishRecordingAsPicture()\n } finally {\n recorder.delete()\n }\n}\n"],"mappings":";;AAOA,SAAgB,kBAAqB,GAAiB,QAAsB,MAAkB;CAC5F,MAAM,WAAW,EAAE;CACnB,EAAE,gBAAgB;EAChB,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO,OAAO,OAAO;EACxB,GAAG,OAAO,OAAO,OAAO;CAC1B;CACA,IAAI;EACF,OAAO,KAAK;CACd,UAAU;EACR,EAAE,gBAAgB;CACpB;AACF;;AAGA,SAAgB,mBACd,GACA,QACA,MACW;CACX,MAAM,WAAW,IAAI,EAAE,GAAG,gBAAgB;CAC1C,IAAI;EACF,MAAM,SAAS,SAAS,eACtB,EAAE,GAAG,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI,CAClE;EACA,kBAAkB,GAAG,cAAc,KAAK,MAAM,CAAC;EAC/C,OAAO,SAAS,yBAAyB;CAC3C,UAAU;EACR,SAAS,OAAO;CAClB;AACF"}
1
+ {"version":3,"file":"picture.js","names":[],"sources":["../../../src/canvas/renderer/picture.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport type { VisualBounds } from '@pairdraw/scene-graph/geometry'\n\nimport type { SkiaRenderer } from '#core/canvas/renderer'\n\n/** Run `draw` with the renderer's culling viewport set to world-space `bounds`. */\nexport function withWorldViewport<T>(r: SkiaRenderer, bounds: VisualBounds, draw: () => T): T {\n const previous = r.worldViewport\n r.worldViewport = {\n x: bounds.minX,\n y: bounds.minY,\n w: bounds.maxX - bounds.minX,\n h: bounds.maxY - bounds.minY\n }\n try {\n return draw()\n } finally {\n r.worldViewport = previous\n }\n}\n\n/** Record one node, its children included, into a picture of world-space `bounds`. */\nexport function recordNodePicture(\n r: SkiaRenderer,\n graph: SceneGraph,\n nodeId: string,\n bounds: VisualBounds,\n signal?: AbortSignal\n): SkPicture {\n return recordWorldPicture(r, bounds, (canvas) => {\n signal?.throwIfAborted()\n const parentId = graph.getNode(nodeId)?.parentId\n const parent = parentId ? graph.getAbsolutePosition(parentId) : { x: 0, y: 0 }\n r.renderNode(canvas, graph, nodeId, {}, parent.x, parent.y)\n })\n}\n\n/** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */\nexport function recordWorldPicture(\n r: SkiaRenderer,\n bounds: VisualBounds,\n draw: (canvas: Canvas) => void\n): SkPicture {\n const recorder = new r.ck.PictureRecorder()\n try {\n const canvas = recorder.beginRecording(\n r.ck.LTRBRect(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY)\n )\n withWorldViewport(r, bounds, () => draw(canvas))\n return recorder.finishRecordingAsPicture()\n } finally {\n recorder.delete()\n }\n}\n"],"mappings":";;AAQA,SAAgB,kBAAqB,GAAiB,QAAsB,MAAkB;CAC5F,MAAM,WAAW,EAAE;CACnB,EAAE,gBAAgB;EAChB,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO,OAAO,OAAO;EACxB,GAAG,OAAO,OAAO,OAAO;CAC1B;CACA,IAAI;EACF,OAAO,KAAK;CACd,UAAU;EACR,EAAE,gBAAgB;CACpB;AACF;;AAGA,SAAgB,kBACd,GACA,OACA,QACA,QACA,QACW;CACX,OAAO,mBAAmB,GAAG,SAAS,WAAW;EAC/C,QAAQ,eAAe;EACvB,MAAM,WAAW,MAAM,QAAQ,MAAM,CAAC,EAAE;EACxC,MAAM,SAAS,WAAW,MAAM,oBAAoB,QAAQ,IAAI;GAAE,GAAG;GAAG,GAAG;EAAE;EAC7E,EAAE,WAAW,QAAQ,OAAO,QAAQ,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC;CAC5D,CAAC;AACH;;AAGA,SAAgB,mBACd,GACA,QACA,MACW;CACX,MAAM,WAAW,IAAI,EAAE,GAAG,gBAAgB;CAC1C,IAAI;EACF,MAAM,SAAS,SAAS,eACtB,EAAE,GAAG,SAAS,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,OAAO,IAAI,CAClE;EACA,kBAAkB,GAAG,cAAc,KAAK,MAAM,CAAC;EAC/C,OAAO,SAAS,yBAAyB;CAC3C,UAAU;EACR,SAAS,OAAO;CAClB;AACF"}
@@ -7,11 +7,19 @@ import { SceneGraph } from "@pairdraw/scene-graph";
7
7
  interface TransientCanvasPreview {
8
8
  graph: SceneGraph;
9
9
  pageId: string;
10
- picture: SkPicture;
10
+ /** The settled preview; absent while every element enters for the first time. */
11
+ picture?: SkPicture;
11
12
  /** Substitute a whole page child, including its proposed descendant layout. */
12
13
  replaceId?: string;
13
14
  /** Insert before this page-child index, or append when omitted. */
14
15
  insertIndex?: number;
16
+ /** New elements fading in over the picture, with how far their entrance has come (0 to 1). */
17
+ entrance?: {
18
+ pictures: SkPicture[];
19
+ progress: number;
20
+ };
21
+ /** How opaque the whole preview is while a finished call hands off to the committed nodes. */
22
+ fade?: number;
15
23
  }
16
24
  declare function hasTransientPreviews(r: SkiaRenderer, graph: SceneGraph): boolean;
17
25
  /** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */
@@ -1 +1 @@
1
- {"version":3,"file":"transient-previews.d.ts","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"mappings":";;;;;;UAOiB;EACf,OAAO;EACP;EACA,SAAS;;EAET;;EAEA;;iBASc,qBAAqB,GAAG,cAAc,OAAO;;iBAK7C,uBACd,GAAG,cACH,QAAQ,QACR,OAAO,YACP,UAAU"}
1
+ {"version":3,"file":"transient-previews.d.ts","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"mappings":";;;;;;UAOiB;EACf,OAAO;EACP;;EAEA,UAAU;;EAEV;;EAEA;;EAEA;IAAa,UAAU;IAAa;;;EAEpC;;iBASc,qBAAqB,GAAG,cAAc,OAAO;;iBA8B7C,uBACd,GAAG,cACH,QAAQ,QACR,OAAO,YACP,UAAU"}
@@ -5,6 +5,30 @@ function activePreviews(r, graph) {
5
5
  function hasTransientPreviews(r, graph) {
6
6
  return activePreviews(r, graph).length > 0;
7
7
  }
8
+ /** One preview picture, with new elements easing up 4 screen pixels while they fade in. */
9
+ function drawPreview(r, canvas, preview) {
10
+ const fade = preview.fade ?? 1;
11
+ if (fade <= 0) return;
12
+ try {
13
+ if (preview.picture) {
14
+ r.auxFill.setAlphaf(fade);
15
+ canvas.saveLayer(r.auxFill);
16
+ canvas.drawPicture(preview.picture);
17
+ canvas.restore();
18
+ }
19
+ const entrance = preview.entrance;
20
+ if (!entrance || entrance.progress <= 0) return;
21
+ r.auxFill.setAlphaf(fade * entrance.progress);
22
+ canvas.save();
23
+ canvas.translate(0, (1 - entrance.progress) * 4 / (r.zoom || 1));
24
+ canvas.saveLayer(r.auxFill);
25
+ for (const picture of entrance.pictures) canvas.drawPicture(picture);
26
+ canvas.restore();
27
+ canvas.restore();
28
+ } finally {
29
+ r.auxFill.setAlphaf(1);
30
+ }
31
+ }
8
32
  /** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */
9
33
  function renderPageWithPreviews(r, canvas, graph, overlays) {
10
34
  const previews = activePreviews(r, graph);
@@ -20,12 +44,14 @@ function renderPageWithPreviews(r, canvas, graph, overlays) {
20
44
  insertions.set(index, atIndex);
21
45
  }
22
46
  for (let index = 0; index <= children.length; index++) {
23
- for (const preview of insertions.get(index) ?? []) canvas.drawPicture(preview.picture);
47
+ for (const preview of insertions.get(index) ?? []) drawPreview(r, canvas, preview);
24
48
  const id = children[index];
25
49
  if (!id) continue;
26
50
  const replacement = replacements.get(id);
27
- if (replacement) canvas.drawPicture(replacement.picture);
28
- else r.renderNode(canvas, graph, id, overlays);
51
+ if (replacement) {
52
+ if (replacement.fade !== void 0 && replacement.fade < 1) r.renderNode(canvas, graph, id, overlays);
53
+ drawPreview(r, canvas, replacement);
54
+ } else r.renderNode(canvas, graph, id, overlays);
29
55
  }
30
56
  return true;
31
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transient-previews.js","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { RenderOverlays, SkiaRenderer } from '#core/canvas/renderer'\n\n/** Borrowed picture. The publisher owns disposal, including removal from every renderer. */\nexport interface TransientCanvasPreview {\n graph: SceneGraph\n pageId: string\n picture: SkPicture\n /** Substitute a whole page child, including its proposed descendant layout. */\n replaceId?: string\n /** Insert before this page-child index, or append when omitted. */\n insertIndex?: number\n}\n\nfunction activePreviews(r: SkiaRenderer, graph: SceneGraph): TransientCanvasPreview[] {\n return [...r.transientPreviews.values()].filter(\n (preview) => preview.graph === graph && preview.pageId === r.pageId\n )\n}\n\nexport function hasTransientPreviews(r: SkiaRenderer, graph: SceneGraph): boolean {\n return activePreviews(r, graph).length > 0\n}\n\n/** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */\nexport function renderPageWithPreviews(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n overlays: RenderOverlays\n): boolean {\n const previews = activePreviews(r, graph)\n if (previews.length === 0) return false\n const children = graph.getNode(r.pageId ?? graph.rootId)?.childIds ?? []\n const replacements = new Map<string, TransientCanvasPreview>()\n const insertions = new Map<number, TransientCanvasPreview[]>()\n for (const preview of previews) {\n if (preview.replaceId) {\n replacements.set(preview.replaceId, preview)\n } else {\n const index = Math.min(preview.insertIndex ?? children.length, children.length)\n const atIndex = insertions.get(index) ?? []\n atIndex.push(preview)\n insertions.set(index, atIndex)\n }\n }\n for (let index = 0; index <= children.length; index++) {\n for (const preview of insertions.get(index) ?? []) canvas.drawPicture(preview.picture)\n const id = children[index]\n if (!id) continue\n const replacement = replacements.get(id)\n if (replacement) canvas.drawPicture(replacement.picture)\n else r.renderNode(canvas, graph, id, overlays)\n }\n return true\n}\n"],"mappings":";AAiBA,SAAS,eAAe,GAAiB,OAA6C;CACpF,OAAO,CAAC,GAAG,EAAE,kBAAkB,OAAO,CAAC,CAAC,CAAC,QACtC,YAAY,QAAQ,UAAU,SAAS,QAAQ,WAAW,EAAE,MAC/D;AACF;AAEA,SAAgB,qBAAqB,GAAiB,OAA4B;CAChF,OAAO,eAAe,GAAG,KAAK,CAAC,CAAC,SAAS;AAC3C;;AAGA,SAAgB,uBACd,GACA,QACA,OACA,UACS;CACT,MAAM,WAAW,eAAe,GAAG,KAAK;CACxC,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,MAAM,WAAW,MAAM,QAAQ,EAAE,UAAU,MAAM,MAAM,CAAC,EAAE,YAAY,CAAC;CACvE,MAAM,+BAAe,IAAI,IAAoC;CAC7D,MAAM,6BAAa,IAAI,IAAsC;CAC7D,KAAK,MAAM,WAAW,UACpB,IAAI,QAAQ,WACV,aAAa,IAAI,QAAQ,WAAW,OAAO;MACtC;EACL,MAAM,QAAQ,KAAK,IAAI,QAAQ,eAAe,SAAS,QAAQ,SAAS,MAAM;EAC9E,MAAM,UAAU,WAAW,IAAI,KAAK,KAAK,CAAC;EAC1C,QAAQ,KAAK,OAAO;EACpB,WAAW,IAAI,OAAO,OAAO;CAC/B;CAEF,KAAK,IAAI,QAAQ,GAAG,SAAS,SAAS,QAAQ,SAAS;EACrD,KAAK,MAAM,WAAW,WAAW,IAAI,KAAK,KAAK,CAAC,GAAG,OAAO,YAAY,QAAQ,OAAO;EACrF,MAAM,KAAK,SAAS;EACpB,IAAI,CAAC,IAAI;EACT,MAAM,cAAc,aAAa,IAAI,EAAE;EACvC,IAAI,aAAa,OAAO,YAAY,YAAY,OAAO;OAClD,EAAE,WAAW,QAAQ,OAAO,IAAI,QAAQ;CAC/C;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"transient-previews.js","names":[],"sources":["../../../src/canvas/renderer/transient-previews.ts"],"sourcesContent":["import type { Canvas, SkPicture } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { RenderOverlays, SkiaRenderer } from '#core/canvas/renderer'\n\n/** Borrowed picture. The publisher owns disposal, including removal from every renderer. */\nexport interface TransientCanvasPreview {\n graph: SceneGraph\n pageId: string\n /** The settled preview; absent while every element enters for the first time. */\n picture?: SkPicture\n /** Substitute a whole page child, including its proposed descendant layout. */\n replaceId?: string\n /** Insert before this page-child index, or append when omitted. */\n insertIndex?: number\n /** New elements fading in over the picture, with how far their entrance has come (0 to 1). */\n entrance?: { pictures: SkPicture[]; progress: number }\n /** How opaque the whole preview is while a finished call hands off to the committed nodes. */\n fade?: number\n}\n\nfunction activePreviews(r: SkiaRenderer, graph: SceneGraph): TransientCanvasPreview[] {\n return [...r.transientPreviews.values()].filter(\n (preview) => preview.graph === graph && preview.pageId === r.pageId\n )\n}\n\nexport function hasTransientPreviews(r: SkiaRenderer, graph: SceneGraph): boolean {\n return activePreviews(r, graph).length > 0\n}\n\n/** One preview picture, with new elements easing up 4 screen pixels while they fade in. */\nfunction drawPreview(r: SkiaRenderer, canvas: Canvas, preview: TransientCanvasPreview): void {\n const fade = preview.fade ?? 1\n if (fade <= 0) return\n try {\n if (preview.picture) {\n r.auxFill.setAlphaf(fade)\n canvas.saveLayer(r.auxFill)\n canvas.drawPicture(preview.picture)\n canvas.restore()\n }\n const entrance = preview.entrance\n if (!entrance || entrance.progress <= 0) return\n r.auxFill.setAlphaf(fade * entrance.progress)\n canvas.save()\n canvas.translate(0, ((1 - entrance.progress) * 4) / (r.zoom || 1))\n canvas.saveLayer(r.auxFill)\n for (const picture of entrance.pictures) canvas.drawPicture(picture)\n canvas.restore()\n canvas.restore()\n } finally {\n r.auxFill.setAlphaf(1)\n }\n}\n\n/** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */\nexport function renderPageWithPreviews(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n overlays: RenderOverlays\n): boolean {\n const previews = activePreviews(r, graph)\n if (previews.length === 0) return false\n const children = graph.getNode(r.pageId ?? graph.rootId)?.childIds ?? []\n const replacements = new Map<string, TransientCanvasPreview>()\n const insertions = new Map<number, TransientCanvasPreview[]>()\n for (const preview of previews) {\n if (preview.replaceId) {\n replacements.set(preview.replaceId, preview)\n } else {\n const index = Math.min(preview.insertIndex ?? children.length, children.length)\n const atIndex = insertions.get(index) ?? []\n atIndex.push(preview)\n insertions.set(index, atIndex)\n }\n }\n for (let index = 0; index <= children.length; index++) {\n for (const preview of insertions.get(index) ?? []) drawPreview(r, canvas, preview)\n const id = children[index]\n if (!id) continue\n const replacement = replacements.get(id)\n if (replacement) {\n // A fading replacement uncovers the committed node it replaced, so no frame is blank.\n if (replacement.fade !== undefined && replacement.fade < 1)\n r.renderNode(canvas, graph, id, overlays)\n drawPreview(r, canvas, replacement)\n } else r.renderNode(canvas, graph, id, overlays)\n }\n return true\n}\n"],"mappings":";AAsBA,SAAS,eAAe,GAAiB,OAA6C;CACpF,OAAO,CAAC,GAAG,EAAE,kBAAkB,OAAO,CAAC,CAAC,CAAC,QACtC,YAAY,QAAQ,UAAU,SAAS,QAAQ,WAAW,EAAE,MAC/D;AACF;AAEA,SAAgB,qBAAqB,GAAiB,OAA4B;CAChF,OAAO,eAAe,GAAG,KAAK,CAAC,CAAC,SAAS;AAC3C;;AAGA,SAAS,YAAY,GAAiB,QAAgB,SAAuC;CAC3F,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,QAAQ,GAAG;CACf,IAAI;EACF,IAAI,QAAQ,SAAS;GACnB,EAAE,QAAQ,UAAU,IAAI;GACxB,OAAO,UAAU,EAAE,OAAO;GAC1B,OAAO,YAAY,QAAQ,OAAO;GAClC,OAAO,QAAQ;EACjB;EACA,MAAM,WAAW,QAAQ;EACzB,IAAI,CAAC,YAAY,SAAS,YAAY,GAAG;EACzC,EAAE,QAAQ,UAAU,OAAO,SAAS,QAAQ;EAC5C,OAAO,KAAK;EACZ,OAAO,UAAU,IAAK,IAAI,SAAS,YAAY,KAAM,EAAE,QAAQ,EAAE;EACjE,OAAO,UAAU,EAAE,OAAO;EAC1B,KAAK,MAAM,WAAW,SAAS,UAAU,OAAO,YAAY,OAAO;EACnE,OAAO,QAAQ;EACf,OAAO,QAAQ;CACjB,UAAU;EACR,EAAE,QAAQ,UAAU,CAAC;CACvB;AACF;;AAGA,SAAgB,uBACd,GACA,QACA,OACA,UACS;CACT,MAAM,WAAW,eAAe,GAAG,KAAK;CACxC,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,MAAM,WAAW,MAAM,QAAQ,EAAE,UAAU,MAAM,MAAM,CAAC,EAAE,YAAY,CAAC;CACvE,MAAM,+BAAe,IAAI,IAAoC;CAC7D,MAAM,6BAAa,IAAI,IAAsC;CAC7D,KAAK,MAAM,WAAW,UACpB,IAAI,QAAQ,WACV,aAAa,IAAI,QAAQ,WAAW,OAAO;MACtC;EACL,MAAM,QAAQ,KAAK,IAAI,QAAQ,eAAe,SAAS,QAAQ,SAAS,MAAM;EAC9E,MAAM,UAAU,WAAW,IAAI,KAAK,KAAK,CAAC;EAC1C,QAAQ,KAAK,OAAO;EACpB,WAAW,IAAI,OAAO,OAAO;CAC/B;CAEF,KAAK,IAAI,QAAQ,GAAG,SAAS,SAAS,QAAQ,SAAS;EACrD,KAAK,MAAM,WAAW,WAAW,IAAI,KAAK,KAAK,CAAC,GAAG,YAAY,GAAG,QAAQ,OAAO;EACjF,MAAM,KAAK,SAAS;EACpB,IAAI,CAAC,IAAI;EACT,MAAM,cAAc,aAAa,IAAI,EAAE;EACvC,IAAI,aAAa;GAEf,IAAI,YAAY,SAAS,KAAA,KAAa,YAAY,OAAO,GACvD,EAAE,WAAW,QAAQ,OAAO,IAAI,QAAQ;GAC1C,YAAY,GAAG,QAAQ,WAAW;EACpC,OAAO,EAAE,WAAW,QAAQ,OAAO,IAAI,QAAQ;CACjD;CACA,OAAO;AACT"}
@@ -31,8 +31,19 @@ interface PresenceCursor {
31
31
  x: number;
32
32
  y: number;
33
33
  selection?: string[];
34
+ /** What the label says after the name while the agent works, such as `Writing...`. */
35
+ status?: string;
34
36
  /** Outlines in world coordinates of what is not a layer yet, such as streamed JSX. */
35
37
  outline?: Rect[];
38
+ /** The element being written, outlined with a soft pulse while the agent rests on it. */
39
+ focus?: Rect;
40
+ /** Whether the focus outline may pulse; false under reduced motion. */
41
+ pulse?: boolean;
42
+ /** One sheen over what a finished preview built, drawn once at `at`. */
43
+ sheen?: {
44
+ rect: Rect;
45
+ at: number;
46
+ };
36
47
  /** PNG bytes of the mark of what an agent runs on, drawn in its label. */
37
48
  logo?: Uint8Array;
38
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/renderer/types.ts"],"mappings":";;;;;;;;;;;;UAYiB;EACf,OAAO;EACP,YAAY;;UAGG;EACf,YAAY;EACZ,MAAM;EACN,MAAM;;KAGI;;UAGK;;EAEf;EACA;EACA;;EAEA,OAAO;EACP;EACA;EACA;;EAEA,UAAU;;EAEV,OAAO;;;;;;;UAQQ;WACN,OAAO;WACP;WACA,SAAS;;UAGH;;EAEf;;EAEA,aAAa,oBAAoB;;EAEjC,aAAa,oBAAoB;;EAEjC,cAAc;EACd;;EAEA;;EAEA;;EAEA;;EAEA,eAAe;;EAEf,YAAY;EACZ;EACA,kBAAkB;EAClB;;EAEA;EACA,aAAa;EACb,UAAU;EACV,aAAa;EACb,SAAS;EACT,kBAAkB;EAClB;EACA;IACE;IACA;IACA;IACA;;EAEF;IACE;IACA;;IAEA;IACA;IACA;;;EAGF;IAAkB;;;EAElB,mBAAmB;;EAEnB,kBAAkB;EAClB;IACE,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,aAAa;IACb,sBAAsB;IACtB;IACA;IACA;IACA;;EAEF,cAAc;EACd;IACE;IACA,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,SAAS;IACT,uBAAuB;IACvB,yBAAyB;IACzB,kBAAkB;IAClB;MAAsB;MAAsB;;;IAE5C;;IAEA,kBAAkB;;IAElB;;IAEA;;IAEA,eAAe;;EAEjB,kBAAkB;EAClB,uBAAuB;EACvB"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/canvas/renderer/types.ts"],"mappings":";;;;;;;;;;;;UAYiB;EACf,OAAO;EACP,YAAY;;UAGG;EACf,YAAY;EACZ,MAAM;EACN,MAAM;;KAGI;;UAGK;;EAEf;EACA;EACA;;EAEA,OAAO;EACP;EACA;EACA;;EAEA;;EAEA,UAAU;;EAEV,QAAQ;;EAER;;EAEA;IAAU,MAAM;IAAM;;;EAEtB,OAAO;;;;;;;UAQQ;WACN,OAAO;WACP;WACA,SAAS;;UAGH;;EAEf;;EAEA,aAAa,oBAAoB;;EAEjC,aAAa,oBAAoB;;EAEjC,cAAc;EACd;;EAEA;;EAEA;;EAEA;;EAEA,eAAe;;EAEf,YAAY;EACZ;EACA,kBAAkB;EAClB;;EAEA;EACA,aAAa;EACb,UAAU;EACV,aAAa;EACb,SAAS;EACT,kBAAkB;EAClB;EACA;IACE;IACA;IACA;IACA;;EAEF;IACE;IACA;;IAEA;IACA;IACA;;;EAGF;IAAkB;;;EAElB,mBAAmB;;EAEnB,kBAAkB;EAClB;IACE,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,aAAa;IACb,sBAAsB;IACtB;IACA;IACA;IACA;;EAEF,cAAc;EACd;IACE;IACA,UAAU;IACV,UAAU;MACR;MACA;MACA,cAAc;MACd,YAAY;;IAEd,SAAS;IACT,uBAAuB;IACvB,yBAAyB;IACzB,kBAAkB;IAClB;MAAsB;MAAsB;;;IAE5C;;IAEA,kBAAkB;;IAElB;;IAEA;;IAEA,eAAe;;EAEjB,kBAAkB;EAClB,uBAAuB;EACvB"}
@@ -1,4 +1,5 @@
1
1
  import { ResourceCache } from "../cache/resource.js";
2
+ import { TransientCanvasPreview } from "./renderer/transient-previews.js";
2
3
  import { ImagePreviewCache } from "./images/previews.js";
3
4
  import { FontResolutionSnapshot } from "../text/resolver/types.js";
4
5
  import { LabelParagraphCache } from "./labels/paragraph-cache.js";
@@ -23,7 +24,6 @@ import { NodeFontReadiness } from "./text/index.js";
23
24
  import { EffectRasterCache } from "./renderer/effect-raster-cache.js";
24
25
  import { TiledSceneController } from "./renderer/tiles/controller.js";
25
26
  import "./renderer/tiles/index.js";
26
- import { TransientCanvasPreview } from "./renderer/transient-previews.js";
27
27
  import { Blender, Canvas, CanvasKit, Font, FontMgr, Image, ImageFilter, MaskFilter, Paint, RuntimeEffect, SkPicture, Surface, TextureSource, TypefaceFontProvider } from "canvaskit-wasm";
28
28
  import { RenderColorSpace, ResolvedRenderColor } from "@pairdraw/scene-graph/color";
29
29
  import { ColorProfile, Fill, SceneGraph, SceneNode, Stroke } from "@pairdraw/scene-graph";
@@ -1,9 +1,13 @@
1
1
  import { StagedJSXPreview } from "./stage.js";
2
2
  import { CanvasKit, SkPicture } from "canvaskit-wasm";
3
+ import { VisualBounds } from "@pairdraw/scene-graph/geometry";
4
+ import { SceneGraph } from "@pairdraw/scene-graph";
3
5
  //#region src/design-jsx/preview/picture.d.ts
4
6
  interface JSXPreviewRecorder {
5
7
  /** Record `staged` as a picture the caller owns, even when its request becomes stale. */
6
8
  record(staged: StagedJSXPreview, signal: AbortSignal): Promise<SkPicture | null>;
9
+ /** Record one layer of a staged graph, for an entrance drawn apart from the rest. */
10
+ recordNode(graph: SceneGraph, nodeId: string, bounds: VisualBounds, signal: AbortSignal): Promise<SkPicture | null>;
7
11
  /** Free the private renderer once the records already asked for finish. */
8
12
  destroy(): void;
9
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"picture.d.ts","names":[],"sources":["../../../src/design-jsx/preview/picture.ts"],"mappings":";;;UA0CiB;;EAEf,OAAO,QAAQ,kBAAkB,QAAQ,cAAc,QAAQ;;EAE/D;;;;;;;;iBASc,yBAAyB,IAAI,YAAY"}
1
+ {"version":3,"file":"picture.d.ts","names":[],"sources":["../../../src/design-jsx/preview/picture.ts"],"mappings":";;;;;UA2CiB;;EAEf,OAAO,QAAQ,kBAAkB,QAAQ,cAAc,QAAQ;;EAE/D,WACE,OAAO,YACP,gBACA,QAAQ,cACR,QAAQ,cACP,QAAQ;;EAEX;;;;;;;;iBASc,yBAAyB,IAAI,YAAY"}
@@ -1,4 +1,4 @@
1
- import { recordWorldPicture } from "../../canvas/renderer/picture.js";
1
+ import { recordNodePicture, recordWorldPicture } from "../../canvas/renderer/picture.js";
2
2
  import { SkiaRenderer } from "../../canvas/renderer.js";
3
3
  import { computeDescendantVisualBounds } from "@pairdraw/scene-graph/geometry";
4
4
  //#region src/design-jsx/preview/picture.ts
@@ -50,12 +50,24 @@ function createJSXPreviewRecorder(ck) {
50
50
  current.invalidateAllPictures({ keepShapedText: true });
51
51
  return recordStaged(current, staged, signal);
52
52
  }
53
+ async function recordNodeNext(graph, nodeId, bounds, signal) {
54
+ signal.throwIfAborted();
55
+ const current = destroyed ? null : await rendererFor();
56
+ if (!current) return null;
57
+ signal.throwIfAborted();
58
+ return recordNodePicture(current, graph, nodeId, bounds, signal);
59
+ }
53
60
  return {
54
61
  record(staged, signal) {
55
62
  const result = queue.then(() => recordNext(staged, signal));
56
63
  queue = result.catch(() => void 0);
57
64
  return result;
58
65
  },
66
+ recordNode(graph, nodeId, bounds, signal) {
67
+ const result = queue.then(() => recordNodeNext(graph, nodeId, bounds, signal));
68
+ queue = result.catch(() => void 0);
69
+ return result;
70
+ },
59
71
  destroy() {
60
72
  destroyed = true;
61
73
  const release = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"picture.js","names":[],"sources":["../../../src/design-jsx/preview/picture.ts"],"sourcesContent":["import type { CanvasKit, SkPicture } from 'canvaskit-wasm'\n\nimport { computeDescendantVisualBounds, type VisualBounds } from '@pairdraw/scene-graph/geometry'\n\nimport { SkiaRenderer } from '#core/canvas/renderer'\nimport { recordWorldPicture } from '#core/canvas/renderer/picture'\n\nimport type { StagedJSXPreview } from './stage'\n\nconst MAX_PREVIEW_DIMENSION = 8192\n\nfunction fitsPreview({ minX, minY, maxX, maxY }: VisualBounds): boolean {\n const width = maxX - minX\n const height = maxY - minY\n return (\n Number.isFinite(width + height) &&\n width > 0 &&\n height > 0 &&\n width <= MAX_PREVIEW_DIMENSION &&\n height <= MAX_PREVIEW_DIMENSION\n )\n}\n\nasync function recordStaged(\n renderer: SkiaRenderer,\n { graph, pageId, nodeIds }: StagedJSXPreview,\n signal: AbortSignal\n): Promise<SkPicture | null> {\n renderer.pageId = pageId\n await renderer.prepareForExport(graph, pageId, nodeIds)\n signal.throwIfAborted()\n const bounds = computeDescendantVisualBounds(\n nodeIds,\n (id) => graph.getNode(id),\n (id) => graph.getAbsolutePosition(id)\n )\n if (!bounds || !fitsPreview(bounds)) return null\n return recordWorldPicture(renderer, bounds, (canvas) => {\n for (const id of nodeIds) renderer.renderNode(canvas, graph, id, {})\n })\n}\n\nexport interface JSXPreviewRecorder {\n /** Record `staged` as a picture the caller owns, even when its request becomes stale. */\n record(staged: StagedJSXPreview, signal: AbortSignal): Promise<SkPicture | null>\n /** Free the private renderer once the records already asked for finish. */\n destroy(): void\n}\n\n/**\n * A private renderer that records preview pictures one at a time, for previews of JSX that is\n * still streaming. Each record draws a new graph, so only what identical text shaped to carries\n * over: a preview that grows measures just its new text instead of all of it again. Neither\n * speculative nodes nor renderer caches enter the live document.\n */\nexport function createJSXPreviewRecorder(ck: CanvasKit): JSXPreviewRecorder {\n let renderer: SkiaRenderer | null = null\n let destroyed = false\n // Records share one renderer, whose caches and page one record at a time may use.\n let queue: Promise<unknown> = Promise.resolve()\n\n async function rendererFor(): Promise<SkiaRenderer | null> {\n if (renderer) return renderer\n const surface = ck.MakeSurface(1, 1)\n if (!surface) return null\n const created = new SkiaRenderer(ck, surface)\n // Loading fonts drops every cache, so it happens once rather than before each record; a\n // renderer whose fonts failed to load is not kept, so the next record tries again.\n try {\n await created.loadFonts()\n } catch (error) {\n created.destroy()\n throw error\n }\n renderer = created\n return created\n }\n\n async function recordNext(\n staged: StagedJSXPreview,\n signal: AbortSignal\n ): Promise<SkPicture | null> {\n signal.throwIfAborted()\n const current = destroyed ? null : await rendererFor()\n if (!current) return null\n signal.throwIfAborted()\n // Layer IDs repeat between staged graphs with different content, so nothing keyed by them stays.\n current.invalidateAllPictures({ keepShapedText: true })\n return recordStaged(current, staged, signal)\n }\n\n return {\n record(staged, signal) {\n const result = queue.then(() => recordNext(staged, signal))\n queue = result.catch(() => undefined)\n return result\n },\n destroy() {\n destroyed = true\n const release = () => {\n renderer?.destroy()\n renderer = null\n }\n queue = queue.then(release)\n }\n }\n}\n"],"mappings":";;;;AASA,MAAM,wBAAwB;AAE9B,SAAS,YAAY,EAAE,MAAM,MAAM,MAAM,QAA+B;CACtE,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,OAAO;CACtB,OACE,OAAO,SAAS,QAAQ,MAAM,KAC9B,QAAQ,KACR,SAAS,KACT,SAAS,yBACT,UAAU;AAEd;AAEA,eAAe,aACb,UACA,EAAE,OAAO,QAAQ,WACjB,QAC2B;CAC3B,SAAS,SAAS;CAClB,MAAM,SAAS,iBAAiB,OAAO,QAAQ,OAAO;CACtD,OAAO,eAAe;CACtB,MAAM,SAAS,8BACb,UACC,OAAO,MAAM,QAAQ,EAAE,IACvB,OAAO,MAAM,oBAAoB,EAAE,CACtC;CACA,IAAI,CAAC,UAAU,CAAC,YAAY,MAAM,GAAG,OAAO;CAC5C,OAAO,mBAAmB,UAAU,SAAS,WAAW;EACtD,KAAK,MAAM,MAAM,SAAS,SAAS,WAAW,QAAQ,OAAO,IAAI,CAAC,CAAC;CACrE,CAAC;AACH;;;;;;;AAeA,SAAgB,yBAAyB,IAAmC;CAC1E,IAAI,WAAgC;CACpC,IAAI,YAAY;CAEhB,IAAI,QAA0B,QAAQ,QAAQ;CAE9C,eAAe,cAA4C;EACzD,IAAI,UAAU,OAAO;EACrB,MAAM,UAAU,GAAG,YAAY,GAAG,CAAC;EACnC,IAAI,CAAC,SAAS,OAAO;EACrB,MAAM,UAAU,IAAI,aAAa,IAAI,OAAO;EAG5C,IAAI;GACF,MAAM,QAAQ,UAAU;EAC1B,SAAS,OAAO;GACd,QAAQ,QAAQ;GAChB,MAAM;EACR;EACA,WAAW;EACX,OAAO;CACT;CAEA,eAAe,WACb,QACA,QAC2B;EAC3B,OAAO,eAAe;EACtB,MAAM,UAAU,YAAY,OAAO,MAAM,YAAY;EACrD,IAAI,CAAC,SAAS,OAAO;EACrB,OAAO,eAAe;EAEtB,QAAQ,sBAAsB,EAAE,gBAAgB,KAAK,CAAC;EACtD,OAAO,aAAa,SAAS,QAAQ,MAAM;CAC7C;CAEA,OAAO;EACL,OAAO,QAAQ,QAAQ;GACrB,MAAM,SAAS,MAAM,WAAW,WAAW,QAAQ,MAAM,CAAC;GAC1D,QAAQ,OAAO,YAAY,KAAA,CAAS;GACpC,OAAO;EACT;EACA,UAAU;GACR,YAAY;GACZ,MAAM,gBAAgB;IACpB,UAAU,QAAQ;IAClB,WAAW;GACb;GACA,QAAQ,MAAM,KAAK,OAAO;EAC5B;CACF;AACF"}
1
+ {"version":3,"file":"picture.js","names":[],"sources":["../../../src/design-jsx/preview/picture.ts"],"sourcesContent":["import type { CanvasKit, SkPicture } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { computeDescendantVisualBounds, type VisualBounds } from '@pairdraw/scene-graph/geometry'\n\nimport { SkiaRenderer } from '#core/canvas/renderer'\nimport { recordNodePicture, recordWorldPicture } from '#core/canvas/renderer/picture'\n\nimport type { StagedJSXPreview } from './stage'\n\nconst MAX_PREVIEW_DIMENSION = 8192\n\nfunction fitsPreview({ minX, minY, maxX, maxY }: VisualBounds): boolean {\n const width = maxX - minX\n const height = maxY - minY\n return (\n Number.isFinite(width + height) &&\n width > 0 &&\n height > 0 &&\n width <= MAX_PREVIEW_DIMENSION &&\n height <= MAX_PREVIEW_DIMENSION\n )\n}\n\nasync function recordStaged(\n renderer: SkiaRenderer,\n { graph, pageId, nodeIds }: StagedJSXPreview,\n signal: AbortSignal\n): Promise<SkPicture | null> {\n renderer.pageId = pageId\n await renderer.prepareForExport(graph, pageId, nodeIds)\n signal.throwIfAborted()\n const bounds = computeDescendantVisualBounds(\n nodeIds,\n (id) => graph.getNode(id),\n (id) => graph.getAbsolutePosition(id)\n )\n if (!bounds || !fitsPreview(bounds)) return null\n return recordWorldPicture(renderer, bounds, (canvas) => {\n for (const id of nodeIds) renderer.renderNode(canvas, graph, id, {})\n })\n}\n\nexport interface JSXPreviewRecorder {\n /** Record `staged` as a picture the caller owns, even when its request becomes stale. */\n record(staged: StagedJSXPreview, signal: AbortSignal): Promise<SkPicture | null>\n /** Record one layer of a staged graph, for an entrance drawn apart from the rest. */\n recordNode(\n graph: SceneGraph,\n nodeId: string,\n bounds: VisualBounds,\n signal: AbortSignal\n ): Promise<SkPicture | null>\n /** Free the private renderer once the records already asked for finish. */\n destroy(): void\n}\n\n/**\n * A private renderer that records preview pictures one at a time, for previews of JSX that is\n * still streaming. Each record draws a new graph, so only what identical text shaped to carries\n * over: a preview that grows measures just its new text instead of all of it again. Neither\n * speculative nodes nor renderer caches enter the live document.\n */\nexport function createJSXPreviewRecorder(ck: CanvasKit): JSXPreviewRecorder {\n let renderer: SkiaRenderer | null = null\n let destroyed = false\n // Records share one renderer, whose caches and page one record at a time may use.\n let queue: Promise<unknown> = Promise.resolve()\n\n async function rendererFor(): Promise<SkiaRenderer | null> {\n if (renderer) return renderer\n const surface = ck.MakeSurface(1, 1)\n if (!surface) return null\n const created = new SkiaRenderer(ck, surface)\n // Loading fonts drops every cache, so it happens once rather than before each record; a\n // renderer whose fonts failed to load is not kept, so the next record tries again.\n try {\n await created.loadFonts()\n } catch (error) {\n created.destroy()\n throw error\n }\n renderer = created\n return created\n }\n\n async function recordNext(\n staged: StagedJSXPreview,\n signal: AbortSignal\n ): Promise<SkPicture | null> {\n signal.throwIfAborted()\n const current = destroyed ? null : await rendererFor()\n if (!current) return null\n signal.throwIfAborted()\n // Layer IDs repeat between staged graphs with different content, so nothing keyed by them stays.\n current.invalidateAllPictures({ keepShapedText: true })\n return recordStaged(current, staged, signal)\n }\n\n async function recordNodeNext(\n graph: SceneGraph,\n nodeId: string,\n bounds: VisualBounds,\n signal: AbortSignal\n ): Promise<SkPicture | null> {\n signal.throwIfAborted()\n const current = destroyed ? null : await rendererFor()\n if (!current) return null\n signal.throwIfAborted()\n return recordNodePicture(current, graph, nodeId, bounds, signal)\n }\n\n return {\n record(staged, signal) {\n const result = queue.then(() => recordNext(staged, signal))\n queue = result.catch(() => undefined)\n return result\n },\n recordNode(graph, nodeId, bounds, signal) {\n const result = queue.then(() => recordNodeNext(graph, nodeId, bounds, signal))\n queue = result.catch(() => undefined)\n return result\n },\n destroy() {\n destroyed = true\n const release = () => {\n renderer?.destroy()\n renderer = null\n }\n queue = queue.then(release)\n }\n }\n}\n"],"mappings":";;;;AAUA,MAAM,wBAAwB;AAE9B,SAAS,YAAY,EAAE,MAAM,MAAM,MAAM,QAA+B;CACtE,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,OAAO;CACtB,OACE,OAAO,SAAS,QAAQ,MAAM,KAC9B,QAAQ,KACR,SAAS,KACT,SAAS,yBACT,UAAU;AAEd;AAEA,eAAe,aACb,UACA,EAAE,OAAO,QAAQ,WACjB,QAC2B;CAC3B,SAAS,SAAS;CAClB,MAAM,SAAS,iBAAiB,OAAO,QAAQ,OAAO;CACtD,OAAO,eAAe;CACtB,MAAM,SAAS,8BACb,UACC,OAAO,MAAM,QAAQ,EAAE,IACvB,OAAO,MAAM,oBAAoB,EAAE,CACtC;CACA,IAAI,CAAC,UAAU,CAAC,YAAY,MAAM,GAAG,OAAO;CAC5C,OAAO,mBAAmB,UAAU,SAAS,WAAW;EACtD,KAAK,MAAM,MAAM,SAAS,SAAS,WAAW,QAAQ,OAAO,IAAI,CAAC,CAAC;CACrE,CAAC;AACH;;;;;;;AAsBA,SAAgB,yBAAyB,IAAmC;CAC1E,IAAI,WAAgC;CACpC,IAAI,YAAY;CAEhB,IAAI,QAA0B,QAAQ,QAAQ;CAE9C,eAAe,cAA4C;EACzD,IAAI,UAAU,OAAO;EACrB,MAAM,UAAU,GAAG,YAAY,GAAG,CAAC;EACnC,IAAI,CAAC,SAAS,OAAO;EACrB,MAAM,UAAU,IAAI,aAAa,IAAI,OAAO;EAG5C,IAAI;GACF,MAAM,QAAQ,UAAU;EAC1B,SAAS,OAAO;GACd,QAAQ,QAAQ;GAChB,MAAM;EACR;EACA,WAAW;EACX,OAAO;CACT;CAEA,eAAe,WACb,QACA,QAC2B;EAC3B,OAAO,eAAe;EACtB,MAAM,UAAU,YAAY,OAAO,MAAM,YAAY;EACrD,IAAI,CAAC,SAAS,OAAO;EACrB,OAAO,eAAe;EAEtB,QAAQ,sBAAsB,EAAE,gBAAgB,KAAK,CAAC;EACtD,OAAO,aAAa,SAAS,QAAQ,MAAM;CAC7C;CAEA,eAAe,eACb,OACA,QACA,QACA,QAC2B;EAC3B,OAAO,eAAe;EACtB,MAAM,UAAU,YAAY,OAAO,MAAM,YAAY;EACrD,IAAI,CAAC,SAAS,OAAO;EACrB,OAAO,eAAe;EACtB,OAAO,kBAAkB,SAAS,OAAO,QAAQ,QAAQ,MAAM;CACjE;CAEA,OAAO;EACL,OAAO,QAAQ,QAAQ;GACrB,MAAM,SAAS,MAAM,WAAW,WAAW,QAAQ,MAAM,CAAC;GAC1D,QAAQ,OAAO,YAAY,KAAA,CAAS;GACpC,OAAO;EACT;EACA,WAAW,OAAO,QAAQ,QAAQ,QAAQ;GACxC,MAAM,SAAS,MAAM,WAAW,eAAe,OAAO,QAAQ,QAAQ,MAAM,CAAC;GAC7E,QAAQ,OAAO,YAAY,KAAA,CAAS;GACpC,OAAO;EACT;EACA,UAAU;GACR,YAAY;GACZ,MAAM,gBAAgB;IACpB,UAAU,QAAQ;IAClB,WAAW;GACb;GACA,QAAQ,MAAM,KAAK,OAAO;EAC5B;CACF;AACF"}
@@ -12,6 +12,8 @@ interface StagedJSXPreview {
12
12
  replaceId?: string;
13
13
  /** Page insertion slot when the preview adds new top-level nodes. */
14
14
  insertIndex?: number;
15
+ /** The source position each rendered layer came from, so restages keep an element's identity. */
16
+ sources: ReadonlyMap<string, number>;
15
17
  }
16
18
  /** Clone the whole affected page child, preserving ancestors, siblings, padding and layout modes. */
17
19
  declare function stageJSXPreview(source: SceneGraph, tree: TreeNode, input: RenderPlacementInput, pageId: string, signal?: AbortSignal): Promise<StagedJSXPreview | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"stage.d.ts","names":[],"sources":["../../../src/design-jsx/preview/stage.ts"],"mappings":";;;;UAaiB;EACf,OAAO;EACP;EACA;;EAEA;;EAEA;;EAEA;;;iBAgBoB,gBACpB,QAAQ,YACR,MAAM,UACN,OAAO,sBACP,gBACA,SAAS,cACR,QAAQ"}
1
+ {"version":3,"file":"stage.d.ts","names":[],"sources":["../../../src/design-jsx/preview/stage.ts"],"mappings":";;;;UAaiB;EACf,OAAO;EACP;EACA;;EAEA;;EAEA;;EAEA;;EAEA,SAAS;;;iBAgBW,gBACpB,QAAQ,YACR,MAAM,UACN,OAAO,sBACP,gBACA,SAAS,cACR,QAAQ"}
@@ -26,10 +26,18 @@ async function stageJSXPreview(source, tree, input, pageId, signal) {
26
26
  graph.variables = structuredClone(source.variables);
27
27
  graph.variableCollections = structuredClone(source.variableCollections);
28
28
  const results = [];
29
+ const sources = /* @__PURE__ */ new Map();
30
+ const onNode = (element, node) => {
31
+ const sourceStart = element.sourceStart;
32
+ if (typeof sourceStart === "number") sources.set(node.id, sourceStart);
33
+ };
29
34
  for (const root of tree.type === "" ? tree.children : [tree]) {
30
35
  if (typeof root === "string") continue;
31
36
  signal?.throwIfAborted();
32
- results.push(await renderTree(graph, root, placement));
37
+ results.push(await renderTree(graph, root, {
38
+ ...placement,
39
+ onNode
40
+ }));
33
41
  }
34
42
  signal?.throwIfAborted();
35
43
  if (results.length === 0) return null;
@@ -40,7 +48,8 @@ async function stageJSXPreview(source, tree, input, pageId, signal) {
40
48
  nodeIds: owner && graph.getNode(owner) ? [owner] : results.map((result) => result.id),
41
49
  renderedIds: results.map((result) => result.id),
42
50
  replaceId: owner,
43
- insertIndex: placement.insertIndex
51
+ insertIndex: placement.insertIndex,
52
+ sources
44
53
  };
45
54
  }
46
55
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"stage.js","names":[],"sources":["../../../src/design-jsx/preview/stage.ts"],"sourcesContent":["import type { RenderResult, TreeNode } from '@pairdraw/design-jsx'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport {\n finishRenderPlacement,\n resolveRenderPlacement,\n type RenderPlacementInput\n} from '#core/design-jsx/placement'\nimport { renderTree } from '#core/design-jsx/renderer'\nimport { extractPageContext, findPageChildId } from '#core/io/subgraph'\n\nconst MAX_PREVIEW_CONTEXT_NODES = 1000\n\nexport interface StagedJSXPreview {\n graph: SceneGraph\n pageId: string\n nodeIds: string[]\n /** The roots the JSX rendered, in source order, even when `nodeIds` names their owner. */\n renderedIds: string[]\n /** Existing page child to replace visually, without changing the source graph. */\n replaceId?: string\n /** Page insertion slot when the preview adds new top-level nodes. */\n insertIndex?: number\n}\n\nfunction contextFits(graph: SceneGraph, rootId: string): boolean {\n const pending = [rootId]\n let count = 0\n while (pending.length > 0) {\n if (++count > MAX_PREVIEW_CONTEXT_NODES) return false\n const id = pending.pop()\n const node = id ? graph.getNode(id) : undefined\n if (node) pending.push(...node.childIds)\n }\n return true\n}\n\n/** Clone the whole affected page child, preserving ancestors, siblings, padding and layout modes. */\nexport async function stageJSXPreview(\n source: SceneGraph,\n tree: TreeNode,\n input: RenderPlacementInput,\n pageId: string,\n signal?: AbortSignal\n): Promise<StagedJSXPreview | null> {\n signal?.throwIfAborted()\n const placement = resolveRenderPlacement(source, input, pageId)\n if (placement.pageId !== pageId) return null\n const owner =\n placement.parentId === pageId\n ? placement.replaceId\n : (findPageChildId(source, placement.parentId) ?? undefined)\n if (owner && !contextFits(source, owner)) return null\n const graph = extractPageContext(source, pageId, owner ? [owner] : [])\n // Preview props can introduce bindings/images not referenced by the old subtree.\n graph.images = new Map(source.images)\n graph.variables = structuredClone(source.variables)\n graph.variableCollections = structuredClone(source.variableCollections)\n const results: RenderResult[] = []\n for (const root of tree.type === '' ? tree.children : [tree]) {\n if (typeof root === 'string') continue\n signal?.throwIfAborted()\n results.push(await renderTree(graph, root, placement))\n }\n signal?.throwIfAborted()\n if (results.length === 0) return null\n finishRenderPlacement(graph, results, placement)\n return {\n graph,\n pageId,\n nodeIds: owner && graph.getNode(owner) ? [owner] : results.map((result) => result.id),\n renderedIds: results.map((result) => result.id),\n replaceId: owner,\n insertIndex: placement.insertIndex\n }\n}\n"],"mappings":";;;;AAWA,MAAM,4BAA4B;AAclC,SAAS,YAAY,OAAmB,QAAyB;CAC/D,MAAM,UAAU,CAAC,MAAM;CACvB,IAAI,QAAQ;CACZ,OAAO,QAAQ,SAAS,GAAG;EACzB,IAAI,EAAE,QAAQ,2BAA2B,OAAO;EAChD,MAAM,KAAK,QAAQ,IAAI;EACvB,MAAM,OAAO,KAAK,MAAM,QAAQ,EAAE,IAAI,KAAA;EACtC,IAAI,MAAM,QAAQ,KAAK,GAAG,KAAK,QAAQ;CACzC;CACA,OAAO;AACT;;AAGA,eAAsB,gBACpB,QACA,MACA,OACA,QACA,QACkC;CAClC,QAAQ,eAAe;CACvB,MAAM,YAAY,uBAAuB,QAAQ,OAAO,MAAM;CAC9D,IAAI,UAAU,WAAW,QAAQ,OAAO;CACxC,MAAM,QACJ,UAAU,aAAa,SACnB,UAAU,YACT,gBAAgB,QAAQ,UAAU,QAAQ,KAAK,KAAA;CACtD,IAAI,SAAS,CAAC,YAAY,QAAQ,KAAK,GAAG,OAAO;CACjD,MAAM,QAAQ,mBAAmB,QAAQ,QAAQ,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC;CAErE,MAAM,SAAS,IAAI,IAAI,OAAO,MAAM;CACpC,MAAM,YAAY,gBAAgB,OAAO,SAAS;CAClD,MAAM,sBAAsB,gBAAgB,OAAO,mBAAmB;CACtE,MAAM,UAA0B,CAAC;CACjC,KAAK,MAAM,QAAQ,KAAK,SAAS,KAAK,KAAK,WAAW,CAAC,IAAI,GAAG;EAC5D,IAAI,OAAO,SAAS,UAAU;EAC9B,QAAQ,eAAe;EACvB,QAAQ,KAAK,MAAM,WAAW,OAAO,MAAM,SAAS,CAAC;CACvD;CACA,QAAQ,eAAe;CACvB,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,sBAAsB,OAAO,SAAS,SAAS;CAC/C,OAAO;EACL;EACA;EACA,SAAS,SAAS,MAAM,QAAQ,KAAK,IAAI,CAAC,KAAK,IAAI,QAAQ,KAAK,WAAW,OAAO,EAAE;EACpF,aAAa,QAAQ,KAAK,WAAW,OAAO,EAAE;EAC9C,WAAW;EACX,aAAa,UAAU;CACzB;AACF"}
1
+ {"version":3,"file":"stage.js","names":[],"sources":["../../../src/design-jsx/preview/stage.ts"],"sourcesContent":["import type { JSXPreviewNode, RenderResult, TreeNode } from '@pairdraw/design-jsx'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport {\n finishRenderPlacement,\n resolveRenderPlacement,\n type RenderPlacementInput\n} from '#core/design-jsx/placement'\nimport { renderTree } from '#core/design-jsx/renderer'\nimport { extractPageContext, findPageChildId } from '#core/io/subgraph'\n\nconst MAX_PREVIEW_CONTEXT_NODES = 1000\n\nexport interface StagedJSXPreview {\n graph: SceneGraph\n pageId: string\n nodeIds: string[]\n /** The roots the JSX rendered, in source order, even when `nodeIds` names their owner. */\n renderedIds: string[]\n /** Existing page child to replace visually, without changing the source graph. */\n replaceId?: string\n /** Page insertion slot when the preview adds new top-level nodes. */\n insertIndex?: number\n /** The source position each rendered layer came from, so restages keep an element's identity. */\n sources: ReadonlyMap<string, number>\n}\n\nfunction contextFits(graph: SceneGraph, rootId: string): boolean {\n const pending = [rootId]\n let count = 0\n while (pending.length > 0) {\n if (++count > MAX_PREVIEW_CONTEXT_NODES) return false\n const id = pending.pop()\n const node = id ? graph.getNode(id) : undefined\n if (node) pending.push(...node.childIds)\n }\n return true\n}\n\n/** Clone the whole affected page child, preserving ancestors, siblings, padding and layout modes. */\nexport async function stageJSXPreview(\n source: SceneGraph,\n tree: TreeNode,\n input: RenderPlacementInput,\n pageId: string,\n signal?: AbortSignal\n): Promise<StagedJSXPreview | null> {\n signal?.throwIfAborted()\n const placement = resolveRenderPlacement(source, input, pageId)\n if (placement.pageId !== pageId) return null\n const owner =\n placement.parentId === pageId\n ? placement.replaceId\n : (findPageChildId(source, placement.parentId) ?? undefined)\n if (owner && !contextFits(source, owner)) return null\n const graph = extractPageContext(source, pageId, owner ? [owner] : [])\n // Preview props can introduce bindings/images not referenced by the old subtree.\n graph.images = new Map(source.images)\n graph.variables = structuredClone(source.variables)\n graph.variableCollections = structuredClone(source.variableCollections)\n const results: RenderResult[] = []\n const sources = new Map<string, number>()\n const onNode = (element: TreeNode, node: { id: string }) => {\n const sourceStart = (element as JSXPreviewNode).sourceStart\n if (typeof sourceStart === 'number') sources.set(node.id, sourceStart)\n }\n for (const root of tree.type === '' ? tree.children : [tree]) {\n if (typeof root === 'string') continue\n signal?.throwIfAborted()\n results.push(await renderTree(graph, root, { ...placement, onNode }))\n }\n signal?.throwIfAborted()\n if (results.length === 0) return null\n finishRenderPlacement(graph, results, placement)\n return {\n graph,\n pageId,\n nodeIds: owner && graph.getNode(owner) ? [owner] : results.map((result) => result.id),\n renderedIds: results.map((result) => result.id),\n replaceId: owner,\n insertIndex: placement.insertIndex,\n sources\n }\n}\n"],"mappings":";;;;AAWA,MAAM,4BAA4B;AAgBlC,SAAS,YAAY,OAAmB,QAAyB;CAC/D,MAAM,UAAU,CAAC,MAAM;CACvB,IAAI,QAAQ;CACZ,OAAO,QAAQ,SAAS,GAAG;EACzB,IAAI,EAAE,QAAQ,2BAA2B,OAAO;EAChD,MAAM,KAAK,QAAQ,IAAI;EACvB,MAAM,OAAO,KAAK,MAAM,QAAQ,EAAE,IAAI,KAAA;EACtC,IAAI,MAAM,QAAQ,KAAK,GAAG,KAAK,QAAQ;CACzC;CACA,OAAO;AACT;;AAGA,eAAsB,gBACpB,QACA,MACA,OACA,QACA,QACkC;CAClC,QAAQ,eAAe;CACvB,MAAM,YAAY,uBAAuB,QAAQ,OAAO,MAAM;CAC9D,IAAI,UAAU,WAAW,QAAQ,OAAO;CACxC,MAAM,QACJ,UAAU,aAAa,SACnB,UAAU,YACT,gBAAgB,QAAQ,UAAU,QAAQ,KAAK,KAAA;CACtD,IAAI,SAAS,CAAC,YAAY,QAAQ,KAAK,GAAG,OAAO;CACjD,MAAM,QAAQ,mBAAmB,QAAQ,QAAQ,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC;CAErE,MAAM,SAAS,IAAI,IAAI,OAAO,MAAM;CACpC,MAAM,YAAY,gBAAgB,OAAO,SAAS;CAClD,MAAM,sBAAsB,gBAAgB,OAAO,mBAAmB;CACtE,MAAM,UAA0B,CAAC;CACjC,MAAM,0BAAU,IAAI,IAAoB;CACxC,MAAM,UAAU,SAAmB,SAAyB;EAC1D,MAAM,cAAe,QAA2B;EAChD,IAAI,OAAO,gBAAgB,UAAU,QAAQ,IAAI,KAAK,IAAI,WAAW;CACvE;CACA,KAAK,MAAM,QAAQ,KAAK,SAAS,KAAK,KAAK,WAAW,CAAC,IAAI,GAAG;EAC5D,IAAI,OAAO,SAAS,UAAU;EAC9B,QAAQ,eAAe;EACvB,QAAQ,KAAK,MAAM,WAAW,OAAO,MAAM;GAAE,GAAG;GAAW;EAAO,CAAC,CAAC;CACtE;CACA,QAAQ,eAAe;CACvB,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,sBAAsB,OAAO,SAAS,SAAS;CAC/C,OAAO;EACL;EACA;EACA,SAAS,SAAS,MAAM,QAAQ,KAAK,IAAI,CAAC,KAAK,IAAI,QAAQ,KAAK,WAAW,OAAO,EAAE;EACpF,aAAa,QAAQ,KAAK,WAAW,OAAO,EAAE;EAC9C,WAAW;EACX,aAAa,UAAU;EACvB;CACF;AACF"}
@@ -15,7 +15,7 @@ declare function createUndoBridge(undoActions: UndoActions, selection: Selection
15
15
  commitMove: (originals: Map<string, import("@pairdraw/scene-graph/primitives").Vector>) => void;
16
16
  commitMoveWithReparent: (originals: Map<string, MovePlace>) => void;
17
17
  commitDuplicateMove: (rootIds: string[], previousSelection: Set<string>) => void;
18
- commitResize: (nodeId: string, original: import("@pairdraw/scene-graph/primitives").Rect & Partial<Pick<import("@pairdraw/scene-graph").SceneNode, "vectorNetwork" | "fillGeometry" | "strokeGeometry" | "derivedTextGlyphs" | "strokes" | "textPathData" | "textPathBox">>) => void;
18
+ commitResize: (nodeId: string, original: import("@pairdraw/scene-graph/primitives").Rect & Partial<Pick<import("@pairdraw/scene-graph").SceneNode, "strokes" | "vectorNetwork" | "fillGeometry" | "strokeGeometry" | "derivedTextGlyphs" | "textPathData" | "textPathBox">>) => void;
19
19
  commitGroupResize: (nodeId: string, origRect: import("@pairdraw/scene-graph/primitives").Rect, origChildren: Map<string, import("@pairdraw/scene-graph/resize").ResizeSnapshot>) => void;
20
20
  commitRotation: (nodeId: string, origRotation: number) => void;
21
21
  commitNodeUpdate: (nodeId: string, previous: Partial<import("@pairdraw/scene-graph").SceneNode>, label?: string) => void;
@@ -202,7 +202,7 @@ declare function createEditor(options?: EditorOptions): {
202
202
  commitMove: (originals: Map<string, import("@pairdraw/scene-graph/primitives").Vector>) => void;
203
203
  commitMoveWithReparent: (originals: Map<string, MovePlace>) => void;
204
204
  commitDuplicateMove: (rootIds: string[], previousSelection: Set<string>) => void;
205
- commitResize: (nodeId: string, original: import("@pairdraw/scene-graph/primitives").Rect & Partial<Pick<SceneNode, "vectorNetwork" | "fillGeometry" | "strokeGeometry" | "derivedTextGlyphs" | "strokes" | "textPathData" | "textPathBox">>) => void;
205
+ commitResize: (nodeId: string, original: import("@pairdraw/scene-graph/primitives").Rect & Partial<Pick<SceneNode, "strokes" | "vectorNetwork" | "fillGeometry" | "strokeGeometry" | "derivedTextGlyphs" | "textPathData" | "textPathBox">>) => void;
206
206
  commitGroupResize: (nodeId: string, origRect: import("@pairdraw/scene-graph/primitives").Rect, origChildren: Map<string, import("@pairdraw/scene-graph/resize").ResizeSnapshot>) => void;
207
207
  commitRotation: (nodeId: string, origRotation: number) => void;
208
208
  snapshotPage: (pageId?: string) => PageSnapshot;
@@ -20,7 +20,7 @@ declare const reactionSchema: v.StrictObjectSchema<{
20
20
  }, 1, undefined>, v.DescriptionAction<{
21
21
  [x: string]: string;
22
22
  }, string>]>, undefined>;
23
- readonly navigation: v.PicklistSchema<("NAVIGATE" | "OVERLAY" | "CHANGE_TO" | "SCROLL_TO")[], undefined>;
23
+ readonly navigation: v.PicklistSchema<("OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO")[], undefined>;
24
24
  readonly transition: v.OptionalSchema<v.StrictObjectSchema<{
25
25
  readonly type: v.PicklistSchema<("INSTANT" | "DISSOLVE" | "SMART_ANIMATE")[], undefined>;
26
26
  readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -56,7 +56,7 @@ declare const reactionSchema: v.StrictObjectSchema<{
56
56
  variantProperties?: {
57
57
  [x: string]: string;
58
58
  } | undefined;
59
- navigation: "NAVIGATE" | "OVERLAY" | "CHANGE_TO" | "SCROLL_TO";
59
+ navigation: "OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO";
60
60
  transition: {
61
61
  type: "INSTANT" | "DISSOLVE" | "SMART_ANIMATE";
62
62
  duration: number;
@@ -105,7 +105,7 @@ declare const figmaReactionsSchema: v.ArraySchema<v.StrictObjectSchema<{
105
105
  }, 1, undefined>, v.DescriptionAction<{
106
106
  [x: string]: string;
107
107
  }, string>]>, undefined>;
108
- readonly navigation: v.PicklistSchema<("NAVIGATE" | "OVERLAY" | "CHANGE_TO" | "SCROLL_TO")[], undefined>;
108
+ readonly navigation: v.PicklistSchema<("OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO")[], undefined>;
109
109
  readonly transition: v.OptionalSchema<v.StrictObjectSchema<{
110
110
  readonly type: v.PicklistSchema<("INSTANT" | "DISSOLVE" | "SMART_ANIMATE")[], undefined>;
111
111
  readonly duration: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -141,7 +141,7 @@ declare const figmaReactionsSchema: v.ArraySchema<v.StrictObjectSchema<{
141
141
  variantProperties?: {
142
142
  [x: string]: string;
143
143
  } | undefined;
144
- navigation: "NAVIGATE" | "OVERLAY" | "CHANGE_TO" | "SCROLL_TO";
144
+ navigation: "OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO";
145
145
  transition: {
146
146
  type: "INSTANT" | "DISSOLVE" | "SMART_ANIMATE";
147
147
  duration: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairdraw/core",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -11,14 +11,14 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "dependencies": {
13
13
  "@iconify/utils": "^3.1.4",
14
- "@pairdraw/design-jsx": "^0.22.1",
15
- "@pairdraw/dom-css": "^0.22.1",
16
- "@pairdraw/drawio": "^0.22.1",
17
- "@pairdraw/fig": "^0.22.1",
18
- "@pairdraw/kiwi": "^0.22.1",
19
- "@pairdraw/mermaid": "^0.22.1",
20
- "@pairdraw/pen": "^0.22.1",
21
- "@pairdraw/scene-graph": "^0.22.1",
14
+ "@pairdraw/design-jsx": "^0.22.2",
15
+ "@pairdraw/dom-css": "^0.22.2",
16
+ "@pairdraw/drawio": "^0.22.2",
17
+ "@pairdraw/fig": "^0.22.2",
18
+ "@pairdraw/kiwi": "^0.22.2",
19
+ "@pairdraw/mermaid": "^0.22.2",
20
+ "@pairdraw/pen": "^0.22.2",
21
+ "@pairdraw/scene-graph": "^0.22.2",
22
22
  "@tauri-apps/api": "^2.12.1",
23
23
  "@valibot/to-json-schema": "^1.8.0",
24
24
  "@xmldom/xmldom": "^0.9.12",
@@ -23,6 +23,7 @@ export {
23
23
  type GuideViewport
24
24
  } from './guides/geometry'
25
25
  export { computeGuideRedline } from './guides/redlines'
26
+ export type { TransientCanvasPreview } from './renderer/transient-previews'
26
27
  export { hitTestGuides, type GuideHit } from './guides/hit-test'
27
28
  export type { GuideOverlayState, GuidePreview, GuideSelection } from './guides/types'
28
29
  export { canvasLabelForeground } from './labels/color'
@@ -1,4 +1,4 @@
1
- import type { Canvas, Image } from 'canvaskit-wasm'
1
+ import type { Canvas, Image, Paint } from 'canvaskit-wasm'
2
2
 
3
3
  import type { SceneGraph } from '@pairdraw/scene-graph'
4
4
  import { getWorldMatrix } from '@pairdraw/scene-graph/coordinate'
@@ -17,28 +17,122 @@ const LABEL_MAX_WIDTH = 160
17
17
  /** The provider mark before an agent's name, and the gap after it. */
18
18
  const LABEL_LOGO_SIZE = 9
19
19
  const LABEL_LOGO_GAP = 3
20
+ /** The newest outline's soft pulse, and how long a replaced one takes to fade. */
21
+ const FOCUS_PULSE_MS = 1200
22
+ const FOCUS_FADE_MS = 200
23
+ /** One sheen across what a finished preview built. */
24
+ const SHEEN_MS = 400
20
25
 
21
26
  /** Decoded once per logo byte array; the app keeps one array per provider, so this is tiny. */
22
27
  const labelLogoImages = new WeakMap<Uint8Array, Image | null>()
28
+ /** What a cursor's focus outline showed, so a newer element fades the old one out. */
29
+ export interface FocusTransition {
30
+ current: Rect | null
31
+ previous: Rect | null
32
+ /** When the previous outline was replaced. */
33
+ since: number
34
+ }
35
+
36
+ export const NO_FOCUS: FocusTransition = { current: null, previous: null, since: 0 }
37
+
38
+ /** Draw a world-space rectangle in the overlay's screen coordinates. */
39
+ function drawWorldRect(r: SkiaRenderer, canvas: Canvas, rect: Rect, paint: Paint) {
40
+ canvas.drawRect(
41
+ r.ck.XYWHRect(
42
+ rect.x * r.zoom + r.panX,
43
+ rect.y * r.zoom + r.panY,
44
+ rect.width * r.zoom,
45
+ rect.height * r.zoom
46
+ ),
47
+ paint
48
+ )
49
+ }
50
+
51
+ function sameRect(a: Rect, b: Rect): boolean {
52
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height
53
+ }
54
+
55
+ /** Move the outline to `focus`, keeping the one it replaces for its fade. */
56
+ export function nextFocus(
57
+ state: FocusTransition,
58
+ focus: Rect | undefined,
59
+ now: number
60
+ ): FocusTransition {
61
+ if (!focus) return NO_FOCUS
62
+ if (state.current && sameRect(state.current, focus)) return state
63
+ return { current: focus, previous: state.current, since: now }
64
+ }
65
+
66
+ /** The outline to draw now: the current one, pulsing, and the replaced one fading out. */
67
+ export function focusOutlines(
68
+ state: FocusTransition,
69
+ pulse: boolean | undefined,
70
+ now: number
71
+ ): Array<{ rect: Rect; alpha: number }> {
72
+ const outlines: Array<{ rect: Rect; alpha: number }> = []
73
+ const age = now - state.since
74
+ if (pulse && state.previous && age < FOCUS_FADE_MS) {
75
+ outlines.push({ rect: state.previous, alpha: 0.75 * (1 - age / FOCUS_FADE_MS) })
76
+ }
77
+ if (state.current) {
78
+ const alpha = pulse
79
+ ? 0.35 + 0.65 * (0.5 + 0.5 * Math.sin((now / FOCUS_PULSE_MS) * 2 * Math.PI))
80
+ : 0.75
81
+ outlines.push({ rect: state.current, alpha })
82
+ }
83
+ return outlines
84
+ }
85
+
86
+ /** Each canvas keeps its own focus transitions, so two documents' agents never collide. */
87
+ const focusHistories = new WeakMap<SkiaRenderer, Map<string, FocusTransition>>()
88
+
89
+ function focusHistoryFor(r: SkiaRenderer): Map<string, FocusTransition> {
90
+ const existing = focusHistories.get(r)
91
+ if (existing) return existing
92
+ const history = new Map<string, FocusTransition>()
93
+ focusHistories.set(r, history)
94
+ return history
95
+ }
96
+
97
+ /** The element being written, pulsing in the accent color, and the one it replaced fading out. */
98
+ function drawFocus(r: SkiaRenderer, canvas: Canvas, cursor: PresenceCursor) {
99
+ if (cursor.kind !== 'agent') return
100
+ const key = cursor.id ?? cursor.name
101
+ const history = focusHistoryFor(r)
102
+ const now = performance.now()
103
+ const state = nextFocus(history.get(key) ?? NO_FOCUS, cursor.focus, now)
104
+ if (state === NO_FOCUS) history.delete(key)
105
+ else history.set(key, state)
106
+ const { r: red, g, b } = cursor.color
107
+ r.auxStroke.setStrokeWidth(2)
108
+ r.auxStroke.setPathEffect(null)
109
+ for (const { rect, alpha } of focusOutlines(state, cursor.pulse, now)) {
110
+ if (alpha <= 0) continue
111
+ r.auxStroke.setColor(r.ck.Color4f(red, g, b, alpha))
112
+ drawWorldRect(r, canvas, rect, r.auxStroke)
113
+ }
114
+ }
115
+
116
+ /** One soft pass of light across what a finished preview built. */
117
+ function drawSheen(r: SkiaRenderer, canvas: Canvas, cursor: PresenceCursor) {
118
+ if (!cursor.sheen) return
119
+ const age = performance.now() - cursor.sheen.at
120
+ if (age < 0 || age >= SHEEN_MS) return
121
+ const { rect } = cursor.sheen
122
+ r.auxFill.setColor(r.ck.Color4f(1, 1, 1, 0.07 * Math.sin((age / SHEEN_MS) * Math.PI)))
123
+ drawWorldRect(r, canvas, rect, r.auxFill)
124
+ }
23
125
 
24
126
  function drawSelection(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph, cursor: PresenceCursor) {
127
+ drawSheen(r, canvas, cursor)
128
+ drawFocus(r, canvas, cursor)
25
129
  if (!cursor.selection?.length && !cursor.outline?.length) return
26
130
  const { r: red, g, b } = cursor.color
27
131
  r.auxStroke.setColor(r.ck.Color4f(red, g, b, 0.6))
28
132
  r.auxStroke.setStrokeWidth(1.5)
29
133
  r.auxStroke.setPathEffect(null)
30
134
  // Outlines of what is not a layer yet, such as JSX an agent is still streaming.
31
- for (const rect of cursor.outline ?? []) {
32
- canvas.drawRect(
33
- r.ck.XYWHRect(
34
- rect.x * r.zoom + r.panX,
35
- rect.y * r.zoom + r.panY,
36
- rect.width * r.zoom,
37
- rect.height * r.zoom
38
- ),
39
- r.auxStroke
40
- )
41
- }
135
+ for (const rect of cursor.outline ?? []) drawWorldRect(r, canvas, rect, r.auxStroke)
42
136
  for (const nodeId of cursor.selection ?? []) {
43
137
  const node = graph.getNode(nodeId)
44
138
  if (!node) continue
@@ -115,6 +209,8 @@ function drawLabel(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor
115
209
  const agent = cursor.kind === 'agent'
116
210
  const logo = agent ? labelLogo(r, cursor.logo) : null
117
211
  const badge = logo ? LABEL_LOGO_SIZE + LABEL_LOGO_GAP : 0
212
+ // The status climbs through its dots while the agent rests; the name stays first.
213
+ const label = cursor.status ? `${cursor.name} ${cursor.status}` : cursor.name
118
214
  const pillX = x + LABEL_OFFSET_X - LABEL_PADDING_X
119
215
  const pillY = y + LABEL_OFFSET_Y - LABEL_FONT_SIZE - LABEL_PADDING_Y + 2
120
216
  const pillHeight = LABEL_FONT_SIZE + LABEL_PADDING_Y * 2
@@ -122,7 +218,7 @@ function drawLabel(r: SkiaRenderer, canvas: Canvas, x: number, y: number, cursor
122
218
  r.labelParagraphCache.use(
123
219
  r.ck,
124
220
  provider,
125
- cursor.name,
221
+ label,
126
222
  LABEL_FONT_SIZE,
127
223
  LABEL_MAX_WIDTH,
128
224
  agent ? color : r.ck.WHITE,
@@ -171,11 +267,16 @@ export function drawPresenceCursors(
171
267
  graph: SceneGraph,
172
268
  cursors?: PresenceCursor[]
173
269
  ): void {
270
+ const history = focusHistoryFor(r)
271
+ const drawn = new Set<string>()
174
272
  for (const cursor of cursors ?? []) {
273
+ drawn.add(cursor.id ?? cursor.name)
175
274
  const x = cursor.x * r.zoom + r.panX
176
275
  const y = cursor.y * r.zoom + r.panY
177
276
  drawSelection(r, canvas, graph, cursor)
178
277
  drawArrow(r, canvas, x, y, cursor)
179
278
  drawLabel(r, canvas, x, y, cursor)
180
279
  }
280
+ // A cursor no longer drawn (an agent at rest) leaves no outline to flash on its return.
281
+ for (const key of history.keys()) if (!drawn.has(key)) history.delete(key)
181
282
  }
@@ -1,5 +1,6 @@
1
1
  import type { Canvas, SkPicture } from 'canvaskit-wasm'
2
2
 
3
+ import type { SceneGraph } from '@pairdraw/scene-graph'
3
4
  import type { VisualBounds } from '@pairdraw/scene-graph/geometry'
4
5
 
5
6
  import type { SkiaRenderer } from '#core/canvas/renderer'
@@ -20,6 +21,22 @@ export function withWorldViewport<T>(r: SkiaRenderer, bounds: VisualBounds, draw
20
21
  }
21
22
  }
22
23
 
24
+ /** Record one node, its children included, into a picture of world-space `bounds`. */
25
+ export function recordNodePicture(
26
+ r: SkiaRenderer,
27
+ graph: SceneGraph,
28
+ nodeId: string,
29
+ bounds: VisualBounds,
30
+ signal?: AbortSignal
31
+ ): SkPicture {
32
+ return recordWorldPicture(r, bounds, (canvas) => {
33
+ signal?.throwIfAborted()
34
+ const parentId = graph.getNode(nodeId)?.parentId
35
+ const parent = parentId ? graph.getAbsolutePosition(parentId) : { x: 0, y: 0 }
36
+ r.renderNode(canvas, graph, nodeId, {}, parent.x, parent.y)
37
+ })
38
+ }
39
+
23
40
  /** Record `draw` into a picture of world-space `bounds`. The caller owns the picture. */
24
41
  export function recordWorldPicture(
25
42
  r: SkiaRenderer,
@@ -8,11 +8,16 @@ import type { RenderOverlays, SkiaRenderer } from '#core/canvas/renderer'
8
8
  export interface TransientCanvasPreview {
9
9
  graph: SceneGraph
10
10
  pageId: string
11
- picture: SkPicture
11
+ /** The settled preview; absent while every element enters for the first time. */
12
+ picture?: SkPicture
12
13
  /** Substitute a whole page child, including its proposed descendant layout. */
13
14
  replaceId?: string
14
15
  /** Insert before this page-child index, or append when omitted. */
15
16
  insertIndex?: number
17
+ /** New elements fading in over the picture, with how far their entrance has come (0 to 1). */
18
+ entrance?: { pictures: SkPicture[]; progress: number }
19
+ /** How opaque the whole preview is while a finished call hands off to the committed nodes. */
20
+ fade?: number
16
21
  }
17
22
 
18
23
  function activePreviews(r: SkiaRenderer, graph: SceneGraph): TransientCanvasPreview[] {
@@ -25,6 +30,31 @@ export function hasTransientPreviews(r: SkiaRenderer, graph: SceneGraph): boolea
25
30
  return activePreviews(r, graph).length > 0
26
31
  }
27
32
 
33
+ /** One preview picture, with new elements easing up 4 screen pixels while they fade in. */
34
+ function drawPreview(r: SkiaRenderer, canvas: Canvas, preview: TransientCanvasPreview): void {
35
+ const fade = preview.fade ?? 1
36
+ if (fade <= 0) return
37
+ try {
38
+ if (preview.picture) {
39
+ r.auxFill.setAlphaf(fade)
40
+ canvas.saveLayer(r.auxFill)
41
+ canvas.drawPicture(preview.picture)
42
+ canvas.restore()
43
+ }
44
+ const entrance = preview.entrance
45
+ if (!entrance || entrance.progress <= 0) return
46
+ r.auxFill.setAlphaf(fade * entrance.progress)
47
+ canvas.save()
48
+ canvas.translate(0, ((1 - entrance.progress) * 4) / (r.zoom || 1))
49
+ canvas.saveLayer(r.auxFill)
50
+ for (const picture of entrance.pictures) canvas.drawPicture(picture)
51
+ canvas.restore()
52
+ canvas.restore()
53
+ } finally {
54
+ r.auxFill.setAlphaf(1)
55
+ }
56
+ }
57
+
28
58
  /** Draw at the normal scene z-order, not over the top of unchanged originals. Never used for export. */
29
59
  export function renderPageWithPreviews(
30
60
  r: SkiaRenderer,
@@ -48,12 +78,16 @@ export function renderPageWithPreviews(
48
78
  }
49
79
  }
50
80
  for (let index = 0; index <= children.length; index++) {
51
- for (const preview of insertions.get(index) ?? []) canvas.drawPicture(preview.picture)
81
+ for (const preview of insertions.get(index) ?? []) drawPreview(r, canvas, preview)
52
82
  const id = children[index]
53
83
  if (!id) continue
54
84
  const replacement = replacements.get(id)
55
- if (replacement) canvas.drawPicture(replacement.picture)
56
- else r.renderNode(canvas, graph, id, overlays)
85
+ if (replacement) {
86
+ // A fading replacement uncovers the committed node it replaced, so no frame is blank.
87
+ if (replacement.fade !== undefined && replacement.fade < 1)
88
+ r.renderNode(canvas, graph, id, overlays)
89
+ drawPreview(r, canvas, replacement)
90
+ } else r.renderNode(canvas, graph, id, overlays)
57
91
  }
58
92
  return true
59
93
  }
@@ -34,8 +34,16 @@ export interface PresenceCursor {
34
34
  x: number
35
35
  y: number
36
36
  selection?: string[]
37
+ /** What the label says after the name while the agent works, such as `Writing...`. */
38
+ status?: string
37
39
  /** Outlines in world coordinates of what is not a layer yet, such as streamed JSX. */
38
40
  outline?: Rect[]
41
+ /** The element being written, outlined with a soft pulse while the agent rests on it. */
42
+ focus?: Rect
43
+ /** Whether the focus outline may pulse; false under reduced motion. */
44
+ pulse?: boolean
45
+ /** One sheen over what a finished preview built, drawn once at `at`. */
46
+ sheen?: { rect: Rect; at: number }
39
47
  /** PNG bytes of the mark of what an agent runs on, drawn in its label. */
40
48
  logo?: Uint8Array
41
49
  }
@@ -1,9 +1,10 @@
1
1
  import type { CanvasKit, SkPicture } from 'canvaskit-wasm'
2
2
 
3
+ import type { SceneGraph } from '@pairdraw/scene-graph'
3
4
  import { computeDescendantVisualBounds, type VisualBounds } from '@pairdraw/scene-graph/geometry'
4
5
 
5
6
  import { SkiaRenderer } from '#core/canvas/renderer'
6
- import { recordWorldPicture } from '#core/canvas/renderer/picture'
7
+ import { recordNodePicture, recordWorldPicture } from '#core/canvas/renderer/picture'
7
8
 
8
9
  import type { StagedJSXPreview } from './stage'
9
10
 
@@ -43,6 +44,13 @@ async function recordStaged(
43
44
  export interface JSXPreviewRecorder {
44
45
  /** Record `staged` as a picture the caller owns, even when its request becomes stale. */
45
46
  record(staged: StagedJSXPreview, signal: AbortSignal): Promise<SkPicture | null>
47
+ /** Record one layer of a staged graph, for an entrance drawn apart from the rest. */
48
+ recordNode(
49
+ graph: SceneGraph,
50
+ nodeId: string,
51
+ bounds: VisualBounds,
52
+ signal: AbortSignal
53
+ ): Promise<SkPicture | null>
46
54
  /** Free the private renderer once the records already asked for finish. */
47
55
  destroy(): void
48
56
  }
@@ -89,12 +97,30 @@ export function createJSXPreviewRecorder(ck: CanvasKit): JSXPreviewRecorder {
89
97
  return recordStaged(current, staged, signal)
90
98
  }
91
99
 
100
+ async function recordNodeNext(
101
+ graph: SceneGraph,
102
+ nodeId: string,
103
+ bounds: VisualBounds,
104
+ signal: AbortSignal
105
+ ): Promise<SkPicture | null> {
106
+ signal.throwIfAborted()
107
+ const current = destroyed ? null : await rendererFor()
108
+ if (!current) return null
109
+ signal.throwIfAborted()
110
+ return recordNodePicture(current, graph, nodeId, bounds, signal)
111
+ }
112
+
92
113
  return {
93
114
  record(staged, signal) {
94
115
  const result = queue.then(() => recordNext(staged, signal))
95
116
  queue = result.catch(() => undefined)
96
117
  return result
97
118
  },
119
+ recordNode(graph, nodeId, bounds, signal) {
120
+ const result = queue.then(() => recordNodeNext(graph, nodeId, bounds, signal))
121
+ queue = result.catch(() => undefined)
122
+ return result
123
+ },
98
124
  destroy() {
99
125
  destroyed = true
100
126
  const release = () => {
@@ -1,4 +1,4 @@
1
- import type { RenderResult, TreeNode } from '@pairdraw/design-jsx'
1
+ import type { JSXPreviewNode, RenderResult, TreeNode } from '@pairdraw/design-jsx'
2
2
  import type { SceneGraph } from '@pairdraw/scene-graph'
3
3
 
4
4
  import {
@@ -21,6 +21,8 @@ export interface StagedJSXPreview {
21
21
  replaceId?: string
22
22
  /** Page insertion slot when the preview adds new top-level nodes. */
23
23
  insertIndex?: number
24
+ /** The source position each rendered layer came from, so restages keep an element's identity. */
25
+ sources: ReadonlyMap<string, number>
24
26
  }
25
27
 
26
28
  function contextFits(graph: SceneGraph, rootId: string): boolean {
@@ -57,10 +59,15 @@ export async function stageJSXPreview(
57
59
  graph.variables = structuredClone(source.variables)
58
60
  graph.variableCollections = structuredClone(source.variableCollections)
59
61
  const results: RenderResult[] = []
62
+ const sources = new Map<string, number>()
63
+ const onNode = (element: TreeNode, node: { id: string }) => {
64
+ const sourceStart = (element as JSXPreviewNode).sourceStart
65
+ if (typeof sourceStart === 'number') sources.set(node.id, sourceStart)
66
+ }
60
67
  for (const root of tree.type === '' ? tree.children : [tree]) {
61
68
  if (typeof root === 'string') continue
62
69
  signal?.throwIfAborted()
63
- results.push(await renderTree(graph, root, placement))
70
+ results.push(await renderTree(graph, root, { ...placement, onNode }))
64
71
  }
65
72
  signal?.throwIfAborted()
66
73
  if (results.length === 0) return null
@@ -71,6 +78,7 @@ export async function stageJSXPreview(
71
78
  nodeIds: owner && graph.getNode(owner) ? [owner] : results.map((result) => result.id),
72
79
  renderedIds: results.map((result) => result.id),
73
80
  replaceId: owner,
74
- insertIndex: placement.insertIndex
81
+ insertIndex: placement.insertIndex,
82
+ sources
75
83
  }
76
84
  }