sketchmark 2.1.0 → 2.1.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.
- package/package.json +1 -7
- package/ANIMATABLE_MATRIX.md +0 -177
- package/KERNEL_SPEC.md +0 -412
- package/PACKS.md +0 -81
- package/PRESETS.md +0 -182
- package/dist/src/builders/index.d.ts +0 -64
- package/dist/src/builders/index.js +0 -212
- package/dist/src/compounds.d.ts +0 -13
- package/dist/src/compounds.js +0 -118
- package/dist/src/deck.d.ts +0 -4
- package/dist/src/deck.js +0 -91
- package/dist/src/export/index.d.ts +0 -8
- package/dist/src/export/index.js +0 -15
- package/dist/src/kernel.d.ts +0 -8
- package/dist/src/kernel.js +0 -68
- package/dist/src/motion.d.ts +0 -4
- package/dist/src/motion.js +0 -262
- package/dist/src/patch.d.ts +0 -5
- package/dist/src/patch.js +0 -72
- package/dist/src/player/index.d.ts +0 -68
- package/dist/src/player/index.js +0 -600
- package/dist/src/project.d.ts +0 -11
- package/dist/src/project.js +0 -107
- package/dist/src/render/raw-three.d.ts +0 -7
- package/dist/src/render/raw-three.js +0 -17
- package/dist/src/render/three-html.d.ts +0 -2
- package/dist/src/render/three-html.js +0 -257
- package/dist/src/render/three-preview-svg.d.ts +0 -3
- package/dist/src/render/three-preview-svg.js +0 -102
- package/dist/src/scenes.d.ts +0 -4
- package/dist/src/scenes.js +0 -26
- package/dist/src/sequences.d.ts +0 -43
- package/dist/src/sequences.js +0 -109
- package/dist/src/shapes/builtins.d.ts +0 -2
- package/dist/src/shapes/builtins.js +0 -393
- package/dist/src/shapes/common.d.ts +0 -9
- package/dist/src/shapes/common.js +0 -76
- package/dist/src/shapes/geometry.d.ts +0 -22
- package/dist/src/shapes/geometry.js +0 -166
- package/dist/src/shapes/index.d.ts +0 -2
- package/dist/src/shapes/index.js +0 -18
- package/dist/src/shapes/registry.d.ts +0 -8
- package/dist/src/shapes/registry.js +0 -31
- package/dist/src/shapes/types.d.ts +0 -32
- package/dist/src/shapes/types.js +0 -2
- package/examples/1730642890464.jpg +0 -0
- package/examples/app-screen.svg +0 -1
- package/examples/app-screen.visual.json +0 -503
- package/examples/dashboard-table.svg +0 -1
- package/examples/dashboard-table.visual.json +0 -708
- package/examples/dev-docs.svg +0 -1
- package/examples/dev-docs.visual.json +0 -248
- package/examples/explainer.mp4 +0 -0
- package/examples/explainer.visual.json +0 -1713
- package/examples/group-origin-effects-lab-check.svg +0 -1
- package/examples/group-origin-effects-lab.visual.json +0 -1880
- package/examples/image-clip-radius.visual.json +0 -271
- package/examples/make-app-screen.cjs +0 -368
- package/examples/make-dashboard-table.cjs +0 -277
- package/examples/make-dev-docs.cjs +0 -233
- package/examples/make-explainer.cjs +0 -438
- package/examples/make-group-origin-effects-lab.cjs +0 -370
- package/examples/make-image-clip-radius.cjs +0 -169
- package/examples/make-modal-dialog.cjs +0 -355
- package/examples/make-origin-effects-lab.cjs +0 -311
- package/examples/make-preset-character-motion.cjs +0 -32
- package/examples/make-presets-demo.cjs +0 -30
- package/examples/make-pricing.cjs +0 -286
- package/examples/make-product-demo.cjs +0 -468
- package/examples/make-product-hero.cjs +0 -223
- package/examples/make-release-notes.cjs +0 -333
- package/examples/make-settings-panel.cjs +0 -435
- package/examples/make-split-preview.cjs +0 -248
- package/examples/make-storyboard.cjs +0 -215
- package/examples/make-transcript.cjs +0 -234
- package/examples/make-typography-test.cjs +0 -397
- package/examples/make-ui-demo-explainer.cjs +0 -1094
- package/examples/make-ui-flow.cjs +0 -762
- package/examples/make-walkthrough.cjs +0 -815
- package/examples/modal-dialog.svg +0 -1
- package/examples/modal-dialog.visual.json +0 -239
- package/examples/origin-effects-lab-check.svg +0 -1
- package/examples/origin-effects-lab.visual.json +0 -1412
- package/examples/preset-character-motion.visual.json +0 -949
- package/examples/presets-demo.visual.json +0 -787
- package/examples/pricing.svg +0 -1
- package/examples/pricing.visual.json +0 -652
- package/examples/product-demo.mp4 +0 -0
- package/examples/product-demo.visual.json +0 -866
- package/examples/product-hero.svg +0 -1
- package/examples/product-hero.visual.json +0 -242
- package/examples/release-notes.svg +0 -1
- package/examples/release-notes.visual.json +0 -467
- package/examples/settings-panel.svg +0 -1
- package/examples/settings-panel.visual.json +0 -501
- package/examples/split-preview.svg +0 -1
- package/examples/split-preview.visual.json +0 -124
- package/examples/storyboard.svg +0 -1
- package/examples/storyboard.visual.json +0 -312
- package/examples/transcript.svg +0 -1
- package/examples/transcript.visual.json +0 -407
- package/examples/typography-indent-check.svg +0 -1
- package/examples/typography-lineheight-0.svg +0 -1
- package/examples/typography-lineheight-2.svg +0 -1
- package/examples/typography-test-check.svg +0 -1
- package/examples/typography-test.svg +0 -1
- package/examples/typography-test.visual.json +0 -757
- package/examples/ui-demo-explainer-billing.svg +0 -1
- package/examples/ui-demo-explainer-check.svg +0 -1
- package/examples/ui-demo-explainer-save.svg +0 -1
- package/examples/ui-demo-explainer-toggle.svg +0 -1
- package/examples/ui-demo-explainer.mp4 +0 -0
- package/examples/ui-demo-explainer.visual.json +0 -2597
- package/examples/ui-flow.mp4 +0 -0
- package/examples/ui-flow.visual.json +0 -1211
- package/examples/walkthrough.mp4 +0 -0
- package/examples/walkthrough.visual.json +0 -1372
package/dist/src/export/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/src/kernel.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { KernelVisualDocument, ResolvedVisualDocument, ValidationResult, VisualDocument } from "./types";
|
|
2
|
-
import { type NormalizeOptions } from "./normalize";
|
|
3
|
-
export interface LowerOptions extends NormalizeOptions {
|
|
4
|
-
}
|
|
5
|
-
export declare function lowerVisualDocument(document: VisualDocument, options?: LowerOptions): KernelVisualDocument;
|
|
6
|
-
export declare function resolveKernelFrame(document: VisualDocument, time?: number): KernelVisualDocument;
|
|
7
|
-
export declare function lowerResolvedVisualDocument(document: ResolvedVisualDocument): KernelVisualDocument;
|
|
8
|
-
export declare function validateKernelVisualDocument(document: KernelVisualDocument): ValidationResult;
|
package/dist/src/kernel.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lowerVisualDocument = lowerVisualDocument;
|
|
4
|
-
exports.resolveKernelFrame = resolveKernelFrame;
|
|
5
|
-
exports.lowerResolvedVisualDocument = lowerResolvedVisualDocument;
|
|
6
|
-
exports.validateKernelVisualDocument = validateKernelVisualDocument;
|
|
7
|
-
const normalize_1 = require("./normalize");
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const shapes_1 = require("./shapes");
|
|
10
|
-
const KERNEL_2D_TYPES = new Set(["group", "path", "text", "image", "point"]);
|
|
11
|
-
const KERNEL_3D_TYPES = new Set(["group3d", "mesh3d", "line3d", "text3d", "point3d", "light"]);
|
|
12
|
-
function lowerVisualDocument(document, options = {}) {
|
|
13
|
-
return lowerResolvedVisualDocument((0, normalize_1.normalizeVisualDocument)(document, options));
|
|
14
|
-
}
|
|
15
|
-
function resolveKernelFrame(document, time = 0) {
|
|
16
|
-
return lowerResolvedVisualDocument((0, normalize_1.resolveVisualFrame)(document, time));
|
|
17
|
-
}
|
|
18
|
-
function lowerResolvedVisualDocument(document) {
|
|
19
|
-
return {
|
|
20
|
-
version: document.version,
|
|
21
|
-
canvas: (0, utils_1.clone)(document.canvas),
|
|
22
|
-
imports: cloneOptional(document.imports),
|
|
23
|
-
assets: cloneOptional(document.assets),
|
|
24
|
-
exports: cloneOptional(document.exports),
|
|
25
|
-
elements: lowerElements(document.elements ?? [])
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function validateKernelVisualDocument(document) {
|
|
29
|
-
const issues = [];
|
|
30
|
-
const visit = (element, path) => {
|
|
31
|
-
if (!KERNEL_2D_TYPES.has(element.type) && !KERNEL_3D_TYPES.has(element.type)) {
|
|
32
|
-
issues.push({ path, code: "unsupported_kernel_type", message: `Kernel element type '${element.type}' is not supported.` });
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (element.type === "path" && typeof element.d !== "string") {
|
|
36
|
-
issues.push({ path, code: "missing_kernel_path", message: "Kernel path requires string 'd'." });
|
|
37
|
-
}
|
|
38
|
-
if (element.type === "text" && (!isFiniteNumber(element.x) || !isFiniteNumber(element.y))) {
|
|
39
|
-
issues.push({ path, code: "missing_kernel_text_position", message: "Kernel text requires numeric x and y." });
|
|
40
|
-
}
|
|
41
|
-
if (element.type === "image" && (!isFiniteNumber(element.x) || !isFiniteNumber(element.y) || !isFiniteNumber(element.width) || !isFiniteNumber(element.height))) {
|
|
42
|
-
issues.push({ path, code: "missing_kernel_image_box", message: "Kernel image requires numeric x, y, width, and height." });
|
|
43
|
-
}
|
|
44
|
-
if (element.type === "point" && (!isFiniteNumber(element.x) || !isFiniteNumber(element.y))) {
|
|
45
|
-
issues.push({ path, code: "missing_kernel_point", message: "Kernel point requires numeric x and y." });
|
|
46
|
-
}
|
|
47
|
-
if (element.type === "mesh3d" && (!Array.isArray(element.vertices) || !Array.isArray(element.indices))) {
|
|
48
|
-
issues.push({ path, code: "missing_kernel_mesh", message: "Kernel mesh3d requires vertices and indices." });
|
|
49
|
-
}
|
|
50
|
-
if ((element.type === "group" || element.type === "group3d") && Array.isArray(element.children)) {
|
|
51
|
-
element.children.forEach((child, index) => visit(child, `${path}/children/${index}`));
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
(document.elements ?? []).forEach((element, index) => visit(element, `/elements/${index}`));
|
|
55
|
-
return { ok: issues.length === 0, issues, warnings: [] };
|
|
56
|
-
}
|
|
57
|
-
function lowerElements(elements) {
|
|
58
|
-
return elements.flatMap((element) => lowerElement(element));
|
|
59
|
-
}
|
|
60
|
-
function lowerElement(element) {
|
|
61
|
-
return (0, shapes_1.lowerAuthoringElement)(element, { lowerElements });
|
|
62
|
-
}
|
|
63
|
-
function cloneOptional(value) {
|
|
64
|
-
return value === undefined ? undefined : (0, utils_1.clone)(value);
|
|
65
|
-
}
|
|
66
|
-
function isFiniteNumber(value) {
|
|
67
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
68
|
-
}
|
package/dist/src/motion.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { MotionDriver, MotionExpressionInput, MotionValue, VisualDocument, VisualElement } from "./types";
|
|
2
|
-
export declare function applyMotionDrivers(document: VisualDocument, time: number): VisualDocument;
|
|
3
|
-
export declare function evaluateDriver(driver: MotionDriver, elements: VisualElement[], time: number): MotionValue | undefined;
|
|
4
|
-
export declare function evaluateExpression(input: MotionExpressionInput, elements: VisualElement[], time: number): MotionValue;
|
package/dist/src/motion.js
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyMotionDrivers = applyMotionDrivers;
|
|
4
|
-
exports.evaluateDriver = evaluateDriver;
|
|
5
|
-
exports.evaluateExpression = evaluateExpression;
|
|
6
|
-
const path_sampling_1 = require("./path-sampling");
|
|
7
|
-
const shapes_1 = require("./shapes");
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const utils_2 = require("./utils");
|
|
10
|
-
function applyMotionDrivers(document, time) {
|
|
11
|
-
const next = (0, utils_1.clone)(document);
|
|
12
|
-
const drivers = next.motion?.drivers ?? [];
|
|
13
|
-
if (!drivers.length)
|
|
14
|
-
return next;
|
|
15
|
-
const elements = next.elements ?? [];
|
|
16
|
-
for (const driver of drivers) {
|
|
17
|
-
const value = evaluateDriver(driver, elements, time);
|
|
18
|
-
if (value !== undefined)
|
|
19
|
-
applyDriverValue(elements, driver.target, value);
|
|
20
|
-
}
|
|
21
|
-
return next;
|
|
22
|
-
}
|
|
23
|
-
function evaluateDriver(driver, elements, time) {
|
|
24
|
-
if (driver.expr !== undefined)
|
|
25
|
-
return evaluateExpression(driver.expr, elements, time);
|
|
26
|
-
if (Array.isArray(driver.keyframes))
|
|
27
|
-
return interpolateKeyframes(driver.keyframes, time, driver.ease);
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
function evaluateExpression(input, elements, time) {
|
|
31
|
-
if (typeof input === "number" || typeof input === "string" || isMotionPoint(input))
|
|
32
|
-
return (0, utils_1.clone)(input);
|
|
33
|
-
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
34
|
-
return 0;
|
|
35
|
-
switch (input.op) {
|
|
36
|
-
case "time":
|
|
37
|
-
return time;
|
|
38
|
-
case "prop":
|
|
39
|
-
return propertyValue(elements, input.target, input.property);
|
|
40
|
-
case "point": {
|
|
41
|
-
const [x, y] = input.args;
|
|
42
|
-
return [numberValue(evaluateExpression(x, elements, time)), numberValue(evaluateExpression(y, elements, time))];
|
|
43
|
-
}
|
|
44
|
-
case "add":
|
|
45
|
-
return input.args.reduce((total, item) => addValues(total, evaluateExpression(item, elements, time)), 0);
|
|
46
|
-
case "sub": {
|
|
47
|
-
const [first, ...rest] = input.args;
|
|
48
|
-
return rest.reduce((total, item) => subValues(total, evaluateExpression(item, elements, time)), evaluateExpression(first ?? 0, elements, time));
|
|
49
|
-
}
|
|
50
|
-
case "mul":
|
|
51
|
-
return input.args.reduce((total, item) => mulValues(total, evaluateExpression(item, elements, time)), 1);
|
|
52
|
-
case "div": {
|
|
53
|
-
const [first, ...rest] = input.args;
|
|
54
|
-
return rest.reduce((total, item) => divValues(total, evaluateExpression(item, elements, time)), evaluateExpression(first ?? 0, elements, time));
|
|
55
|
-
}
|
|
56
|
-
case "mod": {
|
|
57
|
-
const [left, right] = input.args;
|
|
58
|
-
const divisor = numberValue(evaluateExpression(right ?? 1, elements, time));
|
|
59
|
-
return divisor === 0 ? 0 : numberValue(evaluateExpression(left ?? 0, elements, time)) % divisor;
|
|
60
|
-
}
|
|
61
|
-
case "min":
|
|
62
|
-
return Math.min(...input.args.map((item) => numberValue(evaluateExpression(item, elements, time))));
|
|
63
|
-
case "max":
|
|
64
|
-
return Math.max(...input.args.map((item) => numberValue(evaluateExpression(item, elements, time))));
|
|
65
|
-
case "sin":
|
|
66
|
-
return Math.sin(numberValue(evaluateExpression(input.arg, elements, time)));
|
|
67
|
-
case "cos":
|
|
68
|
-
return Math.cos(numberValue(evaluateExpression(input.arg, elements, time)));
|
|
69
|
-
case "abs":
|
|
70
|
-
return absValue(evaluateExpression(input.arg, elements, time));
|
|
71
|
-
case "clamp":
|
|
72
|
-
return Math.max(numberValue(evaluateExpression(input.min, elements, time)), Math.min(numberValue(evaluateExpression(input.max, elements, time)), numberValue(evaluateExpression(input.value, elements, time))));
|
|
73
|
-
case "lerp":
|
|
74
|
-
return interpolateValue(evaluateExpression(input.from, elements, time), evaluateExpression(input.to, elements, time), numberValue(evaluateExpression(input.t, elements, time)));
|
|
75
|
-
case "bbox": {
|
|
76
|
-
const target = findElement(elements, input.target);
|
|
77
|
-
const box = target ? (0, utils_1.elementBox)(target) : undefined;
|
|
78
|
-
return box ? box[input.property] : 0;
|
|
79
|
-
}
|
|
80
|
-
case "anchor": {
|
|
81
|
-
const target = findElement(elements, input.target);
|
|
82
|
-
const box = target ? (0, utils_1.elementBox)(target) : undefined;
|
|
83
|
-
const point = box ? (0, utils_1.anchorPoint)(box, input.anchor) : [0, 0];
|
|
84
|
-
if (input.offset === undefined)
|
|
85
|
-
return point;
|
|
86
|
-
return point2Value(addValues(point, evaluateExpression(input.offset, elements, time)));
|
|
87
|
-
}
|
|
88
|
-
case "pointAt":
|
|
89
|
-
return pointOnTarget(elements, input.target, numberValue(evaluateExpression(input.progress, elements, time))) ?? [0, 0];
|
|
90
|
-
case "pathLength": {
|
|
91
|
-
const path = firstKernelPathForTarget(elements, input.target);
|
|
92
|
-
return path ? (0, path_sampling_1.pathLength)(path.d) : 0;
|
|
93
|
-
}
|
|
94
|
-
default:
|
|
95
|
-
return 0;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function interpolateKeyframes(keyframes, time, ease) {
|
|
99
|
-
const frames = keyframes
|
|
100
|
-
.filter((frame) => Array.isArray(frame) && (0, utils_1.isFiniteNumber)(frame[0]))
|
|
101
|
-
.slice()
|
|
102
|
-
.sort((left, right) => left[0] - right[0]);
|
|
103
|
-
if (!frames.length)
|
|
104
|
-
return undefined;
|
|
105
|
-
if (time <= frames[0][0])
|
|
106
|
-
return (0, utils_1.clone)(frames[0][1]);
|
|
107
|
-
for (let index = 1; index < frames.length; index += 1) {
|
|
108
|
-
const prev = frames[index - 1];
|
|
109
|
-
const next = frames[index];
|
|
110
|
-
if (time <= next[0]) {
|
|
111
|
-
const span = Math.max(0.000001, next[0] - prev[0]);
|
|
112
|
-
return interpolateValue(prev[1], next[1], (0, utils_2.easing)(ease, (time - prev[0]) / span));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return (0, utils_1.clone)(frames[frames.length - 1][1]);
|
|
116
|
-
}
|
|
117
|
-
function interpolateValue(from, to, t) {
|
|
118
|
-
const eased = Math.max(0, Math.min(1, t));
|
|
119
|
-
if (typeof from === "number" && typeof to === "number")
|
|
120
|
-
return from + (to - from) * eased;
|
|
121
|
-
if (isMotionPoint(from) && isMotionPoint(to))
|
|
122
|
-
return from.map((value, index) => value + (Number(to[index]) - value) * eased);
|
|
123
|
-
if (typeof from === "string" && typeof to === "string") {
|
|
124
|
-
const fromColor = parseHexColor(from);
|
|
125
|
-
const toColor = parseHexColor(to);
|
|
126
|
-
if (fromColor && toColor) {
|
|
127
|
-
return `#${hex(Math.round(fromColor[0] + (toColor[0] - fromColor[0]) * eased))}${hex(Math.round(fromColor[1] + (toColor[1] - fromColor[1]) * eased))}${hex(Math.round(fromColor[2] + (toColor[2] - fromColor[2]) * eased))}`;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return eased < 1 ? (0, utils_1.clone)(from) : (0, utils_1.clone)(to);
|
|
131
|
-
}
|
|
132
|
-
function applyDriverValue(elements, targetPath, value) {
|
|
133
|
-
const separator = targetPath.indexOf(".");
|
|
134
|
-
if (separator <= 0)
|
|
135
|
-
return;
|
|
136
|
-
const id = targetPath.slice(0, separator);
|
|
137
|
-
const property = targetPath.slice(separator + 1);
|
|
138
|
-
const target = findElement(elements, id);
|
|
139
|
-
if (!target)
|
|
140
|
-
return;
|
|
141
|
-
const record = target;
|
|
142
|
-
if (property === "position" && (0, utils_1.isPoint2)(value)) {
|
|
143
|
-
if ("cx" in record || target.type === "circle" || target.type === "ellipse" || target.type === "arc") {
|
|
144
|
-
record.cx = value[0];
|
|
145
|
-
record.cy = value[1];
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
record.x = value[0];
|
|
149
|
-
record.y = value[1];
|
|
150
|
-
}
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
record[property] = (0, utils_1.clone)(value);
|
|
154
|
-
}
|
|
155
|
-
function propertyValue(elements, id, property) {
|
|
156
|
-
const target = findElement(elements, id);
|
|
157
|
-
if (!target)
|
|
158
|
-
return 0;
|
|
159
|
-
const record = target;
|
|
160
|
-
if (property === "position") {
|
|
161
|
-
if ((0, utils_1.isFiniteNumber)(record.cx) && (0, utils_1.isFiniteNumber)(record.cy))
|
|
162
|
-
return [record.cx, record.cy];
|
|
163
|
-
if ((0, utils_1.isFiniteNumber)(record.x) && (0, utils_1.isFiniteNumber)(record.y))
|
|
164
|
-
return [record.x, record.y];
|
|
165
|
-
}
|
|
166
|
-
const value = record[property];
|
|
167
|
-
return typeof value === "number" || typeof value === "string" || isMotionPoint(value) ? (0, utils_1.clone)(value) : 0;
|
|
168
|
-
}
|
|
169
|
-
function pointOnTarget(elements, id, progress) {
|
|
170
|
-
const path = firstKernelPathForTarget(elements, id);
|
|
171
|
-
return path ? (0, path_sampling_1.pointOnPath)(path.d, progress) : undefined;
|
|
172
|
-
}
|
|
173
|
-
function firstKernelPathForTarget(elements, id) {
|
|
174
|
-
const target = findElement(elements, id);
|
|
175
|
-
if (!target)
|
|
176
|
-
return undefined;
|
|
177
|
-
const definition = (0, shapes_1.getInternalShapeDefinition)(target.type);
|
|
178
|
-
if (!definition?.pathQueryable)
|
|
179
|
-
return undefined;
|
|
180
|
-
const lowered = lowerFollowTarget(target);
|
|
181
|
-
return firstKernelPath(lowered);
|
|
182
|
-
}
|
|
183
|
-
function lowerFollowTarget(target) {
|
|
184
|
-
const lowerElements = (items) => items.flatMap((item) => (0, shapes_1.lowerAuthoringElement)(item, { lowerElements }));
|
|
185
|
-
return lowerElements([target]);
|
|
186
|
-
}
|
|
187
|
-
function firstKernelPath(elements) {
|
|
188
|
-
for (const element of elements) {
|
|
189
|
-
if (element.type === "path")
|
|
190
|
-
return element;
|
|
191
|
-
if ((element.type === "group" || element.type === "group3d") && Array.isArray(element.children)) {
|
|
192
|
-
const nested = firstKernelPath(element.children);
|
|
193
|
-
if (nested)
|
|
194
|
-
return nested;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return undefined;
|
|
198
|
-
}
|
|
199
|
-
function findElement(elements, id) {
|
|
200
|
-
return (0, utils_1.flattenElements)(elements).find((element) => element.id === id);
|
|
201
|
-
}
|
|
202
|
-
function numberValue(value) {
|
|
203
|
-
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
204
|
-
}
|
|
205
|
-
function addValues(left, right) {
|
|
206
|
-
if (isMotionPoint(left) || isMotionPoint(right))
|
|
207
|
-
return combinePointValues(left, right, (a, b) => a + b);
|
|
208
|
-
return numberValue(left) + numberValue(right);
|
|
209
|
-
}
|
|
210
|
-
function subValues(left, right) {
|
|
211
|
-
if (isMotionPoint(left) || isMotionPoint(right))
|
|
212
|
-
return combinePointValues(left, right, (a, b) => a - b);
|
|
213
|
-
return numberValue(left) - numberValue(right);
|
|
214
|
-
}
|
|
215
|
-
function mulValues(left, right) {
|
|
216
|
-
if (isMotionPoint(left) || isMotionPoint(right))
|
|
217
|
-
return combinePointValues(left, right, (a, b) => a * b);
|
|
218
|
-
return numberValue(left) * numberValue(right);
|
|
219
|
-
}
|
|
220
|
-
function divValues(left, right) {
|
|
221
|
-
if (isMotionPoint(left) || isMotionPoint(right))
|
|
222
|
-
return combinePointValues(left, right, (a, b) => a / safeDenominator(b));
|
|
223
|
-
return numberValue(left) / safeDenominator(numberValue(right));
|
|
224
|
-
}
|
|
225
|
-
function absValue(value) {
|
|
226
|
-
if (isMotionPoint(value))
|
|
227
|
-
return value.map((item) => Math.abs(item));
|
|
228
|
-
return Math.abs(numberValue(value));
|
|
229
|
-
}
|
|
230
|
-
function combinePointValues(left, right, fn) {
|
|
231
|
-
const length = (isMotionPoint(left) && left.length === 3) || (isMotionPoint(right) && right.length === 3) ? 3 : 2;
|
|
232
|
-
const values = Array.from({ length }, (_, index) => fn(componentValue(left, index), componentValue(right, index)));
|
|
233
|
-
return values;
|
|
234
|
-
}
|
|
235
|
-
function componentValue(value, index) {
|
|
236
|
-
if (isMotionPoint(value))
|
|
237
|
-
return (0, utils_1.isFiniteNumber)(value[index]) ? value[index] : 0;
|
|
238
|
-
return numberValue(value);
|
|
239
|
-
}
|
|
240
|
-
function point2Value(value) {
|
|
241
|
-
if (isMotionPoint(value))
|
|
242
|
-
return [value[0], value[1]];
|
|
243
|
-
const scalar = numberValue(value);
|
|
244
|
-
return [scalar, scalar];
|
|
245
|
-
}
|
|
246
|
-
function safeDenominator(value) {
|
|
247
|
-
if (Math.abs(value) >= 0.000001)
|
|
248
|
-
return value;
|
|
249
|
-
return value < 0 ? -0.000001 : 0.000001;
|
|
250
|
-
}
|
|
251
|
-
function isMotionPoint(value) {
|
|
252
|
-
return Array.isArray(value) && (value.length === 2 || value.length === 3) && value.every((item) => typeof item === "number" && Number.isFinite(item));
|
|
253
|
-
}
|
|
254
|
-
function parseHexColor(value) {
|
|
255
|
-
const match = /^#([0-9a-f]{6})$/i.exec(value.trim());
|
|
256
|
-
if (!match)
|
|
257
|
-
return undefined;
|
|
258
|
-
return [parseInt(match[1].slice(0, 2), 16), parseInt(match[1].slice(2, 4), 16), parseInt(match[1].slice(4, 6), 16)];
|
|
259
|
-
}
|
|
260
|
-
function hex(value) {
|
|
261
|
-
return value.toString(16).padStart(2, "0");
|
|
262
|
-
}
|
package/dist/src/patch.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { VisualDocument, VisualPatchOperation } from "./types";
|
|
2
|
-
export interface PatchResult {
|
|
3
|
-
document: VisualDocument;
|
|
4
|
-
}
|
|
5
|
-
export declare function applyVisualPatch(document: VisualDocument, operations: VisualPatchOperation | VisualPatchOperation[]): PatchResult;
|
package/dist/src/patch.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyVisualPatch = applyVisualPatch;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
|
-
const validate_1 = require("./validate");
|
|
6
|
-
function applyVisualPatch(document, operations) {
|
|
7
|
-
const ops = Array.isArray(operations) ? operations : [operations];
|
|
8
|
-
const next = (0, utils_1.clone)(document);
|
|
9
|
-
next.elements = next.elements ?? [];
|
|
10
|
-
for (const operation of ops) {
|
|
11
|
-
applyOperation(next, operation);
|
|
12
|
-
}
|
|
13
|
-
const result = (0, validate_1.validateVisualDocument)(next);
|
|
14
|
-
if (!result.ok) {
|
|
15
|
-
const first = result.issues[0];
|
|
16
|
-
throw new Error(first ? `${first.path}: ${first.message}` : "Patch produced an invalid document.");
|
|
17
|
-
}
|
|
18
|
-
return { document: next };
|
|
19
|
-
}
|
|
20
|
-
function applyOperation(document, operation) {
|
|
21
|
-
const elements = document.elements ?? [];
|
|
22
|
-
if (operation.op === "add") {
|
|
23
|
-
if (operation.element.id && findElement(elements, operation.element.id))
|
|
24
|
-
throw new Error(`Element '${operation.element.id}' already exists.`);
|
|
25
|
-
const index = clampIndex(operation.index ?? elements.length, elements.length);
|
|
26
|
-
elements.splice(index, 0, (0, utils_1.clone)(operation.element));
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const target = "id" in operation ? findElement(elements, operation.id) : undefined;
|
|
30
|
-
if (!target)
|
|
31
|
-
throw new Error(`Element '${"id" in operation ? operation.id : ""}' was not found.`);
|
|
32
|
-
if (operation.op === "update") {
|
|
33
|
-
Object.assign(target.element, (0, utils_1.clone)(operation.set));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if (operation.op === "remove") {
|
|
37
|
-
target.parent.splice(target.index, 1);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (operation.op === "replace") {
|
|
41
|
-
target.parent[target.index] = (0, utils_1.clone)(operation.element);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (operation.op === "move") {
|
|
45
|
-
const record = target.element;
|
|
46
|
-
for (const key of ["x", "y", "cx", "cy"]) {
|
|
47
|
-
if (typeof operation[key] === "number")
|
|
48
|
-
record[key] = operation[key];
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (operation.op === "reorder") {
|
|
53
|
-
const [item] = target.parent.splice(target.index, 1);
|
|
54
|
-
target.parent.splice(clampIndex(operation.index, target.parent.length), 0, item);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function findElement(elements, id) {
|
|
58
|
-
for (let index = 0; index < elements.length; index += 1) {
|
|
59
|
-
const element = elements[index];
|
|
60
|
-
if (element.id === id)
|
|
61
|
-
return { element, parent: elements, index };
|
|
62
|
-
if (element.type === "group" && Array.isArray(element.children)) {
|
|
63
|
-
const found = findElement(element.children, id);
|
|
64
|
-
if (found)
|
|
65
|
-
return found;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
function clampIndex(index, length) {
|
|
71
|
-
return Math.max(0, Math.min(length, Math.floor(index)));
|
|
72
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { VisualDocument } from "../types";
|
|
2
|
-
import { documentForDeckStep } from "../deck";
|
|
3
|
-
export { documentForDeckStep };
|
|
4
|
-
export type { VisualDocument } from "../types";
|
|
5
|
-
export type BrowserExportFormat = "svg" | "png" | "jpg" | "html" | "json" | "mp4";
|
|
6
|
-
export type BrowserExportExtension = BrowserExportFormat | "webm";
|
|
7
|
-
export interface BrowserExportOptions {
|
|
8
|
-
title?: string;
|
|
9
|
-
filename?: string;
|
|
10
|
-
time?: number;
|
|
11
|
-
document?: VisualDocument;
|
|
12
|
-
sourceDocument?: VisualDocument;
|
|
13
|
-
}
|
|
14
|
-
export interface BrowserExportResult {
|
|
15
|
-
blob: Blob;
|
|
16
|
-
filename: string;
|
|
17
|
-
mimeType: string;
|
|
18
|
-
extension: BrowserExportExtension;
|
|
19
|
-
fallback?: "webm";
|
|
20
|
-
}
|
|
21
|
-
export interface VisualPlayerOptions {
|
|
22
|
-
document: VisualDocument;
|
|
23
|
-
autoplay?: boolean;
|
|
24
|
-
loop?: boolean;
|
|
25
|
-
onFrame?: (state: VisualPlayerState) => void;
|
|
26
|
-
onError?: (error: Error) => void;
|
|
27
|
-
}
|
|
28
|
-
export interface VisualPlayerState {
|
|
29
|
-
time: number;
|
|
30
|
-
duration: number;
|
|
31
|
-
playing: boolean;
|
|
32
|
-
}
|
|
33
|
-
export declare class VisualPlayer {
|
|
34
|
-
readonly ready: Promise<VisualPlayer>;
|
|
35
|
-
private root;
|
|
36
|
-
private document;
|
|
37
|
-
private loop;
|
|
38
|
-
private onFrame?;
|
|
39
|
-
private onError?;
|
|
40
|
-
private raf;
|
|
41
|
-
private startedAt;
|
|
42
|
-
private startedTime;
|
|
43
|
-
private currentTime;
|
|
44
|
-
private playing;
|
|
45
|
-
constructor(root: HTMLElement, options: VisualPlayerOptions);
|
|
46
|
-
play(): void;
|
|
47
|
-
pause(): void;
|
|
48
|
-
seek(time: number): void;
|
|
49
|
-
render(time?: number): void;
|
|
50
|
-
setDocument(document: VisualDocument): void;
|
|
51
|
-
getDocument(): VisualDocument;
|
|
52
|
-
getState(): VisualPlayerState;
|
|
53
|
-
toSvg(time?: number): string;
|
|
54
|
-
downloadSvg(filename?: string, time?: number): void;
|
|
55
|
-
exportBrowser(format: BrowserExportFormat, options?: BrowserExportOptions): Promise<BrowserExportResult>;
|
|
56
|
-
download(format: BrowserExportFormat, options?: BrowserExportOptions): Promise<BrowserExportResult>;
|
|
57
|
-
destroy(): void;
|
|
58
|
-
private tick;
|
|
59
|
-
private duration;
|
|
60
|
-
private emit;
|
|
61
|
-
private handleError;
|
|
62
|
-
}
|
|
63
|
-
export declare function createVisualPlayer(root: HTMLElement, options: VisualPlayerOptions): VisualPlayer;
|
|
64
|
-
export declare class SketchmarkPlayer extends VisualPlayer {
|
|
65
|
-
}
|
|
66
|
-
export declare function createSketchmarkPlayer(root: HTMLElement, options: VisualPlayerOptions): SketchmarkPlayer;
|
|
67
|
-
export declare function exportVisualFromBrowser(player: VisualPlayer, format: BrowserExportFormat, options?: BrowserExportOptions): Promise<BrowserExportResult>;
|
|
68
|
-
export declare function downloadBrowserExport(result: BrowserExportResult): void;
|