@pixodesk/svg-animator-web 1.0.45 → 1.0.46

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/dist/internal.cjs CHANGED
@@ -29,7 +29,7 @@ module.exports = __toCommonJS(internal_exports);
29
29
  // src/shared/PxAnimatorKeys.ts
30
30
  var PX_ANIMATOR_DOC_KEY = "doc";
31
31
 
32
- // ../svg-animator-core/dist/chunk-YVKMPBHE.js
32
+ // ../svg-animator-core/dist/chunk-37OFJ3RX.js
33
33
  var __defProp2 = Object.defineProperty;
34
34
  var __defProps = Object.defineProperties;
35
35
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -60,19 +60,31 @@ function pathStr(path) {
60
60
  return result;
61
61
  }
62
62
  var Base = class {
63
+ /** Structural schemas (objects, arrays, unions of objects…) pass `false`: they state no scalar default. */
64
+ constructor(_statesDefault) {
65
+ this._statesDefault = _statesDefault;
66
+ }
63
67
  _canSanitize(raw) {
64
68
  return this.isValid(raw);
65
69
  }
70
+ /** A REQUIRED field is never absent; its default is the repair value. */
71
+ absentDefault() {
72
+ return this._default;
73
+ }
66
74
  optional() {
67
75
  return new Optional(this);
68
76
  }
69
77
  };
70
78
  var Optional = class extends Base {
71
79
  constructor(inner) {
72
- super();
80
+ super(inner._statesDefault);
73
81
  this.inner = inner;
74
82
  this._default = void 0;
75
83
  }
84
+ /** Absent means the inner schema's STATED default — or nothing at all when it states none. */
85
+ absentDefault() {
86
+ return this.inner._statesDefault ? this.inner._default : void 0;
87
+ }
76
88
  sanitize(raw) {
77
89
  if (raw === void 0 || raw === null) return void 0;
78
90
  return this.inner._canSanitize(raw) ? this.inner.sanitize(raw) : void 0;
@@ -86,8 +98,8 @@ var Optional = class extends Base {
86
98
  }
87
99
  };
88
100
  var Str = class extends Base {
89
- constructor(_default = "") {
90
- super();
101
+ constructor(_default, statesDefault) {
102
+ super(statesDefault);
91
103
  this._default = _default;
92
104
  }
93
105
  sanitize(raw) {
@@ -100,8 +112,8 @@ var Str = class extends Base {
100
112
  }
101
113
  };
102
114
  var Num = class extends Base {
103
- constructor(_default = 0) {
104
- super();
115
+ constructor(_default, statesDefault) {
116
+ super(statesDefault);
105
117
  this._default = _default;
106
118
  }
107
119
  sanitize(raw) {
@@ -114,8 +126,8 @@ var Num = class extends Base {
114
126
  }
115
127
  };
116
128
  var Bool = class extends Base {
117
- constructor(_default = false) {
118
- super();
129
+ constructor(_default, statesDefault) {
130
+ super(statesDefault);
119
131
  this._default = _default;
120
132
  }
121
133
  sanitize(raw) {
@@ -128,8 +140,9 @@ var Bool = class extends Base {
128
140
  }
129
141
  };
130
142
  var Literal = class extends Base {
143
+ /** A literal IS its own value: absent means it. */
131
144
  constructor(value) {
132
- super();
145
+ super(true);
133
146
  this.value = value;
134
147
  this._default = value;
135
148
  }
@@ -143,8 +156,8 @@ var Literal = class extends Base {
143
156
  }
144
157
  };
145
158
  var Enum = class extends Base {
146
- constructor(values, defaultVal) {
147
- super();
159
+ constructor(values, defaultVal, statesDefault) {
160
+ super(statesDefault);
148
161
  this.values = values;
149
162
  this._default = defaultVal != null ? defaultVal : values[0];
150
163
  }
@@ -159,8 +172,8 @@ var Enum = class extends Base {
159
172
  };
160
173
  var UNION_MEMBER_ERROR_LIMIT = 4;
161
174
  var Union = class extends Base {
162
- constructor(schemas, defaultVal) {
163
- super();
175
+ constructor(schemas, defaultVal, statesDefault) {
176
+ super(statesDefault);
164
177
  this.schemas = schemas;
165
178
  this._kind = "union";
166
179
  this._default = defaultVal != null ? defaultVal : schemas[0]._default;
@@ -213,7 +226,7 @@ var Union = class extends Base {
213
226
  var DiscriminatedUnion = class extends Base {
214
227
  constructor(_key, _schemas, defaultVal) {
215
228
  var _a2;
216
- super();
229
+ super(false);
217
230
  this._key = _key;
218
231
  this._schemas = _schemas;
219
232
  this._kind = "discriminatedUnion";
@@ -252,13 +265,19 @@ var DiscriminatedUnion = class extends Base {
252
265
  return schema ? schema._canSanitize(raw) : this._schemas[0]._canSanitize(raw);
253
266
  }
254
267
  };
268
+ function statedDefaults(shape) {
269
+ const out = {};
270
+ for (const key of Object.keys(shape)) if (shape[key]._statesDefault) out[key] = shape[key].absentDefault();
271
+ return Object.freeze(out);
272
+ }
255
273
  var Obj = class extends Base {
256
274
  constructor(_shape) {
257
- super();
275
+ super(false);
258
276
  this._shape = _shape;
259
277
  const d = {};
260
278
  for (const key of Object.keys(_shape)) d[key] = _shape[key]._default;
261
279
  this._default = d;
280
+ this.defaults = statedDefaults(_shape);
262
281
  }
263
282
  sanitize(raw) {
264
283
  const src = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
@@ -300,12 +319,13 @@ var Obj = class extends Base {
300
319
  };
301
320
  var OpenObj = class extends Base {
302
321
  constructor(_shape, _openSchema) {
303
- super();
322
+ super(false);
304
323
  this._shape = _shape;
305
324
  this._openSchema = _openSchema;
306
325
  const d = {};
307
326
  for (const key of Object.keys(_shape)) d[key] = _shape[key]._default;
308
327
  this._default = d;
328
+ this.defaults = statedDefaults(_shape);
309
329
  }
310
330
  sanitize(raw) {
311
331
  const src = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
@@ -350,7 +370,7 @@ var OpenObj = class extends Base {
350
370
  };
351
371
  var Arr = class extends Base {
352
372
  constructor(item) {
353
- super();
373
+ super(false);
354
374
  this.item = item;
355
375
  this._default = [];
356
376
  }
@@ -382,7 +402,7 @@ var Arr = class extends Base {
382
402
  };
383
403
  var Rec = class extends Base {
384
404
  constructor(value) {
385
- super();
405
+ super(false);
386
406
  this.value = value;
387
407
  this._kind = "record";
388
408
  this._default = {};
@@ -415,7 +435,7 @@ var Rec = class extends Base {
415
435
  };
416
436
  var Any = class extends Base {
417
437
  constructor() {
418
- super(...arguments);
438
+ super(false);
419
439
  this._default = void 0;
420
440
  }
421
441
  sanitize(raw) {
@@ -430,7 +450,7 @@ var Any = class extends Base {
430
450
  };
431
451
  var Defined = class extends Base {
432
452
  constructor() {
433
- super(...arguments);
453
+ super(false);
434
454
  this._default = void 0;
435
455
  }
436
456
  sanitize(raw) {
@@ -447,7 +467,7 @@ var Defined = class extends Base {
447
467
  };
448
468
  var Lazy = class extends Base {
449
469
  constructor(fn, _default) {
450
- super();
470
+ super(false);
451
471
  this.fn = fn;
452
472
  this._default = _default;
453
473
  this.resolved = null;
@@ -468,7 +488,7 @@ var Lazy = class extends Base {
468
488
  };
469
489
  var Tuple = class extends Base {
470
490
  constructor(schemas) {
471
- super();
491
+ super(false);
472
492
  this.schemas = schemas;
473
493
  this._kind = "tuple";
474
494
  this._default = schemas.map((s) => s._default);
@@ -499,22 +519,29 @@ var Tuple = class extends Base {
499
519
  function implementsInterface() {
500
520
  return (schema) => schema;
501
521
  }
522
+ function string(defaultVal) {
523
+ return defaultVal === void 0 ? new Str("", false) : new Str(defaultVal, true);
524
+ }
525
+ function number(defaultVal) {
526
+ return defaultVal === void 0 ? new Num(0, false) : new Num(defaultVal, true);
527
+ }
528
+ function boolean(defaultVal) {
529
+ return defaultVal === void 0 ? new Bool(false, false) : new Bool(defaultVal, true);
530
+ }
531
+ function oneOf(values, defaultVal) {
532
+ return defaultVal === void 0 ? new Enum(values, void 0, false) : new Enum(values, defaultVal, true);
533
+ }
534
+ function unionOf(schemas, defaultVal) {
535
+ return defaultVal === void 0 ? new Union(schemas, void 0, false) : new Union(schemas, defaultVal, true);
536
+ }
502
537
  var px = {
503
- /** Matches a string. Default: '' or provided value. */
504
- string: (defaultVal = "") => new Str(defaultVal),
505
- /** Matches a finite number. Default: 0 or provided value. */
506
- number: (defaultVal = 0) => new Num(defaultVal),
507
- /** Matches a boolean. Default: false or provided value. */
508
- boolean: (defaultVal = false) => new Bool(defaultVal),
509
- /** Matches one exact primitive value; its default is the value itself. */
538
+ string,
539
+ number,
540
+ boolean,
541
+ /** Matches one exact primitive value; absent means the value itself. */
510
542
  literal: (value) => new Literal(value),
511
- /** Matches one of a fixed set of string/number values. Default: first value. */
512
- enum: (values, defaultVal) => new Enum(values, defaultVal),
513
- /**
514
- * Returns the first schema whose isValid passes.
515
- * TypeScript infers the union of all member types automatically.
516
- */
517
- union: (schemas, defaultVal) => new Union(schemas, defaultVal),
543
+ enum: oneOf,
544
+ union: unionOf,
518
545
  /**
519
546
  * Discriminated union — reads `raw[key]`, finds the member schema whose
520
547
  * literal at `key` matches, then delegates sanitize/isValid to that member.
@@ -522,7 +549,8 @@ var px = {
522
549
  * TypeScript infers the union of all member types automatically.
523
550
  */
524
551
  discriminatedUnion: (key, schemas) => new DiscriminatedUnion(key, schemas),
525
- /** Typed object — unknown keys are stripped. Required fields fall back to their default. */
552
+ /** Typed object — unknown keys are stripped. Required fields fall back to their default.
553
+ * Its `defaults` say what each stated field means when a document leaves it out. */
526
554
  object: (shape) => new Obj(shape),
527
555
  /**
528
556
  * Open object — validates known keys; passes unknown keys through as-is,
@@ -646,8 +674,11 @@ var PX_TRIGGER_DEFAULTS = {
646
674
  offScreen: "pause",
647
675
  mouseOut: "continue",
648
676
  visibilityThreshold: 0.5,
649
- visibilityDebounce: 150
677
+ visibilityDebounce: 150,
678
+ finish: "hold"
650
679
  };
680
+ var PX_DEFAULT_DURATION_MS = 1e3;
681
+ var PX_DEFAULT_ITERATIONS = 1;
651
682
  var PxLoopRepeatAt = {
652
683
  /** Segment from the START; the repetition runs BEFORE the first keyframe
653
684
  * (intro loops that play until the main timeline begins). */
@@ -747,15 +778,15 @@ var PxKeyframeSchema = implementsInterface()(px.object({
747
778
  }));
748
779
  var PxLoopSchema = implementsInterface()(px.object({
749
780
  segmentCount: px.number().optional(),
750
- repeatAt: px.enum([PxLoopRepeatAt.start, PxLoopRepeatAt.end]).optional(),
751
- direction: px.enum([PxLoopDirection.normal, PxLoopDirection.alternate]).optional()
781
+ repeatAt: px.enum([PxLoopRepeatAt.start, PxLoopRepeatAt.end], PxLoopRepeatAt.end).optional(),
782
+ direction: px.enum([PxLoopDirection.normal, PxLoopDirection.alternate], PxLoopDirection.normal).optional()
752
783
  }));
753
784
  var PxPropertyAnimationSchema = implementsInterface()(px.object({
754
785
  value: PxKeyframeValueSchema.optional(),
755
786
  keyframes: px.array(PxKeyframeSchema).optional(),
756
787
  loop: px.union([PxLoopSchema, px.boolean()]).optional(),
757
788
  autoOrient: px.boolean().optional(),
758
- alongPathMode: px.enum([PxAlongPathMode.sampled, PxAlongPathMode.offsetPath]).optional()
789
+ alongPathMode: px.enum([PxAlongPathMode.sampled, PxAlongPathMode.offsetPath], PxAlongPathMode.sampled).optional()
759
790
  }));
760
791
  var PxTransformPartsSchema = implementsInterface()(px.object({
761
792
  translate: px.tuple([px.number(), px.number()]).optional(),
@@ -785,9 +816,9 @@ var PxTriggerSchema = implementsInterface()(px.object({
785
816
  // What happens after a NATURAL finish — `'hold'` (default: keep the end state per
786
817
  // `fill`) or `'reset'` (snap back to the start state). One of four occasion keys
787
818
  // (`start`, `offScreen`, `mouseOut`, `finish`), all named the same way.
788
- finish: px.enum([PxFinishAction.hold, PxFinishAction.reset]).optional(),
789
- visibilityThreshold: px.number().optional(),
790
- visibilityDebounce: px.number().optional()
819
+ finish: px.enum([PxFinishAction.hold, PxFinishAction.reset], PX_TRIGGER_DEFAULTS.finish).optional(),
820
+ visibilityThreshold: px.number(PX_TRIGGER_DEFAULTS.visibilityThreshold).optional(),
821
+ visibilityDebounce: px.number(PX_TRIGGER_DEFAULTS.visibilityDebounce).optional()
791
822
  }));
792
823
  var PxGlyphSchema = implementsInterface()(px.object({
793
824
  width: px.number(),
@@ -813,7 +844,7 @@ var PxScrollRangePointSchema = implementsInterface()(px.object({
813
844
  PxScrollPhase.exit,
814
845
  PxScrollPhase.entryCrossing,
815
846
  PxScrollPhase.exitCrossing
816
- ]).optional(),
847
+ ], PxScrollPhase.cover).optional(),
817
848
  fraction: px.number().optional()
818
849
  }));
819
850
  var PxScrollRangeSchema = px.object({
@@ -821,37 +852,37 @@ var PxScrollRangeSchema = px.object({
821
852
  end: PxScrollRangePointSchema.optional()
822
853
  });
823
854
  var PxScrollSchema = implementsInterface()(px.object({
824
- kind: px.enum([PxScrollKind.view, PxScrollKind.scroll]).optional(),
825
- axis: px.enum([PxScrollAxis.block, PxScrollAxis.inline, PxScrollAxis.x, PxScrollAxis.y]).optional(),
826
- source: px.enum([PxScrollSource.nearest, PxScrollSource.root]).optional(),
855
+ kind: px.enum([PxScrollKind.view, PxScrollKind.scroll], PxScrollKind.view).optional(),
856
+ axis: px.enum([PxScrollAxis.block, PxScrollAxis.inline, PxScrollAxis.x, PxScrollAxis.y], PxScrollAxis.block).optional(),
857
+ source: px.enum([PxScrollSource.nearest, PxScrollSource.root], PxScrollSource.nearest).optional(),
827
858
  // Free-form: the two keywords `parent`/`scroller` plus any CSS selector.
828
859
  subject: px.string().optional(),
829
860
  smoothing: px.number().optional(),
830
- pin: px.boolean().optional(),
831
- pinAlign: px.enum([PxPinAlign.top, PxPinAlign.center, PxPinAlign.bottom]).optional(),
861
+ pin: px.boolean(false).optional(),
862
+ pinAlign: px.enum([PxPinAlign.top, PxPinAlign.center, PxPinAlign.bottom], PxPinAlign.top).optional(),
832
863
  pinOffset: px.number().optional(),
833
864
  pinDistance: px.number().optional(),
834
865
  range: PxScrollRangeSchema.optional()
835
866
  }));
836
867
  var PxTimelinePinSchema = implementsInterface()(px.object({
837
- align: px.enum([PxPinAlign.top, PxPinAlign.center, PxPinAlign.bottom]).optional(),
868
+ align: px.enum([PxPinAlign.top, PxPinAlign.center, PxPinAlign.bottom], PxPinAlign.top).optional(),
838
869
  offset: px.number().optional(),
839
870
  distance: px.number().optional()
840
871
  }));
841
- var PxTimelineEngineSchema = px.enum([PxTimelineEngineSetting.auto, PxTimelineEngineSetting.native, PxTimelineEngineSetting.js]).optional();
872
+ var PxTimelineEngineSchema = px.enum([PxTimelineEngineSetting.auto, PxTimelineEngineSetting.native, PxTimelineEngineSetting.js], PxTimelineEngineSetting.auto).optional();
842
873
  var PxTimeTimelineSchema = implementsInterface()(px.object({
843
874
  type: px.literal("time").optional(),
844
875
  engine: PxTimelineEngineSchema,
845
876
  frameRate: px.number().optional(),
846
877
  // §2.8: duration is a property of the TIMELINE — how long one pass takes.
847
- duration: px.number().optional(),
878
+ duration: px.number(PX_DEFAULT_DURATION_MS).optional(),
848
879
  trigger: PxTriggerSchema.optional(),
849
- delay: px.number().optional(),
850
- iterations: px.union([px.number(), px.literal("infinite")]).optional(),
880
+ delay: px.number(0).optional(),
881
+ iterations: px.union([px.number(PX_DEFAULT_ITERATIONS), px.literal("infinite")], PX_DEFAULT_ITERATIONS).optional(),
851
882
  // `fillMode` on the wire (CSS `animation-fill-mode`; the runtime view calls it `fill`)
852
883
  // — never `fill`, which is paint everywhere else in the format.
853
- fillMode: px.enum([PxFillMode.forwards, PxFillMode.backwards, PxFillMode.both, PxFillMode.none]).optional(),
854
- direction: px.enum([PxPlaybackDirection.normal, PxPlaybackDirection.reverse, PxPlaybackDirection.alternate, PxPlaybackDirection.alternateReverse]).optional()
884
+ fillMode: px.enum([PxFillMode.forwards, PxFillMode.backwards, PxFillMode.both, PxFillMode.none], PxFillMode.forwards).optional(),
885
+ direction: px.enum([PxPlaybackDirection.normal, PxPlaybackDirection.reverse, PxPlaybackDirection.alternate, PxPlaybackDirection.alternateReverse], PxPlaybackDirection.normal).optional()
855
886
  }));
856
887
  var scrollishTimelineShape = {
857
888
  // §2.8: duration is a property of the TIMELINE — under scrubbing it is the keyframe
@@ -862,8 +893,8 @@ var scrollishTimelineShape = {
862
893
  iterations: px.number().optional(),
863
894
  engine: PxTimelineEngineSchema,
864
895
  frameRate: px.number().optional(),
865
- axis: px.enum([PxScrollAxis.block, PxScrollAxis.inline, PxScrollAxis.x, PxScrollAxis.y]).optional(),
866
- source: px.enum([PxScrollSource.nearest, PxScrollSource.root]).optional(),
896
+ axis: px.enum([PxScrollAxis.block, PxScrollAxis.inline, PxScrollAxis.x, PxScrollAxis.y], PxScrollAxis.block).optional(),
897
+ source: px.enum([PxScrollSource.nearest, PxScrollSource.root], PxScrollSource.nearest).optional(),
867
898
  subject: px.string().optional(),
868
899
  // 'parent' | 'scroller' | any CSS selector
869
900
  smoothing: px.number().optional(),
@@ -943,9 +974,10 @@ var PxRepeaterEffectSchema = implementsInterface()(px.object({
943
974
  }));
944
975
  var PxMaskedByEffectSchema = implementsInterface()(px.object({
945
976
  source: px.string().optional(),
946
- maskType: px.enum([PxMaskType.luminance, PxMaskType.alpha]).optional(),
947
- maskUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox]).optional(),
948
- maskContentUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox]).optional(),
977
+ // SVG's own initial values — what a <mask> does when the attribute is not there.
978
+ maskType: px.enum([PxMaskType.luminance, PxMaskType.alpha], PxMaskType.luminance).optional(),
979
+ maskUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox], PxUnits.objectBoundingBox).optional(),
980
+ maskContentUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox], PxUnits.userSpaceOnUse).optional(),
949
981
  x: px.number().optional(),
950
982
  y: px.number().optional(),
951
983
  width: px.number().optional(),
@@ -957,7 +989,7 @@ var PxClipPathEffectSchema = implementsInterface()(px.object({
957
989
  var PxStrokeTrimEffectSchema = implementsInterface()(px.object({
958
990
  offset: PxAnimatableNumberSchema.optional(),
959
991
  range: PxAnimatableVec2Schema.optional(),
960
- subPaths: px.enum([PxStrokeTrimSubPaths.separate, PxStrokeTrimSubPaths.combined]).optional()
992
+ subPaths: px.enum([PxStrokeTrimSubPaths.separate, PxStrokeTrimSubPaths.combined], PxStrokeTrimSubPaths.separate).optional()
961
993
  }));
962
994
  var PxRetimeEffectSchema = implementsInterface()(px.object({
963
995
  start: px.number().optional(),
@@ -989,17 +1021,20 @@ var PxFillGradientEffectSchema = implementsInterface()(px.object({
989
1021
  radius: PxAnimatableNumberSchema.optional(),
990
1022
  focal: PxAnimatableVec2Schema.optional(),
991
1023
  stops: PxAnimatableGradientStopsSchema.optional(),
992
- gradientUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox]).optional(),
993
- spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat]).optional(),
1024
+ // SVG's own initial values — what a gradient does when the attribute is not there.
1025
+ gradientUnits: px.enum([PxUnits.userSpaceOnUse, PxUnits.objectBoundingBox], PxUnits.objectBoundingBox).optional(),
1026
+ spreadMethod: px.enum([PxGradientSpreadMethod.pad, PxGradientSpreadMethod.reflect, PxGradientSpreadMethod.repeat], PxGradientSpreadMethod.pad).optional(),
994
1027
  gradientTransform: px.string().optional()
995
1028
  }));
996
1029
  var PxStrokeGradientEffectSchema = PxFillGradientEffectSchema;
997
1030
  var PxTextPathEffectSchema = implementsInterface()(px.object({
998
1031
  pathData: px.string(),
999
- pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend]).optional(),
1000
- lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs]).optional(),
1001
- method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch]).optional(),
1002
- spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact]).optional(),
1032
+ // `extend` is what an omitted pathOverflow means (glyphs continue along the tangent); the
1033
+ // other three are SVG's own initial values for the native <textPath> attributes.
1034
+ pathOverflow: px.enum([PxPathOverflow.clip, PxPathOverflow.extend], PxPathOverflow.extend).optional(),
1035
+ lengthAdjust: px.enum([PxLengthAdjust.spacing, PxLengthAdjust.spacingAndGlyphs], PxLengthAdjust.spacing).optional(),
1036
+ method: px.enum([PxTextPathMethod.align, PxTextPathMethod.stretch], PxTextPathMethod.align).optional(),
1037
+ spacing: px.enum([PxTextPathSpacing.auto, PxTextPathSpacing.exact], PxTextPathSpacing.exact).optional(),
1003
1038
  startOffset: PxAnimatableNumberSchema.optional(),
1004
1039
  textLength: PxAnimatableNumberSchema.optional()
1005
1040
  }));