@pixodesk/svg-animator-core 1.0.22 → 1.0.25

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/README.md CHANGED
@@ -56,20 +56,48 @@ runtime crash on a non-browser platform.
56
56
  | **Text** | `materialiseGlyphText`, `layoutGlyphTextChars`, `extendedPathForBrowser` |
57
57
  | **Node helpers** | `getNormalizedProps`, `sanitiseAttributeValue`, `resolveStyle`, `generateNewIds` |
58
58
  | **Playback engine** | `createBasicFrameLoopAnimator` + the `PxPlatformAdapter` interface |
59
+ | **Wire enums** | `PxAnimatorMode`, `PxAnimatorEngine`, `PxLoopExtend`, `PxTrimSubPaths`, `PxMaskType`, `PxCloneType`, `PxUnits`, `PxGradientType`, `PxGradientUnits`, `PxGradientSpreadMethod`, `PxPathOverflow`, `PxLengthAdjust`, `PxTextPathMethod`, `PxTextPathSpacing` — every two-or-more-way wire selector is a named enum, not a bare string |
60
+
61
+ ### Validating a document
62
+
63
+ `isPxElementFileFormat(json)` is the cheap shallow gate (is this a Px document at all?);
64
+ `isPxElementFileFormatDeep(json)` runs the full schema. For per-field diagnostics, call a schema's
65
+ `isValid` with a context:
66
+
67
+ ```ts
68
+ import { PxAnimatedSvgDocumentSchema, type PxValidationContext } from '@pixodesk/svg-animator-core';
69
+
70
+ const ctx: PxValidationContext = { errors: [], warnings: [], strict: true };
71
+ const ok = PxAnimatedSvgDocumentSchema.isValid(doc, ctx, []);
72
+ if (!ok) console.error(ctx.errors); // ["children[0].effects.trimPath.range: …", …]
73
+ ```
74
+
75
+ **Two modes, two different questions:**
76
+
77
+ | mode | question it answers | undeclared keys |
78
+ |---|---|---|
79
+ | default (`strict` absent/false) | *is this document repairable?* — what `sanitize` would accept | ignored, so unknown future fields stay forward-compatible |
80
+ | `strict: true` | *is this document well-formed?* — the wire shape locked to its schema | reported as errors on closed objects |
81
+
82
+ Use default in production readers and `strict` in tests and tooling. Two notes on strict, both
83
+ deliberate: it reaches **inside unions** (a union member is checked in the caller's mode, though its
84
+ per-branch errors are not reported unless every branch fails), and it **ignores keys whose value is
85
+ `undefined`** — those cannot survive `JSON.stringify`, so strict judges the document rather than the
86
+ in-memory object that produced it.
59
87
 
60
88
  ## The materialisation pipeline
61
89
 
62
90
  `materialiseAllInTree(doc, engine)` is the single entry point that turns a
63
91
  lightweight editor document into a flat tree any renderer can walk:
64
92
 
65
- 1. **Effects** — `node.effects` (transformation, repeater, maskedBy, trimPath,
93
+ 1. **Effects** — `node.effects` (transformBy, repeater, maskedBy, trimPath,
66
94
  clone/retime, gradients, textPath) become real nodes, wrappers and defs.
67
95
  2. **Loops** — each property's `loop` is expanded into explicit keyframes.
68
96
  3. **Motion paths** — tangented `transform` keyframes plus `autoOrient` are
69
97
  sampled into plain `{translate, rotate}` keyframes.
70
98
  4. **Animated `<use>`** — replaced by `<g>` + a deep clone with fresh ids.
71
99
 
72
- Steps 3 and 4 run when `engine` is `webapi`. Pass `webapi` for **any renderer
100
+ Steps 3 and 4 run when `engine` is `waapi`. Pass `waapi` for **any renderer
73
101
  without live `<use>` propagation** — that includes `react-native-svg` — and
74
102
  `frames` only for the DOM, which resolves `<use>` references natively.
75
103
 
@@ -80,7 +108,7 @@ import {
80
108
  } from '@pixodesk/svg-animator-core';
81
109
 
82
110
  // Flatten once …
83
- const flat = generateNewIds(materialiseAllInTree(doc, PxAnimatorEngine.webapi));
111
+ const flat = generateNewIds(materialiseAllInTree(doc, PxAnimatorEngine.waapi));
84
112
 
85
113
  // … then ask for values at any time, with no renderer involved.
86
114
  for (const binding of getNormalisedBindings(flat, PxAnimatorEngine.frames) ?? []) {