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.
- 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,528 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import {
|
|
6
|
+
Bodies,
|
|
7
|
+
Body,
|
|
8
|
+
Composite,
|
|
9
|
+
Engine,
|
|
10
|
+
World,
|
|
11
|
+
} from "matter-js";
|
|
12
|
+
import { cn } from "@/lib/utils";
|
|
13
|
+
|
|
14
|
+
/** Mostly charcoal and ash grey, with a few embers. */
|
|
15
|
+
const ASH_COLORS = [
|
|
16
|
+
"#171717",
|
|
17
|
+
"#262626",
|
|
18
|
+
"#404040",
|
|
19
|
+
"#525252",
|
|
20
|
+
"#737373",
|
|
21
|
+
"#a3a3a3",
|
|
22
|
+
"#b91c1c",
|
|
23
|
+
"#f97316",
|
|
24
|
+
];
|
|
25
|
+
/** How long the ember glow stays on the button after a burst. */
|
|
26
|
+
const FIRE_MS = 480;
|
|
27
|
+
|
|
28
|
+
type ParticleKind = "circle" | "square" | "shard";
|
|
29
|
+
|
|
30
|
+
type ParticleMeta = {
|
|
31
|
+
color: string;
|
|
32
|
+
kind: ParticleKind;
|
|
33
|
+
size: number;
|
|
34
|
+
born: number;
|
|
35
|
+
life: number;
|
|
36
|
+
glow: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type AshSim = {
|
|
40
|
+
engine: Matter.Engine;
|
|
41
|
+
buttonBody: Matter.Body;
|
|
42
|
+
leftLip: Matter.Body;
|
|
43
|
+
rightLip: Matter.Body;
|
|
44
|
+
meta: Map<number, ParticleMeta>;
|
|
45
|
+
raf: number;
|
|
46
|
+
canvas: HTMLCanvasElement;
|
|
47
|
+
ctx: CanvasRenderingContext2D;
|
|
48
|
+
startedAt: number;
|
|
49
|
+
lastW: number;
|
|
50
|
+
lastH: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export interface AshBurstButtonProps
|
|
54
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
55
|
+
/** Label used when no children are provided. */
|
|
56
|
+
label?: React.ReactNode;
|
|
57
|
+
/** Ash particles per burst. */
|
|
58
|
+
particleCount?: number;
|
|
59
|
+
/** Burst spread in degrees. */
|
|
60
|
+
spread?: number;
|
|
61
|
+
/** Extra launch velocity (mapped into Matter velocity). */
|
|
62
|
+
startVelocity?: number;
|
|
63
|
+
/** Custom ash / ember colors. */
|
|
64
|
+
colors?: string[];
|
|
65
|
+
/** Show the leading ember icon. */
|
|
66
|
+
icon?: boolean;
|
|
67
|
+
/** Fired after each ash burst. */
|
|
68
|
+
onDestroy?: () => void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Warm reds and oranges get a soft glow; greys stay flat. */
|
|
72
|
+
function isEmber(color: string) {
|
|
73
|
+
const hex = color.replace("#", "");
|
|
74
|
+
if (hex.length < 6) return false;
|
|
75
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
76
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
77
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
78
|
+
return r > 150 && r > g + 40 && r > b + 60;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function pick<T>(items: T[]): T {
|
|
82
|
+
return items[Math.floor(Math.random() * items.length)]!;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function drawShard(
|
|
86
|
+
ctx: CanvasRenderingContext2D,
|
|
87
|
+
size: number,
|
|
88
|
+
color: string,
|
|
89
|
+
) {
|
|
90
|
+
ctx.fillStyle = color;
|
|
91
|
+
ctx.beginPath();
|
|
92
|
+
ctx.moveTo(0, -size);
|
|
93
|
+
ctx.lineTo(size * 0.55, -size * 0.15);
|
|
94
|
+
ctx.lineTo(size * 0.35, size);
|
|
95
|
+
ctx.lineTo(-size * 0.45, size * 0.55);
|
|
96
|
+
ctx.lineTo(-size * 0.2, -size * 0.35);
|
|
97
|
+
ctx.closePath();
|
|
98
|
+
ctx.fill();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function sizeCanvas(canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) {
|
|
102
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
103
|
+
const w = window.innerWidth;
|
|
104
|
+
const h = window.innerHeight;
|
|
105
|
+
canvas.width = w * dpr;
|
|
106
|
+
canvas.height = h * dpr;
|
|
107
|
+
canvas.style.width = `${w}px`;
|
|
108
|
+
canvas.style.height = `${h}px`;
|
|
109
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function syncColliders(sim: AshSim, button: HTMLElement) {
|
|
113
|
+
const rect = button.getBoundingClientRect();
|
|
114
|
+
const cx = rect.left + rect.width / 2;
|
|
115
|
+
const cy = rect.top + rect.height / 2;
|
|
116
|
+
const w = Math.max(8, rect.width);
|
|
117
|
+
const h = Math.max(8, rect.height);
|
|
118
|
+
|
|
119
|
+
if (sim.lastW > 0 && sim.lastH > 0) {
|
|
120
|
+
const sx = w / sim.lastW;
|
|
121
|
+
const sy = h / sim.lastH;
|
|
122
|
+
if (Math.abs(sx - 1) > 0.005 || Math.abs(sy - 1) > 0.005) {
|
|
123
|
+
Body.scale(sim.buttonBody, sx, sy);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
Body.setPosition(sim.buttonBody, { x: cx, y: cy });
|
|
128
|
+
|
|
129
|
+
const lipW = Math.max(10, w * 0.1);
|
|
130
|
+
const lipH = 7;
|
|
131
|
+
Body.setPosition(sim.leftLip, {
|
|
132
|
+
x: rect.left + lipW / 2,
|
|
133
|
+
y: rect.top - lipH / 2 + 1,
|
|
134
|
+
});
|
|
135
|
+
Body.setPosition(sim.rightLip, {
|
|
136
|
+
x: rect.right - lipW / 2,
|
|
137
|
+
y: rect.top - lipH / 2 + 1,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
sim.lastW = w;
|
|
141
|
+
sim.lastH = h;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function createAshSimulation(
|
|
145
|
+
canvas: HTMLCanvasElement,
|
|
146
|
+
button: HTMLElement,
|
|
147
|
+
options: {
|
|
148
|
+
particleCount: number;
|
|
149
|
+
spread: number;
|
|
150
|
+
startVelocity: number;
|
|
151
|
+
colors: string[];
|
|
152
|
+
},
|
|
153
|
+
): AshSim {
|
|
154
|
+
const ctx = canvas.getContext("2d")!;
|
|
155
|
+
sizeCanvas(canvas, ctx);
|
|
156
|
+
|
|
157
|
+
const engine = Engine.create({
|
|
158
|
+
gravity: { x: 0, y: 1.4 },
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const rect = button.getBoundingClientRect();
|
|
162
|
+
const cx = rect.left + rect.width / 2;
|
|
163
|
+
const cy = rect.top + rect.height / 2;
|
|
164
|
+
const w = Math.max(8, rect.width);
|
|
165
|
+
const h = Math.max(8, rect.height);
|
|
166
|
+
|
|
167
|
+
const buttonBody = Bodies.rectangle(cx, cy, w, h, {
|
|
168
|
+
isStatic: true,
|
|
169
|
+
friction: 1.25,
|
|
170
|
+
frictionStatic: 1.4,
|
|
171
|
+
restitution: 0.18,
|
|
172
|
+
chamfer: { radius: Math.min(8, h / 2) },
|
|
173
|
+
label: "ash-button",
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const lipW = Math.max(10, w * 0.1);
|
|
177
|
+
const lipH = 7;
|
|
178
|
+
const leftLip = Bodies.rectangle(
|
|
179
|
+
rect.left + lipW / 2,
|
|
180
|
+
rect.top - lipH / 2 + 1,
|
|
181
|
+
lipW,
|
|
182
|
+
lipH,
|
|
183
|
+
{
|
|
184
|
+
isStatic: true,
|
|
185
|
+
friction: 1.4,
|
|
186
|
+
restitution: 0.04,
|
|
187
|
+
label: "ash-lip",
|
|
188
|
+
},
|
|
189
|
+
);
|
|
190
|
+
const rightLip = Bodies.rectangle(
|
|
191
|
+
rect.right - lipW / 2,
|
|
192
|
+
rect.top - lipH / 2 + 1,
|
|
193
|
+
lipW,
|
|
194
|
+
lipH,
|
|
195
|
+
{
|
|
196
|
+
isStatic: true,
|
|
197
|
+
friction: 1.4,
|
|
198
|
+
restitution: 0.04,
|
|
199
|
+
label: "ash-lip",
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
World.add(engine.world, [buttonBody, leftLip, rightLip]);
|
|
204
|
+
|
|
205
|
+
const meta = new Map<number, ParticleMeta>();
|
|
206
|
+
const now = performance.now();
|
|
207
|
+
const count = Math.max(12, options.particleCount);
|
|
208
|
+
|
|
209
|
+
for (let i = 0; i < count; i++) {
|
|
210
|
+
const kindRoll = Math.random();
|
|
211
|
+
const kind: ParticleKind =
|
|
212
|
+
kindRoll > 0.75 ? "shard" : kindRoll > 0.4 ? "square" : "circle";
|
|
213
|
+
|
|
214
|
+
const size =
|
|
215
|
+
kind === "shard" ? 2.5 + Math.random() * 3 : 1.6 + Math.random() * 2.6;
|
|
216
|
+
|
|
217
|
+
const halfSpread = (options.spread * Math.PI) / 180 / 2;
|
|
218
|
+
const angle = -Math.PI / 2 + (Math.random() * 2 - 1) * halfSpread;
|
|
219
|
+
// Balanced kick: readable burst without flying off too hard.
|
|
220
|
+
const speed =
|
|
221
|
+
options.startVelocity * (0.45 + Math.random() * 0.55) * 0.7;
|
|
222
|
+
|
|
223
|
+
// Mostly explode from center; a few rain down later to settle on top.
|
|
224
|
+
const rain = Math.random() > 0.72;
|
|
225
|
+
const spawnX = rain
|
|
226
|
+
? rect.left + Math.random() * w
|
|
227
|
+
: cx + (Math.random() - 0.5) * w * 0.4;
|
|
228
|
+
const spawnY = rain
|
|
229
|
+
? rect.top - 8 - Math.random() * 28
|
|
230
|
+
: cy + (Math.random() - 0.5) * h * 0.3;
|
|
231
|
+
|
|
232
|
+
const body =
|
|
233
|
+
kind === "circle"
|
|
234
|
+
? Bodies.circle(spawnX, spawnY, size * 0.85, {
|
|
235
|
+
restitution: 0.35 + Math.random() * 0.3,
|
|
236
|
+
friction: 0.65 + Math.random() * 0.4,
|
|
237
|
+
frictionAir: 0.008 + Math.random() * 0.012,
|
|
238
|
+
density: 0.0012,
|
|
239
|
+
label: "ash-particle",
|
|
240
|
+
})
|
|
241
|
+
: Bodies.rectangle(
|
|
242
|
+
spawnX,
|
|
243
|
+
spawnY,
|
|
244
|
+
size * (kind === "shard" ? 1.4 : 1.6),
|
|
245
|
+
size * (kind === "shard" ? 2.2 : 1.6),
|
|
246
|
+
{
|
|
247
|
+
restitution: 0.3 + Math.random() * 0.28,
|
|
248
|
+
friction: 0.7 + Math.random() * 0.4,
|
|
249
|
+
frictionAir: 0.009 + Math.random() * 0.012,
|
|
250
|
+
density: 0.0013,
|
|
251
|
+
angle: Math.random() * Math.PI,
|
|
252
|
+
label: "ash-particle",
|
|
253
|
+
},
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
if (rain) {
|
|
257
|
+
Body.setVelocity(body, {
|
|
258
|
+
x: (Math.random() - 0.5) * 3.5,
|
|
259
|
+
y: 1 + Math.random() * 3,
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
Body.setVelocity(body, {
|
|
263
|
+
x: Math.cos(angle) * speed + (Math.random() - 0.5) * 4,
|
|
264
|
+
y: Math.sin(angle) * speed - (2 + Math.random() * 5),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
Body.setAngularVelocity(body, (Math.random() - 0.5) * 0.55);
|
|
268
|
+
|
|
269
|
+
const color = pick(options.colors);
|
|
270
|
+
meta.set(body.id, {
|
|
271
|
+
color,
|
|
272
|
+
glow: isEmber(color),
|
|
273
|
+
kind,
|
|
274
|
+
size,
|
|
275
|
+
born: now,
|
|
276
|
+
life: 3200 + Math.random() * 2200,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
World.add(engine.world, body);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
engine,
|
|
284
|
+
buttonBody,
|
|
285
|
+
leftLip,
|
|
286
|
+
rightLip,
|
|
287
|
+
meta,
|
|
288
|
+
raf: 0,
|
|
289
|
+
canvas,
|
|
290
|
+
ctx,
|
|
291
|
+
startedAt: now,
|
|
292
|
+
lastW: w,
|
|
293
|
+
lastH: h,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function paintSim(sim: AshSim, button: HTMLElement) {
|
|
298
|
+
const { ctx, canvas, engine, meta } = sim;
|
|
299
|
+
const w = canvas.clientWidth;
|
|
300
|
+
const h = canvas.clientHeight;
|
|
301
|
+
|
|
302
|
+
syncColliders(sim, button);
|
|
303
|
+
Engine.update(engine, 1000 / 60);
|
|
304
|
+
|
|
305
|
+
ctx.clearRect(0, 0, w, h);
|
|
306
|
+
|
|
307
|
+
const now = performance.now();
|
|
308
|
+
const toRemove: Matter.Body[] = [];
|
|
309
|
+
|
|
310
|
+
for (const body of Composite.allBodies(engine.world)) {
|
|
311
|
+
if (body.label !== "ash-particle") continue;
|
|
312
|
+
const info = meta.get(body.id);
|
|
313
|
+
if (!info) continue;
|
|
314
|
+
|
|
315
|
+
const age = now - info.born;
|
|
316
|
+
const fade = Math.max(0, 1 - age / info.life);
|
|
317
|
+
if (
|
|
318
|
+
fade <= 0 ||
|
|
319
|
+
body.position.y > h + 48 ||
|
|
320
|
+
body.position.x < -48 ||
|
|
321
|
+
body.position.x > w + 48
|
|
322
|
+
) {
|
|
323
|
+
toRemove.push(body);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
ctx.save();
|
|
328
|
+
ctx.translate(body.position.x, body.position.y);
|
|
329
|
+
ctx.rotate(body.angle);
|
|
330
|
+
ctx.globalAlpha = 0.4 + fade * 0.6;
|
|
331
|
+
|
|
332
|
+
if (info.glow) {
|
|
333
|
+
ctx.globalAlpha = fade * 0.22;
|
|
334
|
+
ctx.fillStyle = info.color;
|
|
335
|
+
ctx.beginPath();
|
|
336
|
+
ctx.arc(0, 0, info.size * 2, 0, Math.PI * 2);
|
|
337
|
+
ctx.fill();
|
|
338
|
+
ctx.globalAlpha = 0.4 + fade * 0.6;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (info.kind === "shard") {
|
|
342
|
+
drawShard(ctx, info.size, info.color);
|
|
343
|
+
} else if (info.kind === "square") {
|
|
344
|
+
ctx.fillStyle = info.color;
|
|
345
|
+
ctx.fillRect(-info.size, -info.size, info.size * 2, info.size * 2);
|
|
346
|
+
} else {
|
|
347
|
+
ctx.fillStyle = info.color;
|
|
348
|
+
ctx.beginPath();
|
|
349
|
+
ctx.arc(0, 0, info.size, 0, Math.PI * 2);
|
|
350
|
+
ctx.fill();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
ctx.restore();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
for (const body of toRemove) {
|
|
357
|
+
meta.delete(body.id);
|
|
358
|
+
World.remove(engine.world, body);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return meta.size > 0 && now - sim.startedAt < 6500;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export const AshBurstButton = React.forwardRef<
|
|
365
|
+
HTMLButtonElement,
|
|
366
|
+
AshBurstButtonProps
|
|
367
|
+
>(
|
|
368
|
+
(
|
|
369
|
+
{
|
|
370
|
+
children,
|
|
371
|
+
label = "Delete",
|
|
372
|
+
particleCount = 80,
|
|
373
|
+
spread = 110,
|
|
374
|
+
startVelocity = 42,
|
|
375
|
+
colors = ASH_COLORS,
|
|
376
|
+
icon = true,
|
|
377
|
+
onDestroy,
|
|
378
|
+
onClick,
|
|
379
|
+
className,
|
|
380
|
+
disabled,
|
|
381
|
+
type = "button",
|
|
382
|
+
...props
|
|
383
|
+
},
|
|
384
|
+
ref,
|
|
385
|
+
) => {
|
|
386
|
+
const buttonRef = React.useRef<HTMLButtonElement | null>(null);
|
|
387
|
+
const canvasRef = React.useRef<HTMLCanvasElement | null>(null);
|
|
388
|
+
const simRef = React.useRef<AshSim | null>(null);
|
|
389
|
+
const fireTimerRef = React.useRef<number | undefined>(undefined);
|
|
390
|
+
const [simActive, setSimActive] = React.useState(false);
|
|
391
|
+
const [firing, setFiring] = React.useState(false);
|
|
392
|
+
const [mounted, setMounted] = React.useState(false);
|
|
393
|
+
|
|
394
|
+
React.useEffect(() => setMounted(true), []);
|
|
395
|
+
|
|
396
|
+
const setButtonRef = (node: HTMLButtonElement | null) => {
|
|
397
|
+
buttonRef.current = node;
|
|
398
|
+
if (typeof ref === "function") ref(node);
|
|
399
|
+
else if (ref) ref.current = node;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
const clearSim = (sim: AshSim) => {
|
|
403
|
+
cancelAnimationFrame(sim.raf);
|
|
404
|
+
World.clear(sim.engine.world, false);
|
|
405
|
+
Engine.clear(sim.engine);
|
|
406
|
+
sim.ctx.clearRect(0, 0, sim.canvas.clientWidth, sim.canvas.clientHeight);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const stopSim = React.useCallback(() => {
|
|
410
|
+
if (simRef.current) clearSim(simRef.current);
|
|
411
|
+
simRef.current = null;
|
|
412
|
+
setSimActive(false);
|
|
413
|
+
}, []);
|
|
414
|
+
|
|
415
|
+
React.useEffect(
|
|
416
|
+
() => () => {
|
|
417
|
+
stopSim();
|
|
418
|
+
window.clearTimeout(fireTimerRef.current);
|
|
419
|
+
},
|
|
420
|
+
[stopSim],
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
const startPhysicsBurst = () => {
|
|
424
|
+
const button = buttonRef.current;
|
|
425
|
+
const canvas = canvasRef.current;
|
|
426
|
+
if (!button || !canvas) return;
|
|
427
|
+
|
|
428
|
+
if (simRef.current) clearSim(simRef.current);
|
|
429
|
+
setSimActive(true);
|
|
430
|
+
|
|
431
|
+
const sim = createAshSimulation(canvas, button, {
|
|
432
|
+
particleCount,
|
|
433
|
+
spread,
|
|
434
|
+
startVelocity,
|
|
435
|
+
colors,
|
|
436
|
+
});
|
|
437
|
+
simRef.current = sim;
|
|
438
|
+
|
|
439
|
+
const tick = () => {
|
|
440
|
+
const current = simRef.current;
|
|
441
|
+
const btn = buttonRef.current;
|
|
442
|
+
if (!current || !btn) return;
|
|
443
|
+
|
|
444
|
+
if (paintSim(current, btn)) {
|
|
445
|
+
current.raf = requestAnimationFrame(tick);
|
|
446
|
+
} else {
|
|
447
|
+
stopSim();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
sim.raf = requestAnimationFrame(tick);
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
455
|
+
onClick?.(event);
|
|
456
|
+
if (disabled || event.defaultPrevented) return;
|
|
457
|
+
|
|
458
|
+
const reduceMotion = window.matchMedia(
|
|
459
|
+
"(prefers-reduced-motion: reduce)",
|
|
460
|
+
).matches;
|
|
461
|
+
if (!reduceMotion) startPhysicsBurst();
|
|
462
|
+
|
|
463
|
+
setFiring(true);
|
|
464
|
+
window.clearTimeout(fireTimerRef.current);
|
|
465
|
+
fireTimerRef.current = window.setTimeout(() => setFiring(false), FIRE_MS);
|
|
466
|
+
onDestroy?.();
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const overlay = mounted
|
|
470
|
+
? createPortal(
|
|
471
|
+
<canvas
|
|
472
|
+
ref={canvasRef}
|
|
473
|
+
aria-hidden
|
|
474
|
+
className="pointer-events-none fixed inset-0 z-[80]"
|
|
475
|
+
style={{ opacity: simActive ? 1 : 0 }}
|
|
476
|
+
/>,
|
|
477
|
+
document.body,
|
|
478
|
+
)
|
|
479
|
+
: null;
|
|
480
|
+
|
|
481
|
+
return (
|
|
482
|
+
<>
|
|
483
|
+
{overlay}
|
|
484
|
+
<button
|
|
485
|
+
ref={setButtonRef}
|
|
486
|
+
type={type}
|
|
487
|
+
disabled={disabled}
|
|
488
|
+
data-firing={firing || undefined}
|
|
489
|
+
onClick={handleClick}
|
|
490
|
+
className={cn(
|
|
491
|
+
"group/ash 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",
|
|
492
|
+
// Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop.
|
|
493
|
+
"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)]",
|
|
494
|
+
"transition-[scale,filter,box-shadow] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
|
|
495
|
+
// Press eases in fast and settles the shadow; release springs back on the slower base curve.
|
|
496
|
+
"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",
|
|
497
|
+
// A burst leaves a faint ember glow on the face that cools back to the idle surface.
|
|
498
|
+
"data-firing:shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(249_115_22/0.18),inset_0_1px_0_rgb(255_255_255/0.14),inset_0_-8px_16px_-8px_rgb(239_68_68/0.35),0_1px_2px_rgb(0_0_0/0.25),0_4px_16px_-4px_rgb(239_68_68/0.35)]",
|
|
499
|
+
"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",
|
|
500
|
+
icon && "pl-3",
|
|
501
|
+
className,
|
|
502
|
+
)}
|
|
503
|
+
{...props}
|
|
504
|
+
>
|
|
505
|
+
{icon ? (
|
|
506
|
+
<svg
|
|
507
|
+
aria-hidden
|
|
508
|
+
viewBox="0 0 16 16"
|
|
509
|
+
fill="currentColor"
|
|
510
|
+
className={cn(
|
|
511
|
+
"size-3.5 text-neutral-50/45 transition-[translate,scale,color] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)]",
|
|
512
|
+
"group-hover/ash:text-red-400/80",
|
|
513
|
+
"group-data-firing/ash:-translate-y-px group-data-firing/ash:scale-110 group-data-firing/ash:text-orange-400 motion-reduce:transform-none",
|
|
514
|
+
)}
|
|
515
|
+
>
|
|
516
|
+
<path d="M8.6 1.2c.3 2-.6 3.1-1.6 4.2C5.9 6.6 4.5 8 4.5 10.2 4.5 12.6 6.2 14.5 8 14.5s3.5-1.6 3.5-4.1c0-1.5-.6-2.6-1.3-3.4-.1 1.1-.6 1.8-1.4 2.1.5-2.7-.1-5.8-2.2-7.9Z" />
|
|
517
|
+
</svg>
|
|
518
|
+
) : null}
|
|
519
|
+
<span>{children ?? label}</span>
|
|
520
|
+
</button>
|
|
521
|
+
</>
|
|
522
|
+
);
|
|
523
|
+
},
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
AshBurstButton.displayName = "AshBurstButton";
|
|
527
|
+
|
|
528
|
+
export default AshBurstButton;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
|
|
6
|
+
export interface BrutalButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
7
|
+
color?: string;
|
|
8
|
+
textColor?: string;
|
|
9
|
+
hasBorder?: boolean;
|
|
10
|
+
borderColor?: string;
|
|
11
|
+
hasShadow?: boolean;
|
|
12
|
+
shadowColor?: string;
|
|
13
|
+
radius?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const BrutalButton = React.forwardRef<HTMLButtonElement, BrutalButtonProps>(
|
|
17
|
+
(
|
|
18
|
+
{
|
|
19
|
+
className,
|
|
20
|
+
color,
|
|
21
|
+
textColor,
|
|
22
|
+
hasBorder = true,
|
|
23
|
+
borderColor,
|
|
24
|
+
hasShadow = true,
|
|
25
|
+
shadowColor,
|
|
26
|
+
radius = 0,
|
|
27
|
+
children,
|
|
28
|
+
style,
|
|
29
|
+
...props
|
|
30
|
+
},
|
|
31
|
+
ref
|
|
32
|
+
) => {
|
|
33
|
+
const customStyles = {
|
|
34
|
+
"--btn-bg": color || "var(--background)",
|
|
35
|
+
"--btn-text": textColor || "var(--foreground)",
|
|
36
|
+
"--btn-border": hasBorder ? borderColor || "var(--foreground)" : "transparent",
|
|
37
|
+
"--btn-shadow": shadowColor || "var(--foreground)",
|
|
38
|
+
"--btn-radius": `${radius}px`,
|
|
39
|
+
...style,
|
|
40
|
+
} as React.CSSProperties;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<button
|
|
44
|
+
ref={ref}
|
|
45
|
+
className={cn(
|
|
46
|
+
"inline-flex items-center justify-center px-6 py-3 font-bold transition-all duration-200 ease-in-out",
|
|
47
|
+
hasBorder ? "border-2" : "border-0",
|
|
48
|
+
hasShadow
|
|
49
|
+
? "shadow-[4px_4px_0px_var(--btn-shadow)] hover:translate-x-[-2px] hover:translate-y-[-2px] hover:shadow-[6px_6px_0px_var(--btn-shadow)] active:translate-x-[4px] active:translate-y-[4px] active:shadow-none"
|
|
50
|
+
: "active:scale-95",
|
|
51
|
+
className
|
|
52
|
+
)}
|
|
53
|
+
style={{
|
|
54
|
+
backgroundColor: "var(--btn-bg)",
|
|
55
|
+
color: "var(--btn-text)",
|
|
56
|
+
borderColor: "var(--btn-border)",
|
|
57
|
+
borderRadius: "var(--btn-radius)",
|
|
58
|
+
...customStyles,
|
|
59
|
+
}}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
{children}
|
|
63
|
+
</button>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
BrutalButton.displayName = "BrutalButton";
|