sketchmark 2.1.1 → 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 -1
- 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/dist/src/sequences.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compileVisualSequence = compileVisualSequence;
|
|
4
|
-
exports.defaultSequenceId = defaultSequenceId;
|
|
5
|
-
exports.documentForSequenceTime = documentForSequenceTime;
|
|
6
|
-
exports.resolvedFrameForSequenceTime = resolvedFrameForSequenceTime;
|
|
7
|
-
exports.sequenceTimeline = sequenceTimeline;
|
|
8
|
-
const scenes_1 = require("./scenes");
|
|
9
|
-
const normalize_1 = require("./normalize");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
function compileVisualSequence(document, sequenceId) {
|
|
12
|
-
const sequence = document.sequences?.[sequenceId];
|
|
13
|
-
if (!sequence)
|
|
14
|
-
throw new Error(`Unknown sequence '${sequenceId}'.`);
|
|
15
|
-
let cursor = 0;
|
|
16
|
-
const clips = sequence.clips.map((clip) => {
|
|
17
|
-
if (!document.scenes?.[clip.scene])
|
|
18
|
-
throw new Error(`Unknown scene '${clip.scene}' in sequence '${sequenceId}'.`);
|
|
19
|
-
const item = { scene: clip.scene, start: cursor, duration: clip.duration, transition: normalizeTransition(clip.transition) };
|
|
20
|
-
cursor += clip.duration;
|
|
21
|
-
return item;
|
|
22
|
-
});
|
|
23
|
-
return { id: sequenceId, duration: cursor, clips };
|
|
24
|
-
}
|
|
25
|
-
function defaultSequenceId(document) {
|
|
26
|
-
return Object.keys(document.sequences ?? {})[0];
|
|
27
|
-
}
|
|
28
|
-
function documentForSequenceTime(document, sequenceId, time) {
|
|
29
|
-
const sequence = compileVisualSequence(document, sequenceId);
|
|
30
|
-
const clamped = Math.max(0, Math.min(sequence.duration || 0, time));
|
|
31
|
-
const clipIndex = sequence.clips.findIndex((item) => clamped >= item.start && clamped < item.start + item.duration);
|
|
32
|
-
const index = clipIndex === -1 ? sequence.clips.length - 1 : clipIndex;
|
|
33
|
-
const clip = sequence.clips[index];
|
|
34
|
-
if (!clip)
|
|
35
|
-
throw new Error(`Sequence '${sequenceId}' has no clips.`);
|
|
36
|
-
const localTime = Math.max(0, clamped - clip.start);
|
|
37
|
-
const previous = index > 0 ? sequence.clips[index - 1] : undefined;
|
|
38
|
-
if (previous && clip.transition.type === "fade" && clip.transition.duration > 0 && localTime < clip.transition.duration) {
|
|
39
|
-
const progress = Math.max(0, Math.min(1, localTime / clip.transition.duration));
|
|
40
|
-
return {
|
|
41
|
-
document: fadeDocuments((0, scenes_1.documentForScene)(document, previous.scene), (0, scenes_1.documentForScene)(document, clip.scene), progress),
|
|
42
|
-
scene: clip.scene,
|
|
43
|
-
localTime,
|
|
44
|
-
globalTime: clamped,
|
|
45
|
-
transition: { type: "fade", fromScene: previous.scene, toScene: clip.scene, progress, duration: clip.transition.duration }
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
document: (0, scenes_1.documentForScene)(document, clip.scene),
|
|
50
|
-
scene: clip.scene,
|
|
51
|
-
localTime,
|
|
52
|
-
globalTime: clamped
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function resolvedFrameForSequenceTime(document, sequenceId, time) {
|
|
56
|
-
const frame = documentForSequenceTime(document, sequenceId, time);
|
|
57
|
-
return {
|
|
58
|
-
...frame,
|
|
59
|
-
document: (0, normalize_1.resolveVisualFrame)(frame.document, frame.localTime)
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function sequenceTimeline(document, sequenceId, fps) {
|
|
63
|
-
const sequence = compileVisualSequence(document, sequenceId);
|
|
64
|
-
const safeFps = Math.max(1, Math.round(fps));
|
|
65
|
-
const frameCount = Math.max(1, Math.ceil(sequence.duration * safeFps));
|
|
66
|
-
const frames = [];
|
|
67
|
-
for (let index = 0; index < frameCount; index += 1) {
|
|
68
|
-
const time = index / safeFps;
|
|
69
|
-
const frame = documentForSequenceTime(document, sequenceId, time);
|
|
70
|
-
frames.push({
|
|
71
|
-
index,
|
|
72
|
-
time,
|
|
73
|
-
scene: frame.scene,
|
|
74
|
-
localTime: frame.localTime,
|
|
75
|
-
...(frame.transition ? { transition: frame.transition } : {})
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return frames;
|
|
79
|
-
}
|
|
80
|
-
function normalizeTransition(transition) {
|
|
81
|
-
if (!transition || transition === "cut")
|
|
82
|
-
return { type: "cut", duration: 0 };
|
|
83
|
-
if (transition === "fade")
|
|
84
|
-
return { type: "fade", duration: 0.4 };
|
|
85
|
-
return { type: transition.type, duration: Math.max(0, Number(transition.duration ?? (transition.type === "fade" ? 0.4 : 0))) };
|
|
86
|
-
}
|
|
87
|
-
function fadeDocuments(from, to, progress) {
|
|
88
|
-
const resolvedFrom = (0, normalize_1.normalizeVisualDocument)(from);
|
|
89
|
-
const resolvedTo = (0, normalize_1.normalizeVisualDocument)(to);
|
|
90
|
-
return {
|
|
91
|
-
...to,
|
|
92
|
-
elements: [
|
|
93
|
-
...withOpacity(resolvedFrom.elements ?? [], 1 - progress, "fade_from"),
|
|
94
|
-
...withOpacity(resolvedTo.elements ?? [], progress, "fade_to")
|
|
95
|
-
]
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function withOpacity(elements, multiplier, prefix) {
|
|
99
|
-
return elements.map((element) => {
|
|
100
|
-
const next = (0, utils_1.clone)(element);
|
|
101
|
-
if (next.id)
|
|
102
|
-
next.id = `${prefix}_${next.id}`;
|
|
103
|
-
next.opacity = Number(next.opacity ?? 1) * multiplier;
|
|
104
|
-
if (next.type === "group" && Array.isArray(next.children)) {
|
|
105
|
-
next.children = withOpacity(next.children, multiplier, prefix);
|
|
106
|
-
}
|
|
107
|
-
return next;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.builtInShapeLowerers = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const common_1 = require("./common");
|
|
6
|
-
const geometry_1 = require("./geometry");
|
|
7
|
-
const numberProperty = { type: "number" };
|
|
8
|
-
const stringProperty = { type: "string" };
|
|
9
|
-
const point2Property = { $ref: "#/$defs/point2" };
|
|
10
|
-
const endpointProperty = { $ref: "#/$defs/endpoint" };
|
|
11
|
-
exports.builtInShapeLowerers = [
|
|
12
|
-
{
|
|
13
|
-
type: "rect",
|
|
14
|
-
kind: "2d",
|
|
15
|
-
schema: { properties: { x: numberProperty, y: numberProperty, width: numberProperty, height: numberProperty } },
|
|
16
|
-
validateGeometry(element, context) {
|
|
17
|
-
const item = element;
|
|
18
|
-
context.requireNumber(item.x, `${context.path}/x`);
|
|
19
|
-
context.requireNumber(item.y, `${context.path}/y`);
|
|
20
|
-
context.requireNumber(item.width, `${context.path}/width`);
|
|
21
|
-
context.requireNumber(item.height, `${context.path}/height`);
|
|
22
|
-
},
|
|
23
|
-
lower(element) {
|
|
24
|
-
const item = element;
|
|
25
|
-
return (0, common_1.toPath)(item, (0, geometry_1.roundedRectPath)(item.x, item.y, item.width, item.height, Number(item.radius ?? 0)));
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
type: "circle",
|
|
30
|
-
kind: "2d",
|
|
31
|
-
schema: { properties: { cx: numberProperty, cy: numberProperty, radius: numberProperty } },
|
|
32
|
-
validateGeometry(element, context) {
|
|
33
|
-
const item = element;
|
|
34
|
-
context.requireNumber(item.cx, `${context.path}/cx`);
|
|
35
|
-
context.requireNumber(item.cy, `${context.path}/cy`);
|
|
36
|
-
context.requireNumber(item.radius, `${context.path}/radius`);
|
|
37
|
-
},
|
|
38
|
-
lower(element) {
|
|
39
|
-
const item = element;
|
|
40
|
-
return (0, common_1.toPath)(item, (0, geometry_1.circlePath)(item.cx ?? 0, item.cy ?? 0, item.radius));
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
type: "ellipse",
|
|
45
|
-
kind: "2d",
|
|
46
|
-
schema: { properties: { cx: numberProperty, cy: numberProperty, rx: numberProperty, ry: numberProperty } },
|
|
47
|
-
validateGeometry(element, context) {
|
|
48
|
-
const item = element;
|
|
49
|
-
context.requireNumber(item.cx, `${context.path}/cx`);
|
|
50
|
-
context.requireNumber(item.cy, `${context.path}/cy`);
|
|
51
|
-
context.requireNumber(item.rx, `${context.path}/rx`);
|
|
52
|
-
context.requireNumber(item.ry, `${context.path}/ry`);
|
|
53
|
-
},
|
|
54
|
-
lower(element) {
|
|
55
|
-
const item = element;
|
|
56
|
-
return (0, common_1.toPath)(item, (0, geometry_1.ellipsePath)(item.cx, item.cy, item.rx, item.ry));
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
type: "line",
|
|
61
|
-
kind: "2d",
|
|
62
|
-
pathQueryable: true,
|
|
63
|
-
schema: { properties: { from: endpointProperty, to: endpointProperty } },
|
|
64
|
-
validateGeometry(element, context) {
|
|
65
|
-
const item = element;
|
|
66
|
-
if (item.from === undefined)
|
|
67
|
-
context.addIssue(`${context.path}/from`, "missing_from", "Line/arrow from is required.");
|
|
68
|
-
if (item.to === undefined)
|
|
69
|
-
context.addIssue(`${context.path}/to`, "missing_to", "Line/arrow to is required.");
|
|
70
|
-
},
|
|
71
|
-
validateReferences(element, context) {
|
|
72
|
-
const item = element;
|
|
73
|
-
context.validateEndpoint(item.from, `${context.path}/from`);
|
|
74
|
-
context.validateEndpoint(item.to, `${context.path}/to`);
|
|
75
|
-
},
|
|
76
|
-
lower(element) {
|
|
77
|
-
const item = element;
|
|
78
|
-
return (0, common_1.toPath)(item, (0, geometry_1.linePath)((0, geometry_1.point2)(item.from), (0, geometry_1.point2)(item.to)), { fill: "none", stroke: item.stroke ?? "#111827" });
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
type: "arrow",
|
|
83
|
-
kind: "2d",
|
|
84
|
-
pathQueryable: true,
|
|
85
|
-
schema: { properties: { from: endpointProperty, to: endpointProperty } },
|
|
86
|
-
validateGeometry(element, context) {
|
|
87
|
-
const item = element;
|
|
88
|
-
if (item.from === undefined)
|
|
89
|
-
context.addIssue(`${context.path}/from`, "missing_from", "Line/arrow from is required.");
|
|
90
|
-
if (item.to === undefined)
|
|
91
|
-
context.addIssue(`${context.path}/to`, "missing_to", "Line/arrow to is required.");
|
|
92
|
-
},
|
|
93
|
-
validateReferences(element, context) {
|
|
94
|
-
const item = element;
|
|
95
|
-
context.validateEndpoint(item.from, `${context.path}/from`);
|
|
96
|
-
context.validateEndpoint(item.to, `${context.path}/to`);
|
|
97
|
-
},
|
|
98
|
-
lower(element) {
|
|
99
|
-
const item = element;
|
|
100
|
-
return (0, common_1.toPath)(item, (0, geometry_1.linePath)((0, geometry_1.point2)(item.from), (0, geometry_1.point2)(item.to)), {
|
|
101
|
-
fill: "none",
|
|
102
|
-
stroke: item.stroke ?? "#111827",
|
|
103
|
-
metadata: { ...(item.metadata ?? {}), markerEnd: "arrow" }
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
type: "arc",
|
|
109
|
-
kind: "2d",
|
|
110
|
-
pathQueryable: true,
|
|
111
|
-
schema: { properties: { cx: numberProperty, cy: numberProperty, radius: numberProperty, startAngle: numberProperty, endAngle: numberProperty, counterclockwise: { type: "boolean" }, closed: { type: "boolean" } } },
|
|
112
|
-
validateGeometry(element, context) {
|
|
113
|
-
const item = element;
|
|
114
|
-
context.requireNumber(item.cx, `${context.path}/cx`);
|
|
115
|
-
context.requireNumber(item.cy, `${context.path}/cy`);
|
|
116
|
-
context.requireNumber(item.radius, `${context.path}/radius`);
|
|
117
|
-
context.requireNumber(item.startAngle, `${context.path}/startAngle`);
|
|
118
|
-
context.requireNumber(item.endAngle, `${context.path}/endAngle`);
|
|
119
|
-
},
|
|
120
|
-
lower(element) {
|
|
121
|
-
const item = element;
|
|
122
|
-
return (0, common_1.toPath)(item, (0, geometry_1.arcPath)(item.cx, item.cy, item.radius, item.startAngle, item.endAngle, Boolean(item.counterclockwise), Boolean(item.closed)), {
|
|
123
|
-
fill: item.closed ? item.fill : "none"
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
type: "curve",
|
|
129
|
-
kind: "2d",
|
|
130
|
-
pathQueryable: true,
|
|
131
|
-
schema: { properties: { from: endpointProperty, to: endpointProperty, control1: point2Property, control2: point2Property } },
|
|
132
|
-
validateGeometry(element, context) {
|
|
133
|
-
const item = element;
|
|
134
|
-
if (item.from === undefined)
|
|
135
|
-
context.addIssue(`${context.path}/from`, "missing_from", "Curve from is required.");
|
|
136
|
-
if (item.to === undefined)
|
|
137
|
-
context.addIssue(`${context.path}/to`, "missing_to", "Curve to is required.");
|
|
138
|
-
context.requirePoint2(item.control1, `${context.path}/control1`, "missing_control1", "Curve control1 must be [x,y].");
|
|
139
|
-
if (item.control2 !== undefined)
|
|
140
|
-
context.requirePoint2(item.control2, `${context.path}/control2`, "invalid_control2", "Curve control2 must be [x,y].");
|
|
141
|
-
},
|
|
142
|
-
validateReferences(element, context) {
|
|
143
|
-
const item = element;
|
|
144
|
-
context.validateEndpoint(item.from, `${context.path}/from`);
|
|
145
|
-
context.validateEndpoint(item.to, `${context.path}/to`);
|
|
146
|
-
},
|
|
147
|
-
lower(element) {
|
|
148
|
-
const item = element;
|
|
149
|
-
return (0, common_1.toPath)(item, (0, geometry_1.curvePath)((0, geometry_1.point2)(item.from), item.control1, item.control2, (0, geometry_1.point2)(item.to)), { fill: item.fill ?? "none" });
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
type: "polyline",
|
|
154
|
-
kind: "2d",
|
|
155
|
-
pathQueryable: true,
|
|
156
|
-
schema: { properties: { points: { type: "array", items: point2Property } } },
|
|
157
|
-
validateGeometry(element, context) {
|
|
158
|
-
const item = element;
|
|
159
|
-
context.requirePoint2Array(item.points, 2, `${context.path}/points`, "missing_points", "Polyline points must contain at least two [x,y] points.");
|
|
160
|
-
},
|
|
161
|
-
lower(element) {
|
|
162
|
-
const item = element;
|
|
163
|
-
return (0, common_1.toPath)(item, (0, geometry_1.pointsPath)(item.points, false), { fill: "none" });
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
type: "polygon",
|
|
168
|
-
kind: "2d",
|
|
169
|
-
pathQueryable: true,
|
|
170
|
-
schema: { properties: { points: { type: "array", items: point2Property } } },
|
|
171
|
-
validateGeometry(element, context) {
|
|
172
|
-
const item = element;
|
|
173
|
-
context.requirePoint2Array(item.points, 3, `${context.path}/points`, "missing_points", "Polygon points must contain at least three [x,y] points.");
|
|
174
|
-
},
|
|
175
|
-
lower(element) {
|
|
176
|
-
const item = element;
|
|
177
|
-
return (0, common_1.toPath)(item, (0, geometry_1.pointsPath)(item.points, true));
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
type: "path",
|
|
182
|
-
kind: "2d",
|
|
183
|
-
pathQueryable: true,
|
|
184
|
-
schema: { properties: { d: stringProperty } },
|
|
185
|
-
validateGeometry(element, context) {
|
|
186
|
-
const item = element;
|
|
187
|
-
if (typeof item.d !== "string" || !item.d.trim())
|
|
188
|
-
context.addIssue(`${context.path}/d`, "missing_path_d", "Path d is required.");
|
|
189
|
-
},
|
|
190
|
-
lower(element) {
|
|
191
|
-
const item = element;
|
|
192
|
-
return (0, common_1.toPath)(item, item.d);
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
type: "text",
|
|
197
|
-
kind: "2d",
|
|
198
|
-
schema: { properties: { x: numberProperty, y: numberProperty, text: stringProperty, lines: { type: "array", items: stringProperty } } },
|
|
199
|
-
validateGeometry(element, context) {
|
|
200
|
-
const item = element;
|
|
201
|
-
context.requireNumber(item.x, `${context.path}/x`);
|
|
202
|
-
context.requireNumber(item.y, `${context.path}/y`);
|
|
203
|
-
if (typeof item.text !== "string" && !Array.isArray(item.lines))
|
|
204
|
-
context.addIssue(`${context.path}/text`, "missing_text", "Text content is required. Use text or lines.");
|
|
205
|
-
if (item.lines !== undefined && (!Array.isArray(item.lines) || item.lines.some((line) => typeof line !== "string"))) {
|
|
206
|
-
context.addIssue(`${context.path}/lines`, "invalid_text_lines", "Text lines must be an array of strings.");
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
validateWarnings(element, context) {
|
|
210
|
-
const item = element;
|
|
211
|
-
const lines = Array.isArray(item.lines) && item.lines.length ? item.lines : String(item.text ?? "").split(/\r?\n/);
|
|
212
|
-
const text = lines.join("\n");
|
|
213
|
-
if (text.length > 42 && !item.maxWidth && !item.wrap && !item.fit) {
|
|
214
|
-
context.addWarning(`${context.path}/text`, "long_text_no_wrap", "Long text does not resize or wrap automatically.", "Set maxWidth, wrap, or fit explicitly.");
|
|
215
|
-
}
|
|
216
|
-
},
|
|
217
|
-
lower(element) {
|
|
218
|
-
const item = element;
|
|
219
|
-
return {
|
|
220
|
-
...(0, common_1.common2d)(item),
|
|
221
|
-
type: "text",
|
|
222
|
-
x: item.x,
|
|
223
|
-
y: item.y,
|
|
224
|
-
text: item.text,
|
|
225
|
-
lines: (0, common_1.cloneOptional)(item.lines),
|
|
226
|
-
align: item.align,
|
|
227
|
-
valign: item.valign,
|
|
228
|
-
fontSize: item.fontSize,
|
|
229
|
-
fontFamily: item.fontFamily,
|
|
230
|
-
weight: item.weight,
|
|
231
|
-
fontStyle: item.fontStyle,
|
|
232
|
-
lineHeight: item.lineHeight,
|
|
233
|
-
letterSpacing: item.letterSpacing,
|
|
234
|
-
maxWidth: item.maxWidth,
|
|
235
|
-
wrap: item.wrap,
|
|
236
|
-
fit: item.fit
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
type: "image",
|
|
242
|
-
kind: "2d",
|
|
243
|
-
schema: { properties: { src: stringProperty, x: numberProperty, y: numberProperty, width: numberProperty, height: numberProperty, fit: { $ref: "#/$defs/imageFit" }, source: { $ref: "#/$defs/imageSource" } } },
|
|
244
|
-
validateGeometry(element, context) {
|
|
245
|
-
const item = element;
|
|
246
|
-
context.requireNumber(item.x, `${context.path}/x`);
|
|
247
|
-
context.requireNumber(item.y, `${context.path}/y`);
|
|
248
|
-
context.requireNumber(item.width, `${context.path}/width`);
|
|
249
|
-
context.requireNumber(item.height, `${context.path}/height`);
|
|
250
|
-
if (typeof item.src !== "string")
|
|
251
|
-
context.addIssue(`${context.path}/src`, "missing_src", "Image src is required.");
|
|
252
|
-
context.validateImageOptions(item);
|
|
253
|
-
},
|
|
254
|
-
lower(element) {
|
|
255
|
-
const item = element;
|
|
256
|
-
return {
|
|
257
|
-
...(0, common_1.common2d)(item),
|
|
258
|
-
type: "image",
|
|
259
|
-
src: item.src,
|
|
260
|
-
x: item.x,
|
|
261
|
-
y: item.y,
|
|
262
|
-
width: item.width,
|
|
263
|
-
height: item.height,
|
|
264
|
-
fit: item.fit,
|
|
265
|
-
source: (0, common_1.cloneOptional)(item.source)
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
type: "point",
|
|
271
|
-
kind: "2d",
|
|
272
|
-
schema: { properties: { x: numberProperty, y: numberProperty } },
|
|
273
|
-
validateGeometry(element, context) {
|
|
274
|
-
const item = element;
|
|
275
|
-
context.requireNumber(item.x, `${context.path}/x`);
|
|
276
|
-
context.requireNumber(item.y, `${context.path}/y`);
|
|
277
|
-
},
|
|
278
|
-
lower(element) {
|
|
279
|
-
const item = element;
|
|
280
|
-
return { ...(0, common_1.common2d)(item), type: "point", x: item.x, y: item.y };
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
type: "group",
|
|
285
|
-
kind: "2d",
|
|
286
|
-
schema: { properties: { x: numberProperty, y: numberProperty, children: { type: "array", items: { $ref: "#/$defs/element" } } } },
|
|
287
|
-
validateGeometry(element, context) {
|
|
288
|
-
const item = element;
|
|
289
|
-
context.requireNumber(item.x, `${context.path}/x`);
|
|
290
|
-
context.requireNumber(item.y, `${context.path}/y`);
|
|
291
|
-
if (!Array.isArray(item.children))
|
|
292
|
-
context.addIssue(`${context.path}/children`, "missing_group_children", "Group children must be an array.");
|
|
293
|
-
},
|
|
294
|
-
lower(element, context) {
|
|
295
|
-
const item = element;
|
|
296
|
-
return {
|
|
297
|
-
...(0, common_1.common2d)(item),
|
|
298
|
-
type: "group",
|
|
299
|
-
x: item.x,
|
|
300
|
-
y: item.y,
|
|
301
|
-
width: item.width,
|
|
302
|
-
height: item.height,
|
|
303
|
-
children: context.lowerElements(item.children ?? [])
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
{
|
|
308
|
-
type: "cuboid",
|
|
309
|
-
kind: "3d",
|
|
310
|
-
schema: { properties: { position: { $ref: "#/$defs/point3" }, size: { $ref: "#/$defs/point3" } } },
|
|
311
|
-
validateGeometry(element, context) {
|
|
312
|
-
const item = element;
|
|
313
|
-
context.requirePoint3(item.position, `${context.path}/position`, "missing_position", "Cuboid position must be [x,y,z].");
|
|
314
|
-
context.requirePoint3(item.size, `${context.path}/size`, "missing_size", "Cuboid size must be [width,height,depth].");
|
|
315
|
-
},
|
|
316
|
-
lower(element) {
|
|
317
|
-
const item = element;
|
|
318
|
-
const geometry = (0, geometry_1.cuboidGeometry)(item.size);
|
|
319
|
-
return (0, common_1.meshElement)(item, geometry.vertices, geometry.faces, (0, utils_1.clone)(item.position));
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
type: "sphere",
|
|
324
|
-
kind: "3d",
|
|
325
|
-
schema: { properties: { position: { $ref: "#/$defs/point3" }, radius: numberProperty } },
|
|
326
|
-
validateGeometry(element, context) {
|
|
327
|
-
const item = element;
|
|
328
|
-
context.requirePoint3(item.position, `${context.path}/position`, "missing_position", "Sphere position must be [x,y,z].");
|
|
329
|
-
context.requireNumber(item.radius, `${context.path}/radius`);
|
|
330
|
-
},
|
|
331
|
-
lower(element) {
|
|
332
|
-
const item = element;
|
|
333
|
-
const geometry = (0, geometry_1.sphereGeometry)(item.radius);
|
|
334
|
-
return (0, common_1.meshElement)(item, geometry.vertices, geometry.faces, (0, utils_1.clone)(item.position));
|
|
335
|
-
}
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
type: "plane",
|
|
339
|
-
kind: "3d",
|
|
340
|
-
schema: { properties: { position: { $ref: "#/$defs/point3" }, size: point2Property } },
|
|
341
|
-
validateGeometry(element, context) {
|
|
342
|
-
const item = element;
|
|
343
|
-
context.requirePoint3(item.position, `${context.path}/position`, "missing_position", "Plane position must be [x,y,z].");
|
|
344
|
-
context.requirePoint2(item.size, `${context.path}/size`, "missing_size", "Plane size must be [width,height].");
|
|
345
|
-
},
|
|
346
|
-
lower(element) {
|
|
347
|
-
const item = element;
|
|
348
|
-
const geometry = (0, geometry_1.planeGeometry)(item.size);
|
|
349
|
-
return (0, common_1.meshElement)(item, geometry.vertices, geometry.faces, (0, utils_1.clone)(item.position));
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
type: "line3d",
|
|
354
|
-
kind: "3d",
|
|
355
|
-
schema: { properties: { from: { $ref: "#/$defs/point3" }, to: { $ref: "#/$defs/point3" } } },
|
|
356
|
-
validateGeometry(element, context) {
|
|
357
|
-
const item = element;
|
|
358
|
-
context.requirePoint3(item.from, `${context.path}/from`, "missing_from", "line3d from must be [x,y,z].");
|
|
359
|
-
context.requirePoint3(item.to, `${context.path}/to`, "missing_to", "line3d to must be [x,y,z].");
|
|
360
|
-
},
|
|
361
|
-
lower(element) {
|
|
362
|
-
const item = element;
|
|
363
|
-
return { ...(0, common_1.common3d)(item), type: "line3d", from: (0, utils_1.clone)(item.from), to: (0, utils_1.clone)(item.to) };
|
|
364
|
-
}
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
type: "text3d",
|
|
368
|
-
kind: "3d",
|
|
369
|
-
schema: { properties: { text: stringProperty, position: { $ref: "#/$defs/point3" } } },
|
|
370
|
-
validateGeometry(element, context) {
|
|
371
|
-
const item = element;
|
|
372
|
-
if (typeof item.text !== "string")
|
|
373
|
-
context.addIssue(`${context.path}/text`, "missing_text", "text3d text is required.");
|
|
374
|
-
context.requirePoint3(item.position, `${context.path}/position`, "missing_position", "text3d position must be [x,y,z].");
|
|
375
|
-
},
|
|
376
|
-
lower(element) {
|
|
377
|
-
const item = element;
|
|
378
|
-
return { ...(0, common_1.common3d)(item), type: "text3d", text: item.text, position: (0, utils_1.clone)(item.position), fontSize: item.fontSize };
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
{
|
|
382
|
-
type: "light",
|
|
383
|
-
kind: "3d",
|
|
384
|
-
schema: { properties: { kind: { enum: ["ambient", "directional", "point"] }, position: { $ref: "#/$defs/point3" }, intensity: numberProperty } },
|
|
385
|
-
validateGeometry() {
|
|
386
|
-
// Light position is optional for ambient lights and currently permissive for all light kinds.
|
|
387
|
-
},
|
|
388
|
-
lower(element) {
|
|
389
|
-
const item = element;
|
|
390
|
-
return { ...(0, common_1.common3d)(item), type: "light", kind: item.kind, position: (0, common_1.cloneOptional)(item.position), intensity: item.intensity };
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ClipShape, KernelMesh3dElement, KernelPathElement, MaskShape, Point3, VisualElement } from "../types";
|
|
2
|
-
export declare function toPath(element: VisualElement, d: string, overrides?: Record<string, unknown>): KernelPathElement;
|
|
3
|
-
export declare function common2d(element: VisualElement): Record<string, unknown>;
|
|
4
|
-
export declare function common3d(element: VisualElement): Record<string, unknown>;
|
|
5
|
-
export declare function cleanCommon(element: VisualElement, omit: string[]): Record<string, unknown>;
|
|
6
|
-
export declare function lowerClip(clip: ClipShape | undefined): ClipShape | undefined;
|
|
7
|
-
export declare function lowerMask(mask: MaskShape | undefined): MaskShape | undefined;
|
|
8
|
-
export declare function cloneOptional<T>(value: T | undefined): T | undefined;
|
|
9
|
-
export declare function meshElement(source: VisualElement, vertices: Point3[], faces: number[][], position: Point3): KernelMesh3dElement;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toPath = toPath;
|
|
4
|
-
exports.common2d = common2d;
|
|
5
|
-
exports.common3d = common3d;
|
|
6
|
-
exports.cleanCommon = cleanCommon;
|
|
7
|
-
exports.lowerClip = lowerClip;
|
|
8
|
-
exports.lowerMask = lowerMask;
|
|
9
|
-
exports.cloneOptional = cloneOptional;
|
|
10
|
-
exports.meshElement = meshElement;
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
|
-
const geometry_1 = require("./geometry");
|
|
13
|
-
function toPath(element, d, overrides = {}) {
|
|
14
|
-
const base = common2d(element);
|
|
15
|
-
return { ...base, ...overrides, type: "path", d };
|
|
16
|
-
}
|
|
17
|
-
function common2d(element) {
|
|
18
|
-
return cleanCommon(element, ["type", "children"]);
|
|
19
|
-
}
|
|
20
|
-
function common3d(element) {
|
|
21
|
-
return cleanCommon(element, ["type", "children", "position", "size", "radius"]);
|
|
22
|
-
}
|
|
23
|
-
function cleanCommon(element, omit) {
|
|
24
|
-
const record = (0, utils_1.clone)(element);
|
|
25
|
-
for (const key of omit)
|
|
26
|
-
delete record[key];
|
|
27
|
-
record.clip = lowerClip(record.clip);
|
|
28
|
-
record.mask = lowerMask(record.mask);
|
|
29
|
-
resolveOrigin(element, record);
|
|
30
|
-
return record;
|
|
31
|
-
}
|
|
32
|
-
function resolveOrigin(element, record) {
|
|
33
|
-
if ((0, utils_1.isPoint2)(record.origin))
|
|
34
|
-
return;
|
|
35
|
-
if ((0, utils_1.isAnchorSpec)(record.origin)) {
|
|
36
|
-
const box = (0, utils_1.elementBox)(element);
|
|
37
|
-
if (box)
|
|
38
|
-
record.origin = (0, utils_1.anchorPoint)(box, record.origin);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const box = (0, utils_1.elementBox)(element);
|
|
42
|
-
if (!box)
|
|
43
|
-
return;
|
|
44
|
-
record.origin = (0, utils_1.anchorPoint)(box, { kind: "bounds", u: 0.5, v: 0.5 });
|
|
45
|
-
}
|
|
46
|
-
function lowerClip(clip) {
|
|
47
|
-
if (!clip)
|
|
48
|
-
return undefined;
|
|
49
|
-
if (clip.type === "path")
|
|
50
|
-
return (0, utils_1.clone)(clip);
|
|
51
|
-
if (clip.type === "rect")
|
|
52
|
-
return { type: "path", d: (0, geometry_1.roundedRectPath)(clip.x, clip.y, clip.width, clip.height, Number(clip.radius ?? 0)) };
|
|
53
|
-
return { type: "path", d: (0, geometry_1.circlePath)(clip.cx, clip.cy, clip.radius) };
|
|
54
|
-
}
|
|
55
|
-
function lowerMask(mask) {
|
|
56
|
-
if (!mask)
|
|
57
|
-
return undefined;
|
|
58
|
-
if (mask.type === "path")
|
|
59
|
-
return (0, utils_1.clone)(mask);
|
|
60
|
-
if (mask.type === "rect")
|
|
61
|
-
return { type: "path", d: (0, geometry_1.roundedRectPath)(mask.x, mask.y, mask.width, mask.height, Number(mask.radius ?? 0)), opacity: mask.opacity };
|
|
62
|
-
return { type: "path", d: (0, geometry_1.circlePath)(mask.cx, mask.cy, mask.radius), opacity: mask.opacity };
|
|
63
|
-
}
|
|
64
|
-
function cloneOptional(value) {
|
|
65
|
-
return value === undefined ? undefined : (0, utils_1.clone)(value);
|
|
66
|
-
}
|
|
67
|
-
function meshElement(source, vertices, faces, position) {
|
|
68
|
-
return {
|
|
69
|
-
...common3d(source),
|
|
70
|
-
type: "mesh3d",
|
|
71
|
-
vertices,
|
|
72
|
-
faces,
|
|
73
|
-
indices: (0, geometry_1.triangulateFaces)(faces),
|
|
74
|
-
position
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Point2, Point3 } from "../types";
|
|
2
|
-
export declare function roundedRectPath(x: number, y: number, width: number, height: number, radius: number): string;
|
|
3
|
-
export declare function circlePath(cx: number, cy: number, radius: number): string;
|
|
4
|
-
export declare function ellipsePath(cx: number, cy: number, rx: number, ry: number): string;
|
|
5
|
-
export declare function linePath(from: Point2, to: Point2): string;
|
|
6
|
-
export declare function curvePath(from: Point2, control1: Point2, control2: Point2 | undefined, to: Point2): string;
|
|
7
|
-
export declare function pointsPath(points: Point2[], closed: boolean): string;
|
|
8
|
-
export declare function arcPath(cx: number, cy: number, radius: number, startAngle: number, endAngle: number, counterclockwise: boolean, closed: boolean): string;
|
|
9
|
-
export declare function point2(value: unknown): Point2;
|
|
10
|
-
export declare function cuboidGeometry(size: Point3): {
|
|
11
|
-
vertices: Point3[];
|
|
12
|
-
faces: number[][];
|
|
13
|
-
};
|
|
14
|
-
export declare function planeGeometry(size: Point2): {
|
|
15
|
-
vertices: Point3[];
|
|
16
|
-
faces: number[][];
|
|
17
|
-
};
|
|
18
|
-
export declare function sphereGeometry(radius: number, segments?: number, rings?: number): {
|
|
19
|
-
vertices: Point3[];
|
|
20
|
-
faces: number[][];
|
|
21
|
-
};
|
|
22
|
-
export declare function triangulateFaces(faces: number[][]): number[];
|