@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
@@ -0,0 +1,94 @@
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/svg/displace.js
20
+ var displace_exports = {};
21
+ __export(displace_exports, {
22
+ displacePresets: () => displacePresets,
23
+ displaceSettings: () => displaceSettings
24
+ });
25
+ module.exports = __toCommonJS(displace_exports);
26
+ var displacePresets = {
27
+ // Ink bleeding into absorbent paper. Long wavelength, small push.
28
+ "wet-ink": {
29
+ type: "fractalNoise",
30
+ frequency: 0.015,
31
+ octaves: 3,
32
+ scale: 9,
33
+ seed: 2
34
+ },
35
+ // Ink bitten into paper tooth. The edge roughens without the letterform
36
+ // moving, so this is the only preset that survives at body sizes.
37
+ letterpress: {
38
+ type: "fractalNoise",
39
+ frequency: 0.09,
40
+ octaves: 1,
41
+ scale: 2,
42
+ seed: 5
43
+ },
44
+ // Air over heat. Anisotropic so the shimmer rises instead of swimming.
45
+ // Reads as nothing unless animated.
46
+ "heat-haze": {
47
+ type: "fractalNoise",
48
+ frequency: [4e-3, 0.02],
49
+ animateTo: [6e-3, 0.03],
50
+ duration: 8,
51
+ octaves: 2,
52
+ scale: 7,
53
+ seed: 11
54
+ },
55
+ // Tracking error on worn tape. A near-infinite horizontal wavelength against
56
+ // a very short vertical one is what tears rather than blobs.
57
+ "bad-tape": {
58
+ type: "turbulence",
59
+ frequency: [8e-4, 0.06],
60
+ animateTo: [8e-4, 0.09],
61
+ duration: 2.5,
62
+ octaves: 1,
63
+ scale: 14,
64
+ seed: 3
65
+ },
66
+ // Past the shred threshold on purpose.
67
+ shred: {
68
+ type: "turbulence",
69
+ frequency: 0.055,
70
+ octaves: 2,
71
+ scale: 32,
72
+ seed: 7
73
+ }
74
+ };
75
+ var format = (f) => Array.isArray(f) ? f.join(" ") : String(f);
76
+ function displaceSettings(opts = {}) {
77
+ const base = opts.preset && displacePresets[opts.preset] || displacePresets["wet-ink"];
78
+ const frequency = opts.frequency ?? base.frequency;
79
+ const animateTo = opts.animateTo ?? base.animateTo;
80
+ return {
81
+ type: opts.type ?? base.type,
82
+ frequency: format(frequency),
83
+ animateTo: animateTo ? format(animateTo) : null,
84
+ duration: opts.duration ?? base.duration ?? 6,
85
+ octaves: opts.octaves ?? base.octaves,
86
+ scale: opts.scale ?? base.scale,
87
+ seed: opts.seed ?? base.seed
88
+ };
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ displacePresets,
93
+ displaceSettings
94
+ });
@@ -0,0 +1,126 @@
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/svg/index.js
20
+ var svg_exports = {};
21
+ __export(svg_exports, {
22
+ displacePresets: () => displacePresets,
23
+ displaceSettings: () => displaceSettings,
24
+ noiseColorMatrix: () => noiseColorMatrix,
25
+ noisePresets: () => noisePresets
26
+ });
27
+ module.exports = __toCommonJS(svg_exports);
28
+
29
+ // src/lib/svg/displace.js
30
+ var displacePresets = {
31
+ // Ink bleeding into absorbent paper. Long wavelength, small push.
32
+ "wet-ink": {
33
+ type: "fractalNoise",
34
+ frequency: 0.015,
35
+ octaves: 3,
36
+ scale: 9,
37
+ seed: 2
38
+ },
39
+ // Ink bitten into paper tooth. The edge roughens without the letterform
40
+ // moving, so this is the only preset that survives at body sizes.
41
+ letterpress: {
42
+ type: "fractalNoise",
43
+ frequency: 0.09,
44
+ octaves: 1,
45
+ scale: 2,
46
+ seed: 5
47
+ },
48
+ // Air over heat. Anisotropic so the shimmer rises instead of swimming.
49
+ // Reads as nothing unless animated.
50
+ "heat-haze": {
51
+ type: "fractalNoise",
52
+ frequency: [4e-3, 0.02],
53
+ animateTo: [6e-3, 0.03],
54
+ duration: 8,
55
+ octaves: 2,
56
+ scale: 7,
57
+ seed: 11
58
+ },
59
+ // Tracking error on worn tape. A near-infinite horizontal wavelength against
60
+ // a very short vertical one is what tears rather than blobs.
61
+ "bad-tape": {
62
+ type: "turbulence",
63
+ frequency: [8e-4, 0.06],
64
+ animateTo: [8e-4, 0.09],
65
+ duration: 2.5,
66
+ octaves: 1,
67
+ scale: 14,
68
+ seed: 3
69
+ },
70
+ // Past the shred threshold on purpose.
71
+ shred: {
72
+ type: "turbulence",
73
+ frequency: 0.055,
74
+ octaves: 2,
75
+ scale: 32,
76
+ seed: 7
77
+ }
78
+ };
79
+ var format = (f) => Array.isArray(f) ? f.join(" ") : String(f);
80
+ function displaceSettings(opts = {}) {
81
+ const base = opts.preset && displacePresets[opts.preset] || displacePresets["wet-ink"];
82
+ const frequency = opts.frequency ?? base.frequency;
83
+ const animateTo = opts.animateTo ?? base.animateTo;
84
+ return {
85
+ type: opts.type ?? base.type,
86
+ frequency: format(frequency),
87
+ animateTo: animateTo ? format(animateTo) : null,
88
+ duration: opts.duration ?? base.duration ?? 6,
89
+ octaves: opts.octaves ?? base.octaves,
90
+ scale: opts.scale ?? base.scale,
91
+ seed: opts.seed ?? base.seed
92
+ };
93
+ }
94
+
95
+ // src/lib/colors.js
96
+ function hexToRgb(hex) {
97
+ let h = hex.replace("#", "");
98
+ if (h.length === 3)
99
+ h = h.split("").map((c) => c + c).join("");
100
+ const int = parseInt(h, 16);
101
+ return {
102
+ r: +((int >> 16 & 255) / 255).toFixed(3),
103
+ g: +((int >> 8 & 255) / 255).toFixed(3),
104
+ b: +((int & 255) / 255).toFixed(3)
105
+ };
106
+ }
107
+
108
+ // src/lib/svg/noise.js
109
+ var noisePresets = {
110
+ black: "#000000",
111
+ sepia: "#a67c52",
112
+ synthwave: "#ff2bd6"
113
+ };
114
+ function noiseColorMatrix(color, strength) {
115
+ if (!color || color === "rainbow")
116
+ return `1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 ${strength} 0`;
117
+ const { r, g, b } = hexToRgb(noisePresets[color] ?? color);
118
+ return `0 0 0 0 ${r} 0 0 0 0 ${g} 0 0 0 0 ${b} 0 0 0 ${strength} 0`;
119
+ }
120
+ // Annotate the CommonJS export names for ESM import in node:
121
+ 0 && (module.exports = {
122
+ displacePresets,
123
+ displaceSettings,
124
+ noiseColorMatrix,
125
+ noisePresets
126
+ });
@@ -0,0 +1,56 @@
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/svg/noise.js
20
+ var noise_exports = {};
21
+ __export(noise_exports, {
22
+ noiseColorMatrix: () => noiseColorMatrix,
23
+ noisePresets: () => noisePresets
24
+ });
25
+ module.exports = __toCommonJS(noise_exports);
26
+
27
+ // src/lib/colors.js
28
+ function hexToRgb(hex) {
29
+ let h = hex.replace("#", "");
30
+ if (h.length === 3)
31
+ h = h.split("").map((c) => c + c).join("");
32
+ const int = parseInt(h, 16);
33
+ return {
34
+ r: +((int >> 16 & 255) / 255).toFixed(3),
35
+ g: +((int >> 8 & 255) / 255).toFixed(3),
36
+ b: +((int & 255) / 255).toFixed(3)
37
+ };
38
+ }
39
+
40
+ // src/lib/svg/noise.js
41
+ var noisePresets = {
42
+ black: "#000000",
43
+ sepia: "#a67c52",
44
+ synthwave: "#ff2bd6"
45
+ };
46
+ function noiseColorMatrix(color, strength) {
47
+ if (!color || color === "rainbow")
48
+ return `1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 ${strength} 0`;
49
+ const { r, g, b } = hexToRgb(noisePresets[color] ?? color);
50
+ return `0 0 0 0 ${r} 0 0 0 0 ${g} 0 0 0 0 ${b} 0 0 0 ${strength} 0`;
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ noiseColorMatrix,
55
+ noisePresets
56
+ });
@@ -168,17 +168,15 @@ async function fileCache({ dir, file }) {
168
168
  async function getLastModifiedTime(globPath) {
169
169
  let files;
170
170
  if (typeof globPath === "string") {
171
- files = await (0, import_glob.glob)(removeFirstSlash(globPath));
171
+ files = await (0, import_glob.glob)(globPath);
172
172
  }
173
173
  if (Array.isArray(globPath)) {
174
- const a = await Promise.all(
175
- globPath.map((path2) => (0, import_glob.glob)(removeFirstSlash(path2)))
176
- );
174
+ const a = await Promise.all(globPath.map((path2) => (0, import_glob.glob)(path2)));
177
175
  files = a.flat();
178
176
  }
179
177
  const stats = await Promise.all(files.map((file) => import_promises.default.stat(file)));
180
178
  const timestamps = stats.map((stat) => Number(stat.mtimeMs));
181
- const sorted = sort(timestamps, { props: "mtimeMs", reverse: true });
179
+ const sorted = sort(timestamps, { reverse: true });
182
180
  return sorted[0] || 0;
183
181
  }
184
182
  async function getLatestModifiedTime(globPath) {
@@ -189,17 +189,15 @@ async function fileCache({ dir, file }) {
189
189
  async function getLastModifiedTime(globPath) {
190
190
  let files;
191
191
  if (typeof globPath === "string") {
192
- files = await (0, import_glob.glob)(removeFirstSlash(globPath));
192
+ files = await (0, import_glob.glob)(globPath);
193
193
  }
194
194
  if (Array.isArray(globPath)) {
195
- const a = await Promise.all(
196
- globPath.map((path3) => (0, import_glob.glob)(removeFirstSlash(path3)))
197
- );
195
+ const a = await Promise.all(globPath.map((path3) => (0, import_glob.glob)(path3)));
198
196
  files = a.flat();
199
197
  }
200
198
  const stats = await Promise.all(files.map((file) => import_promises.default.stat(file)));
201
199
  const timestamps = stats.map((stat) => Number(stat.mtimeMs));
202
- const sorted = sort(timestamps, { props: "mtimeMs", reverse: true });
200
+ const sorted = sort(timestamps, { reverse: true });
203
201
  return sorted[0] || 0;
204
202
  }
205
203
  async function getLatestModifiedTime(globPath) {
@@ -3,8 +3,13 @@ const queryParams = {
3
3
  const searchParams = new URLSearchParams(location.search);
4
4
  return searchParams.get(key);
5
5
  },
6
+ /**
7
+ * Converts a params object into a URL query string
8
+ * @param {Object} params - Key-value pairs to stringify
9
+ * @returns {string} URL-encoded query string
10
+ */
6
11
  stringify(params) {
7
- const searchParams = new URLSearchParams(location.search);
12
+ const searchParams = new URLSearchParams(params);
8
13
  return searchParams.toString();
9
14
  }
10
15
  };
@@ -0,0 +1,14 @@
1
+ function hexToRgb(hex) {
2
+ let h = hex.replace("#", "");
3
+ if (h.length === 3)
4
+ h = h.split("").map((c) => c + c).join("");
5
+ const int = parseInt(h, 16);
6
+ return {
7
+ r: +((int >> 16 & 255) / 255).toFixed(3),
8
+ g: +((int >> 8 & 255) / 255).toFixed(3),
9
+ b: +((int & 255) / 255).toFixed(3)
10
+ };
11
+ }
12
+ export {
13
+ hexToRgb
14
+ };
@@ -1,5 +1,5 @@
1
1
  function timeout(wait2, callback) {
2
- setTimeout(callback, wait2);
2
+ return setTimeout(callback, wait2);
3
3
  }
4
4
  function delay(ms) {
5
5
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -1,6 +1,7 @@
1
1
  export * from "./arrays/index.js";
2
2
  export * from "./auth/index.js";
3
3
  export * from "./checks.js";
4
+ export * from "./colors.js";
4
5
  export * from "./date/index.js";
5
6
  export * from "./form/index.js";
6
7
  export * from "./functions/index.js";
@@ -12,4 +13,5 @@ export * from "./promises/index.js";
12
13
  export * from "./sse.js";
13
14
  export * from "./strings/index.js";
14
15
  export * from "./style/index.js";
16
+ export * from "./svg/index.js";
15
17
  export * from "./symbols/index.js";
@@ -1,11 +1,3 @@
1
1
  export * from "./math.js";
2
- function splitUnit(string) {
3
- if (typeof string === "number") return [string, null];
4
- const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
5
- const match = string.match(regex);
6
- if (match) return [parseFloat(match[1]), match[2]];
7
- return [parseFloat(string), null];
8
- }
9
- export {
10
- splitUnit
11
- };
2
+ export * from "./random.js";
3
+ export * from "./split-unit.js";
@@ -0,0 +1,10 @@
1
+ function seededRandom(seed = 1) {
2
+ let state = seed >>> 0;
3
+ return () => {
4
+ state = state * 1664525 + 1013904223 >>> 0;
5
+ return state / 4294967296;
6
+ };
7
+ }
8
+ export {
9
+ seededRandom
10
+ };
@@ -0,0 +1,10 @@
1
+ function splitUnit(string) {
2
+ if (typeof string === "number") return [string, null];
3
+ const regex = /(-?\d*\.?\d+)\s*([a-z]+)/i;
4
+ const match = string.match(regex);
5
+ if (match) return [parseFloat(match[1]), match[2]];
6
+ return [parseFloat(string), null];
7
+ }
8
+ export {
9
+ splitUnit
10
+ };
@@ -1,12 +1,2 @@
1
- import { toKebab } from "../strings/convert-case/convert-case.js";
2
- function toStyleString(style) {
3
- if (!style) return null;
4
- if (typeof style === "string") return style;
5
- return Object.entries(style).map(([k, v]) => {
6
- if (k.startsWith("--")) return `${k}:${v}`;
7
- else return `${toKebab(k)}:${v}`;
8
- }).join("; ").concat(";");
9
- }
10
- export {
11
- toStyleString
12
- };
1
+ export * from "./scatter.js";
2
+ export * from "./to-style-string.js";
@@ -0,0 +1,25 @@
1
+ import { seededRandom } from "../numbers/random.js";
2
+ const round = (n) => {
3
+ const value = Math.round(n * 100) / 100;
4
+ return value === 0 ? 0 : value;
5
+ };
6
+ function scatter(count, options = {}) {
7
+ const { seed = 1, spread = 20, rotation = 6, amount = 1 } = options;
8
+ const random = seededRandom(seed);
9
+ const items = [];
10
+ for (let i = 0; i < count; i++) {
11
+ const x = round((random() - 0.5) * 2 * spread * amount);
12
+ const y = round((random() - 0.5) * 2 * spread * amount);
13
+ const r = round((random() - 0.5) * 2 * rotation * amount);
14
+ items.push({
15
+ x,
16
+ y,
17
+ rotation: r,
18
+ transform: `translate(${x}%, ${y}%) rotate(${r}deg)`
19
+ });
20
+ }
21
+ return items;
22
+ }
23
+ export {
24
+ scatter
25
+ };
@@ -0,0 +1,12 @@
1
+ import { toKebab } from "../strings/convert-case/convert-case.js";
2
+ function toStyleString(style) {
3
+ if (!style) return null;
4
+ if (typeof style === "string") return style;
5
+ return Object.entries(style).map(([k, v]) => {
6
+ if (k.startsWith("--")) return `${k}:${v}`;
7
+ else return `${toKebab(k)}:${v}`;
8
+ }).join("; ").concat(";");
9
+ }
10
+ export {
11
+ toStyleString
12
+ };
@@ -0,0 +1,68 @@
1
+ const displacePresets = {
2
+ // Ink bleeding into absorbent paper. Long wavelength, small push.
3
+ "wet-ink": {
4
+ type: "fractalNoise",
5
+ frequency: 0.015,
6
+ octaves: 3,
7
+ scale: 9,
8
+ seed: 2
9
+ },
10
+ // Ink bitten into paper tooth. The edge roughens without the letterform
11
+ // moving, so this is the only preset that survives at body sizes.
12
+ letterpress: {
13
+ type: "fractalNoise",
14
+ frequency: 0.09,
15
+ octaves: 1,
16
+ scale: 2,
17
+ seed: 5
18
+ },
19
+ // Air over heat. Anisotropic so the shimmer rises instead of swimming.
20
+ // Reads as nothing unless animated.
21
+ "heat-haze": {
22
+ type: "fractalNoise",
23
+ frequency: [4e-3, 0.02],
24
+ animateTo: [6e-3, 0.03],
25
+ duration: 8,
26
+ octaves: 2,
27
+ scale: 7,
28
+ seed: 11
29
+ },
30
+ // Tracking error on worn tape. A near-infinite horizontal wavelength against
31
+ // a very short vertical one is what tears rather than blobs.
32
+ "bad-tape": {
33
+ type: "turbulence",
34
+ frequency: [8e-4, 0.06],
35
+ animateTo: [8e-4, 0.09],
36
+ duration: 2.5,
37
+ octaves: 1,
38
+ scale: 14,
39
+ seed: 3
40
+ },
41
+ // Past the shred threshold on purpose.
42
+ shred: {
43
+ type: "turbulence",
44
+ frequency: 0.055,
45
+ octaves: 2,
46
+ scale: 32,
47
+ seed: 7
48
+ }
49
+ };
50
+ const format = (f) => Array.isArray(f) ? f.join(" ") : String(f);
51
+ function displaceSettings(opts = {}) {
52
+ const base = opts.preset && displacePresets[opts.preset] || displacePresets["wet-ink"];
53
+ const frequency = opts.frequency ?? base.frequency;
54
+ const animateTo = opts.animateTo ?? base.animateTo;
55
+ return {
56
+ type: opts.type ?? base.type,
57
+ frequency: format(frequency),
58
+ animateTo: animateTo ? format(animateTo) : null,
59
+ duration: opts.duration ?? base.duration ?? 6,
60
+ octaves: opts.octaves ?? base.octaves,
61
+ scale: opts.scale ?? base.scale,
62
+ seed: opts.seed ?? base.seed
63
+ };
64
+ }
65
+ export {
66
+ displacePresets,
67
+ displaceSettings
68
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./displace.js";
2
+ export * from "./noise.js";
@@ -0,0 +1,16 @@
1
+ import { hexToRgb } from "../colors.js";
2
+ const noisePresets = {
3
+ black: "#000000",
4
+ sepia: "#a67c52",
5
+ synthwave: "#ff2bd6"
6
+ };
7
+ function noiseColorMatrix(color, strength) {
8
+ if (!color || color === "rainbow")
9
+ return `1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 ${strength} 0`;
10
+ const { r, g, b } = hexToRgb(noisePresets[color] ?? color);
11
+ return `0 0 0 0 ${r} 0 0 0 0 ${g} 0 0 0 0 ${b} 0 0 0 ${strength} 0`;
12
+ }
13
+ export {
14
+ noiseColorMatrix,
15
+ noisePresets
16
+ };
@@ -90,17 +90,15 @@ async function fileCache({ dir, file }) {
90
90
  async function getLastModifiedTime(globPath) {
91
91
  let files;
92
92
  if (typeof globPath === "string") {
93
- files = await glob(removeFirstSlash(globPath));
93
+ files = await glob(globPath);
94
94
  }
95
95
  if (Array.isArray(globPath)) {
96
- const a = await Promise.all(
97
- globPath.map((path2) => glob(removeFirstSlash(path2)))
98
- );
96
+ const a = await Promise.all(globPath.map((path2) => glob(path2)));
99
97
  files = a.flat();
100
98
  }
101
99
  const stats = await Promise.all(files.map((file) => fs.stat(file)));
102
100
  const timestamps = stats.map((stat) => Number(stat.mtimeMs));
103
- const sorted = sort(timestamps, { props: "mtimeMs", reverse: true });
101
+ const sorted = sort(timestamps, { reverse: true });
104
102
  return sorted[0] || 0;
105
103
  }
106
104
  async function getLatestModifiedTime(globPath) {
@@ -1,4 +1,4 @@
1
- declare function getUnit(value: any): any;
1
+ declare function getUnit(value: any): string;
2
2
  declare function rem(multiple?: number): number;
3
3
  declare function em(element?: HTMLElement, multiple?: number): number;
4
4
  declare function rlh(multiple?: number): number;
@@ -1,5 +1,10 @@
1
1
  declare namespace queryParams {
2
2
  function get(key: any): string;
3
+ /**
4
+ * Converts a params object into a URL query string
5
+ * @param {Object} params - Key-value pairs to stringify
6
+ * @returns {string} URL-encoded query string
7
+ */
3
8
  function stringify(params: any): string;
4
9
  }
5
10
 
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Parse #rgb or #rrggbb into 0–1 channels (3dp, keeps the data URI short).
3
+ * @param {string} hex
4
+ * @returns {{r: number, g: number, b: number}}
5
+ */
6
+ declare function hexToRgb(hex: string): {
7
+ r: number;
8
+ g: number;
9
+ b: number;
10
+ };
11
+
12
+ export { hexToRgb };
@@ -1,4 +1,4 @@
1
- declare function timeout(wait: any, callback: any): void;
1
+ declare function timeout(wait: any, callback: any): number;
2
2
  declare function delay(ms: any): Promise<any>;
3
3
  declare function wait(ms: any): Promise<any>;
4
4
 
@@ -6,6 +6,7 @@ export { splitArray } from './arrays/split-array.cjs';
6
6
  export { uniqueArray } from './arrays/unique.cjs';
7
7
  export { AuthManager, RouteManager } from './auth/route-manager.cjs';
8
8
  export { getType, isArray, isFunction, isObject, notObject } from './checks.cjs';
9
+ export { hexToRgb } from './colors.cjs';
9
10
  export { DAYS } from './date/days.cjs';
10
11
  export { MONTHS } from './date/months.cjs';
11
12
  export { getTimeInMs, ms, toDays, toHours, toMinutes, toReadableTime, toSeconds, toWeeks } from './date/time.cjs';
@@ -18,7 +19,9 @@ export { throttle } from './functions/throttle.cjs';
18
19
  export { delay, timeout, wait } from './functions/timeout.cjs';
19
20
  export { isHashedValue } from './hash.cjs';
20
21
  export { statusText, statusTexts } from './http/status-text.cjs';
21
- export { splitUnit } from './numbers/index.cjs';
22
+ export { toDegrees, toRadians } from './numbers/math.cjs';
23
+ export { seededRandom } from './numbers/random.cjs';
24
+ export { splitUnit } from './numbers/split-unit.cjs';
22
25
  export { camelCaseKeys } from './objects/camelcase-keys.cjs';
23
26
  export { isEmpty, notEmpty } from './objects/empty.cjs';
24
27
  export { isEqual, notEqual } from './objects/equal.cjs';
@@ -39,6 +42,8 @@ export { markdown, treatMarkdownWhitespace } from './strings/markdown.cjs';
39
42
  export { parseFullName } from './strings/name.cjs';
40
43
  export { createPluralize, isPlural, isSingular, plural, pluralize, singular } from './strings/pluralize.cjs';
41
44
  export { parseQueryString, stripNumbers, toQueryString } from './strings/query-string.cjs';
42
- export { toStyleString } from './style/index.cjs';
45
+ export { ScatterItem, scatter } from './style/scatter.cjs';
46
+ export { toStyleString } from './style/to-style-string.cjs';
47
+ export { DisplacePreset, displacePresets, displaceSettings } from './svg/displace.cjs';
48
+ export { noiseColorMatrix, noisePresets } from './svg/noise.cjs';
43
49
  export { getSymbol, getSymbolValue } from './symbols/symbols.cjs';
44
- export { toDegrees, toRadians } from './numbers/math.cjs';
@@ -1,5 +1,3 @@
1
1
  export { toDegrees, toRadians } from './math.cjs';
2
-
3
- declare function splitUnit(string: any): any[];
4
-
5
- export { splitUnit };
2
+ export { seededRandom } from './random.cjs';
3
+ export { splitUnit } from './split-unit.cjs';