Kinetic Input
A text field with a floating label, helper or error text, optional prefix and suffix, a clear button and a password toggle.
- <kt-kinetic-input>
- Inputs
- No framework
The code
Copy the Kinetic Input
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-input label="Work email" type="email" placeholder="name@company.com" helper="We only use this to send your receipt." clearable></kt-kinetic-input>
<kt-kinetic-input label="Password" type="password" value="hunter2-horse" helper="Use at least 12 characters."></kt-kinetic-input>
<kt-kinetic-input label="Budget" prefix="$" suffix="USD" value="2400" clearable></kt-kinetic-input>
<kt-kinetic-input label="Workspace URL" value="acme corp" error="Use lowercase letters, numbers and dashes only."></kt-kinetic-input>
kt-kinetic-input {
display: block;
width: 100%;
max-width: 340px;
}
.kt-input {
--_color: var(--kt-accent);
--_ink: var(--kt-accent-ink);
--_err: color-mix(in srgb, #dc2626 72%, var(--kt-surface-ink));
width: 100%;
color: var(--kt-surface-ink);
}
.kt-input-field {
position: relative;
display: flex;
align-items: center;
gap: 8px;
min-height: 54px;
padding: 0 10px 0 14px;
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);
box-shadow: var(--kt-comp-shadow);
transition: border-color 160ms ease, box-shadow 180ms ease, background-color 150ms ease;
}
.kt-input-field:hover:not(.is-disabled) {
border-color: var(--kt-comp-border, var(--kt-surface-ink));
}
.kt-input-field.is-focus {
border-color: var(--kt-comp-border, var(--_color));
box-shadow: 0 0 0 3px color-mix(in srgb, var(--_color) 28%, transparent);
}
.kt-input.is-error .kt-input-field {
border-color: var(--_err);
}
.kt-input.is-error .kt-input-field.is-focus {
box-shadow: 0 0 0 3px color-mix(in srgb, var(--_err) 28%, transparent);
}
.kt-input-field.is-disabled {
opacity: 0.55;
cursor: not-allowed;
background: color-mix(in srgb, var(--kt-surface-ink) 6%, var(--kt-surface-bg));
}
.kt-input-control {
position: relative;
flex: 1;
min-width: 0;
height: 54px;
}
.kt-input-native {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
padding: 20px 0 5px;
border: 0;
outline: 0;
background: transparent;
color: var(--kt-surface-ink);
font-family: var(--font-sans);
font-size: 14px;
font-weight: 600;
line-height: 1.3;
text-overflow: ellipsis;
box-shadow: none;
}
.kt-input-field.no-label .kt-input-native {
padding-top: 5px;
}
.kt-input-native:disabled {
cursor: not-allowed;
}
.kt-input-native::placeholder {
color: var(--kt-surface-muted);
font-weight: 500;
opacity: 0;
transition: opacity 140ms ease;
}
.kt-input-field.is-focus .kt-input-native::placeholder,
.kt-input-field.has-value .kt-input-native::placeholder,
.kt-input-field.has-prefix .kt-input-native::placeholder,
.kt-input-field.has-suffix .kt-input-native::placeholder,
.kt-input-field.no-label .kt-input-native::placeholder {
opacity: 0.85;
}
.kt-input-label {
position: absolute;
left: 0;
top: 50%;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
transform: translateY(-50%);
transform-origin: left center;
font-family: var(--font-sans);
font-size: 14px;
font-weight: 600;
line-height: 1;
color: var(--kt-surface-muted);
pointer-events: none;
transition: top 170ms var(--ease-snap), transform 170ms var(--ease-snap), color 150ms ease,
font-size 170ms var(--ease-snap), letter-spacing 170ms ease;
}
.kt-input-field.is-focus .kt-input-label,
.kt-input-field.has-prefix .kt-input-label,
.kt-input-field.has-suffix .kt-input-label,
.kt-input-field.has-value .kt-input-label {
top: 11px;
transform: translateY(-50%);
font-family: var(--font-mono);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.kt-input-field.is-focus .kt-input-label {
color: var(--kt-surface-ink);
}
.kt-input.is-error .kt-input-label {
color: var(--_err);
}
.kt-input-field.no-label .kt-input-label {
display: none;
}
.kt-input-prefix,
.kt-input-suffix {
flex-shrink: 0;
font-family: var(--font-mono);
font-size: 12px;
font-weight: 700;
line-height: 1;
color: var(--kt-surface-muted);
padding-top: 12px;
user-select: none;
}
.kt-input-prefix[hidden],
.kt-input-suffix[hidden],
.kt-input-btn[hidden],
.kt-input-note[hidden] {
display: none;
}
.kt-input-btn {
flex-shrink: 0;
display: inline-grid;
place-items: center;
width: 28px;
height: 28px;
padding: 0;
border: 0;
border-radius: var(--kt-radius-tag);
background: transparent;
color: var(--kt-surface-muted);
cursor: pointer;
transition: color 140ms ease, background-color 140ms ease, transform 160ms var(--ease-snap);
}
.kt-input-btn:hover:not(:disabled) {
color: var(--kt-surface-ink);
background: color-mix(in srgb, var(--kt-surface-ink) 10%, transparent);
}
.kt-input-btn:active:not(:disabled) {
transform: scale(0.92);
}
.kt-input-btn:focus-visible {
outline: 2px solid var(--kt-surface-ink);
outline-offset: 1px;
}
.kt-input-reveal .kt-input-slash {
opacity: 0;
transition: opacity 140ms ease;
}
.kt-input-reveal.is-revealed .kt-input-slash {
opacity: 1;
}
.kt-input-note {
margin: 6px 4px 0;
font-family: var(--font-sans);
font-size: 12px;
font-weight: 500;
line-height: 1.35;
color: var(--kt-surface-muted);
}
.kt-input-note.is-error {
color: var(--_err);
font-weight: 600;
}
/* VFX */
[data-vfx="sakuga"] .kt-input-field.is-shaking { animation: kt-input-shake 380ms var(--ease-overshoot); }
[data-vfx="elastic"] .kt-input-field.is-shaking { animation: kt-input-jelly 460ms cubic-bezier(0.34, 1.56, 0.64, 1); }
[data-vfx="glitch"] .kt-input-field.is-shaking { animation: kt-input-glitch 240ms steps(5, end); }
[data-vfx="neon"] .kt-input-field.is-shaking { animation: kt-input-shake 360ms var(--ease-snap); }
[data-vfx="ink"] .kt-input-field.is-shaking { animation: kt-input-ink 380ms var(--ease-overshoot); }
[data-vfx="neon"] .kt-input-field.is-focus {
box-shadow: 0 0 0 2px color-mix(in srgb, var(--_color) 45%, transparent),
0 0 18px 1px color-mix(in srgb, var(--_color) 55%, transparent);
}
[data-vfx="neon"] .kt-input.is-error .kt-input-field.is-focus {
box-shadow: 0 0 0 2px color-mix(in srgb, var(--_err) 45%, transparent),
0 0 18px 1px color-mix(in srgb, var(--_err) 55%, transparent);
}
@keyframes kt-input-shake {
0%, 100% { transform: translateX(0); }
20% { transform: translateX(-6px); }
40% { transform: translateX(5px); }
60% { transform: translateX(-3px); }
80% { transform: translateX(2px); }
}
@keyframes kt-input-jelly {
0% { transform: scale(1.03, 0.94); }
35% { transform: scale(0.97, 1.05); }
68% { transform: scale(1.01, 0.99); }
100% { transform: scale(1, 1); }
}
@keyframes kt-input-glitch {
0% { transform: translate(-3px, 1px) skewX(-8deg); }
50% { transform: translate(3px, -1px) skewX(6deg); }
100% { transform: translate(0, 0) skewX(0); }
}
@keyframes kt-input-ink {
0% { transform: scale(1.03, 0.95) rotate(-1deg); }
55% { transform: scale(0.98, 1.03) rotate(0.6deg); }
100% { transform: scale(1, 1) rotate(0); }
}
class KtKineticInput extends HTMLElement {
static get observedAttributes() {
return ["label", "value", "type", "placeholder", "helper", "error", "prefix", "suffix", "clearable", "disabled", "name", "autocomplete", "sfx"];
}
constructor() {
super();
this._rendered = false;
this._uid = `kt-input-${Math.random().toString(36).slice(2, 8)}`;
this._revealed = false;
this._shakeTimer = null;
}
connectedCallback() {
if (!this._rendered) {
this.render();
this._rendered = true;
}
this.syncAttributes();
}
disconnectedCallback() {
clearTimeout(this._shakeTimer);
}
attributeChangedCallback(name, oldVal, newVal) {
if (!this._rendered) return;
this.syncAttributes();
if (name === "error" && newVal && newVal !== oldVal) this.shake();
}
get type() {
const t = (this.getAttribute("type") || "text").toLowerCase();
return t === "email" || t === "password" ? t : "text";
}
get value() { return this._input ? this._input.value : this.getAttribute("value") || ""; }
set value(val) { this.setAttribute("value", String(val ?? "")); }
get label() { return this.getAttribute("label") || ""; }
get helper() { return this.getAttribute("helper") || ""; }
get error() { return this.getAttribute("error") || ""; }
get sfx() { return this.getAttribute("sfx") ?? "スッ!"; }
get disabled() { return this.hasAttribute("disabled"); }
get clearable() { return this.hasAttribute("clearable"); }
render() {
this.innerHTML = "";
const wrap = document.createElement("div");
wrap.className = "kt-input";
wrap.innerHTML = `
<div class="kt-input-field">
<span class="kt-input-prefix" aria-hidden="true"></span>
<div class="kt-input-control">
<input class="kt-input-native" />
<label class="kt-input-label"></label>
</div>
<button type="button" class="kt-input-btn kt-input-clear" tabindex="-1" aria-label="Clear" hidden>
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
</button>
<button type="button" class="kt-input-btn kt-input-reveal" aria-pressed="false" aria-label="Show password" hidden>
<svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
<path d="M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/>
<circle cx="8" cy="8" r="2" fill="none" stroke="currentColor" stroke-width="1.5"/>
<path class="kt-input-slash" d="M2.5 13.5l11-11" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
</svg>
</button>
<span class="kt-input-suffix" aria-hidden="true"></span>
</div>
<div class="kt-input-note" aria-live="polite"></div>
`;
this._wrap = wrap;
this._field = wrap.querySelector(".kt-input-field");
this._input = wrap.querySelector(".kt-input-native");
this._labelEl = wrap.querySelector(".kt-input-label");
this._prefixEl = wrap.querySelector(".kt-input-prefix");
this._suffixEl = wrap.querySelector(".kt-input-suffix");
this._clearBtn = wrap.querySelector(".kt-input-clear");
this._revealBtn = wrap.querySelector(".kt-input-reveal");
this._note = wrap.querySelector(".kt-input-note");
this._input.id = this._uid;
this._labelEl.htmlFor = this._uid;
this._note.id = `${this._uid}-note`;
this._input.value = this.getAttribute("value") || "";
this._input.addEventListener("input", (e) => {
e.stopPropagation();
this._commitAttr();
this.syncAttributes();
this.dispatchEvent(new CustomEvent("input", { bubbles: true, detail: { value: this._input.value } }));
});
this._input.addEventListener("change", (e) => {
e.stopPropagation();
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { value: this._input.value } }));
});
this._input.addEventListener("focus", () => this._field.classList.add("is-focus"));
this._input.addEventListener("blur", () => this._field.classList.remove("is-focus"));
this._field.addEventListener("pointerdown", (e) => {
if (this.disabled) return;
if (e.target === this._field || e.target === this._prefixEl || e.target === this._suffixEl) {
e.preventDefault();
this._input.focus();
}
});
this._clearBtn.addEventListener("click", () => this.clear());
this._revealBtn.addEventListener("click", () => this.toggleReveal());
this.appendChild(wrap);
}
_commitAttr() {
// keep the attribute in step with typing so a copied element shows the same text
const v = this._input.value;
if (this.getAttribute("value") !== v) this.setAttribute("value", v);
}
syncAttributes() {
if (!this._input) return;
const input = this._input;
const attrValue = this.getAttribute("value") || "";
if (input.value !== attrValue) input.value = attrValue;
const isPassword = this.type === "password";
input.type = isPassword && this._revealed ? "text" : this.type;
input.disabled = this.disabled;
input.placeholder = this.getAttribute("placeholder") || "";
input.name = this.getAttribute("name") || "";
const ac = this.getAttribute("autocomplete");
if (ac) input.setAttribute("autocomplete", ac);
else input.setAttribute("autocomplete", isPassword ? "current-password" : this.type === "email" ? "email" : "off");
if (this.type === "email") input.setAttribute("inputmode", "email");
input.setAttribute("spellcheck", "false");
this._labelEl.textContent = this.label;
if (!this.label) input.setAttribute("aria-label", this.getAttribute("placeholder") || "Text field");
else input.removeAttribute("aria-label");
const prefix = this.getAttribute("prefix") || "";
const suffix = this.getAttribute("suffix") || "";
this._prefixEl.textContent = prefix;
this._suffixEl.textContent = suffix;
this._prefixEl.hidden = !prefix;
this._suffixEl.hidden = !suffix;
const hasValue = input.value.length > 0;
this._field.classList.toggle("has-value", hasValue);
this._field.classList.toggle("has-prefix", !!prefix);
this._field.classList.toggle("has-suffix", !!suffix);
this._field.classList.toggle("no-label", !this.label);
this._field.classList.toggle("is-disabled", this.disabled);
this._clearBtn.hidden = !(this.clearable && hasValue && !this.disabled);
this._revealBtn.hidden = !isPassword;
this._revealBtn.disabled = this.disabled;
this._revealBtn.setAttribute("aria-pressed", String(this._revealed));
this._revealBtn.setAttribute("aria-label", this._revealed ? "Hide password" : "Show password");
this._revealBtn.classList.toggle("is-revealed", this._revealed);
const err = this.error;
const text = err || this.helper;
this._wrap.classList.toggle("is-error", !!err);
this._note.textContent = text;
this._note.hidden = !text;
this._note.classList.toggle("is-error", !!err);
if (err) input.setAttribute("aria-invalid", "true");
else input.removeAttribute("aria-invalid");
if (text) input.setAttribute("aria-describedby", this._note.id);
else input.removeAttribute("aria-describedby");
}
clear() {
if (this.disabled || !this._input.value) return;
this._input.value = "";
this._commitAttr();
this.syncAttributes();
this._input.focus();
this.dispatchEvent(new CustomEvent("input", { bubbles: true, detail: { value: "" } }));
this.dispatchEvent(new CustomEvent("change", { bubbles: true, detail: { value: "" } }));
this.fx(this._clearBtn, 0.55);
}
toggleReveal() {
if (this.disabled) return;
this._revealed = !this._revealed;
this.syncAttributes();
this._input.focus();
}
shake() {
if (SakugaFX.getMode() === "enterprise") return;
this._field.classList.remove("is-shaking");
void this._field.offsetWidth;
this._field.classList.add("is-shaking");
clearTimeout(this._shakeTimer);
this._shakeTimer = setTimeout(() => this._field.classList.remove("is-shaking"), 480);
}
fx(target, scale) {
if (SakugaFX.getMode() === "enterprise") return;
const rect = target.getBoundingClientRect();
SakugaFX.emitImpact(rect.left + rect.width / 2, rect.top + rect.height / 2, readAccent(this._wrap), {
sfx: this.sfx,
scale,
sfxY: rect.top - 4
});
}
}
customElements.define("kt-kinetic-input", KtKineticInput);
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 |
|---|---|---|
label | Floating label that moves up once the field has focus or text. | — |
value | Current text. Kept in sync as the visitor types. | — |
type | "text", "email" or "password" (adds a show/hide toggle). | text |
placeholder | Hint shown while the field is focused and empty. | — |
helper | Small text under the field. | — |
error | Error message. When present the field turns red, shows this text and is marked invalid. | — |
prefix | Short text before the value, such as a currency symbol. | — |
suffix | Short text after the value, such as a unit. | — |
clearable | Shows a clear button while the field has text. | — |
disabled | Present when the field cannot be used. | — |
name | Name of the inner input, so a surrounding form can read it. | — |
autocomplete | Passed to the inner input (for example "email"). | — |
sfx | Sound-effect text on clear. | スッ! |
Keyboard and screen readers
- A real input with a label tied to it by for/id; the floating label is still the accessible name.
- Helper and error text is linked with aria-describedby; an error sets aria-invalid and is announced politely.
- The password toggle is a button with aria-pressed and a "Show password"/"Hide password" name.
- The clear button is skipped by Tab so it never interrupts typing; it is still clickable and keeps focus in the field.
- Fires input and change events with the text in detail.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 Input: questions answered
How do I use the Kinetic Input?
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-input>.
Which attributes does <kt-kinetic-input> accept?
label, value, type, placeholder, helper, error, prefix, suffix, clearable, disabled, name, autocomplete, sfx. Each one is described in the attributes table on this page.
Is the Kinetic Input accessible?
A real input with a label tied to it by for/id; the floating label is still the accessible name. Helper and error text is linked with aria-describedby; an error sets aria-invalid and is announced politely. The password toggle is a button with aria-pressed and a "Show password"/"Hide password" name. The clear button is skipped by Tab so it never interrupts typing; it is still clickable and keeps focus in the field. Fires input and change events with the text in detail.value.
Can I change the Kinetic Input 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.