@code-of-chaos/dither 0.0.0-stage → 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 +674 -0
- package/README.md +216 -2
- package/dist/DitherBackground.d.ts +37 -0
- package/dist/DitherBackground.d.ts.map +1 -0
- package/dist/DitherBackgroundView.d.ts +65 -0
- package/dist/DitherBackgroundView.d.ts.map +1 -0
- package/dist/DitherTile.d.ts +42 -0
- package/dist/DitherTile.d.ts.map +1 -0
- package/dist/FractalBrownianNoise.d.ts +13 -0
- package/dist/FractalBrownianNoise.d.ts.map +1 -0
- package/dist/MathUtils.d.ts +12 -0
- package/dist/MathUtils.d.ts.map +1 -0
- package/dist/PerlinNoise.d.ts +14 -0
- package/dist/PerlinNoise.d.ts.map +1 -0
- package/dist/RgbColor.d.ts +18 -0
- package/dist/RgbColor.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +304 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +2 -0
- package/package.json +58 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// src/MathUtils.ts
|
|
2
|
+
var e = class e {
|
|
3
|
+
static clamp(e, t, n) {
|
|
4
|
+
return Math.min(Math.max(e, t), n);
|
|
5
|
+
}
|
|
6
|
+
static lerp(e, t, n) {
|
|
7
|
+
return e + (t - e) * n;
|
|
8
|
+
}
|
|
9
|
+
static smoothstep(t, n, r) {
|
|
10
|
+
let i = e.clamp((r - t) / (n - t), 0, 1);
|
|
11
|
+
return i * i * (3 - 2 * i);
|
|
12
|
+
}
|
|
13
|
+
static mod(e, t) {
|
|
14
|
+
return (e % t + t) % t;
|
|
15
|
+
}
|
|
16
|
+
static hash2(e, t, n) {
|
|
17
|
+
let r = Math.imul(e, 374761393) ^ Math.imul(t, 668265263) ^ Math.imul(n, 2246822519);
|
|
18
|
+
return r = Math.imul(r ^ r >>> 13, 1274126177), r ^= r >>> 16, (r >>> 0) / 4294967296;
|
|
19
|
+
}
|
|
20
|
+
}, t = class t {
|
|
21
|
+
period;
|
|
22
|
+
seed;
|
|
23
|
+
static GRADIENTS = Array.from({ length: 16 }, (e, t) => {
|
|
24
|
+
let n = t / 16 * Math.PI * 2;
|
|
25
|
+
return [Math.cos(n), Math.sin(n)];
|
|
26
|
+
});
|
|
27
|
+
constructor(e, t) {
|
|
28
|
+
this.period = e, this.seed = t;
|
|
29
|
+
}
|
|
30
|
+
sample(t, n) {
|
|
31
|
+
let r = Math.floor(t), i = Math.floor(n), a = t - r, o = n - i, s = a * a * a * (a * (a * 6 - 15) + 10), c = o * o * o * (o * (o * 6 - 15) + 10), l = e.mod(r, this.period), u = e.mod(i, this.period), d = e.mod(r + 1, this.period), f = e.mod(i + 1, this.period), p = this.gradientDot(l, u, a, o), m = this.gradientDot(d, u, a - 1, o), h = this.gradientDot(l, f, a, o - 1), g = this.gradientDot(d, f, a - 1, o - 1);
|
|
32
|
+
return e.lerp(e.lerp(p, m, s), e.lerp(h, g, s), c);
|
|
33
|
+
}
|
|
34
|
+
gradientDot(n, r, i, a) {
|
|
35
|
+
let o = t.GRADIENTS, s = o[Math.floor(e.hash2(n, r, this.seed) * o.length) % o.length];
|
|
36
|
+
return s[0] * i + s[1] * a;
|
|
37
|
+
}
|
|
38
|
+
}, n = class {
|
|
39
|
+
noise;
|
|
40
|
+
frequency;
|
|
41
|
+
amplitude;
|
|
42
|
+
constructor(e, t, n) {
|
|
43
|
+
this.noise = e, this.frequency = t, this.amplitude = n;
|
|
44
|
+
}
|
|
45
|
+
}, r = class {
|
|
46
|
+
octaves = [];
|
|
47
|
+
totalAmplitude;
|
|
48
|
+
constructor(e, r, i, a) {
|
|
49
|
+
let o = 1, s = 0;
|
|
50
|
+
for (let c = 0; c < i; c++) {
|
|
51
|
+
let i = Math.max(1, Math.round(e / (r * 2 ** c)));
|
|
52
|
+
this.octaves.push(new n(new t(i, a + c * 1013), i / e, o)), s += o, o *= .5;
|
|
53
|
+
}
|
|
54
|
+
this.totalAmplitude = s;
|
|
55
|
+
}
|
|
56
|
+
sample(t, n) {
|
|
57
|
+
let r = 0;
|
|
58
|
+
for (let e of this.octaves) r += e.amplitude * e.noise.sample(t * e.frequency, n * e.frequency);
|
|
59
|
+
return e.clamp(r / this.totalAmplitude * .6 + .5, 0, 1);
|
|
60
|
+
}
|
|
61
|
+
}, i = class e {
|
|
62
|
+
r;
|
|
63
|
+
g;
|
|
64
|
+
b;
|
|
65
|
+
constructor(e, t, n) {
|
|
66
|
+
this.r = e, this.g = t, this.b = n;
|
|
67
|
+
}
|
|
68
|
+
static fromCss(t, n) {
|
|
69
|
+
let r = e.resolveVariable(n);
|
|
70
|
+
t.fillStyle = "#000000", t.fillStyle = r;
|
|
71
|
+
let i = t.fillStyle;
|
|
72
|
+
if (i.startsWith("#")) {
|
|
73
|
+
let t = i.slice(1), n = t.length === 3 ? t.split("").map((e) => e + e).join("") : t;
|
|
74
|
+
return new e(parseInt(n.slice(0, 2), 16), parseInt(n.slice(2, 4), 16), parseInt(n.slice(4, 6), 16));
|
|
75
|
+
}
|
|
76
|
+
let a = i.match(/rgba?\(([^)]+)\)/);
|
|
77
|
+
if (a) {
|
|
78
|
+
let [t, n, r] = a[1].split(/[,/\s]+/).filter(Boolean).map(Number);
|
|
79
|
+
return new e(t, n, r);
|
|
80
|
+
}
|
|
81
|
+
return new e(255, 255, 255);
|
|
82
|
+
}
|
|
83
|
+
static resolveVariable(e) {
|
|
84
|
+
let t = e.match(/^\s*var\(\s*(--[\w-]+)\s*(?:,\s*([^()]+))?\s*\)\s*$/);
|
|
85
|
+
return t && (getComputedStyle(document.documentElement).getPropertyValue(t[1]).trim() || t[2]?.trim()) || e;
|
|
86
|
+
}
|
|
87
|
+
}, a = class t {
|
|
88
|
+
options;
|
|
89
|
+
static DEFAULT_CELLS = 512;
|
|
90
|
+
static BAYER_4X4 = [
|
|
91
|
+
[
|
|
92
|
+
0,
|
|
93
|
+
8,
|
|
94
|
+
2,
|
|
95
|
+
10
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
12,
|
|
99
|
+
4,
|
|
100
|
+
14,
|
|
101
|
+
6
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
3,
|
|
105
|
+
11,
|
|
106
|
+
1,
|
|
107
|
+
9
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
15,
|
|
111
|
+
7,
|
|
112
|
+
13,
|
|
113
|
+
5
|
|
114
|
+
]
|
|
115
|
+
].map((e) => e.map((e) => (e + .5) / 16));
|
|
116
|
+
islands;
|
|
117
|
+
detail;
|
|
118
|
+
constructor(e) {
|
|
119
|
+
this.options = e, this.islands = new r(e.cells, e.scale, e.octaves, e.seed), this.detail = new r(e.cells, e.detailScale, e.detailOctaves, e.seed + 31337);
|
|
120
|
+
}
|
|
121
|
+
toDataURL() {
|
|
122
|
+
let { cells: n, color: r, density: a, contrast: o, detailStrength: s, clampLow: c, clampHigh: l, seed: u, maxFill: d, jitter: f } = this.options, p = document.createElement("canvas");
|
|
123
|
+
p.width = n, p.height = n;
|
|
124
|
+
let m = p.getContext("2d");
|
|
125
|
+
if (!m) return "";
|
|
126
|
+
let h = i.fromCss(m, r), g = m.createImageData(n, n), _ = g.data;
|
|
127
|
+
for (let r = 0; r < n; r++) for (let i = 0; i < n; i++) {
|
|
128
|
+
let p = this.islands.sample(i, r), m = this.detail.sample(i, r), g = e.clamp(p + (m - .5) * s, 0, 1), v = e.smoothstep(c, Math.max(l, c + .001), g), y = e.clamp((v - .5) * o + a, 0, d);
|
|
129
|
+
if (t.BAYER_4X4[r % 4][i % 4] * (1 - f) + e.hash2(i, r, u + 991) * f < y) {
|
|
130
|
+
let t = (r * n + i) * 4;
|
|
131
|
+
_[t] = h.r, _[t + 1] = h.g, _[t + 2] = h.b, _[t + 3] = Math.round(255 * e.clamp(.4 + .6 * v, 0, 1));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return m.putImageData(g, 0, 0), p.toDataURL("image/png");
|
|
135
|
+
}
|
|
136
|
+
}, o = class e {
|
|
137
|
+
static DEFAULTS = {
|
|
138
|
+
backgroundColor: "linear-gradient(to bottom, var(--color-wine-950) 0%, var(--color-ink-950) 65%)",
|
|
139
|
+
gridColor: "var(--color-steel-500)",
|
|
140
|
+
gridSize: 41,
|
|
141
|
+
gridOpacity: .23,
|
|
142
|
+
noiseColor: "var(--color-scarlet-600)",
|
|
143
|
+
noiseOpacity: .5,
|
|
144
|
+
noiseSize: 3,
|
|
145
|
+
noiseTileCells: a.DEFAULT_CELLS,
|
|
146
|
+
noiseDensity: .55,
|
|
147
|
+
noiseContrast: 1.8,
|
|
148
|
+
noiseScale: 32,
|
|
149
|
+
noiseOctaves: 3,
|
|
150
|
+
noiseDetailScale: 5,
|
|
151
|
+
noiseDetailOctaves: 3,
|
|
152
|
+
noiseDetailStrength: .2,
|
|
153
|
+
noiseClampLow: 0,
|
|
154
|
+
noiseClampHigh: .9,
|
|
155
|
+
noiseSeed: 69,
|
|
156
|
+
noiseMaxFill: .6,
|
|
157
|
+
noiseJitter: .3,
|
|
158
|
+
noiseSpeed: 180,
|
|
159
|
+
noiseAngle: 100,
|
|
160
|
+
noiseTravel: 1,
|
|
161
|
+
fadeStart: 0,
|
|
162
|
+
fadeEnd: 90,
|
|
163
|
+
animateNoise: !0,
|
|
164
|
+
animateGlow: !0
|
|
165
|
+
};
|
|
166
|
+
static TILE_INPUTS = [
|
|
167
|
+
"noiseTileCells",
|
|
168
|
+
"noiseColor",
|
|
169
|
+
"noiseDensity",
|
|
170
|
+
"noiseContrast",
|
|
171
|
+
"noiseScale",
|
|
172
|
+
"noiseOctaves",
|
|
173
|
+
"noiseDetailScale",
|
|
174
|
+
"noiseDetailOctaves",
|
|
175
|
+
"noiseDetailStrength",
|
|
176
|
+
"noiseClampLow",
|
|
177
|
+
"noiseClampHigh",
|
|
178
|
+
"noiseSeed",
|
|
179
|
+
"noiseMaxFill",
|
|
180
|
+
"noiseJitter"
|
|
181
|
+
];
|
|
182
|
+
options;
|
|
183
|
+
constructor(t = {}) {
|
|
184
|
+
this.options = {
|
|
185
|
+
...e.DEFAULTS,
|
|
186
|
+
...e.defined(t)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
merge(t) {
|
|
190
|
+
return new e({
|
|
191
|
+
...this.options,
|
|
192
|
+
...e.defined(t)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
rebuildsTile(t) {
|
|
196
|
+
return e.TILE_INPUTS.some((e) => this.options[e] !== t.options[e]);
|
|
197
|
+
}
|
|
198
|
+
tileOptions() {
|
|
199
|
+
let e = this.options;
|
|
200
|
+
return {
|
|
201
|
+
cells: e.noiseTileCells,
|
|
202
|
+
color: e.noiseColor,
|
|
203
|
+
density: e.noiseDensity,
|
|
204
|
+
contrast: e.noiseContrast,
|
|
205
|
+
scale: e.noiseScale,
|
|
206
|
+
octaves: e.noiseOctaves,
|
|
207
|
+
detailScale: e.noiseDetailScale,
|
|
208
|
+
detailOctaves: e.noiseDetailOctaves,
|
|
209
|
+
detailStrength: e.noiseDetailStrength,
|
|
210
|
+
clampLow: e.noiseClampLow,
|
|
211
|
+
clampHigh: e.noiseClampHigh,
|
|
212
|
+
seed: e.noiseSeed,
|
|
213
|
+
maxFill: e.noiseMaxFill,
|
|
214
|
+
jitter: e.noiseJitter
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
get tileSize() {
|
|
218
|
+
return this.options.noiseTileCells * this.options.noiseSize;
|
|
219
|
+
}
|
|
220
|
+
get travelX() {
|
|
221
|
+
let e = this.options.noiseAngle * Math.PI / 180;
|
|
222
|
+
return Math.round(Math.cos(e) * this.options.noiseTravel) * this.tileSize;
|
|
223
|
+
}
|
|
224
|
+
get travelY() {
|
|
225
|
+
let e = this.options.noiseAngle * Math.PI / 180;
|
|
226
|
+
return Math.round(Math.sin(e) * this.options.noiseTravel) * this.tileSize;
|
|
227
|
+
}
|
|
228
|
+
get overscan() {
|
|
229
|
+
return Math.max(Math.abs(this.travelX), Math.abs(this.travelY)) + this.tileSize;
|
|
230
|
+
}
|
|
231
|
+
cssVars(e) {
|
|
232
|
+
let t = this.options;
|
|
233
|
+
return {
|
|
234
|
+
"--background-color": t.backgroundColor,
|
|
235
|
+
"--grid-color": t.gridColor,
|
|
236
|
+
"--grid-size": `${t.gridSize}px`,
|
|
237
|
+
"--grid-opacity": String(t.gridOpacity),
|
|
238
|
+
"--noise-image": `url("${e}")`,
|
|
239
|
+
"--noise-tile-size": `${this.tileSize}px`,
|
|
240
|
+
"--noise-color": t.noiseColor,
|
|
241
|
+
"--noise-opacity": String(t.noiseOpacity),
|
|
242
|
+
"--noise-speed": `${t.noiseSpeed}s`,
|
|
243
|
+
"--noise-x": `${this.travelX}px`,
|
|
244
|
+
"--noise-y": `${this.travelY}px`,
|
|
245
|
+
"--noise-overscan": `${this.overscan}px`,
|
|
246
|
+
"--fade-start": `${t.fadeStart}%`,
|
|
247
|
+
"--fade-end": `${t.fadeEnd}%`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
static defined(e) {
|
|
251
|
+
let t = Object.entries(e).filter(([, e]) => e !== void 0);
|
|
252
|
+
return Object.fromEntries(t);
|
|
253
|
+
}
|
|
254
|
+
}, s = class e {
|
|
255
|
+
static ROOT_CLASS = "dither-grid-background";
|
|
256
|
+
static ANIMATED_CLASS = "dither-grid-background--animated";
|
|
257
|
+
static GLOW_CLASS = "dither-grid-background--glow";
|
|
258
|
+
view;
|
|
259
|
+
noiseImage = "";
|
|
260
|
+
root = null;
|
|
261
|
+
layers = [];
|
|
262
|
+
constructor(e = {}) {
|
|
263
|
+
this.view = new o(e);
|
|
264
|
+
}
|
|
265
|
+
mount(e) {
|
|
266
|
+
if (this.root) throw Error("DitherBackground is already mounted");
|
|
267
|
+
this.root = e;
|
|
268
|
+
let t = document.createElement("div");
|
|
269
|
+
t.className = "dither-grid-background__noise-texture";
|
|
270
|
+
let n = document.createElement("div");
|
|
271
|
+
n.className = "dither-grid-background__noise", n.setAttribute("aria-hidden", "true"), n.append(t);
|
|
272
|
+
let r = document.createElement("div");
|
|
273
|
+
r.className = "dither-grid-background__grid", r.setAttribute("aria-hidden", "true"), this.layers = [n, r], e.prepend(...this.layers), this.noiseImage = this.createNoiseImage(), this.apply();
|
|
274
|
+
}
|
|
275
|
+
update(e) {
|
|
276
|
+
let t = this.view.merge(e), n = this.view.rebuildsTile(t);
|
|
277
|
+
this.view = t, n && (this.noiseImage = this.createNoiseImage()), this.apply();
|
|
278
|
+
}
|
|
279
|
+
destroy() {
|
|
280
|
+
let t = this.root;
|
|
281
|
+
if (t) {
|
|
282
|
+
for (let e of this.layers) e.remove();
|
|
283
|
+
this.layers = [], t.classList.remove(e.ROOT_CLASS, e.ANIMATED_CLASS, e.GLOW_CLASS);
|
|
284
|
+
for (let e of Object.keys(this.view.cssVars(""))) t.style.removeProperty(e);
|
|
285
|
+
this.root = null, this.noiseImage = "";
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
get element() {
|
|
289
|
+
return this.root;
|
|
290
|
+
}
|
|
291
|
+
apply() {
|
|
292
|
+
let t = this.root;
|
|
293
|
+
if (!t) return;
|
|
294
|
+
t.classList.add(e.ROOT_CLASS), t.classList.toggle(e.ANIMATED_CLASS, this.view.options.animateNoise), t.classList.toggle(e.GLOW_CLASS, this.view.options.animateGlow);
|
|
295
|
+
let n = this.view.cssVars(this.noiseImage);
|
|
296
|
+
for (let [e, r] of Object.entries(n)) t.style.setProperty(e, r);
|
|
297
|
+
}
|
|
298
|
+
createNoiseImage() {
|
|
299
|
+
return new a(this.view.tileOptions()).toDataURL();
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
export { s as DitherBackground, o as DitherBackgroundView, a as DitherTile, r as FractalBrownianNoise, e as MathUtils, t as PerlinNoise, i as RgbColor };
|
|
303
|
+
|
|
304
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["MathUtils","value","min","max","a","b","t","x","edge0","edge1","period","h","y","seed","PerlinNoise","angle","i","x0","y0","fx","fy","u","v","ix0","iy0","ix1","iy1","n00","n10","n01","n11","gradients","g","ix","iy","dx","dy","Octave","noise","frequency","amplitude","FractalBrownianNoise","total","o","octaves","cells","scale","sum","octave","RgbColor","r","resolved","css","normalized","ctx","hex","full","c","match","DitherTile","row","options","canvas","rgb","color","image","data","island","detail","combined","detailStrength","n","clampLow","clampHigh","p","contrast","density","maxFill","jitter","DitherBackgroundView","partial","key","other","noiseImage","entries","DitherBackground","container","texture","grid","next","rebuildTile","root","layer","name","vars"],"sources":["../src/MathUtils.ts","../src/PerlinNoise.ts","../src/FractalBrownianNoise.ts","../src/RgbColor.ts","../src/DitherTile.ts","../src/DitherBackgroundView.ts","../src/DitherBackground.ts"],"sourcesContent":["/**\n * Small math helpers used by the noise and dither pipeline.\n * The standard Math library has no clamp/lerp/smoothstep/mod equivalents.\n */\nexport class MathUtils {\n static clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n }\n\n static lerp(a: number, b: number, t: number): number {\n return a + (b - a) * t;\n }\n\n static smoothstep(edge0: number, edge1: number, x: number): number {\n const t = MathUtils.clamp((x - edge0) / (edge1 - edge0), 0, 1);\n return t * t * (3 - 2 * t);\n }\n\n static mod(value: number, period: number): number {\n return ((value % period) + period) % period;\n }\n\n static hash2(x: number, y: number, seed: number): number {\n let h =\n Math.imul(x, 374761393)\n ^ Math.imul(y, 668265263)\n ^ Math.imul(seed, 2246822519);\n h = Math.imul(h ^ (h >>> 13), 1274126177);\n h ^= h >>> 16;\n return (h >>> 0) / 4294967296;\n }\n}\n","import { MathUtils } from \"./MathUtils\";\n\n/**\n * Tileable 2D Perlin gradient noise. Lattice coordinates wrap at `period`,\n * so sampling the [0, period) cell range produces a seamless tile.\n * Raw output is roughly in [-1, 1] (see FractalBrownianNoise for normalized values).\n */\nexport class PerlinNoise {\n private static readonly GRADIENTS: ReadonlyArray<\n readonly [number, number]\n > = Array.from({ length: 16 }, (_, i) => {\n const angle = (i / 16) * Math.PI * 2;\n return [Math.cos(angle), Math.sin(angle)] as const;\n });\n\n constructor(\n private readonly period: number,\n private readonly seed: number,\n ) {}\n\n sample(x: number, y: number): number {\n const x0 = Math.floor(x);\n const y0 = Math.floor(y);\n const fx = x - x0;\n const fy = y - y0;\n\n const u = fx * fx * fx * (fx * (fx * 6 - 15) + 10);\n const v = fy * fy * fy * (fy * (fy * 6 - 15) + 10);\n\n const ix0 = MathUtils.mod(x0, this.period);\n const iy0 = MathUtils.mod(y0, this.period);\n const ix1 = MathUtils.mod(x0 + 1, this.period);\n const iy1 = MathUtils.mod(y0 + 1, this.period);\n\n const n00 = this.gradientDot(ix0, iy0, fx, fy);\n const n10 = this.gradientDot(ix1, iy0, fx - 1, fy);\n const n01 = this.gradientDot(ix0, iy1, fx, fy - 1);\n const n11 = this.gradientDot(ix1, iy1, fx - 1, fy - 1);\n\n return MathUtils.lerp(\n MathUtils.lerp(n00, n10, u),\n MathUtils.lerp(n01, n11, u),\n v,\n );\n }\n\n private gradientDot(\n ix: number,\n iy: number,\n dx: number,\n dy: number,\n ): number {\n const gradients = PerlinNoise.GRADIENTS;\n const g =\n gradients[\n Math.floor(\n MathUtils.hash2(ix, iy, this.seed) * gradients.length,\n ) % gradients.length\n ];\n return g[0] * dx + g[1] * dy;\n }\n}\n","import { MathUtils } from \"./MathUtils\";\nimport { PerlinNoise } from \"./PerlinNoise\";\n\nclass Octave {\n constructor(\n readonly noise: PerlinNoise,\n readonly frequency: number,\n readonly amplitude: number,\n ) {}\n}\n\n/**\n * Fractal Brownian motion: stacks PerlinNoise octaves with halved amplitude\n * and doubled frequency per octave. Coordinates are expressed in tile cells,\n * keeping every octave (and therefore the whole field) seamlessly tileable.\n * Output is normalized to [0, 1].\n */\nexport class FractalBrownianNoise {\n private readonly octaves: Octave[] = [];\n private readonly totalAmplitude: number;\n\n constructor(cells: number, scale: number, octaves: number, seed: number) {\n let amplitude = 1;\n let total = 0;\n\n for (let o = 0; o < octaves; o++) {\n const period = Math.max(1, Math.round(cells / (scale * 2 ** o)));\n this.octaves.push(\n new Octave(\n new PerlinNoise(period, seed + o * 1013),\n period / cells,\n amplitude,\n ),\n );\n total += amplitude;\n amplitude *= 0.5;\n }\n\n this.totalAmplitude = total;\n }\n\n sample(x: number, y: number): number {\n let sum = 0;\n\n for (const octave of this.octaves) {\n sum +=\n octave.amplitude\n * octave.noise.sample(\n x * octave.frequency,\n y * octave.frequency,\n );\n }\n\n return MathUtils.clamp((sum / this.totalAmplitude) * 0.6 + 0.5, 0, 1);\n }\n}\n","/** Immutable RGB triple with CSS color parsing. */\nexport class RgbColor {\n constructor(\n readonly r: number,\n readonly g: number,\n readonly b: number,\n ) {}\n\n /**\n * Parses any CSS color (named, hex, rgb()/rgba()) by letting the canvas\n * resolve it: assigning to fillStyle normalizes the value to a canonical\n * string which is then read back. Falls back to white on invalid input.\n *\n * A single var(--token, fallback) reference is resolved against the\n * document root first, so theme variables can be used as color parameters.\n */\n static fromCss(ctx: CanvasRenderingContext2D, css: string): RgbColor {\n const resolved = RgbColor.resolveVariable(css);\n ctx.fillStyle = \"#000000\";\n ctx.fillStyle = resolved;\n const normalized = ctx.fillStyle;\n\n if (normalized.startsWith(\"#\")) {\n const hex = normalized.slice(1);\n const full =\n hex.length === 3\n ? hex\n .split(\"\")\n .map((c) => c + c)\n .join(\"\")\n : hex;\n return new RgbColor(\n parseInt(full.slice(0, 2), 16),\n parseInt(full.slice(2, 4), 16),\n parseInt(full.slice(4, 6), 16),\n );\n }\n\n const match = normalized.match(/rgba?\\(([^)]+)\\)/);\n if (match) {\n const [r, g, b] = match[1]\n .split(/[,/\\s]+/)\n .filter(Boolean)\n .map(Number);\n return new RgbColor(r, g, b);\n }\n\n return new RgbColor(255, 255, 255);\n }\n\n private static resolveVariable(css: string): string {\n const match = css.match(\n /^\\s*var\\(\\s*(--[\\w-]+)\\s*(?:,\\s*([^()]+))?\\s*\\)\\s*$/,\n );\n if (!match) return css;\n\n const value = getComputedStyle(document.documentElement)\n .getPropertyValue(match[1])\n .trim();\n return value || match[2]?.trim() || css;\n }\n}\n","import { FractalBrownianNoise } from \"./FractalBrownianNoise\";\nimport { MathUtils } from \"./MathUtils\";\nimport { RgbColor } from \"./RgbColor\";\n\n/**\n * All visual knobs of the tile. `scale`/`octaves` shape the large island\n * field, `detail*` the fine detail field; `clampLow`/`clampHigh` soft-clip\n * the blend (clean voids at the low end, no saturation at the high end),\n * `maxFill` caps how dense the dither can get, and `jitter` blends the\n * Bayer threshold with per-pixel random values for an organic look.\n */\nexport type DitherTileOptions = {\n cells: number;\n color: string;\n density: number;\n contrast: number;\n scale: number;\n octaves: number;\n detailScale: number;\n detailOctaves: number;\n detailStrength: number;\n clampLow: number;\n clampHigh: number;\n seed: number;\n maxFill: number;\n jitter: number;\n};\n\n/**\n * Renders a seamless dithered noise tile as a PNG data URL.\n *\n * Per pixel: the island and detail noise fields are blended into a density\n * value, soft-clamped, then thresholded against a Bayer matrix mixed with\n * per-pixel jitter to decide whether the pixel is inked. Because the noise\n * fields tile seamlessly, the resulting image can be repeated and scrolled\n * forever without visible seams.\n */\nexport class DitherTile {\n static readonly DEFAULT_CELLS = 512;\n\n private static readonly BAYER_4X4 = [\n [0, 8, 2, 10],\n [12, 4, 14, 6],\n [3, 11, 1, 9],\n [15, 7, 13, 5],\n ].map((row) => row.map((v) => (v + 0.5) / 16));\n\n private readonly islands: FractalBrownianNoise;\n private readonly detail: FractalBrownianNoise;\n\n constructor(private readonly options: DitherTileOptions) {\n this.islands = new FractalBrownianNoise(\n options.cells,\n options.scale,\n options.octaves,\n options.seed,\n );\n this.detail = new FractalBrownianNoise(\n options.cells,\n options.detailScale,\n options.detailOctaves,\n options.seed + 31337,\n );\n }\n\n toDataURL(): string {\n const {\n cells,\n color,\n density,\n contrast,\n detailStrength,\n clampLow,\n clampHigh,\n seed,\n maxFill,\n jitter,\n } = this.options;\n\n const canvas = document.createElement(\"canvas\");\n canvas.width = cells;\n canvas.height = cells;\n\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return \"\";\n\n const rgb = RgbColor.fromCss(ctx, color);\n const image = ctx.createImageData(cells, cells);\n const data = image.data;\n\n for (let y = 0; y < cells; y++) {\n for (let x = 0; x < cells; x++) {\n const island = this.islands.sample(x, y);\n const detail = this.detail.sample(x, y);\n const combined = MathUtils.clamp(\n island + (detail - 0.5) * detailStrength,\n 0,\n 1,\n );\n const n = MathUtils.smoothstep(\n clampLow,\n Math.max(clampHigh, clampLow + 0.001),\n combined,\n );\n const p = MathUtils.clamp(\n (n - 0.5) * contrast + density,\n 0,\n maxFill,\n );\n const bayer = DitherTile.BAYER_4X4[y % 4][x % 4];\n const threshold =\n bayer * (1 - jitter)\n + MathUtils.hash2(x, y, seed + 991) * jitter;\n\n if (threshold < p) {\n const i = (y * cells + x) * 4;\n data[i] = rgb.r;\n data[i + 1] = rgb.g;\n data[i + 2] = rgb.b;\n data[i + 3] = Math.round(\n 255 * MathUtils.clamp(0.4 + 0.6 * n, 0, 1),\n );\n }\n }\n }\n\n ctx.putImageData(image, 0, 0);\n return canvas.toDataURL(\"image/png\");\n }\n}\n","import type { DitherTileOptions } from \"./DitherTile\";\nimport { DitherTile } from \"./DitherTile\";\n\n/**\n * Every visual knob of a dither background. All fields are optional and fall\n * back to `DitherBackgroundView.DEFAULTS`. Values are applied as CSS custom\n * properties, so they can be animated at runtime without rebuilding the\n * background; only `DitherBackgroundView.TILE_INPUTS` regenerate the dither\n * bitmap itself.\n */\nexport type DitherBackgroundOptions = {\n backgroundColor?: string;\n\n gridColor?: string;\n gridSize?: number;\n gridOpacity?: number;\n\n noiseColor?: string;\n noiseOpacity?: number;\n noiseSize?: number;\n noiseTileCells?: number;\n noiseDensity?: number;\n noiseContrast?: number;\n noiseScale?: number;\n noiseOctaves?: number;\n noiseDetailScale?: number;\n noiseDetailOctaves?: number;\n noiseDetailStrength?: number;\n noiseClampLow?: number;\n noiseClampHigh?: number;\n noiseSeed?: number;\n noiseMaxFill?: number;\n noiseJitter?: number;\n noiseSpeed?: number;\n noiseAngle?: number;\n noiseTravel?: number;\n\n fadeStart?: number;\n fadeEnd?: number;\n\n animateNoise?: boolean;\n animateGlow?: boolean;\n};\n\nexport type DitherBackgroundCssVars = Record<`--${string}`, string>;\n\n/**\n * Resolves `DitherBackgroundOptions` against the defaults and computes the\n * derived values (tile geometry, scroll travel, CSS custom properties). Used\n * internally by `DitherBackground`; framework wrappers can use it standalone.\n */\nexport class DitherBackgroundView {\n static readonly DEFAULTS: Required<DitherBackgroundOptions> = {\n backgroundColor:\n \"linear-gradient(to bottom, var(--color-wine-950) 0%, var(--color-ink-950) 65%)\",\n\n gridColor: \"var(--color-steel-500)\",\n gridSize: 41,\n gridOpacity: 0.23,\n\n noiseColor: \"var(--color-scarlet-600)\",\n noiseOpacity: 0.5,\n noiseSize: 3,\n noiseTileCells: DitherTile.DEFAULT_CELLS,\n noiseDensity: 0.55,\n noiseContrast: 1.8,\n noiseScale: 32,\n noiseOctaves: 3,\n noiseDetailScale: 5,\n noiseDetailOctaves: 3,\n noiseDetailStrength: 0.2,\n noiseClampLow: 0,\n noiseClampHigh: 0.9,\n noiseSeed: 69,\n noiseMaxFill: 0.6,\n noiseJitter: 0.3,\n noiseSpeed: 180,\n noiseAngle: 100,\n noiseTravel: 1,\n\n fadeStart: 0,\n fadeEnd: 90,\n\n animateNoise: true,\n animateGlow: true,\n };\n\n /** Options that affect the generated tile; all others only set CSS variables. */\n static readonly TILE_INPUTS: ReadonlyArray<keyof DitherBackgroundOptions> =\n [\n \"noiseTileCells\",\n \"noiseColor\",\n \"noiseDensity\",\n \"noiseContrast\",\n \"noiseScale\",\n \"noiseOctaves\",\n \"noiseDetailScale\",\n \"noiseDetailOctaves\",\n \"noiseDetailStrength\",\n \"noiseClampLow\",\n \"noiseClampHigh\",\n \"noiseSeed\",\n \"noiseMaxFill\",\n \"noiseJitter\",\n ];\n\n readonly options: Required<DitherBackgroundOptions>;\n\n constructor(options: DitherBackgroundOptions = {}) {\n this.options = {\n ...DitherBackgroundView.DEFAULTS,\n ...DitherBackgroundView.defined(options),\n };\n }\n\n /** Returns a new view with `partial` merged in; `undefined` values are ignored. */\n merge(partial: DitherBackgroundOptions): DitherBackgroundView {\n return new DitherBackgroundView({\n ...this.options,\n ...DitherBackgroundView.defined(partial),\n });\n }\n\n /** True when the two views would produce different dither tiles. */\n rebuildsTile(other: DitherBackgroundView): boolean {\n return DitherBackgroundView.TILE_INPUTS.some(\n (key) => this.options[key] !== other.options[key],\n );\n }\n\n tileOptions(): DitherTileOptions {\n const o = this.options;\n return {\n cells: o.noiseTileCells,\n color: o.noiseColor,\n density: o.noiseDensity,\n contrast: o.noiseContrast,\n scale: o.noiseScale,\n octaves: o.noiseOctaves,\n detailScale: o.noiseDetailScale,\n detailOctaves: o.noiseDetailOctaves,\n detailStrength: o.noiseDetailStrength,\n clampLow: o.noiseClampLow,\n clampHigh: o.noiseClampHigh,\n seed: o.noiseSeed,\n maxFill: o.noiseMaxFill,\n jitter: o.noiseJitter,\n };\n }\n\n get tileSize(): number {\n return this.options.noiseTileCells * this.options.noiseSize;\n }\n\n /** Horizontal scroll distance in px, snapped to whole tiles (seamless loop). */\n get travelX(): number {\n const angle = (this.options.noiseAngle * Math.PI) / 180;\n return (\n Math.round(Math.cos(angle) * this.options.noiseTravel)\n * this.tileSize\n );\n }\n\n /** Vertical scroll distance in px, snapped to whole tiles (seamless loop). */\n get travelY(): number {\n const angle = (this.options.noiseAngle * Math.PI) / 180;\n return (\n Math.round(Math.sin(angle) * this.options.noiseTravel)\n * this.tileSize\n );\n }\n\n /** Oversizes the texture wrapper so the scroll never exposes its edges. */\n get overscan(): number {\n return (\n Math.max(Math.abs(this.travelX), Math.abs(this.travelY))\n + this.tileSize\n );\n }\n\n cssVars(noiseImage: string): DitherBackgroundCssVars {\n const o = this.options;\n return {\n \"--background-color\": o.backgroundColor,\n\n \"--grid-color\": o.gridColor,\n \"--grid-size\": `${o.gridSize}px`,\n \"--grid-opacity\": String(o.gridOpacity),\n\n \"--noise-image\": `url(\"${noiseImage}\")`,\n \"--noise-tile-size\": `${this.tileSize}px`,\n \"--noise-color\": o.noiseColor,\n \"--noise-opacity\": String(o.noiseOpacity),\n \"--noise-speed\": `${o.noiseSpeed}s`,\n \"--noise-x\": `${this.travelX}px`,\n \"--noise-y\": `${this.travelY}px`,\n \"--noise-overscan\": `${this.overscan}px`,\n\n \"--fade-start\": `${o.fadeStart}%`,\n \"--fade-end\": `${o.fadeEnd}%`,\n };\n }\n\n private static defined(\n options: DitherBackgroundOptions,\n ): DitherBackgroundOptions {\n const entries = Object.entries(options).filter(\n ([, value]) => value !== undefined,\n );\n return Object.fromEntries(entries) as DitherBackgroundOptions;\n }\n}\n","import \"./DitherBackground.css\";\nimport { DitherTile } from \"./DitherTile\";\nimport type {\n DitherBackgroundCssVars,\n DitherBackgroundOptions,\n} from \"./DitherBackgroundView\";\nimport { DitherBackgroundView } from \"./DitherBackgroundView\";\n\n/**\n * Framework-agnostic layered background: a scrolling Bayer-dithered noise\n * texture, a static grid and an optional ambient glow. Plain DOM — mount it\n * on any element from any framework (or none).\n *\n * `mount()` decorates the container: it prepends the hidden layer elements\n * and applies the base class plus the CSS custom properties. Anything else\n * in the container renders above the layers, so frameworks keep rendering\n * their children normally. Options map 1:1 to the CSS custom properties and\n * can be changed at any time via `update()`; the dither bitmap is only\n * regenerated when one of the tile inputs changes.\n *\n * The tile is generated on a canvas, so `mount()` requires a browser DOM.\n */\nexport class DitherBackground {\n static readonly ROOT_CLASS = \"dither-grid-background\";\n static readonly ANIMATED_CLASS = \"dither-grid-background--animated\";\n static readonly GLOW_CLASS = \"dither-grid-background--glow\";\n\n private view: DitherBackgroundView;\n private noiseImage = \"\";\n private root: HTMLElement | null = null;\n private layers: HTMLElement[] = [];\n\n constructor(options: DitherBackgroundOptions = {}) {\n this.view = new DitherBackgroundView(options);\n }\n\n /** Decorates `container` with the background layers. Idempotent per instance. */\n mount(container: HTMLElement): void {\n if (this.root) {\n throw new Error(\"DitherBackground is already mounted\");\n }\n this.root = container;\n\n const texture = document.createElement(\"div\");\n texture.className = \"dither-grid-background__noise-texture\";\n const noise = document.createElement(\"div\");\n noise.className = \"dither-grid-background__noise\";\n noise.setAttribute(\"aria-hidden\", \"true\");\n noise.append(texture);\n\n const grid = document.createElement(\"div\");\n grid.className = \"dither-grid-background__grid\";\n grid.setAttribute(\"aria-hidden\", \"true\");\n\n this.layers = [noise, grid];\n container.prepend(...this.layers);\n\n this.noiseImage = this.createNoiseImage();\n this.apply();\n }\n\n /** Merges new options; regenerates the tile only when tile inputs change. */\n update(partial: DitherBackgroundOptions): void {\n const next = this.view.merge(partial);\n const rebuildTile = this.view.rebuildsTile(next);\n this.view = next;\n if (rebuildTile) {\n this.noiseImage = this.createNoiseImage();\n }\n this.apply();\n }\n\n /** Removes the layers and reverts the container to its unmounted state. */\n destroy(): void {\n const root = this.root;\n if (!root) return;\n\n for (const layer of this.layers) layer.remove();\n this.layers = [];\n\n root.classList.remove(\n DitherBackground.ROOT_CLASS,\n DitherBackground.ANIMATED_CLASS,\n DitherBackground.GLOW_CLASS,\n );\n for (const name of Object.keys(this.view.cssVars(\"\"))) {\n root.style.removeProperty(name);\n }\n\n this.root = null;\n this.noiseImage = \"\";\n }\n\n /** The decorated container element, or `null` before mount / after destroy. */\n get element(): HTMLElement | null {\n return this.root;\n }\n\n private apply(): void {\n const root = this.root;\n if (!root) return;\n\n root.classList.add(DitherBackground.ROOT_CLASS);\n root.classList.toggle(\n DitherBackground.ANIMATED_CLASS,\n this.view.options.animateNoise,\n );\n root.classList.toggle(\n DitherBackground.GLOW_CLASS,\n this.view.options.animateGlow,\n );\n\n const vars: DitherBackgroundCssVars = this.view.cssVars(\n this.noiseImage,\n );\n for (const [name, value] of Object.entries(vars)) {\n root.style.setProperty(name, value);\n }\n }\n\n private createNoiseImage(): string {\n return new Dither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CAE1C;CAEA,mBAAmC;EAC/B,OAAO,IAAI0D,EAAW,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,UAAU;CAC7D;AACJ"}
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
.dither-grid-background{isolation:isolate;background:var(--background-color);min-height:100%;position:relative;overflow:hidden}.dither-grid-background__noise{z-index:-1;pointer-events:none;opacity:var(--noise-opacity);-webkit-mask-image:linear-gradient(to bottom, black 0%, black var(--fade-start), #000000b3 55%, transparent var(--fade-end));-webkit-mask-image:linear-gradient(to bottom, black 0%, black var(--fade-start), #000000b3 55%, transparent var(--fade-end));mask-image:linear-gradient(to bottom, black 0%, black var(--fade-start), #000000b3 55%, transparent var(--fade-end));position:absolute;inset:0;overflow:hidden}.dither-grid-background__noise-texture{inset:calc(-1 * var(--noise-overscan));background-image:var(--noise-image);background-size:var(--noise-tile-size) var(--noise-tile-size);image-rendering:pixelated;background-repeat:repeat;position:absolute}.dither-grid-background--animated .dither-grid-background__noise-texture{will-change:transform;animation:dither-noise-scroll var(--noise-speed) linear infinite}@keyframes dither-noise-scroll{0%{transform:translate(0,0)}to{transform:translate3d(var(--noise-x), var(--noise-y), 0)}}.dither-grid-background__grid{z-index:-1;pointer-events:none;background-image:linear-gradient(to right, var(--grid-color) 1px, transparent 1px), linear-gradient(to bottom, var(--grid-color) 1px, transparent 1px);background-size:var(--grid-size) var(--grid-size);opacity:var(--grid-opacity);position:absolute;inset:0}.dither-grid-background--glow:before{content:"";z-index:-1;pointer-events:none;background:radial-gradient(ellipse at 50% 0%, var(--noise-color) 0%, transparent 65%);opacity:.15;animation:12s ease-in-out infinite alternate dither-glow;position:absolute;inset:-20%}@keyframes dither-glow{0%{opacity:.08;transform:translateY(-2%)}to{opacity:.22;transform:translateY(2%)}}.dither-grid-background__content{z-index:1;min-height:inherit;position:relative}@media (prefers-reduced-motion:reduce){.dither-grid-background--animated .dither-grid-background__noise-texture,.dither-grid-background--glow:before{animation:none}}
|
|
2
|
+
/*$vite$:1*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@code-of-chaos/dither",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Framework-agnostic animated bitmap-dithered gradient backgrounds, with a tileable Perlin/fBm noise engine for generating custom dither tiles.",
|
|
5
|
+
"license": "GPL-3.0-only",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"**/*.css"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./style.css": "./dist/style.css"
|
|
19
|
+
},
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite",
|
|
24
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
"lint": "biome lint .",
|
|
28
|
+
"format": "biome format --write .",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"react",
|
|
33
|
+
"dither",
|
|
34
|
+
"bitmap",
|
|
35
|
+
"gradient",
|
|
36
|
+
"background",
|
|
37
|
+
"noise",
|
|
38
|
+
"perlin",
|
|
39
|
+
"bayer",
|
|
40
|
+
"animation"
|
|
41
|
+
],
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/code-of-chaos/Dither.Js.git"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=26"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@biomejs/biome": "^2.6.5",
|
|
54
|
+
"happy-dom": "^21.0.4",
|
|
55
|
+
"typescript": "~7.0.2",
|
|
56
|
+
"vite": "^8.3.6",
|
|
57
|
+
"vitest": "^5.1.0"
|
|
58
|
+
}
|
|
59
|
+
}
|