stickyflow 0.9.3 → 0.11.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/CHANGELOG.md +20 -0
- package/README.md +1 -1
- package/dist/binding/index.cjs +9 -9
- package/dist/binding/index.d.cts +4 -4
- package/dist/binding/index.d.ts +4 -4
- package/dist/binding/index.js +3 -3
- package/dist/{chunk-EURX7QT3.cjs → chunk-5G3BEXQU.cjs} +1300 -891
- package/dist/chunk-5G3BEXQU.cjs.map +1 -0
- package/dist/{chunk-AAP24GBG.js → chunk-BFQWCOEC.js} +3 -3
- package/dist/chunk-BFQWCOEC.js.map +1 -0
- package/dist/{chunk-3EOG34QN.cjs → chunk-F24JURN2.cjs} +561 -258
- package/dist/chunk-F24JURN2.cjs.map +1 -0
- package/dist/{chunk-2GKXPZRL.cjs → chunk-FXGXUWSI.cjs} +23 -23
- package/dist/chunk-FXGXUWSI.cjs.map +1 -0
- package/dist/{chunk-Q6FBISNP.js → chunk-G6IW2IX3.js} +601 -350
- package/dist/chunk-G6IW2IX3.js.map +1 -0
- package/dist/{chunk-G2N3KJYJ.js → chunk-Q6QLU6YQ.js} +662 -253
- package/dist/chunk-Q6QLU6YQ.js.map +1 -0
- package/dist/{chunk-C3LVKPWQ.js → chunk-RQYZNW2I.js} +532 -229
- package/dist/chunk-RQYZNW2I.js.map +1 -0
- package/dist/{chunk-XNNNIOJU.js → chunk-UB2ANTWF.js} +5 -5
- package/dist/{chunk-XNNNIOJU.js.map → chunk-UB2ANTWF.js.map} +1 -1
- package/dist/{chunk-C25NWWIH.cjs → chunk-UHKFJBY5.cjs} +605 -350
- package/dist/chunk-UHKFJBY5.cjs.map +1 -0
- package/dist/{chunk-MR32IJQO.cjs → chunk-WZA3DJJH.cjs} +15 -15
- package/dist/chunk-WZA3DJJH.cjs.map +1 -0
- package/dist/index.cjs +36 -36
- package/dist/index.d.cts +35 -30
- package/dist/index.d.ts +35 -30
- package/dist/index.js +5 -5
- package/dist/interaction/index.cjs +319 -352
- package/dist/interaction/index.cjs.map +1 -1
- package/dist/interaction/index.d.cts +3 -3
- package/dist/interaction/index.d.ts +3 -3
- package/dist/interaction/index.js +94 -127
- package/dist/interaction/index.js.map +1 -1
- package/dist/{render-DU4lYbRl.d.ts → render-BDO4S5uF.d.cts} +16 -0
- package/dist/{render-DU4lYbRl.d.cts → render-BDO4S5uF.d.ts} +16 -0
- package/dist/{runtime-DG8X3Fwf.d.cts → runtime-C-C5v9po.d.cts} +2 -2
- package/dist/{runtime-kqD1RS17.d.ts → runtime-lCAfU-1Q.d.ts} +2 -2
- package/dist/{runtimeTypes-vRaHOIHi.d.ts → runtimeTypes-B7p6b1Bi.d.cts} +2 -2
- package/dist/{runtimeTypes-CvjlBZds.d.cts → runtimeTypes-BDA_CfWh.d.ts} +2 -2
- package/dist/stickyflow-diagram.global.js +197 -44
- package/dist/stickyflow-diagram.global.js.map +1 -1
- package/dist/{types-B5jrEEcF.d.cts → types-CZJzycKw.d.cts} +1 -1
- package/dist/{types-B7IkZ0w4.d.ts → types-Dp8JVZLB.d.ts} +1 -1
- package/dist/viewer/index.cjs +9 -9
- package/dist/viewer/index.d.cts +4 -4
- package/dist/viewer/index.d.ts +4 -4
- package/dist/viewer/index.js +4 -4
- package/dist/web-component/index.cjs +6 -6
- package/dist/web-component/index.cjs.map +1 -1
- package/dist/web-component/index.d.cts +2 -2
- package/dist/web-component/index.d.ts +2 -2
- package/dist/web-component/index.js +4 -4
- package/dist/web-component/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2GKXPZRL.cjs.map +0 -1
- package/dist/chunk-3EOG34QN.cjs.map +0 -1
- package/dist/chunk-AAP24GBG.js.map +0 -1
- package/dist/chunk-C25NWWIH.cjs.map +0 -1
- package/dist/chunk-C3LVKPWQ.js.map +0 -1
- package/dist/chunk-EURX7QT3.cjs.map +0 -1
- package/dist/chunk-G2N3KJYJ.js.map +0 -1
- package/dist/chunk-MR32IJQO.cjs.map +0 -1
- package/dist/chunk-Q6FBISNP.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { render } from './chunk-
|
|
2
|
-
import { parseContractVersion, isContractCompatible, Emitter, resolveOwner, CHANGE_COLOR, findOwnerNode, isPrimary, linkSelectionOverlay, pathSelectionOverlay, isometricSelectionOverlay, shapeSelectionOverlay, DERIVED_HEIGHT_ROLES, quickDuplicateBubbles, isCameraGesture, linkChangeOverlay, shapeChangeOverlay, startChangeFade, REDUCED_MOTION_DURATION_MS, FLASH_DURATION_MS } from './chunk-
|
|
3
|
-
import { getComponentDescriptor, formatRollingNumber, DEFAULT_ROLLING_NUMBER_STYLE } from './chunk-
|
|
1
|
+
import { render } from './chunk-Q6QLU6YQ.js';
|
|
2
|
+
import { parseContractVersion, isContractCompatible, Emitter, resolveOwner, CHANGE_COLOR, findOwnerNode, isPrimary, linkSelectionOverlay, pathSelectionOverlay, isometricSelectionOverlay, shapeSelectionOverlay, DERIVED_HEIGHT_ROLES, quickDuplicateBubbles, isCameraGesture, linkChangeOverlay, shapeChangeOverlay, startChangeFade, REDUCED_MOTION_DURATION_MS, FLASH_DURATION_MS } from './chunk-BFQWCOEC.js';
|
|
3
|
+
import { getComponentDescriptor, formatRollingNumber, DEFAULT_ROLLING_NUMBER_STYLE, parseHexRgb } from './chunk-G6IW2IX3.js';
|
|
4
4
|
|
|
5
5
|
// src/runtime/viewer/components/rollingNumberDom.ts
|
|
6
6
|
var HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
|
|
@@ -275,10 +275,14 @@ function parameters(surface) {
|
|
|
275
275
|
function positive(value, fallback) {
|
|
276
276
|
return Number(value) > 0 ? Number(value) : fallback;
|
|
277
277
|
}
|
|
278
|
+
function rangeOf(params) {
|
|
279
|
+
return {
|
|
280
|
+
min: Number(params.min) || 0,
|
|
281
|
+
max: Number.isFinite(Number(params.max)) && params.max !== void 0 ? Number(params.max) : 100
|
|
282
|
+
};
|
|
283
|
+
}
|
|
278
284
|
function rulerProgress(surface, value) {
|
|
279
|
-
const
|
|
280
|
-
const min = Number(params.min) || 0;
|
|
281
|
-
const max = Number.isFinite(Number(params.max)) && params.max !== void 0 ? Number(params.max) : 100;
|
|
285
|
+
const { min, max } = rangeOf(parameters(surface));
|
|
282
286
|
return clamp01(max === min ? 0 : (value - min) / (max - min));
|
|
283
287
|
}
|
|
284
288
|
function move(node, dx, dy) {
|
|
@@ -289,19 +293,11 @@ function move(node, dx, dy) {
|
|
|
289
293
|
written.set(node, next);
|
|
290
294
|
node.setAttribute("transform", next);
|
|
291
295
|
}
|
|
292
|
-
function hexToRgb(value) {
|
|
293
|
-
const match = /^#([0-9a-f]{6})$/i.exec(value.trim());
|
|
294
|
-
if (!match) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
const number2 = parseInt(match[1], 16);
|
|
298
|
-
return [number2 >> 16 & 255, number2 >> 8 & 255, number2 & 255];
|
|
299
|
-
}
|
|
300
296
|
var WHITE = [255, 255, 255];
|
|
301
297
|
function shade(node, bump, target) {
|
|
302
298
|
const base = fills.get(node) ?? node.getAttribute("fill") ?? "";
|
|
303
299
|
fills.set(node, base);
|
|
304
|
-
const rgb =
|
|
300
|
+
const rgb = parseHexRgb(base);
|
|
305
301
|
if (!rgb) {
|
|
306
302
|
return;
|
|
307
303
|
}
|
|
@@ -312,61 +308,84 @@ function shade(node, bump, target) {
|
|
|
312
308
|
child.style.fill = fill;
|
|
313
309
|
}
|
|
314
310
|
}
|
|
311
|
+
function rulerOf(surface, progressOf) {
|
|
312
|
+
const params = parameters(surface);
|
|
313
|
+
const id = surface.getAttribute("data-sf-id") ?? "";
|
|
314
|
+
const width = Number(surface.getAttribute("width"));
|
|
315
|
+
const height = Number(surface.getAttribute("height"));
|
|
316
|
+
const horizontal = params.axis === "horizontal";
|
|
317
|
+
const across = horizontal ? height : width;
|
|
318
|
+
const dent = params.dent === void 0 ? 1 : Number(params.dent);
|
|
319
|
+
return {
|
|
320
|
+
id,
|
|
321
|
+
params,
|
|
322
|
+
x: Number(surface.getAttribute("x")),
|
|
323
|
+
y: Number(surface.getAttribute("y")),
|
|
324
|
+
width,
|
|
325
|
+
height,
|
|
326
|
+
horizontal,
|
|
327
|
+
progress: clamp01(progressOf(id) ?? Number(params.progress)),
|
|
328
|
+
inset: positive(params.inset, 0.05),
|
|
329
|
+
extent: horizontal ? width : height,
|
|
330
|
+
across,
|
|
331
|
+
depth: (dent < 0 ? 1 : dent) * 0.16 * across
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function placeKnob(svg, ruler) {
|
|
335
|
+
const { params, x, y, width, height, horizontal, across, depth } = ruler;
|
|
336
|
+
const knobId = typeof params.knob === "string" ? params.knob : "";
|
|
337
|
+
if (!knobId) {
|
|
338
|
+
return void 0;
|
|
339
|
+
}
|
|
340
|
+
const nodes = [...svg.querySelectorAll(`[data-sf-id="${CSS.escape(knobId)}"]`)];
|
|
341
|
+
const primary = nodes.find((node) => node.hasAttribute("data-sf-primary"));
|
|
342
|
+
if (!primary?.getBBox) {
|
|
343
|
+
return void 0;
|
|
344
|
+
}
|
|
345
|
+
move(primary, 0, 0);
|
|
346
|
+
const box = primary.getBBox();
|
|
347
|
+
const half = (horizontal ? box.height : box.width) / 2;
|
|
348
|
+
const along = ruler.inset + (1 - 2 * ruler.inset) * ruler.progress;
|
|
349
|
+
const line = positive(params.line, 0.7);
|
|
350
|
+
const gap = (params.gap === void 0 ? 0.04 : Number(params.gap)) * across;
|
|
351
|
+
const side = line * across - depth + half + gap;
|
|
352
|
+
const target = horizontal ? { x: x + width * along, y: y + side } : { x: x + side, y: y + height * (1 - along) };
|
|
353
|
+
const dx = target.x - (box.x + box.width / 2);
|
|
354
|
+
const dy = target.y - (box.y + box.height / 2);
|
|
355
|
+
for (const node of nodes) {
|
|
356
|
+
move(node, dx, dy);
|
|
357
|
+
}
|
|
358
|
+
return half / across;
|
|
359
|
+
}
|
|
360
|
+
function liftLabels(svg, ruler) {
|
|
361
|
+
const { id, params, horizontal, extent, inset, progress, depth } = ruler;
|
|
362
|
+
const { min, max } = rangeOf(params);
|
|
363
|
+
const peak = (typeof params.peak === "string" ? parseHexRgb(params.peak) : null) ?? WHITE;
|
|
364
|
+
const spread = positive(params.spread, 0.07) * extent;
|
|
365
|
+
const start = inset * extent;
|
|
366
|
+
const span = (1 - 2 * inset) * extent;
|
|
367
|
+
const knobAt = start + span * progress;
|
|
368
|
+
for (const label of svg.querySelectorAll(`text[data-sf-id="${CSS.escape(id)}"]`)) {
|
|
369
|
+
const value = Number(label.textContent);
|
|
370
|
+
if (!Number.isFinite(value) || max === min) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
const labelAt = start + span * clamp01((value - min) / (max - min));
|
|
374
|
+
const bump = Math.exp(-(((labelAt - knobAt) / spread) ** 2));
|
|
375
|
+
const shift = depth * 0.4 * bump;
|
|
376
|
+
move(label, horizontal ? 0 : -shift, horizontal ? -shift : 0);
|
|
377
|
+
shade(label, bump, peak);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
315
380
|
function placeRulerKnobs(svg, progressOf) {
|
|
316
381
|
const radii = /* @__PURE__ */ new Map();
|
|
317
382
|
for (const surface of svg.querySelectorAll('foreignObject[data-sf-shader="ruler"]')) {
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const y = Number(surface.getAttribute("y"));
|
|
323
|
-
const width = Number(surface.getAttribute("width"));
|
|
324
|
-
const height = Number(surface.getAttribute("height"));
|
|
325
|
-
const horizontal = params.axis === "horizontal";
|
|
326
|
-
const progress = clamp01(progressOf(id) ?? Number(params.progress));
|
|
327
|
-
const inset = positive(params.inset, 0.05);
|
|
328
|
-
const line = positive(params.line, 0.7);
|
|
329
|
-
const extent = horizontal ? width : height;
|
|
330
|
-
const across = horizontal ? height : width;
|
|
331
|
-
const along = inset + (1 - 2 * inset) * progress;
|
|
332
|
-
const dent = params.dent === void 0 ? 1 : Number(params.dent);
|
|
333
|
-
const depth = (dent < 0 ? 1 : dent) * 0.16 * across;
|
|
334
|
-
const knobId = typeof params.knob === "string" ? params.knob : "";
|
|
335
|
-
if (knobId) {
|
|
336
|
-
const nodes = [...svg.querySelectorAll(`[data-sf-id="${CSS.escape(knobId)}"]`)];
|
|
337
|
-
const primary = nodes.find((node) => node.hasAttribute("data-sf-primary"));
|
|
338
|
-
if (primary?.getBBox) {
|
|
339
|
-
move(primary, 0, 0);
|
|
340
|
-
const box = primary.getBBox();
|
|
341
|
-
const half = (horizontal ? box.height : box.width) / 2;
|
|
342
|
-
radii.set(id, half / across);
|
|
343
|
-
const gap = (params.gap === void 0 ? 0.04 : Number(params.gap)) * across;
|
|
344
|
-
const side = line * across - depth + half + gap;
|
|
345
|
-
const target = horizontal ? { x: x + width * along, y: y + side } : { x: x + side, y: y + height * (1 - along) };
|
|
346
|
-
const dx = target.x - (box.x + box.width / 2);
|
|
347
|
-
const dy = target.y - (box.y + box.height / 2);
|
|
348
|
-
for (const node of nodes) {
|
|
349
|
-
move(node, dx, dy);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
const min = Number(params.min) || 0;
|
|
354
|
-
const max = Number.isFinite(Number(params.max)) && params.max !== void 0 ? Number(params.max) : 100;
|
|
355
|
-
const spread = positive(params.spread, 0.07) * extent;
|
|
356
|
-
const start = inset * extent;
|
|
357
|
-
const span = (1 - 2 * inset) * extent;
|
|
358
|
-
const knobAt = start + span * progress;
|
|
359
|
-
for (const label of svg.querySelectorAll(`text[data-sf-id="${CSS.escape(id)}"]`)) {
|
|
360
|
-
const value = Number(label.textContent);
|
|
361
|
-
if (!Number.isFinite(value) || max === min) {
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
const labelAt = start + span * clamp01((value - min) / (max - min));
|
|
365
|
-
const bump = Math.exp(-(((labelAt - knobAt) / spread) ** 2));
|
|
366
|
-
const shift = depth * 0.4 * bump;
|
|
367
|
-
move(label, horizontal ? 0 : -shift, horizontal ? -shift : 0);
|
|
368
|
-
shade(label, bump, peak);
|
|
383
|
+
const ruler = rulerOf(surface, progressOf);
|
|
384
|
+
const radius = placeKnob(svg, ruler);
|
|
385
|
+
if (radius !== void 0) {
|
|
386
|
+
radii.set(ruler.id, radius);
|
|
369
387
|
}
|
|
388
|
+
liftLabels(svg, ruler);
|
|
370
389
|
}
|
|
371
390
|
return radii;
|
|
372
391
|
}
|
|
@@ -2950,9 +2969,7 @@ float roundedBoxDistance(vec2 point, vec2 halfSize, float radius) {
|
|
|
2950
2969
|
}
|
|
2951
2970
|
|
|
2952
2971
|
float random(vec2 point) {
|
|
2953
|
-
|
|
2954
|
-
value += dot(value, value.yzx + 33.33);
|
|
2955
|
-
return fract((value.x + value.y) * value.z);
|
|
2972
|
+
return fract(sin(dot(mod(point, 289.0), vec2(127.1, 311.7))) * 43758.5453123);
|
|
2956
2973
|
}
|
|
2957
2974
|
|
|
2958
2975
|
void main() {
|
|
@@ -3563,6 +3580,218 @@ var violetGlassLightProgram = {
|
|
|
3563
3580
|
fragmentSource: fragmentSource26
|
|
3564
3581
|
};
|
|
3565
3582
|
|
|
3583
|
+
// src/runtime/viewer/shaders/builtins/vortex.ts
|
|
3584
|
+
var fragmentSource27 = `
|
|
3585
|
+
precision highp float;
|
|
3586
|
+
|
|
3587
|
+
uniform float uTime;
|
|
3588
|
+
uniform float uSpeed;
|
|
3589
|
+
uniform float uIntensity;
|
|
3590
|
+
uniform float uRings;
|
|
3591
|
+
uniform float uRingWidth;
|
|
3592
|
+
uniform float uTwist;
|
|
3593
|
+
uniform float uArms;
|
|
3594
|
+
uniform float uWobble;
|
|
3595
|
+
uniform float uVariation;
|
|
3596
|
+
uniform float uOffsetX;
|
|
3597
|
+
uniform float uOffsetY;
|
|
3598
|
+
uniform float uSquash;
|
|
3599
|
+
uniform float uEye;
|
|
3600
|
+
uniform float uAngle;
|
|
3601
|
+
uniform float uSpread;
|
|
3602
|
+
uniform float uGlow;
|
|
3603
|
+
uniform float uGloss;
|
|
3604
|
+
uniform float uGlossHeight;
|
|
3605
|
+
uniform float uVignette;
|
|
3606
|
+
uniform float uGrain;
|
|
3607
|
+
uniform vec3 uColor;
|
|
3608
|
+
uniform vec3 uAccent;
|
|
3609
|
+
uniform vec3 uCool;
|
|
3610
|
+
varying vec2 vUv;
|
|
3611
|
+
|
|
3612
|
+
float hash(vec2 p) {
|
|
3613
|
+
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
void main() {
|
|
3617
|
+
vec2 p = vUv * 2.0 - 1.0;
|
|
3618
|
+
float edge = length(p);
|
|
3619
|
+
if (edge > 1.0) discard;
|
|
3620
|
+
|
|
3621
|
+
float time = uTime * max(uSpeed, 0.0);
|
|
3622
|
+
|
|
3623
|
+
// The rings are measured from a middle that can lie off the middle of the face, and squeezed to give a little depth.
|
|
3624
|
+
vec2 q = p - vec2(uOffsetX, uOffsetY);
|
|
3625
|
+
q.y /= max(uSquash, 0.2);
|
|
3626
|
+
float radius = length(q);
|
|
3627
|
+
float around = atan(q.y, q.x);
|
|
3628
|
+
float turn = around / 6.2831853;
|
|
3629
|
+
// The twist turns the pattern more the nearer it is to the middle. The rings themselves stay round.
|
|
3630
|
+
float angle = around + uTwist * pow(1.0 - radius, 2.0) * 3.0 + time * 0.3 * (1.0 - radius);
|
|
3631
|
+
|
|
3632
|
+
// The phase of the rings: outwards from the middle, drifting inwards with time. Whole arms make the rings join into a spiral, and a
|
|
3633
|
+
// whole number leaves no seam. The wobble bends the rings so no two are alike.
|
|
3634
|
+
float bend = uWobble * (0.12 * sin(angle * 2.0 + time * 0.6 + radius * 3.0) + 0.06 * sin(angle * 3.0 - time * 0.45));
|
|
3635
|
+
float phase = (radius + bend) * uRings - time * 0.25 + floor(uArms + 0.5) * turn;
|
|
3636
|
+
float away = abs(fract(phase) - 0.5);
|
|
3637
|
+
float width = mix(0.04, 0.32, clamp(uRingWidth, 0.0, 1.0));
|
|
3638
|
+
// Every ring has a brightness of its own, so a few stand out and the others are faint.
|
|
3639
|
+
float own = mix(1.0, 0.25 + 1.0 * hash(vec2(floor(phase), 3.7)), clamp(uVariation, 0.0, 1.0));
|
|
3640
|
+
float ring = exp(-pow(away / width, 2.0)) * own;
|
|
3641
|
+
float fineAway = abs(fract(phase * 2.3 + 0.5) - 0.5);
|
|
3642
|
+
float fine = exp(-pow(fineAway / (width * 0.8), 2.0)) * 0.5;
|
|
3643
|
+
float halo = exp(-pow(away / (width * 3.0), 2.0));
|
|
3644
|
+
|
|
3645
|
+
// Rings fade in from the eye and out towards the rim, and some arcs of a ring are brighter than the rest.
|
|
3646
|
+
float envelope = smoothstep(uEye, uEye + 0.3, radius) * (1.0 - smoothstep(0.72, 1.05, edge));
|
|
3647
|
+
float arcs = 0.45 + 0.55 * (0.5 + 0.5 * sin(angle * 2.0 + radius * 4.0 + time * 0.5 + 1.0));
|
|
3648
|
+
|
|
3649
|
+
// One side of the face is warm and the other cool, and the spread says how sharp the change is.
|
|
3650
|
+
float side = cos(angle - radians(uAngle));
|
|
3651
|
+
float warm = mix(0.5, smoothstep(-0.7, 0.9, side), clamp(uSpread, 0.0, 1.0));
|
|
3652
|
+
vec3 hue = mix(uCool, uAccent, warm);
|
|
3653
|
+
|
|
3654
|
+
vec3 color = uColor * (0.4 + 0.5 * (1.0 - edge));
|
|
3655
|
+
color += hue * (ring * 0.9 + fine * 0.3) * envelope * arcs * uGlow;
|
|
3656
|
+
color += hue * halo * envelope * 0.1 * uGlow;
|
|
3657
|
+
// The dark eye.
|
|
3658
|
+
color *= 0.55 + 0.45 * smoothstep(0.0, uEye + 0.12, radius);
|
|
3659
|
+
|
|
3660
|
+
// A soft light on the glass at the bottom, with a clear lower edge.
|
|
3661
|
+
float below = smoothstep(-1.0 + uGlossHeight, -1.0 + uGlossHeight * 0.35, p.y);
|
|
3662
|
+
float across = 1.0 - smoothstep(0.45, 1.0, abs(p.x));
|
|
3663
|
+
color += mix(uCool, vec3(1.0), 0.5) * below * across * uGloss;
|
|
3664
|
+
|
|
3665
|
+
color *= 1.0 - smoothstep(0.55, 1.0, edge) * uVignette;
|
|
3666
|
+
color += (hash(gl_FragCoord.xy + time) - 0.5) * uGrain;
|
|
3667
|
+
|
|
3668
|
+
float alpha = 1.0 - smoothstep(0.985, 1.0, edge);
|
|
3669
|
+
gl_FragColor = vec4(clamp(color * max(uIntensity, 0.0), 0.0, 1.0), alpha);
|
|
3670
|
+
}
|
|
3671
|
+
`;
|
|
3672
|
+
var vortexProgram = {
|
|
3673
|
+
name: "vortex",
|
|
3674
|
+
fragmentSource: fragmentSource27,
|
|
3675
|
+
defaultParameters: {
|
|
3676
|
+
speed: 0.3,
|
|
3677
|
+
intensity: 1,
|
|
3678
|
+
rings: 12,
|
|
3679
|
+
ringWidth: 0.28,
|
|
3680
|
+
twist: 0.6,
|
|
3681
|
+
arms: 0,
|
|
3682
|
+
wobble: 0.12,
|
|
3683
|
+
variation: 0.85,
|
|
3684
|
+
offsetX: 0,
|
|
3685
|
+
offsetY: 0,
|
|
3686
|
+
squash: 1,
|
|
3687
|
+
eye: 0.3,
|
|
3688
|
+
angle: 215,
|
|
3689
|
+
spread: 0.6,
|
|
3690
|
+
glow: 0.6,
|
|
3691
|
+
gloss: 0.45,
|
|
3692
|
+
glossHeight: 0.4,
|
|
3693
|
+
vignette: 0.6,
|
|
3694
|
+
grain: 0.02,
|
|
3695
|
+
color: "#05060f",
|
|
3696
|
+
accent: "#e0368f",
|
|
3697
|
+
cool: "#3d4bff"
|
|
3698
|
+
}
|
|
3699
|
+
};
|
|
3700
|
+
|
|
3701
|
+
// src/runtime/viewer/shaders/builtins/waves.ts
|
|
3702
|
+
var fragmentSource28 = `
|
|
3703
|
+
precision highp float;
|
|
3704
|
+
|
|
3705
|
+
uniform float uTime;
|
|
3706
|
+
uniform float uSpeed;
|
|
3707
|
+
uniform float uIntensity;
|
|
3708
|
+
uniform float uLayers;
|
|
3709
|
+
uniform float uLevel;
|
|
3710
|
+
uniform float uAmplitude;
|
|
3711
|
+
uniform float uFrequency;
|
|
3712
|
+
uniform float uTilt;
|
|
3713
|
+
uniform float uSoftness;
|
|
3714
|
+
uniform float uEdge;
|
|
3715
|
+
uniform float uShade;
|
|
3716
|
+
uniform float uGlow;
|
|
3717
|
+
uniform float uVignette;
|
|
3718
|
+
uniform float uGrain;
|
|
3719
|
+
uniform vec3 uColor;
|
|
3720
|
+
uniform vec3 uAccent;
|
|
3721
|
+
uniform vec3 uCool;
|
|
3722
|
+
uniform vec3 uHighlight;
|
|
3723
|
+
varying vec2 vUv;
|
|
3724
|
+
|
|
3725
|
+
float hash(vec2 p) {
|
|
3726
|
+
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3729
|
+
void main() {
|
|
3730
|
+
vec2 p = vUv * 2.0 - 1.0;
|
|
3731
|
+
float edge = length(p);
|
|
3732
|
+
if (edge > 1.0) discard;
|
|
3733
|
+
|
|
3734
|
+
float time = uTime * max(uSpeed, 0.0);
|
|
3735
|
+
float angle = radians(uTilt);
|
|
3736
|
+
vec2 q = vec2(cos(angle) * p.x - sin(angle) * p.y, sin(angle) * p.x + cos(angle) * p.y);
|
|
3737
|
+
|
|
3738
|
+
// The ground, a little lighter in the middle.
|
|
3739
|
+
vec3 color = uColor * (0.6 + 0.4 * (1.0 - edge));
|
|
3740
|
+
float count = clamp(uLayers, 1.0, 8.0);
|
|
3741
|
+
float soft = max(uSoftness, 0.004);
|
|
3742
|
+
|
|
3743
|
+
// The layers lie one behind the other, the farthest first. Each one fills the area under a wave line, and the line itself catches the light.
|
|
3744
|
+
for (int i = 0; i < 8; i++) {
|
|
3745
|
+
float index = float(i);
|
|
3746
|
+
if (index >= count) break;
|
|
3747
|
+
float depth = index / max(count - 1.0, 1.0);
|
|
3748
|
+
float base = uLevel + mix(0.5, -0.55, depth);
|
|
3749
|
+
float swing = uAmplitude * (0.55 + 0.45 * depth);
|
|
3750
|
+
float line = base
|
|
3751
|
+
+ swing * 0.6 * sin(q.x * uFrequency * (1.0 + 0.3 * index) + index * 1.7 + time * (0.4 + 0.08 * index))
|
|
3752
|
+
+ swing * 0.4 * sin(q.x * uFrequency * 2.1 - index * 2.3 - time * 0.3);
|
|
3753
|
+
float under = smoothstep(soft, -soft, q.y - line);
|
|
3754
|
+
// A layer is lit at its crest and falls into shadow below it, so it reads as a fold of cloth and not as a flat band.
|
|
3755
|
+
float sink = clamp((line - q.y) / 0.35, 0.0, 1.0);
|
|
3756
|
+
vec3 layer = mix(uAccent, uCool, depth) * mix(1.15, 1.0 - 0.6 * uShade, sink);
|
|
3757
|
+
color = mix(color, layer, under * (0.5 + 0.2 * depth));
|
|
3758
|
+
float crest = exp(-pow((q.y - line) / (0.012 + soft * 0.5), 2.0));
|
|
3759
|
+
color += uHighlight * crest * uEdge * (0.35 + 0.65 * (1.0 - depth));
|
|
3760
|
+
}
|
|
3761
|
+
|
|
3762
|
+
// A soft light over the surface, and a dark edge.
|
|
3763
|
+
color += uHighlight * uGlow * 0.18 * exp(-pow((q.y - 0.55) / 0.45, 2.0));
|
|
3764
|
+
color *= 1.0 - smoothstep(0.6, 1.0, edge) * uVignette;
|
|
3765
|
+
color += (hash(gl_FragCoord.xy + time) - 0.5) * uGrain;
|
|
3766
|
+
|
|
3767
|
+
float alpha = 1.0 - smoothstep(0.985, 1.0, edge);
|
|
3768
|
+
gl_FragColor = vec4(clamp(color * max(uIntensity, 0.0), 0.0, 1.0), alpha);
|
|
3769
|
+
}
|
|
3770
|
+
`;
|
|
3771
|
+
var wavesProgram = {
|
|
3772
|
+
name: "waves",
|
|
3773
|
+
fragmentSource: fragmentSource28,
|
|
3774
|
+
defaultParameters: {
|
|
3775
|
+
speed: 0.25,
|
|
3776
|
+
intensity: 1,
|
|
3777
|
+
layers: 5,
|
|
3778
|
+
level: 0,
|
|
3779
|
+
amplitude: 0.14,
|
|
3780
|
+
frequency: 3.2,
|
|
3781
|
+
tilt: -12,
|
|
3782
|
+
softness: 0.05,
|
|
3783
|
+
edge: 0.5,
|
|
3784
|
+
shade: 0.6,
|
|
3785
|
+
glow: 0.5,
|
|
3786
|
+
vignette: 0.4,
|
|
3787
|
+
grain: 0.02,
|
|
3788
|
+
color: "#0e0828",
|
|
3789
|
+
accent: "#6b3fd4",
|
|
3790
|
+
cool: "#2f5fe0",
|
|
3791
|
+
highlight: "#b9a0ff"
|
|
3792
|
+
}
|
|
3793
|
+
};
|
|
3794
|
+
|
|
3566
3795
|
// src/runtime/viewer/shaders/programs.ts
|
|
3567
3796
|
var builtins = [
|
|
3568
3797
|
orbProgram,
|
|
@@ -3590,7 +3819,9 @@ var builtins = [
|
|
|
3590
3819
|
lightBandProgram,
|
|
3591
3820
|
silkFoldsProgram,
|
|
3592
3821
|
glowCardProgram,
|
|
3593
|
-
glassDotsProgram
|
|
3822
|
+
glassDotsProgram,
|
|
3823
|
+
vortexProgram,
|
|
3824
|
+
wavesProgram
|
|
3594
3825
|
];
|
|
3595
3826
|
var programs = new Map(builtins.map((program) => [program.name, program]));
|
|
3596
3827
|
function registerShaderProgram(program) {
|
|
@@ -3771,9 +4002,9 @@ function compile(gl, type, source) {
|
|
|
3771
4002
|
}
|
|
3772
4003
|
return shader;
|
|
3773
4004
|
}
|
|
3774
|
-
function linkProgram(gl,
|
|
4005
|
+
function linkProgram(gl, fragmentSource29) {
|
|
3775
4006
|
const vertex = compile(gl, gl.VERTEX_SHADER, VERTEX_SOURCE);
|
|
3776
|
-
const fragment = compile(gl, gl.FRAGMENT_SHADER,
|
|
4007
|
+
const fragment = compile(gl, gl.FRAGMENT_SHADER, fragmentSource29);
|
|
3777
4008
|
if (!vertex || !fragment) {
|
|
3778
4009
|
if (vertex) {
|
|
3779
4010
|
gl.deleteShader(vertex);
|
|
@@ -3874,6 +4105,7 @@ function createSurface(canvas) {
|
|
|
3874
4105
|
const baseFill = baseGeometry?.getAttribute("fill");
|
|
3875
4106
|
baseGeometry?.setAttribute("fill", "none");
|
|
3876
4107
|
return {
|
|
4108
|
+
programName: definition.name,
|
|
3877
4109
|
owner,
|
|
3878
4110
|
canvas,
|
|
3879
4111
|
gl,
|
|
@@ -3910,6 +4142,22 @@ function releaseSurface(surface) {
|
|
|
3910
4142
|
surface.baseGeometry.setAttribute("fill", surface.baseFill);
|
|
3911
4143
|
}
|
|
3912
4144
|
}
|
|
4145
|
+
function refreshSurface(surface, svg) {
|
|
4146
|
+
const owner = surface.canvas.closest("[data-sf-shader]");
|
|
4147
|
+
const name = owner?.getAttribute("data-sf-shader");
|
|
4148
|
+
const definition = name ? shaderProgram(name) : void 0;
|
|
4149
|
+
if (!owner || !svg.contains(surface.canvas) || !definition) {
|
|
4150
|
+
return false;
|
|
4151
|
+
}
|
|
4152
|
+
if (definition.name !== surface.programName || definition.replacesBaseFill || surface.baseGeometry) {
|
|
4153
|
+
return false;
|
|
4154
|
+
}
|
|
4155
|
+
surface.owner = owner;
|
|
4156
|
+
surface.parameters = { ...definition.defaultParameters, ...parametersOf(owner) };
|
|
4157
|
+
surface.surfacePadding = surfacePaddingOf(owner);
|
|
4158
|
+
surface.shapeColor = color(owner.getAttribute("data-sf-shader-fill") ?? void 0, [1, 1, 1]);
|
|
4159
|
+
return true;
|
|
4160
|
+
}
|
|
3913
4161
|
|
|
3914
4162
|
// src/runtime/viewer/shaders/reactiveLightField.ts
|
|
3915
4163
|
function geometryOf(surface) {
|
|
@@ -4042,8 +4290,7 @@ function applyBackdrop(surface, backdrop) {
|
|
|
4042
4290
|
}
|
|
4043
4291
|
var MAX_SURFACE_PIXELS = 2560;
|
|
4044
4292
|
var TRAIL_LENGTH = 16;
|
|
4045
|
-
function
|
|
4046
|
-
const { canvas, gl, parameters: parameters3 } = surface;
|
|
4293
|
+
function fitCanvas(canvas) {
|
|
4047
4294
|
const shown = canvas.getBoundingClientRect();
|
|
4048
4295
|
const density = Math.min(globalThis.devicePixelRatio || 1, 3);
|
|
4049
4296
|
const fit = Math.min(1, MAX_SURFACE_PIXELS / Math.max(1, shown.width * density, shown.height * density));
|
|
@@ -4053,32 +4300,22 @@ function renderSurface(surface, seconds) {
|
|
|
4053
4300
|
canvas.width = width;
|
|
4054
4301
|
canvas.height = height;
|
|
4055
4302
|
}
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
gl
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
surface,
|
|
4067
|
-
"uPixelScale",
|
|
4068
|
-
Number.isFinite(logicalWidth) && logicalWidth > 0 ? width / logicalWidth : density * fit
|
|
4069
|
-
);
|
|
4070
|
-
uniform1f(surface, "uTime", seconds);
|
|
4071
|
-
if (surface.backdropTexture) {
|
|
4072
|
-
syncBackdropBounds(surface);
|
|
4073
|
-
gl.activeTexture(gl.TEXTURE0);
|
|
4074
|
-
gl.bindTexture(gl.TEXTURE_2D, surface.backdropTexture);
|
|
4075
|
-
const sampler = gl.getUniformLocation(surface.program, "uBackdrop");
|
|
4076
|
-
if (sampler) {
|
|
4077
|
-
gl.uniform1i(sampler, 0);
|
|
4078
|
-
}
|
|
4079
|
-
uniform2f(surface, "uBackdropOrigin", surface.backdropOrigin);
|
|
4080
|
-
uniform2f(surface, "uBackdropScale", surface.backdropScale);
|
|
4303
|
+
return { width, height, density, fit };
|
|
4304
|
+
}
|
|
4305
|
+
function bindBackdrop(surface, texture) {
|
|
4306
|
+
const { gl } = surface;
|
|
4307
|
+
syncBackdropBounds(surface);
|
|
4308
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
4309
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
4310
|
+
const sampler = gl.getUniformLocation(surface.program, "uBackdrop");
|
|
4311
|
+
if (sampler) {
|
|
4312
|
+
gl.uniform1i(sampler, 0);
|
|
4081
4313
|
}
|
|
4314
|
+
uniform2f(surface, "uBackdropOrigin", surface.backdropOrigin);
|
|
4315
|
+
uniform2f(surface, "uBackdropScale", surface.backdropScale);
|
|
4316
|
+
}
|
|
4317
|
+
function uploadParameters(surface) {
|
|
4318
|
+
const { parameters: parameters3 } = surface;
|
|
4082
4319
|
for (const [key, fallback] of Object.entries(SHADER_DEFAULTS.numbers)) {
|
|
4083
4320
|
uniform1f(surface, uniformName(key), number(parameters3[key], fallback));
|
|
4084
4321
|
}
|
|
@@ -4086,9 +4323,9 @@ function renderSurface(surface, seconds) {
|
|
|
4086
4323
|
uniform3f(surface, uniformName(key), color(parameters3[key], [...fallback]));
|
|
4087
4324
|
}
|
|
4088
4325
|
uniform3f(surface, "uShapeColor", surface.shapeColor);
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4326
|
+
}
|
|
4327
|
+
function uploadPointer(surface, seconds, elapsed) {
|
|
4328
|
+
const { gl, parameters: parameters3 } = surface;
|
|
4092
4329
|
surface.hover += ((surface.hovering ? 1 : 0) - surface.hover) * (1 - Math.exp(-elapsed / 0.18));
|
|
4093
4330
|
uniform2f(surface, "uPointer", [surface.pointer.x, surface.pointer.y]);
|
|
4094
4331
|
uniform1f(surface, "uHover", surface.hover);
|
|
@@ -4103,13 +4340,44 @@ function renderSurface(surface, seconds) {
|
|
|
4103
4340
|
if (trail) {
|
|
4104
4341
|
gl.uniform3fv(trail, places);
|
|
4105
4342
|
}
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4343
|
+
}
|
|
4344
|
+
function uploadReactiveLight(surface) {
|
|
4345
|
+
if (!surface.reactiveLight) {
|
|
4346
|
+
return;
|
|
4347
|
+
}
|
|
4348
|
+
uniform1f(surface, "uLightX", surface.reactiveLight.x);
|
|
4349
|
+
uniform1f(surface, "uLightY", surface.reactiveLight.y);
|
|
4350
|
+
uniform1f(surface, "uLightStrength", surface.reactiveLight.strength);
|
|
4351
|
+
uniform1f(surface, "uGlowRadius", surface.reactiveLight.radius);
|
|
4352
|
+
uniform3f(surface, "uLightColor", surface.reactiveLight.color);
|
|
4353
|
+
}
|
|
4354
|
+
function renderSurface(surface, seconds) {
|
|
4355
|
+
const { canvas, gl } = surface;
|
|
4356
|
+
const { width, height, density, fit } = fitCanvas(canvas);
|
|
4357
|
+
gl.viewport(0, 0, width, height);
|
|
4358
|
+
gl.clearColor(0, 0, 0, 0);
|
|
4359
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
4360
|
+
gl.useProgram(surface.program);
|
|
4361
|
+
const resolution = gl.getUniformLocation(surface.program, "uResolution");
|
|
4362
|
+
if (resolution) {
|
|
4363
|
+
gl.uniform2f(resolution, width, height);
|
|
4112
4364
|
}
|
|
4365
|
+
const logicalWidth = Number(surface.owner.getAttribute("width"));
|
|
4366
|
+
uniform1f(
|
|
4367
|
+
surface,
|
|
4368
|
+
"uPixelScale",
|
|
4369
|
+
Number.isFinite(logicalWidth) && logicalWidth > 0 ? width / logicalWidth : density * fit
|
|
4370
|
+
);
|
|
4371
|
+
uniform1f(surface, "uTime", seconds);
|
|
4372
|
+
if (surface.backdropTexture) {
|
|
4373
|
+
bindBackdrop(surface, surface.backdropTexture);
|
|
4374
|
+
}
|
|
4375
|
+
uploadParameters(surface);
|
|
4376
|
+
const elapsed = surface.lastSeconds === void 0 ? 0 : Math.max(0, Math.min(seconds - surface.lastSeconds, 0.1));
|
|
4377
|
+
surface.lastSeconds = seconds;
|
|
4378
|
+
applyParameters(surface, elapsed);
|
|
4379
|
+
uploadPointer(surface, seconds, elapsed);
|
|
4380
|
+
uploadReactiveLight(surface);
|
|
4113
4381
|
uniform1f(surface, "uSurfacePadding", surface.surfacePadding);
|
|
4114
4382
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
4115
4383
|
}
|
|
@@ -4184,152 +4452,187 @@ function watchSvgChanges(svg, view, onChange) {
|
|
|
4184
4452
|
sizes?.disconnect();
|
|
4185
4453
|
};
|
|
4186
4454
|
}
|
|
4187
|
-
function
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4455
|
+
function rememberSurfaces(surfaces) {
|
|
4456
|
+
return new Map(
|
|
4457
|
+
surfaces.flatMap((surface) => {
|
|
4458
|
+
const ownerId = surface.owner.getAttribute("data-sf-id");
|
|
4459
|
+
return ownerId ? [
|
|
4460
|
+
[
|
|
4461
|
+
ownerId,
|
|
4462
|
+
{
|
|
4463
|
+
smoothed: new Map(surface.smoothed),
|
|
4464
|
+
reactiveLight: surface.reactiveLight,
|
|
4465
|
+
pointer: surface.pointer,
|
|
4466
|
+
hover: surface.hover,
|
|
4467
|
+
hovering: surface.hovering,
|
|
4468
|
+
trail: surface.trail
|
|
4469
|
+
}
|
|
4470
|
+
]
|
|
4471
|
+
] : [];
|
|
4472
|
+
})
|
|
4473
|
+
);
|
|
4474
|
+
}
|
|
4475
|
+
function createSurfaces(svg, memory, kept) {
|
|
4476
|
+
return [...svg.querySelectorAll("canvas[data-sf-shader-canvas]")].flatMap((canvas) => {
|
|
4477
|
+
const keptSurface = kept.get(canvas);
|
|
4478
|
+
if (keptSurface) {
|
|
4479
|
+
return [keptSurface];
|
|
4480
|
+
}
|
|
4481
|
+
const surface = createSurface(canvas);
|
|
4482
|
+
const ownerId = surface?.owner.getAttribute("data-sf-id");
|
|
4483
|
+
const previous = ownerId ? memory.get(ownerId) : void 0;
|
|
4484
|
+
if (surface && previous) {
|
|
4485
|
+
Object.assign(surface, previous);
|
|
4486
|
+
}
|
|
4487
|
+
return surface ? [surface] : [];
|
|
4488
|
+
});
|
|
4489
|
+
}
|
|
4490
|
+
function followPointer(surface, event, now) {
|
|
4491
|
+
const box = surface.canvas.getBoundingClientRect();
|
|
4492
|
+
const inside = box.width > 0 && box.height > 0 && event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom;
|
|
4493
|
+
surface.hovering = inside;
|
|
4494
|
+
if (!inside) {
|
|
4495
|
+
return;
|
|
4496
|
+
}
|
|
4497
|
+
surface.pointer = { x: (event.clientX - box.left) / box.width, y: 1 - (event.clientY - box.top) / box.height };
|
|
4498
|
+
const last = surface.trail[surface.trail.length - 1];
|
|
4499
|
+
if (!last || now - last.at >= TRAIL_SPACING) {
|
|
4500
|
+
surface.trail.push({ ...surface.pointer, at: now });
|
|
4501
|
+
if (surface.trail.length > TRAIL_LENGTH2) {
|
|
4502
|
+
surface.trail.shift();
|
|
4503
|
+
}
|
|
4504
|
+
}
|
|
4505
|
+
}
|
|
4506
|
+
var ShaderSurfaces = class {
|
|
4507
|
+
constructor(svg) {
|
|
4508
|
+
this.svg = svg;
|
|
4509
|
+
this.view = svg.ownerDocument.defaultView;
|
|
4510
|
+
this.clock = createSurfaceClock(this.view);
|
|
4511
|
+
this.unwatch = watchSvgChanges(svg, this.view, this.scheduleRecapture);
|
|
4512
|
+
svg.addEventListener("pointermove", this.track);
|
|
4513
|
+
svg.addEventListener("pointerleave", this.leave);
|
|
4514
|
+
this.refresh();
|
|
4515
|
+
}
|
|
4516
|
+
svg;
|
|
4517
|
+
surfaces = [];
|
|
4518
|
+
frame;
|
|
4519
|
+
backdropGeneration = 0;
|
|
4520
|
+
recapture;
|
|
4521
|
+
view;
|
|
4522
|
+
clock;
|
|
4523
|
+
unwatch;
|
|
4524
|
+
capture() {
|
|
4525
|
+
return capturePngs(this.svg, this.surfaces, this.clock.now());
|
|
4526
|
+
}
|
|
4527
|
+
setParameters(ownerId, parameters3) {
|
|
4528
|
+
return updateParameters(this.surfaces, ownerId, parameters3, this.clock.now());
|
|
4529
|
+
}
|
|
4530
|
+
setPaused(paused) {
|
|
4531
|
+
this.clock.setPaused(paused);
|
|
4532
|
+
}
|
|
4533
|
+
refresh() {
|
|
4534
|
+
const memory = rememberSurfaces(this.surfaces);
|
|
4535
|
+
this.cancelFrame();
|
|
4536
|
+
const kept = /* @__PURE__ */ new Map();
|
|
4537
|
+
for (const surface of this.surfaces) {
|
|
4538
|
+
if (refreshSurface(surface, this.svg)) {
|
|
4539
|
+
kept.set(surface.canvas, surface);
|
|
4199
4540
|
}
|
|
4200
4541
|
}
|
|
4201
|
-
|
|
4542
|
+
for (const surface of this.surfaces) {
|
|
4543
|
+
if (!kept.has(surface.canvas)) {
|
|
4544
|
+
releaseSurface(surface);
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
const generation = ++this.backdropGeneration;
|
|
4548
|
+
this.surfaces = createSurfaces(this.svg, memory, kept);
|
|
4549
|
+
updateReactiveLightFields(this.surfaces);
|
|
4550
|
+
this.captureBackdrops(generation);
|
|
4551
|
+
if (this.surfaces.length > 0) {
|
|
4552
|
+
this.startFrames();
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4555
|
+
destroy() {
|
|
4556
|
+
this.backdropGeneration += 1;
|
|
4557
|
+
this.unwatch();
|
|
4558
|
+
this.svg.removeEventListener("pointermove", this.track);
|
|
4559
|
+
this.svg.removeEventListener("pointerleave", this.leave);
|
|
4560
|
+
if (this.recapture !== void 0) {
|
|
4561
|
+
this.view?.clearTimeout(this.recapture);
|
|
4562
|
+
}
|
|
4563
|
+
this.stop();
|
|
4564
|
+
}
|
|
4565
|
+
draw = (milliseconds) => {
|
|
4566
|
+
if (!this.clock.paused()) {
|
|
4567
|
+
updateReactiveLightFields(this.surfaces);
|
|
4568
|
+
for (const surface of this.surfaces) {
|
|
4569
|
+
renderSurface(surface, milliseconds / 1e3 - this.clock.spent());
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
this.frame = this.view?.requestAnimationFrame(this.draw);
|
|
4202
4573
|
};
|
|
4203
|
-
|
|
4204
|
-
if (frame !== void 0) {
|
|
4205
|
-
view?.cancelAnimationFrame(frame);
|
|
4206
|
-
frame = void 0;
|
|
4574
|
+
cancelFrame() {
|
|
4575
|
+
if (this.frame !== void 0) {
|
|
4576
|
+
this.view?.cancelAnimationFrame(this.frame);
|
|
4577
|
+
this.frame = void 0;
|
|
4207
4578
|
}
|
|
4208
|
-
|
|
4579
|
+
}
|
|
4580
|
+
stop() {
|
|
4581
|
+
this.cancelFrame();
|
|
4582
|
+
for (const surface of this.surfaces) {
|
|
4209
4583
|
releaseSurface(surface);
|
|
4210
4584
|
}
|
|
4211
|
-
surfaces = [];
|
|
4212
|
-
}
|
|
4213
|
-
|
|
4214
|
-
for (const surface of surfaces) {
|
|
4585
|
+
this.surfaces = [];
|
|
4586
|
+
}
|
|
4587
|
+
captureBackdrops(generation) {
|
|
4588
|
+
for (const surface of this.surfaces) {
|
|
4215
4589
|
if (!surface.usesBackdrop) {
|
|
4216
4590
|
continue;
|
|
4217
4591
|
}
|
|
4218
|
-
void captureShaderBackdrop(svg, surface.owner).then((backdrop) => {
|
|
4219
|
-
if (backdrop && generation === backdropGeneration) {
|
|
4592
|
+
void captureShaderBackdrop(this.svg, surface.owner).then((backdrop) => {
|
|
4593
|
+
if (backdrop && generation === this.backdropGeneration) {
|
|
4220
4594
|
applyBackdrop(surface, backdrop);
|
|
4221
4595
|
}
|
|
4222
4596
|
});
|
|
4223
4597
|
}
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
if (!view?.requestAnimationFrame) {
|
|
4227
|
-
for (const surface of surfaces) {
|
|
4598
|
+
}
|
|
4599
|
+
startFrames() {
|
|
4600
|
+
if (!this.view?.requestAnimationFrame) {
|
|
4601
|
+
for (const surface of this.surfaces) {
|
|
4228
4602
|
renderSurface(surface, 0);
|
|
4229
4603
|
}
|
|
4230
4604
|
return;
|
|
4231
4605
|
}
|
|
4232
|
-
if (clock.paused()) {
|
|
4233
|
-
for (const surface of surfaces) {
|
|
4234
|
-
renderSurface(surface, clock.now());
|
|
4606
|
+
if (this.clock.paused()) {
|
|
4607
|
+
for (const surface of this.surfaces) {
|
|
4608
|
+
renderSurface(surface, this.clock.now());
|
|
4235
4609
|
}
|
|
4236
4610
|
}
|
|
4237
|
-
frame = view.requestAnimationFrame(draw);
|
|
4238
|
-
}
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
const ownerId = surface.owner.getAttribute("data-sf-id");
|
|
4243
|
-
return ownerId ? [
|
|
4244
|
-
[
|
|
4245
|
-
ownerId,
|
|
4246
|
-
{
|
|
4247
|
-
smoothed: new Map(surface.smoothed),
|
|
4248
|
-
reactiveLight: surface.reactiveLight,
|
|
4249
|
-
pointer: surface.pointer,
|
|
4250
|
-
hover: surface.hover,
|
|
4251
|
-
hovering: surface.hovering,
|
|
4252
|
-
trail: surface.trail
|
|
4253
|
-
}
|
|
4254
|
-
]
|
|
4255
|
-
] : [];
|
|
4256
|
-
})
|
|
4257
|
-
);
|
|
4258
|
-
stop();
|
|
4259
|
-
const generation = ++backdropGeneration;
|
|
4260
|
-
surfaces = [...svg.querySelectorAll("canvas[data-sf-shader-canvas]")].flatMap((canvas) => {
|
|
4261
|
-
const surface = createSurface(canvas);
|
|
4262
|
-
const ownerId = surface?.owner.getAttribute("data-sf-id");
|
|
4263
|
-
const previous = ownerId ? previousState.get(ownerId) : void 0;
|
|
4264
|
-
if (surface && previous) {
|
|
4265
|
-
surface.smoothed = previous.smoothed;
|
|
4266
|
-
surface.reactiveLight = previous.reactiveLight;
|
|
4267
|
-
surface.pointer = previous.pointer;
|
|
4268
|
-
surface.hover = previous.hover;
|
|
4269
|
-
surface.hovering = previous.hovering;
|
|
4270
|
-
surface.trail = previous.trail;
|
|
4271
|
-
}
|
|
4272
|
-
return surface ? [surface] : [];
|
|
4273
|
-
});
|
|
4274
|
-
updateReactiveLightFields(surfaces);
|
|
4275
|
-
captureBackdrops(generation);
|
|
4276
|
-
if (surfaces.length > 0) {
|
|
4277
|
-
startFrames();
|
|
4278
|
-
}
|
|
4279
|
-
};
|
|
4280
|
-
const scheduleRecapture = () => {
|
|
4281
|
-
if (recapture !== void 0) {
|
|
4282
|
-
view?.clearTimeout(recapture);
|
|
4611
|
+
this.frame = this.view.requestAnimationFrame(this.draw);
|
|
4612
|
+
}
|
|
4613
|
+
scheduleRecapture = () => {
|
|
4614
|
+
if (this.recapture !== void 0) {
|
|
4615
|
+
this.view?.clearTimeout(this.recapture);
|
|
4283
4616
|
}
|
|
4284
|
-
recapture = view?.setTimeout(() => {
|
|
4285
|
-
recapture = void 0;
|
|
4286
|
-
captureBackdrops(backdropGeneration);
|
|
4617
|
+
this.recapture = this.view?.setTimeout(() => {
|
|
4618
|
+
this.recapture = void 0;
|
|
4619
|
+
this.captureBackdrops(this.backdropGeneration);
|
|
4287
4620
|
}, RECAPTURE_DELAY_MS);
|
|
4288
4621
|
};
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
for (const surface of surfaces) {
|
|
4292
|
-
|
|
4293
|
-
const inside = box.width > 0 && box.height > 0 && event.clientX >= box.left && event.clientX <= box.right && event.clientY >= box.top && event.clientY <= box.bottom;
|
|
4294
|
-
surface.hovering = inside;
|
|
4295
|
-
if (inside) {
|
|
4296
|
-
surface.pointer = { x: (event.clientX - box.left) / box.width, y: 1 - (event.clientY - box.top) / box.height };
|
|
4297
|
-
const now = clock.now();
|
|
4298
|
-
const last = surface.trail[surface.trail.length - 1];
|
|
4299
|
-
if (!last || now - last.at >= TRAIL_SPACING) {
|
|
4300
|
-
surface.trail.push({ ...surface.pointer, at: now });
|
|
4301
|
-
if (surface.trail.length > TRAIL_LENGTH2) {
|
|
4302
|
-
surface.trail.shift();
|
|
4303
|
-
}
|
|
4304
|
-
}
|
|
4305
|
-
}
|
|
4622
|
+
track = (event) => {
|
|
4623
|
+
const now = this.clock.now();
|
|
4624
|
+
for (const surface of this.surfaces) {
|
|
4625
|
+
followPointer(surface, event, now);
|
|
4306
4626
|
}
|
|
4307
4627
|
};
|
|
4308
|
-
|
|
4309
|
-
for (const surface of surfaces) {
|
|
4628
|
+
leave = () => {
|
|
4629
|
+
for (const surface of this.surfaces) {
|
|
4310
4630
|
surface.hovering = false;
|
|
4311
4631
|
}
|
|
4312
4632
|
};
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
const destroy = () => {
|
|
4317
|
-
backdropGeneration += 1;
|
|
4318
|
-
unwatch();
|
|
4319
|
-
svg.removeEventListener("pointermove", track);
|
|
4320
|
-
svg.removeEventListener("pointerleave", leave);
|
|
4321
|
-
if (recapture !== void 0) {
|
|
4322
|
-
view?.clearTimeout(recapture);
|
|
4323
|
-
}
|
|
4324
|
-
stop();
|
|
4325
|
-
};
|
|
4326
|
-
return {
|
|
4327
|
-
capture: () => capturePngs(svg, surfaces, clock.now()),
|
|
4328
|
-
setParameters: (ownerId, parameters3) => updateParameters(surfaces, ownerId, parameters3, clock.now()),
|
|
4329
|
-
setPaused: clock.setPaused,
|
|
4330
|
-
refresh,
|
|
4331
|
-
destroy
|
|
4332
|
-
};
|
|
4633
|
+
};
|
|
4634
|
+
function mountShaderSurfaces(svg) {
|
|
4635
|
+
return new ShaderSurfaces(svg);
|
|
4333
4636
|
}
|
|
4334
4637
|
|
|
4335
4638
|
// src/runtime/viewer/source.ts
|
|
@@ -4717,5 +5020,5 @@ function createViewer(options) {
|
|
|
4717
5020
|
}
|
|
4718
5021
|
|
|
4719
5022
|
export { SHADER_DEFAULTS, connectInteraction, createViewer, registerShaderProgram, shaderProgram };
|
|
4720
|
-
//# sourceMappingURL=chunk-
|
|
4721
|
-
//# sourceMappingURL=chunk-
|
|
5023
|
+
//# sourceMappingURL=chunk-RQYZNW2I.js.map
|
|
5024
|
+
//# sourceMappingURL=chunk-RQYZNW2I.js.map
|