Repository navigation
Expand file tree
/
Copy patheffects.html
More file actions
3678 lines (3542 loc) · 271 KB
/
Copy patheffects.html
File metadata and controls
3678 lines (3542 loc) · 271 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LatteX — \lx fx effect runtime</title>
<style>
:root {
color-scheme: light dark;
--bg:#eceef1; --bg-2:#e3e6ea; --panel:#ffffff; --ink:#171a1f;
--muted:#5b6570; --faint:#8a939d; --line:#d8dce1;
--accent:#b9761b; --accent-2:#d68a2a; --chip:#f1f3f5; --chip-line:#e0e4e8;
--shadow: 0 1px 2px rgba(20,24,30,.04), 0 8px 30px rgba(20,24,30,.06);
}
@media (prefers-color-scheme: dark) {
:root {
--bg:#0e1116; --bg-2:#0a0d11; --panel:#161a20; --ink:#e9ecf1;
--muted:#97a1ad; --faint:#6b7480; --line:#262c34;
--accent:#e6a24c; --accent-2:#f0b96b; --chip:#1b2027; --chip-line:#2a313a;
--shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 34px rgba(0,0,0,.45);
}
}
:root[data-theme="light"] {
color-scheme: light;
--bg:#eceef1; --bg-2:#e3e6ea; --panel:#ffffff; --ink:#171a1f;
--muted:#5b6570; --faint:#8a939d; --line:#d8dce1;
--accent:#b9761b; --accent-2:#d68a2a; --chip:#f1f3f5; --chip-line:#e0e4e8;
--shadow: 0 1px 2px rgba(20,24,30,.04), 0 8px 30px rgba(20,24,30,.06);
}
:root[data-theme="dark"] {
color-scheme: dark;
--bg:#0e1116; --bg-2:#0a0d11; --panel:#161a20; --ink:#e9ecf1;
--muted:#97a1ad; --faint:#6b7480; --line:#262c34;
--accent:#e6a24c; --accent-2:#f0b96b; --chip:#1b2027; --chip-line:#2a313a;
--shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 34px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
margin: 0;
background: radial-gradient(1200px 620px at 50% -8%, var(--bg) 0%, var(--bg-2) 62%, var(--bg-2) 100%);
color: var(--ink);
font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
line-height: 1.55; -webkit-font-smoothing: antialiased;
}
main { max-width: 1080px; margin: 0 auto; padding: 0 1.5rem 6rem; overflow-x: hidden; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
/* Rendered glyph SVGs fill with currentColor, so they inherit the
container's theme-aware ink — dark ink in light mode, light in dark. */
.render { display: flex; align-items: center; justify-content: center; width: 100%; color: var(--ink); }
.render svg { display: block; width: auto; height: auto; max-width: 100%; max-height: 96px; }
/* ---- Hero ---- */
.hero { text-align: center; padding: 4.5rem 0 2.5rem; }
.eyebrow {
font-family: ui-monospace, monospace; font-size: .72rem; letter-spacing: .24em;
text-transform: uppercase; color: var(--accent); margin: 0 0 1.2rem;
}
.wordmark {
font-size: clamp(2rem, 6vw, 3.2rem); font-weight: 800; letter-spacing: -.03em;
line-height: 1; margin: 0; color: var(--ink);
}
.wordmark .x {
background: linear-gradient(160deg, var(--accent-2), var(--accent));
-webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { max-width: 60ch; margin: 1.1rem auto 0; color: var(--muted); font-size: 1rem; }
.tagline code {
font-size: .86em; color: var(--ink); background: var(--chip);
border: 1px solid var(--chip-line); border-radius: 5px; padding: .04em .3em;
}
/* ---- Grid of specimen cards ---- */
.band { margin-top: 2.5rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
margin: 0; display: flex; flex-direction: column; gap: 1.25rem;
background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
padding: 2rem 1.4rem 1.2rem; box-shadow: var(--shadow);
transition: border-color .16s ease;
}
.card:hover { border-color: var(--accent); }
/* overflow visible so a boom scale-burst / glow drop-shadow isn't clipped. */
.card .render { flex: 1; min-height: 110px; overflow: visible; }
.card figcaption { display: flex; flex-direction: column; gap: .55rem; align-items: flex-start; }
.card .cap { font-size: .86rem; font-weight: 600; color: var(--ink); }
.card .src {
font-size: .72rem; color: var(--muted); background: var(--chip);
border: 1px solid var(--chip-line); border-radius: 6px; padding: .28rem .5rem;
max-width: 100%; overflow-x: auto; white-space: nowrap;
}
.card .hint {
font-family: ui-monospace, monospace; font-size: .62rem; letter-spacing: .1em;
text-transform: uppercase; color: var(--accent); font-weight: 600;
}
/* ---- Footer ---- */
.foot { margin-top: 4rem; padding-top: 2.5rem; border-top: 1px solid var(--line); text-align: center; }
.foot-mark { font-weight: 800; font-size: 1.25rem; letter-spacing: -.03em; margin: 0 0 1rem; }
.foot-mark .x {
background: linear-gradient(160deg, var(--accent-2), var(--accent));
-webkit-background-clip: text; background-clip: text; color: transparent;
}
.foot nav { display: flex; flex-wrap: wrap; gap: 1.5rem; justify-content: center; }
.foot nav a { font-size: .92rem; }
.foot-fine {
margin: 1.6rem 0 0; color: var(--faint); font-size: .74rem;
font-family: ui-monospace, monospace; letter-spacing: .04em;
}
/* =====================================================================
/* LatteX fx layer — OPTIONAL styles for the \lx effects (keyframes + effect classes).
Pair with lattex-fx.js. The math renders without either; include both only to enable
effects. Keyed off the container's data-lx-fx-*; the inner <svg> is never touched
(affordance-free). Transforms need an inline-block box. This is the fx layer ONLY — no
page chrome — so it drops into any page without leaking generic styles. */
.lx-math { display: inline-block; transform-origin: center center; }
/* enter=fade / enter=inkdrop / enter=constellation start hidden so the JS reveal has
somewhere to come from (no flash-of-visible before the runtime wires). The hides are
keyed on html.lx-fx — a root marker the RUNTIME stamps as its first act — so a page
that loads this CSS but never runs the JS (blocked/failed/disabled) shows the math
plainly with effects inert, instead of hiding it forever (the CSS-only-invisibility
hole; every pre-hide added for a future enter effect MUST use this prefix). */
html.lx-fx .lx-math[data-lx-fx-enter="fade"] { opacity: 0; }
html.lx-fx .lx-math[data-lx-fx-enter="inkdrop"] { opacity: 0; }
html.lx-fx .lx-math[data-lx-fx-enter="constellation"] { opacity: 0; }
/* fx.*=unfold payload: the pre-rendered expanded <svg> rides a `.lx-fx-expanded`
wrapper span and starts HIDDEN. Unlike the enter-hides above this is NOT keyed on
html.lx-fx: the safe degraded state is "show the collapsed sum only", so the payload
must stay hidden even if the JS never runs (a page with no runtime shows the plain
sum, effect inert — never both states at once). The runtime toggles it on click. */
.lx-math > .lx-fx-expanded { display: none; }
/* fx.*=substitute payload: the pre-rendered substituted <svg> rides a
`.lx-fx-substituted` wrapper span, on exactly the same terms as the unfold payload
above — hidden by default, NOT keyed on html.lx-fx, so a page with no runtime shows
the variable form only and the effect is simply inert. A dedicated class rather than
a shared `.lx-fx-payload`: sharing one would mean refactoring unfold's just-landed
CSS/JS/test surface, and perturbing a landed lane for tidiness is a poor trade. */
.lx-math > .lx-fx-substituted { display: none; }
@keyframes lx-boom {
0% { transform: scale(1); }
30% { transform: scale(1.45); }
60% { transform: scale(.92); }
100% { transform: scale(1); }
}
@keyframes lx-pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.14); }
}
@keyframes lx-fade {
0% { opacity: 0; }
100% { opacity: 1; }
}
/* glow halo colour = --lx-glow-color when the author set fx.glow-color, else currentColor. */
@keyframes lx-glow {
0%, 100% { filter: drop-shadow(0 0 0 var(--lx-glow-color, currentColor)); }
50% { filter: drop-shadow(0 0 12px var(--lx-glow-color, currentColor)); }
}
/* glitch: datamosh — the red/cyan channels rip apart, slice bands drop out and shear
sideways with static jitter, then everything snaps back pixel-perfect. Single-element
(filter + transform + clip-path on the container); the inner <svg> is never touched. */
@keyframes lx-glitch {
0% { transform: none; filter: none; }
8% { transform: translate(-3px, 1px) skewX(-4deg);
filter: drop-shadow(3px 0 rgba(255, 0, 64, .9)) drop-shadow(-3px 0 rgba(0, 229, 255, .9)); }
16% { transform: translate(2px, -1px); clip-path: inset(12% 0 55% 0);
filter: drop-shadow(-4px 0 rgba(255, 0, 64, .9)) drop-shadow(4px 0 rgba(0, 229, 255, .9)); }
24% { transform: translate(-4px, 2px) skewX(6deg); clip-path: inset(58% 0 8% 0); }
32% { transform: translate(3px, 0); clip-path: inset(30% 0 38% 0);
filter: drop-shadow(2px 0 rgba(255, 0, 64, .9)) drop-shadow(-2px 0 rgba(0, 229, 255, .9)); }
40% { transform: translate(-2px, -2px) skewX(-8deg); }
55% { transform: translate(1px, 1px);
filter: drop-shadow(-2px 0 rgba(255, 0, 64, .7)) drop-shadow(2px 0 rgba(0, 229, 255, .7)); }
70% { transform: none; filter: none; }
74% { transform: translate(-3px, 0) skewX(5deg);
filter: drop-shadow(4px 0 rgba(255, 0, 64, .8)) drop-shadow(-4px 0 rgba(0, 229, 255, .8)); }
78% { transform: none; filter: none; }
100% { transform: none; filter: none; }
}
@media (prefers-reduced-motion: reduce) {
/* No motion; held-visible states stay legible. Same html.lx-fx-prefixed shape as
the hides (equal specificity + later in the cascade = the reset wins). */
.lx-math { animation: none !important; }
html.lx-fx .lx-math[data-lx-fx-enter="fade"] { opacity: 1; }
html.lx-fx .lx-math[data-lx-fx-enter="inkdrop"] { opacity: 1; }
html.lx-fx .lx-math[data-lx-fx-enter="constellation"] { opacity: 1; }
}
/* blueprint: the container becomes an engineer's drafting field — a deep cyan-blue ground
under a faint white grid. The JS stroke-draws the glyphs in white over it. */
.lx-math.lx-blueprint {
color: #eaf3ff;
padding: .5rem .7rem;
border-radius: 6px;
box-shadow: inset 0 0 0 1px rgba(226, 238, 255, .18);
background:
repeating-linear-gradient(0deg, rgba(226,238,255,.10) 0 1px, transparent 1px 14px),
repeating-linear-gradient(90deg, rgba(226,238,255,.10) 0 1px, transparent 1px 14px),
linear-gradient(180deg, #0b3a66, #08294a);
}
/* hologram: scrolls the scanline body-overlay's gradient (3px period → 6px loop). */
@keyframes lx-holo-scan {
0% { background-position: 0 0; }
100% { background-position: 0 6px; }
}
</style>
<script>
/* LatteX fx runtime — OPTIONAL. Reads data-lx-fx-* on .lx-math wrappers and animates the
\lx effects. Self-contained, no deps, CSP-friendly (one external script). The math renders
without this; include it (+ lattex-fx.css) only if you want the effects. */
(function () {
// FIRST ACT: stamp the root marker the stylesheet's enter-hide rules key on
// (html.lx-fx ... { opacity: 0 }). CSS loaded without this runtime running
// then hides nothing — the math shows plainly with effects inert, instead of
// the CSS-only-invisibility hole where enter-effect equations vanish forever.
document.documentElement.classList.add('lx-fx');
// CSS-keyframe effect vocabulary — mirrors the Effect enum's keyframe half
// (boom|pulse|fade|glow|none). 'lightning' and 'storm' are special-cased
// below: they are page-side body overlays, NOT keyframes on the element.
var VOCAB = { boom: 1, pulse: 1, fade: 1, glow: 1, glitch: 1, none: 1 };
var reduced = window.matchMedia
&& window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Resolve the strike/halo colour: the author's fx.glow-color if set (and not
// the literal 'currentColor', which canvas can't resolve), else the element's
// computed ink colour so it matches the on-page glyphs.
function resolveColor(el) {
var c = (el.style.getPropertyValue('--lx-glow-color') || '').trim();
if (c && c.toLowerCase() !== 'currentcolor') { return c; }
var ink = getComputedStyle(el).color;
return ink || '#e6a24c';
}
// ---- placement-composing path transforms ---------------------------------
// Every glyph <path> carries its PLACEMENT as an SVG transform ATTRIBUTE
// ('translate(tx ty) scale(s -s)': font design units → user units). The CSS
// transform PROPERTY replaces that attribute wholesale, so a per-path effect
// that sets style.transform naively strips the placement and re-renders the
// glyph as a font-unit-sized blob (Charles's smoke, 2026-07-06). Per-path
// effects therefore express motion as a USER-SPACE delta and COMPOSE it in
// front of the placement via setPathDelta; pivotScaleDelta builds a scale
// about the glyph's own user-space centre (replacing the transform-box
// pattern, which suffers the same stomp). clearPathDelta restores the
// attribute's rule. Paths without a placement attribute pass deltas through.
function placement(p) {
if (p.__lxPlace === undefined) {
var m = /translate\(\s*([-\d.eE]+)[\s,]+([-\d.eE]+)\s*\)\s*scale\(\s*([-\d.eE]+)(?:[\s,]+([-\d.eE]+))?\s*\)/
.exec(p.getAttribute('transform') || '');
p.__lxPlace = m ? {
css: 'translate(' + m[1] + 'px,' + m[2] + 'px) scale(' + m[3] + ',' + (m[4] || m[3]) + ')',
tx: parseFloat(m[1]), ty: parseFloat(m[2]),
sx: parseFloat(m[3]), sy: parseFloat(m[4] || m[3])
} : null;
}
return p.__lxPlace;
}
function setPathDelta(p, deltaCss) {
// The SVG transform ATTRIBUTE applies about the user-space origin (0,0);
// the CSS transform PROPERTY applies about transform-origin, which for SVG
// defaults to 50% 50% OF THE VIEWBOX — replaying the placement through CSS
// without pinning the origin scales the equation about its centre and
// scrunches every glyph into a bar (Charles's smoke, round 2). Pin it.
p.style.transformOrigin = '0px 0px';
var place = placement(p);
p.style.transform = place ? deltaCss + ' ' + place.css : deltaCss;
}
function clearPathDelta(p) {
p.style.transform = '';
p.style.transformOrigin = '';
}
/** The glyph's centre in USER space (local bbox pushed through its placement). */
function userCentre(p) {
var b;
try { b = p.getBBox(); } catch (e) { return null; }
var cx = b.x + b.width / 2, cy = b.y + b.height / 2;
var place = placement(p);
if (!place) { return { x: cx, y: cy }; }
return { x: place.tx + place.sx * cx, y: place.ty + place.sy * cy };
}
/** A scale-about-the-glyph's-own-centre delta (user space). */
function pivotScaleDelta(p, k) {
var c = userCentre(p);
if (!c) { return 'scale(' + k + ')'; }
return 'translate(' + c.x.toFixed(2) + 'px,' + c.y.toFixed(2) + 'px) scale(' + k
+ ') translate(' + (-c.x).toFixed(2) + 'px,' + (-c.y).toFixed(2) + 'px)';
}
// ---- scroll-killable shows ------------------------------------------------
// Overlay effects are FIXED-position bodies anchored to the equation's
// trigger-time rect — scroll the page and the show plays over the wrong
// content (bolts strike a phantom, shards float over prose, a spotlight
// darkens nothing: Charles's smoke sweep, 2026-07-06). scrollKillable wraps
// an effect's teardown into an idempotent `die()` that ALSO fires on the
// first scroll: the normal end and the scroll-abort share one exit, pending
// frames/timers check die.dead() and park. Passive + capture so it hears
// scrolls in any container and never blocks the scroll itself.
function scrollKillable(teardown) {
var dead = false;
// Baseline the viewport at arming: browsers fire spurious/restoration
// 'scroll' events at page load (killing fx.enter shows at birth — Charles:
// "sparkler seems to not always load"), so only a REAL movement of the
// viewport (>4px from the position the show started at) ends the show.
var x0 = window.pageXOffset, y0 = window.pageYOffset;
function onScroll() {
if (Math.abs(window.pageXOffset - x0) < 4
&& Math.abs(window.pageYOffset - y0) < 4) { return; }
die();
}
function die() {
if (dead) { return; }
dead = true;
window.removeEventListener('scroll', onScroll, true);
teardown();
}
die.dead = function () { return dead; };
window.addEventListener('scroll', onScroll, { capture: true, passive: true });
return die;
}
// A jagged polyline from (x0,y0) to (x1,y1): interior points are pushed off
// the straight line by a random perpendicular jitter, so every strike differs.
function jagged(x0, y0, x1, y1, segs, jitter) {
var dx = x1 - x0, dy = y1 - y0;
var len = Math.sqrt(dx * dx + dy * dy) || 1;
var nx = -dy / len, ny = dx / len; // unit normal
var pts = [];
for (var i = 0; i <= segs; i++) {
var t = i / segs;
var x = x0 + dx * t, y = y0 + dy * t;
if (i > 0 && i < segs) {
var off = (Math.random() * 2 - 1) * jitter;
x += nx * off; y += ny * off;
}
pts.push([x, y]);
}
return pts;
}
function stroke(ctx, pts, upto) {
var n = Math.max(2, Math.min(pts.length, upto || pts.length));
if (n < 2) { return; }
ctx.beginPath();
ctx.moveTo(pts[0][0], pts[0][1]);
for (var i = 1; i < n; i++) { ctx.lineTo(pts[i][0], pts[i][1]); }
ctx.stroke();
}
// The confluence: two rivers of lightning arc IN from the left- and right-mid
// viewport edges and converge on the element's centre, flash, then fade. A
// lazily-created, pointer-events-none body overlay — never inside the <svg>.
function lightning(el) {
var r = el.getBoundingClientRect();
var cx = r.left + r.width / 2, cy = r.top + r.height / 2;
var vw = window.innerWidth, vh = window.innerHeight;
var color = resolveColor(el);
var sources = [[0, vh / 2], [vw, vh / 2]]; // left-mid + right-mid edges
var canvas = document.createElement('canvas');
var dpr = window.devicePixelRatio || 1;
canvas.width = Math.round(vw * dpr);
canvas.height = Math.round(vh * dpr);
canvas.style.cssText = 'position:fixed;left:0;top:0;width:100vw;height:100vh;'
+ 'pointer-events:none;z-index:2147483647;';
document.body.appendChild(canvas);
var ctx = canvas.getContext('2d');
ctx.scale(dpr, dpr);
// Reduced motion: one faint static arc from each side, no flicker, no flash.
if (reduced) {
ctx.globalAlpha = 0.45;
ctx.strokeStyle = color;
ctx.lineWidth = 2;
sources.forEach(function (s) { stroke(ctx, jagged(s[0], s[1], cx, cy, 8, 6)); });
setTimeout(function () { canvas.remove(); }, 400);
return;
}
var DRAW = 180, HOLD = 90, FADE = 350;
function drawBolts(progress) {
ctx.clearRect(0, 0, vw, vh);
ctx.strokeStyle = color;
ctx.shadowColor = color;
ctx.shadowBlur = 12;
sources.forEach(function (s) {
for (var k = 0; k < 2; k++) { // 2 forked bolts per side
var pts = jagged(s[0], s[1], cx, cy, 12, 18 + k * 10);
ctx.lineWidth = 2 + k;
ctx.globalAlpha = 0.9;
stroke(ctx, pts, Math.floor(pts.length * progress));
}
});
if (progress > 0.85) { // bright convergence flash blob
var rad = 10 + Math.random() * 6;
var g = ctx.createRadialGradient(cx, cy, 0, cx, cy, rad);
g.addColorStop(0, color);
g.addColorStop(1, 'rgba(0,0,0,0)');
ctx.globalAlpha = 1;
ctx.fillStyle = g;
ctx.beginPath(); ctx.arc(cx, cy, rad, 0, Math.PI * 2); ctx.fill();
}
}
// The bolts converge on where the equation WAS at trigger time (fixed
// overlay) — if the page scrolls the anchor is gone, so end the show
// immediately rather than strike a phantom (Charles, 2026-07-06).
var die = scrollKillable(function () { canvas.remove(); });
var t0 = performance.now();
function frame(now) {
if (die.dead()) { return; }
var e = now - t0;
if (e < DRAW) { drawBolts(e / DRAW); requestAnimationFrame(frame); } // draw in + flicker
else if (e < DRAW + HOLD) { drawBolts(1); requestAnimationFrame(frame); } // hold, still re-jagging
else if (e < DRAW + HOLD + FADE) { // fade the whole overlay
canvas.style.opacity = String(1 - (e - DRAW - HOLD) / FADE);
requestAnimationFrame(frame);
} else { die(); }
}
requestAnimationFrame(frame);
}
// NIGHT LIGHTNING. Reuses the bolt code, but first drops the whole scene to
// near-black behind a radial "spotlight" that stays transparent over the
// target (so the equation stays lit), converges bolts on the centre, and on
// EACH strike FLASHES the dark backdrop bright — like lightning at night —
// then restores the page. The darken backdrop, the white flash veil and the
// bolt canvas are three SEPARATE pointer-events-none body overlays; nothing
// is ever written into the element's <svg> (the containment contract holds).
function storm(el) {
var r = el.getBoundingClientRect();
var cx = r.left + r.width / 2, cy = r.top + r.height / 2;
var vw = window.innerWidth, vh = window.innerHeight;
var color = resolveColor(el);
var sources = [[0, vh / 2], [vw, vh / 2], [cx, 0]]; // left, right, top edges
// Spotlight radius: clears the element plus a soft margin.
var spot = Math.max(r.width, r.height) / 2 + 60;
// (1) DARKEN — a fixed radial backdrop: transparent over the element,
// near-black at the edges. A CSS var drives the edge darkness so a strike
// can momentarily lift it. Fades in fast (~150ms).
var backdrop = document.createElement('div');
backdrop.style.cssText = 'position:fixed;inset:0;pointer-events:none;'
+ 'z-index:2147483645;opacity:0;transition:opacity 150ms ease;background:'
+ 'radial-gradient(circle ' + spot + 'px at ' + cx + 'px ' + cy + 'px,'
+ ' rgba(2,4,9,0) 0%, rgba(2,4,9,0) 58%,'
+ ' rgba(2,4,9,var(--lx-dark,0.94)) 100%);';
document.body.appendChild(backdrop);
// (2) FLASH VEIL — a whitish layer brightest in the dark surround (a
// transparent hole over the element), pulsed on each strike so the night
// "lights up" without washing out the spotlit equation.
var flash = document.createElement('div');
flash.setAttribute('data-lx-fx-overlay', 'lightning');
flash.style.cssText = 'position:fixed;inset:0;pointer-events:none;'
+ 'z-index:2147483646;opacity:0;transition:opacity 70ms ease;background:'
+ 'radial-gradient(circle ' + (spot + 40) + 'px at ' + cx + 'px ' + cy + 'px,'
+ ' rgba(226,238,255,0) 0%, rgba(226,238,255,0) 52%,'
+ ' rgba(226,238,255,0.6) 100%);';
document.body.appendChild(flash);
// The target GLOWS HOTTER as bolts charge into it: a heat level 0..1 maps
// to a growing coloured halo + a white-hot core, warming toward white as
// it peaks. Biased to the author's glow-color if set, else a heated amber.
var authored = (el.style.getPropertyValue('--lx-glow-color') || '').trim();
var heatTint = (authored && authored.toLowerCase() !== 'currentcolor')
? color : '#ffb24d';
// Bolts read as LIGHT, not dark ink — a glowing electric strike against the
// night. Electric blue-white by default, or the author's glow-color if set;
// the halo (shadow) glows too so they blaze rather than draw as black cracks.
var boltColor = (authored && authored.toLowerCase() !== 'currentcolor')
? authored : '#eaf3ff';
var boltGlow = (authored && authored.toLowerCase() !== 'currentcolor')
? authored : '#8fc2ff';
function heatFilter(level) {
var outer = 6 + level * 22; // coloured halo: 6 → 28px
var warm = 4 + level * 16; // warm/amber mid layer
var core = level * 12; // white-hot core (0 at rest)
return 'drop-shadow(0 0 ' + outer + 'px ' + color + ')'
+ ' drop-shadow(0 0 ' + warm + 'px ' + heatTint + ')'
+ ' drop-shadow(0 0 ' + core + 'px rgba(255,255,255,'
+ (0.35 + level * 0.6).toFixed(3) + '))';
}
// Smooth the ramp between strike bumps (restored on cleanup).
var filter0 = el.style.filter, trans0 = el.style.transition;
el.style.transition = 'filter 170ms ease';
el.style.filter = heatFilter(0.15); // subtle base glow while the sky darkens
// (3) The bolt canvas, on top of both overlays.
var canvas = document.createElement('canvas');
var dpr = window.devicePixelRatio || 1;
canvas.width = Math.round(vw * dpr);
canvas.height = Math.round(vh * dpr);
canvas.style.cssText = 'position:fixed;left:0;top:0;width:100vw;height:100vh;'
+ 'pointer-events:none;z-index:2147483647;';
document.body.appendChild(canvas);
var sctx = canvas.getContext('2d');
sctx.scale(dpr, dpr);
// Teardown: reached by the normal fade-out, OR immediately on scroll — the
// darkness + bolts are fixed overlays anchored to where the equation WAS,
// so a scrolled page must get its lights back at once (Charles,
// 2026-07-06). `dead` parks every pending strike frame/timer.
var dead = false;
var cleanup = scrollKillable(function () {
dead = true;
backdrop.remove(); flash.remove(); canvas.remove();
el.style.filter = filter0; el.style.transition = trans0;
});
// Reduced motion: no darkening flurry, no strobing, no heat ramp. A brief
// soft dim + one faint static arc + a soft STEADY glow, then restore.
if (reduced) {
backdrop.style.setProperty('--lx-dark', '0.5');
el.style.filter = heatFilter(0.3); // gentle steady glow, no pulsing
requestAnimationFrame(function () { backdrop.style.opacity = '1'; });
sctx.globalAlpha = 0.55; sctx.strokeStyle = boltColor;
sctx.shadowColor = boltGlow; sctx.shadowBlur = 10; sctx.lineWidth = 2;
stroke(sctx, jagged(0, vh / 2, cx, cy, 8, 6));
setTimeout(function () { backdrop.style.opacity = '0'; }, 520);
setTimeout(cleanup, 950);
return;
}
requestAnimationFrame(function () { backdrop.style.opacity = '1'; });
// One strike: quickly draw converging jagged bolts to the centre, then at
// convergence FLASH the backdrop bright (~70ms) — drop its darkness, pulse
// the white veil, AND heat the equation hotter (level) — before settling
// back to dark while the equation holds its new, hotter glow.
function strike(level, done) {
var DRAW = 130, t0 = performance.now();
function frame(now) {
if (dead) { return; } // scrolled away mid-strike: overlays already gone
var p = Math.min(1, (now - t0) / DRAW);
sctx.clearRect(0, 0, vw, vh);
sctx.strokeStyle = boltColor; sctx.shadowColor = boltGlow; sctx.shadowBlur = 16;
sources.forEach(function (s) {
for (var k = 0; k < 2; k++) { // 2 forked bolts per source
var pts = jagged(s[0], s[1], cx, cy, 12, 18 + k * 10);
sctx.lineWidth = 2 + k; sctx.globalAlpha = 0.9;
stroke(sctx, pts, Math.floor(pts.length * p));
}
});
if (p < 1) { requestAnimationFrame(frame); return; }
backdrop.style.setProperty('--lx-dark', '0.55'); // night lights up
flash.style.opacity = '1';
el.style.filter = heatFilter(level); // charge pulses the math hotter
setTimeout(function () {
if (dead) { return; } // never re-heat the equation after teardown
backdrop.style.setProperty('--lx-dark', '0.94'); // settle back to dark
flash.style.opacity = '0';
sctx.clearRect(0, 0, vw, vh);
done();
}, 70);
}
requestAnimationFrame(frame);
}
// ~3 strikes with a dark gap between; each strikes hotter than the last,
// peaking (white-hot) at the climax. Then fade the backdrop + canvas out
// (~400ms), COOL the equation back to normal, and restore cleanly.
var LEVELS = [0.45, 0.72, 1.0]; // subtle → hot → white-hot climax
var i = 0;
function next() {
if (dead) { return; }
if (i >= LEVELS.length) {
backdrop.style.transition = 'opacity 400ms ease';
canvas.style.transition = 'opacity 400ms ease';
el.style.transition = 'filter 400ms ease';
backdrop.style.opacity = '0'; canvas.style.opacity = '0';
el.style.filter = heatFilter(0); // cool back down as the storm fades
setTimeout(cleanup, 420);
return;
}
strike(LEVELS[i++], function () { setTimeout(next, 200); });
}
setTimeout(next, 170); // let the darken settle before the first strike
}
// The equation writes itself: ink each glyph <path> in stroke-by-stroke,
// staggered left-to-right, then settle to the filled glyph. Special-cased like
// lightning/storm — but this one toggles PRESENTATION attributes on the existing
// inner-<svg> paths (stroke / fill / stroke-dashoffset); it adds NO element to the
// SVG, so the containment contract is unchanged.
function handscribe(el) {
var svg = el.querySelector('svg');
if (!svg) { return; }
var paths = Array.prototype.slice.call(svg.querySelectorAll('path'));
if (!paths.length || reduced) { return; } // reduced motion: leave it static
paths.sort(function (a, b) {
try { return a.getBBox().x - b.getBBox().x; } catch (e) { return 0; }
});
var DRAW = 460, FILL = 260, STAGGER = 55;
paths.forEach(function (p, i) {
var len;
try { len = p.getTotalLength() || 100; } catch (e) { len = 100; }
p.style.stroke = 'currentColor';
p.style.strokeWidth = '1.5';
p.style.fill = 'transparent';
p.style.strokeDasharray = len;
p.style.strokeDashoffset = len;
setTimeout(function () {
p.style.transition = 'stroke-dashoffset ' + DRAW + 'ms ease, fill '
+ FILL + 'ms ease ' + Math.round(DRAW * 0.6) + 'ms';
p.style.strokeDashoffset = '0';
p.style.fill = 'currentColor';
setTimeout(function () { // settle to a pristine filled glyph
p.style.stroke = '';
p.style.strokeWidth = '';
p.style.strokeDasharray = '';
p.style.strokeDashoffset = '';
p.style.transition = '';
}, DRAW + FILL + 120);
}, i * STAGGER);
});
}
// HOLOGRAM. Flickers in as a cyan wireframe: scanlines, RGB-split jitter,
// parallax tilt, flicker dropouts, then a subtle idle loop. Tints/filters/
// transforms the container el and drives a pointer-events-none scanline body
// overlay; nothing reaches the inner <svg>.
function hologram(el) {
if (el._lxHolo) { return; }
el._lxHolo = true;
var authored = (el.style.getPropertyValue('--lx-glow-color') || '').trim();
var tint = (authored && authored.toLowerCase() !== 'currentcolor')
? authored : '#5fe8ff';
// Capture pristine styles BEFORE any mutation (Lattice: capturing after
// the tint meant teardown "restored" the hologram look, not the original).
var col0 = el.style.color, fil0 = el.style.filter,
tf0 = el.style.transform, trans0 = el.style.transition, op0 = el.style.opacity;
el.style.color = tint;
function aberr(px) {
return 'drop-shadow(' + px + 'px 0 0 rgba(255,44,120,.5))'
+ ' drop-shadow(' + (-px) + 'px 0 0 rgba(60,220,255,.55))'
+ ' drop-shadow(0 0 7px ' + tint + ')';
}
el.style.filter = aberr(1.2);
var scan = document.createElement('div');
scan.setAttribute('data-lx-fx-overlay', 'hologram');
scan.style.cssText = 'position:fixed;pointer-events:none;z-index:2147483646;'
+ 'mix-blend-mode:screen;background:repeating-linear-gradient(0deg,'
+ ' rgba(95,232,255,.14) 0px, rgba(95,232,255,.14) 1px,'
+ ' transparent 1px, transparent 3px);';
document.body.appendChild(scan);
el._lxHolo = scan;
function place() {
var r = el.getBoundingClientRect();
scan.style.left = r.left + 'px'; scan.style.top = r.top + 'px';
scan.style.width = r.width + 'px'; scan.style.height = r.height + 'px';
}
place();
window.addEventListener('resize', place);
// The idle loop runs indefinitely, so teardown is MANDATORY, not optional
// (the leak the review flagged HIGH: no clearInterval, listeners + overlay
// outlived the element forever). die() ends it on scroll and restores
// everything; the interval + resize listener + overlay all release.
// ALSO reachable off-scroll (plan 62fafe76): scrollKillable only observes real
// SCROLLING, so in a no-scroll SPA that removes the equation the interval would
// leak forever — the idle tick below self-checks el.isConnected, and an
// explicit LatteXFx.destroy(el) can end it deterministically, via __lxHoloDie.
var idle = 0;
var die = scrollKillable(function () {
if (idle) { clearInterval(idle); idle = 0; }
window.removeEventListener('resize', place);
scan.remove();
el._lxHolo = false;
el.__lxHoloDie = null;
el.style.color = col0; el.style.filter = fil0; el.style.transform = tf0;
el.style.transition = trans0; el.style.opacity = op0;
});
el.__lxHoloDie = die;
if (reduced) { return; }
scan.style.animation = 'lx-holo-scan 1.1s linear infinite';
el.style.transition = 'transform 1400ms ease-in-out, opacity 90ms linear';
var seq = ['0', '1', '.2', '1', '.5', '1'], j = 0;
(function boot() {
if (die.dead()) { return; }
if (j < seq.length) { el.style.opacity = seq[j++]; setTimeout(boot, 55); return; }
var dir = 1;
idle = setInterval(function () {
if (die.dead()) { clearInterval(idle); idle = 0; return; }
if (el.isConnected === false) { die(); return; } // detached: end perpetual work
place();
dir = -dir;
el.style.transform = 'perspective(440px) rotateY(' + (dir * 6) + 'deg)';
if (Math.random() < 0.5) {
el.style.filter = aberr(3 + Math.random() * 3);
setTimeout(function () { if (!die.dead()) { el.style.filter = aberr(1.2); } }, 90);
}
if (Math.random() < 0.28) {
el.style.opacity = '.4';
setTimeout(function () { if (!die.dead()) { el.style.opacity = '1'; } }, 70);
}
}, 900);
})();
}
// NEON SIGN. Buzzes to life: failed stuttering ignitions, then a steady hum —
// one glyph left flickering forever. Drives a drop-shadow bloom + opacity on the
// container and toggles opacity on ONE existing inner-<svg> path; no <svg> edits.
function neonsign(el) {
// Re-entry guard: neonsign was the ONLY JS effect without one, so every
// mouseenter (data-lx-fx-hover=neonsign) stacked a fresh perpetual flicker
// loop (review HIGH). Guard blocks re-entry; the loop stops when the flag
// clears (the element leaving the DOM is out of scope, but re-trigger no
// longer compounds, which was the actual observed leak).
if (el.__lxNeon) { return; }
el.__lxNeon = true;
var color = resolveColor(el);
function glow(on) {
var core = 2 + on * 1;
var near = 4 + on * 5;
var halo = 6 + on * 13;
return 'drop-shadow(0 0 ' + core + 'px rgba(255,255,255,'
+ (0.3 + on * 0.5).toFixed(3) + '))'
+ ' drop-shadow(0 0 ' + near + 'px rgba(255,255,255,'
+ (on * 0.35).toFixed(3) + '))'
+ ' drop-shadow(0 0 ' + halo + 'px ' + color + ')';
}
if (reduced) { el.style.filter = glow(1); return; }
el.style.transition = 'filter 40ms linear, opacity 40ms linear';
var seq = [
[0, 0.35, 1],
[70, 0, 0.25],
[150, 0.8, 1],
[210, 0, 0.25],
[340, 0.5, 1],
[430, 1, 1]
];
seq.forEach(function (s) {
setTimeout(function () {
el.style.opacity = String(s[2]);
el.style.filter = glow(s[1]);
}, s[0]);
});
var paths = el.querySelectorAll('svg path');
if (!paths.length) { el.__lxNeon = false; return; }
var broken = paths[Math.floor(paths.length / 2)];
broken.style.transition = 'opacity 60ms linear';
// The "one glyph flickers forever" idle loop is scroll-killable so it
// releases its timer + clears the guard on scroll-away (the loop no longer
// outlives the element unconditionally). ALSO off-scroll (plan 62fafe76):
// scrollKillable only observes real SCROLLING, so a no-scroll SPA that removes
// the equation would leak this perpetual timeout chain forever — flicker()
// self-checks el.isConnected each tick, and LatteXFx.destroy(el) can end it
// deterministically via __lxNeonDie.
var timer = 0;
var die = scrollKillable(function () {
if (timer) { clearTimeout(timer); timer = 0; }
broken.style.opacity = ''; broken.style.transition = '';
el.__lxNeon = false;
el.__lxNeonDie = null;
});
el.__lxNeonDie = die;
function flicker() {
if (die.dead()) { return; }
if (el.isConnected === false) { die(); return; } // detached: stop rescheduling
var dropout = Math.random() < 0.35;
broken.style.opacity = dropout
? (Math.random() < 0.5 ? '0.15' : '0.6') : '1';
var next = dropout ? 40 + Math.random() * 90 : 300 + Math.random() * 1500;
timer = setTimeout(flicker, next);
}
timer = setTimeout(flicker, 600);
}
// CRYSTALLIZE. A frost front sweeps across (a body-level frost pane, clip-swept),
// an icy blue-white tint fits over the glyphs (filter on el), then sparkle motes
// pop. Filter/clip on el + separate body overlays; no element into the inner <svg>.
function crystallize(el) {
var svg = el.querySelector('svg');
if (!svg) { return; }
var gleam = resolveColor(el);
var icy = 'brightness(1.14) saturate(0.6) sepia(0.18) hue-rotate(165deg)';
var trans0 = el.style.transition;
if (reduced) {
el.style.filter = icy + ' drop-shadow(0 0 4px ' + gleam + ')';
return;
}
var r = el.getBoundingClientRect();
var pane = document.createElement('div');
pane.setAttribute('data-lx-fx-overlay', 'crystallize');
pane.style.cssText = 'position:fixed;pointer-events:none;z-index:2147483646;'
+ 'left:' + r.left + 'px;top:' + r.top + 'px;width:' + r.width + 'px;'
+ 'height:' + r.height + 'px;opacity:0.85;mix-blend-mode:screen;'
+ 'clip-path:inset(0 100% 0 0);transition:clip-path 900ms ease;'
// Frost tint derives from gleam (the author's fx.glow-color, else the
// equation's own ink) — the old hardcoded ice-blue vanished on white
// backgrounds (Charles, 2026-07-06). color-mix keeps it translucent.
+ 'background:linear-gradient(115deg, color-mix(in srgb, ' + gleam + ' 45%, transparent) 0%,'
+ ' color-mix(in srgb, ' + gleam + ' 18%, transparent) 45%,'
+ ' color-mix(in srgb, ' + gleam + ' 38%, transparent) 100%),'
+ ' repeating-linear-gradient(60deg, color-mix(in srgb, ' + gleam + ' 14%, transparent) 0 6px,'
+ ' rgba(255,255,255,0) 6px 13px);';
document.body.appendChild(pane);
el.style.transition = 'filter 900ms ease';
el.style.filter = icy + ' blur(1.4px) drop-shadow(0 0 5px ' + gleam + ')';
requestAnimationFrame(function () {
pane.style.clipPath = 'inset(0 0 0 0)';
el.style.filter = icy + ' blur(0px) drop-shadow(0 0 6px ' + gleam + ')';
});
var motes = [];
for (var i = 0; i < 7; i++) {
(function (i) {
var s = document.createElement('div');
var sz = 3 + Math.random() * 3;
var px = r.left + Math.random() * r.width;
var py = r.top + Math.random() * r.height;
s.style.cssText = 'position:fixed;pointer-events:none;z-index:2147483647;'
+ 'left:' + px + 'px;top:' + py + 'px;width:' + sz + 'px;height:' + sz
+ 'px;margin:' + (-sz / 2) + 'px 0 0 ' + (-sz / 2) + 'px;border-radius:50%;'
+ 'background:color-mix(in srgb, ' + gleam + ' 35%, #fff);box-shadow:0 0 6px 2px ' + gleam + ';opacity:0;'
+ 'transform:scale(0.2);transition:transform 260ms ease, opacity 260ms ease;';
document.body.appendChild(s);
motes.push(s);
setTimeout(function () {
s.style.opacity = '1'; s.style.transform = 'scale(1.3)';
setTimeout(function () {
s.style.opacity = '0'; s.style.transform = 'scale(0.4)';
}, 200);
}, 620 + i * 55);
})(i);
}
setTimeout(function () {
pane.remove();
motes.forEach(function (m) { m.remove(); });
el.style.transition = 'filter 500ms ease';
el.style.filter = 'brightness(1.05) saturate(0.85) drop-shadow(0 0 3px ' + gleam + ')';
setTimeout(function () { el.style.transition = trans0; }, 520);
}, 1300);
}
// BLUEPRINT. The container flips to a cyan drafting field (.lx-blueprint), the
// glyphs stroke-draw in white linework, and a body-level guide overlay (frame,
// tangent circles, centre lines) fades as they resolve. Toggles presentation on
// the existing paths + a separate body overlay; no element into the inner <svg>.
function blueprint(el) {
el.classList.add('lx-blueprint');
var svg = el.querySelector('svg');
var paths = svg
? Array.prototype.slice.call(svg.querySelectorAll('path'))
: [];
var WHITE = '#eaf3ff';
if (reduced) {
paths.forEach(function (p) { p.style.fill = WHITE; });
return;
}
var r = el.getBoundingClientRect();
var w = r.width, h = r.height, cx = w / 2, cy = h / 2;
var rad = Math.min(w, h) / 2;
var guide = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
guide.setAttribute('width', w); guide.setAttribute('height', h);
guide.setAttribute('fill', 'none');
guide.setAttribute('stroke', 'rgba(226,238,255,0.55)');
guide.setAttribute('stroke-width', '1');
guide.style.cssText = 'position:fixed;pointer-events:none;overflow:visible;'
+ 'z-index:2147483647;opacity:0;transition:opacity 300ms ease;'
+ 'left:' + r.left + 'px;top:' + r.top + 'px;'
+ 'width:' + w + 'px;height:' + h + 'px;';
guide.innerHTML =
'<rect x="1" y="1" width="' + (w - 2) + '" height="' + (h - 2)
+ '" stroke-dasharray="4 4"/>'
+ '<circle cx="' + cx + '" cy="' + cy + '" r="' + rad + '"/>'
+ '<circle cx="' + cx + '" cy="' + cy + '" r="' + (rad * 0.62) + '"/>'
+ '<line x1="0" y1="' + cy + '" x2="' + w + '" y2="' + cy + '"/>'
+ '<line x1="' + cx + '" y1="0" x2="' + cx + '" y2="' + h + '"/>';
document.body.appendChild(guide);
requestAnimationFrame(function () { guide.style.opacity = '1'; });
var DRAW = 620, STAGGER = 60, last = 0;
paths.sort(function (a, b) {
try { return a.getBBox().x - b.getBBox().x; } catch (e) { return 0; }
});
paths.forEach(function (p, i) {
var len;
try { len = p.getTotalLength() || 100; } catch (e) { len = 100; }
var delay = i * STAGGER;
if (delay > last) { last = delay; }
p.style.stroke = WHITE;
p.style.strokeWidth = '1.2';
p.style.fill = 'none';
p.style.strokeDasharray = len;
p.style.strokeDashoffset = len;
setTimeout(function () {
p.style.transition = 'stroke-dashoffset ' + DRAW
+ 'ms ease, fill 300ms ease ' + DRAW + 'ms';
p.style.strokeDashoffset = '0';
p.style.fill = WHITE;
}, delay);
});
var total = last + DRAW + 300;
setTimeout(function () { guide.style.opacity = '0'; }, Math.max(0, total - 260));
setTimeout(function () { guide.remove(); }, total + 120);
}
// WOBBLE. On its trigger the glyphs jiggle like jelly: each does an AUTONOMOUS
// damped VERTICAL bob decaying over ~1.4s, staggered left-to-right so it ripples
// across the equation. Pure translateY (origin-independent) — NO rotation (which
// read as an eraser sweep) and NO transform-box (which left a stray horizontal line);
// it toggles style.transform on the existing paths only — nothing touches the <svg>.
function wobble(el) {
if (reduced) { return; }
var svg = el.querySelector('svg');
if (!svg) { return; }
var paths = Array.prototype.slice.call(svg.querySelectorAll('path'));
if (!paths.length) { return; }
paths.sort(function (a, b) { // left-to-right so the ripple reads
try { return a.getBBox().x - b.getBBox().x; } catch (e) { return 0; }
});
var DUR = 1400; // ms of wobble per glyph
paths.forEach(function (p, i) {
setTimeout(function () { // stagger → the ripple
var wobbleAmp = 5 + Math.random() * 2.5; // peak PX of bounce
var freq = 5 + Math.random() * 2; // oscillations over the life
var t0 = performance.now();
function step(now) {
var t = (now - t0) / DUR; // 0..1
if (t >= 1) { clearPathDelta(p); return; } // pristine at rest
var env = (1 - t) * (1 - t); // ease-out decay envelope
var ty = -Math.sin(t * freq * Math.PI * 2) * wobbleAmp * env;
setPathDelta(p, 'translateY(' + ty.toFixed(2) + 'px)'); // composes with placement
requestAnimationFrame(step);
}
requestAnimationFrame(step);
}, i * 50);
});
}
// GRAVWELL. Armed on enter: wire a click listener onto each glyph path. On click,
// the source glyph becomes a gravity well — every other nearby glyph is gently pulled
// TOWARD it and SHRINKS as it's drawn in (1/r² reach), then eases back out. rAF-driven;
// only toggles transform on the existing paths (set while animating, cleared at rest).
// Simple by design: no spiral, no spin, no overlay orb — just pull + shrink.
// GRAVWELL — the spiral black-hole + eclipse (Charles's redesign, 2026-07-06):
// armed on enter; CLICK ANYWHERE on the equation and that point becomes the
// well — an eclipse-like orb (dark disc + bright corona, a body overlay)
// opens there while EVERY glyph shrinks and SPIRALS into it, holds a dark
// beat, then spirals back out as the orb collapses. Click point maps to
// user space via the svg screen CTM; per-glyph motion is a user-space delta
// composed with placement (setPathDelta), spinning about the well while the
// radius and scale collapse. Scroll ends the show instantly (the orb is a
// fixed overlay). Nothing is ever added to the inner <svg>.
function gravwell(el) {
var svg = el.querySelector('svg');
if (!svg || reduced) { return; }
if (el.__lxWellArmed) { return; }
el.__lxWellArmed = true;
var paths = Array.prototype.slice.call(svg.querySelectorAll('path'));
if (!paths.length) { return; }
var IN = 900, HOLD = 240, BACK = 520;
var TURNS = 1.35; // how far each glyph swings around the well on the way in
var busy = false;
svg.style.cursor = 'pointer';
svg.addEventListener('click', function (ev) {
if (busy) { return; }
busy = true;
// The CLICK POINT is the well: map client → svg user space.
var well;
try {
var ctm = svg.getScreenCTM().inverse();
well = { x: ctm.a * ev.clientX + ctm.c * ev.clientY + ctm.e,
y: ctm.b * ev.clientX + ctm.d * ev.clientY + ctm.f };
} catch (e) { busy = false; return; }
// user → screen scale, for sizing the overlay orb in page px.
var toScreen = svg.getScreenCTM();
var wellPx = { x: toScreen.a * well.x + toScreen.c * well.y + toScreen.e,
y: toScreen.b * well.x + toScreen.d * well.y + toScreen.f };
var movers = [];
paths.forEach(function (p) {
var c = userCentre(p);
if (!c) { return; }
var dx = c.x - well.x, dy = c.y - well.y;
movers.push({ p: p, r0: Math.sqrt(dx * dx + dy * dy),
a0: Math.atan2(dy, dx), cx: c.x, cy: c.y });
});
if (!movers.length) { busy = false; return; }
// The eclipse orb: a dark disc with a bright corona at the click point.
var orb = document.createElement('div');
var R = 26;
orb.style.cssText = 'position:fixed;pointer-events:none;z-index:2147483647;'
+ 'left:' + (wellPx.x - R) + 'px;top:' + (wellPx.y - R) + 'px;'
+ 'width:' + (R * 2) + 'px;height:' + (R * 2) + 'px;border-radius:50%;'