@usableapp/cardds 0.7.84 → 0.7.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +4 -1
- package/css/actions.css +1 -0
- package/css/stamp.css +6 -0
- package/dist/cardds.css +7 -0
- package/dist/catalog.json +1 -1
- package/dist/stamp/StampOn.d.ts +7 -1
- package/dist/stamp/StampOn.js +15 -4
- package/package.json +1 -1
package/dist/stamp/StampOn.d.ts
CHANGED
|
@@ -15,6 +15,11 @@ export interface StampOnProps extends ComponentProps<'div'> {
|
|
|
15
15
|
onAtChange?: (at: StampAt) => void;
|
|
16
16
|
/** a draggable stamp's accessible name ("แสตมป์ของต้น") */
|
|
17
17
|
label?: string;
|
|
18
|
+
/** the stamp sticks ITSELF: as it comes onto the screen it is struck onto its place (shown large, pressed down to its size). Nobody
|
|
19
|
+
* picked it or pressed to stick it — the app shows it when its own move (send) begins. With `onArrived` */
|
|
20
|
+
arrive?: boolean;
|
|
21
|
+
/** an arriving stamp has LANDED (its strike ended; at once where motion is off) — the app does what follows: sends, closes */
|
|
22
|
+
onArrived?: () => void;
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
20
25
|
* StampOn — a Stamp (the child) stuck on a surface at the place the member chose. The surface is the nearest positioned box:
|
|
@@ -22,5 +27,6 @@ export interface StampOnProps extends ComponentProps<'div'> {
|
|
|
22
27
|
* The stamp is the SMALL size: 48 × 60 on any surface, whatever the surface's size (`--stamp-sm-size`, one tap wide).
|
|
23
28
|
* With `onAtChange` the member drags it (finger or mouse; the arrow keys move it too): while the finger holds, the stamp writes its
|
|
24
29
|
* own place, and on letting go it ASKS — the app owns `at`. It never leaves the surface.
|
|
30
|
+
* With `arrive` it sticks itself: struck onto its place as it comes on, and `onArrived` tells the app it has landed.
|
|
25
31
|
*/
|
|
26
|
-
export declare function StampOn({ at, defaultAt, turn, onAtChange, label, className, style, children, ...rest }: StampOnProps): import("react").JSX.Element;
|
|
32
|
+
export declare function StampOn({ at, defaultAt, turn, onAtChange, label, arrive, onArrived, className, style, onAnimationEnd, children, ...rest }: StampOnProps): import("react").JSX.Element;
|
package/dist/stamp/StampOn.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useRef, useState } from 'react';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { cx } from '../cx.js';
|
|
4
|
-
import { useControlled } from '../state.js';
|
|
4
|
+
import { reducedMotion, useControlled } from '../state.js';
|
|
5
5
|
const MIDDLE = { x: 0.5, y: 0.5 };
|
|
6
6
|
const STEP = 0.02; // an arrow key's move: a share of the surface
|
|
7
7
|
const MOVES = { ArrowLeft: [-STEP, 0], ArrowRight: [STEP, 0], ArrowUp: [0, -STEP], ArrowDown: [0, STEP] };
|
|
@@ -15,6 +15,7 @@ function within(el, x, y) {
|
|
|
15
15
|
const mx = el.offsetWidth / 2 / box.clientWidth, my = el.offsetHeight / 2 / box.clientHeight;
|
|
16
16
|
return { x: round(clamp(x, mx, 1 - mx)), y: round(clamp(y, my, 1 - my)) };
|
|
17
17
|
}
|
|
18
|
+
const STRIKE = 'stamp-on-strike'; // css/stamp.css
|
|
18
19
|
const write = (el, at) => { el.style.setProperty('--stamp-on-x', String(at.x)); el.style.setProperty('--stamp-on-y', String(at.y)); };
|
|
19
20
|
/**
|
|
20
21
|
* StampOn — a Stamp (the child) stuck on a surface at the place the member chose. The surface is the nearest positioned box:
|
|
@@ -22,8 +23,9 @@ const write = (el, at) => { el.style.setProperty('--stamp-on-x', String(at.x));
|
|
|
22
23
|
* The stamp is the SMALL size: 48 × 60 on any surface, whatever the surface's size (`--stamp-sm-size`, one tap wide).
|
|
23
24
|
* With `onAtChange` the member drags it (finger or mouse; the arrow keys move it too): while the finger holds, the stamp writes its
|
|
24
25
|
* own place, and on letting go it ASKS — the app owns `at`. It never leaves the surface.
|
|
26
|
+
* With `arrive` it sticks itself: struck onto its place as it comes on, and `onArrived` tells the app it has landed.
|
|
25
27
|
*/
|
|
26
|
-
export function StampOn({ at, defaultAt = MIDDLE, turn = 0, onAtChange, label, className, style, children, ...rest }) {
|
|
28
|
+
export function StampOn({ at, defaultAt = MIDDLE, turn = 0, onAtChange, label, arrive, onArrived, className, style, onAnimationEnd, children, ...rest }) {
|
|
27
29
|
const [shown, request] = useControlled(at, defaultAt, onAtChange);
|
|
28
30
|
const [held, setHeld] = useState(false);
|
|
29
31
|
const grip = useRef(null);
|
|
@@ -64,7 +66,16 @@ export function StampOn({ at, defaultAt = MIDDLE, turn = 0, onAtChange, label, c
|
|
|
64
66
|
e.preventDefault();
|
|
65
67
|
ask(within(e.currentTarget, shown.x + by[0], shown.y + by[1]));
|
|
66
68
|
};
|
|
69
|
+
const landed = useRef(onArrived);
|
|
70
|
+
landed.current = onArrived;
|
|
71
|
+
useEffect(() => { if (arrive && reducedMotion())
|
|
72
|
+
landed.current?.(); }, [arrive]); // no strike to wait for
|
|
73
|
+
const struck = (e) => {
|
|
74
|
+
onAnimationEnd?.(e);
|
|
75
|
+
if (arrive && e.target === e.currentTarget && e.animationName === STRIKE)
|
|
76
|
+
onArrived?.();
|
|
77
|
+
};
|
|
67
78
|
const place = { '--stamp-on-x': shown.x, '--stamp-on-y': shown.y, '--stamp-on-turn': turn, ...style };
|
|
68
79
|
const drag = moves ? { tabIndex: 0, role: 'group', 'aria-label': label, onPointerDown: down, onPointerMove: move, onPointerUp: up, onPointerCancel: up, onKeyDown: key } : null;
|
|
69
|
-
return (_jsx("div", { className: cx('stamp-on', moves && 'stamp-on--move', held && 'is-held', className), style: place, ...rest, ...drag, children: children }));
|
|
80
|
+
return (_jsx("div", { className: cx('stamp-on', moves && 'stamp-on--move', arrive && 'stamp-on--arrive', held && 'is-held', className), style: place, onAnimationEnd: struck, ...rest, ...drag, children: children }));
|
|
70
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usableapp/cardds",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.85",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "card-first mobile design system, React-first: the components in src/ are thin wrappers over the CSS contract (css/*.css stays the only truth); gallery/ shows every story live (npm run dev), tests/ measures the geometry.",
|