@sprawlify/primitives 0.0.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 (378) hide show
  1. package/dist/anatomy.cjs +3 -0
  2. package/dist/anatomy.d.cts +2 -0
  3. package/dist/anatomy.d.mts +2 -0
  4. package/dist/anatomy.mjs +3 -0
  5. package/dist/aria-hidden-DqYx0f_y.mjs +177 -0
  6. package/dist/aria-hidden-DtLU6hSU.cjs +182 -0
  7. package/dist/aria-hidden.cjs +4 -0
  8. package/dist/aria-hidden.d.cts +16 -0
  9. package/dist/aria-hidden.d.mts +16 -0
  10. package/dist/aria-hidden.mjs +4 -0
  11. package/dist/auto-resize-D3qHtFy1.mjs +114 -0
  12. package/dist/auto-resize-xzlPFDyD.cjs +125 -0
  13. package/dist/auto-resize.cjs +5 -0
  14. package/dist/auto-resize.d.cts +17 -0
  15. package/dist/auto-resize.d.mts +17 -0
  16. package/dist/auto-resize.mjs +4 -0
  17. package/dist/chunk-CbDLau6x.cjs +34 -0
  18. package/dist/collection-8XqaNHs_.mjs +1279 -0
  19. package/dist/collection-DIoIDISa.cjs +1326 -0
  20. package/dist/collection.cjs +11 -0
  21. package/dist/collection.d.cts +5 -0
  22. package/dist/collection.d.mts +5 -0
  23. package/dist/collection.mjs +4 -0
  24. package/dist/color-BkAP1Tkd.d.mts +60 -0
  25. package/dist/color-VKewNv2e.d.cts +60 -0
  26. package/dist/color-utils-Cc5GVXZh.mjs +657 -0
  27. package/dist/color-utils-LER_6Zwu.cjs +680 -0
  28. package/dist/color-utils.cjs +7 -0
  29. package/dist/color-utils.d.cts +19 -0
  30. package/dist/color-utils.d.mts +19 -0
  31. package/dist/color-utils.mjs +4 -0
  32. package/dist/core-30pJjyC2.d.mts +49 -0
  33. package/dist/core-CQFbMdTl.cjs +176 -0
  34. package/dist/core-CefBjbst.d.cts +49 -0
  35. package/dist/core-DCFNMTZF.mjs +129 -0
  36. package/dist/core.cjs +12 -0
  37. package/dist/core.d.cts +3 -0
  38. package/dist/core.d.mts +3 -0
  39. package/dist/core.mjs +5 -0
  40. package/dist/create-anatomy-B3XYc-qG.d.mts +70 -0
  41. package/dist/create-anatomy-BGQ8pv8J.d.cts +70 -0
  42. package/dist/create-anatomy-BbDZbHpC.mjs +39 -0
  43. package/dist/create-anatomy-CDsIFUXg.cjs +45 -0
  44. package/dist/create-props-BnF_vl-E.mjs +5 -0
  45. package/dist/create-props-YKy7JIKj.cjs +11 -0
  46. package/dist/data-url-C3ITPVRX.d.cts +10 -0
  47. package/dist/data-url-DLwZ9M77.d.mts +10 -0
  48. package/dist/date-utils-D2xPHa_I.cjs +738 -0
  49. package/dist/date-utils-wEa1hhpc.mjs +474 -0
  50. package/dist/date-utils.cjs +46 -0
  51. package/dist/date-utils.d.cts +101 -0
  52. package/dist/date-utils.d.mts +2 -0
  53. package/dist/date-utils.mjs +3 -0
  54. package/dist/defineProperty-BoUOT9Ie.cjs +49 -0
  55. package/dist/defineProperty-DrXfyjd4.mjs +43 -0
  56. package/dist/dismissable-CTfKZ4OG.cjs +282 -0
  57. package/dist/dismissable-DDrx0xnH.mjs +271 -0
  58. package/dist/dismissable-layer-C7pZU2wi.d.cts +39 -0
  59. package/dist/dismissable-layer-t_b0fk-p.d.mts +39 -0
  60. package/dist/dismissable.cjs +7 -0
  61. package/dist/dismissable.d.cts +3 -0
  62. package/dist/dismissable.d.mts +3 -0
  63. package/dist/dismissable.mjs +6 -0
  64. package/dist/dom-query-CWZdWUGp.cjs +2141 -0
  65. package/dist/dom-query-DFCRhyj1.mjs +1374 -0
  66. package/dist/dom-query.cjs +130 -0
  67. package/dist/dom-query.d.cts +307 -0
  68. package/dist/dom-query.d.mts +307 -0
  69. package/dist/dom-query.mjs +3 -0
  70. package/dist/file-utils.cjs +220 -0
  71. package/dist/file-utils.d.cts +51 -0
  72. package/dist/file-utils.d.mts +51 -0
  73. package/dist/file-utils.mjs +210 -0
  74. package/dist/focus-trap-D-bypQEJ.mjs +485 -0
  75. package/dist/focus-trap-D4i52S9A.cjs +496 -0
  76. package/dist/focus-trap.cjs +5 -0
  77. package/dist/focus-trap.d.cts +88 -0
  78. package/dist/focus-trap.d.mts +88 -0
  79. package/dist/focus-trap.mjs +4 -0
  80. package/dist/focus-visible-DYTWdWpa.cjs +210 -0
  81. package/dist/focus-visible-irppYatv.mjs +175 -0
  82. package/dist/focus-visible.cjs +9 -0
  83. package/dist/focus-visible.d.cts +31 -0
  84. package/dist/focus-visible.d.mts +31 -0
  85. package/dist/focus-visible.mjs +4 -0
  86. package/dist/functions-BOkTDEFM.d.cts +15 -0
  87. package/dist/functions-IZtWcC8Q.d.mts +15 -0
  88. package/dist/highlight-word.cjs +100 -0
  89. package/dist/highlight-word.d.cts +24 -0
  90. package/dist/highlight-word.d.mts +24 -0
  91. package/dist/highlight-word.mjs +99 -0
  92. package/dist/hotkeys.cjs +758 -0
  93. package/dist/hotkeys.d.cts +130 -0
  94. package/dist/hotkeys.d.mts +130 -0
  95. package/dist/hotkeys.mjs +754 -0
  96. package/dist/i18n-utils.cjs +450 -0
  97. package/dist/i18n-utils.d.cts +61 -0
  98. package/dist/i18n-utils.d.mts +61 -0
  99. package/dist/i18n-utils.mjs +440 -0
  100. package/dist/index-BkzYij2j.d.mts +25 -0
  101. package/dist/index-Bqw3r34-.d.cts +1383 -0
  102. package/dist/index-C0MKXQmE.d.mts +1383 -0
  103. package/dist/index-C9-feK5c.d.cts +25 -0
  104. package/dist/index-CD5FN7kY.d.mts +114 -0
  105. package/dist/index-CJji6wHl.d.cts +15 -0
  106. package/dist/index-CNi5FkPe.d.mts +15 -0
  107. package/dist/index-D96rs8B0.d.mts +115 -0
  108. package/dist/index.cjs +0 -0
  109. package/dist/index.d.cts +1 -0
  110. package/dist/index.d.mts +1 -0
  111. package/dist/index.mjs +1 -0
  112. package/dist/interact-outside-BplxR9cR.mjs +200 -0
  113. package/dist/interact-outside-C8-oFBpB.cjs +205 -0
  114. package/dist/interact-outside.cjs +5 -0
  115. package/dist/interact-outside.d.cts +2 -0
  116. package/dist/interact-outside.d.mts +2 -0
  117. package/dist/interact-outside.mjs +5 -0
  118. package/dist/json-tree-utils.cjs +1512 -0
  119. package/dist/json-tree-utils.d.cts +117 -0
  120. package/dist/json-tree-utils.d.mts +117 -0
  121. package/dist/json-tree-utils.mjs +1463 -0
  122. package/dist/list-collection-BIMJGQjn.d.cts +61 -0
  123. package/dist/list-collection-Db3eixRU.d.mts +61 -0
  124. package/dist/live-region-CcZPGo89.cjs +52 -0
  125. package/dist/live-region-CnPh21WH.mjs +46 -0
  126. package/dist/live-region.cjs +3 -0
  127. package/dist/live-region.d.cts +2 -0
  128. package/dist/live-region.d.mts +2 -0
  129. package/dist/live-region.mjs +3 -0
  130. package/dist/machines/accordion/index.cjs +328 -0
  131. package/dist/machines/accordion/index.d.cts +83 -0
  132. package/dist/machines/accordion/index.d.mts +83 -0
  133. package/dist/machines/accordion/index.mjs +322 -0
  134. package/dist/machines/async-list/index.cjs +311 -0
  135. package/dist/machines/async-list/index.d.cts +89 -0
  136. package/dist/machines/async-list/index.d.mts +89 -0
  137. package/dist/machines/async-list/index.mjs +310 -0
  138. package/dist/machines/avatar/index.cjs +169 -0
  139. package/dist/machines/avatar/index.d.cts +63 -0
  140. package/dist/machines/avatar/index.d.mts +63 -0
  141. package/dist/machines/avatar/index.mjs +165 -0
  142. package/dist/machines/bottom-sheet/index.cjs +676 -0
  143. package/dist/machines/bottom-sheet/index.d.cts +239 -0
  144. package/dist/machines/bottom-sheet/index.d.mts +239 -0
  145. package/dist/machines/bottom-sheet/index.mjs +672 -0
  146. package/dist/machines/carousel/index.cjs +859 -0
  147. package/dist/machines/carousel/index.d.cts +146 -0
  148. package/dist/machines/carousel/index.d.mts +146 -0
  149. package/dist/machines/carousel/index.mjs +851 -0
  150. package/dist/machines/checkbox/index.cjs +316 -0
  151. package/dist/machines/checkbox/index.d.cts +81 -0
  152. package/dist/machines/checkbox/index.d.mts +81 -0
  153. package/dist/machines/checkbox/index.mjs +312 -0
  154. package/dist/machines/clipboard/index.cjs +225 -0
  155. package/dist/machines/clipboard/index.d.cts +68 -0
  156. package/dist/machines/clipboard/index.d.mts +68 -0
  157. package/dist/machines/clipboard/index.mjs +219 -0
  158. package/dist/machines/collapsible/index.cjs +362 -0
  159. package/dist/machines/collapsible/index.d.cts +82 -0
  160. package/dist/machines/collapsible/index.d.mts +82 -0
  161. package/dist/machines/collapsible/index.mjs +358 -0
  162. package/dist/machines/color-picker/index.cjs +1529 -0
  163. package/dist/machines/color-picker/index.d.cts +205 -0
  164. package/dist/machines/color-picker/index.d.mts +205 -0
  165. package/dist/machines/color-picker/index.mjs +1514 -0
  166. package/dist/machines/combobox/index.cjs +1593 -0
  167. package/dist/machines/combobox/index.d.cts +214 -0
  168. package/dist/machines/combobox/index.d.mts +214 -0
  169. package/dist/machines/combobox/index.mjs +1582 -0
  170. package/dist/machines/date-picker/index.cjs +2177 -0
  171. package/dist/machines/date-picker/index.d.cts +350 -0
  172. package/dist/machines/date-picker/index.d.mts +350 -0
  173. package/dist/machines/date-picker/index.mjs +2161 -0
  174. package/dist/machines/dialog/index.cjs +325 -0
  175. package/dist/machines/dialog/index.d.cts +80 -0
  176. package/dist/machines/dialog/index.d.mts +80 -0
  177. package/dist/machines/dialog/index.mjs +321 -0
  178. package/dist/machines/editable/index.cjs +551 -0
  179. package/dist/machines/editable/index.d.cts +114 -0
  180. package/dist/machines/editable/index.d.mts +114 -0
  181. package/dist/machines/editable/index.mjs +547 -0
  182. package/dist/machines/floating-panel/index.cjs +995 -0
  183. package/dist/machines/floating-panel/index.d.cts +147 -0
  184. package/dist/machines/floating-panel/index.d.mts +147 -0
  185. package/dist/machines/floating-panel/index.mjs +988 -0
  186. package/dist/machines/hover-card/index.cjs +383 -0
  187. package/dist/machines/hover-card/index.d.cts +69 -0
  188. package/dist/machines/hover-card/index.d.mts +69 -0
  189. package/dist/machines/hover-card/index.mjs +379 -0
  190. package/dist/machines/image-cropper/index.cjs +1995 -0
  191. package/dist/machines/image-cropper/index.d.cts +182 -0
  192. package/dist/machines/image-cropper/index.d.mts +182 -0
  193. package/dist/machines/image-cropper/index.mjs +1990 -0
  194. package/dist/machines/listbox/index.cjs +794 -0
  195. package/dist/machines/listbox/index.d.cts +168 -0
  196. package/dist/machines/listbox/index.d.mts +168 -0
  197. package/dist/machines/listbox/index.mjs +782 -0
  198. package/dist/machines/marquee/index.cjs +395 -0
  199. package/dist/machines/marquee/index.d.cts +102 -0
  200. package/dist/machines/marquee/index.d.mts +102 -0
  201. package/dist/machines/marquee/index.mjs +391 -0
  202. package/dist/machines/menu/index.cjs +1298 -0
  203. package/dist/machines/menu/index.d.cts +175 -0
  204. package/dist/machines/menu/index.d.mts +175 -0
  205. package/dist/machines/menu/index.mjs +1286 -0
  206. package/dist/machines/navigation-menu/index.cjs +861 -0
  207. package/dist/machines/navigation-menu/index.d.cts +127 -0
  208. package/dist/machines/navigation-menu/index.d.mts +127 -0
  209. package/dist/machines/navigation-menu/index.mjs +857 -0
  210. package/dist/machines/number-input/index.cjs +996 -0
  211. package/dist/machines/number-input/index.d.cts +134 -0
  212. package/dist/machines/number-input/index.d.mts +134 -0
  213. package/dist/machines/number-input/index.mjs +991 -0
  214. package/dist/machines/pagination/index.cjs +419 -0
  215. package/dist/machines/pagination/index.d.cts +139 -0
  216. package/dist/machines/pagination/index.d.mts +139 -0
  217. package/dist/machines/pagination/index.mjs +411 -0
  218. package/dist/machines/password-input/index.cjs +228 -0
  219. package/dist/machines/password-input/index.d.cts +71 -0
  220. package/dist/machines/password-input/index.d.mts +71 -0
  221. package/dist/machines/password-input/index.mjs +224 -0
  222. package/dist/machines/pin-input/index.cjs +523 -0
  223. package/dist/machines/pin-input/index.d.cts +105 -0
  224. package/dist/machines/pin-input/index.d.mts +105 -0
  225. package/dist/machines/pin-input/index.mjs +519 -0
  226. package/dist/machines/popover/index.cjs +430 -0
  227. package/dist/machines/popover/index.d.cts +88 -0
  228. package/dist/machines/popover/index.d.mts +88 -0
  229. package/dist/machines/popover/index.mjs +426 -0
  230. package/dist/machines/presence/index.cjs +192 -0
  231. package/dist/machines/presence/index.d.cts +44 -0
  232. package/dist/machines/presence/index.d.mts +44 -0
  233. package/dist/machines/presence/index.mjs +190 -0
  234. package/dist/machines/progress/index.cjs +288 -0
  235. package/dist/machines/progress/index.d.cts +96 -0
  236. package/dist/machines/progress/index.d.mts +96 -0
  237. package/dist/machines/progress/index.mjs +284 -0
  238. package/dist/machines/qr-code/index.cjs +172 -0
  239. package/dist/machines/qr-code/index.d.cts +70 -0
  240. package/dist/machines/qr-code/index.d.mts +70 -0
  241. package/dist/machines/qr-code/index.mjs +167 -0
  242. package/dist/machines/radio-group/index.cjs +436 -0
  243. package/dist/machines/radio-group/index.d.cts +106 -0
  244. package/dist/machines/radio-group/index.d.mts +106 -0
  245. package/dist/machines/radio-group/index.mjs +430 -0
  246. package/dist/machines/rating-group/index.cjs +405 -0
  247. package/dist/machines/rating-group/index.d.cts +101 -0
  248. package/dist/machines/rating-group/index.d.mts +101 -0
  249. package/dist/machines/rating-group/index.mjs +399 -0
  250. package/dist/machines/scroll-area/index.cjs +857 -0
  251. package/dist/machines/scroll-area/index.d.cts +159 -0
  252. package/dist/machines/scroll-area/index.d.mts +159 -0
  253. package/dist/machines/scroll-area/index.mjs +853 -0
  254. package/dist/machines/select/index.cjs +1165 -0
  255. package/dist/machines/select/index.d.cts +183 -0
  256. package/dist/machines/select/index.d.mts +183 -0
  257. package/dist/machines/select/index.mjs +1154 -0
  258. package/dist/machines/signature-pad/index.cjs +334 -0
  259. package/dist/machines/signature-pad/index.d.cts +108 -0
  260. package/dist/machines/signature-pad/index.d.mts +108 -0
  261. package/dist/machines/signature-pad/index.mjs +328 -0
  262. package/dist/machines/slider/index.cjs +957 -0
  263. package/dist/machines/slider/index.d.cts +149 -0
  264. package/dist/machines/slider/index.d.mts +149 -0
  265. package/dist/machines/slider/index.mjs +949 -0
  266. package/dist/machines/splitter/index.cjs +1112 -0
  267. package/dist/machines/splitter/index.d.cts +155 -0
  268. package/dist/machines/splitter/index.d.mts +155 -0
  269. package/dist/machines/splitter/index.mjs +1103 -0
  270. package/dist/machines/steps/index.cjs +289 -0
  271. package/dist/machines/steps/index.d.cts +97 -0
  272. package/dist/machines/steps/index.d.mts +97 -0
  273. package/dist/machines/steps/index.mjs +285 -0
  274. package/dist/machines/switch/index.cjs +305 -0
  275. package/dist/machines/switch/index.d.cts +80 -0
  276. package/dist/machines/switch/index.d.mts +80 -0
  277. package/dist/machines/switch/index.mjs +301 -0
  278. package/dist/machines/tabs/index.cjs +508 -0
  279. package/dist/machines/tabs/index.d.cts +111 -0
  280. package/dist/machines/tabs/index.d.mts +111 -0
  281. package/dist/machines/tabs/index.mjs +500 -0
  282. package/dist/machines/tags-input/index.cjs +1127 -0
  283. package/dist/machines/tags-input/index.d.cts +179 -0
  284. package/dist/machines/tags-input/index.d.mts +179 -0
  285. package/dist/machines/tags-input/index.mjs +1121 -0
  286. package/dist/machines/timer/index.cjs +329 -0
  287. package/dist/machines/timer/index.d.cts +98 -0
  288. package/dist/machines/timer/index.d.mts +98 -0
  289. package/dist/machines/timer/index.mjs +324 -0
  290. package/dist/machines/toast/index.cjs +1155 -0
  291. package/dist/machines/toast/index.d.cts +195 -0
  292. package/dist/machines/toast/index.d.mts +195 -0
  293. package/dist/machines/toast/index.mjs +1151 -0
  294. package/dist/machines/toggle/index.cjs +103 -0
  295. package/dist/machines/toggle/index.d.cts +46 -0
  296. package/dist/machines/toggle/index.d.mts +46 -0
  297. package/dist/machines/toggle/index.mjs +99 -0
  298. package/dist/machines/toggle-group/index.cjs +328 -0
  299. package/dist/machines/toggle-group/index.d.cts +81 -0
  300. package/dist/machines/toggle-group/index.d.mts +81 -0
  301. package/dist/machines/toggle-group/index.mjs +322 -0
  302. package/dist/machines/tooltip/index.cjs +516 -0
  303. package/dist/machines/tooltip/index.d.cts +71 -0
  304. package/dist/machines/tooltip/index.d.mts +71 -0
  305. package/dist/machines/tooltip/index.mjs +512 -0
  306. package/dist/machines/tour/index.cjs +1108 -0
  307. package/dist/machines/tour/index.d.cts +206 -0
  308. package/dist/machines/tour/index.d.mts +206 -0
  309. package/dist/machines/tour/index.mjs +1101 -0
  310. package/dist/machines/tree-view/index.cjs +1271 -0
  311. package/dist/machines/tree-view/index.d.cts +215 -0
  312. package/dist/machines/tree-view/index.d.mts +215 -0
  313. package/dist/machines/tree-view/index.mjs +1263 -0
  314. package/dist/node-BctU8GXk.d.mts +24 -0
  315. package/dist/node-CSsuPZVZ.d.cts +24 -0
  316. package/dist/popper-BPJeAtcA.mjs +349 -0
  317. package/dist/popper-D0FAW_p7.cjs +373 -0
  318. package/dist/popper.cjs +8 -0
  319. package/dist/popper.d.cts +74 -0
  320. package/dist/popper.d.mts +2 -0
  321. package/dist/popper.mjs +5 -0
  322. package/dist/raf-BnlYUlDi.d.mts +15 -0
  323. package/dist/raf-Cd2FGy0z.d.cts +15 -0
  324. package/dist/rect-utils-0ellN0a_.mjs +854 -0
  325. package/dist/rect-utils-DKLRhP8G.cjs +1147 -0
  326. package/dist/rect-utils.cjs +51 -0
  327. package/dist/rect-utils.d.cts +198 -0
  328. package/dist/rect-utils.d.mts +198 -0
  329. package/dist/rect-utils.mjs +3 -0
  330. package/dist/remove-scroll-Lrfv79X_.mjs +58 -0
  331. package/dist/remove-scroll-Uvzg1L9r.cjs +63 -0
  332. package/dist/remove-scroll.cjs +0 -0
  333. package/dist/remove-scroll.d.cts +1 -0
  334. package/dist/remove-scroll.d.mts +1 -0
  335. package/dist/remove-scroll.mjs +1 -0
  336. package/dist/scroll-snap-CrTmQRzA.mjs +152 -0
  337. package/dist/scroll-snap-zyiZLv7W.cjs +175 -0
  338. package/dist/scroll-snap.cjs +7 -0
  339. package/dist/scroll-snap.d.cts +14 -0
  340. package/dist/scroll-snap.d.mts +14 -0
  341. package/dist/scroll-snap.mjs +4 -0
  342. package/dist/selection-BIhSzkF7.d.mts +50 -0
  343. package/dist/selection-CS1GBp8e.d.cts +50 -0
  344. package/dist/store-BZcXv49B.cjs +305 -0
  345. package/dist/store-DEojWy9H.mjs +263 -0
  346. package/dist/store.cjs +9 -0
  347. package/dist/store.d.cts +26 -0
  348. package/dist/store.d.mts +26 -0
  349. package/dist/store.mjs +3 -0
  350. package/dist/stringify-state.cjs +49 -0
  351. package/dist/stringify-state.d.cts +8 -0
  352. package/dist/stringify-state.d.mts +8 -0
  353. package/dist/stringify-state.mjs +46 -0
  354. package/dist/tree-collection-BwU5WhGQ.d.mts +78 -0
  355. package/dist/tree-collection-DP_eznnI.d.cts +78 -0
  356. package/dist/typeahead-BdNwVP09.d.cts +45 -0
  357. package/dist/typeahead-XN6lZ7G9.d.mts +45 -0
  358. package/dist/types-BivBkYg9.d.cts +57 -0
  359. package/dist/types-Bl_6JtPQ.d.mts +57 -0
  360. package/dist/types-CPUMVt7c.d.mts +54 -0
  361. package/dist/types-CT_W6HWr.d.cts +54 -0
  362. package/dist/types-DDTcG99l.d.mts +201 -0
  363. package/dist/types-DejIu60O.d.cts +201 -0
  364. package/dist/types-DiIdKZ3K.d.cts +45 -0
  365. package/dist/types-GxLIgJib.d.cts +17 -0
  366. package/dist/types.cjs +15 -0
  367. package/dist/types.d.cts +2 -0
  368. package/dist/types.d.mts +2 -0
  369. package/dist/types.mjs +14 -0
  370. package/dist/utils-BZyrxWWR.mjs +525 -0
  371. package/dist/utils-_6frwjgJ.cjs +1040 -0
  372. package/dist/utils.cjs +88 -0
  373. package/dist/utils.d.cts +144 -0
  374. package/dist/utils.d.mts +144 -0
  375. package/dist/utils.mjs +3 -0
  376. package/dist/wait-for-CMjPsqWk.d.cts +10 -0
  377. package/dist/wait-for-D2nkdD4z.d.mts +10 -0
  378. package/package.json +399 -0
@@ -0,0 +1,1279 @@
1
+ import { t as _defineProperty } from "./defineProperty-DrXfyjd4.mjs";
2
+ import { Ot as prevIndex, Tt as nextIndex, dt as isEqual, et as hasProp, mt as chunk, st as isObject } from "./utils-BZyrxWWR.mjs";
3
+
4
+ //#region src/shared/collection/list-collection.ts
5
+ let _Symbol$iterator;
6
+ const fallback = {
7
+ itemToValue(item) {
8
+ if (typeof item === "string") return item;
9
+ if (isObject(item) && hasProp(item, "value")) return item.value;
10
+ return "";
11
+ },
12
+ itemToString(item) {
13
+ if (typeof item === "string") return item;
14
+ if (isObject(item) && hasProp(item, "label")) return item.label;
15
+ return fallback.itemToValue(item);
16
+ },
17
+ isItemDisabled(item) {
18
+ if (isObject(item) && hasProp(item, "disabled")) return !!item.disabled;
19
+ return false;
20
+ }
21
+ };
22
+ _Symbol$iterator = Symbol.iterator;
23
+ var ListCollection = class ListCollection {
24
+ constructor(options) {
25
+ this.options = options;
26
+ _defineProperty(this, "items", void 0);
27
+ _defineProperty(this, "indexMap", null);
28
+ _defineProperty(this, "copy", (items) => {
29
+ return new ListCollection({
30
+ ...this.options,
31
+ items: items ?? [...this.items]
32
+ });
33
+ });
34
+ _defineProperty(this, "isEqual", (other) => {
35
+ return isEqual(this.items, other.items);
36
+ });
37
+ _defineProperty(this, "setItems", (items) => {
38
+ return this.copy(items);
39
+ });
40
+ _defineProperty(this, "getValues", (items = this.items) => {
41
+ const values = [];
42
+ for (const item of items) {
43
+ const value = this.getItemValue(item);
44
+ if (value != null) values.push(value);
45
+ }
46
+ return values;
47
+ });
48
+ _defineProperty(this, "find", (value) => {
49
+ if (value == null) return null;
50
+ const index = this.indexOf(value);
51
+ return index !== -1 ? this.at(index) : null;
52
+ });
53
+ _defineProperty(this, "findMany", (values) => {
54
+ const result = [];
55
+ for (const value of values) {
56
+ const item = this.find(value);
57
+ if (item != null) result.push(item);
58
+ }
59
+ return result;
60
+ });
61
+ _defineProperty(this, "at", (index) => {
62
+ if (!this.options.groupBy && !this.options.groupSort) return this.items[index] ?? null;
63
+ let idx = 0;
64
+ const groups = this.group();
65
+ for (const [, items] of groups) for (const item of items) {
66
+ if (idx === index) return item;
67
+ idx++;
68
+ }
69
+ return null;
70
+ });
71
+ _defineProperty(this, "sortFn", (valueA, valueB) => {
72
+ const indexA = this.indexOf(valueA);
73
+ const indexB = this.indexOf(valueB);
74
+ return (indexA ?? 0) - (indexB ?? 0);
75
+ });
76
+ _defineProperty(this, "sort", (values) => {
77
+ return [...values].sort(this.sortFn.bind(this));
78
+ });
79
+ _defineProperty(this, "getItemValue", (item) => {
80
+ if (item == null) return null;
81
+ return this.options.itemToValue?.(item) ?? fallback.itemToValue(item);
82
+ });
83
+ _defineProperty(this, "getItemDisabled", (item) => {
84
+ if (item == null) return false;
85
+ return this.options.isItemDisabled?.(item) ?? fallback.isItemDisabled(item);
86
+ });
87
+ _defineProperty(this, "stringifyItem", (item) => {
88
+ if (item == null) return null;
89
+ return this.options.itemToString?.(item) ?? fallback.itemToString(item);
90
+ });
91
+ _defineProperty(this, "stringify", (value) => {
92
+ if (value == null) return null;
93
+ return this.stringifyItem(this.find(value));
94
+ });
95
+ _defineProperty(this, "stringifyItems", (items, separator = ", ") => {
96
+ const strs = [];
97
+ for (const item of items) {
98
+ const str = this.stringifyItem(item);
99
+ if (str != null) strs.push(str);
100
+ }
101
+ return strs.join(separator);
102
+ });
103
+ _defineProperty(this, "stringifyMany", (value, separator) => {
104
+ return this.stringifyItems(this.findMany(value), separator);
105
+ });
106
+ _defineProperty(this, "has", (value) => {
107
+ return this.indexOf(value) !== -1;
108
+ });
109
+ _defineProperty(this, "hasItem", (item) => {
110
+ if (item == null) return false;
111
+ return this.has(this.getItemValue(item));
112
+ });
113
+ _defineProperty(this, "group", () => {
114
+ const { groupBy, groupSort } = this.options;
115
+ if (!groupBy) return [["", [...this.items]]];
116
+ const groups = /* @__PURE__ */ new Map();
117
+ this.items.forEach((item, index) => {
118
+ const groupKey = groupBy(item, index);
119
+ if (!groups.has(groupKey)) groups.set(groupKey, []);
120
+ groups.get(groupKey).push(item);
121
+ });
122
+ let entries = Array.from(groups.entries());
123
+ if (groupSort) entries.sort(([a], [b]) => {
124
+ if (typeof groupSort === "function") return groupSort(a, b);
125
+ if (Array.isArray(groupSort)) {
126
+ const indexA = groupSort.indexOf(a);
127
+ const indexB = groupSort.indexOf(b);
128
+ if (indexA === -1) return 1;
129
+ if (indexB === -1) return -1;
130
+ return indexA - indexB;
131
+ }
132
+ if (groupSort === "asc") return a.localeCompare(b);
133
+ if (groupSort === "desc") return b.localeCompare(a);
134
+ return 0;
135
+ });
136
+ return entries;
137
+ });
138
+ _defineProperty(this, "getNextValue", (value, step = 1, clamp = false) => {
139
+ let index = this.indexOf(value);
140
+ if (index === -1) return null;
141
+ index = clamp ? Math.min(index + step, this.size - 1) : index + step;
142
+ while (index <= this.size && this.getItemDisabled(this.at(index))) index++;
143
+ return this.getItemValue(this.at(index));
144
+ });
145
+ _defineProperty(this, "getPreviousValue", (value, step = 1, clamp = false) => {
146
+ let index = this.indexOf(value);
147
+ if (index === -1) return null;
148
+ index = clamp ? Math.max(index - step, 0) : index - step;
149
+ while (index >= 0 && this.getItemDisabled(this.at(index))) index--;
150
+ return this.getItemValue(this.at(index));
151
+ });
152
+ _defineProperty(this, "indexOf", (value) => {
153
+ if (value == null) return -1;
154
+ if (!this.options.groupBy && !this.options.groupSort) return this.items.findIndex((item) => this.getItemValue(item) === value);
155
+ if (!this.indexMap) {
156
+ this.indexMap = /* @__PURE__ */ new Map();
157
+ let idx = 0;
158
+ const groups = this.group();
159
+ for (const [, items] of groups) for (const item of items) {
160
+ const itemValue = this.getItemValue(item);
161
+ if (itemValue != null) this.indexMap.set(itemValue, idx);
162
+ idx++;
163
+ }
164
+ }
165
+ return this.indexMap.get(value) ?? -1;
166
+ });
167
+ _defineProperty(this, "getByText", (text, current) => {
168
+ const currentIndex = current != null ? this.indexOf(current) : -1;
169
+ const isSingleKey = text.length === 1;
170
+ for (let i = 0; i < this.items.length; i++) {
171
+ const item = this.items[(currentIndex + i + 1) % this.items.length];
172
+ if (isSingleKey && this.getItemValue(item) === current) continue;
173
+ if (this.getItemDisabled(item)) continue;
174
+ if (match(this.stringifyItem(item), text)) return item;
175
+ }
176
+ });
177
+ _defineProperty(this, "search", (queryString, options$1) => {
178
+ const { state, currentValue, timeout = 350 } = options$1;
179
+ const search = state.keysSoFar + queryString;
180
+ const query = search.length > 1 && Array.from(search).every((char) => char === search[0]) ? search[0] : search;
181
+ const item = this.getByText(query, currentValue);
182
+ const value = this.getItemValue(item);
183
+ function cleanup() {
184
+ clearTimeout(state.timer);
185
+ state.timer = -1;
186
+ }
187
+ function update(value$1) {
188
+ state.keysSoFar = value$1;
189
+ cleanup();
190
+ if (value$1 !== "") state.timer = +setTimeout(() => {
191
+ update("");
192
+ cleanup();
193
+ }, timeout);
194
+ }
195
+ update(search);
196
+ return value;
197
+ });
198
+ _defineProperty(this, "update", (value, item) => {
199
+ let index = this.indexOf(value);
200
+ if (index === -1) return this;
201
+ return this.copy([
202
+ ...this.items.slice(0, index),
203
+ item,
204
+ ...this.items.slice(index + 1)
205
+ ]);
206
+ });
207
+ _defineProperty(this, "upsert", (value, item, mode = "append") => {
208
+ let index = this.indexOf(value);
209
+ if (index === -1) return (mode === "append" ? this.append : this.prepend)(item);
210
+ return this.copy([
211
+ ...this.items.slice(0, index),
212
+ item,
213
+ ...this.items.slice(index + 1)
214
+ ]);
215
+ });
216
+ _defineProperty(this, "insert", (index, ...items) => {
217
+ return this.copy(insert$1(this.items, index, ...items));
218
+ });
219
+ _defineProperty(this, "insertBefore", (value, ...items) => {
220
+ let toIndex = this.indexOf(value);
221
+ if (toIndex === -1) if (this.items.length === 0) toIndex = 0;
222
+ else return this;
223
+ return this.copy(insert$1(this.items, toIndex, ...items));
224
+ });
225
+ _defineProperty(this, "insertAfter", (value, ...items) => {
226
+ let toIndex = this.indexOf(value);
227
+ if (toIndex === -1) if (this.items.length === 0) toIndex = 0;
228
+ else return this;
229
+ return this.copy(insert$1(this.items, toIndex + 1, ...items));
230
+ });
231
+ _defineProperty(this, "prepend", (...items) => {
232
+ return this.copy(insert$1(this.items, 0, ...items));
233
+ });
234
+ _defineProperty(this, "append", (...items) => {
235
+ return this.copy(insert$1(this.items, this.items.length, ...items));
236
+ });
237
+ _defineProperty(this, "filter", (fn) => {
238
+ const filteredItems = this.items.filter((item, index) => fn(this.stringifyItem(item), index, item));
239
+ return this.copy(filteredItems);
240
+ });
241
+ _defineProperty(this, "remove", (...itemsOrValues) => {
242
+ const values = itemsOrValues.map((itemOrValue) => typeof itemOrValue === "string" ? itemOrValue : this.getItemValue(itemOrValue));
243
+ return this.copy(this.items.filter((item) => {
244
+ const value = this.getItemValue(item);
245
+ if (value == null) return false;
246
+ return !values.includes(value);
247
+ }));
248
+ });
249
+ _defineProperty(this, "move", (value, toIndex) => {
250
+ const fromIndex = this.indexOf(value);
251
+ if (fromIndex === -1) return this;
252
+ return this.copy(move$1(this.items, [fromIndex], toIndex));
253
+ });
254
+ _defineProperty(this, "moveBefore", (value, ...values) => {
255
+ let toIndex = this.items.findIndex((item) => this.getItemValue(item) === value);
256
+ if (toIndex === -1) return this;
257
+ let indices = values.map((value$1) => this.items.findIndex((item) => this.getItemValue(item) === value$1)).sort((a, b) => a - b);
258
+ return this.copy(move$1(this.items, indices, toIndex));
259
+ });
260
+ _defineProperty(this, "moveAfter", (value, ...values) => {
261
+ let toIndex = this.items.findIndex((item) => this.getItemValue(item) === value);
262
+ if (toIndex === -1) return this;
263
+ let indices = values.map((value$1) => this.items.findIndex((item) => this.getItemValue(item) === value$1)).sort((a, b) => a - b);
264
+ return this.copy(move$1(this.items, indices, toIndex + 1));
265
+ });
266
+ _defineProperty(this, "reorder", (fromIndex, toIndex) => {
267
+ return this.copy(move$1(this.items, [fromIndex], toIndex));
268
+ });
269
+ _defineProperty(this, "compareValue", (a, b) => {
270
+ const indexA = this.indexOf(a);
271
+ const indexB = this.indexOf(b);
272
+ if (indexA < indexB) return -1;
273
+ if (indexA > indexB) return 1;
274
+ return 0;
275
+ });
276
+ _defineProperty(this, "range", (from, to) => {
277
+ let keys = [];
278
+ let key = from;
279
+ while (key != null) {
280
+ if (this.find(key)) keys.push(key);
281
+ if (key === to) return keys;
282
+ key = this.getNextValue(key);
283
+ }
284
+ return [];
285
+ });
286
+ _defineProperty(this, "getValueRange", (from, to) => {
287
+ if (from && to) {
288
+ if (this.compareValue(from, to) <= 0) return this.range(from, to);
289
+ return this.range(to, from);
290
+ }
291
+ return [];
292
+ });
293
+ _defineProperty(this, "toString", () => {
294
+ let result = "";
295
+ for (const item of this.items) {
296
+ const itemString = [
297
+ this.getItemValue(item),
298
+ this.stringifyItem(item),
299
+ this.getItemDisabled(item)
300
+ ].filter(Boolean).join(":");
301
+ result += itemString + ",";
302
+ }
303
+ return result;
304
+ });
305
+ _defineProperty(this, "toJSON", () => {
306
+ return {
307
+ size: this.size,
308
+ first: this.firstValue,
309
+ last: this.lastValue
310
+ };
311
+ });
312
+ this.items = [...options.items];
313
+ }
314
+ get size() {
315
+ return this.items.length;
316
+ }
317
+ get firstValue() {
318
+ let index = 0;
319
+ while (this.getItemDisabled(this.at(index))) index++;
320
+ return this.getItemValue(this.at(index));
321
+ }
322
+ get lastValue() {
323
+ let index = this.size - 1;
324
+ while (this.getItemDisabled(this.at(index))) index--;
325
+ return this.getItemValue(this.at(index));
326
+ }
327
+ *[_Symbol$iterator]() {
328
+ yield* this.items;
329
+ }
330
+ };
331
+ const match = (label, query) => {
332
+ return !!label?.toLowerCase().startsWith(query.toLowerCase());
333
+ };
334
+ function isListCollection(v) {
335
+ return v instanceof ListCollection;
336
+ }
337
+ function insert$1(items, index, ...values) {
338
+ return [
339
+ ...items.slice(0, index),
340
+ ...values,
341
+ ...items.slice(index)
342
+ ];
343
+ }
344
+ function move$1(items, indices, toIndex) {
345
+ indices = [...indices].sort((a, b) => a - b);
346
+ const itemsToMove = indices.map((i) => items[i]);
347
+ for (let i = indices.length - 1; i >= 0; i--) items = [...items.slice(0, indices[i]), ...items.slice(indices[i] + 1)];
348
+ toIndex = Math.max(0, toIndex - indices.filter((i) => i < toIndex).length);
349
+ return [
350
+ ...items.slice(0, toIndex),
351
+ ...itemsToMove,
352
+ ...items.slice(toIndex)
353
+ ];
354
+ }
355
+
356
+ //#endregion
357
+ //#region src/shared/collection/grid-collection.ts
358
+ var GridCollection = class extends ListCollection {
359
+ constructor(options) {
360
+ const { columnCount } = options;
361
+ super(options);
362
+ _defineProperty(this, "columnCount", void 0);
363
+ _defineProperty(this, "rows", null);
364
+ _defineProperty(this, "getRows", () => {
365
+ if (!this.rows) this.rows = chunk([...this.items], this.columnCount);
366
+ return this.rows;
367
+ });
368
+ _defineProperty(this, "getRowCount", () => {
369
+ return Math.ceil(this.items.length / this.columnCount);
370
+ });
371
+ _defineProperty(this, "getCellIndex", (row, column) => {
372
+ return row * this.columnCount + column;
373
+ });
374
+ _defineProperty(this, "getCell", (row, column) => {
375
+ return this.at(this.getCellIndex(row, column));
376
+ });
377
+ _defineProperty(this, "getValueCell", (value) => {
378
+ const index = this.indexOf(value);
379
+ if (index === -1) return null;
380
+ return {
381
+ row: Math.floor(index / this.columnCount),
382
+ column: index % this.columnCount
383
+ };
384
+ });
385
+ _defineProperty(this, "getLastEnabledColumnIndex", (row) => {
386
+ for (let col = this.columnCount - 1; col >= 0; col--) {
387
+ const cell = this.getCell(row, col);
388
+ if (cell && !this.getItemDisabled(cell)) return col;
389
+ }
390
+ return null;
391
+ });
392
+ _defineProperty(this, "getFirstEnabledColumnIndex", (row) => {
393
+ for (let col = 0; col < this.columnCount; col++) {
394
+ const cell = this.getCell(row, col);
395
+ if (cell && !this.getItemDisabled(cell)) return col;
396
+ }
397
+ return null;
398
+ });
399
+ _defineProperty(this, "getPreviousRowValue", (value, loop = false) => {
400
+ const currentCell = this.getValueCell(value);
401
+ if (currentCell === null) return null;
402
+ const rows = this.getRows();
403
+ const rowCount = rows.length;
404
+ let prevRowIndex = currentCell.row;
405
+ let prevColumnIndex = currentCell.column;
406
+ for (let i = 1; i <= rowCount; i++) {
407
+ prevRowIndex = prevIndex(rows, prevRowIndex, { loop });
408
+ const prevRow = rows[prevRowIndex];
409
+ if (!prevRow) continue;
410
+ if (!prevRow[prevColumnIndex]) {
411
+ const lastColumnIndex = this.getLastEnabledColumnIndex(prevRowIndex);
412
+ if (lastColumnIndex != null) prevColumnIndex = lastColumnIndex;
413
+ }
414
+ const cell = this.getCell(prevRowIndex, prevColumnIndex);
415
+ if (!this.getItemDisabled(cell)) return this.getItemValue(cell);
416
+ }
417
+ return this.firstValue;
418
+ });
419
+ _defineProperty(this, "getNextRowValue", (value, loop = false) => {
420
+ const currentCell = this.getValueCell(value);
421
+ if (currentCell === null) return null;
422
+ const rows = this.getRows();
423
+ const rowCount = rows.length;
424
+ let nextRowIndex = currentCell.row;
425
+ let nextColumnIndex = currentCell.column;
426
+ for (let i = 1; i <= rowCount; i++) {
427
+ nextRowIndex = nextIndex(rows, nextRowIndex, { loop });
428
+ const nextRow = rows[nextRowIndex];
429
+ if (!nextRow) continue;
430
+ if (!nextRow[nextColumnIndex]) {
431
+ const lastColumnIndex = this.getLastEnabledColumnIndex(nextRowIndex);
432
+ if (lastColumnIndex != null) nextColumnIndex = lastColumnIndex;
433
+ }
434
+ const cell = this.getCell(nextRowIndex, nextColumnIndex);
435
+ if (!this.getItemDisabled(cell)) return this.getItemValue(cell);
436
+ }
437
+ return this.lastValue;
438
+ });
439
+ this.columnCount = columnCount;
440
+ }
441
+ };
442
+ function isGridCollection(v) {
443
+ return hasProp(v, "columnCount") && hasProp(v, "getRows");
444
+ }
445
+
446
+ //#endregion
447
+ //#region src/shared/collection/selection.ts
448
+ var Selection = class Selection extends Set {
449
+ constructor(values = []) {
450
+ super(values);
451
+ _defineProperty(this, "selectionMode", "single");
452
+ _defineProperty(this, "deselectable", true);
453
+ _defineProperty(this, "copy", () => {
454
+ const clone = new Selection([...this]);
455
+ return this.sync(clone);
456
+ });
457
+ _defineProperty(this, "sync", (other) => {
458
+ other.selectionMode = this.selectionMode;
459
+ other.deselectable = this.deselectable;
460
+ return other;
461
+ });
462
+ _defineProperty(this, "isEmpty", () => {
463
+ return this.size === 0;
464
+ });
465
+ _defineProperty(this, "isSelected", (value) => {
466
+ if (this.selectionMode === "none" || value == null) return false;
467
+ return this.has(value);
468
+ });
469
+ _defineProperty(this, "canSelect", (collection, value) => {
470
+ return this.selectionMode !== "none" || !collection.getItemDisabled(collection.find(value));
471
+ });
472
+ _defineProperty(this, "firstSelectedValue", (collection) => {
473
+ let firstValue = null;
474
+ for (let value of this) if (!firstValue || collection.compareValue(value, firstValue) < 0) firstValue = value;
475
+ return firstValue;
476
+ });
477
+ _defineProperty(this, "lastSelectedValue", (collection) => {
478
+ let lastValue = null;
479
+ for (let value of this) if (!lastValue || collection.compareValue(value, lastValue) > 0) lastValue = value;
480
+ return lastValue;
481
+ });
482
+ _defineProperty(this, "extendSelection", (collection, anchorValue, targetValue) => {
483
+ if (this.selectionMode === "none") return this;
484
+ if (this.selectionMode === "single") return this.replaceSelection(collection, targetValue);
485
+ const selection = this.copy();
486
+ const lastSelected = Array.from(this).pop();
487
+ for (let key of collection.getValueRange(anchorValue, lastSelected ?? targetValue)) selection.delete(key);
488
+ for (let key of collection.getValueRange(targetValue, anchorValue)) if (this.canSelect(collection, key)) selection.add(key);
489
+ return selection;
490
+ });
491
+ _defineProperty(this, "toggleSelection", (collection, value) => {
492
+ if (this.selectionMode === "none") return this;
493
+ if (this.selectionMode === "single" && !this.isSelected(value)) return this.replaceSelection(collection, value);
494
+ const selection = this.copy();
495
+ if (selection.has(value)) selection.delete(value);
496
+ else if (selection.canSelect(collection, value)) selection.add(value);
497
+ return selection;
498
+ });
499
+ _defineProperty(this, "replaceSelection", (collection, value) => {
500
+ if (this.selectionMode === "none") return this;
501
+ if (value == null) return this;
502
+ if (!this.canSelect(collection, value)) return this;
503
+ const selection = new Selection([value]);
504
+ return this.sync(selection);
505
+ });
506
+ _defineProperty(this, "setSelection", (values$1) => {
507
+ if (this.selectionMode === "none") return this;
508
+ let selection = new Selection();
509
+ for (let value of values$1) if (value != null) {
510
+ selection.add(value);
511
+ if (this.selectionMode === "single") break;
512
+ }
513
+ return this.sync(selection);
514
+ });
515
+ _defineProperty(this, "clearSelection", () => {
516
+ const selection = this.copy();
517
+ if (selection.deselectable && selection.size > 0) selection.clear();
518
+ return selection;
519
+ });
520
+ _defineProperty(this, "select", (collection, value, forceToggle) => {
521
+ if (this.selectionMode === "none") return this;
522
+ if (this.selectionMode === "single") if (this.isSelected(value) && this.deselectable) return this.toggleSelection(collection, value);
523
+ else return this.replaceSelection(collection, value);
524
+ else if (this.selectionMode === "multiple" || forceToggle) return this.toggleSelection(collection, value);
525
+ else return this.replaceSelection(collection, value);
526
+ });
527
+ _defineProperty(this, "deselect", (value) => {
528
+ const selection = this.copy();
529
+ selection.delete(value);
530
+ return selection;
531
+ });
532
+ _defineProperty(this, "isEqual", (other) => {
533
+ return isEqual(Array.from(this), Array.from(other));
534
+ });
535
+ }
536
+ };
537
+
538
+ //#endregion
539
+ //#region src/shared/collection/tree-visit.ts
540
+ function access(node, indexPath, options) {
541
+ for (let i = 0; i < indexPath.length; i++) node = options.getChildren(node, indexPath.slice(i + 1))[indexPath[i]];
542
+ return node;
543
+ }
544
+ function ancestorIndexPaths(indexPaths) {
545
+ const sortedPaths = sortIndexPaths(indexPaths);
546
+ const result = [];
547
+ const seen = /* @__PURE__ */ new Set();
548
+ for (const indexPath of sortedPaths) {
549
+ const key = indexPath.join();
550
+ if (!seen.has(key)) {
551
+ seen.add(key);
552
+ result.push(indexPath);
553
+ }
554
+ }
555
+ return result;
556
+ }
557
+ function compareIndexPaths(a, b) {
558
+ for (let i = 0; i < Math.min(a.length, b.length); i++) {
559
+ if (a[i] < b[i]) return -1;
560
+ if (a[i] > b[i]) return 1;
561
+ }
562
+ return a.length - b.length;
563
+ }
564
+ function sortIndexPaths(indexPaths) {
565
+ return indexPaths.sort(compareIndexPaths);
566
+ }
567
+ function find(node, options) {
568
+ let found;
569
+ visit(node, {
570
+ ...options,
571
+ onEnter: (child, indexPath) => {
572
+ if (options.predicate(child, indexPath)) {
573
+ found = child;
574
+ return "stop";
575
+ }
576
+ }
577
+ });
578
+ return found;
579
+ }
580
+ function findAll(node, options) {
581
+ const found = [];
582
+ visit(node, {
583
+ onEnter: (child, indexPath) => {
584
+ if (options.predicate(child, indexPath)) found.push(child);
585
+ },
586
+ getChildren: options.getChildren
587
+ });
588
+ return found;
589
+ }
590
+ function findIndexPath(node, options) {
591
+ let found;
592
+ visit(node, {
593
+ onEnter: (child, indexPath) => {
594
+ if (options.predicate(child, indexPath)) {
595
+ found = [...indexPath];
596
+ return "stop";
597
+ }
598
+ },
599
+ getChildren: options.getChildren
600
+ });
601
+ return found;
602
+ }
603
+ function reduce(node, options) {
604
+ let result = options.initialResult;
605
+ visit(node, {
606
+ ...options,
607
+ onEnter: (child, indexPath) => {
608
+ result = options.nextResult(result, child, indexPath);
609
+ }
610
+ });
611
+ return result;
612
+ }
613
+ function flatMap(node, options) {
614
+ return reduce(node, {
615
+ ...options,
616
+ initialResult: [],
617
+ nextResult: (result, child, indexPath) => {
618
+ result.push(...options.transform(child, indexPath));
619
+ return result;
620
+ }
621
+ });
622
+ }
623
+ function filter(node, options) {
624
+ const { predicate, create, getChildren } = options;
625
+ const filterRecursive = (node$1, indexPath) => {
626
+ const children = getChildren(node$1, indexPath);
627
+ const filteredChildren = [];
628
+ children.forEach((child, index) => {
629
+ const filteredChild = filterRecursive(child, [...indexPath, index]);
630
+ if (filteredChild) filteredChildren.push(filteredChild);
631
+ });
632
+ const isRoot = indexPath.length === 0;
633
+ const nodeMatches = predicate(node$1, indexPath);
634
+ const hasFilteredChildren = filteredChildren.length > 0;
635
+ if (isRoot || nodeMatches || hasFilteredChildren) return create(node$1, filteredChildren, indexPath);
636
+ return null;
637
+ };
638
+ return filterRecursive(node, []) || create(node, [], []);
639
+ }
640
+ function flatten(rootNode, options) {
641
+ const nodes = [];
642
+ let idx = 0;
643
+ const idxMap = /* @__PURE__ */ new Map();
644
+ const parentMap = /* @__PURE__ */ new Map();
645
+ visit(rootNode, {
646
+ getChildren: options.getChildren,
647
+ onEnter: (node, indexPath) => {
648
+ if (!idxMap.has(node)) idxMap.set(node, idx++);
649
+ const children = options.getChildren(node, indexPath);
650
+ children.forEach((child) => {
651
+ if (!parentMap.has(child)) parentMap.set(child, node);
652
+ if (!idxMap.has(child)) idxMap.set(child, idx++);
653
+ });
654
+ const _children = children.length > 0 ? children.map((child) => idxMap.get(child)) : void 0;
655
+ const parent = parentMap.get(node);
656
+ const _parent = parent ? idxMap.get(parent) : void 0;
657
+ const _index = idxMap.get(node);
658
+ nodes.push({
659
+ ...node,
660
+ _children,
661
+ _parent,
662
+ _index
663
+ });
664
+ }
665
+ });
666
+ return nodes;
667
+ }
668
+ function insertOperation(index, nodes) {
669
+ return {
670
+ type: "insert",
671
+ index,
672
+ nodes
673
+ };
674
+ }
675
+ function removeOperation(indexes) {
676
+ return {
677
+ type: "remove",
678
+ indexes
679
+ };
680
+ }
681
+ function replaceOperation() {
682
+ return { type: "replace" };
683
+ }
684
+ function splitIndexPath(indexPath) {
685
+ return [indexPath.slice(0, -1), indexPath[indexPath.length - 1]];
686
+ }
687
+ function getInsertionOperations(indexPath, nodes, operations = /* @__PURE__ */ new Map()) {
688
+ const [parentIndexPath, index] = splitIndexPath(indexPath);
689
+ for (let i = parentIndexPath.length - 1; i >= 0; i--) {
690
+ const parentKey = parentIndexPath.slice(0, i).join();
691
+ switch (operations.get(parentKey)?.type) {
692
+ case "remove": continue;
693
+ }
694
+ operations.set(parentKey, replaceOperation());
695
+ }
696
+ const operation = operations.get(parentIndexPath.join());
697
+ switch (operation?.type) {
698
+ case "remove":
699
+ operations.set(parentIndexPath.join(), {
700
+ type: "removeThenInsert",
701
+ removeIndexes: operation.indexes,
702
+ insertIndex: index,
703
+ insertNodes: nodes
704
+ });
705
+ break;
706
+ default: operations.set(parentIndexPath.join(), insertOperation(index, nodes));
707
+ }
708
+ return operations;
709
+ }
710
+ function getRemovalOperations(indexPaths) {
711
+ const operations = /* @__PURE__ */ new Map();
712
+ const indexesToRemove = /* @__PURE__ */ new Map();
713
+ for (const indexPath of indexPaths) {
714
+ const parentKey = indexPath.slice(0, -1).join();
715
+ const value = indexesToRemove.get(parentKey) ?? [];
716
+ value.push(indexPath[indexPath.length - 1]);
717
+ indexesToRemove.set(parentKey, value.sort((a, b) => a - b));
718
+ }
719
+ for (const indexPath of indexPaths) for (let i = indexPath.length - 2; i >= 0; i--) {
720
+ const parentKey = indexPath.slice(0, i).join();
721
+ if (!operations.has(parentKey)) operations.set(parentKey, replaceOperation());
722
+ }
723
+ for (const [parentKey, indexes] of indexesToRemove) operations.set(parentKey, removeOperation(indexes));
724
+ return operations;
725
+ }
726
+ function getReplaceOperations(indexPath, node) {
727
+ const operations = /* @__PURE__ */ new Map();
728
+ const [parentIndexPath, index] = splitIndexPath(indexPath);
729
+ for (let i = parentIndexPath.length - 1; i >= 0; i--) {
730
+ const parentKey = parentIndexPath.slice(0, i).join();
731
+ operations.set(parentKey, replaceOperation());
732
+ }
733
+ operations.set(parentIndexPath.join(), {
734
+ type: "removeThenInsert",
735
+ removeIndexes: [index],
736
+ insertIndex: index,
737
+ insertNodes: [node]
738
+ });
739
+ return operations;
740
+ }
741
+ function mutate(node, operations, options) {
742
+ return map(node, {
743
+ ...options,
744
+ getChildren: (node$1, indexPath) => {
745
+ const key = indexPath.join();
746
+ switch (operations.get(key)?.type) {
747
+ case "replace":
748
+ case "remove":
749
+ case "removeThenInsert":
750
+ case "insert": return options.getChildren(node$1, indexPath);
751
+ default: return [];
752
+ }
753
+ },
754
+ transform: (node$1, children, indexPath) => {
755
+ const key = indexPath.join();
756
+ const operation = operations.get(key);
757
+ switch (operation?.type) {
758
+ case "remove": return options.create(node$1, children.filter((_, index) => !operation.indexes.includes(index)), indexPath);
759
+ case "removeThenInsert":
760
+ const updatedChildren = children.filter((_, index) => !operation.removeIndexes.includes(index));
761
+ const adjustedIndex = operation.removeIndexes.reduce((index, removedIndex) => removedIndex < index ? index - 1 : index, operation.insertIndex);
762
+ return options.create(node$1, splice(updatedChildren, adjustedIndex, 0, ...operation.insertNodes), indexPath);
763
+ case "insert": return options.create(node$1, splice(children, operation.index, 0, ...operation.nodes), indexPath);
764
+ case "replace": return options.create(node$1, children, indexPath);
765
+ default: return node$1;
766
+ }
767
+ }
768
+ });
769
+ }
770
+ function splice(array, start, deleteCount, ...items) {
771
+ return [
772
+ ...array.slice(0, start),
773
+ ...items,
774
+ ...array.slice(start + deleteCount)
775
+ ];
776
+ }
777
+ function map(node, options) {
778
+ const childrenMap = {};
779
+ visit(node, {
780
+ ...options,
781
+ onLeave: (child, indexPath) => {
782
+ const keyIndexPath = [0, ...indexPath];
783
+ const key = keyIndexPath.join();
784
+ const transformed = options.transform(child, childrenMap[key] ?? [], indexPath);
785
+ const parentKey = keyIndexPath.slice(0, -1).join();
786
+ const parentChildren = childrenMap[parentKey] ?? [];
787
+ parentChildren.push(transformed);
788
+ childrenMap[parentKey] = parentChildren;
789
+ }
790
+ });
791
+ return childrenMap[""][0];
792
+ }
793
+ function insert(node, options) {
794
+ const { nodes, at } = options;
795
+ if (at.length === 0) throw new Error(`Can't insert nodes at the root`);
796
+ return mutate(node, getInsertionOperations(at, nodes), options);
797
+ }
798
+ function replace(node, options) {
799
+ if (options.at.length === 0) return options.node;
800
+ return mutate(node, getReplaceOperations(options.at, options.node), options);
801
+ }
802
+ function remove(node, options) {
803
+ if (options.indexPaths.length === 0) return node;
804
+ for (const indexPath of options.indexPaths) if (indexPath.length === 0) throw new Error(`Can't remove the root node`);
805
+ return mutate(node, getRemovalOperations(options.indexPaths), options);
806
+ }
807
+ function move(node, options) {
808
+ if (options.indexPaths.length === 0) return node;
809
+ for (const indexPath of options.indexPaths) if (indexPath.length === 0) throw new Error(`Can't move the root node`);
810
+ if (options.to.length === 0) throw new Error(`Can't move nodes to the root`);
811
+ const _ancestorIndexPaths = ancestorIndexPaths(options.indexPaths);
812
+ const nodesToInsert = _ancestorIndexPaths.map((indexPath) => access(node, indexPath, options));
813
+ return mutate(node, getInsertionOperations(options.to, nodesToInsert, getRemovalOperations(_ancestorIndexPaths)), options);
814
+ }
815
+ function visit(node, options) {
816
+ const { onEnter, onLeave, getChildren } = options;
817
+ let indexPath = [];
818
+ let stack = [{ node }];
819
+ const getIndexPath = options.reuseIndexPath ? () => indexPath : () => indexPath.slice();
820
+ while (stack.length > 0) {
821
+ let wrapper = stack[stack.length - 1];
822
+ if (wrapper.state === void 0) {
823
+ const enterResult = onEnter?.(wrapper.node, getIndexPath());
824
+ if (enterResult === "stop") return;
825
+ wrapper.state = enterResult === "skip" ? -1 : 0;
826
+ }
827
+ const children = wrapper.children || getChildren(wrapper.node, getIndexPath());
828
+ wrapper.children || (wrapper.children = children);
829
+ if (wrapper.state !== -1) {
830
+ if (wrapper.state < children.length) {
831
+ let currentIndex = wrapper.state;
832
+ indexPath.push(currentIndex);
833
+ stack.push({ node: children[currentIndex] });
834
+ wrapper.state = currentIndex + 1;
835
+ continue;
836
+ }
837
+ if (onLeave?.(wrapper.node, getIndexPath()) === "stop") return;
838
+ }
839
+ indexPath.pop();
840
+ stack.pop();
841
+ }
842
+ }
843
+
844
+ //#endregion
845
+ //#region src/shared/collection/tree-collection.ts
846
+ var TreeCollection = class TreeCollection {
847
+ constructor(options) {
848
+ this.options = options;
849
+ _defineProperty(this, "rootNode", void 0);
850
+ _defineProperty(this, "isEqual", (other) => {
851
+ return isEqual(this.rootNode, other.rootNode);
852
+ });
853
+ _defineProperty(this, "getNodeChildren", (node) => {
854
+ return this.options.nodeToChildren?.(node) ?? fallbackMethods.nodeToChildren(node) ?? [];
855
+ });
856
+ _defineProperty(this, "resolveIndexPath", (valueOrIndexPath) => {
857
+ return typeof valueOrIndexPath === "string" ? this.getIndexPath(valueOrIndexPath) : valueOrIndexPath;
858
+ });
859
+ _defineProperty(this, "resolveNode", (valueOrIndexPath) => {
860
+ const indexPath = this.resolveIndexPath(valueOrIndexPath);
861
+ return indexPath ? this.at(indexPath) : void 0;
862
+ });
863
+ _defineProperty(this, "getNodeChildrenCount", (node) => {
864
+ return this.options.nodeToChildrenCount?.(node) ?? fallbackMethods.nodeToChildrenCount(node);
865
+ });
866
+ _defineProperty(this, "getNodeValue", (node) => {
867
+ return this.options.nodeToValue?.(node) ?? fallbackMethods.nodeToValue(node);
868
+ });
869
+ _defineProperty(this, "getNodeDisabled", (node) => {
870
+ return this.options.isNodeDisabled?.(node) ?? fallbackMethods.isNodeDisabled(node);
871
+ });
872
+ _defineProperty(this, "stringify", (value) => {
873
+ const node = this.findNode(value);
874
+ if (!node) return null;
875
+ return this.stringifyNode(node);
876
+ });
877
+ _defineProperty(this, "stringifyNode", (node) => {
878
+ return this.options.nodeToString?.(node) ?? fallbackMethods.nodeToString(node);
879
+ });
880
+ _defineProperty(this, "getFirstNode", (rootNode = this.rootNode) => {
881
+ let firstChild;
882
+ visit(rootNode, {
883
+ getChildren: this.getNodeChildren,
884
+ onEnter: (node, indexPath) => {
885
+ if (!firstChild && indexPath.length > 0 && !this.getNodeDisabled(node)) {
886
+ firstChild = node;
887
+ return "stop";
888
+ }
889
+ }
890
+ });
891
+ return firstChild;
892
+ });
893
+ _defineProperty(this, "getLastNode", (rootNode = this.rootNode, opts = {}) => {
894
+ let lastChild;
895
+ visit(rootNode, {
896
+ getChildren: this.getNodeChildren,
897
+ onEnter: (node, indexPath) => {
898
+ if (this.isSameNode(node, rootNode)) return;
899
+ if (opts.skip?.({
900
+ value: this.getNodeValue(node),
901
+ node,
902
+ indexPath
903
+ })) return "skip";
904
+ if (indexPath.length > 0 && !this.getNodeDisabled(node)) lastChild = node;
905
+ }
906
+ });
907
+ return lastChild;
908
+ });
909
+ _defineProperty(this, "at", (indexPath) => {
910
+ return access(this.rootNode, indexPath, { getChildren: this.getNodeChildren });
911
+ });
912
+ _defineProperty(this, "findNode", (value, rootNode = this.rootNode) => {
913
+ return find(rootNode, {
914
+ getChildren: this.getNodeChildren,
915
+ predicate: (node) => this.getNodeValue(node) === value
916
+ });
917
+ });
918
+ _defineProperty(this, "findNodes", (values, rootNode = this.rootNode) => {
919
+ const v = new Set(values.filter((v$1) => v$1 != null));
920
+ return findAll(rootNode, {
921
+ getChildren: this.getNodeChildren,
922
+ predicate: (node) => v.has(this.getNodeValue(node))
923
+ });
924
+ });
925
+ _defineProperty(this, "sort", (values) => {
926
+ return values.reduce((acc, value) => {
927
+ const indexPath = this.getIndexPath(value);
928
+ if (indexPath) acc.push({
929
+ value,
930
+ indexPath
931
+ });
932
+ return acc;
933
+ }, []).sort((a, b) => compareIndexPaths(a.indexPath, b.indexPath)).map(({ value }) => value);
934
+ });
935
+ _defineProperty(this, "getIndexPath", (value) => {
936
+ return findIndexPath(this.rootNode, {
937
+ getChildren: this.getNodeChildren,
938
+ predicate: (node) => this.getNodeValue(node) === value
939
+ });
940
+ });
941
+ _defineProperty(this, "getValue", (indexPath) => {
942
+ const node = this.at(indexPath);
943
+ return node ? this.getNodeValue(node) : void 0;
944
+ });
945
+ _defineProperty(this, "getValuePath", (indexPath) => {
946
+ if (!indexPath) return [];
947
+ const valuePath = [];
948
+ let currentPath = [...indexPath];
949
+ while (currentPath.length > 0) {
950
+ const node = this.at(currentPath);
951
+ if (node) valuePath.unshift(this.getNodeValue(node));
952
+ currentPath.pop();
953
+ }
954
+ return valuePath;
955
+ });
956
+ _defineProperty(this, "getDepth", (value) => {
957
+ return findIndexPath(this.rootNode, {
958
+ getChildren: this.getNodeChildren,
959
+ predicate: (node) => this.getNodeValue(node) === value
960
+ })?.length ?? 0;
961
+ });
962
+ _defineProperty(this, "isSameNode", (node, other) => {
963
+ return this.getNodeValue(node) === this.getNodeValue(other);
964
+ });
965
+ _defineProperty(this, "isRootNode", (node) => {
966
+ return this.isSameNode(node, this.rootNode);
967
+ });
968
+ _defineProperty(this, "contains", (parentIndexPath, valueIndexPath) => {
969
+ if (!parentIndexPath || !valueIndexPath) return false;
970
+ return valueIndexPath.slice(0, parentIndexPath.length).every((_, i) => parentIndexPath[i] === valueIndexPath[i]);
971
+ });
972
+ _defineProperty(this, "getNextNode", (value, opts = {}) => {
973
+ let found = false;
974
+ let nextNode;
975
+ visit(this.rootNode, {
976
+ getChildren: this.getNodeChildren,
977
+ onEnter: (node, indexPath) => {
978
+ if (this.isRootNode(node)) return;
979
+ const nodeValue = this.getNodeValue(node);
980
+ if (opts.skip?.({
981
+ value: nodeValue,
982
+ node,
983
+ indexPath
984
+ })) {
985
+ if (nodeValue === value) found = true;
986
+ return "skip";
987
+ }
988
+ if (found && !this.getNodeDisabled(node)) {
989
+ nextNode = node;
990
+ return "stop";
991
+ }
992
+ if (nodeValue === value) found = true;
993
+ }
994
+ });
995
+ return nextNode;
996
+ });
997
+ _defineProperty(this, "getPreviousNode", (value, opts = {}) => {
998
+ let previousNode;
999
+ let found = false;
1000
+ visit(this.rootNode, {
1001
+ getChildren: this.getNodeChildren,
1002
+ onEnter: (node, indexPath) => {
1003
+ if (this.isRootNode(node)) return;
1004
+ const nodeValue = this.getNodeValue(node);
1005
+ if (opts.skip?.({
1006
+ value: nodeValue,
1007
+ node,
1008
+ indexPath
1009
+ })) return "skip";
1010
+ if (nodeValue === value) {
1011
+ found = true;
1012
+ return "stop";
1013
+ }
1014
+ if (!this.getNodeDisabled(node)) previousNode = node;
1015
+ }
1016
+ });
1017
+ return found ? previousNode : void 0;
1018
+ });
1019
+ _defineProperty(this, "getParentNodes", (valueOrIndexPath) => {
1020
+ const indexPath = this.resolveIndexPath(valueOrIndexPath)?.slice();
1021
+ if (!indexPath) return [];
1022
+ const result = [];
1023
+ while (indexPath.length > 0) {
1024
+ indexPath.pop();
1025
+ const parentNode = this.at(indexPath);
1026
+ if (parentNode && !this.isRootNode(parentNode)) result.unshift(parentNode);
1027
+ }
1028
+ return result;
1029
+ });
1030
+ _defineProperty(this, "getDescendantNodes", (valueOrIndexPath, options$1) => {
1031
+ const parentNode = this.resolveNode(valueOrIndexPath);
1032
+ if (!parentNode) return [];
1033
+ const result = [];
1034
+ visit(parentNode, {
1035
+ getChildren: this.getNodeChildren,
1036
+ onEnter: (node, nodeIndexPath) => {
1037
+ if (nodeIndexPath.length === 0) return;
1038
+ if (!options$1?.withBranch && this.isBranchNode(node)) return;
1039
+ result.push(node);
1040
+ }
1041
+ });
1042
+ return result;
1043
+ });
1044
+ _defineProperty(this, "getDescendantValues", (valueOrIndexPath, options$1) => {
1045
+ return this.getDescendantNodes(valueOrIndexPath, options$1).map((child) => this.getNodeValue(child));
1046
+ });
1047
+ _defineProperty(this, "getParentIndexPath", (indexPath) => {
1048
+ return indexPath.slice(0, -1);
1049
+ });
1050
+ _defineProperty(this, "getParentNode", (valueOrIndexPath) => {
1051
+ const indexPath = this.resolveIndexPath(valueOrIndexPath);
1052
+ return indexPath ? this.at(this.getParentIndexPath(indexPath)) : void 0;
1053
+ });
1054
+ _defineProperty(this, "visit", (opts) => {
1055
+ const { skip, ...rest } = opts;
1056
+ visit(this.rootNode, {
1057
+ ...rest,
1058
+ getChildren: this.getNodeChildren,
1059
+ onEnter: (node, indexPath) => {
1060
+ if (this.isRootNode(node)) return;
1061
+ if (skip?.({
1062
+ value: this.getNodeValue(node),
1063
+ node,
1064
+ indexPath
1065
+ })) return "skip";
1066
+ return rest.onEnter?.(node, indexPath);
1067
+ }
1068
+ });
1069
+ });
1070
+ _defineProperty(this, "getPreviousSibling", (indexPath) => {
1071
+ const parentNode = this.getParentNode(indexPath);
1072
+ if (!parentNode) return;
1073
+ const siblings = this.getNodeChildren(parentNode);
1074
+ let idx = indexPath[indexPath.length - 1];
1075
+ while (--idx >= 0) {
1076
+ const sibling = siblings[idx];
1077
+ if (!this.getNodeDisabled(sibling)) return sibling;
1078
+ }
1079
+ });
1080
+ _defineProperty(this, "getNextSibling", (indexPath) => {
1081
+ const parentNode = this.getParentNode(indexPath);
1082
+ if (!parentNode) return;
1083
+ const siblings = this.getNodeChildren(parentNode);
1084
+ let idx = indexPath[indexPath.length - 1];
1085
+ while (++idx < siblings.length) {
1086
+ const sibling = siblings[idx];
1087
+ if (!this.getNodeDisabled(sibling)) return sibling;
1088
+ }
1089
+ });
1090
+ _defineProperty(this, "getSiblingNodes", (indexPath) => {
1091
+ const parentNode = this.getParentNode(indexPath);
1092
+ return parentNode ? this.getNodeChildren(parentNode) : [];
1093
+ });
1094
+ _defineProperty(this, "getValues", (rootNode = this.rootNode) => {
1095
+ return flatMap(rootNode, {
1096
+ getChildren: this.getNodeChildren,
1097
+ transform: (node) => [this.getNodeValue(node)]
1098
+ }).slice(1);
1099
+ });
1100
+ _defineProperty(this, "isValidDepth", (indexPath, depth) => {
1101
+ if (depth == null) return true;
1102
+ if (typeof depth === "function") return depth(indexPath.length);
1103
+ return indexPath.length === depth;
1104
+ });
1105
+ _defineProperty(this, "isBranchNode", (node) => {
1106
+ return this.getNodeChildren(node).length > 0 || this.getNodeChildrenCount(node) != null;
1107
+ });
1108
+ _defineProperty(this, "getBranchValues", (rootNode = this.rootNode, opts = {}) => {
1109
+ let values = [];
1110
+ visit(rootNode, {
1111
+ getChildren: this.getNodeChildren,
1112
+ onEnter: (node, indexPath) => {
1113
+ if (indexPath.length === 0) return;
1114
+ const nodeValue = this.getNodeValue(node);
1115
+ if (opts.skip?.({
1116
+ value: nodeValue,
1117
+ node,
1118
+ indexPath
1119
+ })) return "skip";
1120
+ if (this.isBranchNode(node) && this.isValidDepth(indexPath, opts.depth)) values.push(this.getNodeValue(node));
1121
+ }
1122
+ });
1123
+ return values;
1124
+ });
1125
+ _defineProperty(this, "flatten", (rootNode = this.rootNode) => {
1126
+ return flatten(rootNode, { getChildren: this.getNodeChildren });
1127
+ });
1128
+ _defineProperty(this, "_create", (node, children) => {
1129
+ if (this.getNodeChildren(node).length > 0 || children.length > 0) return {
1130
+ ...node,
1131
+ children
1132
+ };
1133
+ return { ...node };
1134
+ });
1135
+ _defineProperty(this, "_insert", (rootNode, indexPath, nodes) => {
1136
+ return this.copy(insert(rootNode, {
1137
+ at: indexPath,
1138
+ nodes,
1139
+ getChildren: this.getNodeChildren,
1140
+ create: this._create
1141
+ }));
1142
+ });
1143
+ _defineProperty(this, "copy", (rootNode) => {
1144
+ return new TreeCollection({
1145
+ ...this.options,
1146
+ rootNode
1147
+ });
1148
+ });
1149
+ _defineProperty(this, "_replace", (rootNode, indexPath, node) => {
1150
+ return this.copy(replace(rootNode, {
1151
+ at: indexPath,
1152
+ node,
1153
+ getChildren: this.getNodeChildren,
1154
+ create: this._create
1155
+ }));
1156
+ });
1157
+ _defineProperty(this, "_move", (rootNode, indexPaths, to) => {
1158
+ return this.copy(move(rootNode, {
1159
+ indexPaths,
1160
+ to,
1161
+ getChildren: this.getNodeChildren,
1162
+ create: this._create
1163
+ }));
1164
+ });
1165
+ _defineProperty(this, "_remove", (rootNode, indexPaths) => {
1166
+ return this.copy(remove(rootNode, {
1167
+ indexPaths,
1168
+ getChildren: this.getNodeChildren,
1169
+ create: this._create
1170
+ }));
1171
+ });
1172
+ _defineProperty(this, "replace", (indexPath, node) => {
1173
+ return this._replace(this.rootNode, indexPath, node);
1174
+ });
1175
+ _defineProperty(this, "remove", (indexPaths) => {
1176
+ return this._remove(this.rootNode, indexPaths);
1177
+ });
1178
+ _defineProperty(this, "insertBefore", (indexPath, nodes) => {
1179
+ return this.getParentNode(indexPath) ? this._insert(this.rootNode, indexPath, nodes) : void 0;
1180
+ });
1181
+ _defineProperty(this, "insertAfter", (indexPath, nodes) => {
1182
+ if (!this.getParentNode(indexPath)) return;
1183
+ const nextIndex$1 = [...indexPath.slice(0, -1), indexPath[indexPath.length - 1] + 1];
1184
+ return this._insert(this.rootNode, nextIndex$1, nodes);
1185
+ });
1186
+ _defineProperty(this, "move", (fromIndexPaths, toIndexPath) => {
1187
+ return this._move(this.rootNode, fromIndexPaths, toIndexPath);
1188
+ });
1189
+ _defineProperty(this, "filter", (predicate) => {
1190
+ const filteredRoot = filter(this.rootNode, {
1191
+ predicate,
1192
+ getChildren: this.getNodeChildren,
1193
+ create: this._create
1194
+ });
1195
+ return this.copy(filteredRoot);
1196
+ });
1197
+ _defineProperty(this, "toJSON", () => {
1198
+ return this.getValues(this.rootNode);
1199
+ });
1200
+ this.rootNode = options.rootNode;
1201
+ }
1202
+ };
1203
+ function flattenedToTree(nodes, options = fallbackMethods) {
1204
+ if (nodes.length === 0) throw new Error("[sprawlify-js/tree] Cannot create tree from empty flattened array");
1205
+ const rootFlatNode = nodes.find((node) => node._parent === void 0);
1206
+ if (!rootFlatNode) throw new Error("[sprawlify-js/tree] No root node found in flattened data");
1207
+ const nodeMap = /* @__PURE__ */ new Map();
1208
+ nodes.forEach((node) => {
1209
+ nodeMap.set(node._index, node);
1210
+ });
1211
+ const buildNode = (idx) => {
1212
+ const flatNode = nodeMap.get(idx);
1213
+ if (!flatNode) return {};
1214
+ const { _children, ...cleanNode } = flatNode;
1215
+ const children = [];
1216
+ _children?.forEach((childIndex) => {
1217
+ children.push(buildNode(childIndex));
1218
+ });
1219
+ return {
1220
+ ...cleanNode,
1221
+ ...children.length > 0 && { children }
1222
+ };
1223
+ };
1224
+ const rootNode = buildNode(rootFlatNode._index);
1225
+ return new TreeCollection({
1226
+ ...options,
1227
+ rootNode
1228
+ });
1229
+ }
1230
+ function filePathToTree(paths) {
1231
+ const rootNode = {
1232
+ label: "",
1233
+ value: "ROOT",
1234
+ children: []
1235
+ };
1236
+ paths.forEach((path) => {
1237
+ const parts = path.split("/");
1238
+ let currentNode = rootNode;
1239
+ parts.forEach((part, index) => {
1240
+ let childNode = currentNode.children?.find((child) => child.label === part);
1241
+ if (!childNode) {
1242
+ var _currentNode;
1243
+ childNode = {
1244
+ value: parts.slice(0, index + 1).join("/"),
1245
+ label: part
1246
+ };
1247
+ (_currentNode = currentNode).children || (_currentNode.children = []);
1248
+ currentNode.children.push(childNode);
1249
+ }
1250
+ currentNode = childNode;
1251
+ });
1252
+ });
1253
+ return new TreeCollection({ rootNode });
1254
+ }
1255
+ const fallbackMethods = {
1256
+ nodeToValue(node) {
1257
+ if (typeof node === "string") return node;
1258
+ if (isObject(node) && hasProp(node, "value")) return node.value;
1259
+ return "";
1260
+ },
1261
+ nodeToString(node) {
1262
+ if (typeof node === "string") return node;
1263
+ if (isObject(node) && hasProp(node, "label")) return node.label;
1264
+ return fallbackMethods.nodeToValue(node);
1265
+ },
1266
+ isNodeDisabled(node) {
1267
+ if (isObject(node) && hasProp(node, "disabled")) return !!node.disabled;
1268
+ return false;
1269
+ },
1270
+ nodeToChildren(node) {
1271
+ return node.children;
1272
+ },
1273
+ nodeToChildrenCount(node) {
1274
+ if (isObject(node) && hasProp(node, "childrenCount")) return node.childrenCount;
1275
+ }
1276
+ };
1277
+
1278
+ //#endregion
1279
+ export { GridCollection as a, isListCollection as c, Selection as i, filePathToTree as n, isGridCollection as o, flattenedToTree as r, ListCollection as s, TreeCollection as t };