@zealakit/overlay-react 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +547 -2
- package/dist/animation/index.d.ts +1 -0
- package/dist/animation/index.js +1 -0
- package/dist/animation/presence.d.ts +31 -0
- package/dist/animation/presence.js +104 -0
- package/dist/components/arrow.d.ts +30 -0
- package/dist/components/arrow.js +58 -0
- package/dist/components/context-menu/content.d.ts +37 -0
- package/dist/components/context-menu/content.js +52 -0
- package/dist/components/context-menu/context-menu.d.ts +20 -0
- package/dist/components/context-menu/context-menu.js +78 -0
- package/dist/components/context-menu/context.d.ts +47 -0
- package/dist/components/context-menu/context.js +27 -0
- package/dist/components/context-menu/index.d.ts +7 -0
- package/dist/components/context-menu/index.js +6 -0
- package/dist/components/context-menu/items.d.ts +71 -0
- package/dist/components/context-menu/items.js +207 -0
- package/dist/components/context-menu/menu-navigation.d.ts +3 -0
- package/dist/components/context-menu/menu-navigation.js +42 -0
- package/dist/components/context-menu/menu-surface.d.ts +58 -0
- package/dist/components/context-menu/menu-surface.js +172 -0
- package/dist/components/context-menu/sub.d.ts +45 -0
- package/dist/components/context-menu/sub.js +180 -0
- package/dist/components/context-menu/trigger.d.ts +17 -0
- package/dist/components/context-menu/trigger.js +62 -0
- package/dist/components/context-menu/types.d.ts +9 -0
- package/dist/components/context-menu/types.js +1 -0
- package/dist/components/dialog/content.d.ts +87 -0
- package/dist/components/dialog/content.js +238 -0
- package/dist/components/dialog/context.d.ts +41 -0
- package/dist/components/dialog/context.js +26 -0
- package/dist/components/dialog/dialog.d.ts +27 -0
- package/dist/components/dialog/dialog.js +88 -0
- package/dist/components/dialog/helpers.d.ts +24 -0
- package/dist/components/dialog/helpers.js +59 -0
- package/dist/components/dialog/index.d.ts +5 -0
- package/dist/components/dialog/index.js +5 -0
- package/dist/components/dialog/modal-background.d.ts +7 -0
- package/dist/components/dialog/modal-background.js +21 -0
- package/dist/components/dialog/trigger.d.ts +11 -0
- package/dist/components/dialog/trigger.js +29 -0
- package/dist/components/overlay-context.d.ts +13 -0
- package/dist/components/overlay-context.js +10 -0
- package/dist/components/popover/content.d.ts +131 -0
- package/dist/components/popover/content.js +261 -0
- package/dist/components/popover/context.d.ts +27 -0
- package/dist/components/popover/context.js +18 -0
- package/dist/components/popover/helpers.d.ts +23 -0
- package/dist/components/popover/helpers.js +58 -0
- package/dist/components/popover/index.d.ts +4 -0
- package/dist/components/popover/index.js +4 -0
- package/dist/components/popover/popover.d.ts +39 -0
- package/dist/components/popover/popover.js +98 -0
- package/dist/components/portal.d.ts +14 -0
- package/dist/components/portal.js +19 -0
- package/dist/components/slot.d.ts +12 -0
- package/dist/components/slot.js +60 -0
- package/dist/components/tooltip/content.d.ts +21 -0
- package/dist/components/tooltip/content.js +95 -0
- package/dist/components/tooltip/context.d.ts +22 -0
- package/dist/components/tooltip/context.js +10 -0
- package/dist/components/tooltip/index.d.ts +5 -0
- package/dist/components/tooltip/index.js +5 -0
- package/dist/components/tooltip/provider.d.ts +29 -0
- package/dist/components/tooltip/provider.js +29 -0
- package/dist/components/tooltip/tooltip.d.ts +25 -0
- package/dist/components/tooltip/tooltip.js +268 -0
- package/dist/components/tooltip/trigger.d.ts +11 -0
- package/dist/components/tooltip/trigger.js +67 -0
- package/dist/hooks/use-escape-key.d.ts +12 -0
- package/dist/hooks/use-escape-key.js +30 -0
- package/dist/hooks/use-layer.d.ts +33 -0
- package/dist/hooks/use-layer.js +84 -0
- package/dist/hooks/use-overlay.d.ts +31 -0
- package/dist/hooks/use-overlay.js +69 -0
- package/dist/hooks/use-positioner.d.ts +28 -0
- package/dist/hooks/use-positioner.js +127 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/vendor/core/animation/index.d.ts +2 -0
- package/dist/vendor/core/animation/index.js +2 -0
- package/dist/vendor/core/animation/keyframes.d.ts +47 -0
- package/dist/vendor/core/animation/keyframes.js +105 -0
- package/dist/vendor/core/animation/run-animation.d.ts +27 -0
- package/dist/vendor/core/animation/run-animation.js +175 -0
- package/dist/vendor/core/controller/animator.d.ts +19 -0
- package/dist/vendor/core/controller/animator.js +117 -0
- package/dist/vendor/core/controller/context-menu-behavior.d.ts +15 -0
- package/dist/vendor/core/controller/context-menu-behavior.js +123 -0
- package/dist/vendor/core/controller/host.d.ts +10 -0
- package/dist/vendor/core/controller/host.js +1 -0
- package/dist/vendor/core/controller/index.d.ts +2 -0
- package/dist/vendor/core/controller/index.js +1 -0
- package/dist/vendor/core/controller/overlay-controller.d.ts +9 -0
- package/dist/vendor/core/controller/overlay-controller.js +723 -0
- package/dist/vendor/core/controller/tooltip-behavior.d.ts +9 -0
- package/dist/vendor/core/controller/tooltip-behavior.js +123 -0
- package/dist/vendor/core/controller/types.d.ts +92 -0
- package/dist/vendor/core/controller/types.js +1 -0
- package/dist/vendor/core/events/index.d.ts +3 -0
- package/dist/vendor/core/events/index.js +3 -0
- package/dist/vendor/core/events/keyboard.d.ts +2 -0
- package/dist/vendor/core/events/keyboard.js +4 -0
- package/dist/vendor/core/events/outside.d.ts +8 -0
- package/dist/vendor/core/events/outside.js +33 -0
- package/dist/vendor/core/events/pointer.d.ts +13 -0
- package/dist/vendor/core/events/pointer.js +18 -0
- package/dist/vendor/core/focus/focus.d.ts +73 -0
- package/dist/vendor/core/focus/focus.js +312 -0
- package/dist/vendor/core/focus/index.d.ts +1 -0
- package/dist/vendor/core/focus/index.js +1 -0
- package/dist/vendor/core/index.d.ts +13 -0
- package/dist/vendor/core/index.js +13 -0
- package/dist/vendor/core/layer/create-layer-stack.d.ts +25 -0
- package/dist/vendor/core/layer/create-layer-stack.js +247 -0
- package/dist/vendor/core/layer/create-layer.d.ts +10 -0
- package/dist/vendor/core/layer/create-layer.js +78 -0
- package/dist/vendor/core/layer/index.d.ts +3 -0
- package/dist/vendor/core/layer/index.js +3 -0
- package/dist/vendor/core/layer/manager.d.ts +9 -0
- package/dist/vendor/core/layer/manager.js +157 -0
- package/dist/vendor/core/lifecycle/events.d.ts +8 -0
- package/dist/vendor/core/lifecycle/events.js +21 -0
- package/dist/vendor/core/lifecycle/index.d.ts +1 -0
- package/dist/vendor/core/lifecycle/index.js +1 -0
- package/dist/vendor/core/menu/index.d.ts +1 -0
- package/dist/vendor/core/menu/index.js +1 -0
- package/dist/vendor/core/menu/navigation.d.ts +22 -0
- package/dist/vendor/core/menu/navigation.js +107 -0
- package/dist/vendor/core/modal/background.d.ts +10 -0
- package/dist/vendor/core/modal/background.js +115 -0
- package/dist/vendor/core/modal/index.d.ts +1 -0
- package/dist/vendor/core/modal/index.js +1 -0
- package/dist/vendor/core/portal/index.d.ts +1 -0
- package/dist/vendor/core/portal/index.js +1 -0
- package/dist/vendor/core/portal/portal.d.ts +13 -0
- package/dist/vendor/core/portal/portal.js +25 -0
- package/dist/vendor/core/positioning/arrow.d.ts +34 -0
- package/dist/vendor/core/positioning/arrow.js +142 -0
- package/dist/vendor/core/positioning/compute.d.ts +9 -0
- package/dist/vendor/core/positioning/compute.js +22 -0
- package/dist/vendor/core/positioning/coordinates.d.ts +11 -0
- package/dist/vendor/core/positioning/coordinates.js +45 -0
- package/dist/vendor/core/positioning/create-positioner.d.ts +8 -0
- package/dist/vendor/core/positioning/create-positioner.js +251 -0
- package/dist/vendor/core/positioning/index.d.ts +6 -0
- package/dist/vendor/core/positioning/index.js +6 -0
- package/dist/vendor/core/positioning/placement.d.ts +8 -0
- package/dist/vendor/core/positioning/placement.js +30 -0
- package/dist/vendor/core/positioning/same-result.d.ts +8 -0
- package/dist/vendor/core/positioning/same-result.js +13 -0
- package/dist/vendor/core/positioning/strategy.d.ts +12 -0
- package/dist/vendor/core/positioning/strategy.js +46 -0
- package/dist/vendor/core/scroll-lock/index.d.ts +1 -0
- package/dist/vendor/core/scroll-lock/index.js +1 -0
- package/dist/vendor/core/scroll-lock/scroll-lock.d.ts +12 -0
- package/dist/vendor/core/scroll-lock/scroll-lock.js +68 -0
- package/dist/vendor/core/types/animation.d.ts +81 -0
- package/dist/vendor/core/types/animation.js +93 -0
- package/dist/vendor/core/types/dismissal.d.ts +2 -0
- package/dist/vendor/core/types/dismissal.js +1 -0
- package/dist/vendor/core/types/element.d.ts +20 -0
- package/dist/vendor/core/types/element.js +1 -0
- package/dist/vendor/core/types/geometry.d.ts +22 -0
- package/dist/vendor/core/types/geometry.js +1 -0
- package/dist/vendor/core/types/index.d.ts +9 -0
- package/dist/vendor/core/types/index.js +8 -0
- package/dist/vendor/core/types/layer.d.ts +126 -0
- package/dist/vendor/core/types/layer.js +1 -0
- package/dist/vendor/core/types/lifecycle.d.ts +2 -0
- package/dist/vendor/core/types/lifecycle.js +1 -0
- package/dist/vendor/core/types/positioner.d.ts +74 -0
- package/dist/vendor/core/types/positioner.js +1 -0
- package/dist/vendor/core/types/positioning.d.ts +23 -0
- package/dist/vendor/core/types/positioning.js +1 -0
- package/dist/vendor/core/utils/dom.d.ts +11 -0
- package/dist/vendor/core/utils/dom.js +21 -0
- package/dist/vendor/core/utils/element.d.ts +15 -0
- package/dist/vendor/core/utils/element.js +21 -0
- package/dist/vendor/core/utils/global-state.d.ts +1 -0
- package/dist/vendor/core/utils/global-state.js +24 -0
- package/dist/vendor/core/utils/index.d.ts +2 -0
- package/dist/vendor/core/utils/index.js +2 -0
- package/package.json +74 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getGlobalState } from "../utils/global-state.js";
|
|
2
|
+
const states = getGlobalState("scroll-lock", () => new WeakMap());
|
|
3
|
+
function resolveDocument(documentRef) {
|
|
4
|
+
if (documentRef?.body) {
|
|
5
|
+
return documentRef;
|
|
6
|
+
}
|
|
7
|
+
return typeof document !== "undefined" && document.body ? document : null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reference-counted body scroll lock for modal overlays.
|
|
11
|
+
*
|
|
12
|
+
* The first lock saves the current inline overflow/padding styles and applies
|
|
13
|
+
* `overflow: hidden` plus scrollbar-width compensation. Nested locks only
|
|
14
|
+
* increment a counter; the final release restores the original styles.
|
|
15
|
+
*
|
|
16
|
+
* This intentionally does not attach global event listeners. Callers own the
|
|
17
|
+
* lock lifetime and must call the returned cleanup on close/unmount.
|
|
18
|
+
*/
|
|
19
|
+
export function lockBodyScroll(documentRef) {
|
|
20
|
+
const document_ = resolveDocument(documentRef);
|
|
21
|
+
if (!document_) {
|
|
22
|
+
return () => { };
|
|
23
|
+
}
|
|
24
|
+
const body = document_.body;
|
|
25
|
+
const root = document_.documentElement;
|
|
26
|
+
const view = document_.defaultView;
|
|
27
|
+
let state = states.get(document_);
|
|
28
|
+
if (!state) {
|
|
29
|
+
const scrollbarGap = view
|
|
30
|
+
? Math.max(0, view.innerWidth - root.clientWidth)
|
|
31
|
+
: 0;
|
|
32
|
+
const currentPadding = view
|
|
33
|
+
? Number.parseFloat(view.getComputedStyle(body).paddingRight) || 0
|
|
34
|
+
: 0;
|
|
35
|
+
state = {
|
|
36
|
+
count: 0,
|
|
37
|
+
bodyOverflow: body.style.overflow,
|
|
38
|
+
bodyPaddingRight: body.style.paddingRight,
|
|
39
|
+
htmlOverflow: root.style.overflow,
|
|
40
|
+
};
|
|
41
|
+
states.set(document_, state);
|
|
42
|
+
root.style.overflow = "hidden";
|
|
43
|
+
body.style.overflow = "hidden";
|
|
44
|
+
if (scrollbarGap > 0) {
|
|
45
|
+
body.style.paddingRight = `${currentPadding + scrollbarGap}px`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
state.count += 1;
|
|
49
|
+
let released = false;
|
|
50
|
+
return () => {
|
|
51
|
+
if (released) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
released = true;
|
|
55
|
+
const current = states.get(document_);
|
|
56
|
+
if (!current) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
current.count -= 1;
|
|
60
|
+
if (current.count > 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
body.style.overflow = current.bodyOverflow;
|
|
64
|
+
body.style.paddingRight = current.bodyPaddingRight;
|
|
65
|
+
root.style.overflow = current.htmlOverflow;
|
|
66
|
+
states.delete(document_);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Align, Side } from "./geometry.js";
|
|
2
|
+
/**
|
|
3
|
+
* Direction of built-in movement. For `fade` it is the direction the popup
|
|
4
|
+
* travels (exit reverses it); for `expand` it is the direction it grows.
|
|
5
|
+
*/
|
|
6
|
+
export type AnimationDirection = "up" | "down" | "left" | "right";
|
|
7
|
+
/** Auto resolves from the final placement; explicit values take precedence. */
|
|
8
|
+
export type AnimationDirectionSetting = AnimationDirection | "auto";
|
|
9
|
+
/** Built-in timing presets. */
|
|
10
|
+
export type AnimationTimingFunction = "ease-in-out" | "linear";
|
|
11
|
+
/** Presets plus any valid CSS timing function (for example `cubic-bezier(...)`). */
|
|
12
|
+
export type AnimationEasing = AnimationTimingFunction | "ease" | "ease-in" | "ease-out" | (string & {});
|
|
13
|
+
/** Built-in presets plus consumer-defined animation. */
|
|
14
|
+
export type AnimationType = "fade" | "expand" | "custom";
|
|
15
|
+
/** CSS classes added for the enter/exit phase; your CSS owns the animation. */
|
|
16
|
+
export type CustomAnimationClasses = {
|
|
17
|
+
enter: string;
|
|
18
|
+
exit: string;
|
|
19
|
+
};
|
|
20
|
+
/** Information a custom keyframes function can use. */
|
|
21
|
+
export type AnimationContext = {
|
|
22
|
+
phase: "enter" | "exit";
|
|
23
|
+
/** Final placement after collision handling; undefined for Dialog. */
|
|
24
|
+
placement: string | undefined;
|
|
25
|
+
/** Side of the anchor the popup is on; null when there is no anchor. */
|
|
26
|
+
side: Side | null;
|
|
27
|
+
align: Align | null;
|
|
28
|
+
/** CSS `transform-origin` that points at the anchor (RTL aware). */
|
|
29
|
+
transformOrigin: string;
|
|
30
|
+
};
|
|
31
|
+
export type CustomKeyframes = Keyframe[] | ((context: AnimationContext) => Keyframe[]);
|
|
32
|
+
/**
|
|
33
|
+
* Web Animations keyframes. Omit `exit` to play `enter` in reverse.
|
|
34
|
+
* `duration`, `delay` and `easing` from the animation config still apply.
|
|
35
|
+
*/
|
|
36
|
+
export type CustomAnimationKeyframes = {
|
|
37
|
+
enter: CustomKeyframes;
|
|
38
|
+
exit?: CustomKeyframes;
|
|
39
|
+
};
|
|
40
|
+
export type CustomAnimation = CustomAnimationClasses | CustomAnimationKeyframes;
|
|
41
|
+
export declare function isCustomClasses(custom: CustomAnimation): custom is CustomAnimationClasses;
|
|
42
|
+
export type AnimationConfig = {
|
|
43
|
+
/** Defaults to true when a config object is passed. */
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
/** `fade` (default), `expand` (grow from the anchor edge), or `custom`. */
|
|
46
|
+
type?: AnimationType;
|
|
47
|
+
/** Explicit direction; defaults to "auto" based on resolved placement. */
|
|
48
|
+
direction?: AnimationDirectionSetting;
|
|
49
|
+
/** Milliseconds. Defaults to 160. */
|
|
50
|
+
duration?: number;
|
|
51
|
+
/** Milliseconds. Defaults to 0. */
|
|
52
|
+
delay?: number;
|
|
53
|
+
/** CSS timing function. Defaults to "ease-in-out". */
|
|
54
|
+
easing?: AnimationEasing;
|
|
55
|
+
/** Required when type is "custom": CSS classes or Web Animations keyframes. */
|
|
56
|
+
custom?: CustomAnimation;
|
|
57
|
+
};
|
|
58
|
+
/** Animation is disabled unless `true` or a config object is passed. */
|
|
59
|
+
export type AnimationSetting = boolean | AnimationConfig;
|
|
60
|
+
export type ResolvedAnimationConfig = {
|
|
61
|
+
enabled: boolean;
|
|
62
|
+
type: AnimationType;
|
|
63
|
+
direction: AnimationDirectionSetting;
|
|
64
|
+
duration: number;
|
|
65
|
+
delay: number;
|
|
66
|
+
easing: AnimationEasing;
|
|
67
|
+
custom: CustomAnimation | null;
|
|
68
|
+
};
|
|
69
|
+
export declare const DEFAULT_ANIMATION_DURATION = 160;
|
|
70
|
+
export declare const DEFAULT_ANIMATION_DELAY = 0;
|
|
71
|
+
export declare const DEFAULT_ANIMATION_EASING: AnimationEasing;
|
|
72
|
+
/**
|
|
73
|
+
* Normalize an animation setting into the contract adapters implement.
|
|
74
|
+
* Invalid numeric values and incomplete custom configurations throw early.
|
|
75
|
+
*/
|
|
76
|
+
export declare function normalizeAnimationConfig(setting: AnimationSetting | undefined): ResolvedAnimationConfig;
|
|
77
|
+
/**
|
|
78
|
+
* Resolve automatic direction from the final (collision-adjusted) placement.
|
|
79
|
+
* Explicit directions always win.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveAnimationDirection(direction: AnimationDirectionSetting | undefined, placement: string | undefined): AnimationDirection;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export function isCustomClasses(custom) {
|
|
2
|
+
return typeof custom.enter === "string";
|
|
3
|
+
}
|
|
4
|
+
export const DEFAULT_ANIMATION_DURATION = 160;
|
|
5
|
+
export const DEFAULT_ANIMATION_DELAY = 0;
|
|
6
|
+
export const DEFAULT_ANIMATION_EASING = "ease-in-out";
|
|
7
|
+
function finiteNonNegative(value, name) {
|
|
8
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
9
|
+
throw new RangeError(`[overlay-core] animation.${name} must be a finite non-negative number.`);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function nonEmptyString(value) {
|
|
14
|
+
return typeof value === "string" && value.trim() !== "";
|
|
15
|
+
}
|
|
16
|
+
function validKeyframes(value) {
|
|
17
|
+
return (typeof value === "function" || (Array.isArray(value) && value.length > 0));
|
|
18
|
+
}
|
|
19
|
+
function validCustom(custom) {
|
|
20
|
+
if (!custom) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (typeof custom.enter === "string") {
|
|
24
|
+
return nonEmptyString(custom.enter) &&
|
|
25
|
+
nonEmptyString(custom.exit)
|
|
26
|
+
? custom
|
|
27
|
+
: null;
|
|
28
|
+
}
|
|
29
|
+
const exit = custom.exit;
|
|
30
|
+
return validKeyframes(custom.enter) &&
|
|
31
|
+
(exit === undefined || validKeyframes(exit))
|
|
32
|
+
? custom
|
|
33
|
+
: null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Normalize an animation setting into the contract adapters implement.
|
|
37
|
+
* Invalid numeric values and incomplete custom configurations throw early.
|
|
38
|
+
*/
|
|
39
|
+
export function normalizeAnimationConfig(setting) {
|
|
40
|
+
const config = setting === undefined || setting === false
|
|
41
|
+
? { enabled: false }
|
|
42
|
+
: setting === true
|
|
43
|
+
? {}
|
|
44
|
+
: setting;
|
|
45
|
+
const enabled = config.enabled ?? true;
|
|
46
|
+
const custom = validCustom(config.custom);
|
|
47
|
+
const type = config.type ?? (custom ? "custom" : "fade");
|
|
48
|
+
if (!enabled) {
|
|
49
|
+
return {
|
|
50
|
+
enabled: false,
|
|
51
|
+
type: "fade",
|
|
52
|
+
direction: config.direction ?? "auto",
|
|
53
|
+
duration: 0,
|
|
54
|
+
delay: 0,
|
|
55
|
+
easing: config.easing ?? DEFAULT_ANIMATION_EASING,
|
|
56
|
+
custom: null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (type === "custom" && !custom) {
|
|
60
|
+
throw new Error("[overlay-core] animation.custom is required for custom animation: pass { enter, exit } CSS classes or { enter } keyframes.");
|
|
61
|
+
}
|
|
62
|
+
if (typeof config.easing === "string" && !config.easing.trim()) {
|
|
63
|
+
throw new Error("[overlay-core] animation.easing must be a non-empty CSS timing function.");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
enabled: true,
|
|
67
|
+
type,
|
|
68
|
+
direction: config.direction ?? "auto",
|
|
69
|
+
duration: finiteNonNegative(config.duration ?? DEFAULT_ANIMATION_DURATION, "duration"),
|
|
70
|
+
delay: finiteNonNegative(config.delay ?? DEFAULT_ANIMATION_DELAY, "delay"),
|
|
71
|
+
easing: config.easing ?? DEFAULT_ANIMATION_EASING,
|
|
72
|
+
custom,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve automatic direction from the final (collision-adjusted) placement.
|
|
77
|
+
* Explicit directions always win.
|
|
78
|
+
*/
|
|
79
|
+
export function resolveAnimationDirection(direction, placement) {
|
|
80
|
+
if (direction && direction !== "auto") {
|
|
81
|
+
return direction;
|
|
82
|
+
}
|
|
83
|
+
switch (placement?.split("-")[0]) {
|
|
84
|
+
case "top":
|
|
85
|
+
return "down";
|
|
86
|
+
case "right":
|
|
87
|
+
return "left";
|
|
88
|
+
case "left":
|
|
89
|
+
return "right";
|
|
90
|
+
default:
|
|
91
|
+
return "up";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Rect } from "./geometry.js";
|
|
2
|
+
/**
|
|
3
|
+
* Anything that can act as the anchor of a floating element.
|
|
4
|
+
*
|
|
5
|
+
* `VirtualElement` lets pointer coordinates, canvas hits, or synthetic rects be
|
|
6
|
+
* used without a real DOM node. `contextElement` allows dismissal logic to
|
|
7
|
+
* treat clicks inside a larger surface as "inside" the reference.
|
|
8
|
+
*/
|
|
9
|
+
export type VirtualElement = {
|
|
10
|
+
getBoundingClientRect: () => Rect;
|
|
11
|
+
contextElement?: Element;
|
|
12
|
+
};
|
|
13
|
+
export type ReferenceElement = Element | VirtualElement;
|
|
14
|
+
export type FloatingElement = Element;
|
|
15
|
+
/** A nullable DOM reference, suitable for framework refs. */
|
|
16
|
+
export type ElementRef<T extends Element = Element> = T | null;
|
|
17
|
+
/** A lazily resolved element reference, for refs that change over time. */
|
|
18
|
+
export type ElementGetter<T extends Element = Element> = () => T | null;
|
|
19
|
+
/** An element or a getter that resolves the current element. */
|
|
20
|
+
export type ElementSource<T extends Element = Element> = ElementRef<T> | ElementGetter<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placement primitives shared by every adapter.
|
|
3
|
+
*
|
|
4
|
+
* A placement is a side plus an optional alignment. A bare side (`"top"`) is
|
|
5
|
+
* equivalent to `"top-center"`.
|
|
6
|
+
*/
|
|
7
|
+
export type Side = "top" | "right" | "bottom" | "left";
|
|
8
|
+
export type Align = "start" | "center" | "end";
|
|
9
|
+
export type Placement = Side | `${Side}-${Align}`;
|
|
10
|
+
/** A placement after normalization: center alignment collapses to the bare side. */
|
|
11
|
+
export type NormalizedPlacement = Side | `${Side}-start` | `${Side}-end`;
|
|
12
|
+
export type Size = {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
/** A viewport-relative rectangle, structurally compatible with `DOMRect`. */
|
|
17
|
+
export type Rect = {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./dismissal.js";
|
|
2
|
+
export * from "./element.js";
|
|
3
|
+
export * from "./geometry.js";
|
|
4
|
+
export * from "./layer.js";
|
|
5
|
+
export * from "./lifecycle.js";
|
|
6
|
+
export * from "./positioner.js";
|
|
7
|
+
export * from "./positioning.js";
|
|
8
|
+
export type { AnimationConfig, AnimationContext, AnimationDirection, AnimationDirectionSetting, AnimationEasing, AnimationSetting, AnimationTimingFunction, AnimationType, CustomAnimation, CustomAnimationClasses, CustomAnimationKeyframes, CustomKeyframes, ResolvedAnimationConfig, } from "./animation.js";
|
|
9
|
+
export { DEFAULT_ANIMATION_DELAY, DEFAULT_ANIMATION_DURATION, DEFAULT_ANIMATION_EASING, isCustomClasses, normalizeAnimationConfig, resolveAnimationDirection, } from "./animation.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./dismissal.js";
|
|
2
|
+
export * from "./element.js";
|
|
3
|
+
export * from "./geometry.js";
|
|
4
|
+
export * from "./layer.js";
|
|
5
|
+
export * from "./lifecycle.js";
|
|
6
|
+
export * from "./positioner.js";
|
|
7
|
+
export * from "./positioning.js";
|
|
8
|
+
export { DEFAULT_ANIMATION_DELAY, DEFAULT_ANIMATION_DURATION, DEFAULT_ANIMATION_EASING, isCustomClasses, normalizeAnimationConfig, resolveAnimationDirection, } from "./animation.js";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { DismissReason } from "./dismissal.js";
|
|
2
|
+
import type { Cleanup } from "./lifecycle.js";
|
|
3
|
+
export type LayerStatus = "open" | "closed";
|
|
4
|
+
/**
|
|
5
|
+
* Declarative configuration for a layer. Adapters translate these flags into
|
|
6
|
+
* framework-specific wiring; core only stores and exposes them.
|
|
7
|
+
*/
|
|
8
|
+
export type LayerConfig = {
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
dismissOnEscape?: boolean;
|
|
11
|
+
dismissOnOutsidePress?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type ResolvedLayerConfig = Required<LayerConfig>;
|
|
14
|
+
export type LayerEvent = {
|
|
15
|
+
type: "open";
|
|
16
|
+
status: "open";
|
|
17
|
+
} | {
|
|
18
|
+
type: "close";
|
|
19
|
+
status: "closed";
|
|
20
|
+
reason: DismissReason;
|
|
21
|
+
};
|
|
22
|
+
export type LayerListener = (event: LayerEvent) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Framework-free open/closed lifecycle. It owns no DOM and no listeners besides
|
|
25
|
+
* its own subscribers, so it is safe to create during many render phases.
|
|
26
|
+
*/
|
|
27
|
+
export type Layer = {
|
|
28
|
+
readonly status: LayerStatus;
|
|
29
|
+
readonly config: Readonly<ResolvedLayerConfig>;
|
|
30
|
+
open(): void;
|
|
31
|
+
close(reason?: DismissReason): void;
|
|
32
|
+
toggle(): void;
|
|
33
|
+
subscribe(listener: LayerListener): () => void;
|
|
34
|
+
destroy(): void;
|
|
35
|
+
};
|
|
36
|
+
/** Snapshot entry for one registered layer. */
|
|
37
|
+
export type LayerEntry = {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly parentId: string | null;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Element (or lazy element getter) used for outside-interaction detection.
|
|
43
|
+
* Getter form supports elements that change over time.
|
|
44
|
+
*/
|
|
45
|
+
export type LayerElementSource = Element | (() => Element | null) | null;
|
|
46
|
+
/**
|
|
47
|
+
* Additional elements that belong to a layer's interaction boundary.
|
|
48
|
+
* The primary `element` and `reference` are always included.
|
|
49
|
+
*/
|
|
50
|
+
export type LayerBoundarySource = LayerElementSource | readonly LayerElementSource[];
|
|
51
|
+
export type RegisterLayerOptions = {
|
|
52
|
+
/** Defaults to a manager-local incrementing id. */
|
|
53
|
+
id?: string;
|
|
54
|
+
parentId?: string | null;
|
|
55
|
+
element?: LayerElementSource;
|
|
56
|
+
};
|
|
57
|
+
export type LayerHandle = {
|
|
58
|
+
readonly id: string;
|
|
59
|
+
readonly parentId: string | null;
|
|
60
|
+
readonly isRegistered: boolean;
|
|
61
|
+
dispose(): void;
|
|
62
|
+
};
|
|
63
|
+
export type LayerStackListener = (stack: readonly LayerEntry[]) => void;
|
|
64
|
+
/** Handle returned by a layer stack (manager handle plus stack position). */
|
|
65
|
+
export type LayerStackHandle = LayerHandle & {
|
|
66
|
+
readonly isTopmost: boolean;
|
|
67
|
+
};
|
|
68
|
+
/** Per-layer registration options for a shared layer stack. */
|
|
69
|
+
export type LayerStackRegistration = {
|
|
70
|
+
id?: string;
|
|
71
|
+
/** Parent layer handle. Must belong to the same stack. */
|
|
72
|
+
parent?: LayerStackHandle | null;
|
|
73
|
+
element?: LayerElementSource;
|
|
74
|
+
reference?: LayerElementSource;
|
|
75
|
+
/** Extra elements that should not count as outside the layer. */
|
|
76
|
+
boundaries?: LayerBoundarySource;
|
|
77
|
+
dismissOnEscape?: boolean;
|
|
78
|
+
dismissOnOutsidePress?: boolean;
|
|
79
|
+
onDismiss?: (reason: DismissReason) => void;
|
|
80
|
+
};
|
|
81
|
+
export type LayerStackOptions = {
|
|
82
|
+
/** Document that owns the shared keyboard/pointer listeners. */
|
|
83
|
+
document?: Document;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Shared layer stack: ordering, parent/child links, and one set of
|
|
87
|
+
* document-level Escape/outside listeners for every registered layer.
|
|
88
|
+
*/
|
|
89
|
+
export type LayerStack = {
|
|
90
|
+
readonly size: number;
|
|
91
|
+
register(options?: LayerStackRegistration): LayerStackHandle;
|
|
92
|
+
getTopmost(): LayerEntry | null;
|
|
93
|
+
isTopmost(id: string): boolean;
|
|
94
|
+
subscribe(listener: LayerStackListener): Cleanup;
|
|
95
|
+
dispose(): void;
|
|
96
|
+
};
|
|
97
|
+
/** A reference-counted stack borrowed from a registry. */
|
|
98
|
+
export type LayerStackLease = {
|
|
99
|
+
readonly stack: LayerStack;
|
|
100
|
+
release(): void;
|
|
101
|
+
};
|
|
102
|
+
export type LayerStackRegistry = {
|
|
103
|
+
acquire(document: Document): LayerStackLease;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Minimal stack registry for layered UI.
|
|
107
|
+
*
|
|
108
|
+
* The manager tracks registration order (bottom → top), parent/child
|
|
109
|
+
* relationships, and which registered element contains an event target.
|
|
110
|
+
* It does not open, close, focus, or render anything.
|
|
111
|
+
*/
|
|
112
|
+
export type LayerManager = {
|
|
113
|
+
readonly size: number;
|
|
114
|
+
register(options?: RegisterLayerOptions): LayerHandle;
|
|
115
|
+
unregister(id: string): boolean;
|
|
116
|
+
get(id: string): LayerEntry | null;
|
|
117
|
+
getStack(): readonly LayerEntry[];
|
|
118
|
+
getTopmost(): LayerEntry | null;
|
|
119
|
+
isTopmost(id: string): boolean;
|
|
120
|
+
/** True when the event target is outside this layer and its descendants. */
|
|
121
|
+
isOutside(id: string, event: Event): boolean;
|
|
122
|
+
/** True when the event target is outside the topmost layer. */
|
|
123
|
+
isOutsideActive(event: Event): boolean;
|
|
124
|
+
subscribe(listener: LayerStackListener): Cleanup;
|
|
125
|
+
dispose(): void;
|
|
126
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ReferenceElement, FloatingElement } from "./element.js";
|
|
2
|
+
import type { NormalizedPlacement, Placement } from "./geometry.js";
|
|
3
|
+
import type { Cleanup } from "./lifecycle.js";
|
|
4
|
+
export type Strategy = "absolute" | "fixed";
|
|
5
|
+
/** Collision boundary for flipping and shifting. */
|
|
6
|
+
export type PositionerBoundary = Element | "clippingAncestors" | "viewport";
|
|
7
|
+
/** Floating UI-compatible arrow element and boundary padding. */
|
|
8
|
+
export type ArrowOptions = {
|
|
9
|
+
element: Element;
|
|
10
|
+
/** Space kept between the arrow and the floating element edges. Defaults to 0. */
|
|
11
|
+
padding?: number;
|
|
12
|
+
};
|
|
13
|
+
export type ArrowData = {
|
|
14
|
+
/** Arrow offset relative to the floating element on its alignment axis. */
|
|
15
|
+
x?: number;
|
|
16
|
+
y?: number;
|
|
17
|
+
/** Offset from the floating element center; useful for custom arrow shapes. */
|
|
18
|
+
centerOffset: number;
|
|
19
|
+
};
|
|
20
|
+
export type PositionerOptions = {
|
|
21
|
+
/** Preferred placement; may be flipped by collision handling. */
|
|
22
|
+
placement?: Placement;
|
|
23
|
+
/** Gap between reference and floating element on the main axis. */
|
|
24
|
+
offset?: number;
|
|
25
|
+
/** Shift along the alignment axis. */
|
|
26
|
+
alignOffset?: number;
|
|
27
|
+
/** Flip to the opposite side when the preferred side overflows. */
|
|
28
|
+
flip?: boolean;
|
|
29
|
+
/** Shift along the cross axis to keep the floating element in view. */
|
|
30
|
+
shift?: boolean;
|
|
31
|
+
/** Padding from the collision boundary edges, in pixels. */
|
|
32
|
+
padding?: number;
|
|
33
|
+
boundary?: PositionerBoundary;
|
|
34
|
+
/**
|
|
35
|
+
* CSS positioning strategy. Omit for automatic: `absolute` (moves with the page
|
|
36
|
+
* in the same frame while scrolling) unless the anchor sits in a fixed/sticky
|
|
37
|
+
* ancestor or is a bare viewport point, which use `fixed`.
|
|
38
|
+
*/
|
|
39
|
+
strategy?: Strategy;
|
|
40
|
+
/** Keep the result updated on scroll, resize, and layout changes. */
|
|
41
|
+
autoUpdate?: boolean;
|
|
42
|
+
/** Optional arrow element measured by the positioning engine. */
|
|
43
|
+
arrow?: ArrowOptions | null;
|
|
44
|
+
};
|
|
45
|
+
export type CreatePositionerOptions = PositionerOptions & {
|
|
46
|
+
reference?: ReferenceElement | null;
|
|
47
|
+
floating?: FloatingElement | null;
|
|
48
|
+
};
|
|
49
|
+
export type PositionerResult = {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
/** The placement actually used after collision handling. */
|
|
53
|
+
placement: NormalizedPlacement;
|
|
54
|
+
strategy: Strategy;
|
|
55
|
+
/** Present only when an arrow element is configured and measured. */
|
|
56
|
+
arrow?: ArrowData;
|
|
57
|
+
};
|
|
58
|
+
export type PositionerListener = (result: PositionerResult) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Stateful, framework-independent positioning session.
|
|
61
|
+
*
|
|
62
|
+
* The instance owns no DOM of its own; it measures the supplied elements and
|
|
63
|
+
* reports results. `dispose()` stops observers and drops subscribers.
|
|
64
|
+
*/
|
|
65
|
+
export type Positioner = {
|
|
66
|
+
readonly isDisposed: boolean;
|
|
67
|
+
setReference(reference: ReferenceElement | null): void;
|
|
68
|
+
setFloating(floating: FloatingElement | null): void;
|
|
69
|
+
setOptions(options: Partial<PositionerOptions>): void;
|
|
70
|
+
/** Measure now. Resolves `null` when elements are missing or detached. */
|
|
71
|
+
update(): Promise<PositionerResult | null>;
|
|
72
|
+
subscribe(listener: PositionerListener): Cleanup;
|
|
73
|
+
dispose(): void;
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Align, NormalizedPlacement, Placement, Rect, Side, Size } from "./geometry.js";
|
|
2
|
+
export type PlacementOptions = {
|
|
3
|
+
placement?: Placement;
|
|
4
|
+
/** Gap between the reference and the floating element, in pixels. */
|
|
5
|
+
offset?: number;
|
|
6
|
+
/** Shift along the alignment axis, in pixels. */
|
|
7
|
+
alignOffset?: number;
|
|
8
|
+
};
|
|
9
|
+
export type PlacementCoordinatesInput = PlacementOptions & {
|
|
10
|
+
reference: Rect;
|
|
11
|
+
floating: Size;
|
|
12
|
+
};
|
|
13
|
+
export type PlacementCoordinates = {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
/** The normalized placement that was resolved. */
|
|
17
|
+
placement: NormalizedPlacement;
|
|
18
|
+
};
|
|
19
|
+
export type ParsedPlacement = {
|
|
20
|
+
placement: NormalizedPlacement;
|
|
21
|
+
side: Side;
|
|
22
|
+
align: Align;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReferenceElement } from "../types/element.js";
|
|
2
|
+
import type { Rect } from "../types/geometry.js";
|
|
3
|
+
/** True only when a usable browser DOM is present. Safe to call during SSR. */
|
|
4
|
+
export declare function isBrowser(): boolean;
|
|
5
|
+
/** Read a reference element's viewport rectangle as a plain object. */
|
|
6
|
+
export declare function getRect(element: ReferenceElement): Rect;
|
|
7
|
+
/**
|
|
8
|
+
* Duck-typed `Element` check. Avoids relying on cross-realm globals such as
|
|
9
|
+
* `instanceof Element`, which differ between an iframe and the parent document.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isElement(value: ReferenceElement | null | undefined): value is Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** True only when a usable browser DOM is present. Safe to call during SSR. */
|
|
2
|
+
export function isBrowser() {
|
|
3
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
4
|
+
}
|
|
5
|
+
/** Read a reference element's viewport rectangle as a plain object. */
|
|
6
|
+
export function getRect(element) {
|
|
7
|
+
const rect = element.getBoundingClientRect();
|
|
8
|
+
return {
|
|
9
|
+
x: rect.x,
|
|
10
|
+
y: rect.y,
|
|
11
|
+
width: rect.width,
|
|
12
|
+
height: rect.height,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Duck-typed `Element` check. Avoids relying on cross-realm globals such as
|
|
17
|
+
* `instanceof Element`, which differ between an iframe and the parent document.
|
|
18
|
+
*/
|
|
19
|
+
export function isElement(value) {
|
|
20
|
+
return typeof value?.nodeType === "number";
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ElementSource } from "../types/element.js";
|
|
2
|
+
/**
|
|
3
|
+
* Resolve a nullable element or an element getter to the current element.
|
|
4
|
+
*
|
|
5
|
+
* Never touches the DOM itself, so it is safe to call during SSR as long as the
|
|
6
|
+
* getter is safe (adapters only pass getters that read their own refs).
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveElement<T extends Element>(source: ElementSource<T> | null | undefined): T | null;
|
|
9
|
+
/**
|
|
10
|
+
* True when the element is currently attached to its document.
|
|
11
|
+
*
|
|
12
|
+
* Detached elements still render a zero rect but cannot be positioned
|
|
13
|
+
* meaningfully, so positioning skips them.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isConnected(element: Element | null | undefined): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a nullable element or an element getter to the current element.
|
|
3
|
+
*
|
|
4
|
+
* Never touches the DOM itself, so it is safe to call during SSR as long as the
|
|
5
|
+
* getter is safe (adapters only pass getters that read their own refs).
|
|
6
|
+
*/
|
|
7
|
+
export function resolveElement(source) {
|
|
8
|
+
if (!source) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return typeof source === "function" ? source() : source;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* True when the element is currently attached to its document.
|
|
15
|
+
*
|
|
16
|
+
* Detached elements still render a zero rect but cannot be positioned
|
|
17
|
+
* meaningfully, so positioning skips them.
|
|
18
|
+
*/
|
|
19
|
+
export function isConnected(element) {
|
|
20
|
+
return element?.isConnected === true;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getGlobalState<T>(name: string, create: () => T): T;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide state shared by every copy of Core loaded on a page.
|
|
3
|
+
*
|
|
4
|
+
* Each public adapter ships its own bundled copy of Core, so module-level
|
|
5
|
+
* variables would split per adapter (a React and a Vue overlay on the same
|
|
6
|
+
* page would get separate layer stacks, scroll locks, and id counters). State
|
|
7
|
+
* that must stay page-global lives on `globalThis` under a versioned
|
|
8
|
+
* `Symbol.for` key instead. Bump the version when a stored shape changes so
|
|
9
|
+
* incompatible copies never read each other's state.
|
|
10
|
+
*
|
|
11
|
+
* SSR-safe: it only touches `globalThis`, never `window` or `document`, and
|
|
12
|
+
* state is created lazily on first use.
|
|
13
|
+
*/
|
|
14
|
+
const STATE_VERSION = 1;
|
|
15
|
+
export function getGlobalState(name, create) {
|
|
16
|
+
const key = Symbol.for(`@zealakit/overlay-core/v${STATE_VERSION}/${name}`);
|
|
17
|
+
const store = globalThis;
|
|
18
|
+
let value = store[key];
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
value = create();
|
|
21
|
+
store[key] = value;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|