Kinetic Modal
A dialog with its own trigger button, confirm and cancel actions, a focus trap and a scroll lock, that pops in with the chosen motion style.
- <kt-kinetic-modal>
- Overlays
- No framework
The code
Copy the Kinetic Modal
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-kinetic-modal title="Discard draft?" trigger="Discard draft" confirm-label="Discard" cancel-label="Keep editing">Your changes to "Q3 launch notes" have not been saved and will be lost.</kt-kinetic-modal>
<kt-kinetic-modal title="Publish release 2.4" trigger="Publish release" confirm-label="Publish" sfx="ドン!">This sends 2.4.0 to everyone on the stable channel. You can roll back from the releases page.</kt-kinetic-modal>
kt-kinetic-modal {
display: inline-block;
max-width: 100%;
}
.kt-modal {
--_color: var(--kt-accent);
--_ink: var(--kt-accent-ink);
}
.kt-modal-trigger,
.kt-modal-btn {
min-height: 36px;
padding: 9px 16px;
border-style: solid;
border-width: var(--kt-border-w);
border-radius: var(--kt-radius-btn);
font-family: var(--font-sans);
font-size: 13px;
font-weight: 700;
line-height: 1.2;
cursor: pointer;
transition: transform 140ms var(--ease-snap), border-color 160ms ease, background-color 160ms ease, box-shadow 180ms ease;
}
.kt-modal-trigger,
.kt-modal-confirm {
border-color: var(--_color);
background: var(--_color);
color: var(--_ink);
}
.kt-modal-trigger:hover,
.kt-modal-confirm:hover {
box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--_color) 70%, transparent);
}
.kt-modal-trigger:active,
.kt-modal-btn:active {
transform: scale(0.97);
}
.kt-modal-trigger:disabled {
opacity: 0.5;
cursor: not-allowed;
box-shadow: none;
}
.kt-modal-cancel {
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: transparent;
color: var(--kt-surface-ink);
}
.kt-modal-cancel:hover {
border-color: var(--kt-comp-border, var(--kt-surface-ink));
}
.kt-modal-trigger:focus-visible,
.kt-modal-btn:focus-visible,
.kt-modal-close:focus-visible {
outline: 2px solid var(--kt-surface-ink);
outline-offset: 2px;
}
.kt-modal-overlay {
position: fixed;
inset: 0;
z-index: 1400;
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
background: rgba(8, 8, 12, 0.55);
opacity: 0;
visibility: hidden;
overscroll-behavior: contain;
transition: opacity 160ms ease, visibility 0s linear 160ms;
}
.kt-modal-overlay[data-open="true"] {
opacity: 1;
visibility: visible;
transition: opacity 160ms ease, visibility 0s;
}
[data-vfx="neon"] .kt-modal-overlay[data-open="true"],
[data-vfx="glitch"] .kt-modal-overlay[data-open="true"] {
backdrop-filter: blur(3px);
}
.kt-modal-dialog {
box-sizing: border-box;
width: 100%;
max-width: 420px;
max-height: calc(100vh - 32px);
overflow-y: auto;
padding: 18px 20px 16px;
border-radius: var(--kt-surface-radius);
border-style: solid;
border-width: var(--kt-card-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: var(--kt-surface-bg);
color: var(--kt-surface-ink);
box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
text-align: left;
white-space: normal;
}
.kt-modal-dialog:focus {
outline: none;
}
.kt-modal-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.kt-modal-title {
margin: 0;
font-family: var(--font-sans);
font-size: 17px;
font-weight: 800;
line-height: 1.3;
color: var(--kt-surface-ink);
}
.kt-modal-close {
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
margin: -3px -6px 0 0;
border: 0;
border-radius: var(--kt-radius-btn);
background: transparent;
color: var(--kt-surface-muted);
cursor: pointer;
transition: color 150ms ease, background-color 150ms ease;
}
.kt-modal-close:hover {
color: var(--kt-surface-ink);
background: color-mix(in srgb, var(--kt-surface-ink) 9%, transparent);
}
.kt-modal-body {
margin: 8px 0 0;
font-family: var(--font-sans);
font-size: 14px;
line-height: 1.55;
color: var(--kt-surface-muted);
}
.kt-modal-foot {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
margin-top: 18px;
}
/* entrance per VFX mode */
.kt-modal-overlay[data-open="true"] .kt-modal-dialog {
animation: kt-modal-pop 320ms var(--ease-overshoot) both;
}
[data-vfx="enterprise"] .kt-modal-overlay[data-open="true"] .kt-modal-dialog {
animation: kt-modal-fade 160ms ease both;
}
[data-vfx="elastic"] .kt-modal-overlay[data-open="true"] .kt-modal-dialog {
animation: kt-modal-jelly 520ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
[data-vfx="glitch"] .kt-modal-overlay[data-open="true"] .kt-modal-dialog {
animation: kt-modal-glitch 260ms steps(5, end) both;
}
[data-vfx="neon"] .kt-modal-overlay[data-open="true"] .kt-modal-dialog {
animation: kt-modal-neon 360ms var(--ease-snap) both;
box-shadow: 0 0 0 1px var(--_color), 0 0 28px -4px color-mix(in srgb, var(--_color) 65%, transparent), 0 24px 60px rgba(0, 0, 0, 0.4);
}
[data-vfx="ink"] .kt-modal-overlay[data-open="true"] .kt-modal-dialog {
animation: kt-modal-ink 420ms var(--ease-snap) both;
}
@keyframes kt-modal-fade {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes kt-modal-pop {
0% { opacity: 0; transform: translateY(18px) scale(0.92); }
100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes kt-modal-jelly {
0% { opacity: 0; transform: scale(0.7, 0.55); }
45% { opacity: 1; transform: scale(1.06, 0.95); }
70% { transform: scale(0.98, 1.02); }
100% { transform: scale(1, 1); }
}
@keyframes kt-modal-glitch {
0% { opacity: 0; transform: skewX(-8deg) translateX(-10px); }
40% { opacity: 1; transform: skewX(6deg) translateX(6px); }
70% { transform: skewX(-2deg) translateX(-2px); }
100% { transform: none; }
}
@keyframes kt-modal-neon {
0% { opacity: 0; transform: scale(0.96); filter: brightness(2); }
100% { opacity: 1; transform: scale(1); filter: none; }
}
@keyframes kt-modal-ink {
0% { opacity: 0; clip-path: inset(0 100% 0 0); }
100% { opacity: 1; clip-path: inset(0 0 0 0); }
}
@media (max-width: 380px) {
.kt-modal-dialog { padding: 16px; }
.kt-modal-foot .kt-modal-btn { flex: 1 1 100%; }
}
class KtKineticModal extends HTMLElement {
static get observedAttributes() {
return ["open", "title", "trigger", "confirm-label", "cancel-label", "sfx", "disabled"];
}
constructor() {
super();
this._rendered = false;
this._shown = false;
this._uid = `kt-modal-${Math.random().toString(36).slice(2, 8)}`;
this._downOnBackdrop = false;
this._onDocKeydown = (e) => this.onKeydown(e);
this._onFocusIn = (e) => {
if (this._shown && !this._dialog.contains(e.target)) this.focusFirst();
};
}
connectedCallback() {
if (!this._rendered) {
this.render();
this._rendered = true;
}
this.syncAttributes();
if (this.hasAttribute("open") && !this._shown) this.show();
}
disconnectedCallback() {
if (this._shown) this.hide({ restoreFocus: false });
}
attributeChangedCallback(name) {
if (!this._rendered) return;
if (name === "open") {
if (this.hasAttribute("open")) this.show();
else this.hide({ restoreFocus: true });
return;
}
this.syncAttributes();
}
get title() { return this.getAttribute("title") || "Dialog"; }
set title(v) { this.setAttribute("title", v); }
get triggerLabel() { return this.getAttribute("trigger"); }
get confirmLabel() { return this.getAttribute("confirm-label") || "Confirm"; }
get cancelLabel() { return this.getAttribute("cancel-label") || "Cancel"; }
get sfx() { return this.getAttribute("sfx") ?? "ドン!"; }
get open() { return this.hasAttribute("open"); }
set open(v) { this.toggleAttribute("open", !!v); }
get bodyText() { return this._body ? this._body.textContent.trim() : ""; }
render() {
const body = document.createElement("div");
body.className = "kt-modal-body";
body.id = `${this._uid}-body`;
while (this.firstChild) body.appendChild(this.firstChild);
this._body = body;
const root = document.createElement("div");
root.className = "kt-modal";
root.innerHTML = `
<button type="button" class="kt-modal-trigger" aria-haspopup="dialog" title=""></button>
<div class="kt-modal-overlay" title="" aria-hidden="true">
<div class="kt-modal-dialog" role="dialog" aria-modal="true" tabindex="-1">
<div class="kt-modal-head">
<h2 class="kt-modal-title"></h2>
<button type="button" class="kt-modal-close" aria-label="Close dialog">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3.5 3.5l9 9M12.5 3.5l-9 9" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
</button>
</div>
<div class="kt-modal-body-slot"></div>
<div class="kt-modal-foot">
<button type="button" class="kt-modal-btn kt-modal-cancel"></button>
<button type="button" class="kt-modal-btn kt-modal-confirm"></button>
</div>
</div>
</div>
`;
this._root = root;
this._trigger = root.querySelector(".kt-modal-trigger");
this._overlay = root.querySelector(".kt-modal-overlay");
this._dialog = root.querySelector(".kt-modal-dialog");
this._titleEl = root.querySelector(".kt-modal-title");
this._closeBtn = root.querySelector(".kt-modal-close");
this._cancelBtn = root.querySelector(".kt-modal-cancel");
this._confirmBtn = root.querySelector(".kt-modal-confirm");
root.querySelector(".kt-modal-body-slot").appendChild(body);
this._titleEl.id = `${this._uid}-title`;
this._dialog.setAttribute("aria-labelledby", this._titleEl.id);
this._dialog.setAttribute("aria-describedby", body.id);
this._trigger.addEventListener("click", () => this.setAttribute("open", ""));
this._closeBtn.addEventListener("click", () => this.dismiss("close"));
this._cancelBtn.addEventListener("click", () => this.dismiss("cancel"));
this._confirmBtn.addEventListener("click", () => this.confirm());
this._overlay.addEventListener("pointerdown", (e) => {
this._downOnBackdrop = e.target === this._overlay;
});
this._overlay.addEventListener("click", (e) => {
if (e.target === this._overlay && this._downOnBackdrop) this.dismiss("backdrop");
this._downOnBackdrop = false;
});
this.appendChild(root);
}
syncAttributes() {
if (!this._root) return;
this._titleEl.textContent = this.title;
const t = this.triggerLabel;
this._trigger.textContent = t === null ? "Open dialog" : t;
this._trigger.hidden = t === "";
this._trigger.disabled = this.hasAttribute("disabled");
this._cancelBtn.textContent = this.cancelLabel;
this._confirmBtn.textContent = this.confirmLabel;
}
focusables() {
const sel = 'button:not([disabled]), [href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
return [...this._dialog.querySelectorAll(sel)].filter((el) => el.getClientRects().length > 0);
}
focusFirst() {
const list = this.focusables();
const target = list.find((el) => !el.classList.contains("kt-modal-close")) || list[0] || this._dialog;
target.focus({ preventScroll: true });
}
show() {
if (this._shown) return;
this._shown = true;
this._overlay.setAttribute("data-open", "true");
this._overlay.setAttribute("aria-hidden", "false");
this._trigger.setAttribute("aria-expanded", "true");
KtKineticModal._lock();
document.addEventListener("keydown", this._onDocKeydown, true);
document.addEventListener("focusin", this._onFocusIn);
this.focusFirst();
if (SakugaFX.getMode() !== "enterprise") {
const r = this._dialog.getBoundingClientRect();
SakugaFX.emitImpact(r.left + r.width / 2, r.top + 8, readAccent(this._root), {
sfx: this.sfx, scale: 0.9, sfxY: r.top - 6
});
}
}
hide({ restoreFocus = true } = {}) {
if (!this._shown) return;
this._shown = false;
this._overlay.removeAttribute("data-open");
this._overlay.setAttribute("aria-hidden", "true");
this._trigger.setAttribute("aria-expanded", "false");
KtKineticModal._unlock();
document.removeEventListener("keydown", this._onDocKeydown, true);
document.removeEventListener("focusin", this._onFocusIn);
if (restoreFocus && !this._trigger.hidden) this._trigger.focus({ preventScroll: true });
}
dismiss(reason) {
this.removeAttribute("open");
this.dispatchEvent(new CustomEvent("cancel", { bubbles: true, detail: { reason } }));
}
confirm() {
if (SakugaFX.getMode() !== "enterprise") {
const r = this._confirmBtn.getBoundingClientRect();
SakugaFX.emitImpact(r.left + r.width / 2, r.top + r.height / 2, readAccent(this._root), {
sfx: this.sfx, scale: 0.8, sfxY: r.top - 4
});
}
this.removeAttribute("open");
this.dispatchEvent(new CustomEvent("confirm", { bubbles: true, detail: {} }));
}
onKeydown(e) {
if (!this._shown) return;
if (e.key === "Escape") {
e.preventDefault();
e.stopPropagation();
this.dismiss("escape");
return;
}
if (e.key !== "Tab") return;
const list = this.focusables();
if (!list.length) {
e.preventDefault();
this._dialog.focus();
return;
}
const first = list[0];
const last = list[list.length - 1];
const cur = document.activeElement;
if (!this._dialog.contains(cur) || cur === this._dialog) {
e.preventDefault();
(e.shiftKey ? last : first).focus();
} else if (e.shiftKey && cur === first) {
e.preventDefault();
last.focus();
} else if (!e.shiftKey && cur === last) {
e.preventDefault();
first.focus();
}
}
}
KtKineticModal._n = 0;
KtKineticModal._prev = "";
KtKineticModal._pad = "";
KtKineticModal._lock = function () {
if (KtKineticModal._n++ > 0) return;
const d = document.documentElement;
KtKineticModal._prev = d.style.overflow;
KtKineticModal._pad = d.style.paddingRight;
const bar = window.innerWidth - d.clientWidth;
d.style.overflow = "hidden";
if (bar > 0) d.style.paddingRight = `${bar}px`;
};
KtKineticModal._unlock = function () {
if (--KtKineticModal._n > 0) return;
KtKineticModal._n = 0;
const d = document.documentElement;
d.style.overflow = KtKineticModal._prev;
d.style.paddingRight = KtKineticModal._pad;
};
customElements.define("kt-kinetic-modal", KtKineticModal);
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 |
|---|---|---|
title | Dialog heading, also its accessible name. | Dialog |
trigger | Text of the button that opens the dialog. Set it empty to hide the button and use `open` from your code. | Open dialog |
open | Present while the dialog is open. Add or remove it to open and close. | — |
confirm-label | Text of the confirm button. | Confirm |
cancel-label | Text of the cancel button. | Cancel |
disabled | Disables the trigger button. | — |
sfx | Sound-effect text shown when the dialog opens and on confirm. | ドン! |
Keyboard and screen readers
- role="dialog" with aria-modal, named by its title and described by its body text.
- Tab and Shift+Tab cycle inside the dialog; focus cannot leave it while it is open.
- Escape, the close button, Cancel and a click on the backdrop close it and fire a cancel event.
- Focus moves into the dialog on open and returns to the trigger on close.
- Page scrolling is locked while the dialog is open.
- Confirm fires a confirm event; the entrance animation is skipped for 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
Kinetic Modal: questions answered
How do I use the Kinetic Modal?
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-kinetic-modal>.
Which attributes does <kt-kinetic-modal> accept?
title, trigger, open, confirm-label, cancel-label, disabled, sfx. Each one is described in the attributes table on this page.
Is the Kinetic Modal accessible?
role="dialog" with aria-modal, named by its title and described by its body text. Tab and Shift+Tab cycle inside the dialog; focus cannot leave it while it is open. Escape, the close button, Cancel and a click on the backdrop close it and fire a cancel event. Focus moves into the dialog on open and returns to the trigger on close. Page scrolling is locked while the dialog is open. Confirm fires a confirm event; the entrance animation is skipped for reduced motion.
Can I change the Kinetic Modal 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.