@wordpress/media-editor 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (432) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/components/media-editor/index.cjs +586 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +42 -57
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  6. package/build/components/media-editor/use-save-media-editor.cjs +131 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +117 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +81 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +61 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +181 -257
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/index.cjs +112 -155
  19. package/build/components/media-editor-modal/index.cjs.map +1 -7
  20. package/build/components/media-editor-provider/index.cjs +32 -55
  21. package/build/components/media-editor-provider/index.cjs.map +1 -7
  22. package/build/components/media-form/index.cjs +82 -77
  23. package/build/components/media-form/index.cjs.map +1 -7
  24. package/build/components/media-preview/index.cjs +113 -114
  25. package/build/components/media-preview/index.cjs.map +1 -7
  26. package/build/components/rotation-ruler/index.cjs +181 -188
  27. package/build/components/rotation-ruler/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  29. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  30. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  32. package/build/index.cjs +45 -39
  33. package/build/lock-unlock.cjs +9 -35
  34. package/build/lock-unlock.cjs.map +1 -7
  35. package/build/private-apis.cjs +16 -37
  36. package/build/private-apis.cjs.map +1 -7
  37. package/build/state/aspect-ratio-presets.cjs +59 -0
  38. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  39. package/build/state/composite-reducer.cjs +100 -113
  40. package/build/state/composite-reducer.cjs.map +1 -7
  41. package/build/state/index.cjs +22 -45
  42. package/build/state/media-editor-state-provider.cjs +35 -48
  43. package/build/state/media-editor-state-provider.cjs.map +1 -7
  44. package/build/state/types.cjs +11 -31
  45. package/build/state/types.cjs.map +1 -7
  46. package/build/state/use-media-editor-state.cjs +227 -296
  47. package/build/state/use-media-editor-state.cjs.map +1 -7
  48. package/build/store/actions.cjs +17 -44
  49. package/build/store/actions.cjs.map +1 -7
  50. package/build/store/constants.cjs +8 -29
  51. package/build/store/constants.cjs.map +1 -7
  52. package/build/store/index.cjs +33 -40
  53. package/build/store/index.cjs.map +1 -7
  54. package/build/store/reducer.cjs +28 -50
  55. package/build/store/reducer.cjs.map +1 -7
  56. package/build/store/selectors.cjs +16 -41
  57. package/build/store/selectors.cjs.map +1 -7
  58. package/build/utils/get-media-type.cjs +18 -41
  59. package/build/utils/get-media-type.cjs.map +1 -7
  60. package/build/utils/index.cjs +9 -28
  61. package/build-module/components/media-editor/index.mjs +545 -675
  62. package/build-module/components/media-editor/index.mjs.map +1 -7
  63. package/build-module/components/media-editor/use-crop-options.mjs +37 -32
  64. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  65. package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
  66. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  67. package/build-module/components/media-editor-canvas/index.mjs +95 -98
  68. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  69. package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
  70. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  71. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
  72. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  73. package/build-module/components/media-editor-image-controls/index.mjs +171 -238
  74. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  75. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
  76. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  77. package/build-module/components/media-editor-modal/index.mjs +88 -124
  78. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  79. package/build-module/components/media-editor-provider/index.mjs +26 -29
  80. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  81. package/build-module/components/media-form/index.mjs +74 -56
  82. package/build-module/components/media-form/index.mjs.map +1 -7
  83. package/build-module/components/media-preview/index.mjs +105 -90
  84. package/build-module/components/media-preview/index.mjs.map +1 -7
  85. package/build-module/components/rotation-ruler/index.mjs +161 -164
  86. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  87. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  88. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  89. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  90. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  91. package/build-module/index.mjs +3 -10
  92. package/build-module/lock-unlock.mjs +5 -10
  93. package/build-module/lock-unlock.mjs.map +1 -7
  94. package/build-module/private-apis.mjs +8 -9
  95. package/build-module/private-apis.mjs.map +1 -7
  96. package/build-module/state/aspect-ratio-presets.mjs +53 -0
  97. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  98. package/build-module/state/composite-reducer.mjs +80 -91
  99. package/build-module/state/composite-reducer.mjs.map +1 -7
  100. package/build-module/state/index.mjs +3 -26
  101. package/build-module/state/media-editor-state-provider.mjs +29 -24
  102. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  103. package/build-module/state/types.mjs +7 -7
  104. package/build-module/state/types.mjs.map +1 -7
  105. package/build-module/state/use-media-editor-state.mjs +223 -288
  106. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  107. package/build-module/store/actions.mjs +12 -19
  108. package/build-module/store/actions.mjs.map +1 -7
  109. package/build-module/store/constants.mjs +4 -5
  110. package/build-module/store/constants.mjs.map +1 -7
  111. package/build-module/store/index.mjs +8 -9
  112. package/build-module/store/index.mjs.map +1 -7
  113. package/build-module/store/reducer.mjs +23 -26
  114. package/build-module/store/reducer.mjs.map +1 -7
  115. package/build-module/store/selectors.mjs +8 -13
  116. package/build-module/store/selectors.mjs.map +1 -7
  117. package/build-module/utils/get-media-type.mjs +14 -17
  118. package/build-module/utils/get-media-type.mjs.map +1 -7
  119. package/build-module/utils/index.mjs +1 -6
  120. package/build-style/style-rtl.css +145 -61
  121. package/build-style/style.css +144 -61
  122. package/build-types/components/media-editor/index.d.ts +20 -2
  123. package/build-types/components/media-editor/index.d.ts.map +1 -1
  124. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  125. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  126. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  127. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  128. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  129. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  130. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  131. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  132. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  133. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  134. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  135. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  136. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  137. package/build-types/components/media-form/index.d.ts.map +1 -1
  138. package/build-types/components/media-preview/index.d.ts.map +1 -1
  139. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  140. package/build-types/state/aspect-ratio-presets.d.ts +24 -0
  141. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  142. package/build-types/state/composite-reducer.d.ts +17 -19
  143. package/build-types/state/composite-reducer.d.ts.map +1 -1
  144. package/build-types/state/index.d.ts +2 -4
  145. package/build-types/state/index.d.ts.map +1 -1
  146. package/build-types/state/types.d.ts +20 -63
  147. package/build-types/state/types.d.ts.map +1 -1
  148. package/build-types/state/use-media-editor-state.d.ts +33 -52
  149. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  150. package/package.json +22 -23
  151. package/src/components/media-editor/index.tsx +355 -167
  152. package/src/components/media-editor/style.scss +19 -0
  153. package/src/components/media-editor/use-crop-options.ts +9 -10
  154. package/src/components/media-editor/use-save-media-editor.ts +48 -10
  155. package/src/components/media-editor-canvas/index.tsx +30 -51
  156. package/src/components/media-editor-canvas/style.scss +6 -6
  157. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  158. package/src/components/media-editor-crop-panel/style.scss +21 -0
  159. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  160. package/src/components/media-editor-image-controls/index.tsx +15 -11
  161. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
  162. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  163. package/src/components/media-editor-modal/index.tsx +1 -1
  164. package/src/components/media-editor-modal/style.scss +1 -1
  165. package/src/components/media-form/index.tsx +7 -1
  166. package/src/components/media-preview/index.tsx +65 -23
  167. package/src/components/media-preview/style.scss +16 -2
  168. package/src/components/rotation-ruler/style.scss +9 -5
  169. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  170. package/src/state/README.md +32 -0
  171. package/src/state/aspect-ratio-presets.ts +37 -0
  172. package/src/state/composite-reducer.ts +42 -80
  173. package/src/state/index.ts +2 -17
  174. package/src/state/types.ts +18 -72
  175. package/src/state/use-media-editor-state.ts +155 -238
  176. package/src/style.scss +2 -1
  177. package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
  178. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
  179. package/build/image-editor/core/camera.cjs +0 -225
  180. package/build/image-editor/core/camera.cjs.map +0 -7
  181. package/build/image-editor/core/constants.cjs +0 -108
  182. package/build/image-editor/core/constants.cjs.map +0 -7
  183. package/build/image-editor/core/containment.cjs +0 -276
  184. package/build/image-editor/core/containment.cjs.map +0 -7
  185. package/build/image-editor/core/crop-rect.cjs +0 -48
  186. package/build/image-editor/core/crop-rect.cjs.map +0 -7
  187. package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
  188. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
  189. package/build/image-editor/core/index.cjs +0 -62
  190. package/build/image-editor/core/index.cjs.map +0 -7
  191. package/build/image-editor/core/interaction-controller.cjs +0 -654
  192. package/build/image-editor/core/interaction-controller.cjs.map +0 -7
  193. package/build/image-editor/core/math/rotation.cjs +0 -41
  194. package/build/image-editor/core/math/rotation.cjs.map +0 -7
  195. package/build/image-editor/core/math/sanitize.cjs +0 -92
  196. package/build/image-editor/core/math/sanitize.cjs.map +0 -7
  197. package/build/image-editor/core/setter-helpers.cjs +0 -64
  198. package/build/image-editor/core/setter-helpers.cjs.map +0 -7
  199. package/build/image-editor/core/source-region.cjs +0 -206
  200. package/build/image-editor/core/source-region.cjs.map +0 -7
  201. package/build/image-editor/core/state.cjs +0 -283
  202. package/build/image-editor/core/state.cjs.map +0 -7
  203. package/build/image-editor/core/stencil-math.cjs +0 -216
  204. package/build/image-editor/core/stencil-math.cjs.map +0 -7
  205. package/build/image-editor/core/transform-style.cjs +0 -52
  206. package/build/image-editor/core/transform-style.cjs.map +0 -7
  207. package/build/image-editor/core/transforms/pipeline.cjs +0 -43
  208. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
  209. package/build/image-editor/core/types.cjs +0 -19
  210. package/build/image-editor/core/types.cjs.map +0 -7
  211. package/build/image-editor/core/viewport-state.cjs +0 -50
  212. package/build/image-editor/core/viewport-state.cjs.map +0 -7
  213. package/build/image-editor/index.cjs +0 -67
  214. package/build/image-editor/index.cjs.map +0 -7
  215. package/build/image-editor/react/components/cropper-provider.cjs +0 -50
  216. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
  217. package/build/image-editor/react/components/cropper.cjs +0 -722
  218. package/build/image-editor/react/components/cropper.cjs.map +0 -7
  219. package/build/image-editor/react/components/index.cjs +0 -36
  220. package/build/image-editor/react/components/index.cjs.map +0 -7
  221. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
  222. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
  223. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
  224. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
  225. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
  226. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
  227. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
  228. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
  229. package/build/image-editor/react/components/viewport-provider.cjs +0 -51
  230. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
  231. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
  232. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
  233. package/build/image-editor/react/hooks/index.cjs +0 -34
  234. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  235. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
  236. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -7
  237. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  238. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  239. package/build/image-editor/react/hooks/use-interaction.cjs +0 -213
  240. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
  241. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
  242. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
  243. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
  244. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
  245. package/build/image-editor/react/visually-hidden-style.cjs +0 -41
  246. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -7
  247. package/build/index.cjs.map +0 -7
  248. package/build/state/index.cjs.map +0 -7
  249. package/build/utils/index.cjs.map +0 -7
  250. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -66
  251. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
  252. package/build-module/image-editor/core/camera.mjs +0 -198
  253. package/build-module/image-editor/core/camera.mjs.map +0 -7
  254. package/build-module/image-editor/core/constants.mjs +0 -69
  255. package/build-module/image-editor/core/constants.mjs.map +0 -7
  256. package/build-module/image-editor/core/containment.mjs +0 -253
  257. package/build-module/image-editor/core/containment.mjs.map +0 -7
  258. package/build-module/image-editor/core/crop-rect.mjs +0 -23
  259. package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
  260. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
  261. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
  262. package/build-module/image-editor/core/index.mjs +0 -36
  263. package/build-module/image-editor/core/index.mjs.map +0 -7
  264. package/build-module/image-editor/core/interaction-controller.mjs +0 -635
  265. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
  266. package/build-module/image-editor/core/math/rotation.mjs +0 -15
  267. package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
  268. package/build-module/image-editor/core/math/sanitize.mjs +0 -63
  269. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
  270. package/build-module/image-editor/core/setter-helpers.mjs +0 -39
  271. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
  272. package/build-module/image-editor/core/source-region.mjs +0 -178
  273. package/build-module/image-editor/core/source-region.mjs.map +0 -7
  274. package/build-module/image-editor/core/state.mjs +0 -260
  275. package/build-module/image-editor/core/state.mjs.map +0 -7
  276. package/build-module/image-editor/core/stencil-math.mjs +0 -187
  277. package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
  278. package/build-module/image-editor/core/transform-style.mjs +0 -27
  279. package/build-module/image-editor/core/transform-style.mjs.map +0 -7
  280. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
  281. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
  282. package/build-module/image-editor/core/types.mjs +0 -1
  283. package/build-module/image-editor/core/types.mjs.map +0 -7
  284. package/build-module/image-editor/core/viewport-state.mjs +0 -24
  285. package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
  286. package/build-module/image-editor/index.mjs +0 -39
  287. package/build-module/image-editor/index.mjs.map +0 -7
  288. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
  289. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
  290. package/build-module/image-editor/react/components/cropper.mjs +0 -704
  291. package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
  292. package/build-module/image-editor/react/components/index.mjs +0 -9
  293. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  294. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
  295. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
  296. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
  297. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
  298. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
  299. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
  300. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
  301. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
  302. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
  303. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
  304. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
  305. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
  306. package/build-module/image-editor/react/hooks/index.mjs +0 -8
  307. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  308. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
  309. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -7
  310. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  311. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  312. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -190
  313. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
  314. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
  315. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
  316. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
  317. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
  318. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
  319. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -7
  320. package/build-module/index.mjs.map +0 -7
  321. package/build-module/state/index.mjs.map +0 -7
  322. package/build-module/utils/index.mjs.map +0 -7
  323. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -80
  324. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  325. package/build-types/image-editor/core/camera.d.ts +0 -128
  326. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  327. package/build-types/image-editor/core/constants.d.ts +0 -99
  328. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  329. package/build-types/image-editor/core/containment.d.ts +0 -72
  330. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  331. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  332. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  333. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  334. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  335. package/build-types/image-editor/core/index.d.ts +0 -10
  336. package/build-types/image-editor/core/index.d.ts.map +0 -1
  337. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  338. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  339. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  340. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  341. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  342. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  343. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  344. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  345. package/build-types/image-editor/core/source-region.d.ts +0 -94
  346. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  347. package/build-types/image-editor/core/state.d.ts +0 -51
  348. package/build-types/image-editor/core/state.d.ts.map +0 -1
  349. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  350. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  351. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  352. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  353. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  354. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  355. package/build-types/image-editor/core/types.d.ts +0 -269
  356. package/build-types/image-editor/core/types.d.ts.map +0 -1
  357. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  358. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  359. package/build-types/image-editor/index.d.ts +0 -16
  360. package/build-types/image-editor/index.d.ts.map +0 -1
  361. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  362. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  363. package/build-types/image-editor/react/components/cropper.d.ts +0 -63
  364. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  365. package/build-types/image-editor/react/components/index.d.ts +0 -4
  366. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  367. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  368. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  369. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  370. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  371. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  372. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  373. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  374. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  375. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  376. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  377. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  378. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  379. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  380. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  381. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  382. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  383. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
  384. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  385. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  386. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  387. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  388. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  389. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  390. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  391. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  392. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  393. package/src/components/media-editor-modal/build-modifiers.ts +0 -161
  394. package/src/image-editor/README.md +0 -61
  395. package/src/image-editor/core/camera.ts +0 -429
  396. package/src/image-editor/core/constants.ts +0 -150
  397. package/src/image-editor/core/containment.ts +0 -469
  398. package/src/image-editor/core/crop-rect.ts +0 -42
  399. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  400. package/src/image-editor/core/index.ts +0 -47
  401. package/src/image-editor/core/interaction-controller.ts +0 -976
  402. package/src/image-editor/core/math/rotation.ts +0 -26
  403. package/src/image-editor/core/math/sanitize.ts +0 -155
  404. package/src/image-editor/core/setter-helpers.ts +0 -63
  405. package/src/image-editor/core/source-region.ts +0 -367
  406. package/src/image-editor/core/state.ts +0 -484
  407. package/src/image-editor/core/stencil-math.ts +0 -379
  408. package/src/image-editor/core/transform-style.ts +0 -56
  409. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  410. package/src/image-editor/core/types.ts +0 -230
  411. package/src/image-editor/core/viewport-state.ts +0 -30
  412. package/src/image-editor/docs/architecture.md +0 -63
  413. package/src/image-editor/docs/recipes.md +0 -184
  414. package/src/image-editor/index.ts +0 -52
  415. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  416. package/src/image-editor/react/components/cropper.scss +0 -259
  417. package/src/image-editor/react/components/cropper.tsx +0 -1116
  418. package/src/image-editor/react/components/index.ts +0 -3
  419. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  420. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  421. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  422. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  423. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  424. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  425. package/src/image-editor/react/hooks/index.ts +0 -4
  426. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  427. package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
  428. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  429. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  430. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  431. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  432. package/src/image-editor/style.scss +0 -1
@@ -1,654 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/image-editor/core/interaction-controller.ts
21
- var interaction_controller_exports = {};
22
- __export(interaction_controller_exports, {
23
- InteractionController: () => InteractionController
24
- });
25
- module.exports = __toCommonJS(interaction_controller_exports);
26
- var import_constants = require("./constants.cjs");
27
- var import_containment = require("./containment.cjs");
28
- var DOUBLE_TAP_TIME = 300;
29
- var DOUBLE_TAP_DISTANCE = 30;
30
- var ZOOM_ANIMATION_DURATION = 200;
31
- function getImageSizeFromState(state) {
32
- return state.image ? { width: state.image.naturalWidth, height: state.image.naturalHeight } : { width: 1, height: 1 };
33
- }
34
- function getTouchDistance(t1, t2) {
35
- const dx = t1.clientX - t2.clientX;
36
- const dy = t1.clientY - t2.clientY;
37
- return Math.sqrt(dx * dx + dy * dy);
38
- }
39
- var InteractionController = class {
40
- options;
41
- /** Current drag/zoom status. */
42
- isDragging = false;
43
- isZooming = false;
44
- /** Active drag state during pointer interactions. */
45
- drag = null;
46
- /** Active touch state during touch interactions. */
47
- touch = null;
48
- /** Cleanup function for active touch listeners on document. */
49
- touchCleanup = null;
50
- /**
51
- * Cleanup function for active pointer-drag listeners on the
52
- * captured element. Set while a pointer drag is in progress so
53
- * `destroy()` can tear the drag down cleanly if the consumer
54
- * unmounts mid-drag. Cleared on pointerup/lostpointercapture.
55
- */
56
- pointerCleanup = null;
57
- /** Last tap info for double-tap detection. */
58
- lastTap = null;
59
- /** Timer for the zoom animation state (double-tap). */
60
- zoomTimer;
61
- /** Timer for wheel gesture debounce. */
62
- wheelGestureTimer;
63
- /** Whether a wheel gesture is currently active. */
64
- wheelGestureActive = false;
65
- /** Current requestAnimationFrame ID. */
66
- rafId = 0;
67
- constructor(options) {
68
- this.options = options;
69
- }
70
- /** Read minZoom lazily so option changes take effect immediately. */
71
- get minZoom() {
72
- return this.options.minZoom ?? import_constants.MIN_ZOOM;
73
- }
74
- /** Read maxZoom lazily so option changes take effect immediately. */
75
- get maxZoom() {
76
- return this.options.maxZoom ?? import_constants.MAX_ZOOM;
77
- }
78
- /** Read zoomSpeed lazily so option changes take effect immediately. */
79
- get zoomSpeed() {
80
- return this.options.zoomSpeed ?? import_constants.DEFAULT_WHEEL_ZOOM_SPEED;
81
- }
82
- /** Read keyboardStep lazily so option changes take effect immediately. */
83
- get keyboardStep() {
84
- return this.options.keyboardStep ?? import_constants.DEFAULT_KEYBOARD_STEP;
85
- }
86
- /**
87
- * Get the keyboard pan step, including modifier-based coarse movement.
88
- *
89
- * @param event The native KeyboardEvent.
90
- * @return The normalized pan step.
91
- */
92
- getKeyboardStep(event) {
93
- return event.shiftKey ? this.keyboardStep * import_constants.KEYBOARD_SHIFT_STEP_MULTIPLIER : this.keyboardStep;
94
- }
95
- /** Read doubleTapZoom lazily so option changes take effect immediately. */
96
- get doubleTapZoom() {
97
- return this.options.doubleTapZoom ?? 2;
98
- }
99
- /**
100
- * Update the drag/zoom status and notify via callback if changed.
101
- *
102
- * @param update Partial status with isDragging and/or isZooming.
103
- */
104
- setStatus(update) {
105
- let changed = false;
106
- if (update.isDragging !== void 0 && update.isDragging !== this.isDragging) {
107
- this.isDragging = update.isDragging;
108
- changed = true;
109
- }
110
- if (update.isZooming !== void 0 && update.isZooming !== this.isZooming) {
111
- this.isZooming = update.isZooming;
112
- changed = true;
113
- }
114
- if (changed) {
115
- this.options.onStatusChange?.({
116
- isDragging: this.isDragging,
117
- isZooming: this.isZooming
118
- });
119
- }
120
- }
121
- /**
122
- * Handle a pointer-down event on the container element.
123
- *
124
- * Initiates a drag (pan) interaction. Captures the pointer on the
125
- * provided element and registers pointermove/pointerup/lostpointercapture
126
- * listeners for the duration of the drag.
127
- *
128
- * @param e The native PointerEvent.
129
- * @param el The DOM element to capture the pointer on.
130
- */
131
- handlePointerDown(e, el) {
132
- if (e.button !== 0) {
133
- return;
134
- }
135
- if (e.pointerType === "touch") {
136
- return;
137
- }
138
- e.preventDefault();
139
- const ownerDoc = el.ownerDocument;
140
- if (ownerDoc?.activeElement instanceof HTMLElement && ownerDoc.activeElement !== el) {
141
- ownerDoc.activeElement.blur();
142
- }
143
- el.focus();
144
- el.setPointerCapture(e.pointerId);
145
- if (this.wheelGestureActive) {
146
- clearTimeout(this.wheelGestureTimer);
147
- this.wheelGestureActive = false;
148
- this.options.onGestureEnd?.();
149
- }
150
- this.setStatus({ isDragging: true });
151
- this.options.onGestureStart?.();
152
- const currentState = this.options.getState();
153
- this.drag = {
154
- startX: e.clientX,
155
- startY: e.clientY,
156
- startPanX: currentState.pan.x,
157
- startPanY: currentState.pan.y
158
- };
159
- const onPointerMove = (moveEvent) => {
160
- const drag = this.drag;
161
- if (!drag) {
162
- return;
163
- }
164
- const pe = moveEvent;
165
- cancelAnimationFrame(this.rafId);
166
- this.rafId = requestAnimationFrame(() => {
167
- const s = this.options.getState();
168
- const imgSize = this.options.getImageSize();
169
- const containerSize = this.options.getContainerSize();
170
- const panSize = imgSize ?? containerSize;
171
- const deltaX = panSize.width > 0 ? (pe.clientX - drag.startX) / panSize.width : 0;
172
- const deltaY = panSize.height > 0 ? (pe.clientY - drag.startY) / panSize.height : 0;
173
- const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
174
- {
175
- ...s,
176
- pan: {
177
- x: drag.startPanX + deltaX,
178
- y: drag.startPanY + deltaY
179
- }
180
- },
181
- getImageSizeFromState(s),
182
- s.cropRect
183
- );
184
- this.options.actions.setPan(newCrop);
185
- });
186
- };
187
- const removeListeners = () => {
188
- el.removeEventListener("pointermove", onPointerMove);
189
- el.removeEventListener("pointerup", onPointerUp);
190
- el.removeEventListener("lostpointercapture", onPointerUp);
191
- };
192
- const onPointerUp = () => {
193
- this.setStatus({ isDragging: false });
194
- this.options.onGestureEnd?.();
195
- this.drag = null;
196
- cancelAnimationFrame(this.rafId);
197
- removeListeners();
198
- this.pointerCleanup = null;
199
- };
200
- el.addEventListener("pointermove", onPointerMove);
201
- el.addEventListener("pointerup", onPointerUp);
202
- el.addEventListener("lostpointercapture", onPointerUp);
203
- this.pointerCleanup = removeListeners;
204
- }
205
- /**
206
- * Handle a wheel event on the container element.
207
- *
208
- * Implements focal-point zoom: the point under the cursor stays
209
- * stationary on screen while the zoom level changes.
210
- *
211
- * Must be registered with `{ passive: false }` to allow preventDefault.
212
- *
213
- * @param e The native WheelEvent.
214
- */
215
- handleWheel(e) {
216
- e.preventDefault();
217
- if (this.drag) {
218
- return;
219
- }
220
- if (!this.wheelGestureActive) {
221
- this.wheelGestureActive = true;
222
- this.options.onGestureStart?.();
223
- }
224
- clearTimeout(this.wheelGestureTimer);
225
- this.wheelGestureTimer = setTimeout(() => {
226
- this.wheelGestureActive = false;
227
- this.options.onGestureEnd?.();
228
- }, DOUBLE_TAP_TIME);
229
- const s = this.options.getState();
230
- const delta = -e.deltaY * this.zoomSpeed;
231
- const newZoom = Math.min(
232
- this.maxZoom,
233
- Math.max(this.minZoom, s.zoom + delta)
234
- );
235
- if (newZoom === s.zoom) {
236
- return;
237
- }
238
- const containerSize = this.options.getContainerSize();
239
- const imgSize = this.options.getImageSize();
240
- const visSize = imgSize ?? containerSize;
241
- const target = e.currentTarget;
242
- const rect = target instanceof Element ? target.getBoundingClientRect() : void 0;
243
- if (visSize.width > 0 && visSize.height > 0 && rect) {
244
- const fx = e.clientX - rect.left - containerSize.width / 2;
245
- const fy = e.clientY - rect.top - containerSize.height / 2;
246
- const zoomRatio = 1 - newZoom / s.zoom;
247
- const focalNormX = fx / visSize.width;
248
- const focalNormY = fy / visSize.height;
249
- const newCropX = s.pan.x + (focalNormX - s.pan.x) * zoomRatio;
250
- const newCropY = s.pan.y + (focalNormY - s.pan.y) * zoomRatio;
251
- const { pan: clampedCrop } = (0, import_containment.restrictPanZoom)(
252
- { ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },
253
- getImageSizeFromState(s),
254
- s.cropRect
255
- );
256
- this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
257
- } else {
258
- this.options.actions.setZoom(newZoom);
259
- }
260
- }
261
- /**
262
- * Handle a touch-start event on the container element.
263
- *
264
- * Supports single-finger pan, two-finger pinch zoom, and
265
- * double-tap to toggle between fit and 2x zoom. Registers
266
- * touchmove/touchend/touchcancel on the provided document for the
267
- * duration of the gesture.
268
- *
269
- * @param e The native TouchEvent.
270
- * @param containerRect The bounding rect of the container element.
271
- * @param doc The document to register move/end listeners on.
272
- * Defaults to globalThis.document. Pass the iframe's
273
- * contentDocument when running inside an iframe.
274
- */
275
- handleTouchStart(e, containerRect, doc = document) {
276
- if (this.touch && e.touches.length === 2) {
277
- const s = this.options.getState();
278
- const distance = getTouchDistance(e.touches[0], e.touches[1]);
279
- const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
280
- const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
281
- this.touch.didPinch = true;
282
- this.touch.startDistance = distance;
283
- this.touch.startZoom = s.zoom;
284
- this.touch.startPanX = s.pan.x;
285
- this.touch.startPanY = s.pan.y;
286
- this.touch.startMidX = midX;
287
- this.touch.startMidY = midY;
288
- this.touch.containerRect = containerRect;
289
- this.setStatus({ isDragging: false });
290
- return;
291
- }
292
- if (e.touches.length === 1) {
293
- const tapX = e.touches[0].clientX;
294
- const tapY = e.touches[0].clientY;
295
- if (this.tryDoubleTap(e, tapX, tapY, containerRect)) {
296
- return;
297
- }
298
- const currentState = this.options.getState();
299
- this.touch = {
300
- startDistance: 0,
301
- startZoom: currentState.zoom,
302
- lastTouchX: e.touches[0].clientX,
303
- lastTouchY: e.touches[0].clientY,
304
- startPanX: currentState.pan.x,
305
- startPanY: currentState.pan.y,
306
- containerRect,
307
- startMidX: 0,
308
- startMidY: 0,
309
- didPinch: false,
310
- moved: false
311
- };
312
- this.options.onGestureStart?.();
313
- } else if (e.touches.length === 2) {
314
- const currentState = this.options.getState();
315
- const distance = getTouchDistance(e.touches[0], e.touches[1]);
316
- const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
317
- const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
318
- this.touch = {
319
- startDistance: distance,
320
- startZoom: currentState.zoom,
321
- lastTouchX: 0,
322
- lastTouchY: 0,
323
- startPanX: currentState.pan.x,
324
- startPanY: currentState.pan.y,
325
- containerRect,
326
- startMidX: midX,
327
- startMidY: midY,
328
- didPinch: true,
329
- moved: false
330
- };
331
- this.options.onGestureStart?.();
332
- }
333
- const onTouchEnd = () => {
334
- this.touch = null;
335
- this.touchCleanup = null;
336
- cancelAnimationFrame(this.rafId);
337
- doc.removeEventListener("touchmove", this.handleTouchMove);
338
- doc.removeEventListener("touchend", onTouchEnd);
339
- doc.removeEventListener("touchcancel", onTouchEnd);
340
- this.setStatus({ isDragging: false });
341
- this.options.onGestureEnd?.();
342
- };
343
- this.touchCleanup?.();
344
- doc.addEventListener("touchmove", this.handleTouchMove, {
345
- passive: false
346
- });
347
- doc.addEventListener("touchend", onTouchEnd);
348
- doc.addEventListener("touchcancel", onTouchEnd);
349
- this.touchCleanup = onTouchEnd;
350
- }
351
- // Handle a touchmove event during an active touch gesture. Decides pinch
352
- // vs. pan based on current `moveEvent.touches.length`, so the gesture
353
- // can transition between modes without timing sensitivity (e.g. fingers
354
- // landing 0ms vs 200ms apart). Arrow-property binding so `this` stays
355
- // attached when used as an event listener.
356
- handleTouchMove = (moveEvent) => {
357
- const touch = this.touch;
358
- if (!touch) {
359
- return;
360
- }
361
- moveEvent.preventDefault();
362
- cancelAnimationFrame(this.rafId);
363
- this.rafId = requestAnimationFrame(() => {
364
- const s = this.options.getState();
365
- if (moveEvent.touches.length === 2) {
366
- if (!touch.didPinch) {
367
- touch.didPinch = true;
368
- touch.startDistance = getTouchDistance(
369
- moveEvent.touches[0],
370
- moveEvent.touches[1]
371
- );
372
- touch.startZoom = s.zoom;
373
- touch.startPanX = s.pan.x;
374
- touch.startPanY = s.pan.y;
375
- touch.startMidX = (moveEvent.touches[0].clientX + moveEvent.touches[1].clientX) / 2;
376
- touch.startMidY = (moveEvent.touches[0].clientY + moveEvent.touches[1].clientY) / 2;
377
- this.setStatus({ isDragging: false });
378
- return;
379
- }
380
- const latestContainerSize = this.options.getContainerSize();
381
- const latestImageSize = this.options.getImageSize();
382
- const t0 = moveEvent.touches[0];
383
- const t1 = moveEvent.touches[1];
384
- const currentDistance = getTouchDistance(t0, t1);
385
- const ratio = currentDistance / touch.startDistance;
386
- const newZoom = Math.min(
387
- this.maxZoom,
388
- Math.max(this.minZoom, touch.startZoom * ratio)
389
- );
390
- const visSize = latestImageSize ?? latestContainerSize;
391
- const rect = touch.containerRect;
392
- if (visSize.width > 0 && visSize.height > 0 && rect) {
393
- const mx = (t0.clientX + t1.clientX) / 2 - rect.left - latestContainerSize.width / 2;
394
- const my = (t0.clientY + t1.clientY) / 2 - rect.top - latestContainerSize.height / 2;
395
- const startMx = touch.startMidX - rect.left - latestContainerSize.width / 2;
396
- const startMy = touch.startMidY - rect.top - latestContainerSize.height / 2;
397
- const panDx = visSize.width > 0 ? (mx - startMx) / visSize.width : 0;
398
- const panDy = visSize.height > 0 ? (my - startMy) / visSize.height : 0;
399
- const zoomRatio = touch.startZoom !== 0 ? 1 - newZoom / touch.startZoom : 0;
400
- const startFocalNormX = startMx / visSize.width;
401
- const startFocalNormY = startMy / visSize.height;
402
- const newCropX = touch.startPanX + panDx + (startFocalNormX - touch.startPanX) * zoomRatio;
403
- const newCropY = touch.startPanY + panDy + (startFocalNormY - touch.startPanY) * zoomRatio;
404
- const { pan: clampedCrop } = (0, import_containment.restrictPanZoom)(
405
- {
406
- ...s,
407
- zoom: newZoom,
408
- pan: { x: newCropX, y: newCropY }
409
- },
410
- getImageSizeFromState(s),
411
- s.cropRect
412
- );
413
- this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
414
- } else if (newZoom !== s.zoom) {
415
- this.options.actions.setZoom(newZoom);
416
- }
417
- } else if (moveEvent.touches.length === 1 && !touch.didPinch) {
418
- if (!touch.moved) {
419
- touch.moved = true;
420
- this.setStatus({ isDragging: true });
421
- }
422
- const panImageSize = this.options.getImageSize();
423
- const panContainerSize = this.options.getContainerSize();
424
- const panSize = panImageSize ?? panContainerSize;
425
- const deltaX = panSize.width > 0 ? (moveEvent.touches[0].clientX - touch.lastTouchX) / panSize.width : 0;
426
- const deltaY = panSize.height > 0 ? (moveEvent.touches[0].clientY - touch.lastTouchY) / panSize.height : 0;
427
- const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
428
- {
429
- ...s,
430
- pan: {
431
- x: touch.startPanX + deltaX,
432
- y: touch.startPanY + deltaY
433
- }
434
- },
435
- getImageSizeFromState(s),
436
- s.cropRect
437
- );
438
- this.options.actions.setPan(newCrop);
439
- }
440
- });
441
- };
442
- // Handle double-tap-to-toggle-zoom. On a second tap within the configured
443
- // time/distance threshold, toggles zoom between `minZoom` and
444
- // `doubleTapZoom` around the tap point and dispatches. Returns `true` if
445
- // the tap was handled as a double-tap (caller should early-return),
446
- // `false` otherwise (caller proceeds with normal single-tap handling).
447
- // Either way, records the tap for next time.
448
- tryDoubleTap(e, tapX, tapY, containerRect) {
449
- const now = Date.now();
450
- const lastTap = this.lastTap;
451
- if (!lastTap) {
452
- this.lastTap = { time: now, x: tapX, y: tapY };
453
- return false;
454
- }
455
- const timeDelta = now - lastTap.time;
456
- const distDelta = Math.sqrt(
457
- (tapX - lastTap.x) ** 2 + (tapY - lastTap.y) ** 2
458
- );
459
- const isDoubleTap = timeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;
460
- if (!isDoubleTap) {
461
- this.lastTap = { time: now, x: tapX, y: tapY };
462
- return false;
463
- }
464
- e.preventDefault();
465
- this.lastTap = null;
466
- const currentState = this.options.getState();
467
- const containerSize = this.options.getContainerSize();
468
- const imgSize = this.options.getImageSize();
469
- const targetZoom = currentState.zoom > (this.minZoom + this.doubleTapZoom) / 2 ? this.minZoom : this.doubleTapZoom;
470
- const visSize = imgSize ?? containerSize;
471
- this.setStatus({ isZooming: true });
472
- clearTimeout(this.zoomTimer);
473
- this.zoomTimer = setTimeout(() => {
474
- this.setStatus({ isZooming: false });
475
- }, ZOOM_ANIMATION_DURATION);
476
- this.options.onGestureStart?.();
477
- if (visSize.width > 0 && visSize.height > 0) {
478
- const fx = tapX - containerRect.left - containerSize.width / 2;
479
- const fy = tapY - containerRect.top - containerSize.height / 2;
480
- const zoomRatio = 1 - targetZoom / currentState.zoom;
481
- const focalNormX = fx / visSize.width;
482
- const focalNormY = fy / visSize.height;
483
- const newCropX = currentState.pan.x + (focalNormX - currentState.pan.x) * zoomRatio;
484
- const newCropY = currentState.pan.y + (focalNormY - currentState.pan.y) * zoomRatio;
485
- const { pan: clampedCrop } = (0, import_containment.restrictPanZoom)(
486
- {
487
- ...currentState,
488
- zoom: targetZoom,
489
- pan: { x: newCropX, y: newCropY }
490
- },
491
- getImageSizeFromState(currentState),
492
- currentState.cropRect
493
- );
494
- this.options.actions.setZoomAtPoint(targetZoom, clampedCrop);
495
- } else {
496
- this.options.actions.setZoom(targetZoom);
497
- }
498
- this.options.onGestureEnd?.();
499
- return true;
500
- }
501
- /**
502
- * Handle a keydown event on the container element.
503
- *
504
- * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.
505
- *
506
- * @param e The native KeyboardEvent.
507
- */
508
- handleKeyDown(e) {
509
- const currentState = this.options.getState();
510
- switch (e.key) {
511
- case "ArrowUp": {
512
- e.preventDefault();
513
- const keyboardStep = this.getKeyboardStep(e);
514
- const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
515
- {
516
- ...currentState,
517
- pan: {
518
- x: currentState.pan.x,
519
- y: currentState.pan.y + keyboardStep
520
- }
521
- },
522
- getImageSizeFromState(currentState),
523
- currentState.cropRect
524
- );
525
- this.options.actions.setPan(newCrop);
526
- break;
527
- }
528
- case "ArrowDown": {
529
- e.preventDefault();
530
- const keyboardStep = this.getKeyboardStep(e);
531
- const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
532
- {
533
- ...currentState,
534
- pan: {
535
- x: currentState.pan.x,
536
- y: currentState.pan.y - keyboardStep
537
- }
538
- },
539
- getImageSizeFromState(currentState),
540
- currentState.cropRect
541
- );
542
- this.options.actions.setPan(newCrop);
543
- break;
544
- }
545
- case "ArrowLeft": {
546
- e.preventDefault();
547
- const keyboardStep = this.getKeyboardStep(e);
548
- const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
549
- {
550
- ...currentState,
551
- pan: {
552
- x: currentState.pan.x + keyboardStep,
553
- y: currentState.pan.y
554
- }
555
- },
556
- getImageSizeFromState(currentState),
557
- currentState.cropRect
558
- );
559
- this.options.actions.setPan(newCrop);
560
- break;
561
- }
562
- case "ArrowRight": {
563
- e.preventDefault();
564
- const keyboardStep = this.getKeyboardStep(e);
565
- const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
566
- {
567
- ...currentState,
568
- pan: {
569
- x: currentState.pan.x - keyboardStep,
570
- y: currentState.pan.y
571
- }
572
- },
573
- getImageSizeFromState(currentState),
574
- currentState.cropRect
575
- );
576
- this.options.actions.setPan(newCrop);
577
- break;
578
- }
579
- case "+":
580
- case "=": {
581
- e.preventDefault();
582
- const newZoom = Math.min(
583
- this.maxZoom,
584
- Math.max(this.minZoom, currentState.zoom + 0.5)
585
- );
586
- this.options.actions.setZoom(newZoom);
587
- break;
588
- }
589
- case "-":
590
- case "_": {
591
- e.preventDefault();
592
- const newZoom = Math.min(
593
- this.maxZoom,
594
- Math.max(this.minZoom, currentState.zoom - 0.5)
595
- );
596
- this.options.actions.setZoom(newZoom);
597
- break;
598
- }
599
- case "r":
600
- case "R": {
601
- if (e.metaKey || e.ctrlKey || e.altKey) {
602
- break;
603
- }
604
- e.preventDefault();
605
- this.options.actions.snapRotate90(e.shiftKey ? -1 : 1);
606
- break;
607
- }
608
- case "h":
609
- case "H": {
610
- if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
611
- break;
612
- }
613
- e.preventDefault();
614
- this.options.actions.toggleFlip?.("horizontal");
615
- break;
616
- }
617
- case "v":
618
- case "V": {
619
- if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
620
- break;
621
- }
622
- e.preventDefault();
623
- this.options.actions.toggleFlip?.("vertical");
624
- break;
625
- }
626
- }
627
- }
628
- /**
629
- * Clean up all timers, animation frames, and active touch listeners.
630
- *
631
- * Must be called when the controller is no longer needed (e.g., on
632
- * component unmount or element removal).
633
- */
634
- destroy() {
635
- cancelAnimationFrame(this.rafId);
636
- clearTimeout(this.zoomTimer);
637
- clearTimeout(this.wheelGestureTimer);
638
- this.touchCleanup?.();
639
- this.touchCleanup = null;
640
- this.pointerCleanup?.();
641
- this.pointerCleanup = null;
642
- this.drag = null;
643
- this.touch = null;
644
- this.lastTap = null;
645
- this.wheelGestureActive = false;
646
- this.isDragging = false;
647
- this.isZooming = false;
648
- }
649
- };
650
- // Annotate the CommonJS export names for ESM import in node:
651
- 0 && (module.exports = {
652
- InteractionController
653
- });
654
- //# sourceMappingURL=interaction-controller.cjs.map