@nous-research/ui 0.14.2 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +227 -0
- package/README.md +24 -4
- package/dist/fonts.js +1 -0
- package/dist/hooks/use-capped-frame.js +1 -0
- package/dist/hooks/use-css-var-dims.js +1 -0
- package/dist/hooks/use-gpu-tier.js +1 -0
- package/dist/hooks/use-render-loop.js +1 -0
- package/dist/hooks/use-smooth-controls.js +1 -0
- package/dist/index.js +1 -0
- package/dist/ui/basic-page.js +1 -0
- package/dist/ui/components/animated-count.js +1 -0
- package/dist/ui/components/ascii.js +1 -0
- package/dist/ui/components/badge.js +2 -1
- package/dist/ui/components/badges/nous-girl.js +1 -0
- package/dist/ui/components/blend-mode.js +1 -0
- package/dist/ui/components/blink.js +1 -0
- package/dist/ui/components/button.js +2 -1
- package/dist/ui/components/checkbox.js +1 -0
- package/dist/ui/components/command-block.js +4 -3
- package/dist/ui/components/cursor.js +1 -0
- package/dist/ui/components/dropdown-menu.js +1 -0
- package/dist/ui/components/fit-text/index.js +1 -0
- package/dist/ui/components/graphs/bar-chart.js +1 -0
- package/dist/ui/components/graphs/index.js +1 -0
- package/dist/ui/components/graphs/line-chart.js +1 -0
- package/dist/ui/components/graphs/utils.js +1 -0
- package/dist/ui/components/grid/index.js +1 -0
- package/dist/ui/components/hover-bg.js +1 -0
- package/dist/ui/components/icons/arrow.js +1 -0
- package/dist/ui/components/icons/check.js +1 -0
- package/dist/ui/components/icons/chevron.js +1 -0
- package/dist/ui/components/icons/discord.js +1 -0
- package/dist/ui/components/icons/eye.js +1 -0
- package/dist/ui/components/icons/gear.js +1 -0
- package/dist/ui/components/icons/github.js +1 -0
- package/dist/ui/components/icons/hamburger.js +1 -0
- package/dist/ui/components/icons/heart.js +1 -0
- package/dist/ui/components/icons/index.js +1 -0
- package/dist/ui/components/icons/link.js +1 -0
- package/dist/ui/components/icons/minus.js +1 -0
- package/dist/ui/components/icons/search.js +1 -0
- package/dist/ui/components/image-distortion.js +1 -0
- package/dist/ui/components/leva-client.js +1 -0
- package/dist/ui/components/list-item.js +3 -2
- package/dist/ui/components/modal/index.js +1 -0
- package/dist/ui/components/modal/modal.css +1 -1
- package/dist/ui/components/overlays/blend-modes.js +1 -0
- package/dist/ui/components/overlays/glitch.js +1 -0
- package/dist/ui/components/overlays/greys.js +1 -0
- package/dist/ui/components/overlays/index.js +1 -0
- package/dist/ui/components/overlays/lens-layers.js +1 -0
- package/dist/ui/components/overlays/lens.js +1 -0
- package/dist/ui/components/overlays/noise.js +1 -0
- package/dist/ui/components/overlays/vignette.js +1 -0
- package/dist/ui/components/poster.js +1 -0
- package/dist/ui/components/progress.js +1 -0
- package/dist/ui/components/scene-canvas.js +1 -0
- package/dist/ui/components/scramble.js +1 -0
- package/dist/ui/components/segmented.js +5 -4
- package/dist/ui/components/select.js +1 -0
- package/dist/ui/components/selection-switcher.js +1 -0
- package/dist/ui/components/shader.js +1 -0
- package/dist/ui/components/socials.js +1 -0
- package/dist/ui/components/spinner.js +1 -0
- package/dist/ui/components/stats.js +2 -1
- package/dist/ui/components/switch.js +1 -0
- package/dist/ui/components/tabs.js +4 -3
- package/dist/ui/components/terminal-demo.js +2 -1
- package/dist/ui/components/theme-toggle.js +1 -0
- package/dist/ui/components/tier-card.js +2 -1
- package/dist/ui/components/tv.js +1 -0
- package/dist/ui/components/typography/h1.js +1 -0
- package/dist/ui/components/typography/h2.js +1 -0
- package/dist/ui/components/typography/index.js +1 -0
- package/dist/ui/components/typography/legend.js +1 -0
- package/dist/ui/components/typography/small.js +1 -0
- package/dist/ui/components/watchlist.js +2 -1
- package/dist/ui/footer.js +1 -0
- package/dist/ui/globals.css +33 -1
- package/dist/ui/header.js +1 -0
- package/dist/ui/layout-wrapper.js +2 -1
- package/dist/utils/color.js +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/poly.js +1 -0
- package/package.json +4 -2
- package/src/assets/filler-bg0.webp +0 -0
- package/src/assets.d.ts +38 -0
- package/src/fonts/Collapse-Bold.woff2 +0 -0
- package/src/fonts/Collapse-BoldItalic.woff2 +0 -0
- package/src/fonts/Collapse-Italic.woff2 +0 -0
- package/src/fonts/Collapse-Light.woff2 +0 -0
- package/src/fonts/Collapse-LightItalic.woff2 +0 -0
- package/src/fonts/Collapse-Regular.woff2 +0 -0
- package/src/fonts/Collapse-Thin.woff2 +0 -0
- package/src/fonts/Collapse-ThinItalic.woff2 +0 -0
- package/src/fonts/Mondwest-Regular.woff2 +0 -0
- package/src/fonts/Neuebit-Bold.woff2 +0 -0
- package/src/fonts/RulesCompressed-Medium.woff2 +0 -0
- package/src/fonts/RulesCompressed-Regular.woff2 +0 -0
- package/src/fonts/RulesExpanded-Bold.woff2 +0 -0
- package/src/fonts/RulesExpanded-Regular.woff2 +0 -0
- package/src/fonts.ts +6 -0
- package/src/hooks/use-capped-frame.ts +18 -0
- package/src/hooks/use-css-var-dims.ts +39 -0
- package/src/hooks/use-gpu-tier.ts +165 -0
- package/src/hooks/use-render-loop.ts +121 -0
- package/src/hooks/use-smooth-controls.ts +318 -0
- package/src/index.ts +109 -0
- package/src/ui/basic-page.tsx +34 -0
- package/src/ui/build.css +4 -0
- package/src/ui/components/animated-count.stories.tsx +67 -0
- package/src/ui/components/animated-count.tsx +168 -0
- package/src/ui/components/ascii.stories.tsx +30 -0
- package/src/ui/components/ascii.tsx +110 -0
- package/src/ui/components/badge.stories.tsx +31 -0
- package/src/ui/components/badge.tsx +60 -0
- package/src/ui/components/badges/nous-girl.tsx +52 -0
- package/src/ui/components/blend-mode.stories.tsx +33 -0
- package/src/ui/components/blend-mode.tsx +129 -0
- package/src/ui/components/blink.stories.tsx +32 -0
- package/src/ui/components/blink.tsx +21 -0
- package/src/ui/components/button.stories.tsx +68 -0
- package/src/ui/components/button.tsx +170 -0
- package/src/ui/components/checkbox.stories.tsx +113 -0
- package/src/ui/components/checkbox.tsx +36 -0
- package/src/ui/components/command-block.stories.tsx +52 -0
- package/src/ui/components/command-block.tsx +86 -0
- package/src/ui/components/cursor.tsx +115 -0
- package/src/ui/components/dropdown-menu.stories.tsx +52 -0
- package/src/ui/components/dropdown-menu.tsx +117 -0
- package/src/ui/components/fit-text/fit-text.css +42 -0
- package/src/ui/components/fit-text/index.stories.tsx +33 -0
- package/src/ui/components/fit-text/index.tsx +45 -0
- package/src/ui/components/graphs/bar-chart.tsx +153 -0
- package/src/ui/components/graphs/index.stories.tsx +64 -0
- package/src/ui/components/graphs/index.tsx +4 -0
- package/src/ui/components/graphs/line-chart.tsx +213 -0
- package/src/ui/components/graphs/utils.tsx +265 -0
- package/src/ui/components/grid/grid.css +79 -0
- package/src/ui/components/grid/index.tsx +19 -0
- package/src/ui/components/hover-bg.stories.tsx +29 -0
- package/src/ui/components/hover-bg.tsx +15 -0
- package/src/ui/components/icons/arrow.tsx +42 -0
- package/src/ui/components/icons/check.tsx +14 -0
- package/src/ui/components/icons/chevron.tsx +45 -0
- package/src/ui/components/icons/discord.tsx +16 -0
- package/src/ui/components/icons/eye.tsx +12 -0
- package/src/ui/components/icons/gear.tsx +51 -0
- package/src/ui/components/icons/github.tsx +16 -0
- package/src/ui/components/icons/hamburger.tsx +52 -0
- package/src/ui/components/icons/heart.tsx +12 -0
- package/src/ui/components/icons/index.ts +12 -0
- package/src/ui/components/icons/link.tsx +14 -0
- package/src/ui/components/icons/minus.tsx +14 -0
- package/src/ui/components/icons/search.tsx +28 -0
- package/src/ui/components/image-distortion.stories.tsx +120 -0
- package/src/ui/components/image-distortion.tsx +498 -0
- package/src/ui/components/leva-client.tsx +14 -0
- package/src/ui/components/list-item.stories.tsx +83 -0
- package/src/ui/components/list-item.tsx +37 -0
- package/src/ui/components/modal/index.stories.tsx +46 -0
- package/src/ui/components/modal/index.tsx +48 -0
- package/src/ui/components/modal/modal.css +36 -0
- package/src/ui/components/overlays/blend-modes.ts +13 -0
- package/src/ui/components/overlays/glitch.tsx +243 -0
- package/src/ui/components/overlays/greys.tsx +386 -0
- package/src/ui/components/overlays/index.tsx +47 -0
- package/src/ui/components/overlays/lens-layers.tsx +119 -0
- package/src/ui/components/overlays/lens.ts +91 -0
- package/src/ui/components/overlays/noise.tsx +174 -0
- package/src/ui/components/overlays/vignette.tsx +60 -0
- package/src/ui/components/poster.stories.tsx +513 -0
- package/src/ui/components/poster.tsx +411 -0
- package/src/ui/components/progress.stories.tsx +48 -0
- package/src/ui/components/progress.tsx +56 -0
- package/src/ui/components/scene-canvas.tsx +254 -0
- package/src/ui/components/scramble.stories.tsx +49 -0
- package/src/ui/components/scramble.tsx +95 -0
- package/src/ui/components/segmented.stories.tsx +101 -0
- package/src/ui/components/segmented.tsx +81 -0
- package/src/ui/components/select.stories.tsx +88 -0
- package/src/ui/components/select.tsx +267 -0
- package/src/ui/components/selection-switcher.tsx +44 -0
- package/src/ui/components/shader.tsx +83 -0
- package/src/ui/components/socials.tsx +42 -0
- package/src/ui/components/spinner.stories.tsx +101 -0
- package/src/ui/components/spinner.tsx +60 -0
- package/src/ui/components/stats.stories.tsx +24 -0
- package/src/ui/components/stats.tsx +53 -0
- package/src/ui/components/switch.stories.tsx +77 -0
- package/src/ui/components/switch.tsx +48 -0
- package/src/ui/components/tabs.stories.tsx +101 -0
- package/src/ui/components/tabs.tsx +66 -0
- package/src/ui/components/terminal-demo.stories.tsx +67 -0
- package/src/ui/components/terminal-demo.tsx +189 -0
- package/src/ui/components/theme-toggle.stories.tsx +47 -0
- package/src/ui/components/theme-toggle.tsx +66 -0
- package/src/ui/components/tier-card.stories.tsx +217 -0
- package/src/ui/components/tier-card.tsx +190 -0
- package/src/ui/components/tv.stories.tsx +37 -0
- package/src/ui/components/tv.tsx +257 -0
- package/src/ui/components/typography/h1.tsx +18 -0
- package/src/ui/components/typography/h2.tsx +18 -0
- package/src/ui/components/typography/index.tsx +54 -0
- package/src/ui/components/typography/legend.tsx +24 -0
- package/src/ui/components/typography/small.tsx +11 -0
- package/src/ui/components/watchlist.stories.tsx +33 -0
- package/src/ui/components/watchlist.tsx +105 -0
- package/src/ui/fonts.css +63 -0
- package/src/ui/footer.tsx +111 -0
- package/src/ui/globals.css +383 -0
- package/src/ui/header.tsx +398 -0
- package/src/ui/layout-wrapper.tsx +11 -0
- package/src/utils/color.ts +21 -0
- package/src/utils/index.ts +62 -0
- package/src/utils/poly.ts +26 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
4
|
+
import { createPortal } from 'react-dom'
|
|
5
|
+
|
|
6
|
+
import { cn } from '../../../utils'
|
|
7
|
+
|
|
8
|
+
export function Modal({
|
|
9
|
+
children,
|
|
10
|
+
className,
|
|
11
|
+
id,
|
|
12
|
+
trigger,
|
|
13
|
+
...props
|
|
14
|
+
}: ModalProps) {
|
|
15
|
+
const ref = useRef<HTMLDialogElement>(null)
|
|
16
|
+
const [mounted, setMounted] = useState(false)
|
|
17
|
+
|
|
18
|
+
useEffect(() => setMounted(true), [])
|
|
19
|
+
|
|
20
|
+
const open = useCallback(() => ref.current?.showModal(), [])
|
|
21
|
+
const close = useCallback(() => ref.current?.close(), [])
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
{trigger({ close, open })}
|
|
26
|
+
|
|
27
|
+
{mounted &&
|
|
28
|
+
createPortal(
|
|
29
|
+
<dialog
|
|
30
|
+
className={cn('modal', className)}
|
|
31
|
+
onClick={e => e.target === e.currentTarget && close()}
|
|
32
|
+
{...{ id, ref }}
|
|
33
|
+
{...props}
|
|
34
|
+
>
|
|
35
|
+
<div className="modal-body post">{children}</div>
|
|
36
|
+
</dialog>,
|
|
37
|
+
document.body
|
|
38
|
+
)}
|
|
39
|
+
</>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface ModalProps extends Omit<React.ComponentProps<'dialog'>, 'open'> {
|
|
44
|
+
trigger: (controls: {
|
|
45
|
+
close: () => void
|
|
46
|
+
open: () => void
|
|
47
|
+
}) => React.ReactNode
|
|
48
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.modal {
|
|
2
|
+
@apply bg-foreground-base text-background-base z-50 m-auto max-h-[85dvh] max-w-[90dvw] p-0 opacity-0 outline-none;
|
|
3
|
+
|
|
4
|
+
transition:
|
|
5
|
+
opacity 0.25s ease-out,
|
|
6
|
+
overlay 0.25s ease-out allow-discrete,
|
|
7
|
+
display 0.25s ease-out allow-discrete;
|
|
8
|
+
|
|
9
|
+
&::backdrop {
|
|
10
|
+
@apply bg-foreground-base/2 backdrop-blur-xs;
|
|
11
|
+
|
|
12
|
+
transition:
|
|
13
|
+
opacity 0.25s ease-out,
|
|
14
|
+
overlay 0.25s ease-out allow-discrete,
|
|
15
|
+
display 0.25s ease-out allow-discrete;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&[open] {
|
|
19
|
+
@apply opacity-100;
|
|
20
|
+
|
|
21
|
+
&::backdrop {
|
|
22
|
+
@apply opacity-100;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@starting-style {
|
|
27
|
+
&[open],
|
|
28
|
+
&[open]::backdrop {
|
|
29
|
+
@apply opacity-0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.modal-body {
|
|
35
|
+
@apply overflow-y-auto p-8 font-mono;
|
|
36
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react'
|
|
4
|
+
import * as THREE from 'three'
|
|
5
|
+
|
|
6
|
+
import { $gpuTier, useGpuTier } from '../../../hooks/use-gpu-tier'
|
|
7
|
+
import { runRenderLoop } from '../../../hooks/use-render-loop'
|
|
8
|
+
import { useSmoothControls } from '../../../hooks/use-smooth-controls'
|
|
9
|
+
import { cn } from '../../../utils'
|
|
10
|
+
|
|
11
|
+
import { BLEND_MODES } from './blend-modes'
|
|
12
|
+
|
|
13
|
+
const vert = /*glsl*/ `
|
|
14
|
+
varying vec2 vUv;
|
|
15
|
+
void main() {
|
|
16
|
+
vUv = uv;
|
|
17
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
const frag = /*glsl*/ `
|
|
22
|
+
uniform float uTime, uAlpha, uIntensity, uChroma, uSpeed, uSparsity;
|
|
23
|
+
uniform vec3 uColor;
|
|
24
|
+
varying vec2 vUv;
|
|
25
|
+
|
|
26
|
+
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
|
|
27
|
+
|
|
28
|
+
vec2 hash2(vec2 p) {
|
|
29
|
+
vec3 q = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
|
|
30
|
+
q += dot(q, q.yzx + 33.33);
|
|
31
|
+
return fract((q.xx + q.yz) * q.zy);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
float dither(vec2 p, float a) {
|
|
35
|
+
return step(mod(floor(p.x) + floor(p.y) * 2.0, 4.0) / 4.0, a);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void main() {
|
|
39
|
+
vec3 col = vec3(0.0);
|
|
40
|
+
float t = uTime * uSpeed;
|
|
41
|
+
float tSlow = floor(t / 3.0);
|
|
42
|
+
float dit = dither(gl_FragCoord.xy * 0.5, 0.7);
|
|
43
|
+
|
|
44
|
+
for (float i = 0.0; i < 6.0; i++) {
|
|
45
|
+
float seed = i * 137.3;
|
|
46
|
+
float epoch = floor((t + hash(vec2(seed, 77.7)) * 200.0) / (4.0 + hash(vec2(seed, 0.0)) * 6.0));
|
|
47
|
+
float life = fract((t + hash(vec2(seed, 77.7)) * 200.0) / (4.0 + hash(vec2(seed, 0.0)) * 6.0));
|
|
48
|
+
|
|
49
|
+
if (hash(vec2(epoch, seed)) > 1.0 - uSparsity * 0.7) continue;
|
|
50
|
+
|
|
51
|
+
vec2 center = vec2(hash(vec2(epoch, seed + 13.1)), hash(vec2(epoch, seed + 27.3)));
|
|
52
|
+
vec2 size = vec2(0.015 + hash(vec2(epoch, seed + 41.5)) * 0.08, 0.008 + hash(vec2(epoch, seed + 53.7)) * 0.04);
|
|
53
|
+
vec2 d = abs(vUv - center);
|
|
54
|
+
|
|
55
|
+
if (d.x < size.x && d.y < size.y) {
|
|
56
|
+
float fade = smoothstep(0.0, 0.05, life) * smoothstep(1.0, 0.95, life);
|
|
57
|
+
vec2 gUV = vUv + (hash2(vec2(epoch, seed + 200.0)) - 0.5) * 0.08 * uIntensity;
|
|
58
|
+
float shift = uChroma * 0.015 * (sin(t * 2.0 + hash(vec2(epoch, seed)) * 6.28) * 0.3 + 0.7);
|
|
59
|
+
|
|
60
|
+
col += uColor * vec3(
|
|
61
|
+
hash(gUV * 50.0 + vec2(shift, 0.0) + epoch),
|
|
62
|
+
hash(gUV * 50.0 + epoch),
|
|
63
|
+
hash(gUV * 50.0 - vec2(shift, 0.0) + epoch)
|
|
64
|
+
) * dither(gl_FragCoord.xy * 0.5, fade * 0.8 + 0.2) * uIntensity * 0.7;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (float i = 0.0; i < 12.0; i++) {
|
|
69
|
+
float seed = i * 211.7 + 1000.0;
|
|
70
|
+
float epoch = floor((t + hash(vec2(seed, 77.7)) * 150.0) / (3.0 + hash(vec2(seed, 0.0)) * 5.0));
|
|
71
|
+
float life = fract((t + hash(vec2(seed, 77.7)) * 150.0) / (3.0 + hash(vec2(seed, 0.0)) * 5.0));
|
|
72
|
+
|
|
73
|
+
if (hash(vec2(epoch, seed)) > 1.0 - uSparsity * 0.5) continue;
|
|
74
|
+
|
|
75
|
+
vec2 pos = vec2(hash(vec2(epoch, seed + 13.1)), hash(vec2(epoch, seed + 27.3)));
|
|
76
|
+
float px = 0.003 + hash(vec2(epoch, seed + 41.5)) * 0.008;
|
|
77
|
+
|
|
78
|
+
if (abs(vUv.x - pos.x) < px && abs(vUv.y - pos.y) < px) {
|
|
79
|
+
float fade = smoothstep(0.0, 0.1, life) * smoothstep(1.0, 0.9, life);
|
|
80
|
+
vec3 c = uColor;
|
|
81
|
+
float cs = hash(vec2(epoch, seed + 700.0));
|
|
82
|
+
|
|
83
|
+
if (cs < 0.2) c.r *= 1.8 * uChroma;
|
|
84
|
+
else if (cs < 0.4) c.b *= 1.8 * uChroma;
|
|
85
|
+
|
|
86
|
+
col += c * dither(gl_FragCoord.xy * 0.5, fade * 0.9) * uIntensity;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
float tearSize = 25.0 + uSparsity * 10.0;
|
|
91
|
+
float tearThresh = 0.85 + uSparsity * 0.1;
|
|
92
|
+
|
|
93
|
+
float hY = floor(vUv.y * tearSize);
|
|
94
|
+
if (step(tearThresh, hash(vec2(hY, tSlow))) > 0.0) {
|
|
95
|
+
float shift = (hash(vec2(hY, tSlow + 50.0)) - 0.5) * 0.25 * uIntensity;
|
|
96
|
+
col += uColor * step(0.4, hash(vec2(vUv.x + shift, hY + tSlow))) * dit * uIntensity * 0.5;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
float vX = floor(vUv.x * tearSize);
|
|
100
|
+
if (step(tearThresh, hash(vec2(vX, tSlow + 100.0))) > 0.0) {
|
|
101
|
+
float shift = (hash(vec2(vX, tSlow + 150.0)) - 0.5) * 0.25 * uIntensity;
|
|
102
|
+
col += uColor * step(0.4, hash(vec2(vX + tSlow, vUv.y + shift))) * dit * uIntensity * 0.5;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
gl_FragColor = vec4(col * uAlpha, max(col.r, max(col.g, col.b)) * uAlpha);
|
|
106
|
+
}
|
|
107
|
+
`
|
|
108
|
+
|
|
109
|
+
export function Glitch({ className, style }: GlitchProps) {
|
|
110
|
+
const gpuTier = useGpuTier()
|
|
111
|
+
|
|
112
|
+
const c = useSmoothControls(
|
|
113
|
+
'Effects/Glitch',
|
|
114
|
+
{
|
|
115
|
+
alpha: { max: 2, min: 0, step: 0.01, value: 0.25 },
|
|
116
|
+
blend: { options: BLEND_MODES, value: 'difference' },
|
|
117
|
+
chroma: { max: 3, min: 0, step: 0.01, value: 1.17 },
|
|
118
|
+
color: { value: '#ffe6cb' },
|
|
119
|
+
enabled: { value: true },
|
|
120
|
+
intensity: { max: 1, min: 0, step: 0.01, value: 0.59 },
|
|
121
|
+
sparsity: { max: 1, min: 0, step: 0.01, value: 0.21 },
|
|
122
|
+
speed: { max: 10, min: 0.1, step: 0.1, value: 1 }
|
|
123
|
+
},
|
|
124
|
+
{ collapsed: true }
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
const ref = useRef<HTMLCanvasElement>(null)
|
|
128
|
+
const cRef = useRef(c)
|
|
129
|
+
cRef.current = c
|
|
130
|
+
|
|
131
|
+
const enabled = c.enabled && gpuTier > 0
|
|
132
|
+
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (!ref.current || !enabled) {
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let renderer: THREE.WebGLRenderer
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
renderer = new THREE.WebGLRenderer({
|
|
142
|
+
alpha: true,
|
|
143
|
+
canvas: ref.current
|
|
144
|
+
})
|
|
145
|
+
} catch {
|
|
146
|
+
// See note in noise.tsx — eager gpu-tier detection should keep us
|
|
147
|
+
// out of here, but if the driver fails the renderer constructor
|
|
148
|
+
// anyway, downgrade so other overlays stop trying too.
|
|
149
|
+
$gpuTier.set(0)
|
|
150
|
+
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1)
|
|
155
|
+
const geo = new THREE.PlaneGeometry(2, 2)
|
|
156
|
+
const scene = new THREE.Scene()
|
|
157
|
+
|
|
158
|
+
const mat = new THREE.ShaderMaterial({
|
|
159
|
+
fragmentShader: frag,
|
|
160
|
+
transparent: true,
|
|
161
|
+
uniforms: {
|
|
162
|
+
uAlpha: { value: c.alpha },
|
|
163
|
+
uChroma: { value: c.chroma },
|
|
164
|
+
uColor: { value: new THREE.Color(c.color) },
|
|
165
|
+
uIntensity: { value: c.intensity },
|
|
166
|
+
uSparsity: { value: c.sparsity },
|
|
167
|
+
uSpeed: { value: c.speed },
|
|
168
|
+
uTime: { value: 0 }
|
|
169
|
+
},
|
|
170
|
+
vertexShader: vert
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
scene.add(new THREE.Mesh(geo, mat))
|
|
174
|
+
|
|
175
|
+
const resize = () => {
|
|
176
|
+
renderer.setSize(innerWidth, innerHeight)
|
|
177
|
+
// Cap DPR at 1.5 — at full retina (2x) the glitch shader is one
|
|
178
|
+
// of the heaviest fillrate consumers in the app, and the visual
|
|
179
|
+
// difference is tiny because it's a chromatic-noise effect.
|
|
180
|
+
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5))
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
resize()
|
|
184
|
+
window.addEventListener('resize', resize)
|
|
185
|
+
|
|
186
|
+
let time = 0
|
|
187
|
+
|
|
188
|
+
// gpu-tier 1 → ~10fps (legacy), gpu-tier 2 → ~30fps (was 60fps).
|
|
189
|
+
// Glitch is a background ambient effect; users won't notice 30 vs
|
|
190
|
+
// 60 but the GPU absolutely will.
|
|
191
|
+
const minIntervalMs = gpuTier === 1 ? 100 : 33
|
|
192
|
+
|
|
193
|
+
const dispose = runRenderLoop({
|
|
194
|
+
el: ref.current,
|
|
195
|
+
minIntervalMs,
|
|
196
|
+
onFrame: deltaSeconds => {
|
|
197
|
+
time += deltaSeconds
|
|
198
|
+
|
|
199
|
+
const v = cRef.current
|
|
200
|
+
|
|
201
|
+
mat.uniforms.uTime.value = time
|
|
202
|
+
mat.uniforms.uAlpha.value = v.alpha
|
|
203
|
+
mat.uniforms.uChroma.value = v.chroma
|
|
204
|
+
mat.uniforms.uIntensity.value = v.intensity
|
|
205
|
+
mat.uniforms.uSparsity.value = v.sparsity
|
|
206
|
+
mat.uniforms.uSpeed.value = v.speed
|
|
207
|
+
mat.uniforms.uColor.value.set(v.color)
|
|
208
|
+
|
|
209
|
+
renderer.render(scene, camera)
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
return () => {
|
|
214
|
+
window.removeEventListener('resize', resize)
|
|
215
|
+
dispose()
|
|
216
|
+
|
|
217
|
+
mat.dispose()
|
|
218
|
+
geo.dispose()
|
|
219
|
+
renderer.dispose()
|
|
220
|
+
}
|
|
221
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
222
|
+
}, [enabled, gpuTier])
|
|
223
|
+
|
|
224
|
+
if (!enabled) {
|
|
225
|
+
return null
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<canvas
|
|
230
|
+
className={cn('h-full w-full', className)}
|
|
231
|
+
ref={ref}
|
|
232
|
+
style={{
|
|
233
|
+
mixBlendMode: c.blend as React.CSSProperties['mixBlendMode'],
|
|
234
|
+
...style
|
|
235
|
+
}}
|
|
236
|
+
/>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
interface GlitchProps {
|
|
241
|
+
className?: string
|
|
242
|
+
style?: React.CSSProperties
|
|
243
|
+
}
|