gooee 0.51.1 → 1.0.0
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 +10 -3
- package/package.json +6 -2
- package/scripts/add.js +181 -42
- package/src/base.css +3 -1
- package/src/components/Accordion/Accordion.module.css +7 -5
- package/src/components/Accordion/Accordion.tsx +13 -11
- package/src/components/Accordion/Accordion.vue +16 -15
- package/src/components/Accordion/AccordionItem.vue +8 -7
- package/src/components/Alert/Alert.module.css +9 -7
- package/src/components/Alert/Alert.tsx +25 -16
- package/src/components/Alert/Alert.vue +31 -27
- package/src/components/AlertDialog/AlertDialog.module.css +2 -0
- package/src/components/AlertDialog/AlertDialog.tsx +8 -7
- package/src/components/AlertDialog/AlertDialog.vue +25 -23
- package/src/components/AnimatedNumber/AnimatedNumber.module.css +5 -3
- package/src/components/AnimatedNumber/AnimatedNumber.tsx +6 -6
- package/src/components/AnimatedNumber/AnimatedNumber.vue +5 -5
- package/src/components/AspectRatio/AspectRatio.module.css +2 -0
- package/src/components/AspectRatio/AspectRatio.tsx +3 -3
- package/src/components/AspectRatio/AspectRatio.vue +5 -8
- package/src/components/Avatar/Avatar.module.css +10 -8
- package/src/components/Avatar/Avatar.tsx +4 -3
- package/src/components/Avatar/Avatar.vue +17 -19
- package/src/components/Avatar/index.ts +0 -2
- package/src/components/AvatarGroup/AvatarGroup.module.css +11 -9
- package/src/components/AvatarGroup/AvatarGroup.tsx +4 -4
- package/src/components/AvatarGroup/AvatarGroup.vue +13 -16
- package/src/components/Badge/Badge.module.css +6 -4
- package/src/components/Badge/Badge.tsx +3 -3
- package/src/components/Badge/Badge.vue +15 -14
- package/src/components/Breadcrumb/Breadcrumb.module.css +5 -3
- package/src/components/Breadcrumb/Breadcrumb.tsx +20 -12
- package/src/components/Breadcrumb/Breadcrumb.vue +33 -25
- package/src/components/Button/Button.module.css +16 -14
- package/src/components/Button/Button.tsx +6 -4
- package/src/components/Button/Button.vue +42 -33
- package/src/components/ButtonGroup/ButtonGroup.module.css +2 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +1 -1
- package/src/components/ButtonGroup/ButtonGroup.vue +9 -12
- package/src/components/Card/Card.module.css +6 -4
- package/src/components/Card/Card.tsx +6 -6
- package/src/components/Card/Card.vue +18 -21
- package/src/components/Center/Center.module.css +2 -0
- package/src/components/Center/Center.tsx +1 -1
- package/src/components/Center/Center.vue +18 -15
- package/src/components/Checkbox/Checkbox.module.css +10 -8
- package/src/components/Checkbox/Checkbox.tsx +7 -5
- package/src/components/Checkbox/Checkbox.vue +29 -31
- package/src/components/CheckboxGroup/CheckboxGroup.module.css +3 -1
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +4 -4
- package/src/components/CheckboxGroup/CheckboxGroup.vue +33 -30
- package/src/components/Cluster/Cluster.module.css +2 -0
- package/src/components/Cluster/Cluster.tsx +1 -1
- package/src/components/Cluster/Cluster.vue +21 -17
- package/src/components/CodeBlock/CodeBlock.module.css +12 -10
- package/src/components/CodeBlock/CodeBlock.tsx +18 -10
- package/src/components/CodeBlock/CodeBlock.vue +30 -27
- package/src/components/CodeBlock/highlight.ts +1 -1
- package/src/components/Collapsible/Collapsible.module.css +7 -5
- package/src/components/Collapsible/Collapsible.tsx +7 -6
- package/src/components/Collapsible/Collapsible.vue +30 -26
- package/src/components/Container/Container.module.css +2 -0
- package/src/components/Container/Container.tsx +1 -1
- package/src/components/Container/Container.vue +13 -12
- package/src/components/CopyButton/CopyButton.module.css +20 -18
- package/src/components/CopyButton/CopyButton.tsx +21 -14
- package/src/components/CopyButton/CopyButton.vue +41 -31
- package/src/components/Dial/Dial.module.css +26 -11
- package/src/components/Dial/Dial.tsx +18 -18
- package/src/components/Dial/Dial.vue +57 -60
- package/src/components/Dialog/Dialog.module.css +4 -2
- package/src/components/Dialog/Dialog.tsx +22 -13
- package/src/components/Dialog/Dialog.vue +34 -30
- package/src/components/Divider/Divider.module.css +5 -3
- package/src/components/Divider/Divider.tsx +6 -4
- package/src/components/Divider/Divider.vue +13 -16
- package/src/components/DropdownMenu/DropdownMenu.module.css +8 -6
- package/src/components/DropdownMenu/DropdownMenu.tsx +11 -8
- package/src/components/DropdownMenu/DropdownMenu.vue +24 -27
- package/src/components/EmptyState/EmptyState.module.css +6 -4
- package/src/components/EmptyState/EmptyState.tsx +6 -6
- package/src/components/EmptyState/EmptyState.vue +14 -17
- package/src/components/Fab/Fab.module.css +19 -17
- package/src/components/Fab/Fab.tsx +11 -9
- package/src/components/Fab/Fab.vue +29 -26
- package/src/components/Fieldset/Fieldset.module.css +2 -0
- package/src/components/Fieldset/Fieldset.tsx +4 -3
- package/src/components/Fieldset/Fieldset.vue +4 -4
- package/src/components/FormField/FormField.module.css +5 -3
- package/src/components/FormField/FormField.tsx +7 -7
- package/src/components/FormField/FormField.vue +4 -4
- package/src/components/Grid/Grid.module.css +2 -0
- package/src/components/Grid/Grid.tsx +1 -1
- package/src/components/Grid/Grid.vue +25 -22
- package/src/components/HoldToConfirm/HoldToConfirm.module.css +13 -11
- package/src/components/HoldToConfirm/HoldToConfirm.tsx +11 -9
- package/src/components/HoldToConfirm/HoldToConfirm.vue +37 -32
- package/src/components/IconButton/IconButton.module.css +7 -5
- package/src/components/IconButton/IconButton.tsx +2 -1
- package/src/components/IconButton/IconButton.vue +15 -14
- package/src/components/Input/Input.module.css +12 -10
- package/src/components/Input/Input.tsx +9 -7
- package/src/components/Input/Input.vue +45 -35
- package/src/components/InputGroup/InputGroup.module.css +8 -6
- package/src/components/InputGroup/InputGroup.tsx +5 -4
- package/src/components/InputGroup/InputGroup.vue +41 -36
- package/src/components/Kbd/Kbd.module.css +9 -7
- package/src/components/Kbd/Kbd.tsx +1 -1
- package/src/components/Kbd/Kbd.vue +1 -1
- package/src/components/Link/Link.module.css +4 -2
- package/src/components/Link/Link.tsx +4 -3
- package/src/components/Link/Link.vue +13 -16
- package/src/components/LivePill/LivePill.module.css +39 -37
- package/src/components/LivePill/LivePill.tsx +11 -10
- package/src/components/LivePill/LivePill.vue +38 -40
- package/src/components/Meter/Meter.module.css +5 -3
- package/src/components/Meter/Meter.tsx +9 -8
- package/src/components/Meter/Meter.vue +52 -43
- package/src/components/MorphButton/MorphButton.module.css +11 -9
- package/src/components/MorphButton/MorphButton.tsx +20 -10
- package/src/components/MorphButton/MorphButton.vue +29 -25
- package/src/components/NumberInput/NumberInput.module.css +7 -5
- package/src/components/NumberInput/NumberInput.tsx +11 -8
- package/src/components/NumberInput/NumberInput.vue +69 -57
- package/src/components/Pagination/Pagination.module.css +147 -5
- package/src/components/Pagination/Pagination.tsx +216 -41
- package/src/components/Pagination/Pagination.vue +201 -36
- package/src/components/Pagination/labels.ts +38 -0
- package/src/components/PasswordInput/PasswordInput.module.css +10 -8
- package/src/components/PasswordInput/PasswordInput.tsx +15 -7
- package/src/components/PasswordInput/PasswordInput.vue +20 -16
- package/src/components/PasswordInput/index.ts +1 -1
- package/src/components/PickerWheel/DateWheel.vue +20 -12
- package/src/components/PickerWheel/PickerWheel.module.css +15 -6
- package/src/components/PickerWheel/PickerWheel.tsx +70 -44
- package/src/components/PickerWheel/PickerWheel.vue +39 -38
- package/src/components/PickerWheel/TimeWheel.vue +23 -21
- package/src/components/PickerWheel/WheelColumn.vue +7 -5
- package/src/components/Popover/Popover.module.css +5 -3
- package/src/components/Popover/Popover.tsx +17 -8
- package/src/components/Popover/Popover.vue +26 -25
- package/src/components/ProgressBar/ProgressBar.module.css +4 -2
- package/src/components/ProgressBar/ProgressBar.tsx +6 -5
- package/src/components/ProgressBar/ProgressBar.vue +28 -25
- package/src/components/Prose/Prose.module.css +5 -3
- package/src/components/Prose/Prose.tsx +1 -1
- package/src/components/Prose/Prose.vue +5 -8
- package/src/components/Radio/Radio.module.css +10 -8
- package/src/components/Radio/Radio.tsx +10 -8
- package/src/components/Radio/Radio.vue +8 -8
- package/src/components/Radio/RadioGroup.vue +33 -35
- package/src/components/Radio/radioContext.ts +12 -0
- package/src/components/Retime/Retime.vue +25 -22
- package/src/components/RulerScrubber/RulerScrubber.module.css +11 -2
- package/src/components/RulerScrubber/RulerScrubber.tsx +19 -18
- package/src/components/RulerScrubber/RulerScrubber.vue +50 -54
- package/src/components/ScrollArea/ScrollArea.module.css +17 -15
- package/src/components/ScrollArea/ScrollArea.tsx +5 -4
- package/src/components/ScrollArea/ScrollArea.vue +15 -17
- package/src/components/SearchInput/SearchInput.module.css +6 -4
- package/src/components/SearchInput/SearchInput.tsx +15 -8
- package/src/components/SearchInput/SearchInput.vue +20 -17
- package/src/components/SearchInput/index.ts +1 -1
- package/src/components/SegmentedControl/SegmentedControl.module.css +7 -5
- package/src/components/SegmentedControl/SegmentedControl.tsx +9 -5
- package/src/components/SegmentedControl/SegmentedControl.vue +25 -29
- package/src/components/Select/Select.module.css +19 -17
- package/src/components/Select/Select.tsx +30 -17
- package/src/components/Select/Select.vue +62 -57
- package/src/components/Sheet/Sheet.module.css +6 -4
- package/src/components/Sheet/Sheet.tsx +39 -29
- package/src/components/Sheet/Sheet.vue +46 -40
- package/src/components/Skeleton/Skeleton.module.css +4 -2
- package/src/components/Skeleton/Skeleton.tsx +3 -2
- package/src/components/Skeleton/Skeleton.vue +16 -18
- package/src/components/Slider/Slider.module.css +14 -12
- package/src/components/Slider/Slider.tsx +20 -9
- package/src/components/Slider/Slider.vue +47 -37
- package/src/components/Spinner/Spinner.module.css +2 -0
- package/src/components/Spinner/Spinner.tsx +3 -3
- package/src/components/Spinner/Spinner.vue +9 -12
- package/src/components/Split/Split.module.css +2 -0
- package/src/components/Split/Split.tsx +3 -3
- package/src/components/Split/Split.vue +19 -17
- package/src/components/SplitFlap/SplitFlap.module.css +9 -7
- package/src/components/SplitFlap/SplitFlap.tsx +2 -2
- package/src/components/SplitFlap/SplitFlap.vue +24 -21
- package/src/components/Stack/Stack.module.css +2 -0
- package/src/components/Stack/Stack.tsx +1 -1
- package/src/components/Stack/Stack.vue +13 -12
- package/src/components/SwipeDeck/SwipeDeck.module.css +13 -11
- package/src/components/SwipeDeck/SwipeDeck.tsx +23 -28
- package/src/components/SwipeDeck/SwipeDeck.vue +32 -38
- package/src/components/Switch/Switch.module.css +10 -8
- package/src/components/Switch/Switch.tsx +6 -5
- package/src/components/Switch/Switch.vue +22 -24
- package/src/components/Table/Table.module.css +24 -22
- package/src/components/Table/Table.tsx +27 -30
- package/src/components/Table/Table.vue +93 -79
- package/src/components/TableOfContents/TableOfContents.module.css +9 -7
- package/src/components/TableOfContents/TableOfContents.tsx +8 -8
- package/src/components/TableOfContents/TableOfContents.vue +20 -23
- package/src/components/Tabs/Tab.vue +3 -0
- package/src/components/Tabs/TabList.vue +2 -2
- package/src/components/Tabs/TabPanel.vue +2 -0
- package/src/components/Tabs/Tabs.module.css +4 -2
- package/src/components/Tabs/Tabs.tsx +10 -5
- package/src/components/Tabs/Tabs.vue +1 -1
- package/src/components/Tag/Tag.module.css +12 -10
- package/src/components/Tag/Tag.tsx +13 -15
- package/src/components/Tag/Tag.vue +12 -14
- package/src/components/Textarea/Textarea.module.css +8 -6
- package/src/components/Textarea/Textarea.tsx +4 -3
- package/src/components/Textarea/Textarea.vue +32 -34
- package/src/components/ThemeToggle/ThemeToggle.module.css +2 -0
- package/src/components/ThemeToggle/ThemeToggle.tsx +7 -7
- package/src/components/ThemeToggle/ThemeToggle.vue +24 -22
- package/src/components/Toast/Toast.module.css +17 -15
- package/src/components/Toast/Toast.tsx +51 -34
- package/src/components/Toast/Toast.vue +35 -24
- package/src/components/Toast/ToastItem.vue +17 -16
- package/src/components/Toggle/Toggle.module.css +11 -9
- package/src/components/Toggle/Toggle.tsx +3 -2
- package/src/components/Toggle/Toggle.vue +13 -15
- package/src/components/Tooltip/Tooltip.module.css +5 -3
- package/src/components/Tooltip/Tooltip.tsx +1 -0
- package/src/components/Tooltip/Tooltip.vue +13 -18
- package/src/components/VisuallyHidden/VisuallyHidden.module.css +2 -0
- package/src/components/VisuallyHidden/VisuallyHidden.tsx +1 -1
- package/src/components/VisuallyHidden/VisuallyHidden.vue +5 -8
- package/src/{internal → icons}/icons.module.css +4 -2
- package/src/{internal → icons}/icons.tsx +15 -16
- package/src/internal/FieldMessage.module.css +5 -3
- package/src/internal/FieldMessage.tsx +2 -2
- package/src/internal/FieldMessage.vue +2 -2
- package/src/internal/Roll.module.css +5 -3
- package/src/internal/feel.ts +12 -10
- package/src/internal/fling.ts +3 -3
- package/src/internal/liquid.ts +12 -10
- package/src/internal/liquidMatter.ts +1 -1
- package/src/internal/liquidMore.ts +7 -7
- package/src/internal/motion/checkbox.ts +4 -4
- package/src/internal/motion/fling.ts +19 -9
- package/src/internal/motion/holdToConfirm.ts +3 -3
- package/src/internal/motion/index.ts +8 -6
- package/src/internal/motion/liquid.ts +16 -4
- package/src/internal/motion/liquidMatter.ts +8 -6
- package/src/internal/motion/liquidMore.ts +44 -25
- package/src/internal/motion/livePill.ts +1 -1
- package/src/internal/motion/numberInput.ts +2 -2
- package/src/internal/motion/pickerWheel.ts +7 -4
- package/src/internal/motion/ruler.ts +1 -1
- package/src/internal/motion/scrollArea.ts +3 -3
- package/src/internal/motion/scrollFrame.ts +9 -7
- package/src/internal/motion/scrubber.ts +39 -20
- package/src/internal/motion/slider.ts +38 -4
- package/src/internal/motion/softPress.ts +10 -9
- package/src/internal/motion/splitFlap.ts +4 -4
- package/src/internal/motion/swipeDeck.ts +38 -7
- package/src/internal/motion/table.ts +3 -6
- package/src/internal/motion/themeIcon.ts +1 -1
- package/src/internal/motion/themeReveal.ts +1 -1
- package/src/internal/motion/toast.ts +3 -3
- package/src/internal/motion.ts +7 -8
- package/src/internal/scrollFrame.ts +3 -3
- package/src/internal/useScrub.ts +1 -15
- package/src/internal/vue/useScrub.ts +2 -6
- package/src/tokens.css +81 -421
- package/src/{internal/vueIcons.ts → icons/vue.ts} +5 -5
|
@@ -209,15 +209,24 @@ function nearestOn(cl: Ring, x: number, y: number) {
|
|
|
209
209
|
return best
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
export type EdgeFlowOptions = {
|
|
213
|
+
/** A selector: the edge shows while the field matches it, such as ':focus-within'. */
|
|
214
|
+
when: string
|
|
215
|
+
/** The drawing's class. */
|
|
216
|
+
className: string
|
|
217
|
+
/** Where the drawing goes: the field itself (the default), or a wrapper for a textarea. */
|
|
218
|
+
root?: HTMLElement
|
|
219
|
+
}
|
|
220
|
+
|
|
212
221
|
/**
|
|
213
|
-
* Field focus: while `el` matches `
|
|
214
|
-
* (the field's focus indicator, --gooee-
|
|
222
|
+
* Field focus: while `el` matches `when`, it carries data-edge, which its CSS draws as the dark edge
|
|
223
|
+
* (the field's focus indicator, --gooee-focus-width thick). The drawing is filled with --gooee-flow-edge.
|
|
215
224
|
* When it starts to match, the edge first flows both ways round from where it was pressed (or from the
|
|
216
225
|
* start edge for a key) and meets on the far side, then data-edge lands; when it stops mid-flow, the
|
|
217
|
-
* drawing fades.
|
|
226
|
+
* drawing fades. `destroy` when the field goes.
|
|
218
227
|
*/
|
|
219
|
-
export function
|
|
220
|
-
let shown = el.matches(
|
|
228
|
+
export function createEdgeFlow(el: HTMLElement, { when, className, root = el }: EdgeFlowOptions) {
|
|
229
|
+
let shown = el.matches(when)
|
|
221
230
|
if (shown) el.dataset.edge = ''
|
|
222
231
|
let pressed: { x: number; y: number; t: number } | null = null
|
|
223
232
|
let run: { svg: SVGSVGElement; stop: () => void } | null = null
|
|
@@ -235,8 +244,8 @@ export function edgeFlow(el: HTMLElement, root: HTMLElement, on: string, cls: st
|
|
|
235
244
|
const ms = motionFor('base') + motionFor('instant')
|
|
236
245
|
if (!ms) return settle()
|
|
237
246
|
const look = getComputedStyle(el)
|
|
238
|
-
// The settled edge is a focus indicator: --gooee-
|
|
239
|
-
const bw = parseFloat(look.getPropertyValue('--gooee-
|
|
247
|
+
// The settled edge is a focus indicator: --gooee-focus-width thick, inside the border box.
|
|
248
|
+
const bw = parseFloat(look.getPropertyValue('--gooee-focus-width')) || 2
|
|
240
249
|
const r = parseFloat(look.borderTopLeftRadius) || 0
|
|
241
250
|
const rect = el.getBoundingClientRect()
|
|
242
251
|
let W = el.offsetWidth
|
|
@@ -248,7 +257,7 @@ export function edgeFlow(el: HTMLElement, root: HTMLElement, on: string, cls: st
|
|
|
248
257
|
const i0 = fresh ? nearestOn(cl, pressed!.x - rect.left, pressed!.y - rect.top) : nearestOn(cl, rtl ? W : 0, H / 2)
|
|
249
258
|
let at = i0 / cl.length
|
|
250
259
|
pressed = null
|
|
251
|
-
const { svg, paths } = layer(root,
|
|
260
|
+
const { svg, paths } = layer(root, className, null)
|
|
252
261
|
const path = paths[0]
|
|
253
262
|
path.style.fill = look.getPropertyValue('--gooee-flow-edge').trim() || 'currentColor'
|
|
254
263
|
path.setAttribute('fill-rule', 'evenodd')
|
|
@@ -288,7 +297,7 @@ export function edgeFlow(el: HTMLElement, root: HTMLElement, on: string, cls: st
|
|
|
288
297
|
fade.finished.then(() => run === r && end(), () => {})
|
|
289
298
|
}
|
|
290
299
|
const check = () => {
|
|
291
|
-
const now = el.matches(
|
|
300
|
+
const now = el.matches(when)
|
|
292
301
|
if (now === shown) return
|
|
293
302
|
shown = now
|
|
294
303
|
if (now) start()
|
|
@@ -302,17 +311,19 @@ export function edgeFlow(el: HTMLElement, root: HTMLElement, on: string, cls: st
|
|
|
302
311
|
pressed = { x: ev.clientX, y: ev.clientY, t: performance.now() }
|
|
303
312
|
}
|
|
304
313
|
const watch = new MutationObserver(check)
|
|
305
|
-
watch.observe(el, { attributes: true, attributeFilter: ['data-
|
|
314
|
+
watch.observe(el, { attributes: true, attributeFilter: ['data-state', 'data-invalid'] })
|
|
306
315
|
el.addEventListener('pointerdown', down, true)
|
|
307
316
|
el.addEventListener('focusin', later)
|
|
308
317
|
el.addEventListener('focusout', later)
|
|
309
|
-
return
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
318
|
+
return {
|
|
319
|
+
destroy() {
|
|
320
|
+
watch.disconnect()
|
|
321
|
+
el.removeEventListener('pointerdown', down, true)
|
|
322
|
+
el.removeEventListener('focusin', later)
|
|
323
|
+
el.removeEventListener('focusout', later)
|
|
324
|
+
end()
|
|
325
|
+
delete el.dataset.edge
|
|
326
|
+
},
|
|
316
327
|
}
|
|
317
328
|
}
|
|
318
329
|
|
|
@@ -391,7 +402,7 @@ export function checkLoops(m: number, g: CheckMorph): Pt[][] {
|
|
|
391
402
|
/** Where a copy run is: front filled, back slid under, square morphed into the check, each 0 to 1. */
|
|
392
403
|
export type CopyState = { fill: number; slide: number; morph: number }
|
|
393
404
|
|
|
394
|
-
// The copy icon (
|
|
405
|
+
// The copy icon (icons/icons CopyIcon) in its 24-unit box, and the check's corner and arms.
|
|
395
406
|
const ICON = { front: 8.5, size: 11, r: 2.5, back: 4, stroke: 1.75, B: [9.5, 17] as Pt, L1: 4.5 * Math.SQRT2, L2: 9.5 * Math.SQRT2, check: 2.25 }
|
|
396
407
|
const BACK_D = 'M15.5 8.5V6.5a2 2 0 0 0-2-2h-7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h2'
|
|
397
408
|
|
|
@@ -562,14 +573,20 @@ export function beadLoops(cx: number, hw: number, r: number, F: { y: number; hh:
|
|
|
562
573
|
return trace(sdf, [[cx, F.y, 1, 0]])
|
|
563
574
|
}
|
|
564
575
|
|
|
576
|
+
export type BeadOptions = {
|
|
577
|
+
/** The drawing's class. */
|
|
578
|
+
className: string
|
|
579
|
+
}
|
|
580
|
+
|
|
565
581
|
/**
|
|
566
582
|
* Menu items: the hover fill is a bead that follows focus (which follows the pointer) from item to
|
|
567
583
|
* item. A next item settles in about 100ms with a slight stretch; a jump of two or more stretches a
|
|
568
584
|
* short neck. While it moves `root` (the menu panel) carries data-bead, so the items' own fill stands down; at rest
|
|
569
585
|
* the focused item's CSS fill is back. Focus leaving the panel mid-move fades the bead where it is.
|
|
570
|
-
* Only this panel's own items count (submenus sit
|
|
586
|
+
* The bead is filled with the item's --gooee-bead. Only this panel's own items count (submenus sit
|
|
587
|
+
* inside it). `destroy` when the menu goes.
|
|
571
588
|
*/
|
|
572
|
-
export function
|
|
589
|
+
export function createBead(root: HTMLElement, { className }: BeadOptions) {
|
|
573
590
|
const st = { F: 0, T: 0, hF: 0, hT: 0 }
|
|
574
591
|
let goal: HTMLElement | null = null
|
|
575
592
|
let run: { svg: SVGSVGElement; path: SVGPathElement; id: number; last: number } | null = null
|
|
@@ -642,7 +659,7 @@ export function bead(root: HTMLElement, cls: string) {
|
|
|
642
659
|
const b = boxOf(from)
|
|
643
660
|
st.F = st.T = b.y + b.h / 2
|
|
644
661
|
st.hF = st.hT = b.h / 2
|
|
645
|
-
const { svg, paths } = layer(root,
|
|
662
|
+
const { svg, paths } = layer(root, className, root.firstChild)
|
|
646
663
|
svg.setAttribute('width', `${root.scrollWidth}`)
|
|
647
664
|
svg.setAttribute('height', `${root.scrollHeight}`)
|
|
648
665
|
paths[0].setAttribute('data-measure', 'shape')
|
|
@@ -668,9 +685,11 @@ export function bead(root: HTMLElement, cls: string) {
|
|
|
668
685
|
}
|
|
669
686
|
root.addEventListener('focusin', focusIn)
|
|
670
687
|
root.addEventListener('focusout', focusOut)
|
|
671
|
-
return
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
688
|
+
return {
|
|
689
|
+
destroy() {
|
|
690
|
+
root.removeEventListener('focusin', focusIn)
|
|
691
|
+
root.removeEventListener('focusout', focusOut)
|
|
692
|
+
end()
|
|
693
|
+
},
|
|
675
694
|
}
|
|
676
695
|
}
|
|
@@ -66,6 +66,6 @@ export function pillOutside(shell: () => HTMLElement | null, button: () => HTMLE
|
|
|
66
66
|
|
|
67
67
|
/** A card an alert opened shrinks back after alertMs, never sooner than its own open motion. Returns a stop function. */
|
|
68
68
|
export function pillAlertTimer(alertMs: number, onDone: () => void) {
|
|
69
|
-
const t = window.setTimeout(onDone, Math.max(alertMs, motionMs('
|
|
69
|
+
const t = window.setTimeout(onDone, Math.max(alertMs, motionMs('morph')))
|
|
70
70
|
return () => window.clearTimeout(t)
|
|
71
71
|
}
|
|
@@ -49,9 +49,9 @@ export function createHold() {
|
|
|
49
49
|
if (atEnd()) return stop()
|
|
50
50
|
count++
|
|
51
51
|
bump(count > 12)
|
|
52
|
-
timer = window.setTimeout(tick, tokenMs('--gooee-
|
|
52
|
+
timer = window.setTimeout(tick, tokenMs('--gooee-delay-number-input-repeat-every', 70))
|
|
53
53
|
}
|
|
54
|
-
timer = window.setTimeout(tick, tokenMs('--gooee-
|
|
54
|
+
timer = window.setTimeout(tick, tokenMs('--gooee-delay-number-input-repeat', 400))
|
|
55
55
|
}
|
|
56
56
|
return { start, stop }
|
|
57
57
|
}
|
|
@@ -71,7 +71,7 @@ export function columnScrub(column: WheelColumn, index: number, state: ColumnSta
|
|
|
71
71
|
tap: (e, at) => {
|
|
72
72
|
const el = e.currentTarget as HTMLElement
|
|
73
73
|
const r = el.getBoundingClientRect()
|
|
74
|
-
const tilt = (tokenNumber(el, '--gooee-wheel-tilt') * Math.PI) / 180
|
|
74
|
+
const tilt = (tokenNumber(el, '--gooee-picker-wheel-tilt') * Math.PI) / 180
|
|
75
75
|
const radius = state.row / 2 / Math.tan(tilt / 2)
|
|
76
76
|
const dy = e.clientY - (r.top + r.height / 2)
|
|
77
77
|
if (!tilt || !radius) return null
|
|
@@ -100,9 +100,12 @@ export function drumRows(at: number, n: number, loop: boolean) {
|
|
|
100
100
|
const pad = (v: number) => String(v).padStart(2, '0')
|
|
101
101
|
|
|
102
102
|
/** A time wheel: hour, minute and, on a 12 hour clock, AM or PM, and the turns between rows and "HH:mm". */
|
|
103
|
-
|
|
103
|
+
/** 12 or 24: the hour cycle a locale uses. Undefined is the browser's locale. */
|
|
104
|
+
export const localeHourCycle = (locale?: string): 12 | 24 => (new Intl.DateTimeFormat(locale, { hour: 'numeric' }).resolvedOptions().hour12 ? 12 : 24)
|
|
105
|
+
|
|
106
|
+
export function timeWheel(hourCycle: 12 | 24, step: number, strong: number[]) {
|
|
104
107
|
const twelve = hourCycle === 12
|
|
105
|
-
const minutes = Array.from({ length: Math.ceil(60 /
|
|
108
|
+
const minutes = Array.from({ length: Math.ceil(60 / step) }, (_, i) => i * step)
|
|
106
109
|
const columns: WheelColumn[] = [
|
|
107
110
|
{ label: 'Hour', options: twelve ? Array.from({ length: 12 }, (_, i) => String(i + 1)) : Array.from({ length: 24 }, (_, i) => pad(i)), loop: true },
|
|
108
111
|
{ label: 'Minute', options: minutes.map(pad), loop: true, strong: strong.map((m) => minutes.indexOf(m)).filter((i) => i >= 0) },
|
|
@@ -112,7 +115,7 @@ export function timeWheel(hourCycle: 12 | 24, minuteStep: number, strong: number
|
|
|
112
115
|
columns,
|
|
113
116
|
toRows(hhmm: string) {
|
|
114
117
|
const [h = 0, m = 0] = hhmm.split(':').map(Number)
|
|
115
|
-
const mi = clamp(Math.round(m /
|
|
118
|
+
const mi = clamp(Math.round(m / step), 0, minutes.length - 1)
|
|
116
119
|
return twelve ? [(h % 12 || 12) - 1, mi, h >= 12 ? 1 : 0] : [h, mi]
|
|
117
120
|
},
|
|
118
121
|
toTime(rows: number[]) {
|
|
@@ -52,6 +52,6 @@ export function rulerScrub(p: RulerScale, fit: RulerFit, wheel: ReturnType<typeo
|
|
|
52
52
|
|
|
53
53
|
/** Measures the ruler: the tick gap token, the ticks that fit, its width and the tag's. */
|
|
54
54
|
export function measureRuler(el: HTMLElement, tag: HTMLElement | null): RulerFit {
|
|
55
|
-
const gap = parseFloat(getComputedStyle(el).getPropertyValue('--gooee-ruler-tick-gap')) || 0
|
|
55
|
+
const gap = parseFloat(getComputedStyle(el).getPropertyValue('--gooee-ruler-scrubber-tick-gap')) || 0
|
|
56
56
|
return { gap, span: gap ? Math.ceil(el.clientWidth / 2 / gap) + 1 : 24, width: el.clientWidth, tag: tag?.offsetWidth ?? 0 }
|
|
57
57
|
}
|
|
@@ -35,7 +35,7 @@ export function createScrollArea({ root, viewport, thumb }: Parts) {
|
|
|
35
35
|
if (!overflow) return
|
|
36
36
|
const pad = parseFloat(getComputedStyle(track).paddingTop) || 0
|
|
37
37
|
const trackLen = (axis === 'y' ? track.clientHeight : track.clientWidth) - pad * 2
|
|
38
|
-
const minThumb = parseFloat(getComputedStyle(el).getPropertyValue('--gooee-
|
|
38
|
+
const minThumb = parseFloat(getComputedStyle(el).getPropertyValue('--gooee-scroll-area-thumb-min')) || 24
|
|
39
39
|
const len = Math.max(minThumb, (size / full) * trackLen)
|
|
40
40
|
const offset = (pos / (full - size)) * (trackLen - len)
|
|
41
41
|
if (axis === 'y') {
|
|
@@ -53,10 +53,10 @@ export function createScrollArea({ root, viewport, thumb }: Parts) {
|
|
|
53
53
|
const wake = () => {
|
|
54
54
|
const el = root()
|
|
55
55
|
if (!el) return
|
|
56
|
-
el.setAttribute('data-
|
|
56
|
+
el.setAttribute('data-scrolling', '')
|
|
57
57
|
window.clearTimeout(idle)
|
|
58
58
|
idle = window.setTimeout(() => {
|
|
59
|
-
if (!drag) el.removeAttribute('data-
|
|
59
|
+
if (!drag) el.removeAttribute('data-scrolling')
|
|
60
60
|
}, IDLE_MS)
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -21,7 +21,7 @@ let tokens: ScrollTokens | null = null
|
|
|
21
21
|
export function readScrollTokens(): ScrollTokens {
|
|
22
22
|
const s = getComputedStyle(document.documentElement)
|
|
23
23
|
const n = (name: string) => parseFloat(s.getPropertyValue(name))
|
|
24
|
-
return { ease: n('--gooee-scroll-ease'), start: n('--gooee-draft-start'), end: n('--gooee-draft-end'), turn: n('--gooee-story-turn'), turnNarrow: n('--gooee-story-turn-narrow') }
|
|
24
|
+
return { ease: n('--gooee-scroll-ease'), start: n('--gooee-scroll-draft-start'), end: n('--gooee-scroll-draft-end'), turn: n('--gooee-scroll-story-turn'), turnNarrow: n('--gooee-scroll-story-turn-narrow') }
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/** The tokens, read once each time the loop starts or the window changes size. */
|
|
@@ -126,19 +126,21 @@ function stop() {
|
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
128
|
* Calls `read` once (with the other parts that start in the same task, before the first paint) and then
|
|
129
|
-
* every frame while the page moves
|
|
129
|
+
* every frame while the page moves, until `destroy`.
|
|
130
130
|
*/
|
|
131
|
-
export function
|
|
131
|
+
export function createScrollFrame(read: ScrollReader) {
|
|
132
132
|
const ref = { current: read }
|
|
133
133
|
if (!readers.size) start()
|
|
134
134
|
readers.add(ref)
|
|
135
135
|
mounting.add(ref)
|
|
136
136
|
if (mounting.size === 1) queueMicrotask(runMounts)
|
|
137
137
|
wake()
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
return {
|
|
139
|
+
destroy() {
|
|
140
|
+
if (!readers.delete(ref)) return
|
|
141
|
+
mounting.delete(ref)
|
|
142
|
+
if (!readers.size) stop()
|
|
143
|
+
},
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createScrub, type ScrubOptions } from '../feel'
|
|
2
|
-
import { morphCurve,
|
|
2
|
+
import { morphCurve, motionMs } from '../motion'
|
|
3
3
|
|
|
4
4
|
// Pointer, keys and wheel in, the drawn position out, for Dial, RulerScrubber and PickerWheel. The
|
|
5
5
|
// motion itself lives in feel.ts (createScrub).
|
|
@@ -13,8 +13,9 @@ type KeyLike = Pick<KeyboardEvent, 'key' | 'altKey' | 'ctrlKey' | 'metaKey' | 'p
|
|
|
13
13
|
export type ScrubberOptions<P extends PointerLike = PointerEvent> = Pick<ScrubOptions, 'min' | 'max' | 'edge' | 'land' | 'coast' | 'maxSpeed'> & {
|
|
14
14
|
/** The value it starts at, and later the value from outside: `sync` glides there. */
|
|
15
15
|
value: number
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/** It came to rest on a new value. `from` is where it rested before. */
|
|
17
|
+
onSettle: (value: number, from: number) => void
|
|
18
|
+
/** A new resting value came under it while it moves. */
|
|
18
19
|
onMark?: (value: number) => void
|
|
19
20
|
/** How far a pointer move turns the value, in its units. */
|
|
20
21
|
move: (e: P, last: Last, el: HTMLElement) => number
|
|
@@ -37,14 +38,22 @@ type Press = { id: number; sx: number; sy: number; x: number; y: number; moved:
|
|
|
37
38
|
// A press is not a drag until it moves this far, so a tap stays a tap.
|
|
38
39
|
const SLOP = 4
|
|
39
40
|
|
|
40
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* A scrubbed value: feed it the control's events, or call `listen` on the control. `update` takes new
|
|
43
|
+
* options. `destroy` stops the glide and every listener.
|
|
44
|
+
*/
|
|
41
45
|
export function createScrubber<P extends PointerLike = PointerEvent>(options: ScrubberOptions<P>) {
|
|
42
46
|
let o = options
|
|
43
47
|
let press: Press | null = null
|
|
48
|
+
let ac = new AbortController()
|
|
49
|
+
let wheelEl: HTMLElement | null = null
|
|
50
|
+
// Where it last rested. The value from outside can move on while it moves (a parent that follows each
|
|
51
|
+
// new value), so a landing is compared with this, not with that value.
|
|
52
|
+
let rest = o.value
|
|
44
53
|
const s = createScrub({
|
|
45
54
|
value: o.value,
|
|
46
55
|
land: (p) => o.land(p),
|
|
47
|
-
duration: () =>
|
|
56
|
+
duration: () => motionMs('morph-out'),
|
|
48
57
|
curve: morphCurve,
|
|
49
58
|
onFrame: (v) => o.onFrame?.(v),
|
|
50
59
|
onMoving: (m) => o.onMoving?.(m),
|
|
@@ -53,7 +62,12 @@ export function createScrubber<P extends PointerLike = PointerEvent>(options: Sc
|
|
|
53
62
|
if (o.haptics) navigator.vibrate?.(5)
|
|
54
63
|
},
|
|
55
64
|
// Only a new value is news: a tap, Home at the start, or a drag back to where it was says nothing.
|
|
56
|
-
onSettle: (v) =>
|
|
65
|
+
onSettle: (v) => {
|
|
66
|
+
if (v === rest) return
|
|
67
|
+
const from = rest
|
|
68
|
+
rest = v
|
|
69
|
+
o.onSettle(v, from)
|
|
70
|
+
},
|
|
57
71
|
})
|
|
58
72
|
const update = (next: ScrubberOptions<P>) => {
|
|
59
73
|
o = next
|
|
@@ -101,16 +115,17 @@ export function createScrubber<P extends PointerLike = PointerEvent>(options: Sc
|
|
|
101
115
|
s.go(t)
|
|
102
116
|
}
|
|
103
117
|
|
|
104
|
-
/** Lets the wheel turn it, when `wheel` is set
|
|
105
|
-
const
|
|
118
|
+
/** Lets the wheel turn it, when `wheel` is set, until `destroy`. */
|
|
119
|
+
const listenWheel = (el: HTMLElement) => {
|
|
120
|
+
if (wheelEl === el) return
|
|
121
|
+
wheelEl = el
|
|
106
122
|
const onWheel = (e: WheelEvent) => {
|
|
107
123
|
const t = o.wheel?.(e, s.target, document.activeElement === el) ?? null
|
|
108
124
|
if (t === null) return
|
|
109
125
|
e.preventDefault()
|
|
110
126
|
if (t !== s.target) s.go(t)
|
|
111
127
|
}
|
|
112
|
-
el.addEventListener('wheel', onWheel, { passive: false })
|
|
113
|
-
return () => el.removeEventListener('wheel', onWheel)
|
|
128
|
+
el.addEventListener('wheel', onWheel, { passive: false, signal: ac.signal })
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
return {
|
|
@@ -118,10 +133,11 @@ export function createScrubber<P extends PointerLike = PointerEvent>(options: Sc
|
|
|
118
133
|
move,
|
|
119
134
|
up,
|
|
120
135
|
keyDown,
|
|
121
|
-
|
|
136
|
+
listenWheel,
|
|
122
137
|
/** A value set from outside (a controlled prop, a reset) glides there, unless the hand holds it. */
|
|
123
138
|
sync(value: number) {
|
|
124
139
|
if (press || s.moving || value === s.target) return
|
|
140
|
+
rest = value
|
|
125
141
|
s.go(value)
|
|
126
142
|
},
|
|
127
143
|
update,
|
|
@@ -133,22 +149,25 @@ export function createScrubber<P extends PointerLike = PointerEvent>(options: Sc
|
|
|
133
149
|
},
|
|
134
150
|
target: () => s.target,
|
|
135
151
|
go: (to: number) => s.go(to),
|
|
136
|
-
place: (to: number) =>
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
place: (to: number) => {
|
|
153
|
+
rest = to
|
|
154
|
+
s.place(to)
|
|
155
|
+
},
|
|
156
|
+
destroy() {
|
|
157
|
+
s.stop()
|
|
158
|
+
ac.abort()
|
|
159
|
+
ac = new AbortController()
|
|
160
|
+
wheelEl = null
|
|
161
|
+
},
|
|
162
|
+
/** Listens on the control (pointer, keys, and the wheel when `wheel` is set), until `destroy`. */
|
|
139
163
|
listen(el: HTMLElement) {
|
|
140
|
-
const ac = new AbortController()
|
|
141
164
|
const opts = { signal: ac.signal }
|
|
142
165
|
el.addEventListener('pointerdown', (e) => down(e as unknown as P), opts)
|
|
143
166
|
el.addEventListener('pointermove', (e) => move(e as unknown as P), opts)
|
|
144
167
|
el.addEventListener('pointerup', (e) => up(e as unknown as P), opts)
|
|
145
168
|
el.addEventListener('pointercancel', (e) => up(e as unknown as P), opts)
|
|
146
169
|
el.addEventListener('keydown', keyDown, opts)
|
|
147
|
-
|
|
148
|
-
return () => {
|
|
149
|
-
ac.abort()
|
|
150
|
-
stopWheel()
|
|
151
|
-
}
|
|
170
|
+
if (o.wheel) listenWheel(el)
|
|
152
171
|
},
|
|
153
172
|
}
|
|
154
173
|
}
|
|
@@ -5,10 +5,11 @@ export type SliderRead = { value: number; min: number; max: number; step: number
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A native range input that glides to a click and lands on a mark let go near it. `read` gives the
|
|
8
|
-
* value and props now; `
|
|
9
|
-
* glides (null once it is at the value)
|
|
8
|
+
* value and props now; `onValue` gets each new value; `onShown` gets where the thumb is drawn while it
|
|
9
|
+
* glides (null once it is at the value); `onCommit` gets the value once the hand or key lets go of it.
|
|
10
|
+
* Wire `down`, `move`, `up`, `end`, `input`, `key` and `keyUp` to the input.
|
|
10
11
|
*/
|
|
11
|
-
export function createSlider(read: () => SliderRead,
|
|
12
|
+
export function createSlider(read: () => SliderRead, onValue: (v: number) => void, onShown: (v: number | null) => void, onCommit?: (v: number) => void) {
|
|
12
13
|
// `grab` is how far from the thumb's centre it was picked up, so the thumb does not jump to the pointer.
|
|
13
14
|
let press: { x: number; lastX: number; moved: boolean; grab: number } | null = null
|
|
14
15
|
let shown: number | null = null
|
|
@@ -19,6 +20,25 @@ export function createSlider(read: () => SliderRead, setValue: (v: number) => vo
|
|
|
19
20
|
}
|
|
20
21
|
const at = () => shown ?? read().value
|
|
21
22
|
|
|
23
|
+
// The value when this touch or key began, and the last one set since. Null when nothing holds it.
|
|
24
|
+
let from: number | null = null
|
|
25
|
+
let last = 0
|
|
26
|
+
const begin = () => {
|
|
27
|
+
if (from !== null) return
|
|
28
|
+
from = read().value
|
|
29
|
+
last = from
|
|
30
|
+
}
|
|
31
|
+
const setValue = (v: number) => {
|
|
32
|
+
last = v
|
|
33
|
+
onValue(v)
|
|
34
|
+
}
|
|
35
|
+
const commit = () => {
|
|
36
|
+
if (from === null) return
|
|
37
|
+
const was = from
|
|
38
|
+
from = null
|
|
39
|
+
if (last !== was) onCommit?.(last)
|
|
40
|
+
}
|
|
41
|
+
|
|
22
42
|
const toStep = (v: number) => {
|
|
23
43
|
const { min, max, step } = read()
|
|
24
44
|
const decimals = (String(step).split('.')[1] ?? '').length
|
|
@@ -57,11 +77,17 @@ export function createSlider(read: () => SliderRead, setValue: (v: number) => vo
|
|
|
57
77
|
const end = () => {
|
|
58
78
|
press = null
|
|
59
79
|
}
|
|
80
|
+
const letGo = () => {
|
|
81
|
+
end()
|
|
82
|
+
commit()
|
|
83
|
+
}
|
|
60
84
|
|
|
61
85
|
return {
|
|
62
86
|
/** The input's "input" event, with the number the browser moved to. */
|
|
63
87
|
input(input: HTMLInputElement, native: number) {
|
|
64
88
|
const p = press
|
|
89
|
+
const held = from !== null
|
|
90
|
+
begin()
|
|
65
91
|
const next = p && read().marks?.length ? toStep(fromPointer(input, p.lastX - p.grab)) : native
|
|
66
92
|
// A press that has not moved is a click: the value jumps, the thumb glides there. Once it moves, the hand leads.
|
|
67
93
|
if (p && !p.moved) glideTo(at(), next)
|
|
@@ -70,6 +96,8 @@ export function createSlider(read: () => SliderRead, setValue: (v: number) => vo
|
|
|
70
96
|
show(null)
|
|
71
97
|
}
|
|
72
98
|
setValue(next)
|
|
99
|
+
// A step from assistive tech, with no hand or key down, rests at once.
|
|
100
|
+
if (!held) commit()
|
|
73
101
|
},
|
|
74
102
|
down(input: HTMLInputElement, x: number) {
|
|
75
103
|
const { value, min, max, marks } = read()
|
|
@@ -77,6 +105,7 @@ export function createSlider(read: () => SliderRead, setValue: (v: number) => vo
|
|
|
77
105
|
const centre = t.left + ((value - min) / (max - min || 1)) * t.width
|
|
78
106
|
const grab = marks?.length && Math.abs(x - centre) <= t.thumb / 2 ? x - centre : 0
|
|
79
107
|
press = { x, lastX: x, moved: false, grab }
|
|
108
|
+
begin()
|
|
80
109
|
},
|
|
81
110
|
move(x: number) {
|
|
82
111
|
if (!press) return
|
|
@@ -92,17 +121,22 @@ export function createSlider(read: () => SliderRead, setValue: (v: number) => vo
|
|
|
92
121
|
glideTo(at(), mark)
|
|
93
122
|
setValue(mark)
|
|
94
123
|
}
|
|
124
|
+
commit()
|
|
95
125
|
},
|
|
96
|
-
|
|
126
|
+
/** The hand or the focus went away (cancel, lost capture, blur): the value rests where it is. */
|
|
127
|
+
end: letGo,
|
|
97
128
|
/** A key down, after the caller's own handler. Returns true when it used the key. */
|
|
98
129
|
key(key: string) {
|
|
99
130
|
end()
|
|
131
|
+
begin()
|
|
100
132
|
const { value, min, max, marks } = read()
|
|
101
133
|
if (!marks?.length || (key !== 'PageUp' && key !== 'PageDown')) return false
|
|
102
134
|
const sorted = [...marks].sort((a, b) => a - b)
|
|
103
135
|
setValue(key === 'PageUp' ? (sorted.find((m) => m > value) ?? max) : ([...sorted].reverse().find((m) => m < value) ?? min))
|
|
104
136
|
return true
|
|
105
137
|
},
|
|
138
|
+
/** A key up: the value rests. */
|
|
139
|
+
keyUp: commit,
|
|
106
140
|
destroy: () => cancelAnimationFrame(glide),
|
|
107
141
|
}
|
|
108
142
|
}
|
|
@@ -47,7 +47,8 @@ type KeyLike = Pick<KeyboardEvent, 'key' | 'repeat'> & { currentTarget: EventTar
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Soft press for one button. Options are read at each event, so they can change. Feed it the button's
|
|
50
|
-
* events, or call `listen` on the button.
|
|
50
|
+
* events, or call `listen` on the button. `stop` ends a press now (call it when the button turns inert);
|
|
51
|
+
* `destroy` also stops listening, when the button goes.
|
|
51
52
|
*/
|
|
52
53
|
export function createSoftPress(o: SoftPressOptions) {
|
|
53
54
|
const s = ({
|
|
@@ -68,6 +69,7 @@ export function createSoftPress(o: SoftPressOptions) {
|
|
|
68
69
|
raf: 0,
|
|
69
70
|
off: () => {},
|
|
70
71
|
})
|
|
72
|
+
let ac = new AbortController()
|
|
71
73
|
|
|
72
74
|
// The shape for the button's size now. Runs again when the size changes while the layer is up, such
|
|
73
75
|
// as a label that changes on click.
|
|
@@ -312,12 +314,15 @@ export function createSoftPress(o: SoftPressOptions) {
|
|
|
312
314
|
keyDown,
|
|
313
315
|
keyUp,
|
|
314
316
|
blur,
|
|
315
|
-
/** Ends any press at once and removes the drawing. */
|
|
317
|
+
/** Ends any press at once and removes the drawing. It keeps working after. */
|
|
316
318
|
stop: teardown,
|
|
317
|
-
destroy
|
|
318
|
-
|
|
319
|
+
destroy() {
|
|
320
|
+
ac.abort()
|
|
321
|
+
ac = new AbortController()
|
|
322
|
+
teardown()
|
|
323
|
+
},
|
|
324
|
+
/** Listens on the button, until `destroy`. */
|
|
319
325
|
listen(button: HTMLElement) {
|
|
320
|
-
const ac = new AbortController()
|
|
321
326
|
const opts = { signal: ac.signal }
|
|
322
327
|
button.addEventListener('pointerdown', down, opts)
|
|
323
328
|
button.addEventListener('pointermove', hover, opts)
|
|
@@ -325,10 +330,6 @@ export function createSoftPress(o: SoftPressOptions) {
|
|
|
325
330
|
button.addEventListener('keydown', keyDown, opts)
|
|
326
331
|
button.addEventListener('keyup', keyUp, opts)
|
|
327
332
|
button.addEventListener('blur', blur, opts)
|
|
328
|
-
return () => {
|
|
329
|
-
ac.abort()
|
|
330
|
-
teardown()
|
|
331
|
-
}
|
|
332
333
|
},
|
|
333
334
|
}
|
|
334
335
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { easing,
|
|
1
|
+
import { easing, motionMs } from '../motion'
|
|
2
2
|
|
|
3
3
|
// SplitFlap's board with no framework: each cell runs forward through its drum to the new letter, and
|
|
4
4
|
// the board's edge grows or folds when the text gets longer or shorter.
|
|
@@ -101,7 +101,7 @@ export function createSplitFlap(b: HTMLElement, look: FlapLook, first: string) {
|
|
|
101
101
|
return
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
const scale =
|
|
104
|
+
const scale = motionMs('fast') / FAST_TOKEN
|
|
105
105
|
// Reduced motion: the new text at once, with no flips and no morph.
|
|
106
106
|
if (!scale) {
|
|
107
107
|
cells = [...target].map((ch) => makeCell(look, ch))
|
|
@@ -113,8 +113,8 @@ export function createSplitFlap(b: HTMLElement, look: FlapLook, first: string) {
|
|
|
113
113
|
const n0 = list.length
|
|
114
114
|
const n1 = target.length
|
|
115
115
|
const radius = getComputedStyle(b).borderRadius || '0px'
|
|
116
|
-
const grow = { duration:
|
|
117
|
-
const shrink = { duration:
|
|
116
|
+
const grow = { duration: motionMs('morph'), easing: easing('morph') }
|
|
117
|
+
const shrink = { duration: motionMs('morph-out'), easing: easing('morph') }
|
|
118
118
|
let left = 0
|
|
119
119
|
const landed = () => {
|
|
120
120
|
if (--left === 0) done()
|