@wordpress/media-editor 0.22.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 (353) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/components/media-editor/index.cjs +74 -21
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +23 -3
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +6 -11
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +17 -1
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +4 -5
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +1 -0
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs.map +1 -1
  19. package/build/components/media-form/index.cjs +7 -1
  20. package/build/components/media-form/index.cjs.map +1 -1
  21. package/build/components/media-preview/index.cjs +0 -1
  22. package/build/components/media-preview/index.cjs.map +1 -1
  23. package/build/state/aspect-ratio-presets.cjs +10 -4
  24. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  25. package/build/state/composite-reducer.cjs +32 -67
  26. package/build/state/composite-reducer.cjs.map +1 -1
  27. package/build/state/index.cjs +0 -39
  28. package/build/state/types.cjs +1 -2
  29. package/build/state/types.cjs.map +1 -1
  30. package/build/state/use-media-editor-state.cjs +70 -106
  31. package/build/state/use-media-editor-state.cjs.map +1 -1
  32. package/build-module/components/media-editor/index.mjs +78 -25
  33. package/build-module/components/media-editor/index.mjs.map +1 -1
  34. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  35. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  36. package/build-module/components/media-editor/use-save-media-editor.mjs +23 -3
  37. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  38. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  39. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  40. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  41. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  42. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  43. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  44. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  45. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  46. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +1 -0
  47. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  48. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  49. package/build-module/components/media-form/index.mjs +7 -1
  50. package/build-module/components/media-form/index.mjs.map +1 -1
  51. package/build-module/components/media-preview/index.mjs +0 -1
  52. package/build-module/components/media-preview/index.mjs.map +1 -1
  53. package/build-module/state/aspect-ratio-presets.mjs +10 -5
  54. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  55. package/build-module/state/composite-reducer.mjs +32 -67
  56. package/build-module/state/composite-reducer.mjs.map +1 -1
  57. package/build-module/state/index.mjs +2 -5
  58. package/build-module/state/types.mjs +1 -2
  59. package/build-module/state/types.mjs.map +1 -1
  60. package/build-module/state/use-media-editor-state.mjs +70 -105
  61. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  62. package/build-style/style-rtl.css +104 -57
  63. package/build-style/style.css +103 -57
  64. package/build-types/components/media-editor/index.d.ts +17 -3
  65. package/build-types/components/media-editor/index.d.ts.map +1 -1
  66. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  67. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  68. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  69. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  70. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  71. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  72. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  73. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  74. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  75. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  76. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  77. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  78. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  79. package/build-types/components/media-form/index.d.ts.map +1 -1
  80. package/build-types/components/media-preview/index.d.ts.map +1 -1
  81. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  82. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  83. package/build-types/state/composite-reducer.d.ts +17 -19
  84. package/build-types/state/composite-reducer.d.ts.map +1 -1
  85. package/build-types/state/index.d.ts +2 -5
  86. package/build-types/state/index.d.ts.map +1 -1
  87. package/build-types/state/types.d.ts +20 -64
  88. package/build-types/state/types.d.ts.map +1 -1
  89. package/build-types/state/use-media-editor-state.d.ts +33 -52
  90. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  91. package/package.json +22 -23
  92. package/src/components/media-editor/index.tsx +163 -28
  93. package/src/components/media-editor/use-crop-options.ts +7 -11
  94. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  95. package/src/components/media-editor-canvas/index.tsx +15 -26
  96. package/src/components/media-editor-canvas/style.scss +6 -6
  97. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  98. package/src/components/media-editor-crop-panel/style.scss +21 -0
  99. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  100. package/src/components/media-editor-image-controls/index.tsx +11 -9
  101. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
  102. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  103. package/src/components/media-editor-modal/index.tsx +1 -1
  104. package/src/components/media-form/index.tsx +7 -1
  105. package/src/components/media-preview/index.tsx +0 -1
  106. package/src/components/rotation-ruler/style.scss +3 -3
  107. package/src/state/README.md +32 -0
  108. package/src/state/aspect-ratio-presets.ts +22 -3
  109. package/src/state/composite-reducer.ts +42 -80
  110. package/src/state/index.ts +2 -18
  111. package/src/state/types.ts +18 -68
  112. package/src/state/use-media-editor-state.ts +155 -240
  113. package/src/style.scss +2 -1
  114. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  115. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  116. package/build/image-editor/core/camera.cjs +0 -277
  117. package/build/image-editor/core/camera.cjs.map +0 -1
  118. package/build/image-editor/core/constants.cjs +0 -133
  119. package/build/image-editor/core/constants.cjs.map +0 -1
  120. package/build/image-editor/core/containment.cjs +0 -289
  121. package/build/image-editor/core/containment.cjs.map +0 -1
  122. package/build/image-editor/core/crop-rect.cjs +0 -37
  123. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  124. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  125. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  126. package/build/image-editor/core/index.cjs +0 -89
  127. package/build/image-editor/core/interaction-controller.cjs +0 -591
  128. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  129. package/build/image-editor/core/math/rotation.cjs +0 -32
  130. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  131. package/build/image-editor/core/math/sanitize.cjs +0 -136
  132. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  133. package/build/image-editor/core/setter-helpers.cjs +0 -61
  134. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  135. package/build/image-editor/core/source-region.cjs +0 -236
  136. package/build/image-editor/core/source-region.cjs.map +0 -1
  137. package/build/image-editor/core/state.cjs +0 -296
  138. package/build/image-editor/core/state.cjs.map +0 -1
  139. package/build/image-editor/core/stencil-math.cjs +0 -203
  140. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  141. package/build/image-editor/core/transform-style.cjs +0 -43
  142. package/build/image-editor/core/transform-style.cjs.map +0 -1
  143. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  144. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  145. package/build/image-editor/core/types.cjs +0 -5
  146. package/build/image-editor/core/viewport-state.cjs +0 -36
  147. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  148. package/build/image-editor/index.cjs +0 -68
  149. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  150. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  151. package/build/image-editor/react/components/cropper.cjs +0 -595
  152. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  153. package/build/image-editor/react/components/index.cjs +0 -25
  154. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  155. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  156. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  157. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  158. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  159. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  160. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  161. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  162. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  163. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  164. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  165. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  166. package/build/image-editor/react/hooks/index.cjs +0 -19
  167. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  168. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  169. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  170. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  171. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  172. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  173. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  174. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  175. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  176. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  177. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  178. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  179. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  180. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  181. package/build-module/image-editor/core/camera.mjs +0 -265
  182. package/build-module/image-editor/core/camera.mjs.map +0 -1
  183. package/build-module/image-editor/core/constants.mjs +0 -115
  184. package/build-module/image-editor/core/constants.mjs.map +0 -1
  185. package/build-module/image-editor/core/containment.mjs +0 -281
  186. package/build-module/image-editor/core/containment.mjs.map +0 -1
  187. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  188. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  189. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  190. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  191. package/build-module/image-editor/core/index.mjs +0 -7
  192. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  193. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  194. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  195. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  196. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  197. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  198. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  199. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  200. package/build-module/image-editor/core/source-region.mjs +0 -228
  201. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  202. package/build-module/image-editor/core/state.mjs +0 -288
  203. package/build-module/image-editor/core/state.mjs.map +0 -1
  204. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  205. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  206. package/build-module/image-editor/core/transform-style.mjs +0 -38
  207. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  208. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  209. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  210. package/build-module/image-editor/core/types.mjs +0 -0
  211. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  212. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  213. package/build-module/image-editor/index.mjs +0 -4
  214. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  215. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  216. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  217. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  218. package/build-module/image-editor/react/components/index.mjs +0 -3
  219. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  220. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  221. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  222. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  223. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  224. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  225. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  226. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  227. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  228. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  229. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  230. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  231. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  232. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  233. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  234. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  235. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  236. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  237. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  238. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  239. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  240. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  241. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  242. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  243. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  244. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  245. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  246. package/build-types/image-editor/core/camera.d.ts +0 -128
  247. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  248. package/build-types/image-editor/core/constants.d.ts +0 -98
  249. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  250. package/build-types/image-editor/core/containment.d.ts +0 -72
  251. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  252. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  253. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  254. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  255. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  256. package/build-types/image-editor/core/index.d.ts +0 -10
  257. package/build-types/image-editor/core/index.d.ts.map +0 -1
  258. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  259. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  260. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  261. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  262. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  263. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  264. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  265. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  266. package/build-types/image-editor/core/source-region.d.ts +0 -94
  267. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  268. package/build-types/image-editor/core/state.d.ts +0 -51
  269. package/build-types/image-editor/core/state.d.ts.map +0 -1
  270. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  271. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  272. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  273. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  274. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  275. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  276. package/build-types/image-editor/core/types.d.ts +0 -269
  277. package/build-types/image-editor/core/types.d.ts.map +0 -1
  278. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  279. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  280. package/build-types/image-editor/index.d.ts +0 -17
  281. package/build-types/image-editor/index.d.ts.map +0 -1
  282. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  283. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  284. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  285. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  286. package/build-types/image-editor/react/components/index.d.ts +0 -4
  287. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  288. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  289. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  290. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  291. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  292. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  293. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  294. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  295. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  296. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  297. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  298. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  299. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  300. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  301. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  302. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  303. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  304. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  305. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  306. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  307. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  308. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  309. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  310. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  311. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  312. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  313. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  314. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  315. package/src/image-editor/README.md +0 -61
  316. package/src/image-editor/core/camera.ts +0 -429
  317. package/src/image-editor/core/constants.ts +0 -137
  318. package/src/image-editor/core/containment.ts +0 -469
  319. package/src/image-editor/core/crop-rect.ts +0 -42
  320. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  321. package/src/image-editor/core/index.ts +0 -43
  322. package/src/image-editor/core/interaction-controller.ts +0 -976
  323. package/src/image-editor/core/math/rotation.ts +0 -26
  324. package/src/image-editor/core/math/sanitize.ts +0 -155
  325. package/src/image-editor/core/setter-helpers.ts +0 -63
  326. package/src/image-editor/core/source-region.ts +0 -367
  327. package/src/image-editor/core/state.ts +0 -484
  328. package/src/image-editor/core/stencil-math.ts +0 -379
  329. package/src/image-editor/core/transform-style.ts +0 -56
  330. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  331. package/src/image-editor/core/types.ts +0 -230
  332. package/src/image-editor/core/viewport-state.ts +0 -30
  333. package/src/image-editor/docs/architecture.md +0 -63
  334. package/src/image-editor/docs/recipes.md +0 -184
  335. package/src/image-editor/index.ts +0 -43
  336. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  337. package/src/image-editor/react/components/cropper.scss +0 -259
  338. package/src/image-editor/react/components/cropper.tsx +0 -1108
  339. package/src/image-editor/react/components/index.ts +0 -3
  340. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  341. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  342. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  343. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  344. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  345. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  346. package/src/image-editor/react/hooks/index.ts +0 -4
  347. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  348. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  349. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  350. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  351. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  352. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  353. package/src/image-editor/style.scss +0 -1
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperties(exports, {
3
- __esModule: { value: true },
4
- [Symbol.toStringTag]: { value: "Module" }
5
- });
6
- let __constants_ts = require("./constants.cjs");
7
- let __state_ts = require("./state.cjs");
8
- let __source_region_ts = require("./source-region.cjs");
9
- let __crop_rect_ts = require("./crop-rect.cjs");
10
- let __transforms_pipeline_ts = require("./transforms/pipeline.cjs");
11
- let __export_canvas_renderer_ts = require("./export/canvas-renderer.cjs");
12
- Object.defineProperty(exports, "DEFAULT_STATE", {
13
- enumerable: true,
14
- get: function() {
15
- return __constants_ts.DEFAULT_STATE;
16
- }
17
- });
18
- Object.defineProperty(exports, "ORIGINAL_ASPECT_RATIO", {
19
- enumerable: true,
20
- get: function() {
21
- return __constants_ts.ORIGINAL_ASPECT_RATIO;
22
- }
23
- });
24
- Object.defineProperty(exports, "applyOperationToState", {
25
- enumerable: true,
26
- get: function() {
27
- return __transforms_pipeline_ts.applyOperationToState;
28
- }
29
- });
30
- Object.defineProperty(exports, "applyToCanvas", {
31
- enumerable: true,
32
- get: function() {
33
- return __export_canvas_renderer_ts.applyToCanvas;
34
- }
35
- });
36
- Object.defineProperty(exports, "areCropperStatesEqual", {
37
- enumerable: true,
38
- get: function() {
39
- return __state_ts.areCropperStatesEqual;
40
- }
41
- });
42
- Object.defineProperty(exports, "computeInscribedRect", {
43
- enumerable: true,
44
- get: function() {
45
- return __crop_rect_ts.computeInscribedRect;
46
- }
47
- });
48
- Object.defineProperty(exports, "cropperReducer", {
49
- enumerable: true,
50
- get: function() {
51
- return __state_ts.cropperReducer;
52
- }
53
- });
54
- Object.defineProperty(exports, "enforceContainment", {
55
- enumerable: true,
56
- get: function() {
57
- return __state_ts.enforceContainment;
58
- }
59
- });
60
- Object.defineProperty(exports, "exportCroppedImage", {
61
- enumerable: true,
62
- get: function() {
63
- return __export_canvas_renderer_ts.exportCroppedImage;
64
- }
65
- });
66
- Object.defineProperty(exports, "getSourceRegion", {
67
- enumerable: true,
68
- get: function() {
69
- return __source_region_ts.getSourceRegion;
70
- }
71
- });
72
- Object.defineProperty(exports, "getSourceRegionPercent", {
73
- enumerable: true,
74
- get: function() {
75
- return __source_region_ts.getSourceRegionPercent;
76
- }
77
- });
78
- Object.defineProperty(exports, "isStateDirty", {
79
- enumerable: true,
80
- get: function() {
81
- return __state_ts.isStateDirty;
82
- }
83
- });
84
- Object.defineProperty(exports, "stateFromPipeline", {
85
- enumerable: true,
86
- get: function() {
87
- return __transforms_pipeline_ts.stateFromPipeline;
88
- }
89
- });
@@ -1,591 +0,0 @@
1
- "use strict";
2
- Object.defineProperties(exports, {
3
- __esModule: { value: true },
4
- [Symbol.toStringTag]: { value: "Module" }
5
- });
6
- let __constants_ts = require("./constants.cjs");
7
- let __containment_ts = require("./containment.cjs");
8
- // packages/media-editor/src/image-editor/core/interaction-controller.ts
9
- /** Time window for detecting a double-tap gesture (ms). */
10
- const DOUBLE_TAP_TIME = 300;
11
- /** Max distance between taps to count as a double-tap (px). */
12
- const DOUBLE_TAP_DISTANCE = 30;
13
- /** Duration of the zoom animation state (ms). */
14
- const ZOOM_ANIMATION_DURATION = 200;
15
- /**
16
- * Get the natural image dimensions from cropper state, falling back to 1x1.
17
- *
18
- * @param state The current cropper state.
19
- * @return The image dimensions.
20
- */
21
- function getImageSizeFromState(state) {
22
- return state.image ? {
23
- width: state.image.naturalWidth,
24
- height: state.image.naturalHeight
25
- } : {
26
- width: 1,
27
- height: 1
28
- };
29
- }
30
- /**
31
- * Get the distance between two touch points.
32
- *
33
- * @param t1 The first touch.
34
- * @param t2 The second touch.
35
- * @return The pixel distance between the two touches.
36
- */
37
- function getTouchDistance(t1, t2) {
38
- const dx = t1.clientX - t2.clientX;
39
- const dy = t1.clientY - t2.clientY;
40
- return Math.sqrt(dx * dx + dy * dy);
41
- }
42
- /**
43
- * Framework-agnostic imperative controller for image cropper interactions.
44
- *
45
- * Handles mouse, touch, and keyboard event processing for pan, zoom,
46
- * and crop manipulation. Uses requestAnimationFrame for drag/pinch
47
- * updates to avoid layout thrashing.
48
- *
49
- * The controller does not register DOM event listeners itself — that is the
50
- * responsibility of the UI layer (React hook, Vue directive, or vanilla JS).
51
- * Instead it exposes `handlePointerDown`, `handleWheel`, `handleTouchStart`,
52
- * and `handleKeyDown` methods that the UI layer calls with native DOM events.
53
- *
54
- * Scalar options (minZoom, maxZoom, zoomSpeed, keyboardStep, doubleTapZoom)
55
- * are read lazily from `this.options` on each interaction, so the UI layer
56
- * can update them without recreating the controller.
57
- *
58
- * Call `destroy()` to clean up timers and pending animation frames.
59
- */
60
- var InteractionController = class {
61
- options;
62
- /** Current drag/zoom status. */
63
- isDragging = false;
64
- isZooming = false;
65
- /** Active drag state during pointer interactions. */
66
- drag = null;
67
- /** Active touch state during touch interactions. */
68
- touch = null;
69
- /** Cleanup function for active touch listeners on document. */
70
- touchCleanup = null;
71
- /**
72
- * Cleanup function for active pointer-drag listeners on the
73
- * captured element. Set while a pointer drag is in progress so
74
- * `destroy()` can tear the drag down cleanly if the consumer
75
- * unmounts mid-drag. Cleared on pointerup/lostpointercapture.
76
- */
77
- pointerCleanup = null;
78
- /** Last tap info for double-tap detection. */
79
- lastTap = null;
80
- /** Timer for the zoom animation state (double-tap). */
81
- zoomTimer;
82
- /** Timer for wheel gesture debounce. */
83
- wheelGestureTimer;
84
- /** Whether a wheel gesture is currently active. */
85
- wheelGestureActive = false;
86
- /** Current requestAnimationFrame ID. */
87
- rafId = 0;
88
- constructor(options) {
89
- this.options = options;
90
- }
91
- /** Read minZoom lazily so option changes take effect immediately. */
92
- get minZoom() {
93
- return this.options.minZoom ?? __constants_ts.MIN_ZOOM;
94
- }
95
- /** Read maxZoom lazily so option changes take effect immediately. */
96
- get maxZoom() {
97
- return this.options.maxZoom ?? __constants_ts.MAX_ZOOM;
98
- }
99
- /** Read zoomSpeed lazily so option changes take effect immediately. */
100
- get zoomSpeed() {
101
- return this.options.zoomSpeed ?? __constants_ts.DEFAULT_WHEEL_ZOOM_SPEED;
102
- }
103
- /** Read keyboardStep lazily so option changes take effect immediately. */
104
- get keyboardStep() {
105
- return this.options.keyboardStep ?? __constants_ts.DEFAULT_KEYBOARD_STEP;
106
- }
107
- /**
108
- * Get the keyboard pan step, including modifier-based coarse movement.
109
- *
110
- * @param event The native KeyboardEvent.
111
- * @return The normalized pan step.
112
- */
113
- getKeyboardStep(event) {
114
- return event.shiftKey ? this.keyboardStep * __constants_ts.KEYBOARD_SHIFT_STEP_MULTIPLIER : this.keyboardStep;
115
- }
116
- /** Read doubleTapZoom lazily so option changes take effect immediately. */
117
- get doubleTapZoom() {
118
- return this.options.doubleTapZoom ?? 2;
119
- }
120
- /**
121
- * Update the drag/zoom status and notify via callback if changed.
122
- *
123
- * @param update Partial status with isDragging and/or isZooming.
124
- */
125
- setStatus(update) {
126
- let changed = false;
127
- if (update.isDragging !== void 0 && update.isDragging !== this.isDragging) {
128
- this.isDragging = update.isDragging;
129
- changed = true;
130
- }
131
- if (update.isZooming !== void 0 && update.isZooming !== this.isZooming) {
132
- this.isZooming = update.isZooming;
133
- changed = true;
134
- }
135
- if (changed) this.options.onStatusChange?.({
136
- isDragging: this.isDragging,
137
- isZooming: this.isZooming
138
- });
139
- }
140
- /**
141
- * Handle a pointer-down event on the container element.
142
- *
143
- * Initiates a drag (pan) interaction. Captures the pointer on the
144
- * provided element and registers pointermove/pointerup/lostpointercapture
145
- * listeners for the duration of the drag.
146
- *
147
- * @param e The native PointerEvent.
148
- * @param el The DOM element to capture the pointer on.
149
- */
150
- handlePointerDown(e, el) {
151
- if (e.button !== 0) return;
152
- if (e.pointerType === "touch") return;
153
- e.preventDefault();
154
- const ownerDoc = el.ownerDocument;
155
- if (ownerDoc?.activeElement instanceof HTMLElement && ownerDoc.activeElement !== el) ownerDoc.activeElement.blur();
156
- el.focus();
157
- el.setPointerCapture(e.pointerId);
158
- if (this.wheelGestureActive) {
159
- clearTimeout(this.wheelGestureTimer);
160
- this.wheelGestureActive = false;
161
- this.options.onGestureEnd?.();
162
- }
163
- this.setStatus({ isDragging: true });
164
- this.options.onGestureStart?.();
165
- const currentState = this.options.getState();
166
- this.drag = {
167
- startX: e.clientX,
168
- startY: e.clientY,
169
- startPanX: currentState.pan.x,
170
- startPanY: currentState.pan.y
171
- };
172
- const onPointerMove = (moveEvent) => {
173
- const drag = this.drag;
174
- if (!drag) return;
175
- const pe = moveEvent;
176
- cancelAnimationFrame(this.rafId);
177
- this.rafId = requestAnimationFrame(() => {
178
- const s = this.options.getState();
179
- const imgSize = this.options.getImageSize();
180
- const containerSize = this.options.getContainerSize();
181
- const panSize = imgSize ?? containerSize;
182
- const deltaX = panSize.width > 0 ? (pe.clientX - drag.startX) / panSize.width : 0;
183
- const deltaY = panSize.height > 0 ? (pe.clientY - drag.startY) / panSize.height : 0;
184
- const { pan: newCrop } = (0, __containment_ts.restrictPanZoom)({
185
- ...s,
186
- pan: {
187
- x: drag.startPanX + deltaX,
188
- y: drag.startPanY + deltaY
189
- }
190
- }, getImageSizeFromState(s), s.cropRect);
191
- this.options.actions.setPan(newCrop);
192
- });
193
- };
194
- const removeListeners = () => {
195
- el.removeEventListener("pointermove", onPointerMove);
196
- el.removeEventListener("pointerup", onPointerUp);
197
- el.removeEventListener("lostpointercapture", onPointerUp);
198
- };
199
- const onPointerUp = () => {
200
- this.setStatus({ isDragging: false });
201
- this.options.onGestureEnd?.();
202
- this.drag = null;
203
- cancelAnimationFrame(this.rafId);
204
- removeListeners();
205
- this.pointerCleanup = null;
206
- };
207
- el.addEventListener("pointermove", onPointerMove);
208
- el.addEventListener("pointerup", onPointerUp);
209
- el.addEventListener("lostpointercapture", onPointerUp);
210
- this.pointerCleanup = removeListeners;
211
- }
212
- /**
213
- * Handle a wheel event on the container element.
214
- *
215
- * Implements focal-point zoom: the point under the cursor stays
216
- * stationary on screen while the zoom level changes.
217
- *
218
- * Must be registered with `{ passive: false }` to allow preventDefault.
219
- *
220
- * @param e The native WheelEvent.
221
- */
222
- handleWheel(e) {
223
- e.preventDefault();
224
- if (this.drag) return;
225
- if (!this.wheelGestureActive) {
226
- this.wheelGestureActive = true;
227
- this.options.onGestureStart?.();
228
- }
229
- clearTimeout(this.wheelGestureTimer);
230
- this.wheelGestureTimer = setTimeout(() => {
231
- this.wheelGestureActive = false;
232
- this.options.onGestureEnd?.();
233
- }, DOUBLE_TAP_TIME);
234
- const s = this.options.getState();
235
- const delta = -e.deltaY * this.zoomSpeed;
236
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, s.zoom + delta));
237
- if (newZoom === s.zoom) return;
238
- const containerSize = this.options.getContainerSize();
239
- const visSize = this.options.getImageSize() ?? containerSize;
240
- const target = e.currentTarget;
241
- const rect = target instanceof Element ? target.getBoundingClientRect() : void 0;
242
- if (visSize.width > 0 && visSize.height > 0 && rect) {
243
- const fx = e.clientX - rect.left - containerSize.width / 2;
244
- const fy = e.clientY - rect.top - containerSize.height / 2;
245
- const zoomRatio = 1 - newZoom / s.zoom;
246
- const focalNormX = fx / visSize.width;
247
- const focalNormY = fy / visSize.height;
248
- const newCropX = s.pan.x + (focalNormX - s.pan.x) * zoomRatio;
249
- const newCropY = s.pan.y + (focalNormY - s.pan.y) * zoomRatio;
250
- const { pan: clampedCrop } = (0, __containment_ts.restrictPanZoom)({
251
- ...s,
252
- zoom: newZoom,
253
- pan: {
254
- x: newCropX,
255
- y: newCropY
256
- }
257
- }, getImageSizeFromState(s), s.cropRect);
258
- this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
259
- } else this.options.actions.setZoom(newZoom);
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)) return;
296
- const currentState = this.options.getState();
297
- this.touch = {
298
- startDistance: 0,
299
- startZoom: currentState.zoom,
300
- lastTouchX: e.touches[0].clientX,
301
- lastTouchY: e.touches[0].clientY,
302
- startPanX: currentState.pan.x,
303
- startPanY: currentState.pan.y,
304
- containerRect,
305
- startMidX: 0,
306
- startMidY: 0,
307
- didPinch: false,
308
- moved: false
309
- };
310
- this.options.onGestureStart?.();
311
- } else if (e.touches.length === 2) {
312
- const currentState = this.options.getState();
313
- const distance = getTouchDistance(e.touches[0], e.touches[1]);
314
- const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
315
- const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
316
- this.touch = {
317
- startDistance: distance,
318
- startZoom: currentState.zoom,
319
- lastTouchX: 0,
320
- lastTouchY: 0,
321
- startPanX: currentState.pan.x,
322
- startPanY: currentState.pan.y,
323
- containerRect,
324
- startMidX: midX,
325
- startMidY: midY,
326
- didPinch: true,
327
- moved: false
328
- };
329
- this.options.onGestureStart?.();
330
- }
331
- const onTouchEnd = () => {
332
- this.touch = null;
333
- this.touchCleanup = null;
334
- cancelAnimationFrame(this.rafId);
335
- doc.removeEventListener("touchmove", this.handleTouchMove);
336
- doc.removeEventListener("touchend", onTouchEnd);
337
- doc.removeEventListener("touchcancel", onTouchEnd);
338
- this.setStatus({ isDragging: false });
339
- this.options.onGestureEnd?.();
340
- };
341
- this.touchCleanup?.();
342
- doc.addEventListener("touchmove", this.handleTouchMove, { passive: false });
343
- doc.addEventListener("touchend", onTouchEnd);
344
- doc.addEventListener("touchcancel", onTouchEnd);
345
- this.touchCleanup = onTouchEnd;
346
- }
347
- handleTouchMove = (moveEvent) => {
348
- const touch = this.touch;
349
- if (!touch) return;
350
- moveEvent.preventDefault();
351
- cancelAnimationFrame(this.rafId);
352
- this.rafId = requestAnimationFrame(() => {
353
- const s = this.options.getState();
354
- if (moveEvent.touches.length === 2) {
355
- if (!touch.didPinch) {
356
- touch.didPinch = true;
357
- touch.startDistance = getTouchDistance(moveEvent.touches[0], moveEvent.touches[1]);
358
- touch.startZoom = s.zoom;
359
- touch.startPanX = s.pan.x;
360
- touch.startPanY = s.pan.y;
361
- touch.startMidX = (moveEvent.touches[0].clientX + moveEvent.touches[1].clientX) / 2;
362
- touch.startMidY = (moveEvent.touches[0].clientY + moveEvent.touches[1].clientY) / 2;
363
- this.setStatus({ isDragging: false });
364
- return;
365
- }
366
- const latestContainerSize = this.options.getContainerSize();
367
- const latestImageSize = this.options.getImageSize();
368
- const t0 = moveEvent.touches[0];
369
- const t1 = moveEvent.touches[1];
370
- const ratio = getTouchDistance(t0, t1) / touch.startDistance;
371
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, touch.startZoom * ratio));
372
- const visSize = latestImageSize ?? latestContainerSize;
373
- const rect = touch.containerRect;
374
- if (visSize.width > 0 && visSize.height > 0 && rect) {
375
- const mx = (t0.clientX + t1.clientX) / 2 - rect.left - latestContainerSize.width / 2;
376
- const my = (t0.clientY + t1.clientY) / 2 - rect.top - latestContainerSize.height / 2;
377
- const startMx = touch.startMidX - rect.left - latestContainerSize.width / 2;
378
- const startMy = touch.startMidY - rect.top - latestContainerSize.height / 2;
379
- const panDx = visSize.width > 0 ? (mx - startMx) / visSize.width : 0;
380
- const panDy = visSize.height > 0 ? (my - startMy) / visSize.height : 0;
381
- const zoomRatio = touch.startZoom !== 0 ? 1 - newZoom / touch.startZoom : 0;
382
- const startFocalNormX = startMx / visSize.width;
383
- const startFocalNormY = startMy / visSize.height;
384
- const newCropX = touch.startPanX + panDx + (startFocalNormX - touch.startPanX) * zoomRatio;
385
- const newCropY = touch.startPanY + panDy + (startFocalNormY - touch.startPanY) * zoomRatio;
386
- const { pan: clampedCrop } = (0, __containment_ts.restrictPanZoom)({
387
- ...s,
388
- zoom: newZoom,
389
- pan: {
390
- x: newCropX,
391
- y: newCropY
392
- }
393
- }, getImageSizeFromState(s), s.cropRect);
394
- this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
395
- } else if (newZoom !== s.zoom) this.options.actions.setZoom(newZoom);
396
- } else if (moveEvent.touches.length === 1 && !touch.didPinch) {
397
- if (!touch.moved) {
398
- touch.moved = true;
399
- this.setStatus({ isDragging: true });
400
- }
401
- const panImageSize = this.options.getImageSize();
402
- const panContainerSize = this.options.getContainerSize();
403
- const panSize = panImageSize ?? panContainerSize;
404
- const deltaX = panSize.width > 0 ? (moveEvent.touches[0].clientX - touch.lastTouchX) / panSize.width : 0;
405
- const deltaY = panSize.height > 0 ? (moveEvent.touches[0].clientY - touch.lastTouchY) / panSize.height : 0;
406
- const { pan: newCrop } = (0, __containment_ts.restrictPanZoom)({
407
- ...s,
408
- pan: {
409
- x: touch.startPanX + deltaX,
410
- y: touch.startPanY + deltaY
411
- }
412
- }, getImageSizeFromState(s), s.cropRect);
413
- this.options.actions.setPan(newCrop);
414
- }
415
- });
416
- };
417
- tryDoubleTap(e, tapX, tapY, containerRect) {
418
- const now = Date.now();
419
- const lastTap = this.lastTap;
420
- if (!lastTap) {
421
- this.lastTap = {
422
- time: now,
423
- x: tapX,
424
- y: tapY
425
- };
426
- return false;
427
- }
428
- const timeDelta = now - lastTap.time;
429
- const distDelta = Math.sqrt((tapX - lastTap.x) ** 2 + (tapY - lastTap.y) ** 2);
430
- if (!(timeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE)) {
431
- this.lastTap = {
432
- time: now,
433
- x: tapX,
434
- y: tapY
435
- };
436
- return false;
437
- }
438
- e.preventDefault();
439
- this.lastTap = null;
440
- const currentState = this.options.getState();
441
- const containerSize = this.options.getContainerSize();
442
- const imgSize = this.options.getImageSize();
443
- const targetZoom = currentState.zoom > (this.minZoom + this.doubleTapZoom) / 2 ? this.minZoom : this.doubleTapZoom;
444
- const visSize = imgSize ?? containerSize;
445
- this.setStatus({ isZooming: true });
446
- clearTimeout(this.zoomTimer);
447
- this.zoomTimer = setTimeout(() => {
448
- this.setStatus({ isZooming: false });
449
- }, ZOOM_ANIMATION_DURATION);
450
- this.options.onGestureStart?.();
451
- if (visSize.width > 0 && visSize.height > 0) {
452
- const fx = tapX - containerRect.left - containerSize.width / 2;
453
- const fy = tapY - containerRect.top - containerSize.height / 2;
454
- const zoomRatio = 1 - targetZoom / currentState.zoom;
455
- const focalNormX = fx / visSize.width;
456
- const focalNormY = fy / visSize.height;
457
- const newCropX = currentState.pan.x + (focalNormX - currentState.pan.x) * zoomRatio;
458
- const newCropY = currentState.pan.y + (focalNormY - currentState.pan.y) * zoomRatio;
459
- const { pan: clampedCrop } = (0, __containment_ts.restrictPanZoom)({
460
- ...currentState,
461
- zoom: targetZoom,
462
- pan: {
463
- x: newCropX,
464
- y: newCropY
465
- }
466
- }, getImageSizeFromState(currentState), currentState.cropRect);
467
- this.options.actions.setZoomAtPoint(targetZoom, clampedCrop);
468
- } else this.options.actions.setZoom(targetZoom);
469
- this.options.onGestureEnd?.();
470
- return true;
471
- }
472
- /**
473
- * Handle a keydown event on the container element.
474
- *
475
- * Supports arrow keys for panning, +/- for zoom, and r/R for rotation.
476
- *
477
- * @param e The native KeyboardEvent.
478
- */
479
- handleKeyDown(e) {
480
- const currentState = this.options.getState();
481
- switch (e.key) {
482
- case "ArrowUp": {
483
- e.preventDefault();
484
- const keyboardStep = this.getKeyboardStep(e);
485
- const { pan: newCrop } = (0, __containment_ts.restrictPanZoom)({
486
- ...currentState,
487
- pan: {
488
- x: currentState.pan.x,
489
- y: currentState.pan.y + keyboardStep
490
- }
491
- }, getImageSizeFromState(currentState), currentState.cropRect);
492
- this.options.actions.setPan(newCrop);
493
- break;
494
- }
495
- case "ArrowDown": {
496
- e.preventDefault();
497
- const keyboardStep = this.getKeyboardStep(e);
498
- const { pan: newCrop } = (0, __containment_ts.restrictPanZoom)({
499
- ...currentState,
500
- pan: {
501
- x: currentState.pan.x,
502
- y: currentState.pan.y - keyboardStep
503
- }
504
- }, getImageSizeFromState(currentState), currentState.cropRect);
505
- this.options.actions.setPan(newCrop);
506
- break;
507
- }
508
- case "ArrowLeft": {
509
- e.preventDefault();
510
- const keyboardStep = this.getKeyboardStep(e);
511
- const { pan: newCrop } = (0, __containment_ts.restrictPanZoom)({
512
- ...currentState,
513
- pan: {
514
- x: currentState.pan.x + keyboardStep,
515
- y: currentState.pan.y
516
- }
517
- }, getImageSizeFromState(currentState), currentState.cropRect);
518
- this.options.actions.setPan(newCrop);
519
- break;
520
- }
521
- case "ArrowRight": {
522
- e.preventDefault();
523
- const keyboardStep = this.getKeyboardStep(e);
524
- const { pan: newCrop } = (0, __containment_ts.restrictPanZoom)({
525
- ...currentState,
526
- pan: {
527
- x: currentState.pan.x - keyboardStep,
528
- y: currentState.pan.y
529
- }
530
- }, getImageSizeFromState(currentState), currentState.cropRect);
531
- this.options.actions.setPan(newCrop);
532
- break;
533
- }
534
- case "+":
535
- case "=": {
536
- e.preventDefault();
537
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, currentState.zoom + .5));
538
- this.options.actions.setZoom(newZoom);
539
- break;
540
- }
541
- case "-":
542
- case "_": {
543
- e.preventDefault();
544
- const newZoom = Math.min(this.maxZoom, Math.max(this.minZoom, currentState.zoom - .5));
545
- this.options.actions.setZoom(newZoom);
546
- break;
547
- }
548
- case "r":
549
- case "R":
550
- if (e.metaKey || e.ctrlKey || e.altKey) break;
551
- e.preventDefault();
552
- this.options.actions.snapRotate90(e.shiftKey ? -1 : 1);
553
- break;
554
- case "h":
555
- case "H":
556
- if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) break;
557
- e.preventDefault();
558
- this.options.actions.toggleFlip?.("horizontal");
559
- break;
560
- case "v":
561
- case "V":
562
- if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) break;
563
- e.preventDefault();
564
- this.options.actions.toggleFlip?.("vertical");
565
- }
566
- }
567
- /**
568
- * Clean up all timers, animation frames, and active touch listeners.
569
- *
570
- * Must be called when the controller is no longer needed (e.g., on
571
- * component unmount or element removal).
572
- */
573
- destroy() {
574
- cancelAnimationFrame(this.rafId);
575
- clearTimeout(this.zoomTimer);
576
- clearTimeout(this.wheelGestureTimer);
577
- this.touchCleanup?.();
578
- this.touchCleanup = null;
579
- this.pointerCleanup?.();
580
- this.pointerCleanup = null;
581
- this.drag = null;
582
- this.touch = null;
583
- this.lastTap = null;
584
- this.wheelGestureActive = false;
585
- this.isDragging = false;
586
- this.isZooming = false;
587
- }
588
- };
589
- exports.InteractionController = InteractionController;
590
-
591
- //# sourceMappingURL=interaction-controller.cjs.map