@wirekyt/dom 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (476) hide show
  1. package/dist/anatomy-DMuSMbOP.d.cts +18 -0
  2. package/dist/anatomy-DMuSMbOP.d.ts +18 -0
  3. package/dist/anatomy.cjs +3 -0
  4. package/dist/anatomy.d.cts +2 -0
  5. package/dist/anatomy.d.ts +2 -0
  6. package/dist/anatomy.js +2 -0
  7. package/dist/angle-3hqP0Mp5.cjs +13 -0
  8. package/dist/angle-oNt8uGHQ.js +8 -0
  9. package/dist/aria-hidden-CEXexb2I.js +127 -0
  10. package/dist/aria-hidden-Y7iJHPMr.cjs +132 -0
  11. package/dist/aria-hidden.cjs +3 -0
  12. package/dist/aria-hidden.d.cts +10 -0
  13. package/dist/aria-hidden.d.ts +10 -0
  14. package/dist/aria-hidden.js +2 -0
  15. package/dist/array-BGtygd0o.cjs +198 -0
  16. package/dist/array-C4KbHsha.js +73 -0
  17. package/dist/auto-resize-5F5iiKZb.cjs +106 -0
  18. package/dist/auto-resize-KkNfCcBt.js +95 -0
  19. package/dist/auto-resize.cjs +4 -0
  20. package/dist/auto-resize.d.cts +7 -0
  21. package/dist/auto-resize.d.ts +7 -0
  22. package/dist/auto-resize.js +2 -0
  23. package/dist/caret-CHqaP4XG.cjs +30 -0
  24. package/dist/caret-aiDJ6mAS.js +19 -0
  25. package/dist/closest-Clo6ODcK.js +117 -0
  26. package/dist/closest-IiRz1GIJ.cjs +176 -0
  27. package/dist/collection-CJU0oDtX.js +1295 -0
  28. package/dist/collection-CwzUJwBJ.cjs +1342 -0
  29. package/dist/collection.cjs +15 -0
  30. package/dist/collection.d.cts +34 -0
  31. package/dist/collection.d.ts +34 -0
  32. package/dist/collection.js +3 -0
  33. package/dist/color-CsugZjq6.d.cts +60 -0
  34. package/dist/color-CsugZjq6.d.ts +60 -0
  35. package/dist/color-utils-DzeOVYlL.cjs +662 -0
  36. package/dist/color-utils-lDDg9FEh.js +639 -0
  37. package/dist/color-utils.cjs +6 -0
  38. package/dist/color-utils.d.cts +18 -0
  39. package/dist/color-utils.d.ts +18 -0
  40. package/dist/color-utils.js +2 -0
  41. package/dist/computed-style-B1MKlCoo.js +9 -0
  42. package/dist/computed-style-DLArEFNw.cjs +14 -0
  43. package/dist/controller-B8E8ZJCI.cjs +133 -0
  44. package/dist/controller-Dv7lWHDr.js +92 -0
  45. package/dist/core-BF6G2RiC.d.cts +1 -0
  46. package/dist/core-BNMw-JId.cjs +372 -0
  47. package/dist/core-BdeZuSX6.d.ts +1 -0
  48. package/dist/core-CJ0MZr3D.js +289 -0
  49. package/dist/core.cjs +19 -0
  50. package/dist/core.d.cts +3 -0
  51. package/dist/core.d.ts +3 -0
  52. package/dist/core.js +3 -0
  53. package/dist/create-anatomy-B2q3wiaw.js +22 -0
  54. package/dist/create-anatomy-BwDn25ph.cjs +27 -0
  55. package/dist/create-props-CgtcN_Qu.js +4 -0
  56. package/dist/create-props-CjLx2oS8.cjs +9 -0
  57. package/dist/data-url-C-Uk31Q9.cjs +42 -0
  58. package/dist/data-url-DHUHj7UF.js +37 -0
  59. package/dist/data-url-Gx_SWG-k.d.cts +10 -0
  60. package/dist/data-url-Gx_SWG-k.d.ts +10 -0
  61. package/dist/date-utils-D-JJHedx.cjs +868 -0
  62. package/dist/date-utils-D5zXW-Cs.js +569 -0
  63. package/dist/date-utils.cjs +52 -0
  64. package/dist/date-utils.d.cts +7 -0
  65. package/dist/date-utils.d.ts +7 -0
  66. package/dist/date-utils.js +2 -0
  67. package/dist/dismissable-C0bixtzl.cjs +348 -0
  68. package/dist/dismissable-KM1jPtNQ.js +337 -0
  69. package/dist/dismissable-layer-BTX5EvXw.d.ts +40 -0
  70. package/dist/dismissable-layer-Ch5niVaq.d.cts +40 -0
  71. package/dist/dismissable.cjs +4 -0
  72. package/dist/dismissable.d.cts +3 -0
  73. package/dist/dismissable.d.ts +3 -0
  74. package/dist/dismissable.js +2 -0
  75. package/dist/dom-query-CQzY93XU.cjs +488 -0
  76. package/dist/dom-query-e7fh0TEH.js +243 -0
  77. package/dist/dom-query.cjs +180 -0
  78. package/dist/dom-query.d.cts +142 -0
  79. package/dist/dom-query.d.ts +142 -0
  80. package/dist/dom-query.js +43 -0
  81. package/dist/equal-C927y7MN.cjs +30 -0
  82. package/dist/equal-DtrP8DPh.js +25 -0
  83. package/dist/event-DDz-mMhM.cjs +242 -0
  84. package/dist/event-bTItRgiw.js +117 -0
  85. package/dist/file-utils-6EXCdfHx.js +116 -0
  86. package/dist/file-utils-B7OJigQq.cjs +151 -0
  87. package/dist/file-utils.cjs +92 -0
  88. package/dist/file-utils.d.cts +40 -0
  89. package/dist/file-utils.d.ts +40 -0
  90. package/dist/file-utils.js +82 -0
  91. package/dist/focus-trap-89E5I9nm.js +487 -0
  92. package/dist/focus-trap-D7jKsfHW.cjs +498 -0
  93. package/dist/focus-trap.cjs +4 -0
  94. package/dist/focus-trap.d.cts +89 -0
  95. package/dist/focus-trap.d.ts +89 -0
  96. package/dist/focus-trap.js +2 -0
  97. package/dist/focus-visible-DWdQf__4.js +176 -0
  98. package/dist/focus-visible-G4cmlWqq.cjs +217 -0
  99. package/dist/focus-visible.cjs +9 -0
  100. package/dist/focus-visible.d.cts +32 -0
  101. package/dist/focus-visible.d.ts +32 -0
  102. package/dist/focus-visible.js +2 -0
  103. package/dist/form-B1DW_w_3.js +89 -0
  104. package/dist/form-CoupKpuP.cjs +130 -0
  105. package/dist/from-window-5ZhzSURC.js +68 -0
  106. package/dist/from-window-B9DKtaoR.cjs +115 -0
  107. package/dist/functions-isw5Ovcx.d.cts +16 -0
  108. package/dist/functions-isw5Ovcx.d.ts +16 -0
  109. package/dist/highlight-word.cjs +95 -0
  110. package/dist/highlight-word.d.cts +24 -0
  111. package/dist/highlight-word.d.ts +24 -0
  112. package/dist/highlight-word.js +94 -0
  113. package/dist/hotkeys.cjs +1183 -0
  114. package/dist/hotkeys.d.cts +199 -0
  115. package/dist/hotkeys.d.ts +199 -0
  116. package/dist/hotkeys.js +1173 -0
  117. package/dist/i18n-utils-BD4VtonY.cjs +345 -0
  118. package/dist/i18n-utils-C4FQZ39m.js +280 -0
  119. package/dist/i18n-utils.cjs +216 -0
  120. package/dist/i18n-utils.d.cts +71 -0
  121. package/dist/i18n-utils.d.ts +71 -0
  122. package/dist/i18n-utils.js +204 -0
  123. package/dist/index-3tNJficI.d.cts +117 -0
  124. package/dist/index-3tNJficI.d.ts +117 -0
  125. package/dist/index-BEfvdGE2.d.cts +116 -0
  126. package/dist/index-BEfvdGE2.d.ts +116 -0
  127. package/dist/index-BF6G2RiC.d.cts +1 -0
  128. package/dist/index-BKgxIVbE.d.cts +285 -0
  129. package/dist/index-BMtpmaRD.d.cts +16 -0
  130. package/dist/index-BMtpmaRD.d.ts +16 -0
  131. package/dist/index-BWiYePx8.d.cts +216 -0
  132. package/dist/index-BXfunVyD.d.cts +1342 -0
  133. package/dist/index-BXfunVyD.d.ts +1342 -0
  134. package/dist/index-BdeZuSX6.d.ts +1 -0
  135. package/dist/index-C2865AJq.d.cts +25 -0
  136. package/dist/index-C2865AJq.d.ts +25 -0
  137. package/dist/index-CFoN0L3C.d.ts +285 -0
  138. package/dist/index-vPrqYDHu.d.ts +216 -0
  139. package/dist/index.cjs +19 -0
  140. package/dist/index.d.cts +3 -0
  141. package/dist/index.d.ts +3 -0
  142. package/dist/index.js +3 -0
  143. package/dist/initial-focus-BQxRRFPa.cjs +37 -0
  144. package/dist/initial-focus-BrN5tT2X.js +26 -0
  145. package/dist/interact-outside-BjqIunFx.js +211 -0
  146. package/dist/interact-outside-Dphjr2Zh.cjs +216 -0
  147. package/dist/interact-outside.cjs +3 -0
  148. package/dist/interact-outside.d.cts +2 -0
  149. package/dist/interact-outside.d.ts +2 -0
  150. package/dist/interact-outside.js +2 -0
  151. package/dist/json-tree-utils.cjs +1518 -0
  152. package/dist/json-tree-utils.d.cts +117 -0
  153. package/dist/json-tree-utils.d.ts +117 -0
  154. package/dist/json-tree-utils.js +1469 -0
  155. package/dist/list-collection-D_eNKrot.d.cts +60 -0
  156. package/dist/list-collection-RqYEWHb4.d.ts +60 -0
  157. package/dist/live-region-BD0OgmrH.cjs +68 -0
  158. package/dist/live-region-F8YMmbrY.js +63 -0
  159. package/dist/live-region.cjs +3 -0
  160. package/dist/live-region.d.cts +2 -0
  161. package/dist/live-region.d.ts +2 -0
  162. package/dist/live-region.js +2 -0
  163. package/dist/machines/accordion/index.cjs +328 -0
  164. package/dist/machines/accordion/index.d.cts +83 -0
  165. package/dist/machines/accordion/index.d.ts +83 -0
  166. package/dist/machines/accordion/index.js +321 -0
  167. package/dist/machines/angle-slider/index.cjs +420 -0
  168. package/dist/machines/angle-slider/index.d.cts +84 -0
  169. package/dist/machines/angle-slider/index.d.ts +84 -0
  170. package/dist/machines/angle-slider/index.js +415 -0
  171. package/dist/machines/async-list/index.cjs +310 -0
  172. package/dist/machines/async-list/index.d.cts +90 -0
  173. package/dist/machines/async-list/index.d.ts +90 -0
  174. package/dist/machines/async-list/index.js +308 -0
  175. package/dist/machines/avatar/index.cjs +165 -0
  176. package/dist/machines/avatar/index.d.cts +63 -0
  177. package/dist/machines/avatar/index.d.ts +63 -0
  178. package/dist/machines/avatar/index.js +160 -0
  179. package/dist/machines/carousel/index.cjs +929 -0
  180. package/dist/machines/carousel/index.d.cts +146 -0
  181. package/dist/machines/carousel/index.d.ts +146 -0
  182. package/dist/machines/carousel/index.js +920 -0
  183. package/dist/machines/cascade-select/index.cjs +1426 -0
  184. package/dist/machines/cascade-select/index.d.cts +167 -0
  185. package/dist/machines/cascade-select/index.d.ts +167 -0
  186. package/dist/machines/cascade-select/index.js +1419 -0
  187. package/dist/machines/checkbox/index.cjs +316 -0
  188. package/dist/machines/checkbox/index.d.cts +81 -0
  189. package/dist/machines/checkbox/index.d.ts +81 -0
  190. package/dist/machines/checkbox/index.js +311 -0
  191. package/dist/machines/clipboard/index.cjs +228 -0
  192. package/dist/machines/clipboard/index.d.cts +72 -0
  193. package/dist/machines/clipboard/index.d.ts +72 -0
  194. package/dist/machines/clipboard/index.js +221 -0
  195. package/dist/machines/collapsible/index.cjs +363 -0
  196. package/dist/machines/collapsible/index.d.cts +82 -0
  197. package/dist/machines/collapsible/index.d.ts +82 -0
  198. package/dist/machines/collapsible/index.js +358 -0
  199. package/dist/machines/color-picker/index.cjs +1534 -0
  200. package/dist/machines/color-picker/index.d.cts +207 -0
  201. package/dist/machines/color-picker/index.d.ts +207 -0
  202. package/dist/machines/color-picker/index.js +1518 -0
  203. package/dist/machines/combobox/index.cjs +1554 -0
  204. package/dist/machines/combobox/index.d.cts +219 -0
  205. package/dist/machines/combobox/index.d.ts +219 -0
  206. package/dist/machines/combobox/index.js +1542 -0
  207. package/dist/machines/date-input/index.cjs +1974 -0
  208. package/dist/machines/date-input/index.d.cts +230 -0
  209. package/dist/machines/date-input/index.d.ts +230 -0
  210. package/dist/machines/date-input/index.js +1958 -0
  211. package/dist/machines/date-picker/index.cjs +2424 -0
  212. package/dist/machines/date-picker/index.d.cts +378 -0
  213. package/dist/machines/date-picker/index.d.ts +378 -0
  214. package/dist/machines/date-picker/index.js +2408 -0
  215. package/dist/machines/dialog/index.cjs +378 -0
  216. package/dist/machines/dialog/index.d.cts +94 -0
  217. package/dist/machines/dialog/index.d.ts +94 -0
  218. package/dist/machines/dialog/index.js +373 -0
  219. package/dist/machines/drawer/index.cjs +2066 -0
  220. package/dist/machines/drawer/index.d.cts +334 -0
  221. package/dist/machines/drawer/index.d.ts +334 -0
  222. package/dist/machines/drawer/index.js +2059 -0
  223. package/dist/machines/editable/index.cjs +550 -0
  224. package/dist/machines/editable/index.d.cts +114 -0
  225. package/dist/machines/editable/index.d.ts +114 -0
  226. package/dist/machines/editable/index.js +545 -0
  227. package/dist/machines/file-upload/index.cjs +648 -0
  228. package/dist/machines/file-upload/index.d.cts +150 -0
  229. package/dist/machines/file-upload/index.d.ts +150 -0
  230. package/dist/machines/file-upload/index.js +641 -0
  231. package/dist/machines/floating-panel/index.cjs +1020 -0
  232. package/dist/machines/floating-panel/index.d.cts +149 -0
  233. package/dist/machines/floating-panel/index.d.ts +149 -0
  234. package/dist/machines/floating-panel/index.js +1012 -0
  235. package/dist/machines/hover-card/index.cjs +441 -0
  236. package/dist/machines/hover-card/index.d.cts +82 -0
  237. package/dist/machines/hover-card/index.d.ts +82 -0
  238. package/dist/machines/hover-card/index.js +436 -0
  239. package/dist/machines/image-cropper/index.cjs +2082 -0
  240. package/dist/machines/image-cropper/index.d.cts +182 -0
  241. package/dist/machines/image-cropper/index.d.ts +182 -0
  242. package/dist/machines/image-cropper/index.js +2076 -0
  243. package/dist/machines/listbox/index.cjs +873 -0
  244. package/dist/machines/listbox/index.d.cts +175 -0
  245. package/dist/machines/listbox/index.d.ts +175 -0
  246. package/dist/machines/listbox/index.js +860 -0
  247. package/dist/machines/marquee/index.cjs +387 -0
  248. package/dist/machines/marquee/index.d.cts +102 -0
  249. package/dist/machines/marquee/index.d.ts +102 -0
  250. package/dist/machines/marquee/index.js +382 -0
  251. package/dist/machines/menu/index.cjs +1562 -0
  252. package/dist/machines/menu/index.d.cts +188 -0
  253. package/dist/machines/menu/index.d.ts +188 -0
  254. package/dist/machines/menu/index.js +1549 -0
  255. package/dist/machines/navigation-menu/index.cjs +860 -0
  256. package/dist/machines/navigation-menu/index.d.cts +131 -0
  257. package/dist/machines/navigation-menu/index.d.ts +131 -0
  258. package/dist/machines/navigation-menu/index.js +855 -0
  259. package/dist/machines/number-input/index.cjs +1014 -0
  260. package/dist/machines/number-input/index.d.cts +136 -0
  261. package/dist/machines/number-input/index.d.ts +136 -0
  262. package/dist/machines/number-input/index.js +1009 -0
  263. package/dist/machines/pagination/index.cjs +413 -0
  264. package/dist/machines/pagination/index.d.cts +139 -0
  265. package/dist/machines/pagination/index.d.ts +139 -0
  266. package/dist/machines/pagination/index.js +404 -0
  267. package/dist/machines/password-input/index.cjs +224 -0
  268. package/dist/machines/password-input/index.d.cts +71 -0
  269. package/dist/machines/password-input/index.d.ts +71 -0
  270. package/dist/machines/password-input/index.js +219 -0
  271. package/dist/machines/pin-input/index.cjs +595 -0
  272. package/dist/machines/pin-input/index.d.cts +107 -0
  273. package/dist/machines/pin-input/index.d.ts +107 -0
  274. package/dist/machines/pin-input/index.js +590 -0
  275. package/dist/machines/popover/index.cjs +516 -0
  276. package/dist/machines/popover/index.d.cts +107 -0
  277. package/dist/machines/popover/index.d.ts +107 -0
  278. package/dist/machines/popover/index.js +511 -0
  279. package/dist/machines/presence/index.cjs +193 -0
  280. package/dist/machines/presence/index.d.cts +44 -0
  281. package/dist/machines/presence/index.d.ts +44 -0
  282. package/dist/machines/presence/index.js +190 -0
  283. package/dist/machines/progress/index.cjs +282 -0
  284. package/dist/machines/progress/index.d.cts +96 -0
  285. package/dist/machines/progress/index.d.ts +96 -0
  286. package/dist/machines/progress/index.js +277 -0
  287. package/dist/machines/qr-code/index.cjs +167 -0
  288. package/dist/machines/qr-code/index.d.cts +71 -0
  289. package/dist/machines/qr-code/index.d.ts +71 -0
  290. package/dist/machines/qr-code/index.js +162 -0
  291. package/dist/machines/radio-group/index.cjs +465 -0
  292. package/dist/machines/radio-group/index.d.cts +218 -0
  293. package/dist/machines/radio-group/index.d.ts +218 -0
  294. package/dist/machines/radio-group/index.js +458 -0
  295. package/dist/machines/rating-group/index.cjs +405 -0
  296. package/dist/machines/rating-group/index.d.cts +101 -0
  297. package/dist/machines/rating-group/index.d.ts +101 -0
  298. package/dist/machines/rating-group/index.js +398 -0
  299. package/dist/machines/scroll-area/index.cjs +865 -0
  300. package/dist/machines/scroll-area/index.d.cts +126 -0
  301. package/dist/machines/scroll-area/index.d.ts +126 -0
  302. package/dist/machines/scroll-area/index.js +860 -0
  303. package/dist/machines/select/index.cjs +1226 -0
  304. package/dist/machines/select/index.d.cts +190 -0
  305. package/dist/machines/select/index.d.ts +190 -0
  306. package/dist/machines/select/index.js +1214 -0
  307. package/dist/machines/signature-pad/index.cjs +337 -0
  308. package/dist/machines/signature-pad/index.d.cts +108 -0
  309. package/dist/machines/signature-pad/index.d.ts +108 -0
  310. package/dist/machines/signature-pad/index.js +330 -0
  311. package/dist/machines/slider/index.cjs +1103 -0
  312. package/dist/machines/slider/index.d.cts +154 -0
  313. package/dist/machines/slider/index.d.ts +154 -0
  314. package/dist/machines/slider/index.js +1094 -0
  315. package/dist/machines/splitter/index.cjs +1686 -0
  316. package/dist/machines/splitter/index.d.cts +282 -0
  317. package/dist/machines/splitter/index.d.ts +282 -0
  318. package/dist/machines/splitter/index.js +1675 -0
  319. package/dist/machines/steps/index.cjs +330 -0
  320. package/dist/machines/steps/index.d.cts +109 -0
  321. package/dist/machines/steps/index.d.ts +109 -0
  322. package/dist/machines/steps/index.js +325 -0
  323. package/dist/machines/switch/index.cjs +307 -0
  324. package/dist/machines/switch/index.d.cts +80 -0
  325. package/dist/machines/switch/index.d.ts +80 -0
  326. package/dist/machines/switch/index.js +302 -0
  327. package/dist/machines/tabs/index.cjs +542 -0
  328. package/dist/machines/tabs/index.d.cts +113 -0
  329. package/dist/machines/tabs/index.d.ts +113 -0
  330. package/dist/machines/tabs/index.js +533 -0
  331. package/dist/machines/tags-input/index.cjs +1151 -0
  332. package/dist/machines/tags-input/index.d.cts +182 -0
  333. package/dist/machines/tags-input/index.d.ts +182 -0
  334. package/dist/machines/tags-input/index.js +1144 -0
  335. package/dist/machines/timer/index.cjs +329 -0
  336. package/dist/machines/timer/index.d.cts +102 -0
  337. package/dist/machines/timer/index.d.ts +102 -0
  338. package/dist/machines/timer/index.js +323 -0
  339. package/dist/machines/toast/index.cjs +1185 -0
  340. package/dist/machines/toast/index.d.cts +204 -0
  341. package/dist/machines/toast/index.d.ts +204 -0
  342. package/dist/machines/toast/index.js +1180 -0
  343. package/dist/machines/toc/index.cjs +358 -0
  344. package/dist/machines/toc/index.d.cts +98 -0
  345. package/dist/machines/toc/index.d.ts +98 -0
  346. package/dist/machines/toc/index.js +351 -0
  347. package/dist/machines/toggle/index.cjs +99 -0
  348. package/dist/machines/toggle/index.d.cts +46 -0
  349. package/dist/machines/toggle/index.d.ts +46 -0
  350. package/dist/machines/toggle/index.js +94 -0
  351. package/dist/machines/toggle-group/index.cjs +329 -0
  352. package/dist/machines/toggle-group/index.d.cts +81 -0
  353. package/dist/machines/toggle-group/index.d.ts +81 -0
  354. package/dist/machines/toggle-group/index.js +322 -0
  355. package/dist/machines/tooltip/index.cjs +638 -0
  356. package/dist/machines/tooltip/index.d.cts +84 -0
  357. package/dist/machines/tooltip/index.d.ts +84 -0
  358. package/dist/machines/tooltip/index.js +633 -0
  359. package/dist/machines/tour/index.cjs +1123 -0
  360. package/dist/machines/tour/index.d.cts +207 -0
  361. package/dist/machines/tour/index.d.ts +207 -0
  362. package/dist/machines/tour/index.js +1115 -0
  363. package/dist/machines/tree-view/index.cjs +1288 -0
  364. package/dist/machines/tree-view/index.d.cts +221 -0
  365. package/dist/machines/tree-view/index.d.ts +221 -0
  366. package/dist/machines/tree-view/index.js +1279 -0
  367. package/dist/mutation-observer-_LbwtN3W.cjs +61 -0
  368. package/dist/mutation-observer-qObPUo3D.js +50 -0
  369. package/dist/navigate-CJOaL3vx.js +31 -0
  370. package/dist/navigate-uJG-006f.cjs +42 -0
  371. package/dist/overflow-BBihfMxX.cjs +67 -0
  372. package/dist/overflow-C-zO1CWA.js +44 -0
  373. package/dist/platform-BDB0wXUk.js +26 -0
  374. package/dist/platform-BZS-dkZN.cjs +109 -0
  375. package/dist/point-C9A4dk1i.js +27 -0
  376. package/dist/point-DxnCrJBy.cjs +32 -0
  377. package/dist/pointer-lock-BvfSjt_s.cjs +31 -0
  378. package/dist/pointer-lock-WezxTqu-.js +26 -0
  379. package/dist/pointer-move-CGzan38r.cjs +42 -0
  380. package/dist/pointer-move-Tijb8Ptk.js +37 -0
  381. package/dist/polygon-BvdwYRBw.js +76 -0
  382. package/dist/polygon-CTR1kEoU.cjs +93 -0
  383. package/dist/popper-DkAAS9VE.cjs +487 -0
  384. package/dist/popper-DzBZzAe4.js +464 -0
  385. package/dist/popper.cjs +6 -0
  386. package/dist/popper.d.cts +2 -0
  387. package/dist/popper.d.ts +2 -0
  388. package/dist/popper.js +2 -0
  389. package/dist/press-B7XLrLGR.js +65 -0
  390. package/dist/press-BdD5suLQ.cjs +70 -0
  391. package/dist/proxy-tab-focus-DWMXvAfO.js +54 -0
  392. package/dist/proxy-tab-focus-NthYgHdY.cjs +59 -0
  393. package/dist/raf-BSDcY4UD.cjs +85 -0
  394. package/dist/raf-DgINgykK.d.cts +15 -0
  395. package/dist/raf-DgINgykK.d.ts +15 -0
  396. package/dist/raf-Dhvm7f1e.js +62 -0
  397. package/dist/rect-utils-DiT4k3jS.cjs +548 -0
  398. package/dist/rect-utils-d_3gZVsc.js +459 -0
  399. package/dist/rect-utils.cjs +165 -0
  400. package/dist/rect-utils.d.cts +197 -0
  401. package/dist/rect-utils.d.ts +197 -0
  402. package/dist/rect-utils.js +116 -0
  403. package/dist/remove-scroll-DTVA5f4w.cjs +86 -0
  404. package/dist/remove-scroll-WEheFCiq.js +81 -0
  405. package/dist/remove-scroll.cjs +3 -0
  406. package/dist/remove-scroll.d.cts +4 -0
  407. package/dist/remove-scroll.d.ts +4 -0
  408. package/dist/remove-scroll.js +2 -0
  409. package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
  410. package/dist/scale-C5BBHVgH.js +17 -0
  411. package/dist/scale-C7iiUGhS.cjs +22 -0
  412. package/dist/scope-CysKlKe9.cjs +28 -0
  413. package/dist/scope-D1873Mzi.js +23 -0
  414. package/dist/scroll-CVJ40w2e.js +46 -0
  415. package/dist/scroll-Dyd1QLrc.cjs +63 -0
  416. package/dist/scroll-snap-Cuaqdevf.cjs +224 -0
  417. package/dist/scroll-snap-DqMiFASa.js +201 -0
  418. package/dist/scroll-snap.cjs +6 -0
  419. package/dist/scroll-snap.d.cts +14 -0
  420. package/dist/scroll-snap.d.ts +14 -0
  421. package/dist/scroll-snap.js +2 -0
  422. package/dist/selection-ClKhnWit.d.cts +49 -0
  423. package/dist/selection-DzLiSVkg.d.ts +49 -0
  424. package/dist/selection-map-962WvX2k.js +45 -0
  425. package/dist/selection-map-BwlZr1LH.cjs +68 -0
  426. package/dist/set-CFNGOW5W.js +50 -0
  427. package/dist/set-DrtWCLFb.cjs +73 -0
  428. package/dist/store-BLpJlMxz.js +257 -0
  429. package/dist/store-Btfrm2bs.cjs +47 -0
  430. package/dist/store-C5HvdLyc.js +42 -0
  431. package/dist/store-Wg8KVwNv.cjs +298 -0
  432. package/dist/store.cjs +9 -0
  433. package/dist/store.d.cts +26 -0
  434. package/dist/store.d.ts +26 -0
  435. package/dist/store.js +2 -0
  436. package/dist/stringify-state.cjs +48 -0
  437. package/dist/stringify-state.d.cts +8 -0
  438. package/dist/stringify-state.d.ts +8 -0
  439. package/dist/stringify-state.js +44 -0
  440. package/dist/tabbable-Bz1-1GAY.cjs +206 -0
  441. package/dist/tabbable-CDA1YMjZ.js +147 -0
  442. package/dist/text-selection-B3OQpQGy.cjs +75 -0
  443. package/dist/text-selection-DXvWvm6k.js +64 -0
  444. package/dist/timers-BRyPrXIX.js +82 -0
  445. package/dist/timers-Beu4SfAj.cjs +99 -0
  446. package/dist/tree-collection-3QX3EIhq.d.ts +77 -0
  447. package/dist/tree-collection-C6oDQGUJ.d.cts +77 -0
  448. package/dist/typeahead-DremEgML.d.cts +45 -0
  449. package/dist/typeahead-DremEgML.d.ts +45 -0
  450. package/dist/types-BFuHIo7S.js +10 -0
  451. package/dist/types-CczqoQLL.d.cts +57 -0
  452. package/dist/types-CczqoQLL.d.ts +57 -0
  453. package/dist/types-CjocssbC.d.cts +13 -0
  454. package/dist/types-CjocssbC.d.ts +13 -0
  455. package/dist/types-D7oF7eWh.d.cts +54 -0
  456. package/dist/types-D7oF7eWh.d.ts +54 -0
  457. package/dist/types-HCvp3Bhv.cjs +21 -0
  458. package/dist/types.cjs +14 -0
  459. package/dist/types.d.cts +6 -0
  460. package/dist/types.d.ts +6 -0
  461. package/dist/types.js +12 -0
  462. package/dist/utils-BH-oBBz2.cjs +614 -0
  463. package/dist/utils-Cht5XaHf.js +267 -0
  464. package/dist/utils.cjs +95 -0
  465. package/dist/utils.d.cts +144 -0
  466. package/dist/utils.d.ts +144 -0
  467. package/dist/utils.js +7 -0
  468. package/dist/visually-hidden-BgSCFLz_.cjs +29 -0
  469. package/dist/visually-hidden-yDJ517KZ.js +18 -0
  470. package/dist/wait-for-3n85JcCU.d.cts +15 -0
  471. package/dist/wait-for-3n85JcCU.d.ts +15 -0
  472. package/dist/wait-for-CI5Ye-Lo.js +69 -0
  473. package/dist/wait-for-Db73VpZQ.cjs +86 -0
  474. package/dist/warning-CrzBpWT1.js +19 -0
  475. package/dist/warning-HAmFXLHm.cjs +42 -0
  476. package/package.json +349 -6
@@ -0,0 +1,2076 @@
1
+ import { t as createAnatomy } from "../../create-anatomy-B2q3wiaw.js";
2
+ import { p as contains, r as resizeObserverBorderBox, z as dataAttr } from "../../dom-query-e7fh0TEH.js";
3
+ import { i as getEventPoint, r as getEventKey, s as getEventTarget, t as addDomEvent } from "../../event-bTItRgiw.js";
4
+ import { F as toPx, L as callAll, X as isBoolean, l as clampValue, n as createSplitProps } from "../../utils-Cht5XaHf.js";
5
+ import { r as createMachine } from "../../core-CJ0MZr3D.js";
6
+ import { t as createProps } from "../../create-props-CgtcN_Qu.js";
7
+ //#region src/machines/image-cropper/anatomy.ts
8
+ const anatomy = createAnatomy("image-cropper").parts("root", "viewport", "image", "selection", "handle", "grid");
9
+ const parts = anatomy.build();
10
+ //#endregion
11
+ //#region src/machines/image-cropper/utils.ts
12
+ const { min, max, abs, round, hypot, PI, cos, sin } = Math;
13
+ const ASPECT_RATIO_TOLERANCE = .001;
14
+ const isAspectRatioEqual = (a, b) => {
15
+ return abs(a - b) < ASPECT_RATIO_TOLERANCE;
16
+ };
17
+ const isLeftHandle = (v) => v === "w" || v === "nw" || v === "sw";
18
+ const isRightHandle = (v) => v === "e" || v === "ne" || v === "se";
19
+ const isTopHandle = (v) => v === "n" || v === "nw" || v === "ne";
20
+ const isBottomHandle = (v) => v === "s" || v === "sw" || v === "se";
21
+ const isCornerHandle = (v) => (isLeftHandle(v) || isRightHandle(v)) && (isTopHandle(v) || isBottomHandle(v));
22
+ const isHorizontalEdgeHandle = (v) => (isLeftHandle(v) || isRightHandle(v)) && !(isTopHandle(v) || isBottomHandle(v));
23
+ const isVerticalEdgeHandle = (v) => (isTopHandle(v) || isBottomHandle(v)) && !(isLeftHandle(v) || isRightHandle(v));
24
+ const hasAspectRatio = (value) => typeof value === "number" && value > 0;
25
+ const resolveSizeLimits = (options) => {
26
+ const { minSize, maxSize, viewportSize, aspectRatio } = options;
27
+ let minWidth = min(minSize.width, viewportSize.width);
28
+ let minHeight = min(minSize.height, viewportSize.height);
29
+ let maxWidth = maxSize?.width ?? viewportSize.width;
30
+ if (!Number.isFinite(maxWidth)) maxWidth = viewportSize.width;
31
+ maxWidth = min(maxWidth, viewportSize.width);
32
+ let maxHeight = maxSize?.height ?? viewportSize.height;
33
+ if (!Number.isFinite(maxHeight)) maxHeight = viewportSize.height;
34
+ maxHeight = min(maxHeight, viewportSize.height);
35
+ maxWidth = max(minWidth, maxWidth);
36
+ maxHeight = max(minHeight, maxHeight);
37
+ const hasAspect = hasAspectRatio(aspectRatio);
38
+ if (hasAspect) {
39
+ const minWidthWithAspect = max(minWidth, minHeight * aspectRatio);
40
+ const minHeightWithAspect = minWidthWithAspect / aspectRatio;
41
+ minWidth = min(minWidthWithAspect, viewportSize.width);
42
+ minHeight = min(minHeightWithAspect, viewportSize.height);
43
+ let constrainedMaxWidth = min(maxWidth, maxHeight * aspectRatio, viewportSize.width);
44
+ let constrainedMaxHeight = constrainedMaxWidth / aspectRatio;
45
+ if (constrainedMaxHeight > maxHeight || constrainedMaxHeight > viewportSize.height) {
46
+ constrainedMaxHeight = min(maxHeight, viewportSize.height);
47
+ constrainedMaxWidth = constrainedMaxHeight * aspectRatio;
48
+ }
49
+ maxWidth = max(minWidth, min(constrainedMaxWidth, viewportSize.width));
50
+ maxHeight = max(minHeight, min(constrainedMaxHeight, viewportSize.height));
51
+ } else {
52
+ maxWidth = max(minWidth, min(maxWidth, viewportSize.width));
53
+ maxHeight = max(minHeight, min(maxHeight, viewportSize.height));
54
+ }
55
+ return {
56
+ minWidth,
57
+ minHeight,
58
+ maxWidth,
59
+ maxHeight,
60
+ hasAspect
61
+ };
62
+ };
63
+ const clampAspectSize = (params) => {
64
+ const { widthValue, heightValue, limits, viewportRect, aspectRatio } = params;
65
+ const { minWidth, minHeight, maxWidth, maxHeight } = limits;
66
+ const constrainWidthFromHeight = (height) => {
67
+ let width = clampValue(height * aspectRatio, minWidth, maxWidth);
68
+ width = min(width, viewportRect.width);
69
+ return {
70
+ width,
71
+ height: width / aspectRatio
72
+ };
73
+ };
74
+ const clampByWidth = (value) => {
75
+ let width = clampValue(value, minWidth, maxWidth);
76
+ width = min(width, viewportRect.width);
77
+ let height = width / aspectRatio;
78
+ if (height < minHeight) {
79
+ const constrained = constrainWidthFromHeight(minHeight);
80
+ width = constrained.width;
81
+ height = constrained.height;
82
+ }
83
+ if (height > maxHeight) {
84
+ const clampedHeight = min(maxHeight, viewportRect.height);
85
+ const constrained = constrainWidthFromHeight(clampedHeight);
86
+ width = constrained.width;
87
+ height = constrained.height;
88
+ }
89
+ if (height > viewportRect.height) {
90
+ const constrained = constrainWidthFromHeight(viewportRect.height);
91
+ width = constrained.width;
92
+ height = constrained.height;
93
+ if (height < minHeight) {
94
+ const reconstrainted = constrainWidthFromHeight(minHeight);
95
+ width = reconstrainted.width;
96
+ height = reconstrainted.height;
97
+ }
98
+ }
99
+ return {
100
+ width,
101
+ height
102
+ };
103
+ };
104
+ const clampByHeight = (value) => {
105
+ let height = clampValue(value, minHeight, maxHeight);
106
+ height = min(height, viewportRect.height);
107
+ let width = height * aspectRatio;
108
+ width = clampValue(width, minWidth, maxWidth);
109
+ width = min(width, viewportRect.width);
110
+ let adjustedHeight = width / aspectRatio;
111
+ if (adjustedHeight < minHeight) {
112
+ const constrained = constrainWidthFromHeight(minHeight);
113
+ width = constrained.width;
114
+ adjustedHeight = constrained.height;
115
+ }
116
+ if (adjustedHeight > maxHeight) {
117
+ const clampedHeight = min(maxHeight, viewportRect.height);
118
+ const constrained = constrainWidthFromHeight(clampedHeight);
119
+ width = constrained.width;
120
+ adjustedHeight = constrained.height;
121
+ }
122
+ if (width > viewportRect.width) {
123
+ width = viewportRect.width;
124
+ adjustedHeight = width / aspectRatio;
125
+ if (adjustedHeight > maxHeight) {
126
+ const clampedHeight = min(maxHeight, viewportRect.height);
127
+ const constrained = constrainWidthFromHeight(clampedHeight);
128
+ width = constrained.width;
129
+ adjustedHeight = constrained.height;
130
+ }
131
+ if (adjustedHeight < minHeight) {
132
+ const constrained = constrainWidthFromHeight(minHeight);
133
+ width = constrained.width;
134
+ adjustedHeight = constrained.height;
135
+ }
136
+ }
137
+ return {
138
+ width,
139
+ height: adjustedHeight
140
+ };
141
+ };
142
+ const byWidth = clampByWidth(widthValue);
143
+ const byHeight = clampByHeight(heightValue);
144
+ const deltaWidth = abs(byWidth.width - widthValue) + abs(byWidth.height - heightValue);
145
+ return abs(byHeight.width - widthValue) + abs(byHeight.height - heightValue) < deltaWidth ? byHeight : byWidth;
146
+ };
147
+ const applyDeltaToEdges = (params) => {
148
+ const { bounds, delta, handlePosition, viewportRect, minSize, maxSize } = params;
149
+ let { left, top, right, bottom } = bounds;
150
+ if (isLeftHandle(handlePosition)) {
151
+ const minLeft = max(0, right - maxSize.width);
152
+ const maxLeft = right - minSize.width;
153
+ left = clampValue(left + delta.x, minLeft, maxLeft);
154
+ }
155
+ if (isRightHandle(handlePosition)) {
156
+ const minRight = left + minSize.width;
157
+ const maxRight = min(viewportRect.width, left + maxSize.width);
158
+ right = clampValue(right + delta.x, minRight, maxRight);
159
+ }
160
+ if (isTopHandle(handlePosition)) {
161
+ const minTop = max(0, bottom - maxSize.height);
162
+ const maxTop = bottom - minSize.height;
163
+ top = clampValue(top + delta.y, minTop, maxTop);
164
+ }
165
+ if (isBottomHandle(handlePosition)) {
166
+ const minBottom = top + minSize.height;
167
+ const maxBottom = min(viewportRect.height, top + maxSize.height);
168
+ bottom = clampValue(bottom + delta.y, minBottom, maxBottom);
169
+ }
170
+ return {
171
+ left,
172
+ top,
173
+ right,
174
+ bottom
175
+ };
176
+ };
177
+ const applyAspectToHorizontalResize = (params) => {
178
+ const { bounds, limits, viewportRect, aspectRatio, handlePosition } = params;
179
+ const { left, top, right, bottom } = bounds;
180
+ const centerY = (top + bottom) / 2;
181
+ let nextWidth = right - left;
182
+ let nextHeight = nextWidth / aspectRatio;
183
+ const constrained = clampAspectSize({
184
+ widthValue: nextWidth,
185
+ heightValue: nextHeight,
186
+ limits,
187
+ viewportRect,
188
+ aspectRatio
189
+ });
190
+ nextWidth = constrained.width;
191
+ nextHeight = constrained.height;
192
+ const halfH = nextHeight / 2;
193
+ let newTop = centerY - halfH;
194
+ let newBottom = centerY + halfH;
195
+ if (newTop < 0) {
196
+ newTop = 0;
197
+ newBottom = nextHeight;
198
+ }
199
+ if (newBottom > viewportRect.height) {
200
+ newBottom = viewportRect.height;
201
+ newTop = newBottom - nextHeight;
202
+ }
203
+ return {
204
+ left: isRightHandle(handlePosition) ? left : right - nextWidth,
205
+ top: newTop,
206
+ right: isRightHandle(handlePosition) ? left + nextWidth : right,
207
+ bottom: newBottom
208
+ };
209
+ };
210
+ const applyAspectToVerticalResize = (params) => {
211
+ const { bounds, limits, viewportRect, aspectRatio, handlePosition } = params;
212
+ const { left, top, right, bottom } = bounds;
213
+ const centerX = (left + right) / 2;
214
+ let nextHeight = bottom - top;
215
+ let nextWidth = nextHeight * aspectRatio;
216
+ const constrained = clampAspectSize({
217
+ widthValue: nextWidth,
218
+ heightValue: nextHeight,
219
+ limits,
220
+ viewportRect,
221
+ aspectRatio
222
+ });
223
+ nextWidth = constrained.width;
224
+ nextHeight = constrained.height;
225
+ const halfW = nextWidth / 2;
226
+ let newLeft = centerX - halfW;
227
+ let newRight = centerX + halfW;
228
+ if (newLeft < 0) {
229
+ newLeft = 0;
230
+ newRight = nextWidth;
231
+ }
232
+ if (newRight > viewportRect.width) {
233
+ newRight = viewportRect.width;
234
+ newLeft = newRight - nextWidth;
235
+ }
236
+ return {
237
+ left: newLeft,
238
+ top: isBottomHandle(handlePosition) ? top : bottom - nextHeight,
239
+ right: newRight,
240
+ bottom: isBottomHandle(handlePosition) ? top + nextHeight : bottom
241
+ };
242
+ };
243
+ const applyCornerResize = (params) => {
244
+ const { bounds, width, height, handlePosition } = params;
245
+ const { left, top, right, bottom } = bounds;
246
+ if (isRightHandle(handlePosition) && isBottomHandle(handlePosition)) return {
247
+ left,
248
+ top,
249
+ right: left + width,
250
+ bottom: top + height
251
+ };
252
+ else if (isRightHandle(handlePosition) && isTopHandle(handlePosition)) return {
253
+ left,
254
+ top: bottom - height,
255
+ right: left + width,
256
+ bottom
257
+ };
258
+ else if (isBottomHandle(handlePosition)) return {
259
+ left: right - width,
260
+ top,
261
+ right,
262
+ bottom: top + height
263
+ };
264
+ else return {
265
+ left: right - width,
266
+ top: bottom - height,
267
+ right,
268
+ bottom
269
+ };
270
+ };
271
+ function computeResizeCrop(options) {
272
+ const { cropStart, handlePosition, delta, viewportRect, minSize, maxSize, aspectRatio } = options;
273
+ let { x, y, width, height } = cropStart;
274
+ let left = x;
275
+ let top = y;
276
+ let right = x + width;
277
+ let bottom = y + height;
278
+ const { minWidth, minHeight, maxWidth, maxHeight, hasAspect } = resolveSizeLimits({
279
+ minSize,
280
+ maxSize,
281
+ viewportSize: viewportRect,
282
+ aspectRatio
283
+ });
284
+ const edgesAfterDelta = applyDeltaToEdges({
285
+ bounds: {
286
+ left,
287
+ top,
288
+ right,
289
+ bottom
290
+ },
291
+ delta,
292
+ handlePosition,
293
+ viewportRect,
294
+ minSize,
295
+ maxSize
296
+ });
297
+ left = edgesAfterDelta.left;
298
+ top = edgesAfterDelta.top;
299
+ right = edgesAfterDelta.right;
300
+ bottom = edgesAfterDelta.bottom;
301
+ if (hasAspect) {
302
+ const limits = {
303
+ minWidth,
304
+ minHeight,
305
+ maxWidth,
306
+ maxHeight,
307
+ hasAspect
308
+ };
309
+ if (isCornerHandle(handlePosition)) {
310
+ let tempW = right - left;
311
+ let tempH = tempW / aspectRatio;
312
+ if (tempH > bottom - top || top + tempH > viewportRect.height || left + tempW > viewportRect.width) {
313
+ tempH = bottom - top;
314
+ tempW = tempH * aspectRatio;
315
+ }
316
+ const constrained = clampAspectSize({
317
+ widthValue: tempW,
318
+ heightValue: tempH,
319
+ limits,
320
+ viewportRect,
321
+ aspectRatio
322
+ });
323
+ const result = applyCornerResize({
324
+ bounds: {
325
+ left,
326
+ top,
327
+ right,
328
+ bottom
329
+ },
330
+ width: constrained.width,
331
+ height: constrained.height,
332
+ handlePosition
333
+ });
334
+ left = result.left;
335
+ top = result.top;
336
+ right = result.right;
337
+ bottom = result.bottom;
338
+ } else if (isHorizontalEdgeHandle(handlePosition)) {
339
+ const result = applyAspectToHorizontalResize({
340
+ bounds: {
341
+ left,
342
+ top,
343
+ right,
344
+ bottom
345
+ },
346
+ limits,
347
+ viewportRect,
348
+ aspectRatio,
349
+ handlePosition
350
+ });
351
+ left = result.left;
352
+ top = result.top;
353
+ right = result.right;
354
+ bottom = result.bottom;
355
+ } else if (isVerticalEdgeHandle(handlePosition)) {
356
+ const result = applyAspectToVerticalResize({
357
+ bounds: {
358
+ left,
359
+ top,
360
+ right,
361
+ bottom
362
+ },
363
+ limits,
364
+ viewportRect,
365
+ aspectRatio,
366
+ handlePosition
367
+ });
368
+ left = result.left;
369
+ top = result.top;
370
+ right = result.right;
371
+ bottom = result.bottom;
372
+ }
373
+ }
374
+ const maxLeft = max(0, viewportRect.width - minWidth);
375
+ const maxTop = max(0, viewportRect.height - minHeight);
376
+ left = clampValue(left, 0, maxLeft);
377
+ top = clampValue(top, 0, maxTop);
378
+ const maxRight = min(viewportRect.width, left + maxWidth);
379
+ const maxBottom = min(viewportRect.height, top + maxHeight);
380
+ right = clampValue(right, left + minWidth, maxRight);
381
+ bottom = clampValue(bottom, top + minHeight, maxBottom);
382
+ return {
383
+ x: left,
384
+ y: top,
385
+ width: right - left,
386
+ height: bottom - top
387
+ };
388
+ }
389
+ function getCropSourceRect(params) {
390
+ const { crop, zoom, offset, viewportSize, naturalSize } = params;
391
+ const scaleX = viewportSize.width > 0 ? naturalSize.width / viewportSize.width : 1;
392
+ const scaleY = viewportSize.height > 0 ? naturalSize.height / viewportSize.height : 1;
393
+ const safeZoom = zoom > 0 ? zoom : 1;
394
+ const viewportCenterX = viewportSize.width / 2;
395
+ const viewportCenterY = viewportSize.height / 2;
396
+ const imageCenterX = naturalSize.width / 2;
397
+ const imageCenterY = naturalSize.height / 2;
398
+ const cropCenterX = crop.x + crop.width / 2;
399
+ const cropCenterY = crop.y + crop.height / 2;
400
+ const sourceCenterX = imageCenterX + (cropCenterX - viewportCenterX - offset.x) / safeZoom * scaleX;
401
+ const sourceCenterY = imageCenterY + (cropCenterY - viewportCenterY - offset.y) / safeZoom * scaleY;
402
+ const sourceWidth = crop.width / safeZoom * scaleX;
403
+ const sourceHeight = crop.height / safeZoom * scaleY;
404
+ return {
405
+ x: sourceCenterX - sourceWidth / 2,
406
+ y: sourceCenterY - sourceHeight / 2,
407
+ width: sourceWidth,
408
+ height: sourceHeight
409
+ };
410
+ }
411
+ function computeMoveCrop(cropStart, delta, viewportRect) {
412
+ return {
413
+ x: clampValue(cropStart.x + delta.x, 0, viewportRect.width - cropStart.width),
414
+ y: clampValue(cropStart.y + delta.y, 0, viewportRect.height - cropStart.height),
415
+ width: cropStart.width,
416
+ height: cropStart.height
417
+ };
418
+ }
419
+ function clampOffset(params) {
420
+ const { zoom, rotation, viewportSize, offset, fixedCropArea, crop } = params;
421
+ const { cos, sin } = getRotationTransform(rotation);
422
+ if (fixedCropArea && crop) {
423
+ const aabb = computeAABB(viewportSize, zoom, cos, sin);
424
+ const center = getViewportCenter(viewportSize);
425
+ const cropRight = crop.x + crop.width;
426
+ const cropBottom = crop.y + crop.height;
427
+ const minPoint = {
428
+ x: cropRight - center.x - aabb.width / 2,
429
+ y: cropBottom - center.y - aabb.height / 2
430
+ };
431
+ const maxPoint = {
432
+ x: crop.x - center.x + aabb.width / 2,
433
+ y: crop.y - center.y + aabb.height / 2
434
+ };
435
+ return clampPoint(offset, minPoint, maxPoint);
436
+ }
437
+ const aabb = computeAABB(viewportSize, zoom, cos, sin);
438
+ const extraWidth = max(0, aabb.width - viewportSize.width);
439
+ const extraHeight = max(0, aabb.height - viewportSize.height);
440
+ const minPoint = {
441
+ x: -extraWidth / 2,
442
+ y: -extraHeight / 2
443
+ };
444
+ const maxPoint = {
445
+ x: extraWidth / 2,
446
+ y: extraHeight / 2
447
+ };
448
+ return clampPoint(offset, minPoint, maxPoint);
449
+ }
450
+ const expandLeft = (crop, step, maxWidth) => {
451
+ const newX = max(0, crop.x - step);
452
+ const newWidth = crop.width + (crop.x - newX);
453
+ if (newWidth <= maxWidth) return {
454
+ x: newX,
455
+ width: newWidth
456
+ };
457
+ return {
458
+ x: crop.x + crop.width - maxWidth,
459
+ width: maxWidth
460
+ };
461
+ };
462
+ const expandTop = (crop, step, maxHeight) => {
463
+ const newY = max(0, crop.y - step);
464
+ const newHeight = crop.height + (crop.y - newY);
465
+ if (newHeight <= maxHeight) return {
466
+ y: newY,
467
+ height: newHeight
468
+ };
469
+ return {
470
+ y: crop.y + crop.height - maxHeight,
471
+ height: maxHeight
472
+ };
473
+ };
474
+ const shrinkFromLeft = (crop, step, minWidth) => {
475
+ const newX = min(crop.x + step, crop.x + crop.width - minWidth);
476
+ return {
477
+ x: newX,
478
+ width: crop.width - (newX - crop.x)
479
+ };
480
+ };
481
+ const shrinkFromTop = (crop, step, minHeight) => {
482
+ const newY = min(crop.y + step, crop.y + crop.height - minHeight);
483
+ return {
484
+ y: newY,
485
+ height: crop.height - (newY - crop.y)
486
+ };
487
+ };
488
+ function computeKeyboardCrop(key, handlePosition, step, crop, viewportRect, minSize, maxSize) {
489
+ const nextCrop = { ...crop };
490
+ const { minWidth, minHeight, maxWidth, maxHeight } = resolveSizeLimits({
491
+ minSize,
492
+ maxSize,
493
+ viewportSize: viewportRect
494
+ });
495
+ const isCorner = isCornerHandle(handlePosition);
496
+ if (key === "ArrowLeft") {
497
+ if (isLeftHandle(handlePosition)) {
498
+ const expanded = expandLeft(crop, step, maxWidth);
499
+ nextCrop.x = expanded.x;
500
+ nextCrop.width = expanded.width;
501
+ if (isCorner && isTopHandle(handlePosition)) {
502
+ const expandedY = expandTop(crop, step, maxHeight);
503
+ nextCrop.y = expandedY.y;
504
+ nextCrop.height = expandedY.height;
505
+ } else if (isCorner && isBottomHandle(handlePosition)) {
506
+ const newHeight = nextCrop.height + step;
507
+ nextCrop.height = min(viewportRect.height - nextCrop.y, min(maxHeight, newHeight));
508
+ }
509
+ } else if (isRightHandle(handlePosition)) {
510
+ nextCrop.width = max(minWidth, nextCrop.width - step);
511
+ if (isCorner && isTopHandle(handlePosition)) {
512
+ const shrunk = shrinkFromTop(crop, step, minHeight);
513
+ nextCrop.y = shrunk.y;
514
+ nextCrop.height = shrunk.height;
515
+ } else if (isCorner && isBottomHandle(handlePosition)) nextCrop.height = max(minHeight, nextCrop.height - step);
516
+ }
517
+ } else if (key === "ArrowRight") {
518
+ if (isLeftHandle(handlePosition)) {
519
+ const shrunk = shrinkFromLeft(crop, step, minWidth);
520
+ nextCrop.x = shrunk.x;
521
+ nextCrop.width = shrunk.width;
522
+ if (isCorner && isTopHandle(handlePosition)) {
523
+ const shrunkY = shrinkFromTop(crop, step, minHeight);
524
+ nextCrop.y = shrunkY.y;
525
+ nextCrop.height = shrunkY.height;
526
+ } else if (isCorner && isBottomHandle(handlePosition)) nextCrop.height = max(minHeight, nextCrop.height - step);
527
+ } else if (isRightHandle(handlePosition)) {
528
+ const newWidth = nextCrop.width + step;
529
+ nextCrop.width = min(viewportRect.width - nextCrop.x, min(maxWidth, newWidth));
530
+ if (isCorner && isTopHandle(handlePosition)) {
531
+ const expanded = expandTop(crop, step, maxHeight);
532
+ nextCrop.y = expanded.y;
533
+ nextCrop.height = expanded.height;
534
+ } else if (isCorner && isBottomHandle(handlePosition)) {
535
+ const newHeight = nextCrop.height + step;
536
+ nextCrop.height = min(viewportRect.height - nextCrop.y, min(maxHeight, newHeight));
537
+ }
538
+ }
539
+ }
540
+ if (key === "ArrowUp") {
541
+ if (isTopHandle(handlePosition)) {
542
+ const expanded = expandTop(crop, step, maxHeight);
543
+ nextCrop.y = expanded.y;
544
+ nextCrop.height = expanded.height;
545
+ if (isCorner && isLeftHandle(handlePosition)) {
546
+ const expandedX = expandLeft(crop, step, maxWidth);
547
+ nextCrop.x = expandedX.x;
548
+ nextCrop.width = expandedX.width;
549
+ } else if (isCorner && isRightHandle(handlePosition)) {
550
+ const newWidth = nextCrop.width + step;
551
+ nextCrop.width = min(viewportRect.width - nextCrop.x, min(maxWidth, newWidth));
552
+ }
553
+ } else if (isBottomHandle(handlePosition)) {
554
+ nextCrop.height = max(minHeight, nextCrop.height - step);
555
+ if (isCorner && isLeftHandle(handlePosition)) {
556
+ const shrunk = shrinkFromLeft(crop, step, minWidth);
557
+ nextCrop.x = shrunk.x;
558
+ nextCrop.width = shrunk.width;
559
+ } else if (isCorner && isRightHandle(handlePosition)) nextCrop.width = max(minWidth, nextCrop.width - step);
560
+ }
561
+ } else if (key === "ArrowDown") {
562
+ if (isTopHandle(handlePosition)) {
563
+ const shrunk = shrinkFromTop(crop, step, minHeight);
564
+ nextCrop.y = shrunk.y;
565
+ nextCrop.height = shrunk.height;
566
+ if (isCorner && isLeftHandle(handlePosition)) {
567
+ const shrunkX = shrinkFromLeft(crop, step, minWidth);
568
+ nextCrop.x = shrunkX.x;
569
+ nextCrop.width = shrunkX.width;
570
+ } else if (isCorner && isRightHandle(handlePosition)) nextCrop.width = max(minWidth, nextCrop.width - step);
571
+ } else if (isBottomHandle(handlePosition)) {
572
+ const newHeight = nextCrop.height + step;
573
+ nextCrop.height = min(viewportRect.height - nextCrop.y, min(maxHeight, newHeight));
574
+ if (isCorner && isLeftHandle(handlePosition)) {
575
+ const expanded = expandLeft(crop, step, maxWidth);
576
+ nextCrop.x = expanded.x;
577
+ nextCrop.width = expanded.width;
578
+ } else if (isCorner && isRightHandle(handlePosition)) {
579
+ const newWidth = nextCrop.width + step;
580
+ nextCrop.width = min(viewportRect.width - nextCrop.x, min(maxWidth, newWidth));
581
+ }
582
+ }
583
+ }
584
+ return nextCrop;
585
+ }
586
+ function getKeyboardMoveDelta(key, step) {
587
+ switch (key) {
588
+ case "ArrowLeft": return {
589
+ x: -step,
590
+ y: 0
591
+ };
592
+ case "ArrowRight": return {
593
+ x: step,
594
+ y: 0
595
+ };
596
+ case "ArrowUp": return {
597
+ x: 0,
598
+ y: -step
599
+ };
600
+ case "ArrowDown": return {
601
+ x: 0,
602
+ y: step
603
+ };
604
+ default: return ZERO_POINT;
605
+ }
606
+ }
607
+ const resolveCropAspectRatio = (shape, aspectRatio) => shape === "circle" ? 1 : aspectRatio;
608
+ const getCropSizeLimits = (prop) => ({
609
+ minSize: {
610
+ width: prop("minWidth"),
611
+ height: prop("minHeight")
612
+ },
613
+ maxSize: {
614
+ width: prop("maxWidth"),
615
+ height: prop("maxHeight")
616
+ }
617
+ });
618
+ const getNudgeStep = (prop, modifiers) => {
619
+ if (modifiers.ctrlKey || modifiers.metaKey) return prop("nudgeStepCtrl");
620
+ if (modifiers.shiftKey) return prop("nudgeStepShift");
621
+ return prop("nudgeStep");
622
+ };
623
+ const DEFAULT_VIEWPORT_FILL = .8;
624
+ const computeDefaultCropDimensions = (viewportRect, aspectRatio, fixedCropArea) => {
625
+ const targetWidth = viewportRect.width * DEFAULT_VIEWPORT_FILL;
626
+ const targetHeight = viewportRect.height * DEFAULT_VIEWPORT_FILL;
627
+ if (typeof aspectRatio === "number" && aspectRatio > 0) {
628
+ if (fixedCropArea) {
629
+ let height = viewportRect.height;
630
+ let width = height * aspectRatio;
631
+ if (width > viewportRect.width) {
632
+ width = viewportRect.width;
633
+ height = width / aspectRatio;
634
+ }
635
+ return {
636
+ width,
637
+ height
638
+ };
639
+ }
640
+ if (aspectRatio > targetWidth / targetHeight) {
641
+ const width = targetWidth;
642
+ return {
643
+ width,
644
+ height: width / aspectRatio
645
+ };
646
+ }
647
+ const height = targetHeight;
648
+ return {
649
+ width: height * aspectRatio,
650
+ height
651
+ };
652
+ }
653
+ if (fixedCropArea) {
654
+ const size = min(viewportRect.width, viewportRect.height);
655
+ return {
656
+ width: size,
657
+ height: size
658
+ };
659
+ }
660
+ return {
661
+ width: targetWidth,
662
+ height: targetHeight
663
+ };
664
+ };
665
+ const normalizeFlipState = (nextFlip, currentFlip) => {
666
+ if (!nextFlip) return currentFlip;
667
+ return {
668
+ horizontal: isBoolean(nextFlip.horizontal) ? nextFlip.horizontal : currentFlip.horizontal,
669
+ vertical: isBoolean(nextFlip.vertical) ? nextFlip.vertical : currentFlip.vertical
670
+ };
671
+ };
672
+ const isEqualFlip = (a, b) => {
673
+ return a.horizontal === b.horizontal && a.vertical === b.vertical;
674
+ };
675
+ const isVisibleRect = (rect) => rect.width > 0 && rect.height > 0;
676
+ const getCenterPoint = (rect) => ({
677
+ x: rect.x + rect.width / 2,
678
+ y: rect.y + rect.height / 2
679
+ });
680
+ const getViewportCenter = (size) => ({
681
+ x: size.width / 2,
682
+ y: size.height / 2
683
+ });
684
+ const centerRect = (size, viewport) => ({
685
+ x: max(0, (viewport.width - size.width) / 2),
686
+ y: max(0, (viewport.height - size.height) / 2)
687
+ });
688
+ const getMidpoint = (p1, p2, offset = ZERO_POINT) => ({
689
+ x: (p1.x + p2.x) / 2 - offset.x,
690
+ y: (p1.y + p2.y) / 2 - offset.y
691
+ });
692
+ const getMaxBounds = (cropSize, viewportSize) => ({
693
+ x: max(0, viewportSize.width - cropSize.width),
694
+ y: max(0, viewportSize.height - cropSize.height)
695
+ });
696
+ const centerCropOnPoint = (cropSize, center, viewportSize) => {
697
+ const newPos = {
698
+ x: center.x - cropSize.width / 2,
699
+ y: center.y - cropSize.height / 2
700
+ };
701
+ const maxBounds = getMaxBounds(cropSize, viewportSize);
702
+ return clampPoint(newPos, ZERO_POINT, maxBounds);
703
+ };
704
+ const isSameSize = (a, b) => {
705
+ return a.width === b.width && a.height === b.height;
706
+ };
707
+ const ZERO_POINT = {
708
+ x: 0,
709
+ y: 0
710
+ };
711
+ const getTouchDistance = (p1, p2) => {
712
+ const dx = p1.x - p2.x;
713
+ const dy = p1.y - p2.y;
714
+ return hypot(dx, dy);
715
+ };
716
+ const clampPoint = (point, min, max) => ({
717
+ x: clampValue(point.x, min.x, max.x),
718
+ y: clampValue(point.y, min.y, max.y)
719
+ });
720
+ const subtractPoints = (a, b) => ({
721
+ x: a.x - b.x,
722
+ y: a.y - b.y
723
+ });
724
+ const addPoints = (a, b) => ({
725
+ x: a.x + b.x,
726
+ y: a.y + b.y
727
+ });
728
+ const roundRect = (rect) => ({
729
+ x: round(rect.x),
730
+ y: round(rect.y),
731
+ width: round(rect.width),
732
+ height: round(rect.height)
733
+ });
734
+ const scaleRect = (rect, scale) => ({
735
+ x: rect.x * scale.x,
736
+ y: rect.y * scale.y,
737
+ width: rect.width * scale.x,
738
+ height: rect.height * scale.y
739
+ });
740
+ const getRotationTransform = (rotation) => {
741
+ const theta = rotation % 360 * PI / 180;
742
+ return {
743
+ cos: abs(cos(theta)),
744
+ sin: abs(sin(theta))
745
+ };
746
+ };
747
+ const computeAABB = (size, zoom, cos, sin) => {
748
+ const w = size.width * zoom;
749
+ const h = size.height * zoom;
750
+ return {
751
+ width: w * cos + h * sin,
752
+ height: w * sin + h * cos
753
+ };
754
+ };
755
+ const scaleSize = (size, scale) => ({
756
+ width: size.width * scale,
757
+ height: size.height * scale
758
+ });
759
+ //#endregion
760
+ //#region src/machines/image-cropper/dom.ts
761
+ const getRootId = (ctx) => ctx.ids?.root ?? `image-cropper:${ctx.id}`;
762
+ const getViewportId = (ctx) => ctx.ids?.viewport ?? `image-cropper:${ctx.id}:viewport`;
763
+ const getImageId = (ctx) => ctx.ids?.image ?? `image-cropper:${ctx.id}:image`;
764
+ const getSelectionId = (ctx) => ctx.ids?.selection ?? `image-cropper:${ctx.id}:selection`;
765
+ const getHandleId = (ctx, position) => ctx.ids?.handle?.(position) ?? `image-cropper:${ctx.id}:handle:${position}`;
766
+ const getRootEl = (ctx) => ctx.getById(getRootId(ctx));
767
+ const getViewportEl = (ctx) => ctx.getById(getViewportId(ctx));
768
+ const getImageEl = (ctx) => ctx.getById(getImageId(ctx));
769
+ const getSelectionEl = (ctx) => ctx.getById(getSelectionId(ctx));
770
+ function drawCroppedImageToCanvas(params) {
771
+ const { context, scope } = params;
772
+ const imageEl = getImageEl(scope);
773
+ if (!imageEl || !imageEl.complete) return null;
774
+ const doc = imageEl.ownerDocument;
775
+ const crop = context.get("crop");
776
+ const zoom = context.get("zoom");
777
+ const rotation = context.get("rotation");
778
+ const flip = context.get("flip");
779
+ const viewportRect = context.get("viewportRect");
780
+ const naturalSize = context.get("naturalSize");
781
+ const offset = context.get("offset");
782
+ const canvas = doc.createElement("canvas");
783
+ canvas.width = crop.width;
784
+ canvas.height = crop.height;
785
+ const ctx = canvas.getContext("2d");
786
+ if (!ctx) return null;
787
+ ctx.save();
788
+ ctx.translate(canvas.width / 2, canvas.height / 2);
789
+ ctx.rotate(rotation * Math.PI / 180);
790
+ const scaleX = flip.horizontal ? -1 : 1;
791
+ const scaleY = flip.vertical ? -1 : 1;
792
+ ctx.scale(scaleX, scaleY);
793
+ const sourceRect = getCropSourceRect({
794
+ crop,
795
+ zoom,
796
+ offset,
797
+ viewportSize: viewportRect,
798
+ naturalSize
799
+ });
800
+ ctx.drawImage(imageEl, sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height, -canvas.width / 2, -canvas.height / 2, canvas.width, canvas.height);
801
+ ctx.restore();
802
+ return canvas;
803
+ }
804
+ //#endregion
805
+ //#region src/machines/image-cropper/get-resize-axis-style.ts
806
+ function getHandlePositionStyles(handlePosition) {
807
+ switch (handlePosition) {
808
+ case "n": return {
809
+ position: "absolute",
810
+ cursor: "n-resize",
811
+ width: "96%",
812
+ top: 0,
813
+ left: "50%",
814
+ translate: "-50% -50%"
815
+ };
816
+ case "e": return {
817
+ position: "absolute",
818
+ cursor: "e-resize",
819
+ height: "96%",
820
+ right: 0,
821
+ top: "50%",
822
+ translate: "50% -50%"
823
+ };
824
+ case "s": return {
825
+ position: "absolute",
826
+ cursor: "s-resize",
827
+ width: "96%",
828
+ bottom: 0,
829
+ left: "50%",
830
+ translate: "-50% 50%"
831
+ };
832
+ case "w": return {
833
+ position: "absolute",
834
+ cursor: "w-resize",
835
+ height: "96%",
836
+ left: 0,
837
+ top: "50%",
838
+ translate: "-50% -50%"
839
+ };
840
+ case "se": return {
841
+ position: "absolute",
842
+ cursor: "se-resize",
843
+ bottom: 0,
844
+ right: 0,
845
+ translate: "50% 50%"
846
+ };
847
+ case "sw": return {
848
+ position: "absolute",
849
+ cursor: "sw-resize",
850
+ bottom: 0,
851
+ left: 0,
852
+ translate: "-50% 50%"
853
+ };
854
+ case "ne": return {
855
+ position: "absolute",
856
+ cursor: "ne-resize",
857
+ top: 0,
858
+ right: 0,
859
+ translate: "50% -50%"
860
+ };
861
+ case "nw": return {
862
+ position: "absolute",
863
+ cursor: "nw-resize",
864
+ top: 0,
865
+ left: 0,
866
+ translate: "-50% -50%"
867
+ };
868
+ default: throw new Error(`Invalid handlePosition: ${handlePosition}`);
869
+ }
870
+ }
871
+ //#endregion
872
+ //#region src/machines/image-cropper/connect.ts
873
+ function connect(service, normalize) {
874
+ const { scope, send, context, prop, state, computed } = service;
875
+ const dragging = state.matches("dragging");
876
+ const panning = state.matches("panning");
877
+ const translations = prop("translations");
878
+ const fixedCropArea = prop("fixedCropArea");
879
+ const cropShape = prop("cropShape");
880
+ const zoom = context.get("zoom");
881
+ const rotation = context.get("rotation");
882
+ const flip = context.get("flip");
883
+ const crop = context.get("crop");
884
+ const offset = context.get("offset");
885
+ const naturalSize = context.get("naturalSize");
886
+ const viewportRect = context.get("viewportRect");
887
+ const isImageReady = computed("isImageReady");
888
+ const isMeasured = computed("isMeasured");
889
+ const roundedCrop = roundRect(crop);
890
+ const shouldIgnoreTouchPointer = (event) => {
891
+ if (event.pointerType !== "touch") return false;
892
+ const isSecondaryTouch = event.isPrimary === false;
893
+ const pinchActive = context.get("pinchDistance") != null;
894
+ return isSecondaryTouch || pinchActive;
895
+ };
896
+ return {
897
+ zoom,
898
+ rotation,
899
+ flip,
900
+ crop,
901
+ offset,
902
+ naturalSize,
903
+ viewportRect,
904
+ dragging,
905
+ panning,
906
+ setZoom(value) {
907
+ send({
908
+ type: "SET_ZOOM",
909
+ zoom: value
910
+ });
911
+ },
912
+ zoomBy(delta) {
913
+ send({
914
+ type: "SET_ZOOM",
915
+ zoom: zoom + delta
916
+ });
917
+ },
918
+ setRotation(value) {
919
+ send({
920
+ type: "SET_ROTATION",
921
+ rotation: value
922
+ });
923
+ },
924
+ rotateBy(degrees) {
925
+ send({
926
+ type: "SET_ROTATION",
927
+ rotation: rotation + degrees
928
+ });
929
+ },
930
+ setFlip(nextFlip) {
931
+ if (!nextFlip) return;
932
+ const normalized = normalizeFlipState(nextFlip, flip);
933
+ if (isEqualFlip(normalized, flip)) return;
934
+ send({
935
+ type: "SET_FLIP",
936
+ flip: normalized
937
+ });
938
+ },
939
+ flipHorizontally(value) {
940
+ const nextValue = typeof value === "boolean" ? value : !flip.horizontal;
941
+ if (nextValue === flip.horizontal) return;
942
+ send({
943
+ type: "SET_FLIP",
944
+ flip: { horizontal: nextValue }
945
+ });
946
+ },
947
+ flipVertically(value) {
948
+ const nextValue = typeof value === "boolean" ? value : !flip.vertical;
949
+ if (nextValue === flip.vertical) return;
950
+ send({
951
+ type: "SET_FLIP",
952
+ flip: { vertical: nextValue }
953
+ });
954
+ },
955
+ resize(handlePosition, delta) {
956
+ if (!handlePosition) return;
957
+ if (fixedCropArea) return;
958
+ let deltaX = 0;
959
+ let deltaY = 0;
960
+ if (isLeftHandle(handlePosition)) deltaX = -delta;
961
+ else if (isRightHandle(handlePosition)) deltaX = delta;
962
+ if (isTopHandle(handlePosition)) deltaY = -delta;
963
+ else if (isBottomHandle(handlePosition)) deltaY = delta;
964
+ send({
965
+ type: "RESIZE_CROP",
966
+ handlePosition,
967
+ delta: {
968
+ x: deltaX,
969
+ y: deltaY
970
+ }
971
+ });
972
+ },
973
+ reset() {
974
+ send({ type: "RESET" });
975
+ },
976
+ getCropData() {
977
+ const sourceRect = getCropSourceRect({
978
+ crop,
979
+ zoom,
980
+ offset,
981
+ viewportSize: viewportRect,
982
+ naturalSize
983
+ });
984
+ return {
985
+ x: Math.round(sourceRect.x),
986
+ y: Math.round(sourceRect.y),
987
+ width: Math.round(sourceRect.width),
988
+ height: Math.round(sourceRect.height),
989
+ rotate: rotation,
990
+ flipX: flip.horizontal,
991
+ flipY: flip.vertical
992
+ };
993
+ },
994
+ async getCroppedImage(options = {}) {
995
+ const { type = "image/png", quality = 1, output = "blob" } = options;
996
+ if (!isVisibleRect(naturalSize)) return null;
997
+ const canvas = drawCroppedImageToCanvas(service);
998
+ if (!canvas) return null;
999
+ if (output === "dataUrl") return canvas.toDataURL(type, quality);
1000
+ return new Promise((resolve) => {
1001
+ canvas.toBlob((blob) => {
1002
+ resolve(blob);
1003
+ }, type, quality);
1004
+ });
1005
+ },
1006
+ getRootProps() {
1007
+ return normalize.element({
1008
+ ...parts.root.attrs,
1009
+ id: getRootId(scope),
1010
+ dir: prop("dir"),
1011
+ role: "group",
1012
+ "aria-roledescription": translations.rootRoleDescription,
1013
+ "aria-label": translations.rootLabel,
1014
+ "aria-description": isImageReady ? translations.previewDescription({
1015
+ crop: roundedCrop,
1016
+ zoom: Number.isFinite(zoom) ? zoom : null,
1017
+ rotation: Number.isFinite(rotation) ? rotation : null
1018
+ }) : translations.previewLoading,
1019
+ "aria-live": "polite",
1020
+ "aria-controls": `${getViewportId(scope)} ${getSelectionId(scope)}`,
1021
+ "aria-busy": isImageReady ? void 0 : "true",
1022
+ "data-fixed": dataAttr(fixedCropArea),
1023
+ "data-shape": cropShape,
1024
+ "data-pinch": dataAttr(context.get("pinchDistance") != null),
1025
+ "data-dragging": dataAttr(dragging),
1026
+ "data-panning": dataAttr(panning),
1027
+ style: {
1028
+ "--crop-width": toPx(crop.width),
1029
+ "--crop-height": toPx(crop.height),
1030
+ "--crop-x": toPx(crop.x),
1031
+ "--crop-y": toPx(crop.y),
1032
+ "--image-zoom": zoom,
1033
+ "--image-rotation": rotation,
1034
+ "--image-offset-x": toPx(offset.x),
1035
+ "--image-offset-y": toPx(offset.y)
1036
+ }
1037
+ });
1038
+ },
1039
+ getViewportProps() {
1040
+ const viewportId = getViewportId(scope);
1041
+ return normalize.element({
1042
+ ...parts.viewport.attrs,
1043
+ id: viewportId,
1044
+ role: "presentation",
1045
+ "data-ownedby": getRootId(scope),
1046
+ "data-disabled": dataAttr(!!fixedCropArea),
1047
+ style: {
1048
+ position: "relative",
1049
+ overflow: "hidden",
1050
+ touchAction: "none",
1051
+ userSelect: "none"
1052
+ },
1053
+ onPointerDown(event) {
1054
+ if (event.pointerType === "mouse" && event.button !== 0) return;
1055
+ if (shouldIgnoreTouchPointer(event)) return;
1056
+ const target = getEventTarget(event);
1057
+ const rootEl = getRootEl(scope);
1058
+ if (!target || !rootEl || !contains(rootEl, target)) return;
1059
+ const selectionEl = getSelectionEl(scope);
1060
+ if (!fixedCropArea && contains(selectionEl, target)) return;
1061
+ const handleEl = target.closest("[data-scope=\"image-cropper\"][data-part=\"handle\"]");
1062
+ if (handleEl && contains(rootEl, handleEl)) return;
1063
+ const point = getEventPoint(event);
1064
+ send({
1065
+ type: "PAN_POINTER_DOWN",
1066
+ point
1067
+ });
1068
+ }
1069
+ });
1070
+ },
1071
+ getImageProps() {
1072
+ const flipHorizontal = flip.horizontal;
1073
+ const flipVertical = flip.vertical;
1074
+ const translate = `translate(${toPx(offset.x)}, ${toPx(offset.y)})`;
1075
+ const rotate = `rotate(${rotation}deg)`;
1076
+ const scale = `scale(${zoom * (flipHorizontal ? -1 : 1)}, ${zoom * (flipVertical ? -1 : 1)})`;
1077
+ return normalize.element({
1078
+ ...parts.image.attrs,
1079
+ id: getImageId(scope),
1080
+ draggable: false,
1081
+ role: "presentation",
1082
+ alt: "",
1083
+ "aria-hidden": true,
1084
+ "data-ownedby": getViewportId(scope),
1085
+ "data-ready": dataAttr(isImageReady),
1086
+ "data-flip-horizontal": dataAttr(flipHorizontal),
1087
+ "data-flip-vertical": dataAttr(flipVertical),
1088
+ onLoad(event) {
1089
+ const imageEl = event.currentTarget;
1090
+ if (!imageEl?.complete) return;
1091
+ const { naturalWidth: width, naturalHeight: height } = imageEl;
1092
+ send({
1093
+ type: "SET_NATURAL_SIZE",
1094
+ src: "element",
1095
+ size: {
1096
+ width,
1097
+ height
1098
+ }
1099
+ });
1100
+ },
1101
+ style: {
1102
+ pointerEvents: "none",
1103
+ userSelect: "none",
1104
+ transform: `${translate} ${rotate} ${scale}`,
1105
+ willChange: "transform"
1106
+ }
1107
+ });
1108
+ },
1109
+ getSelectionProps() {
1110
+ const disabled = !!fixedCropArea;
1111
+ return normalize.element({
1112
+ ...parts.selection.attrs,
1113
+ id: getSelectionId(scope),
1114
+ tabIndex: disabled ? void 0 : 0,
1115
+ role: "slider",
1116
+ "aria-label": translations.selectionLabel({ shape: cropShape }),
1117
+ "aria-roledescription": translations.selectionRoleDescription,
1118
+ "aria-disabled": disabled ? "true" : void 0,
1119
+ "aria-valuemin": 0,
1120
+ "aria-valuemax": isVisibleRect(viewportRect) ? Math.max(0, Math.round(viewportRect.width - crop.width)) : Math.max(roundedCrop.x, 0),
1121
+ "aria-valuenow": roundedCrop.x,
1122
+ "aria-valuetext": translations.selectionValueText({
1123
+ shape: cropShape,
1124
+ ...roundedCrop
1125
+ }),
1126
+ "aria-description": translations.selectionInstructions,
1127
+ "data-disabled": dataAttr(disabled),
1128
+ "data-shape": cropShape,
1129
+ "data-measured": dataAttr(isMeasured),
1130
+ "data-dragging": dataAttr(dragging),
1131
+ "data-panning": dataAttr(panning),
1132
+ style: {
1133
+ position: "absolute",
1134
+ top: "var(--crop-y)",
1135
+ left: "var(--crop-x)",
1136
+ width: "var(--crop-width)",
1137
+ height: "var(--crop-height)",
1138
+ touchAction: "none",
1139
+ visibility: isMeasured ? void 0 : "hidden"
1140
+ },
1141
+ onPointerDown(event) {
1142
+ if (disabled) {
1143
+ event.preventDefault();
1144
+ return;
1145
+ }
1146
+ if (shouldIgnoreTouchPointer(event)) return;
1147
+ const point = getEventPoint(event);
1148
+ send({
1149
+ type: "POINTER_DOWN",
1150
+ point
1151
+ });
1152
+ },
1153
+ onKeyDown(event) {
1154
+ if (disabled) {
1155
+ event.preventDefault();
1156
+ return;
1157
+ }
1158
+ if (event.defaultPrevented) return;
1159
+ const src = "selection";
1160
+ const { shiftKey, ctrlKey, metaKey, altKey } = event;
1161
+ const key = getEventKey(event, { dir: prop("dir") });
1162
+ const isZoomInKey = key === "+" || key === "=";
1163
+ if (isZoomInKey || key === "-" || key === "_") {
1164
+ send({
1165
+ type: "ZOOM",
1166
+ trigger: "keyboard",
1167
+ delta: isZoomInKey ? -1 : 1
1168
+ });
1169
+ event.preventDefault();
1170
+ return;
1171
+ }
1172
+ if (altKey && (key === "ArrowUp" || key === "ArrowDown" || key === "ArrowLeft" || key === "ArrowRight")) {
1173
+ send({
1174
+ type: "NUDGE_RESIZE_CROP",
1175
+ handlePosition: key === "ArrowUp" || key === "ArrowDown" ? "s" : "e",
1176
+ key,
1177
+ src,
1178
+ shiftKey,
1179
+ ctrlKey,
1180
+ metaKey
1181
+ });
1182
+ event.preventDefault();
1183
+ return;
1184
+ }
1185
+ const exec = {
1186
+ ArrowUp() {
1187
+ send({
1188
+ type: "NUDGE_MOVE_CROP",
1189
+ key: "ArrowUp",
1190
+ src,
1191
+ shiftKey,
1192
+ ctrlKey,
1193
+ metaKey
1194
+ });
1195
+ },
1196
+ ArrowDown() {
1197
+ send({
1198
+ type: "NUDGE_MOVE_CROP",
1199
+ key: "ArrowDown",
1200
+ src,
1201
+ shiftKey,
1202
+ ctrlKey,
1203
+ metaKey
1204
+ });
1205
+ },
1206
+ ArrowLeft() {
1207
+ send({
1208
+ type: "NUDGE_MOVE_CROP",
1209
+ key: "ArrowLeft",
1210
+ src,
1211
+ shiftKey,
1212
+ ctrlKey,
1213
+ metaKey
1214
+ });
1215
+ },
1216
+ ArrowRight() {
1217
+ send({
1218
+ type: "NUDGE_MOVE_CROP",
1219
+ key: "ArrowRight",
1220
+ src,
1221
+ shiftKey,
1222
+ ctrlKey,
1223
+ metaKey
1224
+ });
1225
+ }
1226
+ }[key];
1227
+ if (exec) {
1228
+ exec(event);
1229
+ event.preventDefault();
1230
+ }
1231
+ }
1232
+ });
1233
+ },
1234
+ getHandleProps(props) {
1235
+ const handlePosition = props.position;
1236
+ const disabled = !!fixedCropArea;
1237
+ return normalize.element({
1238
+ ...parts.handle.attrs,
1239
+ id: getHandleId(scope, handlePosition),
1240
+ "data-position": handlePosition,
1241
+ "aria-hidden": "true",
1242
+ role: "presentation",
1243
+ "data-disabled": dataAttr(disabled),
1244
+ style: getHandlePositionStyles(handlePosition),
1245
+ onPointerDown(event) {
1246
+ if (disabled) {
1247
+ event.preventDefault();
1248
+ return;
1249
+ }
1250
+ if (shouldIgnoreTouchPointer(event)) return;
1251
+ const point = getEventPoint(event);
1252
+ send({
1253
+ type: "POINTER_DOWN",
1254
+ point,
1255
+ handlePosition
1256
+ });
1257
+ }
1258
+ });
1259
+ },
1260
+ getGridProps(props) {
1261
+ const axis = props.axis;
1262
+ const isMeasured = computed("isMeasured");
1263
+ return normalize.element({
1264
+ ...parts.grid.attrs,
1265
+ "aria-hidden": "true",
1266
+ "data-axis": axis,
1267
+ "data-dragging": dataAttr(dragging),
1268
+ "data-panning": dataAttr(panning),
1269
+ style: {
1270
+ position: "absolute",
1271
+ inset: axis === "horizontal" ? "33.33% 0" : "0 33.33%",
1272
+ pointerEvents: "none",
1273
+ visibility: isMeasured ? void 0 : "hidden"
1274
+ }
1275
+ });
1276
+ }
1277
+ };
1278
+ }
1279
+ //#endregion
1280
+ //#region src/machines/image-cropper/machine.ts
1281
+ const machine = createMachine({
1282
+ props({ props }) {
1283
+ return {
1284
+ minWidth: 40,
1285
+ minHeight: 40,
1286
+ maxWidth: Number.POSITIVE_INFINITY,
1287
+ maxHeight: Number.POSITIVE_INFINITY,
1288
+ defaultZoom: 1,
1289
+ zoomStep: .1,
1290
+ zoomSensitivity: 2,
1291
+ minZoom: 1,
1292
+ maxZoom: 5,
1293
+ defaultRotation: 0,
1294
+ defaultFlip: {
1295
+ horizontal: false,
1296
+ vertical: false
1297
+ },
1298
+ fixedCropArea: false,
1299
+ cropShape: "rectangle",
1300
+ nudgeStep: 1,
1301
+ nudgeStepShift: 10,
1302
+ nudgeStepCtrl: 50,
1303
+ ...props,
1304
+ translations: {
1305
+ rootLabel: "Image cropper",
1306
+ rootRoleDescription: "Image cropper",
1307
+ previewLoading: "Image cropper preview loading",
1308
+ previewDescription({ crop, zoom, rotation }) {
1309
+ return `Image cropper preview, ${zoom != null && Number.isFinite(zoom) ? `${zoom.toFixed(2)}x zoom` : "default zoom"}, ${rotation != null && Number.isFinite(rotation) ? `${Math.round(rotation)} degrees rotation` : "0 degrees rotation"}. Crop positioned at ${crop.x}px from the left and ${crop.y}px from the top with a size of ${crop.width}px by ${crop.height}px.`;
1310
+ },
1311
+ selectionLabel: ({ shape }) => `Crop selection area (${shape === "circle" ? "circle" : "rectangle"})`,
1312
+ selectionRoleDescription: "2d slider",
1313
+ selectionInstructions: "Use arrow keys to move the crop. Hold Alt with arrow keys to resize width or height. Press plus or minus to zoom.",
1314
+ selectionValueText({ shape, x, y, width, height }) {
1315
+ if (shape === "circle") return `Position X ${x}px, Y ${y}px. Diameter ${width}px.`;
1316
+ return `Position X ${x}px, Y ${y}px. Size ${width}px by ${height}px.`;
1317
+ },
1318
+ ...props.translations
1319
+ }
1320
+ };
1321
+ },
1322
+ context({ bindable, prop }) {
1323
+ return {
1324
+ naturalSize: bindable(() => ({ defaultValue: {
1325
+ width: 0,
1326
+ height: 0
1327
+ } })),
1328
+ crop: bindable(() => ({
1329
+ defaultValue: {
1330
+ x: 0,
1331
+ y: 0,
1332
+ width: 0,
1333
+ height: 0
1334
+ },
1335
+ onChange(crop) {
1336
+ prop("onCropChange")?.({ crop });
1337
+ }
1338
+ })),
1339
+ pointerStart: bindable(() => ({ defaultValue: null })),
1340
+ cropStart: bindable(() => ({ defaultValue: null })),
1341
+ handlePosition: bindable(() => ({ defaultValue: null })),
1342
+ shiftLockRatio: bindable(() => ({ defaultValue: null })),
1343
+ pinchDistance: bindable(() => ({ defaultValue: null })),
1344
+ pinchMidpoint: bindable(() => ({ defaultValue: null })),
1345
+ zoom: bindable(() => ({
1346
+ defaultValue: prop("zoom") ?? prop("defaultZoom"),
1347
+ onChange(zoom) {
1348
+ prop("onZoomChange")?.({ zoom });
1349
+ }
1350
+ })),
1351
+ rotation: bindable(() => ({
1352
+ defaultValue: prop("defaultRotation"),
1353
+ value: prop("rotation"),
1354
+ onChange(rotation) {
1355
+ prop("onRotationChange")?.({ rotation });
1356
+ }
1357
+ })),
1358
+ flip: bindable(() => {
1359
+ return {
1360
+ defaultValue: { ...prop("defaultFlip") },
1361
+ value: prop("flip"),
1362
+ onChange(flip) {
1363
+ prop("onFlipChange")?.({ flip });
1364
+ }
1365
+ };
1366
+ }),
1367
+ offset: bindable(() => ({ defaultValue: ZERO_POINT })),
1368
+ offsetStart: bindable(() => ({ defaultValue: null })),
1369
+ viewportRect: bindable(() => ({ defaultValue: {
1370
+ width: 0,
1371
+ height: 0,
1372
+ top: 0,
1373
+ left: 0,
1374
+ right: 0,
1375
+ bottom: 0
1376
+ } }))
1377
+ };
1378
+ },
1379
+ initialState() {
1380
+ return "idle";
1381
+ },
1382
+ on: {
1383
+ PINCH_START: { actions: ["setPinchDistance"] },
1384
+ PINCH_MOVE: { actions: ["handlePinchMove"] },
1385
+ PINCH_END: { actions: ["clearPinchDistance"] },
1386
+ SET_ZOOM: { actions: ["updateZoom"] },
1387
+ SET_ROTATION: { actions: ["setRotation"] },
1388
+ SET_FLIP: { actions: ["setFlip"] },
1389
+ RESIZE_CROP: {
1390
+ guard: "canResizeCrop",
1391
+ actions: ["resizeCrop"]
1392
+ },
1393
+ VIEWPORT_RESIZE: { actions: ["resizeViewport"] },
1394
+ RESET: { actions: ["resetToInitialState"] },
1395
+ ADJUST_ASPECT_RATIO: {
1396
+ guard: "hasViewportRect",
1397
+ actions: ["adjustCropAspectRatio"]
1398
+ }
1399
+ },
1400
+ computed: {
1401
+ isMeasured: ({ context }) => isVisibleRect(context.get("viewportRect")) && isVisibleRect(context.get("crop")),
1402
+ isImageReady: ({ context }) => isVisibleRect(context.get("naturalSize"))
1403
+ },
1404
+ watch({ track, context, prop, send }) {
1405
+ track([() => prop("zoom")], () => {
1406
+ const propZoom = prop("zoom");
1407
+ if (propZoom === void 0) return;
1408
+ if (propZoom === context.get("zoom")) return;
1409
+ send({
1410
+ type: "SET_ZOOM",
1411
+ zoom: propZoom,
1412
+ src: "prop"
1413
+ });
1414
+ });
1415
+ track([() => prop("aspectRatio"), () => prop("cropShape")], () => {
1416
+ send({
1417
+ type: "ADJUST_ASPECT_RATIO",
1418
+ src: "prop"
1419
+ });
1420
+ });
1421
+ },
1422
+ states: {
1423
+ idle: {
1424
+ entry: ["checkImageStatus"],
1425
+ effects: [
1426
+ "trackViewportResize",
1427
+ "trackWheelEvent",
1428
+ "trackTouchEvents"
1429
+ ],
1430
+ on: {
1431
+ SET_NATURAL_SIZE: { actions: ["setNaturalSize"] },
1432
+ SET_DEFAULT_CROP: { actions: ["setDefaultCrop"] },
1433
+ POINTER_DOWN: {
1434
+ guard: "canDragSelection",
1435
+ target: "dragging",
1436
+ actions: [
1437
+ "setPointerStart",
1438
+ "setCropStart",
1439
+ "setHandlePosition"
1440
+ ]
1441
+ },
1442
+ PAN_POINTER_DOWN: {
1443
+ guard: "canPan",
1444
+ target: "panning",
1445
+ actions: ["setPointerStart", "setOffsetStart"]
1446
+ },
1447
+ ZOOM: {
1448
+ guard: "hasViewportRect",
1449
+ actions: ["updateZoom"]
1450
+ },
1451
+ NUDGE_RESIZE_CROP: {
1452
+ guard: "hasViewportRect",
1453
+ actions: ["nudgeResizeCrop"]
1454
+ },
1455
+ NUDGE_MOVE_CROP: {
1456
+ guard: "hasViewportRect",
1457
+ actions: ["nudgeMoveCrop"]
1458
+ }
1459
+ }
1460
+ },
1461
+ dragging: {
1462
+ effects: ["trackPointerMove"],
1463
+ on: {
1464
+ POINTER_MOVE: { actions: ["updateCrop"] },
1465
+ POINTER_UP: {
1466
+ target: "idle",
1467
+ actions: [
1468
+ "clearPointerStart",
1469
+ "clearCropStart",
1470
+ "clearHandlePosition",
1471
+ "clearOffsetStart",
1472
+ "clearShiftRatio"
1473
+ ]
1474
+ }
1475
+ }
1476
+ },
1477
+ panning: {
1478
+ effects: ["trackPointerMove"],
1479
+ on: {
1480
+ POINTER_MOVE: { actions: ["updatePanOffset"] },
1481
+ POINTER_UP: {
1482
+ target: "idle",
1483
+ actions: ["clearPointerStart", "clearOffsetStart"]
1484
+ }
1485
+ }
1486
+ }
1487
+ },
1488
+ implementations: {
1489
+ guards: {
1490
+ hasViewportRect({ context }) {
1491
+ return isVisibleRect(context.get("viewportRect"));
1492
+ },
1493
+ canResizeCrop({ context, prop }) {
1494
+ return !prop("fixedCropArea") && isVisibleRect(context.get("viewportRect"));
1495
+ },
1496
+ canPan({ context }) {
1497
+ return isVisibleRect(context.get("naturalSize")) && isVisibleRect(context.get("viewportRect"));
1498
+ },
1499
+ canDragSelection({ context, prop }) {
1500
+ return isVisibleRect(context.get("viewportRect")) && !prop("fixedCropArea");
1501
+ }
1502
+ },
1503
+ actions: {
1504
+ checkImageStatus({ send, scope, context }) {
1505
+ const naturalSize = context.get("naturalSize");
1506
+ const imageEl = getImageEl(scope);
1507
+ if (!imageEl?.complete) return;
1508
+ const { naturalWidth: width, naturalHeight: height } = imageEl;
1509
+ if (isVisibleRect({
1510
+ width,
1511
+ height
1512
+ }) && !isVisibleRect(naturalSize)) send({
1513
+ type: "SET_NATURAL_SIZE",
1514
+ src: "ssr",
1515
+ size: {
1516
+ width,
1517
+ height
1518
+ }
1519
+ });
1520
+ },
1521
+ setNaturalSize({ event, context, send }) {
1522
+ context.set("naturalSize", event.size);
1523
+ send({
1524
+ type: "SET_DEFAULT_CROP",
1525
+ src: "init"
1526
+ });
1527
+ },
1528
+ setDefaultCrop({ context, prop, scope }) {
1529
+ const viewportEl = getViewportEl(scope);
1530
+ if (!viewportEl) return;
1531
+ const viewportRect = getBoundingRect(viewportEl);
1532
+ if (!isVisibleRect(viewportRect)) return;
1533
+ const aspectRatio = resolveCropAspectRatio(prop("cropShape"), prop("aspectRatio"));
1534
+ const { minSize, maxSize } = getCropSizeLimits(prop);
1535
+ const clampSize = (rect) => {
1536
+ const result = computeResizeCrop({
1537
+ cropStart: rect,
1538
+ handlePosition: "se",
1539
+ delta: ZERO_POINT,
1540
+ viewportRect,
1541
+ minSize,
1542
+ maxSize,
1543
+ aspectRatio
1544
+ });
1545
+ return {
1546
+ width: result.width,
1547
+ height: result.height
1548
+ };
1549
+ };
1550
+ const initialCrop = prop("initialCrop");
1551
+ if (initialCrop) {
1552
+ const { width, height } = clampSize({
1553
+ x: 0,
1554
+ y: 0,
1555
+ width: initialCrop.width,
1556
+ height: initialCrop.height
1557
+ });
1558
+ const { x, y } = clampPoint(initialCrop, ZERO_POINT, getMaxBounds({
1559
+ width,
1560
+ height
1561
+ }, viewportRect));
1562
+ context.set("crop", {
1563
+ x,
1564
+ y,
1565
+ width,
1566
+ height
1567
+ });
1568
+ return;
1569
+ }
1570
+ const defaultSize = computeDefaultCropDimensions(viewportRect, aspectRatio, prop("fixedCropArea"));
1571
+ const constrainedSize = clampSize({
1572
+ x: 0,
1573
+ y: 0,
1574
+ width: defaultSize.width,
1575
+ height: defaultSize.height
1576
+ });
1577
+ const width = constrainedSize.width;
1578
+ const height = constrainedSize.height;
1579
+ const { x, y } = centerRect({
1580
+ width,
1581
+ height
1582
+ }, viewportRect);
1583
+ context.set("crop", {
1584
+ x,
1585
+ y,
1586
+ width,
1587
+ height
1588
+ });
1589
+ context.set("viewportRect", viewportRect);
1590
+ },
1591
+ setPointerStart({ event, context }) {
1592
+ const point = event.point;
1593
+ if (!point) return;
1594
+ context.set("pointerStart", point);
1595
+ },
1596
+ setOffsetStart({ context }) {
1597
+ const offset = context.get("offset");
1598
+ context.set("offsetStart", { ...offset });
1599
+ },
1600
+ setCropStart({ context }) {
1601
+ const crop = context.get("crop");
1602
+ context.set("cropStart", crop);
1603
+ },
1604
+ updateCrop({ context, event, prop }) {
1605
+ const handlePosition = context.get("handlePosition");
1606
+ const pointerStart = context.get("pointerStart");
1607
+ const cropStart = context.get("cropStart");
1608
+ const viewportRect = context.get("viewportRect");
1609
+ const cropShape = prop("cropShape");
1610
+ const aspectRatioProp = prop("aspectRatio");
1611
+ let aspectRatio = resolveCropAspectRatio(cropShape, aspectRatioProp);
1612
+ const { minSize, maxSize } = getCropSizeLimits(prop);
1613
+ if (!pointerStart || !cropStart) return;
1614
+ const currentPoint = event.point;
1615
+ let delta = subtractPoints(currentPoint, pointerStart);
1616
+ let nextCrop;
1617
+ if (handlePosition) {
1618
+ if (typeof aspectRatioProp === "undefined" && cropShape !== "circle") if (event.shiftKey) {
1619
+ const currentCrop = context.get("crop");
1620
+ const w = currentCrop.width;
1621
+ const h = currentCrop.height;
1622
+ if (w > 0 && h > 0) {
1623
+ const ratio = w / h;
1624
+ if (ratio > 0) context.set("shiftLockRatio", ratio);
1625
+ }
1626
+ const lockRatio = context.get("shiftLockRatio");
1627
+ if (lockRatio !== null && lockRatio > 0) aspectRatio = lockRatio;
1628
+ } else context.set("shiftLockRatio", null);
1629
+ else context.set("shiftLockRatio", null);
1630
+ if (event.altKey) delta = {
1631
+ x: delta.x * 2,
1632
+ y: delta.y * 2
1633
+ };
1634
+ nextCrop = computeResizeCrop({
1635
+ cropStart,
1636
+ handlePosition,
1637
+ delta,
1638
+ viewportRect,
1639
+ minSize,
1640
+ maxSize,
1641
+ aspectRatio
1642
+ });
1643
+ if (event.altKey) {
1644
+ const originalCenter = getCenterPoint(cropStart);
1645
+ const pos = centerCropOnPoint(nextCrop, originalCenter, viewportRect);
1646
+ nextCrop = {
1647
+ ...nextCrop,
1648
+ x: pos.x,
1649
+ y: pos.y
1650
+ };
1651
+ }
1652
+ } else nextCrop = computeMoveCrop(cropStart, delta, viewportRect);
1653
+ context.set("crop", nextCrop);
1654
+ },
1655
+ updatePanOffset({ context, event, prop }) {
1656
+ const point = event.point;
1657
+ const pointerStart = context.get("pointerStart");
1658
+ const offsetStart = context.get("offsetStart");
1659
+ if (!point || !pointerStart || !offsetStart) return;
1660
+ const nextOffset = clampOffset({
1661
+ zoom: context.get("zoom"),
1662
+ rotation: context.get("rotation"),
1663
+ viewportSize: context.get("viewportRect"),
1664
+ offset: addPoints(offsetStart, subtractPoints(point, pointerStart)),
1665
+ fixedCropArea: prop("fixedCropArea"),
1666
+ crop: context.get("crop")
1667
+ });
1668
+ context.set("offset", nextOffset);
1669
+ },
1670
+ setHandlePosition({ event, context }) {
1671
+ const position = event.handlePosition;
1672
+ if (!position) return;
1673
+ context.set("handlePosition", position);
1674
+ },
1675
+ setRotation({ context, event }) {
1676
+ const rotation = event.rotation;
1677
+ const nextRotation = clampValue(rotation, 0, 360);
1678
+ context.set("rotation", nextRotation);
1679
+ },
1680
+ setFlip({ context, event }) {
1681
+ const nextFlip = event.flip;
1682
+ if (!nextFlip) return;
1683
+ const currentFlip = context.get("flip");
1684
+ const normalized = normalizeFlipState(nextFlip, currentFlip);
1685
+ if (isEqualFlip(normalized, currentFlip)) return;
1686
+ context.set("flip", normalized);
1687
+ },
1688
+ resizeCrop({ context, event, prop }) {
1689
+ const { handlePosition, delta } = event;
1690
+ if (!handlePosition) return;
1691
+ const viewportRect = context.get("viewportRect");
1692
+ if (!isVisibleRect(viewportRect)) return;
1693
+ const aspectRatio = resolveCropAspectRatio(prop("cropShape"), prop("aspectRatio"));
1694
+ const { minSize, maxSize } = getCropSizeLimits(prop);
1695
+ const nextCrop = computeResizeCrop({
1696
+ cropStart: context.get("crop"),
1697
+ handlePosition,
1698
+ delta,
1699
+ viewportRect,
1700
+ minSize,
1701
+ maxSize,
1702
+ aspectRatio
1703
+ });
1704
+ context.set("crop", nextCrop);
1705
+ },
1706
+ clearPointerStart({ context }) {
1707
+ context.set("pointerStart", null);
1708
+ },
1709
+ clearCropStart({ context }) {
1710
+ context.set("cropStart", null);
1711
+ },
1712
+ clearHandlePosition({ context }) {
1713
+ context.set("handlePosition", null);
1714
+ },
1715
+ clearOffsetStart({ context }) {
1716
+ context.set("offsetStart", null);
1717
+ },
1718
+ clearShiftRatio({ context }) {
1719
+ context.set("shiftLockRatio", null);
1720
+ },
1721
+ updateZoom({ context, event, prop }) {
1722
+ let { delta, point, zoom: targetZoom, scale, panDelta } = event;
1723
+ const crop = context.get("crop");
1724
+ const currentZoom = context.get("zoom");
1725
+ const currentOffset = context.get("offset");
1726
+ const rotation = context.get("rotation");
1727
+ const viewportRect = context.get("viewportRect");
1728
+ const fixedCropArea = prop("fixedCropArea");
1729
+ if (!point) point = getCenterPoint(crop);
1730
+ const step = Math.abs(prop("zoomStep"));
1731
+ const sensitivity = Math.max(0, prop("zoomSensitivity"));
1732
+ const [minZoom, maxZoom] = [prop("minZoom"), prop("maxZoom")];
1733
+ const calculateNextZoom = () => {
1734
+ if (typeof targetZoom === "number") return clampValue(targetZoom, minZoom, maxZoom);
1735
+ if (event.trigger === "touch" && typeof scale === "number") {
1736
+ const clampedScale = clampValue(scale, .5, 2);
1737
+ return clampValue(currentZoom * (sensitivity > 0 ? Math.pow(clampedScale, sensitivity) : clampedScale), minZoom, maxZoom);
1738
+ }
1739
+ if (typeof delta === "number") return clampValue(currentZoom + step * (Math.sign(delta) < 0 ? 1 : -1), minZoom, maxZoom);
1740
+ return null;
1741
+ };
1742
+ const applyClampedOffset = (zoom, offset) => {
1743
+ return clampOffset({
1744
+ zoom,
1745
+ rotation,
1746
+ viewportSize: viewportRect,
1747
+ offset,
1748
+ fixedCropArea,
1749
+ crop
1750
+ });
1751
+ };
1752
+ const nextZoom = calculateNextZoom();
1753
+ if (nextZoom === null) return;
1754
+ if (nextZoom === currentZoom && panDelta) {
1755
+ const nextOffset = applyClampedOffset(currentZoom, addPoints(currentOffset, panDelta));
1756
+ context.set("offset", nextOffset);
1757
+ return;
1758
+ }
1759
+ if (nextZoom === currentZoom) return;
1760
+ const { width: viewportWidth, height: viewportHeight } = viewportRect;
1761
+ const { x: centerX, y: centerY } = getViewportCenter(viewportRect);
1762
+ const zoomRatio = nextZoom / currentZoom;
1763
+ let nextOffset = {
1764
+ x: (1 - zoomRatio) * (point.x - centerX) + zoomRatio * currentOffset.x,
1765
+ y: (1 - zoomRatio) * (point.y - centerY) + zoomRatio * currentOffset.y
1766
+ };
1767
+ if (panDelta) nextOffset = applyClampedOffset(nextZoom, addPoints(nextOffset, panDelta));
1768
+ else if (nextZoom < currentZoom) if (fixedCropArea) nextOffset = applyClampedOffset(nextZoom, nextOffset);
1769
+ else {
1770
+ const { width: scaledImageWidth, height: scaledImageHeight } = scaleSize(viewportRect, nextZoom);
1771
+ if (scaledImageWidth <= viewportWidth) nextOffset.x = 0;
1772
+ else {
1773
+ const minX = viewportWidth - centerX - scaledImageWidth / 2;
1774
+ const maxX = scaledImageWidth / 2 - centerX;
1775
+ nextOffset.x = Math.max(minX, Math.min(maxX, nextOffset.x));
1776
+ }
1777
+ if (scaledImageHeight <= viewportHeight) nextOffset.y = 0;
1778
+ else {
1779
+ const minY = viewportHeight - centerY - scaledImageHeight / 2;
1780
+ const maxY = scaledImageHeight / 2 - centerY;
1781
+ nextOffset.y = Math.max(minY, Math.min(maxY, nextOffset.y));
1782
+ }
1783
+ }
1784
+ context.set("zoom", nextZoom);
1785
+ context.set("offset", nextOffset);
1786
+ },
1787
+ setPinchDistance({ context, event, send }) {
1788
+ const touches = Array.isArray(event.touches) ? event.touches : [];
1789
+ if (touches.length < 2) return;
1790
+ if (context.get("pointerStart") !== null) send({
1791
+ type: "POINTER_UP",
1792
+ src: "pinch"
1793
+ });
1794
+ const [first, second] = touches;
1795
+ const distance = getTouchDistance(first, second);
1796
+ const viewportRect = context.get("viewportRect");
1797
+ const midpoint = getMidpoint(first, second, {
1798
+ x: viewportRect.left,
1799
+ y: viewportRect.top
1800
+ });
1801
+ context.set("pinchDistance", distance);
1802
+ context.set("pinchMidpoint", midpoint);
1803
+ },
1804
+ handlePinchMove({ context, event, send }) {
1805
+ const touches = Array.isArray(event.touches) ? event.touches : [];
1806
+ if (touches.length < 2) return;
1807
+ const [first, second] = touches;
1808
+ const distance = getTouchDistance(first, second);
1809
+ const lastDistance = context.get("pinchDistance");
1810
+ const lastMidpoint = context.get("pinchMidpoint");
1811
+ const viewportRect = context.get("viewportRect");
1812
+ const midpoint = getMidpoint(first, second, {
1813
+ x: viewportRect.left,
1814
+ y: viewportRect.top
1815
+ });
1816
+ if (lastDistance != null && lastDistance > 0 && lastMidpoint != null) {
1817
+ const delta = lastDistance - distance;
1818
+ const scale = distance / lastDistance;
1819
+ const hasSignificantZoom = Math.abs(delta) > 1;
1820
+ const panDelta = subtractPoints(midpoint, lastMidpoint);
1821
+ send({
1822
+ type: "ZOOM",
1823
+ trigger: "touch",
1824
+ delta,
1825
+ scale: hasSignificantZoom ? scale : 1,
1826
+ point: midpoint,
1827
+ panDelta
1828
+ });
1829
+ }
1830
+ context.set("pinchDistance", distance);
1831
+ context.set("pinchMidpoint", midpoint);
1832
+ },
1833
+ clearPinchDistance({ context }) {
1834
+ context.set("pinchDistance", null);
1835
+ context.set("pinchMidpoint", null);
1836
+ },
1837
+ nudgeResizeCrop({ context, event, prop }) {
1838
+ const { key, handlePosition, shiftKey, ctrlKey, metaKey } = event;
1839
+ const crop = context.get("crop");
1840
+ const viewportRect = context.get("viewportRect");
1841
+ const step = getNudgeStep(prop, {
1842
+ shiftKey,
1843
+ ctrlKey,
1844
+ metaKey
1845
+ });
1846
+ const { minSize, maxSize } = getCropSizeLimits(prop);
1847
+ const nextCrop = computeKeyboardCrop(key, handlePosition, step, crop, viewportRect, minSize, maxSize);
1848
+ context.set("crop", nextCrop);
1849
+ },
1850
+ nudgeMoveCrop({ context, event, prop }) {
1851
+ const { key, shiftKey, ctrlKey, metaKey } = event;
1852
+ const crop = context.get("crop");
1853
+ const viewportRect = context.get("viewportRect");
1854
+ const nextCrop = computeMoveCrop(crop, getKeyboardMoveDelta(key, getNudgeStep(prop, {
1855
+ shiftKey,
1856
+ ctrlKey,
1857
+ metaKey
1858
+ })), viewportRect);
1859
+ context.set("crop", nextCrop);
1860
+ },
1861
+ resizeViewport({ context, prop, scope, send }) {
1862
+ const viewportEl = getViewportEl(scope);
1863
+ if (!viewportEl) return;
1864
+ const newViewportRect = getBoundingRect(viewportEl);
1865
+ if (!isVisibleRect(newViewportRect)) return;
1866
+ const oldViewportRect = context.get("viewportRect");
1867
+ if (isSameSize(oldViewportRect, newViewportRect)) return;
1868
+ context.set("viewportRect", newViewportRect);
1869
+ const oldCrop = context.get("crop");
1870
+ if (!isVisibleRect(oldCrop)) {
1871
+ send({
1872
+ type: "SET_DEFAULT_CROP",
1873
+ src: "viewport-resize"
1874
+ });
1875
+ return;
1876
+ }
1877
+ if (!isVisibleRect(oldViewportRect)) return;
1878
+ const aspectRatio = resolveCropAspectRatio(prop("cropShape"), prop("aspectRatio"));
1879
+ const { minSize, maxSize } = getCropSizeLimits(prop);
1880
+ const constrainedCrop = computeResizeCrop({
1881
+ cropStart: scaleRect(oldCrop, {
1882
+ x: newViewportRect.width / oldViewportRect.width,
1883
+ y: newViewportRect.height / oldViewportRect.height
1884
+ }),
1885
+ handlePosition: "se",
1886
+ delta: ZERO_POINT,
1887
+ viewportRect: newViewportRect,
1888
+ minSize,
1889
+ maxSize,
1890
+ aspectRatio
1891
+ });
1892
+ const { x, y } = clampPoint(constrainedCrop, ZERO_POINT, getMaxBounds(constrainedCrop, newViewportRect));
1893
+ context.set("crop", {
1894
+ x,
1895
+ y,
1896
+ width: constrainedCrop.width,
1897
+ height: constrainedCrop.height
1898
+ });
1899
+ },
1900
+ resetToInitialState({ context, send }) {
1901
+ context.set("zoom", context.initial("zoom"));
1902
+ context.set("rotation", context.initial("rotation"));
1903
+ context.set("flip", context.initial("flip"));
1904
+ context.set("offset", ZERO_POINT);
1905
+ send({
1906
+ type: "SET_DEFAULT_CROP",
1907
+ src: "reset"
1908
+ });
1909
+ },
1910
+ adjustCropAspectRatio({ context, prop }) {
1911
+ const viewportRect = context.get("viewportRect");
1912
+ if (!isVisibleRect(viewportRect)) return;
1913
+ const crop = context.get("crop");
1914
+ if (!isVisibleRect(crop)) return;
1915
+ const aspectRatio = resolveCropAspectRatio(prop("cropShape"), prop("aspectRatio"));
1916
+ if (aspectRatio === void 0) return;
1917
+ if (isAspectRatioEqual(crop.width / crop.height, aspectRatio)) return;
1918
+ const { minSize, maxSize } = getCropSizeLimits(prop);
1919
+ const constrainedCrop = computeResizeCrop({
1920
+ cropStart: crop,
1921
+ handlePosition: "se",
1922
+ delta: ZERO_POINT,
1923
+ viewportRect,
1924
+ minSize,
1925
+ maxSize,
1926
+ aspectRatio
1927
+ });
1928
+ if (isSameSize(crop, constrainedCrop)) return;
1929
+ const pos = centerCropOnPoint(constrainedCrop, getCenterPoint(crop), viewportRect);
1930
+ context.set("crop", {
1931
+ x: pos.x,
1932
+ y: pos.y,
1933
+ width: constrainedCrop.width,
1934
+ height: constrainedCrop.height
1935
+ });
1936
+ }
1937
+ },
1938
+ effects: {
1939
+ trackPointerMove({ scope, send }) {
1940
+ function onPointerMove(event) {
1941
+ send({
1942
+ type: "POINTER_MOVE",
1943
+ point: getEventPoint(event),
1944
+ target: getEventTarget(event),
1945
+ shiftKey: event.shiftKey,
1946
+ altKey: event.altKey
1947
+ });
1948
+ }
1949
+ function onPointerUp() {
1950
+ send({ type: "POINTER_UP" });
1951
+ }
1952
+ return callAll(addDomEvent(scope.getDoc(), "pointermove", onPointerMove), addDomEvent(scope.getDoc(), "pointerup", onPointerUp));
1953
+ },
1954
+ trackViewportResize({ scope, send }) {
1955
+ const viewportEl = getViewportEl(scope);
1956
+ if (!viewportEl) return;
1957
+ return resizeObserverBorderBox.observe(viewportEl, () => {
1958
+ send({
1959
+ type: "VIEWPORT_RESIZE",
1960
+ src: "resize"
1961
+ });
1962
+ });
1963
+ },
1964
+ trackWheelEvent({ scope, send }) {
1965
+ const viewportEl = getViewportEl(scope);
1966
+ if (!viewportEl) return;
1967
+ function onWheel(event) {
1968
+ event.preventDefault();
1969
+ if (!viewportEl) return;
1970
+ const rect = viewportEl.getBoundingClientRect();
1971
+ const point = {
1972
+ x: event.clientX - rect.left,
1973
+ y: event.clientY - rect.top
1974
+ };
1975
+ send({
1976
+ type: "ZOOM",
1977
+ trigger: "wheel",
1978
+ delta: event.deltaY,
1979
+ point
1980
+ });
1981
+ }
1982
+ return addDomEvent(viewportEl, "wheel", onWheel, { passive: false });
1983
+ },
1984
+ trackTouchEvents({ scope, send }) {
1985
+ const viewportEl = getViewportEl(scope);
1986
+ if (!viewportEl) return;
1987
+ function onTouchStart(event) {
1988
+ if (event.touches.length >= 2) {
1989
+ event.preventDefault();
1990
+ send({
1991
+ type: "PINCH_START",
1992
+ touches: Array.from(event.touches).map((touch) => ({
1993
+ x: touch.clientX,
1994
+ y: touch.clientY
1995
+ }))
1996
+ });
1997
+ }
1998
+ }
1999
+ function onTouchMove(event) {
2000
+ if (event.touches.length >= 2) {
2001
+ event.preventDefault();
2002
+ send({
2003
+ type: "PINCH_MOVE",
2004
+ touches: Array.from(event.touches).map((touch) => ({
2005
+ x: touch.clientX,
2006
+ y: touch.clientY
2007
+ }))
2008
+ });
2009
+ }
2010
+ }
2011
+ function onTouchEnd(event) {
2012
+ if (event.touches.length < 2) send({ type: "PINCH_END" });
2013
+ }
2014
+ return callAll(addDomEvent(viewportEl, "touchstart", onTouchStart, { passive: false }), addDomEvent(viewportEl, "touchmove", onTouchMove, { passive: false }), addDomEvent(viewportEl, "touchend", onTouchEnd));
2015
+ }
2016
+ }
2017
+ }
2018
+ });
2019
+ const getBoundingRect = (el) => {
2020
+ const rect = el.getBoundingClientRect();
2021
+ return {
2022
+ width: rect.width,
2023
+ height: rect.height,
2024
+ top: rect.top,
2025
+ left: rect.left,
2026
+ right: rect.right,
2027
+ bottom: rect.bottom
2028
+ };
2029
+ };
2030
+ //#endregion
2031
+ //#region src/machines/image-cropper/props.ts
2032
+ const props = createProps()([
2033
+ "id",
2034
+ "ids",
2035
+ "dir",
2036
+ "getRootNode",
2037
+ "initialCrop",
2038
+ "minWidth",
2039
+ "minHeight",
2040
+ "maxWidth",
2041
+ "maxHeight",
2042
+ "aspectRatio",
2043
+ "cropShape",
2044
+ "zoom",
2045
+ "rotation",
2046
+ "flip",
2047
+ "defaultZoom",
2048
+ "defaultRotation",
2049
+ "defaultFlip",
2050
+ "zoomStep",
2051
+ "zoomSensitivity",
2052
+ "minZoom",
2053
+ "maxZoom",
2054
+ "onZoomChange",
2055
+ "onRotationChange",
2056
+ "onFlipChange",
2057
+ "onCropChange",
2058
+ "fixedCropArea",
2059
+ "nudgeStep",
2060
+ "nudgeStepShift",
2061
+ "nudgeStepCtrl",
2062
+ "translations"
2063
+ ]);
2064
+ const splitProps = createSplitProps(props);
2065
+ const handles = [
2066
+ "nw",
2067
+ "n",
2068
+ "ne",
2069
+ "e",
2070
+ "se",
2071
+ "s",
2072
+ "sw",
2073
+ "w"
2074
+ ];
2075
+ //#endregion
2076
+ export { anatomy, connect, handles, machine, props, splitProps };