@pixodesk/svg-animator-web 1.0.35 → 1.0.39

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,21 @@ 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
+ | `onPlay` · `onPause` · `onCancel` · `onFinish` · `onRemove` · `onStop` | `() => void` | the lifecycle callbacks, inline — the same names the components take; plus `onWarn`, `onError`, `silent` for diagnostics. See [Callbacks](#callbacks) | <!-- px names=onPlay,onPause,onCancel,onFinish,onRemove,onStop,onWarn,onError,silent -->
90
91
  | `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` |
92
+ | `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) |
93
+ | `resetTimeline` | `boolean` | ignore the document's own timeline and start from the player's default timeline, with `timeline` on top |
94
+ | `duration` · `delay` | `number` | Shortcuts for `timeline.duration` / `.delay` (ms) | <!-- px names=duration,delay -->
95
+ | `iterations` | `number \| 'infinite'` | Shortcut for `timeline.iterations` |
96
+ | `startOn` | `PxStartOn` | Shortcut for `timeline.trigger.startOn` |
96
97
 
97
- The document plays the way it was designed with no configuration at all; `config` is for when
98
+ The document plays the way it was designed with no configuration at all; `timeline` is for when
98
99
  one page needs it to play differently — the same file mounted twice at two speeds, or a file
99
100
  that autostarts everywhere except inside your own transport UI:
100
101
 
@@ -102,13 +103,14 @@ that autostarts everywhere except inside your own transport UI:
102
103
  const animator = createAnimator({
103
104
  src: '/animation.json',
104
105
  container: '#box',
105
- config: { timeline: { iterations: 'infinite', trigger: { startOn: 'programmatic' } } },
106
+ timeline: { iterations: 'infinite', trigger: { startOn: 'programmatic' } },
106
107
  });
107
108
  animator.play();
108
109
  ```
109
110
 
110
111
  It returns a `PxAnimatorAPI`:
111
112
 
113
+ <!-- px-check props PxAnimatorAPI pkg=web -->
112
114
  | Method | Description |
113
115
  | ----------------------- | ----------------------------------------------------------------- |
114
116
  | `play()` | Start or resume playback |
@@ -118,6 +120,8 @@ It returns a `PxAnimatorAPI`:
118
120
  | `setPlaybackRate(rate)` | Change speed (1 = normal, 2 = double, -1 = reverse) |
119
121
  | `getCurrentTime()` | Current time in ms |
120
122
  | `setCurrentTime(ms)` | Jump to a point in the animation, in milliseconds from its start |
123
+ | `getCurrentProgress()` | The same position as 0–1 of the whole run (`null` before ready) |
124
+ | `setCurrentProgress(p)` | Jump to 0–1 of the whole run |
121
125
  | `isPlaying()` | Whether the animation is currently playing |
122
126
  | `isReady()` | Whether the document has loaded (relevant for URL-based creation) |
123
127
  | `getRootElement()` | The rendered SVG DOM element |
@@ -127,15 +131,13 @@ It returns a `PxAnimatorAPI`:
127
131
 
128
132
  ```js
129
133
  createAnimator({
130
- data: doc,
134
+ doc: doc,
131
135
  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
- },
136
+ onPlay: () => { /* started/resumed */ },
137
+ onPause: () => { /* paused */ },
138
+ onCancel: () => { /* canceled */ },
139
+ onFinish: () => { /* finished naturally (or via finish()) */ },
140
+ onRemove: () => { /* destroyed / cleaned up */ },
139
141
  });
140
142
  ```
141
143
 
@@ -145,7 +147,7 @@ createAnimator({
145
147
 
146
148
  - `'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
149
  - `'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.
150
+ - `'js'` — the player's `requestAnimationFrame` loop only; honors `timeline.frameRate`. Required for path morphing in Safari < 18.5.
149
151
 
150
152
  ### Document format & effects
151
153
 
@@ -158,8 +160,8 @@ same shape as the JSON export. It comes in two modes:
158
160
 
159
161
  Elements may also carry a `node.effects` bucket (structural effects such as
160
162
  `transformBy`, `repeater`, `maskedBy`, `strokeTrim`, `clone`, `fillGradient` /
161
- `strokeGradient`, `textPath`). This player materialises and removes them at
162
- runtime before any other normalisation.
163
+ `strokeGradient`, `textPath`). This player materializes and removes them at
164
+ runtime before any other normalization.
163
165
 
164
166
  See the [JSON format reference](../../docs/format/README.md#json-format-reference) and
165
167
  [Player effects](../../docs/format/README.md#player-effects) for the full schema and