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