@pixodesk/svg-animator-web 1.0.19 → 1.0.20

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
@@ -56,25 +56,38 @@ Use `createAnimator` for full control:
56
56
  ```js
57
57
  import { createAnimator } from '@pixodesk/svg-animator-web';
58
58
 
59
- // From a URL — returns a proxy that queues calls until the document is fetched
60
- const animator = createAnimator('/animation.json', undefined, {
61
- onFinish: () => console.log('done'),
62
- }, '#container');
59
+ // From a URL — returns a proxy immediately; control calls made before the
60
+ // document loads are queued and replayed once it's ready
61
+ const animator = createAnimator({
62
+ src: '/animation.json',
63
+ container: '#container',
64
+ callbacks: { onFinish: () => console.log('done') },
65
+ });
63
66
 
64
67
  // Or from an already-loaded document object
65
- const animator = createAnimator(animationDoc, undefined, undefined, '#container');
68
+ const animator = createAnimator({ data: animationDoc, container: '#container' });
66
69
 
67
70
  animator.play();
68
71
  animator.pause();
69
72
  animator.setCurrentTime(500); // seek to 500ms
70
- animator.setPlaybackRate(2); // 2x speed
73
+ animator.setPlaybackRate(2); // 2x speed (-1 plays in reverse)
71
74
  animator.finish(); // jump to end
72
75
  animator.destroy(); // cleanup
73
76
  ```
74
77
 
75
78
  ### API
76
79
 
77
- `createAnimator(docOrUrl, adapter?, callbacks?, containerElement?)` returns a `PxAnimatorAPI`:
80
+ `createAnimator(options)` takes a single options object:
81
+
82
+ | Option | Type | Description |
83
+ | ----------- | ------------------------- | -------------------------------------------------- |
84
+ | `src` | `string` | URL to fetch the animation document from (provide either `src` or `data`) |
85
+ | `data` | `PxAnimatedSvgDocument` | Inline animation document object |
86
+ | `container` | `string \| Element` | CSS selector or element to render the SVG into |
87
+ | `callbacks` | `PxAnimatorCallbacksConfig` | Lifecycle callbacks (see below) |
88
+ | `adapter` | `PxPlatformAdapter` | Custom attribute-writer for frame-loop rendering (advanced) |
89
+
90
+ It returns a `PxAnimatorAPI`:
78
91
 
79
92
  | Method | Description |
80
93
  | ----------------------- | ----------------------------------------------------------------- |
@@ -93,13 +106,17 @@ animator.destroy(); // cleanup
93
106
  ### Callbacks
94
107
 
95
108
  ```js
96
- createAnimator(doc, undefined, {
97
- onPlay: () => { /* started/resumed */ },
98
- onPause: () => { /* paused */ },
99
- onCancel: () => { /* cancelled */ },
100
- onFinish: () => { /* finished */ },
101
- onRemove: () => { /* cleaned up */ },
102
- }, '#container');
109
+ createAnimator({
110
+ data: doc,
111
+ container: '#container',
112
+ callbacks: {
113
+ onPlay: () => { /* started/resumed */ },
114
+ onPause: () => { /* paused */ },
115
+ onCancel: () => { /* cancelled */ },
116
+ onFinish: () => { /* finished naturally (or via finish()) */ },
117
+ onRemove: () => { /* destroyed / cleaned up */ },
118
+ },
119
+ });
103
120
  ```
104
121
 
105
122
  ### Engine modes