@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.
- package/dist/cjs/dom/font-size.cjs +1 -1
- package/dist/cjs/dom/index.cjs +7 -2
- package/dist/cjs/dom/query-params.cjs +6 -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/functions/index.cjs +1 -1
- package/dist/cjs/lib/functions/timeout.cjs +1 -1
- package/dist/cjs/lib/index.cjs +141 -3
- 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/cjs/node/file-cache.cjs +3 -5
- package/dist/cjs/node/index.cjs +3 -5
- package/dist/esm/dom/query-params.js +6 -1
- package/dist/esm/lib/colors.js +14 -0
- package/dist/esm/lib/functions/timeout.js +1 -1
- 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/esm/node/file-cache.js +3 -5
- package/dist/types/dom/font-size.d.cts +1 -1
- package/dist/types/dom/query-params.d.cts +5 -0
- package/dist/types/lib/colors.d.cts +12 -0
- package/dist/types/lib/functions/timeout.d.cts +1 -1
- 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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic pseudo-random generator.
|
|
3
|
+
*
|
|
4
|
+
* Math.random() runs once on the server and again on the client, so anything
|
|
5
|
+
* built from it disagrees between SSR and hydration and jumps on load. Seeding
|
|
6
|
+
* makes both passes produce the same sequence. Change the seed for a different
|
|
7
|
+
* arrangement.
|
|
8
|
+
*
|
|
9
|
+
* @param {number} [seed]
|
|
10
|
+
* @returns {() => number} Generator returning a value in [0, 1)
|
|
11
|
+
*/
|
|
12
|
+
declare function seededRandom(seed?: number): () => number;
|
|
13
|
+
|
|
14
|
+
export { seededRandom };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Splits a value into its numeric part and unit.
|
|
3
|
+
* @param {string|number} string - Value like `'2rem'`, `'30 days'`, or a plain number.
|
|
4
|
+
* @returns {[number, string|null]} `[value, unit]` — unit is null when there isn't one.
|
|
5
|
+
*/
|
|
6
|
+
declare function splitUnit(string: string | number): [number, string | null];
|
|
7
|
+
|
|
8
|
+
export { splitUnit };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { toStyleString };
|
|
1
|
+
export { ScatterItem, scatter } from './scatter.cjs';
|
|
2
|
+
export { toStyleString } from './to-style-string.cjs';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} ScatterItem
|
|
3
|
+
* @property {number} x Horizontal offset, in % of the element's own size
|
|
4
|
+
* @property {number} y Vertical offset, in % of the element's own size
|
|
5
|
+
* @property {number} rotation Rotation in degrees
|
|
6
|
+
* @property {string} transform Ready-to-use CSS transform value
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Places elements off a perfect grid so they read as laid down by hand rather
|
|
10
|
+
* than generated. Offsets are in % so they scale with the element.
|
|
11
|
+
*
|
|
12
|
+
* Seeded, so the same seed always produces the same arrangement — which is what
|
|
13
|
+
* keeps SSR and hydration in agreement.
|
|
14
|
+
*
|
|
15
|
+
* @param {number} count Number of elements to place
|
|
16
|
+
* @param {Object} [options]
|
|
17
|
+
* @param {number} [options.seed] Change for a different arrangement
|
|
18
|
+
* @param {number} [options.spread] Max offset, in % of the element's own size
|
|
19
|
+
* @param {number} [options.rotation] Max rotation in degrees
|
|
20
|
+
* @param {number} [options.amount] 0–1 dial over both spread and rotation
|
|
21
|
+
* @returns {ScatterItem[]}
|
|
22
|
+
*/
|
|
23
|
+
declare function scatter(count: number, options?: {
|
|
24
|
+
seed?: number;
|
|
25
|
+
spread?: number;
|
|
26
|
+
rotation?: number;
|
|
27
|
+
amount?: number;
|
|
28
|
+
}): ScatterItem[];
|
|
29
|
+
type ScatterItem = {
|
|
30
|
+
/**
|
|
31
|
+
* Horizontal offset, in % of the element's own size
|
|
32
|
+
*/
|
|
33
|
+
x: number;
|
|
34
|
+
/**
|
|
35
|
+
* Vertical offset, in % of the element's own size
|
|
36
|
+
*/
|
|
37
|
+
y: number;
|
|
38
|
+
/**
|
|
39
|
+
* Rotation in degrees
|
|
40
|
+
*/
|
|
41
|
+
rotation: number;
|
|
42
|
+
/**
|
|
43
|
+
* Ready-to-use CSS transform value
|
|
44
|
+
*/
|
|
45
|
+
transform: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { type ScatterItem, scatter };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a style object into a CSS style string. Passes strings through untouched.
|
|
3
|
+
* @param {string|Object} style - Style string or object of camelCase/custom properties.
|
|
4
|
+
* @returns {string|null} CSS style string, or null if no style given.
|
|
5
|
+
*/
|
|
6
|
+
declare function toStyleString(style: string | any): string | null;
|
|
7
|
+
|
|
8
|
+
export { toStyleString };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge a preset with explicit overrides. Explicit always wins.
|
|
3
|
+
* @param {Partial<DisplacePreset> & { preset?: string }} [opts]
|
|
4
|
+
*/
|
|
5
|
+
declare function displaceSettings(opts?: Partial<DisplacePreset> & {
|
|
6
|
+
preset?: string;
|
|
7
|
+
}): {
|
|
8
|
+
type: string;
|
|
9
|
+
frequency: string;
|
|
10
|
+
animateTo: string;
|
|
11
|
+
duration: number;
|
|
12
|
+
octaves: number;
|
|
13
|
+
scale: number;
|
|
14
|
+
seed: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Two numbers govern the effect.
|
|
18
|
+
*
|
|
19
|
+
* frequency — wavelength of the distortion, roughly (1 / frequency) px
|
|
20
|
+
* scale — how far each pixel is pushed
|
|
21
|
+
*
|
|
22
|
+
* Their ratio decides the outcome. Once scale approaches the wavelength,
|
|
23
|
+
* neighbouring pixels displace past each other and the form comes apart.
|
|
24
|
+
*
|
|
25
|
+
* scale < wavelength × 0.25 warp — shape survives, edges soften
|
|
26
|
+
* scale ≈ wavelength × 0.5 distress — edges tear, holes open
|
|
27
|
+
* scale > wavelength shred — shape is destroyed
|
|
28
|
+
*
|
|
29
|
+
* type='fractalNoise' is smooth and symmetric — warps.
|
|
30
|
+
* type='turbulence' takes the absolute value, so it creases — wisps and tears.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {Object} DisplacePreset
|
|
34
|
+
* @property {string} type
|
|
35
|
+
* @property {number|number[]} frequency
|
|
36
|
+
* @property {number|number[]} [animateTo]
|
|
37
|
+
* @property {number} [duration]
|
|
38
|
+
* @property {number} octaves
|
|
39
|
+
* @property {number} scale
|
|
40
|
+
* @property {number} seed
|
|
41
|
+
*/
|
|
42
|
+
/** @type {Record<string, DisplacePreset>} */
|
|
43
|
+
declare const displacePresets: Record<string, DisplacePreset>;
|
|
44
|
+
type DisplacePreset = {
|
|
45
|
+
type: string;
|
|
46
|
+
frequency: number | number[];
|
|
47
|
+
animateTo?: number | number[];
|
|
48
|
+
duration?: number;
|
|
49
|
+
octaves: number;
|
|
50
|
+
scale: number;
|
|
51
|
+
seed: number;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { type DisplacePreset, displacePresets, displaceSettings };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the feColorMatrix values for a noise colour.
|
|
3
|
+
*
|
|
4
|
+
* feTurbulence outputs independent noise per RGB channel, so colour is the
|
|
5
|
+
* natural state — the matrix decides what survives:
|
|
6
|
+
* - no color or 'rainbow' → RGB passes through: coloured static (default)
|
|
7
|
+
* - preset name ('black', 'sepia', 'synthwave') or hex → constant tint,
|
|
8
|
+
* alpha still noise-driven
|
|
9
|
+
*
|
|
10
|
+
* strength scales the per-pixel alpha. 0–1 fades the grain; above 1 the
|
|
11
|
+
* alpha saturates, so the grain gets denser rather than stronger.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} [color] - 'rainbow' (default), a preset name, or a hex colour.
|
|
14
|
+
* @param {number} strength - Per-pixel alpha multiplier.
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
declare function noiseColorMatrix(color?: string, strength: number): string;
|
|
18
|
+
declare namespace noisePresets {
|
|
19
|
+
let black: string;
|
|
20
|
+
let sepia: string;
|
|
21
|
+
let synthwave: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { noiseColorMatrix, noisePresets };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @param url — import.meta.url
|
|
4
4
|
* @returns
|
|
5
5
|
*/
|
|
6
|
-
declare function __dirname$1(url: any):
|
|
7
|
-
declare function dirname(url: any):
|
|
6
|
+
declare function __dirname$1(url: any): any;
|
|
7
|
+
declare function dirname(url: any): any;
|
|
8
8
|
|
|
9
9
|
export { __dirname$1 as __dirname, dirname };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare function PKCE(): Promise<{
|
|
2
|
-
state:
|
|
3
|
-
code_verifier:
|
|
4
|
-
code_challenge:
|
|
2
|
+
state: any;
|
|
3
|
+
code_verifier: any;
|
|
4
|
+
code_challenge: any;
|
|
5
5
|
code_challenge_method: string;
|
|
6
6
|
}>;
|
|
7
7
|
/**
|
|
@@ -9,6 +9,6 @@ declare function PKCE(): Promise<{
|
|
|
9
9
|
* @param {string} verifier
|
|
10
10
|
* @returns string
|
|
11
11
|
*/
|
|
12
|
-
declare function getCodeChallenge(verifier: string):
|
|
12
|
+
declare function getCodeChallenge(verifier: string): any;
|
|
13
13
|
|
|
14
14
|
export { PKCE, getCodeChallenge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splendidlabz/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://splendidlabz.com/docs/utils",
|
|
@@ -67,8 +67,7 @@
|
|
|
67
67
|
"sanitize-html": "^2.17.3"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@splendidlabz/eslint-config": "2.1.
|
|
71
|
-
"jsdom": "^29.0.2",
|
|
70
|
+
"@splendidlabz/eslint-config": "2.1.6",
|
|
72
71
|
"np": "^11.1.0",
|
|
73
72
|
"tsup": "^8.5.1",
|
|
74
73
|
"typescript": "^6.0.3",
|