@pixodesk/svg-animator-web 1.0.43 → 1.0.44

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.
@@ -58,7 +58,9 @@ var PixodeskAnimator = (() => {
58
58
  PxTimelineEngineSetting: () => PxTimelineEngineSetting,
59
59
  createAnimator: () => createAnimator,
60
60
  generateNewIds: () => generateNewIds,
61
+ getAllAnimators: () => getAllAnimators,
61
62
  loadTagAnimators: () => loadTagAnimators,
63
+ onAnimatorsChange: () => onAnimatorsChange,
62
64
  setupAnimationTriggers: () => setupAnimationTriggers,
63
65
  validateDocument: () => validateDocument
64
66
  });
@@ -571,7 +573,7 @@ var PixodeskAnimator = (() => {
571
573
  };
572
574
 
573
575
  // ../svg-animator-core/src/version/PxSchemaVersion.ts
574
- var PX_WIRE_SCHEMA_VERSION = "1.1";
576
+ var PX_WIRE_SCHEMA_VERSION = "1.2";
575
577
 
576
578
  // ../svg-animator-core/src/version/PxWireVersion.ts
577
579
  var VERSION_RE = /^(\d+)\.(\d+)(?:\.(\d+))?$/;
@@ -599,14 +601,18 @@ var PixodeskAnimator = (() => {
599
601
  };
600
602
  var PX_ANIM_SRC_ATTR_NAME = "data-px-animation-src";
601
603
  var PX_ANIM_ATTR_NAME = "_px_animator";
602
- var PxStartOn = {
604
+ var PxTriggerStart = {
603
605
  load: "load",
604
606
  mouseOver: "mouseOver",
605
607
  click: "click",
606
- scrollIntoView: "scrollIntoView",
607
- programmatic: "programmatic"
608
+ none: "none"
609
+ };
610
+ var PxOffScreenAction = {
611
+ pause: "pause",
612
+ continue: "continue",
613
+ reset: "reset"
608
614
  };
609
- var PxOutAction = {
615
+ var PxMouseOutAction = {
610
616
  continue: "continue",
611
617
  pause: "pause",
612
618
  reset: "reset",
@@ -674,16 +680,20 @@ var PixodeskAnimator = (() => {
674
680
  return engine !== PxTimelineEngineSetting.js;
675
681
  }
676
682
  var PX_TRIGGER_DEFAULTS = {
677
- startOn: "load",
678
- outAction: "continue",
679
- scrollIntoViewThreshold: 0
683
+ start: "load",
684
+ offScreen: "pause",
685
+ mouseOut: "continue",
686
+ visibilityThreshold: 0.5,
687
+ visibilityDebounce: 150
680
688
  };
681
689
  function resolveTrigger(trigger) {
682
- var _a2, _b, _c;
690
+ var _a2, _b, _c, _d, _e;
683
691
  return {
684
- startOn: (_a2 = trigger == null ? void 0 : trigger.startOn) != null ? _a2 : PX_TRIGGER_DEFAULTS.startOn,
685
- outAction: (_b = trigger == null ? void 0 : trigger.outAction) != null ? _b : PX_TRIGGER_DEFAULTS.outAction,
686
- scrollIntoViewThreshold: (_c = trigger == null ? void 0 : trigger.scrollIntoViewThreshold) != null ? _c : PX_TRIGGER_DEFAULTS.scrollIntoViewThreshold
692
+ start: (_a2 = trigger == null ? void 0 : trigger.start) != null ? _a2 : PX_TRIGGER_DEFAULTS.start,
693
+ offScreen: (_b = trigger == null ? void 0 : trigger.offScreen) != null ? _b : PX_TRIGGER_DEFAULTS.offScreen,
694
+ mouseOut: (_c = trigger == null ? void 0 : trigger.mouseOut) != null ? _c : PX_TRIGGER_DEFAULTS.mouseOut,
695
+ visibilityThreshold: (_d = trigger == null ? void 0 : trigger.visibilityThreshold) != null ? _d : PX_TRIGGER_DEFAULTS.visibilityThreshold,
696
+ visibilityDebounce: (_e = trigger == null ? void 0 : trigger.visibilityDebounce) != null ? _e : PX_TRIGGER_DEFAULTS.visibilityDebounce
687
697
  };
688
698
  }
689
699
  var PxLoopRepeatAt = {
@@ -819,9 +829,9 @@ var PixodeskAnimator = (() => {
819
829
  } else {
820
830
  if (timeline.duration !== void 0) flat.duration = timeline.duration;
821
831
  if (timeline.trigger !== void 0) {
822
- const _b = timeline.trigger, { finishAction } = _b, restTrigger = __objRest(_b, ["finishAction"]);
832
+ const _b = timeline.trigger, { finish } = _b, restTrigger = __objRest(_b, ["finish"]);
823
833
  if (Object.keys(restTrigger).length) flat.trigger = restTrigger;
824
- if (finishAction !== void 0) flat.resetOnFinish = finishAction === "reset";
834
+ if (finish !== void 0) flat.resetOnFinish = finish === "reset";
825
835
  }
826
836
  if (timeline.delay !== void 0) flat.delay = timeline.delay;
827
837
  if (timeline.iterations !== void 0) flat.iterations = timeline.iterations;
@@ -922,13 +932,15 @@ var PixodeskAnimator = (() => {
922
932
  PxAnimationDefinitionSchema
923
933
  ]));
924
934
  var PxTriggerSchema = implementsInterface()(px.object({
925
- startOn: px.enum([PxStartOn.load, PxStartOn.mouseOver, PxStartOn.click, PxStartOn.scrollIntoView, PxStartOn.programmatic], PX_TRIGGER_DEFAULTS.startOn).optional(),
926
- outAction: px.enum([PxOutAction.continue, PxOutAction.pause, PxOutAction.reset, PxOutAction.reverse], PX_TRIGGER_DEFAULTS.outAction).optional(),
935
+ start: px.enum([PxTriggerStart.load, PxTriggerStart.mouseOver, PxTriggerStart.click, PxTriggerStart.none], PX_TRIGGER_DEFAULTS.start).optional(),
936
+ offScreen: px.enum([PxOffScreenAction.pause, PxOffScreenAction.continue, PxOffScreenAction.reset], PX_TRIGGER_DEFAULTS.offScreen).optional(),
937
+ mouseOut: px.enum([PxMouseOutAction.continue, PxMouseOutAction.pause, PxMouseOutAction.reset, PxMouseOutAction.reverse], PX_TRIGGER_DEFAULTS.mouseOut).optional(),
927
938
  // What happens after a NATURAL finish — `'hold'` (default: keep the end state per
928
- // `fill`) or `'reset'` (snap back to the start state). Pairs with `outAction` ("what
929
- // happens when the trigger condition ends"); both end-of-life knobs now read alike.
930
- finishAction: px.enum([PxFinishAction.hold, PxFinishAction.reset]).optional(),
931
- scrollIntoViewThreshold: px.number().optional()
939
+ // `fill`) or `'reset'` (snap back to the start state). One of four occasion keys
940
+ // (`start`, `offScreen`, `mouseOut`, `finish`), all named the same way.
941
+ finish: px.enum([PxFinishAction.hold, PxFinishAction.reset]).optional(),
942
+ visibilityThreshold: px.number().optional(),
943
+ visibilityDebounce: px.number().optional()
932
944
  }));
933
945
  var PxGlyphSchema = implementsInterface()(px.object({
934
946
  width: px.number(),
@@ -6210,16 +6222,16 @@ var PixodeskAnimator = (() => {
6210
6222
  } else {
6211
6223
  base = timeline != null ? timeline : void 0;
6212
6224
  }
6213
- const { duration, delay, iterations, startOn } = shortcuts;
6214
- if (duration === void 0 && delay === void 0 && iterations === void 0 && startOn === void 0) {
6225
+ const { duration, delay, iterations, start } = shortcuts;
6226
+ if (duration === void 0 && delay === void 0 && iterations === void 0 && start === void 0) {
6215
6227
  return base === void 0 ? void 0 : { timeline: base };
6216
6228
  }
6217
6229
  const out = isPlainObject(base) ? __spreadValues({}, base) : {};
6218
6230
  if (duration !== void 0) out.duration = duration;
6219
6231
  if (delay !== void 0) out.delay = delay;
6220
6232
  if (iterations !== void 0) out.iterations = iterations;
6221
- if (startOn !== void 0) {
6222
- out.trigger = __spreadProps(__spreadValues({}, out.trigger), { startOn });
6233
+ if (start !== void 0) {
6234
+ out.trigger = __spreadProps(__spreadValues({}, out.trigger), { start });
6223
6235
  }
6224
6236
  return { timeline: out };
6225
6237
  }
@@ -6385,6 +6397,202 @@ var PixodeskAnimator = (() => {
6385
6397
  return e instanceof Error ? e : new Error(String(e));
6386
6398
  }
6387
6399
 
6400
+ // src/registry/PxAnimatorRegistry.ts
6401
+ var STORE_KEY = /* @__PURE__ */ Symbol.for("@pixodesk/svg-animator-web:animators");
6402
+ var GLOBAL_NAME = "__pixodeskAnimators";
6403
+ function store() {
6404
+ const g = globalThis;
6405
+ let s = g[STORE_KEY];
6406
+ if (!s) {
6407
+ const animators = /* @__PURE__ */ new Set();
6408
+ const listeners = /* @__PURE__ */ new Set();
6409
+ s = {
6410
+ animators,
6411
+ listeners,
6412
+ getAll: () => Array.from(animators),
6413
+ subscribe: (listener) => {
6414
+ listeners.add(listener);
6415
+ return () => {
6416
+ listeners.delete(listener);
6417
+ };
6418
+ }
6419
+ };
6420
+ g[STORE_KEY] = s;
6421
+ if (g[GLOBAL_NAME] === void 0) g[GLOBAL_NAME] = s;
6422
+ }
6423
+ return s;
6424
+ }
6425
+ function getAllAnimators() {
6426
+ return store().getAll();
6427
+ }
6428
+ function onAnimatorsChange(listener) {
6429
+ return store().subscribe(listener);
6430
+ }
6431
+ function notify(event, animator) {
6432
+ for (const listener of store().listeners) {
6433
+ try {
6434
+ listener(event, animator);
6435
+ } catch (e) {
6436
+ setTimeout(() => {
6437
+ throw e;
6438
+ }, 0);
6439
+ }
6440
+ }
6441
+ }
6442
+ function registerAnimator(animator) {
6443
+ const s = store();
6444
+ if (s.animators.has(animator)) return;
6445
+ s.animators.add(animator);
6446
+ notify("add", animator);
6447
+ const destroy = animator.destroy.bind(animator);
6448
+ animator.destroy = () => {
6449
+ destroy();
6450
+ if (s.animators.delete(animator)) notify("remove", animator);
6451
+ };
6452
+ }
6453
+ function withRegistryEvents(callbacks, api) {
6454
+ const fire = (event) => {
6455
+ const a = api();
6456
+ if (a) notify(event, a);
6457
+ };
6458
+ return __spreadProps(__spreadValues({}, callbacks), {
6459
+ onPlay: () => {
6460
+ var _a2;
6461
+ (_a2 = callbacks == null ? void 0 : callbacks.onPlay) == null ? void 0 : _a2.call(callbacks);
6462
+ fire("play");
6463
+ },
6464
+ onPause: () => {
6465
+ var _a2;
6466
+ (_a2 = callbacks == null ? void 0 : callbacks.onPause) == null ? void 0 : _a2.call(callbacks);
6467
+ fire("pause");
6468
+ },
6469
+ onCancel: () => {
6470
+ var _a2;
6471
+ (_a2 = callbacks == null ? void 0 : callbacks.onCancel) == null ? void 0 : _a2.call(callbacks);
6472
+ fire("cancel");
6473
+ },
6474
+ onFinish: () => {
6475
+ var _a2;
6476
+ (_a2 = callbacks == null ? void 0 : callbacks.onFinish) == null ? void 0 : _a2.call(callbacks);
6477
+ fire("finish");
6478
+ }
6479
+ });
6480
+ }
6481
+
6482
+ // src/triggers/PxVisibilityGate.ts
6483
+ var PLAY_WHEN_VISIBLE_DEFAULTS = {
6484
+ offScreen: PX_TRIGGER_DEFAULTS.offScreen,
6485
+ visibilityThreshold: PX_TRIGGER_DEFAULTS.visibilityThreshold,
6486
+ visibilityDebounce: PX_TRIGGER_DEFAULTS.visibilityDebounce
6487
+ };
6488
+ var THRESHOLD_STEPS = Array.from({ length: 21 }, (_, i) => i / 20);
6489
+ function effectiveRatio(entry) {
6490
+ var _a2, _b;
6491
+ const target = entry.boundingClientRect;
6492
+ const visible = entry.intersectionRect;
6493
+ if (!(target == null ? void 0 : target.height) || !visible) return entry.intersectionRatio;
6494
+ const live = typeof window !== "undefined" && window.innerHeight ? window.innerHeight : Infinity;
6495
+ const declared = (_b = (_a2 = entry.rootBounds) == null ? void 0 : _a2.height) != null ? _b : Infinity;
6496
+ const viewport = Math.min(live, declared);
6497
+ const denom = Math.min(target.height, Number.isFinite(viewport) ? viewport : target.height);
6498
+ return denom > 0 ? visible.height / denom : entry.intersectionRatio;
6499
+ }
6500
+ function openGate(host) {
6501
+ return {
6502
+ requestStart: () => host.play(),
6503
+ dispose: () => {
6504
+ }
6505
+ };
6506
+ }
6507
+ function isGated(offScreen) {
6508
+ return offScreen !== PxOffScreenAction.continue;
6509
+ }
6510
+ function createVisibilityGate(root, trigger, host) {
6511
+ if (!isGated(trigger.offScreen)) return openGate(host);
6512
+ if (typeof IntersectionObserver === "undefined") return openGate(host);
6513
+ const threshold = trigger.visibilityThreshold;
6514
+ const debounceMs = trigger.visibilityDebounce;
6515
+ let isOpen = void 0;
6516
+ let startPending = false;
6517
+ let pausedByGate = false;
6518
+ let lastRatio = 0;
6519
+ let openTimer;
6520
+ const cancelPendingOpen = () => {
6521
+ if (openTimer !== void 0) {
6522
+ clearTimeout(openTimer);
6523
+ openTimer = void 0;
6524
+ }
6525
+ };
6526
+ const open = () => {
6527
+ openTimer = void 0;
6528
+ if (isOpen === true) return;
6529
+ isOpen = true;
6530
+ if (startPending || pausedByGate) {
6531
+ startPending = false;
6532
+ pausedByGate = false;
6533
+ host.play();
6534
+ }
6535
+ };
6536
+ const close = () => {
6537
+ cancelPendingOpen();
6538
+ if (isOpen === false) return;
6539
+ isOpen = false;
6540
+ if (!host.isPlaying()) return;
6541
+ if (trigger.offScreen === PxOffScreenAction.reset) {
6542
+ host.cancel();
6543
+ } else {
6544
+ host.pause();
6545
+ }
6546
+ pausedByGate = true;
6547
+ };
6548
+ const apply2 = (ratio) => {
6549
+ lastRatio = ratio;
6550
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") {
6551
+ close();
6552
+ return;
6553
+ }
6554
+ if (ratio >= threshold) {
6555
+ if (isOpen === true || openTimer !== void 0) return;
6556
+ if (debounceMs > 0) openTimer = setTimeout(open, debounceMs);
6557
+ else open();
6558
+ return;
6559
+ }
6560
+ if (ratio <= 0) {
6561
+ close();
6562
+ return;
6563
+ }
6564
+ if (isOpen !== true) cancelPendingOpen();
6565
+ };
6566
+ const observer = new IntersectionObserver((entries) => {
6567
+ const last = entries[entries.length - 1];
6568
+ if (last) apply2(last.isIntersecting ? effectiveRatio(last) : 0);
6569
+ }, { threshold: THRESHOLD_STEPS });
6570
+ observer.observe(root);
6571
+ const onVisibilityChange = () => {
6572
+ apply2(lastRatio);
6573
+ };
6574
+ const hasDocument = typeof document !== "undefined";
6575
+ if (hasDocument) document.addEventListener("visibilitychange", onVisibilityChange);
6576
+ return {
6577
+ requestStart: (immediate) => {
6578
+ if (immediate || isOpen === true) {
6579
+ cancelPendingOpen();
6580
+ isOpen = true;
6581
+ startPending = false;
6582
+ pausedByGate = false;
6583
+ host.play();
6584
+ return;
6585
+ }
6586
+ startPending = true;
6587
+ },
6588
+ dispose: () => {
6589
+ cancelPendingOpen();
6590
+ observer.disconnect();
6591
+ if (hasDocument) document.removeEventListener("visibilitychange", onVisibilityChange);
6592
+ }
6593
+ };
6594
+ }
6595
+
6388
6596
  // src/triggers/PxAnimatorTriggers.ts
6389
6597
  function setupAnimationTriggers(api, trigger, diag) {
6390
6598
  const report = diag != null ? diag : createDiagnostics(void 0, "[PxAnimator]");
@@ -6392,7 +6600,7 @@ var PixodeskAnimator = (() => {
6392
6600
  const dispose = () => {
6393
6601
  for (const undo of cleanups.splice(0)) undo();
6394
6602
  };
6395
- const { startOn, outAction, scrollIntoViewThreshold } = resolveTrigger(trigger);
6603
+ const resolved = resolveTrigger(trigger);
6396
6604
  const root = api.getRootElement();
6397
6605
  if (!root) {
6398
6606
  report.warn(PxDiagnosticKind.host, 1201 /* triggersNoRoot */);
@@ -6406,27 +6614,34 @@ var PixodeskAnimator = (() => {
6406
6614
  }
6407
6615
  api.play();
6408
6616
  };
6409
- const handleEndAction = () => {
6410
- switch (outAction) {
6411
- case "pause":
6617
+ const gate = createVisibilityGate(root, resolved, {
6618
+ isPlaying: () => api.isPlaying(),
6619
+ play: start,
6620
+ pause: () => api.pause(),
6621
+ cancel: () => api.cancel()
6622
+ });
6623
+ cleanups.push(() => gate.dispose());
6624
+ const handleMouseOut = () => {
6625
+ switch (resolved.mouseOut) {
6626
+ case PxMouseOutAction.pause:
6412
6627
  api.pause();
6413
6628
  break;
6414
- case "reset":
6629
+ case PxMouseOutAction.reset:
6415
6630
  api.cancel();
6416
6631
  break;
6417
- case "reverse":
6632
+ case PxMouseOutAction.reverse:
6418
6633
  reversed = true;
6419
6634
  api.setPlaybackRate(-1);
6420
6635
  api.play();
6421
6636
  break;
6422
- case "continue":
6637
+ case PxMouseOutAction.continue:
6423
6638
  default:
6424
6639
  break;
6425
6640
  }
6426
6641
  };
6427
- switch (startOn) {
6428
- case "load": {
6429
- const startHandler = () => start();
6642
+ switch (resolved.start) {
6643
+ case PxTriggerStart.load: {
6644
+ const startHandler = () => gate.requestStart(false);
6430
6645
  if (document.readyState === "complete") {
6431
6646
  startHandler();
6432
6647
  } else {
@@ -6435,14 +6650,14 @@ var PixodeskAnimator = (() => {
6435
6650
  }
6436
6651
  break;
6437
6652
  }
6438
- case "mouseOver": {
6653
+ case PxTriggerStart.mouseOver: {
6439
6654
  let enteredOnce = false;
6440
6655
  const mouseOverHandler = () => {
6441
6656
  enteredOnce = true;
6442
- start();
6657
+ gate.requestStart(true);
6443
6658
  };
6444
6659
  const mouseOutHandler = () => {
6445
- if (enteredOnce) handleEndAction();
6660
+ if (enteredOnce) handleMouseOut();
6446
6661
  };
6447
6662
  root.addEventListener("mouseenter", mouseOverHandler);
6448
6663
  root.addEventListener("mouseleave", mouseOutHandler);
@@ -6452,51 +6667,16 @@ var PixodeskAnimator = (() => {
6452
6667
  });
6453
6668
  break;
6454
6669
  }
6455
- case "click": {
6670
+ case PxTriggerStart.click: {
6456
6671
  const clickHandler = () => {
6457
- if (api.isPlaying()) {
6458
- handleEndAction();
6459
- } else {
6460
- start();
6461
- }
6672
+ if (api.isPlaying()) api.pause();
6673
+ else gate.requestStart(true);
6462
6674
  };
6463
6675
  root.addEventListener("click", clickHandler);
6464
6676
  cleanups.push(() => root.removeEventListener("click", clickHandler));
6465
6677
  break;
6466
6678
  }
6467
- case "scrollIntoView": {
6468
- const effectiveRatio = (entry) => {
6469
- var _a2, _b;
6470
- const target = entry.boundingClientRect;
6471
- const visible = entry.intersectionRect;
6472
- if (!(target == null ? void 0 : target.height) || !visible) return entry.intersectionRatio;
6473
- const live = typeof window !== "undefined" && window.innerHeight ? window.innerHeight : Infinity;
6474
- const declared = (_b = (_a2 = entry.rootBounds) == null ? void 0 : _a2.height) != null ? _b : Infinity;
6475
- const viewport = Math.min(live, declared);
6476
- const denom = Math.min(target.height, Number.isFinite(viewport) ? viewport : target.height);
6477
- return denom > 0 ? visible.height / denom : entry.intersectionRatio;
6478
- };
6479
- const thresholdSteps = Array.from({ length: 21 }, (_, i) => i / 20);
6480
- let wasIntersecting = false;
6481
- const observer = new IntersectionObserver(
6482
- (entries) => {
6483
- entries.forEach((entry) => {
6484
- if (entry.isIntersecting && effectiveRatio(entry) >= scrollIntoViewThreshold) {
6485
- wasIntersecting = true;
6486
- start();
6487
- } else if (wasIntersecting) {
6488
- wasIntersecting = false;
6489
- handleEndAction();
6490
- }
6491
- });
6492
- },
6493
- { threshold: thresholdSteps }
6494
- );
6495
- observer.observe(root);
6496
- cleanups.push(() => observer.disconnect());
6497
- break;
6498
- }
6499
- case "programmatic":
6679
+ case PxTriggerStart.none:
6500
6680
  break;
6501
6681
  }
6502
6682
  return dispose;
@@ -6504,7 +6684,12 @@ var PixodeskAnimator = (() => {
6504
6684
 
6505
6685
  // src/engines/PxAnimatorFrameLoop.ts
6506
6686
  function getSelector(id) {
6507
- return "#" + id;
6687
+ return "#" + escapeCssId(id);
6688
+ }
6689
+ function escapeCssId(id) {
6690
+ const css = globalThis.CSS;
6691
+ if (typeof (css == null ? void 0 : css.escape) === "function") return css.escape(id);
6692
+ return id.replace(/^([0-9])/, (_all, digit) => "\\3" + digit + " ").replace(/([^\w\-\\ ])/g, "\\$1");
6508
6693
  }
6509
6694
  function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
6510
6695
  var _a2;
@@ -7303,14 +7488,15 @@ var PixodeskAnimator = (() => {
7303
7488
  return "adapter" in options;
7304
7489
  }
7305
7490
  function resolveTimelineOption(options) {
7306
- const { timeline, duration, delay, iterations, startOn } = options;
7307
- return foldTimelineOverride(timeline, { duration, delay, iterations, startOn });
7491
+ const { timeline, duration, delay, iterations, start } = options;
7492
+ return foldTimelineOverride(timeline, { duration, delay, iterations, start });
7308
7493
  }
7309
7494
  function createAnimator(options) {
7310
7495
  const { src, doc, container, resetTimeline } = options;
7311
7496
  const adapter = isInternalOptions(options) ? options.adapter : void 0;
7312
7497
  const patch = resolveTimelineOption(options);
7313
- const callbacks = toEngineCallbacks(options);
7498
+ let proxy;
7499
+ const callbacks = withRegistryEvents(toEngineCallbacks(options), () => proxy);
7314
7500
  if (doc !== void 0 && src !== void 0) {
7315
7501
  throw new Error("createAnimator: provide either `src` or `doc`, not both");
7316
7502
  }
@@ -7346,19 +7532,7 @@ var PixodeskAnimator = (() => {
7346
7532
  failed(PxDiagnosticKind.internal, 1001 /* buildFailed */, err);
7347
7533
  }
7348
7534
  };
7349
- if (doc !== void 0) {
7350
- build(doc);
7351
- } else {
7352
- fetch(src).then((res) => res.json()).then((json) => {
7353
- if (destroyed) return;
7354
- if (isPxDocument(json)) build(json);
7355
- else failed(PxDiagnosticKind.document, 1002 /* invalidDocumentAtSrc */, src);
7356
- }).catch((err) => {
7357
- var _a2;
7358
- failed(PxDiagnosticKind.host, 1003 /* loadFailed */, src, (_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err));
7359
- });
7360
- }
7361
- return {
7535
+ proxy = {
7362
7536
  "isReady": () => !!animator,
7363
7537
  "getRootElement": () => animator ? animator.getRootElement() : null,
7364
7538
  "isPlaying": () => (animator == null ? void 0 : animator.isPlaying()) || false,
@@ -7391,6 +7565,20 @@ var PixodeskAnimator = (() => {
7391
7565
  animator == null ? void 0 : animator.destroy();
7392
7566
  }
7393
7567
  };
7568
+ registerAnimator(proxy);
7569
+ if (doc !== void 0) {
7570
+ build(doc);
7571
+ } else {
7572
+ fetch(src).then((res) => res.json()).then((json) => {
7573
+ if (destroyed) return;
7574
+ if (isPxDocument(json)) build(json);
7575
+ else failed(PxDiagnosticKind.document, 1002 /* invalidDocumentAtSrc */, src);
7576
+ }).catch((err) => {
7577
+ var _a2;
7578
+ failed(PxDiagnosticKind.host, 1003 /* loadFailed */, src, (_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err));
7579
+ });
7580
+ }
7581
+ return proxy;
7394
7582
  }
7395
7583
  function loadTagAnimators(options) {
7396
7584
  const elements = document.querySelectorAll("[" + PX_ANIM_SRC_ATTR_NAME + "]");