@wordpress/media-editor 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (432) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/components/media-editor/index.cjs +586 -686
  3. package/build/components/media-editor/index.cjs.map +1 -7
  4. package/build/components/media-editor/use-crop-options.cjs +42 -57
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  6. package/build/components/media-editor/use-save-media-editor.cjs +131 -185
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  8. package/build/components/media-editor-canvas/index.cjs +117 -124
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  10. package/build/components/media-editor-crop-panel/index.cjs +81 -72
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  12. package/build/components/media-editor-fine-rotation/index.cjs +61 -72
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  14. package/build/components/media-editor-image-controls/index.cjs +181 -257
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +120 -157
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  18. package/build/components/media-editor-modal/index.cjs +112 -155
  19. package/build/components/media-editor-modal/index.cjs.map +1 -7
  20. package/build/components/media-editor-provider/index.cjs +32 -55
  21. package/build/components/media-editor-provider/index.cjs.map +1 -7
  22. package/build/components/media-form/index.cjs +82 -77
  23. package/build/components/media-form/index.cjs.map +1 -7
  24. package/build/components/media-preview/index.cjs +113 -114
  25. package/build/components/media-preview/index.cjs.map +1 -7
  26. package/build/components/rotation-ruler/index.cjs +181 -188
  27. package/build/components/rotation-ruler/index.cjs.map +1 -7
  28. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  29. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  30. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  32. package/build/index.cjs +45 -39
  33. package/build/lock-unlock.cjs +9 -35
  34. package/build/lock-unlock.cjs.map +1 -7
  35. package/build/private-apis.cjs +16 -37
  36. package/build/private-apis.cjs.map +1 -7
  37. package/build/state/aspect-ratio-presets.cjs +59 -0
  38. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  39. package/build/state/composite-reducer.cjs +100 -113
  40. package/build/state/composite-reducer.cjs.map +1 -7
  41. package/build/state/index.cjs +22 -45
  42. package/build/state/media-editor-state-provider.cjs +35 -48
  43. package/build/state/media-editor-state-provider.cjs.map +1 -7
  44. package/build/state/types.cjs +11 -31
  45. package/build/state/types.cjs.map +1 -7
  46. package/build/state/use-media-editor-state.cjs +227 -296
  47. package/build/state/use-media-editor-state.cjs.map +1 -7
  48. package/build/store/actions.cjs +17 -44
  49. package/build/store/actions.cjs.map +1 -7
  50. package/build/store/constants.cjs +8 -29
  51. package/build/store/constants.cjs.map +1 -7
  52. package/build/store/index.cjs +33 -40
  53. package/build/store/index.cjs.map +1 -7
  54. package/build/store/reducer.cjs +28 -50
  55. package/build/store/reducer.cjs.map +1 -7
  56. package/build/store/selectors.cjs +16 -41
  57. package/build/store/selectors.cjs.map +1 -7
  58. package/build/utils/get-media-type.cjs +18 -41
  59. package/build/utils/get-media-type.cjs.map +1 -7
  60. package/build/utils/index.cjs +9 -28
  61. package/build-module/components/media-editor/index.mjs +545 -675
  62. package/build-module/components/media-editor/index.mjs.map +1 -7
  63. package/build-module/components/media-editor/use-crop-options.mjs +37 -32
  64. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  65. package/build-module/components/media-editor/use-save-media-editor.mjs +109 -157
  66. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  67. package/build-module/components/media-editor-canvas/index.mjs +95 -98
  68. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  69. package/build-module/components/media-editor-crop-panel/index.mjs +59 -46
  70. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  71. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -46
  72. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  73. package/build-module/components/media-editor-image-controls/index.mjs +171 -238
  74. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  75. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +113 -137
  76. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  77. package/build-module/components/media-editor-modal/index.mjs +88 -124
  78. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  79. package/build-module/components/media-editor-provider/index.mjs +26 -29
  80. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  81. package/build-module/components/media-form/index.mjs +74 -56
  82. package/build-module/components/media-form/index.mjs.map +1 -7
  83. package/build-module/components/media-preview/index.mjs +105 -90
  84. package/build-module/components/media-preview/index.mjs.map +1 -7
  85. package/build-module/components/rotation-ruler/index.mjs +161 -164
  86. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  87. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  88. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  89. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  90. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  91. package/build-module/index.mjs +3 -10
  92. package/build-module/lock-unlock.mjs +5 -10
  93. package/build-module/lock-unlock.mjs.map +1 -7
  94. package/build-module/private-apis.mjs +8 -9
  95. package/build-module/private-apis.mjs.map +1 -7
  96. package/build-module/state/aspect-ratio-presets.mjs +53 -0
  97. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  98. package/build-module/state/composite-reducer.mjs +80 -91
  99. package/build-module/state/composite-reducer.mjs.map +1 -7
  100. package/build-module/state/index.mjs +3 -26
  101. package/build-module/state/media-editor-state-provider.mjs +29 -24
  102. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  103. package/build-module/state/types.mjs +7 -7
  104. package/build-module/state/types.mjs.map +1 -7
  105. package/build-module/state/use-media-editor-state.mjs +223 -288
  106. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  107. package/build-module/store/actions.mjs +12 -19
  108. package/build-module/store/actions.mjs.map +1 -7
  109. package/build-module/store/constants.mjs +4 -5
  110. package/build-module/store/constants.mjs.map +1 -7
  111. package/build-module/store/index.mjs +8 -9
  112. package/build-module/store/index.mjs.map +1 -7
  113. package/build-module/store/reducer.mjs +23 -26
  114. package/build-module/store/reducer.mjs.map +1 -7
  115. package/build-module/store/selectors.mjs +8 -13
  116. package/build-module/store/selectors.mjs.map +1 -7
  117. package/build-module/utils/get-media-type.mjs +14 -17
  118. package/build-module/utils/get-media-type.mjs.map +1 -7
  119. package/build-module/utils/index.mjs +1 -6
  120. package/build-style/style-rtl.css +145 -61
  121. package/build-style/style.css +144 -61
  122. package/build-types/components/media-editor/index.d.ts +20 -2
  123. package/build-types/components/media-editor/index.d.ts.map +1 -1
  124. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  125. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  126. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  127. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  128. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  129. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  130. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  131. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  132. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  133. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  134. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  135. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  136. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  137. package/build-types/components/media-form/index.d.ts.map +1 -1
  138. package/build-types/components/media-preview/index.d.ts.map +1 -1
  139. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  140. package/build-types/state/aspect-ratio-presets.d.ts +24 -0
  141. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  142. package/build-types/state/composite-reducer.d.ts +17 -19
  143. package/build-types/state/composite-reducer.d.ts.map +1 -1
  144. package/build-types/state/index.d.ts +2 -4
  145. package/build-types/state/index.d.ts.map +1 -1
  146. package/build-types/state/types.d.ts +20 -63
  147. package/build-types/state/types.d.ts.map +1 -1
  148. package/build-types/state/use-media-editor-state.d.ts +33 -52
  149. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  150. package/package.json +22 -23
  151. package/src/components/media-editor/index.tsx +355 -167
  152. package/src/components/media-editor/style.scss +19 -0
  153. package/src/components/media-editor/use-crop-options.ts +9 -10
  154. package/src/components/media-editor/use-save-media-editor.ts +48 -10
  155. package/src/components/media-editor-canvas/index.tsx +30 -51
  156. package/src/components/media-editor-canvas/style.scss +6 -6
  157. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  158. package/src/components/media-editor-crop-panel/style.scss +21 -0
  159. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  160. package/src/components/media-editor-image-controls/index.tsx +15 -11
  161. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +1 -0
  162. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  163. package/src/components/media-editor-modal/index.tsx +1 -1
  164. package/src/components/media-editor-modal/style.scss +1 -1
  165. package/src/components/media-form/index.tsx +7 -1
  166. package/src/components/media-preview/index.tsx +65 -23
  167. package/src/components/media-preview/style.scss +16 -2
  168. package/src/components/rotation-ruler/style.scss +9 -5
  169. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  170. package/src/state/README.md +32 -0
  171. package/src/state/aspect-ratio-presets.ts +37 -0
  172. package/src/state/composite-reducer.ts +42 -80
  173. package/src/state/index.ts +2 -17
  174. package/src/state/types.ts +18 -72
  175. package/src/state/use-media-editor-state.ts +155 -238
  176. package/src/style.scss +2 -1
  177. package/build/components/media-editor-modal/build-modifiers.cjs +0 -91
  178. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -7
  179. package/build/image-editor/core/camera.cjs +0 -225
  180. package/build/image-editor/core/camera.cjs.map +0 -7
  181. package/build/image-editor/core/constants.cjs +0 -108
  182. package/build/image-editor/core/constants.cjs.map +0 -7
  183. package/build/image-editor/core/containment.cjs +0 -276
  184. package/build/image-editor/core/containment.cjs.map +0 -7
  185. package/build/image-editor/core/crop-rect.cjs +0 -48
  186. package/build/image-editor/core/crop-rect.cjs.map +0 -7
  187. package/build/image-editor/core/export/canvas-renderer.cjs +0 -151
  188. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -7
  189. package/build/image-editor/core/index.cjs +0 -62
  190. package/build/image-editor/core/index.cjs.map +0 -7
  191. package/build/image-editor/core/interaction-controller.cjs +0 -654
  192. package/build/image-editor/core/interaction-controller.cjs.map +0 -7
  193. package/build/image-editor/core/math/rotation.cjs +0 -41
  194. package/build/image-editor/core/math/rotation.cjs.map +0 -7
  195. package/build/image-editor/core/math/sanitize.cjs +0 -92
  196. package/build/image-editor/core/math/sanitize.cjs.map +0 -7
  197. package/build/image-editor/core/setter-helpers.cjs +0 -64
  198. package/build/image-editor/core/setter-helpers.cjs.map +0 -7
  199. package/build/image-editor/core/source-region.cjs +0 -206
  200. package/build/image-editor/core/source-region.cjs.map +0 -7
  201. package/build/image-editor/core/state.cjs +0 -283
  202. package/build/image-editor/core/state.cjs.map +0 -7
  203. package/build/image-editor/core/stencil-math.cjs +0 -216
  204. package/build/image-editor/core/stencil-math.cjs.map +0 -7
  205. package/build/image-editor/core/transform-style.cjs +0 -52
  206. package/build/image-editor/core/transform-style.cjs.map +0 -7
  207. package/build/image-editor/core/transforms/pipeline.cjs +0 -43
  208. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -7
  209. package/build/image-editor/core/types.cjs +0 -19
  210. package/build/image-editor/core/types.cjs.map +0 -7
  211. package/build/image-editor/core/viewport-state.cjs +0 -50
  212. package/build/image-editor/core/viewport-state.cjs.map +0 -7
  213. package/build/image-editor/index.cjs +0 -67
  214. package/build/image-editor/index.cjs.map +0 -7
  215. package/build/image-editor/react/components/cropper-provider.cjs +0 -50
  216. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -7
  217. package/build/image-editor/react/components/cropper.cjs +0 -722
  218. package/build/image-editor/react/components/cropper.cjs.map +0 -7
  219. package/build/image-editor/react/components/index.cjs +0 -36
  220. package/build/image-editor/react/components/index.cjs.map +0 -7
  221. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -172
  222. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -7
  223. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -62
  224. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -7
  225. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -91
  226. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -7
  227. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -426
  228. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -7
  229. package/build/image-editor/react/components/viewport-provider.cjs +0 -51
  230. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -7
  231. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -71
  232. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -7
  233. package/build/image-editor/react/hooks/index.cjs +0 -34
  234. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  235. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -160
  236. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -7
  237. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  238. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  239. package/build/image-editor/react/hooks/use-interaction.cjs +0 -213
  240. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -7
  241. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -38
  242. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -7
  243. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -51
  244. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -7
  245. package/build/image-editor/react/visually-hidden-style.cjs +0 -41
  246. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -7
  247. package/build/index.cjs.map +0 -7
  248. package/build/state/index.cjs.map +0 -7
  249. package/build/utils/index.cjs.map +0 -7
  250. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -66
  251. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -7
  252. package/build-module/image-editor/core/camera.mjs +0 -198
  253. package/build-module/image-editor/core/camera.mjs.map +0 -7
  254. package/build-module/image-editor/core/constants.mjs +0 -69
  255. package/build-module/image-editor/core/constants.mjs.map +0 -7
  256. package/build-module/image-editor/core/containment.mjs +0 -253
  257. package/build-module/image-editor/core/containment.mjs.map +0 -7
  258. package/build-module/image-editor/core/crop-rect.mjs +0 -23
  259. package/build-module/image-editor/core/crop-rect.mjs.map +0 -7
  260. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -120
  261. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -7
  262. package/build-module/image-editor/core/index.mjs +0 -36
  263. package/build-module/image-editor/core/index.mjs.map +0 -7
  264. package/build-module/image-editor/core/interaction-controller.mjs +0 -635
  265. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -7
  266. package/build-module/image-editor/core/math/rotation.mjs +0 -15
  267. package/build-module/image-editor/core/math/rotation.mjs.map +0 -7
  268. package/build-module/image-editor/core/math/sanitize.mjs +0 -63
  269. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -7
  270. package/build-module/image-editor/core/setter-helpers.mjs +0 -39
  271. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -7
  272. package/build-module/image-editor/core/source-region.mjs +0 -178
  273. package/build-module/image-editor/core/source-region.mjs.map +0 -7
  274. package/build-module/image-editor/core/state.mjs +0 -260
  275. package/build-module/image-editor/core/state.mjs.map +0 -7
  276. package/build-module/image-editor/core/stencil-math.mjs +0 -187
  277. package/build-module/image-editor/core/stencil-math.mjs.map +0 -7
  278. package/build-module/image-editor/core/transform-style.mjs +0 -27
  279. package/build-module/image-editor/core/transform-style.mjs.map +0 -7
  280. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -17
  281. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -7
  282. package/build-module/image-editor/core/types.mjs +0 -1
  283. package/build-module/image-editor/core/types.mjs.map +0 -7
  284. package/build-module/image-editor/core/viewport-state.mjs +0 -24
  285. package/build-module/image-editor/core/viewport-state.mjs.map +0 -7
  286. package/build-module/image-editor/index.mjs +0 -39
  287. package/build-module/image-editor/index.mjs.map +0 -7
  288. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -26
  289. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -7
  290. package/build-module/image-editor/react/components/cropper.mjs +0 -704
  291. package/build-module/image-editor/react/components/cropper.mjs.map +0 -7
  292. package/build-module/image-editor/react/components/index.mjs +0 -9
  293. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  294. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -147
  295. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -7
  296. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -37
  297. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -7
  298. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -66
  299. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -7
  300. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -414
  301. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -7
  302. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -27
  303. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -7
  304. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -46
  305. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -7
  306. package/build-module/image-editor/react/hooks/index.mjs +0 -8
  307. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  308. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -135
  309. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -7
  310. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  311. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  312. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -190
  313. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -7
  314. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -13
  315. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -7
  316. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -29
  317. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -7
  318. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -16
  319. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -7
  320. package/build-module/index.mjs.map +0 -7
  321. package/build-module/state/index.mjs.map +0 -7
  322. package/build-module/utils/index.mjs.map +0 -7
  323. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -80
  324. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  325. package/build-types/image-editor/core/camera.d.ts +0 -128
  326. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  327. package/build-types/image-editor/core/constants.d.ts +0 -99
  328. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  329. package/build-types/image-editor/core/containment.d.ts +0 -72
  330. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  331. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  332. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  333. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  334. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  335. package/build-types/image-editor/core/index.d.ts +0 -10
  336. package/build-types/image-editor/core/index.d.ts.map +0 -1
  337. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  338. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  339. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  340. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  341. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  342. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  343. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  344. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  345. package/build-types/image-editor/core/source-region.d.ts +0 -94
  346. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  347. package/build-types/image-editor/core/state.d.ts +0 -51
  348. package/build-types/image-editor/core/state.d.ts.map +0 -1
  349. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  350. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  351. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  352. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  353. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  354. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  355. package/build-types/image-editor/core/types.d.ts +0 -269
  356. package/build-types/image-editor/core/types.d.ts.map +0 -1
  357. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  358. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  359. package/build-types/image-editor/index.d.ts +0 -16
  360. package/build-types/image-editor/index.d.ts.map +0 -1
  361. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  362. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  363. package/build-types/image-editor/react/components/cropper.d.ts +0 -63
  364. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  365. package/build-types/image-editor/react/components/index.d.ts +0 -4
  366. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  367. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  368. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  369. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  370. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  371. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  372. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  373. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  374. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  375. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  376. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  377. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  378. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  379. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  380. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  381. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  382. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  383. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +0 -55
  384. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  385. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  386. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  387. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  388. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  389. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  390. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  391. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  392. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  393. package/src/components/media-editor-modal/build-modifiers.ts +0 -161
  394. package/src/image-editor/README.md +0 -61
  395. package/src/image-editor/core/camera.ts +0 -429
  396. package/src/image-editor/core/constants.ts +0 -150
  397. package/src/image-editor/core/containment.ts +0 -469
  398. package/src/image-editor/core/crop-rect.ts +0 -42
  399. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  400. package/src/image-editor/core/index.ts +0 -47
  401. package/src/image-editor/core/interaction-controller.ts +0 -976
  402. package/src/image-editor/core/math/rotation.ts +0 -26
  403. package/src/image-editor/core/math/sanitize.ts +0 -155
  404. package/src/image-editor/core/setter-helpers.ts +0 -63
  405. package/src/image-editor/core/source-region.ts +0 -367
  406. package/src/image-editor/core/state.ts +0 -484
  407. package/src/image-editor/core/stencil-math.ts +0 -379
  408. package/src/image-editor/core/transform-style.ts +0 -56
  409. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  410. package/src/image-editor/core/types.ts +0 -230
  411. package/src/image-editor/core/viewport-state.ts +0 -30
  412. package/src/image-editor/docs/architecture.md +0 -63
  413. package/src/image-editor/docs/recipes.md +0 -184
  414. package/src/image-editor/index.ts +0 -52
  415. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  416. package/src/image-editor/react/components/cropper.scss +0 -259
  417. package/src/image-editor/react/components/cropper.tsx +0 -1116
  418. package/src/image-editor/react/components/index.ts +0 -3
  419. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  420. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  421. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  422. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  423. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  424. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  425. package/src/image-editor/react/hooks/index.ts +0 -4
  426. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  427. package/src/image-editor/react/hooks/use-cropper-reducer.ts +0 -197
  428. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  429. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  430. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  431. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  432. package/src/image-editor/style.scss +0 -1
@@ -1,623 +0,0 @@
1
- import {
2
- useCallback,
3
- useEffect,
4
- useId,
5
- useMemo,
6
- useRef,
7
- } from '@wordpress/element';
8
- import { __ } from '@wordpress/i18n';
9
- import type { StencilProps, NormalizedRect } from '../../../core/types';
10
- import {
11
- DEFAULT_KEYBOARD_STEP,
12
- KEYBOARD_SHIFT_STEP_MULTIPLIER,
13
- } from '../../../core/constants';
14
- import {
15
- computeFreeResizeRect,
16
- computeLockedResizeRect,
17
- computeShiftLockedResizeRect,
18
- type HandlePosition,
19
- type CropBounds,
20
- type ResizeDragState,
21
- type ResizeDriverAxis,
22
- } from '../../../core/stencil-math';
23
- import { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';
24
-
25
- /**
26
- * Corner handle positions only — used when aspect ratio is locked.
27
- * Ordered clockwise from top-left for logical tab order.
28
- */
29
- const CORNER_POSITIONS: HandlePosition[] = [ 'nw', 'ne', 'se', 'sw' ];
30
-
31
- /**
32
- * All handle positions rendered by the stencil.
33
- * Ordered clockwise from top-left for logical tab order.
34
- */
35
- const ALL_POSITIONS: HandlePosition[] = [
36
- 'nw',
37
- 'n',
38
- 'ne',
39
- 'e',
40
- 'se',
41
- 's',
42
- 'sw',
43
- 'w',
44
- ];
45
-
46
- /**
47
- * Get the translated aria-label for a resize handle position.
48
- *
49
- * @param pos The handle position identifier.
50
- * @return The translated label string.
51
- */
52
- function getHandleLabel( pos: HandlePosition ): string {
53
- switch ( pos ) {
54
- case 'n':
55
- return __( 'Resize from top edge' );
56
- case 's':
57
- return __( 'Resize from bottom edge' );
58
- case 'e':
59
- return __( 'Resize from right edge' );
60
- case 'w':
61
- return __( 'Resize from left edge' );
62
- case 'nw':
63
- return __( 'Resize from top-left corner' );
64
- case 'ne':
65
- return __( 'Resize from top-right corner' );
66
- case 'sw':
67
- return __( 'Resize from bottom-left corner' );
68
- case 'se':
69
- return __( 'Resize from bottom-right corner' );
70
- }
71
- }
72
-
73
- /** Delay before keyboard resize triggers settle (ms). */
74
- const KEYBOARD_SETTLE_DELAY = 500;
75
-
76
- /**
77
- * Props for the RectangleStencil component.
78
- */
79
- type RectangleStencilProps = StencilProps;
80
-
81
- /**
82
- * A rectangular crop stencil with resize handles.
83
- *
84
- * In freeform mode, handles resize the crop area. Clicks inside the
85
- * crop pass through to the container for image panning. The crop
86
- * auto-centers after resize via SETTLE_CROP.
87
- *
88
- * @param props Component props implementing StencilProps.
89
- * @param props.cropRect The crop rectangle in normalized coordinates.
90
- * @param props.containerSize The container element dimensions in pixels.
91
- * @param props.imageSize The rendered image dimensions in pixels.
92
- * @param props.onCropChange Callback fired when the crop rect changes.
93
- * @param props.onResizeStart Callback fired when a resize drag starts.
94
- * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).
95
- * @param props.aspectRatio Optional fixed aspect ratio (width / height).
96
- * @param props.freeformCrop Whether resize handles are shown.
97
- * @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.
98
- * @param props.stencilTransition CSS transition string for settle animation.
99
- * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).
100
- * @param props.onEscape Called when Escape is pressed on a resize handle.
101
- * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.
102
- * @param props.snapCropRect Optional post-processor for freeform resize output.
103
- * @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.
104
- * @return The rectangle stencil element.
105
- */
106
- export function RectangleStencil( {
107
- cropRect,
108
- containerSize,
109
- imageSize,
110
- onCropChange,
111
- onResizeStart,
112
- onResizeEnd,
113
- aspectRatio,
114
- freeformCrop = false,
115
- isResizeDisabled = false,
116
- stencilTransition,
117
- cropBounds,
118
- onEscape,
119
- minCropSize,
120
- snapCropRect,
121
- keyboardResizeStep,
122
- }: RectangleStencilProps ) {
123
- // Use cropBounds from the camera if available, otherwise default to [0,1].
124
- const boundsMinX = cropBounds?.minX ?? 0;
125
- const boundsMinY = cropBounds?.minY ?? 0;
126
- const boundsMaxX = cropBounds?.maxX ?? 1;
127
- const boundsMaxY = cropBounds?.maxY ?? 1;
128
- const bounds: CropBounds = useMemo(
129
- () => ( {
130
- minX: boundsMinX,
131
- minY: boundsMinY,
132
- maxX: boundsMaxX,
133
- maxY: boundsMaxY,
134
- } ),
135
- [ boundsMinX, boundsMinY, boundsMaxX, boundsMaxY ]
136
- );
137
- const keyboardSettleTimerRef = useRef<
138
- ReturnType< typeof setTimeout > | undefined
139
- >( undefined );
140
- const keyboardResizeActiveRef = useRef( false );
141
- const resizeHandleDescriptionId = useId();
142
- const hasLockedRatio = !! ( aspectRatio && aspectRatio > 0 );
143
- const activePointerResizeRef = useRef< {
144
- cancel: ( notifyResizeEnd?: boolean ) => void;
145
- } | null >( null );
146
-
147
- // Clear the pending keyboard settle timer on unmount so it can't
148
- // fire onResizeEnd / dispatch onto an unmounted parent.
149
- useEffect( () => {
150
- return () => {
151
- clearTimeout( keyboardSettleTimerRef.current );
152
- keyboardResizeActiveRef.current = false;
153
- activePointerResizeRef.current?.cancel( false );
154
- };
155
- }, [] );
156
-
157
- // Latest callbacks for the drag listeners. The drag closure in
158
- // handlePointerDown reads from this ref so it always sees current
159
- // props without having to re-attach listeners mid-drag. Previously,
160
- // drag listeners lived in a useEffect that re-ran whenever `bounds`
161
- // changed (every SET_CROP_RECT dispatch), creating a window where
162
- // pointerup could be missed and the crop would never settle.
163
- const latestHandlersRef = useRef< {
164
- hasLockedRatio: boolean;
165
- computeLockedRect: (
166
- drag: ResizeDragState,
167
- clientX: number,
168
- clientY: number,
169
- driverAxis?: ResizeDriverAxis
170
- ) => NormalizedRect;
171
- computeFreeRect: (
172
- drag: ResizeDragState,
173
- clientX: number,
174
- clientY: number
175
- ) => NormalizedRect;
176
- computeShiftLockedRect: (
177
- drag: ResizeDragState,
178
- clientX: number,
179
- clientY: number
180
- ) => NormalizedRect;
181
- onCropChange: ( rect: NormalizedRect ) => void;
182
- onResizeEnd?: () => void;
183
- snapCropRect?: (
184
- rect: NormalizedRect,
185
- handle: HandlePosition
186
- ) => NormalizedRect;
187
- } | null >( null );
188
-
189
- // The normalized aspect ratio: the w/h ratio in normalized space that
190
- // produces the desired pixel aspect ratio.
191
- // pixelW = w * imageSize.width, pixelH = h * imageSize.height
192
- // pixelW / pixelH = aspectRatio => w / h = aspectRatio * imageSize.height / imageSize.width
193
- const normalizedRatio = useMemo( () => {
194
- if ( ! hasLockedRatio || imageSize.width === 0 ) {
195
- return 0;
196
- }
197
- return ( aspectRatio * imageSize.height ) / imageSize.width;
198
- }, [ aspectRatio, hasLockedRatio, imageSize.width, imageSize.height ] );
199
-
200
- // Convert normalized crop rect to pixel bounds, accounting for the
201
- // image offset within the container.
202
- const offsetX = ( containerSize.width - imageSize.width ) / 2;
203
- const offsetY = ( containerSize.height - imageSize.height ) / 2;
204
- const left = offsetX + cropRect.x * imageSize.width;
205
- const top = offsetY + cropRect.y * imageSize.height;
206
- const width = cropRect.width * imageSize.width;
207
- const height = cropRect.height * imageSize.height;
208
-
209
- /**
210
- * Start a resize drag on a handle. Registers pointer listeners
211
- * synchronously so no events are missed between capture and the
212
- * next React commit.
213
- */
214
- const handlePointerDown = useCallback(
215
- ( handle: HandlePosition, event: React.PointerEvent ) => {
216
- if (
217
- isResizeDisabled ||
218
- ( event.pointerType === 'touch' && event.isPrimary === false )
219
- ) {
220
- event.preventDefault();
221
- event.stopPropagation();
222
- return;
223
- }
224
- if ( event.button !== 0 ) {
225
- return;
226
- }
227
- event.preventDefault();
228
- event.stopPropagation();
229
- // Blur any previously focused handle.
230
- const ownerDoc = event.currentTarget.ownerDocument;
231
- if ( ownerDoc.activeElement instanceof HTMLElement ) {
232
- ownerDoc.activeElement.blur();
233
- }
234
- // Capture pointer so drag works across iframe boundaries.
235
- const el = event.currentTarget as HTMLButtonElement;
236
- el.setPointerCapture( event.pointerId );
237
-
238
- const drag: ResizeDragState = {
239
- handle,
240
- startX: event.clientX,
241
- startY: event.clientY,
242
- startRect: { ...cropRect },
243
- };
244
-
245
- // RAF-throttle: stash the latest pointer position and
246
- // process it once per animation frame. Avoids dispatching
247
- // on every pointermove (which fires at much higher than
248
- // screen refresh rate) and matches the pan-drag path in
249
- // InteractionController.
250
- let rafId = 0;
251
- let latestX = event.clientX;
252
- let latestY = event.clientY;
253
- let latestShift = event.shiftKey;
254
-
255
- const onMove = ( e: Event ) => {
256
- const pe = e as PointerEvent;
257
- latestX = pe.clientX;
258
- latestY = pe.clientY;
259
- latestShift = pe.shiftKey;
260
- if ( rafId ) {
261
- return;
262
- }
263
- rafId = requestAnimationFrame( () => {
264
- rafId = 0;
265
- const h = latestHandlersRef.current;
266
- if ( ! h ) {
267
- return;
268
- }
269
- let newRect: NormalizedRect;
270
- if ( h.hasLockedRatio ) {
271
- newRect = h.computeLockedRect( drag, latestX, latestY );
272
- } else if ( latestShift ) {
273
- newRect = h.computeShiftLockedRect(
274
- drag,
275
- latestX,
276
- latestY
277
- );
278
- } else {
279
- newRect = h.computeFreeRect( drag, latestX, latestY );
280
- newRect =
281
- h.snapCropRect?.( newRect, drag.handle ) ?? newRect;
282
- }
283
- h.onCropChange( newRect );
284
- } );
285
- };
286
-
287
- // Guard against duplicate firing: pointerup and
288
- // lostpointercapture both fire on normal release.
289
- let ended = false;
290
- const endResize = (
291
- notifyResizeEnd = true,
292
- restoreFocus = true
293
- ) => {
294
- if ( ended ) {
295
- return;
296
- }
297
- ended = true;
298
- if ( rafId ) {
299
- cancelAnimationFrame( rafId );
300
- rafId = 0;
301
- }
302
- el.removeEventListener( 'pointermove', onMove );
303
- el.removeEventListener( 'pointerup', onEnd );
304
- el.removeEventListener( 'lostpointercapture', onEnd );
305
- activePointerResizeRef.current = null;
306
- if ( notifyResizeEnd ) {
307
- latestHandlersRef.current?.onResizeEnd?.();
308
- }
309
- // Restore focus to the handle so arrow keys work
310
- // immediately after a mouse drag. Browsers suppress
311
- // :focus-visible after pointer interactions, so the
312
- // focus ring stays hidden until the user presses a key.
313
- if ( restoreFocus ) {
314
- el.focus( { preventScroll: true } );
315
- }
316
- };
317
- const cancelResize = ( notifyResizeEnd = true ) =>
318
- endResize( notifyResizeEnd, false );
319
- const onEnd = () => endResize();
320
-
321
- el.addEventListener( 'pointermove', onMove );
322
- el.addEventListener( 'pointerup', onEnd );
323
- el.addEventListener( 'lostpointercapture', onEnd );
324
- activePointerResizeRef.current = { cancel: cancelResize };
325
-
326
- onResizeStart?.( handle );
327
- // Cancel any pending keyboard settle so it can't fire onResizeEnd
328
- // mid-drag if the user switches from keyboard to pointer within
329
- // the settle window.
330
- clearTimeout( keyboardSettleTimerRef.current );
331
- keyboardResizeActiveRef.current = false;
332
- },
333
- [ cropRect, isResizeDisabled, onResizeStart ]
334
- );
335
-
336
- /**
337
- * Compute the new crop rect for a free (no aspect ratio) resize.
338
- * Delegates to the pure function in core/stencil-math.ts.
339
- */
340
- const computeFreeRect = useCallback(
341
- (
342
- drag: ResizeDragState,
343
- clientX: number,
344
- clientY: number
345
- ): NormalizedRect =>
346
- computeFreeResizeRect(
347
- drag,
348
- clientX,
349
- clientY,
350
- imageSize,
351
- bounds,
352
- minCropSize
353
- ),
354
- [ imageSize, bounds, minCropSize ]
355
- );
356
-
357
- /**
358
- * Compute the new crop rect for a locked-aspect-ratio corner resize.
359
- * Delegates to the pure function in core/stencil-math.ts.
360
- */
361
- const computeLockedRect = useCallback(
362
- (
363
- drag: ResizeDragState,
364
- clientX: number,
365
- clientY: number,
366
- driverAxis?: ResizeDriverAxis
367
- ): NormalizedRect =>
368
- computeLockedResizeRect(
369
- drag,
370
- clientX,
371
- clientY,
372
- imageSize,
373
- bounds,
374
- normalizedRatio,
375
- minCropSize,
376
- driverAxis
377
- ),
378
- [ imageSize, bounds, normalizedRatio, minCropSize ]
379
- );
380
-
381
- /**
382
- * Compute the new crop rect when Shift is held during a freeform
383
- * resize — preserves the start rect's aspect ratio.
384
- */
385
- const computeShiftLockedRect = useCallback(
386
- (
387
- drag: ResizeDragState,
388
- clientX: number,
389
- clientY: number
390
- ): NormalizedRect =>
391
- computeShiftLockedResizeRect(
392
- drag,
393
- clientX,
394
- clientY,
395
- imageSize,
396
- bounds,
397
- minCropSize
398
- ),
399
- [ imageSize, bounds, minCropSize ]
400
- );
401
-
402
- latestHandlersRef.current = {
403
- hasLockedRatio,
404
- computeLockedRect,
405
- computeFreeRect,
406
- computeShiftLockedRect,
407
- onCropChange,
408
- onResizeEnd,
409
- snapCropRect,
410
- };
411
-
412
- // Cancel an in-flight resize when the handles are disabled. Reads
413
- // `onResizeEnd` from the ref above so a new callback identity does
414
- // not re-run this and close the gesture twice.
415
- useEffect( () => {
416
- if ( ! isResizeDisabled ) {
417
- return;
418
- }
419
- activePointerResizeRef.current?.cancel();
420
- // A keyboard resize settles on a timer rather than a pointer
421
- // release, so close it here too: otherwise the pending timer
422
- // fires `onResizeEnd` after the resize was already cancelled.
423
- if ( keyboardResizeActiveRef.current ) {
424
- clearTimeout( keyboardSettleTimerRef.current );
425
- keyboardResizeActiveRef.current = false;
426
- latestHandlersRef.current?.onResizeEnd?.();
427
- }
428
- }, [ isResizeDisabled ] );
429
-
430
- /**
431
- * Handle keyboard events on a resize handle.
432
- * Arrow keys resize; Escape returns focus to the canvas.
433
- * Shift multiplies the step size by 10 for coarser movement.
434
- */
435
- const handleKeyDown = useCallback(
436
- ( handle: HandlePosition, event: React.KeyboardEvent ) => {
437
- const key = event.key;
438
-
439
- if ( isResizeDisabled ) {
440
- return;
441
- }
442
-
443
- if ( key === 'Escape' ) {
444
- event.preventDefault();
445
- event.stopPropagation();
446
- onEscape?.();
447
- return;
448
- }
449
-
450
- if (
451
- key !== 'ArrowUp' &&
452
- key !== 'ArrowDown' &&
453
- key !== 'ArrowLeft' &&
454
- key !== 'ArrowRight'
455
- ) {
456
- return;
457
- }
458
-
459
- event.preventDefault();
460
- event.stopPropagation();
461
-
462
- if ( ! keyboardResizeActiveRef.current ) {
463
- keyboardResizeActiveRef.current = true;
464
- onResizeStart?.( handle );
465
- }
466
-
467
- const scheduleKeyboardResizeEnd = () => {
468
- clearTimeout( keyboardSettleTimerRef.current );
469
- keyboardSettleTimerRef.current = setTimeout( () => {
470
- keyboardResizeActiveRef.current = false;
471
- onResizeEnd?.();
472
- }, KEYBOARD_SETTLE_DELAY );
473
- };
474
-
475
- const stepMultiplier = event.shiftKey
476
- ? KEYBOARD_SHIFT_STEP_MULTIPLIER
477
- : 1;
478
- const stepX = keyboardResizeStep?.width ?? DEFAULT_KEYBOARD_STEP;
479
- const stepY = keyboardResizeStep?.height ?? DEFAULT_KEYBOARD_STEP;
480
- const adjustedStepX = stepX * stepMultiplier;
481
- const adjustedStepY = stepY * stepMultiplier;
482
-
483
- // Determine the normalized delta from the arrow key.
484
- let dx = 0;
485
- let dy = 0;
486
- if ( key === 'ArrowLeft' ) {
487
- dx = -adjustedStepX;
488
- }
489
- if ( key === 'ArrowRight' ) {
490
- dx = adjustedStepX;
491
- }
492
- if ( key === 'ArrowUp' ) {
493
- dy = -adjustedStepY;
494
- }
495
- if ( key === 'ArrowDown' ) {
496
- dy = adjustedStepY;
497
- }
498
- const keyboardDriverAxis: ResizeDriverAxis =
499
- dx !== 0 ? 'width' : 'height';
500
-
501
- if ( hasLockedRatio ) {
502
- // For locked aspect ratio, synthesize a drag from the
503
- // current rect and apply the delta via computeLockedRect.
504
- const syntheticDrag: ResizeDragState = {
505
- handle,
506
- startX: 0,
507
- startY: 0,
508
- startRect: { ...cropRect },
509
- };
510
- const clientX = dx * imageSize.width;
511
- const clientY = dy * imageSize.height;
512
- onCropChange(
513
- computeLockedRect(
514
- syntheticDrag,
515
- clientX,
516
- clientY,
517
- keyboardDriverAxis
518
- )
519
- );
520
- scheduleKeyboardResizeEnd();
521
- } else {
522
- // For freeform resize, synthesize a drag via computeFreeRect.
523
- const syntheticDrag: ResizeDragState = {
524
- handle,
525
- startX: 0,
526
- startY: 0,
527
- startRect: { ...cropRect },
528
- };
529
- const clientX = dx * imageSize.width;
530
- const clientY = dy * imageSize.height;
531
- const rect = computeFreeRect( syntheticDrag, clientX, clientY );
532
- onCropChange( snapCropRect?.( rect, handle ) ?? rect );
533
- scheduleKeyboardResizeEnd();
534
- }
535
- },
536
- [
537
- cropRect,
538
- hasLockedRatio,
539
- imageSize.width,
540
- imageSize.height,
541
- computeLockedRect,
542
- computeFreeRect,
543
- onCropChange,
544
- onResizeStart,
545
- onResizeEnd,
546
- onEscape,
547
- keyboardResizeStep,
548
- snapCropRect,
549
- isResizeDisabled,
550
- ]
551
- );
552
-
553
- if ( containerSize.width === 0 || containerSize.height === 0 ) {
554
- return null;
555
- }
556
-
557
- const handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;
558
-
559
- return (
560
- <div
561
- className="wp-media-editor-image-editor__stencil"
562
- data-testid="cropper-stencil"
563
- style={ {
564
- left,
565
- top,
566
- width,
567
- height,
568
- transition: stencilTransition,
569
- } }
570
- >
571
- { freeformCrop && (
572
- <div
573
- id={ resizeHandleDescriptionId }
574
- style={ VISUALLY_HIDDEN_STYLE }
575
- >
576
- { __(
577
- 'Use arrow keys to resize the crop area. Hold Shift for larger steps.'
578
- ) }
579
- </div>
580
- ) }
581
- { /* The crop rectangle border. pointer-events: none is set in
582
- CSS so clicks pass through to the container for panning. */ }
583
- <div
584
- className="wp-media-editor-image-editor__stencil-rect"
585
- style={ {
586
- width: '100%',
587
- height: '100%',
588
- top: 0,
589
- left: 0,
590
- } }
591
- />
592
- { /* Resize handles — only in freeform mode.
593
- Semantics: role="button" with aria-label describing
594
- which edge/corner. Arrow keys resize (onKeyDown).
595
- role="slider" would be more precise but requires
596
- per-handle aria-valuemin/max/now which don't map
597
- cleanly to a 2D crop rect. */ }
598
- { freeformCrop &&
599
- handles.map( ( pos ) => (
600
- <button
601
- key={ pos }
602
- type="button"
603
- className={ `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${ pos }` }
604
- onPointerDown={ ( event ) =>
605
- handlePointerDown( pos, event )
606
- }
607
- onTouchStart={ ( event ) => {
608
- if ( event.touches.length < 2 ) {
609
- event.stopPropagation();
610
- }
611
- } }
612
- onKeyDown={ ( event ) => handleKeyDown( pos, event ) }
613
- // The handlers already refuse input, but the
614
- // button must say so too, or assistive technology
615
- // announces a control that does nothing.
616
- disabled={ isResizeDisabled }
617
- aria-label={ getHandleLabel( pos ) }
618
- aria-describedby={ resizeHandleDescriptionId }
619
- />
620
- ) ) }
621
- </div>
622
- );
623
- }
@@ -1,32 +0,0 @@
1
- import { createContext, useContext } from '@wordpress/element';
2
- import {
3
- useViewportState,
4
- type UseViewportStateReturn,
5
- } from '../hooks/use-viewport-state';
6
-
7
- type ViewportContextValue = UseViewportStateReturn;
8
-
9
- const ViewportContext = createContext< ViewportContextValue | null >( null );
10
-
11
- export function ViewportProvider( {
12
- children,
13
- }: {
14
- children: React.ReactNode;
15
- } ) {
16
- const viewportState = useViewportState();
17
- return (
18
- <ViewportContext.Provider value={ viewportState }>
19
- { children }
20
- </ViewportContext.Provider>
21
- );
22
- }
23
-
24
- export function useViewport(): UseViewportStateReturn {
25
- const context = useContext( ViewportContext );
26
- if ( ! context ) {
27
- throw new Error(
28
- 'useViewport must be used within a ViewportProvider.'
29
- );
30
- }
31
- return context;
32
- }