@lordicon/utils-lottie 1.3.0 → 1.4.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.
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Icon data in JSON format.
2
+ * Any Lottie JSON, untyped. The older functions take it; `IconData` describes the file for
3
+ * new code.
3
4
  */
4
5
  export type LottieData = any;
5
6
  /**
package/dist/lottie.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { IconData } from './icon-data';
1
2
  import { ColorMap, LottieAnimationInstance, LottieData, LottieProperty, RgbColor, RgbTuple } from './interfaces';
2
3
  /**
3
4
  * Converts an RGB color object to a hexadecimal color string.
@@ -47,12 +48,27 @@ export declare function resetLottieProperties(data: LottieData | LottieAnimation
47
48
  */
48
49
  export declare function updateLottieProperties(data: LottieData | LottieAnimationInstance, properties: LottieProperty[], value: any): void;
49
50
  /**
50
- * Remaps colors in Lottie data according to the provided color map.
51
- * @param data Lottie data to remap colors in.
52
- * @param colors Color map where keys are original colors in hex format and values are new colors in hex format.
53
- * @returns Lottie data with colors remapped according to the provided color map.
51
+ * The icon's own colors, by name: `{ primary: '#121331', secondary: '#08a88a' }`.
52
+ * @param data Lottie data.
53
+ */
54
+ export declare function defaultColors(data: LottieData): ColorMap;
55
+ /**
56
+ * Replaces colours in Lottie data, matched by the icon's own colours: `{ '#121331': 'red' }`.
57
+ * Keys and values may be any hex value or CSS colour name; ones that are not colours are
58
+ * skipped.
59
+ *
60
+ * Changes `data` in place and returns the same object, not a copy. To keep the original,
61
+ * pass a copy: `remapColors(structuredClone(data), colors)`.
54
62
  */
55
63
  export declare function remapColors(data: LottieData, colors: ColorMap): LottieData;
64
+ /**
65
+ * The icon's colours to change, by name, from a map keyed by the icon's own colours:
66
+ * `{ '#121331': 'red' }` gives `{ primary: '#ff0000' }` for an icon whose primary is `#121331`.
67
+ * For the player's `colors` or the `colors` attribute.
68
+ */
69
+ export declare function colorsByName(data: IconData, colors: ColorMap): ColorMap;
70
+ /** True when the icon's stroke width can be changed: it has a `stroke` or `stroke-layers` effect. */
71
+ export declare function hasStroke(data: IconData): boolean;
56
72
  /**
57
73
  * Recursively removes expressions from Lottie data by deleting "x" properties that contain expressions.
58
74
  * @param data Lottie data to remove expressions from.
package/dist/parsers.d.ts CHANGED
@@ -1,40 +1,43 @@
1
1
  import { ColorMap } from './interfaces.js';
2
2
  /**
3
- * Returns a hexadecimal color string for a given color name or hex code.
3
+ * A `#rrggbb` colour for a hex value or a CSS colour name, and black for anything else.
4
+ * @deprecated Use `resolveColor()`, which says when a value is not a colour.
5
+ */
6
+ export declare function parseColor(colorName: string): string;
7
+ /**
8
+ * A `#rrggbb` color for a hex value (`#0f0` or `#00ff00`) or a CSS color name. Null when the
9
+ * value is neither, where `parseColor()` would give black.
10
+ */
11
+ export declare function resolveColor(value: string): string | null;
12
+ /**
13
+ * Parses a `colors` attribute into a colour map. Names are lower-cased, colours come out as
14
+ * `#rrggbb`, and a pair whose colour is not a colour is left out.
4
15
  *
5
- * Example:
6
16
  * ```js
7
- * parseColor('red'); // "#ff0000"
8
- * parseColor('#0f0'); // "#00ff00"
17
+ * parseColors('primary:red, secondary:#0f0'); // { primary: '#ff0000', secondary: '#00ff00' }
9
18
  * ```
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
19
  */
14
- export declare function parseColor(colorName: string): string;
20
+ export declare function parseColors(colors: string): ColorMap | undefined;
15
21
  /**
16
- * Parses a colors attribute string into a ColorMap object.
22
+ * Writes a colour map the way `parseColors()` reads it, with every colour as `#rrggbb`.
23
+ * Colours that are not colours are left out.
17
24
  *
18
- * Example:
19
25
  * ```js
20
- * parseColors('primary:red,secondary:#00ff00');
21
- * // Returns: { primary: '#ff0000', secondary: '#00ff00' }
26
+ * formatColors({ primary: 'red', secondary: '#0f0' }); // 'primary:#ff0000,secondary:#00ff00'
22
27
  * ```
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
28
  */
27
- export declare function parseColors(colors: string): ColorMap | undefined;
29
+ export declare function formatColors(colors: ColorMap): string;
28
30
  /**
29
31
  * Parses a stroke attribute value to a supported numeric range.
30
32
  *
31
33
  * @param value Stroke value as a string or number ("light", 1, "1", "regular", 2, "2", "bold", 3, "3").
32
34
  * @returns Stroke value as 1, 2, or 3, or undefined if not valid.
33
35
  */
34
- export declare function parseStroke(value: string | number): (1 | 2 | 3 | undefined);
36
+ export declare function parseStroke(value: string | number): 1 | 2 | 3 | undefined;
35
37
  /**
36
- * Parse state attribute.
37
- * @param value State value.
38
- * @returns Returns the state as a string if valid, otherwise undefined.
38
+ * The name of a stroke width: 1, `'1'` and `'light'` give `'light'`. Null when the value is
39
+ * not a stroke width.
39
40
  */
40
- export declare function parseState(value: any): (string | undefined);
41
+ export declare function strokeName(value: string | number): 'light' | 'regular' | 'bold' | null;
42
+ /** @deprecated Returns a string as it is; nothing to parse. */
43
+ export declare function parseState(value: any): string | undefined;
package/dist/states.d.ts CHANGED
@@ -5,3 +5,34 @@ import { IconState, LottieData } from './interfaces.js';
5
5
  * @returns Array of icon states extracted from the data.
6
6
  */
7
7
  export declare function readStates(data: LottieData): IconState[];
8
+ /** A frame range `[start, end)`. The end is exclusive, as `setSegment()` takes it. */
9
+ export type Segment = [number, number];
10
+ /** The frames of a state. `+ 1` keeps the state's last frame in the segment. */
11
+ export declare function stateSegment(state: IconState): Segment;
12
+ /**
13
+ * The split ratio a morph marker carries: `morph-close:0.5` gives 0.5. Null without one, or
14
+ * when it is not between 0 and 1 (both excluded).
15
+ */
16
+ export declare function stateRatio(state: IconState): number | null;
17
+ /**
18
+ * Splits a state in two at a ratio: the way to the second look, and the way back. `ratio`
19
+ * overrides the one in the marker. Null when neither gives one between 0 and 1, or the state
20
+ * is a single frame. Each half keeps at least one frame.
21
+ */
22
+ export declare function splitSegment(state: IconState, ratio?: number): [Segment, Segment] | null;
23
+ /** The state with this exact name, or the first one whose name starts with it. */
24
+ export declare function findState(states: IconState[], name: string): IconState | null;
25
+ /** What kind of animation a state is, from its name: `morph-select` is a `morph`. */
26
+ export type StateType = 'in' | 'hover' | 'morph' | 'loop';
27
+ /**
28
+ * The kind of a state, from the prefix of its name: `in`, `hover`, `morph` or `loop`. Takes a
29
+ * state or a name, with or without a `default:` flag. Null for any other prefix.
30
+ */
31
+ export declare function stateType(state: IconState | string): StateType | null;
32
+ /**
33
+ * The frame a state ends on: its last frame, or for a morph with a ratio the last frame of
34
+ * the first half, where the icon holds its second look. `ratio` overrides the marker's.
35
+ */
36
+ export declare function stateEndFrame(state: IconState, ratio?: number): number;
37
+ /** The state marked `default:`, or null. */
38
+ export declare function defaultState(states: IconState[]): IconState | null;
package/dist/utils.d.ts CHANGED
@@ -31,7 +31,7 @@ export declare function has<T>(object: T, path: string | string[]): boolean;
31
31
  */
32
32
  export declare function get<T>(object: T, path: string | string[], defaultValue?: any): any;
33
33
  /**
34
- * Update object value on path.
34
+ * Sets the value at a path. Does nothing when a step on the way is missing or not an object.
35
35
  * @param object Object to update.
36
36
  * @param path Path to the value.
37
37
  * @param value New value to set.
package/package.json CHANGED
@@ -1,39 +1,58 @@
1
1
  {
2
2
  "name": "@lordicon/utils-lottie",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
+ "description": "Utilities for Lordicon Lottie files: states, colours, stroke and customised copies of an icon.",
4
5
  "author": "Lordicon <dev@lordicon.com>",
5
6
  "homepage": "https://lordicon.com/",
6
7
  "repository": "https://github.com/lordicondev/utils-lottie",
7
8
  "license": "MIT",
8
9
  "private": false,
9
- "sideEffects": false,
10
10
  "type": "module",
11
- "main": "dist/index.js",
12
- "types": "dist/index.d.ts",
11
+ "sideEffects": false,
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
13
21
  "files": [
14
- "dist/**/*",
15
- "README.md"
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE.md",
25
+ "CHANGELOG.md"
16
26
  ],
17
27
  "keywords": [
18
28
  "lordicon",
19
29
  "lottie"
20
30
  ],
31
+ "engines": {
32
+ "node": ">=20"
33
+ },
21
34
  "scripts": {
22
35
  "start": "vite --config vite-examples.config.ts",
23
36
  "build": "vite build",
24
- "prepack": "npm run build",
25
- "test": "vitest"
37
+ "test": "vitest run",
38
+ "lint": "eslint .",
39
+ "format": "prettier --write .",
40
+ "format:check": "prettier --check .",
41
+ "check:types": "tsc --noEmit",
42
+ "check": "npm run check:types && npm run lint && npm run format:check",
43
+ "prepack": "npm run build"
26
44
  },
27
- "dependencies": {},
28
45
  "devDependencies": {
46
+ "@eslint/js": "^10.0.1",
29
47
  "@lordicon/internal": "^0.5.0",
30
- "@types/node": "^22.9.0",
31
- "typescript": "~5.6.2",
32
- "vite": "^6.2.3",
33
- "vite-plugin-dts": "^4.5.4",
34
- "vitest": "^3.2.3"
35
- },
36
- "engines": {
37
- "node": ">=20.0.0"
48
+ "@types/node": "^26.6.2",
49
+ "eslint": "^10.11.0",
50
+ "globals": "^17.12.0",
51
+ "prettier": "^3.9.9",
52
+ "typescript": "^6.0.3",
53
+ "typescript-eslint": "^8.70.1",
54
+ "vite": "^8.3.0",
55
+ "vite-plugin-dts": "^5.1.1",
56
+ "vitest": "^5.0.1"
38
57
  }
39
- }
58
+ }