@lordicon/web 1.0.1 → 1.2.0
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/.claude/settings.local.json +14 -0
- package/dist/index.d.ts +2 -394
- package/dist/index.js +5289 -6272
- package/dist/interfaces.d.ts +163 -0
- package/dist/lottie.d.ts +48 -0
- package/dist/parsers.d.ts +40 -0
- package/dist/player.d.ts +233 -0
- package/dist/utils.d.ts +39 -0
- package/examples/03-states.html +3 -1
- package/package.json +10 -10
- package/src/player.ts +3 -1
- package/vite.config.ts +8 -2
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icon animation data in Lottie JSON format.
|
|
3
|
+
* This player is optimized for icons from [Lordicon](https://lordicon.com/).
|
|
4
|
+
*/
|
|
5
|
+
export type LottieData = any;
|
|
6
|
+
/**
|
|
7
|
+
* Represents a single Lottie animation instance from `@lordicon/internal`.
|
|
8
|
+
* Contains the current state and methods for controlling playback.
|
|
9
|
+
*/
|
|
10
|
+
export type LottieAnimationInstance = {
|
|
11
|
+
name: string;
|
|
12
|
+
isLoaded: boolean;
|
|
13
|
+
currentFrame: number;
|
|
14
|
+
currentRawFrame: number;
|
|
15
|
+
firstFrame: number;
|
|
16
|
+
totalFrames: number;
|
|
17
|
+
frameRate: number;
|
|
18
|
+
frameMult: number;
|
|
19
|
+
playSpeed: number;
|
|
20
|
+
playDirection: number;
|
|
21
|
+
playCount: number;
|
|
22
|
+
isPaused: boolean;
|
|
23
|
+
autoplay: boolean;
|
|
24
|
+
loop: boolean | number;
|
|
25
|
+
renderer: any;
|
|
26
|
+
animationID: string;
|
|
27
|
+
assetsPath: string;
|
|
28
|
+
timeCompleted: number;
|
|
29
|
+
segmentPos: number;
|
|
30
|
+
isSubframeEnabled: boolean;
|
|
31
|
+
segments: FrameSegment | FrameSegment[];
|
|
32
|
+
play(name?: string): void;
|
|
33
|
+
stop(name?: string): void;
|
|
34
|
+
togglePause(name?: string): void;
|
|
35
|
+
destroy(name?: string): void;
|
|
36
|
+
pause(name?: string): void;
|
|
37
|
+
goToAndStop(value: number | string, isFrame?: boolean, name?: string): void;
|
|
38
|
+
goToAndPlay(value: number | string, isFrame?: boolean, name?: string): void;
|
|
39
|
+
includeLayers(data: any): void;
|
|
40
|
+
setSegment(init: number, end: number): void;
|
|
41
|
+
resetSegments(forceFlag: boolean): void;
|
|
42
|
+
hide(): void;
|
|
43
|
+
show(): void;
|
|
44
|
+
resize(): void;
|
|
45
|
+
setSpeed(speed: number): void;
|
|
46
|
+
setDirection(direction: PlaybackDirection): void;
|
|
47
|
+
setLoop(isLooping: boolean): void;
|
|
48
|
+
playSegments(segments: FrameSegment | FrameSegment[], forceFlag?: boolean): void;
|
|
49
|
+
setSubframe(useSubFrames: boolean): void;
|
|
50
|
+
getDuration(inFrames?: boolean): number;
|
|
51
|
+
triggerEvent(name: string, args: any): void;
|
|
52
|
+
addEventListener(name: string, callback: any): () => void;
|
|
53
|
+
removeEventListener(name: string, callback?: any): void;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Supported property types for Lottie animations.
|
|
57
|
+
*/
|
|
58
|
+
export type LottiePropertyType = 'color' | 'slider' | 'point' | 'checkbox' | 'feature';
|
|
59
|
+
/**
|
|
60
|
+
* Describes a property found in the animation.
|
|
61
|
+
*/
|
|
62
|
+
export interface LottieProperty {
|
|
63
|
+
name: string;
|
|
64
|
+
path: string;
|
|
65
|
+
type: LottiePropertyType;
|
|
66
|
+
value: any;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Supported stroke weights for icons.
|
|
70
|
+
*/
|
|
71
|
+
export type Stroke = 1 | 2 | 3 | 'light' | 'regular' | 'bold';
|
|
72
|
+
/**
|
|
73
|
+
* RGB color tuple in Lottie format: [r, g, b].
|
|
74
|
+
*/
|
|
75
|
+
export type RgbTuple = [number, number, number];
|
|
76
|
+
/**
|
|
77
|
+
* RGB color as an object.
|
|
78
|
+
*/
|
|
79
|
+
export interface RgbColor {
|
|
80
|
+
r: number;
|
|
81
|
+
g: number;
|
|
82
|
+
b: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Object storing multiple named colors.
|
|
86
|
+
*
|
|
87
|
+
* Example:
|
|
88
|
+
* {
|
|
89
|
+
* primary: 'red',
|
|
90
|
+
* secondary: '#ff0000',
|
|
91
|
+
* }
|
|
92
|
+
*/
|
|
93
|
+
export interface ColorMap {
|
|
94
|
+
[key: string]: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Animation segment as a tuple: [startFrame, endFrame].
|
|
98
|
+
*/
|
|
99
|
+
export type FrameSegment = [number, number];
|
|
100
|
+
/**
|
|
101
|
+
* Animation playback direction: 1 (forward) or -1 (backward).
|
|
102
|
+
*/
|
|
103
|
+
export type PlaybackDirection = 1 | -1;
|
|
104
|
+
/**
|
|
105
|
+
* Supported player event names.
|
|
106
|
+
*/
|
|
107
|
+
export type EventName = 'ready' | 'complete' | 'frame' | 'refresh';
|
|
108
|
+
/**
|
|
109
|
+
* Player event callback type.
|
|
110
|
+
*/
|
|
111
|
+
export type EventHandler = () => void;
|
|
112
|
+
/**
|
|
113
|
+
* Properties for legacy icons.
|
|
114
|
+
*/
|
|
115
|
+
export interface LegacyIconProperties {
|
|
116
|
+
/**
|
|
117
|
+
* Scale for legacy icons.
|
|
118
|
+
*/
|
|
119
|
+
scale?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Axis x for legacy icons.
|
|
122
|
+
*/
|
|
123
|
+
axisX?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Axis y for legacy icons.
|
|
126
|
+
*/
|
|
127
|
+
axisY?: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Properties for customizing icons.
|
|
131
|
+
*
|
|
132
|
+
* Example:
|
|
133
|
+
* {
|
|
134
|
+
* stroke: 'bold',
|
|
135
|
+
* colors: {
|
|
136
|
+
* primary: 'red',
|
|
137
|
+
* },
|
|
138
|
+
* }
|
|
139
|
+
*/
|
|
140
|
+
export interface IconProperties {
|
|
141
|
+
/**
|
|
142
|
+
* State (motion type) of the icon. States allow switching between multiple animations built into a single icon file.
|
|
143
|
+
*/
|
|
144
|
+
state?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Colors.
|
|
147
|
+
*/
|
|
148
|
+
colors?: ColorMap;
|
|
149
|
+
/**
|
|
150
|
+
* Stroke.
|
|
151
|
+
*/
|
|
152
|
+
stroke?: Stroke;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Details of a single animation state.
|
|
156
|
+
*/
|
|
157
|
+
export interface IconState {
|
|
158
|
+
name: string;
|
|
159
|
+
time: number;
|
|
160
|
+
duration: number;
|
|
161
|
+
params: string[];
|
|
162
|
+
default?: boolean;
|
|
163
|
+
}
|
package/dist/lottie.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { LottieAnimationInstance, LottieData, LottieProperty, RgbColor, RgbTuple } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an RGB color object to a hexadecimal color string.
|
|
4
|
+
* @param value Color object with r, g, b properties.
|
|
5
|
+
* @returns Hexadecimal color string (e.g., "#ff0000").
|
|
6
|
+
*/
|
|
7
|
+
export declare function rgbToHex(value: RgbColor): string;
|
|
8
|
+
/**
|
|
9
|
+
* Converts a hexadecimal color string to an RGB color object.
|
|
10
|
+
* @param hex Hexadecimal color string (with or without "#").
|
|
11
|
+
* @returns RgbColor object with r, g, b properties.
|
|
12
|
+
*/
|
|
13
|
+
export declare function hexToRgb(hex: string): RgbColor;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a hexadecimal color string to an RGB tuple in the 0-1 range.
|
|
16
|
+
* @param hex Hexadecimal color string.
|
|
17
|
+
* @returns RgbTuple with values normalized to 0-1.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hexToTupleColor(hex: string): RgbTuple;
|
|
20
|
+
/**
|
|
21
|
+
* Converts an RGB tuple (0-1 range) to a hexadecimal color string.
|
|
22
|
+
* @param value RgbTuple with values in the 0-1 range.
|
|
23
|
+
* @returns Hexadecimal color string.
|
|
24
|
+
*/
|
|
25
|
+
export declare function tupleColorToHex(value: RgbTuple): string;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts all supported customizable properties from Lottie data.
|
|
28
|
+
* @param data Lottie animation data.
|
|
29
|
+
* @param options Extraction options (e.g., lottieInstance: boolean).
|
|
30
|
+
* @returns Array of LottieProperty objects describing customizable properties.
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractLottieProperties(data: LottieData, { lottieInstance }?: {
|
|
33
|
+
lottieInstance?: boolean;
|
|
34
|
+
}): LottieProperty[];
|
|
35
|
+
/**
|
|
36
|
+
* Resets Lottie data or animation instance to default values for the given properties.
|
|
37
|
+
* @param data Lottie data or animation instance to reset.
|
|
38
|
+
* @param properties Array of properties to reset.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resetLottieProperties(data: LottieData | LottieAnimationInstance, properties: LottieProperty[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* Updates Lottie data or animation instance with a new value for the given properties.
|
|
43
|
+
* Handles color, point, and other property types accordingly.
|
|
44
|
+
* @param data Lottie data or animation instance to update.
|
|
45
|
+
* @param properties Array of properties to update.
|
|
46
|
+
* @param value New value to set for each property.
|
|
47
|
+
*/
|
|
48
|
+
export declare function updateLottieProperties(data: LottieData | LottieAnimationInstance, properties: LottieProperty[], value: any): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ColorMap } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a hexadecimal color string for a given color name or hex code.
|
|
4
|
+
*
|
|
5
|
+
* Example:
|
|
6
|
+
* ```js
|
|
7
|
+
* parseColor('red'); // "#ff0000"
|
|
8
|
+
* parseColor('#0f0'); // "#00ff00"
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param colorName Color name (e.g., "red") or hex string (e.g., "#ff0000" or "#0f0").
|
|
12
|
+
* @returns Hexadecimal color string in the format "#rrggbb".
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseColor(colorName: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Parses a colors attribute string into a ColorMap object.
|
|
17
|
+
*
|
|
18
|
+
* Example:
|
|
19
|
+
* ```js
|
|
20
|
+
* parseColors('primary:red,secondary:#00ff00');
|
|
21
|
+
* // Returns: { primary: '#ff0000', secondary: '#00ff00' }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param colors Colors defined as a comma-separated string (e.g., "primary:red,secondary:#00ff00").
|
|
25
|
+
* @returns Object mapping color names to hex strings, or undefined if input is invalid.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseColors(colors: any): ColorMap | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Parses a stroke attribute value to a supported numeric range.
|
|
30
|
+
*
|
|
31
|
+
* @param value Stroke value as a string or number ("light", 1, "1", "regular", 2, "2", "bold", 3, "3").
|
|
32
|
+
* @returns Stroke value as 1, 2, or 3, or undefined if not valid.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseStroke(value: any): (1 | 2 | 3 | undefined);
|
|
35
|
+
/**
|
|
36
|
+
* Parse state attribute.
|
|
37
|
+
* @param value State value.
|
|
38
|
+
* @returns Returns the state as a string if valid, otherwise undefined.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseState(value: any): (string | undefined);
|
package/dist/player.d.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { AnimationConfig } from '@lordicon/internal';
|
|
2
|
+
import { ColorMap, EventHandler, EventName, IconProperties, IconState, LegacyIconProperties, LottieAnimationInstance, LottieData, LottieProperty, PlaybackDirection, Stroke } from './interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* LottieOptions type represents the configuration options for the Lottie player.
|
|
5
|
+
*/
|
|
6
|
+
export type LottieOptions = Omit<AnimationConfig, 'container'>;
|
|
7
|
+
/**
|
|
8
|
+
* Player class for controlling and customizing Lottie-based icons.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Player {
|
|
11
|
+
protected _container: HTMLElement;
|
|
12
|
+
protected _iconData: any;
|
|
13
|
+
protected _initialProperties: IconProperties & LegacyIconProperties;
|
|
14
|
+
protected _lottieInstance?: LottieAnimationInstance;
|
|
15
|
+
protected _ready: boolean;
|
|
16
|
+
protected _colorsProxy?: any;
|
|
17
|
+
protected _direction: PlaybackDirection;
|
|
18
|
+
protected _speed: number;
|
|
19
|
+
protected _lottieProperties?: LottieProperty[];
|
|
20
|
+
protected _eventHandlers: any;
|
|
21
|
+
protected _state?: IconState;
|
|
22
|
+
protected _availableStates: IconState[];
|
|
23
|
+
protected _animationFrameRate: number;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new Player instance.
|
|
26
|
+
* @param container The DOM element where the animation will be rendered.
|
|
27
|
+
* @param data Lottie animation data.
|
|
28
|
+
* @param properties Initial icon properties (colors, stroke, state, etc.).
|
|
29
|
+
* @param options Additional options (e.g., autoInit).
|
|
30
|
+
*/
|
|
31
|
+
constructor(container: HTMLElement, data: LottieData, properties?: IconProperties & LegacyIconProperties, options?: {
|
|
32
|
+
autoInit?: boolean;
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Initializes the player and connects it to the DOM element.
|
|
36
|
+
* Throws an error if already initialized.
|
|
37
|
+
*/
|
|
38
|
+
init(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Destroys the player and releases all resources.
|
|
41
|
+
* Throws an error if not initialized.
|
|
42
|
+
*/
|
|
43
|
+
destroy(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Registers an event listener for a player event.
|
|
46
|
+
* @param name Event name (e.g., 'complete', 'frame', 'ready').
|
|
47
|
+
* @param handler Handler function to call when the event is triggered.
|
|
48
|
+
* @returns Function to remove the listener.
|
|
49
|
+
*/
|
|
50
|
+
addEventListener(name: EventName, handler: EventHandler): () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Removes an event listener for a player event.
|
|
53
|
+
* @param name Event name.
|
|
54
|
+
* @param handler Handler function to remove. If not provided, removes all handlers for the event.
|
|
55
|
+
*/
|
|
56
|
+
removeEventListener(name: EventName, handler?: EventHandler): void;
|
|
57
|
+
/**
|
|
58
|
+
* Triggers a player event and invokes all registered callbacks.
|
|
59
|
+
* @param name Event name.
|
|
60
|
+
* @param args Optional arguments to pass to the callbacks.
|
|
61
|
+
*/
|
|
62
|
+
protected triggerEvent(name: EventName, args?: any): void;
|
|
63
|
+
/**
|
|
64
|
+
* Forces a re-render of the animation.
|
|
65
|
+
*/
|
|
66
|
+
protected refresh(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Starts playing the animation from the current frame.
|
|
69
|
+
* Note: If the animation is finished, it cannot be played again from the last frame.
|
|
70
|
+
*/
|
|
71
|
+
play(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Plays the animation from the beginning of the current state or from the start if no state is set.
|
|
74
|
+
*/
|
|
75
|
+
playFromStart(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Pauses the animation at the current frame.
|
|
78
|
+
*/
|
|
79
|
+
pause(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Stop the animation.
|
|
82
|
+
*/
|
|
83
|
+
stop(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Moves the animation to a specific frame and stops.
|
|
86
|
+
* @param frame Frame number to seek to.
|
|
87
|
+
*/
|
|
88
|
+
seek(frame: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* Moves the animation to the first frame and stops.
|
|
91
|
+
*/
|
|
92
|
+
seekToStart(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Moves the animation to the last frame and stops.
|
|
95
|
+
*/
|
|
96
|
+
seekToEnd(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Sets the animation segment to play.
|
|
99
|
+
* If no segment is provided, resets to the default segment.
|
|
100
|
+
* @param segment Optional segment as [start, end] frame numbers.
|
|
101
|
+
*/
|
|
102
|
+
switchSegment(segment?: [number, number]): void;
|
|
103
|
+
/**
|
|
104
|
+
* Sets multiple icon properties at once.
|
|
105
|
+
* Any property not provided will be reset to its default value.
|
|
106
|
+
* @param properties Properties to assign.
|
|
107
|
+
*/
|
|
108
|
+
set properties(properties: IconProperties);
|
|
109
|
+
/**
|
|
110
|
+
* Gets the current icon properties (colors, stroke, state).
|
|
111
|
+
* @returns The current properties.
|
|
112
|
+
*/
|
|
113
|
+
get properties(): IconProperties;
|
|
114
|
+
/**
|
|
115
|
+
* Sets all customizable colors at once.
|
|
116
|
+
* Pass null to reset all colors to default.
|
|
117
|
+
* @param colors Color map or null.
|
|
118
|
+
*/
|
|
119
|
+
set colors(colors: ColorMap | null);
|
|
120
|
+
/**
|
|
121
|
+
* Provides a proxy for reading or updating individual colors by name.
|
|
122
|
+
*
|
|
123
|
+
* Example:
|
|
124
|
+
* player.colors.primary = '#ff0000';
|
|
125
|
+
* delete player.colors.secondary;
|
|
126
|
+
*/
|
|
127
|
+
get colors(): ColorMap;
|
|
128
|
+
/**
|
|
129
|
+
* Sets the stroke width for the icon.
|
|
130
|
+
* Pass null to reset to default.
|
|
131
|
+
* @param stroke Stroke value or null.
|
|
132
|
+
*/
|
|
133
|
+
set stroke(stroke: Stroke | null);
|
|
134
|
+
/**
|
|
135
|
+
* Gets the current stroke width of the icon.
|
|
136
|
+
* @returns Stroke value or null if not set.
|
|
137
|
+
*/
|
|
138
|
+
get stroke(): Stroke | null;
|
|
139
|
+
/**
|
|
140
|
+
* Sets the current state (animation segment) of the icon.
|
|
141
|
+
* If the state does not exist, falls back to the default state.
|
|
142
|
+
* @param state State name or null for default.
|
|
143
|
+
*/
|
|
144
|
+
set state(state: string | null);
|
|
145
|
+
/**
|
|
146
|
+
* Gets the current state (animation segment) of the icon.
|
|
147
|
+
* @returns State name or null if not set.
|
|
148
|
+
*/
|
|
149
|
+
get state(): string | null;
|
|
150
|
+
/**
|
|
151
|
+
* Sets the playback speed of the animation.
|
|
152
|
+
* @param speed Playback speed (1 = normal).
|
|
153
|
+
*/
|
|
154
|
+
set speed(speed: number);
|
|
155
|
+
/**
|
|
156
|
+
* Gets the current playback speed.
|
|
157
|
+
* @returns Playback speed.
|
|
158
|
+
*/
|
|
159
|
+
get speed(): number;
|
|
160
|
+
/**
|
|
161
|
+
* Sets the playback direction.
|
|
162
|
+
* @param direction 1 for forward, -1 for reverse.
|
|
163
|
+
*/
|
|
164
|
+
set direction(direction: PlaybackDirection);
|
|
165
|
+
/**
|
|
166
|
+
* Gets the current playback direction.
|
|
167
|
+
* @returns Playback direction.
|
|
168
|
+
*/
|
|
169
|
+
get direction(): PlaybackDirection;
|
|
170
|
+
/**
|
|
171
|
+
* Enables or disables looping of the animation.
|
|
172
|
+
* @param loop True to loop, false otherwise.
|
|
173
|
+
*/
|
|
174
|
+
set loop(loop: boolean);
|
|
175
|
+
/**
|
|
176
|
+
* Gets whether the animation is set to loop.
|
|
177
|
+
* @returns True if looping, false otherwise.
|
|
178
|
+
*/
|
|
179
|
+
get loop(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Sets the current frame of the animation.
|
|
182
|
+
* @param frame Frame number.
|
|
183
|
+
*/
|
|
184
|
+
set frame(frame: number);
|
|
185
|
+
/**
|
|
186
|
+
* Gets the current frame of the animation.
|
|
187
|
+
* @returns Current frame number.
|
|
188
|
+
*/
|
|
189
|
+
get frame(): number;
|
|
190
|
+
/**
|
|
191
|
+
* Gets the list of available states for the icon.
|
|
192
|
+
* @returns Array of available states.
|
|
193
|
+
*/
|
|
194
|
+
get availableStates(): IconState[];
|
|
195
|
+
/**
|
|
196
|
+
* Gets the frame rate of the animation.
|
|
197
|
+
* @returns Frame rate in frames per second.
|
|
198
|
+
*/
|
|
199
|
+
get frameRate(): number;
|
|
200
|
+
/**
|
|
201
|
+
* Returns true if the animation is currently playing.
|
|
202
|
+
*/
|
|
203
|
+
get playing(): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Returns true if the player is ready for interaction.
|
|
206
|
+
*/
|
|
207
|
+
get ready(): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Gets the total number of frames in the animation.
|
|
210
|
+
* @returns Frame count.
|
|
211
|
+
*/
|
|
212
|
+
get frameCount(): number;
|
|
213
|
+
/**
|
|
214
|
+
* Gets the current segment of the animation as [start, end] frame numbers.
|
|
215
|
+
* @returns Segment as [start, end].
|
|
216
|
+
*/
|
|
217
|
+
get segment(): [number, number];
|
|
218
|
+
/**
|
|
219
|
+
* Gets the duration of the animation in seconds.
|
|
220
|
+
* @returns Duration in seconds.
|
|
221
|
+
*/
|
|
222
|
+
get duration(): number;
|
|
223
|
+
/**
|
|
224
|
+
* Provides access to the underlying Lottie player instance.
|
|
225
|
+
* @returns LottieAnimationInstance.
|
|
226
|
+
*/
|
|
227
|
+
get lottieInstance(): LottieAnimationInstance | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* Gets all customizable properties for the icon.
|
|
230
|
+
* @returns Array of LottieProperty.
|
|
231
|
+
*/
|
|
232
|
+
get lottieProperties(): LottieProperty[];
|
|
233
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep clone value.
|
|
3
|
+
* @param value Value to clone.
|
|
4
|
+
*/
|
|
5
|
+
export declare function deepClone<T = any>(value: T): T;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if value is null or undefined.
|
|
8
|
+
* @param value Value to check.
|
|
9
|
+
* @returns True if value is null or undefined, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isNil(value: any): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if value is object like.
|
|
14
|
+
* @param value Value to check.
|
|
15
|
+
* @returns True if value is object like, false otherwise.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isObjectLike(value: any): value is object;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if path is a direct property of object.
|
|
20
|
+
* @param object Object to check.
|
|
21
|
+
* @param path Path to check.
|
|
22
|
+
*/
|
|
23
|
+
export declare function has<T>(object: T, path: string | string[]): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the value at the given path from the object.
|
|
26
|
+
* Returns defaultValue if the path does not exist.
|
|
27
|
+
* @param object Object to get value from.
|
|
28
|
+
* @param path Property path as a dot-separated string or array of keys.
|
|
29
|
+
* @param defaultValue Value to return if the path does not exist.
|
|
30
|
+
* @returns Value at the given path or defaultValue.
|
|
31
|
+
*/
|
|
32
|
+
export declare function get<T>(object: T, path: string | string[], defaultValue?: any): any;
|
|
33
|
+
/**
|
|
34
|
+
* Update object value on path.
|
|
35
|
+
* @param object Object to update.
|
|
36
|
+
* @param path Path to the value.
|
|
37
|
+
* @param value New value to set.
|
|
38
|
+
*/
|
|
39
|
+
export declare function set(object: any, path: string | string[], value: any): void;
|
package/examples/03-states.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lordicon/web",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A lightweight and flexible player for seamlessly embedding, controlling, and customizing animated Lordicon icons in any web application.",
|
|
5
5
|
"repository": "https://github.com/lordicondev/player-web",
|
|
6
6
|
"homepage": "https://lordicon.com/",
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@lordicon/internal": "^0.5.0",
|
|
27
|
-
"vite": "^
|
|
28
|
-
"vite-plugin-dts": "^
|
|
29
|
-
"concurrently": "^
|
|
30
|
-
"eslint-config-prettier": "^
|
|
31
|
-
"eslint": "^
|
|
32
|
-
"prettier": "^3.
|
|
33
|
-
"typescript": "^
|
|
34
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
35
|
-
"@typescript-eslint/parser": "^
|
|
27
|
+
"vite": "^8.0.16",
|
|
28
|
+
"vite-plugin-dts": "^5.0.2",
|
|
29
|
+
"concurrently": "^10.0.3",
|
|
30
|
+
"eslint-config-prettier": "^10.1.8",
|
|
31
|
+
"eslint": "^10.5.0",
|
|
32
|
+
"prettier": "^3.8.4",
|
|
33
|
+
"typescript": "^6.0.3",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.61.1",
|
|
35
|
+
"@typescript-eslint/parser": "^8.61.1",
|
|
36
36
|
"@types/node": "^22.13.13"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/player.ts
CHANGED
|
@@ -184,7 +184,7 @@ export class Player {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// Fallback to default state if initial is invalid.
|
|
187
|
-
if (this._initialProperties.state && !this._state) {
|
|
187
|
+
if (this._initialProperties.state && !this._state && this._initialProperties.state !== '*') {
|
|
188
188
|
this._state = this._availableStates.filter(c => c.default)[0];
|
|
189
189
|
}
|
|
190
190
|
}
|
|
@@ -624,6 +624,8 @@ export class Player {
|
|
|
624
624
|
|
|
625
625
|
if (isNil(state)) {
|
|
626
626
|
this._state = this._availableStates.filter(c => c.default)[0];
|
|
627
|
+
} else if (state === '*') {
|
|
628
|
+
this._state = undefined;
|
|
627
629
|
} else if (state) {
|
|
628
630
|
this._state = this._availableStates.filter(c => c.name === state)[0];
|
|
629
631
|
|
package/vite.config.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
1
|
+
import { resolve, sep } from 'path';
|
|
2
2
|
import { defineConfig } from 'vite';
|
|
3
3
|
import dts from 'vite-plugin-dts';
|
|
4
4
|
|
|
5
5
|
export default defineConfig({
|
|
6
6
|
plugins: [
|
|
7
7
|
dts({
|
|
8
|
-
|
|
8
|
+
insertTypesEntry: true,
|
|
9
|
+
beforeWriteFile: (filePath, content) => {
|
|
10
|
+
return {
|
|
11
|
+
filePath: filePath.replace(`${sep}dist${sep}src${sep}`, `${sep}dist${sep}`),
|
|
12
|
+
content,
|
|
13
|
+
};
|
|
14
|
+
},
|
|
9
15
|
}),
|
|
10
16
|
],
|
|
11
17
|
build: {
|