@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,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor/use-save-media-editor.ts"],
4
- "sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\nimport {\n\tbuildModifiers,\n\ttype Modifier,\n} from '../media-editor-modal/build-modifiers';\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tconst { state } = session.cropper;\n\tif ( ! session.hasOutputEdits || ! state.image ) {\n\t\treturn [];\n\t}\n\treturn buildModifiers( state, {\n\t\twidth: state.image.naturalWidth,\n\t\theight: state.image.naturalHeight,\n\t} );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.cropper.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],
5
- "mappings": "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",
6
- "names": []
7
- }
1
+ {"version":3,"file":"use-save-media-editor.mjs","names":["coreStore","noticesStore"],"sources":["../../../src/components/media-editor/use-save-media-editor.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useCallback, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getImageEdit, mapImageEdit } from '@wordpress/image-editor';\nimport type { Media } from '../media-editor-provider';\nimport type { MediaEditorSession } from '../../state';\n\n/**\n * A single modifier in the Core REST `/edit` payload. Order is\n * significant — the server applies modifiers sequentially (see\n * `WP_REST_Attachments_Controller::edit_media_item`).\n *\n * Shape/units:\n * - `flip`: booleans per axis.\n * - `rotate`: `angle` in degrees, clockwise-positive (matches the\n * image editor's own convention; Core negates it internally for\n * `WP_Image_Editor::rotate`, which is counterclockwise-positive).\n * - `crop`: percentages (0–100) of the image's dimensions **at the\n * moment the crop is applied**. Because modifiers are applied in\n * order, after a preceding `rotate` the server's\n * `WP_Image_Editor::get_size()` reports the full post-rotate AABB,\n * so the percentages are of that AABB. Origin is top-left.\n */\ntype Modifier =\n\t| {\n\t\t\ttype: 'flip';\n\t\t\targs: { flip: { horizontal: boolean; vertical: boolean } };\n\t }\n\t| { type: 'rotate'; args: { angle: number } }\n\t| {\n\t\t\ttype: 'crop';\n\t\t\targs: { left: number; top: number; width: number; height: number };\n\t };\n\n// Details-tab edits are bundled into transformed `/edit` requests. Core's\n// endpoint only accepts this whitelist.\nconst METADATA_EDIT_KEYS = [\n\t'title',\n\t'caption',\n\t'description',\n\t'alt_text',\n\t'post',\n] as const;\n\n// Scope media editor snackbars so they don't leak into the host editor/page.\nexport const MEDIA_EDITOR_NOTICES_CONTEXT = 'media-editor';\n\ntype PendingMetadataEdits = Record< string, unknown > | undefined;\n\nexport interface MediaEditorSaveResult {\n\tid: number;\n\turl?: string;\n\tmedia: Media;\n\tprevious?: {\n\t\tid: number;\n\t\turl?: string;\n\t};\n}\n\ninterface UseSaveMediaEditorArgs {\n\tsession: MediaEditorSession;\n\tid: number;\n\tisImage: boolean;\n\tmedia?: Media | null;\n\tonSaved?: ( result: MediaEditorSaveResult ) => void;\n\t/**\n\t * When another attachment has replaced the edited one (today, the original\n\t * via \"Restore original image\"), the save targets the replacement:\n\t * - with no fresh crop, the block is repointed at the replacement and any\n\t * changed details are saved there (no `/edit`);\n\t * - with a fresh crop, `/edit` runs against the replacement's id and url.\n\t */\n\treplacementSource?: {\n\t\tid: number;\n\t\turl?: string;\n\t\tmedia: Media;\n\t};\n}\n\ninterface UseSaveMediaEditorReturn {\n\tisSaving: boolean;\n\tsave: () => Promise< void >;\n}\n\nfunction getCropModifiers( session: MediaEditorSession ): Modifier[] {\n\tif ( ! session.hasOutputEdits ) {\n\t\treturn [];\n\t}\n\tconst edit = getImageEdit( session.imageEditor.state );\n\tif ( ! edit ) {\n\t\treturn [];\n\t}\n\n\t// Core applies modifiers in the order they arrive.\n\treturn mapImageEdit< Modifier >( edit, {\n\t\tflip: ( flip ) => ( { type: 'flip', args: { flip } } ),\n\t\trotation: ( angle ) => ( { type: 'rotate', args: { angle } } ),\n\t\tcrop: ( { x, y, width, height } ) => ( {\n\t\t\ttype: 'crop',\n\t\t\targs: {\n\t\t\t\tleft: x * 100,\n\t\t\t\ttop: y * 100,\n\t\t\t\twidth: width * 100,\n\t\t\t\theight: height * 100,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction getMetadataEdits(\n\tpendingEdits: PendingMetadataEdits,\n\tmedia?: Media | null\n): Record< string, unknown > {\n\tconst metadataEdits: Record< string, unknown > = {};\n\tfor ( const key of METADATA_EDIT_KEYS ) {\n\t\tif ( pendingEdits && key in pendingEdits ) {\n\t\t\tmetadataEdits[ key ] = pendingEdits[ key ];\n\t\t}\n\t}\n\t// The `/edit` endpoint creates a new attachment for the crop and doesn't\n\t// inherit `post_parent` from the source (unlike title/caption/etc.), so\n\t// carry the existing value across when the user hasn't explicitly edited\n\t// it. Use a defined-check so an explicit `0` (unattached) is preserved.\n\tif ( ! ( 'post' in metadataEdits ) && media?.post !== undefined ) {\n\t\tmetadataEdits.post = media.post;\n\t}\n\treturn metadataEdits;\n}\n\nexport function useSaveMediaEditor( {\n\tsession,\n\tid,\n\tisImage,\n\tmedia,\n\tonSaved,\n\treplacementSource,\n}: UseSaveMediaEditorArgs ): UseSaveMediaEditorReturn {\n\tconst registry = useRegistry();\n\tconst {\n\t\tclearEntityRecordEdits,\n\t\treceiveEntityRecords,\n\t\tsaveEditedEntityRecord,\n\t} = useDispatch( coreStore );\n\tconst { createErrorNotice, removeAllNotices } = useDispatch( noticesStore );\n\tconst [ isSaving, setIsSaving ] = useState( false );\n\n\tconst save = useCallback( async () => {\n\t\tremoveAllNotices( 'snackbar', MEDIA_EDITOR_NOTICES_CONTEXT );\n\t\tsetIsSaving( true );\n\t\ttry {\n\t\t\tlet saved: Media | null | undefined;\n\t\t\tconst modifiers = getCropModifiers( session );\n\n\t\t\t// A replacement retargets the save; without one the current\n\t\t\t// attachment is both source and target as before.\n\t\t\tconst targetId = replacementSource?.id ?? id;\n\t\t\tconst targetUrl = replacementSource?.url ?? media?.source_url;\n\t\t\tconst targetMedia = replacementSource?.media ?? media;\n\n\t\t\t// Both a fresh crop and a bare replacement swap the block's image,\n\t\t\t// so both offer an Undo back to the current attachment.\n\t\t\tconst previous =\n\t\t\t\t( modifiers.length > 0 || replacementSource ) && media\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\turl: media.source_url,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\n\t\t\tif ( modifiers.length > 0 ) {\n\t\t\t\tconst pendingEdits = registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.getEntityRecordNonTransientEdits(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t) as PendingMetadataEdits;\n\t\t\t\tconst metadataEdits = getMetadataEdits(\n\t\t\t\t\tpendingEdits,\n\t\t\t\t\ttargetMedia\n\t\t\t\t);\n\n\t\t\t\tsaved = ( await apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/media/${ targetId }/edit`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tsrc: targetUrl,\n\t\t\t\t\t\tmodifiers,\n\t\t\t\t\t\t...metadataEdits,\n\t\t\t\t\t},\n\t\t\t\t} ) ) as Media;\n\n\t\t\t\tif ( saved ) {\n\t\t\t\t\treceiveEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tsaved,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\treplacementSource &&\n\t\t\t\t! registry\n\t\t\t\t\t.select( coreStore )\n\t\t\t\t\t.hasEditsForEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\ttargetId\n\t\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// A bare replacement only repoints the block. The replacement\n\t\t\t\t// already exists and has no changes to persist.\n\t\t\t\tsaved = replacementSource.media;\n\t\t\t} else {\n\t\t\t\tsaved = ( await saveEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\ttargetId,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t) ) as Media | undefined;\n\t\t\t}\n\n\t\t\tconst next = ( saved ?? targetMedia ) as Media | null;\n\n\t\t\tif ( next && next.id !== targetId ) {\n\t\t\t\tclearEntityRecordEdits( 'postType', 'attachment', targetId );\n\t\t\t}\n\n\t\t\tif ( next && next.id ) {\n\t\t\t\tif ( next.id === id ) {\n\t\t\t\t\tsession.reset();\n\t\t\t\t}\n\t\t\t\tonSaved?.( {\n\t\t\t\t\tid: next.id,\n\t\t\t\t\turl: next.source_url,\n\t\t\t\t\tmedia: next,\n\t\t\t\t\tprevious,\n\t\t\t\t} );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tconst message =\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: ( ( error as { message?: string } )?.message ??\n\t\t\t\t\t\t__( 'An unknown error occurred.' ) );\n\t\t\tcreateErrorNotice(\n\t\t\t\tisImage\n\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save image. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t)\n\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t\t\t__( 'Could not save media. %s' ),\n\t\t\t\t\t\t\tmessage\n\t\t\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tcontext: MEDIA_EDITOR_NOTICES_CONTEXT,\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsSaving( false );\n\t\t}\n\t}, [\n\t\tclearEntityRecordEdits,\n\t\tcreateErrorNotice,\n\t\tid,\n\t\tisImage,\n\t\tmedia,\n\t\tonSaved,\n\t\treceiveEntityRecords,\n\t\tregistry,\n\t\tremoveAllNotices,\n\t\treplacementSource,\n\t\tsaveEditedEntityRecord,\n\t\tsession,\n\t] );\n\n\treturn { isSaving, save };\n}\n"],"mappings":"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"}
@@ -1,104 +1,101 @@
1
- // packages/media-editor/src/components/media-editor-canvas/index.tsx
2
1
  import clsx from "clsx";
3
- import { useCallback, useEffect, useMemo, useState } from "@wordpress/element";
4
- import { Spinner as WCSpinner } from "@wordpress/components";
2
+ import { useCallback, useEffect, useState } from "@wordpress/element";
3
+ import { Spinner } from "@wordpress/components";
5
4
  import { __ } from "@wordpress/i18n";
5
+ import { ImageEditorCanvas } from "@wordpress/image-editor";
6
6
  import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
7
7
  import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
8
- import { Cropper } from "../../image-editor/index.mjs";
9
- import { useMediaEditor, resolveAspectRatio } from "../../state/index.mjs";
8
+ import { useMediaEditor } from "../../state/index.mjs";
10
9
  import { jsx, jsxs } from "react/jsx-runtime";
11
- function MediaEditorCanvas({
12
- isPlacementActive = false,
13
- onGestureStart,
14
- onGestureEnd,
15
- disabled = false
16
- }) {
17
- const { media } = useMediaEditorContext();
18
- const session = useMediaEditor();
19
- const { aspectRatioValue } = session.cropOptions;
20
- const cropperImage = session.cropper.state.image;
21
- const { beginGesture, endGesture, setSourceImage } = session;
22
- const [status, setStatus] = useState(
23
- "loading"
24
- );
25
- const aspectRatio = useMemo(
26
- () => resolveAspectRatio(aspectRatioValue, cropperImage),
27
- [aspectRatioValue, cropperImage]
28
- );
29
- const handleGestureStart = useCallback(() => {
30
- beginGesture();
31
- onGestureStart?.();
32
- }, [beginGesture, onGestureStart]);
33
- const handleGestureEnd = useCallback(() => {
34
- endGesture();
35
- onGestureEnd?.();
36
- }, [endGesture, onGestureEnd]);
37
- const mediaUrl = media?.source_url;
38
- const mediaType = getMediaTypeFromMimeType(media?.mime_type);
39
- const mediaWidth = Number(media?.media_details?.width);
40
- const mediaHeight = Number(media?.media_details?.height);
41
- useEffect(() => {
42
- if (!mediaUrl || !Number.isFinite(mediaWidth) || !Number.isFinite(mediaHeight) || mediaWidth <= 0 || mediaHeight <= 0) {
43
- return;
44
- }
45
- setSourceImage({
46
- src: mediaUrl,
47
- naturalWidth: mediaWidth,
48
- naturalHeight: mediaHeight
49
- });
50
- }, [mediaUrl, mediaWidth, mediaHeight, setSourceImage]);
51
- const isImage = mediaType.type === "image";
52
- useEffect(() => {
53
- if (!mediaUrl || !isImage) {
54
- return;
55
- }
56
- setStatus("loading");
57
- const probe = new window.Image();
58
- probe.onload = () => setStatus("loaded");
59
- probe.onerror = () => setStatus("error");
60
- probe.src = mediaUrl;
61
- if (probe.complete) {
62
- setStatus(probe.naturalWidth > 0 ? "loaded" : "error");
63
- }
64
- return () => {
65
- probe.onload = null;
66
- probe.onerror = null;
67
- };
68
- }, [mediaUrl, isImage]);
69
- if (!mediaUrl || !isImage) {
70
- return null;
71
- }
72
- if (status === "error") {
73
- return /* @__PURE__ */ jsx("div", { className: "media-editor-canvas", children: /* @__PURE__ */ jsx("div", { className: "media-editor-canvas__error", role: "alert", children: /* @__PURE__ */ jsx("p", { children: __("Failed to load image.") }) }) });
74
- }
75
- return /* @__PURE__ */ jsxs("div", { className: "media-editor-canvas", children: [
76
- status === "loading" && /* @__PURE__ */ jsx("div", { className: "media-editor-canvas__spinner", children: /* @__PURE__ */ jsx(WCSpinner, {}) }),
77
- /* @__PURE__ */ jsx(
78
- "div",
79
- {
80
- className: clsx("media-editor-canvas__cropper", {
81
- "is-loaded": status === "loaded"
82
- }),
83
- children: /* @__PURE__ */ jsx(
84
- Cropper,
85
- {
86
- src: mediaUrl,
87
- controller: session.cropper,
88
- aspectRatio,
89
- freeformCrop: true,
90
- showGrid: "interactive",
91
- isPlacementActive,
92
- onGestureStart: handleGestureStart,
93
- onGestureEnd: handleGestureEnd,
94
- disabled
95
- }
96
- )
97
- }
98
- )
99
- ] });
10
+ // packages/media-editor/src/components/media-editor-canvas/index.tsx
11
+ /**
12
+ * Editing surface for image media in the media editor modal. Pulls
13
+ * its image editor controller from the surrounding `<MediaEditorStateProvider>`
14
+ * so the bottom bar and Crop sidebar tab share the same state.
15
+ *
16
+ * Returns `null` for missing or non-image media so the modal's outer
17
+ * guards can render a spinner or fall through to `<MediaPreview>`.
18
+ *
19
+ * @param props
20
+ * @param props.isPlacementActive
21
+ * @param props.onGestureStart
22
+ * @param props.onGestureEnd
23
+ * @param props.disabled
24
+ */
25
+ function MediaEditorCanvas({ isPlacementActive = false, onGestureStart, onGestureEnd, disabled = false }) {
26
+ const { media } = useMediaEditorContext();
27
+ const session = useMediaEditor();
28
+ const { beginGesture, endGesture, setSourceImage } = session;
29
+ const [settled, setSettled] = useState();
30
+ const handleGestureStart = useCallback(() => {
31
+ beginGesture();
32
+ onGestureStart?.();
33
+ }, [beginGesture, onGestureStart]);
34
+ const handleGestureEnd = useCallback(() => {
35
+ endGesture();
36
+ onGestureEnd?.();
37
+ }, [endGesture, onGestureEnd]);
38
+ const mediaUrl = media?.source_url;
39
+ const mediaType = getMediaTypeFromMimeType(media?.mime_type);
40
+ const mediaWidth = Number(media?.media_details?.width);
41
+ const mediaHeight = Number(media?.media_details?.height);
42
+ useEffect(() => {
43
+ if (!mediaUrl || !Number.isFinite(mediaWidth) || !Number.isFinite(mediaHeight) || mediaWidth <= 0 || mediaHeight <= 0) return;
44
+ setSourceImage({
45
+ src: mediaUrl,
46
+ naturalWidth: mediaWidth,
47
+ naturalHeight: mediaHeight
48
+ });
49
+ }, [
50
+ mediaUrl,
51
+ mediaWidth,
52
+ mediaHeight,
53
+ setSourceImage
54
+ ]);
55
+ const isImage = mediaType.type === "image";
56
+ const status = settled && settled.url === mediaUrl ? settled.status : "loading";
57
+ const handleImageLoaded = useCallback(() => {
58
+ setSettled({
59
+ url: mediaUrl,
60
+ status: "loaded"
61
+ });
62
+ }, [mediaUrl]);
63
+ const handleImageError = useCallback(() => {
64
+ setSettled({
65
+ url: mediaUrl,
66
+ status: "error"
67
+ });
68
+ }, [mediaUrl]);
69
+ if (!mediaUrl || !isImage) return null;
70
+ if (status === "error") return /* @__PURE__ */ jsx("div", {
71
+ className: "media-editor-canvas",
72
+ children: /* @__PURE__ */ jsx("div", {
73
+ className: "media-editor-canvas__error",
74
+ role: "alert",
75
+ children: /* @__PURE__ */ jsx("p", { children: __("Failed to load image.") })
76
+ })
77
+ });
78
+ return /* @__PURE__ */ jsxs("div", {
79
+ className: "media-editor-canvas",
80
+ children: [status === "loading" && /* @__PURE__ */ jsx("div", {
81
+ className: "media-editor-canvas__spinner",
82
+ children: /* @__PURE__ */ jsx(Spinner, {})
83
+ }), /* @__PURE__ */ jsx("div", {
84
+ className: clsx("media-editor-canvas__image-editor", { "is-loaded": status === "loaded" }),
85
+ children: /* @__PURE__ */ jsx(ImageEditorCanvas, {
86
+ src: mediaUrl,
87
+ controller: session.imageEditor,
88
+ freeformCrop: true,
89
+ showGrid: isPlacementActive ? true : "interactive",
90
+ onGestureStart: handleGestureStart,
91
+ onGestureEnd: handleGestureEnd,
92
+ onImageLoaded: handleImageLoaded,
93
+ onImageError: handleImageError,
94
+ disabled
95
+ })
96
+ })]
97
+ });
100
98
  }
101
- export {
102
- MediaEditorCanvas as default
103
- };
104
- //# sourceMappingURL=index.mjs.map
99
+ export { MediaEditorCanvas as default };
100
+
101
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor-canvas/index.tsx"],
4
- "sourcesContent": ["import clsx from 'clsx';\nimport { useCallback, useEffect, useMemo, useState } from '@wordpress/element';\nimport { Spinner as WCSpinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { Cropper } from '../../image-editor';\nimport { useMediaEditor, resolveAspectRatio } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas cropper gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas cropper gesture ends. */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Disable crop interaction on the canvas. Set while the edit is saving,\n\t * so a drag cannot change the crop after the request was built.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its cropper controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n * @param props.disabled\n */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n\tdisabled = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst session = useMediaEditor();\n\tconst { aspectRatioValue } = session.cropOptions;\n\tconst cropperImage = session.cropper.state.image;\n\tconst { beginGesture, endGesture, setSourceImage } = session;\n\n\t// Tracks whether the image pixels have actually loaded. The cropper's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\tconst [ status, setStatus ] = useState< 'loading' | 'loaded' | 'error' >(\n\t\t'loading'\n\t);\n\n\t// Resolved aspect ratio is derived from the preset key + the\n\t// loaded image (for the \"Original\" preset). The reducer doesn't\n\t// store this number — only the preset key — so it's a render-time\n\t// derivation here.\n\tconst aspectRatio = useMemo(\n\t\t() => resolveAspectRatio( aspectRatioValue, cropperImage ),\n\t\t[ aspectRatioValue, cropperImage ]\n\t);\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetSourceImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\n\t// Probe the image to know when its pixels have loaded (or failed),\n\t// independent of the cropper. The browser shares one fetch/cache with the\n\t// cropper's own `<img>`, so this adds no network cost. The cropper stays\n\t// framework-pure — load/error handling lives here in the wrapper layer.\n\tuseEffect( () => {\n\t\tif ( ! mediaUrl || ! isImage ) {\n\t\t\treturn;\n\t\t}\n\t\tsetStatus( 'loading' );\n\t\tconst probe = new window.Image();\n\t\tprobe.onload = () => setStatus( 'loaded' );\n\t\tprobe.onerror = () => setStatus( 'error' );\n\t\tprobe.src = mediaUrl;\n\t\t// Cached images may already be complete before listeners attach.\n\t\tif ( probe.complete ) {\n\t\t\tsetStatus( probe.naturalWidth > 0 ? 'loaded' : 'error' );\n\t\t}\n\t\treturn () => {\n\t\t\tprobe.onload = null;\n\t\t\tprobe.onerror = null;\n\t\t};\n\t}, [ mediaUrl, isImage ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The cropper stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS).\n\t\t\t *\n\t\t\t * The crop area is never focused programmatically: the modal keeps\n\t\t\t * initial focus on the dialog frame, and users reach the crop area\n\t\t\t * by tabbing to it.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__cropper', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Cropper\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ session.cropper }\n\t\t\t\t\taspectRatio={ aspectRatio }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\tshowGrid=\"interactive\"\n\t\t\t\t\tisPlacementActive={ isPlacementActive }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": "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",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-editor-canvas/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useCallback, useEffect, useState } from '@wordpress/element';\nimport { Spinner as WCSpinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { ImageEditorCanvas } from '@wordpress/image-editor';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\nimport { useMediaEditor } from '../../state';\n\nexport interface MediaEditorCanvasProps {\n\t/** Whether external placement activity should reveal the grid. */\n\tisPlacementActive?: boolean;\n\t/** Fires when a canvas gesture begins. */\n\tonGestureStart?: () => void;\n\t/** Fires when a canvas gesture ends. */\n\tonGestureEnd?: () => void;\n\t/**\n\t * Disable crop interaction on the canvas. Set while the edit is saving,\n\t * so a drag cannot change the crop after the request was built.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Editing surface for image media in the media editor modal. Pulls\n * its image editor controller from the surrounding `<MediaEditorStateProvider>`\n * so the bottom bar and Crop sidebar tab share the same state.\n *\n * Returns `null` for missing or non-image media so the modal's outer\n * guards can render a spinner or fall through to `<MediaPreview>`.\n *\n * @param props\n * @param props.isPlacementActive\n * @param props.onGestureStart\n * @param props.onGestureEnd\n * @param props.disabled\n */\nexport default function MediaEditorCanvas( {\n\tisPlacementActive = false,\n\tonGestureStart,\n\tonGestureEnd,\n\tdisabled = false,\n}: MediaEditorCanvasProps ) {\n\tconst { media } = useMediaEditorContext();\n\tconst session = useMediaEditor();\n\tconst { beginGesture, endGesture, setSourceImage } = session;\n\n\t// Tracks whether the image pixels have actually loaded. The image editor's\n\t// geometry is driven by the known media dimensions, so its handles and\n\t// overlays would otherwise appear before the image finishes streaming in.\n\t// Stored with the URL it is for, so a new URL (restoring the original\n\t// swaps it in place) counts as loading until the image editor reports back.\n\tconst [ settled, setSettled ] = useState< {\n\t\turl: string | undefined;\n\t\tstatus: 'loaded' | 'error';\n\t} >();\n\n\tconst handleGestureStart = useCallback( () => {\n\t\tbeginGesture();\n\t\tonGestureStart?.();\n\t}, [ beginGesture, onGestureStart ] );\n\n\tconst handleGestureEnd = useCallback( () => {\n\t\tendGesture();\n\t\tonGestureEnd?.();\n\t}, [ endGesture, onGestureEnd ] );\n\n\tconst mediaUrl = media?.source_url;\n\tconst mediaType = getMediaTypeFromMimeType( media?.mime_type );\n\tconst mediaWidth = Number( media?.media_details?.width );\n\tconst mediaHeight = Number( media?.media_details?.height );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! mediaUrl ||\n\t\t\t! Number.isFinite( mediaWidth ) ||\n\t\t\t! Number.isFinite( mediaHeight ) ||\n\t\t\tmediaWidth <= 0 ||\n\t\t\tmediaHeight <= 0\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tsetSourceImage( {\n\t\t\tsrc: mediaUrl,\n\t\t\tnaturalWidth: mediaWidth,\n\t\t\tnaturalHeight: mediaHeight,\n\t\t} );\n\t}, [ mediaUrl, mediaWidth, mediaHeight, setSourceImage ] );\n\n\tconst isImage = mediaType.type === 'image';\n\tconst status =\n\t\tsettled && settled.url === mediaUrl ? settled.status : 'loading';\n\tconst handleImageLoaded = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'loaded' } );\n\t}, [ mediaUrl ] );\n\tconst handleImageError = useCallback( () => {\n\t\tsetSettled( { url: mediaUrl, status: 'error' } );\n\t}, [ mediaUrl ] );\n\n\tif ( ! mediaUrl || ! isImage ) {\n\t\treturn null;\n\t}\n\n\tif ( status === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-canvas\">\n\t\t\t\t<div className=\"media-editor-canvas__error\" role=\"alert\">\n\t\t\t\t\t<p>{ __( 'Failed to load image.' ) }</p>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div className=\"media-editor-canvas\">\n\t\t\t{ status === 'loading' && (\n\t\t\t\t<div className=\"media-editor-canvas__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * The image editor stays mounted while loading (hidden behind the\n\t\t\t * spinner) so the image decodes off-screen and reveals in one paint\n\t\t\t * instead of streaming in top-to-bottom. Until it's revealed it's\n\t\t\t * non-interactive (`pointer-events: none` in CSS).\n\t\t\t *\n\t\t\t * The crop area is never focused programmatically: the modal keeps\n\t\t\t * initial focus on the dialog frame, and users reach the crop area\n\t\t\t * by tabbing to it.\n\t\t\t */ }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'media-editor-canvas__image-editor', {\n\t\t\t\t\t'is-loaded': status === 'loaded',\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<ImageEditorCanvas\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\tcontroller={ session.imageEditor }\n\t\t\t\t\tfreeformCrop\n\t\t\t\t\t// Keep the grid up while a sidebar placement control is in\n\t\t\t\t\t// use; otherwise show it only while the crop is changing.\n\t\t\t\t\tshowGrid={ isPlacementActive ? true : 'interactive' }\n\t\t\t\t\tonGestureStart={ handleGestureStart }\n\t\t\t\t\tonGestureEnd={ handleGestureEnd }\n\t\t\t\t\tonImageLoaded={ handleImageLoaded }\n\t\t\t\t\tonImageError={ handleImageError }\n\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAwB,kBAAmB,EAC1C,oBAAoB,OACpB,gBACA,cACA,WAAW,SACgB;CAC3B,MAAM,EAAE,UAAU,sBAAsB;CACxC,MAAM,UAAU,eAAe;CAC/B,MAAM,EAAE,cAAc,YAAY,mBAAmB;CAOrD,MAAM,CAAE,SAAS,cAAe,SAG5B;CAEJ,MAAM,qBAAqB,kBAAmB;EAC7C,aAAa;EACb,iBAAiB;CAClB,GAAG,CAAE,cAAc,cAAe,CAAE;CAEpC,MAAM,mBAAmB,kBAAmB;EAC3C,WAAW;EACX,eAAe;CAChB,GAAG,CAAE,YAAY,YAAa,CAAE;CAEhC,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,yBAA0B,OAAO,SAAU;CAC7D,MAAM,aAAa,OAAQ,OAAO,eAAe,KAAM;CACvD,MAAM,cAAc,OAAQ,OAAO,eAAe,MAAO;CAEzD,gBAAiB;EAChB,IACC,CAAE,YACF,CAAE,OAAO,SAAU,UAAW,KAC9B,CAAE,OAAO,SAAU,WAAY,KAC/B,cAAc,KACd,eAAe,GAEf;EAED,eAAgB;GACf,KAAK;GACL,cAAc;GACd,eAAe;EAChB,CAAE;CACH,GAAG;EAAE;EAAU;EAAY;EAAa;CAAe,CAAE;CAEzD,MAAM,UAAU,UAAU,SAAS;CACnC,MAAM,SACL,WAAW,QAAQ,QAAQ,WAAW,QAAQ,SAAS;CACxD,MAAM,oBAAoB,kBAAmB;EAC5C,WAAY;GAAE,KAAK;GAAU,QAAQ;EAAS,CAAE;CACjD,GAAG,CAAE,QAAS,CAAE;CAChB,MAAM,mBAAmB,kBAAmB;EAC3C,WAAY;GAAE,KAAK;GAAU,QAAQ;EAAQ,CAAE;CAChD,GAAG,CAAE,QAAS,CAAE;CAEhB,IAAK,CAAE,YAAY,CAAE,SACpB,OAAO;CAGR,IAAK,WAAW,SACf,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAAC,OAAD;GAAK,WAAU;GAA6B,MAAK;GAChD,UAAA,oBAAC,KAAD,EAAA,UAAK,GAAI,uBAAwB,EAAM,CAAA;EACnC,CAAA;CACD,CAAA;CAIP,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACG,WAAW,aACZ,oBAAC,OAAD;GAAK,WAAU;GACd,UAAA,oBAACA,SAAD,CAAY,CAAA;EACR,CAAA,GAYN,oBAAC,OAAD;GACC,WAAY,KAAM,qCAAqC,EACtD,aAAa,WAAW,SACzB,CAAE;GAEF,UAAA,oBAAC,mBAAD;IACC,KAAM;IACN,YAAa,QAAQ;IACrB,cAAA;IAGA,UAAW,oBAAoB,OAAO;IACtC,gBAAiB;IACjB,cAAe;IACf,eAAgB;IAChB,cAAe;IACJ;GACX,CAAA;EACG,CAAA,CACD;;AAEP"}
@@ -1,52 +1,65 @@
1
- // packages/media-editor/src/components/media-editor-crop-panel/index.tsx
2
1
  import { SelectControl, Stack, VisuallyHidden } from "@wordpress/ui";
3
2
  import { __ } from "@wordpress/i18n";
3
+ import { Icon, getAspectRatioIcon } from "@wordpress/icons";
4
4
  import { CROP_CONTROL_ATTR } from "../../hooks/use-crop-gesture-handlers.mjs";
5
5
  import MediaEditorImageControls from "../media-editor-image-controls/index.mjs";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
- function MediaEditorCropPanel({
8
- aspectRatioValue,
9
- onAspectRatioChange,
10
- aspectRatioOptions,
11
- disabled = false
12
- }) {
13
- const items = aspectRatioOptions.map((preset) => ({
14
- label: preset.label,
15
- value: preset.value.toString()
16
- }));
17
- return (
18
- // Tag the whole panel as a crop-control region so the modal's
19
- // Cmd+Z handler doesn't mistake the SelectControl input for a
20
- // metadata field (which would suppress undo).
21
- /* @__PURE__ */ jsxs(
22
- Stack,
23
- {
24
- direction: "column",
25
- gap: "xl",
26
- ...{ [CROP_CONTROL_ATTR]: true },
27
- children: [
28
- /* @__PURE__ */ jsx(VisuallyHidden, { render: /* @__PURE__ */ jsx("h2", {}), children: __("Crop options") }),
29
- /* @__PURE__ */ jsx(MediaEditorImageControls, { withLabels: true, disabled }),
30
- /* @__PURE__ */ jsx(
31
- SelectControl,
32
- {
33
- label: __("Aspect ratio"),
34
- value: items.find((item) => item.value === aspectRatioValue) ?? null,
35
- onValueChange: (item) => {
36
- if (item && item.value !== null) {
37
- onAspectRatioChange(item.value);
38
- }
39
- },
40
- disabled,
41
- items
42
- }
43
- )
44
- ]
45
- }
46
- )
47
- );
7
+ // packages/media-editor/src/components/media-editor-crop-panel/index.tsx
8
+ /**
9
+ * Sidebar panel for crop controls: rotate, flip and zoom above the
10
+ * aspect-ratio selector. Rendered where the panel docks; below that the
11
+ * transform controls sit under the canvas instead, placed by the editor.
12
+ * @param props
13
+ * @param props.aspectRatioValue
14
+ * @param props.onAspectRatioChange
15
+ * @param props.aspectRatioOptions
16
+ * @param props.disabled
17
+ */
18
+ function MediaEditorCropPanel({ aspectRatioValue, onAspectRatioChange, aspectRatioOptions, disabled = false }) {
19
+ const items = aspectRatioOptions.map((preset) => ({
20
+ label: preset.label,
21
+ value: preset.value.toString()
22
+ }));
23
+ return /* @__PURE__ */ jsxs(Stack, {
24
+ direction: "column",
25
+ gap: "xl",
26
+ [CROP_CONTROL_ATTR]: true,
27
+ children: [
28
+ /* @__PURE__ */ jsx(VisuallyHidden, {
29
+ render: /* @__PURE__ */ jsx("h2", {}),
30
+ children: __("Crop options")
31
+ }),
32
+ /* @__PURE__ */ jsx(MediaEditorImageControls, {
33
+ withLabels: true,
34
+ disabled
35
+ }),
36
+ /* @__PURE__ */ jsx(SelectControl, {
37
+ label: __("Aspect ratio"),
38
+ value: items.find((item) => item.value === aspectRatioValue) ?? null,
39
+ onValueChange: (item) => {
40
+ if (item && item.value !== null) onAspectRatioChange(item.value);
41
+ },
42
+ disabled,
43
+ items,
44
+ trigger: /* @__PURE__ */ jsx(SelectControl.Trigger, { children: (item) => /* @__PURE__ */ jsxs("span", {
45
+ className: "media-editor-crop-panel__aspect-ratio-option",
46
+ children: [/* @__PURE__ */ jsx(Icon, { icon: getAspectRatioIcon(Number(item.value)) }), /* @__PURE__ */ jsx("span", {
47
+ className: "media-editor-crop-panel__aspect-ratio-label",
48
+ children: item.label
49
+ })]
50
+ }) }),
51
+ children: items.map((item) => /* @__PURE__ */ jsx(SelectControl.Item, {
52
+ value: item,
53
+ label: item.label,
54
+ children: /* @__PURE__ */ jsx(SelectControl.ItemLabel, { children: /* @__PURE__ */ jsxs("span", {
55
+ className: "media-editor-crop-panel__aspect-ratio-option",
56
+ children: [/* @__PURE__ */ jsx(Icon, { icon: getAspectRatioIcon(Number(item.value)) }), item.label]
57
+ }) })
58
+ }, item.value))
59
+ })
60
+ ]
61
+ });
48
62
  }
49
- export {
50
- MediaEditorCropPanel as default
51
- };
52
- //# sourceMappingURL=index.mjs.map
63
+ export { MediaEditorCropPanel as default };
64
+
65
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor-crop-panel/index.tsx"],
4
- "sourcesContent": ["import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\nimport type { AspectRatioPreset } from '../../image-editor/core/constants';\n\nexport interface MediaEditorCropPanelProps {\n\t/**\n\t * Selected aspect-ratio preset value as a string (so it round-trips\n\t * through `<SelectControl>`). `'0'` = free, `'-1'` = original, any\n\t * positive number = fixed ratio.\n\t */\n\taspectRatioValue: string;\n\t/** Setter for the aspect-ratio preset value. */\n\tonAspectRatioChange: ( value: string ) => void;\n\t/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n\t/** Disable every control in the panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls: rotate, flip and zoom above the\n * aspect-ratio selector. Rendered where the panel docks; below that the\n * transform controls sit under the canvas instead, placed by the editor.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.disabled\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tdisabled = false,\n}: MediaEditorCropPanelProps ) {\n\tconst items = aspectRatioOptions.map( ( preset ) => ( {\n\t\tlabel: preset.label,\n\t\tvalue: preset.value.toString(),\n\t} ) );\n\n\treturn (\n\t\t// Tag the whole panel as a crop-control region so the modal's\n\t\t// Cmd+Z handler doesn't mistake the SelectControl input for a\n\t\t// metadata field (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"xl\"\n\t\t\t{ ...{ [ CROP_CONTROL_ATTR ]: true } }\n\t\t>\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Crop options' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<MediaEditorImageControls withLabels disabled={ disabled } />\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={\n\t\t\t\t\titems.find( ( item ) => item.value === aspectRatioValue ) ??\n\t\t\t\t\tnull\n\t\t\t\t}\n\t\t\t\tonValueChange={ ( item ) => {\n\t\t\t\t\tif ( item && item.value !== null ) {\n\t\t\t\t\t\tonAspectRatioChange( item.value );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\titems={ items }\n\t\t\t/>\n\t\t</Stack>\n\t);\n}\n"],
5
- "mappings": ";AAAA,SAAS,eAAe,OAAO,sBAAsB;AACrD,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAClC,OAAO,8BAA8B;AA2CnC,SAK0B,KAL1B;AAfa,SAAR,qBAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AACZ,GAA+B;AAC9B,QAAM,QAAQ,mBAAmB,IAAK,CAAE,YAAc;AAAA,IACrD,OAAO,OAAO;AAAA,IACd,OAAO,OAAO,MAAM,SAAS;AAAA,EAC9B,EAAI;AAEJ;AAAA;AAAA;AAAA;AAAA,IAIC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,KAAI;AAAA,QACF,GAAG,EAAE,CAAE,iBAAkB,GAAG,KAAK;AAAA,QAEnC;AAAA,8BAAC,kBAAe,QAAS,oBAAC,QAAG,GAC1B,aAAI,cAAe,GACtB;AAAA,UACA,oBAAC,4BAAyB,YAAU,MAAC,UAAsB;AAAA,UAC3D;AAAA,YAAC;AAAA;AAAA,cACA,OAAQ,GAAI,cAAe;AAAA,cAC3B,OACC,MAAM,KAAM,CAAE,SAAU,KAAK,UAAU,gBAAiB,KACxD;AAAA,cAED,eAAgB,CAAE,SAAU;AAC3B,oBAAK,QAAQ,KAAK,UAAU,MAAO;AAClC,sCAAqB,KAAK,KAAM;AAAA,gBACjC;AAAA,cACD;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACD;AAAA;AAAA;AAAA,IACD;AAAA;AAEF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-crop-panel/index.tsx"],"sourcesContent":["import { SelectControl, Stack, VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, getAspectRatioIcon } from '@wordpress/icons';\nimport type { AspectRatioPreset } from '../../state/aspect-ratio-presets';\nimport { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';\nimport MediaEditorImageControls from '../media-editor-image-controls';\n\nexport interface MediaEditorCropPanelProps {\n\t/**\n\t * Selected aspect-ratio preset value as a string (so it round-trips\n\t * through `<SelectControl>`). `'0'` = free, `'-1'` = original, any\n\t * positive number = fixed ratio.\n\t */\n\taspectRatioValue: string;\n\t/** Setter for the aspect-ratio preset value. */\n\tonAspectRatioChange: ( value: string ) => void;\n\t/** Aspect-ratio presets to display in the selector. */\n\taspectRatioOptions: AspectRatioPreset[];\n\t/** Disable every control in the panel while the edit is saving. */\n\tdisabled?: boolean;\n}\n\n/**\n * Sidebar panel for crop controls: rotate, flip and zoom above the\n * aspect-ratio selector. Rendered where the panel docks; below that the\n * transform controls sit under the canvas instead, placed by the editor.\n * @param props\n * @param props.aspectRatioValue\n * @param props.onAspectRatioChange\n * @param props.aspectRatioOptions\n * @param props.disabled\n */\nexport default function MediaEditorCropPanel( {\n\taspectRatioValue,\n\tonAspectRatioChange,\n\taspectRatioOptions,\n\tdisabled = false,\n}: MediaEditorCropPanelProps ) {\n\tconst items = aspectRatioOptions.map( ( preset ) => ( {\n\t\tlabel: preset.label,\n\t\tvalue: preset.value.toString(),\n\t} ) );\n\n\treturn (\n\t\t// Tag the whole panel as a crop-control region so the modal's\n\t\t// Cmd+Z handler doesn't mistake the SelectControl input for a\n\t\t// metadata field (which would suppress undo).\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"xl\"\n\t\t\t{ ...{ [ CROP_CONTROL_ATTR ]: true } }\n\t\t>\n\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t{ __( 'Crop options' ) }\n\t\t\t</VisuallyHidden>\n\t\t\t<MediaEditorImageControls withLabels disabled={ disabled } />\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={\n\t\t\t\t\titems.find( ( item ) => item.value === aspectRatioValue ) ??\n\t\t\t\t\tnull\n\t\t\t\t}\n\t\t\t\tonValueChange={ ( item ) => {\n\t\t\t\t\tif ( item && item.value !== null ) {\n\t\t\t\t\t\tonAspectRatioChange( item.value );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\titems={ items }\n\t\t\t\ttrigger={\n\t\t\t\t\t<SelectControl.Trigger>\n\t\t\t\t\t\t{ ( item ) => (\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-label\">\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</SelectControl.Trigger>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ items.map( ( item ) => (\n\t\t\t\t\t<SelectControl.Item\n\t\t\t\t\t\tkey={ item.value }\n\t\t\t\t\t\tvalue={ item }\n\t\t\t\t\t\tlabel={ item.label }\n\t\t\t\t\t>\n\t\t\t\t\t\t<SelectControl.ItemLabel>\n\t\t\t\t\t\t\t<span className=\"media-editor-crop-panel__aspect-ratio-option\">\n\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\ticon={ getAspectRatioIcon(\n\t\t\t\t\t\t\t\t\t\tNumber( item.value )\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</SelectControl.ItemLabel>\n\t\t\t\t\t</SelectControl.Item>\n\t\t\t\t) ) }\n\t\t\t</SelectControl>\n\t\t</Stack>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,SAAwB,qBAAsB,EAC7C,kBACA,qBACA,oBACA,WAAW,SACmB;CAC9B,MAAM,QAAQ,mBAAmB,KAAO,YAAc;EACrD,OAAO,OAAO;EACd,OAAO,OAAO,MAAM,SAAS;CAC9B,EAAI;CAEJ,OAIC,qBAAC,OAAD;EACC,WAAU;EACV,KAAI;GACK,oBAAqB;EAH/B,UAAA;GAKC,oBAAC,gBAAD;IAAgB,QAAS,oBAAC,MAAD,CAAK,CAAA;IAC3B,UAAA,GAAI,cAAe;GACN,CAAA;GAChB,oBAAC,0BAAD;IAA0B,YAAA;IAAsB;GAAY,CAAA;GAC5D,oBAAC,eAAD;IACC,OAAQ,GAAI,cAAe;IAC3B,OACC,MAAM,MAAQ,SAAU,KAAK,UAAU,gBAAiB,KACxD;IAED,gBAAkB,SAAU;KAC3B,IAAK,QAAQ,KAAK,UAAU,MAC3B,oBAAqB,KAAK,KAAM;IAElC;IACW;IACH;IACR,SACC,oBAAC,cAAc,SAAf,EAAA,WACK,SACH,qBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACC,oBAAC,MAAD,EACC,MAAO,mBACN,OAAQ,KAAK,KAAM,CACpB,EACA,CAAA,GACD,oBAAC,QAAD;MAAM,WAAU;MACb,UAAA,KAAK;KACF,CAAA,CACD;IAEe,CAAA,EAAA,CAAA;IAGtB,UAAA,MAAM,KAAO,SACd,oBAAC,cAAc,MAAf;KAEC,OAAQ;KACR,OAAQ,KAAK;KAEb,UAAA,oBAAC,cAAc,WAAf,EAAA,UACC,qBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACC,oBAAC,MAAD,EACC,MAAO,mBACN,OAAQ,KAAK,KAAM,CACpB,EACA,CAAA,GACC,KAAK,KACF;KACkB,CAAA,EAAA,CAAA;IACN,GAdb,KAAK,KAcQ,CACnB;GACY,CAAA;EACT;;AAET"}
@@ -1,52 +1,45 @@
1
- // packages/media-editor/src/components/media-editor-fine-rotation/index.tsx
2
1
  import { __ } from "@wordpress/i18n";
3
2
  import { useMediaEditor } from "../../state/index.mjs";
4
3
  import { useCropGestureHandlers } from "../../hooks/use-crop-gesture-handlers.mjs";
5
- import { MAX_ROTATION_OFFSET } from "../../image-editor/core/constants.mjs";
6
4
  import RotationRuler from "../rotation-ruler/index.mjs";
7
5
  import { jsx } from "react/jsx-runtime";
8
- function MediaEditorFineRotation({
9
- onPlacementControlInteraction,
10
- disabled = false
11
- }) {
12
- const { state, setRotation } = useMediaEditor().cropper;
13
- const rotationGestureHandlers = useCropGestureHandlers({
14
- commitOnKeyUp: false
15
- });
16
- const baseAngle = Math.round(state.rotation / 90) * 90;
17
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
18
- const visualDir = singleFlip ? -1 : 1;
19
- const fineOffset = (state.rotation - baseAngle) * visualDir;
20
- const handleRotationSlider = (value) => {
21
- const EPS = 0.01;
22
- const clamped = Math.max(
23
- -MAX_ROTATION_OFFSET + EPS,
24
- Math.min(MAX_ROTATION_OFFSET - EPS, value)
25
- );
26
- onPlacementControlInteraction?.();
27
- setRotation(baseAngle + clamped * visualDir);
28
- };
29
- return /* @__PURE__ */ jsx(
30
- "div",
31
- {
32
- role: "presentation",
33
- className: "media-editor-fine-rotation",
34
- ...rotationGestureHandlers,
35
- children: /* @__PURE__ */ jsx(
36
- RotationRuler,
37
- {
38
- label: __("Fine rotation"),
39
- min: -MAX_ROTATION_OFFSET,
40
- max: MAX_ROTATION_OFFSET,
41
- value: fineOffset,
42
- onChange: handleRotationSlider,
43
- disabled
44
- }
45
- )
46
- }
47
- );
6
+ // packages/media-editor/src/components/media-editor-fine-rotation/index.tsx
7
+ /**
8
+ * Fine-rotation slider for the media editor. It renders under the canvas so it
9
+ * stays constrained to the canvas column at all viewport sizes. Lives
10
+ * separately from the snap-rotate / flip buttons so the two can be placed
11
+ * independently per viewport.
12
+ *
13
+ * @param props
14
+ * @param props.onPlacementControlInteraction
15
+ * @param props.disabled
16
+ */
17
+ function MediaEditorFineRotation({ onPlacementControlInteraction, disabled = false }) {
18
+ const { state, setRotation, maxRotationOffset } = useMediaEditor().imageEditor;
19
+ const rotationGestureHandlers = useCropGestureHandlers({ commitOnKeyUp: false });
20
+ const baseAngle = Math.round(state.rotation / 90) * 90;
21
+ const visualDir = state.flip.horizontal !== state.flip.vertical ? -1 : 1;
22
+ const fineOffset = (state.rotation - baseAngle) * visualDir;
23
+ const handleRotationSlider = (value) => {
24
+ const EPS = .01;
25
+ const clamped = Math.max(-maxRotationOffset + EPS, Math.min(maxRotationOffset - EPS, value));
26
+ onPlacementControlInteraction?.();
27
+ setRotation(baseAngle + clamped * visualDir);
28
+ };
29
+ return /* @__PURE__ */ jsx("div", {
30
+ role: "presentation",
31
+ className: "media-editor-fine-rotation",
32
+ ...rotationGestureHandlers,
33
+ children: /* @__PURE__ */ jsx(RotationRuler, {
34
+ label: __("Fine rotation"),
35
+ min: -maxRotationOffset,
36
+ max: maxRotationOffset,
37
+ value: fineOffset,
38
+ onChange: handleRotationSlider,
39
+ disabled
40
+ })
41
+ });
48
42
  }
49
- export {
50
- MediaEditorFineRotation as default
51
- };
52
- //# sourceMappingURL=index.mjs.map
43
+ export { MediaEditorFineRotation as default };
44
+
45
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor-fine-rotation/index.tsx"],
4
- "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation } = useMediaEditor().cropper;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";AAAA,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,OAAO,mBAAmB;AA6DvB;AAvCY,SAAR,wBAA0C;AAAA,EAChD;AAAA,EACA,WAAW;AACZ,GAAkC;AACjC,QAAM,EAAE,OAAO,YAAY,IAAI,eAAe,EAAE;AAIhD,QAAM,0BAA0B,uBAAwB;AAAA,IACvD,eAAe;AAAA,EAChB,CAAE;AAKF,QAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;AACtD,QAAM,aAAa,MAAM,KAAK,eAAe,MAAM,KAAK;AACxD,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,cAAe,MAAM,WAAW,aAAc;AAEpD,QAAM,uBAAuB,CAAE,UAAmB;AAIjD,UAAM,MAAM;AACZ,UAAM,UAAU,KAAK;AAAA,MACpB,CAAC,sBAAsB;AAAA,MACvB,KAAK,IAAK,sBAAsB,KAAK,KAAM;AAAA,IAC5C;AACA,oCAAgC;AAChC,gBAAa,YAAY,UAAU,SAAU;AAAA,EAC9C;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,WAAU;AAAA,MACR,GAAG;AAAA,MAEL;AAAA,QAAC;AAAA;AAAA,UACA,OAAQ,GAAI,eAAgB;AAAA,UAC5B,KAAM,CAAC;AAAA,UACP,KAAM;AAAA,UACN,OAAQ;AAAA,UACR,UAAW;AAAA,UACX;AAAA;AAAA,MACD;AAAA;AAAA,EACD;AAEF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/media-editor-fine-rotation/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { useMediaEditor } from '../../state';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorFineRotationProps {\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/**\n\t * Disable the ruler. Set while the edit is saving; `RotationRuler`\n\t * cancels an in-flight drag when this flips.\n\t */\n\tdisabled?: boolean;\n}\n\n/**\n * Fine-rotation slider for the media editor. It renders under the canvas so it\n * stays constrained to the canvas column at all viewport sizes. Lives\n * separately from the snap-rotate / flip buttons so the two can be placed\n * independently per viewport.\n *\n * @param props\n * @param props.onPlacementControlInteraction\n * @param props.disabled\n */\nexport default function MediaEditorFineRotation( {\n\tonPlacementControlInteraction,\n\tdisabled = false,\n}: MediaEditorFineRotationProps ) {\n\tconst { state, setRotation, maxRotationOffset } =\n\t\tuseMediaEditor().imageEditor;\n\t// `commitOnKeyUp: false` lets rapid arrow-key adjustments coalesce\n\t// into one undo entry via the gesture idle window. Pointer-up still\n\t// closes pointer drags immediately.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly ±MAX lands state on a\n\t\t// 90° midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-maxRotationOffset + EPS,\n\t\t\tMath.min( maxRotationOffset - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<div\n\t\t\trole=\"presentation\"\n\t\t\tclassName=\"media-editor-fine-rotation\"\n\t\t\t{ ...rotationGestureHandlers }\n\t\t>\n\t\t\t<RotationRuler\n\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\tmin={ -maxRotationOffset }\n\t\t\t\tmax={ maxRotationOffset }\n\t\t\t\tvalue={ fineOffset }\n\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\tdisabled={ disabled }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,SAAwB,wBAAyB,EAChD,+BACA,WAAW,SACsB;CACjC,MAAM,EAAE,OAAO,aAAa,sBAC3B,eAAe,CAAC,CAAC;CAIlB,MAAM,0BAA0B,uBAAwB,EACvD,eAAe,MAChB,CAAE;CAKF,MAAM,YAAY,KAAK,MAAO,MAAM,WAAW,EAAG,IAAI;CAEtD,MAAM,YADa,MAAM,KAAK,eAAe,MAAM,KAAK,WACzB,KAAK;CACpC,MAAM,cAAe,MAAM,WAAW,aAAc;CAEpD,MAAM,wBAAyB,UAAmB;EAIjD,MAAM,MAAM;EACZ,MAAM,UAAU,KAAK,IACpB,CAAC,oBAAoB,KACrB,KAAK,IAAK,oBAAoB,KAAK,KAAM,CAC1C;EACA,gCAAgC;EAChC,YAAa,YAAY,UAAU,SAAU;CAC9C;CAEA,OACC,oBAAC,OAAD;EACC,MAAK;EACL,WAAU;EACV,GAAK;EAEL,UAAA,oBAAC,eAAD;GACC,OAAQ,GAAI,eAAgB;GAC5B,KAAM,CAAC;GACP,KAAM;GACN,OAAQ;GACR,UAAW;GACA;EACX,CAAA;CACG,CAAA;AAEP"}