@pixodesk/svg-animator-rn 1.0.21
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 +21 -0
- package/dist/index.cjs +459 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +158 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +470 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
- package/src/PixodeskSvgAnimator.tsx +386 -0
- package/src/PxRnPropNames.ts +55 -0
- package/src/PxRnRender.tsx +94 -0
- package/src/PxRnTracks.test.ts +185 -0
- package/src/PxRnTracks.ts +150 -0
- package/src/PxRnTypeMap.ts +64 -0
- package/src/index.ts +15 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { PxAnimatedSvgDocument, FillMode, PlaybackDirection, PxNode } from '@pixodesk/svg-animator-core';
|
|
2
|
+
import React, { ReactElement, ComponentType, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Imperative playback API — mirrors ReactAnimatorApi from svg-animator-react. */
|
|
5
|
+
interface RnAnimatorApi {
|
|
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
|
+
/** Changes the speed of the animation. 1 is normal, 2 is double. */
|
|
17
|
+
setPlaybackRate(rate: number): void;
|
|
18
|
+
/** Returns the current playback time in milliseconds. */
|
|
19
|
+
getCurrentTime(): number | null;
|
|
20
|
+
/** Jumps to a specific time (in milliseconds) in the animation. */
|
|
21
|
+
setCurrentTime(time: number): void;
|
|
22
|
+
}
|
|
23
|
+
interface PixodeskSvgAnimatorProps {
|
|
24
|
+
/** The animation document to render. */
|
|
25
|
+
doc: PxAnimatedSvgDocument;
|
|
26
|
+
/** Duration of a single iteration in milliseconds. */
|
|
27
|
+
duration?: number;
|
|
28
|
+
/** Delay before the animation starts, in milliseconds. */
|
|
29
|
+
delay?: number;
|
|
30
|
+
/** Number of iterations, or 'infinite' for endless looping. */
|
|
31
|
+
iterations?: number | 'infinite';
|
|
32
|
+
/** Defines the element's state when the animation is not active. */
|
|
33
|
+
fill?: FillMode;
|
|
34
|
+
/** Playback direction. */
|
|
35
|
+
direction?: PlaybackDirection;
|
|
36
|
+
/** When true, honours the document trigger (`startOn: 'load'` plays on mount). */
|
|
37
|
+
autoplay?: boolean;
|
|
38
|
+
/** Starts playback unconditionally. */
|
|
39
|
+
play?: boolean;
|
|
40
|
+
/** Pauses current playback. */
|
|
41
|
+
pause?: boolean;
|
|
42
|
+
/** Ref populated with the imperative playback API. */
|
|
43
|
+
apiRef?: React.RefObject<RnAnimatorApi | null>;
|
|
44
|
+
/** Seek to a fraction (0–1) of the whole timeline (duration × iterations). */
|
|
45
|
+
time?: number;
|
|
46
|
+
/** Seek to a specific time in milliseconds. */
|
|
47
|
+
timeMs?: number;
|
|
48
|
+
onPlay?: () => void;
|
|
49
|
+
onStop?: () => void;
|
|
50
|
+
onPause?: () => void;
|
|
51
|
+
onCancel?: () => void;
|
|
52
|
+
onFinish?: () => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* React Native component for rendering and controlling Pixodesk SVG animations.
|
|
56
|
+
*
|
|
57
|
+
* The document is materialised once through the shared core pipeline (effects,
|
|
58
|
+
* loops, motion-path sampling, animated-`<use>` inlining — identical to the
|
|
59
|
+
* web frames engine), compiled into densely sampled per-element tracks, and
|
|
60
|
+
* played back natively: a single reanimated progress value driven by
|
|
61
|
+
* `withTiming`/`withRepeat` on the UI thread, with per-element worklets
|
|
62
|
+
* indexing the precompiled tracks. No JS-thread frame loop.
|
|
63
|
+
*/
|
|
64
|
+
declare function PixodeskSvgAnimator({ doc, duration, delay, iterations, fill, direction, autoplay, play, pause, apiRef, time, timeMs, onPlay, onStop, onPause, onCancel, onFinish, }: PixodeskSvgAnimatorProps): ReactElement | null;
|
|
65
|
+
|
|
66
|
+
interface RenderRnNodeOptions {
|
|
67
|
+
/** Collects non-fatal issues (unsupported tags, dropped attrs). */
|
|
68
|
+
warnings?: Array<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Wraps the created element for animated nodes: receives the resolved
|
|
71
|
+
* component + static props and returns the element to mount (the animator
|
|
72
|
+
* substitutes an Animated component wired to its tracks). Return undefined
|
|
73
|
+
* to keep the plain static element.
|
|
74
|
+
*/
|
|
75
|
+
decorate?: (node: PxNode, Component: ComponentType<any>, props: Record<string, any>, children: ReactNode) => ReactElement | undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Converts core-normalised wire props into react-native-svg props: RN prop
|
|
79
|
+
* naming, sanitisation (same security rules as the web renderer), numeric
|
|
80
|
+
* coercion where possible.
|
|
81
|
+
*/
|
|
82
|
+
declare function toRnProps(props: Record<string, any>, warnings?: Array<string>): Record<string, any>;
|
|
83
|
+
/**
|
|
84
|
+
* Renders a (materialised) PxNode tree to react-native-svg elements.
|
|
85
|
+
* Mirrors the web `renderNode` contract: unsupported/dangerous tags are
|
|
86
|
+
* skipped with a warning, never a crash.
|
|
87
|
+
*/
|
|
88
|
+
declare function renderRnNode(node: PxNode, opts?: RenderRnNodeOptions, key?: string | number): ReactElement | null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Sampled animation tracks for ONE element: prop name → per-sample values.
|
|
92
|
+
*
|
|
93
|
+
* The compiler densely samples every animated property through core's
|
|
94
|
+
* `calcAnimationValues` — the exact function the web frames engine renders
|
|
95
|
+
* with — so RN playback is value-identical to the web player. Easing, loops,
|
|
96
|
+
* transform composition, colour interpolation and path morphing are all baked
|
|
97
|
+
* into the samples at compile time; the UI-thread worklet only indexes arrays.
|
|
98
|
+
*/
|
|
99
|
+
interface PxElementTracks {
|
|
100
|
+
/** Element id (after id regeneration). */
|
|
101
|
+
id: string;
|
|
102
|
+
/** react-native-svg prop name → one value per sample. */
|
|
103
|
+
props: Record<string, Array<string | number | Array<number>>>;
|
|
104
|
+
}
|
|
105
|
+
interface PxCompiledTracks {
|
|
106
|
+
/** Per-iteration duration, ms. */
|
|
107
|
+
duration: number;
|
|
108
|
+
/** Iteration count (Infinity for 'infinite'). */
|
|
109
|
+
iterations: number;
|
|
110
|
+
/** 'normal' | 'reverse' | 'alternate' | 'alternate-reverse' */
|
|
111
|
+
direction: string;
|
|
112
|
+
/** Delay before start, ms (positive = wait). */
|
|
113
|
+
delay: number;
|
|
114
|
+
/** WAAPI-style fill mode (default 'forwards'). */
|
|
115
|
+
fill: string;
|
|
116
|
+
/** Sample step, ms. */
|
|
117
|
+
stepMs: number;
|
|
118
|
+
/** Number of samples per iteration (>= 2; sample i is at time i*stepMs). */
|
|
119
|
+
sampleCount: number;
|
|
120
|
+
/** Tracks for every animated element. */
|
|
121
|
+
elements: Array<PxElementTracks>;
|
|
122
|
+
}
|
|
123
|
+
interface CompileTracksOptions {
|
|
124
|
+
/** Target sample rate, samples/second. Default 60 (one per frame). */
|
|
125
|
+
sampleRate?: number;
|
|
126
|
+
/** Hard cap on samples per iteration (memory guard). Default 600. */
|
|
127
|
+
maxSamples?: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Compiles a MATERIALISED document (run `materialiseAllInTree(doc, 'frames')`
|
|
131
|
+
* + `generateNewIds` first) into densely sampled per-element tracks.
|
|
132
|
+
*/
|
|
133
|
+
declare function compileTracks(doc: PxAnimatedSvgDocument, opts?: CompileTracksOptions): PxCompiledTracks;
|
|
134
|
+
/**
|
|
135
|
+
* Worklet-safe sample lookup: returns the per-prop values at time `tMs`
|
|
136
|
+
* (already mapped into a single iteration by the caller). Kept deliberately
|
|
137
|
+
* trivial — runs on the UI thread every frame.
|
|
138
|
+
*/
|
|
139
|
+
declare function sampleProps(tracks: PxElementTracks, tMs: number, stepMs: number, sampleCount: number): Record<string, string | number | Array<number>>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Converts one normalised wire attribute name (camelCase after core's
|
|
143
|
+
* `getNormalizedProps`, or kebab-case raw) to a react-native-svg prop name.
|
|
144
|
+
* Returns undefined for props that must be dropped.
|
|
145
|
+
*
|
|
146
|
+
* Pure (no react-native-svg import) so the track compiler and its tests
|
|
147
|
+
* don't need a React Native environment.
|
|
148
|
+
*/
|
|
149
|
+
declare function toRnPropName(attrName: string): string | undefined;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* SVG tag → react-native-svg component. Tags not in this map are skipped at
|
|
153
|
+
* render time (with a warning collected by the renderer) — they go on the
|
|
154
|
+
* feature-gap list rather than crashing the tree.
|
|
155
|
+
*/
|
|
156
|
+
declare const RN_SVG_COMPONENTS: Record<string, ComponentType<any>>;
|
|
157
|
+
|
|
158
|
+
export { type CompileTracksOptions, PixodeskSvgAnimator, type PixodeskSvgAnimatorProps, type PxCompiledTracks, type PxElementTracks, RN_SVG_COMPONENTS, type RenderRnNodeOptions, type RnAnimatorApi, compileTracks, PixodeskSvgAnimator as default, renderRnNode, sampleProps, toRnPropName, toRnProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { PxAnimatedSvgDocument, FillMode, PlaybackDirection, PxNode } from '@pixodesk/svg-animator-core';
|
|
2
|
+
import React, { ReactElement, ComponentType, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/** Imperative playback API — mirrors ReactAnimatorApi from svg-animator-react. */
|
|
5
|
+
interface RnAnimatorApi {
|
|
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
|
+
/** Changes the speed of the animation. 1 is normal, 2 is double. */
|
|
17
|
+
setPlaybackRate(rate: number): void;
|
|
18
|
+
/** Returns the current playback time in milliseconds. */
|
|
19
|
+
getCurrentTime(): number | null;
|
|
20
|
+
/** Jumps to a specific time (in milliseconds) in the animation. */
|
|
21
|
+
setCurrentTime(time: number): void;
|
|
22
|
+
}
|
|
23
|
+
interface PixodeskSvgAnimatorProps {
|
|
24
|
+
/** The animation document to render. */
|
|
25
|
+
doc: PxAnimatedSvgDocument;
|
|
26
|
+
/** Duration of a single iteration in milliseconds. */
|
|
27
|
+
duration?: number;
|
|
28
|
+
/** Delay before the animation starts, in milliseconds. */
|
|
29
|
+
delay?: number;
|
|
30
|
+
/** Number of iterations, or 'infinite' for endless looping. */
|
|
31
|
+
iterations?: number | 'infinite';
|
|
32
|
+
/** Defines the element's state when the animation is not active. */
|
|
33
|
+
fill?: FillMode;
|
|
34
|
+
/** Playback direction. */
|
|
35
|
+
direction?: PlaybackDirection;
|
|
36
|
+
/** When true, honours the document trigger (`startOn: 'load'` plays on mount). */
|
|
37
|
+
autoplay?: boolean;
|
|
38
|
+
/** Starts playback unconditionally. */
|
|
39
|
+
play?: boolean;
|
|
40
|
+
/** Pauses current playback. */
|
|
41
|
+
pause?: boolean;
|
|
42
|
+
/** Ref populated with the imperative playback API. */
|
|
43
|
+
apiRef?: React.RefObject<RnAnimatorApi | null>;
|
|
44
|
+
/** Seek to a fraction (0–1) of the whole timeline (duration × iterations). */
|
|
45
|
+
time?: number;
|
|
46
|
+
/** Seek to a specific time in milliseconds. */
|
|
47
|
+
timeMs?: number;
|
|
48
|
+
onPlay?: () => void;
|
|
49
|
+
onStop?: () => void;
|
|
50
|
+
onPause?: () => void;
|
|
51
|
+
onCancel?: () => void;
|
|
52
|
+
onFinish?: () => void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* React Native component for rendering and controlling Pixodesk SVG animations.
|
|
56
|
+
*
|
|
57
|
+
* The document is materialised once through the shared core pipeline (effects,
|
|
58
|
+
* loops, motion-path sampling, animated-`<use>` inlining — identical to the
|
|
59
|
+
* web frames engine), compiled into densely sampled per-element tracks, and
|
|
60
|
+
* played back natively: a single reanimated progress value driven by
|
|
61
|
+
* `withTiming`/`withRepeat` on the UI thread, with per-element worklets
|
|
62
|
+
* indexing the precompiled tracks. No JS-thread frame loop.
|
|
63
|
+
*/
|
|
64
|
+
declare function PixodeskSvgAnimator({ doc, duration, delay, iterations, fill, direction, autoplay, play, pause, apiRef, time, timeMs, onPlay, onStop, onPause, onCancel, onFinish, }: PixodeskSvgAnimatorProps): ReactElement | null;
|
|
65
|
+
|
|
66
|
+
interface RenderRnNodeOptions {
|
|
67
|
+
/** Collects non-fatal issues (unsupported tags, dropped attrs). */
|
|
68
|
+
warnings?: Array<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Wraps the created element for animated nodes: receives the resolved
|
|
71
|
+
* component + static props and returns the element to mount (the animator
|
|
72
|
+
* substitutes an Animated component wired to its tracks). Return undefined
|
|
73
|
+
* to keep the plain static element.
|
|
74
|
+
*/
|
|
75
|
+
decorate?: (node: PxNode, Component: ComponentType<any>, props: Record<string, any>, children: ReactNode) => ReactElement | undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Converts core-normalised wire props into react-native-svg props: RN prop
|
|
79
|
+
* naming, sanitisation (same security rules as the web renderer), numeric
|
|
80
|
+
* coercion where possible.
|
|
81
|
+
*/
|
|
82
|
+
declare function toRnProps(props: Record<string, any>, warnings?: Array<string>): Record<string, any>;
|
|
83
|
+
/**
|
|
84
|
+
* Renders a (materialised) PxNode tree to react-native-svg elements.
|
|
85
|
+
* Mirrors the web `renderNode` contract: unsupported/dangerous tags are
|
|
86
|
+
* skipped with a warning, never a crash.
|
|
87
|
+
*/
|
|
88
|
+
declare function renderRnNode(node: PxNode, opts?: RenderRnNodeOptions, key?: string | number): ReactElement | null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Sampled animation tracks for ONE element: prop name → per-sample values.
|
|
92
|
+
*
|
|
93
|
+
* The compiler densely samples every animated property through core's
|
|
94
|
+
* `calcAnimationValues` — the exact function the web frames engine renders
|
|
95
|
+
* with — so RN playback is value-identical to the web player. Easing, loops,
|
|
96
|
+
* transform composition, colour interpolation and path morphing are all baked
|
|
97
|
+
* into the samples at compile time; the UI-thread worklet only indexes arrays.
|
|
98
|
+
*/
|
|
99
|
+
interface PxElementTracks {
|
|
100
|
+
/** Element id (after id regeneration). */
|
|
101
|
+
id: string;
|
|
102
|
+
/** react-native-svg prop name → one value per sample. */
|
|
103
|
+
props: Record<string, Array<string | number | Array<number>>>;
|
|
104
|
+
}
|
|
105
|
+
interface PxCompiledTracks {
|
|
106
|
+
/** Per-iteration duration, ms. */
|
|
107
|
+
duration: number;
|
|
108
|
+
/** Iteration count (Infinity for 'infinite'). */
|
|
109
|
+
iterations: number;
|
|
110
|
+
/** 'normal' | 'reverse' | 'alternate' | 'alternate-reverse' */
|
|
111
|
+
direction: string;
|
|
112
|
+
/** Delay before start, ms (positive = wait). */
|
|
113
|
+
delay: number;
|
|
114
|
+
/** WAAPI-style fill mode (default 'forwards'). */
|
|
115
|
+
fill: string;
|
|
116
|
+
/** Sample step, ms. */
|
|
117
|
+
stepMs: number;
|
|
118
|
+
/** Number of samples per iteration (>= 2; sample i is at time i*stepMs). */
|
|
119
|
+
sampleCount: number;
|
|
120
|
+
/** Tracks for every animated element. */
|
|
121
|
+
elements: Array<PxElementTracks>;
|
|
122
|
+
}
|
|
123
|
+
interface CompileTracksOptions {
|
|
124
|
+
/** Target sample rate, samples/second. Default 60 (one per frame). */
|
|
125
|
+
sampleRate?: number;
|
|
126
|
+
/** Hard cap on samples per iteration (memory guard). Default 600. */
|
|
127
|
+
maxSamples?: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Compiles a MATERIALISED document (run `materialiseAllInTree(doc, 'frames')`
|
|
131
|
+
* + `generateNewIds` first) into densely sampled per-element tracks.
|
|
132
|
+
*/
|
|
133
|
+
declare function compileTracks(doc: PxAnimatedSvgDocument, opts?: CompileTracksOptions): PxCompiledTracks;
|
|
134
|
+
/**
|
|
135
|
+
* Worklet-safe sample lookup: returns the per-prop values at time `tMs`
|
|
136
|
+
* (already mapped into a single iteration by the caller). Kept deliberately
|
|
137
|
+
* trivial — runs on the UI thread every frame.
|
|
138
|
+
*/
|
|
139
|
+
declare function sampleProps(tracks: PxElementTracks, tMs: number, stepMs: number, sampleCount: number): Record<string, string | number | Array<number>>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Converts one normalised wire attribute name (camelCase after core's
|
|
143
|
+
* `getNormalizedProps`, or kebab-case raw) to a react-native-svg prop name.
|
|
144
|
+
* Returns undefined for props that must be dropped.
|
|
145
|
+
*
|
|
146
|
+
* Pure (no react-native-svg import) so the track compiler and its tests
|
|
147
|
+
* don't need a React Native environment.
|
|
148
|
+
*/
|
|
149
|
+
declare function toRnPropName(attrName: string): string | undefined;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* SVG tag → react-native-svg component. Tags not in this map are skipped at
|
|
153
|
+
* render time (with a warning collected by the renderer) — they go on the
|
|
154
|
+
* feature-gap list rather than crashing the tree.
|
|
155
|
+
*/
|
|
156
|
+
declare const RN_SVG_COMPONENTS: Record<string, ComponentType<any>>;
|
|
157
|
+
|
|
158
|
+
export { type CompileTracksOptions, PixodeskSvgAnimator, type PixodeskSvgAnimatorProps, type PxCompiledTracks, type PxElementTracks, RN_SVG_COMPONENTS, type RenderRnNodeOptions, type RnAnimatorApi, compileTracks, PixodeskSvgAnimator as default, renderRnNode, sampleProps, toRnPropName, toRnProps };
|