Files
ianitor/packages/domi-ui/src/lib/strike.ts
T
mnovak c9aa55ec99 [web] Domi UI: the web UI on @domi/ui v1.0.4, vendored (CPAL-1.0), with the Built on Domi credit (PR #14, squashed)
@domi/ui v1.0.4 vendored unchanged in packages/domi-ui by domi-design's tools/vendor.mjs and used as workspace:*, so
the Nix build fetches nothing from Gitea (web.nix sources the folder; fetchPnpmDeps hash from the NixOS runner).
Its fonts, roles (data-domi-room="ianitor", the same hex) and controls replace Ianitor's copies: Button through
Ianitor's adapter (desktop sizes kept), every text field a TextField with its seal, Checkbox, Select, Segmented.
Ianitor's 22 role names renamed to --domi-*. <DomiCredit /> on every screen and in About, with the CPAL section 15
note beside the source link; the README names the vendored package. Disabled buttons are natively disabled.
2026-11-23 00:52:19 +01:00

51 lines
2.0 KiB
TypeScript

import type { Action } from 'svelte/action';
/**
* The press flow of every Domi button: on pointer down it places the seal impression where the press landed
* (--_px, --_py) and replays it (data-struck); Enter and Space show the sunk plate while held (data-pressed), so a
* keyboard press looks like a pointer press. Reduced motion is handled in CSS (no impression, no movement).
*/
export const strike: Action<HTMLElement> = (node) => {
const replay = (x: string, y: string) => {
node.style.setProperty('--_px', x);
node.style.setProperty('--_py', y);
node.removeAttribute('data-struck');
// Force a style flush so the animation restarts on a quick second press.
void node.offsetWidth;
node.setAttribute('data-struck', '');
};
const down = (e: PointerEvent) => {
if (e.button !== 0 || isInert(node)) return;
const r = node.getBoundingClientRect();
replay(`${e.clientX - r.left}px`, `${e.clientY - r.top}px`);
};
const keydown = (e: KeyboardEvent) => {
if ((e.key === 'Enter' || e.key === ' ') && !e.repeat && !isInert(node)) {
node.setAttribute('data-pressed', '');
replay('50%', '50%');
}
};
const release = () => node.removeAttribute('data-pressed');
const end = (e: AnimationEvent) => {
if (e.target === node && e.pseudoElement === '::after') node.removeAttribute('data-struck');
};
node.addEventListener('pointerdown', down);
node.addEventListener('keydown', keydown);
node.addEventListener('keyup', release);
node.addEventListener('blur', release);
node.addEventListener('animationend', end);
return {
destroy() {
node.removeEventListener('pointerdown', down);
node.removeEventListener('keydown', keydown);
node.removeEventListener('keyup', release);
node.removeEventListener('blur', release);
node.removeEventListener('animationend', end);
},
};
};
function isInert(node: HTMLElement): boolean {
return (node as HTMLButtonElement).disabled === true || node.getAttribute('aria-disabled') === 'true';
}