@astryxdesign/core 0.7.14 → 0.7.15-canary.g79b95eb
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/Calendar/Calendar.d.ts.map +1 -1
- package/dist/Calendar/Calendar.js +11 -2
- package/dist/Calendar/getInitialFocusDate.d.ts +8 -3
- package/dist/Calendar/getInitialFocusDate.d.ts.map +1 -1
- package/dist/Calendar/getInitialFocusDate.js +42 -7
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +9 -4
- package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
- package/dist/CheckboxList/CheckboxListItem.js +3 -8
- package/dist/DateInput/useTypedDate.d.ts.map +1 -1
- package/dist/DateInput/useTypedDate.js +3 -2
- package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
- package/dist/DateTimeInput/DateTimeInput.js +6 -3
- package/dist/DateTimeInput/NativeDateSegment.d.ts.map +1 -1
- package/dist/DateTimeInput/NativeDateSegment.js +23 -9
- package/dist/DateTimeInput/NativeTimeSegment.d.ts.map +1 -1
- package/dist/DateTimeInput/NativeTimeSegment.js +22 -8
- package/dist/Drawer/Drawer.d.ts.map +1 -1
- package/dist/Drawer/Drawer.js +7 -5
- package/dist/DropdownMenu/MenuBottomSheetActionList.d.ts.map +1 -1
- package/dist/DropdownMenu/MenuBottomSheetActionList.js +5 -1
- package/dist/Item/Item.d.ts +1 -1
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +4 -2
- package/dist/Link/useLinkify.d.ts.map +1 -1
- package/dist/Link/useLinkify.js +3 -2
- package/dist/List/List.d.ts +4 -1
- package/dist/List/List.d.ts.map +1 -1
- package/dist/Markdown/Markdown.d.ts.map +1 -1
- package/dist/Markdown/Markdown.js +8 -0
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +19 -4
- package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts +43 -15
- package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -1
- package/dist/SegmentedControl/useSegmentedSelectionMotion.js +108 -18
- package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts.map +1 -1
- package/dist/SegmentedControl/useSegmentedTouchTracking.js +5 -0
- package/dist/Table/plugins/sortable/useTableSortableState.d.ts.map +1 -1
- package/dist/Table/plugins/sortable/useTableSortableState.js +7 -3
- package/dist/Token/Token.d.ts.map +1 -1
- package/dist/Token/Token.js +2 -0
- package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
- package/dist/Tokenizer/Tokenizer.js +85 -12
- package/dist/astryx.css +11 -10
- package/dist/gestures/GestureHost.d.ts +5 -0
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +54 -28
- package/dist/hooks/menuPressGesture.d.ts +39 -2
- package/dist/hooks/menuPressGesture.d.ts.map +1 -1
- package/dist/hooks/menuPressGesture.js +92 -5
- package/dist/hooks/scrollOwnerRegistry.d.ts +0 -1
- package/dist/hooks/scrollOwnerRegistry.d.ts.map +1 -1
- package/dist/hooks/scrollOwnerRegistry.js +4 -1
- package/dist/hooks/useClickableContainer.d.ts +6 -4
- package/dist/hooks/useClickableContainer.d.ts.map +1 -1
- package/dist/hooks/useClickableContainer.js +11 -8
- package/dist/hooks/useFocusTrap.d.ts.map +1 -1
- package/dist/hooks/useFocusTrap.js +6 -0
- package/dist/hooks/useMenuPress.d.ts.map +1 -1
- package/dist/hooks/useMenuPress.js +35 -2
- package/dist/hooks/useStreamingText.d.ts.map +1 -1
- package/dist/hooks/useStreamingText.js +38 -23
- package/dist/i18n/generated-english/DateInput/useTypedDate.generated.js +2 -2
- package/dist/i18n/generated-locales/en.generated.js +2 -2
- package/dist/i18n/generated-locales/pseudo.generated.js +2 -2
- package/dist/motion/uikit/segmented.d.ts +35 -7
- package/dist/motion/uikit/segmented.d.ts.map +1 -1
- package/dist/motion/uikit/segmented.js +39 -11
- package/dist/privateAttributes/press.stylex.d.ts.map +1 -1
- package/dist/privateAttributes/press.stylex.js +1 -1
- package/dist/privateAttributes/pressBox.stylex.d.ts +12 -4
- package/dist/privateAttributes/pressBox.stylex.d.ts.map +1 -1
- package/dist/privateAttributes/pressBox.stylex.js +21 -4
- package/dist/privateAttributes/tokenRemove.stylex.d.ts +5 -0
- package/dist/privateAttributes/tokenRemove.stylex.d.ts.map +1 -0
- package/dist/privateAttributes/tokenRemove.stylex.js +25 -0
- package/dist/theme/defineTheme.d.ts +0 -1
- package/dist/theme/defineTheme.d.ts.map +1 -1
- package/dist/utils/inputAge.d.ts +5 -2
- package/dist/utils/inputAge.d.ts.map +1 -1
- package/dist/utils/inputAge.js +4 -1
- package/dist/utils/pressFeedback.d.ts.map +1 -1
- package/dist/utils/pressFeedback.js +60 -9
- package/locales/en.json +3 -3
- package/locales/pseudo.json +2 -2
- package/package.json +5 -5
- package/src/Calendar/Calendar.tsx +11 -1
- package/src/Calendar/getInitialFocusDate.ts +70 -8
- package/src/CheckboxInput/CheckboxInput.doc.mjs +16 -2
- package/src/CheckboxInput/CheckboxInput.tsx +32 -23
- package/src/CheckboxList/CheckboxList.doc.mjs +1 -1
- package/src/CheckboxList/CheckboxListItem.tsx +3 -6
- package/src/DateInput/useTypedDate.ts +9 -6
- package/src/DateTimeInput/DateTimeInput.tsx +7 -3
- package/src/DateTimeInput/NativeDateSegment.tsx +28 -10
- package/src/DateTimeInput/NativeTimeSegment.tsx +19 -9
- package/src/Drawer/Drawer.tsx +7 -5
- package/src/DropdownMenu/MenuBottomSheetActionList.tsx +3 -0
- package/src/Item/Item.doc.mjs +2 -1
- package/src/Item/Item.tsx +7 -3
- package/src/Link/useLinkify.tsx +7 -9
- package/src/List/List.doc.mjs +9 -21
- package/src/List/List.tsx +4 -1
- package/src/List/ListItem.doc.mjs +4 -2
- package/src/Markdown/Markdown.tsx +7 -0
- package/src/RadioList/RadioListItem.tsx +60 -30
- package/src/SegmentedControl/SegmentedControl.doc.mjs +3 -3
- package/src/SegmentedControl/useSegmentedSelectionMotion.ts +115 -19
- package/src/SegmentedControl/useSegmentedTouchTracking.ts +5 -0
- package/src/Table/plugins/sortable/useTableSortableState.tsx +5 -1
- package/src/Token/Token.tsx +2 -0
- package/src/Tokenizer/Tokenizer.tsx +102 -7
- package/src/gestures/GestureHost.ts +62 -32
- package/src/hooks/menuPressGesture.ts +116 -9
- package/src/hooks/scrollOwnerRegistry.ts +8 -1
- package/src/hooks/useClickableContainer.ts +11 -8
- package/src/hooks/useFocusTrap.ts +6 -0
- package/src/hooks/useMenuPress.ts +32 -2
- package/src/hooks/useStreamingText.ts +30 -25
- package/src/i18n/generated-english/DateInput/useTypedDate.generated.ts +2 -2
- package/src/i18n/generated-locales/en.generated.ts +2 -2
- package/src/i18n/generated-locales/pseudo.generated.ts +2 -2
- package/src/motion/MEASUREMENTS.md +2 -3
- package/src/motion/uikit/segmented.ts +35 -10
- package/src/privateAttributes/press.stylex.ts +2 -8
- package/src/privateAttributes/pressBox.stylex.ts +23 -4
- package/src/privateAttributes/tokenRemove.stylex.ts +27 -0
- package/src/theme/defineTheme.ts +0 -1
- package/src/theme/useThemeName.doc.mjs +69 -0
- package/src/utils/inputAge.ts +5 -2
- package/src/utils/pressFeedback.ts +80 -9
|
@@ -145,30 +145,32 @@ export function useStreamingText(
|
|
|
145
145
|
return Math.max(4, Math.round(tick));
|
|
146
146
|
}, [token, speed]);
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
// Where the reveal restarts: at 0 on a clear (a new message), at the whole
|
|
149
|
+
// text on a stream's end. Adjusted during render, and only then, never per
|
|
150
|
+
// chunk. State, not refs: a render React discards takes its adjustment with
|
|
151
|
+
// it. The frame clock alone advances `revealed`, which counts only within
|
|
152
|
+
// its restart's epoch.
|
|
153
|
+
const [restart, setRestart] = useState({epoch: 0, len: 0});
|
|
154
|
+
const [revealed, setRevealed] = useState({epoch: 0, len: 0});
|
|
155
|
+
const displayedLen =
|
|
156
|
+
revealed.epoch === restart.epoch ? revealed.len : restart.len;
|
|
149
157
|
const targetRef = useRef(targetText);
|
|
150
|
-
const displayedLenRef = useRef(0);
|
|
151
158
|
const lastTickRef = useRef(0);
|
|
152
159
|
const rafRef = useRef<number | null>(null);
|
|
153
160
|
|
|
154
161
|
targetRef.current = targetText;
|
|
155
162
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (targetText.length !== prevTargetLenRef.current) {
|
|
159
|
-
prevTargetLenRef.current = targetText.length;
|
|
160
|
-
if (targetText.length === 0 && displayedLen !== 0) {
|
|
161
|
-
displayedLenRef.current = 0;
|
|
162
|
-
setDisplayedLen(0);
|
|
163
|
-
}
|
|
163
|
+
if (targetText.length === 0 && displayedLen !== 0) {
|
|
164
|
+
setRestart(previous => ({epoch: previous.epoch + 1, len: 0}));
|
|
164
165
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
prevIsStreamingRef.current = isStreaming;
|
|
166
|
+
const [wasStreaming, setWasStreaming] = useState(isStreaming);
|
|
167
|
+
if (isStreaming !== wasStreaming) {
|
|
168
|
+
setWasStreaming(isStreaming);
|
|
169
169
|
if (!isStreaming && targetText.length > 0) {
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
setRestart(previous => ({
|
|
171
|
+
epoch: previous.epoch + 1,
|
|
172
|
+
len: targetText.length,
|
|
173
|
+
}));
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
|
|
@@ -190,14 +192,17 @@ export function useStreamingText(
|
|
|
190
192
|
if (elapsed >= tickMs) {
|
|
191
193
|
lastTickRef.current = now;
|
|
192
194
|
const target = targetRef.current;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
setRevealed(previous => {
|
|
196
|
+
const currentLen =
|
|
197
|
+
previous.epoch === restart.epoch ? previous.len : restart.len;
|
|
198
|
+
if (currentLen >= target.length) {
|
|
199
|
+
return previous;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
epoch: restart.epoch,
|
|
203
|
+
len: Math.min(currentLen + charsPerTick, target.length),
|
|
204
|
+
};
|
|
205
|
+
});
|
|
201
206
|
}
|
|
202
207
|
|
|
203
208
|
rafRef.current = requestAnimationFrame(tick);
|
|
@@ -210,7 +215,7 @@ export function useStreamingText(
|
|
|
210
215
|
rafRef.current = null;
|
|
211
216
|
}
|
|
212
217
|
};
|
|
213
|
-
}, [isStreaming, charsPerTick, tickMs, speed, prefersReducedMotion]);
|
|
218
|
+
}, [isStreaming, charsPerTick, tickMs, speed, prefersReducedMotion, restart]);
|
|
214
219
|
|
|
215
220
|
if (!isStreaming || speed === 'instant' || prefersReducedMotion) {
|
|
216
221
|
return targetText;
|
|
@@ -10,8 +10,8 @@ const english: Readonly<Record<string, string>> = {
|
|
|
10
10
|
"@astryx.dateInput.calendarDescription": "Dates use the {calendar}",
|
|
11
11
|
"@astryx.dateInput.formatHint": "e.g., {example}",
|
|
12
12
|
"@astryx.dateInput.invalidDate": "Invalid date",
|
|
13
|
-
"@astryx.dateInput.nonexistentDate": "
|
|
14
|
-
"@astryx.dateInput.outOfRangeDate": "{bounds, select, both {Enter a date from {min} to {max}} min {Enter a date on or after {min}} max {Enter a date on or before {max}} other {
|
|
13
|
+
"@astryx.dateInput.nonexistentDate": "{named, select, yes {Enter a real date ({calendar})} other {Enter a real date}}",
|
|
14
|
+
"@astryx.dateInput.outOfRangeDate": "{bounds, select, both {Enter a date from {min} to {max}} min {Enter a date on or after {min}} max {Enter a date on or before {max}} other {Enter an available date}}"
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export default english;
|
|
@@ -358,9 +358,9 @@ const runtimeCatalog: Readonly<Record<string, string>> = {
|
|
|
358
358
|
'@astryx.dateInput.clear': 'Clear {label}',
|
|
359
359
|
'@astryx.dateInput.invalidDate': 'Invalid date',
|
|
360
360
|
'@astryx.dateInput.nonexistentDate':
|
|
361
|
-
'
|
|
361
|
+
'{named, select, yes {Enter a real date ({calendar})} other {Enter a real date}}',
|
|
362
362
|
'@astryx.dateInput.outOfRangeDate':
|
|
363
|
-
'{bounds, select, both {Enter a date from {min} to {max}} min {Enter a date on or after {min}} max {Enter a date on or before {max}} other {
|
|
363
|
+
'{bounds, select, both {Enter a date from {min} to {max}} min {Enter a date on or after {min}} max {Enter a date on or before {max}} other {Enter an available date}}',
|
|
364
364
|
'@astryx.dateInput.formatHint': 'e.g., {example}',
|
|
365
365
|
'@astryx.dateInput.calendarDescription': 'Dates use the {calendar}',
|
|
366
366
|
'@astryx.dateInput.resetPicking': 'Reset',
|
|
@@ -366,9 +366,9 @@ const runtimeCatalog: Readonly<Record<string, string>> = {
|
|
|
366
366
|
'@astryx.dateInput.clear': '⟦Çłéàř {label}⟧',
|
|
367
367
|
'@astryx.dateInput.invalidDate': '⟦Íñṽàłíð ðàţé⟧',
|
|
368
368
|
'@astryx.dateInput.nonexistentDate':
|
|
369
|
-
'
|
|
369
|
+
'⟦{named, select, yes {Enter a real date ({calendar})} other {Enter a real date}}⟧',
|
|
370
370
|
'@astryx.dateInput.outOfRangeDate':
|
|
371
|
-
'⟦{bounds, select, both {Enter a date from {min} to {max}} min {Enter a date on or after {min}} max {Enter a date on or before {max}} other {
|
|
371
|
+
'⟦{bounds, select, both {Enter a date from {min} to {max}} min {Enter a date on or after {min}} max {Enter a date on or before {max}} other {Enter an available date}}⟧',
|
|
372
372
|
'@astryx.dateInput.formatHint': '⟦é.ĝ., {example}⟧',
|
|
373
373
|
'@astryx.dateInput.calendarDescription': '⟦Ðàţéš úšé ţĥé {calendar}⟧',
|
|
374
374
|
'@astryx.dateInput.resetPicking': '⟦Řéšéţ⟧',
|
|
@@ -223,9 +223,8 @@ Bookmarks sheet.
|
|
|
223
223
|
Done (UIKit lab, iOS 26.2 simulator, Oct 23–24 2026; in the segmented control's
|
|
224
224
|
own table, `uikit/segmented.ts`, tagged `measured:`): M-SG02 (the selection
|
|
225
225
|
spring and the drag clamp; the tracking spring is the shared
|
|
226
|
-
`springs.fingerTracking`; the lift
|
|
227
|
-
|
|
228
|
-
fitted per frame).
|
|
226
|
+
`springs.fingerTracking`; the lift's growth and spring are in the table too,
|
|
227
|
+
as `liftGrowth` and `lift`) and M-SG03 (the tap's frames, fitted per frame).
|
|
229
228
|
|
|
230
229
|
## Sheets (UISheetPresentationController)
|
|
231
230
|
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @file segmented.ts
|
|
5
5
|
* @input Nothing; data only
|
|
6
6
|
* @output Exports `segmentedControl`, UISegmentedControl's selection slide
|
|
7
|
-
* spring
|
|
8
|
-
* registers the
|
|
7
|
+
* spring, its drag overshoot and its lift; and `registerSegmentedTable`,
|
|
8
|
+
* which registers the two springs as internal motion roles
|
|
9
9
|
* @position The segmented-control domain of the UIKit constants table
|
|
10
10
|
* (motion/uikit); read by SegmentedControl's touch presentation
|
|
11
11
|
*
|
|
@@ -26,10 +26,11 @@ import {registerMotionTable} from '../roles';
|
|
|
26
26
|
* cross-fade needs a second copy of each title. Under Reduce Motion, UIKit's
|
|
27
27
|
* lens fades in at the new segment and scales from 0.88. Astryx allows no
|
|
28
28
|
* scaling there, so the animator's Reduce Motion cross-fade replaces it.
|
|
29
|
-
* UIKit's lens also
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
29
|
+
* UIKit's lens also stretches along a slide; that stretch is not modeled.
|
|
30
|
+
* The lens chases a dragging finger on the shared `springs.fingerTracking`
|
|
31
|
+
* role, which matches the values UIKit reports for this control. A flick
|
|
32
|
+
* carries the selection no further than a slow drag: UIKit projects no
|
|
33
|
+
* flick, so the release position alone decides.
|
|
33
34
|
*/
|
|
34
35
|
export const segmentedControl = {
|
|
35
36
|
/**
|
|
@@ -59,16 +60,40 @@ export const segmentedControl = {
|
|
|
59
60
|
* 11 pt past its center (312 vs 301), Oct 23 2026
|
|
60
61
|
*/
|
|
61
62
|
dragOvershoot: 11,
|
|
63
|
+
/**
|
|
64
|
+
* How much a finger's press on the selected segment grows the lens, in pt
|
|
65
|
+
* (width, height). The growth is the same at every control size.
|
|
66
|
+
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
67
|
+
* iPhone 17 Pro, per-frame lens bounds of a held selected segment:
|
|
68
|
+
* 96 × 27 to 120 × 43 (three segments), 71 × 27 to 95 × 43 (four
|
|
69
|
+
* segments), 126 × 40 to 150 × 56 (a 390 × 44 control), Oct 23 2026
|
|
70
|
+
*/
|
|
71
|
+
liftGrowth: [24, 16],
|
|
72
|
+
/**
|
|
73
|
+
* The lens growing by `liftGrowth` under a finger that presses the
|
|
74
|
+
* selected segment, and shrinking back after the release. It is critically
|
|
75
|
+
* damped and reaches 99 % in about 0.27 s.
|
|
76
|
+
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
77
|
+
* iPhone 17 Pro, UIViewSpringAnimationBehaviorSettings read on the lens
|
|
78
|
+
* while it lifts and settles (dampingRatio 1.0, response 0.25),
|
|
79
|
+
* Oct 23 2026
|
|
80
|
+
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
81
|
+
* iPhone 17 Pro, per-frame lens bounds of a 600 ms hold of the selected
|
|
82
|
+
* segment, spring fit with (1.0, 0.25): lift rms 0.16 pt (width) and
|
|
83
|
+
* 0.13 pt (height), settle rms 0.05 pt and 0.03 pt, each starting about
|
|
84
|
+
* 16 ms after the touch event, Nov 2 2026
|
|
85
|
+
*/
|
|
86
|
+
lift: {response: 0.25, dampingRatio: 1},
|
|
62
87
|
} as const;
|
|
63
88
|
|
|
64
89
|
/**
|
|
65
90
|
* Registers this table with the motion registry (motion/roles.ts). The
|
|
66
|
-
* slide's
|
|
67
|
-
*
|
|
68
|
-
* a second call does nothing.
|
|
91
|
+
* slide's and the lift's springs become internal motion roles. The drag
|
|
92
|
+
* overshoot and the lift's growth are not motion, so they stay internal
|
|
93
|
+
* constants. Nothing registers on import, and a second call does nothing.
|
|
69
94
|
*/
|
|
70
95
|
export function registerSegmentedTable(): void {
|
|
71
96
|
registerMotionTable('segmented', segmentedControl, {
|
|
72
|
-
roles: ['selectionSpring'],
|
|
97
|
+
roles: ['selectionSpring', 'lift'],
|
|
73
98
|
});
|
|
74
99
|
}
|
|
@@ -369,14 +369,8 @@ export const rowPressPaintStyles = stylex.create({
|
|
|
369
369
|
checkboxRow: {
|
|
370
370
|
'--_checkbox-row-press-paint': {
|
|
371
371
|
default: 'none',
|
|
372
|
-
':is([data-astryx-press="on"])':
|
|
373
|
-
|
|
374
|
-
'@media (pointer: coarse)': 'var(--_press-paint-image)',
|
|
375
|
-
},
|
|
376
|
-
':is([data-astryx-press="fading"])': {
|
|
377
|
-
default: 'none',
|
|
378
|
-
'@media (pointer: coarse)': 'var(--_press-paint-image)',
|
|
379
|
-
},
|
|
372
|
+
':is([data-astryx-press="on"])': 'var(--_press-paint-image)',
|
|
373
|
+
':is([data-astryx-press="fading"])': 'var(--_press-paint-image)',
|
|
380
374
|
},
|
|
381
375
|
},
|
|
382
376
|
});
|
|
@@ -2,15 +2,24 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @file privateAttributes/pressBox.stylex.ts
|
|
4
4
|
* @input A control's box: the non-text part around its input and indicator
|
|
5
|
-
* @output pressBoxProps, which marks the box,
|
|
6
|
-
* marked box that a press starts in
|
|
5
|
+
* @output pressBoxProps, which marks the box, pressBoxAt, which finds the
|
|
6
|
+
* marked box that a press starts in, and pressBoxesIn, which lists the
|
|
7
|
+
* marked boxes a surface owns
|
|
7
8
|
* @position Owner module of the private press-box attribute: the only file
|
|
8
|
-
* that writes its name. CheckboxInput and RadioListItem mark their boxes
|
|
9
|
-
*
|
|
9
|
+
* that writes its name. CheckboxInput and RadioListItem mark their boxes.
|
|
10
|
+
* utils/boxHold.ts reads the mark. The press controller and the container
|
|
11
|
+
* rule give a surface that owns a box the fine-pointer press. No package
|
|
12
|
+
* entry exports it.
|
|
10
13
|
*/
|
|
11
14
|
|
|
12
15
|
const PRESS_BOX = 'data-astryx-press-box';
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The public pressable marker (utils/pressFeedback.ts PRESSABLE_ATTRIBUTE).
|
|
19
|
+
* The press controller imports this module, so this module cannot import it.
|
|
20
|
+
*/
|
|
21
|
+
const PRESSABLE = '[data-astryx-pressable]';
|
|
22
|
+
|
|
14
23
|
/** Spread on the box around a control's input and indicator. */
|
|
15
24
|
export const pressBoxProps: Readonly<Record<string, string>> = {
|
|
16
25
|
[PRESS_BOX]: '',
|
|
@@ -27,3 +36,13 @@ export function pressBoxAt(
|
|
|
27
36
|
const box = target.closest(`[${PRESS_BOX}]`);
|
|
28
37
|
return box instanceof HTMLElement && surface.contains(box) ? box : null;
|
|
29
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The marked boxes that `surface` owns: those inside it, with no other
|
|
42
|
+
* pressable surface between the two.
|
|
43
|
+
*/
|
|
44
|
+
export function pressBoxesIn(surface: Element): Element[] {
|
|
45
|
+
return Array.from(surface.querySelectorAll(`[${PRESS_BOX}]`)).filter(
|
|
46
|
+
box => box.closest(PRESSABLE) === surface,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file privateAttributes/tokenRemove.stylex.ts
|
|
5
|
+
* @input Nothing
|
|
6
|
+
* @output tokenRemoveProps, which marks a Token's remove button, and
|
|
7
|
+
* removeControlOf, which finds that button from an event target
|
|
8
|
+
* @position Owner module of the private token-remove attribute: the only
|
|
9
|
+
* file that writes its name. Token marks its remove button; Tokenizer
|
|
10
|
+
* reads the mark. No package entry exports it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const TOKEN_REMOVE = 'data-astryx-token-remove';
|
|
14
|
+
|
|
15
|
+
/** Spread on a Token's remove button: marks it for a field holding tokens. */
|
|
16
|
+
export const tokenRemoveProps: Readonly<Record<string, string>> = {
|
|
17
|
+
[TOKEN_REMOVE]: '',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** The token remove button at or around `target`, or null. */
|
|
21
|
+
export function removeControlOf(target: EventTarget | null): Element | null {
|
|
22
|
+
// A node type check, not `instanceof`: a field in another document passes.
|
|
23
|
+
const node = target as Node | null;
|
|
24
|
+
return node != null && node.nodeType === 1
|
|
25
|
+
? (node as Element).closest(`[${TOKEN_REMOVE}]`)
|
|
26
|
+
: null;
|
|
27
|
+
}
|
package/src/theme/defineTheme.ts
CHANGED
|
@@ -601,7 +601,6 @@ export interface DefinedTheme {
|
|
|
601
601
|
/**
|
|
602
602
|
* Component icon slot values with their functions, present when any value
|
|
603
603
|
* is a function. Only component slot resolution reads it.
|
|
604
|
-
* @internal
|
|
605
604
|
*/
|
|
606
605
|
__componentIcons?: Partial<Record<string, StoredComponentIconValue>>;
|
|
607
606
|
/** Indicator overrides for stateful control visuals, keyed by name */
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').HookDoc} */
|
|
4
|
+
export const docs = {
|
|
5
|
+
name: 'useThemeName',
|
|
6
|
+
displayName: 'useThemeName',
|
|
7
|
+
keywords: ['theme', 'name', 'identity', 'provider', 'icon'],
|
|
8
|
+
params: [],
|
|
9
|
+
returns: [
|
|
10
|
+
{
|
|
11
|
+
name: 'name',
|
|
12
|
+
type: 'string | null',
|
|
13
|
+
description:
|
|
14
|
+
'The nearest Theme name. Null when no Theme context is present and the root has not set a theme name.',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
usage: {
|
|
18
|
+
description:
|
|
19
|
+
'Reads only the active theme name. Use it when code needs to know which theme is on, and does not need tokens or the color mode. It reads ThemeContext when a Theme is above the caller, and otherwise the root theme name on the document element.',
|
|
20
|
+
bestPractices: [
|
|
21
|
+
{
|
|
22
|
+
guidance: true,
|
|
23
|
+
description:
|
|
24
|
+
'Use this hook for theme identity, such as picking a semantic icon for the active theme.',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
guidance: true,
|
|
28
|
+
description:
|
|
29
|
+
'Use useTheme when the caller also needs token values or the resolved light or dark mode.',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
guidance: false,
|
|
33
|
+
description:
|
|
34
|
+
'Treat null as the name default. Null means no theme name is available.',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
relatedComponents: ['Theme'],
|
|
39
|
+
relatedHooks: ['useTheme'],
|
|
40
|
+
importPath: '@astryxdesign/core/theme',
|
|
41
|
+
category: 'Utility',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** @type {import('@astryxdesign/cli/authoring').HookTranslationDoc} */
|
|
45
|
+
export const docsDense = {
|
|
46
|
+
description:
|
|
47
|
+
'The nearest theme name, or null when none is set. Lighter than useTheme.',
|
|
48
|
+
returnDescriptions: {
|
|
49
|
+
name: 'nearest Theme name, or null when no theme name is available.',
|
|
50
|
+
},
|
|
51
|
+
usage: {
|
|
52
|
+
description:
|
|
53
|
+
'The active theme name only. Reads ThemeContext, else the root theme name.',
|
|
54
|
+
bestPractices: [
|
|
55
|
+
{
|
|
56
|
+
guidance: true,
|
|
57
|
+
description: 'Use it when only the theme name is needed.',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
guidance: true,
|
|
61
|
+
description: 'Use useTheme for tokens or the color mode.',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
guidance: false,
|
|
65
|
+
description: 'Treat null as a theme named default.',
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
};
|
package/src/utils/inputAge.ts
CHANGED
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
import {isDocument, isNode} from './nodeType';
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The part of a window's performance timeline an input's age reads, with
|
|
17
|
+
* the time origin that converts an epoch stamp.
|
|
18
|
+
*/
|
|
19
|
+
export type EventClock = Pick<Performance, 'now' | 'timeOrigin'>;
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* The clock of the window that stamped an input: an event's `view`, or the
|
|
@@ -22,10 +22,16 @@
|
|
|
22
22
|
// costs one attribute write and no React render.
|
|
23
23
|
//
|
|
24
24
|
// Where the primary pointer is fine, the controller ignores the mouse and the
|
|
25
|
-
// keyboard, and CSS `:active` keeps their press.
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
25
|
+
// keyboard, and CSS `:active` keeps their press. A surface that owns a
|
|
26
|
+
// control's box (pressBox.stylex.ts), as a checkbox or a radio row does, is
|
|
27
|
+
// the exception. There the controller paints a mouse's or a pen's press at
|
|
28
|
+
// once and fades it on release, as it does a finger's. The surface's `:active`
|
|
29
|
+
// arm yields while it does. On a row, a press on a nested control is that
|
|
30
|
+
// control's: the row's container rule ends the row's paint
|
|
31
|
+
// (hooks/useClickableContainer.ts).
|
|
32
|
+
// Under a coarse primary pointer the CSS drops `:active`, so the controller
|
|
33
|
+
// paints every press. A mouse, trackpad or Space press paints at once. The
|
|
34
|
+
// controller reads the same query as the stylesheet, so they agree.
|
|
29
35
|
//
|
|
30
36
|
// A finger waits only inside a scroller. Outside one, a surface highlights in
|
|
31
37
|
// the frame the finger lands, as a UIControl does. Inside one, it waits the
|
|
@@ -56,6 +62,8 @@ import {subscribeInput} from './inputStream';
|
|
|
56
62
|
import {isInsideScrollView} from './scrollView';
|
|
57
63
|
import {msSinceInput} from './inputAge';
|
|
58
64
|
import {TOUCH_QUERY} from './touchPresentation';
|
|
65
|
+
import {pressBoxesIn} from '../privateAttributes/pressBox.stylex';
|
|
66
|
+
import {isPrimaryClick} from './primaryClick';
|
|
59
67
|
import {holdsPressThroughDrag} from '../privateAttributes/pressHoldsDrag.stylex';
|
|
60
68
|
import {isTrackedByGroup} from '../privateAttributes/pressGroupItem.stylex';
|
|
61
69
|
|
|
@@ -482,6 +490,24 @@ function stylesheetDroppedActive(): boolean {
|
|
|
482
490
|
);
|
|
483
491
|
}
|
|
484
492
|
|
|
493
|
+
/**
|
|
494
|
+
* Whether the press on `target` lands on a surface that takes the
|
|
495
|
+
* fine-pointer press. There a mouse's or a pen's press paints at once, on any
|
|
496
|
+
* primary pointer.
|
|
497
|
+
*/
|
|
498
|
+
function paintsFinePress(target: EventTarget | null): boolean {
|
|
499
|
+
const surface = surfaceAt(target);
|
|
500
|
+
return surface != null && paintsFinePointerPress(surface);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Whether `surface` takes the fine-pointer press. It does when it owns a
|
|
505
|
+
* control's box.
|
|
506
|
+
*/
|
|
507
|
+
function paintsFinePointerPress(surface: Element): boolean {
|
|
508
|
+
return pressBoxesIn(surface).length > 0;
|
|
509
|
+
}
|
|
510
|
+
|
|
485
511
|
/**
|
|
486
512
|
* The surface a mouse button's or the Space key's press paints, if any: the
|
|
487
513
|
* innermost marked surface, outside a menu and off a tracked action. A key's
|
|
@@ -523,12 +549,30 @@ function pressButton(
|
|
|
523
549
|
apply(button, pressGestureStep(button.live.gesture, {kind: 'buttonDown'}));
|
|
524
550
|
}
|
|
525
551
|
|
|
552
|
+
/**
|
|
553
|
+
* Whether a release on `element` ends at once. Under Reduce Motion a fine
|
|
554
|
+
* pointer's release changes at once, with no fade. This holds on a surface
|
|
555
|
+
* that takes the fine-pointer press, where the primary pointer is fine.
|
|
556
|
+
*/
|
|
557
|
+
function releasesAtOnce(element: Element): boolean {
|
|
558
|
+
return (
|
|
559
|
+
paintsFinePointerPress(element) &&
|
|
560
|
+
!stylesheetDroppedActive() &&
|
|
561
|
+
typeof window.matchMedia === 'function' &&
|
|
562
|
+
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
|
|
526
566
|
/** The mouse button or the key came up: the press fades like a finger's. */
|
|
527
567
|
function releaseButton(): void {
|
|
528
568
|
holdKey(false);
|
|
529
569
|
if (button.live == null) {
|
|
530
570
|
return;
|
|
531
571
|
}
|
|
572
|
+
if (releasesAtOnce(button.live.element)) {
|
|
573
|
+
cancelButton();
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
532
576
|
apply(button, pressGestureStep(button.live.gesture, {kind: 'up'}));
|
|
533
577
|
}
|
|
534
578
|
|
|
@@ -547,12 +591,27 @@ function onPointerDown(event: PointerEvent): void {
|
|
|
547
591
|
// A mouse already has hover and keeps `:active` where the primary pointer
|
|
548
592
|
// is fine; the touch treatment's CSS is inside `@media (pointer: coarse)`.
|
|
549
593
|
// Not tracking it there keeps desktop identical and costs the mouse path
|
|
550
|
-
// nothing
|
|
551
|
-
|
|
594
|
+
// nothing, except on a surface that takes the fine-pointer press. Only
|
|
595
|
+
// the primary button paints, as `:active` does. On such a surface a
|
|
596
|
+
// macOS ctrl-click is a context click, so it paints nothing either.
|
|
597
|
+
if (
|
|
598
|
+
stylesheetDroppedActive()
|
|
599
|
+
? event.button === 0
|
|
600
|
+
: isPrimaryClick(event) && paintsFinePress(event.target)
|
|
601
|
+
) {
|
|
552
602
|
pressButton(event.target, event.pointerId);
|
|
553
603
|
}
|
|
554
604
|
return;
|
|
555
605
|
}
|
|
606
|
+
// On a surface that takes the fine-pointer press, a pen's barrel or eraser
|
|
607
|
+
// button is not a press.
|
|
608
|
+
if (
|
|
609
|
+
event.pointerType === 'pen' &&
|
|
610
|
+
!isPrimaryClick(event) &&
|
|
611
|
+
paintsFinePress(event.target)
|
|
612
|
+
) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
556
615
|
armTouchCancel();
|
|
557
616
|
// A second finger or a new press ends the last box contact; its lift is not
|
|
558
617
|
// a still lift.
|
|
@@ -574,11 +633,19 @@ function onPointerDown(event: PointerEvent): void {
|
|
|
574
633
|
finish(finger);
|
|
575
634
|
}
|
|
576
635
|
const element = surfaceAt(event.target);
|
|
636
|
+
// On a surface that takes the fine-pointer press, a pen presses at once on
|
|
637
|
+
// any primary pointer, in a scroll view too. The delay and the brake wait
|
|
638
|
+
// out a finger's scroll.
|
|
639
|
+
const presentsAtOnce =
|
|
640
|
+
event.pointerType === 'pen' &&
|
|
641
|
+
element != null &&
|
|
642
|
+
paintsFinePointerPress(element);
|
|
577
643
|
// The touch clock is stamped AFTER the brake reads it, deliberately: the
|
|
578
644
|
// question the brake asks is whether a PREVIOUS finger could still be
|
|
579
645
|
// driving this scroll, and stamping first would make every first touch on a
|
|
580
646
|
// freshly restored page answer yes.
|
|
581
|
-
const braking =
|
|
647
|
+
const braking =
|
|
648
|
+
element != null && !presentsAtOnce && scrollerIsBraking(element);
|
|
582
649
|
lastTouchAt = Date.now();
|
|
583
650
|
lastTouchTarget = event.target instanceof Node ? event.target : null;
|
|
584
651
|
// A group's tracker that follows this pointer paints its action, so two
|
|
@@ -611,7 +678,7 @@ function onPointerDown(event: PointerEvent): void {
|
|
|
611
678
|
kind: 'down',
|
|
612
679
|
x: event.clientX,
|
|
613
680
|
y: event.clientY,
|
|
614
|
-
delayed: isInsideScrollView(element),
|
|
681
|
+
delayed: !presentsAtOnce && isInsideScrollView(element),
|
|
615
682
|
}),
|
|
616
683
|
msSinceInput(event.timeStamp, event),
|
|
617
684
|
);
|
|
@@ -673,7 +740,11 @@ function onPointerUp(event: PointerEvent): void {
|
|
|
673
740
|
) {
|
|
674
741
|
return;
|
|
675
742
|
}
|
|
676
|
-
|
|
743
|
+
const step =
|
|
744
|
+
event.pointerType === 'pen' && releasesAtOnce(live.element)
|
|
745
|
+
? 'cancel'
|
|
746
|
+
: 'up';
|
|
747
|
+
apply(finger, pressGestureStep(live.gesture, {kind: step}));
|
|
677
748
|
releaseIfDead(finger);
|
|
678
749
|
}
|
|
679
750
|
|