@human-kit/ui 1.0.0-beta.7 → 1.0.0-beta.9
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/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/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 +16 -0
- package/dist/index.js +15 -0
- package/dist/internal/localized-strings.d.ts +72 -0
- package/dist/internal/localized-strings.js +72 -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/aria-hide-outside.d.ts +13 -0
- package/dist/primitives/aria-hide-outside.js +7 -1
- 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-trap.d.ts +2 -0
- package/dist/primitives/focus-trap.js +7 -1
- package/dist/primitives/keyboard-navigation.d.ts +6 -0
- package/dist/primitives/keyboard-navigation.js +2 -1
- package/dist/primitives/presence.svelte.js +6 -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/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/toast/README.md +75 -0
- package/dist/toast/action/toast-action.svelte +42 -0
- package/dist/toast/action/toast-action.svelte.d.ts +4 -0
- package/dist/toast/close/toast-close.svelte +41 -0
- package/dist/toast/close/toast-close.svelte.d.ts +4 -0
- package/dist/toast/content/toast-content.svelte +24 -0
- package/dist/toast/content/toast-content.svelte.d.ts +4 -0
- package/dist/toast/description/toast-description.svelte +41 -0
- package/dist/toast/description/toast-description.svelte.d.ts +4 -0
- package/dist/toast/index.d.ts +34 -0
- package/dist/toast/index.js +15 -0
- package/dist/toast/index.parts.d.ts +9 -0
- package/dist/toast/index.parts.js +9 -0
- package/dist/toast/positioner/toast-positioner.svelte +75 -0
- package/dist/toast/positioner/toast-positioner.svelte.d.ts +4 -0
- package/dist/toast/provider/context.d.ts +36 -0
- package/dist/toast/provider/context.js +22 -0
- package/dist/toast/provider/toast-manager.svelte.d.ts +113 -0
- package/dist/toast/provider/toast-manager.svelte.js +210 -0
- package/dist/toast/provider/toast-provider.svelte +98 -0
- package/dist/toast/provider/toast-provider.svelte.d.ts +4 -0
- package/dist/toast/root/context.d.ts +18 -0
- package/dist/toast/root/context.js +15 -0
- package/dist/toast/root/toast-root.svelte +296 -0
- package/dist/toast/root/toast-root.svelte.d.ts +4 -0
- package/dist/toast/title/toast-title.svelte +38 -0
- package/dist/toast/title/toast-title.svelte.d.ts +4 -0
- package/dist/toast/types.d.ts +100 -0
- package/dist/toast/types.js +1 -0
- package/dist/toast/viewport/toast-viewport.svelte +389 -0
- package/dist/toast/viewport/toast-viewport.svelte.d.ts +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 +41 -1
|
@@ -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 {};
|
|
@@ -0,0 +1,41 @@
|
|
|
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 const DEFAULT_TOOLTIP_DELAY = 600;
|
|
10
|
+
export const DEFAULT_TOOLTIP_CLOSE_DELAY = 100;
|
|
11
|
+
export const DEFAULT_TOOLTIP_SKIP_DELAY = 300;
|
|
12
|
+
let openTooltip = null;
|
|
13
|
+
let lastCloseAt = -Infinity;
|
|
14
|
+
/** Registers the tooltip that opened, and closes the one that was open before it. */
|
|
15
|
+
export function registerOpenTooltip(tooltip) {
|
|
16
|
+
if (openTooltip && openTooltip !== tooltip) {
|
|
17
|
+
openTooltip.close('other-tooltip');
|
|
18
|
+
}
|
|
19
|
+
openTooltip = tooltip;
|
|
20
|
+
}
|
|
21
|
+
/** Forgets a tooltip that closed, and starts the window in which the next one skips its delay. */
|
|
22
|
+
export function unregisterOpenTooltip(tooltip) {
|
|
23
|
+
if (openTooltip === tooltip) {
|
|
24
|
+
openTooltip = null;
|
|
25
|
+
}
|
|
26
|
+
lastCloseAt = Date.now();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether the next tooltip opens at once: another one is open, or one closed less than
|
|
30
|
+
* `skipDelay` milliseconds ago.
|
|
31
|
+
*/
|
|
32
|
+
export function shouldSkipDelay(skipDelay) {
|
|
33
|
+
if (openTooltip)
|
|
34
|
+
return true;
|
|
35
|
+
return Date.now() - lastCloseAt < skipDelay;
|
|
36
|
+
}
|
|
37
|
+
/** For tests: forgets every tooltip and the close time. */
|
|
38
|
+
export function resetTooltipGroup() {
|
|
39
|
+
openTooltip = null;
|
|
40
|
+
lastCloseAt = -Infinity;
|
|
41
|
+
}
|