@splendidlabz/utils 1.12.1 → 1.14.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.
Files changed (55) hide show
  1. package/dist/cjs/dom/font-size.cjs +1 -1
  2. package/dist/cjs/dom/index.cjs +7 -2
  3. package/dist/cjs/dom/query-params.cjs +6 -1
  4. package/dist/cjs/lib/colors.cjs +39 -0
  5. package/dist/cjs/lib/date/index.cjs +1 -1
  6. package/dist/cjs/lib/date/time.cjs +1 -1
  7. package/dist/cjs/lib/functions/index.cjs +1 -1
  8. package/dist/cjs/lib/functions/timeout.cjs +1 -1
  9. package/dist/cjs/lib/index.cjs +141 -3
  10. package/dist/cjs/lib/numbers/index.cjs +12 -1
  11. package/dist/cjs/lib/numbers/random.cjs +35 -0
  12. package/dist/cjs/lib/numbers/split-unit.cjs +35 -0
  13. package/dist/cjs/lib/style/index.cjs +35 -1
  14. package/dist/cjs/lib/style/scatter.cjs +60 -0
  15. package/dist/cjs/lib/style/to-style-string.cjs +64 -0
  16. package/dist/cjs/lib/svg/displace.cjs +94 -0
  17. package/dist/cjs/lib/svg/index.cjs +126 -0
  18. package/dist/cjs/lib/svg/noise.cjs +56 -0
  19. package/dist/cjs/node/file-cache.cjs +3 -5
  20. package/dist/cjs/node/index.cjs +3 -5
  21. package/dist/esm/dom/query-params.js +6 -1
  22. package/dist/esm/lib/colors.js +14 -0
  23. package/dist/esm/lib/functions/timeout.js +1 -1
  24. package/dist/esm/lib/index.js +2 -0
  25. package/dist/esm/lib/numbers/index.js +2 -10
  26. package/dist/esm/lib/numbers/random.js +10 -0
  27. package/dist/esm/lib/numbers/split-unit.js +10 -0
  28. package/dist/esm/lib/style/index.js +2 -12
  29. package/dist/esm/lib/style/scatter.js +25 -0
  30. package/dist/esm/lib/style/to-style-string.js +12 -0
  31. package/dist/esm/lib/svg/displace.js +68 -0
  32. package/dist/esm/lib/svg/index.js +2 -0
  33. package/dist/esm/lib/svg/noise.js +16 -0
  34. package/dist/esm/node/file-cache.js +3 -5
  35. package/dist/types/dom/font-size.d.cts +1 -1
  36. package/dist/types/dom/query-params.d.cts +5 -0
  37. package/dist/types/lib/colors.d.cts +12 -0
  38. package/dist/types/lib/functions/timeout.d.cts +1 -1
  39. package/dist/types/lib/index.d.cts +8 -3
  40. package/dist/types/lib/numbers/index.d.cts +2 -4
  41. package/dist/types/lib/numbers/random.d.cts +14 -0
  42. package/dist/types/lib/numbers/split-unit.d.cts +8 -0
  43. package/dist/types/lib/style/index.d.cts +2 -3
  44. package/dist/types/lib/style/scatter.d.cts +48 -0
  45. package/dist/types/lib/style/to-style-string.d.cts +8 -0
  46. package/dist/types/lib/svg/displace.d.cts +54 -0
  47. package/dist/types/lib/svg/index.d.cts +2 -0
  48. package/dist/types/lib/svg/noise.d.cts +24 -0
  49. package/dist/types/node/dirname.d.cts +2 -2
  50. package/dist/types/node/file.d.cts +1 -1
  51. package/dist/types/node/hash.d.cts +1 -1
  52. package/dist/types/node/pkce.d.cts +4 -4
  53. package/dist/types/node/random-string.d.cts +1 -1
  54. package/dist/types/node/uuid.d.cts +1 -1
  55. package/package.json +2 -3
@@ -28,7 +28,7 @@ __export(font_size_exports, {
28
28
  });
29
29
  module.exports = __toCommonJS(font_size_exports);
30
30
 
31
- // src/lib/numbers/index.js
31
+ // src/lib/numbers/split-unit.js
32
32
  function splitUnit(string) {
33
33
  if (typeof string === "number") return [string, null];
34
34
  const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
@@ -705,7 +705,7 @@ function Focusable(container = document.body) {
705
705
  return getFocusableElements(container);
706
706
  }
707
707
 
708
- // src/lib/numbers/index.js
708
+ // src/lib/numbers/split-unit.js
709
709
  function splitUnit(string) {
710
710
  if (typeof string === "number") return [string, null];
711
711
  const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
@@ -1023,8 +1023,13 @@ var queryParams = {
1023
1023
  const searchParams = new URLSearchParams(location.search);
1024
1024
  return searchParams.get(key);
1025
1025
  },
1026
+ /**
1027
+ * Converts a params object into a URL query string
1028
+ * @param {Object} params - Key-value pairs to stringify
1029
+ * @returns {string} URL-encoded query string
1030
+ */
1026
1031
  stringify(params) {
1027
- const searchParams = new URLSearchParams(location.search);
1032
+ const searchParams = new URLSearchParams(params);
1028
1033
  return searchParams.toString();
1029
1034
  }
1030
1035
  };
@@ -27,8 +27,13 @@ var queryParams = {
27
27
  const searchParams = new URLSearchParams(location.search);
28
28
  return searchParams.get(key);
29
29
  },
30
+ /**
31
+ * Converts a params object into a URL query string
32
+ * @param {Object} params - Key-value pairs to stringify
33
+ * @returns {string} URL-encoded query string
34
+ */
30
35
  stringify(params) {
31
- const searchParams = new URLSearchParams(location.search);
36
+ const searchParams = new URLSearchParams(params);
32
37
  return searchParams.toString();
33
38
  }
34
39
  };
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/colors.js
20
+ var colors_exports = {};
21
+ __export(colors_exports, {
22
+ hexToRgb: () => hexToRgb
23
+ });
24
+ module.exports = __toCommonJS(colors_exports);
25
+ function hexToRgb(hex) {
26
+ let h = hex.replace("#", "");
27
+ if (h.length === 3)
28
+ h = h.split("").map((c) => c + c).join("");
29
+ const int = parseInt(h, 16);
30
+ return {
31
+ r: +((int >> 16 & 255) / 255).toFixed(3),
32
+ g: +((int >> 8 & 255) / 255).toFixed(3),
33
+ b: +((int & 255) / 255).toFixed(3)
34
+ };
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ hexToRgb
39
+ });
@@ -119,7 +119,7 @@ var MONTHS = [
119
119
  }
120
120
  ];
121
121
 
122
- // src/lib/numbers/index.js
122
+ // src/lib/numbers/split-unit.js
123
123
  function splitUnit(string) {
124
124
  if (typeof string === "number") return [string, null];
125
125
  const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
@@ -30,7 +30,7 @@ __export(time_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(time_exports);
32
32
 
33
- // src/lib/numbers/index.js
33
+ // src/lib/numbers/split-unit.js
34
34
  function splitUnit(string) {
35
35
  if (typeof string === "number") return [string, null];
36
36
  const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
@@ -117,7 +117,7 @@ function throttle(callback, wait2) {
117
117
 
118
118
  // src/lib/functions/timeout.js
119
119
  function timeout(wait2, callback) {
120
- setTimeout(callback, wait2);
120
+ return setTimeout(callback, wait2);
121
121
  }
122
122
  function delay(ms) {
123
123
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -25,7 +25,7 @@ __export(timeout_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(timeout_exports);
27
27
  function timeout(wait2, callback) {
28
- setTimeout(callback, wait2);
28
+ return setTimeout(callback, wait2);
29
29
  }
30
30
  function delay(ms) {
31
31
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -43,6 +43,8 @@ __export(lib_exports, {
43
43
  curry: () => curry,
44
44
  debounce: () => debounce,
45
45
  delay: () => delay,
46
+ displacePresets: () => displacePresets,
47
+ displaceSettings: () => displaceSettings,
46
48
  extendObject: () => extendObject,
47
49
  flattenArrayFields: () => flattenArrayFields,
48
50
  flattenObject: () => flattenObject,
@@ -55,6 +57,7 @@ __export(lib_exports, {
55
57
  getSymbolValue: () => getSymbolValue,
56
58
  getTimeInMs: () => getTimeInMs,
57
59
  getType: () => getType,
60
+ hexToRgb: () => hexToRgb,
58
61
  isArray: () => isArray,
59
62
  isEmpty: () => isEmpty,
60
63
  isEqual: () => isEqual,
@@ -70,6 +73,8 @@ __export(lib_exports, {
70
73
  markdown: () => markdown,
71
74
  mix: () => mix,
72
75
  ms: () => ms,
76
+ noiseColorMatrix: () => noiseColorMatrix,
77
+ noisePresets: () => noisePresets,
73
78
  normalizeObject: () => normalizeObject,
74
79
  notEmpty: () => notEmpty,
75
80
  notEqual: () => notEqual,
@@ -89,6 +94,8 @@ __export(lib_exports, {
89
94
  sanitize: () => sanitize,
90
95
  sanitizeArray: () => sanitizeArray,
91
96
  sanitizeObject: () => sanitizeObject,
97
+ scatter: () => scatter,
98
+ seededRandom: () => seededRandom,
92
99
  shuffle: () => shuffle,
93
100
  singular: () => singular,
94
101
  sizeOf: () => sizeOf,
@@ -285,6 +292,19 @@ function isFunction(x) {
285
292
  return typeof x === "function";
286
293
  }
287
294
 
295
+ // src/lib/colors.js
296
+ function hexToRgb(hex) {
297
+ let h = hex.replace("#", "");
298
+ if (h.length === 3)
299
+ h = h.split("").map((c) => c + c).join("");
300
+ const int = parseInt(h, 16);
301
+ return {
302
+ r: +((int >> 16 & 255) / 255).toFixed(3),
303
+ g: +((int >> 8 & 255) / 255).toFixed(3),
304
+ b: +((int & 255) / 255).toFixed(3)
305
+ };
306
+ }
307
+
288
308
  // src/lib/date/days.js
289
309
  var DAYS = [
290
310
  { short: "Sun", long: "Sunday", numeric: 1 },
@@ -380,7 +400,16 @@ function toRadians(angle) {
380
400
  return angle * (Math.PI / 180);
381
401
  }
382
402
 
383
- // src/lib/numbers/index.js
403
+ // src/lib/numbers/random.js
404
+ function seededRandom(seed = 1) {
405
+ let state = seed >>> 0;
406
+ return () => {
407
+ state = state * 1664525 + 1013904223 >>> 0;
408
+ return state / 4294967296;
409
+ };
410
+ }
411
+
412
+ // src/lib/numbers/split-unit.js
384
413
  function splitUnit(string) {
385
414
  if (typeof string === "number") return [string, null];
386
415
  const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
@@ -624,7 +653,7 @@ function throttle(callback, wait2) {
624
653
 
625
654
  // src/lib/functions/timeout.js
626
655
  function timeout(wait2, callback) {
627
- setTimeout(callback, wait2);
656
+ return setTimeout(callback, wait2);
628
657
  }
629
658
  function delay(ms2) {
630
659
  return new Promise((resolve) => setTimeout(resolve, ms2));
@@ -1527,7 +1556,30 @@ function stripNumbers(string) {
1527
1556
  return string.replace(/\d*/, "");
1528
1557
  }
1529
1558
 
1530
- // src/lib/style/index.js
1559
+ // src/lib/style/scatter.js
1560
+ var round = (n) => {
1561
+ const value = Math.round(n * 100) / 100;
1562
+ return value === 0 ? 0 : value;
1563
+ };
1564
+ function scatter(count, options = {}) {
1565
+ const { seed = 1, spread = 20, rotation = 6, amount = 1 } = options;
1566
+ const random = seededRandom(seed);
1567
+ const items = [];
1568
+ for (let i = 0; i < count; i++) {
1569
+ const x = round((random() - 0.5) * 2 * spread * amount);
1570
+ const y = round((random() - 0.5) * 2 * spread * amount);
1571
+ const r = round((random() - 0.5) * 2 * rotation * amount);
1572
+ items.push({
1573
+ x,
1574
+ y,
1575
+ rotation: r,
1576
+ transform: `translate(${x}%, ${y}%) rotate(${r}deg)`
1577
+ });
1578
+ }
1579
+ return items;
1580
+ }
1581
+
1582
+ // src/lib/style/to-style-string.js
1531
1583
  function toStyleString(style) {
1532
1584
  if (!style) return null;
1533
1585
  if (typeof style === "string") return style;
@@ -1537,6 +1589,85 @@ function toStyleString(style) {
1537
1589
  }).join("; ").concat(";");
1538
1590
  }
1539
1591
 
1592
+ // src/lib/svg/displace.js
1593
+ var displacePresets = {
1594
+ // Ink bleeding into absorbent paper. Long wavelength, small push.
1595
+ "wet-ink": {
1596
+ type: "fractalNoise",
1597
+ frequency: 0.015,
1598
+ octaves: 3,
1599
+ scale: 9,
1600
+ seed: 2
1601
+ },
1602
+ // Ink bitten into paper tooth. The edge roughens without the letterform
1603
+ // moving, so this is the only preset that survives at body sizes.
1604
+ letterpress: {
1605
+ type: "fractalNoise",
1606
+ frequency: 0.09,
1607
+ octaves: 1,
1608
+ scale: 2,
1609
+ seed: 5
1610
+ },
1611
+ // Air over heat. Anisotropic so the shimmer rises instead of swimming.
1612
+ // Reads as nothing unless animated.
1613
+ "heat-haze": {
1614
+ type: "fractalNoise",
1615
+ frequency: [4e-3, 0.02],
1616
+ animateTo: [6e-3, 0.03],
1617
+ duration: 8,
1618
+ octaves: 2,
1619
+ scale: 7,
1620
+ seed: 11
1621
+ },
1622
+ // Tracking error on worn tape. A near-infinite horizontal wavelength against
1623
+ // a very short vertical one is what tears rather than blobs.
1624
+ "bad-tape": {
1625
+ type: "turbulence",
1626
+ frequency: [8e-4, 0.06],
1627
+ animateTo: [8e-4, 0.09],
1628
+ duration: 2.5,
1629
+ octaves: 1,
1630
+ scale: 14,
1631
+ seed: 3
1632
+ },
1633
+ // Past the shred threshold on purpose.
1634
+ shred: {
1635
+ type: "turbulence",
1636
+ frequency: 0.055,
1637
+ octaves: 2,
1638
+ scale: 32,
1639
+ seed: 7
1640
+ }
1641
+ };
1642
+ var format = (f) => Array.isArray(f) ? f.join(" ") : String(f);
1643
+ function displaceSettings(opts = {}) {
1644
+ const base = opts.preset && displacePresets[opts.preset] || displacePresets["wet-ink"];
1645
+ const frequency = opts.frequency ?? base.frequency;
1646
+ const animateTo = opts.animateTo ?? base.animateTo;
1647
+ return {
1648
+ type: opts.type ?? base.type,
1649
+ frequency: format(frequency),
1650
+ animateTo: animateTo ? format(animateTo) : null,
1651
+ duration: opts.duration ?? base.duration ?? 6,
1652
+ octaves: opts.octaves ?? base.octaves,
1653
+ scale: opts.scale ?? base.scale,
1654
+ seed: opts.seed ?? base.seed
1655
+ };
1656
+ }
1657
+
1658
+ // src/lib/svg/noise.js
1659
+ var noisePresets = {
1660
+ black: "#000000",
1661
+ sepia: "#a67c52",
1662
+ synthwave: "#ff2bd6"
1663
+ };
1664
+ function noiseColorMatrix(color, strength) {
1665
+ if (!color || color === "rainbow")
1666
+ return `1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 ${strength} 0`;
1667
+ const { r, g, b } = hexToRgb(noisePresets[color] ?? color);
1668
+ return `0 0 0 0 ${r} 0 0 0 0 ${g} 0 0 0 0 ${b} 0 0 0 ${strength} 0`;
1669
+ }
1670
+
1540
1671
  // src/lib/symbols/symbols.js
1541
1672
  function getSymbol(object, description) {
1542
1673
  return Object.getOwnPropertySymbols(object).find(
@@ -1562,6 +1693,8 @@ function getSymbolValue(object, description) {
1562
1693
  curry,
1563
1694
  debounce,
1564
1695
  delay,
1696
+ displacePresets,
1697
+ displaceSettings,
1565
1698
  extendObject,
1566
1699
  flattenArrayFields,
1567
1700
  flattenObject,
@@ -1574,6 +1707,7 @@ function getSymbolValue(object, description) {
1574
1707
  getSymbolValue,
1575
1708
  getTimeInMs,
1576
1709
  getType,
1710
+ hexToRgb,
1577
1711
  isArray,
1578
1712
  isEmpty,
1579
1713
  isEqual,
@@ -1589,6 +1723,8 @@ function getSymbolValue(object, description) {
1589
1723
  markdown,
1590
1724
  mix,
1591
1725
  ms,
1726
+ noiseColorMatrix,
1727
+ noisePresets,
1592
1728
  normalizeObject,
1593
1729
  notEmpty,
1594
1730
  notEqual,
@@ -1608,6 +1744,8 @@ function getSymbolValue(object, description) {
1608
1744
  sanitize,
1609
1745
  sanitizeArray,
1610
1746
  sanitizeObject,
1747
+ scatter,
1748
+ seededRandom,
1611
1749
  shuffle,
1612
1750
  singular,
1613
1751
  sizeOf,
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/lib/numbers/index.js
20
20
  var numbers_exports = {};
21
21
  __export(numbers_exports, {
22
+ seededRandom: () => seededRandom,
22
23
  splitUnit: () => splitUnit,
23
24
  toDegrees: () => toDegrees,
24
25
  toRadians: () => toRadians
@@ -33,7 +34,16 @@ function toRadians(angle) {
33
34
  return angle * (Math.PI / 180);
34
35
  }
35
36
 
36
- // src/lib/numbers/index.js
37
+ // src/lib/numbers/random.js
38
+ function seededRandom(seed = 1) {
39
+ let state = seed >>> 0;
40
+ return () => {
41
+ state = state * 1664525 + 1013904223 >>> 0;
42
+ return state / 4294967296;
43
+ };
44
+ }
45
+
46
+ // src/lib/numbers/split-unit.js
37
47
  function splitUnit(string) {
38
48
  if (typeof string === "number") return [string, null];
39
49
  const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
@@ -43,6 +53,7 @@ function splitUnit(string) {
43
53
  }
44
54
  // Annotate the CommonJS export names for ESM import in node:
45
55
  0 && (module.exports = {
56
+ seededRandom,
46
57
  splitUnit,
47
58
  toDegrees,
48
59
  toRadians
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/numbers/random.js
20
+ var random_exports = {};
21
+ __export(random_exports, {
22
+ seededRandom: () => seededRandom
23
+ });
24
+ module.exports = __toCommonJS(random_exports);
25
+ function seededRandom(seed = 1) {
26
+ let state = seed >>> 0;
27
+ return () => {
28
+ state = state * 1664525 + 1013904223 >>> 0;
29
+ return state / 4294967296;
30
+ };
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ seededRandom
35
+ });
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/numbers/split-unit.js
20
+ var split_unit_exports = {};
21
+ __export(split_unit_exports, {
22
+ splitUnit: () => splitUnit
23
+ });
24
+ module.exports = __toCommonJS(split_unit_exports);
25
+ function splitUnit(string) {
26
+ if (typeof string === "number") return [string, null];
27
+ const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
28
+ const match = string.match(regex);
29
+ if (match) return [parseFloat(match[1]), match[2]];
30
+ return [parseFloat(string), null];
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ splitUnit
35
+ });
@@ -19,10 +19,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/lib/style/index.js
20
20
  var style_exports = {};
21
21
  __export(style_exports, {
22
+ scatter: () => scatter,
22
23
  toStyleString: () => toStyleString
23
24
  });
24
25
  module.exports = __toCommonJS(style_exports);
25
26
 
27
+ // src/lib/numbers/random.js
28
+ function seededRandom(seed = 1) {
29
+ let state = seed >>> 0;
30
+ return () => {
31
+ state = state * 1664525 + 1013904223 >>> 0;
32
+ return state / 4294967296;
33
+ };
34
+ }
35
+
36
+ // src/lib/style/scatter.js
37
+ var round = (n) => {
38
+ const value = Math.round(n * 100) / 100;
39
+ return value === 0 ? 0 : value;
40
+ };
41
+ function scatter(count, options = {}) {
42
+ const { seed = 1, spread = 20, rotation = 6, amount = 1 } = options;
43
+ const random = seededRandom(seed);
44
+ const items = [];
45
+ for (let i = 0; i < count; i++) {
46
+ const x = round((random() - 0.5) * 2 * spread * amount);
47
+ const y = round((random() - 0.5) * 2 * spread * amount);
48
+ const r = round((random() - 0.5) * 2 * rotation * amount);
49
+ items.push({
50
+ x,
51
+ y,
52
+ rotation: r,
53
+ transform: `translate(${x}%, ${y}%) rotate(${r}deg)`
54
+ });
55
+ }
56
+ return items;
57
+ }
58
+
26
59
  // src/lib/strings/convert-case/convert-case.js
27
60
  function toKebab(string) {
28
61
  if (!string) return "";
@@ -49,7 +82,7 @@ function isDigit(char) {
49
82
  return /[0-9]/.test(char);
50
83
  }
51
84
 
52
- // src/lib/style/index.js
85
+ // src/lib/style/to-style-string.js
53
86
  function toStyleString(style) {
54
87
  if (!style) return null;
55
88
  if (typeof style === "string") return style;
@@ -60,5 +93,6 @@ function toStyleString(style) {
60
93
  }
61
94
  // Annotate the CommonJS export names for ESM import in node:
62
95
  0 && (module.exports = {
96
+ scatter,
63
97
  toStyleString
64
98
  });
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/style/scatter.js
20
+ var scatter_exports = {};
21
+ __export(scatter_exports, {
22
+ scatter: () => scatter
23
+ });
24
+ module.exports = __toCommonJS(scatter_exports);
25
+
26
+ // src/lib/numbers/random.js
27
+ function seededRandom(seed = 1) {
28
+ let state = seed >>> 0;
29
+ return () => {
30
+ state = state * 1664525 + 1013904223 >>> 0;
31
+ return state / 4294967296;
32
+ };
33
+ }
34
+
35
+ // src/lib/style/scatter.js
36
+ var round = (n) => {
37
+ const value = Math.round(n * 100) / 100;
38
+ return value === 0 ? 0 : value;
39
+ };
40
+ function scatter(count, options = {}) {
41
+ const { seed = 1, spread = 20, rotation = 6, amount = 1 } = options;
42
+ const random = seededRandom(seed);
43
+ const items = [];
44
+ for (let i = 0; i < count; i++) {
45
+ const x = round((random() - 0.5) * 2 * spread * amount);
46
+ const y = round((random() - 0.5) * 2 * spread * amount);
47
+ const r = round((random() - 0.5) * 2 * rotation * amount);
48
+ items.push({
49
+ x,
50
+ y,
51
+ rotation: r,
52
+ transform: `translate(${x}%, ${y}%) rotate(${r}deg)`
53
+ });
54
+ }
55
+ return items;
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ scatter
60
+ });
@@ -0,0 +1,64 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/lib/style/to-style-string.js
20
+ var to_style_string_exports = {};
21
+ __export(to_style_string_exports, {
22
+ toStyleString: () => toStyleString
23
+ });
24
+ module.exports = __toCommonJS(to_style_string_exports);
25
+
26
+ // src/lib/strings/convert-case/convert-case.js
27
+ function toKebab(string) {
28
+ if (!string) return "";
29
+ return string.split("").map((letter, index) => {
30
+ const previousLetter = string[index - 1] || "";
31
+ const currentLetter = letter;
32
+ if (isDigit(currentLetter) && !isDigit(previousLetter)) {
33
+ return `-${currentLetter}`;
34
+ }
35
+ if (!isCaps(currentLetter)) return currentLetter;
36
+ if (previousLetter === "") {
37
+ return `${currentLetter.toLowerCase()}`;
38
+ }
39
+ if (isCaps(previousLetter)) {
40
+ return `${currentLetter.toLowerCase()}`;
41
+ }
42
+ return `-${currentLetter.toLowerCase()}`;
43
+ }).join("").trim().replace(/[-_\s]+/g, "-");
44
+ }
45
+ function isCaps(char) {
46
+ return /\p{Lu}/u.test(char);
47
+ }
48
+ function isDigit(char) {
49
+ return /[0-9]/.test(char);
50
+ }
51
+
52
+ // src/lib/style/to-style-string.js
53
+ function toStyleString(style) {
54
+ if (!style) return null;
55
+ if (typeof style === "string") return style;
56
+ return Object.entries(style).map(([k, v]) => {
57
+ if (k.startsWith("--")) return `${k}:${v}`;
58
+ else return `${toKebab(k)}:${v}`;
59
+ }).join("; ").concat(";");
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ toStyleString
64
+ });