@wordpress/media-editor 0.9.0 → 0.10.1

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 (322) hide show
  1. package/build/components/media-editor/index.cjs +212 -170
  2. package/build/components/media-editor/index.cjs.map +3 -3
  3. package/build/components/media-editor/use-crop-options.cjs +63 -0
  4. package/build/components/media-editor/use-crop-options.cjs.map +7 -0
  5. package/build/components/media-editor/use-save-media-editor.cjs +185 -0
  6. package/build/components/media-editor/use-save-media-editor.cjs.map +7 -0
  7. package/build/components/media-editor-canvas/index.cjs +33 -12
  8. package/build/components/media-editor-canvas/index.cjs.map +2 -2
  9. package/build/components/media-editor-crop-panel/index.cjs +70 -84
  10. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  11. package/build/components/media-editor-fine-rotation/index.cjs +81 -0
  12. package/build/components/media-editor-fine-rotation/index.cjs.map +7 -0
  13. package/build/components/media-editor-modal/index.cjs +63 -16
  14. package/build/components/media-editor-modal/index.cjs.map +3 -3
  15. package/build/components/media-editor-transform-controls/index.cjs +84 -0
  16. package/build/components/media-editor-transform-controls/index.cjs.map +7 -0
  17. package/build/components/media-form/index.cjs +19 -1
  18. package/build/components/media-form/index.cjs.map +3 -3
  19. package/build/components/media-form/sidebar-datetime-view.cjs +53 -0
  20. package/build/components/media-form/sidebar-datetime-view.cjs.map +7 -0
  21. package/build/components/rotation-ruler/index.cjs +8 -2
  22. package/build/components/rotation-ruler/index.cjs.map +2 -2
  23. package/build/hooks/use-crop-gesture-handlers.cjs +41 -4
  24. package/build/hooks/use-crop-gesture-handlers.cjs.map +2 -2
  25. package/build/image-editor/core/camera.cjs +29 -11
  26. package/build/image-editor/core/camera.cjs.map +2 -2
  27. package/build/image-editor/core/constants.cjs +6 -0
  28. package/build/image-editor/core/constants.cjs.map +2 -2
  29. package/build/image-editor/core/containment.cjs +71 -34
  30. package/build/image-editor/core/containment.cjs.map +2 -2
  31. package/build/image-editor/core/crop-rect.cjs +48 -0
  32. package/build/image-editor/core/crop-rect.cjs.map +7 -0
  33. package/build/image-editor/core/index.cjs +12 -0
  34. package/build/image-editor/core/index.cjs.map +2 -2
  35. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  36. package/build/image-editor/core/math/sanitize.cjs +92 -0
  37. package/build/image-editor/core/math/sanitize.cjs.map +7 -0
  38. package/build/image-editor/core/setter-helpers.cjs +64 -0
  39. package/build/image-editor/core/setter-helpers.cjs.map +7 -0
  40. package/build/image-editor/core/source-region.cjs +16 -14
  41. package/build/image-editor/core/source-region.cjs.map +2 -2
  42. package/build/image-editor/core/state.cjs +20 -10
  43. package/build/image-editor/core/state.cjs.map +2 -2
  44. package/build/image-editor/core/stencil-math.cjs +31 -20
  45. package/build/image-editor/core/stencil-math.cjs.map +2 -2
  46. package/build/image-editor/core/transform-style.cjs +12 -6
  47. package/build/image-editor/core/transform-style.cjs.map +2 -2
  48. package/build/image-editor/core/types.cjs.map +1 -1
  49. package/build/image-editor/index.cjs +12 -2
  50. package/build/image-editor/index.cjs.map +2 -2
  51. package/build/image-editor/react/components/cropper-provider.cjs +2 -2
  52. package/build/image-editor/react/components/cropper-provider.cjs.map +2 -2
  53. package/build/image-editor/react/components/cropper.cjs +120 -47
  54. package/build/image-editor/react/components/cropper.cjs.map +2 -2
  55. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +172 -0
  56. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +7 -0
  57. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +19 -9
  58. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
  59. package/build/image-editor/react/hooks/build-cropper-setters.cjs +71 -0
  60. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +7 -0
  61. package/build/image-editor/react/hooks/index.cjs +6 -3
  62. package/build/image-editor/react/hooks/index.cjs.map +2 -2
  63. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +113 -0
  64. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +7 -0
  65. package/build/state/composite-reducer.cjs +103 -0
  66. package/build/state/composite-reducer.cjs.map +7 -0
  67. package/build/state/index.cjs +48 -0
  68. package/build/state/index.cjs.map +7 -0
  69. package/build/state/media-editor-state-provider.cjs +58 -0
  70. package/build/state/media-editor-state-provider.cjs.map +7 -0
  71. package/build/state/types.cjs +33 -0
  72. package/build/state/types.cjs.map +7 -0
  73. package/build/state/use-media-editor-state.cjs +287 -0
  74. package/build/state/use-media-editor-state.cjs.map +7 -0
  75. package/build/store/actions.cjs +4 -2
  76. package/build/store/actions.cjs.map +2 -2
  77. package/build/store/reducer.cjs +5 -3
  78. package/build/store/reducer.cjs.map +2 -2
  79. package/build/store/selectors.cjs +5 -0
  80. package/build/store/selectors.cjs.map +2 -2
  81. package/build-module/components/media-editor/index.mjs +224 -177
  82. package/build-module/components/media-editor/index.mjs.map +2 -2
  83. package/build-module/components/media-editor/use-crop-options.mjs +37 -0
  84. package/build-module/components/media-editor/use-crop-options.mjs.map +7 -0
  85. package/build-module/components/media-editor/use-save-media-editor.mjs +151 -0
  86. package/build-module/components/media-editor/use-save-media-editor.mjs.map +7 -0
  87. package/build-module/components/media-editor-canvas/index.mjs +34 -13
  88. package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
  89. package/build-module/components/media-editor-crop-panel/index.mjs +73 -89
  90. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  91. package/build-module/components/media-editor-fine-rotation/index.mjs +50 -0
  92. package/build-module/components/media-editor-fine-rotation/index.mjs.map +7 -0
  93. package/build-module/components/media-editor-modal/index.mjs +64 -17
  94. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  95. package/build-module/components/media-editor-transform-controls/index.mjs +68 -0
  96. package/build-module/components/media-editor-transform-controls/index.mjs.map +7 -0
  97. package/build-module/components/media-form/index.mjs +9 -1
  98. package/build-module/components/media-form/index.mjs.map +2 -2
  99. package/build-module/components/media-form/sidebar-datetime-view.mjs +32 -0
  100. package/build-module/components/media-form/sidebar-datetime-view.mjs.map +7 -0
  101. package/build-module/components/rotation-ruler/index.mjs +8 -2
  102. package/build-module/components/rotation-ruler/index.mjs.map +2 -2
  103. package/build-module/hooks/use-crop-gesture-handlers.mjs +41 -4
  104. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +2 -2
  105. package/build-module/image-editor/core/camera.mjs +34 -11
  106. package/build-module/image-editor/core/camera.mjs.map +2 -2
  107. package/build-module/image-editor/core/constants.mjs +4 -0
  108. package/build-module/image-editor/core/constants.mjs.map +2 -2
  109. package/build-module/image-editor/core/containment.mjs +75 -34
  110. package/build-module/image-editor/core/containment.mjs.map +2 -2
  111. package/build-module/image-editor/core/crop-rect.mjs +23 -0
  112. package/build-module/image-editor/core/crop-rect.mjs.map +7 -0
  113. package/build-module/image-editor/core/index.mjs +12 -0
  114. package/build-module/image-editor/core/index.mjs.map +2 -2
  115. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  116. package/build-module/image-editor/core/math/sanitize.mjs +63 -0
  117. package/build-module/image-editor/core/math/sanitize.mjs.map +7 -0
  118. package/build-module/image-editor/core/setter-helpers.mjs +39 -0
  119. package/build-module/image-editor/core/setter-helpers.mjs.map +7 -0
  120. package/build-module/image-editor/core/source-region.mjs +16 -14
  121. package/build-module/image-editor/core/source-region.mjs.map +2 -2
  122. package/build-module/image-editor/core/state.mjs +25 -11
  123. package/build-module/image-editor/core/state.mjs.map +2 -2
  124. package/build-module/image-editor/core/stencil-math.mjs +30 -19
  125. package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
  126. package/build-module/image-editor/core/transform-style.mjs +12 -6
  127. package/build-module/image-editor/core/transform-style.mjs.map +2 -2
  128. package/build-module/image-editor/index.mjs +11 -2
  129. package/build-module/image-editor/index.mjs.map +2 -2
  130. package/build-module/image-editor/react/components/cropper-provider.mjs +3 -3
  131. package/build-module/image-editor/react/components/cropper-provider.mjs.map +2 -2
  132. package/build-module/image-editor/react/components/cropper.mjs +121 -48
  133. package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
  134. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +147 -0
  135. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +7 -0
  136. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +19 -9
  137. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
  138. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +46 -0
  139. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +7 -0
  140. package/build-module/image-editor/react/hooks/index.mjs +4 -2
  141. package/build-module/image-editor/react/hooks/index.mjs.map +2 -2
  142. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +100 -0
  143. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +7 -0
  144. package/build-module/state/composite-reducer.mjs +82 -0
  145. package/build-module/state/composite-reducer.mjs.map +7 -0
  146. package/build-module/state/index.mjs +26 -0
  147. package/build-module/state/index.mjs.map +7 -0
  148. package/build-module/state/media-editor-state-provider.mjs +34 -0
  149. package/build-module/state/media-editor-state-provider.mjs.map +7 -0
  150. package/build-module/state/types.mjs +8 -0
  151. package/build-module/state/types.mjs.map +7 -0
  152. package/build-module/state/use-media-editor-state.mjs +278 -0
  153. package/build-module/state/use-media-editor-state.mjs.map +7 -0
  154. package/build-module/store/actions.mjs +4 -2
  155. package/build-module/store/actions.mjs.map +2 -2
  156. package/build-module/store/reducer.mjs +5 -3
  157. package/build-module/store/reducer.mjs.map +2 -2
  158. package/build-module/store/selectors.mjs +4 -0
  159. package/build-module/store/selectors.mjs.map +2 -2
  160. package/build-style/style-rtl.css +97 -44
  161. package/build-style/style.css +97 -44
  162. package/build-types/components/media-editor/index.d.ts +14 -5
  163. package/build-types/components/media-editor/index.d.ts.map +1 -1
  164. package/build-types/components/media-editor/use-crop-options.d.ts +35 -0
  165. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -0
  166. package/build-types/components/media-editor/use-save-media-editor.d.ts +29 -0
  167. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -0
  168. package/build-types/components/media-editor-canvas/index.d.ts +5 -10
  169. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  170. package/build-types/components/media-editor-crop-panel/index.d.ts +6 -25
  171. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  172. package/build-types/components/media-editor-fine-rotation/index.d.ts +14 -0
  173. package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -0
  174. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  175. package/build-types/components/media-editor-transform-controls/index.d.ts +8 -0
  176. package/build-types/components/media-editor-transform-controls/index.d.ts.map +1 -0
  177. package/build-types/components/media-form/index.d.ts.map +1 -1
  178. package/build-types/components/media-form/sidebar-datetime-view.d.ts +10 -0
  179. package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +1 -0
  180. package/build-types/components/rotation-ruler/index.d.ts.map +1 -1
  181. package/build-types/hooks/use-crop-gesture-handlers.d.ts +13 -14
  182. package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -1
  183. package/build-types/image-editor/core/camera.d.ts.map +1 -1
  184. package/build-types/image-editor/core/constants.d.ts +18 -0
  185. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  186. package/build-types/image-editor/core/containment.d.ts +10 -0
  187. package/build-types/image-editor/core/containment.d.ts.map +1 -1
  188. package/build-types/image-editor/core/crop-rect.d.ts +19 -0
  189. package/build-types/image-editor/core/crop-rect.d.ts.map +1 -0
  190. package/build-types/image-editor/core/index.d.ts +3 -1
  191. package/build-types/image-editor/core/index.d.ts.map +1 -1
  192. package/build-types/image-editor/core/interaction-controller.d.ts +5 -1
  193. package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
  194. package/build-types/image-editor/core/math/sanitize.d.ts +70 -0
  195. package/build-types/image-editor/core/math/sanitize.d.ts.map +1 -0
  196. package/build-types/image-editor/core/setter-helpers.d.ts +24 -0
  197. package/build-types/image-editor/core/setter-helpers.d.ts.map +1 -0
  198. package/build-types/image-editor/core/source-region.d.ts.map +1 -1
  199. package/build-types/image-editor/core/state.d.ts +12 -0
  200. package/build-types/image-editor/core/state.d.ts.map +1 -1
  201. package/build-types/image-editor/core/stencil-math.d.ts +23 -18
  202. package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
  203. package/build-types/image-editor/core/transform-style.d.ts.map +1 -1
  204. package/build-types/image-editor/core/types.d.ts +23 -4
  205. package/build-types/image-editor/core/types.d.ts.map +1 -1
  206. package/build-types/image-editor/index.d.ts +4 -4
  207. package/build-types/image-editor/index.d.ts.map +1 -1
  208. package/build-types/image-editor/react/components/cropper-provider.d.ts +11 -7
  209. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  210. package/build-types/image-editor/react/components/cropper.d.ts +6 -4
  211. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  212. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +36 -0
  213. package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +1 -0
  214. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +2 -1
  215. package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
  216. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +47 -0
  217. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +1 -0
  218. package/build-types/image-editor/react/hooks/index.d.ts +4 -2
  219. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  220. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts +58 -0
  221. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +1 -0
  222. package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
  223. package/build-types/state/composite-reducer.d.ts +39 -0
  224. package/build-types/state/composite-reducer.d.ts.map +1 -0
  225. package/build-types/state/index.d.ts +7 -0
  226. package/build-types/state/index.d.ts.map +1 -0
  227. package/build-types/state/media-editor-state-provider.d.ts +34 -0
  228. package/build-types/state/media-editor-state-provider.d.ts.map +1 -0
  229. package/build-types/state/types.d.ts +96 -0
  230. package/build-types/state/types.d.ts.map +1 -0
  231. package/build-types/state/use-media-editor-state.d.ts +101 -0
  232. package/build-types/state/use-media-editor-state.d.ts.map +1 -0
  233. package/build-types/store/actions.d.ts +3 -1
  234. package/build-types/store/actions.d.ts.map +1 -1
  235. package/build-types/store/reducer.d.ts +3 -0
  236. package/build-types/store/reducer.d.ts.map +1 -1
  237. package/build-types/store/selectors.d.ts +1 -0
  238. package/build-types/store/selectors.d.ts.map +1 -1
  239. package/package.json +19 -16
  240. package/src/components/media-editor/index.tsx +262 -229
  241. package/src/components/media-editor/style.scss +0 -9
  242. package/src/components/media-editor/test/use-crop-options.tsx +110 -0
  243. package/src/components/media-editor/use-crop-options.ts +79 -0
  244. package/src/components/media-editor/use-save-media-editor.ts +214 -0
  245. package/src/components/media-editor-canvas/index.tsx +57 -25
  246. package/src/components/media-editor-crop-panel/index.tsx +53 -87
  247. package/src/components/media-editor-crop-panel/test/index.tsx +46 -53
  248. package/src/components/media-editor-fine-rotation/index.tsx +74 -0
  249. package/src/components/media-editor-modal/index.tsx +70 -16
  250. package/src/components/media-editor-modal/style.scss +80 -0
  251. package/src/components/media-editor-modal/test/build-modifiers.test.ts +14 -0
  252. package/src/components/media-editor-modal/test/index.tsx +146 -0
  253. package/src/components/media-editor-transform-controls/index.tsx +70 -0
  254. package/src/components/media-editor-transform-controls/style.scss +8 -0
  255. package/src/components/media-form/index.tsx +15 -1
  256. package/src/components/media-form/sidebar-datetime-view.tsx +47 -0
  257. package/src/components/media-form/test/sidebar-datetime-view.test.tsx +96 -0
  258. package/src/components/rotation-ruler/README.md +11 -25
  259. package/src/components/rotation-ruler/index.tsx +17 -2
  260. package/src/components/rotation-ruler/style.scss +49 -13
  261. package/src/hooks/use-crop-gesture-handlers.ts +64 -17
  262. package/src/image-editor/README.md +28 -129
  263. package/src/image-editor/core/camera.ts +51 -26
  264. package/src/image-editor/core/constants.ts +19 -0
  265. package/src/image-editor/core/containment.ts +102 -49
  266. package/src/image-editor/core/crop-rect.ts +45 -0
  267. package/src/image-editor/core/index.ts +16 -4
  268. package/src/image-editor/core/interaction-controller.ts +5 -1
  269. package/src/image-editor/core/math/sanitize.ts +158 -0
  270. package/src/image-editor/core/math/test/sanitize.ts +244 -0
  271. package/src/image-editor/core/setter-helpers.ts +66 -0
  272. package/src/image-editor/core/source-region.ts +21 -14
  273. package/src/image-editor/core/state.ts +67 -15
  274. package/src/image-editor/core/stencil-math.ts +55 -35
  275. package/src/image-editor/core/test/camera.ts +367 -1
  276. package/src/image-editor/core/test/state.ts +101 -8
  277. package/src/image-editor/core/test/stencil-math.ts +193 -0
  278. package/src/image-editor/core/transform-style.ts +21 -6
  279. package/src/image-editor/core/types.ts +24 -4
  280. package/src/image-editor/docs/architecture.md +48 -89
  281. package/src/image-editor/docs/recipes.md +123 -659
  282. package/src/image-editor/index.ts +12 -3
  283. package/src/image-editor/react/components/cropper-provider.tsx +16 -12
  284. package/src/image-editor/react/components/cropper.scss +23 -4
  285. package/src/image-editor/react/components/cropper.tsx +194 -89
  286. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +269 -0
  287. package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +19 -8
  288. package/src/image-editor/react/components/test/cropper.tsx +55 -13
  289. package/src/image-editor/react/hooks/build-cropper-setters.ts +105 -0
  290. package/src/image-editor/react/hooks/index.ts +4 -2
  291. package/src/image-editor/react/hooks/test/{use-cropper-state.ts → use-cropper-reducer.ts} +142 -286
  292. package/src/image-editor/react/hooks/use-cropper-reducer.ts +204 -0
  293. package/src/image-editor/stories/rectangle-crop.story.tsx +7 -17
  294. package/src/state/composite-reducer.ts +137 -0
  295. package/src/state/index.ts +20 -0
  296. package/src/state/media-editor-state-provider.tsx +70 -0
  297. package/src/state/test/use-media-editor-state.ts +330 -0
  298. package/src/state/types.ts +101 -0
  299. package/src/state/use-media-editor-state.ts +472 -0
  300. package/src/store/actions.ts +3 -0
  301. package/src/store/reducer.ts +6 -1
  302. package/src/store/selectors.ts +4 -0
  303. package/src/store/test/reducer.ts +9 -0
  304. package/src/style.scss +1 -1
  305. package/tsconfig.json +3 -0
  306. package/tsconfig.tsbuildinfo +1 -1
  307. package/build/components/media-editor-toolbar/index.cjs +0 -214
  308. package/build/components/media-editor-toolbar/index.cjs.map +0 -7
  309. package/build/image-editor/react/hooks/use-cropper-state.cjs +0 -277
  310. package/build/image-editor/react/hooks/use-cropper-state.cjs.map +0 -7
  311. package/build-module/components/media-editor-toolbar/index.mjs +0 -190
  312. package/build-module/components/media-editor-toolbar/index.mjs.map +0 -7
  313. package/build-module/image-editor/react/hooks/use-cropper-state.mjs +0 -262
  314. package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +0 -7
  315. package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
  316. package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
  317. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -97
  318. package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
  319. package/src/components/media-editor-toolbar/index.tsx +0 -209
  320. package/src/components/media-editor-toolbar/style.scss +0 -49
  321. package/src/image-editor/docs/roadmap.md +0 -66
  322. package/src/image-editor/react/hooks/use-cropper-state.ts +0 -457
@@ -1,214 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // packages/media-editor/src/components/media-editor-toolbar/index.tsx
31
- var media_editor_toolbar_exports = {};
32
- __export(media_editor_toolbar_exports, {
33
- default: () => MediaEditorToolbar
34
- });
35
- module.exports = __toCommonJS(media_editor_toolbar_exports);
36
- var import_components = require("@wordpress/components");
37
- var import_ui = require("@wordpress/ui");
38
- var import_i18n = require("@wordpress/i18n");
39
- var import_keycodes = require("@wordpress/keycodes");
40
- var import_icons = require("@wordpress/icons");
41
- var import_image_editor = require("../../image-editor/index.cjs");
42
- var import_use_crop_gesture_handlers = require("../../hooks/use-crop-gesture-handlers.cjs");
43
- var import_constants = require("../../image-editor/core/constants.cjs");
44
- var import_rotation_ruler = __toESM(require("../rotation-ruler/index.cjs"));
45
- var import_jsx_runtime = require("react/jsx-runtime");
46
- function MediaEditorToolbar({
47
- onReset,
48
- onPlacementControlInteraction,
49
- isUndoRedoDisabled = false
50
- }) {
51
- const {
52
- state,
53
- setRotation,
54
- setFlip,
55
- snapRotate90,
56
- reset,
57
- isDirty,
58
- hasUndo,
59
- hasRedo,
60
- undo: undoCrop,
61
- redo: redoCrop
62
- } = (0, import_image_editor.useCropper)();
63
- const rotationGestureHandlers = (0, import_use_crop_gesture_handlers.useCropGestureHandlers)({
64
- commitOnKeyUp: false
65
- });
66
- const handleReset = () => {
67
- reset();
68
- onReset?.();
69
- };
70
- const handleUndo = () => {
71
- if (isUndoRedoDisabled) {
72
- return;
73
- }
74
- undoCrop();
75
- };
76
- const handleRedo = () => {
77
- if (isUndoRedoDisabled) {
78
- return;
79
- }
80
- redoCrop();
81
- };
82
- const baseAngle = Math.round(state.rotation / 90) * 90;
83
- const singleFlip = state.flip.horizontal !== state.flip.vertical;
84
- const visualDir = singleFlip ? -1 : 1;
85
- const fineOffset = (state.rotation - baseAngle) * visualDir;
86
- const handleRotationSlider = (value) => {
87
- const EPS = 0.01;
88
- const clamped = Math.max(
89
- -import_constants.MAX_ROTATION_OFFSET + EPS,
90
- Math.min(import_constants.MAX_ROTATION_OFFSET - EPS, value)
91
- );
92
- onPlacementControlInteraction?.();
93
- setRotation(baseAngle + clamped * visualDir);
94
- };
95
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
96
- import_ui.Stack,
97
- {
98
- className: "media-editor-toolbar",
99
- direction: "row",
100
- align: "center",
101
- justify: "center",
102
- gap: "sm",
103
- wrap: "wrap",
104
- children: [
105
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
106
- "div",
107
- {
108
- role: "presentation",
109
- className: "media-editor-toolbar__rotation-slider",
110
- ...rotationGestureHandlers,
111
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
112
- import_rotation_ruler.default,
113
- {
114
- label: (0, import_i18n.__)("Fine rotation"),
115
- min: -import_constants.MAX_ROTATION_OFFSET,
116
- max: import_constants.MAX_ROTATION_OFFSET,
117
- value: fineOffset,
118
- onChange: handleRotationSlider
119
- }
120
- )
121
- }
122
- ),
123
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "media-editor-toolbar__action-cluster", children: [
124
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
- import_components.Button,
126
- {
127
- size: "compact",
128
- icon: import_icons.rotateLeft,
129
- label: (0, import_i18n.__)("Rotate 90\xB0 counter-clockwise"),
130
- showTooltip: true,
131
- onClick: () => snapRotate90(-1)
132
- }
133
- ),
134
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
135
- import_components.Button,
136
- {
137
- size: "compact",
138
- icon: import_icons.rotateRight,
139
- label: (0, import_i18n.__)("Rotate 90\xB0 clockwise"),
140
- showTooltip: true,
141
- onClick: () => snapRotate90(1)
142
- }
143
- ),
144
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
145
- import_components.Button,
146
- {
147
- size: "compact",
148
- icon: import_icons.flipHorizontal,
149
- label: (0, import_i18n.__)("Flip horizontal"),
150
- showTooltip: true,
151
- isPressed: state.flip.horizontal,
152
- onClick: () => setFlip({
153
- horizontal: !state.flip.horizontal,
154
- vertical: state.flip.vertical
155
- })
156
- }
157
- ),
158
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
159
- import_components.Button,
160
- {
161
- size: "compact",
162
- icon: import_icons.flipVertical,
163
- label: (0, import_i18n.__)("Flip vertical"),
164
- showTooltip: true,
165
- isPressed: state.flip.vertical,
166
- onClick: () => setFlip({
167
- horizontal: state.flip.horizontal,
168
- vertical: !state.flip.vertical
169
- })
170
- }
171
- ),
172
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
173
- import_components.Button,
174
- {
175
- size: "compact",
176
- icon: import_icons.undo,
177
- label: (0, import_i18n.__)("Undo"),
178
- showTooltip: true,
179
- shortcut: import_keycodes.displayShortcut.primary("z"),
180
- disabled: isUndoRedoDisabled || !hasUndo,
181
- accessibleWhenDisabled: true,
182
- onClick: handleUndo
183
- }
184
- ),
185
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
- import_components.Button,
187
- {
188
- size: "compact",
189
- icon: import_icons.redo,
190
- label: (0, import_i18n.__)("Redo"),
191
- showTooltip: true,
192
- shortcut: (0, import_keycodes.isAppleOS)() ? import_keycodes.displayShortcut.primaryShift("z") : import_keycodes.displayShortcut.primary("y"),
193
- disabled: isUndoRedoDisabled || !hasRedo,
194
- accessibleWhenDisabled: true,
195
- onClick: handleRedo
196
- }
197
- ),
198
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
199
- import_components.Button,
200
- {
201
- size: "compact",
202
- variant: "tertiary",
203
- disabled: !isDirty,
204
- accessibleWhenDisabled: true,
205
- onClick: handleReset,
206
- children: (0, import_i18n.__)("Reset")
207
- }
208
- )
209
- ] })
210
- ]
211
- }
212
- );
213
- }
214
- //# sourceMappingURL=index.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-editor-toolbar/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport { displayShortcut, isAppleOS } from '@wordpress/keycodes';\nimport {\n\trotateLeft,\n\trotateRight,\n\tflipHorizontal,\n\tflipVertical,\n\tundo,\n\tredo,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useCropper } from '../../image-editor';\nimport { useCropGestureHandlers } from '../../hooks/use-crop-gesture-handlers';\nimport { MAX_ROTATION_OFFSET } from '../../image-editor/core/constants';\nimport RotationRuler from '../rotation-ruler';\n\nexport interface MediaEditorToolbarProps {\n\t/**\n\t * Extra work to run when the user clicks Reset \u2014 e.g. clearing\n\t * aspect-ratio / freeform state that lives outside the cropper\n\t * controller.\n\t */\n\tonReset?: () => void;\n\t/** Signal that a placement-oriented control is being adjusted. */\n\tonPlacementControlInteraction?: () => void;\n\t/** Whether undo/redo should be unavailable during an active gesture. */\n\tisUndoRedoDisabled?: boolean;\n}\n\n/**\n * Toolbar for the media editor modal. Hosts the tactile cropper verbs \u2014\n * rotate, flip, fine rotation, reset \u2014 so they stay within thumb reach\n * when the toolbar sits at the bottom of the modal. Aspect-ratio presets\n * and freeform toggle live in the Crop sidebar tab instead.\n * @param props\n * @param props.onReset\n * @param props.onPlacementControlInteraction\n * @param props.isUndoRedoDisabled\n */\nexport default function MediaEditorToolbar( {\n\tonReset,\n\tonPlacementControlInteraction,\n\tisUndoRedoDisabled = false,\n}: MediaEditorToolbarProps ) {\n\tconst {\n\t\tstate,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\tsnapRotate90,\n\t\treset,\n\t\tisDirty,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo: undoCrop,\n\t\tredo: redoCrop,\n\t} = useCropper();\n\t// `commitOnKeyUp: false` keeps rapid arrow-key adjustments coalesced\n\t// into a single undo entry by the state-change debounce. Pointer-up\n\t// still commits immediately so each drag is its own undo step.\n\tconst rotationGestureHandlers = useCropGestureHandlers( {\n\t\tcommitOnKeyUp: false,\n\t} );\n\n\tconst handleReset = () => {\n\t\treset();\n\t\tonReset?.();\n\t};\n\tconst handleUndo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tundoCrop();\n\t};\n\tconst handleRedo = () => {\n\t\tif ( isUndoRedoDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tredoCrop();\n\t};\n\n\t// `setRotation` is an absolute-angle setter. When a single flip is active\n\t// the visual direction inverts, so slider input must flip sign to match\n\t// what the user sees. `snapRotate90` already handles this internally.\n\tconst baseAngle = Math.round( state.rotation / 90 ) * 90;\n\tconst singleFlip = state.flip.horizontal !== state.flip.vertical;\n\tconst visualDir = singleFlip ? -1 : 1;\n\tconst fineOffset = ( state.rotation - baseAngle ) * visualDir;\n\n\tconst handleRotationSlider = ( value: number ) => {\n\t\t// Clamp strictly inside [-MAX, MAX). Exactly \u00B1MAX lands state on a\n\t\t// 90\u00B0 midpoint and flips the derived baseAngle on the next render,\n\t\t// causing subsequent events to spiral.\n\t\tconst EPS = 0.01;\n\t\tconst clamped = Math.max(\n\t\t\t-MAX_ROTATION_OFFSET + EPS,\n\t\t\tMath.min( MAX_ROTATION_OFFSET - EPS, value )\n\t\t);\n\t\tonPlacementControlInteraction?.();\n\t\tsetRotation( baseAngle + clamped * visualDir );\n\t};\n\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"media-editor-toolbar\"\n\t\t\tdirection=\"row\"\n\t\t\talign=\"center\"\n\t\t\tjustify=\"center\"\n\t\t\tgap=\"sm\"\n\t\t\twrap=\"wrap\"\n\t\t>\n\t\t\t<div\n\t\t\t\trole=\"presentation\"\n\t\t\t\tclassName=\"media-editor-toolbar__rotation-slider\"\n\t\t\t\t{ ...rotationGestureHandlers }\n\t\t\t>\n\t\t\t\t<RotationRuler\n\t\t\t\t\tlabel={ __( 'Fine rotation' ) }\n\t\t\t\t\tmin={ -MAX_ROTATION_OFFSET }\n\t\t\t\t\tmax={ MAX_ROTATION_OFFSET }\n\t\t\t\t\tvalue={ fineOffset }\n\t\t\t\t\tonChange={ handleRotationSlider }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"media-editor-toolbar__action-cluster\">\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateLeft }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 counter-clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( -1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ rotateRight }\n\t\t\t\t\tlabel={ __( 'Rotate 90\u00B0 clockwise' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tonClick={ () => snapRotate90( 1 ) }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipHorizontal }\n\t\t\t\t\tlabel={ __( 'Flip horizontal' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.horizontal }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: ! state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ flipVertical }\n\t\t\t\t\tlabel={ __( 'Flip vertical' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tisPressed={ state.flip.vertical }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tsetFlip( {\n\t\t\t\t\t\t\thorizontal: state.flip.horizontal,\n\t\t\t\t\t\t\tvertical: ! state.flip.vertical,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ undo }\n\t\t\t\t\tlabel={ __( 'Undo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={ displayShortcut.primary( 'z' ) }\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasUndo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleUndo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ redo }\n\t\t\t\t\tlabel={ __( 'Redo' ) }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\tshortcut={\n\t\t\t\t\t\tisAppleOS()\n\t\t\t\t\t\t\t? displayShortcut.primaryShift( 'z' )\n\t\t\t\t\t\t\t: displayShortcut.primary( 'y' )\n\t\t\t\t\t}\n\t\t\t\t\tdisabled={ isUndoRedoDisabled || ! hasRedo }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleRedo }\n\t\t\t\t/>\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! isDirty }\n\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\tonClick={ handleReset }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t</Stack>\n\t);\n}\n"],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AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,WAAQ,gBAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,UAAW,gCAAgB,QAAS,GAAI;AAAA,cACxC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,MAAO;AAAA,cACP,WAAQ,gBAAI,MAAO;AAAA,cACnB,aAAW;AAAA,cACX,cACC,2BAAU,IACP,gCAAgB,aAAc,GAAI,IAClC,gCAAgB,QAAS,GAAI;AAAA,cAEjC,UAAW,sBAAsB,CAAE;AAAA,cACnC,wBAAsB;AAAA,cACtB,SAAU;AAAA;AAAA,UACX;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,MAAK;AAAA,cACL,SAAQ;AAAA,cACR,UAAW,CAAE;AAAA,cACb,wBAAsB;AAAA,cACtB,SAAU;AAAA,cAER,8BAAI,OAAQ;AAAA;AAAA,UACf;AAAA,WACD;AAAA;AAAA;AAAA,EACD;AAEF;",
6
- "names": ["RotationRuler"]
7
- }
@@ -1,277 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-editor/src/image-editor/react/hooks/use-cropper-state.ts
21
- var use_cropper_state_exports = {};
22
- __export(use_cropper_state_exports, {
23
- useCropperState: () => useCropperState
24
- });
25
- module.exports = __toCommonJS(use_cropper_state_exports);
26
- var import_element = require("@wordpress/element");
27
- var import_constants = require("../../core/constants.cjs");
28
- var import_canvas_renderer = require("../../core/export/canvas-renderer.cjs");
29
- var import_state = require("../../core/state.cjs");
30
- var HISTORY_DEBOUNCE_MS = 300;
31
- var HISTORY_EPSILON = 1e-6;
32
- function nearlyEqual(a, b) {
33
- return Math.abs(a - b) < HISTORY_EPSILON;
34
- }
35
- function areHistoryStatesEqual(a, b) {
36
- const aImage = a.image;
37
- const bImage = b.image;
38
- return aImage?.src === bImage?.src && aImage?.naturalWidth === bImage?.naturalWidth && aImage?.naturalHeight === bImage?.naturalHeight && nearlyEqual(a.pan.x, b.pan.x) && nearlyEqual(a.pan.y, b.pan.y) && nearlyEqual(a.zoom, b.zoom) && nearlyEqual(a.rotation, b.rotation) && a.flip.horizontal === b.flip.horizontal && a.flip.vertical === b.flip.vertical && nearlyEqual(a.cropRect.x, b.cropRect.x) && nearlyEqual(a.cropRect.y, b.cropRect.y) && nearlyEqual(a.cropRect.width, b.cropRect.width) && nearlyEqual(a.cropRect.height, b.cropRect.height);
39
- }
40
- function useCropperState(initialState) {
41
- const [state, dispatch] = (0, import_element.useReducer)(
42
- import_state.cropperReducer,
43
- initialState,
44
- (init) => (0, import_state.enforceContainment)({ ...import_constants.DEFAULT_STATE, ...init })
45
- );
46
- const initialRef = (0, import_element.useRef)(
47
- (0, import_state.enforceContainment)({ ...import_constants.DEFAULT_STATE, ...initialState })
48
- );
49
- const stateRef = (0, import_element.useRef)(state);
50
- stateRef.current = state;
51
- const historyRef = (0, import_element.useRef)([]);
52
- const redoStackRef = (0, import_element.useRef)([]);
53
- const [hasUndo, setHasUndo] = (0, import_element.useState)(false);
54
- const [hasRedo, setHasRedo] = (0, import_element.useState)(false);
55
- const lastCommittedStateRef = (0, import_element.useRef)(state);
56
- const debounceTimerRef = (0, import_element.useRef)();
57
- const suppressDebounceRef = (0, import_element.useRef)(false);
58
- const pushToHistory = (0, import_element.useCallback)((entry) => {
59
- const target = entry ?? stateRef.current;
60
- const previousEntry = historyRef.current[historyRef.current.length - 1];
61
- if (previousEntry && areHistoryStatesEqual(previousEntry, target)) {
62
- return;
63
- }
64
- historyRef.current = [...historyRef.current, target];
65
- redoStackRef.current = [];
66
- setHasUndo(true);
67
- setHasRedo(false);
68
- }, []);
69
- (0, import_element.useEffect)(() => {
70
- if (suppressDebounceRef.current) {
71
- suppressDebounceRef.current = false;
72
- lastCommittedStateRef.current = stateRef.current;
73
- return;
74
- }
75
- if (lastCommittedStateRef.current !== null && areHistoryStatesEqual(
76
- lastCommittedStateRef.current,
77
- stateRef.current
78
- )) {
79
- lastCommittedStateRef.current = stateRef.current;
80
- return;
81
- }
82
- clearTimeout(debounceTimerRef.current);
83
- debounceTimerRef.current = setTimeout(() => {
84
- const snapshot = lastCommittedStateRef.current;
85
- if (snapshot !== null && !areHistoryStatesEqual(snapshot, stateRef.current)) {
86
- pushToHistory(snapshot);
87
- }
88
- lastCommittedStateRef.current = stateRef.current;
89
- }, HISTORY_DEBOUNCE_MS);
90
- return () => clearTimeout(debounceTimerRef.current);
91
- }, [state, pushToHistory]);
92
- const commitHistory = (0, import_element.useCallback)(() => {
93
- clearTimeout(debounceTimerRef.current);
94
- const snapshot = lastCommittedStateRef.current;
95
- if (snapshot !== null && !areHistoryStatesEqual(snapshot, stateRef.current)) {
96
- pushToHistory(snapshot);
97
- }
98
- lastCommittedStateRef.current = stateRef.current;
99
- }, [pushToHistory]);
100
- const undo = (0, import_element.useCallback)(() => {
101
- commitHistory();
102
- const prev = historyRef.current[historyRef.current.length - 1];
103
- if (!prev) {
104
- return;
105
- }
106
- redoStackRef.current = [stateRef.current, ...redoStackRef.current];
107
- historyRef.current = historyRef.current.slice(0, -1);
108
- suppressDebounceRef.current = true;
109
- setHasUndo(historyRef.current.length > 0);
110
- setHasRedo(true);
111
- dispatch({ type: "RESET", payload: prev });
112
- }, [dispatch, commitHistory]);
113
- const redo = (0, import_element.useCallback)(() => {
114
- commitHistory();
115
- const next = redoStackRef.current[0];
116
- if (!next) {
117
- return;
118
- }
119
- historyRef.current = [...historyRef.current, stateRef.current];
120
- redoStackRef.current = redoStackRef.current.slice(1);
121
- suppressDebounceRef.current = true;
122
- setHasUndo(true);
123
- setHasRedo(redoStackRef.current.length > 0);
124
- dispatch({ type: "RESET", payload: next });
125
- }, [dispatch, commitHistory]);
126
- const setImage = (0, import_element.useCallback)(
127
- (image) => {
128
- clearTimeout(debounceTimerRef.current);
129
- suppressDebounceRef.current = true;
130
- dispatch({ type: "SET_IMAGE", payload: image });
131
- initialRef.current = (0, import_state.enforceContainment)({
132
- ...initialRef.current,
133
- image
134
- });
135
- },
136
- [dispatch]
137
- );
138
- const setPan = (0, import_element.useCallback)(
139
- (pan) => {
140
- dispatch({ type: "SET_PAN", payload: pan });
141
- },
142
- [dispatch]
143
- );
144
- const setZoom = (0, import_element.useCallback)(
145
- (zoom) => {
146
- dispatch({ type: "SET_ZOOM", payload: zoom });
147
- },
148
- [dispatch]
149
- );
150
- const setZoomAtPoint = (0, import_element.useCallback)(
151
- (zoom, pan) => {
152
- dispatch({
153
- type: "SET_ZOOM_AT_POINT",
154
- payload: { zoom, pan }
155
- });
156
- },
157
- [dispatch]
158
- );
159
- const setRotation = (0, import_element.useCallback)(
160
- (rotation) => {
161
- dispatch({ type: "SET_ROTATION", payload: rotation });
162
- },
163
- [dispatch]
164
- );
165
- const setFlip = (0, import_element.useCallback)(
166
- (flip) => {
167
- commitHistory();
168
- pushToHistory();
169
- suppressDebounceRef.current = true;
170
- dispatch({ type: "SET_FLIP", payload: flip });
171
- },
172
- [dispatch, pushToHistory, commitHistory]
173
- );
174
- const toggleFlip = (0, import_element.useCallback)(
175
- (direction) => {
176
- setFlip({
177
- ...stateRef.current.flip,
178
- [direction]: !stateRef.current.flip[direction]
179
- });
180
- },
181
- [setFlip]
182
- );
183
- const snapRotate90 = (0, import_element.useCallback)(
184
- (direction) => {
185
- commitHistory();
186
- pushToHistory();
187
- suppressDebounceRef.current = true;
188
- dispatch({
189
- type: "SNAP_ROTATE_90",
190
- payload: { direction }
191
- });
192
- },
193
- [dispatch, pushToHistory, commitHistory]
194
- );
195
- const setCropRect = (0, import_element.useCallback)(
196
- (rect) => {
197
- dispatch({ type: "SET_CROP_RECT", payload: rect });
198
- },
199
- [dispatch]
200
- );
201
- const settleCrop = (0, import_element.useCallback)(() => {
202
- commitHistory();
203
- suppressDebounceRef.current = true;
204
- dispatch({ type: "SETTLE_CROP" });
205
- }, [dispatch, commitHistory]);
206
- const applyOperation = (0, import_element.useCallback)(
207
- (op) => {
208
- commitHistory();
209
- pushToHistory();
210
- suppressDebounceRef.current = true;
211
- dispatch({ type: "APPLY_OPERATION", payload: op });
212
- },
213
- [dispatch, pushToHistory, commitHistory]
214
- );
215
- const reset = (0, import_element.useCallback)(
216
- (resetState) => {
217
- commitHistory();
218
- const nextInitialState = (0, import_state.enforceContainment)({
219
- ...import_constants.DEFAULT_STATE,
220
- image: stateRef.current.image,
221
- ...resetState
222
- });
223
- if (!areHistoryStatesEqual(stateRef.current, nextInitialState)) {
224
- pushToHistory();
225
- }
226
- suppressDebounceRef.current = true;
227
- dispatch({ type: "RESET", payload: resetState });
228
- initialRef.current = nextInitialState;
229
- },
230
- [dispatch, pushToHistory, commitHistory]
231
- );
232
- const isDirty = (0, import_state.isStateDirty)(state, initialRef.current);
233
- const getCroppedImage = (0, import_element.useCallback)(
234
- (mimeType, quality) => {
235
- if (!state.image) {
236
- return Promise.reject(
237
- new Error("No image loaded \u2014 call setImage first.")
238
- );
239
- }
240
- return (0, import_canvas_renderer.exportCroppedImage)(
241
- state.image.src,
242
- state,
243
- mimeType,
244
- quality
245
- );
246
- },
247
- [state]
248
- );
249
- const controller = {
250
- state,
251
- setImage,
252
- setPan,
253
- setZoom,
254
- setZoomAtPoint,
255
- setRotation,
256
- setFlip,
257
- toggleFlip,
258
- snapRotate90,
259
- setCropRect,
260
- settleCrop,
261
- applyOperation,
262
- reset,
263
- isDirty,
264
- getCroppedImage,
265
- hasUndo,
266
- hasRedo,
267
- undo,
268
- redo,
269
- commitHistory
270
- };
271
- return controller;
272
- }
273
- // Annotate the CommonJS export names for ESM import in node:
274
- 0 && (module.exports = {
275
- useCropperState
276
- });
277
- //# sourceMappingURL=use-cropper-state.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/image-editor/react/hooks/use-cropper-state.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseReducer,\n\tuseCallback,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tTransformOperation,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tFlip,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\n\n/**\n * The return type of the useCropperState hook.\n *\n * The hook exposes its state through named setter methods rather\n * than a raw dispatch function. Each setter has a specific\n * behavioral contract (see individual JSDoc) that maps 1:1 to a\n * reducer action internally. Keeping the reducer actions private\n * lets the implementation evolve without breaking consumers.\n */\nexport interface UseCropperStateReturn {\n\t/** The current cropper state (read-only). */\n\tstate: CropperState;\n\t/** Set the loaded image (natural size and src). */\n\tsetImage: ( image: CropperState[ 'image' ] ) => void;\n\t/**\n\t * Set the image pan offset in normalized coordinates. Use\n\t * `setCropRect` for the crop rectangle.\n\t */\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\t/** Set the zoom level. Clamped to [1, 10]. */\n\tsetZoom: ( zoom: number ) => void;\n\t/** Set zoom and pan together so focal-point zoom remains atomic. */\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\t/** Set the rotation in degrees. Normalized to [0, 360). */\n\tsetRotation: ( rotation: number ) => void;\n\t/** Set the flip state. */\n\tsetFlip: ( flip: Flip ) => void;\n\t/** Toggle flip on the given axis. */\n\ttoggleFlip: ( direction: 'horizontal' | 'vertical' ) => void;\n\t/** Snap rotate 90\u00B0 preserving the image selection (Google Photos style). */\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\t/** Set the crop rectangle in normalized coordinates. */\n\tsetCropRect: ( rect: NormalizedRect ) => void;\n\t/**\n\t * Settle the crop rect after a resize drag: expand to fill the\n\t * available visual area while preserving the framed image region.\n\t * Typically called from a stencil's `onResizeEnd` callback.\n\t *\n\t * Flushes the pending resize history before dispatching, then suppresses\n\t * the settle dispatch itself so resizing and settling undo as one step.\n\t */\n\tsettleCrop: () => void;\n\t/** Apply a transform operation through the pipeline. */\n\tapplyOperation: ( op: TransformOperation ) => void;\n\t/** Reset the state. Optionally merge partial state overrides. */\n\treset: ( resetState?: Partial< CropperState > ) => void;\n\t/** Whether the current state differs from the initial state. */\n\tisDirty: boolean;\n\t/** Whether there is a cropper state to undo. */\n\thasUndo: boolean;\n\t/** Whether there is a cropper state to redo. */\n\thasRedo: boolean;\n\t/** Undo the last committed cropper operation. */\n\tundo: () => void;\n\t/** Redo the last undone cropper operation. */\n\tredo: () => void;\n\t/**\n\t * Flush the pending history entry immediately, bypassing the debounce\n\t * timer. Useful in two situations:\n\t *\n\t * - **Pointer-up / key-up**: commit as soon as the user releases so the\n\t * undo button lights up without waiting for the debounce window.\n\t * - **Gesture start**: pass to `onGestureStart` on the `Cropper` so any\n\t * pending sidebar interaction is committed before a new canvas gesture\n\t * begins, keeping the two interactions as separate undo steps.\n\t */\n\tcommitHistory: () => void;\n\t/**\n\t * Export the cropped image as a Blob. Throws on failure \u2014 see\n\t * `exportCroppedImage` in core for the error semantics (image\n\t * load errors, CORS taint, missing canvas context). Wrap in\n\t * try/catch if you need to recover.\n\t */\n\tgetCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;\n}\n\n/** Milliseconds of inactivity after which a continuous interaction is committed to history. */\nconst HISTORY_DEBOUNCE_MS = 300;\n\n/** Small tolerance for cropper floating-point comparisons. */\nconst HISTORY_EPSILON = 1e-6;\n\nfunction nearlyEqual( a: number, b: number ): boolean {\n\treturn Math.abs( a - b ) < HISTORY_EPSILON;\n}\n\nfunction areHistoryStatesEqual( a: CropperState, b: CropperState ): boolean {\n\tconst aImage = a.image;\n\tconst bImage = b.image;\n\treturn (\n\t\taImage?.src === bImage?.src &&\n\t\taImage?.naturalWidth === bImage?.naturalWidth &&\n\t\taImage?.naturalHeight === bImage?.naturalHeight &&\n\t\tnearlyEqual( a.pan.x, b.pan.x ) &&\n\t\tnearlyEqual( a.pan.y, b.pan.y ) &&\n\t\tnearlyEqual( a.zoom, b.zoom ) &&\n\t\tnearlyEqual( a.rotation, b.rotation ) &&\n\t\ta.flip.horizontal === b.flip.horizontal &&\n\t\ta.flip.vertical === b.flip.vertical &&\n\t\tnearlyEqual( a.cropRect.x, b.cropRect.x ) &&\n\t\tnearlyEqual( a.cropRect.y, b.cropRect.y ) &&\n\t\tnearlyEqual( a.cropRect.width, b.cropRect.width ) &&\n\t\tnearlyEqual( a.cropRect.height, b.cropRect.height )\n\t);\n}\n\n/**\n * Reducer-based state management hook for the image editor.\n *\n * Provides the full cropper state and named setter methods for\n * every supported transition. The reducer and containment logic\n * live in core/state.ts (framework-agnostic); this hook is a thin\n * React wrapper around that pure reducer, with memoized callbacks.\n *\n * History is recorded via a state-change debounce: any state change\n * starts a 300 ms timer; when it fires the pre-change state is pushed\n * onto the undo stack. `commitHistory` flushes the timer immediately\n * (useful on pointer-up / key-up for a crisp commit feel).\n *\n * @param initialState Optional partial state to merge with DEFAULT_STATE.\n * @return The cropper state, setters, and utilities.\n */\nexport function useCropperState(\n\tinitialState?: Partial< CropperState >\n): UseCropperStateReturn {\n\tconst [ state, dispatch ] = useReducer(\n\t\tcropperReducer,\n\t\tinitialState,\n\t\t( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )\n\t);\n\n\tconst initialRef = useRef< CropperState >(\n\t\tenforceContainment( { ...DEFAULT_STATE, ...initialState } )\n\t);\n\t// Keep a ref to the latest state so callbacks with stable identity\n\t// (reset, setImage) can read fresh state without re-creating themselves.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\n\t// History stack for undo/redo. Using refs for the arrays avoids\n\t// unnecessary re-renders on every push; a pair of boolean state values\n\t// drives the enabled/disabled state of the undo/redo buttons.\n\tconst historyRef = useRef< CropperState[] >( [] );\n\tconst redoStackRef = useRef< CropperState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Debounce-based history: tracks the last committed state and a pending\n\t// timer. Any state change resets the timer; when it expires the\n\t// pre-change state is pushed to history.\n\tconst lastCommittedStateRef = useRef< CropperState | null >( state );\n\tconst debounceTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\t// Set to true before dispatching actions that must not produce a debounce\n\t// history entry (undo, redo, reset, setImage, discrete actions).\n\tconst suppressDebounceRef = useRef( false );\n\n\t// Pushes `entry` (defaults to current state) onto the undo stack and\n\t// clears the redo stack. Skips if `entry` is already the last item,\n\t// so rapid discrete actions on unchanged state don't create duplicates.\n\tconst pushToHistory = useCallback( ( entry?: CropperState ) => {\n\t\tconst target = entry ?? stateRef.current;\n\t\tconst previousEntry =\n\t\t\thistoryRef.current[ historyRef.current.length - 1 ];\n\t\tif ( previousEntry && areHistoryStatesEqual( previousEntry, target ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, target ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\t// Watch state and debounce history commits. Any dispatch resets the\n\t// timer; once the state has settled for HISTORY_DEBOUNCE_MS the\n\t// pre-change snapshot is pushed to the undo stack.\n\tuseEffect( () => {\n\t\t// Suppress flag: undo/redo/reset/setImage/discrete actions set this\n\t\t// to opt out of the debounce for their own state changes.\n\t\tif ( suppressDebounceRef.current ) {\n\t\t\tsuppressDebounceRef.current = false;\n\t\t\tlastCommittedStateRef.current = stateRef.current;\n\t\t\treturn;\n\t\t}\n\t\tif (\n\t\t\tlastCommittedStateRef.current !== null &&\n\t\t\tareHistoryStatesEqual(\n\t\t\t\tlastCommittedStateRef.current,\n\t\t\t\tstateRef.current\n\t\t\t)\n\t\t) {\n\t\t\tlastCommittedStateRef.current = stateRef.current;\n\t\t\treturn;\n\t\t}\n\t\tclearTimeout( debounceTimerRef.current );\n\t\tdebounceTimerRef.current = setTimeout( () => {\n\t\t\tconst snapshot = lastCommittedStateRef.current;\n\t\t\tif (\n\t\t\t\tsnapshot !== null &&\n\t\t\t\t! areHistoryStatesEqual( snapshot, stateRef.current )\n\t\t\t) {\n\t\t\t\tpushToHistory( snapshot );\n\t\t\t}\n\t\t\tlastCommittedStateRef.current = stateRef.current;\n\t\t}, HISTORY_DEBOUNCE_MS );\n\t\treturn () => clearTimeout( debounceTimerRef.current );\n\t}, [ state, pushToHistory ] );\n\n\t// Flush the pending debounce immediately: cancel the timer and push the\n\t// pre-change snapshot if the state has actually changed. Used by\n\t// pointer-up / key-up handlers for an instant commit feel, and by\n\t// undo/redo/discrete actions before recording their own history entry.\n\tconst commitHistory = useCallback( () => {\n\t\tclearTimeout( debounceTimerRef.current );\n\t\tconst snapshot = lastCommittedStateRef.current;\n\t\tif (\n\t\t\tsnapshot !== null &&\n\t\t\t! areHistoryStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushToHistory( snapshot );\n\t\t}\n\t\tlastCommittedStateRef.current = stateRef.current;\n\t}, [ pushToHistory ] );\n\n\tconst undo = useCallback( () => {\n\t\t// Flush any pending gesture so it becomes a distinct undo step\n\t\t// before we pop history. This ensures mid-gesture undo undoes the\n\t\t// pending change rather than silently discarding it.\n\t\tcommitHistory();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsuppressDebounceRef.current = true;\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tdispatch( { type: 'RESET', payload: prev } );\n\t}, [ dispatch, commitHistory ] );\n\n\tconst redo = useCallback( () => {\n\t\t// Flush any pending gesture before redoing so the in-flight change\n\t\t// is saved and the redo target lands on top of it.\n\t\tcommitHistory();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsuppressDebounceRef.current = true;\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tdispatch( { type: 'RESET', payload: next } );\n\t}, [ dispatch, commitHistory ] );\n\n\tconst setImage = useCallback(\n\t\t( image: CropperState[ 'image' ] ) => {\n\t\t\tclearTimeout( debounceTimerRef.current );\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'SET_IMAGE', payload: image } );\n\t\t\t// Refresh the \"clean\" snapshot to match the post-load state\n\t\t\t// produced by the reducer. Otherwise containment can nudge\n\t\t\t// pan/zoom by tiny amounts on load and `isDirty` would\n\t\t\t// report true from the start.\n\t\t\tinitialRef.current = enforceContainment( {\n\t\t\t\t...initialRef.current,\n\t\t\t\timage,\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setPan = useCallback(\n\t\t( pan: NormalizedPoint ) => {\n\t\t\tdispatch( { type: 'SET_PAN', payload: pan } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoom = useCallback(\n\t\t( zoom: number ) => {\n\t\t\tdispatch( { type: 'SET_ZOOM', payload: zoom } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setZoomAtPoint = useCallback(\n\t\t( zoom: number, pan: NormalizedPoint ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\t\t\tpayload: { zoom, pan },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setRotation = useCallback(\n\t\t( rotation: number ) => {\n\t\t\tdispatch( { type: 'SET_ROTATION', payload: rotation } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst setFlip = useCallback(\n\t\t( flip: Flip ) => {\n\t\t\tcommitHistory(); // flush any pending continuous gesture first\n\t\t\tpushToHistory(); // record current state as the undo point\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'SET_FLIP', payload: flip } );\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst toggleFlip = useCallback(\n\t\t( direction: 'horizontal' | 'vertical' ) => {\n\t\t\tsetFlip( {\n\t\t\t\t...stateRef.current.flip,\n\t\t\t\t[ direction ]: ! stateRef.current.flip[ direction ],\n\t\t\t} );\n\t\t},\n\t\t[ setFlip ]\n\t);\n\n\tconst snapRotate90 = useCallback(\n\t\t( direction: 1 | -1 ) => {\n\t\t\tcommitHistory();\n\t\t\tpushToHistory();\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SNAP_ROTATE_90',\n\t\t\t\tpayload: { direction },\n\t\t\t} );\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst setCropRect = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatch( { type: 'SET_CROP_RECT', payload: rect } );\n\t\t},\n\t\t[ dispatch ]\n\t);\n\n\tconst settleCrop = useCallback( () => {\n\t\tcommitHistory();\n\t\tsuppressDebounceRef.current = true;\n\t\tdispatch( { type: 'SETTLE_CROP' } );\n\t}, [ dispatch, commitHistory ] );\n\n\tconst applyOperation = useCallback(\n\t\t( op: TransformOperation ) => {\n\t\t\tcommitHistory();\n\t\t\tpushToHistory();\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'APPLY_OPERATION', payload: op } );\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tcommitHistory();\n\t\t\tconst nextInitialState = enforceContainment( {\n\t\t\t\t...DEFAULT_STATE,\n\t\t\t\timage: stateRef.current.image,\n\t\t\t\t...resetState,\n\t\t\t} );\n\t\t\tif (\n\t\t\t\t! areHistoryStatesEqual( stateRef.current, nextInitialState )\n\t\t\t) {\n\t\t\t\tpushToHistory();\n\t\t\t}\n\t\t\tsuppressDebounceRef.current = true;\n\t\t\tdispatch( { type: 'RESET', payload: resetState } );\n\t\t\t// Mirror the reducer's RESET exactly so isDirty stays in\n\t\t\t// sync. RESET preserves the currently-loaded image; the\n\t\t\t// containment step can tweak pan/zoom/cropRect by float ulp,\n\t\t\t// which we must fold into the \"initial\" snapshot or isDirty\n\t\t\t// would report true after a reset.\n\t\t\tinitialRef.current = nextInitialState;\n\t\t},\n\t\t[ dispatch, pushToHistory, commitHistory ]\n\t);\n\n\tconst isDirty = isStateDirty( state, initialRef.current );\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded \u2014 call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.image.src,\n\t\t\t\tstate,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state ]\n\t);\n\n\tconst controller: UseCropperStateReturn = {\n\t\tstate,\n\t\tsetImage,\n\t\tsetPan,\n\t\tsetZoom,\n\t\tsetZoomAtPoint,\n\t\tsetRotation,\n\t\tsetFlip,\n\t\ttoggleFlip,\n\t\tsnapRotate90,\n\t\tsetCropRect,\n\t\tsettleCrop,\n\t\tapplyOperation,\n\t\treset,\n\t\tisDirty,\n\t\tgetCroppedImage,\n\t\thasUndo,\n\t\thasRedo,\n\t\tundo,\n\t\tredo,\n\t\tcommitHistory,\n\t};\n\treturn controller;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAMO;AAYP,uBAA8B;AAC9B,6BAAmC;AACnC,mBAIO;AA+EP,IAAM,sBAAsB;AAG5B,IAAM,kBAAkB;AAExB,SAAS,YAAa,GAAW,GAAqB;AACrD,SAAO,KAAK,IAAK,IAAI,CAAE,IAAI;AAC5B;AAEA,SAAS,sBAAuB,GAAiB,GAA2B;AAC3E,QAAM,SAAS,EAAE;AACjB,QAAM,SAAS,EAAE;AACjB,SACC,QAAQ,QAAQ,QAAQ,OACxB,QAAQ,iBAAiB,QAAQ,gBACjC,QAAQ,kBAAkB,QAAQ,iBAClC,YAAa,EAAE,IAAI,GAAG,EAAE,IAAI,CAAE,KAC9B,YAAa,EAAE,IAAI,GAAG,EAAE,IAAI,CAAE,KAC9B,YAAa,EAAE,MAAM,EAAE,IAAK,KAC5B,YAAa,EAAE,UAAU,EAAE,QAAS,KACpC,EAAE,KAAK,eAAe,EAAE,KAAK,cAC7B,EAAE,KAAK,aAAa,EAAE,KAAK,YAC3B,YAAa,EAAE,SAAS,GAAG,EAAE,SAAS,CAAE,KACxC,YAAa,EAAE,SAAS,GAAG,EAAE,SAAS,CAAE,KACxC,YAAa,EAAE,SAAS,OAAO,EAAE,SAAS,KAAM,KAChD,YAAa,EAAE,SAAS,QAAQ,EAAE,SAAS,MAAO;AAEpD;AAkBO,SAAS,gBACf,cACwB;AACxB,QAAM,CAAE,OAAO,QAAS,QAAI;AAAA,IAC3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