@wordpress/media-editor 0.22.0 → 0.24.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 (391) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/build/components/media-editor/index.cjs +229 -126
  3. package/build/components/media-editor/index.cjs.map +1 -1
  4. package/build/components/media-editor/use-crop-options.cjs +4 -5
  5. package/build/components/media-editor/use-crop-options.cjs.map +1 -1
  6. package/build/components/media-editor/use-save-media-editor.cjs +41 -11
  7. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
  8. package/build/components/media-editor-canvas/index.cjs +15 -18
  9. package/build/components/media-editor-canvas/index.cjs.map +1 -1
  10. package/build/components/media-editor-crop-panel/index.cjs +26 -8
  11. package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
  12. package/build/components/media-editor-fine-rotation/index.cjs +13 -12
  13. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
  14. package/build/components/media-editor-image-controls/index.cjs +4 -6
  15. package/build/components/media-editor-image-controls/index.cjs.map +1 -1
  16. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
  18. package/build/components/media-editor-modal/index.cjs +10 -7
  19. package/build/components/media-editor-modal/index.cjs.map +1 -1
  20. package/build/components/media-editor-panel/error-boundary.cjs +68 -0
  21. package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
  22. package/build/components/media-editor-panel/index.cjs +158 -0
  23. package/build/components/media-editor-panel/index.cjs.map +1 -0
  24. package/build/components/media-form/index.cjs +7 -1
  25. package/build/components/media-form/index.cjs.map +1 -1
  26. package/build/components/media-preview/index.cjs +143 -37
  27. package/build/components/media-preview/index.cjs.map +1 -1
  28. package/build/components/rotation-ruler/index.cjs +9 -7
  29. package/build/components/rotation-ruler/index.cjs.map +1 -1
  30. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
  31. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
  32. package/build/index.cjs +10 -8
  33. package/build/private-apis.cjs.map +1 -1
  34. package/build/state/aspect-ratio-presets.cjs +12 -6
  35. package/build/state/aspect-ratio-presets.cjs.map +1 -1
  36. package/build/state/composite-reducer.cjs +41 -74
  37. package/build/state/composite-reducer.cjs.map +1 -1
  38. package/build/state/index.cjs +0 -39
  39. package/build/state/types.cjs +1 -2
  40. package/build/state/types.cjs.map +1 -1
  41. package/build/state/use-media-editor-state.cjs +70 -106
  42. package/build/state/use-media-editor-state.cjs.map +1 -1
  43. package/build/store/index.cjs +11 -9
  44. package/build/store/index.cjs.map +1 -1
  45. package/build/utils/get-media-type.cjs +8 -0
  46. package/build/utils/get-media-type.cjs.map +1 -1
  47. package/build/utils/index.cjs +6 -0
  48. package/build-module/components/media-editor/index.mjs +217 -117
  49. package/build-module/components/media-editor/index.mjs.map +1 -1
  50. package/build-module/components/media-editor/use-crop-options.mjs +4 -5
  51. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
  52. package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
  53. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
  54. package/build-module/components/media-editor-canvas/index.mjs +8 -13
  55. package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
  56. package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
  57. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
  58. package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
  59. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
  60. package/build-module/components/media-editor-image-controls/index.mjs +5 -7
  61. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
  62. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
  63. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
  64. package/build-module/components/media-editor-modal/index.mjs +1 -0
  65. package/build-module/components/media-editor-modal/index.mjs.map +1 -1
  66. package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
  67. package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
  68. package/build-module/components/media-editor-panel/index.mjs +123 -0
  69. package/build-module/components/media-editor-panel/index.mjs.map +1 -0
  70. package/build-module/components/media-form/index.mjs +7 -1
  71. package/build-module/components/media-form/index.mjs.map +1 -1
  72. package/build-module/components/media-preview/index.mjs +123 -41
  73. package/build-module/components/media-preview/index.mjs.map +1 -1
  74. package/build-module/state/aspect-ratio-presets.mjs +12 -7
  75. package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
  76. package/build-module/state/composite-reducer.mjs +32 -67
  77. package/build-module/state/composite-reducer.mjs.map +1 -1
  78. package/build-module/state/index.mjs +2 -5
  79. package/build-module/state/types.mjs +1 -2
  80. package/build-module/state/types.mjs.map +1 -1
  81. package/build-module/state/use-media-editor-state.mjs +70 -105
  82. package/build-module/state/use-media-editor-state.mjs.map +1 -1
  83. package/build-module/utils/get-media-type.mjs +8 -1
  84. package/build-module/utils/get-media-type.mjs.map +1 -1
  85. package/build-module/utils/index.mjs +1 -1
  86. package/build-style/style-rtl.css +122 -87
  87. package/build-style/style.css +121 -87
  88. package/build-types/components/media-editor/index.d.ts +25 -3
  89. package/build-types/components/media-editor/index.d.ts.map +1 -1
  90. package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
  91. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  92. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  93. package/build-types/components/media-editor-canvas/index.d.ts +3 -3
  94. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  95. package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
  96. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  97. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
  98. package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
  99. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  100. package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
  101. package/build-types/components/media-editor-modal/index.d.ts +1 -1
  102. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  103. package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
  104. package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
  105. package/build-types/components/media-editor-panel/index.d.ts +46 -0
  106. package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
  107. package/build-types/components/media-form/index.d.ts.map +1 -1
  108. package/build-types/components/media-preview/index.d.ts.map +1 -1
  109. package/build-types/state/aspect-ratio-presets.d.ts +20 -3
  110. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
  111. package/build-types/state/composite-reducer.d.ts +17 -19
  112. package/build-types/state/composite-reducer.d.ts.map +1 -1
  113. package/build-types/state/index.d.ts +2 -5
  114. package/build-types/state/index.d.ts.map +1 -1
  115. package/build-types/state/types.d.ts +20 -64
  116. package/build-types/state/types.d.ts.map +1 -1
  117. package/build-types/state/use-media-editor-state.d.ts +40 -54
  118. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  119. package/build-types/utils/get-media-type.d.ts +3 -1
  120. package/build-types/utils/get-media-type.d.ts.map +1 -1
  121. package/build-types/utils/index.d.ts +1 -1
  122. package/build-types/utils/index.d.ts.map +1 -1
  123. package/package.json +27 -24
  124. package/src/components/media-editor/index.tsx +372 -142
  125. package/src/components/media-editor/style.scss +21 -1
  126. package/src/components/media-editor/use-crop-options.ts +7 -11
  127. package/src/components/media-editor/use-save-media-editor.ts +48 -6
  128. package/src/components/media-editor-canvas/index.tsx +15 -26
  129. package/src/components/media-editor-canvas/style.scss +6 -6
  130. package/src/components/media-editor-crop-panel/index.tsx +38 -2
  131. package/src/components/media-editor-crop-panel/style.scss +21 -0
  132. package/src/components/media-editor-fine-rotation/index.tsx +6 -6
  133. package/src/components/media-editor-image-controls/index.tsx +11 -9
  134. package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
  135. package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
  136. package/src/components/media-editor-modal/index.tsx +4 -1
  137. package/src/components/media-editor-panel/error-boundary.tsx +88 -0
  138. package/src/components/media-editor-panel/index.tsx +211 -0
  139. package/src/components/media-form/index.tsx +7 -1
  140. package/src/components/media-preview/index.tsx +195 -37
  141. package/src/components/media-preview/style.scss +11 -32
  142. package/src/components/rotation-ruler/style.scss +3 -3
  143. package/src/state/README.md +34 -0
  144. package/src/state/aspect-ratio-presets.ts +22 -3
  145. package/src/state/composite-reducer.ts +42 -80
  146. package/src/state/index.ts +2 -18
  147. package/src/state/types.ts +18 -68
  148. package/src/state/use-media-editor-state.ts +162 -242
  149. package/src/style.scss +2 -1
  150. package/src/utils/get-media-type.ts +9 -1
  151. package/src/utils/index.ts +1 -1
  152. package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
  153. package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
  154. package/build/image-editor/core/camera.cjs +0 -277
  155. package/build/image-editor/core/camera.cjs.map +0 -1
  156. package/build/image-editor/core/constants.cjs +0 -133
  157. package/build/image-editor/core/constants.cjs.map +0 -1
  158. package/build/image-editor/core/containment.cjs +0 -289
  159. package/build/image-editor/core/containment.cjs.map +0 -1
  160. package/build/image-editor/core/crop-rect.cjs +0 -37
  161. package/build/image-editor/core/crop-rect.cjs.map +0 -1
  162. package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
  163. package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
  164. package/build/image-editor/core/index.cjs +0 -89
  165. package/build/image-editor/core/interaction-controller.cjs +0 -591
  166. package/build/image-editor/core/interaction-controller.cjs.map +0 -1
  167. package/build/image-editor/core/math/rotation.cjs +0 -32
  168. package/build/image-editor/core/math/rotation.cjs.map +0 -1
  169. package/build/image-editor/core/math/sanitize.cjs +0 -136
  170. package/build/image-editor/core/math/sanitize.cjs.map +0 -1
  171. package/build/image-editor/core/setter-helpers.cjs +0 -61
  172. package/build/image-editor/core/setter-helpers.cjs.map +0 -1
  173. package/build/image-editor/core/source-region.cjs +0 -236
  174. package/build/image-editor/core/source-region.cjs.map +0 -1
  175. package/build/image-editor/core/state.cjs +0 -296
  176. package/build/image-editor/core/state.cjs.map +0 -1
  177. package/build/image-editor/core/stencil-math.cjs +0 -203
  178. package/build/image-editor/core/stencil-math.cjs.map +0 -1
  179. package/build/image-editor/core/transform-style.cjs +0 -43
  180. package/build/image-editor/core/transform-style.cjs.map +0 -1
  181. package/build/image-editor/core/transforms/pipeline.cjs +0 -41
  182. package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
  183. package/build/image-editor/core/types.cjs +0 -5
  184. package/build/image-editor/core/viewport-state.cjs +0 -36
  185. package/build/image-editor/core/viewport-state.cjs.map +0 -1
  186. package/build/image-editor/index.cjs +0 -68
  187. package/build/image-editor/react/components/cropper-provider.cjs +0 -49
  188. package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
  189. package/build/image-editor/react/components/cropper.cjs +0 -595
  190. package/build/image-editor/react/components/cropper.cjs.map +0 -1
  191. package/build/image-editor/react/components/index.cjs +0 -25
  192. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
  193. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
  194. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
  195. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
  196. package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
  197. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
  198. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
  199. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
  200. package/build/image-editor/react/components/viewport-provider.cjs +0 -26
  201. package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
  202. package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
  203. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
  204. package/build/image-editor/react/hooks/index.cjs +0 -19
  205. package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
  206. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
  207. package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
  208. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
  209. package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
  210. package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
  211. package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
  212. package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
  213. package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
  214. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
  215. package/build/image-editor/react/visually-hidden-style.cjs +0 -24
  216. package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
  217. package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
  218. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
  219. package/build-module/image-editor/core/camera.mjs +0 -265
  220. package/build-module/image-editor/core/camera.mjs.map +0 -1
  221. package/build-module/image-editor/core/constants.mjs +0 -115
  222. package/build-module/image-editor/core/constants.mjs.map +0 -1
  223. package/build-module/image-editor/core/containment.mjs +0 -281
  224. package/build-module/image-editor/core/containment.mjs.map +0 -1
  225. package/build-module/image-editor/core/crop-rect.mjs +0 -32
  226. package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
  227. package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
  228. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
  229. package/build-module/image-editor/core/index.mjs +0 -7
  230. package/build-module/image-editor/core/interaction-controller.mjs +0 -586
  231. package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
  232. package/build-module/image-editor/core/math/rotation.mjs +0 -26
  233. package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
  234. package/build-module/image-editor/core/math/sanitize.mjs +0 -127
  235. package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
  236. package/build-module/image-editor/core/setter-helpers.mjs +0 -56
  237. package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
  238. package/build-module/image-editor/core/source-region.mjs +0 -228
  239. package/build-module/image-editor/core/source-region.mjs.map +0 -1
  240. package/build-module/image-editor/core/state.mjs +0 -288
  241. package/build-module/image-editor/core/state.mjs.map +0 -1
  242. package/build-module/image-editor/core/stencil-math.mjs +0 -194
  243. package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
  244. package/build-module/image-editor/core/transform-style.mjs +0 -38
  245. package/build-module/image-editor/core/transform-style.mjs.map +0 -1
  246. package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
  247. package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
  248. package/build-module/image-editor/core/types.mjs +0 -0
  249. package/build-module/image-editor/core/viewport-state.mjs +0 -30
  250. package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
  251. package/build-module/image-editor/index.mjs +0 -4
  252. package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
  253. package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
  254. package/build-module/image-editor/react/components/cropper.mjs +0 -568
  255. package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
  256. package/build-module/image-editor/react/components/index.mjs +0 -3
  257. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
  258. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
  259. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
  260. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
  261. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
  262. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
  263. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
  264. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
  265. package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
  266. package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
  267. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
  268. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
  269. package/build-module/image-editor/react/hooks/index.mjs +0 -3
  270. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
  271. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
  272. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
  273. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
  274. package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
  275. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
  276. package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
  277. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
  278. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
  279. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
  280. package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
  281. package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
  282. package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
  283. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
  284. package/build-types/image-editor/core/camera.d.ts +0 -128
  285. package/build-types/image-editor/core/camera.d.ts.map +0 -1
  286. package/build-types/image-editor/core/constants.d.ts +0 -98
  287. package/build-types/image-editor/core/constants.d.ts.map +0 -1
  288. package/build-types/image-editor/core/containment.d.ts +0 -72
  289. package/build-types/image-editor/core/containment.d.ts.map +0 -1
  290. package/build-types/image-editor/core/crop-rect.d.ts +0 -16
  291. package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
  292. package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
  293. package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
  294. package/build-types/image-editor/core/index.d.ts +0 -10
  295. package/build-types/image-editor/core/index.d.ts.map +0 -1
  296. package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
  297. package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
  298. package/build-types/image-editor/core/math/rotation.d.ts +0 -18
  299. package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
  300. package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
  301. package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
  302. package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
  303. package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
  304. package/build-types/image-editor/core/source-region.d.ts +0 -94
  305. package/build-types/image-editor/core/source-region.d.ts.map +0 -1
  306. package/build-types/image-editor/core/state.d.ts +0 -51
  307. package/build-types/image-editor/core/state.d.ts.map +0 -1
  308. package/build-types/image-editor/core/stencil-math.d.ts +0 -102
  309. package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
  310. package/build-types/image-editor/core/transform-style.d.ts +0 -20
  311. package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
  312. package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
  313. package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
  314. package/build-types/image-editor/core/types.d.ts +0 -269
  315. package/build-types/image-editor/core/types.d.ts.map +0 -1
  316. package/build-types/image-editor/core/viewport-state.d.ts +0 -4
  317. package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
  318. package/build-types/image-editor/index.d.ts +0 -17
  319. package/build-types/image-editor/index.d.ts.map +0 -1
  320. package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
  321. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
  322. package/build-types/image-editor/react/components/cropper.d.ts +0 -54
  323. package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
  324. package/build-types/image-editor/react/components/index.d.ts +0 -4
  325. package/build-types/image-editor/react/components/index.d.ts.map +0 -1
  326. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
  327. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
  328. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
  329. package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
  330. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
  331. package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
  332. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
  333. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
  334. package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
  335. package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
  336. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
  337. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
  338. package/build-types/image-editor/react/hooks/index.d.ts +0 -5
  339. package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
  340. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
  341. package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
  342. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
  343. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
  344. package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
  345. package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
  346. package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
  347. package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
  348. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
  349. package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
  350. package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
  351. package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
  352. package/src/components/media-editor-modal/build-modifiers.ts +0 -167
  353. package/src/image-editor/README.md +0 -61
  354. package/src/image-editor/core/camera.ts +0 -429
  355. package/src/image-editor/core/constants.ts +0 -137
  356. package/src/image-editor/core/containment.ts +0 -469
  357. package/src/image-editor/core/crop-rect.ts +0 -42
  358. package/src/image-editor/core/export/canvas-renderer.ts +0 -250
  359. package/src/image-editor/core/index.ts +0 -43
  360. package/src/image-editor/core/interaction-controller.ts +0 -976
  361. package/src/image-editor/core/math/rotation.ts +0 -26
  362. package/src/image-editor/core/math/sanitize.ts +0 -155
  363. package/src/image-editor/core/setter-helpers.ts +0 -63
  364. package/src/image-editor/core/source-region.ts +0 -367
  365. package/src/image-editor/core/state.ts +0 -484
  366. package/src/image-editor/core/stencil-math.ts +0 -379
  367. package/src/image-editor/core/transform-style.ts +0 -56
  368. package/src/image-editor/core/transforms/pipeline.ts +0 -40
  369. package/src/image-editor/core/types.ts +0 -230
  370. package/src/image-editor/core/viewport-state.ts +0 -30
  371. package/src/image-editor/docs/architecture.md +0 -63
  372. package/src/image-editor/docs/recipes.md +0 -184
  373. package/src/image-editor/index.ts +0 -43
  374. package/src/image-editor/react/components/cropper-provider.tsx +0 -70
  375. package/src/image-editor/react/components/cropper.scss +0 -259
  376. package/src/image-editor/react/components/cropper.tsx +0 -1108
  377. package/src/image-editor/react/components/index.ts +0 -3
  378. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
  379. package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
  380. package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
  381. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
  382. package/src/image-editor/react/components/viewport-provider.tsx +0 -32
  383. package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
  384. package/src/image-editor/react/hooks/index.ts +0 -4
  385. package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
  386. package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
  387. package/src/image-editor/react/hooks/use-interaction.ts +0 -294
  388. package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
  389. package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
  390. package/src/image-editor/react/visually-hidden-style.ts +0 -15
  391. package/src/image-editor/style.scss +0 -1
@@ -1,379 +0,0 @@
1
- import { MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX } from './constants';
2
- import type { HandlePosition, NormalizedRect, Size } from './types';
3
-
4
- export type { HandlePosition };
5
-
6
- /** Axis whose resize distance controls the locked-ratio size projection. */
7
- export type ResizeDriverAxis = 'width' | 'height';
8
-
9
- /**
10
- * Resolve the minimum crop dimension, in source-image pixels, for the current
11
- * display scale.
12
- *
13
- * Two floors compete: a fixed source-pixel floor (`MIN_CROP_PIXELS`) that
14
- * avoids sub-pixel crops, and an on-screen floor (`MIN_CROP_SCREEN_PX`) that
15
- * keeps the crop large enough to grab. The on-screen floor converted to source
16
- * pixels is `MIN_CROP_SCREEN_PX / displayScale`; the binding constraint is the
17
- * larger of the two. When the image is shown small (small `displayScale`) the
18
- * on-screen floor dominates; once it is shown large enough the source-pixel
19
- * floor takes over.
20
- *
21
- * @param displayScale CSS pixels rendered per source pixel
22
- * (fit scale × zoom × view scale).
23
- * @return Minimum crop dimension in source-image pixels.
24
- */
25
- export function getMinCropPixels( displayScale: number ): number {
26
- if ( displayScale <= 0 ) {
27
- return MIN_CROP_PIXELS;
28
- }
29
- return Math.max( MIN_CROP_PIXELS, MIN_CROP_SCREEN_PX / displayScale );
30
- }
31
-
32
- /**
33
- * Default minimum crop rect dimension in normalized space, used when no
34
- * explicit per-axis minimum is supplied (e.g. before the source image
35
- * has loaded). Real usage derives a pixel-based min from the source
36
- * image dimensions and `MIN_CROP_PIXELS` in `constants.ts`.
37
- */
38
- export const DEFAULT_MIN_CROP_SIZE: Size = { width: 0.05, height: 0.05 };
39
-
40
- /**
41
- * Bounds within which the crop rect must stay.
42
- */
43
- export interface CropBounds {
44
- minX: number;
45
- minY: number;
46
- maxX: number;
47
- maxY: number;
48
- }
49
-
50
- /**
51
- * Drag state for tracking a resize interaction.
52
- */
53
- export interface ResizeDragState {
54
- /** Which handle is being dragged. */
55
- handle: HandlePosition;
56
- /** The mouse position (pixels) when the drag started. */
57
- startX: number;
58
- startY: number;
59
- /** The crop rect (normalized) when the drag started. */
60
- startRect: NormalizedRect;
61
- }
62
-
63
- /**
64
- * Compute the new crop rect for a free (no aspect ratio) resize.
65
- *
66
- * Each edge moves independently based on the handle being dragged.
67
- * Edges are clamped to the provided bounds and maintain a minimum size.
68
- *
69
- * @param drag The current drag state.
70
- * @param clientX Current mouse/touch X position in pixels.
71
- * @param clientY Current mouse/touch Y position in pixels.
72
- * @param imageSize The rendered image dimensions in pixels.
73
- * @param bounds The allowed crop area bounds.
74
- * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
75
- * @return The new crop rect in normalized coordinates.
76
- */
77
- export function computeFreeResizeRect(
78
- drag: ResizeDragState,
79
- clientX: number,
80
- clientY: number,
81
- imageSize: Size,
82
- bounds: CropBounds,
83
- minCropSize: Size = DEFAULT_MIN_CROP_SIZE
84
- ): NormalizedRect {
85
- const dx =
86
- imageSize.width > 0 ? ( clientX - drag.startX ) / imageSize.width : 0;
87
- const dy =
88
- imageSize.height > 0 ? ( clientY - drag.startY ) / imageSize.height : 0;
89
-
90
- const s = drag.startRect;
91
- const handle = drag.handle;
92
-
93
- let edgeTop = s.y;
94
- let edgeBottom = s.y + s.height;
95
- let edgeLeft = s.x;
96
- let edgeRight = s.x + s.width;
97
-
98
- if ( handle === 'n' || handle === 'nw' || handle === 'ne' ) {
99
- edgeTop = Math.max(
100
- bounds.minY,
101
- Math.min( s.y + dy, edgeBottom - minCropSize.height )
102
- );
103
- }
104
- if ( handle === 's' || handle === 'sw' || handle === 'se' ) {
105
- edgeBottom = Math.max(
106
- edgeTop + minCropSize.height,
107
- Math.min( s.y + s.height + dy, bounds.maxY )
108
- );
109
- }
110
- if ( handle === 'w' || handle === 'nw' || handle === 'sw' ) {
111
- edgeLeft = Math.max(
112
- bounds.minX,
113
- Math.min( s.x + dx, edgeRight - minCropSize.width )
114
- );
115
- }
116
- if ( handle === 'e' || handle === 'ne' || handle === 'se' ) {
117
- edgeRight = Math.max(
118
- edgeLeft + minCropSize.width,
119
- Math.min( s.x + s.width + dx, bounds.maxX )
120
- );
121
- }
122
-
123
- return {
124
- x: edgeLeft,
125
- y: edgeTop,
126
- width: edgeRight - edgeLeft,
127
- height: edgeBottom - edgeTop,
128
- };
129
- }
130
-
131
- /**
132
- * Compute the new crop rect for a locked-aspect-ratio corner resize.
133
- *
134
- * The opposite corner is the anchor. The dragged corner moves freely
135
- * but the result is clamped to maintain the aspect ratio and stay
136
- * within bounds.
137
- *
138
- * @param drag The current drag state.
139
- * @param clientX Current mouse/touch X position in pixels.
140
- * @param clientY Current mouse/touch Y position in pixels.
141
- * @param imageSize The rendered image dimensions in pixels.
142
- * @param bounds The allowed crop area bounds.
143
- * @param normalizedRatio The locked aspect ratio (width / height in normalized space).
144
- * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
145
- * @param driverAxis Optional explicit driver axis. Used for keyboard
146
- * resize, where one arrow axis should determine the step.
147
- * @return The new crop rect in normalized coordinates.
148
- */
149
- export function computeLockedResizeRect(
150
- drag: ResizeDragState,
151
- clientX: number,
152
- clientY: number,
153
- imageSize: Size,
154
- bounds: CropBounds,
155
- normalizedRatio: number,
156
- minCropSize: Size = DEFAULT_MIN_CROP_SIZE,
157
- driverAxis?: ResizeDriverAxis
158
- ): NormalizedRect {
159
- // The math below divides by `normalizedRatio` and `imageSize`, so
160
- // bail out with the start rect when any of them is zero. This can
161
- // happen if a resize is triggered (e.g. via keyboard arrows on a
162
- // focused handle) before the image has loaded.
163
- if (
164
- normalizedRatio <= 0 ||
165
- imageSize.width <= 0 ||
166
- imageSize.height <= 0
167
- ) {
168
- return { ...drag.startRect };
169
- }
170
-
171
- const dx = ( clientX - drag.startX ) / imageSize.width;
172
- const dy = ( clientY - drag.startY ) / imageSize.height;
173
-
174
- const s = drag.startRect;
175
- const handle = drag.handle;
176
-
177
- // Determine the anchor corner (opposite to the dragged corner).
178
- const anchorX = handle === 'nw' || handle === 'sw' ? s.x + s.width : s.x;
179
- const anchorY = handle === 'nw' || handle === 'ne' ? s.y + s.height : s.y;
180
-
181
- // Direction the crop grows from the anchor (+1 = right/down, -1 = left/up).
182
- const dirX = handle === 'nw' || handle === 'sw' ? -1 : 1;
183
- const dirY = handle === 'nw' || handle === 'ne' ? -1 : 1;
184
-
185
- // Desired new position of the dragged corner.
186
- const draggedX =
187
- ( handle === 'nw' || handle === 'sw' ? s.x : s.x + s.width ) + dx;
188
- const draggedY =
189
- ( handle === 'nw' || handle === 'ne' ? s.y : s.y + s.height ) + dy;
190
-
191
- // Raw distances from anchor to dragged corner.
192
- let distW = ( draggedX - anchorX ) * dirX;
193
- let distH = ( draggedY - anchorY ) * dirY;
194
-
195
- // Enforce minimum size on both axes, projecting through the ratio so
196
- // neither axis falls below its per-axis floor.
197
- const minDistW = Math.max(
198
- minCropSize.width,
199
- minCropSize.height * normalizedRatio
200
- );
201
- const minDistH = minDistW / normalizedRatio;
202
- distW = Math.max( distW, minDistW );
203
- distH = Math.max( distH, minDistH );
204
-
205
- // Determine which axis "drives". Pointer drags use the dragged-corner
206
- // geometry so the projected crop changes continuously as the pointer moves.
207
- // Keyboard resize passes an explicit axis because a single-axis arrow step
208
- // should drive that axis instead of being cancelled by the unchanged axis.
209
- const pixelRatio = ( normalizedRatio * imageSize.width ) / imageSize.height;
210
- const isWidthDriver =
211
- driverAxis === 'width' ||
212
- ( ! driverAxis &&
213
- ( distW * imageSize.width ) / ( distH * imageSize.height ) >
214
- pixelRatio );
215
-
216
- if ( isWidthDriver ) {
217
- // Width is the driver — compute height from ratio.
218
- distH = distW / normalizedRatio;
219
- } else {
220
- // Height is the driver — compute width from ratio.
221
- distW = distH * normalizedRatio;
222
- }
223
-
224
- // Clamp to image coverage bounds. If the rect would exceed,
225
- // shrink it (maintaining ratio) to fit.
226
- const maxW = dirX > 0 ? bounds.maxX - anchorX : anchorX - bounds.minX;
227
- const maxH = dirY > 0 ? bounds.maxY - anchorY : anchorY - bounds.minY;
228
-
229
- if ( distW > maxW ) {
230
- distW = maxW;
231
- distH = distW / normalizedRatio;
232
- }
233
- if ( distH > maxH ) {
234
- distH = maxH;
235
- distW = distH * normalizedRatio;
236
- }
237
-
238
- // Enforce minimum after clamping.
239
- distW = Math.max( distW, minDistW );
240
- distH = Math.max( distH, minDistH );
241
-
242
- // Compute the final rect position from the anchor.
243
- const newX = dirX > 0 ? anchorX : anchorX - distW;
244
- const newY = dirY > 0 ? anchorY : anchorY - distH;
245
-
246
- return { x: newX, y: newY, width: distW, height: distH };
247
- }
248
-
249
- /**
250
- * Compute the new crop rect for a resize that temporarily locks the
251
- * aspect ratio to `drag.startRect`'s ratio (e.g. while Shift is held).
252
- *
253
- * Corner handles delegate to {@link computeLockedResizeRect}. Edge
254
- * handles size the dragged axis freely, then expand the perpendicular
255
- * axis symmetrically around the rect's center to preserve the ratio,
256
- * clamping symmetrically so the rect stays within bounds.
257
- *
258
- * @param drag The current drag state.
259
- * @param clientX Current mouse/touch X position in pixels.
260
- * @param clientY Current mouse/touch Y position in pixels.
261
- * @param imageSize The rendered image dimensions in pixels.
262
- * @param bounds The allowed crop area bounds.
263
- * @param minCropSize Minimum crop rect dimension in normalized space, per axis.
264
- * @return The new crop rect in normalized coordinates.
265
- */
266
- export function computeShiftLockedResizeRect(
267
- drag: ResizeDragState,
268
- clientX: number,
269
- clientY: number,
270
- imageSize: Size,
271
- bounds: CropBounds,
272
- minCropSize: Size = DEFAULT_MIN_CROP_SIZE
273
- ): NormalizedRect {
274
- const s = drag.startRect;
275
- const pixelW = s.width * imageSize.width;
276
- const pixelH = s.height * imageSize.height;
277
- if ( pixelH <= 0 || pixelW <= 0 ) {
278
- return computeFreeResizeRect(
279
- drag,
280
- clientX,
281
- clientY,
282
- imageSize,
283
- bounds,
284
- minCropSize
285
- );
286
- }
287
- const normalizedRatio = s.width / s.height;
288
-
289
- const handle = drag.handle;
290
- if (
291
- handle === 'nw' ||
292
- handle === 'ne' ||
293
- handle === 'sw' ||
294
- handle === 'se'
295
- ) {
296
- return computeLockedResizeRect(
297
- drag,
298
- clientX,
299
- clientY,
300
- imageSize,
301
- bounds,
302
- normalizedRatio,
303
- minCropSize
304
- );
305
- }
306
-
307
- // Edge handle: size the dragged axis with free-resize logic, then
308
- // expand the perpendicular axis symmetrically around the rect's center.
309
- const free = computeFreeResizeRect(
310
- drag,
311
- clientX,
312
- clientY,
313
- imageSize,
314
- bounds,
315
- minCropSize
316
- );
317
-
318
- if ( handle === 'n' || handle === 's' ) {
319
- // Height is the driver; derive width from ratio.
320
- let newHeight = free.height;
321
- let newWidth = newHeight * normalizedRatio;
322
- const centerX = s.x + s.width / 2;
323
- // Symmetric clamp: limit by the smaller of the two side gaps so
324
- // the rect stays centered around centerX.
325
- const maxWidth =
326
- Math.min( centerX - bounds.minX, bounds.maxX - centerX ) * 2;
327
- if ( newWidth > maxWidth ) {
328
- newWidth = maxWidth;
329
- newHeight = newWidth / normalizedRatio;
330
- }
331
- // Enforce the minimum on the driving axis, then derive the
332
- // other axis from the ratio so it stays consistent. The
333
- // effective minimum height has to satisfy the per-axis floor
334
- // on both axes simultaneously.
335
- const minHeight = Math.max(
336
- minCropSize.height,
337
- minCropSize.width / normalizedRatio
338
- );
339
- if ( newHeight < minHeight ) {
340
- newHeight = minHeight;
341
- newWidth = newHeight * normalizedRatio;
342
- }
343
- // Re-anchor the dragged axis to the opposite edge so the
344
- // height adjustment after clamping keeps that edge fixed.
345
- const newY = handle === 'n' ? s.y + s.height - newHeight : s.y;
346
- return {
347
- x: centerX - newWidth / 2,
348
- y: newY,
349
- width: newWidth,
350
- height: newHeight,
351
- };
352
- }
353
-
354
- // 'e' or 'w': width is the driver; derive height from ratio.
355
- let newWidth = free.width;
356
- let newHeight = newWidth / normalizedRatio;
357
- const centerY = s.y + s.height / 2;
358
- const maxHeight =
359
- Math.min( centerY - bounds.minY, bounds.maxY - centerY ) * 2;
360
- if ( newHeight > maxHeight ) {
361
- newHeight = maxHeight;
362
- newWidth = newHeight * normalizedRatio;
363
- }
364
- const minWidth = Math.max(
365
- minCropSize.width,
366
- minCropSize.height * normalizedRatio
367
- );
368
- if ( newWidth < minWidth ) {
369
- newWidth = minWidth;
370
- newHeight = newWidth / normalizedRatio;
371
- }
372
- const newX = handle === 'w' ? s.x + s.width - newWidth : s.x;
373
- return {
374
- x: newX,
375
- y: centerY - newHeight / 2,
376
- width: newWidth,
377
- height: newHeight,
378
- };
379
- }
@@ -1,56 +0,0 @@
1
- import type { CropperState, Size } from './types';
2
- import { degreesToRadians } from './math/rotation';
3
- import { isValidSize, sanitizeCropperState } from './math/sanitize';
4
-
5
- /** Identity CSS transform — applied when inputs aren't safe to compose. */
6
- const IDENTITY_MATRIX_STYLE = 'matrix(1, 0, 0, 1, 0, 0)';
7
-
8
- /**
9
- * Computes a CSS matrix() transform string from the cropper state.
10
- *
11
- * The combined transform is: translate(tx, ty) * scale(sx, sy) * rotate(r) * scale(z)
12
- * expressed as a 2D CSS matrix(a, b, c, d, tx, ty).
13
- *
14
- * Flip is composed outside rotation so it is viewport-relative — horizontal
15
- * flip mirrors across the viewport's vertical axis regardless of rotation.
16
- * Must match the matrix order in `createCamera` / `getImageCropBounds`.
17
- *
18
- * This is a pure function with no framework dependencies. The React hook
19
- * `useTransformStyle` wraps this in `useMemo` for memoization.
20
- *
21
- * @param state The current cropper state.
22
- * @param imageSize The rendered image dimensions in pixels.
23
- * @return A CSS transform string.
24
- */
25
- export function computeTransformStyle(
26
- state: CropperState,
27
- imageSize: Size
28
- ): string {
29
- // Match the identity short-circuit used by `createCamera` and
30
- // `getSourceRegion` so the preview path stays consistent with the math
31
- // path when `imageSize` itself is hostile (state sanitization below
32
- // only guards the state fields, not these size arguments).
33
- if ( ! isValidSize( imageSize ) ) {
34
- return IDENTITY_MATRIX_STYLE;
35
- }
36
- // Sanitize so hostile state can't produce `matrix(NaN, NaN, ...)` here
37
- // while the parallel `createCamera` path returns a finite matrix. Both
38
- // paths must agree under defense-in-depth conditions.
39
- const safeState = sanitizeCropperState( state );
40
- const translateX = safeState.pan.x * imageSize.width;
41
- const translateY = safeState.pan.y * imageSize.height;
42
- const rad = degreesToRadians( safeState.rotation );
43
- const cos = Math.cos( rad );
44
- const sin = Math.sin( rad );
45
- const sx = safeState.flip.horizontal ? -1 : 1;
46
- const sy = safeState.flip.vertical ? -1 : 1;
47
- const z = safeState.zoom;
48
-
49
- // Combined: translate(tx,ty) * scale(sx,sy) * rotate(r) * scale(z)
50
- const a = sx * cos * z;
51
- const b = sy * sin * z;
52
- const c = -sx * sin * z;
53
- const d = sy * cos * z;
54
-
55
- return `matrix(${ a }, ${ b }, ${ c }, ${ d }, ${ translateX }, ${ translateY })`;
56
- }
@@ -1,40 +0,0 @@
1
- import type { TransformOperation, CropperState } from '../types';
2
- import { DEFAULT_STATE } from '../constants';
3
- import { cropperReducer } from '../state';
4
-
5
- /**
6
- * Apply a single transform operation to a cropper state, returning
7
- * a new state with the containment invariant enforced.
8
- *
9
- * Delegates to the reducer via APPLY_OPERATION so pipeline replay
10
- * produces identical bounded state to UI interaction or setter
11
- * calls. The same logical operation yields the same result
12
- * regardless of entrypoint.
13
- *
14
- * @param state The current cropper state.
15
- * @param op The operation to apply.
16
- * @return A new cropper state with the operation applied.
17
- */
18
- export function applyOperationToState(
19
- state: CropperState,
20
- op: TransformOperation
21
- ): CropperState {
22
- return cropperReducer( state, { type: 'APPLY_OPERATION', payload: op } );
23
- }
24
-
25
- /**
26
- * Replay all operations from an initial state to produce the final state.
27
- *
28
- * @param pipeline The array of transform operations to replay.
29
- * @param initialState The starting state. Defaults to DEFAULT_STATE.
30
- * @return The resulting cropper state after all operations are applied.
31
- */
32
- export function stateFromPipeline(
33
- pipeline: TransformOperation[],
34
- initialState: CropperState = { ...DEFAULT_STATE }
35
- ): CropperState {
36
- return pipeline.reduce(
37
- ( state, op ) => applyOperationToState( state, op ),
38
- initialState
39
- );
40
- }
@@ -1,230 +0,0 @@
1
- import type { mat2d } from 'gl-matrix';
2
-
3
- /**
4
- * A 2D camera represented as a 2×3 affine transformation matrix (`mat2d`).
5
- *
6
- * This is not a camera object with properties — it's a raw 6-element matrix
7
- * `[a, b, c, d, tx, ty]` that maps normalized world coordinates [0,1] to
8
- * screen pixels. It composes pan, rotation, flip, zoom, and contain-fit
9
- * into a single transform.
10
- *
11
- * Use `createCamera()` to build one from `CropperState`, then pass it to
12
- * `worldToScreen()` / `screenToWorld()` for coordinate conversion.
13
- *
14
- * A 3D camera would use `mat4`; this is strictly 2D (no perspective).
15
- */
16
- export type Camera = mat2d;
17
-
18
- /**
19
- * A point with normalized coordinates (0-1 range relative to image dimensions).
20
- */
21
- export interface NormalizedPoint {
22
- x: number;
23
- y: number;
24
- }
25
-
26
- /**
27
- * A rectangle with normalized coordinates (0-1 range).
28
- * Origin is the top-left corner of the image.
29
- */
30
- export interface NormalizedRect {
31
- x: number;
32
- y: number;
33
- width: number;
34
- height: number;
35
- }
36
-
37
- /**
38
- * Width and height dimensions.
39
- */
40
- export interface Size {
41
- width: number;
42
- height: number;
43
- }
44
-
45
- /**
46
- * Flip state for horizontal and vertical axes.
47
- */
48
- export interface Flip {
49
- horizontal: boolean;
50
- vertical: boolean;
51
- }
52
-
53
- /**
54
- * A JSON-serializable transform operation for the non-destructive pipeline.
55
- */
56
- export type TransformOperation =
57
- | { type: 'crop'; rect: NormalizedRect }
58
- | { type: 'rotate'; degrees: number }
59
- | { type: 'flip'; direction: 'horizontal' | 'vertical' }
60
- | { type: 'zoom'; factor: number };
61
-
62
- /**
63
- * Full cropper state.
64
- */
65
- export interface CropperState {
66
- /** The source image information. Null until an image is loaded. */
67
- image: {
68
- src: string;
69
- naturalWidth: number;
70
- naturalHeight: number;
71
- } | null;
72
- /**
73
- * Image pan offset in normalized coordinates. Not the crop
74
- * rectangle — that's `cropRect` below.
75
- */
76
- pan: NormalizedPoint;
77
- /** Zoom level. 1 = no zoom. */
78
- zoom: number;
79
- /** Rotation in degrees, normalized to 0-360. */
80
- rotation: number;
81
- /**
82
- * Base pan/zoom/rotation — the pose the user last explicitly set.
83
- *
84
- * During continuous fine rotation (SET_ROTATION), every tick
85
- * re-derives the transient `pan`/`zoom` from these base values
86
- * rather than compounding on the previous tick. This prevents
87
- * drift from accumulated containment clamping near image edges:
88
- * rotating 0°→30°→0° returns to the exact starting pan, not a
89
- * slightly-nudged version of it.
90
- *
91
- * These are updated by every action except SET_ROTATION itself —
92
- * explicit zoom, pan, crop-rect, flip, and 90° snap all commit
93
- * the post-containment state into base. SET_ROTATION reads from
94
- * `basePan` and `baseRotation` to compute the new pan, and reads
95
- * `baseZoom` as the zoom floor (enforceContainment may bump it up
96
- * to cover the rotated crop, but never leaves it above baseZoom).
97
- */
98
- basePan: NormalizedPoint;
99
- baseZoom: number;
100
- baseRotation: number;
101
- /** Flip state. */
102
- flip: Flip;
103
- /** The crop rectangle in normalized coordinates. */
104
- cropRect: NormalizedRect;
105
- }
106
-
107
- /**
108
- * Internal reducer action union.
109
- *
110
- * This type is intentionally not exported from the image-editor public barrel.
111
- * Consumers should drive state through the controller returned by
112
- * `useCropperController()` (or a composite store) or through serializable
113
- * `TransformOperation` values.
114
- */
115
- export type CropperAction =
116
- /** Sets the loaded image metadata (natural size, src). */
117
- | { type: 'SET_IMAGE'; payload: CropperState[ 'image' ] }
118
- /** Sets the image pan offset. (Crop rectangle is SET_CROP_RECT.) */
119
- | { type: 'SET_PAN'; payload: NormalizedPoint }
120
- /** Sets the zoom level, clamped to [coverage-aware min, MAX_ZOOM]. */
121
- | { type: 'SET_ZOOM'; payload: number }
122
- /**
123
- * Sets zoom and pan together atomically. Used by focal-point
124
- * zoom (wheel, pinch) to keep a target point stationary while
125
- * zoom changes.
126
- */
127
- | {
128
- type: 'SET_ZOOM_AT_POINT';
129
- payload: { zoom: number; pan: NormalizedPoint };
130
- }
131
- /** Sets the absolute rotation angle in degrees. */
132
- | { type: 'SET_ROTATION'; payload: number }
133
- /** Rotates by +/-90 degrees (snap). */
134
- | { type: 'SNAP_ROTATE_90'; payload: { direction: 1 | -1 } }
135
- /** Sets the flip state. */
136
- | { type: 'SET_FLIP'; payload: Flip }
137
- /** Sets the crop rectangle. */
138
- | { type: 'SET_CROP_RECT'; payload: NormalizedRect }
139
- /** Settle animation after resize drag, recentering the crop rect. */
140
- | { type: 'SETTLE_CROP' }
141
- /** Applies a single pipeline transform via the reducer. */
142
- | { type: 'APPLY_OPERATION'; payload: TransformOperation }
143
- /** Resets to DEFAULT_STATE, optionally merging a partial override. */
144
- | { type: 'RESET'; payload?: Partial< CropperState > };
145
-
146
- /**
147
- * Viewport camera state — display-only, does not affect export or undo.
148
- *
149
- * Applied as a CSS transform on the inner stage div so the user can scroll
150
- * the view independently of the crop. zoom > 1 magnifies; pan shifts in CSS px.
151
- */
152
- export interface ViewportState {
153
- zoom: number;
154
- pan: { x: number; y: number };
155
- }
156
-
157
- export type ViewportAction =
158
- | { type: 'SET_VIEWPORT_ZOOM'; payload: number }
159
- | { type: 'SET_VIEWPORT_PAN'; payload: { x: number; y: number } }
160
- | { type: 'RESET_VIEWPORT' };
161
-
162
- /**
163
- * Direction of a crop resize handle. Eight compass positions: four
164
- * corners and four edge midpoints. Used by stencil callbacks and any
165
- * overlay that needs to know which handle the user is dragging.
166
- */
167
- export type HandlePosition = 'n' | 's' | 'e' | 'w' | 'nw' | 'ne' | 'sw' | 'se';
168
-
169
- /**
170
- * The contract for a pluggable stencil component.
171
- * Stencils render the crop area overlay and handle resize interactions.
172
- */
173
- export interface StencilProps {
174
- /** The current crop rectangle in normalized coordinates. */
175
- cropRect: NormalizedRect;
176
- /** The container element dimensions in pixels. */
177
- containerSize: Size;
178
- /** The rendered image dimensions in pixels within the container. */
179
- imageSize: Size;
180
- /** Callback when the crop rectangle changes (during drag). */
181
- onCropChange: ( rect: NormalizedRect ) => void;
182
- /**
183
- * Callback when a resize interaction starts — pointerdown on a handle
184
- * or the first arrow-key press on a focused handle. The handle direction
185
- * is passed so downstream overlays can anchor to it. The argument is
186
- * optional to keep custom stencils that don't track a direction
187
- * backward-compatible.
188
- */
189
- onResizeStart?: ( handle?: HandlePosition ) => void;
190
- /** Callback when a resize drag ends (mouseup after handle drag). */
191
- onResizeEnd?: () => void;
192
- /** Optional fixed aspect ratio (width / height) in pixel space. */
193
- aspectRatio?: number;
194
- /** Whether the crop handles are shown for freeform resizing. */
195
- freeformCrop?: boolean;
196
- /** Whether resize handles should ignore pointer and keyboard input. */
197
- isResizeDisabled?: boolean;
198
- /** CSS transition string for settle animation. */
199
- stencilTransition?: string;
200
- /** Maximum crop rect bounds based on current zoom/rotation. */
201
- cropBounds?: {
202
- minX: number;
203
- minY: number;
204
- maxX: number;
205
- maxY: number;
206
- };
207
- /** Called when Escape is pressed on a resize handle. */
208
- onEscape?: () => void;
209
- /**
210
- * Minimum crop rect dimension in normalized space, per axis. Derived
211
- * by the host from a pixel-based floor (see `MIN_CROP_PIXELS`) and
212
- * the source image dimensions. Omit to use the stencil's default.
213
- */
214
- minCropSize?: Size;
215
- /**
216
- * Optional post-processor for freeform resize output. Hosts use this for
217
- * display-gated behavior such as snapping visible pixel grids to source
218
- * pixel boundaries.
219
- */
220
- snapCropRect?: (
221
- rect: NormalizedRect,
222
- handle: HandlePosition
223
- ) => NormalizedRect;
224
- /**
225
- * Optional keyboard resize step in normalized space, per axis. Hosts use
226
- * this when keyboard resize should follow the rendered image scale instead
227
- * of the default percentage-based step.
228
- */
229
- keyboardResizeStep?: Size;
230
- }