@citrusworx/juiceui 0.9.3 → 0.9.5
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/README.md +345 -242
- package/dist/index.css +465 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +605 -2
- package/dist/js/juice.d.ts +6 -0
- package/dist/js/src/keyboard-avoider/keyboard-avoider-runtime.d.ts +96 -0
- package/dist/js/src/pressable/pressable-runtime.d.ts +106 -0
- package/dist/js/src/shared/change.d.ts +1 -0
- package/dist/js/src/touchable-row/touchable-row-runtime.d.ts +123 -0
- package/package.json +2 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM-first runtime for Juice keyboard-avoider chrome.
|
|
3
|
+
*
|
|
4
|
+
* Markup contract (Slice A — do not rename attrs):
|
|
5
|
+
* [keyboard-avoider] host. Padding mode. Any unknown
|
|
6
|
+
* value is still a host. Words
|
|
7
|
+
* compose, same as the CSS.
|
|
8
|
+
* [keyboard-avoider="padding"] padding mode. Matches ~= .
|
|
9
|
+
* [keyboard-avoider~="translate"] translateY by the inset.
|
|
10
|
+
* [keyboard-avoider~="footer"] sticky; bottom is the inset.
|
|
11
|
+
* [keyboard-avoider~="noscroll"] this runtime does not
|
|
12
|
+
* scrollIntoView a focus inside
|
|
13
|
+
* that host. The word is behavior,
|
|
14
|
+
* not a layout mode. CSS ignores it.
|
|
15
|
+
* [keyboard-open] set on <html> and on each host
|
|
16
|
+
* while the keyboard is open.
|
|
17
|
+
* Slice A does not select it. The
|
|
18
|
+
* inset is the layout input.
|
|
19
|
+
*
|
|
20
|
+
* The overlap is the layout viewport minus the visual viewport:
|
|
21
|
+
*
|
|
22
|
+
* inset = max(0, round(innerHeight - (visualViewport.height + visualViewport.offsetTop)))
|
|
23
|
+
*
|
|
24
|
+
* iOS reports part of that overlap as offsetTop. Leaving it out
|
|
25
|
+
* counts the keyboard twice. Chrome Android with
|
|
26
|
+
* interactive-widget=resizes-content shrinks innerHeight with the
|
|
27
|
+
* keyboard, so the same formula is about 0 and this runtime does not
|
|
28
|
+
* pad on top of the layout viewport. Pinch zoom (visualViewport.scale
|
|
29
|
+
* other than 1) skips the update and leaves the previous inset.
|
|
30
|
+
*
|
|
31
|
+
* While open, the inset is written as `<n>px` on
|
|
32
|
+
* document.documentElement (the <html> element), not on each host.
|
|
33
|
+
* --juice-keyboard-inset inherits. When the keyboard is not open the
|
|
34
|
+
* inline property is removed. A closed keyboard must not leave an
|
|
35
|
+
* inline length behind: an inline value beats both the 0px role on
|
|
36
|
+
* :root and the @supports env(keyboard-inset-height) fallback. Clearing
|
|
37
|
+
* it is what lets that fallback show through. getState().inset is still
|
|
38
|
+
* the measured overlap. Only the custom property is cleared.
|
|
39
|
+
*
|
|
40
|
+
* open is inset > threshold (default 80) and an editable element has
|
|
41
|
+
* focus. Editable is a text-like input, the same set as the Input
|
|
42
|
+
* runtime (missing type, empty type, text, email, password, search,
|
|
43
|
+
* tel, url, number), plus a textarea, a select, or [contenteditable]
|
|
44
|
+
* (including a focused descendant). A hardware keyboard does not
|
|
45
|
+
* shrink the visual viewport, so a focused field stays closed. Every
|
|
46
|
+
* other input type is not editable: checkbox, radio, range, date,
|
|
47
|
+
* time, datetime-local, month, week, color, file, hidden, button,
|
|
48
|
+
* submit, reset, and image.
|
|
49
|
+
*
|
|
50
|
+
* Listeners: visualViewport resize and scroll, window resize and
|
|
51
|
+
* orientationchange, focusin and focusout on root. Updates are
|
|
52
|
+
* coalesced with requestAnimationFrame. This runtime does not set
|
|
53
|
+
* navigator.virtualKeyboard.overlaysContent.
|
|
54
|
+
*
|
|
55
|
+
* Scroll-into-view is on by default. focusin inside a host remembers
|
|
56
|
+
* the focused element. The scroll runs two frames after geometry
|
|
57
|
+
* events go quiet, so a resize burst settles before the element moves,
|
|
58
|
+
* and the inset written on the first of those frames is the one layout
|
|
59
|
+
* sees. A focus that never resizes still scrolls on that quiet window.
|
|
60
|
+
* The call is element.scrollIntoView({ block: 'nearest', behavior })
|
|
61
|
+
* with behavior 'auto' when prefersReducedMotion() is true and 'smooth'
|
|
62
|
+
* otherwise. [keyboard-avoider~="noscroll"] or scrollIntoView: false
|
|
63
|
+
* opts out. destroy cancels a pending scroll.
|
|
64
|
+
*
|
|
65
|
+
* State is { open, inset }. juice:change bubbles from each host with
|
|
66
|
+
* detail { runtime: 'keyboard-avoider', state }. The first observation
|
|
67
|
+
* is silent. Later events fire when open flips, or when the inset has
|
|
68
|
+
* moved by at least `threshold` pixels from the last published inset
|
|
69
|
+
* while open. Smaller steps still update the custom property and
|
|
70
|
+
* getState. They accumulate against the last published inset, so a
|
|
71
|
+
* slow drift still publishes once it is stale by `threshold`.
|
|
72
|
+
*
|
|
73
|
+
* No window, or no visualViewport, is a no-op (SSR and old browsers).
|
|
74
|
+
* getState then returns { open: false, inset: 0 }. No Sig
|
|
75
|
+
* KeyboardAvoider factory. Keyboard-avoider is the thirty-first
|
|
76
|
+
* Emerging auto-enhance runtime.
|
|
77
|
+
*/
|
|
78
|
+
export type KeyboardAvoiderOptions = {
|
|
79
|
+
root?: ParentNode;
|
|
80
|
+
keyboardAvoiderSelector?: string;
|
|
81
|
+
threshold?: number;
|
|
82
|
+
scrollIntoView?: boolean;
|
|
83
|
+
};
|
|
84
|
+
export type KeyboardAvoiderState = {
|
|
85
|
+
open: boolean;
|
|
86
|
+
inset: number;
|
|
87
|
+
};
|
|
88
|
+
export type KeyboardAvoiderController = {
|
|
89
|
+
destroy: () => void;
|
|
90
|
+
sync: () => void;
|
|
91
|
+
getState: (target?: HTMLElement | null) => KeyboardAvoiderState | null;
|
|
92
|
+
};
|
|
93
|
+
export declare const createKeyboardAvoider: (options?: KeyboardAvoiderOptions) => KeyboardAvoiderController;
|
|
94
|
+
export declare const initKeyboardAvoider: (options?: KeyboardAvoiderOptions) => KeyboardAvoiderController;
|
|
95
|
+
export declare const startKeyboardAvoiderRuntime: () => KeyboardAvoiderController | null;
|
|
96
|
+
export declare const stopKeyboardAvoiderRuntime: () => void;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM-first runtime for Juice pressable chrome.
|
|
3
|
+
*
|
|
4
|
+
* Markup contract (Slice A — do not rename attrs):
|
|
5
|
+
* [pressable] host. Any value, including "scale", is still
|
|
6
|
+
* a pressable. Sync does not rewrite it.
|
|
7
|
+
* [pressed] transient press. This runtime sets it only
|
|
8
|
+
* for the gesture, and only when it added the
|
|
9
|
+
* attribute. It is not a latched toggle.
|
|
10
|
+
* [pressable-longpress] opt-in. Absent, the host does not arm a
|
|
11
|
+
* long-press. Present with an empty value or
|
|
12
|
+
* "true", the delay is `longPressDelay`
|
|
13
|
+
* (default 500). A non-negative number is the
|
|
14
|
+
* delay in milliseconds. "false" does not arm.
|
|
15
|
+
* Any other value uses the default delay.
|
|
16
|
+
* [pressable-slop] optional pixel slop for this host. A
|
|
17
|
+
* non-negative number overrides `moveSlop`
|
|
18
|
+
* (default 10). Anything else uses the option.
|
|
19
|
+
*
|
|
20
|
+
* Pointer:
|
|
21
|
+
* Primary pointerdown (mouse button 0, touch, or pen, and a primary
|
|
22
|
+
* pointer) sets the transient press. It clears on pointerup,
|
|
23
|
+
* pointercancel, pointerleave, pointerout that leaves the host,
|
|
24
|
+
* pointermove whose target is outside the host, lostpointercapture,
|
|
25
|
+
* and blur of the host itself. Moving farther than the slop, or a
|
|
26
|
+
* scroll whose target is the host or an ancestor (including the
|
|
27
|
+
* document), cancels the press and drops a pending long-press.
|
|
28
|
+
* pointermove and touch scrolling are not preventDefault'd.
|
|
29
|
+
* touch-action stays in CSS.
|
|
30
|
+
*
|
|
31
|
+
* Keyboard:
|
|
32
|
+
* Enter or Space on the host itself sets the transient press while
|
|
33
|
+
* the key is held, including on a native button. Native buttons
|
|
34
|
+
* already match :active; the attribute is set too so the pressed
|
|
35
|
+
* ring matches a pointer press. Keyup clears it. Repeat keydowns
|
|
36
|
+
* do not restart the gesture. Enter is never preventDefault'd, so
|
|
37
|
+
* a native click still fires. Space is preventDefault'd only on a
|
|
38
|
+
* custom button-like host, so the page does not scroll. That host's
|
|
39
|
+
* first role token is button, switch, checkbox, radio, menuitem,
|
|
40
|
+
* menuitemcheckbox, menuitemradio, option, tab, or treeitem, and
|
|
41
|
+
* the host is not a native control that already owns Space (button,
|
|
42
|
+
* input, textarea, select, summary, or contenteditable). A pressable
|
|
43
|
+
* with no button-like role is left alone, and role="link" keeps the
|
|
44
|
+
* scroll. Long-press is pointer-only. The host has to be the event
|
|
45
|
+
* target. This runtime does not add tabindex or role.
|
|
46
|
+
*
|
|
47
|
+
* Long-press:
|
|
48
|
+
* Armed only when [pressable-longpress] enables it. After the delay,
|
|
49
|
+
* the host dispatches a bubbling, cancelable, composed
|
|
50
|
+
* `juice:longpress` CustomEvent. detail is
|
|
51
|
+
* `{ pressed: true, longPressed: true }`. If the event is not
|
|
52
|
+
* preventDefault'd, the click that follows that gesture is
|
|
53
|
+
* suppressed once (capture-phase preventDefault and
|
|
54
|
+
* stopPropagation). If the event is canceled, the click is left
|
|
55
|
+
* alone. A slop or scroll cancel before the timer fires does not
|
|
56
|
+
* long-press and does not suppress the click. If the long-press
|
|
57
|
+
* already fired, a later cancel still suppresses that one click.
|
|
58
|
+
* The suppress flag expires on that click or on the next turn, so
|
|
59
|
+
* a later click is not swallowed.
|
|
60
|
+
*
|
|
61
|
+
* Latched [pressed]:
|
|
62
|
+
* [icon-button][toggle] and any host with aria-pressed own [pressed]
|
|
63
|
+
* as a latched toggle. This runtime never sets or removes [pressed]
|
|
64
|
+
* on those hosts. The gesture is still getState().pressed and still
|
|
65
|
+
* dispatches juice:change. :active paints the ring. On every other
|
|
66
|
+
* host, [pressed] is set only when it was absent, and removed only
|
|
67
|
+
* when this runtime added it. An author [pressed] that was already
|
|
68
|
+
* there is left in place.
|
|
69
|
+
*
|
|
70
|
+
* Disabled:
|
|
71
|
+
* :disabled (the disabled property), [disabled], and
|
|
72
|
+
* [aria-disabled="true"] do not press and do not long-press. A host
|
|
73
|
+
* that becomes disabled during a press is cleared.
|
|
74
|
+
*
|
|
75
|
+
* State is { pressed, longPressed }. pressed is the transient gesture,
|
|
76
|
+
* not a latched attribute. longPressed is true only after
|
|
77
|
+
* juice:longpress has fired for the current gesture. Both return to
|
|
78
|
+
* false when the gesture ends. The first observation is recorded
|
|
79
|
+
* and does not dispatch. Later changes dispatch a bubbling
|
|
80
|
+
* juice:change CustomEvent with detail
|
|
81
|
+
* { runtime: "pressable", state }.
|
|
82
|
+
*
|
|
83
|
+
* Reduced motion stays in CSS. This runtime does not read
|
|
84
|
+
* prefers-reduced-motion and does not animate. No Sig Pressable
|
|
85
|
+
* factory. Pressable is the twenty-ninth Emerging auto-enhance
|
|
86
|
+
* runtime.
|
|
87
|
+
*/
|
|
88
|
+
export type PressableOptions = {
|
|
89
|
+
root?: ParentNode;
|
|
90
|
+
pressableSelector?: string;
|
|
91
|
+
longPressDelay?: number;
|
|
92
|
+
moveSlop?: number;
|
|
93
|
+
};
|
|
94
|
+
export type PressableState = {
|
|
95
|
+
pressed: boolean;
|
|
96
|
+
longPressed: boolean;
|
|
97
|
+
};
|
|
98
|
+
export type PressableController = {
|
|
99
|
+
destroy: () => void;
|
|
100
|
+
sync: () => void;
|
|
101
|
+
getState: (target?: HTMLElement | null) => PressableState | null;
|
|
102
|
+
};
|
|
103
|
+
export declare const createPressable: (options?: PressableOptions) => PressableController;
|
|
104
|
+
export declare const initPressable: (options?: PressableOptions) => PressableController;
|
|
105
|
+
export declare const startPressableRuntime: () => PressableController | null;
|
|
106
|
+
export declare const stopPressableRuntime: () => void;
|
|
@@ -29,4 +29,5 @@ export declare const createJuiceChanges: <TState>(runtime: string) => {
|
|
|
29
29
|
has: (host: EventTarget) => boolean;
|
|
30
30
|
prime: (host: EventTarget, state: TState) => void;
|
|
31
31
|
note: (host: EventTarget, state: TState, options?: JuiceChangeNoteOptions<TState>) => void;
|
|
32
|
+
adopt: (host: EventTarget, state: TState) => void;
|
|
32
33
|
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM-first runtime for Juice touchable-row chrome.
|
|
3
|
+
*
|
|
4
|
+
* Markup contract (Slice A — do not rename attrs):
|
|
5
|
+
* [touchable-row] host. Any value is still a row. Words
|
|
6
|
+
* compose, same as the CSS: dense,
|
|
7
|
+
* chevron, undivided, plus the two words
|
|
8
|
+
* this runtime owns.
|
|
9
|
+
* [touchable-row~="select"] opt-in. Activation toggles selection.
|
|
10
|
+
* Absent, the row does not toggle.
|
|
11
|
+
* getState().selected still reports the
|
|
12
|
+
* CSS selected state.
|
|
13
|
+
* [touchable-row~="activate"] explicit opt-in for keyboard chrome
|
|
14
|
+
* when the row is not [pressable] and
|
|
15
|
+
* not selectable. See below.
|
|
16
|
+
* [selected] selected signal, with aria-selected
|
|
17
|
+
* or aria-current. CSS paints the start
|
|
18
|
+
* bar from any of the three.
|
|
19
|
+
* [pressable] press feedback stays on Pressable.
|
|
20
|
+
* This runtime does not set [pressed].
|
|
21
|
+
*
|
|
22
|
+
* Why those words, and not [touchable-row-select]: dense, chevron,
|
|
23
|
+
* and undivided already compose on the host attribute. Selection and
|
|
24
|
+
* the keyboard opt-in are host behavior, not slots.
|
|
25
|
+
* [touchable-row-leading], [touchable-row-content], [touchable-row-title],
|
|
26
|
+
* [touchable-row-subtitle], and [touchable-row-trailing] are the parts.
|
|
27
|
+
* A [touchable-row-select] attribute would read as another part.
|
|
28
|
+
*
|
|
29
|
+
* Keyboard activation:
|
|
30
|
+
* Enter or Space on a non-native host (not `a` or `button`) dispatches
|
|
31
|
+
* one bubbling click. Repeat keydowns do not. Enter is never
|
|
32
|
+
* preventDefault'd. Space is preventDefault'd only on those
|
|
33
|
+
* non-native hosts, so the page does not scroll (the same reason as
|
|
34
|
+
* the Pressable Space fix, applied to every li/div row rather than
|
|
35
|
+
* only to a button-like role). Native `a` and `button` already
|
|
36
|
+
* activate from the platform — Enter on a link, Enter and Space on
|
|
37
|
+
* a button — and this runtime does not dispatch a second click and
|
|
38
|
+
* does not preventDefault Space on them. An `<a>` without href is
|
|
39
|
+
* still native: give it an href, or use a div with select / activate
|
|
40
|
+
* / pressable. An editing host is left alone so Space can type.
|
|
41
|
+
* A [menuitem] host (the attribute, or a menuitem role) is left
|
|
42
|
+
* alone on the key. The menu runtime owns Enter and Space and clicks
|
|
43
|
+
* the item once. This runtime still sees that click.
|
|
44
|
+
*
|
|
45
|
+
* Keys and clicks that start in an interactive descendant do not
|
|
46
|
+
* activate the row, so a trailing control works on its own. The
|
|
47
|
+
* descendant is a button, a, input, textarea, select, summary,
|
|
48
|
+
* [switch], [icon-button], [menuitem], an editing host, or an
|
|
49
|
+
* element whose first role token is button, switch, checkbox, radio,
|
|
50
|
+
* link, menuitem, menuitemcheckbox, menuitemradio, option, tab,
|
|
51
|
+
* textbox, searchbox, combobox, slider, or spinbutton.
|
|
52
|
+
*
|
|
53
|
+
* Role and tabindex:
|
|
54
|
+
* A plain row is a layout shell. Sync does not give it a role or a
|
|
55
|
+
* tabindex, or it would enter the tab order just by being drawn.
|
|
56
|
+
* Chrome is added only when the row is interactive, the author has
|
|
57
|
+
* not set that attribute, the host is not native, and the host is
|
|
58
|
+
* not a menuitem:
|
|
59
|
+
* [pressable] the row is a press target
|
|
60
|
+
* [touchable-row~="select"] the row toggles selection
|
|
61
|
+
* [touchable-row~="activate"] explicit opt-in
|
|
62
|
+
* The added role is "button" and the added tabindex is "0". An
|
|
63
|
+
* author role or tabindex is kept, including role="link". Native
|
|
64
|
+
* links and buttons already have a platform role and tab stop.
|
|
65
|
+
* Menuitems keep the role the menu runtime writes. A disabled row
|
|
66
|
+
* is not given a tab stop it did not already have. Destroy does
|
|
67
|
+
* not remove a role or tabindex this runtime added.
|
|
68
|
+
*
|
|
69
|
+
* Selection:
|
|
70
|
+
* Independent toggles. There is no single-select group. List has
|
|
71
|
+
* no runtime, and its [selected] wash is author state. Tabs are a
|
|
72
|
+
* different widget (panels and a roving tabindex). Radio groups use
|
|
73
|
+
* the native name on inputs. This row has no container. Activating
|
|
74
|
+
* one selectable row does not clear its siblings.
|
|
75
|
+
* Activation is the click, including the click this runtime
|
|
76
|
+
* dispatches for a non-native host. The written signal is [selected]
|
|
77
|
+
* plus aria-selected on a host that is not a link, or aria-current
|
|
78
|
+
* on `a` and role="link". CSS treats aria-current other than "false"
|
|
79
|
+
* as selected, which is the link-shaped signal. Turning a row off
|
|
80
|
+
* clears [selected] and writes the chosen aria attribute to "false",
|
|
81
|
+
* and clears the other aria signal when that signal is still
|
|
82
|
+
* selected, so one toggle fully unselects the row. Rows without
|
|
83
|
+
* [touchable-row~="select"] do not toggle.
|
|
84
|
+
*
|
|
85
|
+
* Long-press:
|
|
86
|
+
* Not implemented here. A row with [pressable][pressable-longpress]
|
|
87
|
+
* uses Pressable's juice:longpress. Pressable suppresses the click
|
|
88
|
+
* that follows a long-press on the capture phase (preventDefault
|
|
89
|
+
* and stopPropagation) unless that event was canceled. Selection
|
|
90
|
+
* listens for click on the bubble phase, so the suppressed click
|
|
91
|
+
* never toggles. A later click does.
|
|
92
|
+
*
|
|
93
|
+
* Disabled:
|
|
94
|
+
* :disabled (the disabled property), [disabled], and
|
|
95
|
+
* [aria-disabled="true"] are ignored entirely. No click is
|
|
96
|
+
* synthesized, selection does not change, and the attempt does not
|
|
97
|
+
* dispatch juice:change.
|
|
98
|
+
*
|
|
99
|
+
* State is { selected, disabled }. selected is the CSS selected
|
|
100
|
+
* state, not the select word. The first observation is recorded and
|
|
101
|
+
* does not dispatch. Later changes dispatch a bubbling juice:change
|
|
102
|
+
* CustomEvent with detail { runtime: "touchable-row", state }.
|
|
103
|
+
*
|
|
104
|
+
* No Sig TouchableRow factory. Touchable-row is the thirtieth
|
|
105
|
+
* Emerging auto-enhance runtime.
|
|
106
|
+
*/
|
|
107
|
+
export type TouchableRowOptions = {
|
|
108
|
+
root?: ParentNode;
|
|
109
|
+
touchableRowSelector?: string;
|
|
110
|
+
};
|
|
111
|
+
export type TouchableRowState = {
|
|
112
|
+
selected: boolean;
|
|
113
|
+
disabled: boolean;
|
|
114
|
+
};
|
|
115
|
+
export type TouchableRowController = {
|
|
116
|
+
destroy: () => void;
|
|
117
|
+
sync: () => void;
|
|
118
|
+
getState: (target?: HTMLElement | null) => TouchableRowState | null;
|
|
119
|
+
};
|
|
120
|
+
export declare const createTouchableRow: (options?: TouchableRowOptions) => TouchableRowController;
|
|
121
|
+
export declare const initTouchableRow: (options?: TouchableRowOptions) => TouchableRowController;
|
|
122
|
+
export declare const startTouchableRowRuntime: () => TouchableRowController | null;
|
|
123
|
+
export declare const stopTouchableRowRuntime: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citrusworx/juiceui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
"access": "public"
|
|
175
175
|
},
|
|
176
176
|
"dependencies": {
|
|
177
|
-
"@citrusworx/sigjs": "^0.
|
|
177
|
+
"@citrusworx/sigjs": "^1.0.0"
|
|
178
178
|
},
|
|
179
179
|
"devDependencies": {
|
|
180
180
|
"@testing-library/jest-dom": "^6.9.1",
|