react-video-ascii 1.3.0 → 1.4.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/README.md CHANGED
@@ -30,6 +30,12 @@ import { VideoAscii } from 'react-video-ascii';
30
30
  const sources = ['/video1.mp4', '/video2.mp4'];
31
31
  <VideoAscii src={sources} />
32
32
 
33
+ // Sample an element you already loaded instead of a URL
34
+ // (swap between preloaded elements without any reload)
35
+ const [video, setVideo] = useState<HTMLVideoElement | null>(null);
36
+ <video ref={setVideo} src="/video.mp4" muted playsInline preload="auto" hidden />
37
+ <VideoAscii media={video} />
38
+
33
39
  // With options
34
40
  <VideoAscii
35
41
  src="/video.mp4"
@@ -65,12 +71,15 @@ const sources = ['/video1.mp4', '/video2.mp4'];
65
71
 
66
72
  > **Note 2:** The component fills its parent container. Control size via the parent element or the `className` prop.
67
73
 
74
+ > **Note 3:** With `media`, VideoAscii calls `play()` on a video when it starts sampling it and never pauses it; pausing, muting and loading are up to you. Changing `media` re-initialises the renderer but performs no network load.
75
+
68
76
  ## Props
69
77
 
70
78
  | Prop | Type | Default | Range | Description |
71
79
  |------|------|---------|-------|-------------|
72
- | `src` | `string \| string[]` | — | — | Video or image source URL(s). Multiple video URLs play sequentially. |
80
+ | `src` | `string \| string[]` | — | — | Video or image source URL(s). Multiple video URLs play sequentially. Required unless `media` is given. |
73
81
  | `mediaType` | `'auto' \| 'video' \| 'image'` | `'auto'` | — | How to load `src`. `auto` treats common image extensions as images and everything else as video. |
82
+ | `media` | `HTMLVideoElement \| HTMLImageElement \| null` | — | — | A loaded element to sample instead of `src`. Pass `null` while it isn't ready. |
74
83
  | `videoMode` | `boolean` | `false` | — | Show original video/image colors instead of ASCII. |
75
84
  | `numColsRaw` | `number` | `250` | `20–350` | Number of character columns. |
76
85
  | `brightnessRaw` | `number` | `1.0` | `0.0–2.0` | Brightness multiplier. |
@@ -1,3 +1,3 @@
1
1
  import { Props } from '../lib/ascii-props';
2
- declare function VideoAscii({ src, mediaType, videoMode, numColsRaw, brightnessRaw, saturationRaw, bgOpacityRaw, revealEffect, chars, mouseEffect, clickEffect, charMode, className, cropFocus, maxDpr: maxDprRaw, }: Props): import("react/jsx-runtime").JSX.Element;
2
+ declare function VideoAscii({ src, mediaType, media: mediaProp, videoMode, numColsRaw, brightnessRaw, saturationRaw, bgOpacityRaw, revealEffect, chars, mouseEffect, clickEffect, charMode, className, cropFocus, maxDpr: maxDprRaw, }: Props): import("react/jsx-runtime").JSX.Element;
3
3
  export default VideoAscii;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { default as VideoAscii } from './components/VideoAscii';
2
- export type { Props, MediaType } from './lib/ascii-props';
2
+ export type { Props, SourceProps, ElementProps, MediaType } from './lib/ascii-props';
@@ -21,9 +21,7 @@ export interface RevealEffectOptions {
21
21
  }
22
22
  export type MediaType = 'auto' | 'video' | 'image';
23
23
  export declare function resolveMediaType(src: string | string[], mediaType: MediaType): 'video' | 'image';
24
- export interface Props {
25
- src: string | string[];
26
- mediaType?: MediaType;
24
+ interface BaseProps {
27
25
  videoMode?: boolean;
28
26
  numColsRaw?: number;
29
27
  brightnessRaw?: number;
@@ -38,6 +36,17 @@ export interface Props {
38
36
  cropFocus?: 'left' | 'center' | 'right';
39
37
  maxDpr?: number;
40
38
  }
39
+ export interface SourceProps extends BaseProps {
40
+ src: string | string[];
41
+ mediaType?: MediaType;
42
+ media?: undefined;
43
+ }
44
+ export interface ElementProps extends BaseProps {
45
+ media: HTMLVideoElement | HTMLImageElement | null;
46
+ src?: undefined;
47
+ mediaType?: undefined;
48
+ }
49
+ export type Props = SourceProps | ElementProps;
41
50
  export interface ParsedProps {
42
51
  numCols: number;
43
52
  brightness: number;
@@ -66,3 +75,4 @@ export interface ParsedProps {
66
75
  maxDpr: number;
67
76
  }
68
77
  export declare function parseProps(numColsRaw: number, brightnessRaw: number, saturationRaw: number, bgOpacityRaw: number, mouseEffect: boolean | MouseEffectOptions, clickEffect: boolean | ClickEffectOptions, revealEffect: boolean | RevealEffectOptions, maxDprRaw?: number): ParsedProps;
78
+ export {};
@@ -57,14 +57,14 @@ function c(e, t) {
57
57
  return s.test(n) ? "image" : "video";
58
58
  }
59
59
  function l(e, t, n, r, i, a, o, s) {
60
- let c = !!i, l = typeof i == "object" ? i : {}, u = l.style ?? "brighten", d = c && u !== "scatter", f = c && u === "scatter", p = l.scatterChars ?? "->o", m = l.trailLen ?? 15, h = l.trailDecay ?? 10, g = l.duration ?? 1, _ = l.radius ?? (u === "scatter" ? .05 : .08), v = l.brightness ?? 2, y = !!a, b = typeof a == "object" ? a : {}, x = b.style ?? "ripple", S = y && x !== "spread", C = y && x === "spread", w = b.brightness ?? 1.1, T = b.speed ?? 2, E = b.spreadExpandDuration ?? 1.5, D = b.spreadSpeed ?? 7.5, O = !!o, k = typeof o == "object" ? o : {}, A = k.type ?? "random", j = k.duration ?? .4, M = Math.max(20, Math.min(350, Math.round(e))), ee = Math.max(0, Math.min(2, t)), te = Math.max(0, Math.min(2, n)), N = Math.max(0, Math.min(1, r));
60
+ let c = !!i, l = typeof i == "object" ? i : {}, u = l.style ?? "brighten", d = c && u !== "scatter", f = c && u === "scatter", p = l.scatterChars ?? "->o", m = l.trailLen ?? 15, h = l.trailDecay ?? 10, g = l.duration ?? 1, _ = l.radius ?? (u === "scatter" ? .05 : .08), v = l.brightness ?? 2, y = !!a, b = typeof a == "object" ? a : {}, x = b.style ?? "ripple", S = y && x !== "spread", C = y && x === "spread", w = b.brightness ?? 1.1, T = b.speed ?? 2, E = b.spreadExpandDuration ?? 1.5, D = b.spreadSpeed ?? 7.5, O = !!o, k = typeof o == "object" ? o : {}, A = k.type ?? "random", j = k.duration ?? .4, ee = Math.max(20, Math.min(350, Math.round(e))), M = Math.max(0, Math.min(2, t)), te = Math.max(0, Math.min(2, n)), ne = Math.max(0, Math.min(1, r));
61
61
  j = Math.max(.1, Math.min(4, j)), m = Math.max(0, Math.min(30, Math.round(m))), h = Math.max(1, Math.min(15, h)), g = Math.max(.1, Math.min(4, g)), _ = Math.max(.03, Math.min(.2, _)), v = Math.max(.2, Math.min(5, v)), w = Math.max(1.05, Math.min(2, w)), T = Math.max(.5, Math.min(4, T)), E = Math.max(.5, Math.min(5, E)), D = Math.max(.5, Math.min(10, D));
62
- let P = s === void 0 ? Infinity : Math.max(1, Math.min(4, s)), F;
63
- return F = O ? A === "diagonal" ? 1 : A === "radial" ? 2 : 3 : 0, {
64
- numCols: M,
65
- brightness: ee,
62
+ let N = s === void 0 ? Infinity : Math.max(1, Math.min(4, s)), P;
63
+ return P = O ? A === "diagonal" ? 1 : A === "radial" ? 2 : 3 : 0, {
64
+ numCols: ee,
65
+ brightness: M,
66
66
  saturation: te,
67
- bgOpacity: N,
67
+ bgOpacity: ne,
68
68
  mouseEnabled: c,
69
69
  mouseStyle: u,
70
70
  brightenEnabled: d,
@@ -84,8 +84,8 @@ function l(e, t, n, r, i, a, o, s) {
84
84
  revealEnabled: O,
85
85
  revealType: A,
86
86
  revealDuration: j,
87
- revealEffectFlag: F,
88
- maxDpr: P
87
+ revealEffectFlag: P,
88
+ maxDpr: N
89
89
  };
90
90
  }
91
91
  //#endregion
@@ -399,24 +399,24 @@ function x(e, t) {
399
399
  }
400
400
  //#endregion
401
401
  //#region src/components/VideoAscii.tsx
402
- function S({ src: i, mediaType: s = "auto", videoMode: u = !1, numColsRaw: d = 250, brightnessRaw: f = 1, saturationRaw: p = 1, bgOpacityRaw: m = .3, revealEffect: v = !1, chars: S = o, mouseEffect: C = !0, clickEffect: w = !0, charMode: T = "shape", className: E, cropFocus: D = "center", maxDpr: O }) {
403
- let k = t(null), A = t(null), j = t(null), M = t(null), ee = t(null), te = t(null), { numCols: N, brightness: P, saturation: F, bgOpacity: I, mouseEnabled: L, mouseStyle: R, brightenEnabled: z, scatterEnabled: B, scatterChars: V, trailLen: H, trailDecay: U, duration: ne, mouseRadius: re, mouseBrightness: W, clickEnabled: G, clickBrightness: K, clickSpeed: q, spreadEnabled: J, spreadExpandDuration: Y, spreadSpeed: X, revealEnabled: ie, revealDuration: ae, revealEffectFlag: oe, maxDpr: Z } = l(d, f, p, m, C, w, v, O), se = c(i, s) === "image", ce = t(P), le = t(F), ue = t(I), de = t(L), fe = t(R), pe = t(z), me = t(B), he = t(W), ge = t(re), _e = t(H), ve = t(U), ye = t(ne), Q = t(V), be = t(G), xe = t(K), Se = t(q), Ce = t(J), we = t(Y), Te = t(X), Ee = t(N), De = t(u), Oe = t(D), ke = t(0), Ae = t(0), je = t(Z), Me = t(1), Ne = t(null), Pe = t(null);
402
+ function S({ src: i, mediaType: s = "auto", media: u, videoMode: d = !1, numColsRaw: f = 250, brightnessRaw: p = 1, saturationRaw: m = 1, bgOpacityRaw: v = .3, revealEffect: S = !1, chars: C = o, mouseEffect: w = !0, clickEffect: T = !0, charMode: E = "shape", className: D, cropFocus: O = "center", maxDpr: k }) {
403
+ let A = t(null), j = t(null), ee = t(null), M = t(null), te = t(null), ne = t(null), { numCols: N, brightness: P, saturation: F, bgOpacity: I, mouseEnabled: re, mouseStyle: L, brightenEnabled: R, scatterEnabled: z, scatterChars: B, trailLen: V, trailDecay: H, duration: ie, mouseRadius: U, mouseBrightness: W, clickEnabled: G, clickBrightness: K, clickSpeed: q, spreadEnabled: J, spreadExpandDuration: Y, spreadSpeed: X, revealEnabled: ae, revealDuration: oe, revealEffectFlag: se, maxDpr: Z } = l(f, p, m, v, w, T, S, k), ce = i === void 0, le = i !== void 0 && c(i, s) === "image", ue = t(P), de = t(F), fe = t(I), pe = t(re), me = t(L), he = t(R), ge = t(z), _e = t(W), ve = t(U), ye = t(V), be = t(H), xe = t(ie), Q = t(B), Se = t(G), Ce = t(K), we = t(q), Te = t(J), Ee = t(Y), De = t(X), Oe = t(N), ke = t(d), Ae = t(O), je = t(0), Me = t(0), Ne = t(Z), Pe = t(1), Fe = t(null), Ie = t(null);
404
404
  e(() => {
405
- ce.current = P, le.current = F, ue.current = I, de.current = L, fe.current = R, pe.current = z, me.current = B, he.current = W, ge.current = re, _e.current = H, ve.current = U, ye.current = ne, Q.current !== V && $.current ? (Q.current = V, Ie.current?.()) : Q.current = V, be.current = G, xe.current = K, Se.current = q, Ce.current = J, we.current = Y, Te.current = X, Ee.current = N, De.current = u;
405
+ ue.current = P, de.current = F, fe.current = I, pe.current = re, me.current = L, he.current = R, ge.current = z, _e.current = W, ve.current = U, ye.current = V, be.current = H, xe.current = ie, Q.current !== B && $.current ? (Q.current = B, Re.current?.()) : Q.current = B, Se.current = G, Ce.current = K, we.current = q, Te.current = J, Ee.current = Y, De.current = X, Oe.current = N, ke.current = d;
406
406
  }, [
407
407
  P,
408
408
  F,
409
409
  I,
410
+ re,
410
411
  L,
411
412
  R,
412
413
  z,
413
- B,
414
414
  W,
415
- re,
416
- H,
417
415
  U,
418
- ne,
419
416
  V,
417
+ H,
418
+ ie,
419
+ B,
420
420
  G,
421
421
  K,
422
422
  q,
@@ -424,120 +424,120 @@ function S({ src: i, mediaType: s = "auto", videoMode: u = !1, numColsRaw: d = 2
424
424
  Y,
425
425
  X,
426
426
  N,
427
- u
427
+ d
428
428
  ]);
429
- let Fe = t(null), Ie = t(null), Le = t(null), $ = t(!1);
429
+ let Le = t(null), Re = t(null), ze = t(null), $ = t(!1);
430
430
  e(() => {
431
- $.current && Fe.current?.(N);
431
+ $.current && Le.current?.(N);
432
432
  }, [N]), e(() => {
433
- Oe.current = D, $.current && ke.current > 0 && Le.current?.(ke.current, Ae.current);
434
- }, [D]), e(() => {
435
- je.current = Z, $.current && Ne.current && Pe.current?.(Ne.current);
433
+ Ae.current = O, $.current && je.current > 0 && ze.current?.(je.current, Me.current);
434
+ }, [O]), e(() => {
435
+ Ne.current = Z, $.current && Fe.current && Ie.current?.(Fe.current);
436
436
  }, [Z]), e(() => {
437
437
  $.current = !1;
438
- let e = [], t = 0, n = 0, r = 1, o = 1, s = 0, c = 0, l = 0, u = 0, d = k.current;
439
- if (!d) return;
440
- let f = se ? j.current : A.current;
438
+ let e = [], t = 0, n = 0, r = 1, o = 1, s = 0, c = 0, l = 0, d = 0, f = A.current;
441
439
  if (!f) return;
442
- let p = f instanceof HTMLVideoElement ? f : null, m = f instanceof HTMLImageElement ? f : null, v = () => f instanceof HTMLVideoElement ? {
443
- width: f.videoWidth,
444
- height: f.videoHeight
440
+ let p = ce ? u : le ? ee.current : j.current;
441
+ if (!p) return;
442
+ let m = p instanceof HTMLVideoElement ? p : null, v = p instanceof HTMLImageElement ? p : null, S = () => p instanceof HTMLVideoElement ? {
443
+ width: p.videoWidth,
444
+ height: p.videoHeight
445
445
  } : {
446
- width: f.naturalWidth,
447
- height: f.naturalHeight
448
- }, C = d.getContext("webgl2");
449
- if (!C) return;
450
- C.pixelStorei(C.UNPACK_ALIGNMENT, 1);
451
- let w = h(C);
446
+ width: p.naturalWidth,
447
+ height: p.naturalHeight
448
+ }, w = f.getContext("webgl2");
452
449
  if (!w) return;
453
- let { program: E, pass1Program: D } = w;
454
- ee.current = w.atlasTexture, te.current = w.scatterAtlasTexture, C.uniform1i(w.shapeMatchingLoc, +(T === "shape")), C.uniform1i(w.revealEffectFlagLoc, oe), C.uniform1f(w.revealProgressLoc, 0);
455
- let O = g({
456
- scatterEnabledRef: me,
457
- mouseRadiusRef: ge,
458
- durationRef: ye,
450
+ w.pixelStorei(w.UNPACK_ALIGNMENT, 1);
451
+ let T = h(w);
452
+ if (!T) return;
453
+ let { program: D, pass1Program: O } = T;
454
+ te.current = T.atlasTexture, ne.current = T.scatterAtlasTexture, w.uniform1i(T.shapeMatchingLoc, +(E === "shape")), w.uniform1i(T.revealEffectFlagLoc, se), w.uniform1f(T.revealProgressLoc, 0);
455
+ let k = g({
456
+ scatterEnabledRef: ge,
457
+ mouseRadiusRef: ve,
458
+ durationRef: xe,
459
459
  scatterCharsRef: Q
460
460
  }), N = _({
461
- brightenEnabledRef: pe,
462
- trailLenRef: _e,
463
- durationRef: ye,
464
- trailDecayRef: ve
461
+ brightenEnabledRef: he,
462
+ trailLenRef: ye,
463
+ durationRef: xe,
464
+ trailDecayRef: be
465
465
  }), P = y({
466
- clickEnabledRef: be,
467
- clickSpeedRef: Se,
468
- clickBrightnessRef: xe,
469
- pixelScaleRef: Me
466
+ clickEnabledRef: Se,
467
+ clickSpeedRef: we,
468
+ clickBrightnessRef: Ce,
469
+ pixelScaleRef: Pe
470
470
  }), F = b({
471
- spreadEnabledRef: Ce,
471
+ spreadEnabledRef: Te,
472
472
  scatterCharsRef: Q,
473
- spreadExpandDurationRef: we,
474
- spreadSpeedRef: Te
475
- }), I, L = -1, R = -1, z = 0, B = Array.isArray(i) ? i : [i], V = B.length > 1, H = document.createElement("canvas"), U = H.getContext("2d"), ne = (i) => {
476
- let f = l > 0 ? l : d.width, p = u > 0 ? u : d.height;
477
- r = Math.max(1, Math.floor(f / i));
473
+ spreadExpandDurationRef: Ee,
474
+ spreadSpeedRef: De
475
+ }), I = 0, re = -1, L = -1, R = 0, z = Array.isArray(i) ? i : i === void 0 ? [] : [i], B = z.length > 1, V = document.createElement("canvas"), H = V.getContext("2d"), ie = (i) => {
476
+ let u = l > 0 ? l : f.width, p = d > 0 ? d : f.height;
477
+ r = Math.max(1, Math.floor(u / i));
478
478
  let m = r * 2;
479
- if (U.font = `${m}px monospace`, o = Math.max(1, Math.round(m * r / U.measureText("M").width)), t = Math.ceil(f / r), n = Math.ceil(p / o), s = Math.floor((f - t * r) / 2), c = Math.floor((p - n * o) / 2), C.viewport(0, 0, d.width, d.height), C.useProgram(E), C.uniform2f(w.resLoc, d.width, d.height), C.uniform2f(w.gridOffsetLoc, s, c), C.useProgram(D), C.uniform2f(w.p1ResLoc, d.width, d.height), C.uniform2f(w.p1GridOffsetLoc, s, c), C.useProgram(E), O.setup(C, t, n, r, o, s, c, w.scatterStateTexture), F.setup(C, t, n, r, o, s, c, w.spreadStateTexture), T === "shape") {
480
- e = a(S, r, o);
479
+ if (H.font = `${m}px monospace`, o = Math.max(1, Math.round(m * r / H.measureText("M").width)), t = Math.ceil(u / r), n = Math.ceil(p / o), s = Math.floor((u - t * r) / 2), c = Math.floor((p - n * o) / 2), w.viewport(0, 0, f.width, f.height), w.useProgram(D), w.uniform2f(T.resLoc, f.width, f.height), w.uniform2f(T.gridOffsetLoc, s, c), w.useProgram(O), w.uniform2f(T.p1ResLoc, f.width, f.height), w.uniform2f(T.p1GridOffsetLoc, s, c), w.useProgram(D), k.setup(w, t, n, r, o, s, c, T.scatterStateTexture), F.setup(w, t, n, r, o, s, c, T.spreadStateTexture), E === "shape") {
480
+ e = a(C, r, o);
481
481
  let i = e.length, s = new Float32Array(i * 8);
482
482
  for (let t = 0; t < i; t++) {
483
483
  let n = e[t].vector;
484
484
  s[t * 4 + 0] = n[0], s[t * 4 + 1] = n[1], s[t * 4 + 2] = n[2], s[t * 4 + 3] = n[3], s[i * 4 + t * 4 + 0] = n[4], s[i * 4 + t * 4 + 1] = n[5];
485
485
  }
486
- C.activeTexture(C.TEXTURE2), C.bindTexture(C.TEXTURE_2D, w.charVectorsTexture), C.texImage2D(C.TEXTURE_2D, 0, C.RGBA32F, i, 2, 0, C.RGBA, C.FLOAT, s), C.activeTexture(C.TEXTURE3), C.bindTexture(C.TEXTURE_2D, w.fboTexture), C.texImage2D(C.TEXTURE_2D, 0, C.R8UI, t, n, 0, C.RED_INTEGER, C.UNSIGNED_BYTE, null), C.bindFramebuffer(C.FRAMEBUFFER, w.fbo), C.framebufferTexture2D(C.FRAMEBUFFER, C.COLOR_ATTACHMENT0, C.TEXTURE_2D, w.fboTexture, 0), C.bindFramebuffer(C.FRAMEBUFFER, null);
486
+ w.activeTexture(w.TEXTURE2), w.bindTexture(w.TEXTURE_2D, T.charVectorsTexture), w.texImage2D(w.TEXTURE_2D, 0, w.RGBA32F, i, 2, 0, w.RGBA, w.FLOAT, s), w.activeTexture(w.TEXTURE3), w.bindTexture(w.TEXTURE_2D, T.fboTexture), w.texImage2D(w.TEXTURE_2D, 0, w.R8UI, t, n, 0, w.RED_INTEGER, w.UNSIGNED_BYTE, null), w.bindFramebuffer(w.FRAMEBUFFER, T.fbo), w.framebufferTexture2D(w.FRAMEBUFFER, w.COLOR_ATTACHMENT0, w.TEXTURE_2D, T.fboTexture, 0), w.bindFramebuffer(w.FRAMEBUFFER, null);
487
487
  let c = Math.max(1, Math.round(r / 5));
488
- C.useProgram(D), C.uniform2f(w.p1CellsizeLoc, r, o), C.uniform1i(w.p1CircleNLoc, c), C.uniform1i(w.p1NumCharsLoc, i), C.uniform1f(w.p1ExponentLoc, 2), C.useProgram(E);
488
+ w.useProgram(O), w.uniform2f(T.p1CellsizeLoc, r, o), w.uniform1i(T.p1CircleNLoc, c), w.uniform1i(T.p1NumCharsLoc, i), w.uniform1f(T.p1ExponentLoc, 2), w.useProgram(D);
489
489
  }
490
- C.uniform2f(w.gridSizeLoc, t, n), H.width = S.length * r, H.height = o, U.font = `${o}px monospace`, U.fillStyle = "black", U.fillRect(0, 0, S.length * r, o), U.fillStyle = "white", U.textBaseline = "top";
491
- for (let e = 0; e < S.length; e++) U.fillText(S[e], e * r, 0);
492
- C.activeTexture(C.TEXTURE1), C.bindTexture(C.TEXTURE_2D, ee.current), C.texImage2D(C.TEXTURE_2D, 0, C.RGBA, C.RGBA, C.UNSIGNED_BYTE, H), C.uniform1f(w.numLoc, S.length), C.uniform2f(w.sizeLoc, r, o), re();
493
- }, re = () => {
490
+ w.uniform2f(T.gridSizeLoc, t, n), V.width = C.length * r, V.height = o, H.font = `${o}px monospace`, H.fillStyle = "black", H.fillRect(0, 0, C.length * r, o), H.fillStyle = "white", H.textBaseline = "top";
491
+ for (let e = 0; e < C.length; e++) H.fillText(C[e], e * r, 0);
492
+ w.activeTexture(w.TEXTURE1), w.bindTexture(w.TEXTURE_2D, te.current), w.texImage2D(w.TEXTURE_2D, 0, w.RGBA, w.RGBA, w.UNSIGNED_BYTE, V), w.uniform1f(T.numLoc, C.length), w.uniform2f(T.sizeLoc, r, o), U();
493
+ }, U = () => {
494
494
  let e = Q.current;
495
- H.width = e.length * r, H.height = o, U.fillStyle = "black", U.fillRect(0, 0, H.width, o), U.fillStyle = "white", U.textBaseline = "top", U.font = `${o}px monospace`;
496
- for (let t = 0; t < e.length; t++) U.fillText(e[t], t * r, 0);
497
- C.activeTexture(C.TEXTURE4), C.bindTexture(C.TEXTURE_2D, te.current), C.texImage2D(C.TEXTURE_2D, 0, C.RGBA, C.RGBA, C.UNSIGNED_BYTE, H), C.uniform1f(w.scatterNumCharsLoc, e.length), O.reset(C);
495
+ V.width = e.length * r, V.height = o, H.fillStyle = "black", H.fillRect(0, 0, V.width, o), H.fillStyle = "white", H.textBaseline = "top", H.font = `${o}px monospace`;
496
+ for (let t = 0; t < e.length; t++) H.fillText(e[t], t * r, 0);
497
+ w.activeTexture(w.TEXTURE4), w.bindTexture(w.TEXTURE_2D, ne.current), w.texImage2D(w.TEXTURE_2D, 0, w.RGBA, w.RGBA, w.UNSIGNED_BYTE, V), w.uniform1f(T.scatterNumCharsLoc, e.length), k.reset(w);
498
498
  };
499
- Fe.current = ne, Ie.current = re;
499
+ Le.current = ie, Re.current = U;
500
500
  let W = (e, t) => {
501
- l = Math.round(e), u = Math.round(t), ke.current = l, Ae.current = u, d.width = l, d.height = u, ne(Ee.current);
502
- let n = v(), r = n.width / n.height, i = d.width / d.height, a = 1, o = 1, s = 0, c = 0;
501
+ l = Math.round(e), d = Math.round(t), je.current = l, Me.current = d, f.width = l, f.height = d, ie(Oe.current);
502
+ let n = S(), r = n.width / n.height, i = f.width / f.height, a = 1, o = 1, s = 0, c = 0;
503
503
  if (i > r) o = r / i, c = (1 - o) / 2;
504
504
  else {
505
505
  a = i / r;
506
- let e = Oe.current, t = e === "left" ? .25 : e === "right" ? .75 : .5;
506
+ let e = Ae.current, t = e === "left" ? .25 : e === "right" ? .75 : .5;
507
507
  s = Math.max(0, Math.min(1 - a, t - a / 2));
508
508
  }
509
- C.uniform2f(w.cropOffsetLoc, s, c), C.uniform2f(w.cropScaleLoc, a, o), C.useProgram(D), C.uniform2f(w.p1CropOffsetLoc, s, c), C.uniform2f(w.p1CropScaleLoc, a, o), C.useProgram(E);
509
+ w.uniform2f(T.cropOffsetLoc, s, c), w.uniform2f(T.cropScaleLoc, a, o), w.useProgram(O), w.uniform2f(T.p1CropOffsetLoc, s, c), w.uniform2f(T.p1CropScaleLoc, a, o), w.useProgram(D);
510
510
  };
511
- Le.current = W;
511
+ ze.current = W;
512
512
  let G = (e) => {
513
- Ne.current = e;
514
- let t = Math.min(1, je.current / (window.devicePixelRatio || 1)), n = Math.max(1, Math.round(e.width * t)), r = Math.max(1, Math.round(e.height * t));
515
- Me.current = e.cssWidth > 0 ? n / e.cssWidth : 1, W(n, r);
513
+ Fe.current = e;
514
+ let t = Math.min(1, Ne.current / (window.devicePixelRatio || 1)), n = Math.max(1, Math.round(e.width * t)), r = Math.max(1, Math.round(e.height * t));
515
+ Pe.current = e.cssWidth > 0 ? n / e.cssWidth : 1, W(n, r);
516
516
  };
517
- Pe.current = G;
517
+ Ie.current = G;
518
518
  let K = (e) => {
519
- if (!de.current) return;
520
- let t = d.getBoundingClientRect(), n = (e.clientX - t.left) * (d.width / t.width), r = (e.clientY - t.top) * (d.height / t.height), i = performance.now();
521
- N.handleMouseMove(n, r, i), O.handleMouseMove(n, r, i);
519
+ if (!pe.current) return;
520
+ let t = f.getBoundingClientRect(), n = (e.clientX - t.left) * (f.width / t.width), r = (e.clientY - t.top) * (f.height / t.height), i = performance.now();
521
+ N.handleMouseMove(n, r, i), k.handleMouseMove(n, r, i);
522
522
  };
523
- d.addEventListener("mousemove", K);
524
- let q = () => O.handleMouseLeave();
525
- d.addEventListener("mouseleave", q);
523
+ f.addEventListener("mousemove", K);
524
+ let q = () => k.handleMouseLeave();
525
+ f.addEventListener("mouseleave", q);
526
526
  let J = (e) => {
527
- P.handleClick(e, d), F.handleClick(e, d);
527
+ P.handleClick(e, f), F.handleClick(e, f);
528
528
  };
529
- d.addEventListener("click", J);
529
+ f.addEventListener("click", J);
530
530
  let Y = () => {
531
- if (C.uniform1i(w.videoModeLoc, +!!De.current), C.uniform1f(w.brightnessLoc, ce.current), C.uniform1f(w.saturationLoc, le.current), C.uniform1f(w.bgOpacityLoc, ue.current), C.uniform1i(w.mouseEffectFlagLoc, +!!pe.current), C.uniform1i(w.scatterEffectFlagLoc, +!!me.current), C.uniform1i(w.clickEffectFlagLoc, +!!be.current), C.uniform1i(w.spreadEffectFlagLoc, +!!Ce.current), C.uniform1f(w.mouseBrightnessLoc, he.current), C.uniform1f(w.mouseRadiusLoc, Math.min(d.width, d.height) * ge.current), ie) {
532
- let e = R < 0 ? 0 : Math.min(1, (performance.now() - R) / (ae * 1e3));
533
- C.uniform1f(w.revealProgressLoc, e);
531
+ if (w.uniform1i(T.videoModeLoc, +!!ke.current), w.uniform1f(T.brightnessLoc, ue.current), w.uniform1f(T.saturationLoc, de.current), w.uniform1f(T.bgOpacityLoc, fe.current), w.uniform1i(T.mouseEffectFlagLoc, +!!he.current), w.uniform1i(T.scatterEffectFlagLoc, +!!ge.current), w.uniform1i(T.clickEffectFlagLoc, +!!Se.current), w.uniform1i(T.spreadEffectFlagLoc, +!!Te.current), w.uniform1f(T.mouseBrightnessLoc, _e.current), w.uniform1f(T.mouseRadiusLoc, Math.min(f.width, f.height) * ve.current), ae) {
532
+ let e = L < 0 ? 0 : Math.min(1, (performance.now() - L) / (oe * 1e3));
533
+ w.uniform1f(T.revealProgressLoc, e);
534
534
  }
535
- $.current && p && p.currentTime != L && p.readyState >= 2 && (C.activeTexture(C.TEXTURE0), C.bindTexture(C.TEXTURE_2D, w.texture), C.texSubImage2D(C.TEXTURE_2D, 0, 0, 0, C.RGBA, C.UNSIGNED_BYTE, p), L = p.currentTime), N.tick(C, w.mousePositionsLoc, w.mouseLifeFracsLoc), O.tick(C, d), P.tick(C, d, w.ripplePositionsLoc, w.rippleRadiiLoc, w.rippleBrightnessesLoc), F.tick(C), T === "shape" && (C.bindFramebuffer(C.FRAMEBUFFER, w.fbo), C.viewport(0, 0, t, n), C.useProgram(D), C.drawArrays(C.TRIANGLES, 0, 6), C.bindFramebuffer(C.FRAMEBUFFER, null), C.viewport(0, 0, d.width, d.height), C.useProgram(E)), C.drawArrays(C.TRIANGLES, 0, 6), I = requestAnimationFrame(Y);
535
+ $.current && m && m.currentTime != re && m.readyState >= 2 && (w.activeTexture(w.TEXTURE0), w.bindTexture(w.TEXTURE_2D, T.texture), w.texSubImage2D(w.TEXTURE_2D, 0, 0, 0, w.RGBA, w.UNSIGNED_BYTE, m), re = m.currentTime), N.tick(w, T.mousePositionsLoc, T.mouseLifeFracsLoc), k.tick(w, f), P.tick(w, f, T.ripplePositionsLoc, T.rippleRadiiLoc, T.rippleBrightnessesLoc), F.tick(w), E === "shape" && (w.bindFramebuffer(w.FRAMEBUFFER, T.fbo), w.viewport(0, 0, t, n), w.useProgram(O), w.drawArrays(w.TRIANGLES, 0, 6), w.bindFramebuffer(w.FRAMEBUFFER, null), w.viewport(0, 0, f.width, f.height), w.useProgram(D)), w.drawArrays(w.TRIANGLES, 0, 6), I = requestAnimationFrame(Y);
536
536
  }, X = () => {
537
- let e = M.current, t = Ne.current;
537
+ let e = M.current, t = Fe.current;
538
538
  if (t && t.width > 0 && t.height > 0) G(t);
539
539
  else {
540
- let t = window.devicePixelRatio || 1, n = v(), r = e.clientWidth || n.width, i = e.clientHeight || n.height;
540
+ let t = window.devicePixelRatio || 1, n = S(), r = e.clientWidth || n.width, i = e.clientHeight || n.height;
541
541
  G({
542
542
  width: Math.round(r * t),
543
543
  height: Math.round(i * t),
@@ -545,50 +545,52 @@ function S({ src: i, mediaType: s = "auto", videoMode: u = !1, numColsRaw: d = 2
545
545
  cssHeight: i
546
546
  });
547
547
  }
548
- C.activeTexture(C.TEXTURE0), C.bindTexture(C.TEXTURE_2D, w.texture), C.texImage2D(C.TEXTURE_2D, 0, C.RGBA, C.RGBA, C.UNSIGNED_BYTE, f), p?.play(), R = performance.now(), $.current = !0, I = requestAnimationFrame(Y);
548
+ w.activeTexture(w.TEXTURE0), w.bindTexture(w.TEXTURE_2D, T.texture), w.texImage2D(w.TEXTURE_2D, 0, w.RGBA, w.RGBA, w.UNSIGNED_BYTE, p), m?.play(), L = performance.now(), $.current = !0, cancelAnimationFrame(I), I = requestAnimationFrame(Y);
549
549
  }, Z = () => {
550
- p && (z = (z + 1) % B.length, p.src = B[z], p.load(), p.addEventListener("canplay", () => p.play(), { once: !0 }));
551
- }, fe = M.current ? x(M.current, (e) => {
552
- Ne.current = e, $.current && e.width > 0 && e.height > 0 && G(e);
550
+ m && (R = (R + 1) % z.length, m.src = z[R], m.load(), m.addEventListener("canplay", () => m.play(), { once: !0 }));
551
+ }, me = M.current ? x(M.current, (e) => {
552
+ Fe.current = e, $.current && e.width > 0 && e.height > 0 && G(e);
553
553
  }) : () => {};
554
- return p ? (p.addEventListener("loadeddata", X, { once: !0 }), V && p.addEventListener("ended", Z), p.readyState >= 2 && p.currentSrc.endsWith(B[0]) ? X() : p.currentSrc.endsWith(B[0]) || p.load()) : m && (m.complete && m.naturalWidth > 0 ? X() : m.addEventListener("load", X, { once: !0 })), () => {
555
- fe(), Fe.current = null, Ie.current = null, Le.current = null, Pe.current = null, $.current = !1, cancelAnimationFrame(I), p ? (p.removeEventListener("loadeddata", X), V && p.removeEventListener("ended", Z)) : m?.removeEventListener("load", X), d.removeEventListener("mousemove", K), d.removeEventListener("mouseleave", q), d.removeEventListener("click", J), C.deleteTexture(w.texture), C.deleteTexture(w.charVectorsTexture), C.deleteFramebuffer(w.fbo), C.deleteTexture(w.fboTexture), C.deleteBuffer(w.buffer), C.deleteShader(w.vertShader), C.deleteShader(w.fragShader), C.deleteShader(w.pass1FragShader), C.deleteProgram(E), C.deleteProgram(D), C.deleteTexture(ee.current), C.deleteTexture(te.current), C.deleteTexture(w.scatterStateTexture), C.deleteTexture(w.spreadStateTexture);
554
+ return m ? (m.addEventListener("loadeddata", X, { once: !ce }), B && m.addEventListener("ended", Z), ce ? m.readyState >= 2 && X() : m.readyState >= 2 && m.currentSrc.endsWith(z[0]) ? X() : m.currentSrc.endsWith(z[0]) || m.load()) : v && (v.complete && v.naturalWidth > 0 ? X() : v.addEventListener("load", X, { once: !0 })), () => {
555
+ me(), Le.current = null, Re.current = null, ze.current = null, Ie.current = null, $.current = !1, cancelAnimationFrame(I), m ? (m.removeEventListener("loadeddata", X), B && m.removeEventListener("ended", Z)) : v?.removeEventListener("load", X), f.removeEventListener("mousemove", K), f.removeEventListener("mouseleave", q), f.removeEventListener("click", J), w.deleteTexture(T.texture), w.deleteTexture(T.charVectorsTexture), w.deleteFramebuffer(T.fbo), w.deleteTexture(T.fboTexture), w.deleteBuffer(T.buffer), w.deleteShader(T.vertShader), w.deleteShader(T.fragShader), w.deleteShader(T.pass1FragShader), w.deleteProgram(D), w.deleteProgram(O), w.deleteTexture(te.current), w.deleteTexture(ne.current), w.deleteTexture(T.scatterStateTexture), w.deleteTexture(T.spreadStateTexture);
556
556
  };
557
557
  }, [
558
558
  i,
559
- T,
560
- S,
559
+ u,
560
+ ce,
561
+ E,
562
+ C,
563
+ se,
561
564
  oe,
562
565
  ae,
563
- ie,
564
- se
566
+ le
565
567
  ]);
566
- let Re = Array.isArray(i) ? i[0] : i;
568
+ let Be = Array.isArray(i) ? i[0] : i;
567
569
  return /* @__PURE__ */ r("div", {
568
570
  ref: M,
569
- className: E,
571
+ className: D,
570
572
  style: {
571
573
  height: "100%",
572
574
  width: "100%"
573
575
  },
574
- children: [se ? /* @__PURE__ */ n("img", {
575
- ref: j,
576
- src: Re,
576
+ children: [ce ? null : le ? /* @__PURE__ */ n("img", {
577
+ ref: ee,
578
+ src: Be,
577
579
  alt: "",
578
580
  style: { display: "none" }
579
581
  }) : /* @__PURE__ */ n("video", {
580
- ref: A,
582
+ ref: j,
581
583
  muted: !0,
582
584
  playsInline: !0,
583
585
  autoPlay: !0,
584
586
  loop: !Array.isArray(i) || i.length === 1,
585
587
  style: { display: "none" },
586
588
  children: /* @__PURE__ */ n("source", {
587
- src: Re,
589
+ src: Be,
588
590
  type: "video/mp4"
589
591
  })
590
592
  }), /* @__PURE__ */ n("canvas", {
591
- ref: k,
593
+ ref: A,
592
594
  style: {
593
595
  width: "100%",
594
596
  height: "100%",
@@ -1,4 +1,4 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ReactVideoAscii={},e.React,e.ReactJSXRuntime))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=[[.25,.25],[.75,.25],[.25,.5],[.75,.5],[.25,.75],[.75,.75]];function i(e,t,n){let i=[],a=document.createElement(`canvas`);a.width=t,a.height=n;let o=a.getContext(`2d`,{willReadFrequently:!0});if(!o)return[];o.font=`${n}px monospace`,o.textBaseline=`top`;let s=t/5;for(let a of e){o.fillStyle=`black`,o.fillRect(0,0,t,n),o.fillStyle=`white`,o.fillText(a,0,0);let e=o.getImageData(0,0,t,n),c=[];for(let[i,a]of r){let r=i*t,o=a*n,l=0,u=0;for(let n=Math.floor(r-s);n<=Math.ceil(r+s);n+=1)for(let i=Math.floor(o-s);i<=Math.ceil(o+s);i+=1){let a=r-n,c=o-i;if(a*a+c*c<=s*s){let r=(i*t+n)*4,a=e.data[r];l+=a/255,u++}}let d=u>0?l/u:0;c.push(d)}i.push({char:a,vector:c})}let c=[,,,,,,].fill(0);for(let{vector:e}of i)for(let t=0;t<6;++t)e[t]>c[t]&&(c[t]=e[t]);for(let{vector:e}of i)for(let t=0;t<6;++t)e[t]/=c[t];return i}var a=` \`.',-_:!;|"~+^lr[](\\/L)>t<v=Tz?icf1{sIxY*jJno}CZyVwmSXRqM$O%#9&NW0Q@`,o=/\.(png|jpe?g|gif|webp|avif|bmp|svg)(?:[?#].*)?$/i;function s(e,t){if(t!==`auto`)return t;let n=Array.isArray(e)?e[0]:e;return o.test(n)?`image`:`video`}function c(e,t,n,r,i,a,o,s){let c=!!i,l=typeof i==`object`?i:{},u=l.style??`brighten`,d=c&&u!==`scatter`,f=c&&u===`scatter`,p=l.scatterChars??`->o`,m=l.trailLen??15,h=l.trailDecay??10,g=l.duration??1,_=l.radius??(u===`scatter`?.05:.08),v=l.brightness??2,y=!!a,b=typeof a==`object`?a:{},x=b.style??`ripple`,S=y&&x!==`spread`,C=y&&x===`spread`,w=b.brightness??1.1,T=b.speed??2,E=b.spreadExpandDuration??1.5,D=b.spreadSpeed??7.5,O=!!o,k=typeof o==`object`?o:{},A=k.type??`random`,j=k.duration??.4,ee=Math.max(20,Math.min(350,Math.round(e))),M=Math.max(0,Math.min(2,t)),N=Math.max(0,Math.min(2,n)),P=Math.max(0,Math.min(1,r));j=Math.max(.1,Math.min(4,j)),m=Math.max(0,Math.min(30,Math.round(m))),h=Math.max(1,Math.min(15,h)),g=Math.max(.1,Math.min(4,g)),_=Math.max(.03,Math.min(.2,_)),v=Math.max(.2,Math.min(5,v)),w=Math.max(1.05,Math.min(2,w)),T=Math.max(.5,Math.min(4,T)),E=Math.max(.5,Math.min(5,E)),D=Math.max(.5,Math.min(10,D));let F=s===void 0?1/0:Math.max(1,Math.min(4,s)),I;return I=O?A===`diagonal`?1:A===`radial`?2:3:0,{numCols:ee,brightness:M,saturation:N,bgOpacity:P,mouseEnabled:c,mouseStyle:u,brightenEnabled:d,scatterEnabled:f,scatterChars:p,trailLen:m,trailDecay:h,duration:g,mouseRadius:_,mouseBrightness:v,clickEnabled:S,clickBrightness:w,clickSpeed:T,spreadEnabled:C,spreadExpandDuration:E,spreadSpeed:D,revealEnabled:O,revealType:A,revealDuration:j,revealEffectFlag:I,maxDpr:F}}function l(e,t,n){let r=e.createShader(t);if(!r)throw Error(`Failed to create shader`);return e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.log(e.getShaderInfoLog(r)),e.deleteShader(r),null)}function u(e,t,n){let r=e.createProgram();return e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(console.log(e.getProgramInfoLog(r)),e.deleteProgram(r),null)}var d=`#version 300 es
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ReactVideoAscii={},e.React,e.ReactJSXRuntime))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=[[.25,.25],[.75,.25],[.25,.5],[.75,.5],[.25,.75],[.75,.75]];function i(e,t,n){let i=[],a=document.createElement(`canvas`);a.width=t,a.height=n;let o=a.getContext(`2d`,{willReadFrequently:!0});if(!o)return[];o.font=`${n}px monospace`,o.textBaseline=`top`;let s=t/5;for(let a of e){o.fillStyle=`black`,o.fillRect(0,0,t,n),o.fillStyle=`white`,o.fillText(a,0,0);let e=o.getImageData(0,0,t,n),c=[];for(let[i,a]of r){let r=i*t,o=a*n,l=0,u=0;for(let n=Math.floor(r-s);n<=Math.ceil(r+s);n+=1)for(let i=Math.floor(o-s);i<=Math.ceil(o+s);i+=1){let a=r-n,c=o-i;if(a*a+c*c<=s*s){let r=(i*t+n)*4,a=e.data[r];l+=a/255,u++}}let d=u>0?l/u:0;c.push(d)}i.push({char:a,vector:c})}let c=[,,,,,,].fill(0);for(let{vector:e}of i)for(let t=0;t<6;++t)e[t]>c[t]&&(c[t]=e[t]);for(let{vector:e}of i)for(let t=0;t<6;++t)e[t]/=c[t];return i}var a=` \`.',-_:!;|"~+^lr[](\\/L)>t<v=Tz?icf1{sIxY*jJno}CZyVwmSXRqM$O%#9&NW0Q@`,o=/\.(png|jpe?g|gif|webp|avif|bmp|svg)(?:[?#].*)?$/i;function s(e,t){if(t!==`auto`)return t;let n=Array.isArray(e)?e[0]:e;return o.test(n)?`image`:`video`}function c(e,t,n,r,i,a,o,s){let c=!!i,l=typeof i==`object`?i:{},u=l.style??`brighten`,d=c&&u!==`scatter`,f=c&&u===`scatter`,p=l.scatterChars??`->o`,m=l.trailLen??15,h=l.trailDecay??10,g=l.duration??1,_=l.radius??(u===`scatter`?.05:.08),v=l.brightness??2,y=!!a,b=typeof a==`object`?a:{},x=b.style??`ripple`,S=y&&x!==`spread`,C=y&&x===`spread`,w=b.brightness??1.1,T=b.speed??2,E=b.spreadExpandDuration??1.5,D=b.spreadSpeed??7.5,ee=!!o,O=typeof o==`object`?o:{},k=O.type??`random`,A=O.duration??.4,te=Math.max(20,Math.min(350,Math.round(e))),ne=Math.max(0,Math.min(2,t)),j=Math.max(0,Math.min(2,n)),M=Math.max(0,Math.min(1,r));A=Math.max(.1,Math.min(4,A)),m=Math.max(0,Math.min(30,Math.round(m))),h=Math.max(1,Math.min(15,h)),g=Math.max(.1,Math.min(4,g)),_=Math.max(.03,Math.min(.2,_)),v=Math.max(.2,Math.min(5,v)),w=Math.max(1.05,Math.min(2,w)),T=Math.max(.5,Math.min(4,T)),E=Math.max(.5,Math.min(5,E)),D=Math.max(.5,Math.min(10,D));let N=s===void 0?1/0:Math.max(1,Math.min(4,s)),P;return P=ee?k===`diagonal`?1:k===`radial`?2:3:0,{numCols:te,brightness:ne,saturation:j,bgOpacity:M,mouseEnabled:c,mouseStyle:u,brightenEnabled:d,scatterEnabled:f,scatterChars:p,trailLen:m,trailDecay:h,duration:g,mouseRadius:_,mouseBrightness:v,clickEnabled:S,clickBrightness:w,clickSpeed:T,spreadEnabled:C,spreadExpandDuration:E,spreadSpeed:D,revealEnabled:ee,revealType:k,revealDuration:A,revealEffectFlag:P,maxDpr:N}}function l(e,t,n){let r=e.createShader(t);if(!r)throw Error(`Failed to create shader`);return e.shaderSource(r,n),e.compileShader(r),e.getShaderParameter(r,e.COMPILE_STATUS)?r:(console.log(e.getShaderInfoLog(r)),e.deleteShader(r),null)}function u(e,t,n){let r=e.createProgram();return e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(console.log(e.getProgramInfoLog(r)),e.deleteProgram(r),null)}var d=`#version 300 es
2
2
 
3
3
  in vec2 a_position;
4
4
 
@@ -282,4 +282,4 @@ void main() {
282
282
  }
283
283
 
284
284
  fragCharInd = uvec4(bestChar, 0u, 0u, 0u);
285
- }`;function m(e){let t=l(e,e.VERTEX_SHADER,d),n=l(e,e.FRAGMENT_SHADER,f);if(!t||!n)return null;let r=u(e,t,n);if(!r)return null;let i=new Float32Array([1,1,-1,1,1,-1,-1,-1,-1,1,1,-1]),a=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,a),e.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW);let o=e.getAttribLocation(r,`a_position`);e.vertexAttribPointer(o,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(o),e.useProgram(r);let s=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);let c=e.getUniformLocation(r,`u_texture`);e.uniform1i(c,0);let m=e.createTexture();e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,m),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let h=e.getUniformLocation(r,`u_atlas`);e.uniform1i(h,1);let g=e.createTexture();e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,g),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let _=l(e,e.FRAGMENT_SHADER,p);if(!_)return null;let v=u(e,t,_);if(!v)return null;e.useProgram(v),e.uniform1i(e.getUniformLocation(v,`u_texture`),0),e.uniform1i(e.getUniformLocation(v,`u_charVectors`),2);let y=e.getUniformLocation(v,`u_resolution`),b=e.getUniformLocation(v,`u_cellsize`),x=e.getUniformLocation(v,`u_circleN`),S=e.getUniformLocation(v,`u_numCharsInt`),C=e.getUniformLocation(v,`u_shapeExponent`),w=e.getUniformLocation(v,`u_cropOffset`),T=e.getUniformLocation(v,`u_cropScale`),E=e.getUniformLocation(v,`u_gridOffset`),D=e.createTexture();e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_2D,D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let O=e.createFramebuffer(),k=e.createTexture();e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_2D,k),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let A=e.createTexture();e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,A),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let j=e.createTexture();return e.activeTexture(e.TEXTURE6),e.bindTexture(e.TEXTURE_2D,j),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.useProgram(r),e.uniform1i(e.getUniformLocation(r,`u_fboTexture`),3),e.uniform1i(e.getUniformLocation(r,`u_scatterAtlas`),4),e.uniform1i(e.getUniformLocation(r,`u_scatterStateTexture`),5),e.uniform1i(e.getUniformLocation(r,`u_spreadStateTexture`),6),{program:r,pass1Program:v,buffer:a,vertShader:t,fragShader:n,pass1FragShader:_,texture:s,atlasTexture:m,charVectorsTexture:g,fboTexture:D,fbo:O,scatterAtlasTexture:k,scatterStateTexture:A,spreadStateTexture:j,p1ResLoc:y,p1CellsizeLoc:b,p1CircleNLoc:x,p1NumCharsLoc:S,p1ExponentLoc:C,p1CropOffsetLoc:w,p1CropScaleLoc:T,p1GridOffsetLoc:E,revealEffectFlagLoc:e.getUniformLocation(r,`u_revealEffectFlag`),mouseEffectFlagLoc:e.getUniformLocation(r,`u_mouseEffect`),clickEffectFlagLoc:e.getUniformLocation(r,`u_clickEffect`),shapeMatchingLoc:e.getUniformLocation(r,`u_shapeMatching`),revealProgressLoc:e.getUniformLocation(r,`u_revealProgress`),brightnessLoc:e.getUniformLocation(r,`u_brightness`),saturationLoc:e.getUniformLocation(r,`u_saturation`),bgOpacityLoc:e.getUniformLocation(r,`u_bgOpacity`),mouseBrightnessLoc:e.getUniformLocation(r,`u_mouseBrightness`),mousePositionsLoc:e.getUniformLocation(r,`u_mousePositions`),mouseLifeFracsLoc:e.getUniformLocation(r,`u_mouseLifeFracs`),mouseRadiusLoc:e.getUniformLocation(r,`u_mouseRadius`),ripplePositionsLoc:e.getUniformLocation(r,`u_ripplePositions`),rippleRadiiLoc:e.getUniformLocation(r,`u_rippleRadii`),rippleBrightnessesLoc:e.getUniformLocation(r,`u_rippleBrightnesses`),scatterEffectFlagLoc:e.getUniformLocation(r,`u_scatterEffect`),scatterNumCharsLoc:e.getUniformLocation(r,`u_scatterNumChars`),spreadEffectFlagLoc:e.getUniformLocation(r,`u_spreadEffect`),videoModeLoc:e.getUniformLocation(r,`u_videoMode`),resLoc:e.getUniformLocation(r,`u_resolution`),sizeLoc:e.getUniformLocation(r,`u_cellsize`),numLoc:e.getUniformLocation(r,`u_numChars`),gridSizeLoc:e.getUniformLocation(r,`u_gridSize`),cropOffsetLoc:e.getUniformLocation(r,`u_cropOffset`),cropScaleLoc:e.getUniformLocation(r,`u_cropScale`),gridOffsetLoc:e.getUniformLocation(r,`u_gridOffset`)}}function h({scatterEnabledRef:e,mouseRadiusRef:t,durationRef:n,scatterCharsRef:r}){let i=new Uint8Array,a=new Float32Array,o=new Float32Array,s=new Uint8Array,c=null,l=null,u=0,d=0,f=-1,p=()=>Math.floor(Math.random()*r.current.length),m=0,h=0,g=1,_=1,v=0,y=0,b=null;return{setup(e,t,n,r,f,p,x,S){m=t,h=n,g=r,_=f,v=p,y=x,b=S;let C=t*n;i=new Uint8Array(C),a=new Float32Array(C),o=new Float32Array(C),s=new Uint8Array(C),c=null,l=null,u=0,d=0,e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,S),e.texImage2D(e.TEXTURE_2D,0,e.R8UI,t,n,0,e.RED_INTEGER,e.UNSIGNED_BYTE,i)},handleMouseMove(t,n,r){e.current&&(l=c,c={x:t,y:n,t:r})},handleMouseLeave(){c=null,l=null,u=0,d=0},reset(e){i.fill(0),b&&m>0&&(e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,b),e.texSubImage2D(e.TEXTURE_2D,0,0,0,m,h,e.RED_INTEGER,e.UNSIGNED_BYTE,i))},tick(r,x){if(!e.current||m===0||h===0)return;let S=performance.now(),C=f<0?0:Math.min(.1,(S-f)/1e3);f=S;let w=Math.min(x.width,x.height)*t.current,T=!1;if(c&&S-c.t<80){if(l){let e=(c.t-l.t)/1e3;if(e>0&&e<.2){let t=(c.x-l.x)/e,n=(c.y-l.y)/e;u=u*.7+t*.3,d=d*.7+n*.3}}else u=0,d=0;Math.hypot(u,d)>g*2&&(T=!0)}else u*=.6,d*=.6;if(s.fill(0),T&&c&&w>0){let e=c.x,t=c.y,n=Math.max(0,Math.floor((e-v-w)/g)),r=Math.min(m-1,Math.floor((e-v+w)/g)),l=Math.max(0,Math.floor((t-y-w)/_)),u=Math.min(h-1,Math.floor((t-y+w)/_));for(let c=l;c<=u;c++)for(let l=n;l<=r;l++){let n=v+(l+.5)*g,r=y+(c+.5)*_;if(Math.hypot(n-e,r-t)>w)continue;let u=c*m+l;s[u]=1,i[u]===0&&(i[u]=1+p(),o[u]=.5+Math.random()*2),a[u]=1}}let E=n.current;if(C>0)for(let e=0;e<h;e++)for(let t=0;t<m;t++){let n=e*m+t;if(i[n]===0||s[n])continue;let r=t>0?i[n-1]!==0:!1,c=t<m-1?i[n+1]!==0:!1,l=e>0?i[n-m]!==0:!1,u=e<h-1?i[n+m]!==0:!1,d=(!r||!c||!l||!u?5:1)*o[n]/E;a[n]-=d*C,a[n]<=0&&(i[n]=0)}r.activeTexture(r.TEXTURE5),r.bindTexture(r.TEXTURE_2D,b),r.texSubImage2D(r.TEXTURE_2D,0,0,0,m,h,r.RED_INTEGER,r.UNSIGNED_BYTE,i)}}}function g({brightenEnabledRef:e,trailLenRef:t,durationRef:n,trailDecayRef:r}){let i=[];return{handleMouseMove(n,r,a){e.current&&(i.push({x:n,y:r,t:a}),i.length>t.current&&i.shift())},tick(a,o,s){if(!e.current)return;let c=performance.now(),l=new Float32Array(t.current*2),u=new Float32Array(t.current);for(let e=0;e<i.length;e++){let t=c-i[e].t,a=Math.max(0,1-t/(n.current*1e3))**r.current;l[e*2]=i[e].x,l[e*2+1]=i[e].y,u[e]=a}a.uniform2fv(o,l),a.uniform1fv(s,u)}}}var _=10;function v({clickEnabledRef:e,clickSpeedRef:t,clickBrightnessRef:n,pixelScaleRef:r}){let i=[];return{handleClick(t,n){if(!e.current)return;let r=n.getBoundingClientRect(),a=(t.clientX-r.left)*(n.width/r.width),o=(t.clientY-r.top)*(n.height/r.height);i.push({x:a,y:o,t:performance.now()}),i.length>_&&i.shift()},tick(a,o,s,c,l){if(!e.current)return;let u=performance.now(),d=Math.hypot(o.width,o.height),f=t.current*r.current,p=new Float32Array(_*2),m=new Float32Array(_),h=new Float32Array(_);for(;i.length>0&&(u-i[0].t)*f>=d;)i.shift();for(let e=0;e<i.length;e++){let t=(u-i[e].t)*f,r=t/d,a=1+(n.current-1)*(1-r**2);p[e*2]=i[e].x,p[e*2+1]=i[e].y,m[e]=t,h[e]=a}a.uniform2fv(s,p),a.uniform1fv(c,m),a.uniform1fv(l,h)}}}function y({spreadEnabledRef:e,scatterCharsRef:t,spreadExpandDurationRef:n,spreadSpeedRef:r}){let i=new Uint8Array,a=new Uint8Array,o=0,s=0,c=1,l=1,u=0,d=0,f=null,p=-1,m=-1,h=()=>Math.floor(Math.random()*t.current.length),g=[[-1,0],[1,0],[0,-1],[0,1]];return{setup(e,t,n,r,h,g,_,v){o=t,s=n,c=r,l=h,u=g,d=_,f=v;let y=t*n;i=new Uint8Array(y),a=new Uint8Array(y),m=-1,p=-1,e.activeTexture(e.TEXTURE6),e.bindTexture(e.TEXTURE_2D,v),e.texImage2D(e.TEXTURE_2D,0,e.R8UI,t,n,0,e.RED_INTEGER,e.UNSIGNED_BYTE,i)},handleClick(t,r){if(!e.current||o===0)return;let f=r.getBoundingClientRect(),p=(t.clientX-f.left)*(r.width/f.width),g=(t.clientY-f.top)*(r.height/f.height),_=Math.floor((p-u)/c),v=Math.floor((g-d)/l);if(_<0||_>=o||v<0||v>=s)return;let y=v*o+_;i[y]=1+h(),a[y]=1,m=performance.now()+n.current*1e3},tick(t){if(!e.current||o===0||s===0)return;let n=performance.now(),c=p<0?0:Math.min(.1,(n-p)/1e3);p=n;let l=m>0&&n<m;if(!l&&m>0){for(let e=0;e<i.length;e++)a[e]===1&&(a[e]=2);m=-1}if(c>0)for(let e=0;e<s;e++)for(let t=0;t<o;t++){let n=e*o+t;if(a[n]!==0){if(l&&a[n]===1)for(let[n,l]of g){let u=e+n,d=t+l;if(u<0||u>=s||d<0||d>=o)continue;let f=u*o+d;a[f]===0&&Math.random()<r.current*c&&(i[f]=1+h(),a[f]=1)}else if(a[n]===2)for(let[l,u]of g){let d=e+l,f=t+u;if(d<0||d>=s||f<0||f>=o||i[d*o+f]===0){Math.random()<r.current*c&&(i[n]=0,a[n]=0);break}}}}t.activeTexture(t.TEXTURE6),t.bindTexture(t.TEXTURE_2D,f),t.texSubImage2D(t.TEXTURE_2D,0,0,0,o,s,t.RED_INTEGER,t.UNSIGNED_BYTE,i)}}}function b(e,t){let n=0,r=0,i=!1,a=null,o=()=>{let e=window.devicePixelRatio||1;t({width:Math.round(n*e),height:Math.round(r*e),cssWidth:n,cssHeight:r})},s=()=>{a?.();let e=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),t=()=>{i||(o(),s())};e.addEventListener(`change`,t,{once:!0}),a=()=>e.removeEventListener(`change`,t)},c=new ResizeObserver(e=>{let i=e[0],a=i.contentBoxSize?.[0];n=a?a.inlineSize:i.contentRect.width,r=a?a.blockSize:i.contentRect.height;let s=i.devicePixelContentBoxSize?.[0];s?t({width:s.inlineSize,height:s.blockSize,cssWidth:n,cssHeight:r}):o()});try{c.observe(e,{box:`device-pixel-content-box`})}catch{c.observe(e),s()}return()=>{i=!0,c.disconnect(),a?.()}}function x({src:e,mediaType:r=`auto`,videoMode:o=!1,numColsRaw:l=250,brightnessRaw:u=1,saturationRaw:d=1,bgOpacityRaw:f=.3,revealEffect:p=!1,chars:_=a,mouseEffect:x=!0,clickEffect:S=!0,charMode:C=`shape`,className:w,cropFocus:T=`center`,maxDpr:E}){let D=(0,t.useRef)(null),O=(0,t.useRef)(null),k=(0,t.useRef)(null),A=(0,t.useRef)(null),j=(0,t.useRef)(null),ee=(0,t.useRef)(null),{numCols:M,brightness:N,saturation:P,bgOpacity:F,mouseEnabled:I,mouseStyle:L,brightenEnabled:R,scatterEnabled:z,scatterChars:B,trailLen:V,trailDecay:H,duration:U,mouseRadius:W,mouseBrightness:te,clickEnabled:ne,clickBrightness:G,clickSpeed:K,spreadEnabled:q,spreadExpandDuration:J,spreadSpeed:Y,revealEnabled:re,revealDuration:ie,revealEffectFlag:ae,maxDpr:X}=c(l,u,d,f,x,S,p,E),oe=s(e,r)===`image`,se=(0,t.useRef)(N),ce=(0,t.useRef)(P),le=(0,t.useRef)(F),ue=(0,t.useRef)(I),Z=(0,t.useRef)(L),de=(0,t.useRef)(R),fe=(0,t.useRef)(z),pe=(0,t.useRef)(te),me=(0,t.useRef)(W),he=(0,t.useRef)(V),ge=(0,t.useRef)(H),_e=(0,t.useRef)(U),Q=(0,t.useRef)(B),ve=(0,t.useRef)(ne),ye=(0,t.useRef)(G),be=(0,t.useRef)(K),xe=(0,t.useRef)(q),Se=(0,t.useRef)(J),Ce=(0,t.useRef)(Y),we=(0,t.useRef)(M),Te=(0,t.useRef)(o),Ee=(0,t.useRef)(T),De=(0,t.useRef)(0),Oe=(0,t.useRef)(0),ke=(0,t.useRef)(X),Ae=(0,t.useRef)(1),je=(0,t.useRef)(null),Me=(0,t.useRef)(null);(0,t.useEffect)(()=>{se.current=N,ce.current=P,le.current=F,ue.current=I,Z.current=L,de.current=R,fe.current=z,pe.current=te,me.current=W,he.current=V,ge.current=H,_e.current=U,Q.current!==B&&$.current?(Q.current=B,Pe.current?.()):Q.current=B,ve.current=ne,ye.current=G,be.current=K,xe.current=q,Se.current=J,Ce.current=Y,we.current=M,Te.current=o},[N,P,F,I,L,R,z,te,W,V,H,U,B,ne,G,K,q,J,Y,M,o]);let Ne=(0,t.useRef)(null),Pe=(0,t.useRef)(null),Fe=(0,t.useRef)(null),$=(0,t.useRef)(!1);(0,t.useEffect)(()=>{$.current&&Ne.current?.(M)},[M]),(0,t.useEffect)(()=>{Ee.current=T,$.current&&De.current>0&&Fe.current?.(De.current,Oe.current)},[T]),(0,t.useEffect)(()=>{ke.current=X,$.current&&je.current&&Me.current?.(je.current)},[X]),(0,t.useEffect)(()=>{$.current=!1;let t=[],n=0,r=0,a=1,o=1,s=0,c=0,l=0,u=0,d=D.current;if(!d)return;let f=oe?k.current:O.current;if(!f)return;let p=f instanceof HTMLVideoElement?f:null,x=f instanceof HTMLImageElement?f:null,S=()=>f instanceof HTMLVideoElement?{width:f.videoWidth,height:f.videoHeight}:{width:f.naturalWidth,height:f.naturalHeight},w=d.getContext(`webgl2`);if(!w)return;w.pixelStorei(w.UNPACK_ALIGNMENT,1);let T=m(w);if(!T)return;let{program:E,pass1Program:M}=T;j.current=T.atlasTexture,ee.current=T.scatterAtlasTexture,w.uniform1i(T.shapeMatchingLoc,+(C===`shape`)),w.uniform1i(T.revealEffectFlagLoc,ae),w.uniform1f(T.revealProgressLoc,0);let N=h({scatterEnabledRef:fe,mouseRadiusRef:me,durationRef:_e,scatterCharsRef:Q}),P=g({brightenEnabledRef:de,trailLenRef:he,durationRef:_e,trailDecayRef:ge}),F=v({clickEnabledRef:ve,clickSpeedRef:be,clickBrightnessRef:ye,pixelScaleRef:Ae}),I=y({spreadEnabledRef:xe,scatterCharsRef:Q,spreadExpandDurationRef:Se,spreadSpeedRef:Ce}),L,R=-1,z=-1,B=0,V=Array.isArray(e)?e:[e],H=V.length>1,U=document.createElement(`canvas`),W=U.getContext(`2d`),te=e=>{let f=l>0?l:d.width,p=u>0?u:d.height;a=Math.max(1,Math.floor(f/e));let m=a*2;if(W.font=`${m}px monospace`,o=Math.max(1,Math.round(m*a/W.measureText(`M`).width)),n=Math.ceil(f/a),r=Math.ceil(p/o),s=Math.floor((f-n*a)/2),c=Math.floor((p-r*o)/2),w.viewport(0,0,d.width,d.height),w.useProgram(E),w.uniform2f(T.resLoc,d.width,d.height),w.uniform2f(T.gridOffsetLoc,s,c),w.useProgram(M),w.uniform2f(T.p1ResLoc,d.width,d.height),w.uniform2f(T.p1GridOffsetLoc,s,c),w.useProgram(E),N.setup(w,n,r,a,o,s,c,T.scatterStateTexture),I.setup(w,n,r,a,o,s,c,T.spreadStateTexture),C===`shape`){t=i(_,a,o);let e=t.length,s=new Float32Array(e*8);for(let n=0;n<e;n++){let r=t[n].vector;s[n*4+0]=r[0],s[n*4+1]=r[1],s[n*4+2]=r[2],s[n*4+3]=r[3],s[e*4+n*4+0]=r[4],s[e*4+n*4+1]=r[5]}w.activeTexture(w.TEXTURE2),w.bindTexture(w.TEXTURE_2D,T.charVectorsTexture),w.texImage2D(w.TEXTURE_2D,0,w.RGBA32F,e,2,0,w.RGBA,w.FLOAT,s),w.activeTexture(w.TEXTURE3),w.bindTexture(w.TEXTURE_2D,T.fboTexture),w.texImage2D(w.TEXTURE_2D,0,w.R8UI,n,r,0,w.RED_INTEGER,w.UNSIGNED_BYTE,null),w.bindFramebuffer(w.FRAMEBUFFER,T.fbo),w.framebufferTexture2D(w.FRAMEBUFFER,w.COLOR_ATTACHMENT0,w.TEXTURE_2D,T.fboTexture,0),w.bindFramebuffer(w.FRAMEBUFFER,null);let c=Math.max(1,Math.round(a/5));w.useProgram(M),w.uniform2f(T.p1CellsizeLoc,a,o),w.uniform1i(T.p1CircleNLoc,c),w.uniform1i(T.p1NumCharsLoc,e),w.uniform1f(T.p1ExponentLoc,2),w.useProgram(E)}w.uniform2f(T.gridSizeLoc,n,r),U.width=_.length*a,U.height=o,W.font=`${o}px monospace`,W.fillStyle=`black`,W.fillRect(0,0,_.length*a,o),W.fillStyle=`white`,W.textBaseline=`top`;for(let e=0;e<_.length;e++)W.fillText(_[e],e*a,0);w.activeTexture(w.TEXTURE1),w.bindTexture(w.TEXTURE_2D,j.current),w.texImage2D(w.TEXTURE_2D,0,w.RGBA,w.RGBA,w.UNSIGNED_BYTE,U),w.uniform1f(T.numLoc,_.length),w.uniform2f(T.sizeLoc,a,o),ne()},ne=()=>{let e=Q.current;U.width=e.length*a,U.height=o,W.fillStyle=`black`,W.fillRect(0,0,U.width,o),W.fillStyle=`white`,W.textBaseline=`top`,W.font=`${o}px monospace`;for(let t=0;t<e.length;t++)W.fillText(e[t],t*a,0);w.activeTexture(w.TEXTURE4),w.bindTexture(w.TEXTURE_2D,ee.current),w.texImage2D(w.TEXTURE_2D,0,w.RGBA,w.RGBA,w.UNSIGNED_BYTE,U),w.uniform1f(T.scatterNumCharsLoc,e.length),N.reset(w)};Ne.current=te,Pe.current=ne;let G=(e,t)=>{l=Math.round(e),u=Math.round(t),De.current=l,Oe.current=u,d.width=l,d.height=u,te(we.current);let n=S(),r=n.width/n.height,i=d.width/d.height,a=1,o=1,s=0,c=0;if(i>r)o=r/i,c=(1-o)/2;else{a=i/r;let e=Ee.current,t=e===`left`?.25:e===`right`?.75:.5;s=Math.max(0,Math.min(1-a,t-a/2))}w.uniform2f(T.cropOffsetLoc,s,c),w.uniform2f(T.cropScaleLoc,a,o),w.useProgram(M),w.uniform2f(T.p1CropOffsetLoc,s,c),w.uniform2f(T.p1CropScaleLoc,a,o),w.useProgram(E)};Fe.current=G;let K=e=>{je.current=e;let t=Math.min(1,ke.current/(window.devicePixelRatio||1)),n=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));Ae.current=e.cssWidth>0?n/e.cssWidth:1,G(n,r)};Me.current=K;let q=e=>{if(!ue.current)return;let t=d.getBoundingClientRect(),n=(e.clientX-t.left)*(d.width/t.width),r=(e.clientY-t.top)*(d.height/t.height),i=performance.now();P.handleMouseMove(n,r,i),N.handleMouseMove(n,r,i)};d.addEventListener(`mousemove`,q);let J=()=>N.handleMouseLeave();d.addEventListener(`mouseleave`,J);let Y=e=>{F.handleClick(e,d),I.handleClick(e,d)};d.addEventListener(`click`,Y);let X=()=>{if(w.uniform1i(T.videoModeLoc,+!!Te.current),w.uniform1f(T.brightnessLoc,se.current),w.uniform1f(T.saturationLoc,ce.current),w.uniform1f(T.bgOpacityLoc,le.current),w.uniform1i(T.mouseEffectFlagLoc,+!!de.current),w.uniform1i(T.scatterEffectFlagLoc,+!!fe.current),w.uniform1i(T.clickEffectFlagLoc,+!!ve.current),w.uniform1i(T.spreadEffectFlagLoc,+!!xe.current),w.uniform1f(T.mouseBrightnessLoc,pe.current),w.uniform1f(T.mouseRadiusLoc,Math.min(d.width,d.height)*me.current),re){let e=z<0?0:Math.min(1,(performance.now()-z)/(ie*1e3));w.uniform1f(T.revealProgressLoc,e)}$.current&&p&&p.currentTime!=R&&p.readyState>=2&&(w.activeTexture(w.TEXTURE0),w.bindTexture(w.TEXTURE_2D,T.texture),w.texSubImage2D(w.TEXTURE_2D,0,0,0,w.RGBA,w.UNSIGNED_BYTE,p),R=p.currentTime),P.tick(w,T.mousePositionsLoc,T.mouseLifeFracsLoc),N.tick(w,d),F.tick(w,d,T.ripplePositionsLoc,T.rippleRadiiLoc,T.rippleBrightnessesLoc),I.tick(w),C===`shape`&&(w.bindFramebuffer(w.FRAMEBUFFER,T.fbo),w.viewport(0,0,n,r),w.useProgram(M),w.drawArrays(w.TRIANGLES,0,6),w.bindFramebuffer(w.FRAMEBUFFER,null),w.viewport(0,0,d.width,d.height),w.useProgram(E)),w.drawArrays(w.TRIANGLES,0,6),L=requestAnimationFrame(X)},Z=()=>{let e=A.current,t=je.current;if(t&&t.width>0&&t.height>0)K(t);else{let t=window.devicePixelRatio||1,n=S(),r=e.clientWidth||n.width,i=e.clientHeight||n.height;K({width:Math.round(r*t),height:Math.round(i*t),cssWidth:r,cssHeight:i})}w.activeTexture(w.TEXTURE0),w.bindTexture(w.TEXTURE_2D,T.texture),w.texImage2D(w.TEXTURE_2D,0,w.RGBA,w.RGBA,w.UNSIGNED_BYTE,f),p?.play(),z=performance.now(),$.current=!0,L=requestAnimationFrame(X)},Ie=()=>{p&&(B=(B+1)%V.length,p.src=V[B],p.load(),p.addEventListener(`canplay`,()=>p.play(),{once:!0}))},Le=A.current?b(A.current,e=>{je.current=e,$.current&&e.width>0&&e.height>0&&K(e)}):()=>{};return p?(p.addEventListener(`loadeddata`,Z,{once:!0}),H&&p.addEventListener(`ended`,Ie),p.readyState>=2&&p.currentSrc.endsWith(V[0])?Z():p.currentSrc.endsWith(V[0])||p.load()):x&&(x.complete&&x.naturalWidth>0?Z():x.addEventListener(`load`,Z,{once:!0})),()=>{Le(),Ne.current=null,Pe.current=null,Fe.current=null,Me.current=null,$.current=!1,cancelAnimationFrame(L),p?(p.removeEventListener(`loadeddata`,Z),H&&p.removeEventListener(`ended`,Ie)):x?.removeEventListener(`load`,Z),d.removeEventListener(`mousemove`,q),d.removeEventListener(`mouseleave`,J),d.removeEventListener(`click`,Y),w.deleteTexture(T.texture),w.deleteTexture(T.charVectorsTexture),w.deleteFramebuffer(T.fbo),w.deleteTexture(T.fboTexture),w.deleteBuffer(T.buffer),w.deleteShader(T.vertShader),w.deleteShader(T.fragShader),w.deleteShader(T.pass1FragShader),w.deleteProgram(E),w.deleteProgram(M),w.deleteTexture(j.current),w.deleteTexture(ee.current),w.deleteTexture(T.scatterStateTexture),w.deleteTexture(T.spreadStateTexture)}},[e,C,_,ae,ie,re,oe]);let Ie=Array.isArray(e)?e[0]:e;return(0,n.jsxs)(`div`,{ref:A,className:w,style:{height:`100%`,width:`100%`},children:[oe?(0,n.jsx)(`img`,{ref:k,src:Ie,alt:``,style:{display:`none`}}):(0,n.jsx)(`video`,{ref:O,muted:!0,playsInline:!0,autoPlay:!0,loop:!Array.isArray(e)||e.length===1,style:{display:`none`},children:(0,n.jsx)(`source`,{src:Ie,type:`video/mp4`})}),(0,n.jsx)(`canvas`,{ref:D,style:{width:`100%`,height:`100%`,display:`block`}})]})}e.VideoAscii=x});
285
+ }`;function m(e){let t=l(e,e.VERTEX_SHADER,d),n=l(e,e.FRAGMENT_SHADER,f);if(!t||!n)return null;let r=u(e,t,n);if(!r)return null;let i=new Float32Array([1,1,-1,1,1,-1,-1,-1,-1,1,1,-1]),a=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,a),e.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW);let o=e.getAttribLocation(r,`a_position`);e.vertexAttribPointer(o,2,e.FLOAT,!1,0,0),e.enableVertexAttribArray(o),e.useProgram(r);let s=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);let c=e.getUniformLocation(r,`u_texture`);e.uniform1i(c,0);let m=e.createTexture();e.activeTexture(e.TEXTURE1),e.bindTexture(e.TEXTURE_2D,m),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let h=e.getUniformLocation(r,`u_atlas`);e.uniform1i(h,1);let g=e.createTexture();e.activeTexture(e.TEXTURE2),e.bindTexture(e.TEXTURE_2D,g),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let _=l(e,e.FRAGMENT_SHADER,p);if(!_)return null;let v=u(e,t,_);if(!v)return null;e.useProgram(v),e.uniform1i(e.getUniformLocation(v,`u_texture`),0),e.uniform1i(e.getUniformLocation(v,`u_charVectors`),2);let y=e.getUniformLocation(v,`u_resolution`),b=e.getUniformLocation(v,`u_cellsize`),x=e.getUniformLocation(v,`u_circleN`),S=e.getUniformLocation(v,`u_numCharsInt`),C=e.getUniformLocation(v,`u_shapeExponent`),w=e.getUniformLocation(v,`u_cropOffset`),T=e.getUniformLocation(v,`u_cropScale`),E=e.getUniformLocation(v,`u_gridOffset`),D=e.createTexture();e.activeTexture(e.TEXTURE3),e.bindTexture(e.TEXTURE_2D,D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let ee=e.createFramebuffer(),O=e.createTexture();e.activeTexture(e.TEXTURE4),e.bindTexture(e.TEXTURE_2D,O),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let k=e.createTexture();e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,k),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);let A=e.createTexture();return e.activeTexture(e.TEXTURE6),e.bindTexture(e.TEXTURE_2D,A),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.useProgram(r),e.uniform1i(e.getUniformLocation(r,`u_fboTexture`),3),e.uniform1i(e.getUniformLocation(r,`u_scatterAtlas`),4),e.uniform1i(e.getUniformLocation(r,`u_scatterStateTexture`),5),e.uniform1i(e.getUniformLocation(r,`u_spreadStateTexture`),6),{program:r,pass1Program:v,buffer:a,vertShader:t,fragShader:n,pass1FragShader:_,texture:s,atlasTexture:m,charVectorsTexture:g,fboTexture:D,fbo:ee,scatterAtlasTexture:O,scatterStateTexture:k,spreadStateTexture:A,p1ResLoc:y,p1CellsizeLoc:b,p1CircleNLoc:x,p1NumCharsLoc:S,p1ExponentLoc:C,p1CropOffsetLoc:w,p1CropScaleLoc:T,p1GridOffsetLoc:E,revealEffectFlagLoc:e.getUniformLocation(r,`u_revealEffectFlag`),mouseEffectFlagLoc:e.getUniformLocation(r,`u_mouseEffect`),clickEffectFlagLoc:e.getUniformLocation(r,`u_clickEffect`),shapeMatchingLoc:e.getUniformLocation(r,`u_shapeMatching`),revealProgressLoc:e.getUniformLocation(r,`u_revealProgress`),brightnessLoc:e.getUniformLocation(r,`u_brightness`),saturationLoc:e.getUniformLocation(r,`u_saturation`),bgOpacityLoc:e.getUniformLocation(r,`u_bgOpacity`),mouseBrightnessLoc:e.getUniformLocation(r,`u_mouseBrightness`),mousePositionsLoc:e.getUniformLocation(r,`u_mousePositions`),mouseLifeFracsLoc:e.getUniformLocation(r,`u_mouseLifeFracs`),mouseRadiusLoc:e.getUniformLocation(r,`u_mouseRadius`),ripplePositionsLoc:e.getUniformLocation(r,`u_ripplePositions`),rippleRadiiLoc:e.getUniformLocation(r,`u_rippleRadii`),rippleBrightnessesLoc:e.getUniformLocation(r,`u_rippleBrightnesses`),scatterEffectFlagLoc:e.getUniformLocation(r,`u_scatterEffect`),scatterNumCharsLoc:e.getUniformLocation(r,`u_scatterNumChars`),spreadEffectFlagLoc:e.getUniformLocation(r,`u_spreadEffect`),videoModeLoc:e.getUniformLocation(r,`u_videoMode`),resLoc:e.getUniformLocation(r,`u_resolution`),sizeLoc:e.getUniformLocation(r,`u_cellsize`),numLoc:e.getUniformLocation(r,`u_numChars`),gridSizeLoc:e.getUniformLocation(r,`u_gridSize`),cropOffsetLoc:e.getUniformLocation(r,`u_cropOffset`),cropScaleLoc:e.getUniformLocation(r,`u_cropScale`),gridOffsetLoc:e.getUniformLocation(r,`u_gridOffset`)}}function h({scatterEnabledRef:e,mouseRadiusRef:t,durationRef:n,scatterCharsRef:r}){let i=new Uint8Array,a=new Float32Array,o=new Float32Array,s=new Uint8Array,c=null,l=null,u=0,d=0,f=-1,p=()=>Math.floor(Math.random()*r.current.length),m=0,h=0,g=1,_=1,v=0,y=0,b=null;return{setup(e,t,n,r,f,p,x,S){m=t,h=n,g=r,_=f,v=p,y=x,b=S;let C=t*n;i=new Uint8Array(C),a=new Float32Array(C),o=new Float32Array(C),s=new Uint8Array(C),c=null,l=null,u=0,d=0,e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,S),e.texImage2D(e.TEXTURE_2D,0,e.R8UI,t,n,0,e.RED_INTEGER,e.UNSIGNED_BYTE,i)},handleMouseMove(t,n,r){e.current&&(l=c,c={x:t,y:n,t:r})},handleMouseLeave(){c=null,l=null,u=0,d=0},reset(e){i.fill(0),b&&m>0&&(e.activeTexture(e.TEXTURE5),e.bindTexture(e.TEXTURE_2D,b),e.texSubImage2D(e.TEXTURE_2D,0,0,0,m,h,e.RED_INTEGER,e.UNSIGNED_BYTE,i))},tick(r,x){if(!e.current||m===0||h===0)return;let S=performance.now(),C=f<0?0:Math.min(.1,(S-f)/1e3);f=S;let w=Math.min(x.width,x.height)*t.current,T=!1;if(c&&S-c.t<80){if(l){let e=(c.t-l.t)/1e3;if(e>0&&e<.2){let t=(c.x-l.x)/e,n=(c.y-l.y)/e;u=u*.7+t*.3,d=d*.7+n*.3}}else u=0,d=0;Math.hypot(u,d)>g*2&&(T=!0)}else u*=.6,d*=.6;if(s.fill(0),T&&c&&w>0){let e=c.x,t=c.y,n=Math.max(0,Math.floor((e-v-w)/g)),r=Math.min(m-1,Math.floor((e-v+w)/g)),l=Math.max(0,Math.floor((t-y-w)/_)),u=Math.min(h-1,Math.floor((t-y+w)/_));for(let c=l;c<=u;c++)for(let l=n;l<=r;l++){let n=v+(l+.5)*g,r=y+(c+.5)*_;if(Math.hypot(n-e,r-t)>w)continue;let u=c*m+l;s[u]=1,i[u]===0&&(i[u]=1+p(),o[u]=.5+Math.random()*2),a[u]=1}}let E=n.current;if(C>0)for(let e=0;e<h;e++)for(let t=0;t<m;t++){let n=e*m+t;if(i[n]===0||s[n])continue;let r=t>0?i[n-1]!==0:!1,c=t<m-1?i[n+1]!==0:!1,l=e>0?i[n-m]!==0:!1,u=e<h-1?i[n+m]!==0:!1,d=(!r||!c||!l||!u?5:1)*o[n]/E;a[n]-=d*C,a[n]<=0&&(i[n]=0)}r.activeTexture(r.TEXTURE5),r.bindTexture(r.TEXTURE_2D,b),r.texSubImage2D(r.TEXTURE_2D,0,0,0,m,h,r.RED_INTEGER,r.UNSIGNED_BYTE,i)}}}function g({brightenEnabledRef:e,trailLenRef:t,durationRef:n,trailDecayRef:r}){let i=[];return{handleMouseMove(n,r,a){e.current&&(i.push({x:n,y:r,t:a}),i.length>t.current&&i.shift())},tick(a,o,s){if(!e.current)return;let c=performance.now(),l=new Float32Array(t.current*2),u=new Float32Array(t.current);for(let e=0;e<i.length;e++){let t=c-i[e].t,a=Math.max(0,1-t/(n.current*1e3))**r.current;l[e*2]=i[e].x,l[e*2+1]=i[e].y,u[e]=a}a.uniform2fv(o,l),a.uniform1fv(s,u)}}}var _=10;function v({clickEnabledRef:e,clickSpeedRef:t,clickBrightnessRef:n,pixelScaleRef:r}){let i=[];return{handleClick(t,n){if(!e.current)return;let r=n.getBoundingClientRect(),a=(t.clientX-r.left)*(n.width/r.width),o=(t.clientY-r.top)*(n.height/r.height);i.push({x:a,y:o,t:performance.now()}),i.length>_&&i.shift()},tick(a,o,s,c,l){if(!e.current)return;let u=performance.now(),d=Math.hypot(o.width,o.height),f=t.current*r.current,p=new Float32Array(_*2),m=new Float32Array(_),h=new Float32Array(_);for(;i.length>0&&(u-i[0].t)*f>=d;)i.shift();for(let e=0;e<i.length;e++){let t=(u-i[e].t)*f,r=t/d,a=1+(n.current-1)*(1-r**2);p[e*2]=i[e].x,p[e*2+1]=i[e].y,m[e]=t,h[e]=a}a.uniform2fv(s,p),a.uniform1fv(c,m),a.uniform1fv(l,h)}}}function y({spreadEnabledRef:e,scatterCharsRef:t,spreadExpandDurationRef:n,spreadSpeedRef:r}){let i=new Uint8Array,a=new Uint8Array,o=0,s=0,c=1,l=1,u=0,d=0,f=null,p=-1,m=-1,h=()=>Math.floor(Math.random()*t.current.length),g=[[-1,0],[1,0],[0,-1],[0,1]];return{setup(e,t,n,r,h,g,_,v){o=t,s=n,c=r,l=h,u=g,d=_,f=v;let y=t*n;i=new Uint8Array(y),a=new Uint8Array(y),m=-1,p=-1,e.activeTexture(e.TEXTURE6),e.bindTexture(e.TEXTURE_2D,v),e.texImage2D(e.TEXTURE_2D,0,e.R8UI,t,n,0,e.RED_INTEGER,e.UNSIGNED_BYTE,i)},handleClick(t,r){if(!e.current||o===0)return;let f=r.getBoundingClientRect(),p=(t.clientX-f.left)*(r.width/f.width),g=(t.clientY-f.top)*(r.height/f.height),_=Math.floor((p-u)/c),v=Math.floor((g-d)/l);if(_<0||_>=o||v<0||v>=s)return;let y=v*o+_;i[y]=1+h(),a[y]=1,m=performance.now()+n.current*1e3},tick(t){if(!e.current||o===0||s===0)return;let n=performance.now(),c=p<0?0:Math.min(.1,(n-p)/1e3);p=n;let l=m>0&&n<m;if(!l&&m>0){for(let e=0;e<i.length;e++)a[e]===1&&(a[e]=2);m=-1}if(c>0)for(let e=0;e<s;e++)for(let t=0;t<o;t++){let n=e*o+t;if(a[n]!==0){if(l&&a[n]===1)for(let[n,l]of g){let u=e+n,d=t+l;if(u<0||u>=s||d<0||d>=o)continue;let f=u*o+d;a[f]===0&&Math.random()<r.current*c&&(i[f]=1+h(),a[f]=1)}else if(a[n]===2)for(let[l,u]of g){let d=e+l,f=t+u;if(d<0||d>=s||f<0||f>=o||i[d*o+f]===0){Math.random()<r.current*c&&(i[n]=0,a[n]=0);break}}}}t.activeTexture(t.TEXTURE6),t.bindTexture(t.TEXTURE_2D,f),t.texSubImage2D(t.TEXTURE_2D,0,0,0,o,s,t.RED_INTEGER,t.UNSIGNED_BYTE,i)}}}function b(e,t){let n=0,r=0,i=!1,a=null,o=()=>{let e=window.devicePixelRatio||1;t({width:Math.round(n*e),height:Math.round(r*e),cssWidth:n,cssHeight:r})},s=()=>{a?.();let e=window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),t=()=>{i||(o(),s())};e.addEventListener(`change`,t,{once:!0}),a=()=>e.removeEventListener(`change`,t)},c=new ResizeObserver(e=>{let i=e[0],a=i.contentBoxSize?.[0];n=a?a.inlineSize:i.contentRect.width,r=a?a.blockSize:i.contentRect.height;let s=i.devicePixelContentBoxSize?.[0];s?t({width:s.inlineSize,height:s.blockSize,cssWidth:n,cssHeight:r}):o()});try{c.observe(e,{box:`device-pixel-content-box`})}catch{c.observe(e),s()}return()=>{i=!0,c.disconnect(),a?.()}}function x({src:e,mediaType:r=`auto`,media:o,videoMode:l=!1,numColsRaw:u=250,brightnessRaw:d=1,saturationRaw:f=1,bgOpacityRaw:p=.3,revealEffect:_=!1,chars:x=a,mouseEffect:S=!0,clickEffect:C=!0,charMode:w=`shape`,className:T,cropFocus:E=`center`,maxDpr:D}){let ee=(0,t.useRef)(null),O=(0,t.useRef)(null),k=(0,t.useRef)(null),A=(0,t.useRef)(null),te=(0,t.useRef)(null),ne=(0,t.useRef)(null),{numCols:j,brightness:M,saturation:N,bgOpacity:P,mouseEnabled:F,mouseStyle:I,brightenEnabled:re,scatterEnabled:L,scatterChars:R,trailLen:z,trailDecay:B,duration:V,mouseRadius:H,mouseBrightness:ie,clickEnabled:U,clickBrightness:W,clickSpeed:G,spreadEnabled:K,spreadExpandDuration:q,spreadSpeed:J,revealEnabled:ae,revealDuration:oe,revealEffectFlag:se,maxDpr:Y}=c(u,d,f,p,S,C,_,D),X=e===void 0,ce=e!==void 0&&s(e,r)===`image`,le=(0,t.useRef)(M),ue=(0,t.useRef)(N),de=(0,t.useRef)(P),fe=(0,t.useRef)(F),Z=(0,t.useRef)(I),pe=(0,t.useRef)(re),me=(0,t.useRef)(L),he=(0,t.useRef)(ie),ge=(0,t.useRef)(H),_e=(0,t.useRef)(z),ve=(0,t.useRef)(B),ye=(0,t.useRef)(V),Q=(0,t.useRef)(R),be=(0,t.useRef)(U),xe=(0,t.useRef)(W),Se=(0,t.useRef)(G),Ce=(0,t.useRef)(K),we=(0,t.useRef)(q),Te=(0,t.useRef)(J),Ee=(0,t.useRef)(j),De=(0,t.useRef)(l),Oe=(0,t.useRef)(E),ke=(0,t.useRef)(0),Ae=(0,t.useRef)(0),je=(0,t.useRef)(Y),Me=(0,t.useRef)(1),Ne=(0,t.useRef)(null),Pe=(0,t.useRef)(null);(0,t.useEffect)(()=>{le.current=M,ue.current=N,de.current=P,fe.current=F,Z.current=I,pe.current=re,me.current=L,he.current=ie,ge.current=H,_e.current=z,ve.current=B,ye.current=V,Q.current!==R&&$.current?(Q.current=R,Ie.current?.()):Q.current=R,be.current=U,xe.current=W,Se.current=G,Ce.current=K,we.current=q,Te.current=J,Ee.current=j,De.current=l},[M,N,P,F,I,re,L,ie,H,z,B,V,R,U,W,G,K,q,J,j,l]);let Fe=(0,t.useRef)(null),Ie=(0,t.useRef)(null),Le=(0,t.useRef)(null),$=(0,t.useRef)(!1);(0,t.useEffect)(()=>{$.current&&Fe.current?.(j)},[j]),(0,t.useEffect)(()=>{Oe.current=E,$.current&&ke.current>0&&Le.current?.(ke.current,Ae.current)},[E]),(0,t.useEffect)(()=>{je.current=Y,$.current&&Ne.current&&Pe.current?.(Ne.current)},[Y]),(0,t.useEffect)(()=>{$.current=!1;let t=[],n=0,r=0,a=1,s=1,c=0,l=0,u=0,d=0,f=ee.current;if(!f)return;let p=X?o:ce?k.current:O.current;if(!p)return;let _=p instanceof HTMLVideoElement?p:null,S=p instanceof HTMLImageElement?p:null,C=()=>p instanceof HTMLVideoElement?{width:p.videoWidth,height:p.videoHeight}:{width:p.naturalWidth,height:p.naturalHeight},T=f.getContext(`webgl2`);if(!T)return;T.pixelStorei(T.UNPACK_ALIGNMENT,1);let E=m(T);if(!E)return;let{program:D,pass1Program:j}=E;te.current=E.atlasTexture,ne.current=E.scatterAtlasTexture,T.uniform1i(E.shapeMatchingLoc,+(w===`shape`)),T.uniform1i(E.revealEffectFlagLoc,se),T.uniform1f(E.revealProgressLoc,0);let M=h({scatterEnabledRef:me,mouseRadiusRef:ge,durationRef:ye,scatterCharsRef:Q}),N=g({brightenEnabledRef:pe,trailLenRef:_e,durationRef:ye,trailDecayRef:ve}),P=v({clickEnabledRef:be,clickSpeedRef:Se,clickBrightnessRef:xe,pixelScaleRef:Me}),F=y({spreadEnabledRef:Ce,scatterCharsRef:Q,spreadExpandDurationRef:we,spreadSpeedRef:Te}),I=0,re=-1,L=-1,R=0,z=Array.isArray(e)?e:e===void 0?[]:[e],B=z.length>1,V=document.createElement(`canvas`),H=V.getContext(`2d`),ie=e=>{let o=u>0?u:f.width,p=d>0?d:f.height;a=Math.max(1,Math.floor(o/e));let m=a*2;if(H.font=`${m}px monospace`,s=Math.max(1,Math.round(m*a/H.measureText(`M`).width)),n=Math.ceil(o/a),r=Math.ceil(p/s),c=Math.floor((o-n*a)/2),l=Math.floor((p-r*s)/2),T.viewport(0,0,f.width,f.height),T.useProgram(D),T.uniform2f(E.resLoc,f.width,f.height),T.uniform2f(E.gridOffsetLoc,c,l),T.useProgram(j),T.uniform2f(E.p1ResLoc,f.width,f.height),T.uniform2f(E.p1GridOffsetLoc,c,l),T.useProgram(D),M.setup(T,n,r,a,s,c,l,E.scatterStateTexture),F.setup(T,n,r,a,s,c,l,E.spreadStateTexture),w===`shape`){t=i(x,a,s);let e=t.length,o=new Float32Array(e*8);for(let n=0;n<e;n++){let r=t[n].vector;o[n*4+0]=r[0],o[n*4+1]=r[1],o[n*4+2]=r[2],o[n*4+3]=r[3],o[e*4+n*4+0]=r[4],o[e*4+n*4+1]=r[5]}T.activeTexture(T.TEXTURE2),T.bindTexture(T.TEXTURE_2D,E.charVectorsTexture),T.texImage2D(T.TEXTURE_2D,0,T.RGBA32F,e,2,0,T.RGBA,T.FLOAT,o),T.activeTexture(T.TEXTURE3),T.bindTexture(T.TEXTURE_2D,E.fboTexture),T.texImage2D(T.TEXTURE_2D,0,T.R8UI,n,r,0,T.RED_INTEGER,T.UNSIGNED_BYTE,null),T.bindFramebuffer(T.FRAMEBUFFER,E.fbo),T.framebufferTexture2D(T.FRAMEBUFFER,T.COLOR_ATTACHMENT0,T.TEXTURE_2D,E.fboTexture,0),T.bindFramebuffer(T.FRAMEBUFFER,null);let c=Math.max(1,Math.round(a/5));T.useProgram(j),T.uniform2f(E.p1CellsizeLoc,a,s),T.uniform1i(E.p1CircleNLoc,c),T.uniform1i(E.p1NumCharsLoc,e),T.uniform1f(E.p1ExponentLoc,2),T.useProgram(D)}T.uniform2f(E.gridSizeLoc,n,r),V.width=x.length*a,V.height=s,H.font=`${s}px monospace`,H.fillStyle=`black`,H.fillRect(0,0,x.length*a,s),H.fillStyle=`white`,H.textBaseline=`top`;for(let e=0;e<x.length;e++)H.fillText(x[e],e*a,0);T.activeTexture(T.TEXTURE1),T.bindTexture(T.TEXTURE_2D,te.current),T.texImage2D(T.TEXTURE_2D,0,T.RGBA,T.RGBA,T.UNSIGNED_BYTE,V),T.uniform1f(E.numLoc,x.length),T.uniform2f(E.sizeLoc,a,s),U()},U=()=>{let e=Q.current;V.width=e.length*a,V.height=s,H.fillStyle=`black`,H.fillRect(0,0,V.width,s),H.fillStyle=`white`,H.textBaseline=`top`,H.font=`${s}px monospace`;for(let t=0;t<e.length;t++)H.fillText(e[t],t*a,0);T.activeTexture(T.TEXTURE4),T.bindTexture(T.TEXTURE_2D,ne.current),T.texImage2D(T.TEXTURE_2D,0,T.RGBA,T.RGBA,T.UNSIGNED_BYTE,V),T.uniform1f(E.scatterNumCharsLoc,e.length),M.reset(T)};Fe.current=ie,Ie.current=U;let W=(e,t)=>{u=Math.round(e),d=Math.round(t),ke.current=u,Ae.current=d,f.width=u,f.height=d,ie(Ee.current);let n=C(),r=n.width/n.height,i=f.width/f.height,a=1,o=1,s=0,c=0;if(i>r)o=r/i,c=(1-o)/2;else{a=i/r;let e=Oe.current,t=e===`left`?.25:e===`right`?.75:.5;s=Math.max(0,Math.min(1-a,t-a/2))}T.uniform2f(E.cropOffsetLoc,s,c),T.uniform2f(E.cropScaleLoc,a,o),T.useProgram(j),T.uniform2f(E.p1CropOffsetLoc,s,c),T.uniform2f(E.p1CropScaleLoc,a,o),T.useProgram(D)};Le.current=W;let G=e=>{Ne.current=e;let t=Math.min(1,je.current/(window.devicePixelRatio||1)),n=Math.max(1,Math.round(e.width*t)),r=Math.max(1,Math.round(e.height*t));Me.current=e.cssWidth>0?n/e.cssWidth:1,W(n,r)};Pe.current=G;let K=e=>{if(!fe.current)return;let t=f.getBoundingClientRect(),n=(e.clientX-t.left)*(f.width/t.width),r=(e.clientY-t.top)*(f.height/t.height),i=performance.now();N.handleMouseMove(n,r,i),M.handleMouseMove(n,r,i)};f.addEventListener(`mousemove`,K);let q=()=>M.handleMouseLeave();f.addEventListener(`mouseleave`,q);let J=e=>{P.handleClick(e,f),F.handleClick(e,f)};f.addEventListener(`click`,J);let Y=()=>{if(T.uniform1i(E.videoModeLoc,+!!De.current),T.uniform1f(E.brightnessLoc,le.current),T.uniform1f(E.saturationLoc,ue.current),T.uniform1f(E.bgOpacityLoc,de.current),T.uniform1i(E.mouseEffectFlagLoc,+!!pe.current),T.uniform1i(E.scatterEffectFlagLoc,+!!me.current),T.uniform1i(E.clickEffectFlagLoc,+!!be.current),T.uniform1i(E.spreadEffectFlagLoc,+!!Ce.current),T.uniform1f(E.mouseBrightnessLoc,he.current),T.uniform1f(E.mouseRadiusLoc,Math.min(f.width,f.height)*ge.current),ae){let e=L<0?0:Math.min(1,(performance.now()-L)/(oe*1e3));T.uniform1f(E.revealProgressLoc,e)}$.current&&_&&_.currentTime!=re&&_.readyState>=2&&(T.activeTexture(T.TEXTURE0),T.bindTexture(T.TEXTURE_2D,E.texture),T.texSubImage2D(T.TEXTURE_2D,0,0,0,T.RGBA,T.UNSIGNED_BYTE,_),re=_.currentTime),N.tick(T,E.mousePositionsLoc,E.mouseLifeFracsLoc),M.tick(T,f),P.tick(T,f,E.ripplePositionsLoc,E.rippleRadiiLoc,E.rippleBrightnessesLoc),F.tick(T),w===`shape`&&(T.bindFramebuffer(T.FRAMEBUFFER,E.fbo),T.viewport(0,0,n,r),T.useProgram(j),T.drawArrays(T.TRIANGLES,0,6),T.bindFramebuffer(T.FRAMEBUFFER,null),T.viewport(0,0,f.width,f.height),T.useProgram(D)),T.drawArrays(T.TRIANGLES,0,6),I=requestAnimationFrame(Y)},Z=()=>{let e=A.current,t=Ne.current;if(t&&t.width>0&&t.height>0)G(t);else{let t=window.devicePixelRatio||1,n=C(),r=e.clientWidth||n.width,i=e.clientHeight||n.height;G({width:Math.round(r*t),height:Math.round(i*t),cssWidth:r,cssHeight:i})}T.activeTexture(T.TEXTURE0),T.bindTexture(T.TEXTURE_2D,E.texture),T.texImage2D(T.TEXTURE_2D,0,T.RGBA,T.RGBA,T.UNSIGNED_BYTE,p),_?.play(),L=performance.now(),$.current=!0,cancelAnimationFrame(I),I=requestAnimationFrame(Y)},Re=()=>{_&&(R=(R+1)%z.length,_.src=z[R],_.load(),_.addEventListener(`canplay`,()=>_.play(),{once:!0}))},ze=A.current?b(A.current,e=>{Ne.current=e,$.current&&e.width>0&&e.height>0&&G(e)}):()=>{};return _?(_.addEventListener(`loadeddata`,Z,{once:!X}),B&&_.addEventListener(`ended`,Re),X?_.readyState>=2&&Z():_.readyState>=2&&_.currentSrc.endsWith(z[0])?Z():_.currentSrc.endsWith(z[0])||_.load()):S&&(S.complete&&S.naturalWidth>0?Z():S.addEventListener(`load`,Z,{once:!0})),()=>{ze(),Fe.current=null,Ie.current=null,Le.current=null,Pe.current=null,$.current=!1,cancelAnimationFrame(I),_?(_.removeEventListener(`loadeddata`,Z),B&&_.removeEventListener(`ended`,Re)):S?.removeEventListener(`load`,Z),f.removeEventListener(`mousemove`,K),f.removeEventListener(`mouseleave`,q),f.removeEventListener(`click`,J),T.deleteTexture(E.texture),T.deleteTexture(E.charVectorsTexture),T.deleteFramebuffer(E.fbo),T.deleteTexture(E.fboTexture),T.deleteBuffer(E.buffer),T.deleteShader(E.vertShader),T.deleteShader(E.fragShader),T.deleteShader(E.pass1FragShader),T.deleteProgram(D),T.deleteProgram(j),T.deleteTexture(te.current),T.deleteTexture(ne.current),T.deleteTexture(E.scatterStateTexture),T.deleteTexture(E.spreadStateTexture)}},[e,o,X,w,x,se,oe,ae,ce]);let Re=Array.isArray(e)?e[0]:e;return(0,n.jsxs)(`div`,{ref:A,className:T,style:{height:`100%`,width:`100%`},children:[X?null:ce?(0,n.jsx)(`img`,{ref:k,src:Re,alt:``,style:{display:`none`}}):(0,n.jsx)(`video`,{ref:O,muted:!0,playsInline:!0,autoPlay:!0,loop:!Array.isArray(e)||e.length===1,style:{display:`none`},children:(0,n.jsx)(`source`,{src:Re,type:`video/mp4`})}),(0,n.jsx)(`canvas`,{ref:ee,style:{width:`100%`,height:`100%`,display:`block`}})]})}e.VideoAscii=x});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-video-ascii",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "description": "React component that renders videos and images as ASCII animations using WebGL2.",
6
6
  "author": "Lucas Jin",