@pixodesk/svg-animator-web 1.0.44 → 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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PxAnimatorApi } from './PxAnimator-yjuSFhQw.cjs';
2
- export { a as PxAnimatorOptions, b as PxPlaybackApi, c as PxTagAnimatorOptions, d as createAnimator, l as loadTagAnimators } from './PxAnimator-yjuSFhQw.cjs';
1
+ import { P as PxAnimatorApi } from './PxAnimator-BS-SZULN.cjs';
2
+ export { a as PxAnimatorOptions, b as PxPlaybackApi, c as PxTagAnimatorOptions, d as createAnimator, l as loadTagAnimators } from './PxAnimator-BS-SZULN.cjs';
3
3
  import { PxAnimatorCallbacks, PxAnimatedSvgDocument, PxTrigger, PxDiagnostics, PxNode, PxDefinitions } from '@pixodesk/svg-animator-core';
4
4
  export { PxAnimatedSvgDocument, PxAnimatorCallbacks, PxAnimatorConfig, PxAnimatorConfigSchema, PxBinding, PxDefinitions, PxDefinitionsSchema, PxDiagnostic, PxDiagnosticKind, PxDiagnostics, PxDiagnosticsConfig, PxEngineCallbacks, PxFillMode, PxInfer, PxNode, PxNodeBaseSchema, PxPlatformAdapter, PxPlaybackDirection, PxPlaybackOverride, PxSchema, PxScrollSchema, PxSvgNode, PxSvgNodeRootSchema, PxTimelineEngineSetting, PxTimelinePatch, PxTrigger, PxTriggerSchema, PxTriggerStart, PxValidationContext, createAdapterAnimator, generateNewIds, px, toDomProps, validateDocument } from '@pixodesk/svg-animator-core';
5
5
 
@@ -84,6 +84,6 @@ declare function onAnimatorsChange(listener: PxAnimatorsListener): () => void;
84
84
  * Renders a PxNode tree to DOM elements.
85
85
  * @public @advanced
86
86
  */
87
- declare function renderNode(node: PxNode, defs?: PxDefinitions, diag?: PxDiagnostics): Element | null;
87
+ declare function renderNode(node: PxNode, _defs?: PxDefinitions, diag?: PxDiagnostics): Element | null;
88
88
 
89
89
  export { PxAnimatorApi, type PxAnimatorRegistry, type PxAnimatorsEvent, type PxAnimatorsListener, type PxPrerenderedAnimatorOptions, getAllAnimators, onAnimatorsChange, renderNode, setupAnimationTriggers };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PxAnimatorApi } from './PxAnimator-yjuSFhQw.js';
2
- export { a as PxAnimatorOptions, b as PxPlaybackApi, c as PxTagAnimatorOptions, d as createAnimator, l as loadTagAnimators } from './PxAnimator-yjuSFhQw.js';
1
+ import { P as PxAnimatorApi } from './PxAnimator-BS-SZULN.js';
2
+ export { a as PxAnimatorOptions, b as PxPlaybackApi, c as PxTagAnimatorOptions, d as createAnimator, l as loadTagAnimators } from './PxAnimator-BS-SZULN.js';
3
3
  import { PxAnimatorCallbacks, PxAnimatedSvgDocument, PxTrigger, PxDiagnostics, PxNode, PxDefinitions } from '@pixodesk/svg-animator-core';
4
4
  export { PxAnimatedSvgDocument, PxAnimatorCallbacks, PxAnimatorConfig, PxAnimatorConfigSchema, PxBinding, PxDefinitions, PxDefinitionsSchema, PxDiagnostic, PxDiagnosticKind, PxDiagnostics, PxDiagnosticsConfig, PxEngineCallbacks, PxFillMode, PxInfer, PxNode, PxNodeBaseSchema, PxPlatformAdapter, PxPlaybackDirection, PxPlaybackOverride, PxSchema, PxScrollSchema, PxSvgNode, PxSvgNodeRootSchema, PxTimelineEngineSetting, PxTimelinePatch, PxTrigger, PxTriggerSchema, PxTriggerStart, PxValidationContext, createAdapterAnimator, generateNewIds, px, toDomProps, validateDocument } from '@pixodesk/svg-animator-core';
5
5
 
@@ -84,6 +84,6 @@ declare function onAnimatorsChange(listener: PxAnimatorsListener): () => void;
84
84
  * Renders a PxNode tree to DOM elements.
85
85
  * @public @advanced
86
86
  */
87
- declare function renderNode(node: PxNode, defs?: PxDefinitions, diag?: PxDiagnostics): Element | null;
87
+ declare function renderNode(node: PxNode, _defs?: PxDefinitions, diag?: PxDiagnostics): Element | null;
88
88
 
89
89
  export { PxAnimatorApi, type PxAnimatorRegistry, type PxAnimatorsEvent, type PxAnimatorsListener, type PxPrerenderedAnimatorOptions, getAllAnimators, onAnimatorsChange, renderNode, setupAnimationTriggers };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  PX_COLOR_ATTR_NAMES,
5
5
  PX_CSS_ONLY_STYLE_PROPS,
6
6
  PX_DEFAULT_DURATION_MS,
7
+ PX_DEFAULT_ITERATIONS,
7
8
  PX_DISALLOWED_SVG_TAGS_LOWER,
8
9
  PX_PCT_BASED_ATTR_NAMES,
9
10
  PX_STYLE_ATTR_NAMES,
@@ -37,7 +38,6 @@ import {
37
38
  foldTimelineOverride,
38
39
  generateNewIds,
39
40
  getAnimatorConfig,
40
- getDefinitions,
41
41
  interpolateValue,
42
42
  isNativeForced,
43
43
  isPxDocument,
@@ -61,9 +61,53 @@ import {
61
61
  toRGBA,
62
62
  validateDocument,
63
63
  validateNodeEffects
64
- } from "./chunk-ZEMEZT7X.js";
64
+ } from "./chunk-ZBGGXE5W.js";
65
65
 
66
66
  // ../svg-animator-core/dist/internal.js
67
+ var CLASS_NAME_KEY = "className";
68
+ var CLASS_ATTR = "class";
69
+ var DOM_TYPE_KEY = "domType";
70
+ var TYPE_ATTR = "type";
71
+ var DEFAULT_TAG = "g";
72
+ function renderPxTree(node, factory, diag) {
73
+ return node ? renderOne(node, factory, diag, true, 0) : null;
74
+ }
75
+ function renderOne(node, factory, diag, isRoot, index) {
76
+ const _a = node, { type, children, style } = _a, props = __objRest(_a, ["type", "children", "style"]);
77
+ const tag = type || DEFAULT_TAG;
78
+ if (PX_DISALLOWED_SVG_TAGS_LOWER.has(tag.toLowerCase())) {
79
+ (diag != null ? diag : createDiagnostics(void 0, "[PxAnimator]")).warn(PxDiagnosticKind.document, 1103, tag);
80
+ return null;
81
+ }
82
+ const domType = props[DOM_TYPE_KEY];
83
+ if (domType !== void 0) delete props[DOM_TYPE_KEY];
84
+ const attrs = {};
85
+ let inlineStyle;
86
+ const domProps = toDomProps(props);
87
+ for (const propName of Object.keys(domProps)) {
88
+ const sanitized = sanitizeAttributeValue(propName, domProps[propName]);
89
+ if (sanitized === void 0) continue;
90
+ if (PX_CSS_ONLY_STYLE_PROPS.has(propName)) {
91
+ (inlineStyle != null ? inlineStyle : inlineStyle = {})[propName] = String(sanitized);
92
+ continue;
93
+ }
94
+ attrs[propName === CLASS_NAME_KEY ? CLASS_ATTR : camelCaseToKebabWordIfNeeded(propName)] = sanitized;
95
+ }
96
+ if (domType !== void 0) attrs[TYPE_ATTR] = String(domType);
97
+ if (style) {
98
+ for (const styleProp of Object.keys(style)) (inlineStyle != null ? inlineStyle : inlineStyle = {})[styleProp] = String(style[styleProp]);
99
+ }
100
+ const rendered = [];
101
+ if (children) {
102
+ children.forEach((child, i) => {
103
+ const el = renderOne(child, factory, diag, false, i);
104
+ if (el !== null) rendered.push(el);
105
+ });
106
+ }
107
+ const ownText = props[PX_TEXT_CONTENT_ATTR];
108
+ const text = !rendered.length && typeof ownText === "string" && ownText ? ownText : void 0;
109
+ return factory({ tag, attrs, style: inlineStyle, children: rendered, text, node, isRoot, index });
110
+ }
67
111
  function isScrollTimeline(config) {
68
112
  return (config == null ? void 0 : config.timelineSource) === "scroll";
69
113
  }
@@ -521,7 +565,7 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
521
565
  let seekPosition;
522
566
  if (config.delay && config.delay < 0 && config.duration) {
523
567
  const rawSeek = -config.delay;
524
- seekPosition = iterations === Infinity ? rawSeek % config.duration : Math.min(rawSeek, config.duration * (iterations != null ? iterations : 1));
568
+ seekPosition = iterations === Infinity ? rawSeek % config.duration : Math.min(rawSeek, config.duration * (iterations != null ? iterations : PX_DEFAULT_ITERATIONS));
525
569
  }
526
570
  const effectOptions = {
527
571
  duration: config.duration,
@@ -628,7 +672,7 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
628
672
  },
629
673
  "setCurrentTime": (time) => {
630
674
  var _a2;
631
- const ceiling = seekCeilingMs((_a2 = config.duration) != null ? _a2 : 0, iterations != null ? iterations : 1);
675
+ const ceiling = seekCeilingMs((_a2 = config.duration) != null ? _a2 : 0, iterations != null ? iterations : PX_DEFAULT_ITERATIONS);
632
676
  const seek = ceiling > 0 ? clampSeekMs(time, ceiling) : Math.max(0, time);
633
677
  finishNotified = false;
634
678
  animations.forEach((a) => {
@@ -638,11 +682,11 @@ function createWebApiAnimator(doc, callbacks, rootElement, forceEvenIfHasUnsuppo
638
682
  "getCurrentProgress": () => {
639
683
  var _a2;
640
684
  const t = api.getCurrentTime();
641
- return t === null ? null : timeToProgress(t, (_a2 = config.duration) != null ? _a2 : 0, iterations != null ? iterations : 1);
685
+ return t === null ? null : timeToProgress(t, (_a2 = config.duration) != null ? _a2 : 0, iterations != null ? iterations : PX_DEFAULT_ITERATIONS);
642
686
  },
643
687
  "setCurrentProgress": (progress) => {
644
688
  var _a2;
645
- api.setCurrentTime(progressToTimeMs(progress, (_a2 = config.duration) != null ? _a2 : 0, iterations != null ? iterations : 1));
689
+ api.setCurrentTime(progressToTimeMs(progress, (_a2 = config.duration) != null ? _a2 : 0, iterations != null ? iterations : PX_DEFAULT_ITERATIONS));
646
690
  },
647
691
  "destroy": () => {
648
692
  var _a2;
@@ -1015,69 +1059,26 @@ function bindWithEngineChoice(doc, adapter, callbacks, rootElement) {
1015
1059
 
1016
1060
  // src/dom/PxAnimatorDOM.ts
1017
1061
  var SVG_NS = "http://www.w3.org/2000/svg";
1018
- function createElement(tagName, normalizedProps, style, children, textContent, diag) {
1019
- if (PX_DISALLOWED_SVG_TAGS_LOWER.has(tagName.toLowerCase())) {
1020
- (diag != null ? diag : createDiagnostics(void 0, "[PxAnimator]")).warn(PxDiagnosticKind.document, PxDiagnosticCode.blockedTag, tagName);
1021
- return null;
1022
- }
1023
- const element = document.createElementNS(SVG_NS, tagName);
1024
- for (const propName in normalizedProps) {
1025
- const sanitized = sanitizeAttributeValue(propName, normalizedProps[propName]);
1026
- if (sanitized === void 0) continue;
1027
- if (PX_CSS_ONLY_STYLE_PROPS.has(propName)) {
1028
- element.style[propName] = String(sanitized);
1029
- continue;
1030
- }
1031
- element.setAttribute(camelCaseToKebabWordIfNeeded(propName), sanitized);
1032
- }
1062
+ var createDomElement = ({ tag, attrs, style, children, text }) => {
1063
+ const element = document.createElementNS(SVG_NS, tag);
1064
+ for (const name of Object.keys(attrs)) element.setAttribute(name, attrs[name]);
1033
1065
  if (style) {
1034
- for (const styleProp in style) {
1035
- element.style[styleProp] = String(style[styleProp]);
1036
- }
1037
- }
1038
- if (children == null ? void 0 : children.length) {
1039
- for (const child of children) {
1040
- element.appendChild(child);
1041
- }
1042
- } else if (textContent) {
1043
- element.textContent = textContent;
1066
+ const target = element.style;
1067
+ for (const prop of Object.keys(style)) target[prop] = style[prop];
1044
1068
  }
1069
+ for (const child of children) element.appendChild(child);
1070
+ if (text !== void 0) element.textContent = text;
1045
1071
  return element;
1046
- }
1047
- function renderNode(node, defs, diag) {
1048
- if (!node) return null;
1049
- const _a = node, { type, children, style } = _a, props = __objRest(_a, ["type", "children", "style"]);
1050
- const domType = props.domType;
1051
- if (domType !== void 0) delete props.domType;
1052
- const nodeDefs = getDefinitions(node) || defs;
1053
- const resolvedStyle = style;
1054
- let childElements;
1055
- if (children) {
1056
- for (const ch of children) {
1057
- const child = renderNode(ch, nodeDefs, diag);
1058
- if (child) {
1059
- if (!childElements) childElements = [];
1060
- childElements.push(child);
1061
- }
1062
- }
1063
- }
1064
- const element = createElement(
1065
- type || "g",
1066
- toDomProps(props),
1067
- resolvedStyle,
1068
- childElements,
1069
- props[PX_TEXT_CONTENT_ATTR],
1070
- diag
1071
- );
1072
- if (element && domType !== void 0) element.setAttribute("type", domType);
1073
- return element;
1072
+ };
1073
+ function renderNode(node, _defs, diag) {
1074
+ return renderPxTree(node, createDomElement, diag);
1074
1075
  }
1075
1076
 
1076
1077
  // src/animator/PxAnimator.ts
1077
1078
  function createAnimatorFromConfig(doc, adapter, callbacks, rootElement) {
1078
1079
  return bindWithEngineChoice(doc, adapter, callbacks, rootElement);
1079
1080
  }
1080
- function createAnimatorImpl(doc, adapter, callbacks, containerElement, patch, resetTimeline) {
1081
+ function createAnimatorImpl(doc, adapter, callbacks, containerElement, patch, resetTimeline, providedRoot) {
1081
1082
  const diag = createDiagnostics(callbacks, "[PxAnimator]");
1082
1083
  const effectsWarnings = validateNodeEffects(doc);
1083
1084
  for (const w of effectsWarnings) diag.warn(PxDiagnosticKind.document, PxDiagnosticCode.effectsShape, w);
@@ -1101,6 +1102,7 @@ function createAnimatorImpl(doc, adapter, callbacks, containerElement, patch, re
1101
1102
  }
1102
1103
  }
1103
1104
  }
1105
+ if (!rootElement && providedRoot) rootElement = providedRoot;
1104
1106
  const api = createAnimatorFromConfig(doc, adapter, callbacks, rootElement);
1105
1107
  if (containerElement && rootElement) {
1106
1108
  const rendered = rootElement;
@@ -1113,7 +1115,7 @@ function createAnimatorImpl(doc, adapter, callbacks, containerElement, patch, re
1113
1115
  return api;
1114
1116
  }
1115
1117
  function isInternalOptions(options) {
1116
- return "adapter" in options;
1118
+ return "adapter" in options || "rootElement" in options;
1117
1119
  }
1118
1120
  function resolveTimelineOption(options) {
1119
1121
  const { timeline, duration, delay, iterations, start } = options;
@@ -1122,6 +1124,7 @@ function resolveTimelineOption(options) {
1122
1124
  function createAnimator(options) {
1123
1125
  const { src, doc, container, resetTimeline } = options;
1124
1126
  const adapter = isInternalOptions(options) ? options.adapter : void 0;
1127
+ const providedRoot = isInternalOptions(options) ? options.rootElement : void 0;
1125
1128
  const patch = resolveTimelineOption(options);
1126
1129
  let proxy;
1127
1130
  const callbacks = withRegistryEvents(toEngineCallbacks(options), () => proxy);
@@ -1154,7 +1157,7 @@ function createAnimator(options) {
1154
1157
  };
1155
1158
  const build = (document2) => {
1156
1159
  try {
1157
- ready(createAnimatorImpl(document2, adapter, callbacks, container, patch, resetTimeline));
1160
+ ready(createAnimatorImpl(document2, adapter, callbacks, container, patch, resetTimeline, providedRoot));
1158
1161
  } catch (e) {
1159
1162
  const err = asThrownError(e);
1160
1163
  failed(PxDiagnosticKind.internal, PxDiagnosticCode.buildFailed, err);