@pairdraw/core 0.22.1 → 0.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/providers.d.ts +1 -1
- package/dist/ai/providers.d.ts.map +1 -1
- package/dist/ai/providers.js +12 -0
- package/dist/ai/providers.js.map +1 -1
- package/dist/canvas/images/previews.d.ts +1 -1
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/overlays/presence.d.ts +16 -1
- package/dist/canvas/overlays/presence.d.ts.map +1 -1
- package/dist/canvas/overlays/presence.js +90 -3
- package/dist/canvas/overlays/presence.js.map +1 -1
- package/dist/canvas/renderer/picture.d.ts +4 -1
- package/dist/canvas/renderer/picture.d.ts.map +1 -1
- package/dist/canvas/renderer/picture.js +13 -1
- package/dist/canvas/renderer/picture.js.map +1 -1
- package/dist/canvas/renderer/transient-previews.d.ts +9 -1
- package/dist/canvas/renderer/transient-previews.d.ts.map +1 -1
- package/dist/canvas/renderer/transient-previews.js +29 -3
- package/dist/canvas/renderer/transient-previews.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +11 -0
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +1 -1
- package/dist/design-jsx/preview/picture.d.ts +4 -0
- package/dist/design-jsx/preview/picture.d.ts.map +1 -1
- package/dist/design-jsx/preview/picture.js +13 -1
- package/dist/design-jsx/preview/picture.js.map +1 -1
- package/dist/design-jsx/preview/stage.d.ts +2 -0
- package/dist/design-jsx/preview/stage.d.ts.map +1 -1
- package/dist/design-jsx/preview/stage.js +11 -2
- package/dist/design-jsx/preview/stage.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/create.d.ts +1 -1
- package/dist/figma-api/reactions.d.ts +4 -4
- package/dist/io/formats/design-tokens/apply.d.ts +1 -1
- package/package.json +9 -9
- package/src/ai/providers.ts +10 -1
- package/src/canvas/index.ts +1 -0
- package/src/canvas/overlays/presence.ts +114 -13
- package/src/canvas/renderer/picture.ts +17 -0
- package/src/canvas/renderer/transient-previews.ts +38 -4
- package/src/canvas/renderer/types.ts +8 -0
- package/src/design-jsx/preview/picture.ts +27 -1
- package/src/design-jsx/preview/stage.ts +11 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.d.ts","names":[],"sources":["../../../src/design-jsx/preview/picture.ts"],"mappings":"
|
|
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":";;;;
|
|
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;;;
|
|
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,
|
|
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;
|
|
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, "
|
|
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;
|
package/dist/editor/create.d.ts
CHANGED
|
@@ -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, "
|
|
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<("
|
|
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: "
|
|
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<("
|
|
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: "
|
|
144
|
+
navigation: "OVERLAY" | "NAVIGATE" | "CHANGE_TO" | "SCROLL_TO";
|
|
145
145
|
transition: {
|
|
146
146
|
type: "INSTANT" | "DISSOLVE" | "SMART_ANIMATE";
|
|
147
147
|
duration: number;
|
|
@@ -47,7 +47,7 @@ declare function styleNodeProps(style: Pick<PlannedStyle, 'kind'> | {
|
|
|
47
47
|
}, fields: Partial<SceneNode>): Partial<SceneNode>;
|
|
48
48
|
declare function styleNodeType(style: Pick<PlannedStyle, 'kind'> | {
|
|
49
49
|
kind: SharedStyleType;
|
|
50
|
-
}): "
|
|
50
|
+
}): "TEXT" | "RECTANGLE";
|
|
51
51
|
/**
|
|
52
52
|
* Imports straight into a graph, for scripts, tools, and the CLI working on a document without
|
|
53
53
|
* an editor; the layers bound to variables whose values changed are resolved and laid out
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pairdraw/core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.3",
|
|
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.
|
|
15
|
-
"@pairdraw/dom-css": "^0.22.
|
|
16
|
-
"@pairdraw/drawio": "^0.22.
|
|
17
|
-
"@pairdraw/fig": "^0.22.
|
|
18
|
-
"@pairdraw/kiwi": "^0.22.
|
|
19
|
-
"@pairdraw/mermaid": "^0.22.
|
|
20
|
-
"@pairdraw/pen": "^0.22.
|
|
21
|
-
"@pairdraw/scene-graph": "^0.22.
|
|
14
|
+
"@pairdraw/design-jsx": "^0.22.3",
|
|
15
|
+
"@pairdraw/dom-css": "^0.22.3",
|
|
16
|
+
"@pairdraw/drawio": "^0.22.3",
|
|
17
|
+
"@pairdraw/fig": "^0.22.3",
|
|
18
|
+
"@pairdraw/kiwi": "^0.22.3",
|
|
19
|
+
"@pairdraw/mermaid": "^0.22.3",
|
|
20
|
+
"@pairdraw/pen": "^0.22.3",
|
|
21
|
+
"@pairdraw/scene-graph": "^0.22.3",
|
|
22
22
|
"@tauri-apps/api": "^2.12.1",
|
|
23
23
|
"@valibot/to-json-schema": "^1.8.0",
|
|
24
24
|
"@xmldom/xmldom": "^0.9.12",
|
package/src/ai/providers.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { OPENAI_COMPATIBLE_PRESETS } from './presets'
|
|
4
4
|
|
|
5
|
-
export type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli' | 'omp'
|
|
5
|
+
export type ACPAgentID = 'claude-code' | 'codex' | 'gemini-cli' | 'agy' | 'omp'
|
|
6
6
|
|
|
7
7
|
export interface ACPAgentDef {
|
|
8
8
|
id: ACPAgentID
|
|
@@ -64,6 +64,15 @@ export const ACP_AGENTS: ACPAgentDef[] = [
|
|
|
64
64
|
setupURL: 'https://geminicli.com/docs/get-started/installation/',
|
|
65
65
|
installCommand: 'npm i -g @google/gemini-cli'
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
id: 'agy',
|
|
69
|
+
name: 'agy',
|
|
70
|
+
command: 'agy',
|
|
71
|
+
args: ['acp'],
|
|
72
|
+
setupURL: 'https://antigravity.google/docs/cli/overview',
|
|
73
|
+
installCommand: 'curl -fsSL https://antigravity.google/cli/install.sh | bash',
|
|
74
|
+
signIn: { via: 'acp', method: 'oauth-personal' }
|
|
75
|
+
},
|
|
67
76
|
{
|
|
68
77
|
id: 'omp',
|
|
69
78
|
name: 'omp',
|
package/src/canvas/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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)
|
|
56
|
-
|
|
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 = () => {
|