@pixodesk/svg-animator-web 1.0.41 → 1.0.43

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/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  __spreadValues
5
5
  } from "./chunk-BYDBNKO7.js";
6
6
 
7
- // ../svg-animator-core/dist/chunk-L6GJ6Y2M.js
7
+ // ../svg-animator-core/dist/chunk-BOTZI36B.js
8
8
  var __defProp = Object.defineProperty;
9
9
  var __defProps = Object.defineProperties;
10
10
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -3921,32 +3921,34 @@ var PxDiagnosticKind = {
3921
3921
  /** The player failed where it did not expect to — report it to us. */
3922
3922
  internal: "internal"
3923
3923
  };
3924
- function asError(error) {
3925
- return typeof error === "string" ? new Error(error) : error;
3924
+ var DOCS_URL = "https://github.com/pixodesk/pixodesk-svg-animator/blob/main/docs/diagnostics.md";
3925
+ function codeLine(code) {
3926
+ return "PX" + code + " " + DOCS_URL + "#px" + code;
3927
+ }
3928
+ function errorIn(data) {
3929
+ return data.find((d) => d instanceof Error);
3926
3930
  }
3927
3931
  function createDiagnostics(config, prefix) {
3928
3932
  const tag = prefix ? prefix + " " : "";
3929
3933
  return {
3930
- warn: (kind, message, detail) => {
3934
+ warn: (kind, code, ...data) => {
3935
+ const message = codeLine(code);
3931
3936
  if (config == null ? void 0 : config.onWarn) {
3932
- config.onWarn({ kind, message, detail });
3937
+ config.onWarn({ code, kind, data, message });
3933
3938
  return;
3934
3939
  }
3935
3940
  if (config == null ? void 0 : config.muteWarn) return;
3936
- const line = tag + kind + ": " + message;
3937
- if (detail === void 0) console.warn(line);
3938
- else console.warn(line, detail);
3941
+ console.warn(tag + kind + " " + message, ...data);
3939
3942
  },
3940
- error: (kind, error, detail) => {
3941
- const err = asError(error);
3943
+ error: (kind, code, ...data) => {
3944
+ const message = codeLine(code);
3945
+ const error = errorIn(data);
3942
3946
  if (config == null ? void 0 : config.onError) {
3943
- config.onError({ kind, message: err.message, error: err, detail });
3947
+ config.onError({ code, kind, data, message, error });
3944
3948
  return;
3945
3949
  }
3946
3950
  if (config == null ? void 0 : config.muteError) return;
3947
- const line = tag + kind + ": " + err.message;
3948
- if (detail === void 0) console.error(line);
3949
- else console.error(line, detail);
3951
+ console.error(tag + kind + " " + message, ...data);
3950
3952
  }
3951
3953
  };
3952
3954
  }
@@ -6063,6 +6065,36 @@ function createAdapterAnimator(doc, adapter, callbacks) {
6063
6065
  };
6064
6066
  return api;
6065
6067
  }
6068
+ var PxDiagnosticCode = /* @__PURE__ */ ((PxDiagnosticCode2) => {
6069
+ PxDiagnosticCode2[PxDiagnosticCode2["buildFailed"] = 1001] = "buildFailed";
6070
+ PxDiagnosticCode2[PxDiagnosticCode2["invalidDocumentAtSrc"] = 1002] = "invalidDocumentAtSrc";
6071
+ PxDiagnosticCode2[PxDiagnosticCode2["loadFailed"] = 1003] = "loadFailed";
6072
+ PxDiagnosticCode2[PxDiagnosticCode2["animationBuildFailed"] = 1004] = "animationBuildFailed";
6073
+ PxDiagnosticCode2[PxDiagnosticCode2["effectsShape"] = 1101] = "effectsShape";
6074
+ PxDiagnosticCode2[PxDiagnosticCode2["timelineOverrideIgnored"] = 1102] = "timelineOverrideIgnored";
6075
+ PxDiagnosticCode2[PxDiagnosticCode2["blockedTag"] = 1103] = "blockedTag";
6076
+ PxDiagnosticCode2[PxDiagnosticCode2["unsupportedAnimatedAttrs"] = 1104] = "unsupportedAnimatedAttrs";
6077
+ PxDiagnosticCode2[PxDiagnosticCode2["noBindings"] = 1105] = "noBindings";
6078
+ PxDiagnosticCode2[PxDiagnosticCode2["unresolvedBinding"] = 1106] = "unresolvedBinding";
6079
+ PxDiagnosticCode2[PxDiagnosticCode2["triggersNoRoot"] = 1201] = "triggersNoRoot";
6080
+ PxDiagnosticCode2[PxDiagnosticCode2["noRootForSelector"] = 1202] = "noRootForSelector";
6081
+ PxDiagnosticCode2[PxDiagnosticCode2["noRootElement"] = 1203] = "noRootElement";
6082
+ PxDiagnosticCode2[PxDiagnosticCode2["noElementsForSelector"] = 1206] = "noElementsForSelector";
6083
+ PxDiagnosticCode2[PxDiagnosticCode2["setAttributeNoElement"] = 1207] = "setAttributeNoElement";
6084
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollSmoothingNeedsOwnDriver"] = 1301] = "scrollSmoothingNeedsOwnDriver";
6085
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollNativeUnavailable"] = 1302] = "scrollNativeUnavailable";
6086
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollSubjectInvalid"] = 1303] = "scrollSubjectInvalid";
6087
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollSubjectNoMatch"] = 1304] = "scrollSubjectNoMatch";
6088
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollNoRootToObserve"] = 1305] = "scrollNoRootToObserve";
6089
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollTriggerIgnored"] = 1306] = "scrollTriggerIgnored";
6090
+ PxDiagnosticCode2[PxDiagnosticCode2["rateRejected"] = 1401] = "rateRejected";
6091
+ PxDiagnosticCode2[PxDiagnosticCode2["controlPropsConflict"] = 1501] = "controlPropsConflict";
6092
+ PxDiagnosticCode2[PxDiagnosticCode2["rnCompileFailed"] = 1601] = "rnCompileFailed";
6093
+ PxDiagnosticCode2[PxDiagnosticCode2["rnRenderFailed"] = 1602] = "rnRenderFailed";
6094
+ PxDiagnosticCode2[PxDiagnosticCode2["rnBoundaryCaught"] = 1603] = "rnBoundaryCaught";
6095
+ PxDiagnosticCode2[PxDiagnosticCode2["rnUnsupported"] = 1604] = "rnUnsupported";
6096
+ return PxDiagnosticCode2;
6097
+ })(PxDiagnosticCode || {});
6066
6098
  var FLAT_ONLY_KEYS = [
6067
6099
  "timelineSource",
6068
6100
  "scroll",
@@ -6303,7 +6335,7 @@ function setupAnimationTriggers(api, trigger, diag) {
6303
6335
  const { startOn, outAction, scrollIntoViewThreshold } = resolveTrigger(trigger);
6304
6336
  const root = api.getRootElement();
6305
6337
  if (!root) {
6306
- report.warn(PxDiagnosticKind.host, "setupAnimationTriggers: No root element found for animation.");
6338
+ report.warn(PxDiagnosticKind.host, PxDiagnosticCode.triggersNoRoot);
6307
6339
  return dispose;
6308
6340
  }
6309
6341
  let reversed = false;
@@ -6422,9 +6454,9 @@ function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
6422
6454
  if (doc.id) {
6423
6455
  const rootSelector = getSelector(doc.id);
6424
6456
  rootElement = document.querySelector(rootSelector);
6425
- if (!rootElement) diag.warn(PxDiagnosticKind.host, "createFrameLoopAnimator: No root element found for selector: " + rootSelector);
6457
+ if (!rootElement) diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootForSelector, rootSelector);
6426
6458
  } else {
6427
- diag.warn(PxDiagnosticKind.host, "createFrameLoopAnimator: No root element provided");
6459
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootElement);
6428
6460
  }
6429
6461
  }
6430
6462
  const basicApi = createAdapterAnimator(
@@ -6436,7 +6468,7 @@ function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
6436
6468
  "getRootElement": () => rootElement || null
6437
6469
  });
6438
6470
  if (isScrollTimeline(config)) {
6439
- if (config.trigger) diag.warn(PxDiagnosticKind.usage, "scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
6471
+ if (config.trigger) diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.scrollTriggerIgnored);
6440
6472
  } else {
6441
6473
  const detachTriggers = setupAnimationTriggers(api, (_a2 = config.trigger) != null ? _a2 : {}, diag);
6442
6474
  const destroyEngine = api.destroy.bind(api);
@@ -6461,7 +6493,7 @@ function createDomAdapter(rootElement, diag) {
6461
6493
  const elements = (rootElement == null ? void 0 : rootElement.querySelectorAll(selector)) || document.querySelectorAll(selector);
6462
6494
  if (elements.length === 0 && !warnedSelectors.has(selector)) {
6463
6495
  warnedSelectors.add(selector);
6464
- report.warn(PxDiagnosticKind.host, 'setAttribute: No elements found for selector "' + selector + '"');
6496
+ report.warn(PxDiagnosticKind.host, PxDiagnosticCode.setAttributeNoElement, selector);
6465
6497
  }
6466
6498
  for (let i = 0; i < elements.length; i++) {
6467
6499
  const element = elements[i];
@@ -6580,9 +6612,9 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6580
6612
  if (doc.id) {
6581
6613
  const rootSelector = getSelector(doc.id);
6582
6614
  rootElement = document.querySelector(rootSelector);
6583
- if (!rootElement) diag.warn(PxDiagnosticKind.host, "createWebApiAnimator: No root element found for selector: " + rootSelector);
6615
+ if (!rootElement) diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootForSelector, rootSelector);
6584
6616
  } else {
6585
- diag.warn(PxDiagnosticKind.host, "createWebApiAnimator: No root element provided");
6617
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootElement);
6586
6618
  }
6587
6619
  }
6588
6620
  const bindings = normalizeBindings(doc, PxTimelineEngine.native);
@@ -6595,18 +6627,18 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6595
6627
  let finishNotified = false;
6596
6628
  let removeCalled = false;
6597
6629
  if (!(bindings == null ? void 0 : bindings.length)) {
6598
- diag.warn(PxDiagnosticKind.document, "createWebApiAnimator: No animation bindings defined");
6630
+ diag.warn(PxDiagnosticKind.document, PxDiagnosticCode.noBindings);
6599
6631
  }
6600
6632
  for (const binding of bindings || []) {
6601
6633
  const animDef = binding.animate;
6602
6634
  if (!animDef || typeof animDef !== "object" || Array.isArray(animDef)) {
6603
- diag.warn(PxDiagnosticKind.document, "createWebApiAnimator: Empty or unresolved binding", binding);
6635
+ diag.warn(PxDiagnosticKind.document, PxDiagnosticCode.unresolvedBinding, binding);
6604
6636
  continue;
6605
6637
  }
6606
6638
  const selector = getSelector(binding.id);
6607
6639
  const elements = (rootElement == null ? void 0 : rootElement.querySelectorAll(selector)) || document.querySelectorAll(selector);
6608
6640
  if (elements.length === 0) {
6609
- diag.warn(PxDiagnosticKind.host, 'createWebApiAnimator: No elements found for selector "' + selector + '"');
6641
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noElementsForSelector, selector);
6610
6642
  }
6611
6643
  const keyframesMap = convertToWebApiKeyframes(animDef, unsupportedSet, config);
6612
6644
  const positiveDelay = config.delay && config.delay > 0 ? config.delay : void 0;
@@ -6655,14 +6687,14 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6655
6687
  }
6656
6688
  animations.push(anim);
6657
6689
  } catch (e) {
6658
- diag.warn(PxDiagnosticKind.internal, "createWebApiAnimator: could not build the animation", e);
6690
+ diag.warn(PxDiagnosticKind.internal, PxDiagnosticCode.animationBuildFailed, e);
6659
6691
  }
6660
6692
  }
6661
6693
  }
6662
6694
  }
6663
6695
  }
6664
6696
  if (!forceEvenIfHasUnsupportedAttrs && unsupportedSet.size) {
6665
- diag.warn(PxDiagnosticKind.platform, "Unsupported CSS attrs: " + [...unsupportedSet].join(", "));
6697
+ diag.warn(PxDiagnosticKind.platform, PxDiagnosticCode.unsupportedAnimatedAttrs, [...unsupportedSet].join(", "));
6666
6698
  return null;
6667
6699
  }
6668
6700
  const api = {
@@ -6707,7 +6739,7 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6707
6739
  },
6708
6740
  "setPlaybackRate": (rate) => {
6709
6741
  if (!isValidPlaybackRate(rate)) {
6710
- diag.warn(PxDiagnosticKind.usage, PX_RATE_REJECTED);
6742
+ diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.rateRejected);
6711
6743
  return api;
6712
6744
  }
6713
6745
  animations.forEach((a) => a.playbackRate = rate);
@@ -6747,7 +6779,7 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6747
6779
  }
6748
6780
  };
6749
6781
  if (config.timelineSource === "scroll") {
6750
- if (config.trigger) diag.warn(PxDiagnosticKind.usage, "scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
6782
+ if (config.trigger) diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.scrollTriggerIgnored);
6751
6783
  } else {
6752
6784
  const detachTriggers = setupAnimationTriggers(api, (_b = config.trigger) != null ? _b : {}, diag);
6753
6785
  const destroyEngine = api.destroy.bind(api);
@@ -6777,7 +6809,7 @@ function createNativeScrollTimeline(subject, config, diag) {
6777
6809
  const scroll = config.scroll || {};
6778
6810
  const kind = (_a2 = scroll.kind) != null ? _a2 : "view";
6779
6811
  if (scroll.smoothing) {
6780
- report.warn(PxDiagnosticKind.platform, "scroll timeline: `smoothing` needs the built-in driver \u2014 using the built-in driver instead of the browser timeline");
6812
+ report.warn(PxDiagnosticKind.platform, PxDiagnosticCode.scrollSmoothingNeedsOwnDriver);
6781
6813
  return null;
6782
6814
  }
6783
6815
  const g = globalThis;
@@ -6794,7 +6826,7 @@ function createNativeScrollTimeline(subject, config, diag) {
6794
6826
  timeline = new Ctor({ source, axis });
6795
6827
  }
6796
6828
  } catch (e) {
6797
- report.warn(PxDiagnosticKind.platform, "scroll timeline: native timeline construction failed \u2014 falling back to the player measuring progress itself", e);
6829
+ report.warn(PxDiagnosticKind.platform, PxDiagnosticCode.scrollNativeUnavailable, e);
6798
6830
  return null;
6799
6831
  }
6800
6832
  return {
@@ -6841,11 +6873,11 @@ function resolveScrollSubject(svgRoot, subject, diag) {
6841
6873
  try {
6842
6874
  found = document.querySelector(spec);
6843
6875
  } catch (e) {
6844
- report.warn(PxDiagnosticKind.document, 'scroll timeline: subject "' + spec + '" is not a valid selector \u2014 measuring the SVG itself');
6876
+ report.warn(PxDiagnosticKind.document, PxDiagnosticCode.scrollSubjectInvalid, spec);
6845
6877
  return svgRoot;
6846
6878
  }
6847
6879
  if (!found) {
6848
- report.warn(PxDiagnosticKind.host, 'scroll timeline: subject "' + spec + '" matched no element \u2014 measuring the SVG itself');
6880
+ report.warn(PxDiagnosticKind.host, PxDiagnosticCode.scrollSubjectNoMatch, spec);
6849
6881
  return svgRoot;
6850
6882
  }
6851
6883
  return found;
@@ -7087,7 +7119,7 @@ function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
7087
7119
  };
7088
7120
  }
7089
7121
  } else {
7090
- diag.warn(PxDiagnosticKind.host, "scroll timeline: no root element to observe \u2014 animation will stay at frame 0");
7122
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.scrollNoRootToObserve);
7091
7123
  }
7092
7124
  return api;
7093
7125
  });
@@ -7109,7 +7141,7 @@ function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
7109
7141
  var SVG_NS = "http://www.w3.org/2000/svg";
7110
7142
  function createElement(tagName, normalizedProps, style, children, textContent, diag) {
7111
7143
  if (PX_DISALLOWED_SVG_TAGS_LOWER.has(tagName.toLowerCase())) {
7112
- (diag != null ? diag : createDiagnostics(void 0, "[PxAnimator]")).warn(PxDiagnosticKind.document, "SVG tag blocked (dangerous): " + tagName);
7144
+ (diag != null ? diag : createDiagnostics(void 0, "[PxAnimator]")).warn(PxDiagnosticKind.document, PxDiagnosticCode.blockedTag, tagName);
7113
7145
  return null;
7114
7146
  }
7115
7147
  const element = document.createElementNS(SVG_NS, tagName);
@@ -7172,11 +7204,11 @@ function createAnimatorFromConfig(doc, adapter, callbacks, rootElement) {
7172
7204
  function createAnimatorImpl(doc, adapter, callbacks, containerElement, patch, resetTimeline) {
7173
7205
  const diag = createDiagnostics(callbacks, "[PxAnimator]");
7174
7206
  const effectsWarnings = validateNodeEffects(doc);
7175
- for (const w of effectsWarnings) diag.warn(PxDiagnosticKind.document, "effects shape: " + w);
7207
+ for (const w of effectsWarnings) diag.warn(PxDiagnosticKind.document, PxDiagnosticCode.effectsShape, w);
7176
7208
  reportDocumentDiagnostics(doc, "[PxAnimator] createAnimator");
7177
7209
  if (patch !== void 0 || resetTimeline) {
7178
7210
  const patched = applyAnimatorConfig(doc, patch != null ? patch : {}, { resetTimeline: !!resetTimeline });
7179
- for (const w of patched.warnings) diag.warn(PxDiagnosticKind.usage, "timeline override: " + w);
7211
+ for (const w of patched.warnings) diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.timelineOverrideIgnored, w);
7180
7212
  doc = patched.doc;
7181
7213
  }
7182
7214
  const animatorConfig = getAnimatorConfig(doc) || {};
@@ -7239,16 +7271,16 @@ function createAnimator(options) {
7239
7271
  pending = null;
7240
7272
  queued == null ? void 0 : queued.forEach((call) => call(api));
7241
7273
  };
7242
- const failed = (kind, message, detail) => {
7274
+ const failed = (kind, code, ...data) => {
7243
7275
  pending = null;
7244
- diag.error(kind, message, detail);
7276
+ diag.error(kind, code, ...data);
7245
7277
  };
7246
7278
  const build = (document2) => {
7247
7279
  try {
7248
7280
  ready(createAnimatorImpl(document2, adapter, callbacks, container, patch, resetTimeline));
7249
7281
  } catch (e) {
7250
7282
  const err = asThrownError(e);
7251
- failed(PxDiagnosticKind.internal, "createAnimator: could not build the player \u2014 " + err.message, err);
7283
+ failed(PxDiagnosticKind.internal, PxDiagnosticCode.buildFailed, err);
7252
7284
  }
7253
7285
  };
7254
7286
  if (doc !== void 0) {
@@ -7257,10 +7289,10 @@ function createAnimator(options) {
7257
7289
  fetch(src).then((res) => res.json()).then((json) => {
7258
7290
  if (destroyed) return;
7259
7291
  if (isPxDocument(json)) build(json);
7260
- else failed(PxDiagnosticKind.document, 'createAnimator: invalid animation document format at "' + src + '"');
7292
+ else failed(PxDiagnosticKind.document, PxDiagnosticCode.invalidDocumentAtSrc, src);
7261
7293
  }).catch((err) => {
7262
7294
  var _a2;
7263
- failed(PxDiagnosticKind.host, 'createAnimator: failed to load "' + src + '" \u2014 ' + ((_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err)));
7295
+ failed(PxDiagnosticKind.host, PxDiagnosticCode.loadFailed, src, (_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err));
7264
7296
  });
7265
7297
  }
7266
7298
  return {