sketchmark 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +188 -0
  2. package/bin/sketchmark.cjs +2008 -0
  3. package/dist/src/builders/index.d.ts +74 -0
  4. package/dist/src/builders/index.js +230 -0
  5. package/dist/src/compounds.d.ts +13 -0
  6. package/dist/src/compounds.js +118 -0
  7. package/dist/src/deck.d.ts +4 -0
  8. package/dist/src/deck.js +91 -0
  9. package/dist/src/diagnostics.d.ts +5 -0
  10. package/dist/src/diagnostics.js +113 -0
  11. package/dist/src/export/index.d.ts +8 -0
  12. package/dist/src/export/index.js +15 -0
  13. package/dist/src/index.d.ts +19 -0
  14. package/dist/src/index.js +35 -0
  15. package/dist/src/kernel.d.ts +8 -0
  16. package/dist/src/kernel.js +68 -0
  17. package/dist/src/normalize.d.ts +6 -0
  18. package/dist/src/normalize.js +191 -0
  19. package/dist/src/patch.d.ts +5 -0
  20. package/dist/src/patch.js +72 -0
  21. package/dist/src/path-sampling.d.ts +3 -0
  22. package/dist/src/path-sampling.js +275 -0
  23. package/dist/src/player/index.d.ts +68 -0
  24. package/dist/src/player/index.js +600 -0
  25. package/dist/src/project.d.ts +11 -0
  26. package/dist/src/project.js +107 -0
  27. package/dist/src/render/html.d.ts +2 -0
  28. package/dist/src/render/html.js +13 -0
  29. package/dist/src/render/raw-three.d.ts +7 -0
  30. package/dist/src/render/raw-three.js +17 -0
  31. package/dist/src/render/svg.d.ts +3 -0
  32. package/dist/src/render/svg.js +277 -0
  33. package/dist/src/render/three-html.d.ts +2 -0
  34. package/dist/src/render/three-html.js +303 -0
  35. package/dist/src/render/three-preview-svg.d.ts +3 -0
  36. package/dist/src/render/three-preview-svg.js +102 -0
  37. package/dist/src/scenes.d.ts +4 -0
  38. package/dist/src/scenes.js +25 -0
  39. package/dist/src/schema.d.ts +2 -0
  40. package/dist/src/schema.js +403 -0
  41. package/dist/src/sequences.d.ts +43 -0
  42. package/dist/src/sequences.js +109 -0
  43. package/dist/src/shapes/builtins.d.ts +2 -0
  44. package/dist/src/shapes/builtins.js +429 -0
  45. package/dist/src/shapes/common.d.ts +9 -0
  46. package/dist/src/shapes/common.js +75 -0
  47. package/dist/src/shapes/geometry.d.ts +22 -0
  48. package/dist/src/shapes/geometry.js +166 -0
  49. package/dist/src/shapes/index.d.ts +2 -0
  50. package/dist/src/shapes/index.js +18 -0
  51. package/dist/src/shapes/registry.d.ts +9 -0
  52. package/dist/src/shapes/registry.js +35 -0
  53. package/dist/src/shapes/types.d.ts +34 -0
  54. package/dist/src/shapes/types.js +2 -0
  55. package/dist/src/types.d.ts +439 -0
  56. package/dist/src/types.js +2 -0
  57. package/dist/src/utils.d.ts +25 -0
  58. package/dist/src/utils.js +157 -0
  59. package/dist/src/validate.d.ts +2 -0
  60. package/dist/src/validate.js +434 -0
  61. package/dist/tests/run.d.ts +1 -0
  62. package/dist/tests/run.js +651 -0
  63. package/package.json +52 -0
  64. package/schema/visual.schema.json +930 -0
@@ -0,0 +1,74 @@
1
+ import type { AnimationValue, ArcElement, CircleElement, CurveElement, EllipseElement, Endpoint, GroupElement, LineElement, PointElement, PolygonElement, PolylineElement, RectElement, TextElement, VisualDocument, VisualElement } from "../types";
2
+ export type ElementInput = VisualElement | VisualElement[];
3
+ export declare function scene(input: Omit<VisualDocument, "version"> & {
4
+ version?: 1;
5
+ }): VisualDocument;
6
+ export declare function rect(input: Omit<RectElement, "type">): RectElement;
7
+ export declare function circle(input: Omit<CircleElement, "type">): CircleElement;
8
+ export declare function ellipse(input: Omit<EllipseElement, "type">): EllipseElement;
9
+ export declare function point(input: Omit<PointElement, "type">): PointElement;
10
+ export declare function polyline(input: Omit<PolylineElement, "type">): PolylineElement;
11
+ export declare function polygon(input: Omit<PolygonElement, "type">): PolygonElement;
12
+ export declare function text(input: Omit<TextElement, "type">): TextElement;
13
+ export declare function line(input: Omit<LineElement, "type">): LineElement;
14
+ export declare function arrow(input: Omit<LineElement, "type">): LineElement;
15
+ export declare function arc(input: Omit<ArcElement, "type">): ArcElement;
16
+ export declare function curve(input: Omit<CurveElement, "type">): CurveElement;
17
+ export declare function group(input: Omit<GroupElement, "type">): GroupElement;
18
+ export declare function animate(from: number | string, to: number | string, options?: Omit<AnimationValue, "from" | "to">): AnimationValue;
19
+ export declare function keyframes(values: Array<[number, number | string]>): AnimationValue;
20
+ export interface NodeOptions {
21
+ id: string;
22
+ label: string;
23
+ x: number;
24
+ y: number;
25
+ width: number;
26
+ height: number;
27
+ radius?: number;
28
+ fill?: string;
29
+ stroke?: string;
30
+ strokeWidth?: number;
31
+ fontSize?: number;
32
+ textFill?: string;
33
+ }
34
+ export declare function node(options: NodeOptions): [RectElement, TextElement];
35
+ export interface FlowOptions {
36
+ id: string;
37
+ from: Endpoint;
38
+ to: Endpoint;
39
+ stroke?: string;
40
+ strokeWidth?: number;
41
+ label?: string;
42
+ labelX?: number;
43
+ labelY?: number;
44
+ }
45
+ export declare function flow(options: FlowOptions): VisualElement[];
46
+ export interface PacketOptions {
47
+ id: string;
48
+ on: string;
49
+ radius?: number;
50
+ fill?: string;
51
+ progress: number | AnimationValue;
52
+ }
53
+ export declare function packet(options: PacketOptions): CircleElement;
54
+ export interface CalloutOptions {
55
+ id: string;
56
+ text: string;
57
+ x: number;
58
+ y: number;
59
+ width: number;
60
+ height: number;
61
+ target: Endpoint;
62
+ fill?: string;
63
+ textFill?: string;
64
+ stroke?: string;
65
+ }
66
+ export declare function callout(options: CalloutOptions): VisualElement[];
67
+ export interface StackOptions {
68
+ x: number;
69
+ y: number;
70
+ gap?: number;
71
+ children: ElementInput[];
72
+ }
73
+ export declare function row(options: StackOptions): VisualElement[];
74
+ export declare function column(options: StackOptions): VisualElement[];
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scene = scene;
4
+ exports.rect = rect;
5
+ exports.circle = circle;
6
+ exports.ellipse = ellipse;
7
+ exports.point = point;
8
+ exports.polyline = polyline;
9
+ exports.polygon = polygon;
10
+ exports.text = text;
11
+ exports.line = line;
12
+ exports.arrow = arrow;
13
+ exports.arc = arc;
14
+ exports.curve = curve;
15
+ exports.group = group;
16
+ exports.animate = animate;
17
+ exports.keyframes = keyframes;
18
+ exports.node = node;
19
+ exports.flow = flow;
20
+ exports.packet = packet;
21
+ exports.callout = callout;
22
+ exports.row = row;
23
+ exports.column = column;
24
+ const utils_1 = require("../utils");
25
+ function scene(input) {
26
+ return { version: 1, ...input };
27
+ }
28
+ function rect(input) {
29
+ return { type: "rect", ...input };
30
+ }
31
+ function circle(input) {
32
+ return { type: "circle", ...input };
33
+ }
34
+ function ellipse(input) {
35
+ return { type: "ellipse", ...input };
36
+ }
37
+ function point(input) {
38
+ return { type: "point", ...input };
39
+ }
40
+ function polyline(input) {
41
+ return { type: "polyline", ...input };
42
+ }
43
+ function polygon(input) {
44
+ return { type: "polygon", ...input };
45
+ }
46
+ function text(input) {
47
+ return { type: "text", ...input };
48
+ }
49
+ function line(input) {
50
+ return { type: "line", ...input };
51
+ }
52
+ function arrow(input) {
53
+ return { type: "arrow", ...input };
54
+ }
55
+ function arc(input) {
56
+ return { type: "arc", ...input };
57
+ }
58
+ function curve(input) {
59
+ return { type: "curve", ...input };
60
+ }
61
+ function group(input) {
62
+ return { type: "group", ...input };
63
+ }
64
+ function animate(from, to, options = {}) {
65
+ return { from, to, ...options };
66
+ }
67
+ function keyframes(values) {
68
+ return { keyframes: values };
69
+ }
70
+ function node(options) {
71
+ return [
72
+ rect({
73
+ id: `${options.id}_box`,
74
+ x: options.x,
75
+ y: options.y,
76
+ width: options.width,
77
+ height: options.height,
78
+ radius: options.radius ?? 12,
79
+ fill: options.fill ?? "#ffffff",
80
+ stroke: options.stroke ?? "#2563eb",
81
+ strokeWidth: options.strokeWidth ?? 2
82
+ }),
83
+ text({
84
+ id: `${options.id}_label`,
85
+ text: options.label,
86
+ x: options.x + options.width / 2,
87
+ y: options.y + options.height / 2,
88
+ align: "center",
89
+ valign: "middle",
90
+ fontSize: options.fontSize ?? 18,
91
+ fill: options.textFill ?? "#111827"
92
+ })
93
+ ];
94
+ }
95
+ function flow(options) {
96
+ const out = [
97
+ arrow({
98
+ id: options.id,
99
+ from: options.from,
100
+ to: options.to,
101
+ stroke: options.stroke ?? "#2563eb",
102
+ strokeWidth: options.strokeWidth ?? 2
103
+ })
104
+ ];
105
+ if (options.label) {
106
+ if (typeof options.labelX !== "number" || typeof options.labelY !== "number") {
107
+ throw new Error("flow label requires explicit labelX and labelY. The builder does not infer label positions.");
108
+ }
109
+ out.push(text({
110
+ id: `${options.id}_label`,
111
+ text: options.label,
112
+ x: options.labelX,
113
+ y: options.labelY,
114
+ align: "center",
115
+ valign: "middle",
116
+ fontSize: 14,
117
+ fill: options.stroke ?? "#2563eb"
118
+ }));
119
+ }
120
+ return out;
121
+ }
122
+ function packet(options) {
123
+ return circle({
124
+ id: options.id,
125
+ radius: options.radius ?? 7,
126
+ fill: options.fill ?? "#ef4444",
127
+ follow: options.on,
128
+ progress: options.progress
129
+ });
130
+ }
131
+ function callout(options) {
132
+ const boxId = `${options.id}_box`;
133
+ return [
134
+ rect({
135
+ id: boxId,
136
+ x: options.x,
137
+ y: options.y,
138
+ width: options.width,
139
+ height: options.height,
140
+ radius: 8,
141
+ fill: options.fill ?? "#111827",
142
+ stroke: options.stroke ?? "none"
143
+ }),
144
+ text({
145
+ id: `${options.id}_text`,
146
+ text: options.text,
147
+ x: options.x + options.width / 2,
148
+ y: options.y + options.height / 2,
149
+ align: "center",
150
+ valign: "middle",
151
+ fontSize: 15,
152
+ fill: options.textFill ?? "#ffffff"
153
+ }),
154
+ arrow({
155
+ id: `${options.id}_arrow`,
156
+ from: `${boxId}.bottom`,
157
+ to: options.target,
158
+ stroke: options.stroke ?? "#ef4444",
159
+ strokeWidth: 2
160
+ })
161
+ ];
162
+ }
163
+ function row(options) {
164
+ return stack(options, "row");
165
+ }
166
+ function column(options) {
167
+ return stack(options, "column");
168
+ }
169
+ function stack(options, direction) {
170
+ const gap = options.gap ?? 0;
171
+ let cursorX = options.x;
172
+ let cursorY = options.y;
173
+ const out = [];
174
+ for (const childInput of options.children) {
175
+ const child = Array.isArray(childInput) ? childInput : [childInput];
176
+ const bounds = boundsFor(child);
177
+ if (!bounds)
178
+ throw new Error(`${direction} children must have explicit geometry. No auto measurement is performed.`);
179
+ const dx = cursorX - bounds.x;
180
+ const dy = cursorY - bounds.y;
181
+ const moved = child.map((element) => translateElement(element, dx, dy));
182
+ out.push(...moved);
183
+ if (direction === "row")
184
+ cursorX += bounds.width + gap;
185
+ else
186
+ cursorY += bounds.height + gap;
187
+ }
188
+ return out;
189
+ }
190
+ function boundsFor(elements) {
191
+ const boxes = elements.map((element) => (0, utils_1.elementBox)(element)).filter(Boolean);
192
+ if (!boxes.length)
193
+ return undefined;
194
+ const left = Math.min(...boxes.map((box) => box.x));
195
+ const top = Math.min(...boxes.map((box) => box.y));
196
+ const right = Math.max(...boxes.map((box) => box.x + box.width));
197
+ const bottom = Math.max(...boxes.map((box) => box.y + box.height));
198
+ return { x: left, y: top, width: right - left, height: bottom - top };
199
+ }
200
+ function translateElement(element, dx, dy) {
201
+ const next = (0, utils_1.clone)(element);
202
+ if ("x" in next && typeof next.x === "number")
203
+ next.x += dx;
204
+ if ("y" in next && typeof next.y === "number")
205
+ next.y += dy;
206
+ if ("cx" in next && typeof next.cx === "number")
207
+ next.cx += dx;
208
+ if ("cy" in next && typeof next.cy === "number")
209
+ next.cy += dy;
210
+ if ((next.type === "line" || next.type === "arrow" || next.type === "curve") && Array.isArray(next.from) && Array.isArray(next.to)) {
211
+ next.from = [Number(next.from[0]) + dx, Number(next.from[1]) + dy];
212
+ next.to = [Number(next.to[0]) + dx, Number(next.to[1]) + dy];
213
+ }
214
+ if (next.type === "arc") {
215
+ next.cx += dx;
216
+ next.cy += dy;
217
+ }
218
+ if (next.type === "curve") {
219
+ next.control1 = [next.control1[0] + dx, next.control1[1] + dy];
220
+ if (next.control2)
221
+ next.control2 = [next.control2[0] + dx, next.control2[1] + dy];
222
+ }
223
+ if ((next.type === "polyline" || next.type === "polygon") && Array.isArray(next.points)) {
224
+ next.points = next.points.map((point) => [point[0] + dx, point[1] + dy]);
225
+ }
226
+ if (next.type === "group" && Array.isArray(next.children)) {
227
+ next.children = next.children.map((child) => translateElement(child, dx, dy));
228
+ }
229
+ return next;
230
+ }
@@ -0,0 +1,13 @@
1
+ import type { VisualDocument } from "./types";
2
+ type LooseElement = Record<string, unknown> & {
3
+ type?: string;
4
+ children?: LooseElement[];
5
+ };
6
+ type LooseDocument = Omit<VisualDocument, "elements" | "scenes"> & {
7
+ elements?: LooseElement[];
8
+ scenes?: Record<string, Record<string, unknown> & {
9
+ elements?: LooseElement[];
10
+ }>;
11
+ };
12
+ export declare function compileCompounds(input: LooseDocument): VisualDocument;
13
+ export {};
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileCompounds = compileCompounds;
4
+ const builders_1 = require("./builders");
5
+ const utils_1 = require("./utils");
6
+ function compileCompounds(input) {
7
+ const document = (0, utils_1.clone)(input);
8
+ const elements = compileElementList(document.elements ?? []);
9
+ const scenes = {};
10
+ for (const [sceneId, scene] of Object.entries(document.scenes ?? {})) {
11
+ scenes[sceneId] = {
12
+ ...scene,
13
+ elements: compileElementList(scene.elements ?? [])
14
+ };
15
+ }
16
+ return {
17
+ ...document,
18
+ elements,
19
+ ...(Object.keys(scenes).length ? { scenes } : {})
20
+ };
21
+ }
22
+ function compileElementList(elements) {
23
+ return elements.flatMap((element) => compileElement(element));
24
+ }
25
+ function compileElement(element) {
26
+ switch (element.type) {
27
+ case "node":
28
+ return (0, builders_1.node)({
29
+ id: stringProp(element, "id"),
30
+ label: stringProp(element, "label"),
31
+ x: numberProp(element, "x"),
32
+ y: numberProp(element, "y"),
33
+ width: numberProp(element, "width"),
34
+ height: numberProp(element, "height"),
35
+ radius: optionalNumber(element, "radius"),
36
+ fill: optionalString(element, "fill"),
37
+ stroke: optionalString(element, "stroke"),
38
+ strokeWidth: optionalNumber(element, "strokeWidth"),
39
+ fontSize: optionalNumber(element, "fontSize"),
40
+ textFill: optionalString(element, "textFill")
41
+ });
42
+ case "flow":
43
+ return (0, builders_1.flow)({
44
+ id: stringProp(element, "id"),
45
+ from: element.from,
46
+ to: element.to,
47
+ stroke: optionalString(element, "stroke"),
48
+ strokeWidth: optionalNumber(element, "strokeWidth"),
49
+ label: optionalString(element, "label"),
50
+ labelX: optionalNumber(element, "labelX"),
51
+ labelY: optionalNumber(element, "labelY")
52
+ });
53
+ case "packet":
54
+ return [
55
+ (0, builders_1.packet)({
56
+ id: stringProp(element, "id"),
57
+ on: stringProp(element, "on"),
58
+ radius: optionalNumber(element, "radius"),
59
+ fill: optionalString(element, "fill"),
60
+ progress: element.progress
61
+ })
62
+ ];
63
+ case "callout":
64
+ return (0, builders_1.callout)({
65
+ id: stringProp(element, "id"),
66
+ text: stringProp(element, "text"),
67
+ x: numberProp(element, "x"),
68
+ y: numberProp(element, "y"),
69
+ width: numberProp(element, "width"),
70
+ height: numberProp(element, "height"),
71
+ target: element.target,
72
+ fill: optionalString(element, "fill"),
73
+ textFill: optionalString(element, "textFill"),
74
+ stroke: optionalString(element, "stroke")
75
+ });
76
+ case "row":
77
+ return (0, builders_1.row)({
78
+ x: numberProp(element, "x"),
79
+ y: numberProp(element, "y"),
80
+ gap: optionalNumber(element, "gap"),
81
+ children: (element.children ?? []).map((child) => compileElement(child))
82
+ });
83
+ case "column":
84
+ return (0, builders_1.column)({
85
+ x: numberProp(element, "x"),
86
+ y: numberProp(element, "y"),
87
+ gap: optionalNumber(element, "gap"),
88
+ children: (element.children ?? []).map((child) => compileElement(child))
89
+ });
90
+ default: {
91
+ const next = (0, utils_1.clone)(element);
92
+ if (next.type === "group" && Array.isArray(next.children)) {
93
+ next.children = compileElementList(next.children);
94
+ }
95
+ return [next];
96
+ }
97
+ }
98
+ }
99
+ function stringProp(element, key) {
100
+ const value = element[key];
101
+ if (typeof value !== "string" || !value)
102
+ throw new Error(`Compound '${element.type}' requires string '${key}'.`);
103
+ return value;
104
+ }
105
+ function optionalString(element, key) {
106
+ const value = element[key];
107
+ return typeof value === "string" ? value : undefined;
108
+ }
109
+ function numberProp(element, key) {
110
+ const value = element[key];
111
+ if (typeof value !== "number" || !Number.isFinite(value))
112
+ throw new Error(`Compound '${element.type}' requires number '${key}'.`);
113
+ return value;
114
+ }
115
+ function optionalNumber(element, key) {
116
+ const value = element[key];
117
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
118
+ }
@@ -0,0 +1,4 @@
1
+ import type { ResolvedVisualDocument, VisualDocument } from "./types";
2
+ export declare function documentForDeckStep(document: VisualDocument, sceneId: string, stepIndex: number): VisualDocument;
3
+ export declare function resolvedFrameForDeckStep(document: VisualDocument, sceneId: string, stepIndex: number, time?: number): ResolvedVisualDocument;
4
+ export declare function renderDeckToHtml(document: VisualDocument, sceneId: string): string;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.documentForDeckStep = documentForDeckStep;
4
+ exports.resolvedFrameForDeckStep = resolvedFrameForDeckStep;
5
+ exports.renderDeckToHtml = renderDeckToHtml;
6
+ const scenes_1 = require("./scenes");
7
+ const normalize_1 = require("./normalize");
8
+ const utils_1 = require("./utils");
9
+ const svg_1 = require("./render/svg");
10
+ function documentForDeckStep(document, sceneId, stepIndex) {
11
+ const scene = document.scenes?.[sceneId];
12
+ if (!scene)
13
+ throw new Error(`Unknown scene '${sceneId}'.`);
14
+ const frame = (0, scenes_1.documentForScene)(document, sceneId);
15
+ const activeSteps = (scene.steps ?? []).slice(0, Math.max(0, stepIndex + 1));
16
+ if (!activeSteps.length)
17
+ return frame;
18
+ const hidden = new Set();
19
+ const shown = new Set();
20
+ for (const step of activeSteps) {
21
+ for (const id of step.hide ?? [])
22
+ hidden.add(id);
23
+ for (const id of step.show ?? []) {
24
+ hidden.delete(id);
25
+ shown.add(id);
26
+ }
27
+ }
28
+ frame.elements = applyDeckVisibility(frame.elements ?? [], hidden, shown);
29
+ return frame;
30
+ }
31
+ function resolvedFrameForDeckStep(document, sceneId, stepIndex, time = 0) {
32
+ return (0, normalize_1.resolveVisualFrame)(documentForDeckStep(document, sceneId, stepIndex), time);
33
+ }
34
+ function renderDeckToHtml(document, sceneId) {
35
+ const scene = document.scenes?.[sceneId];
36
+ if (!scene)
37
+ throw new Error(`Unknown scene '${sceneId}'.`);
38
+ const steps = scene.steps ?? [];
39
+ const frameCount = Math.max(1, steps.length + 1);
40
+ const frames = Array.from({ length: frameCount }, (_, index) => {
41
+ const stepIndex = index - 1;
42
+ const frame = stepIndex < 0 ? (0, scenes_1.documentForScene)(document, sceneId) : documentForDeckStep(document, sceneId, stepIndex);
43
+ return (0, svg_1.renderToSvg)(frame);
44
+ });
45
+ const labels = ["Base", ...steps.map((step) => step.id)];
46
+ return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeHtml(sceneId)} Deck</title><style>
47
+ html,body{margin:0;width:100%;height:100%;background:#111827;color:#e5e7eb;font-family:Inter,Arial,sans-serif}
48
+ body{display:grid;grid-template-rows:1fr auto}
49
+ main{display:grid;place-items:center;padding:24px}
50
+ #stage svg{max-width:min(100vw,${document.canvas.width}px);max-height:calc(100vh - 112px);background:white;box-shadow:0 20px 50px rgba(0,0,0,.35)}
51
+ footer{display:flex;align-items:center;gap:12px;padding:12px 16px;background:#020617;border-top:1px solid #1f2937}
52
+ button{border:0;border-radius:6px;padding:8px 12px;background:#2563eb;color:#fff;font-weight:700}
53
+ button:disabled{opacity:.45}
54
+ code{color:#93c5fd}
55
+ </style></head><body><main><div id="stage"></div></main><footer><button id="prev">Prev</button><button id="next">Next</button><span id="count"></span><code id="label"></code></footer><script>
56
+ const frames=${JSON.stringify(frames)};
57
+ const labels=${JSON.stringify(labels)};
58
+ let index=0;
59
+ const stage=document.getElementById("stage");
60
+ const prev=document.getElementById("prev");
61
+ const next=document.getElementById("next");
62
+ const count=document.getElementById("count");
63
+ const label=document.getElementById("label");
64
+ function show(){
65
+ stage.innerHTML=frames[index];
66
+ prev.disabled=index===0;
67
+ next.disabled=index===frames.length-1;
68
+ count.textContent=(index+1)+" / "+frames.length;
69
+ label.textContent=labels[index] || "";
70
+ }
71
+ prev.addEventListener("click",()=>{ index=Math.max(0,index-1); show(); });
72
+ next.addEventListener("click",()=>{ index=Math.min(frames.length-1,index+1); show(); });
73
+ window.addEventListener("keydown",(event)=>{ if(event.key==="ArrowRight") next.click(); if(event.key==="ArrowLeft") prev.click(); });
74
+ show();
75
+ </script></body></html>`;
76
+ }
77
+ function applyDeckVisibility(elements, hidden, shown) {
78
+ return elements.map((element) => {
79
+ const next = (0, utils_1.clone)(element);
80
+ if (next.id && hidden.has(next.id))
81
+ next.opacity = 0;
82
+ if (next.id && shown.has(next.id) && next.opacity === 0)
83
+ next.opacity = 1;
84
+ if (next.type === "group" && Array.isArray(next.children))
85
+ next.children = applyDeckVisibility(next.children, hidden, shown);
86
+ return next;
87
+ });
88
+ }
89
+ function escapeHtml(value) {
90
+ return String(value).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
91
+ }
@@ -0,0 +1,5 @@
1
+ import type { ValidationWarning, VisualDocument } from "./types";
2
+ export interface VisualDiagnosticReport {
3
+ warnings: ValidationWarning[];
4
+ }
5
+ export declare function lintVisualDocument(document: VisualDocument): VisualDiagnosticReport;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lintVisualDocument = lintVisualDocument;
4
+ const utils_1 = require("./utils");
5
+ function lintVisualDocument(document) {
6
+ const warnings = [];
7
+ const elements = (0, utils_1.flattenElements)(document.elements ?? []);
8
+ const boxes = elements
9
+ .map((element) => ({ element, box: (0, utils_1.elementBox)(element) }))
10
+ .filter((item) => Boolean(item.box));
11
+ for (const { element, box } of boxes) {
12
+ const path = element.id ? `/elements/${element.id}` : "/elements";
13
+ if (box.x < 0 || box.y < 0 || box.x + box.width > document.canvas.width || box.y + box.height > document.canvas.height) {
14
+ warnings.push({
15
+ path,
16
+ code: "element_outside_canvas",
17
+ message: `Element '${element.id ?? element.type}' extends outside the canvas.`,
18
+ suggestion: "Move it inside the canvas or intentionally clip it with a group/mask later."
19
+ });
20
+ }
21
+ if (element.type === "text" && Number(element.fontSize ?? 16) < 10) {
22
+ warnings.push({
23
+ path,
24
+ code: "tiny_text",
25
+ message: `Text '${element.id ?? ""}' may be unreadable below 10px.`,
26
+ suggestion: "Use fontSize 12 or larger for explainer visuals."
27
+ });
28
+ }
29
+ if (element.type === "text") {
30
+ const containingBox = boxes.find((item) => item.element.type === "rect" && item.element.id !== element.id && pointInside(element.x, element.y, item.box));
31
+ if (containingBox && !boxInside(box, containingBox.box)) {
32
+ warnings.push({
33
+ path,
34
+ code: "text_likely_outside_box",
35
+ message: `Text '${element.id ?? ""}' is anchored inside '${containingBox.element.id ?? "rect"}' but its estimated bounds extend outside.`,
36
+ suggestion: "Move the text explicitly, reduce fontSize, or set maxWidth/wrap intentionally."
37
+ });
38
+ }
39
+ const contrastAgainst = containingBox?.element.fill ?? document.canvas.background ?? "#ffffff";
40
+ const ratio = contrastRatio(String(element.fill ?? "#111827"), String(contrastAgainst));
41
+ if (ratio !== undefined && ratio < 3) {
42
+ warnings.push({
43
+ path,
44
+ code: "low_text_contrast",
45
+ message: `Text '${element.id ?? ""}' may not have enough contrast.`,
46
+ suggestion: "Choose a darker or lighter explicit fill color; diagnostics do not recolor text."
47
+ });
48
+ }
49
+ }
50
+ }
51
+ for (let left = 0; left < boxes.length; left += 1) {
52
+ for (let right = left + 1; right < boxes.length; right += 1) {
53
+ const a = boxes[left];
54
+ const b = boxes[right];
55
+ if (a.element.type !== "text" || b.element.type !== "text")
56
+ continue;
57
+ if (overlaps(a.box, b.box)) {
58
+ warnings.push({
59
+ path: "/elements",
60
+ code: "possible_text_overlap",
61
+ message: `Text may overlap between '${a.element.id ?? a.element.type}' and '${b.element.id ?? b.element.type}'.`,
62
+ suggestion: "Move one text element explicitly; diagnostics do not auto-layout."
63
+ });
64
+ }
65
+ }
66
+ }
67
+ return { warnings };
68
+ }
69
+ function overlaps(a, b) {
70
+ return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
71
+ }
72
+ function pointInside(x, y, box) {
73
+ return x >= box.x && x <= box.x + box.width && y >= box.y && y <= box.y + box.height;
74
+ }
75
+ function boxInside(inner, outer) {
76
+ return inner.x >= outer.x && inner.y >= outer.y && inner.x + inner.width <= outer.x + outer.width && inner.y + inner.height <= outer.y + outer.height;
77
+ }
78
+ function contrastRatio(foreground, background) {
79
+ const fg = parseHexColor(foreground);
80
+ const bg = parseHexColor(background);
81
+ if (!fg || !bg)
82
+ return undefined;
83
+ const a = relativeLuminance(fg);
84
+ const b = relativeLuminance(bg);
85
+ const light = Math.max(a, b);
86
+ const dark = Math.min(a, b);
87
+ return (light + 0.05) / (dark + 0.05);
88
+ }
89
+ function parseHexColor(value) {
90
+ const text = value.trim();
91
+ if (/^#[0-9a-fA-F]{3}$/.test(text)) {
92
+ return [
93
+ parseInt(text[1] + text[1], 16),
94
+ parseInt(text[2] + text[2], 16),
95
+ parseInt(text[3] + text[3], 16)
96
+ ];
97
+ }
98
+ if (/^#[0-9a-fA-F]{6}$/.test(text)) {
99
+ return [
100
+ parseInt(text.slice(1, 3), 16),
101
+ parseInt(text.slice(3, 5), 16),
102
+ parseInt(text.slice(5, 7), 16)
103
+ ];
104
+ }
105
+ return undefined;
106
+ }
107
+ function relativeLuminance([r, g, b]) {
108
+ const values = [r, g, b].map((channel) => {
109
+ const value = channel / 255;
110
+ return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
111
+ });
112
+ return 0.2126 * values[0] + 0.7152 * values[1] + 0.0722 * values[2];
113
+ }
@@ -0,0 +1,8 @@
1
+ import type { ExportOptions, VisualDocument } from "../types";
2
+ export interface ExportResult {
3
+ format: string;
4
+ content: string;
5
+ mimeType: string;
6
+ warnings?: string[];
7
+ }
8
+ export declare function exportVisual(document: VisualDocument, options?: ExportOptions): ExportResult;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportVisual = exportVisual;
4
+ const html_1 = require("../render/html");
5
+ const svg_1 = require("../render/svg");
6
+ function exportVisual(document, options = {}) {
7
+ const format = options.format ?? "svg";
8
+ if (format === "svg") {
9
+ return { format, content: (0, svg_1.renderToSvg)(document, options), mimeType: "image/svg+xml" };
10
+ }
11
+ if (format === "html") {
12
+ return { format, content: (0, html_1.renderToHtml)(document, options), mimeType: "text/html" };
13
+ }
14
+ throw new Error(`${format.toUpperCase()} export is reserved for the advanced renderer/export adapter. The primitive JSON core currently exports svg and html directly.`);
15
+ }