@wordpress/media-editor 0.7.0 → 0.8.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 (306) hide show
  1. package/build/components/media-editor-canvas/index.cjs +54 -0
  2. package/build/components/media-editor-canvas/index.cjs.map +7 -0
  3. package/build/components/media-editor-crop-panel/index.cjs +116 -0
  4. package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
  5. package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
  6. package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
  7. package/build/components/media-editor-modal/index.cjs +497 -0
  8. package/build/components/media-editor-modal/index.cjs.map +7 -0
  9. package/build/components/media-editor-toolbar/index.cjs +146 -0
  10. package/build/components/media-editor-toolbar/index.cjs.map +7 -0
  11. package/build/components/media-preview/index.cjs +1 -1
  12. package/build/components/media-preview/index.cjs.map +2 -2
  13. package/build/image-editor/core/camera.cjs +194 -0
  14. package/build/image-editor/core/camera.cjs.map +7 -0
  15. package/build/image-editor/core/constants.cjs +81 -0
  16. package/build/image-editor/core/constants.cjs.map +7 -0
  17. package/build/image-editor/core/containment.cjs +245 -0
  18. package/build/image-editor/core/containment.cjs.map +7 -0
  19. package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
  20. package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
  21. package/build/image-editor/core/index.cjs +50 -0
  22. package/build/image-editor/core/index.cjs.map +7 -0
  23. package/build/image-editor/core/interaction-controller.cjs +608 -0
  24. package/build/image-editor/core/interaction-controller.cjs.map +7 -0
  25. package/build/image-editor/core/math/rotation.cjs +41 -0
  26. package/build/image-editor/core/math/rotation.cjs.map +7 -0
  27. package/build/image-editor/core/source-region.cjs +95 -0
  28. package/build/image-editor/core/source-region.cjs.map +7 -0
  29. package/build/image-editor/core/state.cjs +269 -0
  30. package/build/image-editor/core/state.cjs.map +7 -0
  31. package/build/image-editor/core/stencil-math.cjs +197 -0
  32. package/build/image-editor/core/stencil-math.cjs.map +7 -0
  33. package/build/image-editor/core/transform-style.cjs +46 -0
  34. package/build/image-editor/core/transform-style.cjs.map +7 -0
  35. package/build/image-editor/core/transforms/pipeline.cjs +43 -0
  36. package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
  37. package/build/image-editor/core/types.cjs +19 -0
  38. package/build/image-editor/core/types.cjs.map +7 -0
  39. package/build/image-editor/index.cjs +57 -0
  40. package/build/image-editor/index.cjs.map +7 -0
  41. package/build/image-editor/react/components/cropper-provider.cjs +50 -0
  42. package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
  43. package/build/image-editor/react/components/cropper.cjs +365 -0
  44. package/build/image-editor/react/components/cropper.cjs.map +7 -0
  45. package/build/image-editor/react/components/index.cjs +36 -0
  46. package/build/image-editor/react/components/index.cjs.map +7 -0
  47. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
  48. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
  49. package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
  50. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
  51. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
  52. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
  53. package/build/image-editor/react/hooks/index.cjs +31 -0
  54. package/build/image-editor/react/hooks/index.cjs.map +7 -0
  55. package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
  56. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
  57. package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
  58. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
  59. package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
  60. package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
  61. package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
  62. package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
  63. package/build/index.cjs +5 -2
  64. package/build/index.cjs.map +2 -2
  65. package/build/lock-unlock.cjs +37 -0
  66. package/build/lock-unlock.cjs.map +7 -0
  67. package/build/private-apis.cjs +38 -0
  68. package/build/private-apis.cjs.map +7 -0
  69. package/build/store/actions.cjs +45 -0
  70. package/build/store/actions.cjs.map +7 -0
  71. package/build/store/constants.cjs +31 -0
  72. package/build/store/constants.cjs.map +7 -0
  73. package/build/store/index.cjs +51 -0
  74. package/build/store/index.cjs.map +7 -0
  75. package/build/store/reducer.cjs +51 -0
  76. package/build/store/reducer.cjs.map +7 -0
  77. package/build/store/selectors.cjs +43 -0
  78. package/build/store/selectors.cjs.map +7 -0
  79. package/build-module/components/media-editor-canvas/index.mjs +33 -0
  80. package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
  81. package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
  82. package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
  83. package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
  84. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
  85. package/build-module/components/media-editor-modal/index.mjs +483 -0
  86. package/build-module/components/media-editor-modal/index.mjs.map +7 -0
  87. package/build-module/components/media-editor-toolbar/index.mjs +130 -0
  88. package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
  89. package/build-module/components/media-preview/index.mjs +1 -1
  90. package/build-module/components/media-preview/index.mjs.map +2 -2
  91. package/build-module/image-editor/core/camera.mjs +163 -0
  92. package/build-module/image-editor/core/camera.mjs.map +7 -0
  93. package/build-module/image-editor/core/constants.mjs +51 -0
  94. package/build-module/image-editor/core/constants.mjs.map +7 -0
  95. package/build-module/image-editor/core/containment.mjs +218 -0
  96. package/build-module/image-editor/core/containment.mjs.map +7 -0
  97. package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
  98. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
  99. package/build-module/image-editor/core/index.mjs +24 -0
  100. package/build-module/image-editor/core/index.mjs.map +7 -0
  101. package/build-module/image-editor/core/interaction-controller.mjs +583 -0
  102. package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
  103. package/build-module/image-editor/core/math/rotation.mjs +15 -0
  104. package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
  105. package/build-module/image-editor/core/source-region.mjs +69 -0
  106. package/build-module/image-editor/core/source-region.mjs.map +7 -0
  107. package/build-module/image-editor/core/state.mjs +242 -0
  108. package/build-module/image-editor/core/state.mjs.map +7 -0
  109. package/build-module/image-editor/core/stencil-math.mjs +169 -0
  110. package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
  111. package/build-module/image-editor/core/transform-style.mjs +21 -0
  112. package/build-module/image-editor/core/transform-style.mjs.map +7 -0
  113. package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
  114. package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
  115. package/build-module/image-editor/core/types.mjs +1 -0
  116. package/build-module/image-editor/core/types.mjs.map +7 -0
  117. package/build-module/image-editor/index.mjs +30 -0
  118. package/build-module/image-editor/index.mjs.map +7 -0
  119. package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
  120. package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
  121. package/build-module/image-editor/react/components/cropper.mjs +337 -0
  122. package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
  123. package/build-module/image-editor/react/components/index.mjs +9 -0
  124. package/build-module/image-editor/react/components/index.mjs.map +7 -0
  125. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
  126. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
  127. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
  128. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
  129. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
  130. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
  131. package/build-module/image-editor/react/hooks/index.mjs +6 -0
  132. package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
  133. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
  134. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
  135. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
  136. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
  137. package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
  138. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
  139. package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
  140. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
  141. package/build-module/index.mjs +3 -1
  142. package/build-module/index.mjs.map +2 -2
  143. package/build-module/lock-unlock.mjs +11 -0
  144. package/build-module/lock-unlock.mjs.map +7 -0
  145. package/build-module/private-apis.mjs +13 -0
  146. package/build-module/private-apis.mjs.map +7 -0
  147. package/build-module/store/actions.mjs +19 -0
  148. package/build-module/store/actions.mjs.map +7 -0
  149. package/build-module/store/constants.mjs +6 -0
  150. package/build-module/store/constants.mjs.map +7 -0
  151. package/build-module/store/index.mjs +16 -0
  152. package/build-module/store/index.mjs.map +7 -0
  153. package/build-module/store/reducer.mjs +26 -0
  154. package/build-module/store/reducer.mjs.map +7 -0
  155. package/build-module/store/selectors.mjs +16 -0
  156. package/build-module/store/selectors.mjs.map +7 -0
  157. package/build-style/style-rtl.css +315 -0
  158. package/build-style/style.css +315 -0
  159. package/build-types/components/media-editor-canvas/index.d.ts +22 -0
  160. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
  161. package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
  162. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
  163. package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
  164. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
  165. package/build-types/components/media-editor-modal/index.d.ts +20 -0
  166. package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
  167. package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
  168. package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
  169. package/build-types/components/media-preview/index.d.ts.map +1 -1
  170. package/build-types/image-editor/core/camera.d.ts +107 -0
  171. package/build-types/image-editor/core/camera.d.ts.map +1 -0
  172. package/build-types/image-editor/core/constants.d.ts +46 -0
  173. package/build-types/image-editor/core/constants.d.ts.map +1 -0
  174. package/build-types/image-editor/core/containment.d.ts +61 -0
  175. package/build-types/image-editor/core/containment.d.ts.map +1 -0
  176. package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
  177. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
  178. package/build-types/image-editor/core/index.d.ts +8 -0
  179. package/build-types/image-editor/core/index.d.ts.map +1 -0
  180. package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
  181. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
  182. package/build-types/image-editor/core/math/rotation.d.ts +18 -0
  183. package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
  184. package/build-types/image-editor/core/source-region.d.ts +75 -0
  185. package/build-types/image-editor/core/source-region.d.ts.map +1 -0
  186. package/build-types/image-editor/core/state.d.ts +42 -0
  187. package/build-types/image-editor/core/state.d.ts.map +1 -0
  188. package/build-types/image-editor/core/stencil-math.d.ts +79 -0
  189. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
  190. package/build-types/image-editor/core/transform-style.d.ts +23 -0
  191. package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
  192. package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
  193. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
  194. package/build-types/image-editor/core/types.d.ts +211 -0
  195. package/build-types/image-editor/core/types.d.ts.map +1 -0
  196. package/build-types/image-editor/index.d.ts +16 -0
  197. package/build-types/image-editor/index.d.ts.map +1 -0
  198. package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
  199. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
  200. package/build-types/image-editor/react/components/cropper.d.ts +59 -0
  201. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
  202. package/build-types/image-editor/react/components/index.d.ts +4 -0
  203. package/build-types/image-editor/react/components/index.d.ts.map +1 -0
  204. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
  205. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
  206. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
  207. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
  208. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
  209. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
  210. package/build-types/image-editor/react/hooks/index.d.ts +3 -0
  211. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
  212. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
  213. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
  214. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
  215. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
  216. package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
  217. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
  218. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
  219. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
  220. package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
  221. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
  222. package/build-types/index.d.ts +1 -0
  223. package/build-types/index.d.ts.map +1 -1
  224. package/build-types/lock-unlock.d.ts +2 -0
  225. package/build-types/lock-unlock.d.ts.map +1 -0
  226. package/build-types/private-apis.d.ts +2 -0
  227. package/build-types/private-apis.d.ts.map +1 -0
  228. package/build-types/store/actions.d.ts +27 -0
  229. package/build-types/store/actions.d.ts.map +1 -0
  230. package/build-types/store/constants.d.ts +2 -0
  231. package/build-types/store/constants.d.ts.map +1 -0
  232. package/build-types/store/index.d.ts +4 -0
  233. package/build-types/store/index.d.ts.map +1 -0
  234. package/build-types/store/reducer.d.ts +23 -0
  235. package/build-types/store/reducer.d.ts.map +1 -0
  236. package/build-types/store/selectors.d.ts +8 -0
  237. package/build-types/store/selectors.d.ts.map +1 -0
  238. package/package.json +21 -8
  239. package/src/components/media-editor-canvas/index.tsx +56 -0
  240. package/src/components/media-editor-canvas/style.scss +9 -0
  241. package/src/components/media-editor-crop-panel/index.tsx +143 -0
  242. package/src/components/media-editor-modal/build-modifiers.ts +164 -0
  243. package/src/components/media-editor-modal/index.tsx +639 -0
  244. package/src/components/media-editor-modal/style.scss +139 -0
  245. package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
  246. package/src/components/media-editor-toolbar/index.tsx +150 -0
  247. package/src/components/media-editor-toolbar/style.scss +21 -0
  248. package/src/components/media-preview/index.tsx +2 -1
  249. package/src/image-editor/README.md +162 -0
  250. package/src/image-editor/core/camera.ts +352 -0
  251. package/src/image-editor/core/constants.ts +93 -0
  252. package/src/image-editor/core/containment.ts +435 -0
  253. package/src/image-editor/core/export/canvas-renderer.ts +253 -0
  254. package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
  255. package/src/image-editor/core/index.ts +35 -0
  256. package/src/image-editor/core/interaction-controller.ts +889 -0
  257. package/src/image-editor/core/math/rotation.ts +26 -0
  258. package/src/image-editor/core/source-region.ts +166 -0
  259. package/src/image-editor/core/state.ts +428 -0
  260. package/src/image-editor/core/stencil-math.ts +330 -0
  261. package/src/image-editor/core/test/camera.ts +593 -0
  262. package/src/image-editor/core/test/interaction-controller.ts +996 -0
  263. package/src/image-editor/core/test/preview-export-parity.ts +242 -0
  264. package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
  265. package/src/image-editor/core/test/state.ts +762 -0
  266. package/src/image-editor/core/test/stencil-math.ts +321 -0
  267. package/src/image-editor/core/transform-style.ts +44 -0
  268. package/src/image-editor/core/transforms/pipeline.ts +43 -0
  269. package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
  270. package/src/image-editor/core/types.ts +177 -0
  271. package/src/image-editor/docs/architecture.md +96 -0
  272. package/src/image-editor/docs/recipes.md +720 -0
  273. package/src/image-editor/docs/roadmap.md +66 -0
  274. package/src/image-editor/index.ts +43 -0
  275. package/src/image-editor/react/components/cropper-provider.tsx +73 -0
  276. package/src/image-editor/react/components/cropper.scss +195 -0
  277. package/src/image-editor/react/components/cropper.tsx +534 -0
  278. package/src/image-editor/react/components/index.ts +3 -0
  279. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
  280. package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
  281. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
  282. package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
  283. package/src/image-editor/react/components/test/cropper.tsx +140 -0
  284. package/src/image-editor/react/hooks/index.ts +2 -0
  285. package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
  286. package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
  287. package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
  288. package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
  289. package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
  290. package/src/image-editor/react/hooks/use-interaction.ts +223 -0
  291. package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
  292. package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
  293. package/src/image-editor/stories/style.css +94 -0
  294. package/src/image-editor/style.scss +1 -0
  295. package/src/index.ts +3 -0
  296. package/src/lock-unlock.ts +10 -0
  297. package/src/private-apis.ts +12 -0
  298. package/src/store/actions.ts +33 -0
  299. package/src/store/constants.ts +1 -0
  300. package/src/store/index.ts +20 -0
  301. package/src/store/reducer.ts +48 -0
  302. package/src/store/selectors.ts +16 -0
  303. package/src/store/test/reducer.ts +57 -0
  304. package/src/style.scss +4 -0
  305. package/tsconfig.json +10 -2
  306. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,66 @@
1
+ # Roadmap
2
+
3
+ Follow-up work and future phases for the image editor. These are not blockers for the MVP — they're captured here so we don't lose track.
4
+
5
+ ## Phase 1 — API refinements
6
+
7
+ ### ~~Hide `dispatch` and `CropperAction`~~ — **done**
8
+
9
+ Reducer details are no longer part of the public API. `useCropperState()` returns a `controller` object with named setters (`setPan`, `setZoom`, `setZoomAtPoint`, `setRotation`, `setFlip`, `snapRotate90`, `setCropRect`, `settleCrop`, `applyOperation`, `reset`), plus `setImage` for loading and `getCroppedImage` for export. `<Cropper>` takes the controller as a single prop (`controller={ controller }`).
10
+
11
+ The controller object does not expose the reducer dispatch. Internal React code uses named interaction callbacks, and the reducer action type `CropperAction` is intentionally not exported from the public barrel.
12
+
13
+ ## Phase 2 — Framework-agnostic consumers
14
+
15
+ ### Promote core to public API if a real non-React consumer materializes
16
+
17
+ The `core/` layer (cropperReducer, InteractionController, computeTransformStyle, stencil math) is zero-dependency pure code. It's currently **not** exported publicly — tree-shaking means React-only consumers never bundle it, but non-React consumers can't use it either.
18
+
19
+ **Trigger to promote:** A concrete use case emerges (Vue integration, vanilla JS integration, server-side pipeline). At that point, decide whether to add these to the public barrel.
20
+
21
+ **Alternative:** Split into `@wordpress/image-editor-core` and `@wordpress/image-editor-react` as separate packages when there's real demand.
22
+
23
+ ## Phase 3 — Media editor expansion
24
+
25
+ ### Video editing
26
+
27
+ The package is named `@wordpress/media-editor` but currently only supports images. Adding video would require:
28
+
29
+ - Video frame extraction via `<VideoCropper>` wrapper (feed a frame through `applyToCanvas`).
30
+ - FFmpeg flag generator from `getSourceRegion()` for server-side transcoding.
31
+ - Eventually, client-side WebCodecs integration for in-browser video processing.
32
+
33
+ See `docs/planning/video-roadmap.md` in the git history for earlier thinking.
34
+
35
+ ### AI integration
36
+
37
+ The pipeline API (`TransformOperation[]`) is intentionally JSON-serializable for AI agent control:
38
+
39
+ - Auto-crop suggestions from image subject detection.
40
+ - Auto-straighten from horizon detection.
41
+ - Smart resize that preserves important content when aspect ratio changes.
42
+
43
+ These are consumer-side features built on the existing pipeline API. No core changes needed.
44
+
45
+ ## Phase 4 — Package distribution
46
+
47
+ ### Decide the final package boundary
48
+
49
+ The cropper currently lives inside `@wordpress/media-editor` as an internal module. Options for broader distribution:
50
+
51
+ - **Subpath export:** `@wordpress/media-editor/image-editor` — explicit subpath for consumers who only want the cropper.
52
+ - **Separate package:** `@wordpress/image-editor-next` (or similar) — ships independently.
53
+ - **Keep internal:** The cropper stays internal; only the media editor's top-level components are public.
54
+
55
+ Defer this decision until the API is stable and we have real consumers.
56
+
57
+ ## Known issues and follow-ups
58
+
59
+ ### Minor nits
60
+
61
+ - Custom slider for ±45° rotation would avoid the native `<input type="range">` behavior of tracking pointer outside the rail (see story demos).
62
+ - `cropBounds` recomputation depends on full `state` because React Compiler requires it. Lightweight enough to not matter, but documented as intentional.
63
+
64
+ ### Documented "escape hatches"
65
+
66
+ - Application code should use the controller's named setters or `applyOperation()`. Raw reducer actions are intentionally not part of the supported API.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Public image editor contract.
3
+ *
4
+ * Keep this barrel explicit so implementation details from `core/`,
5
+ * `react/hooks/`, or `react/components/` do not become supported API by
6
+ * accident. Internal modules may export additional helpers for local tests or
7
+ * React wiring; consumers should import through this file.
8
+ */
9
+
10
+ // React surface.
11
+ export { useCropperState } from './react/hooks';
12
+ export { Cropper, CropperProvider, useCropper } from './react/components';
13
+ export type { UseCropperStateReturn } from './react/hooks';
14
+ export type { CropperProps } from './react/components';
15
+
16
+ // State and extension types.
17
+ export type {
18
+ CropperState,
19
+ TransformOperation,
20
+ NormalizedPoint,
21
+ NormalizedRect,
22
+ Size,
23
+ Flip,
24
+ StencilProps,
25
+ } from './core';
26
+
27
+ // Deterministic cropper helpers.
28
+ export {
29
+ DEFAULT_STATE,
30
+ DEFAULT_ASPECT_RATIOS,
31
+ ORIGINAL_ASPECT_RATIO,
32
+ getSourceRegion,
33
+ getSourceRegionPercent,
34
+ applyOperationToState,
35
+ stateFromPipeline,
36
+ exportCroppedImage,
37
+ applyToCanvas,
38
+ } from './core';
39
+ export type {
40
+ AspectRatioPreset,
41
+ SourceRegion,
42
+ SourceRegionPercent,
43
+ } from './core';
@@ -0,0 +1,73 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { createContext, useContext } from '@wordpress/element';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import {
10
+ useCropperState,
11
+ type UseCropperStateReturn,
12
+ } from '../hooks/use-cropper-state';
13
+ import type { CropperState } from '../../core/types';
14
+
15
+ /**
16
+ * The context value type for the CropperProvider.
17
+ * Contains the full return value of useCropperState.
18
+ */
19
+ type CropperContextValue = UseCropperStateReturn | null;
20
+
21
+ const CropperContext = createContext< CropperContextValue >( null );
22
+
23
+ /**
24
+ * Props for the CropperProvider component.
25
+ */
26
+ interface CropperProviderProps {
27
+ /** Optional partial initial state to merge with defaults. */
28
+ initialState?: Partial< CropperState >;
29
+ /** Child components. */
30
+ children: React.ReactNode;
31
+ }
32
+
33
+ /**
34
+ * Convenience context provider that wraps useCropperState.
35
+ *
36
+ * Provides the full cropper state and action creators to all
37
+ * descendant components via React context.
38
+ *
39
+ * @param props Provider props.
40
+ * @param props.initialState
41
+ * @param props.children
42
+ * @return The provider element wrapping children.
43
+ */
44
+ export function CropperProvider( {
45
+ initialState,
46
+ children,
47
+ }: CropperProviderProps ) {
48
+ const cropperReturn = useCropperState( initialState );
49
+
50
+ return (
51
+ <CropperContext.Provider value={ cropperReturn }>
52
+ { children }
53
+ </CropperContext.Provider>
54
+ );
55
+ }
56
+
57
+ /**
58
+ * Hook to consume the CropperProvider context.
59
+ *
60
+ * Must be used within a CropperProvider. Throws if used outside
61
+ * of the provider tree.
62
+ *
63
+ * @return The cropper state and action creators.
64
+ */
65
+ export function useCropper(): UseCropperStateReturn {
66
+ const context = useContext( CropperContext );
67
+
68
+ if ( ! context ) {
69
+ throw new Error( 'useCropper must be used within a CropperProvider.' );
70
+ }
71
+
72
+ return context;
73
+ }
@@ -0,0 +1,195 @@
1
+ // Handle touch target size — used both for the handle ::before hit area and
2
+ // for the inner canvas inset (half the touch target on each side so the full
3
+ // reach extends to the crop edge).
4
+ $handle-touch-target-size: 44px;
5
+
6
+ .wp-media-editor-image-editor {
7
+ position: relative;
8
+ overflow: hidden;
9
+ width: 100%;
10
+ height: 100%;
11
+ touch-action: none;
12
+ user-select: none;
13
+ cursor: grab;
14
+
15
+ // Inner gutter for resize handles. Handles use negative offsets and a
16
+ // touch target that extends past the crop edge; the root clips overflow
17
+ // (required for the dimming overlay's box-shadow trick), so a flush
18
+ // handle would be clipped. The inner `__canvas` wrapper is inset by half
19
+ // the touch target, reserving reach room on all sides while keeping the
20
+ // root as the clipping boundary.
21
+ &__canvas {
22
+ position: absolute;
23
+ inset: calc($handle-touch-target-size / 2);
24
+ }
25
+
26
+ &--dragging {
27
+ cursor: grabbing;
28
+ }
29
+
30
+ &__image {
31
+ position: absolute;
32
+ top: 0;
33
+ left: 0;
34
+ will-change: transform;
35
+ transform-origin: center center;
36
+ }
37
+
38
+ &__stencil {
39
+ position: absolute;
40
+ pointer-events: none;
41
+ }
42
+
43
+ &__dimming {
44
+ position: absolute;
45
+ pointer-events: none;
46
+ /* Large shadow spread dims everything outside the crop area.
47
+ Darker at rest for clear crop framing, lighter during drag
48
+ so the user can see where they're panning. */
49
+ box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
50
+ transition: box-shadow 0.15s ease;
51
+ }
52
+
53
+ &--dragging &__dimming {
54
+ box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
55
+ }
56
+
57
+ &__grid {
58
+ position: absolute;
59
+ pointer-events: none;
60
+ overflow: hidden;
61
+ transition: opacity 0.15s ease;
62
+ }
63
+
64
+ &__canvas--grid-interactive &__grid {
65
+ opacity: 0;
66
+ transition-delay: 0.1s;
67
+ }
68
+
69
+ &__canvas--show-grid &__grid {
70
+ opacity: 1;
71
+ transition-delay: 0s;
72
+ }
73
+
74
+ &__grid-line {
75
+ position: absolute;
76
+ background: rgba(255, 255, 255, 0.4);
77
+
78
+ &--horizontal {
79
+ left: 0;
80
+ width: 100%;
81
+ height: 1px;
82
+ }
83
+
84
+ &--vertical {
85
+ top: 0;
86
+ height: 100%;
87
+ width: 1px;
88
+ }
89
+ }
90
+
91
+ &__stencil-rect {
92
+ position: absolute;
93
+ border: 1px solid rgba(255, 255, 255, 0.7);
94
+ box-sizing: border-box;
95
+ pointer-events: none;
96
+ }
97
+
98
+ &__handle {
99
+ // Reset native <button> UA styles — the handle is a button for
100
+ // accessibility (native keyboard focus, button semantics), but
101
+ // it's styled as a small draggable circle.
102
+ appearance: none;
103
+ margin: 0;
104
+ padding: 0;
105
+ font: inherit;
106
+ cursor: default;
107
+
108
+ position: absolute;
109
+ width: 12px;
110
+ height: 12px;
111
+ background: rgba(255, 255, 255, 0.6);
112
+ border: 1px solid rgba(255, 255, 255, 0.9);
113
+ border-radius: 50%;
114
+ box-sizing: border-box;
115
+ pointer-events: auto;
116
+ transition: background-color 0.15s ease, box-shadow 0.15s ease;
117
+
118
+ &:focus {
119
+ outline: none;
120
+ }
121
+
122
+ // Double ring (white inner + theme-color outer) for legibility
123
+ // over the dark dimming overlay.
124
+ &:focus-visible {
125
+ background: var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
126
+ border-color: transparent;
127
+ box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--wp-image-editor-focus-color, var(--wp-admin-theme-color, #007cba));
128
+ }
129
+
130
+ // Extend touch target to the minimum accessible hit area.
131
+ &::before {
132
+ content: "";
133
+ position: absolute;
134
+ top: 50%;
135
+ left: 50%;
136
+ width: $handle-touch-target-size;
137
+ height: $handle-touch-target-size;
138
+ transform: translate(-50%, -50%);
139
+ }
140
+
141
+ /* Offset by half the handle width (12px / 2 = 6px) to center on crop edge */
142
+ &--n {
143
+ top: -6px;
144
+ left: 50%;
145
+ margin-left: -6px;
146
+ cursor: ns-resize;
147
+ }
148
+
149
+ &--s {
150
+ bottom: -6px;
151
+ left: 50%;
152
+ margin-left: -6px;
153
+ cursor: ns-resize;
154
+ }
155
+
156
+ &--e {
157
+ top: 50%;
158
+ right: -6px;
159
+ margin-top: -6px;
160
+ cursor: ew-resize;
161
+ }
162
+
163
+ &--w {
164
+ top: 50%;
165
+ left: -6px;
166
+ margin-top: -6px;
167
+ cursor: ew-resize;
168
+ }
169
+
170
+ &--nw {
171
+ top: -6px;
172
+ left: -6px;
173
+ cursor: nwse-resize;
174
+ }
175
+
176
+ &--ne {
177
+ top: -6px;
178
+ right: -6px;
179
+ cursor: nesw-resize;
180
+ }
181
+
182
+ &--sw {
183
+ bottom: -6px;
184
+ left: -6px;
185
+ cursor: nesw-resize;
186
+ }
187
+
188
+ &--se {
189
+ bottom: -6px;
190
+ right: -6px;
191
+ cursor: nwse-resize;
192
+ }
193
+ }
194
+
195
+ }