@wordpress/media-editor 0.21.0 → 0.22.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 (339) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/components/media-editor/index.cjs +533 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +43 -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 +111 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +122 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +65 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +183 -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 +119 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  19. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  20. package/build/components/media-editor-modal/index.cjs +112 -155
  21. package/build/components/media-editor-modal/index.cjs.map +1 -7
  22. package/build/components/media-editor-provider/index.cjs +32 -55
  23. package/build/components/media-editor-provider/index.cjs.map +1 -7
  24. package/build/components/media-form/index.cjs +76 -77
  25. package/build/components/media-form/index.cjs.map +1 -7
  26. package/build/components/media-preview/index.cjs +114 -114
  27. package/build/components/media-preview/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/index.cjs +181 -188
  29. package/build/components/rotation-ruler/index.cjs.map +1 -7
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  32. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  33. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  34. package/build/image-editor/core/camera.cjs +257 -205
  35. package/build/image-editor/core/camera.cjs.map +1 -7
  36. package/build/image-editor/core/constants.cjs +127 -102
  37. package/build/image-editor/core/constants.cjs.map +1 -7
  38. package/build/image-editor/core/containment.cjs +275 -262
  39. package/build/image-editor/core/containment.cjs.map +1 -7
  40. package/build/image-editor/core/crop-rect.cjs +33 -44
  41. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  42. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  43. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  44. package/build/image-editor/core/index.cjs +88 -61
  45. package/build/image-editor/core/interaction-controller.cjs +583 -646
  46. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  47. package/build/image-editor/core/math/rotation.cjs +26 -35
  48. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  49. package/build/image-editor/core/math/sanitize.cjs +124 -80
  50. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  51. package/build/image-editor/core/setter-helpers.cjs +57 -60
  52. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  53. package/build/image-editor/core/source-region.cjs +220 -190
  54. package/build/image-editor/core/source-region.cjs.map +1 -7
  55. package/build/image-editor/core/state.cjs +278 -265
  56. package/build/image-editor/core/state.cjs.map +1 -7
  57. package/build/image-editor/core/stencil-math.cjs +193 -206
  58. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  59. package/build/image-editor/core/transform-style.cjs +39 -48
  60. package/build/image-editor/core/transform-style.cjs.map +1 -7
  61. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  62. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  63. package/build/image-editor/core/types.cjs +4 -18
  64. package/build/image-editor/core/viewport-state.cjs +31 -45
  65. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  66. package/build/image-editor/index.cjs +65 -64
  67. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  68. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  69. package/build/image-editor/react/components/cropper.cjs +583 -710
  70. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  71. package/build/image-editor/react/components/index.cjs +22 -33
  72. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  74. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  76. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  78. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  80. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  81. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  82. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  84. package/build/image-editor/react/hooks/index.cjs +16 -31
  85. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  87. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  89. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  90. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  91. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  92. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  93. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  95. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  96. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  97. package/build/index.cjs +45 -39
  98. package/build/lock-unlock.cjs +9 -35
  99. package/build/lock-unlock.cjs.map +1 -7
  100. package/build/private-apis.cjs +16 -37
  101. package/build/private-apis.cjs.map +1 -7
  102. package/build/state/aspect-ratio-presets.cjs +53 -0
  103. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  104. package/build/state/composite-reducer.cjs +134 -112
  105. package/build/state/composite-reducer.cjs.map +1 -7
  106. package/build/state/index.cjs +63 -47
  107. package/build/state/media-editor-state-provider.cjs +35 -48
  108. package/build/state/media-editor-state-provider.cjs.map +1 -7
  109. package/build/state/types.cjs +12 -31
  110. package/build/state/types.cjs.map +1 -7
  111. package/build/state/use-media-editor-state.cjs +261 -294
  112. package/build/state/use-media-editor-state.cjs.map +1 -7
  113. package/build/store/actions.cjs +17 -44
  114. package/build/store/actions.cjs.map +1 -7
  115. package/build/store/constants.cjs +8 -29
  116. package/build/store/constants.cjs.map +1 -7
  117. package/build/store/index.cjs +33 -40
  118. package/build/store/index.cjs.map +1 -7
  119. package/build/store/reducer.cjs +28 -50
  120. package/build/store/reducer.cjs.map +1 -7
  121. package/build/store/selectors.cjs +16 -41
  122. package/build/store/selectors.cjs.map +1 -7
  123. package/build/utils/get-media-type.cjs +18 -41
  124. package/build/utils/get-media-type.cjs.map +1 -7
  125. package/build/utils/index.cjs +9 -28
  126. package/build-module/components/media-editor/index.mjs +490 -673
  127. package/build-module/components/media-editor/index.mjs.map +1 -7
  128. package/build-module/components/media-editor/use-crop-options.mjs +38 -32
  129. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  130. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  131. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  132. package/build-module/components/media-editor-canvas/index.mjs +98 -96
  133. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  134. package/build-module/components/media-editor-crop-panel/index.mjs +43 -46
  135. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  136. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  137. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  138. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  139. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  140. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  142. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  144. package/build-module/components/media-editor-modal/index.mjs +88 -124
  145. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  146. package/build-module/components/media-editor-provider/index.mjs +26 -29
  147. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  148. package/build-module/components/media-form/index.mjs +68 -56
  149. package/build-module/components/media-form/index.mjs.map +1 -7
  150. package/build-module/components/media-preview/index.mjs +106 -90
  151. package/build-module/components/media-preview/index.mjs.map +1 -7
  152. package/build-module/components/rotation-ruler/index.mjs +161 -164
  153. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  154. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  156. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  158. package/build-module/image-editor/core/camera.mjs +245 -178
  159. package/build-module/image-editor/core/camera.mjs.map +1 -7
  160. package/build-module/image-editor/core/constants.mjs +110 -64
  161. package/build-module/image-editor/core/constants.mjs.map +1 -7
  162. package/build-module/image-editor/core/containment.mjs +265 -237
  163. package/build-module/image-editor/core/containment.mjs.map +1 -7
  164. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  165. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  166. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  168. package/build-module/image-editor/core/index.mjs +5 -34
  169. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  170. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  171. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  172. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  173. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  174. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  175. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  176. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  177. package/build-module/image-editor/core/source-region.mjs +210 -160
  178. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  179. package/build-module/image-editor/core/state.mjs +271 -243
  180. package/build-module/image-editor/core/state.mjs.map +1 -7
  181. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  182. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  183. package/build-module/image-editor/core/transform-style.mjs +34 -23
  184. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  185. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  186. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  187. package/build-module/image-editor/core/types.mjs +0 -1
  188. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  189. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  190. package/build-module/image-editor/index.mjs +3 -38
  191. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  192. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  193. package/build-module/image-editor/react/components/cropper.mjs +550 -686
  194. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  195. package/build-module/image-editor/react/components/index.mjs +1 -7
  196. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  198. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  200. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  202. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  204. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  205. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  206. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  208. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  209. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  211. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  213. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  215. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  217. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  219. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  220. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  221. package/build-module/index.mjs +3 -10
  222. package/build-module/lock-unlock.mjs +5 -10
  223. package/build-module/lock-unlock.mjs.map +1 -7
  224. package/build-module/private-apis.mjs +8 -9
  225. package/build-module/private-apis.mjs.map +1 -7
  226. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  227. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  228. package/build-module/state/composite-reducer.mjs +114 -90
  229. package/build-module/state/composite-reducer.mjs.map +1 -7
  230. package/build-module/state/index.mjs +5 -25
  231. package/build-module/state/media-editor-state-provider.mjs +29 -24
  232. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  233. package/build-module/state/types.mjs +8 -7
  234. package/build-module/state/types.mjs.map +1 -7
  235. package/build-module/state/use-media-editor-state.mjs +256 -286
  236. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  237. package/build-module/store/actions.mjs +12 -19
  238. package/build-module/store/actions.mjs.map +1 -7
  239. package/build-module/store/constants.mjs +4 -5
  240. package/build-module/store/constants.mjs.map +1 -7
  241. package/build-module/store/index.mjs +8 -9
  242. package/build-module/store/index.mjs.map +1 -7
  243. package/build-module/store/reducer.mjs +23 -26
  244. package/build-module/store/reducer.mjs.map +1 -7
  245. package/build-module/store/selectors.mjs +8 -13
  246. package/build-module/store/selectors.mjs.map +1 -7
  247. package/build-module/utils/get-media-type.mjs +14 -17
  248. package/build-module/utils/get-media-type.mjs.map +1 -7
  249. package/build-module/utils/index.mjs +1 -6
  250. package/build-style/style-rtl.css +41 -4
  251. package/build-style/style.css +41 -4
  252. package/build-types/components/media-editor/index.d.ts +4 -0
  253. package/build-types/components/media-editor/index.d.ts.map +1 -1
  254. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  256. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  257. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  258. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  259. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  260. package/build-types/components/media-preview/index.d.ts.map +1 -1
  261. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  262. package/build-types/image-editor/core/constants.d.ts +0 -1
  263. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  264. package/build-types/image-editor/core/index.d.ts +1 -1
  265. package/build-types/image-editor/core/index.d.ts.map +1 -1
  266. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  267. package/build-types/image-editor/core/types.d.ts +1 -1
  268. package/build-types/image-editor/index.d.ts +7 -6
  269. package/build-types/image-editor/index.d.ts.map +1 -1
  270. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  271. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  272. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  273. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  274. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  275. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  276. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  277. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  278. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  279. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  280. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  281. package/build-types/state/composite-reducer.d.ts +1 -1
  282. package/build-types/state/composite-reducer.d.ts.map +1 -1
  283. package/build-types/state/index.d.ts +1 -0
  284. package/build-types/state/index.d.ts.map +1 -1
  285. package/build-types/state/types.d.ts +2 -1
  286. package/build-types/state/types.d.ts.map +1 -1
  287. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  288. package/package.json +21 -21
  289. package/src/components/media-editor/index.tsx +215 -162
  290. package/src/components/media-editor/style.scss +19 -0
  291. package/src/components/media-editor/use-crop-options.ts +5 -2
  292. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  293. package/src/components/media-editor-canvas/index.tsx +16 -26
  294. package/src/components/media-editor-image-controls/index.tsx +4 -2
  295. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  296. package/src/components/media-editor-modal/style.scss +1 -1
  297. package/src/components/media-preview/index.tsx +66 -23
  298. package/src/components/media-preview/style.scss +16 -2
  299. package/src/components/rotation-ruler/style.scss +6 -2
  300. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  301. package/src/image-editor/README.md +8 -8
  302. package/src/image-editor/core/constants.ts +0 -13
  303. package/src/image-editor/core/index.ts +1 -5
  304. package/src/image-editor/core/setter-helpers.ts +1 -1
  305. package/src/image-editor/core/types.ts +1 -1
  306. package/src/image-editor/docs/architecture.md +1 -1
  307. package/src/image-editor/docs/recipes.md +3 -3
  308. package/src/image-editor/index.ts +7 -16
  309. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  310. package/src/image-editor/react/components/cropper.tsx +19 -27
  311. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  312. package/src/image-editor/react/hooks/index.ts +2 -2
  313. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  314. package/src/state/aspect-ratio-presets.ts +18 -0
  315. package/src/state/composite-reducer.ts +2 -2
  316. package/src/state/index.ts +1 -0
  317. package/src/state/types.ts +2 -6
  318. package/src/state/use-media-editor-state.ts +7 -5
  319. package/build/image-editor/core/index.cjs.map +0 -7
  320. package/build/image-editor/core/types.cjs.map +0 -7
  321. package/build/image-editor/index.cjs.map +0 -7
  322. package/build/image-editor/react/components/index.cjs.map +0 -7
  323. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  324. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  325. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  326. package/build/index.cjs.map +0 -7
  327. package/build/state/index.cjs.map +0 -7
  328. package/build/utils/index.cjs.map +0 -7
  329. package/build-module/image-editor/core/index.mjs.map +0 -7
  330. package/build-module/image-editor/core/types.mjs.map +0 -7
  331. package/build-module/image-editor/index.mjs.map +0 -7
  332. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  333. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  334. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  335. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  336. package/build-module/index.mjs.map +0 -7
  337. package/build-module/state/index.mjs.map +0 -7
  338. package/build-module/utils/index.mjs.map +0 -7
  339. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
@@ -1,213 +1,187 @@
1
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/react/hooks/use-interaction.ts
21
- var use_interaction_exports = {};
22
- __export(use_interaction_exports, {
23
- useInteraction: () => useInteraction
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(use_interaction_exports);
26
- var import_element = require("@wordpress/element");
27
- var import_interaction_controller = require("../../core/interaction-controller.cjs");
28
- var KEYBOARD_INTERACTION_IDLE_MS = 300;
6
+ let _wordpress_element = require("@wordpress/element");
7
+ let ______core_interaction_controller_ts = require("../../core/interaction-controller.cjs");
8
+ // packages/media-editor/src/image-editor/react/hooks/use-interaction.ts
9
+ /** How long keyboard placement stays active after the latest handled key. */
10
+ const KEYBOARD_INTERACTION_IDLE_MS = 300;
29
11
  function isHandledKeyboardPan(event) {
30
- switch (event.key) {
31
- case "ArrowUp":
32
- case "ArrowDown":
33
- case "ArrowLeft":
34
- case "ArrowRight":
35
- return true;
36
- default:
37
- return false;
38
- }
12
+ switch (event.key) {
13
+ case "ArrowUp":
14
+ case "ArrowDown":
15
+ case "ArrowLeft":
16
+ case "ArrowRight": return true;
17
+ default: return false;
18
+ }
39
19
  }
40
20
  function isHandledKeyboardZoom(event) {
41
- switch (event.key) {
42
- case "+":
43
- case "=":
44
- case "-":
45
- case "_":
46
- return true;
47
- default:
48
- return false;
49
- }
21
+ switch (event.key) {
22
+ case "+":
23
+ case "=":
24
+ case "-":
25
+ case "_": return true;
26
+ default: return false;
27
+ }
50
28
  }
29
+ /**
30
+ * Mouse, touch, and keyboard event handling for pan, zoom,
31
+ * and crop manipulation.
32
+ *
33
+ * Returns event handler props to spread on the container element.
34
+ * Uses requestAnimationFrame for drag/pinch updates to avoid
35
+ * layout thrashing.
36
+ *
37
+ * @param state The current cropper state.
38
+ * @param actions Named state updates for cropper interactions.
39
+ * @param containerSize The container dimensions in pixels.
40
+ * @param imageSize The rendered image dimensions in pixels.
41
+ * @param options Optional configuration for zoom and keyboard behavior.
42
+ * @return Event handler props for the container element.
43
+ */
51
44
  function useInteraction(state, actions, containerSize, imageSize, options) {
52
- const [isDragging, setIsDragging] = (0, import_element.useState)(false);
53
- const [isZooming, setIsZooming] = (0, import_element.useState)(false);
54
- const [isGestureActive, setIsGestureActive] = (0, import_element.useState)(false);
55
- const [isKeyboardPanning, setIsKeyboardPanning] = (0, import_element.useState)(false);
56
- const keyboardInteractionTimerRef = (0, import_element.useRef)(void 0);
57
- const isKeyboardGestureActiveRef = (0, import_element.useRef)(false);
58
- const stateRef = (0, import_element.useRef)(state);
59
- stateRef.current = state;
60
- const containerSizeRef = (0, import_element.useRef)(containerSize);
61
- containerSizeRef.current = containerSize;
62
- const imageSizeRef = (0, import_element.useRef)(imageSize);
63
- imageSizeRef.current = imageSize;
64
- const optionsRef = (0, import_element.useRef)(options);
65
- optionsRef.current = options;
66
- const actionsRef = (0, import_element.useRef)(actions);
67
- actionsRef.current = actions;
68
- const controllerRef = (0, import_element.useRef)(null);
69
- const startPlacementGesture = (0, import_element.useCallback)(() => {
70
- setIsGestureActive(true);
71
- }, []);
72
- const stopPlacementGesture = (0, import_element.useCallback)(() => {
73
- setIsGestureActive(false);
74
- }, []);
75
- const signalKeyboardGesture = (0, import_element.useCallback)(() => {
76
- if (!isKeyboardGestureActiveRef.current) {
77
- isKeyboardGestureActiveRef.current = true;
78
- optionsRef.current?.onGestureStart?.();
79
- }
80
- clearTimeout(keyboardInteractionTimerRef.current);
81
- keyboardInteractionTimerRef.current = setTimeout(() => {
82
- isKeyboardGestureActiveRef.current = false;
83
- setIsKeyboardPanning(false);
84
- optionsRef.current?.onGestureEnd?.();
85
- }, KEYBOARD_INTERACTION_IDLE_MS);
86
- }, []);
87
- (0, import_element.useEffect)(() => {
88
- return () => {
89
- clearTimeout(keyboardInteractionTimerRef.current);
90
- };
91
- }, []);
92
- (0, import_element.useEffect)(() => {
93
- const controller = new import_interaction_controller.InteractionController({
94
- getState: () => stateRef.current,
95
- actions: {
96
- setPan: (pan) => actionsRef.current.setPan(pan),
97
- setZoom: (zoom) => actionsRef.current.setZoom(zoom),
98
- setZoomAtPoint: (zoom, pan) => actionsRef.current.setZoomAtPoint(zoom, pan),
99
- snapRotate90: (direction) => actionsRef.current.snapRotate90(direction),
100
- toggleFlip: (direction) => actionsRef.current.toggleFlip?.(direction)
101
- },
102
- getContainerSize: () => containerSizeRef.current,
103
- getImageSize: () => imageSizeRef.current,
104
- get minZoom() {
105
- return optionsRef.current?.minZoom;
106
- },
107
- get maxZoom() {
108
- return optionsRef.current?.maxZoom;
109
- },
110
- get zoomSpeed() {
111
- return optionsRef.current?.zoomSpeed;
112
- },
113
- get keyboardStep() {
114
- return optionsRef.current?.keyboardStep;
115
- },
116
- get doubleTapZoom() {
117
- return optionsRef.current?.doubleTapZoom;
118
- },
119
- onGestureStart: () => {
120
- startPlacementGesture();
121
- optionsRef.current?.onGestureStart?.();
122
- },
123
- onGestureEnd: () => {
124
- stopPlacementGesture();
125
- optionsRef.current?.onGestureEnd?.();
126
- },
127
- onStatusChange: (status) => {
128
- setIsDragging(status.isDragging);
129
- setIsZooming(status.isZooming);
130
- }
131
- });
132
- controllerRef.current = controller;
133
- return () => {
134
- controller.destroy();
135
- controllerRef.current = null;
136
- };
137
- }, [startPlacementGesture, stopPlacementGesture]);
138
- const isDisabled = options?.disabled ?? false;
139
- (0, import_element.useEffect)(() => {
140
- if (!isDisabled) {
141
- return;
142
- }
143
- controllerRef.current?.destroy();
144
- setIsDragging(false);
145
- setIsZooming(false);
146
- setIsKeyboardPanning(false);
147
- const wasGestureOpen = isGestureActive || isKeyboardGestureActiveRef.current;
148
- if (isKeyboardGestureActiveRef.current) {
149
- isKeyboardGestureActiveRef.current = false;
150
- clearTimeout(keyboardInteractionTimerRef.current);
151
- }
152
- stopPlacementGesture();
153
- if (wasGestureOpen) {
154
- optionsRef.current?.onGestureEnd?.();
155
- }
156
- }, [isDisabled, isGestureActive, stopPlacementGesture]);
157
- const onPointerDown = (0, import_element.useCallback)((e) => {
158
- if (optionsRef.current?.disabled) {
159
- return;
160
- }
161
- const el = e.currentTarget;
162
- controllerRef.current?.handlePointerDown(e.nativeEvent, el);
163
- }, []);
164
- const onTouchStart = (0, import_element.useCallback)((e) => {
165
- if (optionsRef.current?.disabled) {
166
- return;
167
- }
168
- const el = e.currentTarget;
169
- const rect = el.getBoundingClientRect();
170
- controllerRef.current?.handleTouchStart(
171
- e.nativeEvent,
172
- rect,
173
- el.ownerDocument
174
- );
175
- }, []);
176
- const onKeyDown = (0, import_element.useCallback)(
177
- (e) => {
178
- if (optionsRef.current?.disabled) {
179
- return;
180
- }
181
- if (isHandledKeyboardPan(e.nativeEvent)) {
182
- setIsKeyboardPanning(true);
183
- signalKeyboardGesture();
184
- } else if (isHandledKeyboardZoom(e.nativeEvent)) {
185
- signalKeyboardGesture();
186
- }
187
- controllerRef.current?.handleKeyDown(e.nativeEvent);
188
- },
189
- [signalKeyboardGesture]
190
- );
191
- const onWheelNative = (0, import_element.useCallback)((e) => {
192
- if (optionsRef.current?.disabled) {
193
- return;
194
- }
195
- controllerRef.current?.handleWheel(e);
196
- }, []);
197
- return {
198
- handlers: {
199
- onPointerDown,
200
- onTouchStart,
201
- onKeyDown
202
- },
203
- onWheelNative,
204
- isDragging,
205
- isZooming,
206
- isPlacementActive: isGestureActive || isKeyboardPanning || isZooming
207
- };
45
+ const [isDragging, setIsDragging] = (0, _wordpress_element.useState)(false);
46
+ const [isZooming, setIsZooming] = (0, _wordpress_element.useState)(false);
47
+ const [isGestureActive, setIsGestureActive] = (0, _wordpress_element.useState)(false);
48
+ const [isKeyboardPanning, setIsKeyboardPanning] = (0, _wordpress_element.useState)(false);
49
+ const keyboardInteractionTimerRef = (0, _wordpress_element.useRef)(void 0);
50
+ const isKeyboardGestureActiveRef = (0, _wordpress_element.useRef)(false);
51
+ const stateRef = (0, _wordpress_element.useRef)(state);
52
+ stateRef.current = state;
53
+ const containerSizeRef = (0, _wordpress_element.useRef)(containerSize);
54
+ containerSizeRef.current = containerSize;
55
+ const imageSizeRef = (0, _wordpress_element.useRef)(imageSize);
56
+ imageSizeRef.current = imageSize;
57
+ const optionsRef = (0, _wordpress_element.useRef)(options);
58
+ optionsRef.current = options;
59
+ const actionsRef = (0, _wordpress_element.useRef)(actions);
60
+ actionsRef.current = actions;
61
+ const controllerRef = (0, _wordpress_element.useRef)(null);
62
+ const startPlacementGesture = (0, _wordpress_element.useCallback)(() => {
63
+ setIsGestureActive(true);
64
+ }, []);
65
+ const stopPlacementGesture = (0, _wordpress_element.useCallback)(() => {
66
+ setIsGestureActive(false);
67
+ }, []);
68
+ const signalKeyboardGesture = (0, _wordpress_element.useCallback)(() => {
69
+ if (!isKeyboardGestureActiveRef.current) {
70
+ isKeyboardGestureActiveRef.current = true;
71
+ optionsRef.current?.onGestureStart?.();
72
+ }
73
+ clearTimeout(keyboardInteractionTimerRef.current);
74
+ keyboardInteractionTimerRef.current = setTimeout(() => {
75
+ isKeyboardGestureActiveRef.current = false;
76
+ setIsKeyboardPanning(false);
77
+ optionsRef.current?.onGestureEnd?.();
78
+ }, KEYBOARD_INTERACTION_IDLE_MS);
79
+ }, []);
80
+ (0, _wordpress_element.useEffect)(() => {
81
+ return () => {
82
+ clearTimeout(keyboardInteractionTimerRef.current);
83
+ };
84
+ }, []);
85
+ (0, _wordpress_element.useEffect)(() => {
86
+ const controller = new ______core_interaction_controller_ts.InteractionController({
87
+ getState: () => stateRef.current,
88
+ actions: {
89
+ setPan: (pan) => actionsRef.current.setPan(pan),
90
+ setZoom: (zoom) => actionsRef.current.setZoom(zoom),
91
+ setZoomAtPoint: (zoom, pan) => actionsRef.current.setZoomAtPoint(zoom, pan),
92
+ snapRotate90: (direction) => actionsRef.current.snapRotate90(direction),
93
+ toggleFlip: (direction) => actionsRef.current.toggleFlip?.(direction)
94
+ },
95
+ getContainerSize: () => containerSizeRef.current,
96
+ getImageSize: () => imageSizeRef.current,
97
+ get minZoom() {
98
+ return optionsRef.current?.minZoom;
99
+ },
100
+ get maxZoom() {
101
+ return optionsRef.current?.maxZoom;
102
+ },
103
+ get zoomSpeed() {
104
+ return optionsRef.current?.zoomSpeed;
105
+ },
106
+ get keyboardStep() {
107
+ return optionsRef.current?.keyboardStep;
108
+ },
109
+ get doubleTapZoom() {
110
+ return optionsRef.current?.doubleTapZoom;
111
+ },
112
+ onGestureStart: () => {
113
+ startPlacementGesture();
114
+ optionsRef.current?.onGestureStart?.();
115
+ },
116
+ onGestureEnd: () => {
117
+ stopPlacementGesture();
118
+ optionsRef.current?.onGestureEnd?.();
119
+ },
120
+ onStatusChange: (status) => {
121
+ setIsDragging(status.isDragging);
122
+ setIsZooming(status.isZooming);
123
+ }
124
+ });
125
+ controllerRef.current = controller;
126
+ return () => {
127
+ controller.destroy();
128
+ controllerRef.current = null;
129
+ };
130
+ }, [startPlacementGesture, stopPlacementGesture]);
131
+ const isDisabled = options?.disabled ?? false;
132
+ (0, _wordpress_element.useEffect)(() => {
133
+ if (!isDisabled) return;
134
+ controllerRef.current?.destroy();
135
+ setIsDragging(false);
136
+ setIsZooming(false);
137
+ setIsKeyboardPanning(false);
138
+ const wasGestureOpen = isGestureActive || isKeyboardGestureActiveRef.current;
139
+ if (isKeyboardGestureActiveRef.current) {
140
+ isKeyboardGestureActiveRef.current = false;
141
+ clearTimeout(keyboardInteractionTimerRef.current);
142
+ }
143
+ stopPlacementGesture();
144
+ if (wasGestureOpen) optionsRef.current?.onGestureEnd?.();
145
+ }, [
146
+ isDisabled,
147
+ isGestureActive,
148
+ stopPlacementGesture
149
+ ]);
150
+ const onPointerDown = (0, _wordpress_element.useCallback)((e) => {
151
+ if (optionsRef.current?.disabled) return;
152
+ const el = e.currentTarget;
153
+ controllerRef.current?.handlePointerDown(e.nativeEvent, el);
154
+ }, []);
155
+ const onTouchStart = (0, _wordpress_element.useCallback)((e) => {
156
+ if (optionsRef.current?.disabled) return;
157
+ const el = e.currentTarget;
158
+ const rect = el.getBoundingClientRect();
159
+ controllerRef.current?.handleTouchStart(e.nativeEvent, rect, el.ownerDocument);
160
+ }, []);
161
+ const onKeyDown = (0, _wordpress_element.useCallback)((e) => {
162
+ if (optionsRef.current?.disabled) return;
163
+ if (isHandledKeyboardPan(e.nativeEvent)) {
164
+ setIsKeyboardPanning(true);
165
+ signalKeyboardGesture();
166
+ } else if (isHandledKeyboardZoom(e.nativeEvent)) signalKeyboardGesture();
167
+ controllerRef.current?.handleKeyDown(e.nativeEvent);
168
+ }, [signalKeyboardGesture]);
169
+ const onWheelNative = (0, _wordpress_element.useCallback)((e) => {
170
+ if (optionsRef.current?.disabled) return;
171
+ controllerRef.current?.handleWheel(e);
172
+ }, []);
173
+ return {
174
+ handlers: {
175
+ onPointerDown,
176
+ onTouchStart,
177
+ onKeyDown
178
+ },
179
+ onWheelNative,
180
+ isDragging,
181
+ isZooming,
182
+ isPlacementActive: isGestureActive || isKeyboardPanning || isZooming
183
+ };
208
184
  }
209
- // Annotate the CommonJS export names for ESM import in node:
210
- 0 && (module.exports = {
211
- useInteraction
212
- });
213
- //# sourceMappingURL=use-interaction.cjs.map
185
+ exports.useInteraction = useInteraction;
186
+
187
+ //# sourceMappingURL=use-interaction.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/image-editor/react/hooks/use-interaction.ts"],
4
- "sourcesContent": ["import { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler — must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Ignore all interaction. Any gesture already in flight is torn down,\n\t * so a drag started before this flipped cannot keep moving the image.\n\t */\n\tdisabled?: boolean;\n}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isHandledKeyboardZoom( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase '+':\n\t\tcase '=':\n\t\tcase '-':\n\t\tcase '_':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\t// Tracks whether a keyboard gesture (pan or zoom) is currently active so\n\t// onGestureStart is only fired once per gesture, not on every key repeat.\n\tconst isKeyboardGestureActiveRef = useRef( false );\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\t// Shared timer logic for any keyboard gesture (pan or zoom): fires\n\t// onGestureStart once per burst and onGestureEnd after the idle window.\n\tconst signalKeyboardGesture = useCallback( () => {\n\t\tif ( ! isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = true;\n\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tsetIsKeyboardPanning( false );\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t\ttoggleFlip: ( direction ) =>\n\t\t\t\t\tactionsRef.current.toggleFlip?.( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\t// Cancel any gesture already in flight when interaction is switched off,\n\t// so a drag that started before the flip cannot keep moving the image.\n\t// `destroy()` releases the pointer/touch listeners and the pending rAF;\n\t// the controller keeps working for later gestures once re-enabled.\n\t//\n\t// It does not signal the end of the gesture it just cut short, so that\n\t// is done here: a caller told a gesture began is otherwise left waiting\n\t// for an end that never comes, which keeps undo/redo disabled and leaves\n\t// the cropper's history batch open after a failed save.\n\tconst isDisabled = options?.disabled ?? false;\n\tuseEffect( () => {\n\t\tif ( ! isDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tcontrollerRef.current?.destroy();\n\t\tsetIsDragging( false );\n\t\tsetIsZooming( false );\n\t\tsetIsKeyboardPanning( false );\n\t\tconst wasGestureOpen =\n\t\t\tisGestureActive || isKeyboardGestureActiveRef.current;\n\t\tif ( isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t}\n\t\tstopPlacementGesture();\n\t\tif ( wasGestureOpen ) {\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}\n\t}, [ isDisabled, isGestureActive, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( optionsRef.current?.disabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsetIsKeyboardPanning( true );\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t} else if ( isHandledKeyboardZoom( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardGesture ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouchStart,\n\t\t\tonKeyDown,\n\t\t},\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isGestureActive || isKeyboardPanning || isZooming,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAyD;AAEzD,oCAGO;AAmDP,IAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;AAC9D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,sBAAuB,OAAgC;AAC/D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAiBO,SAAS,eACf,OACA,SACA,eACA,WACA,SACuB;AACvB,QAAM,CAAE,YAAY,aAAc,QAAI,yBAAU,KAAM;AACtD,QAAM,CAAE,WAAW,YAAa,QAAI,yBAAU,KAAM;AACpD,QAAM,CAAE,iBAAiB,kBAAmB,QAAI,yBAAU,KAAM;AAChE,QAAM,CAAE,mBAAmB,oBAAqB,QAAI,yBAAU,KAAM;AACpE,QAAM,kCAA8B,uBAEjC,MAAU;AAGb,QAAM,iCAA6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,GAAG,CAAE,YAAY,iBAAiB,oBAAqB,CAAE;AAEzD,QAAM,oBAAgB,4BAAa,CAAE,MAA2B;AAC/D,QAAK,WAAW,SAAS,UAAW;AACnC;AAAA,IACD;AACA,UAAM,KAAK,EAAE;AACb,kBAAc,SAAS,kBAAmB,EAAE,aAAa,EAAG;AAAA,EAC7D,GAAG,CAAC,CAAE;AAEN,QAAM,mBAAe,4BAAa,CAAE,MAAyB;AAC5D,QAAK,WAAW,SAAS,UAAW;AACnC;AAAA,IACD;AACA,UAAM,KAAK,EAAE;AACb,UAAM,OAAO,GAAG,sBAAsB;AACtC,kBAAc,SAAS;AAAA,MACtB,EAAE;AAAA,MACF;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,gBAAY;AAAA,IACjB,CAAE,MAA4B;AAC7B,UAAK,WAAW,SAAS,UAAW;AACnC;AAAA,MACD;AACA,UAAK,qBAAsB,EAAE,WAAY,GAAI;AAC5C,6BAAsB,IAAK;AAC3B,8BAAsB;AAAA,MACvB,WAAY,sBAAuB,EAAE,WAAY,GAAI;AACpD,8BAAsB;AAAA,MACvB;AACA,oBAAc,SAAS,cAAe,EAAE,WAAY;AAAA,IACrD;AAAA,IACA,CAAE,qBAAsB;AAAA,EACzB;AAEA,QAAM,oBAAgB,4BAAa,CAAE,MAAmB;AACvD,QAAK,WAAW,SAAS,UAAW;AACnC;AAAA,IACD;AACA,kBAAc,SAAS,YAAa,CAAE;AAAA,EACvC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,UAAU;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,mBAAmB,qBAAqB;AAAA,EAC5D;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"use-interaction.cjs","names":["useState","useRef","useCallback","InteractionController"],"sources":["../../../../src/image-editor/react/hooks/use-interaction.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler — must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Ignore all interaction. Any gesture already in flight is torn down,\n\t * so a drag started before this flipped cannot keep moving the image.\n\t */\n\tdisabled?: boolean;\n}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isHandledKeyboardZoom( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase '+':\n\t\tcase '=':\n\t\tcase '-':\n\t\tcase '_':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef = useRef<\n\t\tReturnType< typeof setTimeout > | undefined\n\t>( undefined );\n\t// Tracks whether a keyboard gesture (pan or zoom) is currently active so\n\t// onGestureStart is only fired once per gesture, not on every key repeat.\n\tconst isKeyboardGestureActiveRef = useRef( false );\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\t// Shared timer logic for any keyboard gesture (pan or zoom): fires\n\t// onGestureStart once per burst and onGestureEnd after the idle window.\n\tconst signalKeyboardGesture = useCallback( () => {\n\t\tif ( ! isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = true;\n\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tsetIsKeyboardPanning( false );\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t\ttoggleFlip: ( direction ) =>\n\t\t\t\t\tactionsRef.current.toggleFlip?.( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\t// Cancel any gesture already in flight when interaction is switched off,\n\t// so a drag that started before the flip cannot keep moving the image.\n\t// `destroy()` releases the pointer/touch listeners and the pending rAF;\n\t// the controller keeps working for later gestures once re-enabled.\n\t//\n\t// It does not signal the end of the gesture it just cut short, so that\n\t// is done here: a caller told a gesture began is otherwise left waiting\n\t// for an end that never comes, which keeps undo/redo disabled and leaves\n\t// the cropper's history batch open after a failed save.\n\tconst isDisabled = options?.disabled ?? false;\n\tuseEffect( () => {\n\t\tif ( ! isDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tcontrollerRef.current?.destroy();\n\t\tsetIsDragging( false );\n\t\tsetIsZooming( false );\n\t\tsetIsKeyboardPanning( false );\n\t\tconst wasGestureOpen =\n\t\t\tisGestureActive || isKeyboardGestureActiveRef.current;\n\t\tif ( isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t}\n\t\tstopPlacementGesture();\n\t\tif ( wasGestureOpen ) {\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}\n\t}, [ isDisabled, isGestureActive, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( optionsRef.current?.disabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsetIsKeyboardPanning( true );\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t} else if ( isHandledKeyboardZoom( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardGesture ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tif ( optionsRef.current?.disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouch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YAAAA,EACf,MAA4B;EAC7B,IAAK,WAAW,SAAS,UACxB;EAED,IAAK,qBAAsB,EAAE,WAAY,GAAI;GAC5C,qBAAsB,IAAK;GAC3B,sBAAsB;EACvB,OAAO,IAAK,sBAAuB,EAAE,WAAY,GAChD,sBAAsB;EAEvB,cAAc,SAAS,cAAe,EAAE,WAAY;CACrD,GACA,CAAE,qBAAsB,CACzB;CAEA,MAAM,iBAAA,GAAgBA,mBAAAA,YAAAA,EAAe,MAAmB;EACvD,IAAK,WAAW,SAAS,UACxB;EAED,cAAc,SAAS,YAAa,CAAE;CACvC,GAAG,CAAC,CAAE;CAEN,OAAO;EACN,UAAU;GACT;GACA;GACA;EACD;EACA;EACA;EACA;EACA,mBAAmB,mBAAmB,qBAAqB;CAC5D;AACD"}
@@ -1,38 +1,24 @@
1
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/react/hooks/use-transform-style.ts
21
- var use_transform_style_exports = {};
22
- __export(use_transform_style_exports, {
23
- useTransformStyle: () => useTransformStyle
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(use_transform_style_exports);
26
- var import_element = require("@wordpress/element");
27
- var import_transform_style = require("../../core/transform-style.cjs");
6
+ let _wordpress_element = require("@wordpress/element");
7
+ let ______core_transform_style_ts = require("../../core/transform-style.cjs");
8
+ // packages/media-editor/src/image-editor/react/hooks/use-transform-style.ts
9
+ /**
10
+ * React hook that computes a memoized CSS matrix() transform string
11
+ * from the cropper state.
12
+ *
13
+ * Delegates to the pure `computeTransformStyle` function in core.
14
+ *
15
+ * @param state The current cropper state.
16
+ * @param imageSize The rendered image dimensions in pixels.
17
+ * @return A CSS transform string.
18
+ */
28
19
  function useTransformStyle(state, imageSize) {
29
- return (0, import_element.useMemo)(
30
- () => (0, import_transform_style.computeTransformStyle)(state, imageSize),
31
- [state, imageSize]
32
- );
20
+ return (0, _wordpress_element.useMemo)(() => (0, ______core_transform_style_ts.computeTransformStyle)(state, imageSize), [state, imageSize]);
33
21
  }
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- useTransformStyle
37
- });
38
- //# sourceMappingURL=use-transform-style.cjs.map
22
+ exports.useTransformStyle = useTransformStyle;
23
+
24
+ //# sourceMappingURL=use-transform-style.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/image-editor/react/hooks/use-transform-style.ts"],
4
- "sourcesContent": ["import { useMemo } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport { computeTransformStyle } from '../../core/transform-style';\n\n/**\n * React hook that computes a memoized CSS matrix() transform string\n * from the cropper state.\n *\n * Delegates to the pure `computeTransformStyle` function in core.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function useTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\treturn useMemo(\n\t\t() => computeTransformStyle( state, imageSize ),\n\t\t[ state, imageSize ]\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,6BAAsC;AAY/B,SAAS,kBACf,OACA,WACS;AACT,aAAO;AAAA,IACN,UAAM,8CAAuB,OAAO,SAAU;AAAA,IAC9C,CAAE,OAAO,SAAU;AAAA,EACpB;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"use-transform-style.cjs","names":["useMemo","computeTransformStyle"],"sources":["../../../../src/image-editor/react/hooks/use-transform-style.ts"],"sourcesContent":["import { useMemo } from '@wordpress/element';\nimport type { CropperState, Size } from '../../core/types';\nimport { computeTransformStyle } from '../../core/transform-style';\n\n/**\n * React hook that computes a memoized CSS matrix() transform string\n * from the cropper state.\n *\n * Delegates to the pure `computeTransformStyle` function in core.\n *\n * @param state The current cropper state.\n * @param imageSize The rendered image dimensions in pixels.\n * @return A CSS transform string.\n */\nexport function useTransformStyle(\n\tstate: CropperState,\n\timageSize: Size\n): string {\n\treturn useMemo(\n\t\t() => computeTransformStyle( state, imageSize ),\n\t\t[ state, imageSize ]\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,SAAgB,kBACf,OACA,WACS;CACT,QAAA,GAAOA,mBAAAA,QAAAA,QAAAA,GACAC,8BAAAA,sBAAAA,CAAuB,OAAO,SAAU,GAC9C,CAAE,OAAO,SAAU,CACpB;AACD"}
@@ -1,51 +1,40 @@
1
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/react/hooks/use-viewport-state.ts
21
- var use_viewport_state_exports = {};
22
- __export(use_viewport_state_exports, {
23
- useViewportState: () => useViewportState
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(use_viewport_state_exports);
26
- var import_element = require("@wordpress/element");
27
- var import_viewport_state = require("../../core/viewport-state.cjs");
6
+ let _wordpress_element = require("@wordpress/element");
7
+ let ______core_viewport_state_ts = require("../../core/viewport-state.cjs");
8
+ // packages/media-editor/src/image-editor/react/hooks/use-viewport-state.ts
28
9
  function useViewportState() {
29
- const [viewport, dispatch] = (0, import_element.useReducer)(
30
- import_viewport_state.viewportReducer,
31
- import_viewport_state.DEFAULT_VIEWPORT_STATE
32
- );
33
- const setViewportZoom = (0, import_element.useCallback)((zoom) => {
34
- dispatch({ type: "SET_VIEWPORT_ZOOM", payload: zoom });
35
- }, []);
36
- const setViewportPan = (0, import_element.useCallback)((pan) => {
37
- dispatch({ type: "SET_VIEWPORT_PAN", payload: pan });
38
- }, []);
39
- const resetViewport = (0, import_element.useCallback)(() => {
40
- dispatch({ type: "RESET_VIEWPORT" });
41
- }, []);
42
- return (0, import_element.useMemo)(
43
- () => ({ viewport, setViewportZoom, setViewportPan, resetViewport }),
44
- [viewport, setViewportZoom, setViewportPan, resetViewport]
45
- );
10
+ const [viewport, dispatch] = (0, _wordpress_element.useReducer)(______core_viewport_state_ts.viewportReducer, ______core_viewport_state_ts.DEFAULT_VIEWPORT_STATE);
11
+ const setViewportZoom = (0, _wordpress_element.useCallback)((zoom) => {
12
+ dispatch({
13
+ type: "SET_VIEWPORT_ZOOM",
14
+ payload: zoom
15
+ });
16
+ }, []);
17
+ const setViewportPan = (0, _wordpress_element.useCallback)((pan) => {
18
+ dispatch({
19
+ type: "SET_VIEWPORT_PAN",
20
+ payload: pan
21
+ });
22
+ }, []);
23
+ const resetViewport = (0, _wordpress_element.useCallback)(() => {
24
+ dispatch({ type: "RESET_VIEWPORT" });
25
+ }, []);
26
+ return (0, _wordpress_element.useMemo)(() => ({
27
+ viewport,
28
+ setViewportZoom,
29
+ setViewportPan,
30
+ resetViewport
31
+ }), [
32
+ viewport,
33
+ setViewportZoom,
34
+ setViewportPan,
35
+ resetViewport
36
+ ]);
46
37
  }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- useViewportState
50
- });
51
- //# sourceMappingURL=use-viewport-state.cjs.map
38
+ exports.useViewportState = useViewportState;
39
+
40
+ //# sourceMappingURL=use-viewport-state.cjs.map