@lordicon/utils-lottie 0.9.5 → 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.
@@ -1,9 +1,7 @@
1
- The MIT License
1
+ The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2025 Lordicon
4
4
 
5
- ====
6
-
7
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
6
  of this software and associated documentation files (the "Software"), to deal
9
7
  in the Software without restriction, including without limitation the rights
@@ -20,11 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
24
-
25
- ====
26
-
27
- Files located in the node_modules and encoders directories are externally
28
- maintained libraries used by this software which have their own
29
- licenses; we recommend you read them, as their terms may differ from the
30
- terms above.
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const S = {
1
+ const O = {
2
2
  aliceblue: "#f0f8ff",
3
3
  antiquewhite: "#faebd7",
4
4
  aqua: "#00ffff",
@@ -141,13 +141,13 @@ const S = {
141
141
  yellow: "#ffff00",
142
142
  yellowgreen: "#9acd32"
143
143
  };
144
- function y(e) {
145
- return e.startsWith("#") ? e.length === 4 ? `#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}` : e : S[e.toLowerCase()] || "#000000";
144
+ function h(e) {
145
+ return e.startsWith("#") ? e.length === 4 ? `#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}` : e : O[e.toLowerCase()] || "#000000";
146
146
  }
147
- function H(e) {
147
+ function U(e) {
148
148
  return !e || typeof e != "string" ? void 0 : e.split(",").filter((r) => r).map((r) => r.split(":")).filter((r) => r.length == 2).reduce((r, t) => {
149
149
  const o = t[0];
150
- return r[o.toLowerCase()] = y(t[1]), r;
150
+ return r[o.toLowerCase()] = h(t[1]), r;
151
151
  }, {});
152
152
  }
153
153
  function C(e) {
@@ -158,14 +158,14 @@ function C(e) {
158
158
  if (e === "bold" || e === 3 || e === "3")
159
159
  return 3;
160
160
  }
161
- function $(e) {
161
+ function S(e) {
162
162
  if (typeof e == "string")
163
163
  return e;
164
164
  }
165
165
  function j(e) {
166
166
  return structuredClone(e);
167
167
  }
168
- function R(e) {
168
+ function H(e) {
169
169
  return e == null;
170
170
  }
171
171
  function m(e) {
@@ -181,7 +181,7 @@ function z(e, f) {
181
181
  }
182
182
  return !0;
183
183
  }
184
- function U(e, f, r) {
184
+ function F(e, f, r) {
185
185
  const t = Array.isArray(f) ? f : f.split(".");
186
186
  let o = e;
187
187
  for (const n of t) {
@@ -207,10 +207,10 @@ function d(e) {
207
207
  function g(e) {
208
208
  return Math.round(e * 255);
209
209
  }
210
- function B(e) {
210
+ function E(e) {
211
211
  return "#" + k(e.r) + k(e.g) + k(e.b);
212
212
  }
213
- function q(e) {
213
+ function P(e) {
214
214
  let f = parseInt(e[0] != "#" ? e : e.substring(1), 16);
215
215
  return {
216
216
  r: f >> 16 & 255,
@@ -218,40 +218,40 @@ function q(e) {
218
218
  b: f & 255
219
219
  };
220
220
  }
221
- function h(e) {
221
+ function y(e) {
222
222
  const {
223
223
  r: f,
224
224
  g: r,
225
225
  b: t
226
- } = q(e);
226
+ } = P(e);
227
227
  return [d(f), d(r), d(t)];
228
228
  }
229
- function E(e) {
229
+ function T(e) {
230
230
  const f = {
231
231
  r: g(e[0]),
232
232
  g: g(e[1]),
233
233
  b: g(e[2])
234
234
  };
235
- return B(f);
235
+ return E(f);
236
236
  }
237
- function x(e, { lottieInstance: f } = {}) {
237
+ function $(e, { lottieInstance: f } = {}) {
238
238
  const r = [];
239
239
  return !e || !e.layers || e.layers.forEach((t, o) => {
240
240
  !t.nm || !t.ef || t.ef.forEach((n, s) => {
241
241
  var b, w, A;
242
- const i = (A = (w = (b = n == null ? void 0 : n.ef) == null ? void 0 : b[0]) == null ? void 0 : w.v) == null ? void 0 : A.k;
243
- if (i === void 0)
242
+ const c = (A = (w = (b = n == null ? void 0 : n.ef) == null ? void 0 : b[0]) == null ? void 0 : w.v) == null ? void 0 : A.k;
243
+ if (c === void 0)
244
244
  return;
245
- let c;
246
- f ? c = `renderer.elements.${o}.effectsManager.effectElements.${s}.effectElements.0.p.v` : c = `layers.${o}.ef.${s}.ef.0.v.k`;
245
+ let i;
246
+ f ? i = `renderer.elements.${o}.effectsManager.effectElements.${s}.effectElements.0.p.v` : i = `layers.${o}.ef.${s}.ef.0.v.k`;
247
247
  let l;
248
248
  if (n.mn === "ADBE Color Control" ? l = "color" : n.mn === "ADBE Slider Control" ? l = "slider" : n.mn === "ADBE Point Control" ? l = "point" : n.mn === "ADBE Checkbox Control" ? l = "checkbox" : n.mn.startsWith("Pseudo/") && (l = "feature"), !l)
249
249
  return;
250
250
  const u = n.nm.toLowerCase();
251
251
  r.push({
252
252
  name: u,
253
- path: c,
254
- value: i,
253
+ path: i,
254
+ value: c,
255
255
  type: l
256
256
  });
257
257
  });
@@ -261,17 +261,17 @@ function W(e, f) {
261
261
  for (const r of f)
262
262
  a(e, r.path, r.value);
263
263
  }
264
- function O(e, f, r) {
264
+ function x(e, f, r) {
265
265
  for (const t of f)
266
- t.type === "color" ? typeof r == "object" && "r" in r && "g" in r && "b" in r ? a(e, t.path, [d(r.r), d(r.g), d(r.b)]) : Array.isArray(r) ? a(e, t.path, r) : typeof r == "string" && a(e, t.path, h(y(r))) : t.type === "point" ? typeof r == "object" && "x" in r && "y" in r ? (a(e, t.path + ".0", r.x), a(e, t.path + ".1", r.y)) : Array.isArray(r) && (a(e, t.path + ".0", r[0]), a(e, t.path + ".1", r[1])) : a(e, t.path, r);
266
+ t.type === "color" ? typeof r == "object" && "r" in r && "g" in r && "b" in r ? a(e, t.path, [d(r.r), d(r.g), d(r.b)]) : Array.isArray(r) ? a(e, t.path, r) : typeof r == "string" && a(e, t.path, y(h(r))) : t.type === "point" ? typeof r == "object" && "x" in r && "y" in r ? (a(e, t.path + ".0", r.x), a(e, t.path + ".1", r.y)) : Array.isArray(r) && (a(e, t.path + ".0", r[0]), a(e, t.path + ".1", r[1])) : a(e, t.path, r);
267
267
  }
268
268
  function v(e, f) {
269
269
  if (Object.keys(f).length > 0) {
270
- const t = x(e).filter((o) => o.type === "color");
270
+ const t = $(e).filter((o) => o.type === "color");
271
271
  for (const o of t) {
272
- const n = E(o.value);
273
- for (const [s, i] of Object.entries(f))
274
- n === s && a(e, o.path, h(i));
272
+ const n = T(o.value);
273
+ for (const [s, c] of Object.entries(f))
274
+ n === s && a(e, o.path, y(c));
275
275
  }
276
276
  return e;
277
277
  } else
@@ -285,7 +285,7 @@ function p(e, f) {
285
285
  }
286
286
  return e.x && typeof e.x == "string" && e.x.includes(f) && r.push(e), r;
287
287
  }
288
- function L(e, f, r) {
288
+ function q(e, f, r) {
289
289
  const t = C(r);
290
290
  if (!t)
291
291
  return;
@@ -297,55 +297,61 @@ function L(e, f, r) {
297
297
  3: p(e, "effect('stroke-layers')('Menu') == 3")
298
298
  };
299
299
  for (const s of [1, 2, 3])
300
- for (const i of n[s])
301
- s == t ? i.k = 100 : i.k = 0;
300
+ for (const c of n[s])
301
+ s == t ? c.k = 100 : c.k = 0;
302
302
  } else if (o.includes("stroke")) {
303
- const n = /\$bm_div\(value,[ ]{0,}([0-9]+)\)/gm, s = f.filter((c) => c.name === "stroke")[0], i = p(e, "effect('stroke')('Menu')");
304
- for (const c of i) {
303
+ const n = /\$bm_div\(value,[ ]{0,}([0-9]+)\)/gm, s = f.filter((i) => i.name === "stroke")[0], c = p(e, "effect('stroke')('Menu')");
304
+ for (const i of c) {
305
305
  const l = s && s.value ? t / s.value : t;
306
- if (m(c.k) && Array.isArray(c.k))
307
- for (const u of c.k)
306
+ if (m(i.k) && Array.isArray(i.k))
307
+ for (const u of i.k)
308
308
  Array.isArray(u.s) && (u.s = u.s.map((b) => b * l));
309
309
  else
310
- c.k = c.k * l;
311
- c.x = c.x.replace(n, `$bm_div(value, ${t})`);
310
+ i.k = i.k * l;
311
+ i.x = i.x.replace(n, `$bm_div(value, ${t})`);
312
312
  }
313
313
  }
314
314
  for (const n of f)
315
- (n.name === "stroke" || n.name === "stroke-layers") && O(e, [n], t);
315
+ (n.name === "stroke" || n.name === "stroke-layers") && x(e, [n], t);
316
316
  }
317
- function P(e, f, r) {
317
+ function L(e, f, r) {
318
318
  for (const t of Object.keys(r)) {
319
- const o = y(r[t]), n = p(e, `effect('${t}')('Color')`);
319
+ const o = h(r[t]), n = p(e, `effect('${t}')('Color')`);
320
320
  for (const s of n)
321
- s.k = [...h(o), 1];
321
+ s.k = [...y(o), 1];
322
322
  for (const s of f)
323
- s.name === t && O(e, [s], o);
323
+ s.name === t && x(e, [s], o);
324
324
  }
325
325
  }
326
- function M(e, f, r) {
327
- const t = $(r);
326
+ function B(e, f, r) {
327
+ const t = S(r);
328
328
  if (t)
329
329
  for (const o of e.markers || []) {
330
- const [n, s] = o.cm.split(":"), i = s || n;
331
- o.cm = i, i === t && (o.cm = `default:${i}`, e.ip = o.tm, e.op = o.tm + o.dr);
330
+ const n = o.cm.split(":");
331
+ n[0] === "default" && n.shift();
332
+ const [s, ...c] = n;
333
+ o.cm = s, s === t && (o.cm = [
334
+ "default",
335
+ s,
336
+ ...c
337
+ ].join(":"), e.ip = o.tm, e.op = o.tm + o.dr);
332
338
  }
333
339
  }
334
- function T(e, f, r) {
335
- const t = $(r);
340
+ function M(e, f, r) {
341
+ const t = S(r);
336
342
  if (!t)
337
343
  return;
338
344
  const o = (e.markers || []).map((s) => {
339
- const [i, c] = s.cm.split(":");
340
- return c || i;
345
+ const [c, i] = s.cm.split(":");
346
+ return i || c;
341
347
  });
342
348
  t && e.markers && (e.markers = e.markers.filter((s) => {
343
- const [i, c] = s.cm.split(":");
344
- return (c || i) === t;
349
+ const [c, i] = s.cm.split(":");
350
+ return (i || c) === t;
345
351
  }));
346
352
  for (const s of ["assets", "layers"])
347
- e[s] = e[s].filter((i) => {
348
- const [c, l] = i.nm.split(":"), u = l || c;
353
+ e[s] = e[s].filter((c) => {
354
+ const [i, l] = c.nm.split(":"), u = l || i;
349
355
  return o.includes(u) ? u === t : !0;
350
356
  });
351
357
  const n = e.ip;
@@ -366,46 +372,58 @@ function _(e, f, r) {
366
372
  };
367
373
  for (const n of ["assets", "layers"])
368
374
  e[n] = e[n].filter((s) => {
369
- const [i, c] = s.nm.split(":");
370
- return !(c && t && i != o[t]);
375
+ const [c, i] = s.nm.split(":");
376
+ return !(i && t && c != o[t]);
371
377
  });
372
378
  for (const n of f)
373
379
  n.name === "stroke" || n.name;
374
380
  }
375
- function F(e, f, r) {
376
- const t = x(e), o = j(e);
377
- return f.stroke && L(o, t, f.stroke), f.colors && P(o, t, f.colors), f.state && M(o, t, f.state), (r === "partial" || r === "full") && f.stroke && _(o, t, f.stroke), r === "full" && f.state && T(o, t, f.state), o;
381
+ function D(e, f, r) {
382
+ const t = $(e), o = j(e);
383
+ return f.stroke && q(o, t, f.stroke), f.colors && L(o, t, f.colors), f.state && B(o, t, f.state), (r === "partial" || r === "full") && f.stroke && _(o, t, f.stroke), r === "full" && f.state && M(o, t, f.state), o;
378
384
  }
379
- function K(e) {
385
+ const R = ["default"];
386
+ function G(e) {
380
387
  return !e || !e.markers || !Array.isArray(e.markers) ? [] : e.markers.map((f) => {
381
- const [r, t] = f.cm.split(":");
382
- return {
388
+ const r = f.cm.split(":"), t = {
383
389
  time: f.tm,
384
390
  duration: f.dr,
385
- name: t || r,
386
- default: !!(t && r.includes("default"))
391
+ name: "",
392
+ default: !1,
393
+ params: []
387
394
  };
395
+ for (; R.includes(r[0]); ) {
396
+ switch (r[0]) {
397
+ case "default":
398
+ t.default = !0;
399
+ break;
400
+ default:
401
+ throw new Error(`Unsupported state flag: ${r[0]}`);
402
+ }
403
+ r.shift();
404
+ }
405
+ return t.name = r[0], t.params = r.slice(1, r.length), t;
388
406
  });
389
407
  }
390
408
  export {
391
- F as customizeIcon,
409
+ D as customizeIcon,
392
410
  j as deepClone,
393
- x as extractLottieProperties,
394
- U as get,
411
+ $ as extractLottieProperties,
412
+ F as get,
395
413
  z as has,
396
- q as hexToRgb,
397
- h as hexToTupleColor,
398
- R as isNil,
414
+ P as hexToRgb,
415
+ y as hexToTupleColor,
416
+ H as isNil,
399
417
  m as isObjectLike,
400
- y as parseColor,
401
- H as parseColors,
402
- $ as parseState,
418
+ h as parseColor,
419
+ U as parseColors,
420
+ S as parseState,
403
421
  C as parseStroke,
404
- K as readStates,
422
+ G as readStates,
405
423
  v as remapColors,
406
424
  W as resetLottieProperties,
407
- B as rgbToHex,
425
+ E as rgbToHex,
408
426
  a as set,
409
- E as tupleColorToHex,
410
- O as updateLottieProperties
427
+ T as tupleColorToHex,
428
+ x as updateLottieProperties
411
429
  };
@@ -83,5 +83,6 @@ export interface IconState {
83
83
  name: string;
84
84
  time: number;
85
85
  duration: number;
86
+ params: string[];
86
87
  default?: boolean;
87
88
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lordicon/utils-lottie",
3
- "version": "0.9.5",
4
- "author": "Marcin Baszczewski <marcin@baszczewski.pl> (https://www.baszczewski.pl/)",
3
+ "version": "1.1.0",
4
+ "author": "Lordicon <dev@lordicon.com>",
5
5
  "homepage": "https://lordicon.com/",
6
6
  "repository": "https://github.com/lordicondev/utils-lottie",
7
7
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {},
28
28
  "devDependencies": {
29
- "@lordicon/internal": "^0.2.0",
29
+ "@lordicon/internal": "^0.5.0",
30
30
  "@types/node": "^22.9.0",
31
31
  "typescript": "~5.6.2",
32
32
  "vite": "^6.2.3",