@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.cjs CHANGED
@@ -69,7 +69,7 @@ __export(index_exports, {
69
69
  });
70
70
  module.exports = __toCommonJS(index_exports);
71
71
 
72
- // ../svg-animator-core/dist/chunk-L6GJ6Y2M.js
72
+ // ../svg-animator-core/dist/chunk-BOTZI36B.js
73
73
  var __defProp2 = Object.defineProperty;
74
74
  var __defProps2 = Object.defineProperties;
75
75
  var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
@@ -3986,32 +3986,34 @@ var PxDiagnosticKind = {
3986
3986
  /** The player failed where it did not expect to — report it to us. */
3987
3987
  internal: "internal"
3988
3988
  };
3989
- function asError(error) {
3990
- return typeof error === "string" ? new Error(error) : error;
3989
+ var DOCS_URL = "https://github.com/pixodesk/pixodesk-svg-animator/blob/main/docs/diagnostics.md";
3990
+ function codeLine(code) {
3991
+ return "PX" + code + " " + DOCS_URL + "#px" + code;
3992
+ }
3993
+ function errorIn(data) {
3994
+ return data.find((d) => d instanceof Error);
3991
3995
  }
3992
3996
  function createDiagnostics(config, prefix) {
3993
3997
  const tag = prefix ? prefix + " " : "";
3994
3998
  return {
3995
- warn: (kind, message, detail) => {
3999
+ warn: (kind, code, ...data) => {
4000
+ const message = codeLine(code);
3996
4001
  if (config == null ? void 0 : config.onWarn) {
3997
- config.onWarn({ kind, message, detail });
4002
+ config.onWarn({ code, kind, data, message });
3998
4003
  return;
3999
4004
  }
4000
4005
  if (config == null ? void 0 : config.muteWarn) return;
4001
- const line = tag + kind + ": " + message;
4002
- if (detail === void 0) console.warn(line);
4003
- else console.warn(line, detail);
4006
+ console.warn(tag + kind + " " + message, ...data);
4004
4007
  },
4005
- error: (kind, error, detail) => {
4006
- const err = asError(error);
4008
+ error: (kind, code, ...data) => {
4009
+ const message = codeLine(code);
4010
+ const error = errorIn(data);
4007
4011
  if (config == null ? void 0 : config.onError) {
4008
- config.onError({ kind, message: err.message, error: err, detail });
4012
+ config.onError({ code, kind, data, message, error });
4009
4013
  return;
4010
4014
  }
4011
4015
  if (config == null ? void 0 : config.muteError) return;
4012
- const line = tag + kind + ": " + err.message;
4013
- if (detail === void 0) console.error(line);
4014
- else console.error(line, detail);
4016
+ console.error(tag + kind + " " + message, ...data);
4015
4017
  }
4016
4018
  };
4017
4019
  }
@@ -6128,6 +6130,36 @@ function createAdapterAnimator(doc, adapter, callbacks) {
6128
6130
  };
6129
6131
  return api;
6130
6132
  }
6133
+ var PxDiagnosticCode = /* @__PURE__ */ ((PxDiagnosticCode2) => {
6134
+ PxDiagnosticCode2[PxDiagnosticCode2["buildFailed"] = 1001] = "buildFailed";
6135
+ PxDiagnosticCode2[PxDiagnosticCode2["invalidDocumentAtSrc"] = 1002] = "invalidDocumentAtSrc";
6136
+ PxDiagnosticCode2[PxDiagnosticCode2["loadFailed"] = 1003] = "loadFailed";
6137
+ PxDiagnosticCode2[PxDiagnosticCode2["animationBuildFailed"] = 1004] = "animationBuildFailed";
6138
+ PxDiagnosticCode2[PxDiagnosticCode2["effectsShape"] = 1101] = "effectsShape";
6139
+ PxDiagnosticCode2[PxDiagnosticCode2["timelineOverrideIgnored"] = 1102] = "timelineOverrideIgnored";
6140
+ PxDiagnosticCode2[PxDiagnosticCode2["blockedTag"] = 1103] = "blockedTag";
6141
+ PxDiagnosticCode2[PxDiagnosticCode2["unsupportedAnimatedAttrs"] = 1104] = "unsupportedAnimatedAttrs";
6142
+ PxDiagnosticCode2[PxDiagnosticCode2["noBindings"] = 1105] = "noBindings";
6143
+ PxDiagnosticCode2[PxDiagnosticCode2["unresolvedBinding"] = 1106] = "unresolvedBinding";
6144
+ PxDiagnosticCode2[PxDiagnosticCode2["triggersNoRoot"] = 1201] = "triggersNoRoot";
6145
+ PxDiagnosticCode2[PxDiagnosticCode2["noRootForSelector"] = 1202] = "noRootForSelector";
6146
+ PxDiagnosticCode2[PxDiagnosticCode2["noRootElement"] = 1203] = "noRootElement";
6147
+ PxDiagnosticCode2[PxDiagnosticCode2["noElementsForSelector"] = 1206] = "noElementsForSelector";
6148
+ PxDiagnosticCode2[PxDiagnosticCode2["setAttributeNoElement"] = 1207] = "setAttributeNoElement";
6149
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollSmoothingNeedsOwnDriver"] = 1301] = "scrollSmoothingNeedsOwnDriver";
6150
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollNativeUnavailable"] = 1302] = "scrollNativeUnavailable";
6151
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollSubjectInvalid"] = 1303] = "scrollSubjectInvalid";
6152
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollSubjectNoMatch"] = 1304] = "scrollSubjectNoMatch";
6153
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollNoRootToObserve"] = 1305] = "scrollNoRootToObserve";
6154
+ PxDiagnosticCode2[PxDiagnosticCode2["scrollTriggerIgnored"] = 1306] = "scrollTriggerIgnored";
6155
+ PxDiagnosticCode2[PxDiagnosticCode2["rateRejected"] = 1401] = "rateRejected";
6156
+ PxDiagnosticCode2[PxDiagnosticCode2["controlPropsConflict"] = 1501] = "controlPropsConflict";
6157
+ PxDiagnosticCode2[PxDiagnosticCode2["rnCompileFailed"] = 1601] = "rnCompileFailed";
6158
+ PxDiagnosticCode2[PxDiagnosticCode2["rnRenderFailed"] = 1602] = "rnRenderFailed";
6159
+ PxDiagnosticCode2[PxDiagnosticCode2["rnBoundaryCaught"] = 1603] = "rnBoundaryCaught";
6160
+ PxDiagnosticCode2[PxDiagnosticCode2["rnUnsupported"] = 1604] = "rnUnsupported";
6161
+ return PxDiagnosticCode2;
6162
+ })(PxDiagnosticCode || {});
6131
6163
  var FLAT_ONLY_KEYS = [
6132
6164
  "timelineSource",
6133
6165
  "scroll",
@@ -6368,7 +6400,7 @@ function setupAnimationTriggers(api, trigger, diag) {
6368
6400
  const { startOn, outAction, scrollIntoViewThreshold } = resolveTrigger(trigger);
6369
6401
  const root = api.getRootElement();
6370
6402
  if (!root) {
6371
- report.warn(PxDiagnosticKind.host, "setupAnimationTriggers: No root element found for animation.");
6403
+ report.warn(PxDiagnosticKind.host, PxDiagnosticCode.triggersNoRoot);
6372
6404
  return dispose;
6373
6405
  }
6374
6406
  let reversed = false;
@@ -6487,9 +6519,9 @@ function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
6487
6519
  if (doc.id) {
6488
6520
  const rootSelector = getSelector(doc.id);
6489
6521
  rootElement = document.querySelector(rootSelector);
6490
- if (!rootElement) diag.warn(PxDiagnosticKind.host, "createFrameLoopAnimator: No root element found for selector: " + rootSelector);
6522
+ if (!rootElement) diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootForSelector, rootSelector);
6491
6523
  } else {
6492
- diag.warn(PxDiagnosticKind.host, "createFrameLoopAnimator: No root element provided");
6524
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootElement);
6493
6525
  }
6494
6526
  }
6495
6527
  const basicApi = createAdapterAnimator(
@@ -6501,7 +6533,7 @@ function createFrameLoopAnimator(doc, adapter, callbacks, rootElement) {
6501
6533
  "getRootElement": () => rootElement || null
6502
6534
  });
6503
6535
  if (isScrollTimeline(config)) {
6504
- if (config.trigger) diag.warn(PxDiagnosticKind.usage, "scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
6536
+ if (config.trigger) diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.scrollTriggerIgnored);
6505
6537
  } else {
6506
6538
  const detachTriggers = setupAnimationTriggers(api, (_a2 = config.trigger) != null ? _a2 : {}, diag);
6507
6539
  const destroyEngine = api.destroy.bind(api);
@@ -6526,7 +6558,7 @@ function createDomAdapter(rootElement, diag) {
6526
6558
  const elements = (rootElement == null ? void 0 : rootElement.querySelectorAll(selector)) || document.querySelectorAll(selector);
6527
6559
  if (elements.length === 0 && !warnedSelectors.has(selector)) {
6528
6560
  warnedSelectors.add(selector);
6529
- report.warn(PxDiagnosticKind.host, 'setAttribute: No elements found for selector "' + selector + '"');
6561
+ report.warn(PxDiagnosticKind.host, PxDiagnosticCode.setAttributeNoElement, selector);
6530
6562
  }
6531
6563
  for (let i = 0; i < elements.length; i++) {
6532
6564
  const element = elements[i];
@@ -6645,9 +6677,9 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6645
6677
  if (doc.id) {
6646
6678
  const rootSelector = getSelector(doc.id);
6647
6679
  rootElement = document.querySelector(rootSelector);
6648
- if (!rootElement) diag.warn(PxDiagnosticKind.host, "createWebApiAnimator: No root element found for selector: " + rootSelector);
6680
+ if (!rootElement) diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootForSelector, rootSelector);
6649
6681
  } else {
6650
- diag.warn(PxDiagnosticKind.host, "createWebApiAnimator: No root element provided");
6682
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noRootElement);
6651
6683
  }
6652
6684
  }
6653
6685
  const bindings = normalizeBindings(doc, PxTimelineEngine.native);
@@ -6660,18 +6692,18 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6660
6692
  let finishNotified = false;
6661
6693
  let removeCalled = false;
6662
6694
  if (!(bindings == null ? void 0 : bindings.length)) {
6663
- diag.warn(PxDiagnosticKind.document, "createWebApiAnimator: No animation bindings defined");
6695
+ diag.warn(PxDiagnosticKind.document, PxDiagnosticCode.noBindings);
6664
6696
  }
6665
6697
  for (const binding of bindings || []) {
6666
6698
  const animDef = binding.animate;
6667
6699
  if (!animDef || typeof animDef !== "object" || Array.isArray(animDef)) {
6668
- diag.warn(PxDiagnosticKind.document, "createWebApiAnimator: Empty or unresolved binding", binding);
6700
+ diag.warn(PxDiagnosticKind.document, PxDiagnosticCode.unresolvedBinding, binding);
6669
6701
  continue;
6670
6702
  }
6671
6703
  const selector = getSelector(binding.id);
6672
6704
  const elements = (rootElement == null ? void 0 : rootElement.querySelectorAll(selector)) || document.querySelectorAll(selector);
6673
6705
  if (elements.length === 0) {
6674
- diag.warn(PxDiagnosticKind.host, 'createWebApiAnimator: No elements found for selector "' + selector + '"');
6706
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.noElementsForSelector, selector);
6675
6707
  }
6676
6708
  const keyframesMap = convertToWebApiKeyframes(animDef, unsupportedSet, config);
6677
6709
  const positiveDelay = config.delay && config.delay > 0 ? config.delay : void 0;
@@ -6720,14 +6752,14 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6720
6752
  }
6721
6753
  animations.push(anim);
6722
6754
  } catch (e) {
6723
- diag.warn(PxDiagnosticKind.internal, "createWebApiAnimator: could not build the animation", e);
6755
+ diag.warn(PxDiagnosticKind.internal, PxDiagnosticCode.animationBuildFailed, e);
6724
6756
  }
6725
6757
  }
6726
6758
  }
6727
6759
  }
6728
6760
  }
6729
6761
  if (!forceEvenIfHasUnsupportedAttrs && unsupportedSet.size) {
6730
- diag.warn(PxDiagnosticKind.platform, "Unsupported CSS attrs: " + [...unsupportedSet].join(", "));
6762
+ diag.warn(PxDiagnosticKind.platform, PxDiagnosticCode.unsupportedAnimatedAttrs, [...unsupportedSet].join(", "));
6731
6763
  return null;
6732
6764
  }
6733
6765
  const api = {
@@ -6772,7 +6804,7 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6772
6804
  },
6773
6805
  "setPlaybackRate": (rate) => {
6774
6806
  if (!isValidPlaybackRate(rate)) {
6775
- diag.warn(PxDiagnosticKind.usage, PX_RATE_REJECTED);
6807
+ diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.rateRejected);
6776
6808
  return api;
6777
6809
  }
6778
6810
  animations.forEach((a) => a.playbackRate = rate);
@@ -6812,7 +6844,7 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
6812
6844
  }
6813
6845
  };
6814
6846
  if (config.timelineSource === "scroll") {
6815
- if (config.trigger) diag.warn(PxDiagnosticKind.usage, "scroll timeline: `animator.trigger` is ignored (triggers do not apply to scroll-driven playback)");
6847
+ if (config.trigger) diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.scrollTriggerIgnored);
6816
6848
  } else {
6817
6849
  const detachTriggers = setupAnimationTriggers(api, (_b = config.trigger) != null ? _b : {}, diag);
6818
6850
  const destroyEngine = api.destroy.bind(api);
@@ -6842,7 +6874,7 @@ function createNativeScrollTimeline(subject, config, diag) {
6842
6874
  const scroll = config.scroll || {};
6843
6875
  const kind = (_a2 = scroll.kind) != null ? _a2 : "view";
6844
6876
  if (scroll.smoothing) {
6845
- report.warn(PxDiagnosticKind.platform, "scroll timeline: `smoothing` needs the built-in driver \u2014 using the built-in driver instead of the browser timeline");
6877
+ report.warn(PxDiagnosticKind.platform, PxDiagnosticCode.scrollSmoothingNeedsOwnDriver);
6846
6878
  return null;
6847
6879
  }
6848
6880
  const g = globalThis;
@@ -6859,7 +6891,7 @@ function createNativeScrollTimeline(subject, config, diag) {
6859
6891
  timeline = new Ctor({ source, axis });
6860
6892
  }
6861
6893
  } catch (e) {
6862
- report.warn(PxDiagnosticKind.platform, "scroll timeline: native timeline construction failed \u2014 falling back to the player measuring progress itself", e);
6894
+ report.warn(PxDiagnosticKind.platform, PxDiagnosticCode.scrollNativeUnavailable, e);
6863
6895
  return null;
6864
6896
  }
6865
6897
  return {
@@ -6906,11 +6938,11 @@ function resolveScrollSubject(svgRoot, subject, diag) {
6906
6938
  try {
6907
6939
  found = document.querySelector(spec);
6908
6940
  } catch (e) {
6909
- report.warn(PxDiagnosticKind.document, 'scroll timeline: subject "' + spec + '" is not a valid selector \u2014 measuring the SVG itself');
6941
+ report.warn(PxDiagnosticKind.document, PxDiagnosticCode.scrollSubjectInvalid, spec);
6910
6942
  return svgRoot;
6911
6943
  }
6912
6944
  if (!found) {
6913
- report.warn(PxDiagnosticKind.host, 'scroll timeline: subject "' + spec + '" matched no element \u2014 measuring the SVG itself');
6945
+ report.warn(PxDiagnosticKind.host, PxDiagnosticCode.scrollSubjectNoMatch, spec);
6914
6946
  return svgRoot;
6915
6947
  }
6916
6948
  return found;
@@ -7152,7 +7184,7 @@ function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
7152
7184
  };
7153
7185
  }
7154
7186
  } else {
7155
- diag.warn(PxDiagnosticKind.host, "scroll timeline: no root element to observe \u2014 animation will stay at frame 0");
7187
+ diag.warn(PxDiagnosticKind.host, PxDiagnosticCode.scrollNoRootToObserve);
7156
7188
  }
7157
7189
  return api;
7158
7190
  });
@@ -7174,7 +7206,7 @@ function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
7174
7206
  var SVG_NS = "http://www.w3.org/2000/svg";
7175
7207
  function createElement(tagName, normalizedProps, style, children, textContent, diag) {
7176
7208
  if (PX_DISALLOWED_SVG_TAGS_LOWER.has(tagName.toLowerCase())) {
7177
- (diag != null ? diag : createDiagnostics(void 0, "[PxAnimator]")).warn(PxDiagnosticKind.document, "SVG tag blocked (dangerous): " + tagName);
7209
+ (diag != null ? diag : createDiagnostics(void 0, "[PxAnimator]")).warn(PxDiagnosticKind.document, PxDiagnosticCode.blockedTag, tagName);
7178
7210
  return null;
7179
7211
  }
7180
7212
  const element = document.createElementNS(SVG_NS, tagName);
@@ -7237,11 +7269,11 @@ function createAnimatorFromConfig(doc, adapter, callbacks, rootElement) {
7237
7269
  function createAnimatorImpl(doc, adapter, callbacks, containerElement, patch, resetTimeline) {
7238
7270
  const diag = createDiagnostics(callbacks, "[PxAnimator]");
7239
7271
  const effectsWarnings = validateNodeEffects(doc);
7240
- for (const w of effectsWarnings) diag.warn(PxDiagnosticKind.document, "effects shape: " + w);
7272
+ for (const w of effectsWarnings) diag.warn(PxDiagnosticKind.document, PxDiagnosticCode.effectsShape, w);
7241
7273
  reportDocumentDiagnostics(doc, "[PxAnimator] createAnimator");
7242
7274
  if (patch !== void 0 || resetTimeline) {
7243
7275
  const patched = applyAnimatorConfig(doc, patch != null ? patch : {}, { resetTimeline: !!resetTimeline });
7244
- for (const w of patched.warnings) diag.warn(PxDiagnosticKind.usage, "timeline override: " + w);
7276
+ for (const w of patched.warnings) diag.warn(PxDiagnosticKind.usage, PxDiagnosticCode.timelineOverrideIgnored, w);
7245
7277
  doc = patched.doc;
7246
7278
  }
7247
7279
  const animatorConfig = getAnimatorConfig(doc) || {};
@@ -7304,16 +7336,16 @@ function createAnimator(options) {
7304
7336
  pending = null;
7305
7337
  queued == null ? void 0 : queued.forEach((call) => call(api));
7306
7338
  };
7307
- const failed = (kind, message, detail) => {
7339
+ const failed = (kind, code, ...data) => {
7308
7340
  pending = null;
7309
- diag.error(kind, message, detail);
7341
+ diag.error(kind, code, ...data);
7310
7342
  };
7311
7343
  const build = (document2) => {
7312
7344
  try {
7313
7345
  ready(createAnimatorImpl(document2, adapter, callbacks, container, patch, resetTimeline));
7314
7346
  } catch (e) {
7315
7347
  const err = asThrownError(e);
7316
- failed(PxDiagnosticKind.internal, "createAnimator: could not build the player \u2014 " + err.message, err);
7348
+ failed(PxDiagnosticKind.internal, PxDiagnosticCode.buildFailed, err);
7317
7349
  }
7318
7350
  };
7319
7351
  if (doc !== void 0) {
@@ -7322,10 +7354,10 @@ function createAnimator(options) {
7322
7354
  fetch(src).then((res) => res.json()).then((json) => {
7323
7355
  if (destroyed) return;
7324
7356
  if (isPxDocument(json)) build(json);
7325
- else failed(PxDiagnosticKind.document, 'createAnimator: invalid animation document format at "' + src + '"');
7357
+ else failed(PxDiagnosticKind.document, PxDiagnosticCode.invalidDocumentAtSrc, src);
7326
7358
  }).catch((err) => {
7327
7359
  var _a2;
7328
- failed(PxDiagnosticKind.host, 'createAnimator: failed to load "' + src + '" \u2014 ' + ((_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err)));
7360
+ failed(PxDiagnosticKind.host, PxDiagnosticCode.loadFailed, src, (_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err));
7329
7361
  });
7330
7362
  }
7331
7363
  return {