motion-ui-skill 2.0.0 → 2.1.1

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,651 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { createPortal } from "react-dom";
5
+ import { cn } from "@/lib/utils";
6
+
7
+ /** One texture pixel, in CSS pixels. Everything snaps to this grid. */
8
+ const PX = 3;
9
+ /** Stone tile size in texels (Minecraft block textures are 16×16). */
10
+ const TILE = 16;
11
+
12
+ const STONE_BASE = "#7d7d7d";
13
+ const STONE_SHADES = ["#747474", "#6a6a6a", "#868686", "#8f8f8f", "#5f5f5f"];
14
+
15
+ function mulberry32(seed: number) {
16
+ let a = seed >>> 0;
17
+ return () => {
18
+ a = (a + 0x6d2b79f5) >>> 0;
19
+ let t = a;
20
+ t = Math.imul(t ^ (t >>> 15), t | 1);
21
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
22
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
23
+ };
24
+ }
25
+
26
+ /** A seeded 16×16 stone texture, so server and client render the same tile. */
27
+ const STONE_TEXTURE = (() => {
28
+ const rand = mulberry32(1337);
29
+ let rects = "";
30
+ for (let y = 0; y < TILE; y++) {
31
+ for (let x = 0; x < TILE; x++) {
32
+ if (rand() < 0.45) continue;
33
+ const shade = STONE_SHADES[Math.floor(rand() * STONE_SHADES.length)]!;
34
+ rects += `<rect x="${x}" y="${y}" width="1" height="1" fill="${shade}"/>`;
35
+ }
36
+ }
37
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${TILE}" height="${TILE}" shape-rendering="crispEdges"><rect width="${TILE}" height="${TILE}" fill="${STONE_BASE}"/>${rects}</svg>`;
38
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
39
+ })();
40
+
41
+ const pixelFont: React.CSSProperties = {
42
+ // Bring your own pixel font through --font-pixel (the docs use Pixelify Sans).
43
+ fontFamily: "var(--font-pixel, ui-monospace), monospace",
44
+ };
45
+
46
+ const stoneStyle: React.CSSProperties = {
47
+ backgroundColor: STONE_BASE,
48
+ backgroundImage: STONE_TEXTURE,
49
+ backgroundSize: `${TILE * PX}px ${TILE * PX}px`,
50
+ imageRendering: "pixelated",
51
+ };
52
+
53
+ /**
54
+ * Pixels of a crack network across a cols×rows grid, ordered so that any
55
+ * prefix is a plausible "earlier" stage: every branch grows one step per round.
56
+ */
57
+ function crackOrder(cols: number, rows: number, seed: number) {
58
+ if (cols < 2 || rows < 2) return [] as [number, number][];
59
+ const rand = mulberry32(seed);
60
+ type Walker = { x: number; y: number; a: number; left: number };
61
+ const walkers: Walker[] = [];
62
+ const origins = Math.max(1, Math.round(cols / 24));
63
+
64
+ for (let i = 0; i < origins; i++) {
65
+ const ox = ((i + 0.5) / origins) * cols + (rand() - 0.5) * 4;
66
+ const oy = rows / 2 + (rand() - 0.5) * 3;
67
+ const branches = 4 + Math.floor(rand() * 2);
68
+ for (let b = 0; b < branches; b++) {
69
+ walkers.push({
70
+ x: ox,
71
+ y: oy,
72
+ a: (b / branches) * Math.PI * 2 + rand() * 0.8,
73
+ left: 7 + Math.floor(rand() * 12),
74
+ });
75
+ }
76
+ }
77
+
78
+ const seen = new Set<number>();
79
+ const order: [number, number][] = [];
80
+ while (walkers.some((w) => w.left > 0)) {
81
+ for (const w of [...walkers]) {
82
+ if (w.left <= 0) continue;
83
+ w.left--;
84
+ w.a += (rand() - 0.5) * 1.1;
85
+ w.x += Math.cos(w.a);
86
+ w.y += Math.sin(w.a) * 0.75;
87
+ const x = Math.round(w.x);
88
+ const y = Math.round(w.y);
89
+ if (x < 0 || y < 0 || x >= cols || y >= rows) {
90
+ w.left = 0;
91
+ continue;
92
+ }
93
+ const key = y * cols + x;
94
+ if (!seen.has(key)) {
95
+ seen.add(key);
96
+ order.push([x, y]);
97
+ }
98
+ if (rand() < 0.12 && w.left > 3) {
99
+ walkers.push({
100
+ x: w.x,
101
+ y: w.y,
102
+ a: w.a + (rand() < 0.5 ? -0.9 : 0.9),
103
+ left: Math.floor(w.left / 2),
104
+ });
105
+ }
106
+ }
107
+ }
108
+ return order;
109
+ }
110
+
111
+ /* ---------- Sound: synthesized, no assets ---------- */
112
+
113
+ let audioCtx: AudioContext | null = null;
114
+
115
+ function getAudio() {
116
+ if (typeof window === "undefined") return null;
117
+ if (!audioCtx) {
118
+ const Ctor =
119
+ window.AudioContext ??
120
+ (window as unknown as { webkitAudioContext?: typeof AudioContext })
121
+ .webkitAudioContext;
122
+ if (!Ctor) return null;
123
+ audioCtx = new Ctor();
124
+ }
125
+ if (audioCtx.state === "suspended") void audioCtx.resume();
126
+ return audioCtx;
127
+ }
128
+
129
+ function playNoise(freq: number, duration: number, volume: number, q = 1) {
130
+ const ctx = getAudio();
131
+ if (!ctx) return;
132
+ const length = Math.floor(ctx.sampleRate * duration);
133
+ const buffer = ctx.createBuffer(1, length, ctx.sampleRate);
134
+ const data = buffer.getChannelData(0);
135
+ for (let i = 0; i < length; i++) data[i] = Math.random() * 2 - 1;
136
+
137
+ const source = ctx.createBufferSource();
138
+ source.buffer = buffer;
139
+ const filter = ctx.createBiquadFilter();
140
+ filter.type = "bandpass";
141
+ filter.frequency.value = freq;
142
+ filter.Q.value = q;
143
+ const gain = ctx.createGain();
144
+ const t = ctx.currentTime;
145
+ gain.gain.setValueAtTime(volume, t);
146
+ gain.gain.exponentialRampToValueAtTime(0.001, t + duration);
147
+
148
+ source.connect(filter).connect(gain).connect(ctx.destination);
149
+ source.start(t);
150
+ }
151
+
152
+ function playPop() {
153
+ const ctx = getAudio();
154
+ if (!ctx) return;
155
+ const osc = ctx.createOscillator();
156
+ const gain = ctx.createGain();
157
+ const t = ctx.currentTime;
158
+ const base = 480 + Math.random() * 160;
159
+ osc.type = "triangle";
160
+ osc.frequency.setValueAtTime(base, t);
161
+ osc.frequency.exponentialRampToValueAtTime(base * 2, t + 0.07);
162
+ gain.gain.setValueAtTime(0.16, t);
163
+ gain.gain.exponentialRampToValueAtTime(0.001, t + 0.12);
164
+ osc.connect(gain).connect(ctx.destination);
165
+ osc.start(t);
166
+ osc.stop(t + 0.13);
167
+ }
168
+
169
+ const sounds = {
170
+ dig: () => playNoise(900 + Math.random() * 400, 0.08, 0.35, 1.4),
171
+ crack: () => playNoise(520, 0.16, 0.5, 0.9),
172
+ break: () => {
173
+ playNoise(320, 0.38, 0.7, 0.7);
174
+ playNoise(1300, 0.22, 0.3, 1.2);
175
+ },
176
+ pop: playPop,
177
+ place: () => playNoise(240, 0.12, 0.55, 0.8),
178
+ };
179
+
180
+ /* ---------- Particles: pixel chips flung with gravity ---------- */
181
+
182
+ function spawnChips(
183
+ layer: HTMLElement,
184
+ origin: { x: number; y: number },
185
+ area: { w: number; h: number },
186
+ count: number,
187
+ force: number,
188
+ ) {
189
+ for (let i = 0; i < count; i++) {
190
+ const chip = document.createElement("span");
191
+ const size = PX * (1 + Math.floor(Math.random() * 2));
192
+ const color =
193
+ Math.random() < 0.3
194
+ ? STONE_BASE
195
+ : STONE_SHADES[Math.floor(Math.random() * STONE_SHADES.length)]!;
196
+ const x0 = origin.x + (Math.random() - 0.5) * area.w;
197
+ const y0 = origin.y + (Math.random() - 0.5) * area.h;
198
+ Object.assign(chip.style, {
199
+ position: "absolute",
200
+ left: `${x0}px`,
201
+ top: `${y0}px`,
202
+ width: `${size}px`,
203
+ height: `${size}px`,
204
+ background: color,
205
+ boxShadow: `inset -1px -1px 0 rgb(0 0 0 / 0.25)`,
206
+ } satisfies Partial<CSSStyleDeclaration>);
207
+ layer.appendChild(chip);
208
+
209
+ const vx = (Math.random() - 0.5) * 2 * force;
210
+ const vy = -(0.4 + Math.random()) * force;
211
+ const gravity = 900;
212
+ const duration = 450 + Math.random() * 450;
213
+ const frames: Keyframe[] = [];
214
+ for (let s = 0; s <= 10; s++) {
215
+ const t = (s / 10) * (duration / 1000);
216
+ const dx = Math.round((vx * t) / PX) * PX;
217
+ const dy = Math.round((vy * t + 0.5 * gravity * t * t) / PX) * PX;
218
+ frames.push({
219
+ transform: `translate(${dx}px, ${dy}px)`,
220
+ opacity: s < 7 ? 1 : 1 - (s - 7) / 3,
221
+ });
222
+ }
223
+ chip
224
+ .animate(frames, { duration, easing: "linear", fill: "forwards" })
225
+ .finished.then(
226
+ () => chip.remove(),
227
+ () => chip.remove(),
228
+ );
229
+ }
230
+ }
231
+
232
+ /* ---------- Pickaxe cursor ---------- */
233
+
234
+ /** 16×16 diamond pickaxe sprite (drawn at 4×, head facing left), inlined so the item stays one file. */
235
+ const PICKAXE_SPRITE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAACmUlEQVR42u1bsUorQRQ9ioUiWCh2GlexeGCTKpWgrQhiwB8QXqEoiM37Bhv9AtFP0M5WQZs0pnwPIaxB3hPCswgEGwubRPaOmtmbuTOzm8zpbnZ2ZvZkztk7d3eBgICBxpDl/iMARQALQv3VAFQBxFITHLFMQHFipXQh2WHzplKWJGDYMgFS/7y1Pm0TkHlwJRCBp+myhTkn+zT2BK4Jbu5sFIimH59fSYO7sXkSzx79IvFb46XrACPTkyQeXZwj8cPWHonbnnDZKwFcCdjQtCmM5jTwHtAPBNRMTmbnAdfV/yTeXpuhs1n/SWJV8/+OT42utnlTuQXQ8aGOCbojIAO4AHAi1Vk/SGDgCDDSvAq2BP7OL5H4TNG8eh8vHOyS+E+lkdRwLxdf9UqAAEQ1bIo8SkAUuhUQgeb+Erm9aC5vCt1eYFPdz+ty+6H9QxKvFqdIrO4drioNo1zeFDoJuMj9ve4vggf4ngA8ewKbAF1u36y3kvf5MoDl5HF179A+/tGm7QnZJSAF1Pv8MvN8p54QPMBy/73k7U49wTYB1d/1VhmJROr86olIQs0T1krTTj3BNgHxF5PPlCcED3A8XuY8gU2Aut9n4pMnwHOe4HoFxMiYJwQP8Dy+d09gE6A+qzOE9zzB9wqI4dkTggdojveiUZO6vXNP0NUEIyhF0YmVElmi3zyrSz0B3Xg/CuNd84Tre1qf4NYYdSsghl6jknX+NOPpwPKE4AHM9rWUv0nBuidw3xGKQDVqu2ChjvfJE0yfO3BXQGzxYtOOJ+oJwQN8T4AJcU/IGwHi9YS8ERBD2BMG3gPyToBxDpI3Cahg1xP6jYAYhp6QdwkYo98ISOMJpI3tj6ZcI0L3Dzq8v5QVEBAQEBCQIbwDjb7c841t6aMAAAAASUVORK5CYII=";
236
+
237
+ /** The pointer sits on the head's top-left corner (texel 3,2); swings pivot on the grip (texel 14,13). */
238
+ const PICKAXE_HOTSPOT = { x: 3.5 * PX, y: 2.5 * PX };
239
+ const PICKAXE_GRIP = { x: 14.5 * PX, y: 13.5 * PX };
240
+ /** Head lifts back clockwise, then strikes down counter-clockwise. */
241
+ const WIND_UP = "rotate(24deg)";
242
+ const STRIKE = "rotate(-28deg)";
243
+
244
+ const pickaxeStyle: React.CSSProperties = {
245
+ width: 16 * PX,
246
+ height: 16 * PX,
247
+ backgroundImage: `url("${PICKAXE_SPRITE}")`,
248
+ backgroundSize: "100% 100%",
249
+ imageRendering: "pixelated",
250
+ transformOrigin: `${PICKAXE_GRIP.x}px ${PICKAXE_GRIP.y}px`,
251
+ };
252
+
253
+ /* ---------- Component ---------- */
254
+
255
+ export interface MinecraftButtonProps
256
+ extends React.ButtonHTMLAttributes<HTMLButtonElement> {
257
+ /** Label used when no children are provided. */
258
+ label?: React.ReactNode;
259
+ /** Taps needed to advance one crack stage. */
260
+ tapsPerStage?: number;
261
+ /** Stages until the button breaks. Breaks after `tapsPerStage * stages` taps. */
262
+ stages?: number;
263
+ /** Play synthesized dig, crack, break, and pickup sounds. */
264
+ sound?: boolean;
265
+ /** Swap the mouse cursor for a pickaxe that swings on each tap. */
266
+ pickaxe?: boolean;
267
+ /** Auto-respawn this many ms after breaking. Omit to wait for the drop to be picked up. */
268
+ respawnAfter?: number;
269
+ /** Fired when the crack deepens to a new stage (1-based). */
270
+ onCrack?: (stage: number) => void;
271
+ /** Fired when the button finally breaks. */
272
+ onBreak?: () => void;
273
+ /** Fired when the button comes back. */
274
+ onRespawn?: () => void;
275
+ }
276
+
277
+ export const MinecraftButton = React.forwardRef<
278
+ HTMLButtonElement,
279
+ MinecraftButtonProps
280
+ >(
281
+ (
282
+ {
283
+ children,
284
+ label = "Singleplayer",
285
+ tapsPerStage = 5,
286
+ stages = 4,
287
+ sound = true,
288
+ pickaxe = true,
289
+ respawnAfter,
290
+ onCrack,
291
+ onBreak,
292
+ onRespawn,
293
+ onClick,
294
+ className,
295
+ style,
296
+ disabled,
297
+ type = "button",
298
+ ...props
299
+ },
300
+ ref,
301
+ ) => {
302
+ const buttonRef = React.useRef<HTMLButtonElement | null>(null);
303
+ const layerRef = React.useRef<HTMLSpanElement | null>(null);
304
+ const itemRef = React.useRef<HTMLButtonElement | null>(null);
305
+ const itemBodyRef = React.useRef<HTMLSpanElement | null>(null);
306
+ const [taps, setTaps] = React.useState(0);
307
+ const [broken, setBroken] = React.useState(false);
308
+ const [grid, setGrid] = React.useState({ cols: 0, rows: 0 });
309
+ const [seed, setSeed] = React.useState(7);
310
+ const [aiming, setAiming] = React.useState(false);
311
+ const pointerRef = React.useRef({ x: 0, y: 0 });
312
+ const cursorRef = React.useRef<HTMLDivElement | null>(null);
313
+ const swingRef = React.useRef<HTMLDivElement | null>(null);
314
+ const swingAnim = React.useRef<Animation | undefined>(undefined);
315
+
316
+ const placeCursor = React.useCallback((node: HTMLDivElement | null) => {
317
+ cursorRef.current = node;
318
+ if (!node) return;
319
+ const { x, y } = pointerRef.current;
320
+ node.style.transform = `translate(${x - PICKAXE_HOTSPOT.x}px, ${y - PICKAXE_HOTSPOT.y}px)`;
321
+ }, []);
322
+
323
+ const swing = (keyframes: Keyframe[], duration: number) => {
324
+ const node = swingRef.current;
325
+ if (!node || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
326
+ swingAnim.current?.cancel();
327
+ swingAnim.current = node.animate(keyframes, {
328
+ duration,
329
+ easing: "cubic-bezier(0.3, 0, 0.2, 1)",
330
+ fill: "forwards",
331
+ });
332
+ };
333
+
334
+ const trackPointer = (event: React.PointerEvent) => {
335
+ const overButton =
336
+ pickaxe &&
337
+ !broken &&
338
+ !disabled &&
339
+ event.pointerType !== "touch" &&
340
+ !!buttonRef.current?.contains(event.target as Node);
341
+ pointerRef.current = { x: event.clientX, y: event.clientY };
342
+ if (cursorRef.current) placeCursor(cursorRef.current);
343
+ if (overButton !== aiming) setAiming(overButton);
344
+ };
345
+
346
+ const perStage = Math.max(1, Math.floor(tapsPerStage));
347
+ const stageCount = Math.max(1, Math.floor(stages));
348
+ const breakAt = perStage * stageCount;
349
+ // The last stage is the break itself, so the visible crack levels stop one short.
350
+ const crackLevels = Math.max(1, stageCount - 1);
351
+ const level = Math.min(Math.floor(taps / perStage), crackLevels);
352
+
353
+ const setButtonRef = (node: HTMLButtonElement | null) => {
354
+ buttonRef.current = node;
355
+ if (typeof ref === "function") ref(node);
356
+ else if (ref) ref.current = node;
357
+ };
358
+
359
+ React.useEffect(() => {
360
+ const button = buttonRef.current;
361
+ if (!button) return;
362
+ const observer = new ResizeObserver(() => {
363
+ setGrid({
364
+ cols: Math.ceil(button.offsetWidth / PX),
365
+ rows: Math.ceil(button.offsetHeight / PX),
366
+ });
367
+ });
368
+ observer.observe(button);
369
+ return () => observer.disconnect();
370
+ }, []);
371
+
372
+ const order = React.useMemo(
373
+ () => crackOrder(grid.cols, grid.rows, seed),
374
+ [grid.cols, grid.rows, seed],
375
+ );
376
+ const visible = order.slice(
377
+ 0,
378
+ Math.round((order.length * level) / crackLevels),
379
+ );
380
+
381
+ const reduceMotion = () =>
382
+ window.matchMedia("(prefers-reduced-motion: reduce)").matches;
383
+
384
+ const respawn = React.useCallback(() => {
385
+ setBroken(false);
386
+ setTaps(0);
387
+ setSeed((s) => s + 1);
388
+ onRespawn?.();
389
+ requestAnimationFrame(() => {
390
+ const button = buttonRef.current;
391
+ if (!button) return;
392
+ button.focus({ preventScroll: true });
393
+ if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
394
+ button.animate(
395
+ [{ transform: "scale(0.9)" }, { transform: "scale(1)" }],
396
+ { duration: 180, easing: "steps(3, end)" },
397
+ );
398
+ }
399
+ });
400
+ }, [onRespawn]);
401
+
402
+ const pickUp = () => {
403
+ if (sound) sounds.pop();
404
+ const item = itemRef.current;
405
+ if (item && !reduceMotion()) {
406
+ item
407
+ .animate(
408
+ [
409
+ { transform: "translate(-50%, -50%) scale(1)", opacity: 1 },
410
+ { transform: "translate(-50%, -110%) scale(0.4)", opacity: 0 },
411
+ ],
412
+ { duration: 140, easing: "ease-in", fill: "forwards" },
413
+ )
414
+ .finished.then(respawn, respawn);
415
+ } else {
416
+ respawn();
417
+ }
418
+ };
419
+
420
+ // Dropped item: pops out, then bobs and spins like an item entity.
421
+ React.useEffect(() => {
422
+ if (!broken) return;
423
+ itemRef.current?.focus({ preventScroll: true });
424
+ const body = itemBodyRef.current;
425
+ let loop: Animation | undefined;
426
+ let drop: Animation | undefined;
427
+ if (body && !window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
428
+ drop = body.animate(
429
+ [
430
+ { transform: "translateY(0) scale(0.5)" },
431
+ { transform: "translateY(-18px) scale(0.9)", offset: 0.4 },
432
+ { transform: "translateY(0) scale(1)" },
433
+ ],
434
+ { duration: 360, easing: "ease-out" },
435
+ );
436
+ drop.finished.then(
437
+ () => {
438
+ loop = body.animate(
439
+ [
440
+ { transform: "translateY(0) rotateY(0deg)" },
441
+ { transform: "translateY(-5px) rotateY(180deg)" },
442
+ { transform: "translateY(0) rotateY(360deg)" },
443
+ ],
444
+ { duration: 2600, iterations: Infinity, easing: "linear" },
445
+ );
446
+ },
447
+ () => {},
448
+ );
449
+ }
450
+ const timer =
451
+ respawnAfter !== undefined
452
+ ? window.setTimeout(respawn, Math.max(0, respawnAfter))
453
+ : undefined;
454
+ return () => {
455
+ drop?.cancel();
456
+ loop?.cancel();
457
+ window.clearTimeout(timer);
458
+ };
459
+ }, [broken, respawnAfter, respawn]);
460
+
461
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
462
+ onClick?.(event);
463
+ if (disabled || broken || event.defaultPrevented) return;
464
+
465
+ // Strike from wherever the pointer-down wind-up left the pickaxe.
466
+ if (aiming) {
467
+ swing(
468
+ [
469
+ { transform: WIND_UP },
470
+ { transform: STRIKE, offset: 0.35 },
471
+ { transform: "rotate(0deg)" },
472
+ ],
473
+ 240,
474
+ );
475
+ }
476
+
477
+ const button = buttonRef.current;
478
+ const layer = layerRef.current;
479
+ const next = taps + 1;
480
+ const nextLevel = Math.min(Math.floor(next / perStage), crackLevels);
481
+ const breaking = next >= breakAt;
482
+ const deepened = !breaking && nextLevel > level;
483
+ const motion = !reduceMotion();
484
+
485
+ if (button && layer && motion) {
486
+ const rect = button.getBoundingClientRect();
487
+ // Keyboard clicks report 0,0; chip from the center instead.
488
+ const fromPointer = event.detail > 0;
489
+ const origin = {
490
+ x: fromPointer ? event.clientX - rect.left : rect.width / 2,
491
+ y: fromPointer ? event.clientY - rect.top : rect.height / 2,
492
+ };
493
+ if (breaking) {
494
+ spawnChips(
495
+ layer,
496
+ { x: rect.width / 2, y: rect.height / 2 },
497
+ { w: rect.width, h: rect.height },
498
+ Math.min(90, Math.round(rect.width / 3)),
499
+ 260,
500
+ );
501
+ } else {
502
+ spawnChips(
503
+ layer,
504
+ origin,
505
+ { w: 6, h: 6 },
506
+ deepened ? 10 : 4,
507
+ deepened ? 200 : 140,
508
+ );
509
+ const kick = deepened ? 3 : 1.5;
510
+ button.animate(
511
+ [
512
+ { transform: "translate(0, 0)" },
513
+ { transform: `translate(${-kick}px, ${kick / 2}px)` },
514
+ { transform: `translate(${kick}px, 0)` },
515
+ { transform: "translate(0, 0)" },
516
+ ],
517
+ { duration: deepened ? 180 : 110, easing: "steps(4, end)" },
518
+ );
519
+ }
520
+ }
521
+
522
+ if (sound) {
523
+ if (breaking) sounds.break();
524
+ else if (deepened) sounds.crack();
525
+ else sounds.dig();
526
+ }
527
+
528
+ setTaps(next);
529
+ if (deepened) onCrack?.(nextLevel);
530
+ if (breaking) {
531
+ setBroken(true);
532
+ onBreak?.();
533
+ }
534
+ };
535
+
536
+ const content = children ?? label;
537
+
538
+ return (
539
+ <span
540
+ className="relative inline-flex align-middle"
541
+ onPointerEnter={trackPointer}
542
+ onPointerMove={trackPointer}
543
+ onPointerLeave={() => setAiming(false)}
544
+ onPointerDown={(event) => {
545
+ trackPointer(event);
546
+ if (aiming) swing([{ transform: WIND_UP }], 90);
547
+ }}
548
+ >
549
+ <button
550
+ ref={setButtonRef}
551
+ type={type}
552
+ disabled={disabled || broken}
553
+ aria-hidden={broken || undefined}
554
+ tabIndex={broken ? -1 : undefined}
555
+ data-stage={level || undefined}
556
+ onClick={handleClick}
557
+ style={{
558
+ ...stoneStyle,
559
+ ...pixelFont,
560
+ ...(aiming ? { cursor: "none" } : null),
561
+ ...style,
562
+ }}
563
+ className={cn(
564
+ "group/mc relative inline-flex h-12 min-w-56 cursor-pointer items-center justify-center rounded-none px-6 outline-none select-none",
565
+ "text-lg leading-none tracking-wide text-[#e0e0e0] [text-shadow:3px_3px_0_#3f3f3f]",
566
+ // Black texel outline with a light top-left bevel and dark bottom-right bevel.
567
+ "shadow-[0_0_0_3px_#000,inset_3px_3px_0_rgb(255_255_255/0.32),inset_-3px_-3px_0_rgb(0_0_0/0.38)]",
568
+ // Hover lights the outline white and turns the label pale yellow, like the Java menus.
569
+ "hover:text-[#ffffa0] hover:shadow-[0_0_0_3px_#fff,inset_3px_3px_0_rgb(255_255_255/0.32),inset_-3px_-3px_0_rgb(0_0_0/0.38)]",
570
+ "focus-visible:text-[#ffffa0] focus-visible:shadow-[0_0_0_3px_#fff,inset_3px_3px_0_rgb(255_255_255/0.32),inset_-3px_-3px_0_rgb(0_0_0/0.38)]",
571
+ // Pressing flips the bevel and sinks the face one texel.
572
+ "active:translate-y-[3px] active:shadow-[0_0_0_3px_#fff,inset_3px_3px_0_rgb(0_0_0/0.38),inset_-3px_-3px_0_rgb(255_255_255/0.2)] motion-reduce:active:translate-y-0",
573
+ "disabled:cursor-not-allowed disabled:text-[#a0a0a0] disabled:brightness-75",
574
+ broken && "invisible",
575
+ className,
576
+ )}
577
+ {...props}
578
+ >
579
+ {visible.length > 0 ? (
580
+ <svg
581
+ aria-hidden
582
+ className="pointer-events-none absolute inset-0 size-full"
583
+ viewBox={`0 0 ${grid.cols} ${grid.rows}`}
584
+ preserveAspectRatio="none"
585
+ shapeRendering="crispEdges"
586
+ >
587
+ {visible.map(([x, y]) => (
588
+ <React.Fragment key={`${x}-${y}`}>
589
+ <rect x={x} y={y + 1} width={1} height={1} fill="rgb(255 255 255 / 0.14)" />
590
+ <rect x={x} y={y} width={1} height={1} fill="rgb(16 16 16 / 0.82)" />
591
+ </React.Fragment>
592
+ ))}
593
+ </svg>
594
+ ) : null}
595
+ <span className="relative">{content}</span>
596
+ </button>
597
+
598
+ <span
599
+ ref={layerRef}
600
+ aria-hidden
601
+ className="pointer-events-none absolute inset-0 z-10 overflow-visible"
602
+ />
603
+
604
+ {/* aiming only turns on from a pointer event, so this never renders on the server. */}
605
+ {aiming
606
+ ? createPortal(
607
+ <div
608
+ ref={placeCursor}
609
+ aria-hidden
610
+ className="pointer-events-none fixed top-0 left-0 z-[90]"
611
+ >
612
+ <div
613
+ ref={swingRef}
614
+ className="drop-shadow-[2px_2px_0_rgb(0_0_0/0.25)]"
615
+ style={pickaxeStyle}
616
+ />
617
+ </div>,
618
+ document.body,
619
+ )
620
+ : null}
621
+
622
+ {broken ? (
623
+ <button
624
+ ref={itemRef}
625
+ type="button"
626
+ onClick={pickUp}
627
+ aria-label={typeof content === "string" ? `Pick up ${content}` : "Pick up"}
628
+ className="group/item absolute top-1/2 left-1/2 z-20 grid size-12 -translate-x-1/2 -translate-y-1/2 cursor-pointer place-items-center outline-none [perspective:240px]"
629
+ >
630
+ <span
631
+ ref={itemBodyRef}
632
+ style={stoneStyle}
633
+ className="block size-6 shadow-[0_0_0_2px_#000,inset_2px_2px_0_rgb(255_255_255/0.32),inset_-2px_-2px_0_rgb(0_0_0/0.38)] [transform-style:preserve-3d] group-focus-visible/item:shadow-[0_0_0_2px_#fff,inset_2px_2px_0_rgb(255_255_255/0.32),inset_-2px_-2px_0_rgb(0_0_0/0.38)]"
634
+ />
635
+ <span className="absolute bottom-1 h-1 w-5 bg-black/30" />
636
+ {/* Item tooltip: near-black purple panel with the violet gradient frame. */}
637
+ <span
638
+ style={pixelFont}
639
+ className="pointer-events-none absolute bottom-full left-1/2 mb-1 -translate-x-1/2 border-2 border-[#100010]/95 bg-[#100010]/95 px-1.5 py-1 text-sm leading-none whitespace-nowrap text-white opacity-0 shadow-[inset_0_0_0_1px_#5000ff80] [text-shadow:2px_2px_0_#3f3f3f] group-hover/item:opacity-100 group-focus-visible/item:opacity-100">
640
+ {content}
641
+ </span>
642
+ </button>
643
+ ) : null}
644
+ </span>
645
+ );
646
+ },
647
+ );
648
+
649
+ MinecraftButton.displayName = "MinecraftButton";
650
+
651
+ export default MinecraftButton;
@@ -0,0 +1,50 @@
1
+ import * as React from "react";
2
+ import { cn } from "@/lib/utils";
3
+
4
+ export interface MinimalButtonProps
5
+ extends React.ButtonHTMLAttributes<HTMLButtonElement> {
6
+ /** Show a trailing chevron that nudges forward on hover. */
7
+ arrow?: boolean;
8
+ }
9
+
10
+ const MinimalButton = React.forwardRef<HTMLButtonElement, MinimalButtonProps>(
11
+ ({ children, className, arrow = true, type = "button", ...props }, ref) => (
12
+ <button
13
+ ref={ref}
14
+ type={type}
15
+ className={cn(
16
+ "group/minimal inline-flex h-9 cursor-pointer items-center justify-center gap-2 rounded-[10px] px-4 text-sm font-medium text-neutral-50 outline-none select-none",
17
+ // Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop.
18
+ "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)]",
19
+ "transition-[scale,filter,box-shadow] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
20
+ // Press eases in fast and settles the shadow; release springs back on the slower base curve.
21
+ "active:scale-[0.97] active:brightness-95 active:duration-100 active:ease-out active: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:active:scale-100",
22
+ "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",
23
+ arrow && "pr-3",
24
+ className,
25
+ )}
26
+ {...props}
27
+ >
28
+ <span>{children}</span>
29
+ {arrow ? (
30
+ <svg
31
+ aria-hidden
32
+ viewBox="0 0 16 16"
33
+ fill="none"
34
+ stroke="currentColor"
35
+ strokeWidth="1.75"
36
+ strokeLinecap="round"
37
+ strokeLinejoin="round"
38
+ className="size-3.5 text-neutral-50/45 transition-[translate,color] duration-150 group-hover/minimal:translate-x-0.5 group-hover/minimal:text-neutral-50/75"
39
+ >
40
+ <path d="m6 4 4 4-4 4" />
41
+ </svg>
42
+ ) : null}
43
+ </button>
44
+ ),
45
+ );
46
+
47
+ MinimalButton.displayName = "MinimalButton";
48
+
49
+ export { MinimalButton };
50
+ export default MinimalButton;