@pixodesk/svg-animator-web 1.0.35 → 1.0.40

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/README.md CHANGED
@@ -63,11 +63,11 @@ import { createAnimator } from '@pixodesk/svg-animator-web';
63
63
  const animator = createAnimator({
64
64
  src: '/animation.json',
65
65
  container: '#container',
66
- callbacks: { onFinish: () => console.log('done') },
66
+ onFinish: () => console.log('done'),
67
67
  });
68
68
 
69
69
  // Or from an already-loaded document object
70
- const fromObject = createAnimator({ data: animationDoc, container: '#container' });
70
+ const fromObject = createAnimator({ doc: animationDoc, container: '#container' });
71
71
 
72
72
  animator.play();
73
73
  animator.pause();
@@ -81,20 +81,20 @@ animator.destroy(); // cleanup
81
81
 
82
82
  `createAnimator(options)` takes a single options object:
83
83
 
84
+ <!-- px-check props PxAnimatorOptions pkg=web -->
84
85
  | Option | Type | Description |
85
86
  | ----------- | ------------------------- | -------------------------------------------------- |
86
- | `src` | `string` | URL to fetch the animation document from (provide either `src` or `data`) |
87
- | `data` | `PxAnimatedSvgDocument` | Inline animation document object |
87
+ | `src` | `string` | URL to fetch the animation document from (provide either `src` or `doc`) |
88
+ | `doc` | `PxAnimatedSvgDocument` | Inline animation document object |
88
89
  | `container` | `string \| Element` | CSS selector or element to render the SVG into |
89
- | `callbacks` | `PxAnimatorCallbacksConfig` | Lifecycle callbacks (see below) |
90
- | `adapter` | `PxPlatformAdapter` | Custom attribute-writer for frame-loop rendering (advanced) |
91
- | `config` | `object \| string` | Per-instance playback override, deep-merged over the document's `animator` block — same shape as the file; `null` at a slot deletes that key. A JSON string is accepted too |
92
- | `resetDocDefaults` | `boolean` | Ignore the document's playback settings and start from the player's defaults, with `config` on top |
93
- | `duration` · `delay` | `number` | Shortcuts for `config.timeline.duration` / `.delay` (ms) |
94
- | `iterations` | `number \| 'infinite'` | Shortcut for `config.timeline.iterations` |
95
- | `startOn` | `StartOn` | Shortcut for `config.timeline.trigger.startOn` |
96
-
97
- The document plays the way it was designed with no configuration at all; `config` is for when
90
+ | `onPlay` · `onPause` · `onCancel` · `onFinish` · `onRemove` · `onStop` | `() => void` | the lifecycle callbacks, inline — the same names the components take; plus `onWarn`, `onError`, `muteWarn`, `muteError` for diagnostics. See [Callbacks](#callbacks) | <!-- px names=onPlay,onPause,onCancel,onFinish,onRemove,onStop,onWarn,onError,muteWarn,muteError -->
91
+ | `timeline` | `object \| string` | per-instance override of the document's `timeline` block, deep-merged over it — same shape as the file; `null` at any slot deletes that key. A JSON string is accepted too. See [Playback overrides](#playback-overrides) |
92
+ | `resetTimeline` | `boolean` | ignore the document's own timeline and start from the player's default timeline, with `timeline` on top |
93
+ | `duration` · `delay` | `number` | Shortcuts for `timeline.duration` / `.delay` (ms) | <!-- px names=duration,delay -->
94
+ | `iterations` | `number \| 'infinite'` | Shortcut for `timeline.iterations` |
95
+ | `startOn` | `PxStartOn` | Shortcut for `timeline.trigger.startOn` |
96
+
97
+ The document plays the way it was designed with no configuration at all; `timeline` is for when
98
98
  one page needs it to play differently — the same file mounted twice at two speeds, or a file
99
99
  that autostarts everywhere except inside your own transport UI:
100
100
 
@@ -102,13 +102,14 @@ that autostarts everywhere except inside your own transport UI:
102
102
  const animator = createAnimator({
103
103
  src: '/animation.json',
104
104
  container: '#box',
105
- config: { timeline: { iterations: 'infinite', trigger: { startOn: 'programmatic' } } },
105
+ timeline: { iterations: 'infinite', trigger: { startOn: 'programmatic' } },
106
106
  });
107
107
  animator.play();
108
108
  ```
109
109
 
110
110
  It returns a `PxAnimatorAPI`:
111
111
 
112
+ <!-- px-check props PxAnimatorAPI pkg=web -->
112
113
  | Method | Description |
113
114
  | ----------------------- | ----------------------------------------------------------------- |
114
115
  | `play()` | Start or resume playback |
@@ -118,6 +119,8 @@ It returns a `PxAnimatorAPI`:
118
119
  | `setPlaybackRate(rate)` | Change speed (1 = normal, 2 = double, -1 = reverse) |
119
120
  | `getCurrentTime()` | Current time in ms |
120
121
  | `setCurrentTime(ms)` | Jump to a point in the animation, in milliseconds from its start |
122
+ | `getCurrentProgress()` | The same position as 0–1 of the whole run (`null` before ready) |
123
+ | `setCurrentProgress(p)` | Jump to 0–1 of the whole run |
121
124
  | `isPlaying()` | Whether the animation is currently playing |
122
125
  | `isReady()` | Whether the document has loaded (relevant for URL-based creation) |
123
126
  | `getRootElement()` | The rendered SVG DOM element |
@@ -127,15 +130,13 @@ It returns a `PxAnimatorAPI`:
127
130
 
128
131
  ```js
129
132
  createAnimator({
130
- data: doc,
133
+ doc: doc,
131
134
  container: '#container',
132
- callbacks: {
133
- onPlay: () => { /* started/resumed */ },
134
- onPause: () => { /* paused */ },
135
- onCancel: () => { /* cancelled */ },
136
- onFinish: () => { /* finished naturally (or via finish()) */ },
137
- onRemove: () => { /* destroyed / cleaned up */ },
138
- },
135
+ onPlay: () => { /* started/resumed */ },
136
+ onPause: () => { /* paused */ },
137
+ onCancel: () => { /* canceled */ },
138
+ onFinish: () => { /* finished naturally (or via finish()) */ },
139
+ onRemove: () => { /* destroyed / cleaned up */ },
139
140
  });
140
141
  ```
141
142
 
@@ -145,7 +146,7 @@ createAnimator({
145
146
 
146
147
  - `'auto'` (default) — the browser where it can (Web Animations API; its ScrollTimeline for scroll-driven documents), the player's frame loop where it must.
147
148
  - `'native'` — the browser only (Web Animations API).
148
- - `'js'` — the player's `requestAnimationFrame` loop only; honours `timeline.frameRate`. Required for path morphing in Safari < 18.5.
149
+ - `'js'` — the player's `requestAnimationFrame` loop only; honors `timeline.frameRate`. Required for path morphing in Safari < 18.5.
149
150
 
150
151
  ### Document format & effects
151
152
 
@@ -154,12 +155,12 @@ same shape as the JSON export. It comes in two modes:
154
155
 
155
156
  - **Self-contained document** — has `children`: the player renders the SVG tree and animates it.
156
157
  - **Bind-by-id document** — no `children`: the player animates a pre-existing SVG DOM, mapping
157
- element ids to animation specs via `animator.animateById`.
158
+ each `bindings` entry names an element (`target`, `#id`) and the named animations it plays (`animateWith`).
158
159
 
159
160
  Elements may also carry a `node.effects` bucket (structural effects such as
160
161
  `transformBy`, `repeater`, `maskedBy`, `strokeTrim`, `clone`, `fillGradient` /
161
- `strokeGradient`, `textPath`). This player materialises and removes them at
162
- runtime before any other normalisation.
162
+ `strokeGradient`, `textPath`). This player materializes and removes them at
163
+ runtime before any other normalization.
163
164
 
164
165
  See the [JSON format reference](../../docs/format/README.md#json-format-reference) and
165
166
  [Player effects](../../docs/format/README.md#player-effects) for the full schema and
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,r=Object.defineProperties,t=Object.getOwnPropertyDescriptors,o=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,n=(r,t,o)=>t in r?e(r,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[t]=o,c=(e,r)=>{for(var t in r||(r={}))a.call(r,t)&&n(e,t,r[t]);if(o)for(var t of o(r))l.call(r,t)&&n(e,t,r[t]);return e},f=(e,o)=>r(e,t(o)),i=(e,r)=>{var t={};for(var n in e)a.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&o)for(var n of o(e))r.indexOf(n)<0&&l.call(e,n)&&(t[n]=e[n]);return t},p="doc";export{c as __spreadValues,f as __spreadProps,i as __objRest,p as PX_ANIMATOR_DOC_KEY};
@@ -0,0 +1,42 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/shared/PxAnimatorKeys.ts
34
+ var PX_ANIMATOR_DOC_KEY = "doc";
35
+
36
+ export {
37
+ __spreadValues,
38
+ __spreadProps,
39
+ __objRest,
40
+ PX_ANIMATOR_DOC_KEY
41
+ };
42
+ //# sourceMappingURL=chunk-TNWZIIVG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/PxAnimatorKeys.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------\n * Copyright (c) Pixodesk LTD.\n * Licensed under the MIT License. See the LICENSE file in the project root for details.\n *---------------------------------------------------------------------------------------*/\n\n/**\n * Wire keys shared by every entry point.\n *\n * These live here rather than in `PxAnimator.ts` on purpose: that module used to end with a\n * top-level `if (typeof window !== 'undefined')` block publishing `createAnimator` /\n * `loadTagAnimators` as globals. A module-level side effect cannot be tree-shaken, so\n * importing ANY symbol from `PxAnimator.ts` pulled the entire full player in with it —\n * which silently made the pre-rendered builds the same size as the full one until this\n * constant was moved out. See PRERENDERED-PLAYER-BUILDS.md.\n *\n * That block is gone (API review §4) and the package now declares `\"sideEffects\": false`, but\n * keeping these here costs nothing and removes the trap for good.\n */\n\n/**\n * Key under which `createAnimator` options carry the inline animation document. The editor\n * writes it into every exported SVG+JS — `createAnimator({\"doc\": …})` — so it is part of the\n * export format, which is why it is a named constant and not a literal.\n * @internal\n */\nexport const PX_ANIMATOR_DOC_KEY = 'doc';\n\n/** Key under which `createAnimator` options carry the per-instance `timeline` override. */\nexport const PX_ANIMATOR_TIMELINE_KEY = 'timeline';\n\n/** Key that makes the override start from the player's default timeline instead of the document's. */\nexport const PX_ANIMATOR_RESET_KEY = 'resetTimeline';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,IAAM,sBAAsB;","names":[]}