@lovo/matter 0.1.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/README.md +44 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.cjs +555 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +361 -0
- package/dist/index.d.ts +361 -0
- package/dist/index.js +512 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
// src/runtime/createRenderer.ts
|
|
2
|
+
import { WebGPURenderer } from "three/webgpu";
|
|
3
|
+
import { Color } from "three";
|
|
4
|
+
async function createRenderer(canvas, opts = {}) {
|
|
5
|
+
const {
|
|
6
|
+
antialias = true,
|
|
7
|
+
forceWebGL = false,
|
|
8
|
+
clearColor = 0,
|
|
9
|
+
clearAlpha = 0,
|
|
10
|
+
maxDPR = 2
|
|
11
|
+
} = opts;
|
|
12
|
+
const three = new WebGPURenderer({
|
|
13
|
+
canvas,
|
|
14
|
+
antialias,
|
|
15
|
+
forceWebGL
|
|
16
|
+
});
|
|
17
|
+
await three.init();
|
|
18
|
+
three.setPixelRatio(Math.min(window.devicePixelRatio, maxDPR));
|
|
19
|
+
const resolvedClearColor = clearColor instanceof Color ? clearColor : new Color(clearColor);
|
|
20
|
+
three.setClearColor(resolvedClearColor, clearAlpha);
|
|
21
|
+
const resize = () => {
|
|
22
|
+
const w = canvas.clientWidth;
|
|
23
|
+
const h = canvas.clientHeight;
|
|
24
|
+
if (canvas.width !== w * three.getPixelRatio() || canvas.height !== h * three.getPixelRatio()) {
|
|
25
|
+
three.setSize(w, h, false);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
resize();
|
|
29
|
+
const backend = forceWebGL || three.backend?.isWebGLBackend ? "webgl2" : "webgpu";
|
|
30
|
+
return {
|
|
31
|
+
three,
|
|
32
|
+
backend,
|
|
33
|
+
dispose: () => three.dispose(),
|
|
34
|
+
resize
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/runtime/MatterScheduler.ts
|
|
39
|
+
var MatterScheduler = class {
|
|
40
|
+
clients = /* @__PURE__ */ new Set();
|
|
41
|
+
rafId = null;
|
|
42
|
+
running = false;
|
|
43
|
+
paused = false;
|
|
44
|
+
idle = false;
|
|
45
|
+
flushPending = false;
|
|
46
|
+
startedAt = 0;
|
|
47
|
+
lastTickAt = 0;
|
|
48
|
+
/** Activate the scheduler. The rAF loop starts on the first client added. */
|
|
49
|
+
start() {
|
|
50
|
+
this.running = true;
|
|
51
|
+
this.paused = false;
|
|
52
|
+
this.maybeQueue();
|
|
53
|
+
}
|
|
54
|
+
/** Halt the rAF loop entirely. Use dispose() for permanent teardown. */
|
|
55
|
+
stop() {
|
|
56
|
+
this.running = false;
|
|
57
|
+
this.cancel();
|
|
58
|
+
}
|
|
59
|
+
/** Temporarily skip ticks without losing client registrations. */
|
|
60
|
+
pause() {
|
|
61
|
+
this.paused = true;
|
|
62
|
+
}
|
|
63
|
+
/** Resume after pause(). */
|
|
64
|
+
resume() {
|
|
65
|
+
this.paused = false;
|
|
66
|
+
if (this.running) this.maybeQueue();
|
|
67
|
+
}
|
|
68
|
+
/** Register a client to be called every frame. */
|
|
69
|
+
add(client) {
|
|
70
|
+
this.clients.add(client);
|
|
71
|
+
if (this.running) this.maybeQueue();
|
|
72
|
+
}
|
|
73
|
+
/** Unregister a client. */
|
|
74
|
+
remove(client) {
|
|
75
|
+
this.clients.delete(client);
|
|
76
|
+
}
|
|
77
|
+
/** Permanent teardown: stop the loop and drop all clients. */
|
|
78
|
+
dispose() {
|
|
79
|
+
this.stop();
|
|
80
|
+
this.clients.clear();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Mark the scheduler idle. The next tick still fires (a final flush so
|
|
84
|
+
* uniform changes that triggered the idle state are rendered), then the
|
|
85
|
+
* rAF loop halts. Use `requestRender()` or `setIdle(false)` to wake.
|
|
86
|
+
*/
|
|
87
|
+
setIdle(idle) {
|
|
88
|
+
if (this.idle === idle) return;
|
|
89
|
+
this.idle = idle;
|
|
90
|
+
if (idle) {
|
|
91
|
+
this.flushPending = true;
|
|
92
|
+
this.maybeQueue();
|
|
93
|
+
} else {
|
|
94
|
+
this.flushPending = false;
|
|
95
|
+
this.maybeQueue();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Force a single tick while idle. Useful for prop-change invalidation. */
|
|
99
|
+
requestRender() {
|
|
100
|
+
if (!this.idle) return;
|
|
101
|
+
this.flushPending = true;
|
|
102
|
+
this.maybeQueue();
|
|
103
|
+
}
|
|
104
|
+
maybeQueue() {
|
|
105
|
+
if (this.rafId !== null) return;
|
|
106
|
+
if (!this.running) return;
|
|
107
|
+
if (this.clients.size === 0) return;
|
|
108
|
+
if (this.idle && !this.flushPending) return;
|
|
109
|
+
this.rafId = requestAnimationFrame(this.frame);
|
|
110
|
+
}
|
|
111
|
+
cancel() {
|
|
112
|
+
if (this.rafId !== null) {
|
|
113
|
+
cancelAnimationFrame(this.rafId);
|
|
114
|
+
this.rafId = null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
frame = (now) => {
|
|
118
|
+
this.rafId = null;
|
|
119
|
+
if (!this.running || this.paused) return;
|
|
120
|
+
if (this.startedAt === 0) {
|
|
121
|
+
this.startedAt = now;
|
|
122
|
+
this.lastTickAt = now;
|
|
123
|
+
}
|
|
124
|
+
const delta = (now - this.lastTickAt) / 1e3;
|
|
125
|
+
const elapsed = (now - this.startedAt) / 1e3;
|
|
126
|
+
this.lastTickAt = now;
|
|
127
|
+
const tick = { delta, elapsed, now };
|
|
128
|
+
for (const client of this.clients) {
|
|
129
|
+
client(tick);
|
|
130
|
+
}
|
|
131
|
+
this.flushPending = false;
|
|
132
|
+
this.maybeQueue();
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/inputs/CursorInput.ts
|
|
137
|
+
var CursorInput = class {
|
|
138
|
+
value;
|
|
139
|
+
target;
|
|
140
|
+
targetDirty = false;
|
|
141
|
+
smoothing;
|
|
142
|
+
listeners = /* @__PURE__ */ new Set();
|
|
143
|
+
eventTarget;
|
|
144
|
+
element;
|
|
145
|
+
handleMouseMove;
|
|
146
|
+
disposed = false;
|
|
147
|
+
constructor(opts = {}) {
|
|
148
|
+
const { smoothing = 0.1, initial = [0.5, 0.5], target, element } = opts;
|
|
149
|
+
this.smoothing = clamp01(smoothing);
|
|
150
|
+
this.value = [initial[0], initial[1]];
|
|
151
|
+
this.target = [initial[0], initial[1]];
|
|
152
|
+
this.eventTarget = target ?? (typeof window !== "undefined" ? window : new EventTarget());
|
|
153
|
+
this.element = element;
|
|
154
|
+
this.handleMouseMove = (e) => {
|
|
155
|
+
const me = e;
|
|
156
|
+
if (this.element) {
|
|
157
|
+
const r = this.element.getBoundingClientRect();
|
|
158
|
+
const w = r.width || 1;
|
|
159
|
+
const h = r.height || 1;
|
|
160
|
+
this.target = [(me.clientX - r.left) / w, (me.clientY - r.top) / h];
|
|
161
|
+
} else {
|
|
162
|
+
const w = typeof window !== "undefined" && window.innerWidth || 1;
|
|
163
|
+
const h = typeof window !== "undefined" && window.innerHeight || 1;
|
|
164
|
+
this.target = [me.clientX / w, me.clientY / h];
|
|
165
|
+
}
|
|
166
|
+
this.targetDirty = true;
|
|
167
|
+
};
|
|
168
|
+
this.eventTarget.addEventListener("mousemove", this.handleMouseMove);
|
|
169
|
+
}
|
|
170
|
+
/** Current smoothed position. Implements MatterSignal protocol. */
|
|
171
|
+
get() {
|
|
172
|
+
return this.value;
|
|
173
|
+
}
|
|
174
|
+
/** Subscribe to change events. Returns an unsubscribe function. */
|
|
175
|
+
on(_event, cb) {
|
|
176
|
+
this.listeners.add(cb);
|
|
177
|
+
return () => this.listeners.delete(cb);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Advance the smoothing one tick. Called by the host scheduler; not
|
|
181
|
+
* typically called directly except in tests.
|
|
182
|
+
*/
|
|
183
|
+
tick(delta) {
|
|
184
|
+
if (this.disposed) return;
|
|
185
|
+
const factor = this.smoothing === 0 ? 1 : 1 - Math.pow(this.smoothing, delta * 60);
|
|
186
|
+
const prev0 = this.value[0];
|
|
187
|
+
const prev1 = this.value[1];
|
|
188
|
+
const next0 = lerp(prev0, this.target[0], factor);
|
|
189
|
+
const next1 = lerp(prev1, this.target[1], factor);
|
|
190
|
+
const moved = next0 !== prev0 || next1 !== prev1;
|
|
191
|
+
if (moved || this.targetDirty) {
|
|
192
|
+
this.value = [next0, next1];
|
|
193
|
+
this.targetDirty = false;
|
|
194
|
+
const snapshot = [next0, next1];
|
|
195
|
+
for (const listener of this.listeners) listener(snapshot);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** Tear down listeners. */
|
|
199
|
+
dispose() {
|
|
200
|
+
if (this.disposed) return;
|
|
201
|
+
this.disposed = true;
|
|
202
|
+
this.eventTarget.removeEventListener("mousemove", this.handleMouseMove);
|
|
203
|
+
this.listeners.clear();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var clamp01 = (n) => Math.max(0, Math.min(1, n));
|
|
207
|
+
var lerp = (a, b, t) => a + (b - a) * t;
|
|
208
|
+
|
|
209
|
+
// src/primitives/colorRamp.ts
|
|
210
|
+
import { mix, vec3 } from "three/tsl";
|
|
211
|
+
function colorRamp(t, stops) {
|
|
212
|
+
if (stops.length === 0) return vec3(0, 0, 0);
|
|
213
|
+
if (stops.length === 1) return stops[0].color;
|
|
214
|
+
let result = stops[0].color;
|
|
215
|
+
for (let i = 1; i < stops.length; i++) {
|
|
216
|
+
const prev = stops[i - 1];
|
|
217
|
+
const next = stops[i];
|
|
218
|
+
const span = next.position - prev.position;
|
|
219
|
+
if (span <= 0) continue;
|
|
220
|
+
const tNode = t;
|
|
221
|
+
const localT = tNode.sub(prev.position).div(span).clamp(0, 1);
|
|
222
|
+
result = mix(result, next.color, localT);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/primitives/noise.ts
|
|
228
|
+
import { mx_noise_float } from "three/tsl";
|
|
229
|
+
function noise(p) {
|
|
230
|
+
return mx_noise_float(p);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/primitives/fbm.ts
|
|
234
|
+
function fbm(p, opts = {}) {
|
|
235
|
+
const octaves = opts.octaves ?? 4;
|
|
236
|
+
const lacunarity = opts.lacunarity ?? 2;
|
|
237
|
+
const gain = opts.gain ?? 0.5;
|
|
238
|
+
let sum = noise(p);
|
|
239
|
+
let amp = 1;
|
|
240
|
+
let freq = 1;
|
|
241
|
+
let total = amp;
|
|
242
|
+
for (let i = 1; i < octaves; i++) {
|
|
243
|
+
freq *= lacunarity;
|
|
244
|
+
amp *= gain;
|
|
245
|
+
total += amp;
|
|
246
|
+
const pAtFreq = p.mul(freq);
|
|
247
|
+
const layer = noise(pAtFreq).mul(amp);
|
|
248
|
+
sum = sum.add(layer);
|
|
249
|
+
}
|
|
250
|
+
return sum.div(total);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/primitives/voronoi.ts
|
|
254
|
+
import { mx_worley_noise_float } from "three/tsl";
|
|
255
|
+
function voronoi(p) {
|
|
256
|
+
return mx_worley_noise_float(p);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/primitives/quantize.ts
|
|
260
|
+
function quantize(t, steps) {
|
|
261
|
+
if (steps <= 1) {
|
|
262
|
+
return t.mul(0);
|
|
263
|
+
}
|
|
264
|
+
const denom = steps - 1;
|
|
265
|
+
return t.mul(denom).add(0.5).floor().div(denom);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/primitives/sdfCircle.ts
|
|
269
|
+
import { length } from "three/tsl";
|
|
270
|
+
function sdfCircle(p, radius) {
|
|
271
|
+
const lp = length(p);
|
|
272
|
+
if (typeof radius === "number") {
|
|
273
|
+
return lp.sub(radius);
|
|
274
|
+
}
|
|
275
|
+
return lp.sub(radius);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/primitives/displace.ts
|
|
279
|
+
function displace(p, by) {
|
|
280
|
+
return p.add(by);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/primitives/cursorRipple.ts
|
|
284
|
+
import { sin as sin2, length as length3, smoothstep as smoothstep2 } from "three/tsl";
|
|
285
|
+
|
|
286
|
+
// src/primitives/tsl-reexports.ts
|
|
287
|
+
import {
|
|
288
|
+
uniform as uniform2,
|
|
289
|
+
vec2,
|
|
290
|
+
vec3 as vec32,
|
|
291
|
+
vec4,
|
|
292
|
+
mix as mix2,
|
|
293
|
+
smoothstep,
|
|
294
|
+
mod,
|
|
295
|
+
sin,
|
|
296
|
+
cos,
|
|
297
|
+
length as length2,
|
|
298
|
+
dot,
|
|
299
|
+
normalize,
|
|
300
|
+
uv,
|
|
301
|
+
max,
|
|
302
|
+
min
|
|
303
|
+
} from "three/tsl";
|
|
304
|
+
import { time as _builtinTime } from "three/tsl";
|
|
305
|
+
|
|
306
|
+
// src/runtime/reducedMotion.ts
|
|
307
|
+
import { uniform } from "three/tsl";
|
|
308
|
+
var state = {
|
|
309
|
+
policy: "auto",
|
|
310
|
+
watchers: /* @__PURE__ */ new Set()
|
|
311
|
+
};
|
|
312
|
+
function setReducedMotionPolicy(policy) {
|
|
313
|
+
if (state.policy === policy) return;
|
|
314
|
+
state.policy = policy;
|
|
315
|
+
for (const w of state.watchers) w.recompute();
|
|
316
|
+
}
|
|
317
|
+
function getReducedMotionPolicy() {
|
|
318
|
+
return state.policy;
|
|
319
|
+
}
|
|
320
|
+
var computeScale = (mqlMatches) => {
|
|
321
|
+
switch (state.policy) {
|
|
322
|
+
case "off":
|
|
323
|
+
return 1;
|
|
324
|
+
case "slow":
|
|
325
|
+
return 0.3;
|
|
326
|
+
case "paused":
|
|
327
|
+
return 0;
|
|
328
|
+
case "auto":
|
|
329
|
+
return mqlMatches ? 0.3 : 1;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
function createReducedMotionWatcher() {
|
|
333
|
+
if (typeof matchMedia !== "function") {
|
|
334
|
+
return {
|
|
335
|
+
scale: () => computeScale(false),
|
|
336
|
+
subscribe: (cb) => {
|
|
337
|
+
void cb;
|
|
338
|
+
return () => {
|
|
339
|
+
};
|
|
340
|
+
},
|
|
341
|
+
/** SSR watcher does not emit policy-change notifications. */
|
|
342
|
+
dispose: () => {
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
const mql = matchMedia("(prefers-reduced-motion: reduce)");
|
|
347
|
+
const subs = /* @__PURE__ */ new Set();
|
|
348
|
+
let last = computeScale(mql.matches);
|
|
349
|
+
const onChange = () => {
|
|
350
|
+
const next = computeScale(mql.matches);
|
|
351
|
+
if (next !== last) {
|
|
352
|
+
last = next;
|
|
353
|
+
for (const cb of subs) cb(next);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
mql.addEventListener("change", onChange);
|
|
357
|
+
const watcher = {
|
|
358
|
+
scale: () => last,
|
|
359
|
+
subscribe(cb) {
|
|
360
|
+
subs.add(cb);
|
|
361
|
+
return () => subs.delete(cb);
|
|
362
|
+
},
|
|
363
|
+
recompute() {
|
|
364
|
+
const next = computeScale(mql.matches);
|
|
365
|
+
if (next !== last) {
|
|
366
|
+
last = next;
|
|
367
|
+
for (const cb of subs) cb(next);
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
dispose() {
|
|
371
|
+
mql.removeEventListener("change", onChange);
|
|
372
|
+
subs.clear();
|
|
373
|
+
state.watchers.delete(watcher);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
state.watchers.add(watcher);
|
|
377
|
+
return watcher;
|
|
378
|
+
}
|
|
379
|
+
var globalScaleUniform = null;
|
|
380
|
+
var globalWatcher = null;
|
|
381
|
+
function getReducedMotionTimeScale() {
|
|
382
|
+
if (globalScaleUniform === null) {
|
|
383
|
+
globalWatcher = createReducedMotionWatcher();
|
|
384
|
+
globalScaleUniform = uniform(globalWatcher.scale());
|
|
385
|
+
globalWatcher.subscribe((s) => {
|
|
386
|
+
if (globalScaleUniform === null) return;
|
|
387
|
+
globalScaleUniform.value = s;
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return globalScaleUniform;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/primitives/tsl-reexports.ts
|
|
394
|
+
var time = _builtinTime.mul(
|
|
395
|
+
getReducedMotionTimeScale()
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
// src/primitives/cursorRipple.ts
|
|
399
|
+
function cursorRipple(p, center, opts = {}) {
|
|
400
|
+
const reach = opts.reach ?? 0.4;
|
|
401
|
+
const frequency = opts.frequency ?? 30;
|
|
402
|
+
const speed = opts.speed ?? 6;
|
|
403
|
+
const amplitude = opts.amplitude ?? 0.5;
|
|
404
|
+
const d = length3(
|
|
405
|
+
p.sub(center)
|
|
406
|
+
);
|
|
407
|
+
const wave = sin2(d.mul(frequency).sub(time.mul(speed)));
|
|
408
|
+
const decay = smoothstep2(reach, 0, d);
|
|
409
|
+
return wave.mul(amplitude).mul(decay);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/runtime/visibility.ts
|
|
413
|
+
function createVisibilityWatcher() {
|
|
414
|
+
if (typeof document === "undefined") {
|
|
415
|
+
return {
|
|
416
|
+
isVisible: () => true,
|
|
417
|
+
subscribe: () => () => {
|
|
418
|
+
},
|
|
419
|
+
dispose: () => {
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
const subs = /* @__PURE__ */ new Set();
|
|
424
|
+
const onChange = () => {
|
|
425
|
+
const v = document.visibilityState === "visible";
|
|
426
|
+
for (const cb of subs) cb(v);
|
|
427
|
+
};
|
|
428
|
+
document.addEventListener("visibilitychange", onChange);
|
|
429
|
+
return {
|
|
430
|
+
isVisible: () => document.visibilityState === "visible",
|
|
431
|
+
subscribe(cb) {
|
|
432
|
+
subs.add(cb);
|
|
433
|
+
return () => subs.delete(cb);
|
|
434
|
+
},
|
|
435
|
+
dispose() {
|
|
436
|
+
document.removeEventListener("visibilitychange", onChange);
|
|
437
|
+
subs.clear();
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// src/runtime/intersection.ts
|
|
443
|
+
function createIntersectionWatcher(canvas) {
|
|
444
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
445
|
+
return {
|
|
446
|
+
isInView: () => true,
|
|
447
|
+
subscribe: () => () => {
|
|
448
|
+
},
|
|
449
|
+
dispose: () => {
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
const subs = /* @__PURE__ */ new Set();
|
|
454
|
+
let inView = true;
|
|
455
|
+
const obs = new IntersectionObserver(
|
|
456
|
+
(entries) => {
|
|
457
|
+
const next = entries.some((e) => e.isIntersecting);
|
|
458
|
+
if (next === inView) return;
|
|
459
|
+
inView = next;
|
|
460
|
+
for (const cb of subs) cb(inView);
|
|
461
|
+
},
|
|
462
|
+
{ threshold: 0 }
|
|
463
|
+
);
|
|
464
|
+
obs.observe(canvas);
|
|
465
|
+
return {
|
|
466
|
+
isInView: () => inView,
|
|
467
|
+
subscribe(cb) {
|
|
468
|
+
subs.add(cb);
|
|
469
|
+
return () => subs.delete(cb);
|
|
470
|
+
},
|
|
471
|
+
dispose() {
|
|
472
|
+
obs.disconnect();
|
|
473
|
+
subs.clear();
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
export {
|
|
478
|
+
CursorInput,
|
|
479
|
+
MatterScheduler,
|
|
480
|
+
colorRamp,
|
|
481
|
+
cos,
|
|
482
|
+
createIntersectionWatcher,
|
|
483
|
+
createReducedMotionWatcher,
|
|
484
|
+
createRenderer,
|
|
485
|
+
createVisibilityWatcher,
|
|
486
|
+
cursorRipple,
|
|
487
|
+
displace,
|
|
488
|
+
dot,
|
|
489
|
+
fbm,
|
|
490
|
+
getReducedMotionPolicy,
|
|
491
|
+
getReducedMotionTimeScale,
|
|
492
|
+
length2 as length,
|
|
493
|
+
max,
|
|
494
|
+
min,
|
|
495
|
+
mix2 as mix,
|
|
496
|
+
mod,
|
|
497
|
+
noise,
|
|
498
|
+
normalize,
|
|
499
|
+
quantize,
|
|
500
|
+
sdfCircle,
|
|
501
|
+
setReducedMotionPolicy,
|
|
502
|
+
sin,
|
|
503
|
+
smoothstep,
|
|
504
|
+
time,
|
|
505
|
+
uniform2 as uniform,
|
|
506
|
+
uv,
|
|
507
|
+
vec2,
|
|
508
|
+
vec32 as vec3,
|
|
509
|
+
vec4,
|
|
510
|
+
voronoi
|
|
511
|
+
};
|
|
512
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/createRenderer.ts","../src/runtime/MatterScheduler.ts","../src/inputs/CursorInput.ts","../src/primitives/colorRamp.ts","../src/primitives/noise.ts","../src/primitives/fbm.ts","../src/primitives/voronoi.ts","../src/primitives/quantize.ts","../src/primitives/sdfCircle.ts","../src/primitives/displace.ts","../src/primitives/cursorRipple.ts","../src/primitives/tsl-reexports.ts","../src/runtime/reducedMotion.ts","../src/runtime/visibility.ts","../src/runtime/intersection.ts"],"sourcesContent":["import { WebGPURenderer } from 'three/webgpu'\nimport { Color } from 'three'\n\nexport type MatterBackend = 'webgpu' | 'webgl2'\n\nexport interface CreateRendererOptions {\n /** Anti-alias the framebuffer. Default: true. */\n antialias?: boolean\n /** Force WebGL2 even if WebGPU is available (useful for testing fallback). Default: false. */\n forceWebGL?: boolean\n /** Clear color (hex, CSS string, or THREE.Color). Default: transparent. */\n clearColor?: number | string | Color\n /** Clear alpha (0–1). Default: 0 (transparent). */\n clearAlpha?: number\n /** Cap on devicePixelRatio. Default: 2. Pass Infinity to disable. */\n maxDPR?: number\n}\n\nexport interface MatterRenderer {\n /** The underlying Three.js WebGPURenderer (which may be running on a WebGL2 backend). */\n three: WebGPURenderer\n /** Which backend the renderer initialized with. */\n backend: MatterBackend\n /** Tear down the renderer and release GPU resources. */\n dispose: () => void\n /** Resize the renderer to the canvas's current client dimensions. */\n resize: () => void\n}\n\n/**\n * Create a Matter renderer wrapping THREE.WebGPURenderer.\n *\n * Tries WebGPU first; falls back to WebGL2 automatically if WebGPU is\n * unavailable on the host. The returned object exposes the underlying\n * three renderer plus a small wrapper for resize and disposal.\n */\nexport async function createRenderer(\n canvas: HTMLCanvasElement,\n opts: CreateRendererOptions = {},\n): Promise<MatterRenderer> {\n const {\n antialias = true,\n forceWebGL = false,\n clearColor = 0x000000,\n clearAlpha = 0,\n maxDPR = 2,\n } = opts\n\n const three = new WebGPURenderer({\n canvas,\n antialias,\n forceWebGL,\n })\n\n await three.init()\n\n three.setPixelRatio(Math.min(window.devicePixelRatio, maxDPR))\n const resolvedClearColor =\n clearColor instanceof Color ? clearColor : new Color(clearColor as number | string)\n three.setClearColor(resolvedClearColor, clearAlpha)\n\n const resize = () => {\n const w = canvas.clientWidth\n const h = canvas.clientHeight\n if (canvas.width !== w * three.getPixelRatio() || canvas.height !== h * three.getPixelRatio()) {\n three.setSize(w, h, false)\n }\n }\n resize()\n\n // Detect backend after init. The exact API may differ between three versions;\n // probe the renderer's backend symbol if present, fall back to a property check.\n const backend: MatterBackend =\n forceWebGL || (three as unknown as { backend?: { isWebGLBackend?: boolean } }).backend?.isWebGLBackend\n ? 'webgl2'\n : 'webgpu'\n\n return {\n three,\n backend,\n dispose: () => three.dispose(),\n resize,\n }\n}\n","export interface SchedulerTick {\n /** Seconds since the previous tick. 0 on the first call. */\n delta: number\n /** Total seconds since the scheduler started its current run. */\n elapsed: number\n /** The raw `performance.now()` timestamp the rAF callback received. */\n now: number\n}\n\nexport type SchedulerClient = (tick: SchedulerTick) => void\n\n/**\n * Batches `requestAnimationFrame` calls across all clients registered with\n * a single scheduler. One scheduler is created per <MatterScene>; clients\n * are typically a Three.js renderer's render call.\n */\nexport class MatterScheduler {\n private readonly clients = new Set<SchedulerClient>()\n private rafId: number | null = null\n private running = false\n private paused = false\n private idle = false\n private flushPending = false\n private startedAt = 0\n private lastTickAt = 0\n\n /** Activate the scheduler. The rAF loop starts on the first client added. */\n start(): void {\n this.running = true\n this.paused = false\n this.maybeQueue()\n }\n\n /** Halt the rAF loop entirely. Use dispose() for permanent teardown. */\n stop(): void {\n this.running = false\n this.cancel()\n }\n\n /** Temporarily skip ticks without losing client registrations. */\n pause(): void {\n this.paused = true\n }\n\n /** Resume after pause(). */\n resume(): void {\n this.paused = false\n if (this.running) this.maybeQueue()\n }\n\n /** Register a client to be called every frame. */\n add(client: SchedulerClient): void {\n this.clients.add(client)\n if (this.running) this.maybeQueue()\n }\n\n /** Unregister a client. */\n remove(client: SchedulerClient): void {\n this.clients.delete(client)\n }\n\n /** Permanent teardown: stop the loop and drop all clients. */\n dispose(): void {\n this.stop()\n this.clients.clear()\n }\n\n /**\n * Mark the scheduler idle. The next tick still fires (a final flush so\n * uniform changes that triggered the idle state are rendered), then the\n * rAF loop halts. Use `requestRender()` or `setIdle(false)` to wake.\n */\n setIdle(idle: boolean): void {\n if (this.idle === idle) return\n this.idle = idle\n if (idle) {\n this.flushPending = true\n this.maybeQueue()\n } else {\n this.flushPending = false\n this.maybeQueue()\n }\n }\n\n /** Force a single tick while idle. Useful for prop-change invalidation. */\n requestRender(): void {\n if (!this.idle) return\n this.flushPending = true\n this.maybeQueue()\n }\n\n private maybeQueue(): void {\n if (this.rafId !== null) return\n if (!this.running) return\n if (this.clients.size === 0) return\n if (this.idle && !this.flushPending) return\n this.rafId = requestAnimationFrame(this.frame)\n }\n\n private cancel(): void {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId)\n this.rafId = null\n }\n }\n\n private readonly frame = (now: number): void => {\n this.rafId = null\n if (!this.running || this.paused) return\n\n if (this.startedAt === 0) {\n this.startedAt = now\n this.lastTickAt = now\n }\n const delta = (now - this.lastTickAt) / 1000\n const elapsed = (now - this.startedAt) / 1000\n this.lastTickAt = now\n\n const tick: SchedulerTick = { delta, elapsed, now }\n for (const client of this.clients) {\n client(tick)\n }\n\n this.flushPending = false\n this.maybeQueue()\n }\n}\n","export type Vec2 = readonly [number, number]\n\nexport interface CursorInputOptions {\n /**\n * Smoothing factor: 0 = no smoothing (snap to target instantly).\n * 1 = max smoothing (essentially never reaches target).\n * Sensible default: 0.1.\n *\n * Implementation: per-frame, value moves toward target by `(1 - smoothing) * delta * 60`,\n * roughly meaning \"at smoothing=0.1, ~90% of the gap is closed in 1 second at 60fps.\"\n */\n smoothing?: number\n /** Starting position. Default: [0.5, 0.5] (center). */\n initial?: Vec2\n /** Listen on this target. Default: window. */\n target?: EventTarget\n /**\n * Element to normalize cursor coordinates against. Default: window viewport.\n *\n * When set, cursor x/y are in [0,1] across the element's bounding rect, with\n * extrapolation outside (negative when left/above, >1 when right/below). This\n * matches what shader UV space expects: a cursor at the canvas's top-left\n * corner reads as (0, 0); at bottom-right as (1, 1); regardless of where the\n * canvas sits in the viewport. Without this, components inside a partial-\n * viewport scene (e.g. a 70vh hero section) see a cursor offset that scales\n * with the canvas's vertical position on the page.\n */\n element?: { getBoundingClientRect(): { left: number; top: number; width: number; height: number } }\n}\n\ntype ChangeListener = (value: Vec2) => void\n\n/**\n * Smoothed pointer tracker emitting a normalized (0..1) Vec2 position.\n * Implements the MatterSignal protocol (`get()` + `on('change', cb)`)\n * so it composes with Motion's `useTransform` and similar tools.\n */\nexport class CursorInput {\n private value: [number, number]\n private target: [number, number]\n private targetDirty = false\n private readonly smoothing: number\n private readonly listeners = new Set<ChangeListener>()\n private readonly eventTarget: EventTarget\n private readonly element: CursorInputOptions['element']\n private readonly handleMouseMove: (e: Event) => void\n private disposed = false\n\n constructor(opts: CursorInputOptions = {}) {\n const { smoothing = 0.1, initial = [0.5, 0.5], target, element } = opts\n this.smoothing = clamp01(smoothing)\n this.value = [initial[0], initial[1]]\n this.target = [initial[0], initial[1]]\n this.eventTarget = target ?? (typeof window !== 'undefined' ? window : new EventTarget())\n this.element = element\n\n this.handleMouseMove = (e: Event) => {\n const me = e as MouseEvent\n if (this.element) {\n // Normalize to 0..1 across the element's bounding rect. Reading the\n // rect on every move is fine — `getBoundingClientRect` is cheap and\n // mousemove is already throttled to ~60Hz by the browser. The benefit\n // is tracking the element's position even if it moved/scrolled since\n // the last frame.\n const r = this.element.getBoundingClientRect()\n const w = r.width || 1\n const h = r.height || 1\n this.target = [(me.clientX - r.left) / w, (me.clientY - r.top) / h]\n } else {\n // Fallback: viewport-normalized. Used when no element is supplied —\n // mostly the standalone-API case for users not consuming through\n // <MatterScene>'s context.\n const w = (typeof window !== 'undefined' && window.innerWidth) || 1\n const h = (typeof window !== 'undefined' && window.innerHeight) || 1\n this.target = [me.clientX / w, me.clientY / h]\n }\n this.targetDirty = true\n }\n\n this.eventTarget.addEventListener('mousemove', this.handleMouseMove)\n }\n\n /** Current smoothed position. Implements MatterSignal protocol. */\n get(): Vec2 {\n return this.value\n }\n\n /** Subscribe to change events. Returns an unsubscribe function. */\n on(_event: 'change', cb: ChangeListener): () => void {\n this.listeners.add(cb)\n return () => this.listeners.delete(cb)\n }\n\n /**\n * Advance the smoothing one tick. Called by the host scheduler; not\n * typically called directly except in tests.\n */\n tick(delta: number): void {\n if (this.disposed) return\n const factor = this.smoothing === 0 ? 1 : 1 - Math.pow(this.smoothing, delta * 60)\n const prev0 = this.value[0]\n const prev1 = this.value[1]\n const next0 = lerp(prev0, this.target[0], factor)\n const next1 = lerp(prev1, this.target[1], factor)\n const moved = next0 !== prev0 || next1 !== prev1\n if (moved || this.targetDirty) {\n this.value = [next0, next1]\n this.targetDirty = false\n const snapshot: Vec2 = [next0, next1]\n for (const listener of this.listeners) listener(snapshot)\n }\n }\n\n /** Tear down listeners. */\n dispose(): void {\n if (this.disposed) return\n this.disposed = true\n this.eventTarget.removeEventListener('mousemove', this.handleMouseMove)\n this.listeners.clear()\n }\n}\n\nconst clamp01 = (n: number) => Math.max(0, Math.min(1, n))\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t\n","import { mix, vec3 } from 'three/tsl'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\nexport type TSLNode = Node | ShaderNodeObject<Node>\n\nexport interface ColorRampStop {\n /** Color expressed as a TSL node (typically `vec3(r,g,b)`). */\n color: TSLNode\n /** Position 0..1 along the ramp. */\n position: number\n}\n\n/**\n * Multi-stop color interpolation. Given a t in [0..1] and N color stops at\n * fixed positions, returns the smoothly-interpolated color.\n *\n * Falls back to the first/last stop's color outside the bracketing positions.\n */\nexport function colorRamp(t: TSLNode, stops: ColorRampStop[]): TSLNode {\n if (stops.length === 0) return vec3(0, 0, 0)\n if (stops.length === 1) return stops[0]!.color\n\n // Build a chain of nested mixes, one per adjacent pair of stops.\n // For three stops at positions 0, 0.5, 1:\n // inner = mix(stop0, stop1, smoothstep(0, 0.5, t))\n // outer = mix(inner, stop2, smoothstep(0.5, 1, t))\n let result: TSLNode = stops[0]!.color\n for (let i = 1; i < stops.length; i++) {\n const prev = stops[i - 1]!\n const next = stops[i]!\n const span = next.position - prev.position\n if (span <= 0) continue\n // Localize t into the [prev..next] range.\n const tNode = t as ShaderNodeObject<Node>\n const localT = tNode.sub(prev.position).div(span).clamp(0, 1)\n result = mix(result, next.color, localT)\n }\n return result\n}\n","// packages/matter/src/primitives/noise.ts\nimport { mx_noise_float } from 'three/tsl'\nimport type { TSLNode } from './colorRamp.js'\n\n/**\n * 2D simplex noise sampled at a point. Returns a scalar TSL node in\n * approximately [-1, 1] (MaterialX's mx_noise_float is roughly that range).\n *\n * @param p — Vec2 TSL node (typically `uv()` or a scaled/offset uv).\n *\n * Built on top of three's `mx_noise_float`; we wrap it so consumers have a\n * stable import path through `@lovo/matter` and we can swap the\n * implementation if a different noise primitive proves better in practice.\n */\nexport function noise(p: TSLNode): TSLNode {\n return mx_noise_float(p) as unknown as TSLNode\n}\n","// packages/matter/src/primitives/fbm.ts\nimport { noise } from './noise.js'\nimport type { TSLNode } from './colorRamp.js'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\nexport interface FBMOptions {\n /** Number of octaves to sum. JS-side number — fixed at TSL build time, not a uniform. Default: 4. */\n octaves?: number\n /** Per-octave frequency multiplier. JS-side number. Default: 2. */\n lacunarity?: number\n /** Per-octave amplitude multiplier. JS-side number. Default: 0.5. */\n gain?: number\n}\n\n/**\n * Fractal Brownian Motion — sum of N octaves of 2D simplex noise.\n *\n * `octaves`, `lacunarity`, and `gain` are JavaScript numbers (NOT TSL\n * uniforms) because the loop must be unrolled at TSL-build time — TSL has\n * no dynamic-length loop primitive that maps cleanly to all backends.\n * Animatable parameters that *do* survive on the GPU are the input UV\n * (which the caller can scale/translate per frame) and `time`.\n *\n * @param p — Vec2 TSL node (UV-space position).\n * @returns scalar TSL node, roughly [-1..1] but normalized closer to\n * [-0.5..0.5] when amplitude sums approach 1 with the default gain.\n */\nexport function fbm(p: TSLNode, opts: FBMOptions = {}): TSLNode {\n const octaves = opts.octaves ?? 4\n const lacunarity = opts.lacunarity ?? 2\n const gain = opts.gain ?? 0.5\n\n let sum: TSLNode = noise(p)\n let amp = 1\n let freq = 1\n let total = amp\n for (let i = 1; i < octaves; i++) {\n freq *= lacunarity\n amp *= gain\n total += amp\n // Multiply UV by the per-octave frequency before sampling.\n // (`p as ShaderNodeObject` so we can call `.mul`; #12 doesn't apply\n // here because `p` is built from `uv()`/`vec2()`, not from a uniform.)\n const pAtFreq = (p as ShaderNodeObject<Node>).mul(freq)\n const layer = (noise(pAtFreq) as ShaderNodeObject<Node>).mul(amp)\n sum = (sum as ShaderNodeObject<Node>).add(layer)\n }\n // Normalize to approximate [-1..1] regardless of octave count / gain.\n return (sum as ShaderNodeObject<Node>).div(total)\n}\n","// packages/matter/src/primitives/voronoi.ts\nimport { mx_worley_noise_float } from 'three/tsl'\nimport type { TSLNode } from './colorRamp.js'\n\n/**\n * 2D voronoi (Worley) noise — distance to the nearest jittered cell point,\n * normalized roughly to [0, 1]. Higher values = farther from any cell point\n * (cell interiors); lower values = near a cell boundary.\n *\n * Built on three's `mx_worley_noise_float`. Combine with `colorRamp` for\n * a multi-color cellular pattern; threshold via `step`/`smoothstep` for\n * hard cell shapes.\n *\n * @param p — Vec2 TSL node, typically `uv() * scale`.\n */\nexport function voronoi(p: TSLNode): TSLNode {\n return mx_worley_noise_float(p) as unknown as TSLNode\n}\n","// packages/matter/src/primitives/quantize.ts\nimport type { TSLNode } from './colorRamp.js'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\n/**\n * Quantize a scalar TSL node to `steps` discrete levels.\n *\n * quantize(t, 4) → values in {0, 0.25, 0.5, 0.75, 1.0}\n *\n * `steps` is a JS-side number (loop-equivalent at TSL build time, baked in).\n * If you need an animatable step count, rebuild the TSL fragment.\n */\nexport function quantize(t: TSLNode, steps: number): TSLNode {\n if (steps <= 1) {\n // Edge case: single step → constant 0. Return as-is wrapped in mul(0).\n return (t as ShaderNodeObject<Node>).mul(0)\n }\n const denom = steps - 1\n // floor(t * (steps-1) + 0.5) / (steps-1)\n // Using floor(x + 0.5) instead of round() for TSL portability.\n return (t as ShaderNodeObject<Node>)\n .mul(denom)\n .add(0.5)\n .floor()\n .div(denom)\n}\n","import { length } from 'three/tsl'\nimport type { TSLNode } from './colorRamp.js'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\n/**\n * Signed distance field for a circle centered at the origin.\n *\n * sdfCircle(p, r) = length(p) - r\n *\n * Negative inside the circle, zero on the boundary, positive outside.\n * Combine with `smoothstep(-edge, +edge, sdf)` to render a soft-edged disk.\n *\n * @param p — Vec2 TSL node (typically a UV-space offset from the center).\n * @param radius — JS-side scalar OR a scalar TSL node.\n */\nexport function sdfCircle(p: TSLNode, radius: TSLNode | number): TSLNode {\n const lp = length(p) as ShaderNodeObject<Node>\n if (typeof radius === 'number') {\n return lp.sub(radius)\n }\n return lp.sub(radius as ShaderNodeObject<Node>)\n}\n","import type { TSLNode } from './colorRamp.js'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\n/**\n * Naive vector addition: returns `p + by`.\n *\n * displace(p, by) = p + by\n *\n * Thin wrapper that names the spatial intent of shifting a sample point.\n *\n * **SDF caveat:** when using this to translate an SDF render, pass the\n * NEGATED translation — `sdfCircle(displace(p, v.mul(-1)), r)` renders the\n * disk at position `+v` because SDF translation evaluates as\n * `length(p - center) - r`. Adding `+v` to the sample point shifts the\n * rendered shape in the OPPOSITE direction.\n *\n * @param p — Vec2 TSL node (the position being displaced).\n * @param by — Vec2 TSL node (the displacement vector).\n */\nexport function displace(p: TSLNode, by: TSLNode): TSLNode {\n return (p as ShaderNodeObject<Node>).add(by as ShaderNodeObject<Node>)\n}\n","import { sin, length, smoothstep } from 'three/tsl'\nimport { time } from './tsl-reexports.js'\nimport type { TSLNode } from './colorRamp.js'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\nexport interface CursorRippleOptions {\n /** Decay radius (UV space). Beyond this, the ripple is ~0. Default: 0.4. */\n reach?: number\n /** Wavelength controls the ripple spacing. Default: 30. Larger = wider rings. */\n frequency?: number\n /** Time multiplier on the wave phase. Default: 6. Larger = faster oscillation. */\n speed?: number\n /** Output amplitude. Default: 0.5. Final result is in roughly [-amplitude, +amplitude]. */\n amplitude?: number\n}\n\n/**\n * A radial ripple emanating from `center`. Returns a scalar TSL node in\n * roughly [-amplitude, +amplitude] that decays to ~0 outside `reach`.\n *\n * ripple = sin(d*frequency - time*speed) * amplitude * smoothstep(reach, 0, d)\n *\n * Compose into a wave field by adding it to the underlying base wave.\n *\n * Note: `frequency` / `speed` / `reach` / `amplitude` are JS-side numbers\n * (baked into the TSL fragment at material-build time). The animatable\n * cursor position is the only live uniform consumed.\n *\n * @param p — Vec2 TSL node (typically `uv()`).\n * @param center — Vec2 TSL node (cursor uniform, in UV space).\n */\nexport function cursorRipple(\n p: TSLNode,\n center: TSLNode,\n opts: CursorRippleOptions = {},\n): TSLNode {\n const reach = opts.reach ?? 0.4\n const frequency = opts.frequency ?? 30\n const speed = opts.speed ?? 6\n const amplitude = opts.amplitude ?? 0.5\n\n // d = length(p - center). Build the chain rooted in `p` (uv()-derived) and\n // pass `center` (a uniform in real callers) as the SUBTRACTION ARGUMENT —\n // never as the receiver. Per gotcha #12, chaining `.sub(...).mul(...)` off\n // a raw `uniform()` receiver silently produces wrong GPU values.\n const d = length(\n (p as ShaderNodeObject<Node>).sub(center as ShaderNodeObject<Node>),\n ) as ShaderNodeObject<Node>\n // `time` is the engine-gated TSL node (re-exported from tsl-reexports.ts);\n // chains rooted in `time` automatically respect `prefers-reduced-motion` and\n // the runtime override set via `setReducedMotionPolicy`.\n const wave = sin(d.mul(frequency).sub(time.mul(speed))) as ShaderNodeObject<Node>\n const decay = smoothstep(reach, 0, d as never) as ShaderNodeObject<Node>\n return wave.mul(amplitude).mul(decay)\n}\n","// Stable surface for TSL primitives matter consumers reach for constantly.\n// Re-exporting through @lovo/matter means user code has one import path\n// and we can absorb three.js TSL renames without breaking downstream code.\n\nexport {\n uniform,\n vec2,\n vec3,\n vec4,\n mix,\n smoothstep,\n mod,\n sin,\n cos,\n length,\n dot,\n normalize,\n uv,\n max,\n min,\n} from 'three/tsl'\n\nimport { time as _builtinTime } from 'three/tsl'\nimport { getReducedMotionTimeScale } from '../runtime/reducedMotion.js'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\n/**\n * Engine-gated `time`: equals the TSL built-in `time` multiplied by the\n * reduced-motion scale uniform. Components consuming `time` from `@lovo/matter`\n * automatically respect `prefers-reduced-motion` and the policy override set\n * via `setReducedMotionPolicy`.\n *\n * If you want raw uncapped time (e.g. for a debug overlay), import\n * `time` from `three/tsl` directly.\n */\nexport const time: ShaderNodeObject<Node> = (_builtinTime as ShaderNodeObject<Node>).mul(\n getReducedMotionTimeScale(),\n) as ShaderNodeObject<Node>\n","import { uniform } from 'three/tsl'\nimport type { ShaderNodeObject } from 'three/tsl'\nimport type { Node } from 'three/webgpu'\n\nexport type ReducedMotionPolicy = 'auto' | 'off' | 'slow' | 'paused'\n\n/**\n * Public surface exposed to package consumers. `recompute` is intentionally\n * absent — it is engine-internal and should not be callable from outside.\n */\nexport interface ReducedMotionWatcher {\n /** Current time scale: 0, 0.3, or 1. */\n scale(): number\n /** Subscribe to scale changes. Returns unsubscribe. */\n subscribe(cb: (scale: number) => void): () => void\n /** Tear down media-query listener. */\n dispose(): void\n}\n\n/**\n * Engine-internal extension of the public watcher. Only `setReducedMotionPolicy`\n * calls `recompute`; it is never part of the consumer-visible type.\n */\ninterface InternalWatcher extends ReducedMotionWatcher {\n recompute(): void\n}\n\ninterface PolicyState {\n policy: ReducedMotionPolicy\n watchers: Set<InternalWatcher>\n}\n\nconst state: PolicyState = {\n policy: 'auto',\n watchers: new Set(),\n}\n\n/**\n * Override Matter's default behavior of honoring `prefers-reduced-motion`.\n * - 'auto' — follow the OS media query (default)\n * - 'off' — full speed regardless of OS setting\n * - 'slow' — 30% speed regardless of OS setting\n * - 'paused' — 0 (animation effectively frozen) regardless of OS setting\n */\nexport function setReducedMotionPolicy(policy: ReducedMotionPolicy): void {\n if (state.policy === policy) return\n state.policy = policy\n for (const w of state.watchers) w.recompute()\n}\n\nexport function getReducedMotionPolicy(): ReducedMotionPolicy {\n return state.policy\n}\n\nconst computeScale = (mqlMatches: boolean): number => {\n switch (state.policy) {\n case 'off':\n return 1\n case 'slow':\n return 0.3\n case 'paused':\n return 0\n case 'auto':\n return mqlMatches ? 0.3 : 1\n }\n}\n\n/**\n * Create a watcher that tracks `prefers-reduced-motion: reduce` and the\n * global Matter policy override. Strict-mode-safe — callers create+dispose\n * one per mount cycle.\n */\nexport function createReducedMotionWatcher(): ReducedMotionWatcher {\n // SSR safety: bail to the no-op watcher if matchMedia is missing.\n // SSR watcher: scale() respects policy override but does not emit\n // subscription events (the engine has no way to notify SSR-created\n // watchers because they are not added to state.watchers — but in\n // practice CLAUDE.md gotcha #10 requires `ssr: false` for any component\n // that touches the matter engine).\n if (typeof matchMedia !== 'function') {\n return {\n scale: () => computeScale(false),\n subscribe: (cb) => {\n // No-op: SSR watchers are not in state.watchers and will never\n // receive policy-change notifications.\n void cb\n return () => {}\n },\n /** SSR watcher does not emit policy-change notifications. */\n dispose: () => {},\n }\n }\n\n const mql = matchMedia('(prefers-reduced-motion: reduce)')\n const subs = new Set<(s: number) => void>()\n let last = computeScale(mql.matches)\n\n const onChange = () => {\n const next = computeScale(mql.matches)\n if (next !== last) {\n last = next\n for (const cb of subs) cb(next)\n }\n }\n\n mql.addEventListener('change', onChange)\n\n const watcher: InternalWatcher = {\n scale: () => last,\n subscribe(cb) {\n subs.add(cb)\n return () => subs.delete(cb)\n },\n recompute() {\n const next = computeScale(mql.matches)\n if (next !== last) {\n last = next\n for (const cb of subs) cb(next)\n }\n },\n dispose() {\n mql.removeEventListener('change', onChange)\n subs.clear()\n state.watchers.delete(watcher)\n },\n }\n state.watchers.add(watcher)\n return watcher\n}\n\nlet globalScaleUniform: ShaderNodeObject<Node> | null = null\nlet globalWatcher: ReducedMotionWatcher | null = null\n\n/**\n * Returns the engine-shared TSL uniform that `time` is multiplied by. Lazily\n * initialized on first read; reused across all materials. Mutating `.value`\n * imperatively when policy changes is safe — TSL re-reads the uniform every\n * frame.\n */\nexport function getReducedMotionTimeScale(): ShaderNodeObject<Node> {\n if (globalScaleUniform === null) {\n globalWatcher = createReducedMotionWatcher()\n globalScaleUniform = uniform(globalWatcher.scale()) as unknown as ShaderNodeObject<Node>\n globalWatcher.subscribe((s) => {\n if (globalScaleUniform === null) return\n ;(globalScaleUniform as unknown as { value: number }).value = s\n })\n }\n return globalScaleUniform\n}\n\n// Keep a typed reference for tests that may want to re-init between tests.\nexport const __resetReducedMotionForTests = () => {\n globalWatcher?.dispose()\n globalWatcher = null\n globalScaleUniform = null\n}\n","export interface VisibilityWatcher {\n isVisible(): boolean\n /** Subscribe to changes. Receives the new visibility state. Returns unsubscribe. */\n subscribe(cb: (visible: boolean) => void): () => void\n dispose(): void\n}\n\n/**\n * Watch `document.visibilityState`. Strict-mode-safe — callers create+dispose\n * one per mount cycle.\n *\n * SSR: if `document` is unavailable, returns a no-op watcher whose\n * `isVisible()` always returns `true` and whose `subscribe` does nothing.\n */\nexport function createVisibilityWatcher(): VisibilityWatcher {\n if (typeof document === 'undefined') {\n return {\n isVisible: () => true,\n subscribe: () => () => {},\n dispose: () => {},\n }\n }\n\n const subs = new Set<(v: boolean) => void>()\n const onChange = () => {\n const v = document.visibilityState === 'visible'\n for (const cb of subs) cb(v)\n }\n document.addEventListener('visibilitychange', onChange)\n\n return {\n isVisible: () => document.visibilityState === 'visible',\n subscribe(cb) {\n subs.add(cb)\n return () => subs.delete(cb)\n },\n dispose() {\n document.removeEventListener('visibilitychange', onChange)\n subs.clear()\n },\n }\n}\n","export interface IntersectionWatcher {\n isInView(): boolean\n /** Subscribe to changes. Receives the new in-view state. Returns unsubscribe. */\n subscribe(cb: (inView: boolean) => void): () => void\n dispose(): void\n}\n\n/**\n * Watch a canvas's viewport intersection. Pauses tied to this watcher should\n * be resumed when the canvas is *any* fraction visible. Strict-mode-safe.\n *\n * SSR: if `IntersectionObserver` is unavailable, returns a no-op watcher whose\n * `isInView()` always returns `true` and whose `subscribe` does nothing.\n */\nexport function createIntersectionWatcher(canvas: HTMLCanvasElement): IntersectionWatcher {\n if (typeof IntersectionObserver === 'undefined') {\n return {\n isInView: () => true,\n subscribe: () => () => {},\n dispose: () => {},\n }\n }\n\n const subs = new Set<(v: boolean) => void>()\n let inView = true\n const obs = new IntersectionObserver(\n (entries) => {\n const next = entries.some((e) => e.isIntersecting)\n if (next === inView) return\n inView = next\n for (const cb of subs) cb(inView)\n },\n { threshold: 0 },\n )\n obs.observe(canvas)\n\n return {\n isInView: () => inView,\n subscribe(cb) {\n subs.add(cb)\n return () => subs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ClB;AAAA,EACF;AAEA,QAAM,OAAO,oBAAI,IAA0B;AAC3C,MAAI,SAAS;AACb,QAAM,MAAM,IAAI;AAAA,IACd,CAAC,YAAY;AACX,YAAM,OAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,cAAc;AACjD,UAAI,SAAS,OAAQ;AACrB,eAAS;AACT,iBAAW,MAAM,KAAM,IAAG,MAAM;AAAA,IAClC;AAAA,IACA,EAAE,WAAW,EAAE;AAAA,EACjB;AACA,MAAI,QAAQ,MAAM;AAElB,SAAO;AAAA,IACL,UAAU,MAAM;AAAA,IAChB,UAAU,IAAI;AACZ,WAAK,IAAI,EAAE;AACX,aAAO,MAAM,KAAK,OAAO,EAAE;AAAA,IAC7B;AAAA,IACA,UAAU;AACR,UAAI,WAAW;AACf,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AACF;","names":["sin","length","smoothstep","uniform","vec3","mix","length","length","sin","smoothstep"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lovo/matter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Engine for Matter — TSL primitives, renderer, scheduler. Framework-agnostic.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"shader",
|
|
8
|
+
"shaders",
|
|
9
|
+
"webgpu",
|
|
10
|
+
"tsl",
|
|
11
|
+
"three.js",
|
|
12
|
+
"react",
|
|
13
|
+
"components",
|
|
14
|
+
"gradient",
|
|
15
|
+
"background"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/lovo-hq/matter.git",
|
|
20
|
+
"directory": "packages/matter"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/lovo-hq/matter#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/lovo-hq/matter/issues"
|
|
25
|
+
},
|
|
26
|
+
"author": "lovo-hq",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"require": "./dist/index.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"three": "^0.170.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/three": "^0.170.0",
|
|
50
|
+
"happy-dom": "^15.0.0",
|
|
51
|
+
"three": "^0.170.0",
|
|
52
|
+
"tsup": "^8.3.0",
|
|
53
|
+
"typescript": "^5.6.0",
|
|
54
|
+
"vitest": "^2.1.0",
|
|
55
|
+
"@matter/eslint-config": "0.0.0",
|
|
56
|
+
"@matter/tsconfig": "0.0.0"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsup",
|
|
60
|
+
"dev": "tsup --watch",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"lint": "eslint src",
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"test:watch": "vitest",
|
|
65
|
+
"clean": "rm -rf dist .turbo *.tsbuildinfo"
|
|
66
|
+
}
|
|
67
|
+
}
|