@alulore/kumiko 0.20.2 → 0.21.1
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/dist/avatar/avatar.js +1 -1
- package/dist/badge/badge.css +41 -3
- package/dist/badge/badge.js +11 -4
- package/dist/button/button.css +21 -7
- package/dist/card/card.css +3 -2
- package/dist/card/item-card.d.ts +1 -1
- package/dist/card/item-card.js +3 -2
- package/dist/chip/chip.css +6 -10
- package/dist/chip/chip.js +1 -1
- package/dist/form/error-line.js +4 -3
- package/dist/input/input.css +99 -114
- package/dist/list-row/list-row-motion.js +29 -10
- package/dist/media-viewer/gesture-press.d.ts +1 -0
- package/dist/media-viewer/gesture-press.js +12 -0
- package/dist/media-viewer/media-slide.d.ts +3 -1
- package/dist/media-viewer/media-slide.js +3 -2
- package/dist/media-viewer/media-viewer.css +5 -1
- package/dist/media-viewer/media-viewer.js +41 -23
- package/dist/media-viewer/stage-rect.d.ts +16 -0
- package/dist/media-viewer/stage-rect.js +56 -0
- package/dist/media-viewer/view-gesture.d.ts +1 -2
- package/dist/media-viewer/view-gesture.js +39 -44
- package/dist/media-viewer/viewer-chrome.d.ts +2 -1
- package/dist/media-viewer/viewer-chrome.js +3 -1
- package/dist/media-viewer/viewer-motion.d.ts +1 -0
- package/dist/media-viewer/viewer-motion.js +20 -7
- package/dist/media-viewer/zoom-pan.d.ts +1 -0
- package/dist/media-viewer/zoom-pan.js +3 -0
- package/dist/media-viewer/zoom-store.d.ts +8 -0
- package/dist/media-viewer/zoom-store.js +30 -0
- package/dist/menu/menu.js +6 -3
- package/dist/menu/point-menu.js +32 -12
- package/dist/page/page-actions.js +2 -1
- package/dist/page/page-breadcrumbs.js +2 -1
- package/dist/page/use-measured-fit.d.ts +5 -0
- package/dist/page/use-measured-fit.js +47 -5
- package/dist/page/use-stuck.js +12 -2
- package/dist/pagination/pagination-fit.d.ts +3 -1
- package/dist/pagination/pagination-fit.js +4 -3
- package/dist/pagination/pagination-motion.js +18 -11
- package/dist/pagination/pagination.css +50 -6
- package/dist/pagination/pagination.js +20 -3
- package/dist/progress/progress.css +3 -2
- package/dist/progress/progress.js +15 -3
- package/dist/select/select-labels.d.ts +2 -0
- package/dist/select/select-labels.js +5 -1
- package/dist/select/select.css +7 -11
- package/dist/select/select.d.ts +1 -1
- package/dist/select/select.js +12 -6
- package/dist/shortcuts/hints.js +10 -4
- package/dist/shortcuts/provider.d.ts +4 -2
- package/dist/shortcuts/provider.js +14 -17
- package/dist/skeleton/skeleton.css +22 -9
- package/dist/slider/slider-feel.js +18 -6
- package/dist/slider/slider.css +9 -10
- package/dist/slider/slider.js +13 -10
- package/dist/smooth-caret/caret-controller.js +37 -11
- package/dist/smooth-caret/caret-geometry.js +18 -7
- package/dist/smooth-caret/caret-glide.js +3 -2
- package/dist/smooth-caret/remote-carets.js +20 -3
- package/dist/smooth-caret/smooth-caret.css +4 -2
- package/dist/smooth-caret/top-layer.d.ts +2 -0
- package/dist/smooth-caret/top-layer.js +6 -0
- package/dist/switch/switch-gesture.d.ts +4 -4
- package/dist/switch/switch-gesture.js +52 -14
- package/dist/switch/switch.css +12 -13
- package/dist/switch/switch.d.ts +2 -1
- package/dist/switch/switch.js +4 -6
- package/dist/table/data-table.js +32 -12
- package/dist/table/table-cells.d.ts +20 -8
- package/dist/table/table-cells.js +18 -20
- package/dist/table/table-model.d.ts +0 -2
- package/dist/table/table-model.js +15 -9
- package/dist/table/table-search.d.ts +12 -0
- package/dist/table/table-search.js +34 -0
- package/dist/table/table-sections.d.ts +3 -2
- package/dist/table/table-sections.js +16 -13
- package/dist/table/table.css +2 -14
- package/dist/table/use-latest.d.ts +6 -0
- package/dist/table/use-latest.js +22 -0
- package/dist/table/use-table-view.js +36 -24
- package/package.json +1 -1
package/dist/shortcuts/hints.js
CHANGED
|
@@ -3,13 +3,18 @@ import { ariaKeyshortcuts } from "@ui-sdk/react/shortcuts";
|
|
|
3
3
|
import { cloneElement } from "react";
|
|
4
4
|
import { Kbd } from "../kbd";
|
|
5
5
|
import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip";
|
|
6
|
-
import { useShortcuts } from "./provider";
|
|
6
|
+
import { useModHeldValue, useShortcuts } from "./provider";
|
|
7
|
+
/** The badge of a hint, the one part of it that follows the mod key. */
|
|
8
|
+
function HintBadge({ keys }) {
|
|
9
|
+
const [modHeld] = useModHeldValue();
|
|
10
|
+
return (_jsx(Kbd, { keys: keys, listen: false, className: "kumiko-shortcuts-badge", "data-shown": modHeld ? "" : undefined, "aria-hidden": "true" }));
|
|
11
|
+
}
|
|
7
12
|
/**
|
|
8
13
|
* Shows an action's current keys on the control that runs it, the way the provider's `hints` says:
|
|
9
14
|
* a tooltip, a badge while the mod key is held, or nothing.
|
|
10
15
|
*/
|
|
11
16
|
export function ShortcutHint({ action, label, children }) {
|
|
12
|
-
const { keysFor, options
|
|
17
|
+
const { keysFor, options } = useShortcuts();
|
|
13
18
|
const keys = keysFor(action);
|
|
14
19
|
const first = keys[0];
|
|
15
20
|
const control = cloneElement(children, {
|
|
@@ -19,13 +24,14 @@ export function ShortcutHint({ action, label, children }) {
|
|
|
19
24
|
return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: control }), _jsxs(TooltipContent, { children: [label, first ? (_jsxs(_Fragment, { children: [" ", _jsx(Kbd, { keys: first, listen: false, look: "flat" })] })) : null] })] }));
|
|
20
25
|
}
|
|
21
26
|
if (options.hints === "badges") {
|
|
22
|
-
return (_jsxs("span", { className: "kumiko-shortcuts-target", children: [control, first ?
|
|
27
|
+
return (_jsxs("span", { className: "kumiko-shortcuts-target", children: [control, first ? _jsx(HintBadge, { keys: first }) : null] }));
|
|
23
28
|
}
|
|
24
29
|
return control;
|
|
25
30
|
}
|
|
26
31
|
/** A button that shows the key badges on a touch screen, where there is no mod key to hold. Renders only when `hints` is "badges". */
|
|
27
32
|
export function ShortcutBadgesButton({ className, children = "Show key badges" }) {
|
|
28
|
-
const { options
|
|
33
|
+
const { options } = useShortcuts();
|
|
34
|
+
const [modHeld, setModHeld] = useModHeldValue();
|
|
29
35
|
if (options.hints !== "badges") {
|
|
30
36
|
return null;
|
|
31
37
|
}
|
|
@@ -85,14 +85,15 @@ export interface ShortcutsContextValue {
|
|
|
85
85
|
available: ReadonlySet<string>;
|
|
86
86
|
/** Whether the last attempt to save the changed keys failed. */
|
|
87
87
|
saveFailed: boolean;
|
|
88
|
-
modHeld: boolean;
|
|
89
|
-
setModHeld: (held: boolean) => void;
|
|
90
88
|
/**
|
|
91
89
|
* Binds code to a declared action. The binding last mounted for an id wins, and the one before it takes
|
|
92
90
|
* over again when that one goes. Returns the way to remove it.
|
|
93
91
|
*/
|
|
94
92
|
bind: (id: string, binding: React.RefObject<BoundShortcutAction>) => () => void;
|
|
95
93
|
}
|
|
94
|
+
type ModHeldValue = readonly [held: boolean, setHeld: (held: boolean) => void];
|
|
95
|
+
/** Whether the mod key is held, and a way to set it. Only the parts that show the badges read it, so a key press renders no one else. */
|
|
96
|
+
export declare function useModHeldValue(): ModHeldValue;
|
|
96
97
|
export declare function useShortcuts(): ShortcutsContextValue;
|
|
97
98
|
/** The shortcuts of the nearest provider, or nothing when there is none. */
|
|
98
99
|
export declare function useOptionalShortcuts(): ShortcutsContextValue | null;
|
|
@@ -103,3 +104,4 @@ export type ShortcutsProviderProps = ShortcutsOptions & {
|
|
|
103
104
|
};
|
|
104
105
|
/** Wraps the part of the app that has shortcuts: registers every action and holds what the help sheet and hints need. */
|
|
105
106
|
export declare function ShortcutsProvider(props: ShortcutsProviderProps): React.JSX.Element;
|
|
107
|
+
export {};
|
|
@@ -5,6 +5,17 @@ import { isOverrides, keysOf, sanitizeOverrides, withoutActions } from "./bindin
|
|
|
5
5
|
import { defaultReservedKeys } from "./keys";
|
|
6
6
|
import { listAvailable, useModHeld, useRegistration } from "./registration";
|
|
7
7
|
const ShortcutsContext = createContext(null);
|
|
8
|
+
const ModHeldContext = createContext([false, () => { }]);
|
|
9
|
+
/** Whether the mod key is held, and a way to set it. Only the parts that show the badges read it, so a key press renders no one else. */
|
|
10
|
+
export function useModHeldValue() {
|
|
11
|
+
return use(ModHeldContext);
|
|
12
|
+
}
|
|
13
|
+
/** Holds the mod key state apart from the shortcuts' own context, so holding the key renders only its readers. */
|
|
14
|
+
function ModHeldScope({ enabled, children }) {
|
|
15
|
+
const [held, setHeld] = useModHeld(enabled);
|
|
16
|
+
const value = useMemo(() => [held, setHeld], [held, setHeld]);
|
|
17
|
+
return _jsx(ModHeldContext, { value: value, children: children });
|
|
18
|
+
}
|
|
8
19
|
export function useShortcuts() {
|
|
9
20
|
const value = use(ShortcutsContext);
|
|
10
21
|
if (!value) {
|
|
@@ -116,7 +127,6 @@ export function ShortcutsProvider(props) {
|
|
|
116
127
|
const { bind, binding } = useBindings();
|
|
117
128
|
const live = useRef({ ...options, actions, overrides, toggleHelp: () => { }, binding });
|
|
118
129
|
const help = useHelpState(live);
|
|
119
|
-
const [modHeld, setModHeld] = useModHeld(options.hints === "badges");
|
|
120
130
|
useRegistered(live, { options, actions, overrides, binding, help });
|
|
121
131
|
const value = useMemo(() => ({
|
|
122
132
|
...help,
|
|
@@ -133,20 +143,7 @@ export function ShortcutsProvider(props) {
|
|
|
133
143
|
setOverrides,
|
|
134
144
|
resetAll: () => setOverrides(withoutActions(overrides, actions)),
|
|
135
145
|
bind,
|
|
136
|
-
saveFailed
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}), [
|
|
140
|
-
help,
|
|
141
|
-
actions,
|
|
142
|
-
notes,
|
|
143
|
-
overrides,
|
|
144
|
-
options,
|
|
145
|
-
setOverrides,
|
|
146
|
-
saveFailed,
|
|
147
|
-
modHeld,
|
|
148
|
-
setModHeld,
|
|
149
|
-
bind
|
|
150
|
-
]);
|
|
151
|
-
return _jsx(ShortcutsContext, { value: value, children: children });
|
|
146
|
+
saveFailed
|
|
147
|
+
}), [help, actions, notes, overrides, options, setOverrides, saveFailed, bind]);
|
|
148
|
+
return (_jsx(ShortcutsContext, { value: value, children: _jsx(ModHeldScope, { enabled: options.hints === "badges", children: children }) }));
|
|
152
149
|
}
|
|
@@ -26,29 +26,41 @@
|
|
|
26
26
|
block-size: var(--kumiko-skeleton-size);
|
|
27
27
|
border-radius: var(--kumiko-skeleton-radius);
|
|
28
28
|
background-color: var(--kumiko-skeleton-bg);
|
|
29
|
+
position: relative;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* The band lives on its own layer, three times as wide as the block, that slides by translate so no frame repaints. */
|
|
34
|
+
:where([data-slot="skeleton"])::after {
|
|
35
|
+
content: "";
|
|
36
|
+
display: var(--_skeleton-shine-display, block);
|
|
37
|
+
position: absolute;
|
|
38
|
+
top: 0;
|
|
39
|
+
left: 0;
|
|
40
|
+
width: 300%;
|
|
41
|
+
height: 100%;
|
|
29
42
|
background-image: linear-gradient(
|
|
30
43
|
90deg,
|
|
31
44
|
transparent calc(50% - var(--kumiko-skeleton-band) / 2),
|
|
32
45
|
var(--kumiko-skeleton-shine) 50%,
|
|
33
46
|
transparent calc(50% + var(--kumiko-skeleton-band) / 2)
|
|
34
47
|
);
|
|
35
|
-
|
|
36
|
-
background-size: 300% 100%;
|
|
48
|
+
pointer-events: none;
|
|
37
49
|
animation: kumiko-skeleton-sweep var(--_skeleton-sweep) ease-in-out infinite;
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
@keyframes kumiko-skeleton-sweep {
|
|
41
53
|
from {
|
|
42
|
-
|
|
54
|
+
translate: -66.667% 0;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
to {
|
|
46
|
-
|
|
58
|
+
translate: 0 0;
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
/* In right-to-left text the band sweeps the other way, from the start of the line. */
|
|
51
|
-
:where([data-slot="skeleton"]:dir(rtl)) {
|
|
63
|
+
:where([data-slot="skeleton"]:dir(rtl))::after {
|
|
52
64
|
animation-direction: reverse;
|
|
53
65
|
}
|
|
54
66
|
|
|
@@ -79,7 +91,7 @@
|
|
|
79
91
|
:not([data-animation]):is([data-kumiko-skeleton~="pulse"] *)
|
|
80
92
|
)
|
|
81
93
|
) {
|
|
82
|
-
|
|
94
|
+
--_skeleton-shine-display: none;
|
|
83
95
|
animation: kumiko-skeleton-pulse var(--_skeleton-pulse) ease-in-out infinite;
|
|
84
96
|
}
|
|
85
97
|
|
|
@@ -95,7 +107,7 @@
|
|
|
95
107
|
:not([data-animation]):is([data-kumiko-skeleton~="still"] *)
|
|
96
108
|
)
|
|
97
109
|
) {
|
|
98
|
-
|
|
110
|
+
--_skeleton-shine-display: none;
|
|
99
111
|
animation: none;
|
|
100
112
|
}
|
|
101
113
|
|
|
@@ -106,7 +118,7 @@
|
|
|
106
118
|
:not([data-animation]):is([data-kumiko-skeleton~="still"] *)
|
|
107
119
|
)
|
|
108
120
|
) {
|
|
109
|
-
|
|
121
|
+
--_skeleton-shine-display: none;
|
|
110
122
|
animation: kumiko-skeleton-pulse calc(var(--_skeleton-pulse) * 1.5) ease-in-out infinite;
|
|
111
123
|
}
|
|
112
124
|
}
|
|
@@ -117,7 +129,7 @@
|
|
|
117
129
|
:not([data-animation]):is([data-kumiko-skeleton~="still"] *)
|
|
118
130
|
)
|
|
119
131
|
) {
|
|
120
|
-
|
|
132
|
+
--_skeleton-shine-display: none;
|
|
121
133
|
animation: kumiko-skeleton-pulse calc(var(--_skeleton-pulse) * 1.5) ease-in-out infinite;
|
|
122
134
|
}
|
|
123
135
|
|
|
@@ -136,6 +148,7 @@
|
|
|
136
148
|
|
|
137
149
|
@media (forced-colors: active) {
|
|
138
150
|
:where([data-slot="skeleton"]) {
|
|
151
|
+
--_skeleton-shine-display: none;
|
|
139
152
|
background: GrayText;
|
|
140
153
|
forced-color-adjust: none;
|
|
141
154
|
}
|
|
@@ -66,10 +66,12 @@ function useBubbleHold() {
|
|
|
66
66
|
};
|
|
67
67
|
return { shown, delay, hold, holdAgain };
|
|
68
68
|
}
|
|
69
|
-
/** Reads the bubble delay, and gives the thumb an event happened in unless the slider is locked. */
|
|
70
|
-
function thumbFor(event, delay) {
|
|
69
|
+
/** Reads the bubble delay once for each press or held key (`reads` is false while a key is already held), and gives the thumb an event happened in unless the slider is locked. */
|
|
70
|
+
function thumbFor(event, delay, reads = true) {
|
|
71
71
|
const index = thumbIn(event.target);
|
|
72
|
-
|
|
72
|
+
if (reads) {
|
|
73
|
+
delay.current = bubbleDelay(event.currentTarget);
|
|
74
|
+
}
|
|
73
75
|
return index !== null && !isLocked(event.currentTarget) ? index : null;
|
|
74
76
|
}
|
|
75
77
|
/** Whether the last thing done to the slider was a pointer press, and whether that press was a finger. */
|
|
@@ -77,6 +79,7 @@ function usePressKind() {
|
|
|
77
79
|
const [pointer, setPointer] = useState(false);
|
|
78
80
|
const [touch, setTouch] = useState(false);
|
|
79
81
|
const pressing = useRef(false);
|
|
82
|
+
const held = useRef(false);
|
|
80
83
|
return {
|
|
81
84
|
pointer,
|
|
82
85
|
touch,
|
|
@@ -88,7 +91,15 @@ function usePressKind() {
|
|
|
88
91
|
up: () => {
|
|
89
92
|
pressing.current = false;
|
|
90
93
|
},
|
|
91
|
-
key: () =>
|
|
94
|
+
key: () => {
|
|
95
|
+
setPointer(false);
|
|
96
|
+
const again = held.current;
|
|
97
|
+
held.current = true;
|
|
98
|
+
return again;
|
|
99
|
+
},
|
|
100
|
+
keyEnd: () => {
|
|
101
|
+
held.current = false;
|
|
102
|
+
},
|
|
92
103
|
left: (event) => {
|
|
93
104
|
if (!pressing.current && !event.currentTarget.contains(event.relatedTarget)) {
|
|
94
105
|
setPointer(false);
|
|
@@ -108,6 +119,7 @@ export function useSliderFeel() {
|
|
|
108
119
|
const kind = usePressKind();
|
|
109
120
|
const { shown, delay, hold, holdAgain } = useBubbleHold();
|
|
110
121
|
const keyUp = () => {
|
|
122
|
+
kind.keyEnd();
|
|
111
123
|
setKeyed(null);
|
|
112
124
|
setFollow(false);
|
|
113
125
|
holdAgain();
|
|
@@ -137,8 +149,8 @@ export function useSliderFeel() {
|
|
|
137
149
|
holdAgain();
|
|
138
150
|
},
|
|
139
151
|
keyDown: (event) => {
|
|
140
|
-
kind.key();
|
|
141
|
-
const index = thumbFor(event, delay);
|
|
152
|
+
const again = kind.key();
|
|
153
|
+
const index = thumbFor(event, delay, !again);
|
|
142
154
|
if (adjusting.has(event.key) && index !== null) {
|
|
143
155
|
setKeyed(index);
|
|
144
156
|
hold(index);
|
package/dist/slider/slider.css
CHANGED
|
@@ -171,11 +171,11 @@
|
|
|
171
171
|
transition: none;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
[data-slot="slider-thumb
|
|
175
|
-
|
|
174
|
+
[data-slot="slider-thumb"]::before {
|
|
175
|
+
content: "";
|
|
176
|
+
position: absolute;
|
|
177
|
+
inset: 0;
|
|
176
178
|
box-sizing: border-box;
|
|
177
|
-
inline-size: 100%;
|
|
178
|
-
block-size: 100%;
|
|
179
179
|
border: var(--kumiko-slider-thumb-border-width) solid var(--kumiko-slider-thumb-border);
|
|
180
180
|
border-radius: 999px;
|
|
181
181
|
background: var(--kumiko-slider-thumb-bg);
|
|
@@ -195,14 +195,13 @@
|
|
|
195
195
|
--_slider-ring: 2px solid var(--kumiko-slider-focus-ring);
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
[data-slot="slider-thumb"][data-dragging]
|
|
198
|
+
[data-slot="slider-thumb"][data-dragging]::before {
|
|
199
199
|
scale: var(--kumiko-squash-x) var(--kumiko-squash-y);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
@media (hover: hover) and (pointer: fine) {
|
|
203
203
|
[data-slot="slider"]:not([data-disabled], [data-readonly])
|
|
204
|
-
[data-slot="slider-thumb"]:hover:not([data-dragging])
|
|
205
|
-
[data-slot="slider-thumb-face"] {
|
|
204
|
+
[data-slot="slider-thumb"]:hover:not([data-dragging])::before {
|
|
206
205
|
scale: var(--kumiko-hover-scale);
|
|
207
206
|
}
|
|
208
207
|
}
|
|
@@ -237,7 +236,7 @@
|
|
|
237
236
|
cursor: not-allowed;
|
|
238
237
|
}
|
|
239
238
|
|
|
240
|
-
[data-slot="slider"][data-readonly] [data-slot="slider-thumb
|
|
239
|
+
[data-slot="slider"][data-readonly] [data-slot="slider-thumb"]::before {
|
|
241
240
|
border-color: var(--kumiko-slider-readonly-thumb-bg);
|
|
242
241
|
background: var(--kumiko-slider-readonly-thumb-bg);
|
|
243
242
|
}
|
|
@@ -313,12 +312,12 @@
|
|
|
313
312
|
box-shadow: none;
|
|
314
313
|
}
|
|
315
314
|
|
|
316
|
-
[data-slot="slider-thumb
|
|
315
|
+
[data-slot="slider-thumb"]::before {
|
|
317
316
|
border-color: ButtonText;
|
|
318
317
|
background: Canvas;
|
|
319
318
|
}
|
|
320
319
|
|
|
321
|
-
[data-slot="slider"][data-readonly] [data-slot="slider-thumb
|
|
320
|
+
[data-slot="slider"][data-readonly] [data-slot="slider-thumb"]::before {
|
|
322
321
|
border-color: GrayText;
|
|
323
322
|
background: GrayText;
|
|
324
323
|
}
|
package/dist/slider/slider.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { pageLocale } from "@ui-sdk/core";
|
|
3
3
|
import { Slider as SdkSlider, SliderControl, SliderIndicator, SliderThumb, SliderTrack, SliderValue } from "@ui-sdk/react/slider";
|
|
4
|
-
import { useState } from "react";
|
|
4
|
+
import { useCallback, useMemo, useState } from "react";
|
|
5
5
|
import { alongside, useSliderFeel } from "./slider-feel";
|
|
6
6
|
import { formatThumb } from "./slider-format";
|
|
7
7
|
import { isPassed, marksFor } from "./slider-marks";
|
|
@@ -13,26 +13,29 @@ function looks(on) {
|
|
|
13
13
|
/** The value bubble, which reads the page's locale once it is mounted, the way ui-sdk does for the thumb's own text. */
|
|
14
14
|
function Bubble({ value, formatting }) {
|
|
15
15
|
const [page, setPage] = useState(undefined);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const read = useCallback((element) => {
|
|
17
|
+
if (element) {
|
|
18
|
+
setPage(pageLocale(element));
|
|
19
|
+
}
|
|
20
|
+
}, []);
|
|
21
|
+
return (_jsx("span", { "data-slot": "slider-bubble", "aria-hidden": "true", ref: read, children: formatThumb(value, { ...formatting, pageLocale: page }) }));
|
|
22
22
|
}
|
|
23
23
|
function Thumbs({ count, labels, bubble, keyed, shown, formatting }) {
|
|
24
|
-
return (_jsx(_Fragment, { children: Array.from({ length: count }, (_, index) => (_jsx(SliderThumb, { index: index, "aria-label": Array.isArray(labels) ? labels[index] : labels, "data-adjusting": keyed === index ? "" : undefined, "data-revealed": shown === index ? "" : undefined, children: (state) =>
|
|
24
|
+
return (_jsx(_Fragment, { children: Array.from({ length: count }, (_, index) => (_jsx(SliderThumb, { index: index, "aria-label": Array.isArray(labels) ? labels[index] : labels, "data-adjusting": keyed === index ? "" : undefined, "data-revealed": shown === index ? "" : undefined, children: (state) => bubble ? _jsx(Bubble, { value: state.thumbValue, formatting: formatting }) : null }, index))) }));
|
|
25
25
|
}
|
|
26
26
|
function markStyle(percent) {
|
|
27
27
|
return { "--kumiko-slider-mark-at": `${percent}%` };
|
|
28
28
|
}
|
|
29
29
|
/** A mark at each step, each told whether the fill has passed it. Nothing above 20 steps. */
|
|
30
30
|
function Marks({ min, max, step, values }) {
|
|
31
|
-
const marks = marksFor(min, max, step)
|
|
31
|
+
const marks = useMemo(() => marksFor(min, max, step).map((mark) => ({
|
|
32
|
+
...mark,
|
|
33
|
+
style: markStyle(mark.percent)
|
|
34
|
+
})), [min, max, step]);
|
|
32
35
|
if (marks.length === 0) {
|
|
33
36
|
return null;
|
|
34
37
|
}
|
|
35
|
-
return (_jsx("span", { "data-slot": "slider-marks", "aria-hidden": "true", children: marks.map((mark) => (_jsx("span", { "data-slot": "slider-mark", "data-passed": isPassed(mark.value, values) ? "" : undefined, style:
|
|
38
|
+
return (_jsx("span", { "data-slot": "slider-marks", "aria-hidden": "true", children: marks.map((mark) => (_jsx("span", { "data-slot": "slider-mark", "data-passed": isPassed(mark.value, values) ? "" : undefined, style: mark.style }, mark.value))) }));
|
|
36
39
|
}
|
|
37
40
|
/** The control with the track, its fill, the marks and the thumbs. */
|
|
38
41
|
function Rail({ marks, thumbs }) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { disposeMirror, findField, measureCaret } from "./caret-geometry";
|
|
2
2
|
import { createGlider, prefersReducedMotion } from "./caret-glide";
|
|
3
|
-
import { canJoinTopLayer, isRaised, raiseToTop, topLayerAncestor } from "./top-layer";
|
|
3
|
+
import { canJoinTopLayer, isRaised, lowerFromTop, raiseToTop, topLayerAncestor } from "./top-layer";
|
|
4
4
|
const GLIDE_LIMIT = 400;
|
|
5
5
|
const IDLE_MS = 500;
|
|
6
6
|
const STILL_FRAMES = 12;
|
|
@@ -52,6 +52,8 @@ class CaretController {
|
|
|
52
52
|
watchFrame = 0;
|
|
53
53
|
watchTimer = 0;
|
|
54
54
|
stillFrames = 0;
|
|
55
|
+
writtenHeight = "";
|
|
56
|
+
writtenColour = "";
|
|
55
57
|
fieldBox = "";
|
|
56
58
|
raisedField = null;
|
|
57
59
|
raisedLayer = null;
|
|
@@ -64,7 +66,11 @@ class CaretController {
|
|
|
64
66
|
this.bar = bar;
|
|
65
67
|
this.glider = createGlider((x, y, height) => {
|
|
66
68
|
caret.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
67
|
-
|
|
69
|
+
const written = `${height}px`;
|
|
70
|
+
if (written !== this.writtenHeight) {
|
|
71
|
+
this.writtenHeight = written;
|
|
72
|
+
caret.style.height = written;
|
|
73
|
+
}
|
|
68
74
|
});
|
|
69
75
|
}
|
|
70
76
|
start() {
|
|
@@ -101,6 +107,7 @@ class CaretController {
|
|
|
101
107
|
this.glider.stop();
|
|
102
108
|
this.resizeObserver.disconnect();
|
|
103
109
|
delete this.tracked?.dataset.smoothCaret;
|
|
110
|
+
this.hide();
|
|
104
111
|
disposeMirror();
|
|
105
112
|
}
|
|
106
113
|
setTracked(field) {
|
|
@@ -149,8 +156,8 @@ class CaretController {
|
|
|
149
156
|
if (this.watchTimer) {
|
|
150
157
|
window.clearTimeout(this.watchTimer);
|
|
151
158
|
this.watchTimer = 0;
|
|
152
|
-
this.watchField();
|
|
153
159
|
}
|
|
160
|
+
this.watchField();
|
|
154
161
|
}
|
|
155
162
|
followField() {
|
|
156
163
|
const { tracked } = this;
|
|
@@ -168,13 +175,26 @@ class CaretController {
|
|
|
168
175
|
hide() {
|
|
169
176
|
this.visible = false;
|
|
170
177
|
delete this.caret.dataset.visible;
|
|
178
|
+
this.lower();
|
|
171
179
|
}
|
|
172
|
-
|
|
180
|
+
lower() {
|
|
181
|
+
lowerFromTop(this.caret);
|
|
182
|
+
this.raisedField = null;
|
|
183
|
+
this.raisedLayer = null;
|
|
184
|
+
}
|
|
185
|
+
/*
|
|
186
|
+
* Paints the caret above the top-layer element that holds the field, once per field and per holder. A
|
|
187
|
+
* field in the page leaves the caret a page element, under any popover like the native caret: Electron
|
|
188
|
+
* drops every window drag region while any popover is open, so a caret left in the top layer would stop
|
|
189
|
+
* the titlebar moving the window.
|
|
190
|
+
*/
|
|
173
191
|
raise(field) {
|
|
174
192
|
const layer = topLayerAncestor(field);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
193
|
+
if (layer === null) {
|
|
194
|
+
this.lower();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const settled = isRaised(this.caret) && layer === this.raisedLayer && field === this.raisedField;
|
|
178
198
|
if (!settled) {
|
|
179
199
|
raiseToTop(this.caret);
|
|
180
200
|
this.raisedField = field;
|
|
@@ -186,16 +206,22 @@ class CaretController {
|
|
|
186
206
|
!this.visible ||
|
|
187
207
|
!this.last ||
|
|
188
208
|
Math.hypot(rect.x - this.last.x, rect.y - this.last.y) > GLIDE_LIMIT;
|
|
189
|
-
const reduced = prefersReducedMotion(field);
|
|
190
209
|
this.raise(field);
|
|
191
|
-
|
|
210
|
+
const reduced = prefersReducedMotion(field);
|
|
211
|
+
const colour = colourOf(field);
|
|
212
|
+
const flourishing = this.flourish && !reduced;
|
|
213
|
+
const flourishDuration = flourishing ? flourishMs(this.bar) : 0;
|
|
214
|
+
if (colour !== this.writtenColour) {
|
|
215
|
+
this.writtenColour = colour;
|
|
216
|
+
this.caret.style.setProperty("--_caret-color", colour);
|
|
217
|
+
}
|
|
192
218
|
this.glider.to(rect.x, rect.y, rect.height, snap || reduced);
|
|
193
219
|
this.caret.dataset.visible = "true";
|
|
194
220
|
this.visible = true;
|
|
195
221
|
this.last = rect;
|
|
196
|
-
if (
|
|
222
|
+
if (flourishing) {
|
|
197
223
|
this.bar.animate(FLOURISH_KEYFRAMES, {
|
|
198
|
-
duration:
|
|
224
|
+
duration: flourishDuration,
|
|
199
225
|
easing: "ease-out"
|
|
200
226
|
});
|
|
201
227
|
}
|
|
@@ -85,25 +85,36 @@ function displayedText(field, text) {
|
|
|
85
85
|
}
|
|
86
86
|
function fillMirror(field, style) {
|
|
87
87
|
const host = ensureMirror();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
/*
|
|
89
|
+
* Everything is read from the field before the mirror is written: a read after a write would force
|
|
90
|
+
* layout and style with the mirror dirty.
|
|
91
|
+
*/
|
|
92
|
+
const values = MIRRORED_PROPERTIES.map((property) => style.getPropertyValue(property));
|
|
93
|
+
const fieldWidth = field.offsetWidth;
|
|
91
94
|
/*
|
|
92
95
|
* Only a textarea can show a scrollbar. Edge 157 leaves an input's padding out of its clientWidth; read as a
|
|
93
96
|
* scrollbar, it narrowed the mirror, so centred and right-to-left text measured from the wrong edge.
|
|
94
97
|
*/
|
|
95
98
|
const scrollbar = field instanceof HTMLTextAreaElement
|
|
96
|
-
? Math.max(0,
|
|
99
|
+
? Math.max(0, fieldWidth -
|
|
97
100
|
field.clientWidth -
|
|
98
101
|
pixels(style.borderLeftWidth) -
|
|
99
102
|
pixels(style.borderRightWidth))
|
|
100
103
|
: 0;
|
|
104
|
+
const paddingRight = pixels(style.paddingRight) + scrollbar;
|
|
105
|
+
const whiteSpace = field instanceof HTMLTextAreaElement ? style.whiteSpace : "pre";
|
|
106
|
+
MIRRORED_PROPERTIES.forEach((property, index) => {
|
|
107
|
+
const value = values[index] ?? "";
|
|
108
|
+
if (host.style.getPropertyValue(property) !== value) {
|
|
109
|
+
host.style.setProperty(property, value);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
101
112
|
host.style.borderStyle = "solid";
|
|
102
113
|
host.style.borderColor = "transparent";
|
|
103
114
|
host.style.boxSizing = "border-box";
|
|
104
|
-
host.style.width = `${
|
|
105
|
-
host.style.paddingRight = `${
|
|
106
|
-
host.style.whiteSpace =
|
|
115
|
+
host.style.width = `${fieldWidth}px`;
|
|
116
|
+
host.style.paddingRight = `${paddingRight}px`;
|
|
117
|
+
host.style.whiteSpace = whiteSpace;
|
|
107
118
|
const caret = field.selectionStart ?? 0;
|
|
108
119
|
const marker = document.createElement("span");
|
|
109
120
|
marker.textContent = MARKER_TEXT;
|
|
@@ -23,10 +23,11 @@ export function leash(axis, target) {
|
|
|
23
23
|
export function atRest(axis, target) {
|
|
24
24
|
return Math.abs(target - axis.at) < REST_DISTANCE && Math.abs(axis.speed) < REST_SPEED;
|
|
25
25
|
}
|
|
26
|
+
let reducedMotionQuery = null;
|
|
26
27
|
/* Reduced motion and the `still` preset both turn the glide off: the caret snaps. */
|
|
27
28
|
export function prefersReducedMotion(from) {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
reducedMotionQuery ??= window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
30
|
+
return reducedMotionQuery.matches || Boolean(from?.closest('[data-kumiko-motion="still"]'));
|
|
30
31
|
}
|
|
31
32
|
export function createGlider(paint) {
|
|
32
33
|
let axes = [];
|
|
@@ -26,11 +26,25 @@ function createEntry(layer) {
|
|
|
26
26
|
tag.dataset.slot = "remote-caret-tag";
|
|
27
27
|
root.append(bar, tag);
|
|
28
28
|
layer.append(root);
|
|
29
|
+
let writtenHeight = "";
|
|
29
30
|
const glider = createGlider((x, y, height) => {
|
|
30
31
|
root.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
31
|
-
|
|
32
|
+
const written = `${height}px`;
|
|
33
|
+
if (written !== writtenHeight) {
|
|
34
|
+
writtenHeight = written;
|
|
35
|
+
root.style.height = written;
|
|
36
|
+
}
|
|
32
37
|
});
|
|
33
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
root,
|
|
40
|
+
tag,
|
|
41
|
+
glider,
|
|
42
|
+
spot: null,
|
|
43
|
+
colour: "",
|
|
44
|
+
shown: false,
|
|
45
|
+
stillTimer: 0,
|
|
46
|
+
leaveTimer: 0
|
|
47
|
+
};
|
|
34
48
|
}
|
|
35
49
|
function hide(entry) {
|
|
36
50
|
delete entry.root.dataset.visible;
|
|
@@ -46,7 +60,10 @@ function settleTag(entry, stillMs) {
|
|
|
46
60
|
}, stillMs);
|
|
47
61
|
}
|
|
48
62
|
function dress(entry, caret) {
|
|
49
|
-
entry.
|
|
63
|
+
if (entry.colour !== caret.colour) {
|
|
64
|
+
entry.colour = caret.colour;
|
|
65
|
+
entry.root.style.setProperty("--kumiko-remote-caret-color", caret.colour);
|
|
66
|
+
}
|
|
50
67
|
if (entry.tag.textContent !== caret.name) {
|
|
51
68
|
entry.tag.textContent = caret.name;
|
|
52
69
|
}
|
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
/*
|
|
18
18
|
* Both are manual popovers, so they sit in the top layer and paint above dialogs and popovers. The
|
|
19
|
-
* resets undo the browser's popover look (centred, bordered, padded, filled).
|
|
19
|
+
* resets undo the browser's popover look (centred, bordered, padded, filled). The caret leaves the top
|
|
20
|
+
* layer when its field is in the page, so it is shown as a plain element too.
|
|
20
21
|
*/
|
|
21
22
|
[data-slot="smooth-caret"] {
|
|
23
|
+
display: block;
|
|
22
24
|
position: fixed;
|
|
23
25
|
inset-block-start: 0;
|
|
24
26
|
inset-inline-start: 0;
|
|
@@ -35,7 +37,7 @@
|
|
|
35
37
|
block-size: 1rem;
|
|
36
38
|
pointer-events: none;
|
|
37
39
|
opacity: 0;
|
|
38
|
-
will-change: transform
|
|
40
|
+
will-change: transform;
|
|
39
41
|
transition: opacity var(--kumiko-fade-duration) var(--kumiko-fade-ease);
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -4,6 +4,8 @@ export declare function canJoinTopLayer(element: HTMLElement): boolean;
|
|
|
4
4
|
export declare function makeTopLayerPopover(element: HTMLElement): void;
|
|
5
5
|
/** Puts the element on top of the top layer: showing it again moves it above everything opened so far. */
|
|
6
6
|
export declare function raiseToTop(element: HTMLElement): void;
|
|
7
|
+
/** Takes the element out of the top layer, if it is there. */
|
|
8
|
+
export declare function lowerFromTop(element: HTMLElement): void;
|
|
7
9
|
/** Whether the element is shown in the top layer right now. */
|
|
8
10
|
export declare function isRaised(element: HTMLElement): boolean;
|
|
9
11
|
/** The modal dialog or open popover that holds this element, or `null` when it sits in the page. */
|
|
@@ -29,6 +29,12 @@ export function raiseToTop(element) {
|
|
|
29
29
|
}
|
|
30
30
|
element.showPopover();
|
|
31
31
|
}
|
|
32
|
+
/** Takes the element out of the top layer, if it is there. */
|
|
33
|
+
export function lowerFromTop(element) {
|
|
34
|
+
if (canJoinTopLayer(element) && isShown(element)) {
|
|
35
|
+
element.hidePopover();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
32
38
|
/** Whether the element is shown in the top layer right now. */
|
|
33
39
|
export function isRaised(element) {
|
|
34
40
|
return isShown(element);
|
|
@@ -14,12 +14,12 @@ export interface Swallow {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function createSwallow(): Swallow;
|
|
16
16
|
/**
|
|
17
|
-
* The drag of a switch's thumb
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* The drag of a switch's thumb: whether it is being dragged, and the pointer handlers that move it. A drag ends
|
|
18
|
+
* on the side where the thumb's centre is, through the controller, and swallows the click that follows it so the
|
|
19
|
+
* switch does not flip twice.
|
|
20
20
|
*/
|
|
21
21
|
export declare function useSwitchDrag(controller: SwitchController): {
|
|
22
|
-
|
|
22
|
+
dragging: boolean;
|
|
23
23
|
down: (event: PointerEvent<HTMLElement>) => void;
|
|
24
24
|
move: (event: PointerEvent<HTMLElement>) => void;
|
|
25
25
|
up: (event: PointerEvent<HTMLElement>) => void;
|