@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,162 @@
1
+ # Image Editor
2
+
3
+ > **Status: internal.** This module is not exported from `@wordpress/media-editor`'s public API. Only code inside `@wordpress/media-editor` should import it, via relative paths (e.g. `../image-editor`). When the module is promoted to the package's public surface, the `@wordpress/media-editor` import paths used in these docs will work.
4
+
5
+ A modular image editor inside `@wordpress/media-editor`. Two layers:
6
+
7
+ - **Core** — framework-agnostic state, math, and interaction logic. Pure TypeScript + `gl-matrix`. The export helpers in `core/export/` are browser-only (they use `HTMLCanvasElement` and `Image`), but everything else — reducer, camera math, interaction controller — has no DOM or React dependency. A non-React UI layer (Vue, Svelte, vanilla) can reuse core directly.
8
+ - **React adapter** — thin wrappers over core. The public surface is `<Cropper>`, `useCropperState`, plus the optional `CropperProvider` / `useCropper` context pair. `useInteraction` and `useTransformStyle` exist internally but are not exported.
9
+
10
+ ## Quick start
11
+
12
+ ```tsx
13
+ import { Cropper, useCropperState } from '../image-editor';
14
+
15
+ function ImageEditor() {
16
+ const controller = useCropperState();
17
+ return (
18
+ <div style={ { width: 600, height: 400 } }>
19
+ <Cropper
20
+ src="https://example.com/photo.jpg"
21
+ controller={ controller }
22
+ showDimming
23
+ showGrid
24
+ freeformCrop
25
+ />
26
+ </div>
27
+ );
28
+ }
29
+ ```
30
+
31
+ `useCropperState` returns a single `controller` object that bundles the current state and every setter. Pass it to `<Cropper>` as a single prop, and call setters like `controller.setZoom( 2 )` or `controller.snapRotate90( 1 )` from your own toolbars.
32
+
33
+ ## Styles
34
+
35
+ The cropper's styles are compiled as part of `@wordpress/media-editor`'s SCSS build. Internal callers that render `<Cropper>` inherit them automatically when the package's stylesheet is loaded. All CSS classes use the `wp-media-editor-image-editor` prefix.
36
+
37
+ ## Docs
38
+
39
+ - [docs/architecture.md](docs/architecture.md) — Data flow, coordinate spaces, and design decisions
40
+ - [docs/recipes.md](docs/recipes.md) — Getting started walkthrough, extension points, and integration patterns
41
+ - [docs/roadmap.md](docs/roadmap.md) — Planned follow-up work and phases
42
+
43
+ ## API Reference
44
+
45
+ ### React components
46
+
47
+ #### `Cropper`
48
+
49
+ Main cropper component. Fills its parent container.
50
+
51
+ | Prop | Type | Default | Description |
52
+ | ---------------- | ------------------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53
+ | `src` | `string` | **required** | Image source URL |
54
+ | `controller` | `UseCropperStateReturn` | **required** | The full object returned by `useCropperState()` |
55
+ | `stencil` | `ComponentType<StencilProps>` | `RectangleStencil` | Custom crop area UI |
56
+ | `showGrid` | `boolean` | `false` | Rule-of-thirds grid overlay |
57
+ | `showDimming` | `boolean` | `true` | Dimming overlay outside crop |
58
+ | `minZoom` | `number` | `1` | Minimum zoom for interactive gestures (wheel, pinch, double-tap). The reducer itself clamps to `[1, 10]` regardless, so a larger `minZoom` only narrows what the user can reach through gestures. |
59
+ | `maxZoom` | `number` | `10` | Maximum zoom for interactive gestures. Same caveat as `minZoom`. |
60
+ | `aspectRatio` | `number` | — | Fixed aspect ratio (width/height) |
61
+ | `freeformCrop` | `boolean` | `false` | Enable resize handles |
62
+ | `onImageLoaded` | `(size: Size) => void` | — | Image load callback |
63
+ | `onStateChange` | `(state: CropperState) => void` | — | Fires on every state change (high frequency — at pointermove rate during drags). Avoid heavy work in the handler; for commit-style events use `onGestureEnd` instead. |
64
+ | `onGestureStart` | `() => void` | — | Gesture boundary start |
65
+ | `onGestureEnd` | `() => void` | — | Gesture boundary end |
66
+ | `className` | `string` | — | Additional CSS class |
67
+
68
+ #### `CropperProvider` / `useCropper()`
69
+
70
+ Context wrapper for deep component trees. Wraps `useCropperState` and provides it to descendants via `useCropper()`.
71
+
72
+ ### React hooks
73
+
74
+ #### `useCropperState( initialState?: Partial<CropperState> ): UseCropperStateReturn`
75
+
76
+ State management hook. Returns a `controller` object with the current state and a named setter for each supported transition.
77
+
78
+ > **Pan vs. crop rectangle**: `setPan` / `state.pan` sets the image _pan offset_ (how the image is translated inside the viewport). `setCropRect` / `state.cropRect` sets the _crop rectangle_ (the region being selected).
79
+
80
+ | Field | Type | Description |
81
+ | ----------------- | ---------------------------------------------------- | ----------------------------------------------------------------------------------- |
82
+ | `state` | `CropperState` | Current state (read-only) |
83
+ | `setImage` | `(image: CropperState['image']) => void` | Set the loaded image (src + natural size) |
84
+ | `setPan` | `(pan: NormalizedPoint) => void` | Set image pan offset |
85
+ | `setZoom` | `(zoom: number) => void` | Set zoom (clamped 1–10) |
86
+ | `setZoomAtPoint` | `(zoom: number, pan: NormalizedPoint) => void` | Set zoom and pan together for focal-point zoom |
87
+ | `setRotation` | `(degrees: number) => void` | Set rotation (normalized 0–360) |
88
+ | `setFlip` | `(flip: Flip) => void` | Set flip state |
89
+ | `snapRotate90` | `(direction: 1 \| -1) => void` | 90° snap rotation |
90
+ | `setCropRect` | `(rect: NormalizedRect) => void` | Set crop rectangle |
91
+ | `settleCrop` | `() => void` | Settle the crop rect after a resize drag (typically from `onResizeEnd`) |
92
+ | `applyOperation` | `(op: TransformOperation) => void` | Apply a pipeline operation |
93
+ | `reset` | `(state?: Partial<CropperState>) => void` | Reset to initial or given state |
94
+ | `isDirty` | `boolean` | Whether state differs from initial |
95
+ | `getCroppedImage` | `(mime?: string, quality?: number) => Promise<Blob>` | Export as Blob. Throws on load/CORS/context failure — wrap in try/catch to recover. |
96
+
97
+ The controller does not expose the reducer dispatch. Use the named setters or `applyOperation()` to change state.
98
+
99
+ ### Source region
100
+
101
+ #### `getSourceRegion( state, imageSize ): SourceRegion`
102
+
103
+ Converts crop state to source-pixel coordinates: `{ x, y, width, height, rotation, flip, zoom }`. For server-side processing (FFmpeg, ImageMagick, etc.).
104
+
105
+ #### `getSourceRegionPercent( state, imageSize ): SourceRegionPercent`
106
+
107
+ Same as `getSourceRegion` but returns percentages (0–100): `{ x, y, width, height }`. Compatible with the WordPress REST API attachments `/edit` endpoint.
108
+
109
+ ### Export
110
+
111
+ #### `exportCroppedImage( src, state, mimeType?, quality? ): Promise<Blob>`
112
+
113
+ End-to-end: load image, render with transforms, export as Blob. Browser-only (needs `HTMLCanvasElement`).
114
+
115
+ Rejects on:
116
+
117
+ - **Image load failures** (network error, 404) — the native load error is propagated.
118
+ - **CORS / tainted canvas** — if the source doesn't set `Access-Control-Allow-Origin`, `canvas.toBlob()` rejects because the canvas is tainted. Fix at the server: send permissive CORS headers.
119
+ - **Missing canvas context** — throws with a descriptive `Error`.
120
+
121
+ Wrap in `try/catch` to distinguish failure modes.
122
+
123
+ #### `applyToCanvas( source: CanvasImageSource, imageSize, state ): HTMLCanvasElement`
124
+
125
+ Applies transforms to any `CanvasImageSource` (image, canvas, video frame, offscreen canvas). For multi-step editing pipelines.
126
+
127
+ ### Pipeline
128
+
129
+ #### `stateFromPipeline( operations: TransformOperation[] ): CropperState`
130
+
131
+ Replays a sequence of operations from default state. Pure function, no DOM needed. For headless/server-side processing.
132
+
133
+ #### `applyOperationToState( state, operation ): CropperState`
134
+
135
+ Applies a single operation to an existing state.
136
+
137
+ ### Types
138
+
139
+ | Type | Description |
140
+ | ----------------------- | --------------------------------------------------------------------------------- |
141
+ | `CropperState` | `{ image, pan, zoom, rotation, flip, cropRect, basePan, baseZoom, baseRotation }` |
142
+ | `UseCropperStateReturn` | The full shape returned by `useCropperState()`: state + setters |
143
+ | `CropperProps` | Props for the `<Cropper>` component |
144
+ | `StencilProps` | Contract for pluggable stencil components |
145
+ | `TransformOperation` | `{ type: 'crop' \| 'rotate' \| 'flip' \| 'zoom', ... }` |
146
+ | `NormalizedPoint` | `{ x: number, y: number }` in [0,1] space |
147
+ | `NormalizedRect` | `{ x, y, width, height }` in [0,1] space |
148
+ | `Size` | `{ width: number, height: number }` |
149
+ | `Flip` | `{ horizontal: boolean, vertical: boolean }` |
150
+ | `SourceRegion` | `{ x, y, width, height, rotation, flip, zoom }` in source pixels |
151
+ | `SourceRegionPercent` | `{ x, y, width, height }` as percentages (0–100) |
152
+ | `AspectRatioPreset` | `{ label: string, value: number }` |
153
+
154
+ `CropperAction` (the reducer's action union) is internal. Drive state through the named setters on the controller object.
155
+
156
+ ### Constants
157
+
158
+ | Constant | Value | Description |
159
+ | ----------------------- | ----- | ------------------------------------------------------ |
160
+ | `DEFAULT_STATE` | — | Default `CropperState` |
161
+ | `DEFAULT_ASPECT_RATIOS` | Array | Preset aspect ratios (Free, Original, 1:1, 16:9, etc.) |
162
+ | `ORIGINAL_ASPECT_RATIO` | `-1` | Sentinel value for "use image's original ratio" |
@@ -0,0 +1,352 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { mat2d, vec2 } from 'gl-matrix';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import type { CropperState, NormalizedPoint, Size, Camera } from './types';
10
+ import { degreesToRadians } from './math/rotation';
11
+
12
+ // Pre-allocated scratch buffers for `screenToWorld`, which is called per
13
+ // pointermove. Module-level singletons — safe because usage is synchronous.
14
+ const _scratchMat = mat2d.create();
15
+ const _scratchVec = vec2.create();
16
+
17
+ /**
18
+ * Compute the axis-aligned bounding box of a rectangle after rotation.
19
+ *
20
+ * @param width The width of the rectangle.
21
+ * @param height The height of the rectangle.
22
+ * @param rotation The rotation angle in degrees.
23
+ * @return The bounding box size after rotation.
24
+ */
25
+ export function getRotatedBBox(
26
+ width: number,
27
+ height: number,
28
+ rotation: number
29
+ ): Size {
30
+ const rad = degreesToRadians( rotation );
31
+ const cosR = Math.abs( Math.cos( rad ) );
32
+ const sinR = Math.abs( Math.sin( rad ) );
33
+ return {
34
+ width: cosR * width + sinR * height,
35
+ height: sinR * width + cosR * height,
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Compute the fitted (unrotated) image element dimensions and the visual
41
+ * (rotated) bounding box dimensions for a given container, image, and rotation.
42
+ *
43
+ * This is the same "contain" fit logic used by createCamera, extracted so
44
+ * cropper.tsx can size the <img> element and position overlays without
45
+ * duplicating the math.
46
+ *
47
+ * @param containerSize The container dimensions in pixels.
48
+ * @param imageSize The natural image dimensions in pixels.
49
+ * @param rotation The rotation angle in degrees.
50
+ * @return The fitted element size and visual bounding box size.
51
+ */
52
+ export function getImageFit(
53
+ containerSize: Size,
54
+ imageSize: Size,
55
+ rotation: number
56
+ ): { elementSize: Size; visualSize: Size } {
57
+ if (
58
+ containerSize.width === 0 ||
59
+ containerSize.height === 0 ||
60
+ imageSize.width === 0 ||
61
+ imageSize.height === 0
62
+ ) {
63
+ return {
64
+ elementSize: { width: 0, height: 0 },
65
+ visualSize: { width: 0, height: 0 },
66
+ };
67
+ }
68
+ // Snap rotation to the nearest 90° multiple for layout sizing.
69
+ // This keeps the stencil a stable size through fine ±45° rotation
70
+ // (no inflation at 15°/30° etc.) while still swapping aspect at
71
+ // 90°/180°/270° so the snap rotate preserves the framed content.
72
+ const snapRotation = Math.round( rotation / 90 ) * 90;
73
+ const naturalBBox = getRotatedBBox(
74
+ imageSize.width,
75
+ imageSize.height,
76
+ snapRotation
77
+ );
78
+ const fitScale = Math.min(
79
+ containerSize.width / naturalBBox.width,
80
+ containerSize.height / naturalBBox.height
81
+ );
82
+ const renderedW = imageSize.width * fitScale;
83
+ const renderedH = imageSize.height * fitScale;
84
+ const visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );
85
+ return {
86
+ elementSize: { width: renderedW, height: renderedH },
87
+ visualSize,
88
+ };
89
+ }
90
+
91
+ /**
92
+ * Compose a camera matrix from cropper state, container, and image dimensions.
93
+ *
94
+ * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.
95
+ * Input (0,0) = image top-left, (1,1) = image bottom-right.
96
+ *
97
+ * Composition order (left-to-right = outermost first, applied last to point):
98
+ * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels
99
+ *
100
+ * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`
101
+ * are viewport-relative: the image mirrors across the viewport's vertical /
102
+ * horizontal axis regardless of current rotation.
103
+ *
104
+ * @param state The current cropper state (zoom, rotation, flip, crop).
105
+ * @param containerSize The size of the container in pixels.
106
+ * @param imageSize The natural size of the image in pixels.
107
+ * @return The composed camera matrix.
108
+ */
109
+ export function createCamera(
110
+ state: CropperState,
111
+ containerSize: Size,
112
+ imageSize: Size
113
+ ): Camera {
114
+ const m = mat2d.create();
115
+
116
+ if (
117
+ containerSize.width === 0 ||
118
+ containerSize.height === 0 ||
119
+ imageSize.width === 0 ||
120
+ imageSize.height === 0
121
+ ) {
122
+ return m;
123
+ }
124
+
125
+ // Use the nearest 90° multiple for layout sizing so the stencil
126
+ // and visual bounds are stable through fine rotation. The actual
127
+ // `state.rotation` is still used for the rotation component of
128
+ // the matrix below.
129
+ const snapRotation = Math.round( state.rotation / 90 ) * 90;
130
+
131
+ // Rotated bounding box of the natural image (at snap angle).
132
+ const naturalBBox = getRotatedBBox(
133
+ imageSize.width,
134
+ imageSize.height,
135
+ snapRotation
136
+ );
137
+
138
+ // "Contain" fit: scale rotated bounding box to fit within container.
139
+ const fitScale = Math.min(
140
+ containerSize.width / naturalBBox.width,
141
+ containerSize.height / naturalBBox.height
142
+ );
143
+
144
+ // The rendered (unrotated) image dimensions at this fit scale.
145
+ const renderedW = imageSize.width * fitScale;
146
+ const renderedH = imageSize.height * fitScale;
147
+
148
+ // Visual (rotated) image footprint in pixels (at snap angle).
149
+ const { width: visualW, height: visualH } = getRotatedBBox(
150
+ renderedW,
151
+ renderedH,
152
+ snapRotation
153
+ );
154
+
155
+ // Build matrix left-to-right (outermost first).
156
+ // Innermost operations (last in code) are applied first to input point.
157
+
158
+ // Outermost: translate to container center.
159
+ mat2d.translate( m, m, [
160
+ containerSize.width / 2,
161
+ containerSize.height / 2,
162
+ ] );
163
+
164
+ // Pan offset in visual-space pixels.
165
+ mat2d.translate( m, m, [ state.pan.x * visualW, state.pan.y * visualH ] );
166
+
167
+ // Flip (viewport-relative — composed outside rotation so horizontal
168
+ // flip always mirrors across the viewport's vertical axis).
169
+ mat2d.scale( m, m, [
170
+ state.flip.horizontal ? -1 : 1,
171
+ state.flip.vertical ? -1 : 1,
172
+ ] );
173
+
174
+ // Rotate.
175
+ mat2d.rotate( m, m, degreesToRadians( state.rotation ) );
176
+
177
+ // Zoom.
178
+ mat2d.scale( m, m, [ state.zoom, state.zoom ] );
179
+
180
+ // Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).
181
+ mat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );
182
+
183
+ // Innermost: scale from normalized [0,1] to rendered pixels.
184
+ mat2d.scale( m, m, [ renderedW, renderedH ] );
185
+
186
+ return m;
187
+ }
188
+
189
+ /**
190
+ * Transform a normalized world point [0,1] to screen pixels.
191
+ *
192
+ * @param camera The camera matrix from createCamera.
193
+ * @param point The normalized world coordinate to transform.
194
+ * @return The screen pixel coordinate.
195
+ */
196
+ export function worldToScreen(
197
+ camera: Camera,
198
+ point: NormalizedPoint
199
+ ): { x: number; y: number } {
200
+ const out = vec2.create();
201
+ vec2.transformMat2d( out, [ point.x, point.y ], camera );
202
+ return { x: out[ 0 ], y: out[ 1 ] };
203
+ }
204
+
205
+ /**
206
+ * Transform a screen pixel point to normalized world coordinates [0,1].
207
+ *
208
+ * @param camera The camera matrix from createCamera.
209
+ * @param point The screen pixel coordinate to transform.
210
+ * @param point.x The x component of the screen pixel coordinate.
211
+ * @param point.y The y component of the screen pixel coordinate.
212
+ * @return The normalized world coordinate.
213
+ */
214
+ export function screenToWorld(
215
+ camera: Camera,
216
+ point: { x: number; y: number }
217
+ ): NormalizedPoint {
218
+ mat2d.invert( _scratchMat, camera );
219
+ const out = _scratchVec;
220
+ vec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );
221
+ return { x: out[ 0 ], y: out[ 1 ] };
222
+ }
223
+
224
+ /**
225
+ * The bounding box of a transformed region in screen (pixel) space.
226
+ */
227
+ export interface VisualBounds {
228
+ left: number;
229
+ top: number;
230
+ width: number;
231
+ height: number;
232
+ }
233
+
234
+ /**
235
+ * Compute the axis-aligned bounding box of a set of corners after
236
+ * transforming them through a camera matrix.
237
+ *
238
+ * @param camera The camera matrix from createCamera.
239
+ * @param corners The corners to transform (each as [x, y]).
240
+ * @return The screen-space bounding box.
241
+ */
242
+ function aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {
243
+ const screenCorners = corners.map( ( c ) => {
244
+ const out = vec2.create();
245
+ vec2.transformMat2d( out, c, camera );
246
+ return out;
247
+ } );
248
+ let minX = screenCorners[ 0 ][ 0 ];
249
+ let maxX = screenCorners[ 0 ][ 0 ];
250
+ let minY = screenCorners[ 0 ][ 1 ];
251
+ let maxY = screenCorners[ 0 ][ 1 ];
252
+ for ( let i = 1; i < screenCorners.length; i++ ) {
253
+ const s = screenCorners[ i ];
254
+ if ( s[ 0 ] < minX ) {
255
+ minX = s[ 0 ];
256
+ }
257
+ if ( s[ 0 ] > maxX ) {
258
+ maxX = s[ 0 ];
259
+ }
260
+ if ( s[ 1 ] < minY ) {
261
+ minY = s[ 1 ];
262
+ }
263
+ if ( s[ 1 ] > maxY ) {
264
+ maxY = s[ 1 ];
265
+ }
266
+ }
267
+ return { left: minX, top: minY, width: maxX - minX, height: maxY - minY };
268
+ }
269
+
270
+ /**
271
+ * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])
272
+ * after applying the camera transform.
273
+ *
274
+ * @param camera The camera matrix from createCamera.
275
+ * @return The screen-space bounding box of the full image.
276
+ */
277
+ export function getVisibleBounds( camera: Camera ): VisualBounds {
278
+ return aabb( camera, [
279
+ [ 0, 0 ],
280
+ [ 1, 0 ],
281
+ [ 1, 1 ],
282
+ [ 0, 1 ],
283
+ ] );
284
+ }
285
+
286
+ /**
287
+ * Compose a camera matrix for exporting to a canvas.
288
+ *
289
+ * The resulting matrix maps image-pixel coordinates directly to output-canvas
290
+ * coordinates. Apply it with `ctx.setTransform( ...camera )` then
291
+ * `ctx.drawImage( image, 0, 0 )`.
292
+ *
293
+ * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:
294
+ * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)
295
+ *
296
+ * @param state The current cropper state.
297
+ * @param imageSize The natural size of the source image in pixels.
298
+ * @param outputSize The desired output canvas size in pixels.
299
+ * @return The composed export camera matrix.
300
+ */
301
+ export function createExportCamera(
302
+ state: CropperState,
303
+ imageSize: Size,
304
+ outputSize: Size
305
+ ): Camera {
306
+ const m = mat2d.create();
307
+ const { rotation, flip, cropRect, zoom, pan } = state;
308
+ if (
309
+ imageSize.width === 0 ||
310
+ imageSize.height === 0 ||
311
+ outputSize.width === 0 ||
312
+ outputSize.height === 0
313
+ ) {
314
+ return m;
315
+ }
316
+ // Reference frame for cropRect/pan is the snap-rotation bbox — that's
317
+ // what the stencil and CSS matrix use in the preview (see createCamera
318
+ // and getImageFit). Using the true rotation here would position the
319
+ // crop window at a different offset than the stencil framed, and show
320
+ // a shifted region after any fine rotation.
321
+ const snapRotation = Math.round( rotation / 90 ) * 90;
322
+ const { width: rotW, height: rotH } = getRotatedBBox(
323
+ imageSize.width,
324
+ imageSize.height,
325
+ snapRotation
326
+ );
327
+
328
+ // Scale factor to map the natural crop region to the output canvas size.
329
+ const naturalCropW = cropRect.width * rotW;
330
+ const naturalCropH = cropRect.height * rotH;
331
+ const outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;
332
+ const outputScaleY =
333
+ naturalCropH > 0 ? outputSize.height / naturalCropH : 1;
334
+
335
+ const cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;
336
+ const cropOffsetY =
337
+ cropRect.y * rotH + outputSize.height / 2 / outputScaleY;
338
+ const visualCenterX = rotW / 2 + pan.x * rotW;
339
+ const visualCenterY = rotH / 2 + pan.y * rotH;
340
+ mat2d.scale( m, m, [ outputScaleX, outputScaleY ] );
341
+ mat2d.translate( m, m, [
342
+ visualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,
343
+ visualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,
344
+ ] );
345
+ // Flip is composed outside rotation so it acts in viewport/output space —
346
+ // must match createCamera's order for preview and export to agree.
347
+ mat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );
348
+ mat2d.rotate( m, m, degreesToRadians( rotation ) );
349
+ mat2d.scale( m, m, [ zoom, zoom ] );
350
+ mat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );
351
+ return m;
352
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import type { NormalizedRect, Flip, CropperState } from './types';
10
+
11
+ export const MIN_ZOOM = 1;
12
+ export const MAX_ZOOM = 10;
13
+
14
+ /**
15
+ * Maximum free-rotation offset in degrees from the nearest 90° step.
16
+ * The rotation slider allows ±45° around the current cardinal angle.
17
+ */
18
+ export const MAX_ROTATION_OFFSET = 45;
19
+
20
+ const DEFAULT_CROP_RECT: NormalizedRect = {
21
+ x: 0,
22
+ y: 0,
23
+ width: 1,
24
+ height: 1,
25
+ };
26
+
27
+ const DEFAULT_FLIP: Flip = {
28
+ horizontal: false,
29
+ vertical: false,
30
+ };
31
+
32
+ const DEFAULT_PAN: { x: number; y: number } = {
33
+ x: 0,
34
+ y: 0,
35
+ };
36
+
37
+ export const DEFAULT_STATE: CropperState = {
38
+ image: null,
39
+ pan: { ...DEFAULT_PAN },
40
+ zoom: MIN_ZOOM,
41
+ rotation: 0,
42
+ basePan: { ...DEFAULT_PAN },
43
+ baseZoom: MIN_ZOOM,
44
+ baseRotation: 0,
45
+ flip: { ...DEFAULT_FLIP },
46
+ cropRect: { ...DEFAULT_CROP_RECT },
47
+ };
48
+
49
+ /**
50
+ * An aspect ratio preset with a human-readable label.
51
+ */
52
+ export interface AspectRatioPreset {
53
+ /** Display label (e.g., "Square (1:1)"). */
54
+ label: string;
55
+ /** The aspect ratio value (width / height). 0 = free / original. */
56
+ value: number;
57
+ }
58
+
59
+ /**
60
+ * Default aspect ratio presets. Consumers can use these as-is, override
61
+ * with their own list, or extend with additional presets.
62
+ *
63
+ * @example
64
+ * // Use defaults:
65
+ * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />
66
+ *
67
+ * // Custom presets:
68
+ * const socialPresets = [
69
+ * { label: 'Instagram Post', value: 1 },
70
+ * { label: 'Instagram Story', value: 9 / 16 },
71
+ * { label: 'YouTube Thumbnail', value: 16 / 9 },
72
+ * ];
73
+ *
74
+ * // Extend defaults:
75
+ * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];
76
+ */
77
+ /**
78
+ * Sentinel value for "Original" aspect ratio — resolved at runtime
79
+ * to the image's natural width / height.
80
+ */
81
+ export const ORIGINAL_ASPECT_RATIO = -1;
82
+
83
+ export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
84
+ { label: __( 'Free' ), value: 0 },
85
+ { label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },
86
+ { label: __( 'Square (1:1)' ), value: 1 },
87
+ { label: __( 'Landscape (16:9)' ), value: 16 / 9 },
88
+ { label: __( 'Portrait (9:16)' ), value: 9 / 16 },
89
+ { label: __( 'Classic (4:3)' ), value: 4 / 3 },
90
+ { label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },
91
+ { label: __( 'Photo (3:2)' ), value: 3 / 2 },
92
+ { label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },
93
+ ];