@human-kit/ui 1.0.0-beta.6 → 1.0.0-beta.8
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/FOCUS_STATE_CONTRACT.md +15 -4
- package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
- package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
- package/dist/avatar/README.md +52 -0
- package/dist/avatar/count/avatar-count.svelte +56 -0
- package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
- package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
- package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
- package/dist/avatar/group/avatar-group.svelte +65 -0
- package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
- package/dist/avatar/group/context.d.ts +15 -0
- package/dist/avatar/group/context.js +15 -0
- package/dist/avatar/image/avatar-image.svelte +104 -0
- package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
- package/dist/avatar/index.d.ts +22 -0
- package/dist/avatar/index.js +10 -0
- package/dist/avatar/index.parts.d.ts +5 -0
- package/dist/avatar/index.parts.js +5 -0
- package/dist/avatar/root/avatar-root.svelte +79 -0
- package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
- package/dist/avatar/root/context.d.ts +14 -0
- package/dist/avatar/root/context.js +15 -0
- package/dist/avatar/types.d.ts +84 -0
- package/dist/avatar/types.js +1 -0
- package/dist/breadcrumbs/README.md +65 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
- package/dist/breadcrumbs/index.d.ts +23 -0
- package/dist/breadcrumbs/index.js +10 -0
- package/dist/breadcrumbs/index.parts.d.ts +6 -0
- package/dist/breadcrumbs/index.parts.js +6 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/context.d.ts +19 -0
- package/dist/breadcrumbs/root/context.js +15 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
- package/dist/breadcrumbs/types.d.ts +80 -0
- package/dist/breadcrumbs/types.js +1 -0
- package/dist/button/root/button-root.svelte +9 -0
- package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
- package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
- package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
- package/dist/checkbox/root/checkbox-root.svelte +106 -30
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
- package/dist/checkbox-group/README.md +95 -0
- package/dist/checkbox-group/index.d.ts +15 -0
- package/dist/checkbox-group/index.js +6 -0
- package/dist/checkbox-group/index.parts.d.ts +4 -0
- package/dist/checkbox-group/index.parts.js +7 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
- package/dist/checkbox-group/root/context.svelte.js +251 -0
- package/dist/checkbox-group/types.d.ts +57 -0
- package/dist/checkbox-group/types.js +1 -0
- package/dist/combobox/popover/combobox-popover.svelte +4 -56
- package/dist/dialog/root/dialog-root.svelte +15 -2
- package/dist/drawer/root/drawer-root.svelte +15 -2
- package/dist/index.d.ts +18 -0
- package/dist/index.js +17 -0
- package/dist/internal/localized-strings.d.ts +48 -0
- package/dist/internal/localized-strings.js +48 -0
- package/dist/internal/number-precision.d.ts +9 -0
- package/dist/internal/number-precision.js +27 -0
- package/dist/menu/root/focus-state.d.ts +2 -2
- package/dist/menu/root/focus-state.js +8 -32
- package/dist/menu/root/menu-state.svelte.js +5 -1
- package/dist/numberfield/root/number-utils.js +1 -20
- package/dist/popover/root/focus-state.d.ts +2 -2
- package/dist/popover/root/focus-state.js +7 -34
- package/dist/primitives/contain-wheel.d.ts +9 -0
- package/dist/primitives/contain-wheel.js +41 -0
- package/dist/primitives/floating.d.ts +6 -0
- package/dist/primitives/floating.js +26 -5
- package/dist/primitives/focus-visible.svelte.d.ts +14 -0
- package/dist/primitives/focus-visible.svelte.js +19 -0
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/input-modality.d.ts +7 -0
- package/dist/primitives/input-modality.js +32 -5
- package/dist/primitives/keyboard-navigation.d.ts +6 -0
- package/dist/primitives/keyboard-navigation.js +2 -1
- package/dist/primitives/trigger-focus-state.d.ts +29 -0
- package/dist/primitives/trigger-focus-state.js +57 -0
- package/dist/progress/README.md +54 -0
- package/dist/progress/index.d.ts +21 -0
- package/dist/progress/index.js +9 -0
- package/dist/progress/index.parts.d.ts +5 -0
- package/dist/progress/index.parts.js +5 -0
- package/dist/progress/indicator/progress-indicator.svelte +37 -0
- package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
- package/dist/progress/label/progress-label.svelte +34 -0
- package/dist/progress/label/progress-label.svelte.d.ts +4 -0
- package/dist/progress/root/context.d.ts +26 -0
- package/dist/progress/root/context.js +15 -0
- package/dist/progress/root/progress-root.svelte +136 -0
- package/dist/progress/root/progress-root.svelte.d.ts +4 -0
- package/dist/progress/root/progress-utils.d.ts +12 -0
- package/dist/progress/root/progress-utils.js +41 -0
- package/dist/progress/track/progress-track.svelte +27 -0
- package/dist/progress/track/progress-track.svelte.d.ts +4 -0
- package/dist/progress/types.d.ts +81 -0
- package/dist/progress/types.js +1 -0
- package/dist/progress/value/progress-value.svelte +36 -0
- package/dist/progress/value/progress-value.svelte.d.ts +4 -0
- package/dist/radio-group/README.md +103 -0
- package/dist/radio-group/index.d.ts +18 -0
- package/dist/radio-group/index.js +9 -0
- package/dist/radio-group/index.parts.d.ts +4 -0
- package/dist/radio-group/index.parts.js +4 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
- package/dist/radio-group/item/context.d.ts +18 -0
- package/dist/radio-group/item/context.js +15 -0
- package/dist/radio-group/item/radio-group-item.svelte +377 -0
- package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
- package/dist/radio-group/label/radio-group-label.svelte +37 -0
- package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
- package/dist/radio-group/root/context.svelte.d.ts +57 -0
- package/dist/radio-group/root/context.svelte.js +284 -0
- package/dist/radio-group/root/radio-group-root.svelte +193 -0
- package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
- package/dist/radio-group/types.d.ts +50 -0
- package/dist/radio-group/types.js +1 -0
- package/dist/select/README.md +129 -0
- package/dist/select/index.d.ts +30 -0
- package/dist/select/index.js +16 -0
- package/dist/select/index.parts.d.ts +8 -0
- package/dist/select/index.parts.js +9 -0
- package/dist/select/item/select-item.svelte +68 -0
- package/dist/select/item/select-item.svelte.d.ts +10 -0
- package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
- package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
- package/dist/select/label/select-label.svelte +46 -0
- package/dist/select/label/select-label.svelte.d.ts +4 -0
- package/dist/select/list/select-list.svelte +241 -0
- package/dist/select/list/select-list.svelte.d.ts +62 -0
- package/dist/select/popover/select-popover.svelte +80 -0
- package/dist/select/popover/select-popover.svelte.d.ts +9 -0
- package/dist/select/root/context.d.ts +106 -0
- package/dist/select/root/context.js +22 -0
- package/dist/select/root/select-root.svelte +544 -0
- package/dist/select/root/select-root.svelte.d.ts +25 -0
- package/dist/select/trigger/select-trigger.svelte +192 -0
- package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
- package/dist/select/types.d.ts +133 -0
- package/dist/select/types.js +1 -0
- package/dist/select/value/select-value.svelte +61 -0
- package/dist/select/value/select-value.svelte.d.ts +4 -0
- package/dist/separator/README.md +35 -0
- package/dist/separator/index.d.ts +7 -0
- package/dist/separator/index.js +3 -0
- package/dist/separator/separator.svelte +254 -0
- package/dist/separator/separator.svelte.d.ts +45 -0
- package/dist/separator/types.d.ts +1 -0
- package/dist/separator/types.js +1 -0
- package/dist/slider/README.md +61 -0
- package/dist/slider/fill/slider-fill.svelte +40 -0
- package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
- package/dist/slider/index.d.ts +9 -0
- package/dist/slider/index.js +8 -0
- package/dist/slider/index.parts.d.ts +6 -0
- package/dist/slider/index.parts.js +6 -0
- package/dist/slider/label/slider-label.svelte +44 -0
- package/dist/slider/label/slider-label.svelte.d.ts +4 -0
- package/dist/slider/output/slider-output.svelte +46 -0
- package/dist/slider/output/slider-output.svelte.d.ts +4 -0
- package/dist/slider/root/context.d.ts +106 -0
- package/dist/slider/root/context.js +15 -0
- package/dist/slider/root/slider-root.svelte +545 -0
- package/dist/slider/root/slider-root.svelte.d.ts +4 -0
- package/dist/slider/root/slider-utils.d.ts +57 -0
- package/dist/slider/root/slider-utils.js +88 -0
- package/dist/slider/thumb/slider-thumb.svelte +276 -0
- package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
- package/dist/slider/track/slider-track.svelte +60 -0
- package/dist/slider/track/slider-track.svelte.d.ts +4 -0
- package/dist/slider/types.d.ts +144 -0
- package/dist/slider/types.js +1 -0
- package/dist/switch/root/switch-root.svelte +9 -0
- package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
- package/dist/table/root/table-root.svelte +29 -6
- package/dist/timepicker/input/time-picker-input.svelte +12 -4
- package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
- package/dist/toggle/root/toggle-root.svelte +28 -0
- package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
- package/dist/toggle-group/README.md +6 -4
- package/dist/toggle-group/index.d.ts +2 -0
- package/dist/toggle-group/index.parts.d.ts +1 -0
- package/dist/toggle-group/index.parts.js +4 -0
- package/dist/tooltip/README.md +53 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
- package/dist/tooltip/content/tooltip-content.svelte +148 -0
- package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
- package/dist/tooltip/index.d.ts +8 -0
- package/dist/tooltip/index.js +7 -0
- package/dist/tooltip/index.parts.d.ts +5 -0
- package/dist/tooltip/index.parts.js +5 -0
- package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
- package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
- package/dist/tooltip/root/context.d.ts +46 -0
- package/dist/tooltip/root/context.js +22 -0
- package/dist/tooltip/root/safe-polygon.d.ts +26 -0
- package/dist/tooltip/root/safe-polygon.js +66 -0
- package/dist/tooltip/root/tooltip-group.d.ts +26 -0
- package/dist/tooltip/root/tooltip-group.js +41 -0
- package/dist/tooltip/root/tooltip-root.svelte +454 -0
- package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
- package/dist/tooltip/types.d.ts +105 -0
- package/dist/tooltip/types.js +1 -0
- package/package.json +46 -1
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
shouldShowFocusVisible,
|
|
6
6
|
trackInteractionModality
|
|
7
7
|
} from '../../primitives/input-modality';
|
|
8
|
+
import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
|
|
8
9
|
import {
|
|
9
10
|
getToggleGroupContext,
|
|
10
11
|
type ToggleGroupValue
|
|
@@ -23,13 +24,32 @@
|
|
|
23
24
|
HTMLButtonAttributes,
|
|
24
25
|
'children' | 'class' | 'disabled' | 'aria-pressed' | 'type' | 'value'
|
|
25
26
|
> & {
|
|
27
|
+
/**
|
|
28
|
+
* The stable identifier, which the component puts on the button. In a `ToggleGroup.Root`, the
|
|
29
|
+
* selection needs it. It does not show the selected state.
|
|
30
|
+
*/
|
|
26
31
|
value?: ToggleGroupValue;
|
|
32
|
+
/**
|
|
33
|
+
* The selected state at the start, for when the component controls the state. In a
|
|
34
|
+
* `ToggleGroup`, the component ignores it.
|
|
35
|
+
*/
|
|
27
36
|
defaultSelected?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The selected state. You can bind it. When your own code controls the state, `undefined`
|
|
39
|
+
* becomes `false`. In a `ToggleGroup`, the component ignores it.
|
|
40
|
+
*/
|
|
28
41
|
selected?: boolean;
|
|
42
|
+
/** The component calls it when the user changes the selected state. */
|
|
29
43
|
onChange?: (selected: boolean) => void;
|
|
44
|
+
/** Stops the interaction with the toggle and removes it from the focus order. */
|
|
30
45
|
disabled?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The content of the button. As a snippet, it can receive the current render state, for
|
|
48
|
+
* example `selected`.
|
|
49
|
+
*/
|
|
31
50
|
children?: Snippet<[ToggleRenderState]> | Snippet;
|
|
32
51
|
class?: string;
|
|
52
|
+
/** A bindable reference to the button element. */
|
|
33
53
|
element?: HTMLButtonElement | null;
|
|
34
54
|
};
|
|
35
55
|
|
|
@@ -91,6 +111,14 @@
|
|
|
91
111
|
let pressed = $state(false);
|
|
92
112
|
let focused = $state(false);
|
|
93
113
|
let focusVisible = $state(false);
|
|
114
|
+
|
|
115
|
+
// The focus ring must appear when a pointer press is followed by a key press, and the
|
|
116
|
+
// modality alone changes there — no focus event fires to re-read it.
|
|
117
|
+
watchFocusVisible({
|
|
118
|
+
isFocused: () => focused,
|
|
119
|
+
element: () => buttonRef,
|
|
120
|
+
set: (visible) => (focusVisible = visible)
|
|
121
|
+
});
|
|
94
122
|
let pressedKey: 'Enter' | 'Space' | null = $state(null);
|
|
95
123
|
|
|
96
124
|
untrack(() => {
|
|
@@ -10,13 +10,32 @@ export type ToggleRenderState = {
|
|
|
10
10
|
disabled: boolean;
|
|
11
11
|
};
|
|
12
12
|
type ToggleRootProps = Omit<HTMLButtonAttributes, 'children' | 'class' | 'disabled' | 'aria-pressed' | 'type' | 'value'> & {
|
|
13
|
+
/**
|
|
14
|
+
* The stable identifier, which the component puts on the button. In a `ToggleGroup.Root`, the
|
|
15
|
+
* selection needs it. It does not show the selected state.
|
|
16
|
+
*/
|
|
13
17
|
value?: ToggleGroupValue;
|
|
18
|
+
/**
|
|
19
|
+
* The selected state at the start, for when the component controls the state. In a
|
|
20
|
+
* `ToggleGroup`, the component ignores it.
|
|
21
|
+
*/
|
|
14
22
|
defaultSelected?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The selected state. You can bind it. When your own code controls the state, `undefined`
|
|
25
|
+
* becomes `false`. In a `ToggleGroup`, the component ignores it.
|
|
26
|
+
*/
|
|
15
27
|
selected?: boolean;
|
|
28
|
+
/** The component calls it when the user changes the selected state. */
|
|
16
29
|
onChange?: (selected: boolean) => void;
|
|
30
|
+
/** Stops the interaction with the toggle and removes it from the focus order. */
|
|
17
31
|
disabled?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The content of the button. As a snippet, it can receive the current render state, for
|
|
34
|
+
* example `selected`.
|
|
35
|
+
*/
|
|
18
36
|
children?: Snippet<[ToggleRenderState]> | Snippet;
|
|
19
37
|
class?: string;
|
|
38
|
+
/** A bindable reference to the button element. */
|
|
20
39
|
element?: HTMLButtonElement | null;
|
|
21
40
|
};
|
|
22
41
|
declare const ToggleRoot: import("svelte").Component<ToggleRootProps, {}, "element" | "selected">;
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
## Anatomy
|
|
8
8
|
|
|
9
9
|
- `ToggleGroup.Root`
|
|
10
|
-
- `
|
|
10
|
+
- `ToggleGroup.Item`
|
|
11
11
|
|
|
12
12
|
```svelte
|
|
13
13
|
<ToggleGroup.Root defaultValue={['bold']} selectionMode="multiple" aria-label="Text style">
|
|
14
|
-
<
|
|
15
|
-
<
|
|
14
|
+
<ToggleGroup.Item value="bold">Bold</ToggleGroup.Item>
|
|
15
|
+
<ToggleGroup.Item value="italic">Italic</ToggleGroup.Item>
|
|
16
16
|
</ToggleGroup.Root>
|
|
17
17
|
```
|
|
18
18
|
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
- Use `selectionMode="single"` when only one toggle can be selected.
|
|
27
27
|
- Use `selectionMode="multiple"` when several toggles can be selected.
|
|
28
28
|
- Use `disallowEmptySelection` when at least one enabled toggle must remain selected.
|
|
29
|
-
-
|
|
29
|
+
- `ToggleGroup.Item` is `Toggle.Root` under the namespace of the group, and the two names are
|
|
30
|
+
the same component. A toggle works on its own, thus it keeps its own name too.
|
|
31
|
+
- Every toggle in a group must provide a unique `value`.
|
|
30
32
|
|
|
31
33
|
## API reference
|
|
32
34
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { ComponentProps } from 'svelte';
|
|
2
|
+
import type ToggleRootComponent from '../toggle/root/toggle-root.svelte';
|
|
2
3
|
import type ToggleGroupRootComponent from './root/toggle-group-root.svelte';
|
|
3
4
|
export * as ToggleGroup from './index.parts.js';
|
|
4
5
|
export { default as ToggleGroupRoot } from './root/toggle-group-root.svelte';
|
|
5
6
|
export type ToggleGroupRootProps = ComponentProps<typeof ToggleGroupRootComponent>;
|
|
7
|
+
export type ToggleGroupItemProps = ComponentProps<typeof ToggleRootComponent>;
|
|
6
8
|
export { createToggleGroupContext, getToggleGroupContext, setToggleGroupContext, valuesToArray, type CreateToggleGroupContextOptions, type ToggleGroupContext, type ToggleGroupOrientation, type ToggleGroupSelectionMode, type ToggleGroupValue } from './root/context.svelte';
|
|
7
9
|
import * as ToggleGroupParts from './index.parts.js';
|
|
8
10
|
export default ToggleGroupParts;
|
|
@@ -1 +1,5 @@
|
|
|
1
1
|
export { default as Root } from './root/toggle-group-root.svelte';
|
|
2
|
+
// `Item` is `Toggle.Root` under the namespace of the group. A toggle works on its own, so it keeps
|
|
3
|
+
// its own name; this only gives every group in the library the same shape — `Group.Root` with
|
|
4
|
+
// `Group.Item` inside.
|
|
5
|
+
export { default as Item } from '../toggle/root/toggle-root.svelte';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Tooltip
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`Tooltip` shows a short description of a control when the pointer rests on it, or when the keyboard puts the focus on it. It holds text only. A screen reader reads the text after the name of the control.
|
|
6
|
+
|
|
7
|
+
## Anatomy
|
|
8
|
+
|
|
9
|
+
- `Tooltip.Provider`
|
|
10
|
+
- `Tooltip.Root`
|
|
11
|
+
- `Tooltip.Trigger`
|
|
12
|
+
- `Tooltip.Content`
|
|
13
|
+
- `Tooltip.Arrow`
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<Tooltip.Root>
|
|
17
|
+
<Tooltip.Trigger aria-label="Bold">B</Tooltip.Trigger>
|
|
18
|
+
<Tooltip.Content>
|
|
19
|
+
Bold
|
|
20
|
+
<Tooltip.Arrow />
|
|
21
|
+
</Tooltip.Content>
|
|
22
|
+
</Tooltip.Root>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage guidelines
|
|
26
|
+
|
|
27
|
+
- Use it for a description the user can do without. A touch has no hover: a long press opens it.
|
|
28
|
+
- Give the trigger a name of its own. The tooltip is the description, not the name.
|
|
29
|
+
- Put only text in the content. It takes no focus.
|
|
30
|
+
- Put a `Tooltip.Provider` around a toolbar, thus every tooltip in it has the same delays.
|
|
31
|
+
- Give an element that is not a `Tooltip.Trigger` to `triggerRef` on the root.
|
|
32
|
+
|
|
33
|
+
## API reference
|
|
34
|
+
|
|
35
|
+
- `Tooltip.Root`
|
|
36
|
+
- `open?: boolean`, `defaultOpen?: boolean`, `controlledOpen?: boolean`
|
|
37
|
+
- `onOpenChange?: (open, details) => void`
|
|
38
|
+
- `delay?: number` (600), `closeDelay?: number` (100)
|
|
39
|
+
- `disabled?: boolean`
|
|
40
|
+
- `openOnLongPress?: boolean`
|
|
41
|
+
- `triggerRef?: HTMLElement | null`
|
|
42
|
+
- `Tooltip.Provider`
|
|
43
|
+
- `delay?: number`, `closeDelay?: number`, `skipDelay?: number` (300)
|
|
44
|
+
- `Tooltip.Content`
|
|
45
|
+
- `placement?: ExtendedPlacement` (top), `offset?: number` (8), `shouldFlip?: boolean`, `boundaryElement?: Element | null`
|
|
46
|
+
- `followPointer?: 'x' | 'y' | 'both'`
|
|
47
|
+
|
|
48
|
+
## Accessibility
|
|
49
|
+
|
|
50
|
+
- `Tooltip.Content` has `role="tooltip"`; the trigger gets `aria-describedby` while the content is in the DOM.
|
|
51
|
+
- A keyboard focus opens at once. A focus that a script gives opens only with the keyboard modality. A touch opens on a long press, and a tap does not.
|
|
52
|
+
- The pointer can cross the gap to the content in a straight line, and rest on the content. `Escape` closes, and a press on the trigger closes.
|
|
53
|
+
- One tooltip at most is open on the page. The next one after a close skips its delay for `skipDelay` milliseconds.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useTooltipContext } from '../root/context';
|
|
3
|
+
import type { TooltipArrowProps } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tooltip.Arrow — the pointer of the panel toward the trigger.
|
|
7
|
+
*
|
|
8
|
+
* The panel moves it along the edge that faces the trigger, with `left` or `top`, and it
|
|
9
|
+
* writes the side in `data-placement`. The shape, the size, and the offset from the edge are
|
|
10
|
+
* for the CSS: for a panel above the trigger, `[data-placement="top"]` sits at the bottom edge.
|
|
11
|
+
*/
|
|
12
|
+
let { children, class: className = '', style, ...restProps }: TooltipArrowProps = $props();
|
|
13
|
+
|
|
14
|
+
const ctx = useTooltipContext('Tooltip.Arrow');
|
|
15
|
+
let arrowRef: HTMLSpanElement | null = $state(null);
|
|
16
|
+
|
|
17
|
+
$effect(() => {
|
|
18
|
+
ctx.setArrowRef(arrowRef);
|
|
19
|
+
return () => {
|
|
20
|
+
ctx.setArrowRef(null);
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const resolvedStyle = $derived(`position: absolute;${style ? ` ${style}` : ''}`);
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<span
|
|
28
|
+
{...restProps}
|
|
29
|
+
bind:this={arrowRef}
|
|
30
|
+
class={className}
|
|
31
|
+
style={resolvedStyle}
|
|
32
|
+
aria-hidden="true"
|
|
33
|
+
data-tooltip-arrow="true"
|
|
34
|
+
>
|
|
35
|
+
{@render children?.()}
|
|
36
|
+
</span>
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { floating, type FloatingAnchor } from '../../primitives/floating';
|
|
3
|
+
import { getFloatingLayerZIndex } from '../../primitives/layer-stack';
|
|
4
|
+
import { createPresence } from '../../primitives/presence.svelte';
|
|
5
|
+
import { Portal } from '../../portal';
|
|
6
|
+
import { useTooltipContext } from '../root/context';
|
|
7
|
+
import type { TooltipContentProps } from '../types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Tooltip.Content — the floating panel with the description.
|
|
11
|
+
*
|
|
12
|
+
* It is `role="tooltip"`, and the trigger points at it with `aria-describedby` while it is in
|
|
13
|
+
* the DOM. It takes no focus and it holds no control: a screen reader reads it as a
|
|
14
|
+
* description of the trigger, and nothing else. The pointer can rest on it, thus the user can
|
|
15
|
+
* read it to the end.
|
|
16
|
+
*/
|
|
17
|
+
let {
|
|
18
|
+
offset = 8,
|
|
19
|
+
placement = 'top',
|
|
20
|
+
shouldFlip = true,
|
|
21
|
+
boundaryElement = null,
|
|
22
|
+
followPointer,
|
|
23
|
+
children,
|
|
24
|
+
class: className = '',
|
|
25
|
+
element = $bindable<HTMLDivElement | null>(null),
|
|
26
|
+
onpointerenter,
|
|
27
|
+
onpointerleave,
|
|
28
|
+
...restProps
|
|
29
|
+
}: TooltipContentProps = $props();
|
|
30
|
+
|
|
31
|
+
const ctx = useTooltipContext('Tooltip.Content');
|
|
32
|
+
|
|
33
|
+
let contentRef: HTMLDivElement | null = $state(null);
|
|
34
|
+
let resolvedPlacement = $state<'top' | 'right' | 'bottom' | 'left'>('top');
|
|
35
|
+
// Resolved when the tooltip opens, thus it draws above the topmost dialog of that moment.
|
|
36
|
+
let zIndex = $state(getFloatingLayerZIndex());
|
|
37
|
+
// The last position of the pointer on the trigger, for a panel that follows it. Null while
|
|
38
|
+
// the pointer was never on the trigger: a keyboard focus opened the tooltip.
|
|
39
|
+
let pointerPosition = $state<{ x: number; y: number } | null>(null);
|
|
40
|
+
|
|
41
|
+
$effect(() => {
|
|
42
|
+
element = contentRef;
|
|
43
|
+
ctx.setContentRef(contentRef);
|
|
44
|
+
return () => {
|
|
45
|
+
ctx.setContentRef(null);
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function resolvePlacementSide(value: string) {
|
|
50
|
+
const side = value.split(/[-\s]/)[0];
|
|
51
|
+
return side === 'top' || side === 'right' || side === 'left' ? side : 'bottom';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A panel that follows the pointer is anchored to a point on the trigger: the pointer on
|
|
55
|
+
// the axes that follow, and the extent of the trigger on the axis that does not.
|
|
56
|
+
$effect(() => {
|
|
57
|
+
const trigger = ctx.triggerRef;
|
|
58
|
+
if (!trigger || !followPointer) {
|
|
59
|
+
pointerPosition = null;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const handleMove = (event: PointerEvent) => {
|
|
63
|
+
if (event.pointerType === 'touch') return;
|
|
64
|
+
pointerPosition = { x: event.clientX, y: event.clientY };
|
|
65
|
+
};
|
|
66
|
+
trigger.addEventListener('pointermove', handleMove);
|
|
67
|
+
return () => {
|
|
68
|
+
trigger.removeEventListener('pointermove', handleMove);
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const anchor = $derived.by<FloatingAnchor>(() => {
|
|
73
|
+
const trigger = ctx.triggerRef;
|
|
74
|
+
if (!trigger || !followPointer || !pointerPosition) return trigger;
|
|
75
|
+
const { x, y } = pointerPosition;
|
|
76
|
+
const axis = followPointer;
|
|
77
|
+
return {
|
|
78
|
+
contextElement: trigger,
|
|
79
|
+
getBoundingClientRect() {
|
|
80
|
+
const rect = trigger.getBoundingClientRect();
|
|
81
|
+
const left = axis === 'y' ? rect.left : x;
|
|
82
|
+
const top = axis === 'x' ? rect.top : y;
|
|
83
|
+
const width = axis === 'y' ? rect.width : 0;
|
|
84
|
+
const height = axis === 'x' ? rect.height : 0;
|
|
85
|
+
return new DOMRect(left, top, width, height);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
function handlePointerEnter(
|
|
91
|
+
event: PointerEvent & { currentTarget: EventTarget & HTMLDivElement }
|
|
92
|
+
) {
|
|
93
|
+
onpointerenter?.(event);
|
|
94
|
+
ctx.handleContentPointerEnter(event);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function handlePointerLeave(
|
|
98
|
+
event: PointerEvent & { currentTarget: EventTarget & HTMLDivElement }
|
|
99
|
+
) {
|
|
100
|
+
onpointerleave?.(event);
|
|
101
|
+
ctx.handleContentPointerLeave(event);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Mounted through the exit animation, with the phases timed from the CSS motion of the panel.
|
|
105
|
+
const presence = createPresence(
|
|
106
|
+
() => ctx.isOpen,
|
|
107
|
+
() => contentRef,
|
|
108
|
+
{
|
|
109
|
+
onOpen: () => {
|
|
110
|
+
zIndex = getFloatingLayerZIndex();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
{#if presence.isMounted}
|
|
117
|
+
<Portal>
|
|
118
|
+
<div
|
|
119
|
+
{...restProps}
|
|
120
|
+
bind:this={contentRef}
|
|
121
|
+
id={ctx.contentId}
|
|
122
|
+
role="tooltip"
|
|
123
|
+
class={className}
|
|
124
|
+
aria-hidden={ctx.isOpen ? undefined : 'true'}
|
|
125
|
+
data-tooltip-content="true"
|
|
126
|
+
data-state={ctx.isOpen ? 'open' : 'closed'}
|
|
127
|
+
data-entering={presence.isEntering || undefined}
|
|
128
|
+
data-exiting={presence.isExiting || undefined}
|
|
129
|
+
data-placement={resolvedPlacement}
|
|
130
|
+
use:floating={{
|
|
131
|
+
anchor,
|
|
132
|
+
offset,
|
|
133
|
+
placement,
|
|
134
|
+
shouldFlip,
|
|
135
|
+
boundaryElement,
|
|
136
|
+
arrow: ctx.arrowRef,
|
|
137
|
+
onPositionUpdate: (_, __, finalPlacement) => {
|
|
138
|
+
resolvedPlacement = resolvePlacementSide(finalPlacement);
|
|
139
|
+
}
|
|
140
|
+
}}
|
|
141
|
+
style="position: fixed; z-index: {zIndex};"
|
|
142
|
+
onpointerenter={handlePointerEnter}
|
|
143
|
+
onpointerleave={handlePointerLeave}
|
|
144
|
+
>
|
|
145
|
+
{@render children?.()}
|
|
146
|
+
</div>
|
|
147
|
+
</Portal>
|
|
148
|
+
{/if}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * as Tooltip from './index.parts.js';
|
|
2
|
+
export { default as TooltipRoot } from './root/tooltip-root.svelte';
|
|
3
|
+
export { default as TooltipProvider } from './provider/tooltip-provider.svelte';
|
|
4
|
+
export { default as TooltipTrigger } from './trigger/tooltip-trigger.svelte';
|
|
5
|
+
export { default as TooltipContent } from './content/tooltip-content.svelte';
|
|
6
|
+
export { default as TooltipArrow } from './arrow/tooltip-arrow.svelte';
|
|
7
|
+
export type { TooltipRootProps, TooltipProviderProps, TooltipTriggerProps, TooltipTriggerRenderState, TooltipContentProps, TooltipArrowProps, TooltipOpenChangeDetails, TooltipChangeReason, TooltipOpenReason, TooltipCloseReason } from './types.js';
|
|
8
|
+
export { getTooltipContext, setTooltipContext, useTooltipContext, type TooltipContext } from './root/context.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as Tooltip from './index.parts.js';
|
|
2
|
+
export { default as TooltipRoot } from './root/tooltip-root.svelte';
|
|
3
|
+
export { default as TooltipProvider } from './provider/tooltip-provider.svelte';
|
|
4
|
+
export { default as TooltipTrigger } from './trigger/tooltip-trigger.svelte';
|
|
5
|
+
export { default as TooltipContent } from './content/tooltip-content.svelte';
|
|
6
|
+
export { default as TooltipArrow } from './arrow/tooltip-arrow.svelte';
|
|
7
|
+
export { getTooltipContext, setTooltipContext, useTooltipContext } from './root/context.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Root } from './root/tooltip-root.svelte';
|
|
2
|
+
export { default as Provider } from './provider/tooltip-provider.svelte';
|
|
3
|
+
export { default as Trigger } from './trigger/tooltip-trigger.svelte';
|
|
4
|
+
export { default as Content } from './content/tooltip-content.svelte';
|
|
5
|
+
export { default as Arrow } from './arrow/tooltip-arrow.svelte';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as Root } from './root/tooltip-root.svelte';
|
|
2
|
+
export { default as Provider } from './provider/tooltip-provider.svelte';
|
|
3
|
+
export { default as Trigger } from './trigger/tooltip-trigger.svelte';
|
|
4
|
+
export { default as Content } from './content/tooltip-content.svelte';
|
|
5
|
+
export { default as Arrow } from './arrow/tooltip-arrow.svelte';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { setTooltipProviderContext } from '../root/context';
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_TOOLTIP_CLOSE_DELAY,
|
|
5
|
+
DEFAULT_TOOLTIP_DELAY,
|
|
6
|
+
DEFAULT_TOOLTIP_SKIP_DELAY
|
|
7
|
+
} from '../root/tooltip-group';
|
|
8
|
+
import type { TooltipProviderProps } from '../types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Tooltip.Provider — the delays of every tooltip inside it.
|
|
12
|
+
*
|
|
13
|
+
* It renders no element. A tooltip reads the delays from the nearest provider, and its own
|
|
14
|
+
* props replace them.
|
|
15
|
+
*/
|
|
16
|
+
let {
|
|
17
|
+
delay = DEFAULT_TOOLTIP_DELAY,
|
|
18
|
+
closeDelay = DEFAULT_TOOLTIP_CLOSE_DELAY,
|
|
19
|
+
skipDelay = DEFAULT_TOOLTIP_SKIP_DELAY,
|
|
20
|
+
children
|
|
21
|
+
}: TooltipProviderProps = $props();
|
|
22
|
+
|
|
23
|
+
setTooltipProviderContext({
|
|
24
|
+
get delay() {
|
|
25
|
+
return delay;
|
|
26
|
+
},
|
|
27
|
+
get closeDelay() {
|
|
28
|
+
return closeDelay;
|
|
29
|
+
},
|
|
30
|
+
get skipDelay() {
|
|
31
|
+
return skipDelay;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{@render children?.()}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type TooltipOpenReason = 'hover' | 'focus' | 'imperative-action';
|
|
2
|
+
export type TooltipCloseReason = 'hover-out' | 'focus-out' | 'escape-key' | 'trigger-press' | 'other-tooltip' | 'imperative-action';
|
|
3
|
+
export type TooltipChangeReason = TooltipOpenReason | TooltipCloseReason;
|
|
4
|
+
export type TooltipOpenChangeDetails = {
|
|
5
|
+
reason: TooltipChangeReason;
|
|
6
|
+
event?: Event;
|
|
7
|
+
cancel: () => void;
|
|
8
|
+
isCanceled: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Context shared between Tooltip.Root and its parts.
|
|
12
|
+
*/
|
|
13
|
+
export type TooltipContext = {
|
|
14
|
+
/** The instance id. */
|
|
15
|
+
instanceId: string;
|
|
16
|
+
/** The id of the content element. The trigger points at it with `aria-describedby`. */
|
|
17
|
+
contentId: string;
|
|
18
|
+
/** Whether the tooltip is open. */
|
|
19
|
+
isOpen: boolean;
|
|
20
|
+
/** Whether the tooltip never opens. */
|
|
21
|
+
isDisabled: boolean;
|
|
22
|
+
/** The reference to the trigger element. */
|
|
23
|
+
triggerRef: HTMLElement | null;
|
|
24
|
+
/** The reference to the arrow element, when a `Tooltip.Arrow` is in the DOM. */
|
|
25
|
+
arrowRef: HTMLElement | null;
|
|
26
|
+
setTriggerRef: (element: HTMLElement | null) => void;
|
|
27
|
+
setContentRef: (element: HTMLElement | null) => void;
|
|
28
|
+
setArrowRef: (element: HTMLElement | null) => void;
|
|
29
|
+
open: (reason?: TooltipOpenReason, event?: Event) => void;
|
|
30
|
+
close: (reason?: TooltipCloseReason, event?: Event) => void;
|
|
31
|
+
/** The pointer entered the content: the tooltip stays open while the pointer is on it. */
|
|
32
|
+
handleContentPointerEnter: (event: PointerEvent) => void;
|
|
33
|
+
/** The pointer left the content. */
|
|
34
|
+
handleContentPointerLeave: (event: PointerEvent) => void;
|
|
35
|
+
};
|
|
36
|
+
export declare function setTooltipContext(ctx: TooltipContext): void;
|
|
37
|
+
export declare function getTooltipContext(): TooltipContext | undefined;
|
|
38
|
+
export declare function useTooltipContext(part: string): TooltipContext;
|
|
39
|
+
/** The delays that a `Tooltip.Provider` gives to the tooltips inside it. */
|
|
40
|
+
export type TooltipProviderContext = {
|
|
41
|
+
delay: number;
|
|
42
|
+
closeDelay: number;
|
|
43
|
+
skipDelay: number;
|
|
44
|
+
};
|
|
45
|
+
export declare function setTooltipProviderContext(ctx: TooltipProviderContext): void;
|
|
46
|
+
export declare function getTooltipProviderContext(): TooltipProviderContext | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
const TOOLTIP_KEY = Symbol('tooltip');
|
|
3
|
+
export function setTooltipContext(ctx) {
|
|
4
|
+
setContext(TOOLTIP_KEY, ctx);
|
|
5
|
+
}
|
|
6
|
+
export function getTooltipContext() {
|
|
7
|
+
return getContext(TOOLTIP_KEY);
|
|
8
|
+
}
|
|
9
|
+
export function useTooltipContext(part) {
|
|
10
|
+
const ctx = getTooltipContext();
|
|
11
|
+
if (!ctx) {
|
|
12
|
+
throw new Error(`${part} must be used inside a Tooltip.Root`);
|
|
13
|
+
}
|
|
14
|
+
return ctx;
|
|
15
|
+
}
|
|
16
|
+
const TOOLTIP_PROVIDER_KEY = Symbol('tooltip-provider');
|
|
17
|
+
export function setTooltipProviderContext(ctx) {
|
|
18
|
+
setContext(TOOLTIP_PROVIDER_KEY, ctx);
|
|
19
|
+
}
|
|
20
|
+
export function getTooltipProviderContext() {
|
|
21
|
+
return getContext(TOOLTIP_PROVIDER_KEY);
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The area the pointer may cross between the trigger and the content of a tooltip.
|
|
3
|
+
*
|
|
4
|
+
* The pointer leaves the trigger toward the content, and for a moment it is on neither: it is in
|
|
5
|
+
* the gap. A tooltip that closes there is one the user cannot reach. The area is a triangle from
|
|
6
|
+
* the point where the pointer left the trigger to the two corners of the content on the edge
|
|
7
|
+
* that faces the trigger, a little wider than the content. A pointer inside it is on its way; a
|
|
8
|
+
* pointer outside it went somewhere else.
|
|
9
|
+
*/
|
|
10
|
+
export type Point = {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
};
|
|
14
|
+
export type Rect = {
|
|
15
|
+
left: number;
|
|
16
|
+
top: number;
|
|
17
|
+
right: number;
|
|
18
|
+
bottom: number;
|
|
19
|
+
};
|
|
20
|
+
export type Side = 'top' | 'bottom' | 'left' | 'right';
|
|
21
|
+
/** How much wider than the content the far edge of the triangle is, in pixels, on each side. */
|
|
22
|
+
export declare const SAFE_POLYGON_PADDING = 8;
|
|
23
|
+
export declare function buildSafePolygon(exit: Point, content: Rect, side: Side, padding?: number): Point[];
|
|
24
|
+
/** Whether a point is inside a polygon, by the crossing number. A point on an edge counts. */
|
|
25
|
+
export declare function isPointInPolygon(point: Point, polygon: Point[]): boolean;
|
|
26
|
+
export declare function isPointInRect(point: Point, rect: Rect): boolean;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The area the pointer may cross between the trigger and the content of a tooltip.
|
|
3
|
+
*
|
|
4
|
+
* The pointer leaves the trigger toward the content, and for a moment it is on neither: it is in
|
|
5
|
+
* the gap. A tooltip that closes there is one the user cannot reach. The area is a triangle from
|
|
6
|
+
* the point where the pointer left the trigger to the two corners of the content on the edge
|
|
7
|
+
* that faces the trigger, a little wider than the content. A pointer inside it is on its way; a
|
|
8
|
+
* pointer outside it went somewhere else.
|
|
9
|
+
*/
|
|
10
|
+
/** How much wider than the content the far edge of the triangle is, in pixels, on each side. */
|
|
11
|
+
export const SAFE_POLYGON_PADDING = 8;
|
|
12
|
+
export function buildSafePolygon(exit, content, side, padding = SAFE_POLYGON_PADDING) {
|
|
13
|
+
switch (side) {
|
|
14
|
+
case 'top':
|
|
15
|
+
return [
|
|
16
|
+
exit,
|
|
17
|
+
{ x: content.left - padding, y: content.bottom },
|
|
18
|
+
{ x: content.right + padding, y: content.bottom }
|
|
19
|
+
];
|
|
20
|
+
case 'bottom':
|
|
21
|
+
return [
|
|
22
|
+
exit,
|
|
23
|
+
{ x: content.left - padding, y: content.top },
|
|
24
|
+
{ x: content.right + padding, y: content.top }
|
|
25
|
+
];
|
|
26
|
+
case 'left':
|
|
27
|
+
return [
|
|
28
|
+
exit,
|
|
29
|
+
{ x: content.right, y: content.top - padding },
|
|
30
|
+
{ x: content.right, y: content.bottom + padding }
|
|
31
|
+
];
|
|
32
|
+
case 'right':
|
|
33
|
+
return [
|
|
34
|
+
exit,
|
|
35
|
+
{ x: content.left, y: content.top - padding },
|
|
36
|
+
{ x: content.left, y: content.bottom + padding }
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Whether a point is inside a polygon, by the crossing number. A point on an edge counts. */
|
|
41
|
+
export function isPointInPolygon(point, polygon) {
|
|
42
|
+
let inside = false;
|
|
43
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i, i += 1) {
|
|
44
|
+
const a = polygon[i];
|
|
45
|
+
const b = polygon[j];
|
|
46
|
+
if (isPointOnSegment(point, a, b))
|
|
47
|
+
return true;
|
|
48
|
+
const crosses = a.y > point.y !== b.y > point.y &&
|
|
49
|
+
point.x < ((b.x - a.x) * (point.y - a.y)) / (b.y - a.y) + a.x;
|
|
50
|
+
if (crosses)
|
|
51
|
+
inside = !inside;
|
|
52
|
+
}
|
|
53
|
+
return inside;
|
|
54
|
+
}
|
|
55
|
+
function isPointOnSegment(point, a, b) {
|
|
56
|
+
const cross = (b.x - a.x) * (point.y - a.y) - (b.y - a.y) * (point.x - a.x);
|
|
57
|
+
if (Math.abs(cross) > 0.5)
|
|
58
|
+
return false;
|
|
59
|
+
return (point.x >= Math.min(a.x, b.x) - 0.5 &&
|
|
60
|
+
point.x <= Math.max(a.x, b.x) + 0.5 &&
|
|
61
|
+
point.y >= Math.min(a.y, b.y) - 0.5 &&
|
|
62
|
+
point.y <= Math.max(a.y, b.y) + 0.5);
|
|
63
|
+
}
|
|
64
|
+
export function isPointInRect(point, rect) {
|
|
65
|
+
return (point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom);
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state that every tooltip on the page shares.
|
|
3
|
+
*
|
|
4
|
+
* Two rules come from it. One tooltip at most is open: a second one that opens closes the first,
|
|
5
|
+
* because two descriptions on the screen describe nothing. And a tooltip that opens soon after
|
|
6
|
+
* another closed skips its delay: the user reads a row of icons, and the wait is for the first
|
|
7
|
+
* one only.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_TOOLTIP_DELAY = 600;
|
|
10
|
+
export declare const DEFAULT_TOOLTIP_CLOSE_DELAY = 100;
|
|
11
|
+
export declare const DEFAULT_TOOLTIP_SKIP_DELAY = 300;
|
|
12
|
+
type OpenTooltip = {
|
|
13
|
+
close: (reason: 'other-tooltip') => void;
|
|
14
|
+
};
|
|
15
|
+
/** Registers the tooltip that opened, and closes the one that was open before it. */
|
|
16
|
+
export declare function registerOpenTooltip(tooltip: OpenTooltip): void;
|
|
17
|
+
/** Forgets a tooltip that closed, and starts the window in which the next one skips its delay. */
|
|
18
|
+
export declare function unregisterOpenTooltip(tooltip: OpenTooltip): void;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the next tooltip opens at once: another one is open, or one closed less than
|
|
21
|
+
* `skipDelay` milliseconds ago.
|
|
22
|
+
*/
|
|
23
|
+
export declare function shouldSkipDelay(skipDelay: number): boolean;
|
|
24
|
+
/** For tests: forgets every tooltip and the close time. */
|
|
25
|
+
export declare function resetTooltipGroup(): void;
|
|
26
|
+
export {};
|