@splendidlabz/utils 1.12.1 → 1.13.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.
- package/dist/cjs/dom/font-size.cjs +1 -1
- package/dist/cjs/dom/index.cjs +1 -1
- package/dist/cjs/lib/colors.cjs +39 -0
- package/dist/cjs/lib/date/index.cjs +1 -1
- package/dist/cjs/lib/date/time.cjs +1 -1
- package/dist/cjs/lib/index.cjs +140 -2
- package/dist/cjs/lib/numbers/index.cjs +12 -1
- package/dist/cjs/lib/numbers/random.cjs +35 -0
- package/dist/cjs/lib/numbers/split-unit.cjs +35 -0
- package/dist/cjs/lib/style/index.cjs +35 -1
- package/dist/cjs/lib/style/scatter.cjs +60 -0
- package/dist/cjs/lib/style/to-style-string.cjs +64 -0
- package/dist/cjs/lib/svg/displace.cjs +94 -0
- package/dist/cjs/lib/svg/index.cjs +126 -0
- package/dist/cjs/lib/svg/noise.cjs +56 -0
- package/dist/esm/lib/colors.js +14 -0
- package/dist/esm/lib/index.js +2 -0
- package/dist/esm/lib/numbers/index.js +2 -10
- package/dist/esm/lib/numbers/random.js +10 -0
- package/dist/esm/lib/numbers/split-unit.js +10 -0
- package/dist/esm/lib/style/index.js +2 -12
- package/dist/esm/lib/style/scatter.js +25 -0
- package/dist/esm/lib/style/to-style-string.js +12 -0
- package/dist/esm/lib/svg/displace.js +68 -0
- package/dist/esm/lib/svg/index.js +2 -0
- package/dist/esm/lib/svg/noise.js +16 -0
- package/dist/types/dom/font-size.d.cts +1 -1
- package/dist/types/lib/colors.d.cts +12 -0
- package/dist/types/lib/index.d.cts +8 -3
- package/dist/types/lib/numbers/index.d.cts +2 -4
- package/dist/types/lib/numbers/random.d.cts +14 -0
- package/dist/types/lib/numbers/split-unit.d.cts +8 -0
- package/dist/types/lib/style/index.d.cts +2 -3
- package/dist/types/lib/style/scatter.d.cts +48 -0
- package/dist/types/lib/style/to-style-string.d.cts +8 -0
- package/dist/types/lib/svg/displace.d.cts +54 -0
- package/dist/types/lib/svg/index.d.cts +2 -0
- package/dist/types/lib/svg/noise.d.cts +24 -0
- package/dist/types/node/dirname.d.cts +2 -2
- package/dist/types/node/file.d.cts +1 -1
- package/dist/types/node/hash.d.cts +1 -1
- package/dist/types/node/pkce.d.cts +4 -4
- package/dist/types/node/random-string.d.cts +1 -1
- package/dist/types/node/uuid.d.cts +1 -1
- 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/
|
|
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;
|
package/dist/cjs/dom/index.cjs
CHANGED
|
@@ -705,7 +705,7 @@ function Focusable(container = document.body) {
|
|
|
705
705
|
return getFocusableElements(container);
|
|
706
706
|
}
|
|
707
707
|
|
|
708
|
-
// src/lib/numbers/
|
|
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;
|
|
@@ -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
|
+
});
|
|
@@ -30,7 +30,7 @@ __export(time_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(time_exports);
|
|
32
32
|
|
|
33
|
-
// src/lib/numbers/
|
|
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;
|
package/dist/cjs/lib/index.cjs
CHANGED
|
@@ -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/
|
|
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;
|
|
@@ -1527,7 +1556,30 @@ function stripNumbers(string) {
|
|
|
1527
1556
|
return string.replace(/\d*/, "");
|
|
1528
1557
|
}
|
|
1529
1558
|
|
|
1530
|
-
// src/lib/style/
|
|
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/
|
|
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/
|
|
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
|
+
});
|
|
@@ -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
|
+
});
|