@octanejs/radix 0.1.32 → 0.1.34

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.
Files changed (60) hide show
  1. package/dist/cjs/AccessibleIcon.cjs +56 -0
  2. package/dist/cjs/Accordion.cjs +272 -0
  3. package/dist/cjs/AlertDialog.cjs +144 -0
  4. package/dist/cjs/Arrow.cjs +43 -0
  5. package/dist/cjs/AspectRatio.cjs +56 -0
  6. package/dist/cjs/Avatar.cjs +150 -0
  7. package/dist/cjs/Checkbox.cjs +281 -0
  8. package/dist/cjs/Collapsible.cjs +176 -0
  9. package/dist/cjs/ContextMenu.cjs +315 -0
  10. package/dist/cjs/Dialog.cjs +291 -0
  11. package/dist/cjs/DismissableLayer.cjs +382 -0
  12. package/dist/cjs/DropdownMenu.cjs +296 -0
  13. package/dist/cjs/FocusScope.cjs +257 -0
  14. package/dist/cjs/Form.cjs +537 -0
  15. package/dist/cjs/HoverCard.cjs +309 -0
  16. package/dist/cjs/Label.cjs +42 -0
  17. package/dist/cjs/Menu.cjs +925 -0
  18. package/dist/cjs/Menubar.cjs +475 -0
  19. package/dist/cjs/NavigationMenu.cjs +942 -0
  20. package/dist/cjs/OneTimePasswordField.cjs +729 -0
  21. package/dist/cjs/PasswordToggleField.cjs +377 -0
  22. package/dist/cjs/Popover.cjs +340 -0
  23. package/dist/cjs/Popper.cjs +368 -0
  24. package/dist/cjs/Portal.cjs +40 -0
  25. package/dist/cjs/Presence.cjs +183 -0
  26. package/dist/cjs/Primitive.cjs +63 -0
  27. package/dist/cjs/Progress.cjs +111 -0
  28. package/dist/cjs/Radio.cjs +240 -0
  29. package/dist/cjs/RadioGroup.cjs +216 -0
  30. package/dist/cjs/RovingFocusGroup.cjs +253 -0
  31. package/dist/cjs/ScrollArea.cjs +828 -0
  32. package/dist/cjs/Select.cjs +1429 -0
  33. package/dist/cjs/Separator.cjs +51 -0
  34. package/dist/cjs/Slider.cjs +634 -0
  35. package/dist/cjs/Slot.cjs +97 -0
  36. package/dist/cjs/Switch.cjs +253 -0
  37. package/dist/cjs/Tabs.cjs +195 -0
  38. package/dist/cjs/Toast.cjs +733 -0
  39. package/dist/cjs/Toggle.cjs +54 -0
  40. package/dist/cjs/ToggleGroup.cjs +174 -0
  41. package/dist/cjs/Toolbar.cjs +165 -0
  42. package/dist/cjs/Tooltip.cjs +628 -0
  43. package/dist/cjs/VisuallyHidden.cjs +52 -0
  44. package/dist/cjs/collection.cjs +95 -0
  45. package/dist/cjs/compose-event-handlers.cjs +35 -0
  46. package/dist/cjs/compose-refs.cjs +68 -0
  47. package/dist/cjs/context.cjs +96 -0
  48. package/dist/cjs/direction.cjs +41 -0
  49. package/dist/cjs/focus-guards.cjs +76 -0
  50. package/dist/cjs/index.cjs +174 -0
  51. package/dist/cjs/internal.cjs +51 -0
  52. package/dist/cjs/scroll-lock.cjs +67 -0
  53. package/dist/cjs/use-callback-ref.cjs +47 -0
  54. package/dist/cjs/use-effect-event.cjs +52 -0
  55. package/dist/cjs/use-is-hydrated.cjs +43 -0
  56. package/dist/cjs/use-previous.cjs +47 -0
  57. package/dist/cjs/use-size.cjs +69 -0
  58. package/dist/cjs/useControllableState.cjs +80 -0
  59. package/dist/cjs/useId.cjs +36 -0
  60. package/package.json +14 -7
@@ -0,0 +1,368 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Popper_exports = {};
30
+ __export(Popper_exports, {
31
+ ALIGN_OPTIONS: () => ALIGN_OPTIONS,
32
+ Anchor: () => Anchor,
33
+ Arrow: () => Arrow,
34
+ Content: () => Content,
35
+ Popper: () => Root,
36
+ PopperAnchor: () => Anchor,
37
+ PopperArrow: () => Arrow,
38
+ PopperContent: () => Content,
39
+ Root: () => Root,
40
+ SIDE_OPTIONS: () => SIDE_OPTIONS,
41
+ createPopperScope: () => createPopperScope
42
+ });
43
+ module.exports = __toCommonJS(Popper_exports);
44
+ var import_floating_ui = require("@octanejs/floating-ui");
45
+ var import_octane = require("octane");
46
+ var ArrowPrimitive = __toESM(require("./Arrow.cjs"), 1);
47
+ var import_compose_refs = require("./compose-refs.cjs");
48
+ var import_context = require("./context.cjs");
49
+ var import_internal = require("./internal.cjs");
50
+ var import_Primitive = require("./Primitive.cjs");
51
+ var import_use_size = require("./use-size.cjs");
52
+ const SIDE_OPTIONS = ["top", "right", "bottom", "left"];
53
+ const ALIGN_OPTIONS = ["start", "center", "end"];
54
+ const [createPopperContext, createPopperScope] = (0, import_context.createContextScope)("Popper");
55
+ const [PopperProvider, usePopperContext] = createPopperContext("Popper");
56
+ const [PopperContentProvider, useContentContext] = createPopperContext("PopperContent");
57
+ function Root(props) {
58
+ const slot = (0, import_internal.S)("Popper.Root");
59
+ const { __scopePopper, children } = props ?? {};
60
+ const [anchor, setAnchor] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "anchor"));
61
+ const [placementState, setPlacementState] = (0, import_octane.useState)(
62
+ void 0,
63
+ (0, import_internal.subSlot)(slot, "placement")
64
+ );
65
+ return (0, import_octane.createElement)(PopperProvider, {
66
+ scope: __scopePopper,
67
+ anchor,
68
+ onAnchorChange: setAnchor,
69
+ placementState,
70
+ setPlacementState,
71
+ children
72
+ });
73
+ }
74
+ function Anchor(props) {
75
+ const slot = (0, import_internal.S)("Popper.Anchor");
76
+ const { __scopePopper, virtualRef, ref: forwardedRef, ...anchorProps } = props ?? {};
77
+ const context = usePopperContext("PopperAnchor", __scopePopper);
78
+ const ref = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "ref"));
79
+ const onAnchorChange = context.onAnchorChange;
80
+ const callbackRef = (0, import_octane.useCallback)(
81
+ (node) => {
82
+ ref.current = node;
83
+ if (node) onAnchorChange(node);
84
+ },
85
+ [onAnchorChange],
86
+ (0, import_internal.subSlot)(slot, "cb")
87
+ );
88
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, callbackRef, (0, import_internal.subSlot)(slot, "refs"));
89
+ const anchorRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "virtual"));
90
+ (0, import_octane.useEffect)(
91
+ () => {
92
+ if (!virtualRef) return;
93
+ const previousAnchor = anchorRef.current;
94
+ anchorRef.current = virtualRef.current;
95
+ if (previousAnchor !== anchorRef.current) {
96
+ onAnchorChange(anchorRef.current);
97
+ }
98
+ },
99
+ void 0,
100
+ (0, import_internal.subSlot)(slot, "e:virtual")
101
+ );
102
+ const sideAndAlign = context.placementState && getSideAndAlignFromPlacement(context.placementState);
103
+ const placedSide = sideAndAlign ? sideAndAlign[0] : void 0;
104
+ const placedAlign = sideAndAlign ? sideAndAlign[1] : void 0;
105
+ return virtualRef ? null : (0, import_octane.createElement)(import_Primitive.Primitive.div, {
106
+ "data-radix-popper-side": placedSide,
107
+ "data-radix-popper-align": placedAlign,
108
+ ...anchorProps,
109
+ ref: composedRefs
110
+ });
111
+ }
112
+ function Content(props) {
113
+ const slot = (0, import_internal.S)("Popper.Content");
114
+ const {
115
+ __scopePopper,
116
+ side = "bottom",
117
+ sideOffset = 0,
118
+ align = "center",
119
+ alignOffset = 0,
120
+ arrowPadding = 0,
121
+ avoidCollisions = true,
122
+ collisionBoundary = [],
123
+ collisionPadding: collisionPaddingProp = 0,
124
+ sticky = "partial",
125
+ hideWhenDetached = false,
126
+ updatePositionStrategy = "optimized",
127
+ onPlaced,
128
+ ref: forwardedRef,
129
+ ...contentProps
130
+ } = props ?? {};
131
+ const context = usePopperContext("PopperContent", __scopePopper);
132
+ const [content, setContent] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "content"));
133
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setContent, (0, import_internal.subSlot)(slot, "refs"));
134
+ const [arrow, setArrow] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "arrow"));
135
+ const arrowSize = (0, import_use_size.useSize)(arrow, (0, import_internal.subSlot)(slot, "arrowSize"));
136
+ const arrowWidth = arrowSize?.width ?? 0;
137
+ const arrowHeight = arrowSize?.height ?? 0;
138
+ const desiredPlacement = side + (align !== "center" ? "-" + align : "");
139
+ const collisionPadding = typeof collisionPaddingProp === "number" ? collisionPaddingProp : { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };
140
+ const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];
141
+ const hasExplicitBoundaries = boundary.length > 0;
142
+ const detectOverflowOptions = {
143
+ padding: collisionPadding,
144
+ boundary: boundary.filter(isNotNull),
145
+ // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
146
+ altBoundary: hasExplicitBoundaries
147
+ };
148
+ const { refs, floatingStyles, placement, isPositioned, middlewareData } = (0, import_floating_ui.usePositionFloating)([
149
+ {
150
+ // default to `fixed` strategy so users don't have to pick and we also avoid
151
+ // focus scroll issues
152
+ strategy: "fixed",
153
+ placement: desiredPlacement,
154
+ whileElementsMounted: (...args) => {
155
+ const cleanup = (0, import_floating_ui.autoUpdate)(...args, {
156
+ animationFrame: updatePositionStrategy === "always"
157
+ });
158
+ return cleanup;
159
+ },
160
+ elements: { reference: context.anchor },
161
+ middleware: [
162
+ (0, import_floating_ui.offset)({ mainAxis: sideOffset + arrowHeight, alignmentAxis: alignOffset }),
163
+ avoidCollisions && (0, import_floating_ui.shift)({
164
+ mainAxis: true,
165
+ crossAxis: false,
166
+ limiter: sticky === "partial" ? (0, import_floating_ui.limitShift)() : void 0,
167
+ ...detectOverflowOptions
168
+ }),
169
+ avoidCollisions && (0, import_floating_ui.flip)({ ...detectOverflowOptions }),
170
+ (0, import_floating_ui.size)({
171
+ ...detectOverflowOptions,
172
+ apply: ({ elements, rects, availableWidth, availableHeight }) => {
173
+ const { width: anchorWidth, height: anchorHeight } = rects.reference;
174
+ const contentStyle = elements.floating.style;
175
+ contentStyle.setProperty("--radix-popper-available-width", `${availableWidth}px`);
176
+ contentStyle.setProperty("--radix-popper-available-height", `${availableHeight}px`);
177
+ contentStyle.setProperty("--radix-popper-anchor-width", `${anchorWidth}px`);
178
+ contentStyle.setProperty("--radix-popper-anchor-height", `${anchorHeight}px`);
179
+ }
180
+ }),
181
+ arrow && (0, import_floating_ui.arrow)({ element: arrow, padding: arrowPadding }),
182
+ transformOrigin({ arrowWidth, arrowHeight }),
183
+ hideWhenDetached && (0, import_floating_ui.hide)({
184
+ strategy: "referenceHidden",
185
+ ...detectOverflowOptions,
186
+ // `hide` detects whether the anchor is clipped — with no explicit
187
+ // collisionBoundary fall back to Floating UI's default clipping
188
+ // ancestors so an occluded submenu hides when its anchor scrolls out
189
+ // of view (radix-ui/primitives#3237).
190
+ boundary: hasExplicitBoundaries ? detectOverflowOptions.boundary : void 0
191
+ })
192
+ ]
193
+ },
194
+ (0, import_internal.subSlot)(slot, "floating")
195
+ ]);
196
+ const setPlacementState = context.setPlacementState;
197
+ (0, import_octane.useLayoutEffect)(
198
+ () => {
199
+ setPlacementState(placement);
200
+ return () => setPlacementState(void 0);
201
+ },
202
+ [placement],
203
+ (0, import_internal.subSlot)(slot, "e:placement")
204
+ );
205
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
206
+ const handlePlaced = (0, import_octane.useEffectEvent)(onPlaced ?? (() => {
207
+ }), (0, import_internal.subSlot)(slot, "placed"));
208
+ (0, import_octane.useLayoutEffect)(
209
+ () => {
210
+ if (isPositioned) handlePlaced();
211
+ },
212
+ [isPositioned],
213
+ (0, import_internal.subSlot)(slot, "e:placed")
214
+ );
215
+ const arrowX = middlewareData.arrow?.x;
216
+ const arrowY = middlewareData.arrow?.y;
217
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
218
+ const [contentZIndex, setContentZIndex] = (0, import_octane.useState)(
219
+ void 0,
220
+ (0, import_internal.subSlot)(slot, "z")
221
+ );
222
+ (0, import_octane.useLayoutEffect)(
223
+ () => {
224
+ if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
225
+ },
226
+ [content],
227
+ (0, import_internal.subSlot)(slot, "e:z")
228
+ );
229
+ return (0, import_octane.createElement)("div", {
230
+ ref: refs.setFloating,
231
+ "data-radix-popper-content-wrapper": "",
232
+ style: {
233
+ ...floatingStyles,
234
+ // keep off the page when measuring
235
+ transform: isPositioned ? floatingStyles.transform : "translate(0, -200%)",
236
+ minWidth: "max-content",
237
+ zIndex: contentZIndex,
238
+ "--radix-popper-transform-origin": [
239
+ middlewareData.transformOrigin?.x,
240
+ middlewareData.transformOrigin?.y
241
+ ].join(" "),
242
+ // hide the content if using the hide middleware and should be hidden — set
243
+ // visibility to hidden and disable pointer events so the UI behaves as if the
244
+ // PopperContent isn't there at all
245
+ ...middlewareData.hide?.referenceHidden && {
246
+ visibility: "hidden",
247
+ pointerEvents: "none"
248
+ }
249
+ },
250
+ // Floating UI internally calculates logical alignment based on the `dir` attribute
251
+ // on the reference/floating node — add it here so it's computed when portalled too.
252
+ dir: props?.dir,
253
+ children: (0, import_octane.createElement)(PopperContentProvider, {
254
+ scope: __scopePopper,
255
+ placedSide,
256
+ placedAlign,
257
+ onArrowChange: setArrow,
258
+ arrowX,
259
+ arrowY,
260
+ shouldHideArrow: cannotCenterArrow,
261
+ children: (0, import_octane.createElement)(import_Primitive.Primitive.div, {
262
+ "data-side": placedSide,
263
+ "data-align": placedAlign,
264
+ ...contentProps,
265
+ ref: composedRefs,
266
+ style: {
267
+ ...contentProps.style,
268
+ // if the PopperContent hasn't been placed yet (not all measurements done)
269
+ // prevent animations so they don't kick in referring to the wrong side
270
+ animation: !isPositioned ? "none" : void 0
271
+ }
272
+ })
273
+ })
274
+ });
275
+ }
276
+ const OPPOSITE_SIDE = {
277
+ top: "bottom",
278
+ right: "left",
279
+ bottom: "top",
280
+ left: "right"
281
+ };
282
+ function Arrow(props) {
283
+ const { __scopePopper, ...arrowProps } = props ?? {};
284
+ const contentContext = useContentContext("PopperArrow", __scopePopper);
285
+ const baseSide = OPPOSITE_SIDE[contentContext.placedSide];
286
+ return (0, import_octane.createElement)("span", {
287
+ ref: contentContext.onArrowChange,
288
+ style: {
289
+ position: "absolute",
290
+ left: contentContext.arrowX,
291
+ top: contentContext.arrowY,
292
+ [baseSide]: 0,
293
+ transformOrigin: {
294
+ top: "",
295
+ right: "0 0",
296
+ bottom: "center 0",
297
+ left: "100% 0"
298
+ }[contentContext.placedSide],
299
+ transform: {
300
+ top: "translateY(100%)",
301
+ right: "translateY(50%) rotate(90deg) translateX(-50%)",
302
+ bottom: `rotate(180deg)`,
303
+ left: "translateY(50%) rotate(-90deg) translateX(50%)"
304
+ }[contentContext.placedSide],
305
+ visibility: contentContext.shouldHideArrow ? "hidden" : void 0
306
+ },
307
+ children: (0, import_octane.createElement)(ArrowPrimitive.Root, {
308
+ ...arrowProps,
309
+ style: {
310
+ ...arrowProps.style,
311
+ // ensures the element can be measured correctly (mostly for if SVG)
312
+ display: "block"
313
+ }
314
+ })
315
+ });
316
+ }
317
+ function isNotNull(value) {
318
+ return value !== null;
319
+ }
320
+ const transformOrigin = (options) => ({
321
+ name: "transformOrigin",
322
+ options,
323
+ fn(data) {
324
+ const { placement, rects, middlewareData } = data;
325
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
326
+ const isArrowHidden = cannotCenterArrow;
327
+ const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
328
+ const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
329
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
330
+ const noArrowAlign = { start: "0%", center: "50%", end: "100%" }[placedAlign];
331
+ const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
332
+ const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
333
+ let x = "";
334
+ let y = "";
335
+ if (placedSide === "bottom") {
336
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
337
+ y = `${-arrowHeight}px`;
338
+ } else if (placedSide === "top") {
339
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
340
+ y = `${rects.floating.height + arrowHeight}px`;
341
+ } else if (placedSide === "right") {
342
+ x = `${-arrowHeight}px`;
343
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
344
+ } else if (placedSide === "left") {
345
+ x = `${rects.floating.width + arrowHeight}px`;
346
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
347
+ }
348
+ return { data: { x, y } };
349
+ }
350
+ });
351
+ function getSideAndAlignFromPlacement(placement) {
352
+ const [side, align = "center"] = placement.split("-");
353
+ return [side, align];
354
+ }
355
+ // Annotate the CommonJS export names for ESM import in node:
356
+ 0 && (module.exports = {
357
+ ALIGN_OPTIONS,
358
+ Anchor,
359
+ Arrow,
360
+ Content,
361
+ Popper,
362
+ PopperAnchor,
363
+ PopperArrow,
364
+ PopperContent,
365
+ Root,
366
+ SIDE_OPTIONS,
367
+ createPopperScope
368
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Portal_exports = {};
20
+ __export(Portal_exports, {
21
+ Portal: () => Portal,
22
+ Root: () => Portal
23
+ });
24
+ module.exports = __toCommonJS(Portal_exports);
25
+ var import_octane = require("octane");
26
+ var import_internal = require("./internal.cjs");
27
+ var import_Primitive = require("./Primitive.cjs");
28
+ function Portal(props) {
29
+ const slot = (0, import_internal.S)("Portal");
30
+ const { container: containerProp, ...portalProps } = props ?? {};
31
+ const [mounted, setMounted] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "mounted"));
32
+ (0, import_octane.useLayoutEffect)(() => setMounted(true), [], (0, import_internal.subSlot)(slot, "e:mount"));
33
+ const container = containerProp || mounted && globalThis?.document?.body;
34
+ return container ? (0, import_octane.createPortal)((0, import_octane.createElement)(import_Primitive.Primitive.div, portalProps), container) : null;
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ Portal,
39
+ Root
40
+ });
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Presence_exports = {};
20
+ __export(Presence_exports, {
21
+ Presence: () => Presence,
22
+ Root: () => Presence
23
+ });
24
+ module.exports = __toCommonJS(Presence_exports);
25
+ var import_octane = require("octane");
26
+ var import_internal = require("./internal.cjs");
27
+ const TRANSITIONS = {
28
+ mounted: { UNMOUNT: "unmounted", ANIMATION_OUT: "unmountSuspended" },
29
+ unmountSuspended: { MOUNT: "mounted", ANIMATION_END: "unmounted" },
30
+ unmounted: { MOUNT: "mounted" }
31
+ };
32
+ function getAnimationName(styles) {
33
+ return styles?.animationName || "none";
34
+ }
35
+ function usePresence(present, slot) {
36
+ const [node, setNode] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "node"));
37
+ const stylesRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "styles"));
38
+ const prevPresentRef = (0, import_octane.useRef)(present, (0, import_internal.subSlot)(slot, "prevPresent"));
39
+ const prevAnimationNameRef = (0, import_octane.useRef)("none", (0, import_internal.subSlot)(slot, "prevAnim"));
40
+ const [state, setState] = (0, import_octane.useState)(
41
+ present ? "mounted" : "unmounted",
42
+ (0, import_internal.subSlot)(slot, "state")
43
+ );
44
+ const send = (0, import_octane.useCallback)(
45
+ (event) => {
46
+ setState((prev) => TRANSITIONS[prev][event] ?? prev);
47
+ },
48
+ [],
49
+ (0, import_internal.subSlot)(slot, "send")
50
+ );
51
+ (0, import_octane.useEffect)(
52
+ () => {
53
+ const currentAnimationName = getAnimationName(stylesRef.current);
54
+ prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
55
+ },
56
+ [state],
57
+ (0, import_internal.subSlot)(slot, "e:anim")
58
+ );
59
+ (0, import_octane.useLayoutEffect)(
60
+ () => {
61
+ const styles = stylesRef.current;
62
+ const wasPresent = prevPresentRef.current;
63
+ const hasPresentChanged = wasPresent !== present;
64
+ if (hasPresentChanged) {
65
+ const prevAnimationName = prevAnimationNameRef.current;
66
+ const currentAnimationName = getAnimationName(styles);
67
+ if (present) {
68
+ send("MOUNT");
69
+ } else if (currentAnimationName === "none" || styles?.display === "none") {
70
+ send("UNMOUNT");
71
+ } else {
72
+ const isAnimating = prevAnimationName !== currentAnimationName;
73
+ send(wasPresent && isAnimating ? "ANIMATION_OUT" : "UNMOUNT");
74
+ }
75
+ prevPresentRef.current = present;
76
+ }
77
+ },
78
+ [present],
79
+ (0, import_internal.subSlot)(slot, "e:present")
80
+ );
81
+ (0, import_octane.useLayoutEffect)(
82
+ () => {
83
+ if (node) {
84
+ let timeoutId;
85
+ const ownerWindow = node.ownerDocument.defaultView ?? window;
86
+ const handleAnimationEnd = (event) => {
87
+ const currentAnimationName = getAnimationName(stylesRef.current);
88
+ const escaped = typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(event.animationName) : event.animationName;
89
+ const isCurrentAnimation = currentAnimationName.includes(escaped);
90
+ if (event.target === node && isCurrentAnimation) {
91
+ send("ANIMATION_END");
92
+ if (!prevPresentRef.current) {
93
+ const currentFillMode = node.style.animationFillMode;
94
+ node.style.animationFillMode = "forwards";
95
+ timeoutId = ownerWindow.setTimeout(() => {
96
+ if (node.style.animationFillMode === "forwards") {
97
+ node.style.animationFillMode = currentFillMode;
98
+ }
99
+ });
100
+ }
101
+ }
102
+ };
103
+ const handleAnimationStart = (event) => {
104
+ if (event.target === node) {
105
+ prevAnimationNameRef.current = getAnimationName(stylesRef.current);
106
+ }
107
+ };
108
+ node.addEventListener("animationstart", handleAnimationStart);
109
+ node.addEventListener("animationcancel", handleAnimationEnd);
110
+ node.addEventListener("animationend", handleAnimationEnd);
111
+ return () => {
112
+ ownerWindow.clearTimeout(timeoutId);
113
+ node.removeEventListener("animationstart", handleAnimationStart);
114
+ node.removeEventListener("animationcancel", handleAnimationEnd);
115
+ node.removeEventListener("animationend", handleAnimationEnd);
116
+ };
117
+ } else {
118
+ send("ANIMATION_END");
119
+ }
120
+ },
121
+ [node],
122
+ (0, import_internal.subSlot)(slot, "e:node")
123
+ );
124
+ return {
125
+ isPresent: state === "mounted" || state === "unmountSuspended",
126
+ ref: (0, import_octane.useCallback)(
127
+ (el) => {
128
+ stylesRef.current = el ? getComputedStyle(el) : null;
129
+ setNode(el);
130
+ },
131
+ [],
132
+ (0, import_internal.subSlot)(slot, "ref")
133
+ )
134
+ };
135
+ }
136
+ function useStableComposedRefs(refs, slot) {
137
+ const refsRef = (0, import_octane.useRef)(refs, (0, import_internal.subSlot)(slot, "refsRef"));
138
+ refsRef.current = refs;
139
+ return (0, import_octane.useCallback)(
140
+ (node) => {
141
+ const currentRefs = refsRef.current;
142
+ let hasCleanup = false;
143
+ const cleanups = currentRefs.map((ref) => {
144
+ const cleanup = setRefValue(ref, node);
145
+ if (!hasCleanup && typeof cleanup === "function") hasCleanup = true;
146
+ return cleanup;
147
+ });
148
+ if (hasCleanup) {
149
+ return () => {
150
+ for (let i = 0; i < cleanups.length; i++) {
151
+ const cleanup = cleanups[i];
152
+ if (typeof cleanup === "function") cleanup();
153
+ else setRefValue(currentRefs[i], null);
154
+ }
155
+ };
156
+ }
157
+ },
158
+ [],
159
+ (0, import_internal.subSlot)(slot, "cb")
160
+ );
161
+ }
162
+ function setRefValue(ref, value) {
163
+ if (typeof ref === "function") return ref(value);
164
+ if (ref !== null && ref !== void 0) ref.current = value;
165
+ }
166
+ function Presence(props) {
167
+ const { present, children } = props;
168
+ const slot = (0, import_internal.S)("Presence");
169
+ const presence = usePresence(present, slot);
170
+ const forceMount = typeof children === "function";
171
+ const child = forceMount ? children({ present: presence.isPresent }) : import_octane.Children.only(children);
172
+ const childRef = (0, import_octane.isValidElement)(child) ? child.props?.ref : void 0;
173
+ const ref = useStableComposedRefs([presence.ref, childRef], slot);
174
+ if (forceMount || presence.isPresent) {
175
+ return (0, import_octane.isValidElement)(child) ? (0, import_octane.cloneElement)(child, { ref }) : child;
176
+ }
177
+ return null;
178
+ }
179
+ // Annotate the CommonJS export names for ESM import in node:
180
+ 0 && (module.exports = {
181
+ Presence,
182
+ Root
183
+ });
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Primitive_exports = {};
20
+ __export(Primitive_exports, {
21
+ Primitive: () => Primitive,
22
+ dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent
23
+ });
24
+ module.exports = __toCommonJS(Primitive_exports);
25
+ var import_octane = require("octane");
26
+ var import_Slot = require("./Slot.cjs");
27
+ function dispatchDiscreteCustomEvent(target, event) {
28
+ if (target) (0, import_octane.flushSync)(() => target.dispatchEvent(event));
29
+ }
30
+ const NODES = [
31
+ "a",
32
+ "button",
33
+ "div",
34
+ "form",
35
+ "h2",
36
+ "h3",
37
+ "img",
38
+ "input",
39
+ "label",
40
+ "li",
41
+ "nav",
42
+ "ol",
43
+ "p",
44
+ "select",
45
+ "span",
46
+ "svg",
47
+ "ul"
48
+ ];
49
+ function makePrimitive(node) {
50
+ return function Primitive2(props) {
51
+ const { asChild, ...primitiveProps } = props ?? {};
52
+ return asChild ? (0, import_octane.createElement)(import_Slot.Slot, primitiveProps) : (0, import_octane.createElement)(node, primitiveProps);
53
+ };
54
+ }
55
+ const Primitive = {};
56
+ for (const node of NODES) {
57
+ Primitive[node] = makePrimitive(node);
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ Primitive,
62
+ dispatchDiscreteCustomEvent
63
+ });