Kinetic Number Stepper
A number field with minus and plus buttons that repeat while held. Typed values are clamped to min and max when you leave the field.
- <kt-kinetic-number>
- Inputs
- No framework
The code
Copy the Kinetic Number Stepper
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-number label="Seats" value="5" min="1" max="50" step="1"></kt-kinetic-number>
<kt-kinetic-number label="Opacity" value="0.8" min="0" max="1" step="0.1"></kt-kinetic-number>
<kt-kinetic-number label="Timeout" value="30" min="5" max="300" step="5" unit="sec"></kt-kinetic-number>
kt-kinetic-number {
display: block;
width: 100%;
max-width: 340px;
}
.kt-number {
--_color: var(--kt-accent);
--_ink: var(--kt-accent-ink);
padding: 12px 14px 14px;
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: var(--kt-comp-shadow);
transition: border-color 160ms ease, box-shadow 180ms ease, border-width 150ms ease;
}
.kt-number.is-disabled {
opacity: 0.55;
}
.kt-number-label {
display: block;
margin-bottom: 8px;
font-family: var(--font-mono);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
color: var(--kt-surface-muted);
}
.kt-number-row {
display: flex;
align-items: stretch;
gap: 8px;
}
.kt-number-btn {
flex-shrink: 0;
display: grid;
place-items: center;
width: 44px;
height: 44px;
padding: 0;
border-radius: var(--kt-radius-btn);
border-style: solid;
border-width: var(--kt-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: color-mix(in srgb, var(--kt-surface-ink) 6%, transparent);
color: var(--kt-surface-ink);
cursor: pointer;
touch-action: manipulation;
user-select: none;
-webkit-tap-highlight-color: transparent;
transition: background-color 140ms ease, border-color 140ms ease, transform 150ms var(--ease-snap), color 140ms ease;
}
.kt-number-btn:hover:not(:disabled) {
border-color: var(--kt-comp-border, var(--kt-surface-ink));
background: color-mix(in srgb, var(--kt-surface-ink) 11%, transparent);
}
.kt-number-btn:active:not(:disabled) {
transform: scale(0.93);
background: var(--_color);
border-color: var(--_color);
color: var(--_ink);
}
.kt-number-btn:disabled {
opacity: 0.4;
cursor: not-allowed;
}
.kt-number-display {
position: relative;
flex: 1;
min-width: 0;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--kt-radius-btn);
border-style: solid;
border-width: var(--kt-border-w);
border-color: var(--kt-comp-border, var(--kt-surface-border));
background: var(--kt-surface-bg);
transition: border-color 150ms ease, box-shadow 170ms ease;
}
.kt-number.is-focus .kt-number-display {
border-color: var(--kt-comp-border, var(--_color));
box-shadow: 0 0 0 3px color-mix(in srgb, var(--_color) 28%, transparent);
}
.kt-number.is-limit .kt-number-display {
border-color: var(--kt-surface-muted);
}
.kt-number-input {
width: 100%;
min-width: 0;
height: 100%;
padding: 0 10px;
margin: 0;
border: 0;
outline: 0;
background: transparent;
color: var(--kt-surface-ink);
font-family: var(--font-mono);
font-size: 18px;
font-weight: 700;
line-height: 1;
text-align: center;
font-variant-numeric: tabular-nums;
box-shadow: none;
}
.kt-number-input[aria-invalid="true"] {
text-decoration: underline wavy color-mix(in srgb, #dc2626 80%, var(--kt-surface-ink));
text-underline-offset: 4px;
}
.kt-number-input:disabled {
cursor: not-allowed;
}
.kt-number-unit {
flex-shrink: 0;
padding-right: 10px;
margin-left: -4px;
font-family: var(--font-mono);
font-size: 11px;
font-weight: 700;
color: var(--kt-surface-muted);
pointer-events: none;
}
.kt-number-unit[hidden] {
display: none;
}
.kt-number-btn:focus-visible {
outline: 2px solid var(--kt-surface-ink);
outline-offset: 2px;
}
/* VFX */
[data-vfx="sakuga"] .kt-number-input.is-bump-up { animation: kt-number-up 220ms var(--ease-overshoot); }
[data-vfx="sakuga"] .kt-number-input.is-bump-down { animation: kt-number-down 220ms var(--ease-overshoot); }
[data-vfx="elastic"] .kt-number-input.is-bump-up,
[data-vfx="elastic"] .kt-number-input.is-bump-down { animation: kt-number-jelly 320ms cubic-bezier(0.34, 1.56, 0.64, 1); }
[data-vfx="glitch"] .kt-number-input.is-bump-up,
[data-vfx="glitch"] .kt-number-input.is-bump-down { animation: kt-number-glitch 160ms steps(3, end); }
[data-vfx="neon"] .kt-number-input.is-bump-up,
[data-vfx="neon"] .kt-number-input.is-bump-down {
text-shadow: 0 0 10px var(--_color);
animation: kt-number-jelly 240ms var(--ease-snap);
}
[data-vfx="ink"] .kt-number-input.is-bump-up,
[data-vfx="ink"] .kt-number-input.is-bump-down { animation: kt-number-ink 240ms var(--ease-overshoot); }
[data-vfx="neon"] .kt-number.is-focus .kt-number-display {
box-shadow: 0 0 0 2px color-mix(in srgb, var(--_color) 45%, transparent),
0 0 16px 1px color-mix(in srgb, var(--_color) 50%, transparent);
}
@keyframes kt-number-up {
0% { transform: translateY(7px); }
100% { transform: translateY(0); }
}
@keyframes kt-number-down {
0% { transform: translateY(-7px); }
100% { transform: translateY(0); }
}
@keyframes kt-number-jelly {
0% { transform: scale(0.88, 1.12); }
45% { transform: scale(1.08, 0.94); }
100% { transform: scale(1, 1); }
}
@keyframes kt-number-glitch {
0% { transform: translate(-2px, 1px) skewX(-8deg); }
50% { transform: translate(2px, -1px) skewX(6deg); }
100% { transform: translate(0, 0); }
}
@keyframes kt-number-ink {
0% { transform: scale(1.1, 0.88) rotate(-2deg); }
100% { transform: scale(1, 1) rotate(0); }
}
class KtKineticNumber extends HTMLElement {
static get observedAttributes() {
return ["value", "min", "max", "step", "label", "unit", "disabled", "readonly", "sfx"];
}
constructor() {
super();
this._rendered = false;
this._uid = `kt-number-${Math.random().toString(36).slice(2, 8)}`;
this._holdDelay = null;
this._holdTimer = null;
this._holdCount = 0;
this._bumpTimer = null;
this._stopHold = () => this.stopHold();
}
connectedCallback() {
if (!this._rendered) {
this.render();
this._rendered = true;
}
this.syncAttributes();
}
disconnectedCallback() {
this.stopHold();
clearTimeout(this._bumpTimer);
}
attributeChangedCallback() {
if (!this._rendered) return;
this.syncAttributes();
}
num(name, fallback) {
const raw = this.getAttribute(name);
if (raw === null || raw.trim() === "") return fallback;
const n = Number(raw);
return Number.isFinite(n) ? n : fallback;
}
get min() { return this.num("min", -Infinity); }
get max() { return this.num("max", Infinity); }
get step() {
const s = this.num("step", 1);
return s > 0 ? s : 1;
}
get label() { return this.getAttribute("label") || "Quantity"; }
get unit() { return this.getAttribute("unit") || ""; }
get disabled() { return this.hasAttribute("disabled"); }
get readOnly() { return this.hasAttribute("readonly"); }
get sfx() { return this.getAttribute("sfx") ?? "ポン!"; }
get value() {
const lo = this.min;
const v = this.num("value", Number.isFinite(lo) ? lo : 0);
return this.clamp(v);
}
set value(val) { this.setAttribute("value", String(val)); }
get precision() {
const dec = (n) => {
const str = String(n);
if (str.includes("e-")) return parseInt(str.split("e-")[1], 10);
return (str.split(".")[1] || "").length;
};
return Math.min(8, Math.max(dec(this.step), Number.isFinite(this.min) ? dec(this.min) : 0));
}
clamp(v) {
return Math.min(this.max, Math.max(this.min, v));
}
round(v) {
return Number(v.toFixed(this.precision));
}
render() {
this.innerHTML = "";
const wrap = document.createElement("div");
wrap.className = "kt-number";
wrap.innerHTML = `
<label class="kt-number-label"></label>
<div class="kt-number-row">
<button type="button" class="kt-number-btn kt-number-dec" tabindex="-1" aria-label="Decrease">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3 8h10" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
</button>
<div class="kt-number-display">
<input class="kt-number-input" type="text" inputmode="decimal" role="spinbutton" autocomplete="off" spellcheck="false" />
<span class="kt-number-unit" aria-hidden="true"></span>
</div>
<button type="button" class="kt-number-btn kt-number-inc" tabindex="-1" aria-label="Increase">
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3 8h10M8 3v10" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
</button>
</div>
`;
this._wrap = wrap;
this._labelEl = wrap.querySelector(".kt-number-label");
this._dec = wrap.querySelector(".kt-number-dec");
this._inc = wrap.querySelector(".kt-number-inc");
this._input = wrap.querySelector(".kt-number-input");
this._unitEl = wrap.querySelector(".kt-number-unit");
this._input.id = this._uid;
this._labelEl.htmlFor = this._uid;
for (const [btn, dir] of [[this._dec, -1], [this._inc, 1]]) {
btn.addEventListener("pointerdown", (e) => {
if (e.button !== 0 || this.disabled || this.readOnly) return;
e.preventDefault();
this._input.focus({ preventScroll: true });
this._pointerHeld = true;
try { btn.setPointerCapture(e.pointerId); } catch (err) { /* not capturable */ }
this.startHold(dir);
});
btn.addEventListener("pointerup", this._stopHold);
btn.addEventListener("pointercancel", this._stopHold);
btn.addEventListener("lostpointercapture", this._stopHold);
btn.addEventListener("click", (e) => {
// a real pointer press already stepped on pointerdown; this catches keyboard and assistive clicks
if (e.detail === 0 && !this.disabled && !this.readOnly) this.stepBy(dir);
});
}
this._input.addEventListener("input", () => {
this._wrap.classList.add("is-typing");
const parsed = this.parse(this._input.value);
this._input.setAttribute("aria-invalid", parsed === null || parsed !== this.clamp(parsed) ? "true" : "false");
});
this._input.addEventListener("blur", () => {
this.commitTyped();
this._wrap.classList.remove("is-focus");
});
this._input.addEventListener("focus", () => this._wrap.classList.add("is-focus"));
this._input.addEventListener("keydown", (e) => this.onKeydown(e));
this.appendChild(wrap);
}
parse(text) {
const t = String(text).trim().replace(",", ".");
if (t === "" || t === "-" || t === "." || t === "-.") return null;
const n = Number(t);
return Number.isFinite(n) ? n : null;
}
syncAttributes() {
if (!this._input) return;
const v = this.value;
const typing = this._wrap.classList.contains("is-typing");
if (!typing) this._input.value = this.format(v);
this._labelEl.textContent = this.label;
this._unitEl.textContent = this.unit;
this._unitEl.hidden = !this.unit;
const i = this._input;
i.disabled = this.disabled;
i.readOnly = this.readOnly;
i.setAttribute("aria-valuenow", String(v));
if (Number.isFinite(this.min)) i.setAttribute("aria-valuemin", String(this.min));
else i.removeAttribute("aria-valuemin");
if (Number.isFinite(this.max)) i.setAttribute("aria-valuemax", String(this.max));
else i.removeAttribute("aria-valuemax");
i.setAttribute("aria-valuetext", this.unit ? `${this.format(v)} ${this.unit}` : this.format(v));
if (!typing) i.setAttribute("aria-invalid", "false");
const off = this.disabled || this.readOnly;
this._dec.disabled = off || v <= this.min;
this._inc.disabled = off || v >= this.max;
this._dec.setAttribute("aria-label", `Decrease ${this.label}`);
this._inc.setAttribute("aria-label", `Increase ${this.label}`);
this._wrap.classList.toggle("is-disabled", this.disabled);
}
format(v) {
return v.toFixed(this.precision);
}
onKeydown(e) {
if (this.disabled || this.readOnly) return;
const big = this.step * 10;
if (e.key === "ArrowUp") { e.preventDefault(); this.stepBy(1); }
else if (e.key === "ArrowDown") { e.preventDefault(); this.stepBy(-1); }
else if (e.key === "PageUp") { e.preventDefault(); this.stepBy(1, big); }
else if (e.key === "PageDown") { e.preventDefault(); this.stepBy(-1, big); }
else if (e.key === "Home" && Number.isFinite(this.min) && !e.shiftKey) { e.preventDefault(); this.setValue(this.min); }
else if (e.key === "End" && Number.isFinite(this.max) && !e.shiftKey) { e.preventDefault(); this.setValue(this.max); }
else if (e.key === "Enter") { e.preventDefault(); this.commitTyped(); this._input.select(); }
else if (e.key === "Escape") {
this._wrap.classList.remove("is-typing");
this.syncAttributes();
} else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !/[0-9.,\-+]/.test(e.key)) {
e.preventDefault();
}
}
commitTyped() {
const typing = this._wrap.classList.contains("is-typing");
this._wrap.classList.remove("is-typing");
if (!typing) return;
const parsed = this.parse(this._input.value);
if (parsed === null) {
this.syncAttributes();
return;
}
this.setValue(parsed);
this.syncAttributes();
}
stepBy(dir, size = this.step) {
// a half-typed number counts: step from what is on screen
const typed = this._wrap.classList.contains("is-typing") ? this.parse(this._input.value) : null;
this._wrap.classList.remove("is-typing");
const base = typed !== null ? this.clamp(typed) : this.value;
const stepped = this.round(base + dir * size);
const next = this.clamp(stepped);
const hitLimit = stepped !== next || next === base;
const changed = this.setValue(next);
this.bump(dir);
if (hitLimit && !changed) this.limit();
return changed;
}
setValue(v) {
const prev = this.value;
const next = this.round(this.clamp(v));
const attrBefore = this.getAttribute("value");
this.setAttribute("value", String(next));
this.syncAttributes();
if (next === prev && attrBefore !== null) return false;
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { value: next } }));
return next !== prev;
}
startHold(dir) {
this.stopHold();
this._holdCount = 0;
const first = this.stepBy(dir);
this.fx(dir, 0.6);
if (!first) return;
this._holdDelay = setTimeout(() => {
const tick = () => {
this._holdCount++;
const moved = this.stepBy(dir, this.step * (this._holdCount > 25 ? 5 : 1));
if (!moved) return this.stopHold();
const wait = this._holdCount > 25 ? 35 : this._holdCount > 10 ? 55 : 90;
this._holdTimer = setTimeout(tick, wait);
};
tick();
}, 380);
}
stopHold() {
clearTimeout(this._holdDelay);
clearTimeout(this._holdTimer);
this._holdDelay = null;
this._holdTimer = null;
}
bump(dir) {
if (SakugaFX.getMode() === "enterprise") return;
const d = this._input;
d.classList.remove("is-bump-up", "is-bump-down");
void d.offsetWidth;
d.classList.add(dir > 0 ? "is-bump-up" : "is-bump-down");
clearTimeout(this._bumpTimer);
this._bumpTimer = setTimeout(() => d.classList.remove("is-bump-up", "is-bump-down"), 260);
}
limit() {
this._wrap.classList.remove("is-limit");
void this._wrap.offsetWidth;
this._wrap.classList.add("is-limit");
setTimeout(() => this._wrap.classList.remove("is-limit"), 360);
}
fx(dir, scale) {
if (SakugaFX.getMode() === "enterprise") return;
const btn = dir > 0 ? this._inc : this._dec;
const rect = btn.getBoundingClientRect();
SakugaFX.emitImpact(rect.left + rect.width / 2, rect.top + rect.height / 2, readAccent(this._wrap), {
sfx: this.sfx,
scale,
dirX: dir,
sfxY: rect.top - 4
});
}
}
customElements.define("kt-kinetic-number", KtKineticNumber);
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 |
|---|---|---|
value | Current number, always inside min and max. | min or 0 |
min | Lowest allowed value. Unset means no lower limit. | — |
max | Highest allowed value. Unset means no upper limit. | — |
step | Amount each press adds or removes. Decimals are rounded cleanly. | 1 |
label | Text above the field. | Quantity |
unit | Short unit shown inside the field, such as "sec". | — |
disabled | Present when the field cannot be used. | — |
readonly | Present when the value can be read but not changed. | — |
sfx | Sound-effect text on the first press. | ポン! |
Keyboard and screen readers
- The field has role="spinbutton" with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext.
- ArrowUp and ArrowDown change the value by step; PageUp and PageDown by ten steps; Home and End jump to min and max.
- Enter or leaving the field commits a typed value, clamped to the range; Escape discards it.
- The minus and plus buttons are named and disable at the limits; they stay out of the Tab order because the field itself handles the keys.
- Holding a button repeats after a short delay and speeds up; fires change with { value }.
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 Number Stepper: questions answered
How do I use the Kinetic Number Stepper?
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-number>.
Which attributes does <kt-kinetic-number> accept?
value, min, max, step, label, unit, disabled, readonly, sfx. Each one is described in the attributes table on this page.
Is the Kinetic Number Stepper accessible?
The field has role="spinbutton" with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext. ArrowUp and ArrowDown change the value by step; PageUp and PageDown by ten steps; Home and End jump to min and max. Enter or leaving the field commits a typed value, clamped to the range; Escape discards it. The minus and plus buttons are named and disable at the limits; they stay out of the Tab order because the field itself handles the keys. Holding a button repeats after a short delay and speeds up; fires change with { value }.
Can I change the Kinetic Number Stepper 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.