motion-ui-skill 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -21
- package/SKILL.md +83 -9
- package/bin/index.mjs +2 -2
- package/bin/installer.mjs +6 -0
- package/catalog.json +1044 -139
- package/components/agents/thinking-states.tsx +156 -0
- package/components/buttons/aqua-button.tsx +145 -0
- package/components/buttons/ash-burst-button.tsx +528 -0
- package/components/buttons/brutal-button.tsx +68 -0
- package/components/buttons/chrome-button.tsx +444 -0
- package/components/buttons/click-powerup.tsx +203 -0
- package/components/buttons/command-button.tsx +226 -0
- package/components/buttons/confetti-button.tsx +132 -0
- package/components/buttons/cooldown-button.tsx +169 -0
- package/components/buttons/demonic-button.tsx +470 -0
- package/components/buttons/dither-button.tsx +192 -0
- package/components/buttons/doubt-button.tsx +240 -0
- package/components/buttons/evil-eye-button.tsx +563 -0
- package/components/buttons/frame-button.tsx +211 -0
- package/components/buttons/glitch-button.tsx +243 -0
- package/components/buttons/highlight-button.tsx +196 -0
- package/components/buttons/hold-button.tsx +245 -0
- package/components/buttons/minecraft-button.tsx +651 -0
- package/components/buttons/minimal-button.tsx +50 -0
- package/components/buttons/morph-status-button.tsx +264 -0
- package/components/buttons/movie-pass-button.tsx +205 -0
- package/components/buttons/realistic-switch.tsx +298 -0
- package/components/buttons/reveal-button.tsx +197 -0
- package/components/buttons/shiny-button.tsx +87 -0
- package/components/buttons/slide-to-detonate.tsx +444 -0
- package/components/buttons/sticky-button.tsx +184 -0
- package/components/buttons/thruster-button.tsx +920 -0
- package/components/buttons/troll-button.tsx +264 -0
- package/components/motion/banner-stacking.tsx +124 -0
- package/components/motion/delete-with-smoky-dissolve.tsx +145 -0
- package/components/motion/donut-chart.tsx +112 -0
- package/components/motion/drag-drop-with-physics.tsx +116 -0
- package/components/motion/dropdown-menu-morph.tsx +157 -0
- package/components/motion/get-pro-button.tsx +54 -0
- package/components/motion/image-open-tilt.tsx +79 -0
- package/components/motion/input-clear-with-dissolve.tsx +111 -0
- package/components/motion/learn-more-hover.tsx +71 -0
- package/components/motion/matrix-dot-loader.tsx +68 -0
- package/components/motion/organic-shimmer.tsx +49 -0
- package/components/motion/pro-gradient-text.tsx +46 -0
- package/components/motion/skeleton-loader-and-reveal.tsx +81 -0
- package/components/motion/spinner-to-check-morph.tsx +99 -0
- package/components/motion/spinning-counter.tsx +64 -0
- package/components/motion/text-morph.tsx +80 -0
- package/components/motion/texts-reveal.tsx +49 -0
- package/data/app-interface.csv +33 -0
- package/data/charts.csv +26 -0
- package/data/colors.csv +193 -0
- package/data/google-fonts.csv +1935 -0
- package/data/icons.csv +106 -0
- package/data/landing.csv +35 -0
- package/data/motion.csv +18 -0
- package/data/products.csv +193 -0
- package/data/react-performance.csv +45 -0
- package/data/stacks/angular.csv +51 -0
- package/data/stacks/astro.csv +54 -0
- package/data/stacks/avalonia.csv +57 -0
- package/data/stacks/flutter.csv +53 -0
- package/data/stacks/html-tailwind.csv +60 -0
- package/data/stacks/javafx.csv +76 -0
- package/data/stacks/jetpack-compose.csv +53 -0
- package/data/stacks/laravel.csv +51 -0
- package/data/stacks/nextjs.csv +62 -0
- package/data/stacks/nuxt-ui.csv +77 -0
- package/data/stacks/nuxtjs.csv +68 -0
- package/data/stacks/react-native.csv +52 -0
- package/data/stacks/react.csv +67 -0
- package/data/stacks/shadcn.csv +69 -0
- package/data/stacks/svelte.csv +56 -0
- package/data/stacks/swiftui.csv +51 -0
- package/data/stacks/threejs.csv +54 -0
- package/data/stacks/uno.csv +60 -0
- package/data/stacks/uwp.csv +56 -0
- package/data/stacks/vue.csv +50 -0
- package/data/stacks/winui.csv +60 -0
- package/data/stacks/wpf.csv +57 -0
- package/data/styles.csv +89 -0
- package/data/typography.csv +75 -0
- package/data/ui-reasoning.csv +193 -0
- package/data/ux-guidelines.csv +120 -0
- package/evals/catalog_eval.py +56 -0
- package/icons/annotations/loop-arrow.tsx +61 -0
- package/icons/brands/anthropic.tsx +26 -0
- package/icons/brands/apple.tsx +26 -0
- package/icons/brands/canva.tsx +26 -0
- package/icons/brands/claude-ai.tsx +26 -0
- package/icons/brands/discord.tsx +26 -0
- package/icons/brands/github.tsx +26 -0
- package/icons/brands/gmail.tsx +26 -0
- package/icons/brands/google.tsx +26 -0
- package/icons/brands/linkedin.tsx +29 -0
- package/icons/brands/microsoft.tsx +26 -0
- package/icons/brands/next-js.tsx +26 -0
- package/icons/brands/producthunt.tsx +26 -0
- package/icons/brands/react-js.tsx +29 -0
- package/icons/brands/shadcn-ui.tsx +26 -0
- package/icons/brands/tailwind-css.tsx +26 -0
- package/icons/brands/twitter.tsx +30 -0
- package/icons/brands/typescript.tsx +26 -0
- package/icons/brands/unsplash.tsx +27 -0
- package/icons/brands/vercel.tsx +26 -0
- package/icons/brands/whatsapp.tsx +26 -0
- package/package.json +9 -3
- package/prompts/install-motion-ui.md +17 -0
- package/references/agents/thinking-states.md +56 -0
- package/references/craft/aqua-button.md +53 -0
- package/references/craft/ash-burst-button.md +55 -0
- package/references/craft/brutal-button.md +52 -0
- package/references/craft/chrome-button.md +53 -0
- package/references/craft/click-powerup.md +53 -0
- package/references/craft/command-button.md +53 -0
- package/references/craft/confetti-button.md +54 -0
- package/references/craft/cooldown-button.md +54 -0
- package/references/craft/demonic-button.md +53 -0
- package/references/craft/dither-button.md +52 -0
- package/references/craft/doubt-button.md +53 -0
- package/references/craft/evil-eye-button.md +52 -0
- package/references/craft/frame-button.md +54 -0
- package/references/craft/glitch-button.md +52 -0
- package/references/craft/highlight-button.md +53 -0
- package/references/craft/hold-button.md +53 -0
- package/references/craft/minecraft-button.md +53 -0
- package/references/craft/minimal-button.md +52 -0
- package/references/craft/morph-status-button.md +53 -0
- package/references/craft/movie-pass-button.md +53 -0
- package/references/craft/realistic-switch.md +54 -0
- package/references/craft/reveal-button.md +53 -0
- package/references/craft/shiny-button.md +52 -0
- package/references/craft/slide-to-detonate.md +53 -0
- package/references/craft/sticky-button.md +54 -0
- package/references/craft/thruster-button.md +53 -0
- package/references/craft/troll-button.md +54 -0
- package/references/guides/design-intelligence.md +125 -0
- package/references/guides/interaction-transitions.md +56 -38
- package/references/guides/motion-polish-rules.md +75 -0
- package/references/guides/stack-best-practices.md +38 -0
- package/references/motion/banner-stacking.md +67 -0
- package/references/motion/delete-with-smoky-dissolve.md +60 -0
- package/references/motion/donut-chart.md +79 -0
- package/references/motion/drag-drop-with-physics.md +61 -0
- package/references/motion/dropdown-menu-morph.md +55 -0
- package/references/motion/get-pro-button.md +56 -0
- package/references/motion/image-open-tilt.md +60 -0
- package/references/motion/input-clear-with-dissolve.md +58 -0
- package/references/motion/learn-more-hover.md +56 -0
- package/references/motion/matrix-dot-loader.md +58 -0
- package/references/motion/organic-shimmer.md +63 -0
- package/references/motion/pro-gradient-text.md +57 -0
- package/references/motion/skeleton-loader-and-reveal.md +67 -0
- package/references/motion/spinner-to-check-morph.md +67 -0
- package/references/motion/spinning-counter.md +74 -0
- package/references/motion/text-morph.md +64 -0
- package/references/motion/texts-reveal.md +56 -0
- package/scripts/build_docs.py +39 -4
- package/scripts/core.py +993 -0
- package/scripts/design_system.py +1668 -0
- package/scripts/reasoning_contract.py +123 -0
- package/scripts/search.py +177 -0
- package/scripts/test_release.py +12 -0
- package/scripts/verify_skill.py +4 -4
- package/test/test_installer.mjs +133 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
|
|
6
|
+
export type ChromeTone = "auto" | "dark" | "light";
|
|
7
|
+
export type ChromeSize = "default" | "sm" | "icon";
|
|
8
|
+
|
|
9
|
+
export interface ChromeButtonProps
|
|
10
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
11
|
+
/** Label used when no children are provided. */
|
|
12
|
+
label?: React.ReactNode;
|
|
13
|
+
/** Follow the theme (dark face under `.dark`), or force a dark or light face. */
|
|
14
|
+
tone?: ChromeTone;
|
|
15
|
+
/** Pill, compact pill, or a round icon-only button. */
|
|
16
|
+
size?: ChromeSize;
|
|
17
|
+
/** Speed multiplier for the liquid metal flowing around the border. */
|
|
18
|
+
speed?: number;
|
|
19
|
+
/** Ripple the metal around the pointer and send a wave through it on press. */
|
|
20
|
+
interactive?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const VERTEX = `
|
|
24
|
+
attribute vec2 aPosition;
|
|
25
|
+
void main() {
|
|
26
|
+
gl_Position = vec4(aPosition, 0.0, 1.0);
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
// Liquid metal: bands of polished chrome travel around the ring (by angle
|
|
31
|
+
// from the center), wobbled by stacked cosines so they slosh like liquid.
|
|
32
|
+
// Shaded as broad silver with dark troughs and thin hot highlights. The canvas
|
|
33
|
+
// fills the whole button, but only the border ring shows around the face.
|
|
34
|
+
const FRAGMENT = `
|
|
35
|
+
precision highp float;
|
|
36
|
+
uniform vec2 uRes;
|
|
37
|
+
uniform float uTime;
|
|
38
|
+
uniform vec2 uPointer;
|
|
39
|
+
uniform float uHover;
|
|
40
|
+
uniform vec3 uPress;
|
|
41
|
+
uniform float uTone;
|
|
42
|
+
|
|
43
|
+
float metal(vec2 px) {
|
|
44
|
+
vec2 uv = (2.0 * px - uRes) / min(uRes.x, uRes.y);
|
|
45
|
+
for (float i = 1.0; i < 8.0; i++) {
|
|
46
|
+
uv.x += 0.22 / i * cos(i * 2.6 * uv.y + uTime);
|
|
47
|
+
uv.y += 0.22 / i * cos(i * 1.9 * uv.x + uTime * 0.8);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Interactions push band phase and contrast directly: nudging the warp, or
|
|
51
|
+
// brightening already-bright metal, barely registers on a thin ring.
|
|
52
|
+
float phase = 0.0;
|
|
53
|
+
float shade = 0.0;
|
|
54
|
+
|
|
55
|
+
// Pointer: tight dark and bright ripples swirl out from the cursor.
|
|
56
|
+
vec2 d = (px - uPointer) / uRes.y;
|
|
57
|
+
float dist = length(d);
|
|
58
|
+
float near = exp(-dist * dist * 1.5) * uHover;
|
|
59
|
+
float swirl = sin(dist * 14.0 - uTime * 7.0);
|
|
60
|
+
phase += swirl * 2.2 * near;
|
|
61
|
+
shade += swirl * 0.45 * near;
|
|
62
|
+
|
|
63
|
+
// Press: a shock front runs out from the click, bright at its leading edge
|
|
64
|
+
// with a dark trough behind it.
|
|
65
|
+
float age = uTime - uPress.z;
|
|
66
|
+
if (age > 0.0 && age < 2.0) {
|
|
67
|
+
float r = length((px - uPress.xy) / uRes.y);
|
|
68
|
+
float front = r - age * 4.0;
|
|
69
|
+
float fade = exp(-age * 1.8);
|
|
70
|
+
phase += exp(-front * front * 2.0) * fade * 5.0;
|
|
71
|
+
shade += (exp(-front * front * 8.0) - exp(-(front + 0.45) * (front + 0.45) * 8.0)) * fade * 0.95;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Normalized so a pill's ends and sides share one angular speed.
|
|
75
|
+
vec2 q = (2.0 * px - uRes) / uRes;
|
|
76
|
+
float angle = atan(q.y, q.x);
|
|
77
|
+
float s = sin(angle * 3.0 - uTime * 2.2 + (uv.x + uv.y) * 1.1 + phase);
|
|
78
|
+
float m = 0.5 + 0.5 * s;
|
|
79
|
+
float c = 0.3 + 0.7 * smoothstep(0.0, 0.75, m);
|
|
80
|
+
c += 0.55 * min(0.035 / abs(s - 0.35), 1.0);
|
|
81
|
+
c -= 0.35 * min(0.02 / abs(s + 0.6), 1.0);
|
|
82
|
+
return clamp(c + shade, 0.0, 1.0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
void main() {
|
|
86
|
+
float c = 0.0;
|
|
87
|
+
c += metal(gl_FragCoord.xy + vec2(-0.25, -0.25));
|
|
88
|
+
c += metal(gl_FragCoord.xy + vec2(0.25, -0.25));
|
|
89
|
+
c += metal(gl_FragCoord.xy + vec2(-0.25, 0.25));
|
|
90
|
+
c += metal(gl_FragCoord.xy + vec2(0.25, 0.25));
|
|
91
|
+
c *= 0.25;
|
|
92
|
+
// Slightly cool lights and warm shadows read as steel rather than grey.
|
|
93
|
+
vec3 col = mix(vec3(0.09, 0.085, 0.08), vec3(1.0, 1.0, 1.02), c);
|
|
94
|
+
// On a white face the ring sits a little darker so it still frames the button.
|
|
95
|
+
col *= uTone > 0.5 ? 0.9 : 1.0;
|
|
96
|
+
gl_FragColor = vec4(col, 1.0);
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
type ChromeGL = {
|
|
101
|
+
gl: WebGLRenderingContext;
|
|
102
|
+
uniforms: Record<
|
|
103
|
+
"uRes" | "uTime" | "uPointer" | "uHover" | "uPress" | "uTone",
|
|
104
|
+
WebGLUniformLocation | null
|
|
105
|
+
>;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
function createChromeGL(canvas: HTMLCanvasElement): ChromeGL | null {
|
|
109
|
+
const gl = canvas.getContext("webgl", {
|
|
110
|
+
alpha: false,
|
|
111
|
+
antialias: false,
|
|
112
|
+
powerPreference: "low-power",
|
|
113
|
+
});
|
|
114
|
+
if (!gl) return null;
|
|
115
|
+
|
|
116
|
+
const compile = (type: number, source: string) => {
|
|
117
|
+
const shader = gl.createShader(type)!;
|
|
118
|
+
gl.shaderSource(shader, source);
|
|
119
|
+
gl.compileShader(shader);
|
|
120
|
+
return gl.getShaderParameter(shader, gl.COMPILE_STATUS) ? shader : null;
|
|
121
|
+
};
|
|
122
|
+
const vs = compile(gl.VERTEX_SHADER, VERTEX);
|
|
123
|
+
const fs = compile(gl.FRAGMENT_SHADER, FRAGMENT);
|
|
124
|
+
if (!vs || !fs) return null;
|
|
125
|
+
|
|
126
|
+
const program = gl.createProgram()!;
|
|
127
|
+
gl.attachShader(program, vs);
|
|
128
|
+
gl.attachShader(program, fs);
|
|
129
|
+
gl.linkProgram(program);
|
|
130
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) return null;
|
|
131
|
+
gl.useProgram(program);
|
|
132
|
+
|
|
133
|
+
// One oversized triangle covers the viewport.
|
|
134
|
+
const buffer = gl.createBuffer();
|
|
135
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
136
|
+
gl.bufferData(
|
|
137
|
+
gl.ARRAY_BUFFER,
|
|
138
|
+
new Float32Array([-1, -1, 3, -1, -1, 3]),
|
|
139
|
+
gl.STATIC_DRAW,
|
|
140
|
+
);
|
|
141
|
+
const position = gl.getAttribLocation(program, "aPosition");
|
|
142
|
+
gl.enableVertexAttribArray(position);
|
|
143
|
+
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
|
|
144
|
+
|
|
145
|
+
const at = (name: string) => gl.getUniformLocation(program, name);
|
|
146
|
+
return {
|
|
147
|
+
gl,
|
|
148
|
+
uniforms: {
|
|
149
|
+
uRes: at("uRes"),
|
|
150
|
+
uTime: at("uTime"),
|
|
151
|
+
uPointer: at("uPointer"),
|
|
152
|
+
uHover: at("uHover"),
|
|
153
|
+
uPress: at("uPress"),
|
|
154
|
+
uTone: at("uTone"),
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const DARK = {
|
|
160
|
+
shell:
|
|
161
|
+
"shadow-[0_0_0_1px_rgb(0_0_0/0.7),0_2px_4px_rgb(0_0_0/0.5),0_8px_20px_-8px_rgb(0_0_0/0.7)]",
|
|
162
|
+
face:
|
|
163
|
+
"bg-[linear-gradient(180deg,#1d1d1d_0%,#111111_60%,#0d0d0d_100%)] text-neutral-50 shadow-[inset_0_1px_3px_rgb(0_0_0/0.9),inset_0_-1px_0_rgb(255_255_255/0.05),0_0_0_1px_rgb(0_0_0/0.55)]",
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const LIGHT = {
|
|
167
|
+
shell:
|
|
168
|
+
"shadow-[0_0_0_1px_rgb(0_0_0/0.18),0_2px_4px_rgb(0_0_0/0.12),0_10px_24px_-8px_rgb(0_0_0/0.3)]",
|
|
169
|
+
face:
|
|
170
|
+
"bg-[linear-gradient(180deg,#ffffff_0%,#fafafa_60%,#f0f0f0_100%)] text-neutral-900 shadow-[inset_0_1px_3px_rgb(0_0_0/0.28),inset_0_-1px_0_rgb(255_255_255/0.9),0_0_0_1px_rgb(0_0_0/0.25)]",
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const TONES: Record<ChromeTone, { shell: string; face: string }> = {
|
|
174
|
+
// Light by default, dark inside a `.dark` ancestor, like shadcn's theming.
|
|
175
|
+
// Written out in full so Tailwind can see every dark: class.
|
|
176
|
+
auto: {
|
|
177
|
+
shell: `${LIGHT.shell} dark:shadow-[0_0_0_1px_rgb(0_0_0/0.7),0_2px_4px_rgb(0_0_0/0.5),0_8px_20px_-8px_rgb(0_0_0/0.7)]`,
|
|
178
|
+
face: `${LIGHT.face} dark:bg-[linear-gradient(180deg,#1d1d1d_0%,#111111_60%,#0d0d0d_100%)] dark:text-neutral-50 dark:shadow-[inset_0_1px_3px_rgb(0_0_0/0.9),inset_0_-1px_0_rgb(255_255_255/0.05),0_0_0_1px_rgb(0_0_0/0.55)]`,
|
|
179
|
+
},
|
|
180
|
+
dark: DARK,
|
|
181
|
+
light: LIGHT,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const SIZES: Record<ChromeSize, { shell: string; face: string }> = {
|
|
185
|
+
default: {
|
|
186
|
+
shell: "h-11 p-[3px]",
|
|
187
|
+
face: "gap-2.5 px-5 text-[15px] [&_svg]:size-4",
|
|
188
|
+
},
|
|
189
|
+
sm: {
|
|
190
|
+
shell: "h-9 p-[2.5px]",
|
|
191
|
+
face: "gap-2 px-3.5 text-[13px] [&_svg]:size-3.5",
|
|
192
|
+
},
|
|
193
|
+
icon: {
|
|
194
|
+
shell: "size-9 p-[2.5px]",
|
|
195
|
+
face: "aspect-square justify-center [&_svg]:size-4",
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export const ChromeButton = React.forwardRef<
|
|
200
|
+
HTMLButtonElement,
|
|
201
|
+
ChromeButtonProps
|
|
202
|
+
>(
|
|
203
|
+
(
|
|
204
|
+
{
|
|
205
|
+
children,
|
|
206
|
+
label = "Continue",
|
|
207
|
+
tone = "auto",
|
|
208
|
+
size = "default",
|
|
209
|
+
speed = 1,
|
|
210
|
+
interactive = true,
|
|
211
|
+
className,
|
|
212
|
+
disabled,
|
|
213
|
+
type = "button",
|
|
214
|
+
onPointerEnter,
|
|
215
|
+
onPointerMove,
|
|
216
|
+
onPointerLeave,
|
|
217
|
+
onPointerDown,
|
|
218
|
+
onClick,
|
|
219
|
+
...props
|
|
220
|
+
},
|
|
221
|
+
ref,
|
|
222
|
+
) => {
|
|
223
|
+
const shellRef = React.useRef<HTMLButtonElement | null>(null);
|
|
224
|
+
const hostRef = React.useRef<HTMLSpanElement | null>(null);
|
|
225
|
+
const canvasRef = React.useRef<HTMLCanvasElement | null>(null);
|
|
226
|
+
const [painted, setPainted] = React.useState(false);
|
|
227
|
+
|
|
228
|
+
// Live inputs the render loop reads without re-running the effect.
|
|
229
|
+
const input = React.useRef({
|
|
230
|
+
pointer: [0, 0] as [number, number],
|
|
231
|
+
hoverTarget: 0,
|
|
232
|
+
press: [0, 0, -10] as [number, number, number],
|
|
233
|
+
time: 0,
|
|
234
|
+
speed,
|
|
235
|
+
tone,
|
|
236
|
+
interactive,
|
|
237
|
+
});
|
|
238
|
+
input.current.speed = speed;
|
|
239
|
+
input.current.tone = tone;
|
|
240
|
+
input.current.interactive = interactive;
|
|
241
|
+
|
|
242
|
+
const setShellRef = (node: HTMLButtonElement | null) => {
|
|
243
|
+
shellRef.current = node;
|
|
244
|
+
if (typeof ref === "function") ref(node);
|
|
245
|
+
else if (ref) ref.current = node;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
React.useEffect(() => {
|
|
249
|
+
const host = hostRef.current;
|
|
250
|
+
const shell = shellRef.current;
|
|
251
|
+
if (!host || !shell) return;
|
|
252
|
+
// A fresh canvas per run: once a context is lost (as cleanup does), the
|
|
253
|
+
// same canvas only ever hands back that dead context, which froze the
|
|
254
|
+
// metal after Strict Mode's mount, unmount, mount in development.
|
|
255
|
+
const canvas = document.createElement("canvas");
|
|
256
|
+
canvas.style.cssText = "display:block;width:100%;height:100%";
|
|
257
|
+
const chrome = createChromeGL(canvas);
|
|
258
|
+
if (!chrome) return;
|
|
259
|
+
host.appendChild(canvas);
|
|
260
|
+
canvasRef.current = canvas;
|
|
261
|
+
const { gl, uniforms } = chrome;
|
|
262
|
+
const state = input.current;
|
|
263
|
+
// Reduced motion slows the flow to a gentle drift instead of freezing it.
|
|
264
|
+
const reduceMotion = window.matchMedia(
|
|
265
|
+
"(prefers-reduced-motion: reduce)",
|
|
266
|
+
).matches;
|
|
267
|
+
|
|
268
|
+
let raf = 0;
|
|
269
|
+
let last = 0;
|
|
270
|
+
let hover = 0;
|
|
271
|
+
let visible = true;
|
|
272
|
+
let first = true;
|
|
273
|
+
|
|
274
|
+
const draw = () => {
|
|
275
|
+
gl.uniform2f(uniforms.uRes, canvas.width, canvas.height);
|
|
276
|
+
gl.uniform1f(uniforms.uTime, state.time);
|
|
277
|
+
gl.uniform2f(uniforms.uPointer, state.pointer[0], state.pointer[1]);
|
|
278
|
+
gl.uniform1f(uniforms.uHover, hover);
|
|
279
|
+
gl.uniform3f(uniforms.uPress, ...state.press);
|
|
280
|
+
const light =
|
|
281
|
+
state.tone === "auto" ? !shell.closest(".dark") : state.tone === "light";
|
|
282
|
+
gl.uniform1f(uniforms.uTone, light ? 1 : 0);
|
|
283
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
284
|
+
if (first) {
|
|
285
|
+
first = false;
|
|
286
|
+
setPainted(true);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const frame = (now: number) => {
|
|
291
|
+
const dt = last ? Math.min(0.05, (now - last) / 1000) : 0;
|
|
292
|
+
last = now;
|
|
293
|
+
const target = state.interactive ? state.hoverTarget : 0;
|
|
294
|
+
hover += (target - hover) * Math.min(1, dt * 8);
|
|
295
|
+
state.time += dt * state.speed * (reduceMotion ? 0.2 : 1) * (1 + hover * 1.2);
|
|
296
|
+
draw();
|
|
297
|
+
raf = requestAnimationFrame(frame);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const start = () => {
|
|
301
|
+
if (raf || !visible || document.hidden) return;
|
|
302
|
+
last = 0;
|
|
303
|
+
raf = requestAnimationFrame(frame);
|
|
304
|
+
};
|
|
305
|
+
const stop = () => {
|
|
306
|
+
cancelAnimationFrame(raf);
|
|
307
|
+
raf = 0;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const resize = () => {
|
|
311
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
312
|
+
canvas.width = Math.max(1, Math.round(shell.clientWidth * dpr));
|
|
313
|
+
canvas.height = Math.max(1, Math.round(shell.clientHeight * dpr));
|
|
314
|
+
gl.viewport(0, 0, canvas.width, canvas.height);
|
|
315
|
+
draw();
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const resizeObserver = new ResizeObserver(resize);
|
|
319
|
+
resizeObserver.observe(shell);
|
|
320
|
+
// Only animate while on screen.
|
|
321
|
+
const intersection = new IntersectionObserver(([entry]) => {
|
|
322
|
+
visible = !!entry?.isIntersecting;
|
|
323
|
+
if (visible) start();
|
|
324
|
+
else stop();
|
|
325
|
+
});
|
|
326
|
+
intersection.observe(shell);
|
|
327
|
+
const onVisibility = () => (document.hidden ? stop() : start());
|
|
328
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
329
|
+
const onLost = (event: Event) => {
|
|
330
|
+
event.preventDefault();
|
|
331
|
+
stop();
|
|
332
|
+
setPainted(false);
|
|
333
|
+
};
|
|
334
|
+
canvas.addEventListener("webglcontextlost", onLost);
|
|
335
|
+
|
|
336
|
+
resize();
|
|
337
|
+
start();
|
|
338
|
+
|
|
339
|
+
return () => {
|
|
340
|
+
stop();
|
|
341
|
+
resizeObserver.disconnect();
|
|
342
|
+
intersection.disconnect();
|
|
343
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
344
|
+
canvas.removeEventListener("webglcontextlost", onLost);
|
|
345
|
+
gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
346
|
+
canvas.remove();
|
|
347
|
+
if (canvasRef.current === canvas) canvasRef.current = null;
|
|
348
|
+
setPainted(false);
|
|
349
|
+
};
|
|
350
|
+
}, []);
|
|
351
|
+
|
|
352
|
+
/** Pointer position in canvas pixels, y up, as the shader expects. */
|
|
353
|
+
const toCanvas = (clientX: number, clientY: number) => {
|
|
354
|
+
const canvas = canvasRef.current;
|
|
355
|
+
const shell = shellRef.current;
|
|
356
|
+
if (!canvas || !shell) return [0, 0] as [number, number];
|
|
357
|
+
const rect = shell.getBoundingClientRect();
|
|
358
|
+
return [
|
|
359
|
+
(clientX - rect.left) * (canvas.width / rect.width),
|
|
360
|
+
(rect.bottom - clientY) * (canvas.height / rect.height),
|
|
361
|
+
] as [number, number];
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const wave = (at: [number, number]) => {
|
|
365
|
+
input.current.press = [at[0], at[1], input.current.time];
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const tones = TONES[tone];
|
|
369
|
+
const sizes = SIZES[size];
|
|
370
|
+
|
|
371
|
+
return (
|
|
372
|
+
<button
|
|
373
|
+
ref={setShellRef}
|
|
374
|
+
type={type}
|
|
375
|
+
disabled={disabled}
|
|
376
|
+
onPointerEnter={(event) => {
|
|
377
|
+
onPointerEnter?.(event);
|
|
378
|
+
input.current.pointer = toCanvas(event.clientX, event.clientY);
|
|
379
|
+
input.current.hoverTarget = 1;
|
|
380
|
+
}}
|
|
381
|
+
onPointerMove={(event) => {
|
|
382
|
+
onPointerMove?.(event);
|
|
383
|
+
input.current.pointer = toCanvas(event.clientX, event.clientY);
|
|
384
|
+
}}
|
|
385
|
+
onPointerLeave={(event) => {
|
|
386
|
+
onPointerLeave?.(event);
|
|
387
|
+
input.current.hoverTarget = 0;
|
|
388
|
+
}}
|
|
389
|
+
onPointerDown={(event) => {
|
|
390
|
+
onPointerDown?.(event);
|
|
391
|
+
if (interactive) wave(toCanvas(event.clientX, event.clientY));
|
|
392
|
+
}}
|
|
393
|
+
onClick={(event) => {
|
|
394
|
+
onClick?.(event);
|
|
395
|
+
// Keyboard activation has no pointer: send the wave from the center.
|
|
396
|
+
const canvas = canvasRef.current;
|
|
397
|
+
if (interactive && event.detail === 0 && canvas) {
|
|
398
|
+
wave([canvas.width / 2, canvas.height / 2]);
|
|
399
|
+
}
|
|
400
|
+
}}
|
|
401
|
+
className={cn(
|
|
402
|
+
"group/chrome relative isolate inline-flex shrink-0 cursor-pointer overflow-hidden rounded-full font-medium tracking-tight outline-none select-none",
|
|
403
|
+
// Static silver shows until the liquid metal paints, and stays if WebGL can't.
|
|
404
|
+
"bg-[linear-gradient(135deg,#f4f4f5_0%,#8a8a8f_28%,#fafafa_48%,#4a4a4f_72%,#d9d9dc_100%)]",
|
|
405
|
+
tones.shell,
|
|
406
|
+
sizes.shell,
|
|
407
|
+
"transition-[scale,filter] duration-300 ease-[cubic-bezier(0.34,1.4,0.64,1)] hover:brightness-110",
|
|
408
|
+
"active:scale-[0.96] active:duration-100 active:ease-out motion-reduce:active:scale-100",
|
|
409
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
410
|
+
"disabled:cursor-not-allowed disabled:opacity-50 disabled:grayscale",
|
|
411
|
+
className,
|
|
412
|
+
)}
|
|
413
|
+
{...props}
|
|
414
|
+
>
|
|
415
|
+
<span
|
|
416
|
+
ref={hostRef}
|
|
417
|
+
aria-hidden
|
|
418
|
+
className={cn(
|
|
419
|
+
"absolute inset-0 -z-10 transition-opacity duration-500",
|
|
420
|
+
painted ? "opacity-100" : "opacity-0",
|
|
421
|
+
)}
|
|
422
|
+
/>
|
|
423
|
+
{/* Tube shading on the ring: a lit top lip and a shadowed underside. */}
|
|
424
|
+
<span
|
|
425
|
+
aria-hidden
|
|
426
|
+
className="pointer-events-none absolute inset-0 rounded-full shadow-[inset_0_1px_0_rgb(255_255_255/0.55),inset_0_-1px_1px_rgb(0_0_0/0.45)]"
|
|
427
|
+
/>
|
|
428
|
+
<span
|
|
429
|
+
className={cn(
|
|
430
|
+
"relative flex h-full items-center rounded-full whitespace-nowrap",
|
|
431
|
+
tones.face,
|
|
432
|
+
sizes.face,
|
|
433
|
+
)}
|
|
434
|
+
>
|
|
435
|
+
{children ?? label}
|
|
436
|
+
</span>
|
|
437
|
+
</button>
|
|
438
|
+
);
|
|
439
|
+
},
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
ChromeButton.displayName = "ChromeButton";
|
|
443
|
+
|
|
444
|
+
export default ChromeButton;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { motion, useReducedMotion, type Variants } from "motion/react";
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
|
|
7
|
+
export interface ClickPowerUpProps extends Omit<
|
|
8
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
9
|
+
"onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart"
|
|
10
|
+
> {
|
|
11
|
+
/** Milliseconds the powered-up flash lasts after a click. */
|
|
12
|
+
tapDuration?: number;
|
|
13
|
+
/** Color of the powered-up flash. */
|
|
14
|
+
accentColor?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type Phase = "rest" | "hover" | "tap" | "powered";
|
|
18
|
+
|
|
19
|
+
const SPRING = { type: "spring", stiffness: 320, damping: 22 } as const;
|
|
20
|
+
|
|
21
|
+
const CORNERS = [
|
|
22
|
+
{ key: "tl", x: -1, y: -1, className: "top-0 left-0 border-t border-l" },
|
|
23
|
+
{ key: "tr", x: 1, y: -1, className: "top-0 right-0 border-t border-r" },
|
|
24
|
+
{ key: "bl", x: -1, y: 1, className: "bottom-0 left-0 border-b border-l" },
|
|
25
|
+
{ key: "br", x: 1, y: 1, className: "right-0 bottom-0 border-r border-b" },
|
|
26
|
+
] as const;
|
|
27
|
+
|
|
28
|
+
const bracketVariants: Variants = {
|
|
29
|
+
rest: { x: 0, y: 0, opacity: 0.45 },
|
|
30
|
+
hover: ({ x, y }: { x: number; y: number }) => ({
|
|
31
|
+
x: x * 4,
|
|
32
|
+
y: y * 4,
|
|
33
|
+
opacity: 1,
|
|
34
|
+
}),
|
|
35
|
+
tap: ({ x, y }: { x: number; y: number }) => ({
|
|
36
|
+
x: -x * 2,
|
|
37
|
+
y: -y * 2,
|
|
38
|
+
opacity: 1,
|
|
39
|
+
}),
|
|
40
|
+
// Bouncy spring so the brackets overshoot outward, then settle.
|
|
41
|
+
powered: ({ x, y }: { x: number; y: number }) => ({
|
|
42
|
+
x: x * 6,
|
|
43
|
+
y: y * 6,
|
|
44
|
+
opacity: 1,
|
|
45
|
+
transition: { type: "spring", stiffness: 600, damping: 11 },
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const panelVariants: Variants = {
|
|
50
|
+
rest: { scaleX: 0 },
|
|
51
|
+
hover: { scaleX: 1 },
|
|
52
|
+
tap: { scaleX: 1 },
|
|
53
|
+
powered: { scaleX: 1 },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const ClickPowerUp = React.forwardRef<
|
|
57
|
+
HTMLButtonElement,
|
|
58
|
+
ClickPowerUpProps
|
|
59
|
+
>(
|
|
60
|
+
(
|
|
61
|
+
{
|
|
62
|
+
children,
|
|
63
|
+
className,
|
|
64
|
+
tapDuration = 500,
|
|
65
|
+
accentColor = "#2CD4BD",
|
|
66
|
+
onClick,
|
|
67
|
+
onPointerEnter,
|
|
68
|
+
onPointerLeave,
|
|
69
|
+
onPointerDown,
|
|
70
|
+
onPointerUp,
|
|
71
|
+
style,
|
|
72
|
+
disabled,
|
|
73
|
+
type = "button",
|
|
74
|
+
...props
|
|
75
|
+
},
|
|
76
|
+
ref,
|
|
77
|
+
) => {
|
|
78
|
+
const reduceMotion = useReducedMotion();
|
|
79
|
+
const [hovered, setHovered] = React.useState(false);
|
|
80
|
+
const [pressed, setPressed] = React.useState(false);
|
|
81
|
+
const [powered, setPowered] = React.useState(false);
|
|
82
|
+
const poweredTimerRef = React.useRef<number | undefined>(undefined);
|
|
83
|
+
|
|
84
|
+
React.useEffect(
|
|
85
|
+
() => () => window.clearTimeout(poweredTimerRef.current),
|
|
86
|
+
[],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
90
|
+
onClick?.(event);
|
|
91
|
+
setPowered(true);
|
|
92
|
+
window.clearTimeout(poweredTimerRef.current);
|
|
93
|
+
poweredTimerRef.current = window.setTimeout(
|
|
94
|
+
() => setPowered(false),
|
|
95
|
+
tapDuration,
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Pressing wins so every click, even mid power-up, snaps in then bursts out.
|
|
100
|
+
const phase: Phase = pressed
|
|
101
|
+
? "tap"
|
|
102
|
+
: powered
|
|
103
|
+
? "powered"
|
|
104
|
+
: hovered
|
|
105
|
+
? "hover"
|
|
106
|
+
: "rest";
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<motion.button
|
|
110
|
+
ref={ref}
|
|
111
|
+
type={type}
|
|
112
|
+
disabled={disabled}
|
|
113
|
+
initial={false}
|
|
114
|
+
animate={phase}
|
|
115
|
+
onClick={handleClick}
|
|
116
|
+
onPointerDown={(event) => {
|
|
117
|
+
onPointerDown?.(event);
|
|
118
|
+
if (event.button === 0) setPressed(true);
|
|
119
|
+
}}
|
|
120
|
+
onPointerUp={(event) => {
|
|
121
|
+
onPointerUp?.(event);
|
|
122
|
+
setPressed(false);
|
|
123
|
+
}}
|
|
124
|
+
onPointerCancel={() => setPressed(false)}
|
|
125
|
+
onPointerEnter={(event) => {
|
|
126
|
+
onPointerEnter?.(event);
|
|
127
|
+
if (event.pointerType !== "touch") setHovered(true);
|
|
128
|
+
}}
|
|
129
|
+
onPointerLeave={(event) => {
|
|
130
|
+
onPointerLeave?.(event);
|
|
131
|
+
setHovered(false);
|
|
132
|
+
setPressed(false);
|
|
133
|
+
}}
|
|
134
|
+
style={{ "--powerup": accentColor, ...style } as React.CSSProperties}
|
|
135
|
+
className={cn(
|
|
136
|
+
"group/powerup relative inline-flex cursor-pointer items-center justify-center px-10 py-3 text-sm font-medium tracking-[0.18em] uppercase shadow-[0_1px_2px_rgb(0_0_0/0.05),0_2px_6px_-3px_rgb(0_0_0/0.07),inset_0_-1px_0_rgb(0_0_0/0.03)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.4),inset_0_1px_0_rgb(255_255_255/0.05)] outline-none select-none",
|
|
137
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
|
|
138
|
+
className,
|
|
139
|
+
)}
|
|
140
|
+
{...props}
|
|
141
|
+
>
|
|
142
|
+
{/* Face: hatched surface with a panel that wipes in when armed. */}
|
|
143
|
+
<span
|
|
144
|
+
aria-hidden
|
|
145
|
+
className="absolute inset-0 overflow-hidden bg-background [--hatch:color-mix(in_oklab,var(--foreground)_10%,transparent)]"
|
|
146
|
+
>
|
|
147
|
+
<span className="absolute inset-0 bg-[repeating-linear-gradient(315deg,var(--hatch)_0,var(--hatch)_1px,transparent_0,transparent_50%)] bg-size-[7px_7px]" />
|
|
148
|
+
<motion.span
|
|
149
|
+
variants={panelVariants}
|
|
150
|
+
transition={SPRING}
|
|
151
|
+
className="absolute inset-0 origin-left bg-foreground"
|
|
152
|
+
/>
|
|
153
|
+
<motion.span
|
|
154
|
+
className="absolute inset-0 bg-(--powerup)"
|
|
155
|
+
initial={false}
|
|
156
|
+
animate={{ opacity: powered ? 1 : 0 }}
|
|
157
|
+
transition={{ duration: powered ? 0.08 : 0.3 }}
|
|
158
|
+
/>
|
|
159
|
+
</span>
|
|
160
|
+
|
|
161
|
+
{CORNERS.map((corner) => (
|
|
162
|
+
<motion.span
|
|
163
|
+
key={corner.key}
|
|
164
|
+
aria-hidden
|
|
165
|
+
custom={corner}
|
|
166
|
+
variants={reduceMotion ? undefined : bracketVariants}
|
|
167
|
+
transition={SPRING}
|
|
168
|
+
className={cn(
|
|
169
|
+
"pointer-events-none absolute z-10 size-2.5 border-foreground",
|
|
170
|
+
phase === "powered" && "border-(--powerup)",
|
|
171
|
+
corner.className,
|
|
172
|
+
)}
|
|
173
|
+
/>
|
|
174
|
+
))}
|
|
175
|
+
|
|
176
|
+
<motion.span
|
|
177
|
+
className={cn(
|
|
178
|
+
"relative z-10 transition-colors duration-150",
|
|
179
|
+
phase === "rest" && "text-foreground",
|
|
180
|
+
(phase === "hover" || phase === "tap") && "text-background",
|
|
181
|
+
phase === "powered" && "text-neutral-950",
|
|
182
|
+
)}
|
|
183
|
+
variants={{
|
|
184
|
+
rest: { scale: 1 },
|
|
185
|
+
hover: { scale: 1 },
|
|
186
|
+
tap: { scale: 0.94 },
|
|
187
|
+
powered: reduceMotion
|
|
188
|
+
? { scale: 1 }
|
|
189
|
+
: {
|
|
190
|
+
scale: 1,
|
|
191
|
+
transition: { type: "spring", stiffness: 600, damping: 12 },
|
|
192
|
+
},
|
|
193
|
+
}}
|
|
194
|
+
transition={SPRING}
|
|
195
|
+
>
|
|
196
|
+
{children}
|
|
197
|
+
</motion.span>
|
|
198
|
+
</motion.button>
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
ClickPowerUp.displayName = "ClickPowerUp";
|