@ariakit/core 0.0.1 → 0.1.1

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 (163) hide show
  1. package/.eslintignore +6 -0
  2. package/CHANGELOG.md +24 -0
  3. package/checkbox/checkbox-store/package.json +7 -0
  4. package/cjs/__chunks/2YFRPUZP.cjs +30 -0
  5. package/cjs/__chunks/3BBA3Z5G.cjs +143 -0
  6. package/cjs/__chunks/3KP2MDG6.cjs +1491 -0
  7. package/cjs/__chunks/5D5Y5EI4.cjs +146 -0
  8. package/cjs/__chunks/7ZXWQTAY.cjs +71 -0
  9. package/cjs/__chunks/AZVDLKO3.cjs +286 -0
  10. package/cjs/__chunks/EFEGT32M.cjs +12 -0
  11. package/cjs/__chunks/EIDN2CWH.cjs +57 -0
  12. package/cjs/__chunks/GDZQUFNP.cjs +30 -0
  13. package/cjs/__chunks/NX5OHIMM.cjs +169 -0
  14. package/cjs/__chunks/OFNGELMA.cjs +182 -0
  15. package/cjs/checkbox/checkbox-store.cjs +27 -0
  16. package/cjs/checkbox/checkbox-store.d.ts +34 -0
  17. package/cjs/collection/collection-store.cjs +9 -0
  18. package/cjs/collection/collection-store.d.ts +65 -0
  19. package/cjs/combobox/combobox-store.cjs +163 -0
  20. package/cjs/combobox/combobox-store.d.ts +67 -0
  21. package/cjs/composite/composite-overflow-store.cjs +15 -0
  22. package/cjs/composite/composite-overflow-store.d.ts +10 -0
  23. package/cjs/composite/composite-store.cjs +11 -0
  24. package/cjs/composite/composite-store.d.ts +202 -0
  25. package/cjs/dialog/dialog-store.cjs +9 -0
  26. package/cjs/dialog/dialog-store.d.ts +10 -0
  27. package/cjs/disclosure/disclosure-store.cjs +8 -0
  28. package/cjs/disclosure/disclosure-store.d.ts +87 -0
  29. package/cjs/form/form-store.cjs +241 -0
  30. package/cjs/form/form-store.d.ts +236 -0
  31. package/cjs/form/types.cjs +1 -0
  32. package/cjs/form/types.d.ts +38 -0
  33. package/cjs/hovercard/hovercard-store.cjs +11 -0
  34. package/cjs/hovercard/hovercard-store.d.ts +45 -0
  35. package/cjs/index.cjs +5 -0
  36. package/cjs/index.d.ts +2 -0
  37. package/cjs/menu/menu-bar-store.cjs +27 -0
  38. package/cjs/menu/menu-bar-store.d.ts +10 -0
  39. package/cjs/menu/menu-store.cjs +108 -0
  40. package/cjs/menu/menu-store.d.ts +70 -0
  41. package/cjs/popover/popover-store.cjs +10 -0
  42. package/cjs/popover/popover-store.d.ts +150 -0
  43. package/cjs/radio/radio-store.cjs +41 -0
  44. package/cjs/radio/radio-store.d.ts +36 -0
  45. package/cjs/select/select-store.cjs +164 -0
  46. package/cjs/select/select-store.d.ts +87 -0
  47. package/cjs/tab/tab-store.cjs +126 -0
  48. package/cjs/tab/tab-store.d.ts +78 -0
  49. package/cjs/toolbar/toolbar-store.cjs +27 -0
  50. package/cjs/toolbar/toolbar-store.d.ts +21 -0
  51. package/cjs/tooltip/tooltip-store.cjs +98 -0
  52. package/cjs/tooltip/tooltip-store.d.ts +28 -0
  53. package/cjs/tsconfig.build.tsbuildinfo +1 -0
  54. package/cjs/utils/array.cjs +12 -0
  55. package/cjs/utils/array.d.ts +29 -0
  56. package/cjs/utils/dom.cjs +38 -0
  57. package/cjs/utils/dom.d.ts +105 -0
  58. package/cjs/utils/events.cjs +132 -0
  59. package/cjs/utils/events.d.ts +73 -0
  60. package/cjs/utils/focus.cjs +222 -0
  61. package/cjs/utils/focus.d.ts +117 -0
  62. package/cjs/utils/misc.cjs +40 -0
  63. package/cjs/utils/misc.d.ts +111 -0
  64. package/cjs/utils/platform.cjs +15 -0
  65. package/cjs/utils/platform.d.ts +20 -0
  66. package/cjs/utils/store.cjs +9 -0
  67. package/cjs/utils/store.d.ts +99 -0
  68. package/cjs/utils/types.cjs +1 -0
  69. package/cjs/utils/types.d.ts +72 -0
  70. package/collection/collection-store/package.json +7 -0
  71. package/combobox/combobox-store/package.json +7 -0
  72. package/composite/composite-overflow-store/package.json +7 -0
  73. package/composite/composite-store/package.json +7 -0
  74. package/dialog/dialog-store/package.json +7 -0
  75. package/disclosure/disclosure-store/package.json +7 -0
  76. package/esm/__chunks/5XEKIOCW.js +30 -0
  77. package/esm/__chunks/6U25WEDX.js +286 -0
  78. package/esm/__chunks/6UPCMUXT.js +1491 -0
  79. package/esm/__chunks/ADRUFBEO.js +12 -0
  80. package/esm/__chunks/DXA3K2FY.js +30 -0
  81. package/esm/__chunks/HCKYJLMC.js +71 -0
  82. package/esm/__chunks/KLKI3AIB.js +146 -0
  83. package/esm/__chunks/L7KN5AYP.js +169 -0
  84. package/esm/__chunks/RX3ZUQ6U.js +57 -0
  85. package/esm/__chunks/UOJSZ35L.js +143 -0
  86. package/esm/__chunks/UVCATTRC.js +182 -0
  87. package/esm/checkbox/checkbox-store.d.ts +34 -0
  88. package/esm/checkbox/checkbox-store.js +27 -0
  89. package/esm/collection/collection-store.d.ts +65 -0
  90. package/esm/collection/collection-store.js +9 -0
  91. package/esm/combobox/combobox-store.d.ts +67 -0
  92. package/esm/combobox/combobox-store.js +163 -0
  93. package/esm/composite/composite-overflow-store.d.ts +10 -0
  94. package/esm/composite/composite-overflow-store.js +15 -0
  95. package/esm/composite/composite-store.d.ts +202 -0
  96. package/esm/composite/composite-store.js +11 -0
  97. package/esm/dialog/dialog-store.d.ts +10 -0
  98. package/esm/dialog/dialog-store.js +9 -0
  99. package/esm/disclosure/disclosure-store.d.ts +87 -0
  100. package/esm/disclosure/disclosure-store.js +8 -0
  101. package/esm/form/form-store.d.ts +236 -0
  102. package/esm/form/form-store.js +241 -0
  103. package/esm/form/types.d.ts +38 -0
  104. package/esm/form/types.js +0 -0
  105. package/esm/hovercard/hovercard-store.d.ts +45 -0
  106. package/esm/hovercard/hovercard-store.js +11 -0
  107. package/esm/index.d.ts +2 -0
  108. package/esm/index.js +5 -0
  109. package/esm/menu/menu-bar-store.d.ts +10 -0
  110. package/esm/menu/menu-bar-store.js +27 -0
  111. package/esm/menu/menu-store.d.ts +70 -0
  112. package/esm/menu/menu-store.js +108 -0
  113. package/esm/popover/popover-store.d.ts +150 -0
  114. package/esm/popover/popover-store.js +10 -0
  115. package/esm/radio/radio-store.d.ts +36 -0
  116. package/esm/radio/radio-store.js +41 -0
  117. package/esm/select/select-store.d.ts +87 -0
  118. package/esm/select/select-store.js +164 -0
  119. package/esm/tab/tab-store.d.ts +78 -0
  120. package/esm/tab/tab-store.js +126 -0
  121. package/esm/toolbar/toolbar-store.d.ts +21 -0
  122. package/esm/toolbar/toolbar-store.js +27 -0
  123. package/esm/tooltip/tooltip-store.d.ts +28 -0
  124. package/esm/tooltip/tooltip-store.js +98 -0
  125. package/esm/tsconfig.build.tsbuildinfo +1 -0
  126. package/esm/utils/array.d.ts +29 -0
  127. package/esm/utils/array.js +12 -0
  128. package/esm/utils/dom.d.ts +105 -0
  129. package/esm/utils/dom.js +38 -0
  130. package/esm/utils/events.d.ts +73 -0
  131. package/esm/utils/events.js +132 -0
  132. package/esm/utils/focus.d.ts +117 -0
  133. package/esm/utils/focus.js +222 -0
  134. package/esm/utils/misc.d.ts +111 -0
  135. package/esm/utils/misc.js +40 -0
  136. package/esm/utils/platform.d.ts +20 -0
  137. package/esm/utils/platform.js +15 -0
  138. package/esm/utils/store.d.ts +99 -0
  139. package/esm/utils/store.js +9 -0
  140. package/esm/utils/types.d.ts +72 -0
  141. package/esm/utils/types.js +0 -0
  142. package/form/form-store/package.json +7 -0
  143. package/form/types/package.json +7 -0
  144. package/hovercard/hovercard-store/package.json +7 -0
  145. package/license +21 -0
  146. package/menu/menu-bar-store/package.json +7 -0
  147. package/menu/menu-store/package.json +7 -0
  148. package/package.json +137 -6
  149. package/popover/popover-store/package.json +7 -0
  150. package/radio/radio-store/package.json +7 -0
  151. package/select/select-store/package.json +7 -0
  152. package/tab/tab-store/package.json +7 -0
  153. package/toolbar/toolbar-store/package.json +7 -0
  154. package/tooltip/tooltip-store/package.json +7 -0
  155. package/tsconfig.build.json +4 -0
  156. package/utils/array/package.json +7 -0
  157. package/utils/dom/package.json +7 -0
  158. package/utils/events/package.json +7 -0
  159. package/utils/focus/package.json +7 -0
  160. package/utils/misc/package.json +7 -0
  161. package/utils/platform/package.json +7 -0
  162. package/utils/store/package.json +7 -0
  163. package/utils/types/package.json +7 -0
@@ -0,0 +1,169 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _3BBA3Z5Gcjs = require('./3BBA3Z5G.cjs');
4
+
5
+
6
+
7
+ var _5D5Y5EI4cjs = require('./5D5Y5EI4.cjs');
8
+
9
+
10
+ var _OFNGELMAcjs = require('./OFNGELMA.cjs');
11
+
12
+ // src/collection/collection-store.ts
13
+ function isElementPreceding(a, b) {
14
+ return Boolean(
15
+ b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING
16
+ );
17
+ }
18
+ function sortBasedOnDOMPosition(items) {
19
+ const pairs = items.map((item, index) => [index, item]);
20
+ let isOrderDifferent = false;
21
+ pairs.sort(([indexA, a], [indexB, b]) => {
22
+ const elementA = a.element;
23
+ const elementB = b.element;
24
+ if (elementA === elementB)
25
+ return 0;
26
+ if (!elementA || !elementB)
27
+ return 0;
28
+ if (isElementPreceding(elementA, elementB)) {
29
+ if (indexA > indexB) {
30
+ isOrderDifferent = true;
31
+ }
32
+ return -1;
33
+ }
34
+ if (indexA < indexB) {
35
+ isOrderDifferent = true;
36
+ }
37
+ return 1;
38
+ });
39
+ if (isOrderDifferent) {
40
+ return pairs.map(([_, item]) => item);
41
+ }
42
+ return items;
43
+ }
44
+ function getCommonParent(items) {
45
+ const firstItem = items.find((item) => !!item.element);
46
+ const lastItem = [...items].reverse().find((item) => !!item.element);
47
+ let parentElement = _optionalChain([firstItem, 'optionalAccess', _2 => _2.element, 'optionalAccess', _3 => _3.parentElement]);
48
+ while (parentElement && _optionalChain([lastItem, 'optionalAccess', _4 => _4.element])) {
49
+ const parent = parentElement;
50
+ if (lastItem && parent.contains(lastItem.element)) {
51
+ return parentElement;
52
+ }
53
+ parentElement = parentElement.parentElement;
54
+ }
55
+ return _OFNGELMAcjs.getDocument.call(void 0, parentElement).body;
56
+ }
57
+ function createCollectionStore(props = {}) {
58
+ const itemsMap = /* @__PURE__ */ new Map();
59
+ const syncState = _optionalChain([props, 'access', _5 => _5.store, 'optionalAccess', _6 => _6.getState, 'call', _7 => _7()]);
60
+ const initialState = {
61
+ items: _5D5Y5EI4cjs.defaultValue.call(void 0, props.items, _optionalChain([syncState, 'optionalAccess', _8 => _8.items]), props.defaultItems, []),
62
+ renderedItems: _5D5Y5EI4cjs.defaultValue.call(void 0, _optionalChain([syncState, 'optionalAccess', _9 => _9.renderedItems]), [])
63
+ };
64
+ const privateStore = _3BBA3Z5Gcjs.createStore.call(void 0, {
65
+ renderedItems: initialState.renderedItems
66
+ });
67
+ const collection = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, props.store);
68
+ const sortItems = () => {
69
+ const state = privateStore.getState();
70
+ const renderedItems = sortBasedOnDOMPosition(state.renderedItems);
71
+ privateStore.setState("renderedItems", renderedItems);
72
+ collection.setState("renderedItems", renderedItems);
73
+ };
74
+ collection.setup(() => {
75
+ return privateStore.syncBatch(
76
+ (state) => {
77
+ let firstRun = true;
78
+ let raf = 0;
79
+ raf = requestAnimationFrame(sortItems);
80
+ if (typeof IntersectionObserver !== "function")
81
+ return;
82
+ const callback = () => {
83
+ if (firstRun) {
84
+ firstRun = false;
85
+ return;
86
+ }
87
+ cancelAnimationFrame(raf);
88
+ raf = requestAnimationFrame(sortItems);
89
+ };
90
+ const root = getCommonParent(state.renderedItems);
91
+ const observer = new IntersectionObserver(callback, { root });
92
+ state.renderedItems.forEach((item) => {
93
+ if (item.element) {
94
+ observer.observe(item.element);
95
+ }
96
+ });
97
+ return () => {
98
+ cancelAnimationFrame(raf);
99
+ observer.disconnect();
100
+ };
101
+ },
102
+ ["renderedItems"]
103
+ );
104
+ });
105
+ const mergeItem = (item, setItems, canDeleteFromMap = false) => {
106
+ let prevItem;
107
+ setItems((items) => {
108
+ const index = itemsMap.get(item.id) && items.findIndex(({ id }) => id === item.id);
109
+ const nextItems = items.slice();
110
+ if (index && index >= 0) {
111
+ prevItem = items[index];
112
+ const nextItem = { ...prevItem, ...item };
113
+ nextItems[index] = nextItem;
114
+ itemsMap.set(item.id, nextItem);
115
+ } else {
116
+ nextItems.push(item);
117
+ itemsMap.set(item.id, item);
118
+ }
119
+ return nextItems;
120
+ });
121
+ const unmergeItem = () => {
122
+ setItems((items) => {
123
+ if (!prevItem) {
124
+ if (canDeleteFromMap) {
125
+ itemsMap.delete(item.id);
126
+ }
127
+ return items.filter(({ id }) => id !== item.id);
128
+ }
129
+ const index = items.findIndex(({ id }) => id === item.id);
130
+ if (index === -1)
131
+ return items;
132
+ const nextItems = items.slice();
133
+ nextItems[index] = prevItem;
134
+ itemsMap.set(item.id, prevItem);
135
+ return nextItems;
136
+ });
137
+ };
138
+ return unmergeItem;
139
+ };
140
+ const registerItem = (item) => mergeItem(item, (getItems) => collection.setState("items", getItems), true);
141
+ return {
142
+ ...collection,
143
+ registerItem,
144
+ renderItem: (item) => _5D5Y5EI4cjs.chain.call(void 0,
145
+ registerItem(item),
146
+ mergeItem(
147
+ item,
148
+ (getItems) => privateStore.setState("renderedItems", getItems)
149
+ )
150
+ ),
151
+ item: (id) => {
152
+ if (!id)
153
+ return null;
154
+ let item = itemsMap.get(id);
155
+ if (!item) {
156
+ const { items } = collection.getState();
157
+ item = items.find((item2) => item2.id === id);
158
+ if (item) {
159
+ itemsMap.set(id, item);
160
+ }
161
+ }
162
+ return item || null;
163
+ }
164
+ };
165
+ }
166
+
167
+
168
+
169
+ exports.createCollectionStore = createCollectionStore;
@@ -0,0 +1,182 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/utils/dom.ts
2
+ var canUseDOM = checkIsBrowser();
3
+ function checkIsBrowser() {
4
+ return typeof window !== "undefined" && !!_optionalChain([window, 'access', _ => _.document, 'optionalAccess', _2 => _2.createElement]);
5
+ }
6
+ function getDocument(node) {
7
+ return node ? node.ownerDocument || node : document;
8
+ }
9
+ function getWindow(node) {
10
+ return getDocument(node).defaultView || window;
11
+ }
12
+ function getActiveElement(node, activeDescendant = false) {
13
+ const { activeElement } = getDocument(node);
14
+ if (!_optionalChain([activeElement, 'optionalAccess', _3 => _3.nodeName])) {
15
+ return null;
16
+ }
17
+ if (isFrame(activeElement) && activeElement.contentDocument) {
18
+ return getActiveElement(
19
+ activeElement.contentDocument.body,
20
+ activeDescendant
21
+ );
22
+ }
23
+ if (activeDescendant) {
24
+ const id = activeElement.getAttribute("aria-activedescendant");
25
+ if (id) {
26
+ const element = getDocument(activeElement).getElementById(id);
27
+ if (element) {
28
+ return element;
29
+ }
30
+ }
31
+ }
32
+ return activeElement;
33
+ }
34
+ function contains(parent, child) {
35
+ return parent === child || parent.contains(child);
36
+ }
37
+ function isFrame(element) {
38
+ return element.tagName === "IFRAME";
39
+ }
40
+ function isButton(element) {
41
+ const tagName = element.tagName.toLowerCase();
42
+ if (tagName === "button")
43
+ return true;
44
+ if (tagName === "input" && element.type) {
45
+ return buttonInputTypes.indexOf(element.type) !== -1;
46
+ }
47
+ return false;
48
+ }
49
+ var buttonInputTypes = [
50
+ "button",
51
+ "color",
52
+ "file",
53
+ "image",
54
+ "reset",
55
+ "submit"
56
+ ];
57
+ function matches(element, selectors) {
58
+ if ("matches" in element) {
59
+ return element.matches(selectors);
60
+ }
61
+ if ("msMatchesSelector" in element) {
62
+ return element.msMatchesSelector(selectors);
63
+ }
64
+ return element.webkitMatchesSelector(selectors);
65
+ }
66
+ function isVisible(element) {
67
+ const htmlElement = element;
68
+ return htmlElement.offsetWidth > 0 || htmlElement.offsetHeight > 0 || element.getClientRects().length > 0;
69
+ }
70
+ function closest(element, selectors) {
71
+ if ("closest" in element)
72
+ return element.closest(selectors);
73
+ do {
74
+ if (matches(element, selectors))
75
+ return element;
76
+ element = element.parentElement || element.parentNode;
77
+ } while (element !== null && element.nodeType === 1);
78
+ return null;
79
+ }
80
+ function isTextField(element) {
81
+ try {
82
+ const isTextInput = element instanceof HTMLInputElement && element.selectionStart !== null;
83
+ const isTextArea = element.tagName === "TEXTAREA";
84
+ return isTextInput || isTextArea || false;
85
+ } catch (error) {
86
+ return false;
87
+ }
88
+ }
89
+ function getPopupRole(element, fallback) {
90
+ const allowedPopupRoles = ["dialog", "menu", "listbox", "tree", "grid"];
91
+ const role = _optionalChain([element, 'optionalAccess', _4 => _4.getAttribute, 'call', _5 => _5("role")]);
92
+ if (role && allowedPopupRoles.indexOf(role) !== -1) {
93
+ return role;
94
+ }
95
+ return fallback;
96
+ }
97
+ function getPopupItemRole(element, fallback) {
98
+ const itemRoleByPopupRole = {
99
+ menu: "menuitem",
100
+ listbox: "option",
101
+ tree: "treeitem",
102
+ grid: "gridcell"
103
+ };
104
+ const popupRole = getPopupRole(element);
105
+ if (!popupRole)
106
+ return fallback;
107
+ const key = popupRole;
108
+ return _nullishCoalesce(itemRoleByPopupRole[key], () => ( fallback));
109
+ }
110
+ function getTextboxSelection(element) {
111
+ let start = 0;
112
+ let end = 0;
113
+ if (isTextField(element)) {
114
+ start = element.selectionStart || 0;
115
+ end = element.selectionEnd || 0;
116
+ } else if (element.isContentEditable) {
117
+ const selection = getDocument(element).getSelection();
118
+ if (_optionalChain([selection, 'optionalAccess', _6 => _6.rangeCount]) && selection.anchorNode && contains(element, selection.anchorNode) && selection.focusNode && contains(element, selection.focusNode)) {
119
+ const range = selection.getRangeAt(0);
120
+ const nextRange = range.cloneRange();
121
+ nextRange.selectNodeContents(element);
122
+ nextRange.setEnd(range.startContainer, range.startOffset);
123
+ start = nextRange.toString().length;
124
+ nextRange.setEnd(range.endContainer, range.endOffset);
125
+ end = nextRange.toString().length;
126
+ }
127
+ }
128
+ return { start, end };
129
+ }
130
+ function scrollIntoViewIfNeeded(element, arg) {
131
+ if (isPartiallyHidden(element) && "scrollIntoView" in element) {
132
+ element.scrollIntoView(arg);
133
+ }
134
+ }
135
+ function getScrollingElement(element) {
136
+ if (!element)
137
+ return null;
138
+ if (element.clientHeight && element.scrollHeight > element.clientHeight) {
139
+ const { overflowY } = getComputedStyle(element);
140
+ const isScrollable = overflowY !== "visible" && overflowY !== "hidden";
141
+ if (isScrollable)
142
+ return element;
143
+ }
144
+ return getScrollingElement(element.parentElement) || document.scrollingElement || document.body;
145
+ }
146
+ function isPartiallyHidden(element) {
147
+ const elementRect = element.getBoundingClientRect();
148
+ const scroller = getScrollingElement(element);
149
+ if (!scroller)
150
+ return false;
151
+ const scrollerRect = scroller.getBoundingClientRect();
152
+ const isHTML = scroller.tagName === "HTML";
153
+ const scrollerTop = isHTML ? scrollerRect.top + scroller.scrollTop : scrollerRect.top;
154
+ const scrollerBottom = isHTML ? scroller.clientHeight : scrollerRect.bottom;
155
+ const scrollerLeft = isHTML ? scrollerRect.left + scroller.scrollLeft : scrollerRect.left;
156
+ const scrollerRight = isHTML ? scroller.clientWidth : scrollerRect.right;
157
+ const top = elementRect.top < scrollerTop;
158
+ const left = elementRect.left < scrollerLeft;
159
+ const bottom = elementRect.bottom > scrollerBottom;
160
+ const right = elementRect.right > scrollerRight;
161
+ return top || left || bottom || right;
162
+ }
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+ exports.canUseDOM = canUseDOM; exports.getDocument = getDocument; exports.getWindow = getWindow; exports.getActiveElement = getActiveElement; exports.contains = contains; exports.isFrame = isFrame; exports.isButton = isButton; exports.matches = matches; exports.isVisible = isVisible; exports.closest = closest; exports.isTextField = isTextField; exports.getPopupRole = getPopupRole; exports.getPopupItemRole = getPopupItemRole; exports.getTextboxSelection = getTextboxSelection; exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded; exports.getScrollingElement = getScrollingElement; exports.isPartiallyHidden = isPartiallyHidden;
@@ -0,0 +1,27 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _3BBA3Z5Gcjs = require('../__chunks/3BBA3Z5G.cjs');
4
+
5
+
6
+ var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
7
+
8
+ // src/checkbox/checkbox-store.ts
9
+ function createCheckboxStore(props = {}) {
10
+ const syncState = _optionalChain([props, 'access', _ => _.store, 'optionalAccess', _2 => _2.getState, 'call', _3 => _3()]);
11
+ const initialState = {
12
+ value: _5D5Y5EI4cjs.defaultValue.call(void 0,
13
+ props.value,
14
+ _optionalChain([syncState, 'optionalAccess', _4 => _4.value]),
15
+ props.defaultValue,
16
+ false
17
+ )
18
+ };
19
+ const checkbox = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, props.store);
20
+ return {
21
+ ...checkbox,
22
+ setValue: (value) => checkbox.setState("value", value)
23
+ };
24
+ }
25
+
26
+
27
+ exports.createCheckboxStore = createCheckboxStore;
@@ -0,0 +1,34 @@
1
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
2
+ import type { PickRequired, SetState, ToPrimitive } from "../utils/types.js";
3
+ type Value = boolean | string | number | Array<string | number>;
4
+ /**
5
+ * Creates a checkbox store.
6
+ */
7
+ export declare function createCheckboxStore<T extends Value = Value>(props: PickRequired<CheckboxStoreProps<T>, "value" | "defaultValue">): CheckboxStore<T>;
8
+ export declare function createCheckboxStore(props?: CheckboxStoreProps): CheckboxStore;
9
+ export type CheckboxStoreValue = Value;
10
+ export interface CheckboxStoreState<T extends Value = Value> {
11
+ /**
12
+ * The checked state of the checkbox.
13
+ */
14
+ value: ToPrimitive<T>;
15
+ }
16
+ export interface CheckboxStoreFunctions<T extends Value = Value> {
17
+ /**
18
+ * Sets the `value` state.
19
+ * @example
20
+ * store.setValue(true);
21
+ * store.setValue((value) => !value);
22
+ */
23
+ setValue: SetState<CheckboxStoreState<T>["value"]>;
24
+ }
25
+ export interface CheckboxStoreOptions<T extends Value = Value> extends StoreOptions<CheckboxStoreState<T>, "value"> {
26
+ /**
27
+ * The default value of the checkbox.
28
+ * @default false
29
+ */
30
+ defaultValue?: CheckboxStoreState<T>["value"];
31
+ }
32
+ export type CheckboxStoreProps<T extends Value = Value> = CheckboxStoreOptions<T> & StoreProps<CheckboxStoreState<T>>;
33
+ export type CheckboxStore<T extends Value = Value> = CheckboxStoreFunctions<T> & Store<CheckboxStoreState<T>>;
34
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _NX5OHIMMcjs = require('../__chunks/NX5OHIMM.cjs');
4
+ require('../__chunks/3BBA3Z5G.cjs');
5
+ require('../__chunks/5D5Y5EI4.cjs');
6
+ require('../__chunks/OFNGELMA.cjs');
7
+
8
+
9
+ exports.createCollectionStore = _NX5OHIMMcjs.createCollectionStore;
@@ -0,0 +1,65 @@
1
+ import type { Store, StoreOptions, StoreProps } from "../utils/store.js";
2
+ import type { BivariantCallback } from "../utils/types.js";
3
+ type Item = {
4
+ id: string;
5
+ element?: HTMLElement | null;
6
+ };
7
+ /**
8
+ * Creates a collection store.
9
+ */
10
+ export declare function createCollectionStore<T extends Item = Item>(props?: CollectionStoreProps<T>): CollectionStore<T>;
11
+ export type CollectionStoreItem = Item;
12
+ export interface CollectionStoreState<T extends Item = Item> {
13
+ /**
14
+ * Lists all the items with their meta data. This state is automatically
15
+ * updated when an item is registered or unregistered with the `registerItem`
16
+ * function.
17
+ */
18
+ items: T[];
19
+ /**
20
+ * Lists all the items that are currently rendered. This state is
21
+ * automatically updated when an item is rendered or unrendered with the
22
+ * `renderItem` function. This state is also automatically sorted based on
23
+ * their DOM position.
24
+ */
25
+ renderedItems: T[];
26
+ }
27
+ export interface CollectionStoreFunctions<T extends Item = Item> {
28
+ /**
29
+ * Registers an item in the collection. This function returns a cleanup
30
+ * function that unregisters the item.
31
+ * @param item The item to register.
32
+ * @example
33
+ * const unregisterItem = store.registerItem({ id: "item-1" });
34
+ * // on cleanup
35
+ * unregisterItem();
36
+ */
37
+ registerItem: BivariantCallback<(item: T) => () => void>;
38
+ /**
39
+ * Renders an item in the collection. This function returns a cleanup function
40
+ * that unrenders the item.
41
+ * @param item The item to render.
42
+ * @example
43
+ * const unrenderItem = store.renderItem({ id: "item-1" });
44
+ * // on cleanup
45
+ * unrenderItem();
46
+ */
47
+ renderItem: BivariantCallback<(item: T) => () => void>;
48
+ /**
49
+ * Gets an item by its id.
50
+ * @param id The id of the item.
51
+ * @example
52
+ * const item = store.item("item-1");
53
+ */
54
+ item: (id: string | null | undefined) => T | null;
55
+ }
56
+ export interface CollectionStoreOptions<T extends Item = Item> extends StoreOptions<CollectionStoreState<T>, "items"> {
57
+ /**
58
+ * The defaut value for the `items` state.
59
+ * @default []
60
+ */
61
+ defaultItems?: CollectionStoreState<T>["items"];
62
+ }
63
+ export type CollectionStoreProps<T extends Item = Item> = CollectionStoreOptions<T> & StoreProps<CollectionStoreState<T>>;
64
+ export type CollectionStore<T extends Item = Item> = CollectionStoreFunctions<T> & Store<CollectionStoreState<T>>;
65
+ export {};
@@ -0,0 +1,163 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _3KP2MDG6cjs = require('../__chunks/3KP2MDG6.cjs');
4
+ require('../__chunks/EFEGT32M.cjs');
5
+ require('../__chunks/7ZXWQTAY.cjs');
6
+
7
+
8
+ var _AZVDLKO3cjs = require('../__chunks/AZVDLKO3.cjs');
9
+ require('../__chunks/NX5OHIMM.cjs');
10
+
11
+
12
+
13
+ var _3BBA3Z5Gcjs = require('../__chunks/3BBA3Z5G.cjs');
14
+
15
+
16
+ var _5D5Y5EI4cjs = require('../__chunks/5D5Y5EI4.cjs');
17
+
18
+
19
+
20
+ var _2YFRPUZPcjs = require('../__chunks/2YFRPUZP.cjs');
21
+ require('../__chunks/OFNGELMA.cjs');
22
+ require('../__chunks/GDZQUFNP.cjs');
23
+
24
+ // src/combobox/combobox-store.ts
25
+ var isSafariOnMobile = _2YFRPUZPcjs.isSafari.call(void 0, ) && _2YFRPUZPcjs.isTouchDevice.call(void 0, );
26
+ function createComboboxStore({
27
+ menu,
28
+ select,
29
+ ...props
30
+ } = {}) {
31
+ const store = _3BBA3Z5Gcjs.mergeStore.call(void 0,
32
+ props.store,
33
+ _optionalChain([menu, 'optionalAccess', _ => _.omit, 'call', _2 => _2(
34
+ "baseElement",
35
+ "arrowElement",
36
+ "anchorElement",
37
+ "contentElement",
38
+ "popoverElement",
39
+ "disclosureElement"
40
+ )]),
41
+ _optionalChain([select, 'optionalAccess', _3 => _3.omit, 'call', _4 => _4(
42
+ "value",
43
+ "items",
44
+ "renderedItems",
45
+ "baseElement",
46
+ "arrowElement",
47
+ "anchorElement",
48
+ "contentElement",
49
+ "popoverElement",
50
+ "disclosureElement"
51
+ )])
52
+ );
53
+ const syncState = store.getState();
54
+ const activeId = _5D5Y5EI4cjs.defaultValue.call(void 0,
55
+ props.activeId,
56
+ syncState.activeId,
57
+ props.defaultActiveId,
58
+ null
59
+ );
60
+ const composite = _AZVDLKO3cjs.createCompositeStore.call(void 0, {
61
+ ...props,
62
+ store,
63
+ activeId,
64
+ includesBaseElement: _5D5Y5EI4cjs.defaultValue.call(void 0,
65
+ props.includesBaseElement,
66
+ syncState.includesBaseElement,
67
+ true
68
+ ),
69
+ orientation: _5D5Y5EI4cjs.defaultValue.call(void 0,
70
+ props.orientation,
71
+ syncState.orientation,
72
+ "vertical"
73
+ ),
74
+ focusLoop: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusLoop, syncState.focusLoop, true),
75
+ focusWrap: _5D5Y5EI4cjs.defaultValue.call(void 0, props.focusWrap, syncState.focusWrap, true),
76
+ virtualFocus: _5D5Y5EI4cjs.defaultValue.call(void 0,
77
+ props.virtualFocus,
78
+ _optionalChain([syncState, 'optionalAccess', _5 => _5.virtualFocus]),
79
+ !isSafariOnMobile
80
+ )
81
+ });
82
+ const popover = _3KP2MDG6cjs.createPopoverStore.call(void 0, {
83
+ ...props,
84
+ store,
85
+ placement: _5D5Y5EI4cjs.defaultValue.call(void 0,
86
+ props.placement,
87
+ syncState.placement,
88
+ "bottom-start"
89
+ )
90
+ });
91
+ const initialValue = _5D5Y5EI4cjs.defaultValue.call(void 0,
92
+ props.value,
93
+ syncState.value,
94
+ props.defaultValue,
95
+ ""
96
+ );
97
+ const initialState = {
98
+ ...composite.getState(),
99
+ ...popover.getState(),
100
+ value: initialValue,
101
+ resetValueOnHide: _5D5Y5EI4cjs.defaultValue.call(void 0,
102
+ props.resetValueOnHide,
103
+ syncState.resetValueOnHide,
104
+ false
105
+ ),
106
+ activeValue: syncState.activeValue
107
+ };
108
+ const combobox = _3BBA3Z5Gcjs.createStore.call(void 0, initialState, composite, popover, store);
109
+ combobox.setup(
110
+ () => combobox.sync(
111
+ (state) => {
112
+ if (!state.resetValueOnHide)
113
+ return;
114
+ if (state.mounted)
115
+ return;
116
+ combobox.setState("value", initialValue);
117
+ },
118
+ ["resetValueOnHide", "mounted"]
119
+ )
120
+ );
121
+ combobox.setup(
122
+ () => combobox.syncBatch(
123
+ (state) => {
124
+ if (state.mounted)
125
+ return;
126
+ combobox.setState("activeId", activeId);
127
+ combobox.setState("moves", 0);
128
+ },
129
+ ["mounted"]
130
+ )
131
+ );
132
+ combobox.setup(
133
+ () => combobox.sync(
134
+ (state, prevState) => {
135
+ if (state.moves === prevState.moves) {
136
+ combobox.setState("activeValue", void 0);
137
+ }
138
+ },
139
+ ["moves", "activeId"]
140
+ )
141
+ );
142
+ combobox.setup(
143
+ () => combobox.syncBatch(
144
+ (state, prev) => {
145
+ if (state.moves === prev.moves)
146
+ return;
147
+ const { activeId: activeId2 } = combobox.getState();
148
+ const activeItem = composite.item(activeId2);
149
+ combobox.setState("activeValue", _optionalChain([activeItem, 'optionalAccess', _6 => _6.value]));
150
+ },
151
+ ["moves", "renderedItems"]
152
+ )
153
+ );
154
+ return {
155
+ ...popover,
156
+ ...composite,
157
+ ...combobox,
158
+ setValue: (value) => combobox.setState("value", value)
159
+ };
160
+ }
161
+
162
+
163
+ exports.createComboboxStore = createComboboxStore;