@lordicon/web 1.0.0 → 1.1.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.
@@ -0,0 +1,2 @@
1
+ export type { ColorMap, EventHandler, EventName, IconProperties, IconState, LegacyIconProperties, PlaybackDirection, Stroke } from './interfaces';
2
+ export { Player } from './player';
@@ -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
+ }
@@ -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);