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.
Files changed (166) hide show
  1. package/README.md +71 -21
  2. package/SKILL.md +83 -9
  3. package/bin/index.mjs +2 -2
  4. package/bin/installer.mjs +6 -0
  5. package/catalog.json +1044 -139
  6. package/components/agents/thinking-states.tsx +156 -0
  7. package/components/buttons/aqua-button.tsx +145 -0
  8. package/components/buttons/ash-burst-button.tsx +528 -0
  9. package/components/buttons/brutal-button.tsx +68 -0
  10. package/components/buttons/chrome-button.tsx +444 -0
  11. package/components/buttons/click-powerup.tsx +203 -0
  12. package/components/buttons/command-button.tsx +226 -0
  13. package/components/buttons/confetti-button.tsx +132 -0
  14. package/components/buttons/cooldown-button.tsx +169 -0
  15. package/components/buttons/demonic-button.tsx +470 -0
  16. package/components/buttons/dither-button.tsx +192 -0
  17. package/components/buttons/doubt-button.tsx +240 -0
  18. package/components/buttons/evil-eye-button.tsx +563 -0
  19. package/components/buttons/frame-button.tsx +211 -0
  20. package/components/buttons/glitch-button.tsx +243 -0
  21. package/components/buttons/highlight-button.tsx +196 -0
  22. package/components/buttons/hold-button.tsx +245 -0
  23. package/components/buttons/minecraft-button.tsx +651 -0
  24. package/components/buttons/minimal-button.tsx +50 -0
  25. package/components/buttons/morph-status-button.tsx +264 -0
  26. package/components/buttons/movie-pass-button.tsx +205 -0
  27. package/components/buttons/realistic-switch.tsx +298 -0
  28. package/components/buttons/reveal-button.tsx +197 -0
  29. package/components/buttons/shiny-button.tsx +87 -0
  30. package/components/buttons/slide-to-detonate.tsx +444 -0
  31. package/components/buttons/sticky-button.tsx +184 -0
  32. package/components/buttons/thruster-button.tsx +920 -0
  33. package/components/buttons/troll-button.tsx +264 -0
  34. package/components/motion/banner-stacking.tsx +124 -0
  35. package/components/motion/delete-with-smoky-dissolve.tsx +145 -0
  36. package/components/motion/donut-chart.tsx +112 -0
  37. package/components/motion/drag-drop-with-physics.tsx +116 -0
  38. package/components/motion/dropdown-menu-morph.tsx +157 -0
  39. package/components/motion/get-pro-button.tsx +54 -0
  40. package/components/motion/image-open-tilt.tsx +79 -0
  41. package/components/motion/input-clear-with-dissolve.tsx +111 -0
  42. package/components/motion/learn-more-hover.tsx +71 -0
  43. package/components/motion/matrix-dot-loader.tsx +68 -0
  44. package/components/motion/organic-shimmer.tsx +49 -0
  45. package/components/motion/pro-gradient-text.tsx +46 -0
  46. package/components/motion/skeleton-loader-and-reveal.tsx +81 -0
  47. package/components/motion/spinner-to-check-morph.tsx +99 -0
  48. package/components/motion/spinning-counter.tsx +64 -0
  49. package/components/motion/text-morph.tsx +80 -0
  50. package/components/motion/texts-reveal.tsx +49 -0
  51. package/data/app-interface.csv +33 -0
  52. package/data/charts.csv +26 -0
  53. package/data/colors.csv +193 -0
  54. package/data/google-fonts.csv +1935 -0
  55. package/data/icons.csv +106 -0
  56. package/data/landing.csv +35 -0
  57. package/data/motion.csv +18 -0
  58. package/data/products.csv +193 -0
  59. package/data/react-performance.csv +45 -0
  60. package/data/stacks/angular.csv +51 -0
  61. package/data/stacks/astro.csv +54 -0
  62. package/data/stacks/avalonia.csv +57 -0
  63. package/data/stacks/flutter.csv +53 -0
  64. package/data/stacks/html-tailwind.csv +60 -0
  65. package/data/stacks/javafx.csv +76 -0
  66. package/data/stacks/jetpack-compose.csv +53 -0
  67. package/data/stacks/laravel.csv +51 -0
  68. package/data/stacks/nextjs.csv +62 -0
  69. package/data/stacks/nuxt-ui.csv +77 -0
  70. package/data/stacks/nuxtjs.csv +68 -0
  71. package/data/stacks/react-native.csv +52 -0
  72. package/data/stacks/react.csv +67 -0
  73. package/data/stacks/shadcn.csv +69 -0
  74. package/data/stacks/svelte.csv +56 -0
  75. package/data/stacks/swiftui.csv +51 -0
  76. package/data/stacks/threejs.csv +54 -0
  77. package/data/stacks/uno.csv +60 -0
  78. package/data/stacks/uwp.csv +56 -0
  79. package/data/stacks/vue.csv +50 -0
  80. package/data/stacks/winui.csv +60 -0
  81. package/data/stacks/wpf.csv +57 -0
  82. package/data/styles.csv +89 -0
  83. package/data/typography.csv +75 -0
  84. package/data/ui-reasoning.csv +193 -0
  85. package/data/ux-guidelines.csv +120 -0
  86. package/evals/catalog_eval.py +56 -0
  87. package/icons/annotations/loop-arrow.tsx +61 -0
  88. package/icons/brands/anthropic.tsx +26 -0
  89. package/icons/brands/apple.tsx +26 -0
  90. package/icons/brands/canva.tsx +26 -0
  91. package/icons/brands/claude-ai.tsx +26 -0
  92. package/icons/brands/discord.tsx +26 -0
  93. package/icons/brands/github.tsx +26 -0
  94. package/icons/brands/gmail.tsx +26 -0
  95. package/icons/brands/google.tsx +26 -0
  96. package/icons/brands/linkedin.tsx +29 -0
  97. package/icons/brands/microsoft.tsx +26 -0
  98. package/icons/brands/next-js.tsx +26 -0
  99. package/icons/brands/producthunt.tsx +26 -0
  100. package/icons/brands/react-js.tsx +29 -0
  101. package/icons/brands/shadcn-ui.tsx +26 -0
  102. package/icons/brands/tailwind-css.tsx +26 -0
  103. package/icons/brands/twitter.tsx +30 -0
  104. package/icons/brands/typescript.tsx +26 -0
  105. package/icons/brands/unsplash.tsx +27 -0
  106. package/icons/brands/vercel.tsx +26 -0
  107. package/icons/brands/whatsapp.tsx +26 -0
  108. package/package.json +9 -3
  109. package/prompts/install-motion-ui.md +17 -0
  110. package/references/agents/thinking-states.md +56 -0
  111. package/references/craft/aqua-button.md +53 -0
  112. package/references/craft/ash-burst-button.md +55 -0
  113. package/references/craft/brutal-button.md +52 -0
  114. package/references/craft/chrome-button.md +53 -0
  115. package/references/craft/click-powerup.md +53 -0
  116. package/references/craft/command-button.md +53 -0
  117. package/references/craft/confetti-button.md +54 -0
  118. package/references/craft/cooldown-button.md +54 -0
  119. package/references/craft/demonic-button.md +53 -0
  120. package/references/craft/dither-button.md +52 -0
  121. package/references/craft/doubt-button.md +53 -0
  122. package/references/craft/evil-eye-button.md +52 -0
  123. package/references/craft/frame-button.md +54 -0
  124. package/references/craft/glitch-button.md +52 -0
  125. package/references/craft/highlight-button.md +53 -0
  126. package/references/craft/hold-button.md +53 -0
  127. package/references/craft/minecraft-button.md +53 -0
  128. package/references/craft/minimal-button.md +52 -0
  129. package/references/craft/morph-status-button.md +53 -0
  130. package/references/craft/movie-pass-button.md +53 -0
  131. package/references/craft/realistic-switch.md +54 -0
  132. package/references/craft/reveal-button.md +53 -0
  133. package/references/craft/shiny-button.md +52 -0
  134. package/references/craft/slide-to-detonate.md +53 -0
  135. package/references/craft/sticky-button.md +54 -0
  136. package/references/craft/thruster-button.md +53 -0
  137. package/references/craft/troll-button.md +54 -0
  138. package/references/guides/design-intelligence.md +125 -0
  139. package/references/guides/interaction-transitions.md +56 -38
  140. package/references/guides/motion-polish-rules.md +75 -0
  141. package/references/guides/stack-best-practices.md +38 -0
  142. package/references/motion/banner-stacking.md +67 -0
  143. package/references/motion/delete-with-smoky-dissolve.md +60 -0
  144. package/references/motion/donut-chart.md +79 -0
  145. package/references/motion/drag-drop-with-physics.md +61 -0
  146. package/references/motion/dropdown-menu-morph.md +55 -0
  147. package/references/motion/get-pro-button.md +56 -0
  148. package/references/motion/image-open-tilt.md +60 -0
  149. package/references/motion/input-clear-with-dissolve.md +58 -0
  150. package/references/motion/learn-more-hover.md +56 -0
  151. package/references/motion/matrix-dot-loader.md +58 -0
  152. package/references/motion/organic-shimmer.md +63 -0
  153. package/references/motion/pro-gradient-text.md +57 -0
  154. package/references/motion/skeleton-loader-and-reveal.md +67 -0
  155. package/references/motion/spinner-to-check-morph.md +67 -0
  156. package/references/motion/spinning-counter.md +74 -0
  157. package/references/motion/text-morph.md +64 -0
  158. package/references/motion/texts-reveal.md +56 -0
  159. package/scripts/build_docs.py +39 -4
  160. package/scripts/core.py +993 -0
  161. package/scripts/design_system.py +1668 -0
  162. package/scripts/reasoning_contract.py +123 -0
  163. package/scripts/search.py +177 -0
  164. package/scripts/test_release.py +12 -0
  165. package/scripts/verify_skill.py +4 -4
  166. package/test/test_installer.mjs +133 -0
@@ -0,0 +1,470 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cn } from "@/lib/utils";
5
+
6
+ export interface DemonicButtonProps
7
+ extends Omit<
8
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
9
+ "children" | "onClick"
10
+ > {
11
+ /** Button label. Falls back to `label`. */
12
+ children?: React.ReactNode;
13
+ /** Label used when no children are provided. */
14
+ label?: React.ReactNode;
15
+ /** Milliseconds of holding needed to fully summon the demon. */
16
+ holdDuration?: number;
17
+ /** Fired once each time the charge reaches 100%. */
18
+ onSummon?: () => void;
19
+ }
20
+
21
+ /** Extra canvas room around the button so flames can spill past its edges. */
22
+ const FIRE_BLEED_X = 40;
23
+ const FIRE_HEIGHT = 150;
24
+ /** Charge drains this many times faster than it fills once released. */
25
+ const DRAIN_RATE = 2.4;
26
+
27
+ type Particle = {
28
+ x: number;
29
+ y: number;
30
+ vx: number;
31
+ vy: number;
32
+ age: number;
33
+ life: number;
34
+ size: number;
35
+ seed: number;
36
+ };
37
+
38
+ // Blackbody-ish ramp: white-hot core, through orange and red, into smoke.
39
+ const FIRE_RAMP: [number, [number, number, number, number]][] = [
40
+ [0, [255, 244, 214, 1]],
41
+ [0.18, [255, 196, 92, 0.95]],
42
+ [0.42, [255, 118, 38, 0.8]],
43
+ [0.68, [206, 48, 24, 0.5]],
44
+ [0.86, [96, 24, 18, 0.22]],
45
+ [1, [40, 20, 20, 0]],
46
+ ];
47
+
48
+ const SPRITE_STEPS = 24;
49
+ const SPRITE_SIZE = 64;
50
+
51
+ function sampleRamp(t: number) {
52
+ for (let i = 1; i < FIRE_RAMP.length; i++) {
53
+ const [t1, c1] = FIRE_RAMP[i];
54
+ if (t <= t1) {
55
+ const [t0, c0] = FIRE_RAMP[i - 1];
56
+ const k = (t - t0) / (t1 - t0);
57
+ return c0.map((v, j) => v + (c1[j] - v) * k) as [
58
+ number,
59
+ number,
60
+ number,
61
+ number,
62
+ ];
63
+ }
64
+ }
65
+ return FIRE_RAMP[FIRE_RAMP.length - 1][1];
66
+ }
67
+
68
+ /** Pre-rendered soft radial blobs, one per step of the fire ramp. */
69
+ function createSprites() {
70
+ return Array.from({ length: SPRITE_STEPS }, (_, i) => {
71
+ const [r, g, b, a] = sampleRamp(i / (SPRITE_STEPS - 1));
72
+ const canvas = document.createElement("canvas");
73
+ canvas.width = canvas.height = SPRITE_SIZE;
74
+ const ctx = canvas.getContext("2d");
75
+ if (ctx) {
76
+ const half = SPRITE_SIZE / 2;
77
+ const gradient = ctx.createRadialGradient(half, half, 0, half, half, half);
78
+ gradient.addColorStop(0, `rgba(${r}, ${g}, ${b}, ${a})`);
79
+ gradient.addColorStop(0.45, `rgba(${r}, ${g}, ${b}, ${a * 0.55})`);
80
+ gradient.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0)`);
81
+ ctx.fillStyle = gradient;
82
+ ctx.fillRect(0, 0, SPRITE_SIZE, SPRITE_SIZE);
83
+ }
84
+ return canvas;
85
+ });
86
+ }
87
+
88
+ function Horn({ side }: { side: "left" | "right" }) {
89
+ const id = React.useId().replace(/:/g, "");
90
+ // Outer edge sweeps out and up to the tip, inner edge curls back to the base.
91
+ const shape =
92
+ "M13 64 C6 50 1.5 33 6.5 15 C8 9.5 10.5 5 13 2 C12.5 12 15 26 21 38 C24.5 45 28.5 53 31 64 Z";
93
+
94
+ return (
95
+ <svg
96
+ viewBox="0 0 34 66"
97
+ className={cn("h-full w-full", side === "right" && "-scale-x-100")}
98
+ aria-hidden
99
+ >
100
+ <defs>
101
+ <linearGradient id={`${id}-body`} x1="0.5" y1="1" x2="0.2" y2="0">
102
+ <stop offset="0" stopColor="#1c0907" />
103
+ <stop offset="0.45" stopColor="#4a120d" />
104
+ <stop offset="0.8" stopColor="#8a3a24" />
105
+ <stop offset="1" stopColor="#e9d6bf" />
106
+ </linearGradient>
107
+ <linearGradient id={`${id}-shade`} x1="0" y1="0" x2="1" y2="0">
108
+ <stop offset="0" stopColor="#ffffff" stopOpacity="0.18" />
109
+ <stop offset="0.35" stopColor="#ffffff" stopOpacity="0" />
110
+ <stop offset="0.75" stopColor="#000000" stopOpacity="0" />
111
+ <stop offset="1" stopColor="#000000" stopOpacity="0.45" />
112
+ </linearGradient>
113
+ <clipPath id={`${id}-clip`}>
114
+ <path d={shape} />
115
+ </clipPath>
116
+ </defs>
117
+ <path d={shape} fill={`url(#${id}-body)`} />
118
+ <g clipPath={`url(#${id}-clip)`}>
119
+ <rect width="34" height="66" fill={`url(#${id}-shade)`} />
120
+ {/* Growth ridges wrapping around the horn. */}
121
+ <g
122
+ fill="none"
123
+ stroke="#000000"
124
+ strokeOpacity="0.38"
125
+ strokeWidth="0.9"
126
+ strokeLinecap="round"
127
+ >
128
+ <path d="M3 56 Q17 50 32 58" />
129
+ <path d="M2 48 Q15 42 28 49" />
130
+ <path d="M2 40 Q13 35 25 41" />
131
+ <path d="M2.5 32 Q12 28 21.5 33" />
132
+ <path d="M3.5 25 Q11 21.5 18.5 25.5" />
133
+ <path d="M5 18 Q10.5 15.5 16 18.5" />
134
+ <path d="M7 12 Q10.5 10.5 14.5 12.5" />
135
+ </g>
136
+ <path
137
+ d="M8 58 C4 44 3 30 7.5 16"
138
+ fill="none"
139
+ stroke="#ffd9b8"
140
+ strokeOpacity="0.28"
141
+ strokeWidth="1.2"
142
+ strokeLinecap="round"
143
+ />
144
+ </g>
145
+ </svg>
146
+ );
147
+ }
148
+
149
+ export const DemonicButton = React.forwardRef<
150
+ HTMLButtonElement,
151
+ DemonicButtonProps
152
+ >(
153
+ (
154
+ {
155
+ children,
156
+ label = "Summon",
157
+ holdDuration = 2200,
158
+ onSummon,
159
+ className,
160
+ disabled,
161
+ type = "button",
162
+ ...props
163
+ },
164
+ ref,
165
+ ) => {
166
+ const wrapperRef = React.useRef<HTMLDivElement>(null);
167
+ const buttonRef = React.useRef<HTMLButtonElement | null>(null);
168
+ const canvasRef = React.useRef<HTMLCanvasElement>(null);
169
+ const glowRef = React.useRef<HTMLSpanElement>(null);
170
+ const leftHornRef = React.useRef<HTMLSpanElement>(null);
171
+ const rightHornRef = React.useRef<HTMLSpanElement>(null);
172
+
173
+ const holdingRef = React.useRef(false);
174
+ const progressRef = React.useRef(0);
175
+ const summonedRef = React.useRef(false);
176
+ const particlesRef = React.useRef<Particle[]>([]);
177
+ const spawnDebtRef = React.useRef(0);
178
+ const spritesRef = React.useRef<HTMLCanvasElement[] | null>(null);
179
+ const rafRef = React.useRef<number | null>(null);
180
+ const lastTimeRef = React.useRef(0);
181
+ const sizeRef = React.useRef({ width: 0, height: 0, dpr: 1 });
182
+ const reduceMotionRef = React.useRef(false);
183
+ const onSummonRef = React.useRef(onSummon);
184
+ const [summoned, setSummoned] = React.useState(false);
185
+
186
+ React.useEffect(() => {
187
+ onSummonRef.current = onSummon;
188
+ }, [onSummon]);
189
+
190
+ const setButtonRef = (node: HTMLButtonElement | null) => {
191
+ buttonRef.current = node;
192
+ if (typeof ref === "function") ref(node);
193
+ else if (ref) ref.current = node;
194
+ };
195
+
196
+ // Keep the canvas backing store matched to its CSS size and DPR.
197
+ React.useEffect(() => {
198
+ const wrapper = wrapperRef.current;
199
+ const canvas = canvasRef.current;
200
+ if (!wrapper || !canvas) return;
201
+
202
+ const query = window.matchMedia("(prefers-reduced-motion: reduce)");
203
+ reduceMotionRef.current = query.matches;
204
+ const onMotionChange = () => {
205
+ reduceMotionRef.current = query.matches;
206
+ };
207
+ query.addEventListener("change", onMotionChange);
208
+
209
+ const resize = () => {
210
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
211
+ const width = wrapper.offsetWidth + FIRE_BLEED_X * 2;
212
+ sizeRef.current = { width, height: FIRE_HEIGHT, dpr };
213
+ canvas.width = Math.round(width * dpr);
214
+ canvas.height = Math.round(FIRE_HEIGHT * dpr);
215
+ };
216
+ resize();
217
+ const observer = new ResizeObserver(resize);
218
+ observer.observe(wrapper);
219
+
220
+ return () => {
221
+ observer.disconnect();
222
+ query.removeEventListener("change", onMotionChange);
223
+ if (rafRef.current !== null) cancelAnimationFrame(rafRef.current);
224
+ };
225
+ }, []);
226
+
227
+ const paint = (progress: number, now: number) => {
228
+ const eased = 1 - Math.pow(1 - progress, 3);
229
+ // Slight overshoot as the horns break free, then settle.
230
+ const pop =
231
+ progress > 0.85 ? Math.sin(((progress - 0.85) / 0.15) * Math.PI) * 0.06 : 0;
232
+ const tremble =
233
+ reduceMotionRef.current || !holdingRef.current || progress >= 1
234
+ ? 0
235
+ : progress * progress;
236
+ const shakeX = (Math.sin(now * 0.09) + Math.sin(now * 0.137)) * 1.2 * tremble;
237
+ const shakeY = Math.cos(now * 0.113) * 0.8 * tremble;
238
+
239
+ const hornY = 26 * (1 - eased);
240
+ const hornScale = 0.55 + 0.45 * eased + pop;
241
+ const hornTilt = 18 * (1 - eased);
242
+ if (leftHornRef.current) {
243
+ leftHornRef.current.style.transform = `translateY(${hornY}px) rotate(${-hornTilt}deg) scale(${hornScale})`;
244
+ leftHornRef.current.style.opacity = String(Math.min(1, progress * 3));
245
+ }
246
+ if (rightHornRef.current) {
247
+ rightHornRef.current.style.transform = `translateY(${hornY}px) rotate(${hornTilt}deg) scale(${hornScale})`;
248
+ rightHornRef.current.style.opacity = String(Math.min(1, progress * 3));
249
+ }
250
+ if (buttonRef.current) {
251
+ buttonRef.current.style.transform = `translate(${shakeX}px, ${shakeY}px)`;
252
+ }
253
+ if (glowRef.current) {
254
+ const flicker = reduceMotionRef.current
255
+ ? 0
256
+ : (Math.sin(now * 0.021) + Math.sin(now * 0.047)) * 0.05;
257
+ glowRef.current.style.opacity = String(
258
+ Math.max(0, Math.min(1, eased * 0.9 + flicker * eased)),
259
+ );
260
+ }
261
+ };
262
+
263
+ const drawFire = (intensity: number, dt: number, now: number) => {
264
+ const canvas = canvasRef.current;
265
+ const ctx = canvas?.getContext("2d");
266
+ const button = buttonRef.current;
267
+ if (!canvas || !ctx || !button) return;
268
+
269
+ spritesRef.current ??= createSprites();
270
+ const sprites = spritesRef.current;
271
+ const { width, height, dpr } = sizeRef.current;
272
+ const particles = particlesRef.current;
273
+ const baseY = height - button.offsetHeight / 2;
274
+ const left = FIRE_BLEED_X + 6;
275
+ const right = width - FIRE_BLEED_X - 6;
276
+ const center = width / 2;
277
+
278
+ if (intensity > 0.02 && !reduceMotionRef.current) {
279
+ spawnDebtRef.current += dt * (70 + 260 * intensity);
280
+ while (spawnDebtRef.current >= 1) {
281
+ spawnDebtRef.current -= 1;
282
+ // Bias spawns toward the middle so the flame has a body.
283
+ const spread = (Math.random() + Math.random()) / 2;
284
+ const life = 0.45 + Math.random() * 0.55 * (0.6 + intensity);
285
+ particles.push({
286
+ x: left + spread * (right - left),
287
+ y: baseY + Math.random() * 6,
288
+ vx: (Math.random() - 0.5) * 18,
289
+ vy: -(35 + Math.random() * 55) * (0.55 + intensity),
290
+ age: 0,
291
+ life,
292
+ size: (9 + Math.random() * 13) * (0.55 + 0.6 * intensity),
293
+ seed: Math.random() * 1000,
294
+ });
295
+ }
296
+ }
297
+
298
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
299
+ ctx.clearRect(0, 0, width, height);
300
+
301
+ let alive = 0;
302
+ for (let i = 0; i < particles.length; i++) {
303
+ const p = particles[i];
304
+ p.age += dt;
305
+ if (p.age >= p.life) continue;
306
+
307
+ // Buoyancy, a gentle pull to the centerline, and turbulent sway.
308
+ p.vy -= 60 * dt;
309
+ p.vx += (center - p.x) * 0.9 * dt;
310
+ p.vx += Math.sin(now * 0.004 + p.seed) * 40 * dt;
311
+ p.x += p.vx * dt;
312
+ p.y += p.vy * dt;
313
+ particles[alive++] = p;
314
+
315
+ const t = p.age / p.life;
316
+ const radius = p.size * (1 - t * 0.55);
317
+ const sprite = sprites[Math.min(SPRITE_STEPS - 1, Math.floor(t * SPRITE_STEPS))];
318
+ ctx.globalAlpha = Math.min(1, (1 - t) * 1.4);
319
+ ctx.drawImage(sprite, p.x - radius, p.y - radius, radius * 2, radius * 2);
320
+ }
321
+ particles.length = alive;
322
+ ctx.globalAlpha = 1;
323
+ };
324
+
325
+ const loop = (now: number) => {
326
+ const last = lastTimeRef.current || now;
327
+ const dt = Math.min((now - last) / 1000, 0.05);
328
+ lastTimeRef.current = now;
329
+
330
+ const holding = holdingRef.current;
331
+ const step = dt / (holdDuration / 1000);
332
+ let progress = progressRef.current + (holding ? step : -step * DRAIN_RATE);
333
+ progress = Math.max(0, Math.min(1, progress));
334
+ progressRef.current = progress;
335
+
336
+ if (progress >= 1 && !summonedRef.current) {
337
+ summonedRef.current = true;
338
+ setSummoned(true);
339
+ onSummonRef.current?.();
340
+ } else if (progress < 1 && summonedRef.current) {
341
+ summonedRef.current = false;
342
+ setSummoned(false);
343
+ }
344
+
345
+ // Flames build slowly, then roar once the demon is summoned.
346
+ const intensity = progress >= 1 ? 1 : Math.pow(progress, 1.6) * 0.85;
347
+ paint(progress, now);
348
+ drawFire(intensity, dt, now);
349
+
350
+ if (!holding && progress <= 0 && particlesRef.current.length === 0) {
351
+ rafRef.current = null;
352
+ lastTimeRef.current = 0;
353
+ return;
354
+ }
355
+ rafRef.current = requestAnimationFrame(loop);
356
+ };
357
+
358
+ const ensureLoop = () => {
359
+ if (rafRef.current === null) {
360
+ lastTimeRef.current = 0;
361
+ rafRef.current = requestAnimationFrame(loop);
362
+ }
363
+ };
364
+
365
+ const startHold = () => {
366
+ if (disabled) return;
367
+ holdingRef.current = true;
368
+ buttonRef.current?.setAttribute("data-holding", "");
369
+ ensureLoop();
370
+ };
371
+
372
+ const stopHold = () => {
373
+ if (!holdingRef.current) return;
374
+ holdingRef.current = false;
375
+ buttonRef.current?.removeAttribute("data-holding");
376
+ ensureLoop();
377
+ };
378
+
379
+ return (
380
+ <div ref={wrapperRef} className="relative inline-flex select-none">
381
+ <canvas
382
+ ref={canvasRef}
383
+ aria-hidden
384
+ className="pointer-events-none absolute bottom-1/2 z-0"
385
+ style={{
386
+ left: -FIRE_BLEED_X,
387
+ width: `calc(100% + ${FIRE_BLEED_X * 2}px)`,
388
+ height: FIRE_HEIGHT,
389
+ }}
390
+ />
391
+
392
+ <span
393
+ ref={leftHornRef}
394
+ aria-hidden
395
+ className="pointer-events-none absolute bottom-[45%] left-[14%] z-[1] h-11 w-6 origin-bottom opacity-0"
396
+ style={{ transform: "translateY(26px) rotate(-18deg) scale(0.55)" }}
397
+ >
398
+ <Horn side="left" />
399
+ </span>
400
+ <span
401
+ ref={rightHornRef}
402
+ aria-hidden
403
+ className="pointer-events-none absolute right-[14%] bottom-[45%] z-[1] h-11 w-6 origin-bottom opacity-0"
404
+ style={{ transform: "translateY(26px) rotate(18deg) scale(0.55)" }}
405
+ >
406
+ <Horn side="right" />
407
+ </span>
408
+
409
+ <button
410
+ ref={setButtonRef}
411
+ type={type}
412
+ disabled={disabled}
413
+ data-state={summoned ? "summoned" : "idle"}
414
+ aria-live="polite"
415
+ onPointerDown={(e) => {
416
+ if (e.button !== 0 && e.pointerType === "mouse") return;
417
+ e.currentTarget.setPointerCapture?.(e.pointerId);
418
+ startHold();
419
+ }}
420
+ onPointerUp={stopHold}
421
+ onPointerCancel={stopHold}
422
+ onLostPointerCapture={stopHold}
423
+ onKeyDown={(e) => {
424
+ if ((e.key === " " || e.key === "Enter") && !e.repeat) {
425
+ e.preventDefault();
426
+ startHold();
427
+ }
428
+ }}
429
+ onKeyUp={(e) => {
430
+ if (e.key === " " || e.key === "Enter") {
431
+ e.preventDefault();
432
+ stopHold();
433
+ }
434
+ }}
435
+ onBlur={stopHold}
436
+ onContextMenu={(e) => e.preventDefault()}
437
+ className={cn(
438
+ "relative z-10 inline-flex h-9 min-w-36 cursor-pointer touch-none items-center justify-center overflow-hidden rounded-[10px] px-5 text-sm font-medium text-neutral-50 outline-none",
439
+ // Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop.
440
+ "bg-linear-to-b from-[#353535] to-[#272727] shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.06),inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25),0_4px_12px_-4px_rgb(0_0_0/0.4)]",
441
+ // The loop writes `transform` every frame for the tremble, so the press animates the separate `scale` property.
442
+ "transition-[scale,filter,box-shadow] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
443
+ // Press eases in fast and settles the shadow; release springs back on the slower base curve.
444
+ // data-holding covers pointer, touch, and Space/Enter holds, where :active is unreliable.
445
+ "data-holding:scale-[0.97] data-holding:brightness-95 data-holding:duration-100 data-holding:ease-out data-holding:shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.05),inset_0_1px_0_rgb(255_255_255/0.08),0_0_1px_rgb(0_0_0/0.2),0_1px_3px_-2px_rgb(0_0_0/0.3)] motion-reduce:data-holding:scale-100",
446
+ "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",
447
+ className,
448
+ )}
449
+ {...props}
450
+ >
451
+ {/* Ember glow that rises from the bottom as the charge builds. */}
452
+ <span
453
+ ref={glowRef}
454
+ aria-hidden
455
+ className="pointer-events-none absolute inset-0 opacity-0"
456
+ style={{
457
+ background:
458
+ "radial-gradient(120% 90% at 50% 130%, rgb(255 140 50 / 0.55), rgb(200 40 20 / 0.28) 45%, transparent 75%)",
459
+ }}
460
+ />
461
+ <span className="relative">{children ?? label}</span>
462
+ </button>
463
+ </div>
464
+ );
465
+ },
466
+ );
467
+
468
+ DemonicButton.displayName = "DemonicButton";
469
+
470
+ export default DemonicButton;
@@ -0,0 +1,192 @@
1
+ "use client";
2
+
3
+ import { cn } from "@/lib/utils";
4
+ import { ButtonHTMLAttributes, useEffect, useRef } from "react";
5
+
6
+ const PIXEL_SIZE = 4;
7
+
8
+ const MIN_PIXEL_SIZE = 1;
9
+ const MAX_PIXEL_SIZE = 32;
10
+
11
+ const BAYER: ReadonlyArray<ReadonlyArray<number>> = [
12
+ [16, 8, 14, 6],
13
+ [5, 12, 2, 10],
14
+ [13, 4, 15, 7],
15
+ [1, 9, 3, 11],
16
+ ];
17
+
18
+ function parseRgb(input: string): [number, number, number] {
19
+ const match = input.match(/\d+(?:\.\d+)?/g);
20
+ if (!match || match.length < 3) return [0, 0, 0];
21
+ return [Number(match[0]), Number(match[1]), Number(match[2])];
22
+ }
23
+
24
+ function parseHex(input: string): [number, number, number] | null {
25
+ const hex = input.trim().replace(/^#/, "");
26
+ if (hex.length === 3) {
27
+ const r = parseInt(hex[0] + hex[0], 16);
28
+ const g = parseInt(hex[1] + hex[1], 16);
29
+ const b = parseInt(hex[2] + hex[2], 16);
30
+ if ([r, g, b].some(Number.isNaN)) return null;
31
+ return [r, g, b];
32
+ }
33
+ if (hex.length === 6) {
34
+ const r = parseInt(hex.slice(0, 2), 16);
35
+ const g = parseInt(hex.slice(2, 4), 16);
36
+ const b = parseInt(hex.slice(4, 6), 16);
37
+ if ([r, g, b].some(Number.isNaN)) return null;
38
+ return [r, g, b];
39
+ }
40
+ return null;
41
+ }
42
+
43
+ export type DitherButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
44
+ children: React.ReactNode;
45
+ ditherColor?: string;
46
+ ditherOpacity?: number;
47
+ ditherSize?: number;
48
+ };
49
+
50
+ function DitherButton({
51
+ children,
52
+ className,
53
+ ditherColor = "#999999",
54
+ ditherOpacity = 1,
55
+ ditherSize = PIXEL_SIZE,
56
+ ...props
57
+ }: DitherButtonProps) {
58
+ const canvasRef = useRef<HTMLCanvasElement>(null);
59
+ const colorOverrideRef = useRef<[number, number, number] | null>(null);
60
+ const pixelSizeRef = useRef<number>(PIXEL_SIZE);
61
+
62
+ useEffect(() => {
63
+ colorOverrideRef.current = ditherColor ? parseHex(ditherColor) : null;
64
+ }, [ditherColor]);
65
+
66
+ useEffect(() => {
67
+ const clamped = Math.max(
68
+ MIN_PIXEL_SIZE,
69
+ Math.min(MAX_PIXEL_SIZE, Math.round(ditherSize)),
70
+ );
71
+ pixelSizeRef.current = clamped;
72
+ const canvas = canvasRef.current;
73
+ if (!canvas) return;
74
+ const rect = canvas.getBoundingClientRect();
75
+ const w = Math.max(1, Math.floor(rect.width / clamped));
76
+ const h = Math.max(1, Math.floor(rect.height / clamped));
77
+ if (canvas.width !== w) canvas.width = w;
78
+ if (canvas.height !== h) canvas.height = h;
79
+ }, [ditherSize]);
80
+
81
+ useEffect(() => {
82
+ const canvas = canvasRef.current;
83
+ if (!canvas) return;
84
+ const ctx = canvas.getContext("2d");
85
+ if (!ctx) return;
86
+
87
+ const reduceMotion = window.matchMedia(
88
+ "(prefers-reduced-motion: reduce)",
89
+ ).matches;
90
+
91
+ let rafId = 0;
92
+ const start = performance.now();
93
+
94
+ const resize = () => {
95
+ const rect = canvas.getBoundingClientRect();
96
+ const ps = pixelSizeRef.current;
97
+ const w = Math.max(1, Math.floor(rect.width / ps));
98
+ const h = Math.max(1, Math.floor(rect.height / ps));
99
+ if (canvas.width !== w) canvas.width = w;
100
+ if (canvas.height !== h) canvas.height = h;
101
+ };
102
+ resize();
103
+
104
+ const ro = new ResizeObserver(resize);
105
+ ro.observe(canvas);
106
+
107
+ const draw = (timeSec: number) => {
108
+ const w = canvas.width;
109
+ const h = canvas.height;
110
+
111
+ const computed = getComputedStyle(canvas);
112
+ const override = colorOverrideRef.current;
113
+ const [fr, fg, fb] = override ?? parseRgb(computed.color);
114
+ const [br, bg, bb] = parseRgb(
115
+ computed.getPropertyValue("background-color") || "rgb(255,255,255)",
116
+ );
117
+
118
+ const angle = Math.sin(timeSec * 0.4545) * 0.112;
119
+ const dx = -Math.sin(angle);
120
+ const dy = Math.cos(angle);
121
+
122
+ const img = ctx.createImageData(w, h);
123
+ const data = img.data;
124
+ const cx = w / 2;
125
+ const cy = h / 2;
126
+
127
+ for (let py = 0; py < h; py++) {
128
+ for (let px = 0; px < w; px++) {
129
+ const ps = pixelSizeRef.current;
130
+ const posX = (px - cx) * ps;
131
+ const posY = (py - cy) * ps;
132
+ const value =
133
+ Math.sin((posX * dx + posY * dy) * 0.048 - timeSec * 1.412) * 0.5 +
134
+ 0.5;
135
+ const threshold = BAYER[py & 3][px & 3] / 17;
136
+ const on = value < threshold;
137
+ const i = (py * w + px) * 4;
138
+ if (on) {
139
+ data[i] = fr;
140
+ data[i + 1] = fg;
141
+ data[i + 2] = fb;
142
+ data[i + 3] = 255;
143
+ } else {
144
+ data[i] = br;
145
+ data[i + 1] = bg;
146
+ data[i + 2] = bb;
147
+ data[i + 3] = 255;
148
+ }
149
+ }
150
+ }
151
+ ctx.putImageData(img, 0, 0);
152
+ };
153
+
154
+ if (reduceMotion) {
155
+ draw(0);
156
+ return () => ro.disconnect();
157
+ }
158
+
159
+ const loop = (now: number) => {
160
+ draw((now - start) / 1000);
161
+ rafId = requestAnimationFrame(loop);
162
+ };
163
+ rafId = requestAnimationFrame(loop);
164
+
165
+ return () => {
166
+ cancelAnimationFrame(rafId);
167
+ ro.disconnect();
168
+ };
169
+ }, []);
170
+
171
+ return (
172
+ <button
173
+ {...props}
174
+ className={cn(
175
+ "group relative inline-flex items-center justify-center overflow-hidden rounded-md border-2 border-foreground bg-background px-7 py-3 font-mono text-sm font-bold uppercase tracking-wider text-foreground transition-transform active:translate-y-0.5 active:scale-[0.99]",
176
+ className,
177
+ )}
178
+ >
179
+ <canvas
180
+ ref={canvasRef}
181
+ aria-hidden
182
+ style={{ opacity: ditherOpacity }}
183
+ className="pointer-events-none absolute inset-0 size-full text-foreground [image-rendering:pixelated]"
184
+ />
185
+ <span className="relative z-10 [text-shadow:1px_1px_0_var(--color-background),-1px_1px_0_var(--color-background),1px_-1px_0_var(--color-background),-1px_-1px_0_var(--color-background),0_2px_0_var(--color-background),0_-2px_0_var(--color-background),2px_0_0_var(--color-background),-2px_0_0_var(--color-background)]">
186
+ {children}
187
+ </span>
188
+ </button>
189
+ );
190
+ }
191
+
192
+ export default DitherButton;