@pixodesk/svg-animator-vue 1.0.6

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pixodesk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # animator-vue
2
+ Vue component for rendering and controlling Pixodesk SVG animations.
3
+
4
+
5
+ # 🚧 **Status - This project is currently under development.**
6
+
7
+ ## Usage
8
+
9
+ ```vue
10
+ <script setup lang="ts">
11
+ import { PixodeskSvgAnimator } from '@pixodesk/svg-animator-vue';
12
+ import animationDoc from './animation.json';
13
+ </script>
14
+ ```
15
+
16
+ ### Autoplay
17
+
18
+ Uses triggers defined in the animation document (load, click, hover, scroll):
19
+
20
+ ```vue
21
+ <template>
22
+ <PixodeskSvgAnimator :doc="animationDoc" autoplay />
23
+ </template>
24
+ ```
25
+
26
+ ### Declarative play/pause
27
+
28
+ Control playback with boolean props:
29
+
30
+ ```vue
31
+ <script setup lang="ts">
32
+ import { ref } from 'vue';
33
+ const paused = ref(false);
34
+ </script>
35
+
36
+ <template>
37
+ <PixodeskSvgAnimator :doc="animationDoc" play :pause="paused" />
38
+ <button @click="paused = !paused">Toggle</button>
39
+ </template>
40
+ ```
41
+
42
+ ### Imperative API
43
+
44
+ Use a template ref for full programmatic control:
45
+
46
+ ```vue
47
+ <script setup lang="ts">
48
+ import { ref } from 'vue';
49
+ import type { VueAnimatorApi } from '@pixodesk/svg-animator-vue';
50
+
51
+ const animator = ref<VueAnimatorApi | null>(null);
52
+ </script>
53
+
54
+ <template>
55
+ <PixodeskSvgAnimator :doc="animationDoc" ref="animator" />
56
+ <button @click="animator?.play()">Play</button>
57
+ <button @click="animator?.pause()">Pause</button>
58
+ </template>
59
+ ```
60
+
61
+ `VueAnimatorApi` methods: `play()`, `pause()`, `cancel()`, `finish()`, `isPlaying()`, `getCurrentTime()`, `setCurrentTime(ms)`.
62
+
63
+ ### Controlled time
64
+
65
+ Render a single frame at a specific point in time:
66
+
67
+ ```vue
68
+ <template>
69
+ <PixodeskSvgAnimator :doc="animationDoc" :time="0.5" />
70
+ <PixodeskSvgAnimator :doc="animationDoc" :timeMs="500" />
71
+ </template>
72
+ ```
73
+
74
+ ## Props
75
+
76
+ | Prop | Type | Description |
77
+ |---|---|---|
78
+ | `doc` | `PxAnimatedSvgDocument` | The animation document to render (required) |
79
+ | `autoplay` | `boolean` | Use triggers from the document |
80
+ | `play` | `boolean` | Start playback, ignoring document triggers |
81
+ | `pause` | `boolean` | Pause current playback |
82
+ | `time` | `number` | Seek to a fractional position |
83
+ | `timeMs` | `number` | Seek to a time in milliseconds |
84
+ | `mode` | `'auto' \| 'webapi' \| 'frames'` | Animation engine |
85
+ | `duration` | `number` | Duration override (ms) |
86
+ | `delay` | `number` | Delay before start (ms) |
87
+ | `iterations` | `number \| 'infinite'` | Loop count |
88
+ | `fill` | `FillMode` | Fill behaviour |
89
+ | `direction` | `PlaybackDirection` | Playback direction |
90
+ | `frameRate` | `number` | Target FPS |
91
+ | `startOn` | `'load' \| 'mouseOver' \| 'click' \| 'scrollIntoView' \| 'programmatic'` | Trigger event override |
92
+ | `outAction` | `'continue' \| 'pause' \| 'reset' \| 'reverse'` | Behaviour when trigger ends |
93
+
94
+ ## Events
95
+
96
+ | Event | Description |
97
+ |---|---|
98
+ | `play` | Animation started or resumed |
99
+ | `pause` | Animation paused |
100
+ | `cancel` | Animation cancelled |
101
+ | `finish` | Animation finished naturally |
102
+ | `remove` | Animation cleaned up |
package/dist/index.cjs ADDED
@@ -0,0 +1,213 @@
1
+ var Vue = window.Vue; var PixodeskAnimatorWeb = window.PixodeskAnimator;
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ PixodeskSvgAnimator: () => PixodeskSvgAnimator_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/PixodeskSvgAnimator.ts
29
+ var import_svg_animator_web = require("@pixodesk/svg-animator-web");
30
+ var import_vue = require("vue");
31
+ function createVueAdapter(elementRefs) {
32
+ const warnedSelectors = /* @__PURE__ */ new Set();
33
+ const adapter = {
34
+ isConnected: () => true,
35
+ setAttribute: (id, attrName, value) => {
36
+ attrName = (0, import_svg_animator_web.camelCaseToKebabWordIfNeeded)(attrName);
37
+ const element = elementRefs.get(id);
38
+ if (!element && !warnedSelectors.has(id)) {
39
+ warnedSelectors.add(id);
40
+ console.warn('setAttribute: No elements found for id "' + id + '"');
41
+ }
42
+ if (element) {
43
+ element.setAttribute(attrName, value);
44
+ if (import_svg_animator_web.STYLE_ATTR_NAMES.has(attrName)) {
45
+ element.style[attrName] = value;
46
+ }
47
+ }
48
+ }
49
+ };
50
+ return adapter;
51
+ }
52
+ function applyDocOverrides(doc, props, compMode) {
53
+ if (compMode !== "autoplay" /* autoplay */) {
54
+ const docStartOn = doc.animator?.trigger?.startOn;
55
+ if (docStartOn && docStartOn !== "programmatic") {
56
+ doc = {
57
+ ...doc,
58
+ animator: {
59
+ ...doc.animator,
60
+ trigger: { ...doc.animator?.trigger, startOn: "programmatic" }
61
+ }
62
+ };
63
+ }
64
+ }
65
+ const { mode, duration, delay, iterations, fill, direction, frameRate } = props;
66
+ if (mode !== void 0 || duration !== void 0 || delay !== void 0 || iterations !== void 0 || fill !== void 0 || direction !== void 0 || frameRate !== void 0) {
67
+ const animator = doc.animator || {};
68
+ doc = {
69
+ ...doc,
70
+ animator: {
71
+ ...animator,
72
+ mode: mode !== void 0 ? mode : animator.mode,
73
+ duration: duration !== void 0 ? duration : animator.duration,
74
+ delay: delay !== void 0 ? delay : animator.delay,
75
+ iterations: iterations !== void 0 ? iterations : animator.iterations,
76
+ fill: fill !== void 0 ? fill : animator.fill,
77
+ direction: direction !== void 0 ? direction : animator.direction,
78
+ frameRate: frameRate !== void 0 ? frameRate : animator.frameRate
79
+ }
80
+ };
81
+ }
82
+ const { startOn, outAction, scrollIntoViewThreshold } = props;
83
+ if (startOn !== void 0 || outAction !== void 0 || scrollIntoViewThreshold !== void 0) {
84
+ const trigger = doc.animator?.trigger || {};
85
+ doc = {
86
+ ...doc,
87
+ animator: {
88
+ ...doc.animator,
89
+ trigger: {
90
+ ...trigger,
91
+ startOn: startOn !== void 0 ? startOn : trigger.startOn,
92
+ outAction: outAction !== void 0 ? outAction : trigger.outAction,
93
+ scrollIntoViewThreshold: scrollIntoViewThreshold !== void 0 ? scrollIntoViewThreshold : trigger.scrollIntoViewThreshold
94
+ }
95
+ }
96
+ };
97
+ }
98
+ if (compMode === "fixedTime" /* fixedTime */) {
99
+ let seekDelay = 0;
100
+ if (props.time !== void 0) seekDelay = -props.time;
101
+ if (props.timeMs !== void 0) seekDelay = -props.timeMs;
102
+ const animator = doc.animator || {};
103
+ doc = { ...doc, animator: { ...animator, delay: seekDelay } };
104
+ }
105
+ return doc;
106
+ }
107
+ var PixodeskSvgAnimator = (0, import_vue.defineComponent)({
108
+ name: "PixodeskSvgAnimator",
109
+ props: {
110
+ // -- Source
111
+ doc: { type: Object, required: true },
112
+ // -- Timeline
113
+ timeline: { type: String },
114
+ // -- Rendering mode
115
+ mode: { type: String },
116
+ // -- Timing overrides
117
+ delay: { type: Number },
118
+ fill: { type: String },
119
+ iterations: { type: [Number, String] },
120
+ duration: { type: Number },
121
+ direction: { type: String },
122
+ frameRate: { type: Number },
123
+ // -- Trigger overrides
124
+ startOn: { type: String },
125
+ outAction: { type: String },
126
+ scrollIntoViewThreshold: { type: Number },
127
+ // -- Declarative control
128
+ autoplay: { type: Boolean, default: void 0 },
129
+ play: { type: Boolean, default: void 0 },
130
+ pause: { type: Boolean, default: void 0 },
131
+ // -- Controlled time
132
+ time: { type: Number },
133
+ timeMs: { type: Number }
134
+ },
135
+ emits: ["play", "stop", "pause", "cancel", "finish", "remove", "warning", "error"],
136
+ setup(props, { expose }) {
137
+ const elementRefs = /* @__PURE__ */ new Map();
138
+ const apiRef = (0, import_vue.shallowRef)(null);
139
+ const compMode = (0, import_vue.computed)(() => {
140
+ if (props.autoplay) return "autoplay" /* autoplay */;
141
+ if (props.time !== void 0 || props.timeMs !== void 0) return "fixedTime" /* fixedTime */;
142
+ if (props.play !== void 0) return "play" /* play */;
143
+ return "static" /* static */;
144
+ });
145
+ const resolvedDoc = (0, import_vue.computed)(() => {
146
+ let doc = (0, import_svg_animator_web.generateNewIds)(props.doc);
147
+ return applyDocOverrides(doc, props, compMode.value);
148
+ });
149
+ function renderNode(node) {
150
+ if (!node) return null;
151
+ const { type, animate, meta, children, ...attrs } = node;
152
+ const normProps = (0, import_svg_animator_web.getNormalizedProps)(attrs);
153
+ if (node["id"]) {
154
+ const nodeId = node["id"];
155
+ normProps["ref"] = (el) => {
156
+ if (el) {
157
+ elementRefs.set(nodeId, el);
158
+ } else {
159
+ elementRefs.delete(nodeId);
160
+ }
161
+ };
162
+ }
163
+ const childVNodes = children?.map((child) => renderNode(child)).filter(Boolean);
164
+ return (0, import_vue.h)(type, normProps, childVNodes);
165
+ }
166
+ function createApi() {
167
+ destroyApi();
168
+ const doc = resolvedDoc.value;
169
+ if (!doc) return;
170
+ apiRef.value = (0, import_svg_animator_web.createAnimator)(doc, createVueAdapter(elementRefs));
171
+ }
172
+ function destroyApi() {
173
+ apiRef.value?.destroy();
174
+ apiRef.value = null;
175
+ }
176
+ (0, import_vue.onMounted)(() => createApi());
177
+ (0, import_vue.watch)(resolvedDoc, () => createApi());
178
+ (0, import_vue.watch)([compMode, () => props.play, () => props.pause], () => {
179
+ if (compMode.value === "play" /* play */) {
180
+ if (props.play && !props.pause) {
181
+ apiRef.value?.play();
182
+ } else if (props.pause) {
183
+ apiRef.value?.pause();
184
+ } else {
185
+ apiRef.value?.finish();
186
+ }
187
+ }
188
+ });
189
+ (0, import_vue.onUnmounted)(() => {
190
+ destroyApi();
191
+ });
192
+ const publicApi = {
193
+ isPlaying: () => apiRef.value?.isPlaying() || false,
194
+ play: () => apiRef.value?.play(),
195
+ pause: () => apiRef.value?.pause(),
196
+ cancel: () => apiRef.value?.cancel(),
197
+ finish: () => apiRef.value?.finish(),
198
+ getCurrentTime: () => apiRef.value?.getCurrentTime() || null,
199
+ setCurrentTime: (time) => apiRef.value?.setCurrentTime(time)
200
+ };
201
+ expose(publicApi);
202
+ return () => {
203
+ const doc = resolvedDoc.value;
204
+ return doc ? renderNode(doc) : null;
205
+ };
206
+ }
207
+ });
208
+ var PixodeskSvgAnimator_default = PixodeskSvgAnimator;
209
+ // Annotate the CommonJS export names for ESM import in node:
210
+ 0 && (module.exports = {
211
+ PixodeskSvgAnimator
212
+ });
213
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/PixodeskSvgAnimator.ts"],"sourcesContent":["import PixodeskSvgAnimator from './PixodeskSvgAnimator';\nexport { PixodeskSvgAnimator };\nexport type { VueAnimatorApi } from './PixodeskSvgAnimator';","import type { PxAnimatedSvgDocument, PxAnimatorAPI, PxNode, PxPlatformAdapter, PxTrigger } from '@pixodesk/svg-animator-web';\nimport { camelCaseToKebabWordIfNeeded, createAnimator, FillMode, generateNewIds, getNormalizedProps, STYLE_ATTR_NAMES } from '@pixodesk/svg-animator-web';\nimport {\n computed, defineComponent, h, onMounted, onUnmounted, ref, shallowRef, type PropType, type VNode,\n watch,\n} from 'vue';\n\n\n// -- Public types -----------------------------------------------------------\n\nexport interface VueAnimatorApi {\n /** Returns true if the animation is currently running. */\n isPlaying(): boolean;\n\n /** Starts or resumes the animation. */\n play(): void;\n\n /** Pauses the animation at its current state. */\n pause(): void;\n\n /** Stops the animation and resets it to its initial state. */\n cancel(): void;\n\n /** Jumps to the end of the animation and holds the final state. */\n finish(): void;\n\n /** Returns the current playback time in milliseconds. */\n getCurrentTime(): number | null;\n\n /** Jumps to a specific time (in milliseconds) in the animation. */\n setCurrentTime(time: number): void;\n}\n\n\n// -- Internal types ---------------------------------------------------------\n\nenum CompMode {\n static = 'static',\n autoplay = 'autoplay',\n play = 'play',\n fixedTime = 'fixedTime'\n}\n\n\n// -- Vue ↔ Animator bridge --------------------------------------------------\n\n/**\n * Creates a platform adapter that routes animator attribute updates\n * to the corresponding Vue-managed DOM element refs.\n */\nfunction createVueAdapter(elementRefs: Map<string, Element>) {\n const warnedSelectors = new Set<string>();\n\n const adapter: PxPlatformAdapter = {\n isConnected: () => true,\n setAttribute: (id, attrName, value) => {\n attrName = camelCaseToKebabWordIfNeeded(attrName);\n\n const element = elementRefs.get(id);\n\n if (!element && !warnedSelectors.has(id)) {\n warnedSelectors.add(id);\n console.warn('setAttribute: No elements found for id \"' + id + '\"');\n }\n\n if (element) {\n element.setAttribute(attrName, value);\n if (STYLE_ATTR_NAMES.has(attrName)) {\n (element as HTMLElement).style[attrName as any] = value;\n }\n }\n },\n };\n return adapter;\n}\n\n// FIXME: add model validation (e.g. isElementFileJson check)\n\n\n// -- Helper: apply doc overrides --------------------------------------------\n\ninterface DocOverrideProps {\n mode?: 'webapi' | 'frames' | 'auto';\n delay?: number;\n fill?: FillMode;\n iterations?: number | 'infinite';\n duration?: number;\n direction?: PlaybackDirection;\n frameRate?: number;\n startOn?: 'load' | 'mouseOver' | 'click' | 'scrollIntoView' | 'programmatic';\n outAction?: 'continue' | 'pause' | 'reset' | 'reverse';\n scrollIntoViewThreshold?: number;\n time?: number;\n timeMs?: number;\n}\n\nfunction applyDocOverrides(\n doc: PxAnimatedSvgDocument,\n props: DocOverrideProps,\n compMode: CompMode,\n): PxAnimatedSvgDocument {\n\n // In non-autoplay modes, override the document trigger to 'programmatic'\n // so the component can manage playback itself.\n if (compMode !== CompMode.autoplay) {\n const docStartOn = doc.animator?.trigger?.startOn;\n if (docStartOn && docStartOn !== 'programmatic') { // FIXME: use enum\n doc = {\n ...doc,\n animator: {\n ...doc.animator,\n trigger: { ...doc.animator?.trigger, startOn: 'programmatic' }\n }\n };\n }\n }\n\n // Apply timing overrides from props onto the document config.\n const { mode, duration, delay, iterations, fill, direction, frameRate } = props;\n if (\n mode !== undefined || duration !== undefined || delay !== undefined ||\n iterations !== undefined || fill !== undefined || direction !== undefined ||\n frameRate !== undefined\n ) {\n const animator = doc.animator || {};\n doc = {\n ...doc,\n animator: {\n ...animator,\n mode: mode !== undefined ? mode : animator.mode,\n duration: duration !== undefined ? duration : animator.duration,\n delay: delay !== undefined ? delay : animator.delay,\n iterations: iterations !== undefined ? iterations : animator.iterations,\n fill: fill !== undefined ? fill : animator.fill,\n direction: direction !== undefined ? direction : animator.direction,\n frameRate: frameRate !== undefined ? frameRate : animator.frameRate,\n }\n };\n }\n\n // Apply trigger overrides from props.\n const { startOn, outAction, scrollIntoViewThreshold } = props;\n if (startOn !== undefined || outAction !== undefined || scrollIntoViewThreshold !== undefined) {\n const trigger: PxTrigger = doc.animator?.trigger || {};\n doc = {\n ...doc,\n animator: {\n ...doc.animator,\n trigger: {\n ...trigger,\n startOn: startOn !== undefined ? startOn : trigger.startOn,\n outAction: outAction !== undefined ? outAction : trigger.outAction,\n scrollIntoViewThreshold: scrollIntoViewThreshold !== undefined ? scrollIntoViewThreshold : trigger.scrollIntoViewThreshold,\n }\n }\n };\n }\n\n // In controlled-time mode, use a negative delay to seek to the given frame.\n if (compMode === CompMode.fixedTime) {\n let seekDelay = 0;\n if (props.time !== undefined) seekDelay = -props.time; // FIXME: time as a fraction of total duration?\n if (props.timeMs !== undefined) seekDelay = -props.timeMs;\n const animator = doc.animator || {};\n doc = { ...doc, animator: { ...animator, delay: seekDelay } };\n }\n\n return doc;\n}\n\n\n// -- Main public component --------------------------------------------------\n\n/**\n * Vue component for rendering and controlling Pixodesk SVG animations.\n *\n * Supports four mutually-exclusive control modes:\n *\n * 1. **Autoplay** – uses triggers from the animation document.\n * ```vue\n * <PixodeskSvgAnimator :doc=\"animation\" autoplay />\n * ```\n *\n * 2. **Declarative play/pause** – controlled via boolean props.\n * ```vue\n * <PixodeskSvgAnimator :doc=\"animation\" play :pause=\"false\" />\n * ```\n *\n * 3. **Imperative** – exposes a ref-based API for full programmatic control.\n * ```vue\n * <PixodeskSvgAnimator :doc=\"animation\" ref=\"animator\" />\n * <button @click=\"$refs.animator.play()\">Play</button>\n * ```\n *\n * 4. **Controlled time** – renders a single frame at a given time.\n * ```vue\n * <PixodeskSvgAnimator :doc=\"animation\" :time=\"0.5\" />\n * <PixodeskSvgAnimator :doc=\"animation\" :timeMs=\"500\" />\n * ```\n */\nconst PixodeskSvgAnimator = defineComponent({\n name: 'PixodeskSvgAnimator',\n\n props: {\n // -- Source\n doc: { type: Object as PropType<PxAnimatedSvgDocument>, required: true },\n\n // -- Timeline\n timeline: { type: String as PropType<'time' | 'scroll'> },\n\n // -- Rendering mode\n mode: { type: String as PropType<'webapi' | 'frames' | 'auto'> },\n\n // -- Timing overrides\n delay: { type: Number },\n fill: { type: String as PropType<FillMode> },\n iterations: { type: [Number, String] as PropType<number | 'infinite'> },\n duration: { type: Number },\n direction: { type: String as PropType<PlaybackDirection> },\n frameRate: { type: Number },\n\n // -- Trigger overrides\n startOn: { type: String as PropType<'load' | 'mouseOver' | 'click' | 'scrollIntoView' | 'programmatic'> },\n outAction: { type: String as PropType<'continue' | 'pause' | 'reset' | 'reverse'> },\n scrollIntoViewThreshold: { type: Number },\n\n // -- Declarative control\n autoplay: { type: Boolean, default: undefined },\n play: { type: Boolean, default: undefined },\n pause: { type: Boolean, default: undefined },\n\n // -- Controlled time\n time: { type: Number },\n timeMs: { type: Number },\n },\n\n emits: ['play', 'stop', 'pause', 'cancel', 'finish', 'remove', 'warning', 'error'],\n\n setup(props, { expose }) {\n const elementRefs = new Map<string, Element>();\n const apiRef = shallowRef<PxAnimatorAPI | null>(null);\n\n // -- Determine control mode ---------------------------------------------\n\n const compMode = computed<CompMode>(() => {\n if (props.autoplay) return CompMode.autoplay;\n if (props.time !== undefined || props.timeMs !== undefined) return CompMode.fixedTime;\n if (props.play !== undefined) return CompMode.play;\n return CompMode.static;\n });\n\n // -- Prepare the document with overrides --------------------------------\n\n const resolvedDoc = computed(() => {\n let doc = generateNewIds(props.doc);\n return applyDocOverrides(doc, props, compMode.value);\n });\n\n // -- Render the SVG node tree -------------------------------------------\n\n function renderNode(node: PxNode | undefined): VNode | null {\n if (!node) return null;\n\n const { type, animate, meta, children, ...attrs } = node;\n const normProps = getNormalizedProps(attrs);\n\n // Capture a ref to each element with an id.\n if (node['id']) {\n const nodeId = node['id'];\n normProps['ref'] = (el: Element | null) => {\n if (el) {\n elementRefs.set(nodeId, el);\n } else {\n elementRefs.delete(nodeId);\n }\n };\n }\n\n const childVNodes = children?.map(child => renderNode(child)).filter(Boolean) as VNode[] | undefined;\n return h(type, normProps, childVNodes);\n }\n\n // -- Animator lifecycle -------------------------------------------------\n\n function createApi() {\n destroyApi();\n const doc = resolvedDoc.value;\n if (!doc) return;\n apiRef.value = createAnimator(doc, createVueAdapter(elementRefs));\n }\n\n function destroyApi() {\n apiRef.value?.destroy();\n apiRef.value = null;\n }\n\n // Create the animator once DOM refs are available.\n onMounted(() => createApi());\n\n // Recreate the animator when the resolved doc changes.\n watch(resolvedDoc, () => createApi());\n\n // Sync declarative play/pause props with the animator.\n watch([compMode, () => props.play, () => props.pause], () => {\n if (compMode.value === CompMode.play) {\n if (props.play && !props.pause) {\n apiRef.value?.play();\n } else if (props.pause) {\n apiRef.value?.pause();\n } else {\n apiRef.value?.finish();\n }\n }\n });\n\n onUnmounted(() => {\n destroyApi();\n });\n\n // -- Expose imperative API ----------------------------------------------\n\n const publicApi: VueAnimatorApi = {\n isPlaying: () => apiRef.value?.isPlaying() || false,\n play: () => apiRef.value?.play(),\n pause: () => apiRef.value?.pause(),\n cancel: () => apiRef.value?.cancel(),\n finish: () => apiRef.value?.finish(),\n getCurrentTime: () => apiRef.value?.getCurrentTime() || null,\n setCurrentTime: (time: number) => apiRef.value?.setCurrentTime(time),\n };\n\n expose(publicApi);\n\n // -- Render -------------------------------------------------------------\n\n return () => {\n const doc = resolvedDoc.value;\n return doc ? renderNode(doc) : null;\n };\n },\n});\n\nexport default PixodeskSvgAnimator;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,8BAA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eAAe,KAAK;AAAA,MACxD,gBAAgB,CAAC,SAAiB,OAAO,OAAO,eAAe,IAAI;AAAA,IACvE;AAEA,WAAO,SAAS;AAIhB,WAAO,MAAM;AACT,YAAM,MAAM,YAAY;AACxB,aAAO,MAAM,WAAW,GAAG,IAAI;AAAA,IACnC;AAAA,EACJ;AACJ,CAAC;AAED,IAAO,8BAAQ;","names":[]}
@@ -0,0 +1,177 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, VNode } from 'vue';
3
+ import { PxAnimatedSvgDocument, FillMode } from '@pixodesk/svg-animator-web';
4
+
5
+ interface VueAnimatorApi {
6
+ /** Returns true if the animation is currently running. */
7
+ isPlaying(): boolean;
8
+ /** Starts or resumes the animation. */
9
+ play(): void;
10
+ /** Pauses the animation at its current state. */
11
+ pause(): void;
12
+ /** Stops the animation and resets it to its initial state. */
13
+ cancel(): void;
14
+ /** Jumps to the end of the animation and holds the final state. */
15
+ finish(): void;
16
+ /** Returns the current playback time in milliseconds. */
17
+ getCurrentTime(): number | null;
18
+ /** Jumps to a specific time (in milliseconds) in the animation. */
19
+ setCurrentTime(time: number): void;
20
+ }
21
+ /**
22
+ * Vue component for rendering and controlling Pixodesk SVG animations.
23
+ *
24
+ * Supports four mutually-exclusive control modes:
25
+ *
26
+ * 1. **Autoplay** – uses triggers from the animation document.
27
+ * ```vue
28
+ * <PixodeskSvgAnimator :doc="animation" autoplay />
29
+ * ```
30
+ *
31
+ * 2. **Declarative play/pause** – controlled via boolean props.
32
+ * ```vue
33
+ * <PixodeskSvgAnimator :doc="animation" play :pause="false" />
34
+ * ```
35
+ *
36
+ * 3. **Imperative** – exposes a ref-based API for full programmatic control.
37
+ * ```vue
38
+ * <PixodeskSvgAnimator :doc="animation" ref="animator" />
39
+ * <button @click="$refs.animator.play()">Play</button>
40
+ * ```
41
+ *
42
+ * 4. **Controlled time** – renders a single frame at a given time.
43
+ * ```vue
44
+ * <PixodeskSvgAnimator :doc="animation" :time="0.5" />
45
+ * <PixodeskSvgAnimator :doc="animation" :timeMs="500" />
46
+ * ```
47
+ */
48
+ declare const PixodeskSvgAnimator: vue.DefineComponent<vue.ExtractPropTypes<{
49
+ doc: {
50
+ type: PropType<PxAnimatedSvgDocument>;
51
+ required: true;
52
+ };
53
+ timeline: {
54
+ type: PropType<"time" | "scroll">;
55
+ };
56
+ mode: {
57
+ type: PropType<"webapi" | "frames" | "auto">;
58
+ };
59
+ delay: {
60
+ type: NumberConstructor;
61
+ };
62
+ fill: {
63
+ type: PropType<FillMode>;
64
+ };
65
+ iterations: {
66
+ type: PropType<number | "infinite">;
67
+ };
68
+ duration: {
69
+ type: NumberConstructor;
70
+ };
71
+ direction: {
72
+ type: PropType<PlaybackDirection>;
73
+ };
74
+ frameRate: {
75
+ type: NumberConstructor;
76
+ };
77
+ startOn: {
78
+ type: PropType<"load" | "mouseOver" | "click" | "scrollIntoView" | "programmatic">;
79
+ };
80
+ outAction: {
81
+ type: PropType<"continue" | "pause" | "reset" | "reverse">;
82
+ };
83
+ scrollIntoViewThreshold: {
84
+ type: NumberConstructor;
85
+ };
86
+ autoplay: {
87
+ type: BooleanConstructor;
88
+ default: undefined;
89
+ };
90
+ play: {
91
+ type: BooleanConstructor;
92
+ default: undefined;
93
+ };
94
+ pause: {
95
+ type: BooleanConstructor;
96
+ default: undefined;
97
+ };
98
+ time: {
99
+ type: NumberConstructor;
100
+ };
101
+ timeMs: {
102
+ type: NumberConstructor;
103
+ };
104
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
105
+ [key: string]: any;
106
+ }> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("play" | "pause" | "stop" | "cancel" | "finish" | "remove" | "warning" | "error")[], "play" | "pause" | "stop" | "cancel" | "finish" | "remove" | "warning" | "error", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
107
+ doc: {
108
+ type: PropType<PxAnimatedSvgDocument>;
109
+ required: true;
110
+ };
111
+ timeline: {
112
+ type: PropType<"time" | "scroll">;
113
+ };
114
+ mode: {
115
+ type: PropType<"webapi" | "frames" | "auto">;
116
+ };
117
+ delay: {
118
+ type: NumberConstructor;
119
+ };
120
+ fill: {
121
+ type: PropType<FillMode>;
122
+ };
123
+ iterations: {
124
+ type: PropType<number | "infinite">;
125
+ };
126
+ duration: {
127
+ type: NumberConstructor;
128
+ };
129
+ direction: {
130
+ type: PropType<PlaybackDirection>;
131
+ };
132
+ frameRate: {
133
+ type: NumberConstructor;
134
+ };
135
+ startOn: {
136
+ type: PropType<"load" | "mouseOver" | "click" | "scrollIntoView" | "programmatic">;
137
+ };
138
+ outAction: {
139
+ type: PropType<"continue" | "pause" | "reset" | "reverse">;
140
+ };
141
+ scrollIntoViewThreshold: {
142
+ type: NumberConstructor;
143
+ };
144
+ autoplay: {
145
+ type: BooleanConstructor;
146
+ default: undefined;
147
+ };
148
+ play: {
149
+ type: BooleanConstructor;
150
+ default: undefined;
151
+ };
152
+ pause: {
153
+ type: BooleanConstructor;
154
+ default: undefined;
155
+ };
156
+ time: {
157
+ type: NumberConstructor;
158
+ };
159
+ timeMs: {
160
+ type: NumberConstructor;
161
+ };
162
+ }>> & Readonly<{
163
+ onPlay?: ((...args: any[]) => any) | undefined;
164
+ onPause?: ((...args: any[]) => any) | undefined;
165
+ onStop?: ((...args: any[]) => any) | undefined;
166
+ onCancel?: ((...args: any[]) => any) | undefined;
167
+ onFinish?: ((...args: any[]) => any) | undefined;
168
+ onRemove?: ((...args: any[]) => any) | undefined;
169
+ onWarning?: ((...args: any[]) => any) | undefined;
170
+ onError?: ((...args: any[]) => any) | undefined;
171
+ }>, {
172
+ autoplay: boolean;
173
+ play: boolean;
174
+ pause: boolean;
175
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
176
+
177
+ export { PixodeskSvgAnimator, type VueAnimatorApi };