Reactor Button
A button that reacts when you press it: a quick strike, or a press-and-hold to confirm with a charging bar.
- <kt-reactor-button>
- Actions
- No framework
The code
Copy the Reactor Button
Fastest: press Copy on the card above for one complete file. To build it into your own
project, use the files below: the markup, the styles, this component’s script and the shared
effects script (effects.js) that every component uses.
<kt-reactor-button mode="strike" sfx="ドン!" tag="STRIKE">Deploy Build</kt-reactor-button>
<kt-reactor-button mode="hold" duration="850" sfx="ドカン!" tag="HOLD">Hold to Confirm</kt-reactor-button>
<kt-reactor-button mode="strike" tone="outline" sfx="カチッ!">Inspect</kt-reactor-button>
kt-reactor-button {
display: inline-block;
}
.kt-btn {
--_color: var(--kt-accent);
--_ink: var(--kt-accent-ink);
--mx: 50%;
--my: 50%;
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
height: 44px;
padding: 0 20px;
border-radius: var(--kt-radius-btn);
border-style: solid;
border-width: var(--kt-border-w);
border-color: var(--kt-comp-border, var(--_color));
background: var(--_color);
color: var(--_ink);
font-family: var(--font-sans);
font-size: 14px;
font-weight: 600;
letter-spacing: -0.01em;
cursor: pointer;
user-select: none;
overflow: hidden;
isolation: isolate;
box-shadow: var(--kt-comp-shadow);
-webkit-tap-highlight-color: transparent;
transition: transform 180ms ease, background-color 150ms ease, border-color 150ms ease, opacity 150ms ease, box-shadow 180ms ease;
}
.kt-btn[data-tone="outline"] {
background: var(--kt-surface-bg);
color: var(--kt-surface-ink);
border-color: var(--kt-comp-border, var(--_color));
}
.kt-btn__spotlight {
position: absolute;
inset: 0;
pointer-events: none;
opacity: 0;
background: radial-gradient(95px circle at var(--mx) var(--my), rgba(255, 255, 255, 0.28), transparent 70%);
transition: opacity 160ms ease;
z-index: 0;
}
[data-vfx="enterprise"] .kt-btn__spotlight {
display: none;
}
.kt-btn:hover:not(:disabled) .kt-btn__spotlight {
opacity: 1;
}
[data-vfx="enterprise"] .kt-btn:hover:not(:disabled) {
opacity: 0.88;
}
[data-vfx="enterprise"] .kt-btn:active:not(:disabled) {
transform: translateY(1px);
}
[data-vfx="sakuga"] .kt-btn:hover:not(:disabled) {
transform: translateY(-2px) scale(1.02);
}
[data-vfx="elastic"] .kt-btn:hover:not(:disabled) {
transform: scale(1.035, 0.975);
}
[data-vfx="glitch"] .kt-btn:hover:not(:disabled) {
transform: translate(-1px, -1px);
}
[data-vfx="neon"] .kt-btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 0 22px -2px color-mix(in srgb, var(--_color) 70%, transparent);
}
[data-vfx="ink"] .kt-btn:hover:not(:disabled) {
transform: translateY(-1px) rotate(-0.6deg);
}
.kt-btn__fill {
position: absolute;
inset: 0;
background: rgba(255, 255, 255, 0.26);
transform-origin: left center;
transform: scaleX(0);
pointer-events: none;
z-index: 0;
}
.kt-btn[data-tone="outline"] .kt-btn__fill {
background: color-mix(in srgb, var(--_color) 18%, transparent);
}
.kt-btn__content {
position: relative;
z-index: 1;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
line-height: 1;
pointer-events: none;
}
.kt-btn__tag {
display: inline-flex;
align-items: center;
justify-content: center;
font-family: var(--font-mono);
font-size: 10px;
font-weight: 700;
line-height: 1;
padding: 3px 6px;
border-radius: var(--kt-radius-tag);
background: rgba(128, 128, 128, 0.22);
}
/* Sakuga, Elastic Jelly & Cyber Glitch Motion Classes */
[data-vfx="sakuga"] .kt-btn.is-pressed:not(:disabled) {
transform: scale(1.07, 0.87) translateY(2px);
transition-duration: 70ms;
}
[data-vfx="elastic"] .kt-btn.is-pressed:not(:disabled) {
transform: scale(1.11, 0.82) translateY(2px);
transition-duration: 90ms;
}
[data-vfx="glitch"] .kt-btn.is-pressed:not(:disabled) {
transform: skewX(-6deg) translate(2px, 1px);
transition-duration: 35ms;
}
[data-vfx="neon"] .kt-btn.is-pressed:not(:disabled) {
transform: scale(0.95);
box-shadow: 0 0 28px 2px color-mix(in srgb, var(--_color) 85%, transparent);
transition-duration: 80ms;
}
[data-vfx="ink"] .kt-btn.is-pressed:not(:disabled) {
transform: scale(1.06, 0.88) rotate(-1.2deg);
transition-duration: 65ms;
}
[data-vfx="sakuga"] .kt-btn.is-charging:not(:disabled) {
animation: kt-tremble 90ms infinite linear;
}
[data-vfx="elastic"] .kt-btn.is-charging:not(:disabled) {
animation: kt-jelly-pulse 320ms ease-in-out infinite;
}
[data-vfx="glitch"] .kt-btn.is-charging:not(:disabled) {
animation: kt-glitch-charge 110ms steps(3, end) infinite;
}
[data-vfx="neon"] .kt-btn.is-charging:not(:disabled) {
animation: kt-neon-charge 420ms ease-in-out infinite;
}
[data-vfx="ink"] .kt-btn.is-charging:not(:disabled) {
animation: kt-tremble 100ms infinite linear;
}
[data-vfx="sakuga"] .kt-btn.is-slamming {
animation: kt-slam-rebound 400ms var(--ease-overshoot);
}
[data-vfx="elastic"] .kt-btn.is-slamming {
animation: kt-jelly-bounce 560ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
[data-vfx="glitch"] .kt-btn.is-slamming {
animation: kt-glitch-snap 240ms steps(4, end);
}
[data-vfx="neon"] .kt-btn.is-slamming {
animation: kt-neon-bloom 420ms var(--ease-snap);
}
[data-vfx="ink"] .kt-btn.is-slamming {
animation: kt-ink-stamp 360ms var(--ease-overshoot);
}
.kt-btn.is-confirmed {
filter: contrast(1.08);
}
.kt-btn:focus-visible {
outline: 2px solid var(--bw-ink);
outline-offset: 3px;
}
@keyframes kt-tremble {
0% { transform: translate(0, 0) scale(1.03, 0.94); }
25% { transform: translate(-1.5px, 1px) scale(1.04, 0.93); }
50% { transform: translate(1.5px, -1px) scale(1.03, 0.94); }
75% { transform: translate(-1px, -1px) scale(1.04, 0.93); }
100% { transform: translate(0, 0) scale(1.03, 0.94); }
}
@keyframes kt-slam-rebound {
0% { transform: scale(1.16, 0.78); }
38% { transform: scale(0.92, 1.12); }
72% { transform: scale(1.03, 0.97); }
100% { transform: scale(1, 1); }
}
@keyframes kt-jelly-pulse {
0%, 100% { transform: scale(1.06, 0.9); }
50% { transform: scale(0.96, 1.05); }
}
@keyframes kt-jelly-bounce {
0% { transform: scale(1.18, 0.78); }
28% { transform: scale(0.88, 1.15); }
54% { transform: scale(1.07, 0.93); }
78% { transform: scale(0.97, 1.03); }
100% { transform: scale(1, 1); }
}
@keyframes kt-glitch-charge {
0% { transform: translate(-2px, 0) skewX(-3deg); }
33% { transform: translate(2px, -1px) skewX(3deg); }
66% { transform: translate(-1px, 1px) skewX(-2deg); }
100% { transform: translate(0, 0); }
}
@keyframes kt-glitch-snap {
0% { transform: translate(-4px, 1px) skewX(-8deg); filter: invert(0.2); }
30% { transform: translate(4px, -1px) skewX(6deg); }
60% { transform: translate(-2px, 0) skewX(-3deg); }
100% { transform: translate(0, 0) skewX(0); filter: none; }
}
@keyframes kt-neon-charge {
0%, 100% { transform: scale(0.96); box-shadow: 0 0 18px 0 color-mix(in srgb, var(--_color) 60%, transparent); }
50% { transform: scale(1.02); box-shadow: 0 0 34px 4px color-mix(in srgb, var(--_color) 90%, transparent); }
}
@keyframes kt-neon-bloom {
0% { transform: scale(0.92); box-shadow: 0 0 38px 6px color-mix(in srgb, var(--_color) 95%, transparent); }
55% { transform: scale(1.04); }
100% { transform: scale(1); box-shadow: var(--kt-comp-shadow); }
}
@keyframes kt-ink-stamp {
0% { transform: scale(1.14, 0.82) rotate(-2deg); }
45% { transform: scale(0.95, 1.07) rotate(1deg); }
100% { transform: scale(1, 1) rotate(0); }
}
class KtReactorButton extends HTMLElement {
static get observedAttributes() {
return ["mode", "duration", "sfx", "tag", "tone"];
}
constructor() {
super();
this._rendered = false;
this._holdRaf = null;
this._holdStart = 0;
this._isHolding = false;
this._sparkTick = 0;
this._confirmTimer = null;
this._labelText = "";
}
connectedCallback() {
if (!this._rendered) {
this._defaultLabel = this.textContent.trim() || "Action";
this._labelText = this._defaultLabel;
this.render();
this._rendered = true;
}
this.syncAttributes();
}
setCustomLabel(val) {
const next = (val || "").trim() || this._defaultLabel;
this._labelText = next;
if (this._labelEl && !this._btn.classList.contains("is-confirmed")) {
this._labelEl.textContent = next;
}
}
disconnectedCallback() {
this.cancelHold();
clearTimeout(this._confirmTimer);
}
attributeChangedCallback() {
if (this._rendered) this.syncAttributes();
}
get mode() { return this.getAttribute("mode") || "strike"; }
get duration() { return Math.max(300, Number(this.getAttribute("duration")) || 850); }
get sfx() { return this.getAttribute("sfx") ?? "ドン!"; }
get tag() { return this.getAttribute("tag") || ""; }
get tone() { return this.getAttribute("tone") || "solid"; }
render() {
this.innerHTML = "";
const btn = document.createElement("button");
btn.type = "button";
btn.className = "kt-btn";
btn.innerHTML = `
<span class="kt-btn__spotlight" aria-hidden="true"></span>
<span class="kt-btn__fill" aria-hidden="true"></span>
<span class="kt-btn__content">
<span class="kt-btn__label"></span>
<span class="kt-btn__tag" hidden></span>
</span>
`;
this._btn = btn;
this._fill = btn.querySelector(".kt-btn__fill");
this._labelEl = btn.querySelector(".kt-btn__label");
this._tagEl = btn.querySelector(".kt-btn__tag");
this._labelEl.textContent = this._labelText;
btn.addEventListener("pointermove", (e) => {
if (SakugaFX.getMode() === "enterprise") return;
const rect = btn.getBoundingClientRect();
btn.style.setProperty("--mx", `${e.clientX - rect.left}px`);
btn.style.setProperty("--my", `${e.clientY - rect.top}px`);
});
btn.addEventListener("pointerdown", (e) => {
if (e.button !== 0) return;
btn.setPointerCapture?.(e.pointerId);
this.beginPress(e.clientX, e.clientY);
});
btn.addEventListener("pointerup", (e) => this.endPress(e.clientX, e.clientY, true));
btn.addEventListener("pointercancel", () => this.cancelHold());
btn.addEventListener("keydown", (e) => {
if (e.repeat) return;
if (e.key === " " || e.key === "Enter") {
e.preventDefault();
const rect = btn.getBoundingClientRect();
this.beginPress(rect.left + rect.width / 2, rect.top + rect.height / 2);
}
});
btn.addEventListener("keyup", (e) => {
if (e.key === " " || e.key === "Enter") {
e.preventDefault();
const rect = btn.getBoundingClientRect();
this.endPress(rect.left + rect.width / 2, rect.top + rect.height / 2, true);
}
});
this.appendChild(btn);
}
syncAttributes() {
if (!this._btn) return;
this._btn.setAttribute("data-tone", this.tone);
if (this.tag) {
this._tagEl.hidden = false;
this._tagEl.textContent = this.tag;
} else {
this._tagEl.hidden = true;
}
}
beginPress(x, y) {
clearTimeout(this._confirmTimer);
this._btn.classList.remove("is-slamming", "is-confirmed");
this._labelEl.textContent = this._labelText;
this._btn.classList.add("is-pressed");
const color = readAccent(this._btn);
if (this.mode === "hold") {
this._isHolding = true;
this._btn.classList.add("is-charging");
this._holdStart = performance.now();
this._sparkTick = 0;
const step = (now) => {
if (!this._isHolding) return;
const progress = Math.min((now - this._holdStart) / this.duration, 1);
this._fill.style.transform = `scaleX(${progress})`;
this._sparkTick++;
if (this._sparkTick % 5 === 0) {
const rect = this._btn.getBoundingClientRect();
SakugaFX.emitBurst(
rect.left + Math.random() * rect.width,
rect.top + (Math.random() > 0.5 ? 2 : rect.height - 2),
color,
{ count: 2, speed: 85, spread: Math.PI, baseAngle: -Math.PI / 2, shards: false }
);
}
if (progress >= 1) {
this._isHolding = false;
this._btn.classList.remove("is-charging", "is-pressed");
this._fill.style.transform = "scaleX(0)";
const rect = this._btn.getBoundingClientRect();
this.triggerImpact(rect.left + rect.width / 2, rect.top + rect.height / 2, true);
} else {
this._holdRaf = requestAnimationFrame(step);
}
};
this._holdRaf = requestAnimationFrame(step);
} else {
SakugaFX.emitSmoke(x, y + 8, color, 0);
}
}
endPress(x, y, fireStrike) {
this._btn.classList.remove("is-pressed");
if (this.mode === "hold") {
if (this._isHolding) this.cancelHold();
} else if (fireStrike) {
this.triggerImpact(x, y, false);
}
}
cancelHold() {
this._isHolding = false;
if (this._holdRaf) cancelAnimationFrame(this._holdRaf);
this._holdRaf = null;
if (this._btn) this._btn.classList.remove("is-charging", "is-pressed");
if (this._fill) this._fill.style.transform = "scaleX(0)";
}
triggerImpact(x, y, isHoldConfirm) {
const color = readAccent(this._btn);
const mode = SakugaFX.getMode();
if (mode !== "enterprise") {
this._btn.classList.remove("is-slamming");
void this._btn.offsetWidth;
this._btn.classList.add("is-slamming");
}
if (mode === "elastic") {
SakugaFX.emitShockwave(x, y, color, isHoldConfirm ? 78 : 54);
setTimeout(() => SakugaFX.emitShockwave(x, y, color, isHoldConfirm ? 105 : 74), 70);
SakugaFX.emitSmoke(x, y, color, 0);
} else if (mode === "glitch") {
SakugaFX.emitPixels(x, y, color, isHoldConfirm ? 22 : 14);
SakugaFX.emitScanline(x, y, color, isHoldConfirm ? 160 : 110);
} else if (mode === "neon") {
SakugaFX.emitShockwave(x, y, color, isHoldConfirm ? 95 : 68);
SakugaFX.emitRays(x, y, color, isHoldConfirm ? 14 : 10, isHoldConfirm ? 86 : 62);
} else if (mode === "ink") {
SakugaFX.emitInkSplatter(x, y, color, isHoldConfirm ? 22 : 14);
} else if (mode !== "enterprise") {
SakugaFX.emitShockwave(x, y, color, isHoldConfirm ? 86 : 60);
SakugaFX.emitBurst(x, y, color, { count: isHoldConfirm ? 20 : 14, speed: isHoldConfirm ? 300 : 230 });
SakugaFX.emitSlash(x, y, color, isHoldConfirm ? -0.42 : -0.28);
}
SakugaFX.emitMangaSFX(x, y - 4, this.sfx, color);
if (isHoldConfirm) {
this._btn.classList.add("is-confirmed");
this._labelEl.textContent = "Confirmed ✓";
this._confirmTimer = setTimeout(() => {
this._btn.classList.remove("is-confirmed");
this._labelEl.textContent = this._labelText;
}, 1200);
}
}
}
customElements.define("kt-reactor-button", KtReactorButton);
function contrastInk(hex) {
const clean = hex.replace("#", "");
if (clean.length !== 6) return "#ffffff";
const r = parseInt(clean.slice(0, 2), 16);
const g = parseInt(clean.slice(2, 4), 16);
const b = parseInt(clean.slice(4, 6), 16);
const lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
return lum > 0.6 ? "#09090b" : "#ffffff";
}
function readAccent(el) {
const val = getComputedStyle(el).getPropertyValue("--kt-accent").trim();
return val || "#09090b";
}
class SakugaVFXEngine {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.rafId = null;
this.lastTime = 0;
this.textEnabled = false;
this.textOverride = "";
this.vfxTextColor = "auto";
this.resize();
window.addEventListener("resize", () => this.resize());
}
attach(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext("2d");
this.items = [];
this.resize();
}
resize() {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
this.canvas.width = Math.floor(window.innerWidth * dpr);
this.canvas.height = Math.floor(window.innerHeight * dpr);
this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
getMode() {
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return "enterprise";
return document.documentElement.getAttribute("data-vfx") || "enterprise";
}
wake() {
if (this.rafId !== null) return;
this.lastTime = performance.now();
const tick = (now) => {
const dt = Math.min((now - this.lastTime) / 1000, 0.05);
this.lastTime = now;
this.render(dt);
if (this.items.length > 0) {
this.rafId = requestAnimationFrame(tick);
} else {
this.rafId = null;
this.ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
}
};
this.rafId = requestAnimationFrame(tick);
}
emitBurst(x, y, color, { count = 14, speed = 240, spread = Math.PI * 2, baseAngle = 0, shards = true } = {}) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < count; i++) {
const angle = baseAngle + (Math.random() - 0.5) * spread;
const vel = speed * (0.45 + Math.random() * 0.75);
this.items.push({
kind: shards && i % 3 === 0 ? "shard" : "spark",
x, y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - (spread > 4 ? 35 : 0),
gravity: 400,
drag: 0.94,
size: 3 + Math.random() * 4,
rot: Math.random() * Math.PI * 2,
vrot: (Math.random() - 0.5) * 14,
life: 0,
maxLife: 0.32 + Math.random() * 0.22,
color
});
}
this.wake();
}
emitShockwave(x, y, color, maxRadius = 64) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "ring", x, y, radius: 8, maxRadius, life: 0, maxLife: 0.32, color });
this.wake();
}
emitSlash(x, y, color, angle = -0.3) {
if (this.getMode() === "enterprise") return;
this.items.push({ kind: "slash", x, y, angle, length: 96, life: 0, maxLife: 0.2, color });
this.wake();
}
emitSmoke(x, y, color, dirX = 0) {
if (this.getMode() === "enterprise") return;
for (let i = 0; i < 4; i++) {
this.items.push({
kind: "smoke",
x: x + (Math.random() - 0.5) * 8,
y: y + (Math.random() - 0.5) * 8,
vx: dirX * (50 + Math.random() * 70) + (Math.random() - 0.5) * 35,
vy: -20 - Math.random() * 50,
size: 5 + Math.random() * 5,
life: 0,
maxLife: 0.34 + Math.random() * 0.16,
color
});
}
this.wake();
}
emitPixels(x, y, color, count = 14) {
if (this.getMode() !== "glitch") return;
for (let i = 0; i < count; i++) {
const angle = Math.floor(Math.random() * 8) * (Math.PI / 4);
const vel = 120 + Math.random() * 200;
this.items.push({
kind: "pixel",
x: x + (Math.random() - 0.5) * 18,
y: y + (Math.random() - 0.5) * 12,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel,
size: 4 + Math.floor(Math.random() * 5),
life: 0,
maxLife: 0.24 + Math.random() * 0.14,
color
});
}
this.wake();
}
emitScanline(x, y, color, width = 120) {
if (this.getMode() !== "glitch") return;
for (let i = -1; i <= 1; i += 2) {
this.items.push({
kind: "scanline",
x,
y: y + i * (5 + Math.random() * 6),
width,
life: 0,
maxLife: 0.18,
color
});
}
this.wake();
}
emitRays(x, y, color, count = 10, maxRadius = 72) {
if (this.getMode() !== "neon") return;
for (let i = 0; i < count; i++) {
const angle = (Math.PI * 2 * i) / count + (Math.random() - 0.5) * 0.18;
this.items.push({
kind: "ray",
x,
y,
angle,
maxRadius: maxRadius * (0.75 + Math.random() * 0.45),
life: 0,
maxLife: 0.34,
color
});
}
this.wake();
}
emitInkSplatter(x, y, color, count = 14) {
if (this.getMode() !== "ink") return;
for (let i = 0; i < count; i++) {
const angle = Math.random() * Math.PI * 2;
const vel = 110 + Math.random() * 230;
this.items.push({
kind: "inkblot",
x,
y,
vx: Math.cos(angle) * vel,
vy: Math.sin(angle) * vel - 30,
gravity: 480,
drag: 0.91,
size: 2.5 + Math.random() * 5.5,
life: 0,
maxLife: 0.38 + Math.random() * 0.22,
color
});
}
// Brush arc sweep
this.items.push({
kind: "brusharc",
x,
y,
radius: 24 + Math.random() * 14,
startAngle: -Math.PI * 0.75,
endAngle: Math.PI * 0.35,
life: 0,
maxLife: 0.26,
color
});
this.wake();
}
emitMangaSFX(x, y, text, color) {
const mode = this.getMode();
const finalText = this.textOverride || text;
if (mode === "enterprise" || !this.textEnabled || !finalText || finalText === "none") return;
const fillColor = this.vfxTextColor !== "auto" ? this.vfxTextColor : color;
const outline = this.vfxTextColor !== "auto"
? contrastInk(this.vfxTextColor)
: (document.documentElement.getAttribute("data-bw") === "dark" ? "#09090b" : "#ffffff");
this.items.push({
kind: "sfx",
x: x + (Math.random() - 0.5) * 14,
y: y - 16,
vy: -48,
tilt: (Math.random() - 0.5) * 0.26,
text: finalText,
life: 0,
maxLife: 0.6,
color: fillColor,
outline
});
this.wake();
}
emitImpact(x, y, color, { sfx = "", scale = 1, dirX = 0, sfxY = y - 4 } = {}) {
const mode = this.getMode();
if (mode === "enterprise") return;
if (mode === "elastic") {
this.emitShockwave(x, y, color, Math.round(52 * scale));
this.emitSmoke(x, y, color, dirX);
} else if (mode === "glitch") {
this.emitPixels(x, y, color, Math.round(12 * scale));
this.emitScanline(x, y, color, Math.round(96 * scale));
} else if (mode === "neon") {
this.emitShockwave(x, y, color, Math.round(58 * scale));
this.emitRays(x, y, color, Math.round(9 * scale), Math.round(52 * scale));
} else if (mode === "ink") {
this.emitInkSplatter(x, y, color, Math.round(13 * scale));
} else {
this.emitShockwave(x, y, color, Math.round(50 * scale));
this.emitBurst(x, y, color, {
count: Math.round(12 * scale),
speed: Math.round(210 * scale),
spread: dirX ? 1.8 : Math.PI * 2,
baseAngle: dirX < 0 ? Math.PI : 0
});
this.emitSlash(x, y, color, -0.28);
}
this.emitMangaSFX(x, sfxY, sfx, color);
}
render(dt) {
const ctx = this.ctx;
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
const next = [];
for (const p of this.items) {
p.life += dt;
if (p.life >= p.maxLife) continue;
const t = p.life / p.maxLife;
const easeOut = 1 - Math.pow(1 - t, 3);
const alpha = Math.max(0, 1 - Math.pow(t, 2));
ctx.save();
ctx.globalAlpha = alpha;
if (p.kind === "spark" || p.kind === "shard") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
p.rot += p.vrot * dt;
ctx.translate(p.x, p.y);
ctx.rotate(p.rot);
ctx.fillStyle = p.color;
if (p.kind === "shard") {
const s = p.size * (1 - t * 0.4);
ctx.beginPath();
ctx.moveTo(0, -s);
ctx.lineTo(s * 0.72, 0);
ctx.lineTo(0, s);
ctx.lineTo(-s * 0.72, 0);
ctx.closePath();
ctx.fill();
} else {
ctx.beginPath();
ctx.arc(0, 0, p.size * 0.5 * (1 - t * 0.5), 0, Math.PI * 2);
ctx.fill();
}
} else if (p.kind === "ring") {
const r = p.radius + (p.maxRadius - p.radius) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineWidth = Math.max(1, 3 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.stroke();
} else if (p.kind === "slash") {
ctx.translate(p.x, p.y);
ctx.rotate(p.angle);
const len = p.length * easeOut;
const th = 4.5 * (1 - t);
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.moveTo(-len, 0);
ctx.quadraticCurveTo(0, -th, len, 0);
ctx.quadraticCurveTo(0, th, -len, 0);
ctx.fill();
} else if (p.kind === "smoke") {
p.x += p.vx * dt;
p.y += p.vy * dt;
const r = p.size * (0.8 + easeOut * 1.25);
ctx.fillStyle = p.color;
ctx.globalAlpha = 0.24 * (1 - t);
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "pixel") {
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
const s = p.size * (1 - t * 0.35);
ctx.fillRect(Math.round(p.x - s / 2), Math.round(p.y - s / 2), s, s);
} else if (p.kind === "scanline") {
const w = p.width * (0.4 + easeOut * 0.8);
ctx.fillStyle = p.color;
ctx.fillRect(p.x - w / 2, p.y, w, 2);
} else if (p.kind === "ray") {
const inner = 12 + easeOut * 16;
const outer = inner + p.maxRadius * (1 - t * 0.35);
ctx.strokeStyle = p.color;
ctx.shadowColor = p.color;
ctx.shadowBlur = 10;
ctx.lineWidth = Math.max(1, 2.8 * (1 - t));
ctx.beginPath();
ctx.moveTo(p.x + Math.cos(p.angle) * inner, p.y + Math.sin(p.angle) * inner);
ctx.lineTo(p.x + Math.cos(p.angle) * outer, p.y + Math.sin(p.angle) * outer);
ctx.stroke();
} else if (p.kind === "inkblot") {
p.vx *= Math.pow(p.drag, dt * 60);
p.vy = p.vy * Math.pow(p.drag, dt * 60) + p.gravity * dt;
p.x += p.vx * dt;
p.y += p.vy * dt;
ctx.fillStyle = p.color;
ctx.beginPath();
ctx.arc(p.x, p.y, p.size * (1 - t * 0.45), 0, Math.PI * 2);
ctx.fill();
} else if (p.kind === "brusharc") {
const sweep = p.startAngle + (p.endAngle - p.startAngle) * easeOut;
ctx.strokeStyle = p.color;
ctx.lineCap = "round";
ctx.lineWidth = Math.max(1.5, 6 * (1 - t));
ctx.beginPath();
ctx.arc(p.x, p.y, p.radius * (0.85 + easeOut * 0.4), p.startAngle, sweep);
ctx.stroke();
} else if (p.kind === "sfx") {
p.y += p.vy * dt * (1 - t * 0.6);
const s = t < 0.18 ? 0.55 + (t / 0.18) * 0.65 : 1.2 - (t - 0.18) * 0.25;
ctx.translate(p.x, p.y);
ctx.rotate(p.tilt);
ctx.scale(s, s);
ctx.font = '900 19px "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif';
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.lineJoin = "round";
ctx.lineWidth = 4.5;
ctx.strokeStyle = p.outline;
ctx.strokeText(p.text, 0, 0);
ctx.fillStyle = p.color;
ctx.fillText(p.text, 0, 0);
}
ctx.restore();
next.push(p);
}
this.items = next;
}
}
const SakugaFX = new SakugaVFXEngine(document.getElementById("sakuga-vfx-canvas"));
window.SakugaFX = SakugaFX;
window.readAccent = readAccent;
window.contrastInk = contrastInk;
Attributes
| Name | What it does | Default |
|---|---|---|
mode | "strike" fires on release; "hold" fires after you hold it. | strike |
duration | Milliseconds to hold in hold mode (minimum 300). | 850 |
tone | "solid" or "outline". | solid |
tag | Small label shown inside the button. | — |
sfx | Comic sound-effect text shown on impact when VFX text is on. | ドン! |
Keyboard and screen readers
- A real button: focusable and announced as a button.
- Space or Enter presses it; hold mode works with a held key.
- Motion effects are skipped when the visitor prefers reduced motion.
Styling variables
Every look is a CSS variable: --kt-accent, --kt-accent-ink, --kt-radius-btn, --kt-surface-radius, --kt-surface-bg, --kt-border-w, --kt-comp-shadow and --font-sans. The
copied file sets them all from your choices.
FAQ
Reactor Button: questions answered
How do I use the Reactor Button?
Press Copy on the card to get a complete HTML file, or copy the HTML, CSS and JavaScript tabs into your own page. In your markup the element is written as <kt-reactor-button>.
Which attributes does <kt-reactor-button> accept?
mode, duration, tone, tag, sfx. Each one is described in the attributes table on this page.
Is the Reactor Button accessible?
A real button: focusable and announced as a button. Space or Enter presses it; hold mode works with a held key. Motion effects are skipped when the visitor prefers reduced motion.
Can I change the Reactor Button colors, corners and font?
Yes. Use the options on this page: accent color, border radius, background, border, shadow and Google font. The copied code already contains your choices, and every one of them is a CSS variable you can edit later.