@ansh-ui/core 0.2.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/LICENSE +21 -0
- package/dist/behaviours.cjs +64 -0
- package/dist/behaviours.cjs.map +1 -0
- package/dist/behaviours.d.cts +3 -0
- package/dist/behaviours.d.ts +3 -0
- package/dist/behaviours.js +7 -0
- package/dist/behaviours.js.map +1 -0
- package/dist/chunk-23GSSIMK.cjs +439 -0
- package/dist/chunk-23GSSIMK.cjs.map +1 -0
- package/dist/chunk-56NNBIAO.js +2446 -0
- package/dist/chunk-56NNBIAO.js.map +1 -0
- package/dist/chunk-6PFYGJWD.cjs +136 -0
- package/dist/chunk-6PFYGJWD.cjs.map +1 -0
- package/dist/chunk-7MEIXWPH.js +313 -0
- package/dist/chunk-7MEIXWPH.js.map +1 -0
- package/dist/chunk-7MYTSAPR.js +83 -0
- package/dist/chunk-7MYTSAPR.js.map +1 -0
- package/dist/chunk-BOQQHICI.js +1036 -0
- package/dist/chunk-BOQQHICI.js.map +1 -0
- package/dist/chunk-C6XPQO2O.js +1170 -0
- package/dist/chunk-C6XPQO2O.js.map +1 -0
- package/dist/chunk-DXJ63QAR.cjs +723 -0
- package/dist/chunk-DXJ63QAR.cjs.map +1 -0
- package/dist/chunk-FAVIEION.js +705 -0
- package/dist/chunk-FAVIEION.js.map +1 -0
- package/dist/chunk-FNR35HTL.cjs +107 -0
- package/dist/chunk-FNR35HTL.cjs.map +1 -0
- package/dist/chunk-GHBRGMSO.cjs +91 -0
- package/dist/chunk-GHBRGMSO.cjs.map +1 -0
- package/dist/chunk-GJRIHN76.cjs +359 -0
- package/dist/chunk-GJRIHN76.cjs.map +1 -0
- package/dist/chunk-ILKUL7GD.cjs +115 -0
- package/dist/chunk-ILKUL7GD.cjs.map +1 -0
- package/dist/chunk-KTUBCQC3.js +409 -0
- package/dist/chunk-KTUBCQC3.js.map +1 -0
- package/dist/chunk-KU2C6GEA.js +90 -0
- package/dist/chunk-KU2C6GEA.js.map +1 -0
- package/dist/chunk-LGA3N3YJ.cjs +413 -0
- package/dist/chunk-LGA3N3YJ.cjs.map +1 -0
- package/dist/chunk-MMO7KO53.cjs +1060 -0
- package/dist/chunk-MMO7KO53.cjs.map +1 -0
- package/dist/chunk-NSXKCJJ7.js +109 -0
- package/dist/chunk-NSXKCJJ7.js.map +1 -0
- package/dist/chunk-QALZKHWH.js +387 -0
- package/dist/chunk-QALZKHWH.js.map +1 -0
- package/dist/chunk-R7UJ7MWP.cjs +2479 -0
- package/dist/chunk-R7UJ7MWP.cjs.map +1 -0
- package/dist/chunk-UJBXY6QC.cjs +1186 -0
- package/dist/chunk-UJBXY6QC.cjs.map +1 -0
- package/dist/chunk-YFQXRC5R.js +99 -0
- package/dist/chunk-YFQXRC5R.js.map +1 -0
- package/dist/color.cjs +257 -0
- package/dist/color.cjs.map +1 -0
- package/dist/color.d.cts +303 -0
- package/dist/color.d.ts +303 -0
- package/dist/color.js +8 -0
- package/dist/color.js.map +1 -0
- package/dist/easing.cjs +189 -0
- package/dist/easing.cjs.map +1 -0
- package/dist/easing.d.cts +134 -0
- package/dist/easing.d.ts +134 -0
- package/dist/easing.js +4 -0
- package/dist/easing.js.map +1 -0
- package/dist/effects.cjs +99 -0
- package/dist/effects.cjs.map +1 -0
- package/dist/effects.d.cts +5 -0
- package/dist/effects.d.ts +5 -0
- package/dist/effects.js +10 -0
- package/dist/effects.js.map +1 -0
- package/dist/index-CCdpefMp.d.ts +967 -0
- package/dist/index-CQEEPu-D.d.ts +435 -0
- package/dist/index-DHOfsEIn.d.cts +967 -0
- package/dist/index-Dl8GCsya.d.cts +435 -0
- package/dist/index.cjs +2206 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1122 -0
- package/dist/index.d.ts +1122 -0
- package/dist/index.js +1182 -0
- package/dist/index.js.map +1 -0
- package/dist/math.cjs +238 -0
- package/dist/math.cjs.map +1 -0
- package/dist/math.d.cts +120 -0
- package/dist/math.d.ts +120 -0
- package/dist/math.js +5 -0
- package/dist/math.js.map +1 -0
- package/dist/noise.cjs +78 -0
- package/dist/noise.cjs.map +1 -0
- package/dist/noise.d.cts +190 -0
- package/dist/noise.d.ts +190 -0
- package/dist/noise.js +5 -0
- package/dist/noise.js.map +1 -0
- package/dist/palette-6HkVltYU.d.cts +219 -0
- package/dist/palette-6HkVltYU.d.ts +219 -0
- package/dist/random--4mSc5Lp.d.cts +75 -0
- package/dist/random--4mSc5Lp.d.ts +75 -0
- package/dist/reduced-motion-D0LUgZle.d.cts +120 -0
- package/dist/reduced-motion-D0LUgZle.d.ts +120 -0
- package/dist/types-B1FLLf3-.d.cts +21 -0
- package/dist/types-B1FLLf3-.d.ts +21 -0
- package/package.json +78 -0
package/dist/math.d.cts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export { R as Rng, c as createRng, d as deriveSeed, g as goldenRatioSequence, h as hashString, j as jitter, r as r2Sequence, w as weightedPick } from './random--4mSc5Lp.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scalar math primitives.
|
|
5
|
+
*
|
|
6
|
+
* Every function here is pure, allocation-free and safe to call inside a frame loop.
|
|
7
|
+
* They are the vocabulary the rest of the engine is written in — if you find yourself
|
|
8
|
+
* writing `Math.min(Math.max(...))` anywhere else, use `clamp` instead.
|
|
9
|
+
*/
|
|
10
|
+
declare const PI: number;
|
|
11
|
+
declare const TAU: number;
|
|
12
|
+
declare const HALF_PI: number;
|
|
13
|
+
declare const EPSILON = 0.000001;
|
|
14
|
+
/** Constrain `value` to the inclusive range `[min, max]`. */
|
|
15
|
+
declare function clamp(value: number, min?: number, max?: number): number;
|
|
16
|
+
/** Linear interpolation. `t` is not clamped — pass values outside `[0,1]` to extrapolate. */
|
|
17
|
+
declare function lerp(from: number, to: number, t: number): number;
|
|
18
|
+
/** The inverse of {@link lerp}: where does `value` sit between `from` and `to`? */
|
|
19
|
+
declare function inverseLerp(from: number, to: number, value: number): number;
|
|
20
|
+
/** Map `value` from one range to another. Set `clampOutput` to avoid extrapolation. */
|
|
21
|
+
declare function remap(value: number, inMin: number, inMax: number, outMin: number, outMax: number, clampOutput?: boolean): number;
|
|
22
|
+
/**
|
|
23
|
+
* Frame-rate independent exponential smoothing.
|
|
24
|
+
*
|
|
25
|
+
* A naive `current += (target - current) * 0.1` moves twice as fast at 120 FPS as it does
|
|
26
|
+
* at 60. `damp` reformulates it in terms of a half-life measured in seconds, so the motion
|
|
27
|
+
* looks identical on every device.
|
|
28
|
+
*
|
|
29
|
+
* @param smoothing Fraction of the remaining distance left after one second. `0.001` is snappy,
|
|
30
|
+
* `0.5` is languid. Must be in `(0, 1)`.
|
|
31
|
+
* @param dt Delta time in seconds.
|
|
32
|
+
*/
|
|
33
|
+
declare function damp(current: number, target: number, smoothing: number, dt: number): number;
|
|
34
|
+
/** Hermite interpolation with zero first-derivative at both ends. */
|
|
35
|
+
declare function smoothstep(edge0: number, edge1: number, x: number): number;
|
|
36
|
+
/** Ken Perlin's quintic smoothstep — zero first *and* second derivative at both ends. */
|
|
37
|
+
declare function smootherstep(edge0: number, edge1: number, x: number): number;
|
|
38
|
+
/** Wrap `value` into `[min, max)`, handling negative inputs correctly (unlike `%`). */
|
|
39
|
+
declare function wrap(value: number, min: number, max: number): number;
|
|
40
|
+
/** Bounce `value` back and forth within `[min, max]` — a triangle wave. */
|
|
41
|
+
declare function pingPong(value: number, min: number, max: number): number;
|
|
42
|
+
/** Move `current` toward `target` by at most `maxDelta`. */
|
|
43
|
+
declare function moveTowards(current: number, target: number, maxDelta: number): number;
|
|
44
|
+
/** Shortest signed angular distance from `a` to `b`, in radians. */
|
|
45
|
+
declare function angleDelta(a: number, b: number): number;
|
|
46
|
+
/** Interpolate between two angles along the shortest arc. */
|
|
47
|
+
declare function lerpAngle(from: number, to: number, t: number): number;
|
|
48
|
+
declare function degrees(radians: number): number;
|
|
49
|
+
declare function radians(degrees: number): number;
|
|
50
|
+
/** Round to a fixed number of decimal places, avoiding float dust in serialised output. */
|
|
51
|
+
declare function roundTo(value: number, decimals?: number): number;
|
|
52
|
+
/** Round to the nearest multiple of `step`. */
|
|
53
|
+
declare function snap(value: number, step: number): number;
|
|
54
|
+
/** Float comparison with a tolerance. */
|
|
55
|
+
declare function approximately(a: number, b: number, epsilon?: number): boolean;
|
|
56
|
+
/** Guard against `NaN`/`Infinity` leaking out of a physics step. */
|
|
57
|
+
declare function finite(value: number, fallback?: number): number;
|
|
58
|
+
/** Arithmetic mean of an array. Returns `0` for an empty array. */
|
|
59
|
+
declare function mean(values: readonly number[]): number;
|
|
60
|
+
/**
|
|
61
|
+
* Percentile of an *already sorted* ascending array, using linear interpolation between
|
|
62
|
+
* neighbouring ranks. Used by the frame budget to compute p50/p95 costs.
|
|
63
|
+
*/
|
|
64
|
+
declare function percentileSorted(sorted: readonly number[], p: number): number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A 2D vector.
|
|
68
|
+
*
|
|
69
|
+
* Deliberately a plain object rather than a class: it serialises cleanly, is cheap for the
|
|
70
|
+
* JIT to inline, and can be stored in component props without surprising anyone. Every
|
|
71
|
+
* operation returns a new object except the `*Into` variants, which write into a target
|
|
72
|
+
* and are used in hot loops to avoid allocation pressure.
|
|
73
|
+
*/
|
|
74
|
+
interface Vec2 {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
}
|
|
78
|
+
declare function vec2(x?: number, y?: number): Vec2;
|
|
79
|
+
declare function cloneVec2(v: Vec2): Vec2;
|
|
80
|
+
declare function addVec2(a: Vec2, b: Vec2): Vec2;
|
|
81
|
+
declare function subVec2(a: Vec2, b: Vec2): Vec2;
|
|
82
|
+
declare function scaleVec2(v: Vec2, s: number): Vec2;
|
|
83
|
+
declare function dotVec2(a: Vec2, b: Vec2): number;
|
|
84
|
+
/** 2D analogue of the cross product — the z component of the 3D result. */
|
|
85
|
+
declare function crossVec2(a: Vec2, b: Vec2): number;
|
|
86
|
+
declare function lengthVec2(v: Vec2): number;
|
|
87
|
+
/** Squared length. Prefer this for comparisons — it avoids a square root. */
|
|
88
|
+
declare function lengthSqVec2(v: Vec2): number;
|
|
89
|
+
declare function distanceVec2(a: Vec2, b: Vec2): number;
|
|
90
|
+
declare function distanceSqVec2(a: Vec2, b: Vec2): number;
|
|
91
|
+
/** Unit vector. A zero-length input returns `(0, 0)` rather than `NaN`. */
|
|
92
|
+
declare function normalizeVec2(v: Vec2): Vec2;
|
|
93
|
+
/** Rotate counter-clockwise by `angle` radians. */
|
|
94
|
+
declare function rotateVec2(v: Vec2, angle: number): Vec2;
|
|
95
|
+
declare function angleOfVec2(v: Vec2): number;
|
|
96
|
+
declare function fromAngle(angle: number, magnitude?: number): Vec2;
|
|
97
|
+
declare function lerpVec2(a: Vec2, b: Vec2, t: number): Vec2;
|
|
98
|
+
/** Clamp the vector's magnitude to `max`, preserving direction. */
|
|
99
|
+
declare function limitVec2(v: Vec2, max: number): Vec2;
|
|
100
|
+
/** Reflect `v` about a unit-length `normal`. */
|
|
101
|
+
declare function reflectVec2(v: Vec2, normal: Vec2): Vec2;
|
|
102
|
+
declare function setVec2(out: Vec2, x: number, y: number): Vec2;
|
|
103
|
+
declare function addVec2Into(out: Vec2, a: Vec2, b: Vec2): Vec2;
|
|
104
|
+
declare function subVec2Into(out: Vec2, a: Vec2, b: Vec2): Vec2;
|
|
105
|
+
declare function scaleVec2Into(out: Vec2, v: Vec2, s: number): Vec2;
|
|
106
|
+
declare function lerpVec2Into(out: Vec2, a: Vec2, b: Vec2, t: number): Vec2;
|
|
107
|
+
/** Add `b * s` to `out` in place — the fused multiply-add of vector code. */
|
|
108
|
+
declare function addScaledVec2(out: Vec2, b: Vec2, s: number): Vec2;
|
|
109
|
+
/** A rectangle in the same coordinate space as its `Vec2` neighbours. */
|
|
110
|
+
interface Rect {
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
}
|
|
116
|
+
declare function rectContains(rect: Rect, x: number, y: number): boolean;
|
|
117
|
+
/** Position of `(x, y)` within `rect`, normalised to `[0,1]` on each axis. */
|
|
118
|
+
declare function normalizeInRect(rect: Rect, x: number, y: number): Vec2;
|
|
119
|
+
|
|
120
|
+
export { EPSILON, HALF_PI, PI, type Rect, TAU, type Vec2, addScaledVec2, addVec2, addVec2Into, angleDelta, angleOfVec2, approximately, clamp, cloneVec2, crossVec2, damp, degrees, distanceSqVec2, distanceVec2, dotVec2, finite, fromAngle, inverseLerp, lengthSqVec2, lengthVec2, lerp, lerpAngle, lerpVec2, lerpVec2Into, limitVec2, mean, moveTowards, normalizeInRect, normalizeVec2, percentileSorted, pingPong, radians, rectContains, reflectVec2, remap, rotateVec2, roundTo, scaleVec2, scaleVec2Into, setVec2, smootherstep, smoothstep, snap, subVec2, subVec2Into, vec2, wrap };
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export { R as Rng, c as createRng, d as deriveSeed, g as goldenRatioSequence, h as hashString, j as jitter, r as r2Sequence, w as weightedPick } from './random--4mSc5Lp.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Scalar math primitives.
|
|
5
|
+
*
|
|
6
|
+
* Every function here is pure, allocation-free and safe to call inside a frame loop.
|
|
7
|
+
* They are the vocabulary the rest of the engine is written in — if you find yourself
|
|
8
|
+
* writing `Math.min(Math.max(...))` anywhere else, use `clamp` instead.
|
|
9
|
+
*/
|
|
10
|
+
declare const PI: number;
|
|
11
|
+
declare const TAU: number;
|
|
12
|
+
declare const HALF_PI: number;
|
|
13
|
+
declare const EPSILON = 0.000001;
|
|
14
|
+
/** Constrain `value` to the inclusive range `[min, max]`. */
|
|
15
|
+
declare function clamp(value: number, min?: number, max?: number): number;
|
|
16
|
+
/** Linear interpolation. `t` is not clamped — pass values outside `[0,1]` to extrapolate. */
|
|
17
|
+
declare function lerp(from: number, to: number, t: number): number;
|
|
18
|
+
/** The inverse of {@link lerp}: where does `value` sit between `from` and `to`? */
|
|
19
|
+
declare function inverseLerp(from: number, to: number, value: number): number;
|
|
20
|
+
/** Map `value` from one range to another. Set `clampOutput` to avoid extrapolation. */
|
|
21
|
+
declare function remap(value: number, inMin: number, inMax: number, outMin: number, outMax: number, clampOutput?: boolean): number;
|
|
22
|
+
/**
|
|
23
|
+
* Frame-rate independent exponential smoothing.
|
|
24
|
+
*
|
|
25
|
+
* A naive `current += (target - current) * 0.1` moves twice as fast at 120 FPS as it does
|
|
26
|
+
* at 60. `damp` reformulates it in terms of a half-life measured in seconds, so the motion
|
|
27
|
+
* looks identical on every device.
|
|
28
|
+
*
|
|
29
|
+
* @param smoothing Fraction of the remaining distance left after one second. `0.001` is snappy,
|
|
30
|
+
* `0.5` is languid. Must be in `(0, 1)`.
|
|
31
|
+
* @param dt Delta time in seconds.
|
|
32
|
+
*/
|
|
33
|
+
declare function damp(current: number, target: number, smoothing: number, dt: number): number;
|
|
34
|
+
/** Hermite interpolation with zero first-derivative at both ends. */
|
|
35
|
+
declare function smoothstep(edge0: number, edge1: number, x: number): number;
|
|
36
|
+
/** Ken Perlin's quintic smoothstep — zero first *and* second derivative at both ends. */
|
|
37
|
+
declare function smootherstep(edge0: number, edge1: number, x: number): number;
|
|
38
|
+
/** Wrap `value` into `[min, max)`, handling negative inputs correctly (unlike `%`). */
|
|
39
|
+
declare function wrap(value: number, min: number, max: number): number;
|
|
40
|
+
/** Bounce `value` back and forth within `[min, max]` — a triangle wave. */
|
|
41
|
+
declare function pingPong(value: number, min: number, max: number): number;
|
|
42
|
+
/** Move `current` toward `target` by at most `maxDelta`. */
|
|
43
|
+
declare function moveTowards(current: number, target: number, maxDelta: number): number;
|
|
44
|
+
/** Shortest signed angular distance from `a` to `b`, in radians. */
|
|
45
|
+
declare function angleDelta(a: number, b: number): number;
|
|
46
|
+
/** Interpolate between two angles along the shortest arc. */
|
|
47
|
+
declare function lerpAngle(from: number, to: number, t: number): number;
|
|
48
|
+
declare function degrees(radians: number): number;
|
|
49
|
+
declare function radians(degrees: number): number;
|
|
50
|
+
/** Round to a fixed number of decimal places, avoiding float dust in serialised output. */
|
|
51
|
+
declare function roundTo(value: number, decimals?: number): number;
|
|
52
|
+
/** Round to the nearest multiple of `step`. */
|
|
53
|
+
declare function snap(value: number, step: number): number;
|
|
54
|
+
/** Float comparison with a tolerance. */
|
|
55
|
+
declare function approximately(a: number, b: number, epsilon?: number): boolean;
|
|
56
|
+
/** Guard against `NaN`/`Infinity` leaking out of a physics step. */
|
|
57
|
+
declare function finite(value: number, fallback?: number): number;
|
|
58
|
+
/** Arithmetic mean of an array. Returns `0` for an empty array. */
|
|
59
|
+
declare function mean(values: readonly number[]): number;
|
|
60
|
+
/**
|
|
61
|
+
* Percentile of an *already sorted* ascending array, using linear interpolation between
|
|
62
|
+
* neighbouring ranks. Used by the frame budget to compute p50/p95 costs.
|
|
63
|
+
*/
|
|
64
|
+
declare function percentileSorted(sorted: readonly number[], p: number): number;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A 2D vector.
|
|
68
|
+
*
|
|
69
|
+
* Deliberately a plain object rather than a class: it serialises cleanly, is cheap for the
|
|
70
|
+
* JIT to inline, and can be stored in component props without surprising anyone. Every
|
|
71
|
+
* operation returns a new object except the `*Into` variants, which write into a target
|
|
72
|
+
* and are used in hot loops to avoid allocation pressure.
|
|
73
|
+
*/
|
|
74
|
+
interface Vec2 {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
}
|
|
78
|
+
declare function vec2(x?: number, y?: number): Vec2;
|
|
79
|
+
declare function cloneVec2(v: Vec2): Vec2;
|
|
80
|
+
declare function addVec2(a: Vec2, b: Vec2): Vec2;
|
|
81
|
+
declare function subVec2(a: Vec2, b: Vec2): Vec2;
|
|
82
|
+
declare function scaleVec2(v: Vec2, s: number): Vec2;
|
|
83
|
+
declare function dotVec2(a: Vec2, b: Vec2): number;
|
|
84
|
+
/** 2D analogue of the cross product — the z component of the 3D result. */
|
|
85
|
+
declare function crossVec2(a: Vec2, b: Vec2): number;
|
|
86
|
+
declare function lengthVec2(v: Vec2): number;
|
|
87
|
+
/** Squared length. Prefer this for comparisons — it avoids a square root. */
|
|
88
|
+
declare function lengthSqVec2(v: Vec2): number;
|
|
89
|
+
declare function distanceVec2(a: Vec2, b: Vec2): number;
|
|
90
|
+
declare function distanceSqVec2(a: Vec2, b: Vec2): number;
|
|
91
|
+
/** Unit vector. A zero-length input returns `(0, 0)` rather than `NaN`. */
|
|
92
|
+
declare function normalizeVec2(v: Vec2): Vec2;
|
|
93
|
+
/** Rotate counter-clockwise by `angle` radians. */
|
|
94
|
+
declare function rotateVec2(v: Vec2, angle: number): Vec2;
|
|
95
|
+
declare function angleOfVec2(v: Vec2): number;
|
|
96
|
+
declare function fromAngle(angle: number, magnitude?: number): Vec2;
|
|
97
|
+
declare function lerpVec2(a: Vec2, b: Vec2, t: number): Vec2;
|
|
98
|
+
/** Clamp the vector's magnitude to `max`, preserving direction. */
|
|
99
|
+
declare function limitVec2(v: Vec2, max: number): Vec2;
|
|
100
|
+
/** Reflect `v` about a unit-length `normal`. */
|
|
101
|
+
declare function reflectVec2(v: Vec2, normal: Vec2): Vec2;
|
|
102
|
+
declare function setVec2(out: Vec2, x: number, y: number): Vec2;
|
|
103
|
+
declare function addVec2Into(out: Vec2, a: Vec2, b: Vec2): Vec2;
|
|
104
|
+
declare function subVec2Into(out: Vec2, a: Vec2, b: Vec2): Vec2;
|
|
105
|
+
declare function scaleVec2Into(out: Vec2, v: Vec2, s: number): Vec2;
|
|
106
|
+
declare function lerpVec2Into(out: Vec2, a: Vec2, b: Vec2, t: number): Vec2;
|
|
107
|
+
/** Add `b * s` to `out` in place — the fused multiply-add of vector code. */
|
|
108
|
+
declare function addScaledVec2(out: Vec2, b: Vec2, s: number): Vec2;
|
|
109
|
+
/** A rectangle in the same coordinate space as its `Vec2` neighbours. */
|
|
110
|
+
interface Rect {
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
width: number;
|
|
114
|
+
height: number;
|
|
115
|
+
}
|
|
116
|
+
declare function rectContains(rect: Rect, x: number, y: number): boolean;
|
|
117
|
+
/** Position of `(x, y)` within `rect`, normalised to `[0,1]` on each axis. */
|
|
118
|
+
declare function normalizeInRect(rect: Rect, x: number, y: number): Vec2;
|
|
119
|
+
|
|
120
|
+
export { EPSILON, HALF_PI, PI, type Rect, TAU, type Vec2, addScaledVec2, addVec2, addVec2Into, angleDelta, angleOfVec2, approximately, clamp, cloneVec2, crossVec2, damp, degrees, distanceSqVec2, distanceVec2, dotVec2, finite, fromAngle, inverseLerp, lengthSqVec2, lengthVec2, lerp, lerpAngle, lerpVec2, lerpVec2Into, limitVec2, mean, moveTowards, normalizeInRect, normalizeVec2, percentileSorted, pingPong, radians, rectContains, reflectVec2, remap, rotateVec2, roundTo, scaleVec2, scaleVec2Into, setVec2, smootherstep, smoothstep, snap, subVec2, subVec2Into, vec2, wrap };
|
package/dist/math.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { addScaledVec2, addVec2, addVec2Into, angleOfVec2, cloneVec2, crossVec2, distanceSqVec2, distanceVec2, dotVec2, fromAngle, lengthSqVec2, lengthVec2, lerpVec2, lerpVec2Into, limitVec2, normalizeInRect, normalizeVec2, rectContains, reflectVec2, rotateVec2, scaleVec2, scaleVec2Into, setVec2, subVec2, subVec2Into, vec2 } from './chunk-NSXKCJJ7.js';
|
|
2
|
+
export { createRng, deriveSeed, goldenRatioSequence, hashString, jitter, r2Sequence, weightedPick } from './chunk-YFQXRC5R.js';
|
|
3
|
+
export { EPSILON, HALF_PI, PI, TAU, angleDelta, approximately, clamp, damp, degrees, finite, inverseLerp, lerp, lerpAngle, mean, moveTowards, percentileSorted, pingPong, radians, remap, roundTo, smootherstep, smoothstep, snap, wrap } from './chunk-KU2C6GEA.js';
|
|
4
|
+
//# sourceMappingURL=math.js.map
|
|
5
|
+
//# sourceMappingURL=math.js.map
|
package/dist/math.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"math.js"}
|
package/dist/noise.cjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkDXJ63QAR_cjs = require('./chunk-DXJ63QAR.cjs');
|
|
4
|
+
require('./chunk-FNR35HTL.cjs');
|
|
5
|
+
require('./chunk-ILKUL7GD.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "FRACTAL_DEFAULTS", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return chunkDXJ63QAR_cjs.FRACTAL_DEFAULTS; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "GRAD3", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkDXJ63QAR_cjs.GRAD3; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "GRAD4", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return chunkDXJ63QAR_cjs.GRAD4; }
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "clearNoiseTableCache", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return chunkDXJ63QAR_cjs.clearNoiseTableCache; }
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "createNoise", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return chunkDXJ63QAR_cjs.createNoise; }
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "createNoiseTables", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return chunkDXJ63QAR_cjs.createNoiseTables; }
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "createPerlinNoise", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () { return chunkDXJ63QAR_cjs.createPerlinNoise; }
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "createSimplexNoise", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return chunkDXJ63QAR_cjs.createSimplexNoise; }
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "createValueNoise", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () { return chunkDXJ63QAR_cjs.createValueNoise; }
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "curl2D", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return chunkDXJ63QAR_cjs.curl2D; }
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "curl2DAnimated", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () { return chunkDXJ63QAR_cjs.curl2DAnimated; }
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, "fbm2D", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () { return chunkDXJ63QAR_cjs.fbm2D; }
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "fbm3D", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () { return chunkDXJ63QAR_cjs.fbm3D; }
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "ridged2D", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () { return chunkDXJ63QAR_cjs.ridged2D; }
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(exports, "tileable2D", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () { return chunkDXJ63QAR_cjs.tileable2D; }
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "turbulence2D", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () { return chunkDXJ63QAR_cjs.turbulence2D; }
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "warp2D", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () { return chunkDXJ63QAR_cjs.warp2D; }
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=noise.cjs.map
|
|
78
|
+
//# sourceMappingURL=noise.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"noise.cjs"}
|
package/dist/noise.d.cts
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fractal composition of a base noise function.
|
|
3
|
+
*
|
|
4
|
+
* A single octave of simplex noise is smooth and featureless. Real natural texture comes from
|
|
5
|
+
* summing octaves at increasing frequency and decreasing amplitude — fractional Brownian
|
|
6
|
+
* motion. This module provides the standard family of summations, all parameterised so that
|
|
7
|
+
* no frequency, amplitude, or octave count is hardcoded inside an effect.
|
|
8
|
+
*/
|
|
9
|
+
type Noise2DFn = (x: number, y: number) => number;
|
|
10
|
+
type Noise3DFn = (x: number, y: number, z: number) => number;
|
|
11
|
+
interface FractalOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Number of summed layers. Each octave roughly doubles the cost, and beyond ~6 the added
|
|
14
|
+
* detail is below a pixel for typical scales. Default `4`.
|
|
15
|
+
*/
|
|
16
|
+
octaves?: number;
|
|
17
|
+
/** Frequency multiplier per octave. `2` is the classic choice. Default `2`. */
|
|
18
|
+
lacunarity?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Amplitude multiplier per octave. Also called persistence. `0.5` gives the pink-noise
|
|
21
|
+
* falloff that reads as natural. Default `0.5`.
|
|
22
|
+
*/
|
|
23
|
+
gain?: number;
|
|
24
|
+
/** Frequency of the first octave. Default `1`. */
|
|
25
|
+
frequency?: number;
|
|
26
|
+
/** Amplitude of the first octave. Default `1`. */
|
|
27
|
+
amplitude?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Normalise the result back into `[-1, 1]` by dividing by the total amplitude.
|
|
30
|
+
* Without this, more octaves means a quieter signal. Default `true`.
|
|
31
|
+
*/
|
|
32
|
+
normalize?: boolean;
|
|
33
|
+
}
|
|
34
|
+
declare const FRACTAL_DEFAULTS: {
|
|
35
|
+
readonly octaves: 4;
|
|
36
|
+
readonly lacunarity: 2;
|
|
37
|
+
readonly gain: 0.5;
|
|
38
|
+
readonly frequency: 1;
|
|
39
|
+
readonly amplitude: 1;
|
|
40
|
+
readonly normalize: true;
|
|
41
|
+
};
|
|
42
|
+
/** Standard fBm over a 2D noise source. Output in `[-1, 1]` when normalised. */
|
|
43
|
+
declare function fbm2D(noise: Noise2DFn, options?: FractalOptions): Noise2DFn;
|
|
44
|
+
/** Standard fBm over a 3D noise source — use the third axis as time for animated fields. */
|
|
45
|
+
declare function fbm3D(noise: Noise3DFn, options?: FractalOptions): Noise3DFn;
|
|
46
|
+
/**
|
|
47
|
+
* Ridged multifractal. Inverts and sharpens each octave (`1 - |n|`, squared), producing crisp
|
|
48
|
+
* ridge lines instead of rolling hills. This is what makes convincing mountain silhouettes,
|
|
49
|
+
* lightning, and the filament structure in aurora curtains.
|
|
50
|
+
*
|
|
51
|
+
* Output is in `[0, 1]`.
|
|
52
|
+
*/
|
|
53
|
+
declare function ridged2D(noise: Noise2DFn, options?: FractalOptions): Noise2DFn;
|
|
54
|
+
/**
|
|
55
|
+
* Turbulence: fBm over the absolute value of each octave. Produces the billowing,
|
|
56
|
+
* smoke-like structure used for clouds and flame.
|
|
57
|
+
*
|
|
58
|
+
* Output is in `[0, 1]`.
|
|
59
|
+
*/
|
|
60
|
+
declare function turbulence2D(noise: Noise2DFn, options?: FractalOptions): Noise2DFn;
|
|
61
|
+
/**
|
|
62
|
+
* Domain warping — feed noise through itself.
|
|
63
|
+
*
|
|
64
|
+
* `warp(p) = noise(p + strength * noise(p))`. This single trick is responsible for most of
|
|
65
|
+
* the "organic liquid" look in modern generative backgrounds: it turns the isotropic blobs of
|
|
66
|
+
* plain fBm into flowing, marbled filaments.
|
|
67
|
+
*
|
|
68
|
+
* @param strength How far the domain is displaced, in noise-space units. `0.5`–`2` is useful.
|
|
69
|
+
*/
|
|
70
|
+
declare function warp2D(noise: Noise2DFn, strength?: number, offset?: number): Noise2DFn;
|
|
71
|
+
interface CurlResult {
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Curl (divergence-free) noise for 2D flow fields.
|
|
77
|
+
*
|
|
78
|
+
* A particle advected by raw noise will pool in sinks and thin out in sources, because the
|
|
79
|
+
* field has non-zero divergence. Taking the perpendicular gradient of a scalar potential —
|
|
80
|
+
* `(∂N/∂y, −∂N/∂x)` — yields a field with zero divergence, so particle density is preserved
|
|
81
|
+
* and the motion looks like real fluid.
|
|
82
|
+
*
|
|
83
|
+
* The derivative is a central difference; `epsilon` trades accuracy against smoothness.
|
|
84
|
+
*/
|
|
85
|
+
declare function curl2D(noise: Noise2DFn, epsilon?: number): (x: number, y: number) => CurlResult;
|
|
86
|
+
/** The 3D-source variant of {@link curl2D}, letting you animate the field over time. */
|
|
87
|
+
declare function curl2DAnimated(noise: Noise3DFn, epsilon?: number): (x: number, y: number, t: number) => CurlResult;
|
|
88
|
+
/**
|
|
89
|
+
* Make a 2D noise field seamlessly tileable over `[0, width) × [0, height)`.
|
|
90
|
+
*
|
|
91
|
+
* Works by sampling 4D noise on the surface of a torus: each axis becomes a circle, so the
|
|
92
|
+
* field wraps exactly with no seam. This is the correct way to do it — blending mirrored
|
|
93
|
+
* copies leaves visible symmetry artefacts.
|
|
94
|
+
*/
|
|
95
|
+
declare function tileable2D(noise4D: (x: number, y: number, z: number, w: number) => number, width: number, height: number): Noise2DFn;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Gradient tables and permutation setup shared by every noise variant.
|
|
99
|
+
*
|
|
100
|
+
* The permutation table is a shuffled `0..255` sequence duplicated to 512 entries. Doubling
|
|
101
|
+
* it lets the noise functions index `perm[i + perm[j]]` without a modulo on every lookup,
|
|
102
|
+
* which matters when these run millions of times per second.
|
|
103
|
+
*
|
|
104
|
+
* The table is derived from the effect's seed, so noise fields are reproducible — the same
|
|
105
|
+
* seed always produces the same landscape.
|
|
106
|
+
*/
|
|
107
|
+
/** 12 edge-midpoint gradients of a cube. Used by 2D and 3D noise. */
|
|
108
|
+
declare const GRAD3: Float32Array<ArrayBuffer>;
|
|
109
|
+
/** 32 gradients for 4D noise — the edge midpoints of a hypercube. */
|
|
110
|
+
declare const GRAD4: Float32Array<ArrayBuffer>;
|
|
111
|
+
interface NoiseTables {
|
|
112
|
+
/** 512-entry doubled permutation table. */
|
|
113
|
+
readonly perm: Uint8Array;
|
|
114
|
+
/** `perm[i] % 12`, precomputed — saves a modulo in the inner loop of 2D/3D noise. */
|
|
115
|
+
readonly permMod12: Uint8Array;
|
|
116
|
+
/** `perm[i] % 32`, precomputed for 4D noise. */
|
|
117
|
+
readonly permMod32: Uint8Array;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Build (or reuse) permutation tables for a seed.
|
|
121
|
+
*
|
|
122
|
+
* Tables are 1.5 KB each and construction costs a shuffle, so we memoise them. The cache is
|
|
123
|
+
* bounded because a page that animates its seed would otherwise grow it without limit; we
|
|
124
|
+
* evict oldest-first, which suits the access pattern (a handful of stable seeds per page).
|
|
125
|
+
*/
|
|
126
|
+
declare function createNoiseTables(seed?: number): NoiseTables;
|
|
127
|
+
/** Clear the memoised permutation tables. Exposed for tests and long-lived workers. */
|
|
128
|
+
declare function clearNoiseTableCache(): void;
|
|
129
|
+
|
|
130
|
+
interface SimplexNoise {
|
|
131
|
+
noise2D(x: number, y: number): number;
|
|
132
|
+
noise3D(x: number, y: number, z: number): number;
|
|
133
|
+
noise4D(x: number, y: number, z: number, w: number): number;
|
|
134
|
+
}
|
|
135
|
+
declare function createSimplexNoise(seed?: number): SimplexNoise;
|
|
136
|
+
|
|
137
|
+
interface PerlinNoise {
|
|
138
|
+
noise2D(x: number, y: number): number;
|
|
139
|
+
noise3D(x: number, y: number, z: number): number;
|
|
140
|
+
}
|
|
141
|
+
declare function createPerlinNoise(seed?: number): PerlinNoise;
|
|
142
|
+
/**
|
|
143
|
+
* Value noise: interpolates hashed *values* at lattice points rather than gradients.
|
|
144
|
+
*
|
|
145
|
+
* Cheaper than gradient noise and blockier in character. Good for film grain, dithering and
|
|
146
|
+
* any place you want visible cell structure rather than smooth flow.
|
|
147
|
+
*/
|
|
148
|
+
declare function createValueNoise(seed?: number): {
|
|
149
|
+
noise2D(x: number, y: number): number;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The one-stop noise factory.
|
|
154
|
+
*
|
|
155
|
+
* Effects generally want several related fields from a single seed — a base simplex, an fBm
|
|
156
|
+
* for the large structure, and a curl field for advection. Creating them individually would
|
|
157
|
+
* rebuild the permutation table each time (it is cached, but the wiring is still repetitive),
|
|
158
|
+
* so `createNoise(seed)` hands back a coherent bundle.
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* const noise = createNoise('hero')
|
|
162
|
+
* const height = noise.fbm2D({ octaves: 5, gain: 0.55 })
|
|
163
|
+
* const flow = noise.curl({ octaves: 2 })
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
declare function createNoise(seed?: number | string): {
|
|
167
|
+
seed: number;
|
|
168
|
+
/** Raw single-octave sources. */
|
|
169
|
+
simplex2D: (x: number, y: number) => number;
|
|
170
|
+
simplex3D: (x: number, y: number, z: number) => number;
|
|
171
|
+
simplex4D: (x: number, y: number, z: number, w: number) => number;
|
|
172
|
+
perlin2D: (x: number, y: number) => number;
|
|
173
|
+
perlin3D: (x: number, y: number, z: number) => number;
|
|
174
|
+
value2D: (x: number, y: number) => number;
|
|
175
|
+
/** Fractal compositions over simplex. */
|
|
176
|
+
fbm2D: (options?: FractalOptions) => Noise2DFn;
|
|
177
|
+
fbm3D: (options?: FractalOptions) => Noise3DFn;
|
|
178
|
+
ridged2D: (options?: FractalOptions) => Noise2DFn;
|
|
179
|
+
turbulence2D: (options?: FractalOptions) => Noise2DFn;
|
|
180
|
+
/** Domain-warped fBm — the organic, marbled look. */
|
|
181
|
+
warped2D: (strength?: number, options?: FractalOptions) => Noise2DFn;
|
|
182
|
+
/** Divergence-free flow field for particle advection. */
|
|
183
|
+
curl: (options?: FractalOptions) => (x: number, y: number) => CurlResult;
|
|
184
|
+
curlAnimated: (options?: FractalOptions) => (x: number, y: number, t: number) => CurlResult;
|
|
185
|
+
/** Seamlessly tiling field over the given extent. */
|
|
186
|
+
tileable: (width: number, height: number) => Noise2DFn;
|
|
187
|
+
};
|
|
188
|
+
type Noise = ReturnType<typeof createNoise>;
|
|
189
|
+
|
|
190
|
+
export { type CurlResult, FRACTAL_DEFAULTS, type FractalOptions, GRAD3, GRAD4, type Noise, type Noise2DFn, type Noise3DFn, type NoiseTables, type PerlinNoise, type SimplexNoise, clearNoiseTableCache, createNoise, createNoiseTables, createPerlinNoise, createSimplexNoise, createValueNoise, curl2D, curl2DAnimated, fbm2D, fbm3D, ridged2D, tileable2D, turbulence2D, warp2D };
|