@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,429 +0,0 @@
1
- import { mat2d, vec2 } from 'gl-matrix';
2
- import type {
3
- CropperState,
4
- NormalizedPoint,
5
- NormalizedRect,
6
- Size,
7
- Camera,
8
- } from './types';
9
- import { degreesToRadians } from './math/rotation';
10
- import {
11
- isSafeNumber,
12
- isValidSize,
13
- safeBoundedNumber,
14
- sanitizeCropperState,
15
- } from './math/sanitize';
16
-
17
- // Pre-allocated scratch buffers for `screenToWorld`, which is called per
18
- // pointermove. Module-level singletons — safe because usage is synchronous.
19
- const _scratchMat = mat2d.create();
20
- const _scratchVec = vec2.create();
21
-
22
- /**
23
- * Compute the axis-aligned bounding box of a rectangle after rotation.
24
- *
25
- * @param width The width of the rectangle.
26
- * @param height The height of the rectangle.
27
- * @param rotation The rotation angle in degrees.
28
- * @return The bounding box size after rotation.
29
- */
30
- export function getRotatedBBox(
31
- width: number,
32
- height: number,
33
- rotation: number
34
- ): Size {
35
- // Short-circuit on any unsafe input. `isSafeNumber` is stricter than
36
- // `Number.isFinite`: very large but technically-finite rotations (e.g.
37
- // `Number.MAX_VALUE`) overflow inside `degreesToRadians` and then
38
- // `Math.cos`/`Math.sin` return `NaN`, so the magnitude bound matters.
39
- if (
40
- ! isSafeNumber( width ) ||
41
- ! isSafeNumber( height ) ||
42
- ! isSafeNumber( rotation ) ||
43
- width <= 0 ||
44
- height <= 0
45
- ) {
46
- return { width: 0, height: 0 };
47
- }
48
- const rad = degreesToRadians( rotation );
49
- const cosR = Math.abs( Math.cos( rad ) );
50
- const sinR = Math.abs( Math.sin( rad ) );
51
- return {
52
- width: cosR * width + sinR * height,
53
- height: sinR * width + cosR * height,
54
- };
55
- }
56
-
57
- /**
58
- * Compute the fitted (unrotated) image element dimensions and the visual
59
- * (rotated) bounding box dimensions for a given container, image, and rotation.
60
- *
61
- * This is the same "contain" fit logic used by createCamera, extracted so
62
- * cropper.tsx can size the <img> element and position overlays without
63
- * duplicating the math.
64
- *
65
- * @param containerSize The container dimensions in pixels.
66
- * @param imageSize The natural image dimensions in pixels.
67
- * @param rotation The rotation angle in degrees.
68
- * @return The fitted element size and visual bounding box size.
69
- */
70
- export function getImageFit(
71
- containerSize: Size,
72
- imageSize: Size,
73
- rotation: number
74
- ): { elementSize: Size; visualSize: Size } {
75
- if ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {
76
- return {
77
- elementSize: { width: 0, height: 0 },
78
- visualSize: { width: 0, height: 0 },
79
- };
80
- }
81
- const safeRotation = safeBoundedNumber( rotation, 0 );
82
- // Snap rotation to the nearest 90° multiple for layout sizing.
83
- // This keeps the stencil a stable size through fine ±45° rotation
84
- // (no inflation at 15°/30° etc.) while still swapping aspect at
85
- // 90°/180°/270° so the snap rotate preserves the framed content.
86
- const snapRotation = Math.round( safeRotation / 90 ) * 90;
87
- const naturalBBox = getRotatedBBox(
88
- imageSize.width,
89
- imageSize.height,
90
- snapRotation
91
- );
92
- // Defensive: getRotatedBBox returns zero dims for hostile inputs, which
93
- // would make fitScale infinite. Mirror the zero-container short-circuit.
94
- if ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {
95
- return {
96
- elementSize: { width: 0, height: 0 },
97
- visualSize: { width: 0, height: 0 },
98
- };
99
- }
100
- const fitScale = Math.min(
101
- containerSize.width / naturalBBox.width,
102
- containerSize.height / naturalBBox.height
103
- );
104
- const renderedW = imageSize.width * fitScale;
105
- const renderedH = imageSize.height * fitScale;
106
- const visualSize = getRotatedBBox( renderedW, renderedH, snapRotation );
107
- return {
108
- elementSize: { width: renderedW, height: renderedH },
109
- visualSize,
110
- };
111
- }
112
-
113
- /**
114
- * Resolve the presentational view magnification that makes the crop fill the
115
- * canvas.
116
- *
117
- * The crop overlay is laid out as `cropRect * visualSize` (the contain-fit
118
- * footprint, with no zoom), so its on-screen size is capped by that footprint.
119
- * When a crop's aspect differs from the image's, it can be much smaller than
120
- * the canvas could show (e.g. a square crop in a tall image is bound by the
121
- * footprint's narrow axis). Scaling `elementSize` and `visualSize` together by
122
- * the returned factor uniformly magnifies the whole scene — image, crop
123
- * overlay, and overlays — so the crop reaches `targetFill` of its constraining
124
- * canvas axis, with the image bleeding past the canvas (clipped by the host).
125
- *
126
- * Purely presentational: it does not touch `zoom`/`pan`/`cropRect`/`rotation`,
127
- * so the framed source region — and therefore the export — is unchanged.
128
- *
129
- * @param cropRect The crop rectangle, normalized to the footprint.
130
- * @param canvasSize The canvas size in pixels.
131
- * @param visualSize The contain-fit (rotated) image footprint in pixels.
132
- * @param targetFill Fraction of the constraining canvas axis to fill (0–1].
133
- * @param maxScale Upper bound on the magnification.
134
- * @return A magnification factor in [1, maxScale]; 1 when none is needed.
135
- */
136
- export function getViewScale(
137
- cropRect: NormalizedRect,
138
- canvasSize: Size,
139
- visualSize: Size,
140
- targetFill: number,
141
- maxScale: number
142
- ): number {
143
- const cropScreenW = cropRect.width * visualSize.width;
144
- const cropScreenH = cropRect.height * visualSize.height;
145
- // `> 0` comparisons (rather than `<= 0`) reject NaN as well as zero and
146
- // negatives, so a non-finite rect/dimension/scale can't propagate to a
147
- // `scale(NaN)`. `isValidSize` already guards finiteness of the sizes.
148
- if (
149
- ! isValidSize( canvasSize ) ||
150
- ! isValidSize( visualSize ) ||
151
- ! ( cropScreenW > 0 ) ||
152
- ! ( cropScreenH > 0 ) ||
153
- ! Number.isFinite( targetFill ) ||
154
- ! Number.isFinite( maxScale ) ||
155
- ! ( targetFill > 0 ) ||
156
- ! ( maxScale >= 1 )
157
- ) {
158
- return 1;
159
- }
160
- const kW = ( targetFill * canvasSize.width ) / cropScreenW;
161
- const kH = ( targetFill * canvasSize.height ) / cropScreenH;
162
- const k = Math.min( kW, kH );
163
- return Math.min( maxScale, Math.max( 1, k ) );
164
- }
165
-
166
- /**
167
- * Compose a camera matrix from cropper state, container, and image dimensions.
168
- *
169
- * The matrix maps normalized world coordinates [0,1] x [0,1] to screen pixels.
170
- * Input (0,0) = image top-left, (1,1) = image bottom-right.
171
- *
172
- * Composition order (left-to-right = outermost first, applied last to point):
173
- * M = T_containerCenter * T_pan * S_flip * R_rotation * S_zoom * T_center * S_toRenderedPixels
174
- *
175
- * Flip is composed outside rotation, so `flip.horizontal` / `flip.vertical`
176
- * are viewport-relative: the image mirrors across the viewport's vertical /
177
- * horizontal axis regardless of current rotation.
178
- *
179
- * @param state The current cropper state (zoom, rotation, flip, crop).
180
- * @param containerSize The size of the container in pixels.
181
- * @param imageSize The natural size of the image in pixels.
182
- * @return The composed camera matrix.
183
- */
184
- export function createCamera(
185
- state: CropperState,
186
- containerSize: Size,
187
- imageSize: Size
188
- ): Camera {
189
- const m = mat2d.create();
190
-
191
- if ( ! isValidSize( containerSize ) || ! isValidSize( imageSize ) ) {
192
- return m;
193
- }
194
-
195
- const safeState = sanitizeCropperState( state );
196
-
197
- // Use the nearest 90° multiple for layout sizing so the stencil
198
- // and visual bounds are stable through fine rotation. The actual
199
- // `state.rotation` is still used for the rotation component of
200
- // the matrix below.
201
- const snapRotation = Math.round( safeState.rotation / 90 ) * 90;
202
-
203
- // Rotated bounding box of the natural image (at snap angle).
204
- const naturalBBox = getRotatedBBox(
205
- imageSize.width,
206
- imageSize.height,
207
- snapRotation
208
- );
209
-
210
- // Defensive: getRotatedBBox returns zero dims for unsafe inputs. Mirror
211
- // the zero-size short-circuit so `fitScale` doesn't become Infinity.
212
- if ( naturalBBox.width === 0 || naturalBBox.height === 0 ) {
213
- return m;
214
- }
215
-
216
- // "Contain" fit: scale rotated bounding box to fit within container.
217
- const fitScale = Math.min(
218
- containerSize.width / naturalBBox.width,
219
- containerSize.height / naturalBBox.height
220
- );
221
-
222
- // The rendered (unrotated) image dimensions at this fit scale.
223
- const renderedW = imageSize.width * fitScale;
224
- const renderedH = imageSize.height * fitScale;
225
-
226
- // Visual (rotated) image footprint in pixels (at snap angle).
227
- const { width: visualW, height: visualH } = getRotatedBBox(
228
- renderedW,
229
- renderedH,
230
- snapRotation
231
- );
232
-
233
- // Build matrix left-to-right (outermost first).
234
- // Innermost operations (last in code) are applied first to input point.
235
-
236
- // Outermost: translate to container center.
237
- mat2d.translate( m, m, [
238
- containerSize.width / 2,
239
- containerSize.height / 2,
240
- ] );
241
-
242
- // Pan offset in visual-space pixels.
243
- mat2d.translate( m, m, [
244
- safeState.pan.x * visualW,
245
- safeState.pan.y * visualH,
246
- ] );
247
-
248
- // Flip (viewport-relative — composed outside rotation so horizontal
249
- // flip always mirrors across the viewport's vertical axis).
250
- mat2d.scale( m, m, [
251
- safeState.flip.horizontal ? -1 : 1,
252
- safeState.flip.vertical ? -1 : 1,
253
- ] );
254
-
255
- // Rotate.
256
- mat2d.rotate( m, m, degreesToRadians( safeState.rotation ) );
257
-
258
- // Zoom.
259
- mat2d.scale( m, m, [ safeState.zoom, safeState.zoom ] );
260
-
261
- // Center origin (shift so 0.5,0.5 in rendered-pixel space = origin).
262
- mat2d.translate( m, m, [ -renderedW / 2, -renderedH / 2 ] );
263
-
264
- // Innermost: scale from normalized [0,1] to rendered pixels.
265
- mat2d.scale( m, m, [ renderedW, renderedH ] );
266
-
267
- return m;
268
- }
269
-
270
- /**
271
- * Transform a normalized world point [0,1] to screen pixels.
272
- *
273
- * @param camera The camera matrix from createCamera.
274
- * @param point The normalized world coordinate to transform.
275
- * @return The screen pixel coordinate.
276
- */
277
- export function worldToScreen(
278
- camera: Camera,
279
- point: NormalizedPoint
280
- ): { x: number; y: number } {
281
- const out = vec2.create();
282
- vec2.transformMat2d( out, [ point.x, point.y ], camera );
283
- return { x: out[ 0 ], y: out[ 1 ] };
284
- }
285
-
286
- /**
287
- * Transform a screen pixel point to normalized world coordinates [0,1].
288
- *
289
- * @param camera The camera matrix from createCamera.
290
- * @param point The screen pixel coordinate to transform.
291
- * @param point.x The x component of the screen pixel coordinate.
292
- * @param point.y The y component of the screen pixel coordinate.
293
- * @return The normalized world coordinate.
294
- */
295
- export function screenToWorld(
296
- camera: Camera,
297
- point: { x: number; y: number }
298
- ): NormalizedPoint {
299
- mat2d.invert( _scratchMat, camera );
300
- const out = _scratchVec;
301
- vec2.transformMat2d( out, [ point.x, point.y ], _scratchMat );
302
- return { x: out[ 0 ], y: out[ 1 ] };
303
- }
304
-
305
- /**
306
- * The bounding box of a transformed region in screen (pixel) space.
307
- */
308
- export interface VisualBounds {
309
- left: number;
310
- top: number;
311
- width: number;
312
- height: number;
313
- }
314
-
315
- /**
316
- * Compute the axis-aligned bounding box of a set of corners after
317
- * transforming them through a camera matrix.
318
- *
319
- * @param camera The camera matrix from createCamera.
320
- * @param corners The corners to transform (each as [x, y]).
321
- * @return The screen-space bounding box.
322
- */
323
- function aabb( camera: Camera, corners: [ number, number ][] ): VisualBounds {
324
- const screenCorners = corners.map( ( c ) => {
325
- const out = vec2.create();
326
- vec2.transformMat2d( out, c, camera );
327
- return out;
328
- } );
329
- let minX = screenCorners[ 0 ][ 0 ];
330
- let maxX = screenCorners[ 0 ][ 0 ];
331
- let minY = screenCorners[ 0 ][ 1 ];
332
- let maxY = screenCorners[ 0 ][ 1 ];
333
- for ( let i = 1; i < screenCorners.length; i++ ) {
334
- const s = screenCorners[ i ];
335
- if ( s[ 0 ] < minX ) {
336
- minX = s[ 0 ];
337
- }
338
- if ( s[ 0 ] > maxX ) {
339
- maxX = s[ 0 ];
340
- }
341
- if ( s[ 1 ] < minY ) {
342
- minY = s[ 1 ];
343
- }
344
- if ( s[ 1 ] > maxY ) {
345
- maxY = s[ 1 ];
346
- }
347
- }
348
- return { left: minX, top: minY, width: maxX - minX, height: maxY - minY };
349
- }
350
-
351
- /**
352
- * Returns the axis-aligned bounding box of the full image (normalized [0,1]x[0,1])
353
- * after applying the camera transform.
354
- *
355
- * @param camera The camera matrix from createCamera.
356
- * @return The screen-space bounding box of the full image.
357
- */
358
- export function getVisibleBounds( camera: Camera ): VisualBounds {
359
- return aabb( camera, [
360
- [ 0, 0 ],
361
- [ 1, 0 ],
362
- [ 1, 1 ],
363
- [ 0, 1 ],
364
- ] );
365
- }
366
-
367
- /**
368
- * Compose a camera matrix for exporting to a canvas.
369
- *
370
- * The resulting matrix maps image-pixel coordinates directly to output-canvas
371
- * coordinates. Apply it with `ctx.setTransform( ...camera )` then
372
- * `ctx.drawImage( image, 0, 0 )`.
373
- *
374
- * The transform chain mirrors the `renderToCanvas` function in canvas-renderer.ts:
375
- * translate(visualCenter - cropOffset + outCenter) → flip → rotate → zoom → translate(-imgCenter)
376
- *
377
- * @param state The current cropper state.
378
- * @param imageSize The natural size of the source image in pixels.
379
- * @param outputSize The desired output canvas size in pixels.
380
- * @return The composed export camera matrix.
381
- */
382
- export function createExportCamera(
383
- state: CropperState,
384
- imageSize: Size,
385
- outputSize: Size
386
- ): Camera {
387
- const m = mat2d.create();
388
- if ( ! isValidSize( imageSize ) || ! isValidSize( outputSize ) ) {
389
- return m;
390
- }
391
- const { rotation, flip, cropRect, zoom, pan } =
392
- sanitizeCropperState( state );
393
- // Reference frame for cropRect/pan is the snap-rotation bbox — that's
394
- // what the stencil and CSS matrix use in the preview (see createCamera
395
- // and getImageFit). Using the true rotation here would position the
396
- // crop window at a different offset than the stencil framed, and show
397
- // a shifted region after any fine rotation.
398
- const snapRotation = Math.round( rotation / 90 ) * 90;
399
- const { width: rotW, height: rotH } = getRotatedBBox(
400
- imageSize.width,
401
- imageSize.height,
402
- snapRotation
403
- );
404
-
405
- // Scale factor to map the natural crop region to the output canvas size.
406
- const naturalCropW = cropRect.width * rotW;
407
- const naturalCropH = cropRect.height * rotH;
408
- const outputScaleX = naturalCropW > 0 ? outputSize.width / naturalCropW : 1;
409
- const outputScaleY =
410
- naturalCropH > 0 ? outputSize.height / naturalCropH : 1;
411
-
412
- const cropOffsetX = cropRect.x * rotW + outputSize.width / 2 / outputScaleX;
413
- const cropOffsetY =
414
- cropRect.y * rotH + outputSize.height / 2 / outputScaleY;
415
- const visualCenterX = rotW / 2 + pan.x * rotW;
416
- const visualCenterY = rotH / 2 + pan.y * rotH;
417
- mat2d.scale( m, m, [ outputScaleX, outputScaleY ] );
418
- mat2d.translate( m, m, [
419
- visualCenterX - cropOffsetX + outputSize.width / 2 / outputScaleX,
420
- visualCenterY - cropOffsetY + outputSize.height / 2 / outputScaleY,
421
- ] );
422
- // Flip is composed outside rotation so it acts in viewport/output space —
423
- // must match createCamera's order for preview and export to agree.
424
- mat2d.scale( m, m, [ flip.horizontal ? -1 : 1, flip.vertical ? -1 : 1 ] );
425
- mat2d.rotate( m, m, degreesToRadians( rotation ) );
426
- mat2d.scale( m, m, [ zoom, zoom ] );
427
- mat2d.translate( m, m, [ -imageSize.width / 2, -imageSize.height / 2 ] );
428
- return m;
429
- }
@@ -1,150 +0,0 @@
1
- import { __ } from '@wordpress/i18n';
2
- import type { NormalizedRect, Flip, CropperState } from './types';
3
-
4
- /**
5
- * Default/resting zoom. A full, unrotated crop needs at least 1x to cover the
6
- * crop area, but smaller/fine-rotated crops can be valid below 1x — the true
7
- * floor for those comes from `getMinZoom`.
8
- */
9
- export const MIN_ZOOM = 1;
10
- /**
11
- * Safety floor for coverage-aware zoom. Degenerate crops can have a geometric
12
- * coverage minimum of 0, but camera and inverse-matrix math need a stable,
13
- * positive scale.
14
- */
15
- export const ABSOLUTE_MIN_ZOOM = 0.1;
16
- export const MAX_ZOOM = 10;
17
-
18
- /**
19
- * Minimum crop rect dimension in source-image pixels, enforced per axis
20
- * during resize. Prevents accidental sub-pixel crops while staying small
21
- * enough to allow tight crops (favicons, icons). Adjust here to tune the
22
- * floor globally.
23
- */
24
- export const MIN_CROP_PIXELS = 16;
25
-
26
- /**
27
- * Minimum on-screen crop rect dimension in CSS pixels. The source-pixel
28
- * floor (`MIN_CROP_PIXELS`) keeps crops from going sub-pixel, but on a large
29
- * image fit into a small canvas it can render only a few CSS pixels wide —
30
- * too small to grab the resize handles. This floor keeps the crop operable
31
- * regardless of display scale; it binds when zoomed out and yields to the
32
- * source-pixel floor once the image is shown large enough. Sized to one
33
- * handle touch target (`$handle-touch-target-size` in `cropper.scss`).
34
- */
35
- export const MIN_CROP_SCREEN_PX = 44;
36
-
37
- /**
38
- * Fraction of the constraining canvas axis the settled crop should occupy on
39
- * screen. When a crop is shown smaller than this (e.g. a square crop in a tall
40
- * image, capped by the contain-fit footprint's narrow axis), the view magnifies
41
- * to fill the canvas. `1` = always fill the canvas; lower = rescue only the
42
- * under-filled cases. See `getViewScale`.
43
- */
44
- export const SETTLE_TARGET_CANVAS_FILL = 0.8;
45
-
46
- /**
47
- * Upper bound on the presentational view magnification (`getViewScale`).
48
- * Prevents a near-degenerate crop from magnifying the scene without limit.
49
- */
50
- export const MAX_VIEW_SCALE = 8;
51
-
52
- /**
53
- * CSS pixels per source pixel required before resize handles snap the selected
54
- * source region to whole-pixel edges. Below 1:1, a source pixel is sub-pixel on
55
- * screen, so snapping would feel notchy without a visible pixel boundary.
56
- */
57
- export const PIXEL_SNAP_DISPLAY_SCALE = 1;
58
-
59
- /**
60
- * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.
61
- * This could be made configurable as a prop to the Cropper component.
62
- */
63
- export const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;
64
-
65
- /** Fine step for keyboard-driven cropper movement, in normalized coordinates. */
66
- export const DEFAULT_KEYBOARD_STEP = 0.01;
67
-
68
- /** Coarse keyboard movement multiplier when Shift is held. */
69
- export const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;
70
-
71
- /**
72
- * Maximum free-rotation offset in degrees from the nearest 90° step.
73
- * The rotation slider allows ±45° around the current cardinal angle.
74
- */
75
- export const MAX_ROTATION_OFFSET = 45;
76
-
77
- const DEFAULT_CROP_RECT: NormalizedRect = {
78
- x: 0,
79
- y: 0,
80
- width: 1,
81
- height: 1,
82
- };
83
-
84
- const DEFAULT_FLIP: Flip = {
85
- horizontal: false,
86
- vertical: false,
87
- };
88
-
89
- const DEFAULT_PAN: { x: number; y: number } = {
90
- x: 0,
91
- y: 0,
92
- };
93
-
94
- export const DEFAULT_STATE: CropperState = {
95
- image: null,
96
- pan: { ...DEFAULT_PAN },
97
- zoom: MIN_ZOOM,
98
- rotation: 0,
99
- basePan: { ...DEFAULT_PAN },
100
- baseZoom: MIN_ZOOM,
101
- baseRotation: 0,
102
- flip: { ...DEFAULT_FLIP },
103
- cropRect: { ...DEFAULT_CROP_RECT },
104
- };
105
-
106
- /**
107
- * An aspect ratio preset with a human-readable label.
108
- */
109
- export interface AspectRatioPreset {
110
- /** Display label (e.g., "Square (1:1)"). */
111
- label: string;
112
- /** The aspect ratio value (width / height). 0 = free / original. */
113
- value: number;
114
- }
115
-
116
- /**
117
- * Default aspect ratio presets. Consumers can use these as-is, override
118
- * with their own list, or extend with additional presets.
119
- *
120
- * @example
121
- * // Use defaults:
122
- * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />
123
- *
124
- * // Custom presets:
125
- * const socialPresets = [
126
- * { label: 'Instagram Post', value: 1 },
127
- * { label: 'Instagram Story', value: 9 / 16 },
128
- * { label: 'YouTube Thumbnail', value: 16 / 9 },
129
- * ];
130
- *
131
- * // Extend defaults:
132
- * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];
133
- */
134
- /**
135
- * Sentinel value for "Original" aspect ratio — resolved at runtime
136
- * to the image's natural width / height.
137
- */
138
- export const ORIGINAL_ASPECT_RATIO = -1;
139
-
140
- export const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [
141
- { label: __( 'Free' ), value: 0 },
142
- { label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },
143
- { label: __( 'Square (1:1)' ), value: 1 },
144
- { label: __( 'Landscape (16:9)' ), value: 16 / 9 },
145
- { label: __( 'Portrait (9:16)' ), value: 9 / 16 },
146
- { label: __( 'Classic (4:3)' ), value: 4 / 3 },
147
- { label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },
148
- { label: __( 'Photo (3:2)' ), value: 3 / 2 },
149
- { label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },
150
- ];