@yoopta/themes-shadcn 6.0.1 → 6.0.2

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 (139) hide show
  1. package/dist/embed/elements/embed/embed-element.d.ts +1 -1
  2. package/dist/embed/elements/embed/embed-element.d.ts.map +1 -1
  3. package/dist/embed/elements/embed/embed-render.d.ts.map +1 -1
  4. package/dist/embed/index.d.ts +1 -1
  5. package/dist/embed.js +2 -2
  6. package/dist/file/elements/file/file-element.d.ts +1 -1
  7. package/dist/file/elements/file/file-element.d.ts.map +1 -1
  8. package/dist/file/index.d.ts +1 -1
  9. package/dist/file.js +2 -2
  10. package/dist/image/elements/image/image-element.d.ts +1 -1
  11. package/dist/image/elements/image/image-element.d.ts.map +1 -1
  12. package/dist/image/elements/image/image-render.d.ts.map +1 -1
  13. package/dist/image/index.d.ts +1 -1
  14. package/dist/image.js +2 -2
  15. package/dist/index.js +1 -1
  16. package/dist/steps/elements/steps-list-item.d.ts.map +1 -1
  17. package/dist/steps.js +1 -1
  18. package/dist/video/elements/video/video-element.d.ts +1 -1
  19. package/dist/video/elements/video/video-element.d.ts.map +1 -1
  20. package/dist/video/elements/video/video-render.d.ts.map +1 -1
  21. package/dist/video/index.d.ts +1 -1
  22. package/dist/video.js +2 -2
  23. package/package.json +13 -13
  24. package/dist/accordion.js.map +0 -1
  25. package/dist/blockquote.js.map +0 -1
  26. package/dist/callout.js.map +0 -1
  27. package/dist/carousel.js.map +0 -1
  28. package/dist/chunks/Combination-3c924518.js +0 -1080
  29. package/dist/chunks/Combination-3c924518.js.map +0 -1
  30. package/dist/chunks/_tslib-514d60fe.js +0 -67
  31. package/dist/chunks/_tslib-514d60fe.js.map +0 -1
  32. package/dist/chunks/arrow-right-5ddace59.js +0 -30
  33. package/dist/chunks/arrow-right-5ddace59.js.map +0 -1
  34. package/dist/chunks/button-27a1fbc2.js +0 -76
  35. package/dist/chunks/button-27a1fbc2.js.map +0 -1
  36. package/dist/chunks/card-12ed876a.js +0 -38
  37. package/dist/chunks/card-12ed876a.js.map +0 -1
  38. package/dist/chunks/check-9acc031a.js +0 -14
  39. package/dist/chunks/check-9acc031a.js.map +0 -1
  40. package/dist/chunks/chevron-down-7424d0c3.js +0 -16
  41. package/dist/chunks/chevron-down-7424d0c3.js.map +0 -1
  42. package/dist/chunks/chevron-up-546faa64.js +0 -14
  43. package/dist/chunks/chevron-up-546faa64.js.map +0 -1
  44. package/dist/chunks/code-5407bf8e.js +0 -17
  45. package/dist/chunks/code-5407bf8e.js.map +0 -1
  46. package/dist/chunks/createLucideIcon-6ba35914.js +0 -56
  47. package/dist/chunks/createLucideIcon-6ba35914.js.map +0 -1
  48. package/dist/chunks/dropdown-menu-9ba446af.js +0 -1250
  49. package/dist/chunks/dropdown-menu-9ba446af.js.map +0 -1
  50. package/dist/chunks/external-link-1bf3c7a2.js +0 -18
  51. package/dist/chunks/external-link-1bf3c7a2.js.map +0 -1
  52. package/dist/chunks/file-text-9e348575.js +0 -23
  53. package/dist/chunks/file-text-9e348575.js.map +0 -1
  54. package/dist/chunks/hover-card-22a4067b.js +0 -258
  55. package/dist/chunks/hover-card-22a4067b.js.map +0 -1
  56. package/dist/chunks/index-0c94b090.js +0 -222
  57. package/dist/chunks/index-0c94b090.js.map +0 -1
  58. package/dist/chunks/index-12e7c5fd.js +0 -155
  59. package/dist/chunks/index-12e7c5fd.js.map +0 -1
  60. package/dist/chunks/index-26994c9d.js +0 -131
  61. package/dist/chunks/index-26994c9d.js.map +0 -1
  62. package/dist/chunks/index-600be8f8.js +0 -190
  63. package/dist/chunks/index-600be8f8.js.map +0 -1
  64. package/dist/chunks/index-7e966ec9.js +0 -16
  65. package/dist/chunks/index-7e966ec9.js.map +0 -1
  66. package/dist/chunks/index-9ac5afe2.js +0 -201
  67. package/dist/chunks/index-9ac5afe2.js.map +0 -1
  68. package/dist/chunks/index-9bb7ddb4.js +0 -104
  69. package/dist/chunks/index-9bb7ddb4.js.map +0 -1
  70. package/dist/chunks/index-ae9b48d5.js +0 -12
  71. package/dist/chunks/index-ae9b48d5.js.map +0 -1
  72. package/dist/chunks/index-b26053ec.js +0 -3805
  73. package/dist/chunks/index-b26053ec.js.map +0 -1
  74. package/dist/chunks/index-b8f2908d.js +0 -40
  75. package/dist/chunks/index-b8f2908d.js.map +0 -1
  76. package/dist/chunks/index-c655a86f.js +0 -7
  77. package/dist/chunks/index-c655a86f.js.map +0 -1
  78. package/dist/chunks/index-d9171717.js +0 -13
  79. package/dist/chunks/index-d9171717.js.map +0 -1
  80. package/dist/chunks/index-e42d0aaf.js +0 -36
  81. package/dist/chunks/index-e42d0aaf.js.map +0 -1
  82. package/dist/chunks/index-ebc47eac.js +0 -2765
  83. package/dist/chunks/index-ebc47eac.js.map +0 -1
  84. package/dist/chunks/index-ffe23855.js +0 -71
  85. package/dist/chunks/index-ffe23855.js.map +0 -1
  86. package/dist/chunks/input-7c5e4260.js +0 -13
  87. package/dist/chunks/input-7c5e4260.js.map +0 -1
  88. package/dist/chunks/label-2a076b3f.js +0 -70
  89. package/dist/chunks/label-2a076b3f.js.map +0 -1
  90. package/dist/chunks/language-select-b35256ab.js +0 -12
  91. package/dist/chunks/language-select-b35256ab.js.map +0 -1
  92. package/dist/chunks/play-c2a06e4e.js +0 -16
  93. package/dist/chunks/play-c2a06e4e.js.map +0 -1
  94. package/dist/chunks/plus-f36f52e8.js +0 -17
  95. package/dist/chunks/plus-f36f52e8.js.map +0 -1
  96. package/dist/chunks/popover-4b5c0941.js +0 -385
  97. package/dist/chunks/popover-4b5c0941.js.map +0 -1
  98. package/dist/chunks/scroll-area-8dc03d8f.js +0 -727
  99. package/dist/chunks/scroll-area-8dc03d8f.js.map +0 -1
  100. package/dist/chunks/select-88f1b66c.js +0 -1281
  101. package/dist/chunks/select-88f1b66c.js.map +0 -1
  102. package/dist/chunks/separator-a6b3e5d2.js +0 -74
  103. package/dist/chunks/separator-a6b3e5d2.js.map +0 -1
  104. package/dist/chunks/settings-2-8e53118c.js +0 -19
  105. package/dist/chunks/settings-2-8e53118c.js.map +0 -1
  106. package/dist/chunks/sparkles-a0316be3.js +0 -26
  107. package/dist/chunks/sparkles-a0316be3.js.map +0 -1
  108. package/dist/chunks/style-inject.es-746bb8ed.js +0 -29
  109. package/dist/chunks/style-inject.es-746bb8ed.js.map +0 -1
  110. package/dist/chunks/tabs-38ee85c4.js +0 -205
  111. package/dist/chunks/tabs-38ee85c4.js.map +0 -1
  112. package/dist/chunks/tooltip-eb8a0f63.js +0 -1671
  113. package/dist/chunks/tooltip-eb8a0f63.js.map +0 -1
  114. package/dist/chunks/trash-2-41ddec45.js +0 -20
  115. package/dist/chunks/trash-2-41ddec45.js.map +0 -1
  116. package/dist/chunks/upload-b987996c.js +0 -44
  117. package/dist/chunks/upload-b987996c.js.map +0 -1
  118. package/dist/chunks/utils-208f599b.js +0 -2500
  119. package/dist/chunks/utils-208f599b.js.map +0 -1
  120. package/dist/chunks/x-f7edc87d.js +0 -17
  121. package/dist/chunks/x-f7edc87d.js.map +0 -1
  122. package/dist/code-group.js.map +0 -1
  123. package/dist/code.js.map +0 -1
  124. package/dist/divider.js.map +0 -1
  125. package/dist/embed.js.map +0 -1
  126. package/dist/emoji.js.map +0 -1
  127. package/dist/file.js.map +0 -1
  128. package/dist/headings.js.map +0 -1
  129. package/dist/image.js.map +0 -1
  130. package/dist/index.js.map +0 -1
  131. package/dist/link.js.map +0 -1
  132. package/dist/lists.js.map +0 -1
  133. package/dist/mention.js.map +0 -1
  134. package/dist/paragraph.js.map +0 -1
  135. package/dist/steps.js.map +0 -1
  136. package/dist/table-of-contents.js.map +0 -1
  137. package/dist/table.js.map +0 -1
  138. package/dist/tabs.js.map +0 -1
  139. package/dist/video.js.map +0 -1
@@ -1,1671 +0,0 @@
1
- import { c as createLucideIcon } from './createLucideIcon-6ba35914.js';
2
- import * as React from 'react';
3
- import { useLayoutEffect, useEffect } from 'react';
4
- import { i as isShadowRoot, u as useFloating$1, d as isElement, c as createPopperScope, A as Anchor, D as DismissableLayer, C as Content, a as Arrow, R as Root2, P as Portal$1 } from './index-ebc47eac.js';
5
- import * as ReactDOM from 'react-dom';
6
- import { _ as __rest } from './_tslib-514d60fe.js';
7
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
8
- import { c as createContextScope, P as Primitive, a as composeEventHandlers } from './index-9ac5afe2.js';
9
- import { u as useComposedRefs } from './index-b8f2908d.js';
10
- import { u as useId$1 } from './index-7e966ec9.js';
11
- import { P as Presence } from './index-26994c9d.js';
12
- import { u as useControllableState } from './index-ffe23855.js';
13
- import { R as Root } from './index-e42d0aaf.js';
14
- import { c as cn } from './utils-208f599b.js';
15
-
16
- /**
17
- * @license lucide-react v0.294.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */
22
-
23
-
24
- const RotateCw = createLucideIcon("RotateCw", [
25
- ["path", { d: "M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8", key: "1p45f6" }],
26
- ["path", { d: "M21 3v5h-5", key: "1q7to0" }]
27
- ]);
28
-
29
- function activeElement(doc) {
30
- let activeElement = doc.activeElement;
31
- while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
32
- var _activeElement;
33
- activeElement = activeElement.shadowRoot.activeElement;
34
- }
35
- return activeElement;
36
- }
37
- function contains(parent, child) {
38
- if (!parent || !child) {
39
- return false;
40
- }
41
- const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
42
-
43
- // First, attempt with faster native method
44
- if (parent.contains(child)) {
45
- return true;
46
- }
47
-
48
- // then fallback to custom implementation with Shadow DOM support
49
- if (rootNode && isShadowRoot(rootNode)) {
50
- let next = child;
51
- while (next) {
52
- if (parent === next) {
53
- return true;
54
- }
55
- // @ts-ignore
56
- next = next.parentNode || next.host;
57
- }
58
- }
59
-
60
- // Give up, the result is false
61
- return false;
62
- }
63
- function isSafari() {
64
- // Chrome DevTools does not complain about navigator.vendor
65
- return /apple/i.test(navigator.vendor);
66
- }
67
- function getDocument(node) {
68
- return (node == null ? void 0 : node.ownerDocument) || document;
69
- }
70
-
71
- /*!
72
- * tabbable 6.4.0
73
- * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
74
- */
75
- // NOTE: separate `:not()` selectors has broader browser support than the newer
76
- // `:not([inert], [inert] *)` (Feb 2023)
77
- var candidateSelectors = ['input:not([inert]):not([inert] *)', 'select:not([inert]):not([inert] *)', 'textarea:not([inert]):not([inert] *)', 'a[href]:not([inert]):not([inert] *)', 'button:not([inert]):not([inert] *)', '[tabindex]:not(slot):not([inert]):not([inert] *)', 'audio[controls]:not([inert]):not([inert] *)', 'video[controls]:not([inert]):not([inert] *)', '[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)', 'details>summary:first-of-type:not([inert]):not([inert] *)', 'details:not([inert]):not([inert] *)'];
78
- var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
79
- var NoElement = typeof Element === 'undefined';
80
- var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
81
- var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
82
- var _element$getRootNode;
83
- return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
84
- } : function (element) {
85
- return element === null || element === void 0 ? void 0 : element.ownerDocument;
86
- };
87
-
88
- /**
89
- * Determines if a node is inert or in an inert ancestor.
90
- * @param {Node} [node]
91
- * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
92
- * see if any of them are inert. If false, only `node` itself is considered.
93
- * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
94
- * False if `node` is falsy.
95
- */
96
- var _isInert = function isInert(node, lookUp) {
97
- var _node$getAttribute;
98
- if (lookUp === void 0) {
99
- lookUp = true;
100
- }
101
- // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
102
- // JS API property; we have to check the attribute, which can either be empty or 'true';
103
- // if it's `null` (not specified) or 'false', it's an active element
104
- var inertAtt = node === null || node === void 0 ? void 0 : (_node$getAttribute = node.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node, 'inert');
105
- var inert = inertAtt === '' || inertAtt === 'true';
106
-
107
- // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
108
- // if it weren't for `matches()` not being a function on shadow roots; the following
109
- // code works for any kind of node
110
- var result = inert || lookUp && node && (
111
- // closest does not exist on shadow roots, so we fall back to a manual
112
- // lookup upward, in case it is not defined.
113
- typeof node.closest === 'function' ? node.closest('[inert]') : _isInert(node.parentNode));
114
- return result;
115
- };
116
-
117
- /**
118
- * Determines if a node's content is editable.
119
- * @param {Element} [node]
120
- * @returns True if it's content-editable; false if it's not or `node` is falsy.
121
- */
122
- var isContentEditable = function isContentEditable(node) {
123
- var _node$getAttribute2;
124
- // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
125
- // to use the attribute directly to check for this, which can either be empty or 'true';
126
- // if it's `null` (not specified) or 'false', it's a non-editable element
127
- var attValue = node === null || node === void 0 ? void 0 : (_node$getAttribute2 = node.getAttribute) === null || _node$getAttribute2 === void 0 ? void 0 : _node$getAttribute2.call(node, 'contenteditable');
128
- return attValue === '' || attValue === 'true';
129
- };
130
-
131
- /**
132
- * @param {Element} el container to check in
133
- * @param {boolean} includeContainer add container to check
134
- * @param {(node: Element) => boolean} filter filter candidates
135
- * @returns {Element[]}
136
- */
137
- var getCandidates = function getCandidates(el, includeContainer, filter) {
138
- // even if `includeContainer=false`, we still have to check it for inertness because
139
- // if it's inert (either by itself or via its parent), then all its children are inert
140
- if (_isInert(el)) {
141
- return [];
142
- }
143
- var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
144
- if (includeContainer && matches.call(el, candidateSelector)) {
145
- candidates.unshift(el);
146
- }
147
- candidates = candidates.filter(filter);
148
- return candidates;
149
- };
150
-
151
- /**
152
- * @callback GetShadowRoot
153
- * @param {Element} element to check for shadow root
154
- * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
155
- */
156
-
157
- /**
158
- * @callback ShadowRootFilter
159
- * @param {Element} shadowHostNode the element which contains shadow content
160
- * @returns {boolean} true if a shadow root could potentially contain valid candidates.
161
- */
162
-
163
- /**
164
- * @typedef {Object} CandidateScope
165
- * @property {Element} scopeParent contains inner candidates
166
- * @property {Element[]} candidates list of candidates found in the scope parent
167
- */
168
-
169
- /**
170
- * @typedef {Object} IterativeOptions
171
- * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
172
- * if a function, implies shadow support is enabled and either returns the shadow root of an element
173
- * or a boolean stating if it has an undisclosed shadow root
174
- * @property {(node: Element) => boolean} filter filter candidates
175
- * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
176
- * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
177
- */
178
-
179
- /**
180
- * @param {Element[]} elements list of element containers to match candidates from
181
- * @param {boolean} includeContainer add container list to check
182
- * @param {IterativeOptions} options
183
- * @returns {Array.<Element|CandidateScope>}
184
- */
185
- var _getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
186
- var candidates = [];
187
- var elementsToCheck = Array.from(elements);
188
- while (elementsToCheck.length) {
189
- var element = elementsToCheck.shift();
190
- if (_isInert(element, false)) {
191
- // no need to look up since we're drilling down
192
- // anything inside this container will also be inert
193
- continue;
194
- }
195
- if (element.tagName === 'SLOT') {
196
- // add shadow dom slot scope (slot itself cannot be focusable)
197
- var assigned = element.assignedElements();
198
- var content = assigned.length ? assigned : element.children;
199
- var nestedCandidates = _getCandidatesIteratively(content, true, options);
200
- if (options.flatten) {
201
- candidates.push.apply(candidates, nestedCandidates);
202
- } else {
203
- candidates.push({
204
- scopeParent: element,
205
- candidates: nestedCandidates
206
- });
207
- }
208
- } else {
209
- // check candidate element
210
- var validCandidate = matches.call(element, candidateSelector);
211
- if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
212
- candidates.push(element);
213
- }
214
-
215
- // iterate over shadow content if possible
216
- var shadowRoot = element.shadowRoot ||
217
- // check for an undisclosed shadow
218
- typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
219
-
220
- // no inert look up because we're already drilling down and checking for inertness
221
- // on the way down, so all containers to this root node should have already been
222
- // vetted as non-inert
223
- var validShadowRoot = !_isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
224
- if (shadowRoot && validShadowRoot) {
225
- // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
226
- // shadow exists, so look at light dom children as fallback BUT create a scope for any
227
- // child candidates found because they're likely slotted elements (elements that are
228
- // children of the web component element (which has the shadow), in the light dom, but
229
- // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
230
- // _after_ we return from this recursive call
231
- var _nestedCandidates = _getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
232
- if (options.flatten) {
233
- candidates.push.apply(candidates, _nestedCandidates);
234
- } else {
235
- candidates.push({
236
- scopeParent: element,
237
- candidates: _nestedCandidates
238
- });
239
- }
240
- } else {
241
- // there's not shadow so just dig into the element's (light dom) children
242
- // __without__ giving the element special scope treatment
243
- elementsToCheck.unshift.apply(elementsToCheck, element.children);
244
- }
245
- }
246
- }
247
- return candidates;
248
- };
249
-
250
- /**
251
- * @private
252
- * Determines if the node has an explicitly specified `tabindex` attribute.
253
- * @param {HTMLElement} node
254
- * @returns {boolean} True if so; false if not.
255
- */
256
- var hasTabIndex = function hasTabIndex(node) {
257
- return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
258
- };
259
-
260
- /**
261
- * Determine the tab index of a given node.
262
- * @param {HTMLElement} node
263
- * @returns {number} Tab order (negative, 0, or positive number).
264
- * @throws {Error} If `node` is falsy.
265
- */
266
- var getTabIndex = function getTabIndex(node) {
267
- if (!node) {
268
- throw new Error('No node provided');
269
- }
270
- if (node.tabIndex < 0) {
271
- // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
272
- // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
273
- // yet they are still part of the regular tab order; in FF, they get a default
274
- // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
275
- // order, consider their tab index to be 0.
276
- // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
277
- // so if they don't have a tabindex attribute specifically set, assume it's 0.
278
- if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
279
- return 0;
280
- }
281
- }
282
- return node.tabIndex;
283
- };
284
-
285
- /**
286
- * Determine the tab index of a given node __for sort order purposes__.
287
- * @param {HTMLElement} node
288
- * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
289
- * has tabIndex -1, but needs to be sorted by document order in order for its content to be
290
- * inserted into the correct sort position.
291
- * @returns {number} Tab order (negative, 0, or positive number).
292
- */
293
- var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
294
- var tabIndex = getTabIndex(node);
295
- if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
296
- return 0;
297
- }
298
- return tabIndex;
299
- };
300
- var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
301
- return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
302
- };
303
- var isInput = function isInput(node) {
304
- return node.tagName === 'INPUT';
305
- };
306
- var isHiddenInput = function isHiddenInput(node) {
307
- return isInput(node) && node.type === 'hidden';
308
- };
309
- var isDetailsWithSummary = function isDetailsWithSummary(node) {
310
- var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
311
- return child.tagName === 'SUMMARY';
312
- });
313
- return r;
314
- };
315
- var getCheckedRadio = function getCheckedRadio(nodes, form) {
316
- for (var i = 0; i < nodes.length; i++) {
317
- if (nodes[i].checked && nodes[i].form === form) {
318
- return nodes[i];
319
- }
320
- }
321
- };
322
- var isTabbableRadio = function isTabbableRadio(node) {
323
- if (!node.name) {
324
- return true;
325
- }
326
- var radioScope = node.form || getRootNode(node);
327
- var queryRadios = function queryRadios(name) {
328
- return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
329
- };
330
- var radioSet;
331
- if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
332
- radioSet = queryRadios(window.CSS.escape(node.name));
333
- } else {
334
- try {
335
- radioSet = queryRadios(node.name);
336
- } catch (err) {
337
- // eslint-disable-next-line no-console
338
- console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
339
- return false;
340
- }
341
- }
342
- var checked = getCheckedRadio(radioSet, node.form);
343
- return !checked || checked === node;
344
- };
345
- var isRadio = function isRadio(node) {
346
- return isInput(node) && node.type === 'radio';
347
- };
348
- var isNonTabbableRadio = function isNonTabbableRadio(node) {
349
- return isRadio(node) && !isTabbableRadio(node);
350
- };
351
-
352
- // determines if a node is ultimately attached to the window's document
353
- var isNodeAttached = function isNodeAttached(node) {
354
- var _nodeRoot;
355
- // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
356
- // (but NOT _the_ document; see second 'If' comment below for more).
357
- // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
358
- // is attached, and the one we need to check if it's in the document or not (because the
359
- // shadow, and all nodes it contains, is never considered in the document since shadows
360
- // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
361
- // is hidden, or is not in the document itself but is detached, it will affect the shadow's
362
- // visibility, including all the nodes it contains). The host could be any normal node,
363
- // or a custom element (i.e. web component). Either way, that's the one that is considered
364
- // part of the document, not the shadow root, nor any of its children (i.e. the node being
365
- // tested).
366
- // To further complicate things, we have to look all the way up until we find a shadow HOST
367
- // that is attached (or find none) because the node might be in nested shadows...
368
- // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
369
- // document (per the docs) and while it's a Document-type object, that document does not
370
- // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
371
- // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
372
- // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
373
- // node is actually detached.
374
- // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
375
- // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
376
- // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
377
- // `ownerDocument` will be `null`, hence the optional chaining on it.
378
- var nodeRoot = node && getRootNode(node);
379
- var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
380
-
381
- // in some cases, a detached node will return itself as the root instead of a document or
382
- // shadow root object, in which case, we shouldn't try to look further up the host chain
383
- var attached = false;
384
- if (nodeRoot && nodeRoot !== node) {
385
- var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
386
- attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && (_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null && _nodeRootHost$ownerDo !== void 0 && _nodeRootHost$ownerDo.contains(nodeRootHost) || node !== null && node !== void 0 && (_node$ownerDocument = node.ownerDocument) !== null && _node$ownerDocument !== void 0 && _node$ownerDocument.contains(node));
387
- while (!attached && nodeRootHost) {
388
- var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
389
- // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
390
- // which means we need to get the host's host and check if that parent host is contained
391
- // in (i.e. attached to) the document
392
- nodeRoot = getRootNode(nodeRootHost);
393
- nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
394
- attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
395
- }
396
- }
397
- return attached;
398
- };
399
- var isZeroArea = function isZeroArea(node) {
400
- var _node$getBoundingClie = node.getBoundingClientRect(),
401
- width = _node$getBoundingClie.width,
402
- height = _node$getBoundingClie.height;
403
- return width === 0 && height === 0;
404
- };
405
- var isHidden = function isHidden(node, _ref) {
406
- var displayCheck = _ref.displayCheck,
407
- getShadowRoot = _ref.getShadowRoot;
408
- if (displayCheck === 'full-native') {
409
- if ('checkVisibility' in node) {
410
- // Chrome >= 105, Edge >= 105, Firefox >= 106, Safari >= 17.4
411
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility#browser_compatibility
412
- var visible = node.checkVisibility({
413
- // Checking opacity might be desirable for some use cases, but natively,
414
- // opacity zero elements _are_ focusable and tabbable.
415
- checkOpacity: false,
416
- opacityProperty: false,
417
- contentVisibilityAuto: true,
418
- visibilityProperty: true,
419
- // This is an alias for `visibilityProperty`. Contemporary browsers
420
- // support both. However, this alias has wider browser support (Chrome
421
- // >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
422
- // we include it anyway.
423
- checkVisibilityCSS: true
424
- });
425
- return !visible;
426
- }
427
- // Fall through to manual visibility checks
428
- }
429
-
430
- // NOTE: visibility will be `undefined` if node is detached from the document
431
- // (see notes about this further down), which means we will consider it visible
432
- // (this is legacy behavior from a very long way back)
433
- // NOTE: we check this regardless of `displayCheck="none"` because this is a
434
- // _visibility_ check, not a _display_ check
435
- if (getComputedStyle(node).visibility === 'hidden') {
436
- return true;
437
- }
438
- var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
439
- var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
440
- if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
441
- return true;
442
- }
443
- if (!displayCheck || displayCheck === 'full' ||
444
- // full-native can run this branch when it falls through in case
445
- // Element#checkVisibility is unsupported
446
- displayCheck === 'full-native' || displayCheck === 'legacy-full') {
447
- if (typeof getShadowRoot === 'function') {
448
- // figure out if we should consider the node to be in an undisclosed shadow and use the
449
- // 'non-zero-area' fallback
450
- var originalNode = node;
451
- while (node) {
452
- var parentElement = node.parentElement;
453
- var rootNode = getRootNode(node);
454
- if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
455
- ) {
456
- // node has an undisclosed shadow which means we can only treat it as a black box, so we
457
- // fall back to a non-zero-area test
458
- return isZeroArea(node);
459
- } else if (node.assignedSlot) {
460
- // iterate up slot
461
- node = node.assignedSlot;
462
- } else if (!parentElement && rootNode !== node.ownerDocument) {
463
- // cross shadow boundary
464
- node = rootNode.host;
465
- } else {
466
- // iterate up normal dom
467
- node = parentElement;
468
- }
469
- }
470
- node = originalNode;
471
- }
472
- // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
473
- // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
474
- // it might be a falsy value, which means shadow DOM support is disabled
475
-
476
- // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
477
- // now we can just test to see if it would normally be visible or not, provided it's
478
- // attached to the main document.
479
- // NOTE: We must consider case where node is inside a shadow DOM and given directly to
480
- // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
481
-
482
- if (isNodeAttached(node)) {
483
- // this works wherever the node is: if there's at least one client rect, it's
484
- // somehow displayed; it also covers the CSS 'display: contents' case where the
485
- // node itself is hidden in place of its contents; and there's no need to search
486
- // up the hierarchy either
487
- return !node.getClientRects().length;
488
- }
489
-
490
- // Else, the node isn't attached to the document, which means the `getClientRects()`
491
- // API will __always__ return zero rects (this can happen, for example, if React
492
- // is used to render nodes onto a detached tree, as confirmed in this thread:
493
- // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
494
- //
495
- // It also means that even window.getComputedStyle(node).display will return `undefined`
496
- // because styles are only computed for nodes that are in the document.
497
- //
498
- // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
499
- // somehow. Though it was never stated officially, anyone who has ever used tabbable
500
- // APIs on nodes in detached containers has actually implicitly used tabbable in what
501
- // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
502
- // considering __everything__ to be visible because of the innability to determine styles.
503
- //
504
- // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
505
- // nodes as visible with the 'none' fallback.__
506
- if (displayCheck !== 'legacy-full') {
507
- return true; // hidden
508
- }
509
- // else, fallback to 'none' mode and consider the node visible
510
- } else if (displayCheck === 'non-zero-area') {
511
- // NOTE: Even though this tests that the node's client rect is non-zero to determine
512
- // whether it's displayed, and that a detached node will __always__ have a zero-area
513
- // client rect, we don't special-case for whether the node is attached or not. In
514
- // this mode, we do want to consider nodes that have a zero area to be hidden at all
515
- // times, and that includes attached or not.
516
- return isZeroArea(node);
517
- }
518
-
519
- // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
520
- // it's visible
521
- return false;
522
- };
523
-
524
- // form fields (nested) inside a disabled fieldset are not focusable/tabbable
525
- // unless they are in the _first_ <legend> element of the top-most disabled
526
- // fieldset
527
- var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
528
- if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
529
- var parentNode = node.parentElement;
530
- // check if `node` is contained in a disabled <fieldset>
531
- while (parentNode) {
532
- if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
533
- // look for the first <legend> among the children of the disabled <fieldset>
534
- for (var i = 0; i < parentNode.children.length; i++) {
535
- var child = parentNode.children.item(i);
536
- // when the first <legend> (in document order) is found
537
- if (child.tagName === 'LEGEND') {
538
- // if its parent <fieldset> is not nested in another disabled <fieldset>,
539
- // return whether `node` is a descendant of its first <legend>
540
- return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
541
- }
542
- }
543
- // the disabled <fieldset> containing `node` has no <legend>
544
- return true;
545
- }
546
- parentNode = parentNode.parentElement;
547
- }
548
- }
549
-
550
- // else, node's tabbable/focusable state should not be affected by a fieldset's
551
- // enabled/disabled state
552
- return false;
553
- };
554
- var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
555
- if (node.disabled || isHiddenInput(node) || isHidden(node, options) ||
556
- // For a details element with a summary, the summary element gets the focus
557
- isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
558
- return false;
559
- }
560
- return true;
561
- };
562
- var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
563
- if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
564
- return false;
565
- }
566
- return true;
567
- };
568
- var isShadowRootTabbable = function isShadowRootTabbable(shadowHostNode) {
569
- var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
570
- if (isNaN(tabIndex) || tabIndex >= 0) {
571
- return true;
572
- }
573
- // If a custom element has an explicit negative tabindex,
574
- // browsers will not allow tab targeting said element's children.
575
- return false;
576
- };
577
-
578
- /**
579
- * @param {Array.<Element|CandidateScope>} candidates
580
- * @returns Element[]
581
- */
582
- var _sortByOrder = function sortByOrder(candidates) {
583
- var regularTabbables = [];
584
- var orderedTabbables = [];
585
- candidates.forEach(function (item, i) {
586
- var isScope = !!item.scopeParent;
587
- var element = isScope ? item.scopeParent : item;
588
- var candidateTabindex = getSortOrderTabIndex(element, isScope);
589
- var elements = isScope ? _sortByOrder(item.candidates) : element;
590
- if (candidateTabindex === 0) {
591
- isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
592
- } else {
593
- orderedTabbables.push({
594
- documentOrder: i,
595
- tabIndex: candidateTabindex,
596
- item: item,
597
- isScope: isScope,
598
- content: elements
599
- });
600
- }
601
- });
602
- return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
603
- sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
604
- return acc;
605
- }, []).concat(regularTabbables);
606
- };
607
- var tabbable = function tabbable(container, options) {
608
- options = options || {};
609
- var candidates;
610
- if (options.getShadowRoot) {
611
- candidates = _getCandidatesIteratively([container], options.includeContainer, {
612
- filter: isNodeMatchingSelectorTabbable.bind(null, options),
613
- flatten: false,
614
- getShadowRoot: options.getShadowRoot,
615
- shadowRootFilter: isShadowRootTabbable
616
- });
617
- } else {
618
- candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
619
- }
620
- return _sortByOrder(candidates);
621
- };
622
-
623
- // https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
624
- const SafeReact = {
625
- ...React
626
- };
627
-
628
- const useInsertionEffect = SafeReact.useInsertionEffect;
629
- const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
630
- function useEffectEvent(callback) {
631
- const ref = React.useRef(() => {
632
- {
633
- throw new Error('Cannot call an event handler while rendering.');
634
- }
635
- });
636
- useSafeInsertionEffect(() => {
637
- ref.current = callback;
638
- });
639
- return React.useCallback(function () {
640
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
641
- args[_key] = arguments[_key];
642
- }
643
- return ref.current == null ? void 0 : ref.current(...args);
644
- }, []);
645
- }
646
-
647
- var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
648
-
649
- function _extends() {
650
- _extends = Object.assign ? Object.assign.bind() : function (target) {
651
- for (var i = 1; i < arguments.length; i++) {
652
- var source = arguments[i];
653
- for (var key in source) {
654
- if (Object.prototype.hasOwnProperty.call(source, key)) {
655
- target[key] = source[key];
656
- }
657
- }
658
- }
659
- return target;
660
- };
661
- return _extends.apply(this, arguments);
662
- }
663
-
664
- let serverHandoffComplete = false;
665
- let count = 0;
666
- const genId = () => // Ensure the id is unique with multiple independent versions of Floating UI
667
- // on <React 18
668
- "floating-ui-" + Math.random().toString(36).slice(2, 6) + count++;
669
- function useFloatingId() {
670
- const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : undefined);
671
- index(() => {
672
- if (id == null) {
673
- setId(genId());
674
- }
675
- // eslint-disable-next-line react-hooks/exhaustive-deps
676
- }, []);
677
- React.useEffect(() => {
678
- serverHandoffComplete = true;
679
- }, []);
680
- return id;
681
- }
682
- const useReactId = SafeReact.useId;
683
-
684
- /**
685
- * Uses React 18's built-in `useId()` when available, or falls back to a
686
- * slightly less performant (requiring a double render) implementation for
687
- * earlier React versions.
688
- * @see https://floating-ui.com/docs/react-utils#useid
689
- */
690
- const useId = useReactId || useFloatingId;
691
-
692
- let devMessageSet;
693
- {
694
- devMessageSet = /*#__PURE__*/new Set();
695
- }
696
- function error() {
697
- var _devMessageSet3;
698
- for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
699
- messages[_key2] = arguments[_key2];
700
- }
701
- const message = "Floating UI: " + messages.join(' ');
702
- if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
703
- var _devMessageSet4;
704
- (_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
705
- console.error(message);
706
- }
707
- }
708
-
709
- function createPubSub() {
710
- const map = new Map();
711
- return {
712
- emit(event, data) {
713
- var _map$get;
714
- (_map$get = map.get(event)) == null || _map$get.forEach(handler => handler(data));
715
- },
716
- on(event, listener) {
717
- map.set(event, [...(map.get(event) || []), listener]);
718
- },
719
- off(event, listener) {
720
- var _map$get2;
721
- map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter(l => l !== listener)) || []);
722
- }
723
- };
724
- }
725
-
726
- const FloatingNodeContext = /*#__PURE__*/React.createContext(null);
727
- const FloatingTreeContext = /*#__PURE__*/React.createContext(null);
728
-
729
- /**
730
- * Returns the parent node id for nested floating elements, if available.
731
- * Returns `null` for top-level floating elements.
732
- */
733
- const useFloatingParentNodeId = () => {
734
- var _React$useContext;
735
- return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
736
- };
737
-
738
- /**
739
- * Returns the nearest floating tree context, if available.
740
- */
741
- const useFloatingTree = () => React.useContext(FloatingTreeContext);
742
-
743
- function createAttribute(name) {
744
- return "data-floating-ui-" + name;
745
- }
746
-
747
- const getTabbableOptions = () => ({
748
- getShadowRoot: true,
749
- displayCheck:
750
- // JSDOM does not support the `tabbable` library. To solve this we can
751
- // check if `ResizeObserver` is a real function (not polyfilled), which
752
- // determines if the current environment is JSDOM-like.
753
- typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
754
- });
755
- function getTabbableIn(container, direction) {
756
- const allTabbable = tabbable(container, getTabbableOptions());
757
- if (direction === 'prev') {
758
- allTabbable.reverse();
759
- }
760
- const activeIndex = allTabbable.indexOf(activeElement(getDocument(container)));
761
- const nextTabbableElements = allTabbable.slice(activeIndex + 1);
762
- return nextTabbableElements[0];
763
- }
764
- function getNextTabbable() {
765
- return getTabbableIn(document.body, 'next');
766
- }
767
- function getPreviousTabbable() {
768
- return getTabbableIn(document.body, 'prev');
769
- }
770
- function isOutsideEvent(event, container) {
771
- const containerElement = container || event.currentTarget;
772
- const relatedTarget = event.relatedTarget;
773
- return !relatedTarget || !contains(containerElement, relatedTarget);
774
- }
775
- function disableFocusInside(container) {
776
- const tabbableElements = tabbable(container, getTabbableOptions());
777
- tabbableElements.forEach(element => {
778
- element.dataset.tabindex = element.getAttribute('tabindex') || '';
779
- element.setAttribute('tabindex', '-1');
780
- });
781
- }
782
- function enableFocusInside(container) {
783
- const elements = container.querySelectorAll('[data-tabindex]');
784
- elements.forEach(element => {
785
- const tabindex = element.dataset.tabindex;
786
- delete element.dataset.tabindex;
787
- if (tabindex) {
788
- element.setAttribute('tabindex', tabindex);
789
- } else {
790
- element.removeAttribute('tabindex');
791
- }
792
- });
793
- }
794
-
795
- // See Diego Haz's Sandbox for making this logic work well on Safari/iOS:
796
- // https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/FocusTrap.tsx
797
-
798
- const HIDDEN_STYLES = {
799
- border: 0,
800
- clip: 'rect(0 0 0 0)',
801
- height: '1px',
802
- margin: '-1px',
803
- overflow: 'hidden',
804
- padding: 0,
805
- position: 'fixed',
806
- whiteSpace: 'nowrap',
807
- width: '1px',
808
- top: 0,
809
- left: 0
810
- };
811
- let timeoutId;
812
- function setActiveElementOnTab(event) {
813
- if (event.key === 'Tab') {
814
- event.target;
815
- clearTimeout(timeoutId);
816
- }
817
- }
818
- const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref) {
819
- const [role, setRole] = React.useState();
820
- index(() => {
821
- if (isSafari()) {
822
- // Unlike other screen readers such as NVDA and JAWS, the virtual cursor
823
- // on VoiceOver does trigger the onFocus event, so we can use the focus
824
- // trap element. On Safari, only buttons trigger the onFocus event.
825
- // NB: "group" role in the Sandbox no longer appears to work, must be a
826
- // button role.
827
- setRole('button');
828
- }
829
- document.addEventListener('keydown', setActiveElementOnTab);
830
- return () => {
831
- document.removeEventListener('keydown', setActiveElementOnTab);
832
- };
833
- }, []);
834
- const restProps = {
835
- ref,
836
- tabIndex: 0,
837
- // Role is only for VoiceOver
838
- role,
839
- 'aria-hidden': role ? undefined : true,
840
- [createAttribute('focus-guard')]: '',
841
- style: HIDDEN_STYLES
842
- };
843
- return /*#__PURE__*/React.createElement("span", _extends({}, props, restProps));
844
- });
845
-
846
- const PortalContext = /*#__PURE__*/React.createContext(null);
847
- const attr = /*#__PURE__*/createAttribute('portal');
848
- /**
849
- * @see https://floating-ui.com/docs/FloatingPortal#usefloatingportalnode
850
- */
851
- function useFloatingPortalNode(props) {
852
- if (props === void 0) {
853
- props = {};
854
- }
855
- const {
856
- id,
857
- root
858
- } = props;
859
- const uniqueId = useId();
860
- const portalContext = usePortalContext$1();
861
- const [portalNode, setPortalNode] = React.useState(null);
862
- const portalNodeRef = React.useRef(null);
863
- index(() => {
864
- return () => {
865
- portalNode == null || portalNode.remove();
866
- // Allow the subsequent layout effects to create a new node on updates.
867
- // The portal node will still be cleaned up on unmount.
868
- // https://github.com/floating-ui/floating-ui/issues/2454
869
- queueMicrotask(() => {
870
- portalNodeRef.current = null;
871
- });
872
- };
873
- }, [portalNode]);
874
- index(() => {
875
- // Wait for the uniqueId to be generated before creating the portal node in
876
- // React <18 (using `useFloatingId` instead of the native `useId`).
877
- // https://github.com/floating-ui/floating-ui/issues/2778
878
- if (!uniqueId) return;
879
- if (portalNodeRef.current) return;
880
- const existingIdRoot = id ? document.getElementById(id) : null;
881
- if (!existingIdRoot) return;
882
- const subRoot = document.createElement('div');
883
- subRoot.id = uniqueId;
884
- subRoot.setAttribute(attr, '');
885
- existingIdRoot.appendChild(subRoot);
886
- portalNodeRef.current = subRoot;
887
- setPortalNode(subRoot);
888
- }, [id, uniqueId]);
889
- index(() => {
890
- // Wait for the root to exist before creating the portal node. The root must
891
- // be stored in state, not a ref, for this to work reactively.
892
- if (root === null) return;
893
- if (!uniqueId) return;
894
- if (portalNodeRef.current) return;
895
- let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
896
- if (container && !isElement(container)) container = container.current;
897
- container = container || document.body;
898
- let idWrapper = null;
899
- if (id) {
900
- idWrapper = document.createElement('div');
901
- idWrapper.id = id;
902
- container.appendChild(idWrapper);
903
- }
904
- const subRoot = document.createElement('div');
905
- subRoot.id = uniqueId;
906
- subRoot.setAttribute(attr, '');
907
- container = idWrapper || container;
908
- container.appendChild(subRoot);
909
- portalNodeRef.current = subRoot;
910
- setPortalNode(subRoot);
911
- }, [id, root, uniqueId, portalContext]);
912
- return portalNode;
913
- }
914
- /**
915
- * Portals the floating element into a given container element — by default,
916
- * outside of the app root and into the body.
917
- * This is necessary to ensure the floating element can appear outside any
918
- * potential parent containers that cause clipping (such as `overflow: hidden`),
919
- * while retaining its location in the React tree.
920
- * @see https://floating-ui.com/docs/FloatingPortal
921
- */
922
- function FloatingPortal(props) {
923
- const {
924
- children,
925
- id,
926
- root,
927
- preserveTabOrder = true
928
- } = props;
929
- const portalNode = useFloatingPortalNode({
930
- id,
931
- root
932
- });
933
- const [focusManagerState, setFocusManagerState] = React.useState(null);
934
- const beforeOutsideRef = React.useRef(null);
935
- const afterOutsideRef = React.useRef(null);
936
- const beforeInsideRef = React.useRef(null);
937
- const afterInsideRef = React.useRef(null);
938
- const modal = focusManagerState == null ? void 0 : focusManagerState.modal;
939
- const open = focusManagerState == null ? void 0 : focusManagerState.open;
940
- const shouldRenderGuards =
941
- // The FocusManager and therefore floating element are currently open/
942
- // rendered.
943
- !!focusManagerState &&
944
- // Guards are only for non-modal focus management.
945
- !focusManagerState.modal &&
946
- // Don't render if unmount is transitioning.
947
- focusManagerState.open && preserveTabOrder && !!(root || portalNode);
948
-
949
- // https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/TabbablePortal.tsx
950
- React.useEffect(() => {
951
- if (!portalNode || !preserveTabOrder || modal) {
952
- return;
953
- }
954
-
955
- // Make sure elements inside the portal element are tabbable only when the
956
- // portal has already been focused, either by tabbing into a focus trap
957
- // element outside or using the mouse.
958
- function onFocus(event) {
959
- if (portalNode && isOutsideEvent(event)) {
960
- const focusing = event.type === 'focusin';
961
- const manageFocus = focusing ? enableFocusInside : disableFocusInside;
962
- manageFocus(portalNode);
963
- }
964
- }
965
- // Listen to the event on the capture phase so they run before the focus
966
- // trap elements onFocus prop is called.
967
- portalNode.addEventListener('focusin', onFocus, true);
968
- portalNode.addEventListener('focusout', onFocus, true);
969
- return () => {
970
- portalNode.removeEventListener('focusin', onFocus, true);
971
- portalNode.removeEventListener('focusout', onFocus, true);
972
- };
973
- }, [portalNode, preserveTabOrder, modal]);
974
- React.useEffect(() => {
975
- if (!portalNode) return;
976
- if (open) return;
977
- enableFocusInside(portalNode);
978
- }, [open, portalNode]);
979
- return /*#__PURE__*/React.createElement(PortalContext.Provider, {
980
- value: React.useMemo(() => ({
981
- preserveTabOrder,
982
- beforeOutsideRef,
983
- afterOutsideRef,
984
- beforeInsideRef,
985
- afterInsideRef,
986
- portalNode,
987
- setFocusManagerState
988
- }), [preserveTabOrder, portalNode])
989
- }, shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
990
- "data-type": "outside",
991
- ref: beforeOutsideRef,
992
- onFocus: event => {
993
- if (isOutsideEvent(event, portalNode)) {
994
- var _beforeInsideRef$curr;
995
- (_beforeInsideRef$curr = beforeInsideRef.current) == null || _beforeInsideRef$curr.focus();
996
- } else {
997
- const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
998
- prevTabbable == null || prevTabbable.focus();
999
- }
1000
- }
1001
- }), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement("span", {
1002
- "aria-owns": portalNode.id,
1003
- style: HIDDEN_STYLES
1004
- }), portalNode && /*#__PURE__*/ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
1005
- "data-type": "outside",
1006
- ref: afterOutsideRef,
1007
- onFocus: event => {
1008
- if (isOutsideEvent(event, portalNode)) {
1009
- var _afterInsideRef$curre;
1010
- (_afterInsideRef$curre = afterInsideRef.current) == null || _afterInsideRef$curre.focus();
1011
- } else {
1012
- const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
1013
- nextTabbable == null || nextTabbable.focus();
1014
- (focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent, 'focus-out'));
1015
- }
1016
- }
1017
- }));
1018
- }
1019
- const usePortalContext$1 = () => React.useContext(PortalContext);
1020
-
1021
- function useFloatingRootContext(options) {
1022
- const {
1023
- open = false,
1024
- onOpenChange: onOpenChangeProp,
1025
- elements: elementsProp
1026
- } = options;
1027
- const floatingId = useId();
1028
- const dataRef = React.useRef({});
1029
- const [events] = React.useState(() => createPubSub());
1030
- const nested = useFloatingParentNodeId() != null;
1031
- {
1032
- const optionDomReference = elementsProp.reference;
1033
- if (optionDomReference && !isElement(optionDomReference)) {
1034
- error('Cannot pass a virtual element to the `elements.reference` option,', 'as it must be a real DOM element. Use `refs.setPositionReference()`', 'instead.');
1035
- }
1036
- }
1037
- const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
1038
- const onOpenChange = useEffectEvent((open, event, reason) => {
1039
- dataRef.current.openEvent = open ? event : undefined;
1040
- events.emit('openchange', {
1041
- open,
1042
- event,
1043
- reason,
1044
- nested
1045
- });
1046
- onOpenChangeProp == null || onOpenChangeProp(open, event, reason);
1047
- });
1048
- const refs = React.useMemo(() => ({
1049
- setPositionReference
1050
- }), []);
1051
- const elements = React.useMemo(() => ({
1052
- reference: positionReference || elementsProp.reference || null,
1053
- floating: elementsProp.floating || null,
1054
- domReference: elementsProp.reference
1055
- }), [positionReference, elementsProp.reference, elementsProp.floating]);
1056
- return React.useMemo(() => ({
1057
- dataRef,
1058
- open,
1059
- onOpenChange,
1060
- elements,
1061
- events,
1062
- floatingId,
1063
- refs
1064
- }), [open, onOpenChange, elements, events, floatingId, refs]);
1065
- }
1066
-
1067
- /**
1068
- * Provides data to position a floating element and context to add interactions.
1069
- * @see https://floating-ui.com/docs/useFloating
1070
- */
1071
- function useFloating(options) {
1072
- if (options === void 0) {
1073
- options = {};
1074
- }
1075
- const {
1076
- nodeId
1077
- } = options;
1078
- const internalRootContext = useFloatingRootContext({
1079
- ...options,
1080
- elements: {
1081
- reference: null,
1082
- floating: null,
1083
- ...options.elements
1084
- }
1085
- });
1086
- const rootContext = options.rootContext || internalRootContext;
1087
- const computedElements = rootContext.elements;
1088
- const [_domReference, setDomReference] = React.useState(null);
1089
- const [positionReference, _setPositionReference] = React.useState(null);
1090
- const optionDomReference = computedElements == null ? void 0 : computedElements.domReference;
1091
- const domReference = optionDomReference || _domReference;
1092
- const domReferenceRef = React.useRef(null);
1093
- const tree = useFloatingTree();
1094
- index(() => {
1095
- if (domReference) {
1096
- domReferenceRef.current = domReference;
1097
- }
1098
- }, [domReference]);
1099
- const position = useFloating$1({
1100
- ...options,
1101
- elements: {
1102
- ...computedElements,
1103
- ...(positionReference && {
1104
- reference: positionReference
1105
- })
1106
- }
1107
- });
1108
- const setPositionReference = React.useCallback(node => {
1109
- const computedPositionReference = isElement(node) ? {
1110
- getBoundingClientRect: () => node.getBoundingClientRect(),
1111
- contextElement: node
1112
- } : node;
1113
- // Store the positionReference in state if the DOM reference is specified externally via the
1114
- // `elements.reference` option. This ensures that it won't be overridden on future renders.
1115
- _setPositionReference(computedPositionReference);
1116
- position.refs.setReference(computedPositionReference);
1117
- }, [position.refs]);
1118
- const setReference = React.useCallback(node => {
1119
- if (isElement(node) || node === null) {
1120
- domReferenceRef.current = node;
1121
- setDomReference(node);
1122
- }
1123
-
1124
- // Backwards-compatibility for passing a virtual element to `reference`
1125
- // after it has set the DOM reference.
1126
- if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
1127
- // Don't allow setting virtual elements using the old technique back to
1128
- // `null` to support `positionReference` + an unstable `reference`
1129
- // callback ref.
1130
- node !== null && !isElement(node)) {
1131
- position.refs.setReference(node);
1132
- }
1133
- }, [position.refs]);
1134
- const refs = React.useMemo(() => ({
1135
- ...position.refs,
1136
- setReference,
1137
- setPositionReference,
1138
- domReference: domReferenceRef
1139
- }), [position.refs, setReference, setPositionReference]);
1140
- const elements = React.useMemo(() => ({
1141
- ...position.elements,
1142
- domReference: domReference
1143
- }), [position.elements, domReference]);
1144
- const context = React.useMemo(() => ({
1145
- ...position,
1146
- ...rootContext,
1147
- refs,
1148
- elements,
1149
- nodeId
1150
- }), [position, refs, elements, nodeId, rootContext]);
1151
- index(() => {
1152
- rootContext.dataRef.current.floatingContext = context;
1153
- const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
1154
- if (node) {
1155
- node.context = context;
1156
- }
1157
- });
1158
- return React.useMemo(() => ({
1159
- ...position,
1160
- context,
1161
- refs,
1162
- elements
1163
- }), [position, refs, elements, context]);
1164
- }
1165
-
1166
- // src/slot.tsx
1167
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
1168
- // @__NO_SIDE_EFFECTS__
1169
- function createSlottable(ownerName) {
1170
- const Slottable2 = ({ children }) => {
1171
- return /* @__PURE__ */ jsx(Fragment, { children });
1172
- };
1173
- Slottable2.displayName = `${ownerName}.Slottable`;
1174
- Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
1175
- return Slottable2;
1176
- }
1177
-
1178
- var [createTooltipContext, createTooltipScope] = createContextScope("Tooltip", [
1179
- createPopperScope
1180
- ]);
1181
- var usePopperScope = createPopperScope();
1182
- var PROVIDER_NAME = "TooltipProvider";
1183
- var DEFAULT_DELAY_DURATION = 700;
1184
- var TOOLTIP_OPEN = "tooltip.open";
1185
- var [TooltipProviderContextProvider, useTooltipProviderContext] = createTooltipContext(PROVIDER_NAME);
1186
- var TooltipProvider$1 = (props) => {
1187
- const {
1188
- __scopeTooltip,
1189
- delayDuration = DEFAULT_DELAY_DURATION,
1190
- skipDelayDuration = 300,
1191
- disableHoverableContent = false,
1192
- children
1193
- } = props;
1194
- const isOpenDelayedRef = React.useRef(true);
1195
- const isPointerInTransitRef = React.useRef(false);
1196
- const skipDelayTimerRef = React.useRef(0);
1197
- React.useEffect(() => {
1198
- const skipDelayTimer = skipDelayTimerRef.current;
1199
- return () => window.clearTimeout(skipDelayTimer);
1200
- }, []);
1201
- return /* @__PURE__ */ jsx(
1202
- TooltipProviderContextProvider,
1203
- {
1204
- scope: __scopeTooltip,
1205
- isOpenDelayedRef,
1206
- delayDuration,
1207
- onOpen: React.useCallback(() => {
1208
- window.clearTimeout(skipDelayTimerRef.current);
1209
- isOpenDelayedRef.current = false;
1210
- }, []),
1211
- onClose: React.useCallback(() => {
1212
- window.clearTimeout(skipDelayTimerRef.current);
1213
- skipDelayTimerRef.current = window.setTimeout(
1214
- () => isOpenDelayedRef.current = true,
1215
- skipDelayDuration
1216
- );
1217
- }, [skipDelayDuration]),
1218
- isPointerInTransitRef,
1219
- onPointerInTransitChange: React.useCallback((inTransit) => {
1220
- isPointerInTransitRef.current = inTransit;
1221
- }, []),
1222
- disableHoverableContent,
1223
- children
1224
- }
1225
- );
1226
- };
1227
- TooltipProvider$1.displayName = PROVIDER_NAME;
1228
- var TOOLTIP_NAME = "Tooltip";
1229
- var [TooltipContextProvider, useTooltipContext] = createTooltipContext(TOOLTIP_NAME);
1230
- var Tooltip$1 = (props) => {
1231
- const {
1232
- __scopeTooltip,
1233
- children,
1234
- open: openProp,
1235
- defaultOpen,
1236
- onOpenChange,
1237
- disableHoverableContent: disableHoverableContentProp,
1238
- delayDuration: delayDurationProp
1239
- } = props;
1240
- const providerContext = useTooltipProviderContext(TOOLTIP_NAME, props.__scopeTooltip);
1241
- const popperScope = usePopperScope(__scopeTooltip);
1242
- const [trigger, setTrigger] = React.useState(null);
1243
- const contentId = useId$1();
1244
- const openTimerRef = React.useRef(0);
1245
- const disableHoverableContent = disableHoverableContentProp ?? providerContext.disableHoverableContent;
1246
- const delayDuration = delayDurationProp ?? providerContext.delayDuration;
1247
- const wasOpenDelayedRef = React.useRef(false);
1248
- const [open, setOpen] = useControllableState({
1249
- prop: openProp,
1250
- defaultProp: defaultOpen ?? false,
1251
- onChange: (open2) => {
1252
- if (open2) {
1253
- providerContext.onOpen();
1254
- document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN));
1255
- } else {
1256
- providerContext.onClose();
1257
- }
1258
- onOpenChange?.(open2);
1259
- },
1260
- caller: TOOLTIP_NAME
1261
- });
1262
- const stateAttribute = React.useMemo(() => {
1263
- return open ? wasOpenDelayedRef.current ? "delayed-open" : "instant-open" : "closed";
1264
- }, [open]);
1265
- const handleOpen = React.useCallback(() => {
1266
- window.clearTimeout(openTimerRef.current);
1267
- openTimerRef.current = 0;
1268
- wasOpenDelayedRef.current = false;
1269
- setOpen(true);
1270
- }, [setOpen]);
1271
- const handleClose = React.useCallback(() => {
1272
- window.clearTimeout(openTimerRef.current);
1273
- openTimerRef.current = 0;
1274
- setOpen(false);
1275
- }, [setOpen]);
1276
- const handleDelayedOpen = React.useCallback(() => {
1277
- window.clearTimeout(openTimerRef.current);
1278
- openTimerRef.current = window.setTimeout(() => {
1279
- wasOpenDelayedRef.current = true;
1280
- setOpen(true);
1281
- openTimerRef.current = 0;
1282
- }, delayDuration);
1283
- }, [delayDuration, setOpen]);
1284
- React.useEffect(() => {
1285
- return () => {
1286
- if (openTimerRef.current) {
1287
- window.clearTimeout(openTimerRef.current);
1288
- openTimerRef.current = 0;
1289
- }
1290
- };
1291
- }, []);
1292
- return /* @__PURE__ */ jsx(Root2, { ...popperScope, children: /* @__PURE__ */ jsx(
1293
- TooltipContextProvider,
1294
- {
1295
- scope: __scopeTooltip,
1296
- contentId,
1297
- open,
1298
- stateAttribute,
1299
- trigger,
1300
- onTriggerChange: setTrigger,
1301
- onTriggerEnter: React.useCallback(() => {
1302
- if (providerContext.isOpenDelayedRef.current) handleDelayedOpen();
1303
- else handleOpen();
1304
- }, [providerContext.isOpenDelayedRef, handleDelayedOpen, handleOpen]),
1305
- onTriggerLeave: React.useCallback(() => {
1306
- if (disableHoverableContent) {
1307
- handleClose();
1308
- } else {
1309
- window.clearTimeout(openTimerRef.current);
1310
- openTimerRef.current = 0;
1311
- }
1312
- }, [handleClose, disableHoverableContent]),
1313
- onOpen: handleOpen,
1314
- onClose: handleClose,
1315
- disableHoverableContent,
1316
- children
1317
- }
1318
- ) });
1319
- };
1320
- Tooltip$1.displayName = TOOLTIP_NAME;
1321
- var TRIGGER_NAME = "TooltipTrigger";
1322
- var TooltipTrigger$1 = React.forwardRef(
1323
- (props, forwardedRef) => {
1324
- const { __scopeTooltip, ...triggerProps } = props;
1325
- const context = useTooltipContext(TRIGGER_NAME, __scopeTooltip);
1326
- const providerContext = useTooltipProviderContext(TRIGGER_NAME, __scopeTooltip);
1327
- const popperScope = usePopperScope(__scopeTooltip);
1328
- const ref = React.useRef(null);
1329
- const composedRefs = useComposedRefs(forwardedRef, ref, context.onTriggerChange);
1330
- const isPointerDownRef = React.useRef(false);
1331
- const hasPointerMoveOpenedRef = React.useRef(false);
1332
- const handlePointerUp = React.useCallback(() => isPointerDownRef.current = false, []);
1333
- React.useEffect(() => {
1334
- return () => document.removeEventListener("pointerup", handlePointerUp);
1335
- }, [handlePointerUp]);
1336
- return /* @__PURE__ */ jsx(Anchor, { asChild: true, ...popperScope, children: /* @__PURE__ */ jsx(
1337
- Primitive.button,
1338
- {
1339
- "aria-describedby": context.open ? context.contentId : void 0,
1340
- "data-state": context.stateAttribute,
1341
- ...triggerProps,
1342
- ref: composedRefs,
1343
- onPointerMove: composeEventHandlers(props.onPointerMove, (event) => {
1344
- if (event.pointerType === "touch") return;
1345
- if (!hasPointerMoveOpenedRef.current && !providerContext.isPointerInTransitRef.current) {
1346
- context.onTriggerEnter();
1347
- hasPointerMoveOpenedRef.current = true;
1348
- }
1349
- }),
1350
- onPointerLeave: composeEventHandlers(props.onPointerLeave, () => {
1351
- context.onTriggerLeave();
1352
- hasPointerMoveOpenedRef.current = false;
1353
- }),
1354
- onPointerDown: composeEventHandlers(props.onPointerDown, () => {
1355
- if (context.open) {
1356
- context.onClose();
1357
- }
1358
- isPointerDownRef.current = true;
1359
- document.addEventListener("pointerup", handlePointerUp, { once: true });
1360
- }),
1361
- onFocus: composeEventHandlers(props.onFocus, () => {
1362
- if (!isPointerDownRef.current) context.onOpen();
1363
- }),
1364
- onBlur: composeEventHandlers(props.onBlur, context.onClose),
1365
- onClick: composeEventHandlers(props.onClick, context.onClose)
1366
- }
1367
- ) });
1368
- }
1369
- );
1370
- TooltipTrigger$1.displayName = TRIGGER_NAME;
1371
- var PORTAL_NAME = "TooltipPortal";
1372
- var [PortalProvider, usePortalContext] = createTooltipContext(PORTAL_NAME, {
1373
- forceMount: void 0
1374
- });
1375
- var TooltipPortal = (props) => {
1376
- const { __scopeTooltip, forceMount, children, container } = props;
1377
- const context = useTooltipContext(PORTAL_NAME, __scopeTooltip);
1378
- return /* @__PURE__ */ jsx(PortalProvider, { scope: __scopeTooltip, forceMount, children: /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(Portal$1, { asChild: true, container, children }) }) });
1379
- };
1380
- TooltipPortal.displayName = PORTAL_NAME;
1381
- var CONTENT_NAME = "TooltipContent";
1382
- var TooltipContent$1 = React.forwardRef(
1383
- (props, forwardedRef) => {
1384
- const portalContext = usePortalContext(CONTENT_NAME, props.__scopeTooltip);
1385
- const { forceMount = portalContext.forceMount, side = "top", ...contentProps } = props;
1386
- const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);
1387
- return /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: context.disableHoverableContent ? /* @__PURE__ */ jsx(TooltipContentImpl, { side, ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx(TooltipContentHoverable, { side, ...contentProps, ref: forwardedRef }) });
1388
- }
1389
- );
1390
- var TooltipContentHoverable = React.forwardRef((props, forwardedRef) => {
1391
- const context = useTooltipContext(CONTENT_NAME, props.__scopeTooltip);
1392
- const providerContext = useTooltipProviderContext(CONTENT_NAME, props.__scopeTooltip);
1393
- const ref = React.useRef(null);
1394
- const composedRefs = useComposedRefs(forwardedRef, ref);
1395
- const [pointerGraceArea, setPointerGraceArea] = React.useState(null);
1396
- const { trigger, onClose } = context;
1397
- const content = ref.current;
1398
- const { onPointerInTransitChange } = providerContext;
1399
- const handleRemoveGraceArea = React.useCallback(() => {
1400
- setPointerGraceArea(null);
1401
- onPointerInTransitChange(false);
1402
- }, [onPointerInTransitChange]);
1403
- const handleCreateGraceArea = React.useCallback(
1404
- (event, hoverTarget) => {
1405
- const currentTarget = event.currentTarget;
1406
- const exitPoint = { x: event.clientX, y: event.clientY };
1407
- const exitSide = getExitSideFromRect(exitPoint, currentTarget.getBoundingClientRect());
1408
- const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
1409
- const hoverTargetPoints = getPointsFromRect(hoverTarget.getBoundingClientRect());
1410
- const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
1411
- setPointerGraceArea(graceArea);
1412
- onPointerInTransitChange(true);
1413
- },
1414
- [onPointerInTransitChange]
1415
- );
1416
- React.useEffect(() => {
1417
- return () => handleRemoveGraceArea();
1418
- }, [handleRemoveGraceArea]);
1419
- React.useEffect(() => {
1420
- if (trigger && content) {
1421
- const handleTriggerLeave = (event) => handleCreateGraceArea(event, content);
1422
- const handleContentLeave = (event) => handleCreateGraceArea(event, trigger);
1423
- trigger.addEventListener("pointerleave", handleTriggerLeave);
1424
- content.addEventListener("pointerleave", handleContentLeave);
1425
- return () => {
1426
- trigger.removeEventListener("pointerleave", handleTriggerLeave);
1427
- content.removeEventListener("pointerleave", handleContentLeave);
1428
- };
1429
- }
1430
- }, [trigger, content, handleCreateGraceArea, handleRemoveGraceArea]);
1431
- React.useEffect(() => {
1432
- if (pointerGraceArea) {
1433
- const handleTrackPointerGrace = (event) => {
1434
- const target = event.target;
1435
- const pointerPosition = { x: event.clientX, y: event.clientY };
1436
- const hasEnteredTarget = trigger?.contains(target) || content?.contains(target);
1437
- const isPointerOutsideGraceArea = !isPointInPolygon(pointerPosition, pointerGraceArea);
1438
- if (hasEnteredTarget) {
1439
- handleRemoveGraceArea();
1440
- } else if (isPointerOutsideGraceArea) {
1441
- handleRemoveGraceArea();
1442
- onClose();
1443
- }
1444
- };
1445
- document.addEventListener("pointermove", handleTrackPointerGrace);
1446
- return () => document.removeEventListener("pointermove", handleTrackPointerGrace);
1447
- }
1448
- }, [trigger, content, pointerGraceArea, onClose, handleRemoveGraceArea]);
1449
- return /* @__PURE__ */ jsx(TooltipContentImpl, { ...props, ref: composedRefs });
1450
- });
1451
- var [VisuallyHiddenContentContextProvider, useVisuallyHiddenContentContext] = createTooltipContext(TOOLTIP_NAME, { isInside: false });
1452
- var Slottable = createSlottable("TooltipContent");
1453
- var TooltipContentImpl = React.forwardRef(
1454
- (props, forwardedRef) => {
1455
- const {
1456
- __scopeTooltip,
1457
- children,
1458
- "aria-label": ariaLabel,
1459
- onEscapeKeyDown,
1460
- onPointerDownOutside,
1461
- ...contentProps
1462
- } = props;
1463
- const context = useTooltipContext(CONTENT_NAME, __scopeTooltip);
1464
- const popperScope = usePopperScope(__scopeTooltip);
1465
- const { onClose } = context;
1466
- React.useEffect(() => {
1467
- document.addEventListener(TOOLTIP_OPEN, onClose);
1468
- return () => document.removeEventListener(TOOLTIP_OPEN, onClose);
1469
- }, [onClose]);
1470
- React.useEffect(() => {
1471
- if (context.trigger) {
1472
- const handleScroll = (event) => {
1473
- const target = event.target;
1474
- if (target?.contains(context.trigger)) onClose();
1475
- };
1476
- window.addEventListener("scroll", handleScroll, { capture: true });
1477
- return () => window.removeEventListener("scroll", handleScroll, { capture: true });
1478
- }
1479
- }, [context.trigger, onClose]);
1480
- return /* @__PURE__ */ jsx(
1481
- DismissableLayer,
1482
- {
1483
- asChild: true,
1484
- disableOutsidePointerEvents: false,
1485
- onEscapeKeyDown,
1486
- onPointerDownOutside,
1487
- onFocusOutside: (event) => event.preventDefault(),
1488
- onDismiss: onClose,
1489
- children: /* @__PURE__ */ jsxs(
1490
- Content,
1491
- {
1492
- "data-state": context.stateAttribute,
1493
- ...popperScope,
1494
- ...contentProps,
1495
- ref: forwardedRef,
1496
- style: {
1497
- ...contentProps.style,
1498
- // re-namespace exposed content custom properties
1499
- ...{
1500
- "--radix-tooltip-content-transform-origin": "var(--radix-popper-transform-origin)",
1501
- "--radix-tooltip-content-available-width": "var(--radix-popper-available-width)",
1502
- "--radix-tooltip-content-available-height": "var(--radix-popper-available-height)",
1503
- "--radix-tooltip-trigger-width": "var(--radix-popper-anchor-width)",
1504
- "--radix-tooltip-trigger-height": "var(--radix-popper-anchor-height)"
1505
- }
1506
- },
1507
- children: [
1508
- /* @__PURE__ */ jsx(Slottable, { children }),
1509
- /* @__PURE__ */ jsx(VisuallyHiddenContentContextProvider, { scope: __scopeTooltip, isInside: true, children: /* @__PURE__ */ jsx(Root, { id: context.contentId, role: "tooltip", children: ariaLabel || children }) })
1510
- ]
1511
- }
1512
- )
1513
- }
1514
- );
1515
- }
1516
- );
1517
- TooltipContent$1.displayName = CONTENT_NAME;
1518
- var ARROW_NAME = "TooltipArrow";
1519
- var TooltipArrow = React.forwardRef(
1520
- (props, forwardedRef) => {
1521
- const { __scopeTooltip, ...arrowProps } = props;
1522
- const popperScope = usePopperScope(__scopeTooltip);
1523
- const visuallyHiddenContentContext = useVisuallyHiddenContentContext(
1524
- ARROW_NAME,
1525
- __scopeTooltip
1526
- );
1527
- return visuallyHiddenContentContext.isInside ? null : /* @__PURE__ */ jsx(Arrow, { ...popperScope, ...arrowProps, ref: forwardedRef });
1528
- }
1529
- );
1530
- TooltipArrow.displayName = ARROW_NAME;
1531
- function getExitSideFromRect(point, rect) {
1532
- const top = Math.abs(rect.top - point.y);
1533
- const bottom = Math.abs(rect.bottom - point.y);
1534
- const right = Math.abs(rect.right - point.x);
1535
- const left = Math.abs(rect.left - point.x);
1536
- switch (Math.min(top, bottom, right, left)) {
1537
- case left:
1538
- return "left";
1539
- case right:
1540
- return "right";
1541
- case top:
1542
- return "top";
1543
- case bottom:
1544
- return "bottom";
1545
- default:
1546
- throw new Error("unreachable");
1547
- }
1548
- }
1549
- function getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
1550
- const paddedExitPoints = [];
1551
- switch (exitSide) {
1552
- case "top":
1553
- paddedExitPoints.push(
1554
- { x: exitPoint.x - padding, y: exitPoint.y + padding },
1555
- { x: exitPoint.x + padding, y: exitPoint.y + padding }
1556
- );
1557
- break;
1558
- case "bottom":
1559
- paddedExitPoints.push(
1560
- { x: exitPoint.x - padding, y: exitPoint.y - padding },
1561
- { x: exitPoint.x + padding, y: exitPoint.y - padding }
1562
- );
1563
- break;
1564
- case "left":
1565
- paddedExitPoints.push(
1566
- { x: exitPoint.x + padding, y: exitPoint.y - padding },
1567
- { x: exitPoint.x + padding, y: exitPoint.y + padding }
1568
- );
1569
- break;
1570
- case "right":
1571
- paddedExitPoints.push(
1572
- { x: exitPoint.x - padding, y: exitPoint.y - padding },
1573
- { x: exitPoint.x - padding, y: exitPoint.y + padding }
1574
- );
1575
- break;
1576
- }
1577
- return paddedExitPoints;
1578
- }
1579
- function getPointsFromRect(rect) {
1580
- const { top, right, bottom, left } = rect;
1581
- return [
1582
- { x: left, y: top },
1583
- { x: right, y: top },
1584
- { x: right, y: bottom },
1585
- { x: left, y: bottom }
1586
- ];
1587
- }
1588
- function isPointInPolygon(point, polygon) {
1589
- const { x, y } = point;
1590
- let inside = false;
1591
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
1592
- const ii = polygon[i];
1593
- const jj = polygon[j];
1594
- const xi = ii.x;
1595
- const yi = ii.y;
1596
- const xj = jj.x;
1597
- const yj = jj.y;
1598
- const intersect = yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
1599
- if (intersect) inside = !inside;
1600
- }
1601
- return inside;
1602
- }
1603
- function getHull(points) {
1604
- const newPoints = points.slice();
1605
- newPoints.sort((a, b) => {
1606
- if (a.x < b.x) return -1;
1607
- else if (a.x > b.x) return 1;
1608
- else if (a.y < b.y) return -1;
1609
- else if (a.y > b.y) return 1;
1610
- else return 0;
1611
- });
1612
- return getHullPresorted(newPoints);
1613
- }
1614
- function getHullPresorted(points) {
1615
- if (points.length <= 1) return points.slice();
1616
- const upperHull = [];
1617
- for (let i = 0; i < points.length; i++) {
1618
- const p = points[i];
1619
- while (upperHull.length >= 2) {
1620
- const q = upperHull[upperHull.length - 1];
1621
- const r = upperHull[upperHull.length - 2];
1622
- if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) upperHull.pop();
1623
- else break;
1624
- }
1625
- upperHull.push(p);
1626
- }
1627
- upperHull.pop();
1628
- const lowerHull = [];
1629
- for (let i = points.length - 1; i >= 0; i--) {
1630
- const p = points[i];
1631
- while (lowerHull.length >= 2) {
1632
- const q = lowerHull[lowerHull.length - 1];
1633
- const r = lowerHull[lowerHull.length - 2];
1634
- if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x)) lowerHull.pop();
1635
- else break;
1636
- }
1637
- lowerHull.push(p);
1638
- }
1639
- lowerHull.pop();
1640
- if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y) {
1641
- return upperHull;
1642
- } else {
1643
- return upperHull.concat(lowerHull);
1644
- }
1645
- }
1646
- var Provider = TooltipProvider$1;
1647
- var Root3 = Tooltip$1;
1648
- var Trigger = TooltipTrigger$1;
1649
- var Portal = TooltipPortal;
1650
- var Content2 = TooltipContent$1;
1651
- var Arrow2 = TooltipArrow;
1652
-
1653
- const TooltipProvider = (_a) => {
1654
- var { delayDuration = 0 } = _a, props = __rest(_a, ["delayDuration"]);
1655
- return (jsx(Provider, Object.assign({ "data-slot": "tooltip-provider", delayDuration: delayDuration }, props)));
1656
- };
1657
- const Tooltip = (_a) => {
1658
- var props = __rest(_a, []);
1659
- return (jsx(TooltipProvider, { children: jsx(Root3, Object.assign({ "data-slot": "tooltip" }, props)) }));
1660
- };
1661
- const TooltipTrigger = (_a) => {
1662
- var props = __rest(_a, []);
1663
- return (jsx(Trigger, Object.assign({ "data-slot": "tooltip-trigger" }, props)));
1664
- };
1665
- const TooltipContent = (_a) => {
1666
- var { className, sideOffset = 0, children } = _a, props = __rest(_a, ["className", "sideOffset", "children"]);
1667
- return (jsx(Portal, { children: jsxs(Content2, Object.assign({ "data-slot": "tooltip-content", sideOffset: sideOffset, className: cn('bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance', className) }, props, { children: [children, jsx(Arrow2, { className: "bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" })] })) }));
1668
- };
1669
-
1670
- export { FloatingPortal as F, RotateCw as R, TooltipProvider as T, Tooltip as a, TooltipTrigger as b, TooltipContent as c, useFloating as u };
1671
- //# sourceMappingURL=tooltip-eb8a0f63.js.map