sketchmark 2.0.0 → 2.1.1

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 (56) hide show
  1. package/README.md +274 -188
  2. package/bin/editor-ui.cjs +2285 -0
  3. package/bin/preview-ui.cjs +74 -0
  4. package/bin/sketchmark.cjs +648 -2008
  5. package/dist/src/animatable.d.ts +21 -0
  6. package/dist/src/animatable.js +439 -0
  7. package/dist/src/builders/index.d.ts +1 -11
  8. package/dist/src/builders/index.js +1 -19
  9. package/dist/src/diagnostics.js +1 -64
  10. package/dist/src/edit.d.ts +27 -0
  11. package/dist/src/edit.js +162 -0
  12. package/dist/src/index.d.ts +4 -13
  13. package/dist/src/index.js +4 -13
  14. package/dist/src/keyframes.d.ts +48 -0
  15. package/dist/src/keyframes.js +182 -0
  16. package/dist/src/motion.d.ts +4 -0
  17. package/dist/src/motion.js +262 -0
  18. package/dist/src/normalize.js +120 -151
  19. package/dist/src/presets/characters.d.ts +15 -0
  20. package/dist/src/presets/characters.js +113 -0
  21. package/dist/src/presets/compose.d.ts +5 -0
  22. package/dist/src/presets/compose.js +80 -0
  23. package/dist/src/presets/effects.d.ts +40 -0
  24. package/dist/src/presets/effects.js +79 -0
  25. package/dist/src/presets/helpers.d.ts +33 -0
  26. package/dist/src/presets/helpers.js +165 -0
  27. package/dist/src/presets/index.d.ts +9 -0
  28. package/dist/src/presets/index.js +48 -0
  29. package/dist/src/presets/motions.d.ts +33 -0
  30. package/dist/src/presets/motions.js +75 -0
  31. package/dist/src/presets/scenes.d.ts +35 -0
  32. package/dist/src/presets/scenes.js +134 -0
  33. package/dist/src/presets/shapes.d.ts +71 -0
  34. package/dist/src/presets/shapes.js +96 -0
  35. package/dist/src/presets/transitions.d.ts +29 -0
  36. package/dist/src/presets/transitions.js +113 -0
  37. package/dist/src/presets/types.d.ts +34 -0
  38. package/dist/src/presets/types.js +2 -0
  39. package/dist/src/render/html.js +1 -4
  40. package/dist/src/render/svg.d.ts +2 -2
  41. package/dist/src/render/svg.js +86 -82
  42. package/dist/src/render/three-html.js +67 -113
  43. package/dist/src/scenes.js +1 -0
  44. package/dist/src/schema.js +218 -280
  45. package/dist/src/shapes/builtins.js +11 -47
  46. package/dist/src/shapes/common.js +12 -11
  47. package/dist/src/shapes/registry.d.ts +0 -1
  48. package/dist/src/shapes/registry.js +0 -4
  49. package/dist/src/shapes/types.d.ts +1 -3
  50. package/dist/src/types.d.ts +57 -288
  51. package/dist/src/utils.d.ts +2 -11
  52. package/dist/src/utils.js +13 -70
  53. package/dist/src/validate.js +321 -275
  54. package/dist/tests/run.js +576 -510
  55. package/package.json +46 -52
  56. package/schema/visual.schema.json +1086 -930
@@ -4,8 +4,6 @@ exports.builtInShapeLowerers = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const common_1 = require("./common");
6
6
  const geometry_1 = require("./geometry");
7
- const STYLE_ANIMATABLE = ["opacity", "fill", "stroke", "strokeWidth", "dashOffset", "drawStart", "drawEnd", "rotation", "scale", "scaleX", "scaleY"];
8
- const THREE_ANIMATABLE = ["opacity", "fill", "stroke", "strokeWidth", "positionX", "positionY", "positionZ", "rotationX", "rotationY", "rotationZ", "scale", "scaleX", "scaleY", "scaleZ"];
9
7
  const numberProperty = { type: "number" };
10
8
  const stringProperty = { type: "string" };
11
9
  const point2Property = { $ref: "#/$defs/point2" };
@@ -14,7 +12,6 @@ exports.builtInShapeLowerers = [
14
12
  {
15
13
  type: "rect",
16
14
  kind: "2d",
17
- animatable: [...STYLE_ANIMATABLE, "x", "y", "width", "height"],
18
15
  schema: { properties: { x: numberProperty, y: numberProperty, width: numberProperty, height: numberProperty } },
19
16
  validateGeometry(element, context) {
20
17
  const item = element;
@@ -31,37 +28,21 @@ exports.builtInShapeLowerers = [
31
28
  {
32
29
  type: "circle",
33
30
  kind: "2d",
34
- animatable: [...STYLE_ANIMATABLE, "cx", "cy", "radius"],
35
31
  schema: { properties: { cx: numberProperty, cy: numberProperty, radius: numberProperty } },
36
32
  validateGeometry(element, context) {
37
33
  const item = element;
38
- if (!item.follow) {
39
- context.requireNumber(item.cx, `${context.path}/cx`);
40
- context.requireNumber(item.cy, `${context.path}/cy`);
41
- }
34
+ context.requireNumber(item.cx, `${context.path}/cx`);
35
+ context.requireNumber(item.cy, `${context.path}/cy`);
42
36
  context.requireNumber(item.radius, `${context.path}/radius`);
43
37
  },
44
- validateReferences(element, context) {
45
- const item = element;
46
- if (!item.follow)
47
- return;
48
- const followed = context.ids.get(item.follow);
49
- if (!followed) {
50
- context.addIssue(`${context.path}/follow`, "unknown_follow_target", `Unknown follow target '${item.follow}'.`);
51
- }
52
- else if (!context.isFollowable(followed.type)) {
53
- context.addIssue(`${context.path}/follow`, "invalid_follow_target", `Element '${item.follow}' is not a line, arrow, arc, curve, path, polyline, or polygon.`);
54
- }
55
- },
56
38
  lower(element) {
57
39
  const item = element;
58
- return (0, common_1.toPath)(item, (0, geometry_1.circlePath)(Number(item.cx ?? 0), Number(item.cy ?? 0), item.radius));
40
+ return (0, common_1.toPath)(item, (0, geometry_1.circlePath)(item.cx ?? 0, item.cy ?? 0, item.radius));
59
41
  }
60
42
  },
61
43
  {
62
44
  type: "ellipse",
63
45
  kind: "2d",
64
- animatable: [...STYLE_ANIMATABLE, "cx", "cy", "rx", "ry"],
65
46
  schema: { properties: { cx: numberProperty, cy: numberProperty, rx: numberProperty, ry: numberProperty } },
66
47
  validateGeometry(element, context) {
67
48
  const item = element;
@@ -78,8 +59,7 @@ exports.builtInShapeLowerers = [
78
59
  {
79
60
  type: "line",
80
61
  kind: "2d",
81
- animatable: [...STYLE_ANIMATABLE],
82
- followable: true,
62
+ pathQueryable: true,
83
63
  schema: { properties: { from: endpointProperty, to: endpointProperty } },
84
64
  validateGeometry(element, context) {
85
65
  const item = element;
@@ -101,8 +81,7 @@ exports.builtInShapeLowerers = [
101
81
  {
102
82
  type: "arrow",
103
83
  kind: "2d",
104
- animatable: [...STYLE_ANIMATABLE],
105
- followable: true,
84
+ pathQueryable: true,
106
85
  schema: { properties: { from: endpointProperty, to: endpointProperty } },
107
86
  validateGeometry(element, context) {
108
87
  const item = element;
@@ -128,8 +107,7 @@ exports.builtInShapeLowerers = [
128
107
  {
129
108
  type: "arc",
130
109
  kind: "2d",
131
- animatable: [...STYLE_ANIMATABLE, "startAngle", "endAngle"],
132
- followable: true,
110
+ pathQueryable: true,
133
111
  schema: { properties: { cx: numberProperty, cy: numberProperty, radius: numberProperty, startAngle: numberProperty, endAngle: numberProperty, counterclockwise: { type: "boolean" }, closed: { type: "boolean" } } },
134
112
  validateGeometry(element, context) {
135
113
  const item = element;
@@ -149,8 +127,7 @@ exports.builtInShapeLowerers = [
149
127
  {
150
128
  type: "curve",
151
129
  kind: "2d",
152
- animatable: [...STYLE_ANIMATABLE],
153
- followable: true,
130
+ pathQueryable: true,
154
131
  schema: { properties: { from: endpointProperty, to: endpointProperty, control1: point2Property, control2: point2Property } },
155
132
  validateGeometry(element, context) {
156
133
  const item = element;
@@ -175,8 +152,7 @@ exports.builtInShapeLowerers = [
175
152
  {
176
153
  type: "polyline",
177
154
  kind: "2d",
178
- animatable: [...STYLE_ANIMATABLE],
179
- followable: true,
155
+ pathQueryable: true,
180
156
  schema: { properties: { points: { type: "array", items: point2Property } } },
181
157
  validateGeometry(element, context) {
182
158
  const item = element;
@@ -190,8 +166,7 @@ exports.builtInShapeLowerers = [
190
166
  {
191
167
  type: "polygon",
192
168
  kind: "2d",
193
- animatable: [...STYLE_ANIMATABLE],
194
- followable: true,
169
+ pathQueryable: true,
195
170
  schema: { properties: { points: { type: "array", items: point2Property } } },
196
171
  validateGeometry(element, context) {
197
172
  const item = element;
@@ -205,8 +180,7 @@ exports.builtInShapeLowerers = [
205
180
  {
206
181
  type: "path",
207
182
  kind: "2d",
208
- animatable: [...STYLE_ANIMATABLE],
209
- followable: true,
183
+ pathQueryable: true,
210
184
  schema: { properties: { d: stringProperty } },
211
185
  validateGeometry(element, context) {
212
186
  const item = element;
@@ -215,13 +189,12 @@ exports.builtInShapeLowerers = [
215
189
  },
216
190
  lower(element) {
217
191
  const item = element;
218
- return { ...(0, common_1.common2d)(item), type: "path", d: item.d };
192
+ return (0, common_1.toPath)(item, item.d);
219
193
  }
220
194
  },
221
195
  {
222
196
  type: "text",
223
197
  kind: "2d",
224
- animatable: [...STYLE_ANIMATABLE, "x", "y"],
225
198
  schema: { properties: { x: numberProperty, y: numberProperty, text: stringProperty, lines: { type: "array", items: stringProperty } } },
226
199
  validateGeometry(element, context) {
227
200
  const item = element;
@@ -267,7 +240,6 @@ exports.builtInShapeLowerers = [
267
240
  {
268
241
  type: "image",
269
242
  kind: "2d",
270
- animatable: [...STYLE_ANIMATABLE, "x", "y", "width", "height"],
271
243
  schema: { properties: { src: stringProperty, x: numberProperty, y: numberProperty, width: numberProperty, height: numberProperty, fit: { $ref: "#/$defs/imageFit" }, source: { $ref: "#/$defs/imageSource" } } },
272
244
  validateGeometry(element, context) {
273
245
  const item = element;
@@ -297,7 +269,6 @@ exports.builtInShapeLowerers = [
297
269
  {
298
270
  type: "point",
299
271
  kind: "2d",
300
- animatable: [...STYLE_ANIMATABLE, "x", "y"],
301
272
  schema: { properties: { x: numberProperty, y: numberProperty } },
302
273
  validateGeometry(element, context) {
303
274
  const item = element;
@@ -312,7 +283,6 @@ exports.builtInShapeLowerers = [
312
283
  {
313
284
  type: "group",
314
285
  kind: "2d",
315
- animatable: [...STYLE_ANIMATABLE, "x", "y"],
316
286
  schema: { properties: { x: numberProperty, y: numberProperty, children: { type: "array", items: { $ref: "#/$defs/element" } } } },
317
287
  validateGeometry(element, context) {
318
288
  const item = element;
@@ -337,7 +307,6 @@ exports.builtInShapeLowerers = [
337
307
  {
338
308
  type: "cuboid",
339
309
  kind: "3d",
340
- animatable: [...THREE_ANIMATABLE],
341
310
  schema: { properties: { position: { $ref: "#/$defs/point3" }, size: { $ref: "#/$defs/point3" } } },
342
311
  validateGeometry(element, context) {
343
312
  const item = element;
@@ -353,7 +322,6 @@ exports.builtInShapeLowerers = [
353
322
  {
354
323
  type: "sphere",
355
324
  kind: "3d",
356
- animatable: [...THREE_ANIMATABLE],
357
325
  schema: { properties: { position: { $ref: "#/$defs/point3" }, radius: numberProperty } },
358
326
  validateGeometry(element, context) {
359
327
  const item = element;
@@ -369,7 +337,6 @@ exports.builtInShapeLowerers = [
369
337
  {
370
338
  type: "plane",
371
339
  kind: "3d",
372
- animatable: [...THREE_ANIMATABLE],
373
340
  schema: { properties: { position: { $ref: "#/$defs/point3" }, size: point2Property } },
374
341
  validateGeometry(element, context) {
375
342
  const item = element;
@@ -385,7 +352,6 @@ exports.builtInShapeLowerers = [
385
352
  {
386
353
  type: "line3d",
387
354
  kind: "3d",
388
- animatable: [...THREE_ANIMATABLE],
389
355
  schema: { properties: { from: { $ref: "#/$defs/point3" }, to: { $ref: "#/$defs/point3" } } },
390
356
  validateGeometry(element, context) {
391
357
  const item = element;
@@ -400,7 +366,6 @@ exports.builtInShapeLowerers = [
400
366
  {
401
367
  type: "text3d",
402
368
  kind: "3d",
403
- animatable: [...THREE_ANIMATABLE],
404
369
  schema: { properties: { text: stringProperty, position: { $ref: "#/$defs/point3" } } },
405
370
  validateGeometry(element, context) {
406
371
  const item = element;
@@ -416,7 +381,6 @@ exports.builtInShapeLowerers = [
416
381
  {
417
382
  type: "light",
418
383
  kind: "3d",
419
- animatable: [...THREE_ANIMATABLE, "intensity"],
420
384
  schema: { properties: { kind: { enum: ["ambient", "directional", "point"] }, position: { $ref: "#/$defs/point3" }, intensity: numberProperty } },
421
385
  validateGeometry() {
422
386
  // Light position is optional for ambient lights and currently permissive for all light kinds.
@@ -10,10 +10,8 @@ exports.cloneOptional = cloneOptional;
10
10
  exports.meshElement = meshElement;
11
11
  const utils_1 = require("../utils");
12
12
  const geometry_1 = require("./geometry");
13
- const KERNEL_PATH_ANIMATABLE = new Set(["opacity", "fill", "stroke", "strokeWidth", "dashOffset", "drawStart", "drawEnd", "rotation", "scale", "scaleX", "scaleY"]);
14
13
  function toPath(element, d, overrides = {}) {
15
14
  const base = common2d(element);
16
- keepAnimatable(base, KERNEL_PATH_ANIMATABLE);
17
15
  return { ...base, ...overrides, type: "path", d };
18
16
  }
19
17
  function common2d(element) {
@@ -28,19 +26,22 @@ function cleanCommon(element, omit) {
28
26
  delete record[key];
29
27
  record.clip = lowerClip(record.clip);
30
28
  record.mask = lowerMask(record.mask);
29
+ resolveOrigin(element, record);
31
30
  return record;
32
31
  }
33
- function keepAnimatable(record, allowed) {
34
- const animation = record.animate;
35
- if (!animation || typeof animation !== "object" || Array.isArray(animation))
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);
36
39
  return;
37
- const entries = Object.entries(animation).filter(([property]) => allowed.has(property));
38
- if (entries.length) {
39
- record.animate = Object.fromEntries(entries);
40
- }
41
- else {
42
- delete record.animate;
43
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 });
44
45
  }
45
46
  function lowerClip(clip) {
46
47
  if (!clip)
@@ -6,4 +6,3 @@ export declare function getInternalShapeDefinition(type: string): ShapeDefinitio
6
6
  export declare function lowerAuthoringElement(element: VisualElement, context: ShapeLoweringContext): KernelElement | KernelElement[];
7
7
  export declare function registeredAuthoringShapeTypes(): string[];
8
8
  export declare function registeredAuthoringShapeDefinitions(): ShapeDefinition[];
9
- export declare function isFollowableAuthoringShape(type: string): boolean;
@@ -6,7 +6,6 @@ exports.getInternalShapeDefinition = getInternalShapeDefinition;
6
6
  exports.lowerAuthoringElement = lowerAuthoringElement;
7
7
  exports.registeredAuthoringShapeTypes = registeredAuthoringShapeTypes;
8
8
  exports.registeredAuthoringShapeDefinitions = registeredAuthoringShapeDefinitions;
9
- exports.isFollowableAuthoringShape = isFollowableAuthoringShape;
10
9
  const builtins_1 = require("./builtins");
11
10
  const shapeLowerers = new Map();
12
11
  for (const lowerer of builtins_1.builtInShapeLowerers)
@@ -30,6 +29,3 @@ function registeredAuthoringShapeTypes() {
30
29
  function registeredAuthoringShapeDefinitions() {
31
30
  return [...shapeLowerers.values()];
32
31
  }
33
- function isFollowableAuthoringShape(type) {
34
- return Boolean(shapeLowerers.get(type)?.followable);
35
- }
@@ -16,7 +16,6 @@ export interface ShapeValidationContext {
16
16
  requirePoint3(value: unknown, path: string, code: string, message: string): void;
17
17
  validateEndpoint(value: unknown, path: string): void;
18
18
  validateImageOptions(element: ImageElement): void;
19
- isFollowable(type: string): boolean;
20
19
  }
21
20
  export interface ShapeSchemaFragment {
22
21
  properties?: Record<string, unknown>;
@@ -24,8 +23,7 @@ export interface ShapeSchemaFragment {
24
23
  export interface ShapeDefinition {
25
24
  type: string;
26
25
  kind: "2d" | "3d";
27
- animatable: string[];
28
- followable?: boolean;
26
+ pathQueryable?: boolean;
29
27
  schema?: ShapeSchemaFragment;
30
28
  lower(element: VisualElement, context: ShapeLoweringContext): KernelElement | KernelElement[];
31
29
  validateGeometry(element: VisualElement, context: ShapeValidationContext): void;