@wordpress/media-editor 0.20.0 → 0.22.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 (386) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/build/components/media-editor/index.cjs +533 -695
  4. package/build/components/media-editor/index.cjs.map +1 -7
  5. package/build/components/media-editor/use-crop-options.cjs +43 -58
  6. package/build/components/media-editor/use-crop-options.cjs.map +1 -7
  7. package/build/components/media-editor/use-save-media-editor.cjs +111 -185
  8. package/build/components/media-editor/use-save-media-editor.cjs.map +1 -7
  9. package/build/components/media-editor-canvas/index.cjs +122 -124
  10. package/build/components/media-editor-canvas/index.cjs.map +1 -7
  11. package/build/components/media-editor-crop-panel/index.cjs +65 -68
  12. package/build/components/media-editor-crop-panel/index.cjs.map +1 -7
  13. package/build/components/media-editor-fine-rotation/index.cjs +62 -72
  14. package/build/components/media-editor-fine-rotation/index.cjs.map +1 -7
  15. package/build/components/media-editor-image-controls/index.cjs +183 -257
  16. package/build/components/media-editor-image-controls/index.cjs.map +1 -7
  17. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +119 -157
  18. package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -7
  19. package/build/components/media-editor-modal/build-modifiers.cjs +107 -88
  20. package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -7
  21. package/build/components/media-editor-modal/index.cjs +112 -153
  22. package/build/components/media-editor-modal/index.cjs.map +1 -7
  23. package/build/components/media-editor-provider/index.cjs +32 -54
  24. package/build/components/media-editor-provider/index.cjs.map +1 -7
  25. package/build/components/media-form/index.cjs +77 -78
  26. package/build/components/media-form/index.cjs.map +1 -7
  27. package/build/components/media-preview/index.cjs +114 -114
  28. package/build/components/media-preview/index.cjs.map +1 -7
  29. package/build/components/rotation-ruler/index.cjs +181 -188
  30. package/build/components/rotation-ruler/index.cjs.map +1 -7
  31. package/build/components/rotation-ruler/use-ruler-drag.cjs +132 -149
  32. package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -7
  33. package/build/hooks/use-crop-gesture-handlers.cjs +82 -76
  34. package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -7
  35. package/build/image-editor/core/camera.cjs +257 -205
  36. package/build/image-editor/core/camera.cjs.map +1 -7
  37. package/build/image-editor/core/constants.cjs +127 -102
  38. package/build/image-editor/core/constants.cjs.map +1 -7
  39. package/build/image-editor/core/containment.cjs +275 -262
  40. package/build/image-editor/core/containment.cjs.map +1 -7
  41. package/build/image-editor/core/crop-rect.cjs +33 -44
  42. package/build/image-editor/core/crop-rect.cjs.map +1 -7
  43. package/build/image-editor/core/export/canvas-renderer.cjs +165 -135
  44. package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -7
  45. package/build/image-editor/core/index.cjs +88 -61
  46. package/build/image-editor/core/interaction-controller.cjs +583 -646
  47. package/build/image-editor/core/interaction-controller.cjs.map +1 -7
  48. package/build/image-editor/core/math/rotation.cjs +26 -35
  49. package/build/image-editor/core/math/rotation.cjs.map +1 -7
  50. package/build/image-editor/core/math/sanitize.cjs +124 -80
  51. package/build/image-editor/core/math/sanitize.cjs.map +1 -7
  52. package/build/image-editor/core/setter-helpers.cjs +57 -60
  53. package/build/image-editor/core/setter-helpers.cjs.map +1 -7
  54. package/build/image-editor/core/source-region.cjs +220 -190
  55. package/build/image-editor/core/source-region.cjs.map +1 -7
  56. package/build/image-editor/core/state.cjs +278 -265
  57. package/build/image-editor/core/state.cjs.map +1 -7
  58. package/build/image-editor/core/stencil-math.cjs +193 -206
  59. package/build/image-editor/core/stencil-math.cjs.map +1 -7
  60. package/build/image-editor/core/transform-style.cjs +39 -48
  61. package/build/image-editor/core/transform-style.cjs.map +1 -7
  62. package/build/image-editor/core/transforms/pipeline.cjs +36 -38
  63. package/build/image-editor/core/transforms/pipeline.cjs.map +1 -7
  64. package/build/image-editor/core/types.cjs +4 -18
  65. package/build/image-editor/core/viewport-state.cjs +31 -45
  66. package/build/image-editor/core/viewport-state.cjs.map +1 -7
  67. package/build/image-editor/index.cjs +65 -64
  68. package/build/image-editor/react/components/cropper-provider.cjs +44 -45
  69. package/build/image-editor/react/components/cropper-provider.cjs.map +1 -7
  70. package/build/image-editor/react/components/cropper.cjs +583 -720
  71. package/build/image-editor/react/components/cropper.cjs.map +1 -7
  72. package/build/image-editor/react/components/index.cjs +22 -33
  73. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +135 -160
  74. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -7
  75. package/build/image-editor/react/components/overlays/dimming-overlay.cjs +28 -59
  76. package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +1 -7
  77. package/build/image-editor/react/components/overlays/grid-overlay.cjs +58 -88
  78. package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +1 -7
  79. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +361 -420
  80. package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +1 -7
  81. package/build/image-editor/react/components/viewport-provider.cjs +21 -46
  82. package/build/image-editor/react/components/viewport-provider.cjs.map +1 -7
  83. package/build/image-editor/react/hooks/build-cropper-setters.cjs +76 -67
  84. package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -7
  85. package/build/image-editor/react/hooks/index.cjs +16 -31
  86. package/build/image-editor/react/hooks/use-aria-announcer.cjs +90 -146
  87. package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +1 -7
  88. package/build/image-editor/react/hooks/use-cropper-controller.cjs +80 -0
  89. package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +1 -0
  90. package/build/image-editor/react/hooks/use-interaction.cjs +179 -205
  91. package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -7
  92. package/build/image-editor/react/hooks/use-transform-style.cjs +20 -34
  93. package/build/image-editor/react/hooks/use-transform-style.cjs.map +1 -7
  94. package/build/image-editor/react/hooks/use-viewport-state.cjs +36 -47
  95. package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -7
  96. package/build/image-editor/react/visually-hidden-style.cjs +21 -38
  97. package/build/image-editor/react/visually-hidden-style.cjs.map +1 -7
  98. package/build/index.cjs +45 -39
  99. package/build/lock-unlock.cjs +9 -35
  100. package/build/lock-unlock.cjs.map +1 -7
  101. package/build/private-apis.cjs +16 -37
  102. package/build/private-apis.cjs.map +1 -7
  103. package/build/state/aspect-ratio-presets.cjs +53 -0
  104. package/build/state/aspect-ratio-presets.cjs.map +1 -0
  105. package/build/state/composite-reducer.cjs +136 -89
  106. package/build/state/composite-reducer.cjs.map +1 -7
  107. package/build/state/index.cjs +63 -47
  108. package/build/state/media-editor-state-provider.cjs +35 -48
  109. package/build/state/media-editor-state-provider.cjs.map +1 -7
  110. package/build/state/types.cjs +12 -31
  111. package/build/state/types.cjs.map +1 -7
  112. package/build/state/use-media-editor-state.cjs +261 -281
  113. package/build/state/use-media-editor-state.cjs.map +1 -7
  114. package/build/store/actions.cjs +17 -44
  115. package/build/store/actions.cjs.map +1 -7
  116. package/build/store/constants.cjs +8 -29
  117. package/build/store/constants.cjs.map +1 -7
  118. package/build/store/index.cjs +33 -40
  119. package/build/store/index.cjs.map +1 -7
  120. package/build/store/reducer.cjs +28 -50
  121. package/build/store/reducer.cjs.map +1 -7
  122. package/build/store/selectors.cjs +16 -41
  123. package/build/store/selectors.cjs.map +1 -7
  124. package/build/utils/get-media-type.cjs +18 -41
  125. package/build/utils/get-media-type.cjs.map +1 -7
  126. package/build/utils/index.cjs +9 -28
  127. package/build-module/components/media-editor/index.mjs +490 -682
  128. package/build-module/components/media-editor/index.mjs.map +1 -7
  129. package/build-module/components/media-editor/use-crop-options.mjs +38 -33
  130. package/build-module/components/media-editor/use-crop-options.mjs.map +1 -7
  131. package/build-module/components/media-editor/use-save-media-editor.mjs +89 -157
  132. package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -7
  133. package/build-module/components/media-editor-canvas/index.mjs +97 -95
  134. package/build-module/components/media-editor-canvas/index.mjs.map +1 -7
  135. package/build-module/components/media-editor-crop-panel/index.mjs +44 -43
  136. package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -7
  137. package/build-module/components/media-editor-fine-rotation/index.mjs +39 -45
  138. package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -7
  139. package/build-module/components/media-editor-image-controls/index.mjs +172 -237
  140. package/build-module/components/media-editor-image-controls/index.mjs.map +1 -7
  141. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +112 -137
  142. package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -7
  143. package/build-module/components/media-editor-modal/build-modifiers.mjs +103 -64
  144. package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -7
  145. package/build-module/components/media-editor-modal/index.mjs +88 -122
  146. package/build-module/components/media-editor-modal/index.mjs.map +1 -7
  147. package/build-module/components/media-editor-provider/index.mjs +26 -28
  148. package/build-module/components/media-editor-provider/index.mjs.map +1 -7
  149. package/build-module/components/media-form/index.mjs +69 -54
  150. package/build-module/components/media-form/index.mjs.map +1 -7
  151. package/build-module/components/media-preview/index.mjs +105 -89
  152. package/build-module/components/media-preview/index.mjs.map +1 -7
  153. package/build-module/components/rotation-ruler/index.mjs +161 -164
  154. package/build-module/components/rotation-ruler/index.mjs.map +1 -7
  155. package/build-module/components/rotation-ruler/use-ruler-drag.mjs +125 -122
  156. package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -7
  157. package/build-module/hooks/use-crop-gesture-handlers.mjs +76 -50
  158. package/build-module/hooks/use-crop-gesture-handlers.mjs.map +1 -7
  159. package/build-module/image-editor/core/camera.mjs +245 -178
  160. package/build-module/image-editor/core/camera.mjs.map +1 -7
  161. package/build-module/image-editor/core/constants.mjs +110 -64
  162. package/build-module/image-editor/core/constants.mjs.map +1 -7
  163. package/build-module/image-editor/core/containment.mjs +265 -237
  164. package/build-module/image-editor/core/containment.mjs.map +1 -7
  165. package/build-module/image-editor/core/crop-rect.mjs +29 -20
  166. package/build-module/image-editor/core/crop-rect.mjs.map +1 -7
  167. package/build-module/image-editor/core/export/canvas-renderer.mjs +155 -105
  168. package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -7
  169. package/build-module/image-editor/core/index.mjs +5 -34
  170. package/build-module/image-editor/core/interaction-controller.mjs +579 -628
  171. package/build-module/image-editor/core/interaction-controller.mjs.map +1 -7
  172. package/build-module/image-editor/core/math/rotation.mjs +21 -10
  173. package/build-module/image-editor/core/math/rotation.mjs.map +1 -7
  174. package/build-module/image-editor/core/math/sanitize.mjs +116 -52
  175. package/build-module/image-editor/core/math/sanitize.mjs.map +1 -7
  176. package/build-module/image-editor/core/setter-helpers.mjs +52 -35
  177. package/build-module/image-editor/core/setter-helpers.mjs.map +1 -7
  178. package/build-module/image-editor/core/source-region.mjs +210 -160
  179. package/build-module/image-editor/core/source-region.mjs.map +1 -7
  180. package/build-module/image-editor/core/state.mjs +271 -243
  181. package/build-module/image-editor/core/state.mjs.map +1 -7
  182. package/build-module/image-editor/core/stencil-math.mjs +185 -178
  183. package/build-module/image-editor/core/stencil-math.mjs.map +1 -7
  184. package/build-module/image-editor/core/transform-style.mjs +34 -23
  185. package/build-module/image-editor/core/transform-style.mjs.map +1 -7
  186. package/build-module/image-editor/core/transforms/pipeline.mjs +29 -11
  187. package/build-module/image-editor/core/transforms/pipeline.mjs.map +1 -7
  188. package/build-module/image-editor/core/types.mjs +0 -1
  189. package/build-module/image-editor/core/viewport-state.mjs +26 -20
  190. package/build-module/image-editor/core/viewport-state.mjs.map +1 -7
  191. package/build-module/image-editor/index.mjs +3 -38
  192. package/build-module/image-editor/react/components/cropper-provider.mjs +38 -21
  193. package/build-module/image-editor/react/components/cropper-provider.mjs.map +1 -7
  194. package/build-module/image-editor/react/components/cropper.mjs +550 -696
  195. package/build-module/image-editor/react/components/cropper.mjs.map +1 -7
  196. package/build-module/image-editor/react/components/index.mjs +1 -7
  197. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +130 -135
  198. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -7
  199. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +24 -35
  200. package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +1 -7
  201. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +54 -64
  202. package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +1 -7
  203. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +355 -407
  204. package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +1 -7
  205. package/build-module/image-editor/react/components/viewport-provider.mjs +15 -22
  206. package/build-module/image-editor/react/components/viewport-provider.mjs.map +1 -7
  207. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +72 -43
  208. package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -7
  209. package/build-module/image-editor/react/hooks/index.mjs +2 -7
  210. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +83 -119
  211. package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +1 -7
  212. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +75 -0
  213. package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +1 -0
  214. package/build-module/image-editor/react/hooks/use-interaction.mjs +175 -183
  215. package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -7
  216. package/build-module/image-editor/react/hooks/use-transform-style.mjs +15 -9
  217. package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +1 -7
  218. package/build-module/image-editor/react/hooks/use-viewport-state.mjs +32 -26
  219. package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -7
  220. package/build-module/image-editor/react/visually-hidden-style.mjs +17 -14
  221. package/build-module/image-editor/react/visually-hidden-style.mjs.map +1 -7
  222. package/build-module/index.mjs +3 -10
  223. package/build-module/lock-unlock.mjs +5 -10
  224. package/build-module/lock-unlock.mjs.map +1 -7
  225. package/build-module/private-apis.mjs +8 -9
  226. package/build-module/private-apis.mjs.map +1 -7
  227. package/build-module/state/aspect-ratio-presets.mjs +48 -0
  228. package/build-module/state/aspect-ratio-presets.mjs.map +1 -0
  229. package/build-module/state/composite-reducer.mjs +114 -75
  230. package/build-module/state/composite-reducer.mjs.map +1 -7
  231. package/build-module/state/index.mjs +5 -25
  232. package/build-module/state/media-editor-state-provider.mjs +29 -24
  233. package/build-module/state/media-editor-state-provider.mjs.map +1 -7
  234. package/build-module/state/types.mjs +8 -7
  235. package/build-module/state/types.mjs.map +1 -7
  236. package/build-module/state/use-media-editor-state.mjs +256 -273
  237. package/build-module/state/use-media-editor-state.mjs.map +1 -7
  238. package/build-module/store/actions.mjs +12 -19
  239. package/build-module/store/actions.mjs.map +1 -7
  240. package/build-module/store/constants.mjs +4 -5
  241. package/build-module/store/constants.mjs.map +1 -7
  242. package/build-module/store/index.mjs +8 -9
  243. package/build-module/store/index.mjs.map +1 -7
  244. package/build-module/store/reducer.mjs +23 -26
  245. package/build-module/store/reducer.mjs.map +1 -7
  246. package/build-module/store/selectors.mjs +8 -13
  247. package/build-module/store/selectors.mjs.map +1 -7
  248. package/build-module/utils/get-media-type.mjs +14 -17
  249. package/build-module/utils/get-media-type.mjs.map +1 -7
  250. package/build-module/utils/index.mjs +1 -6
  251. package/build-style/style-rtl.css +41 -4
  252. package/build-style/style.css +41 -4
  253. package/build-types/components/media-editor/index.d.ts +6 -1
  254. package/build-types/components/media-editor/index.d.ts.map +1 -1
  255. package/build-types/components/media-editor/use-crop-options.d.ts +0 -1
  256. package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
  257. package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
  258. package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
  259. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  260. package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
  261. package/build-types/components/media-editor-modal/build-modifiers.d.ts +6 -5
  262. package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -1
  263. package/build-types/components/media-editor-modal/index.d.ts +7 -2
  264. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  265. package/build-types/components/media-editor-provider/index.d.ts +7 -1
  266. package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
  267. package/build-types/components/media-form/index.d.ts +5 -2
  268. package/build-types/components/media-form/index.d.ts.map +1 -1
  269. package/build-types/components/media-preview/index.d.ts.map +1 -1
  270. package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -1
  271. package/build-types/image-editor/core/constants.d.ts +0 -1
  272. package/build-types/image-editor/core/constants.d.ts.map +1 -1
  273. package/build-types/image-editor/core/index.d.ts +1 -1
  274. package/build-types/image-editor/core/index.d.ts.map +1 -1
  275. package/build-types/image-editor/core/setter-helpers.d.ts +1 -1
  276. package/build-types/image-editor/core/types.d.ts +1 -1
  277. package/build-types/image-editor/index.d.ts +7 -6
  278. package/build-types/image-editor/index.d.ts.map +1 -1
  279. package/build-types/image-editor/react/components/cropper-provider.d.ts +2 -2
  280. package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
  281. package/build-types/image-editor/react/components/cropper.d.ts +5 -14
  282. package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
  283. package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +2 -2
  284. package/build-types/image-editor/react/hooks/index.d.ts +2 -2
  285. package/build-types/image-editor/react/hooks/index.d.ts.map +1 -1
  286. package/build-types/image-editor/react/hooks/{use-cropper-reducer.d.ts → use-cropper-controller.d.ts} +12 -12
  287. package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +1 -0
  288. package/build-types/state/aspect-ratio-presets.d.ts +7 -0
  289. package/build-types/state/aspect-ratio-presets.d.ts.map +1 -0
  290. package/build-types/state/composite-reducer.d.ts +2 -2
  291. package/build-types/state/composite-reducer.d.ts.map +1 -1
  292. package/build-types/state/index.d.ts +2 -1
  293. package/build-types/state/index.d.ts.map +1 -1
  294. package/build-types/state/types.d.ts +36 -6
  295. package/build-types/state/types.d.ts.map +1 -1
  296. package/build-types/state/use-media-editor-state.d.ts +16 -5
  297. package/build-types/state/use-media-editor-state.d.ts.map +1 -1
  298. package/package.json +35 -24
  299. package/src/components/media-editor/index.tsx +226 -183
  300. package/src/components/media-editor/style.scss +19 -0
  301. package/src/components/media-editor/use-crop-options.ts +5 -4
  302. package/src/components/media-editor/use-save-media-editor.ts +2 -6
  303. package/src/components/media-editor-canvas/index.tsx +18 -28
  304. package/src/components/media-editor-crop-panel/index.tsx +17 -9
  305. package/src/components/media-editor-image-controls/index.tsx +4 -2
  306. package/src/components/media-editor-image-controls/style.scss +1 -1
  307. package/src/components/media-editor-modal/build-modifiers.ts +13 -7
  308. package/src/components/media-editor-modal/index.tsx +8 -1
  309. package/src/components/media-editor-modal/style.scss +1 -1
  310. package/src/components/media-editor-provider/index.tsx +8 -1
  311. package/src/components/media-form/index.tsx +48 -42
  312. package/src/components/media-preview/index.tsx +68 -25
  313. package/src/components/media-preview/style.scss +16 -2
  314. package/src/components/rotation-ruler/style.scss +6 -2
  315. package/src/components/rotation-ruler/use-ruler-drag.ts +6 -11
  316. package/src/image-editor/README.md +8 -8
  317. package/src/image-editor/core/constants.ts +0 -13
  318. package/src/image-editor/core/index.ts +1 -5
  319. package/src/image-editor/core/setter-helpers.ts +1 -1
  320. package/src/image-editor/core/types.ts +1 -1
  321. package/src/image-editor/docs/architecture.md +5 -1
  322. package/src/image-editor/docs/recipes.md +3 -3
  323. package/src/image-editor/index.ts +7 -16
  324. package/src/image-editor/react/components/cropper-provider.tsx +5 -5
  325. package/src/image-editor/react/components/cropper.tsx +20 -42
  326. package/src/image-editor/react/hooks/build-cropper-setters.ts +2 -2
  327. package/src/image-editor/react/hooks/index.ts +2 -2
  328. package/src/image-editor/react/hooks/{use-cropper-reducer.ts → use-cropper-controller.ts} +11 -11
  329. package/src/state/aspect-ratio-presets.ts +18 -0
  330. package/src/state/composite-reducer.ts +26 -13
  331. package/src/state/index.ts +3 -0
  332. package/src/state/types.ts +39 -11
  333. package/src/state/use-media-editor-state.ts +53 -16
  334. package/build/image-editor/core/index.cjs.map +0 -7
  335. package/build/image-editor/core/types.cjs.map +0 -7
  336. package/build/image-editor/index.cjs.map +0 -7
  337. package/build/image-editor/react/components/index.cjs.map +0 -7
  338. package/build/image-editor/react/hooks/index.cjs.map +0 -7
  339. package/build/image-editor/react/hooks/use-cropper-reducer.cjs +0 -113
  340. package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +0 -7
  341. package/build/index.cjs.map +0 -7
  342. package/build/state/index.cjs.map +0 -7
  343. package/build/utils/index.cjs.map +0 -7
  344. package/build-module/image-editor/core/index.mjs.map +0 -7
  345. package/build-module/image-editor/core/types.mjs.map +0 -7
  346. package/build-module/image-editor/index.mjs.map +0 -7
  347. package/build-module/image-editor/react/components/index.mjs.map +0 -7
  348. package/build-module/image-editor/react/hooks/index.mjs.map +0 -7
  349. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +0 -100
  350. package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +0 -7
  351. package/build-module/index.mjs.map +0 -7
  352. package/build-module/state/index.mjs.map +0 -7
  353. package/build-module/utils/index.mjs.map +0 -7
  354. package/build-types/image-editor/react/hooks/use-cropper-reducer.d.ts.map +0 -1
  355. package/global.d.ts +0 -5
  356. package/src/components/media-editor/test/restore-original.browser.test.tsx +0 -227
  357. package/src/components/media-editor/test/use-crop-options.jsdom.test.tsx +0 -106
  358. package/src/components/media-editor-crop-panel/test/index.jsdom.test.tsx +0 -72
  359. package/src/components/media-editor-image-controls/test/index.jsdom.test.tsx +0 -186
  360. package/src/components/media-editor-modal/test/build-modifiers.test.ts +0 -359
  361. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +0 -182
  362. package/src/components/rotation-ruler/stories/index.story.tsx +0 -43
  363. package/src/components/rotation-ruler/test/index.jsdom.test.tsx +0 -140
  364. package/src/image-editor/core/export/test/canvas-renderer.jsdom.test.ts +0 -823
  365. package/src/image-editor/core/math/test/sanitize.ts +0 -242
  366. package/src/image-editor/core/test/camera.ts +0 -1218
  367. package/src/image-editor/core/test/interaction-controller.ts +0 -1299
  368. package/src/image-editor/core/test/preview-export-parity.ts +0 -249
  369. package/src/image-editor/core/test/render-camera-bridge.ts +0 -349
  370. package/src/image-editor/core/test/state.ts +0 -876
  371. package/src/image-editor/core/test/stencil-math.ts +0 -665
  372. package/src/image-editor/core/transforms/test/pipeline.ts +0 -267
  373. package/src/image-editor/react/components/stencils/test/rectangle-stencil.browser.test.tsx +0 -438
  374. package/src/image-editor/react/components/test/cropper.browser.test.tsx +0 -1462
  375. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +0 -491
  376. package/src/image-editor/react/hooks/test/use-cropper-reducer.jsdom.test.ts +0 -1049
  377. package/src/image-editor/react/hooks/test/use-interaction.jsdom.test.ts +0 -213
  378. package/src/image-editor/react/hooks/test/use-transform-style.jsdom.test.ts +0 -140
  379. package/src/image-editor/stories/rectangle-crop.story.tsx +0 -1073
  380. package/src/image-editor/stories/style.module.css +0 -65
  381. package/src/state/test/use-media-editor-state.browser.test.tsx +0 -79
  382. package/src/state/test/use-media-editor-state.jsdom.test.ts +0 -386
  383. package/src/store/test/reducer.ts +0 -64
  384. package/tsconfig.build.json +0 -26
  385. package/tsconfig.build.tsbuildinfo +0 -1
  386. package/tsconfig.json +0 -37
@@ -1,98 +1,114 @@
1
- // packages/media-editor/src/components/media-preview/index.tsx
2
1
  import { Spinner } from "@wordpress/components";
3
2
  import { useState } from "@wordpress/element";
4
3
  import { __ } from "@wordpress/i18n";
5
4
  import { useMediaEditorContext } from "../media-editor-provider/index.mjs";
6
5
  import { getMediaTypeFromMimeType } from "../../utils/index.mjs";
7
6
  import { jsx, jsxs } from "react/jsx-runtime";
8
- function MediaPreviewContent({
9
- mediaType,
10
- mediaUrl,
11
- altText,
12
- displayTitle,
13
- mimeType,
14
- onLoad,
15
- onError,
16
- loadingState
17
- }) {
18
- switch (mediaType.type) {
19
- case "image":
20
- return /* @__PURE__ */ jsx(
21
- "img",
22
- {
23
- className: loadingState === "loaded" ? "loaded" : "",
24
- src: mediaUrl,
25
- alt: altText || "",
26
- onLoad,
27
- onError
28
- }
29
- );
30
- case "video":
31
- return /* @__PURE__ */ jsx("video", { src: mediaUrl, controls: true, onError, children: displayTitle });
32
- case "audio":
33
- return /* @__PURE__ */ jsx("audio", { src: mediaUrl, controls: true, onError, children: displayTitle });
34
- default:
35
- return /* @__PURE__ */ jsxs("div", { className: "media-editor-preview__file-info", children: [
36
- /* @__PURE__ */ jsx("p", { className: "media-editor-preview__file-name", children: displayTitle }),
37
- /* @__PURE__ */ jsx("p", { className: "media-editor-preview__mime-type", children: mimeType }),
38
- /* @__PURE__ */ jsx(
39
- "a",
40
- {
41
- href: mediaUrl,
42
- target: "_blank",
43
- rel: "noopener",
44
- className: "media-editor-preview__download-link",
45
- children: __("View file")
46
- }
47
- )
48
- ] });
49
- }
7
+ // packages/media-editor/src/components/media-preview/index.tsx
8
+ function MediaPreviewFileInfo({ mediaUrl, displayTitle, mimeType }) {
9
+ return /* @__PURE__ */ jsxs("div", {
10
+ className: "media-editor-preview__file-info",
11
+ children: [
12
+ /* @__PURE__ */ jsx("p", {
13
+ className: "media-editor-preview__file-name",
14
+ children: displayTitle
15
+ }),
16
+ /* @__PURE__ */ jsx("p", {
17
+ className: "media-editor-preview__mime-type",
18
+ children: mimeType
19
+ }),
20
+ /* @__PURE__ */ jsx("a", {
21
+ href: mediaUrl,
22
+ target: "_blank",
23
+ rel: "noopener",
24
+ className: "media-editor-preview__download-link",
25
+ children: __("View file")
26
+ })
27
+ ]
28
+ });
29
+ }
30
+ function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mimeType, onLoad, onError, loadingState }) {
31
+ switch (previewType) {
32
+ case "image": return /* @__PURE__ */ jsx("img", {
33
+ className: loadingState === "loaded" ? "loaded" : "",
34
+ src: mediaUrl,
35
+ alt: altText || "",
36
+ onLoad,
37
+ onError
38
+ });
39
+ case "video": return /* @__PURE__ */ jsx("video", {
40
+ src: mediaUrl,
41
+ controls: true,
42
+ onError,
43
+ children: displayTitle
44
+ });
45
+ case "audio": return /* @__PURE__ */ jsx("audio", {
46
+ src: mediaUrl,
47
+ controls: true,
48
+ onError,
49
+ children: displayTitle
50
+ });
51
+ case "pdf": return /* @__PURE__ */ jsx("object", {
52
+ className: "media-editor-preview__pdf",
53
+ data: `${mediaUrl}#view=Fit&zoom=page-fit`,
54
+ type: "application/pdf",
55
+ "aria-label": __("Embed of the selected PDF file."),
56
+ children: /* @__PURE__ */ jsx(MediaPreviewFileInfo, {
57
+ mediaUrl,
58
+ displayTitle,
59
+ mimeType
60
+ })
61
+ });
62
+ default: return /* @__PURE__ */ jsx(MediaPreviewFileInfo, {
63
+ mediaUrl,
64
+ displayTitle,
65
+ mimeType
66
+ });
67
+ }
50
68
  }
69
+ /**
70
+ * MediaPreview component displays the media file in the editor canvas.
71
+ * Supports images, videos, audio files, and generic file displays.
72
+ *
73
+ * @param props - Component props including click handlers and accessibility attributes.
74
+ * @return The MediaPreview component.
75
+ */
51
76
  function MediaPreview(props) {
52
- const [loadingState, setLoadingState] = useState("loading");
53
- const { media } = useMediaEditorContext();
54
- const {
55
- source_url: mediaUrl,
56
- mime_type: mimeType,
57
- alt_text: altText,
58
- title
59
- } = media || {};
60
- const mediaType = getMediaTypeFromMimeType(mimeType);
61
- if (!mediaUrl) {
62
- return /* @__PURE__ */ jsx("div", { className: "media-editor-preview media-editor-preview--empty", children: /* @__PURE__ */ jsx("p", { children: __("No media file available.") }) });
63
- }
64
- if (loadingState === "error") {
65
- return /* @__PURE__ */ jsxs("div", { className: "media-editor-preview media-editor-preview--error", children: [
66
- /* @__PURE__ */ jsx("p", { children: __("Failed to load media file.") }),
67
- /* @__PURE__ */ jsx("p", { className: "media-editor-preview__url", children: mediaUrl })
68
- ] });
69
- }
70
- const displayTitle = typeof title === "string" ? title : title?.rendered || title?.raw;
71
- return /* @__PURE__ */ jsxs(
72
- "div",
73
- {
74
- ...props,
75
- className: `media-editor-preview media-editor-preview--${mediaType.type}`,
76
- children: [
77
- mediaType.type === "image" && loadingState === "loading" && /* @__PURE__ */ jsx("div", { className: "media-editor-preview__spinner", children: /* @__PURE__ */ jsx(Spinner, {}) }),
78
- /* @__PURE__ */ jsx(
79
- MediaPreviewContent,
80
- {
81
- mediaType,
82
- mediaUrl,
83
- altText,
84
- displayTitle,
85
- mimeType,
86
- onLoad: () => setLoadingState("loaded"),
87
- onError: () => setLoadingState("error"),
88
- loadingState
89
- }
90
- )
91
- ]
92
- }
93
- );
77
+ const [loadingState, setLoadingState] = useState("loading");
78
+ const { media } = useMediaEditorContext();
79
+ const { source_url: mediaUrl, mime_type: mimeType, alt_text: altText, title } = media || {};
80
+ const mediaType = getMediaTypeFromMimeType(mimeType);
81
+ const previewType = mimeType === "application/pdf" && window.navigator.pdfViewerEnabled ? "pdf" : mediaType.type;
82
+ if (!mediaUrl) return /* @__PURE__ */ jsx("div", {
83
+ className: "media-editor-preview media-editor-preview--empty",
84
+ children: /* @__PURE__ */ jsx("p", { children: __("No media file available.") })
85
+ });
86
+ if (loadingState === "error") return /* @__PURE__ */ jsxs("div", {
87
+ className: "media-editor-preview media-editor-preview--error",
88
+ children: [/* @__PURE__ */ jsx("p", { children: __("Failed to load media file.") }), /* @__PURE__ */ jsx("p", {
89
+ className: "media-editor-preview__url",
90
+ children: mediaUrl
91
+ })]
92
+ });
93
+ const displayTitle = typeof title === "string" ? title : title?.rendered || title?.raw;
94
+ return /* @__PURE__ */ jsxs("div", {
95
+ ...props,
96
+ className: `media-editor-preview media-editor-preview--${previewType}`,
97
+ children: [previewType === "image" && loadingState === "loading" && /* @__PURE__ */ jsx("div", {
98
+ className: "media-editor-preview__spinner",
99
+ children: /* @__PURE__ */ jsx(Spinner, {})
100
+ }), /* @__PURE__ */ jsx(MediaPreviewContent, {
101
+ previewType,
102
+ mediaUrl,
103
+ altText,
104
+ displayTitle,
105
+ mimeType,
106
+ onLoad: () => setLoadingState("loaded"),
107
+ onError: () => setLoadingState("error"),
108
+ loadingState
109
+ })]
110
+ });
94
111
  }
95
- export {
96
- MediaPreview as default
97
- };
98
- //# sourceMappingURL=index.mjs.map
112
+ export { MediaPreview as default };
113
+
114
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/media-preview/index.tsx"],
4
- "sourcesContent": ["import { Spinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tmediaType: { type: string };\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\nfunction MediaPreviewContent( {\n\tmediaType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tmimeType,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( mediaType.type ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t\t\t<p className=\"media-editor-preview__file-name\">\n\t\t\t\t\t\t{ displayTitle }\n\t\t\t\t\t</p>\n\t\t\t\t\t<p className=\"media-editor-preview__mime-type\">\n\t\t\t\t\t\t{ mimeType }\n\t\t\t\t\t</p>\n\t\t\t\t\t{ /* eslint-disable-next-line react/jsx-no-target-blank */ }\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={ mediaUrl }\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"noopener\"\n\t\t\t\t\t\tclassName=\"media-editor-preview__download-link\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'View file' ) }\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty\">\n\t\t\t\t<p>{ __( 'No media file available.' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error\">\n\t\t\t\t<p>{ __( 'Failed to load media file.' ) }</p>\n\t\t\t\t<p className=\"media-editor-preview__url\">{ mediaUrl }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ `media-editor-preview media-editor-preview--${ mediaType.type }` }\n\t\t>\n\t\t\t{ mediaType.type === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tmediaType={ mediaType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tmimeType={ mimeType }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";AAAA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,UAAU;AACnB,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AAoCrC,cAsBA,YAtBA;AAbJ,SAAS,oBAAqB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA8B;AAC7B,UAAS,UAAU,MAAO;AAAA,IACzB,KAAK;AACJ,aACC;AAAA,QAAC;AAAA;AAAA,UACA,WAAY,iBAAiB,WAAW,WAAW;AAAA,UACnD,KAAM;AAAA,UACN,KAAM,WAAW;AAAA,UACjB;AAAA,UACA;AAAA;AAAA,MACD;AAAA,IAEF,KAAK;AACJ,aACC,oBAAC,WAAM,KAAM,UAAW,UAAQ,MAAC,SAC9B,wBACH;AAAA,IAEF,KAAK;AACJ,aACC,oBAAC,WAAM,KAAM,UAAW,UAAQ,MAAC,SAC9B,wBACH;AAAA,IAEF;AACC,aACC,qBAAC,SAAI,WAAU,mCACd;AAAA,4BAAC,OAAE,WAAU,mCACV,wBACH;AAAA,QACA,oBAAC,OAAE,WAAU,mCACV,oBACH;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,MAAO;AAAA,YACP,QAAO;AAAA,YACP,KAAI;AAAA,YACJ,WAAU;AAAA,YAER,aAAI,WAAY;AAAA;AAAA,QACnB;AAAA,SACD;AAAA,EAEH;AACD;AASe,SAAR,aAA+B,OAA2B;AAChE,QAAM,CAAE,cAAc,eAAgB,IAAI,SAEvC,SAAU;AACb,QAAM,EAAE,MAAM,IAAI,sBAAsB;AAExC,QAAM;AAAA,IACL,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,UAAU;AAAA,IACV;AAAA,EACD,IAAI,SAAS,CAAC;AAEd,QAAM,YAAY,yBAA0B,QAAS;AAErD,MAAK,CAAE,UAAW;AACjB,WACC,oBAAC,SAAI,WAAU,oDACd,8BAAC,OAAI,aAAI,0BAA2B,GAAG,GACxC;AAAA,EAEF;AAEA,MAAK,iBAAiB,SAAU;AAC/B,WACC,qBAAC,SAAI,WAAU,oDACd;AAAA,0BAAC,OAAI,aAAI,4BAA6B,GAAG;AAAA,MACzC,oBAAC,OAAE,WAAU,6BAA8B,oBAAU;AAAA,OACtD;AAAA,EAEF;AAEA,QAAM,eACL,OAAO,UAAU,WAAW,QAAQ,OAAO,YAAY,OAAO;AAE/D,SACC;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACL,WAAY,8CAA+C,UAAU,IAAK;AAAA,MAExE;AAAA,kBAAU,SAAS,WAAW,iBAAiB,aAChD,oBAAC,SAAI,WAAU,iCACd,8BAAC,WAAQ,GACV;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,QAAS,MAAM,gBAAiB,QAAS;AAAA,YACzC,SAAU,MAAM,gBAAiB,OAAQ;AAAA,YACzC;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EACD;AAEF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":["WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import { Spinner as WCSpinner } from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport { getMediaTypeFromMimeType } from '../../utils';\n\n/**\n * Props for MediaPreview component.\n */\nexport interface MediaPreviewProps {\n\t[ key: string ]: any; // TODO: Define specific props as needed, this will likely be for click handlers, accessibility attributes, etc.\n}\n\n/**\n * Props for MediaPreviewContent component.\n */\ninterface MediaPreviewContentProps {\n\tpreviewType: string;\n\tmediaUrl: string;\n\taltText?: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tdisplayTitle?: string;\n\tmimeType?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tdisplayTitle,\n\tmimeType,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<div className=\"media-editor-preview__file-info\">\n\t\t\t<p className=\"media-editor-preview__file-name\">{ displayTitle }</p>\n\t\t\t<p className=\"media-editor-preview__mime-type\">{ mimeType }</p>\n\t\t\t{ /* eslint-disable-next-line react/jsx-no-target-blank */ }\n\t\t\t<a\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\trel=\"noopener\"\n\t\t\t\tclassName=\"media-editor-preview__download-link\"\n\t\t\t>\n\t\t\t\t{ __( 'View file' ) }\n\t\t\t</a>\n\t\t</div>\n\t);\n}\n\nfunction MediaPreviewContent( {\n\tpreviewType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tmimeType,\n\tonLoad,\n\tonError,\n\tloadingState,\n}: MediaPreviewContentProps ) {\n\tswitch ( previewType ) {\n\t\tcase 'image':\n\t\t\treturn (\n\t\t\t\t<img\n\t\t\t\t\tclassName={ loadingState === 'loaded' ? 'loaded' : '' }\n\t\t\t\t\tsrc={ mediaUrl }\n\t\t\t\t\talt={ altText || '' }\n\t\t\t\t\tonLoad={ onLoad }\n\t\t\t\t\tonError={ onError }\n\t\t\t\t/>\n\t\t\t);\n\t\tcase 'video':\n\t\t\treturn (\n\t\t\t\t<video src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</video>\n\t\t\t);\n\t\tcase 'audio':\n\t\t\treturn (\n\t\t\t\t<audio src={ mediaUrl } controls onError={ onError }>\n\t\t\t\t\t{ displayTitle }\n\t\t\t\t</audio>\n\t\t\t);\n\t\tcase 'pdf':\n\t\t\t// The browser renders the children instead of the PDF when it\n\t\t\t// can't display it, e.g. when the request fails.\n\t\t\treturn (\n\t\t\t\t<object\n\t\t\t\t\tclassName=\"media-editor-preview__pdf\"\n\t\t\t\t\t// Ask the viewer to fit the whole page rather than the\n\t\t\t\t\t// width. Chrome reads `view`, Firefox reads `zoom`, and\n\t\t\t\t\t// Safari ignores both.\n\t\t\t\t\tdata={ `${ mediaUrl }#view=Fit&zoom=page-fit` }\n\t\t\t\t\ttype=\"application/pdf\"\n\t\t\t\t\taria-label={ __( 'Embed of the selected PDF file.' ) }\n\t\t\t\t>\n\t\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t\t/>\n\t\t\t\t</object>\n\t\t\t);\n\t\tdefault:\n\t\t\treturn (\n\t\t\t\t<MediaPreviewFileInfo\n\t\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\t\tmimeType={ mimeType }\n\t\t\t\t/>\n\t\t\t);\n\t}\n}\n\n/**\n * MediaPreview component displays the media file in the editor canvas.\n * Supports images, videos, audio files, and generic file displays.\n *\n * @param props - Component props including click handlers and accessibility attributes.\n * @return The MediaPreview component.\n */\nexport default function MediaPreview( props: MediaPreviewProps ) {\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'loading' | 'loaded' | 'error'\n\t>( 'loading' );\n\tconst { media } = useMediaEditorContext();\n\n\tconst {\n\t\tsource_url: mediaUrl,\n\t\tmime_type: mimeType,\n\t\talt_text: altText,\n\t\ttitle,\n\t} = media || {};\n\n\tconst mediaType = getMediaTypeFromMimeType( mimeType );\n\n\t// Without a built-in PDF viewer (e.g. on most mobile browsers), show\n\t// the file info instead of an embed that can't render.\n\tconst previewType =\n\t\tmimeType === 'application/pdf' && window.navigator.pdfViewerEnabled\n\t\t\t? 'pdf'\n\t\t\t: mediaType.type;\n\n\tif ( ! mediaUrl ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--empty\">\n\t\t\t\t<p>{ __( 'No media file available.' ) }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error\">\n\t\t\t\t<p>{ __( 'Failed to load media file.' ) }</p>\n\t\t\t\t<p className=\"media-editor-preview__url\">{ mediaUrl }</p>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst displayTitle =\n\t\ttypeof title === 'string' ? title : title?.rendered || title?.raw;\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ `media-editor-preview media-editor-preview--${ previewType }` }\n\t\t>\n\t\t\t{ previewType === 'image' && loadingState === 'loading' && (\n\t\t\t\t<div className=\"media-editor-preview__spinner\">\n\t\t\t\t\t<WCSpinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<MediaPreviewContent\n\t\t\t\tpreviewType={ previewType }\n\t\t\t\tmediaUrl={ mediaUrl }\n\t\t\t\taltText={ altText }\n\t\t\t\tdisplayTitle={ displayTitle }\n\t\t\t\tmimeType={ mimeType }\n\t\t\t\tonLoad={ () => setLoadingState( 'loaded' ) }\n\t\t\t\tonError={ () => setLoadingState( 'error' ) }\n\t\t\t\tloadingState={ loadingState }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,qBAAsB,EAC9B,UACA,cACA,YAC8B;CAC9B,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA;GACC,oBAAC,KAAD;IAAG,WAAU;IAAoC,UAAA;GAAiB,CAAA;GAClE,oBAAC,KAAD;IAAG,WAAU;IAAoC,UAAA;GAAa,CAAA;GAE9D,oBAAC,KAAD;IACC,MAAO;IACP,QAAO;IACP,KAAI;IACJ,WAAU;IAER,UAAA,GAAI,WAAY;GAChB,CAAA;EACC;;AAEP;AAEA,SAAS,oBAAqB,EAC7B,aACA,UACA,SACA,cACA,UACA,QACA,SACA,gBAC6B;CAC7B,QAAS,aAAT;EACC,KAAK,SACJ,OACC,oBAAC,OAAD;GACC,WAAY,iBAAiB,WAAW,WAAW;GACnD,KAAM;GACN,KAAM,WAAW;GACR;GACC;EACV,CAAA;EAEH,KAAK,SACJ,OACC,oBAAC,SAAD;GAAO,KAAM;GAAW,UAAA;GAAmB;GACxC,UAAA;EACI,CAAA;EAET,KAAK,SACJ,OACC,oBAAC,SAAD;GAAO,KAAM;GAAW,UAAA;GAAmB;GACxC,UAAA;EACI,CAAA;EAET,KAAK,OAGJ,OACC,oBAAC,UAAD;GACC,WAAU;GAIV,MAAO,GAAI,SAAU;GACrB,MAAK;GACL,cAAa,GAAI,iCAAkC;GAEnD,UAAA,oBAAC,sBAAD;IACY;IACI;IACJ;GACX,CAAA;EACM,CAAA;EAEV,SACC,OACC,oBAAC,sBAAD;GACY;GACI;GACJ;EACX,CAAA;CAEJ;AACD;;;;;;;;AASA,SAAwB,aAAc,OAA2B;CAChE,MAAM,CAAE,cAAc,mBAAoB,SAEvC,SAAU;CACb,MAAM,EAAE,UAAU,sBAAsB;CAExC,MAAM,EACL,YAAY,UACZ,WAAW,UACX,UAAU,SACV,UACG,SAAS,CAAC;CAEd,MAAM,YAAY,yBAA0B,QAAS;CAIrD,MAAM,cACL,aAAa,qBAAqB,OAAO,UAAU,mBAChD,QACA,UAAU;CAEd,IAAK,CAAE,UACN,OACC,oBAAC,OAAD;EAAK,WAAU;EACd,UAAA,oBAAC,KAAD,EAAA,UAAK,GAAI,0BAA2B,EAAM,CAAA;CACtC,CAAA;CAIP,IAAK,iBAAiB,SACrB,OACC,qBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACC,oBAAC,KAAD,EAAA,UAAK,GAAI,4BAA6B,EAAM,CAAA,GAC5C,oBAAC,KAAD;GAAG,WAAU;GAA8B,UAAA;EAAa,CAAA,CACpD;;CAIP,MAAM,eACL,OAAO,UAAU,WAAW,QAAQ,OAAO,YAAY,OAAO;CAE/D,OACC,qBAAC,OAAD;EACC,GAAK;EACL,WAAY,8CAA+C;EAF5D,UAAA,CAIG,gBAAgB,WAAW,iBAAiB,aAC7C,oBAAC,OAAD;GAAK,WAAU;GACd,UAAA,oBAACA,SAAD,CAAY,CAAA;EACR,CAAA,GAEN,oBAAC,qBAAD;GACe;GACH;GACD;GACK;GACJ;GACX,cAAe,gBAAiB,QAAS;GACzC,eAAgB,gBAAiB,OAAQ;GAC1B;EACf,CAAA,CACG;;AAEP"}
@@ -1,173 +1,170 @@
1
- // packages/media-editor/src/components/rotation-ruler/index.tsx
2
1
  import clsx from "clsx";
3
2
  import { useId, useMemo, useRef } from "@wordpress/element";
4
- import { useRulerDrag, clampValue } from "./use-ruler-drag.mjs";
3
+ import { clampValue, useRulerDrag } from "./use-ruler-drag.mjs";
5
4
  import { jsx, jsxs } from "react/jsx-runtime";
6
- var STRIP_HEIGHT = 32;
7
- var LABEL_BASELINE_Y = 11;
8
- var MAJOR_INTERVAL = 15;
9
- var TICK_HEIGHT_MINOR = 4;
10
- var TICK_HEIGHT_MID = 8;
11
- var TICK_HEIGHT_MAJOR = 14;
5
+ // packages/media-editor/src/components/rotation-ruler/index.tsx
6
+ const STRIP_HEIGHT = 32;
7
+ const LABEL_BASELINE_Y = 11;
8
+ const MAJOR_INTERVAL = 15;
9
+ const TICK_HEIGHT_MINOR = 4;
10
+ const TICK_HEIGHT_MID = 8;
11
+ const TICK_HEIGHT_MAJOR = 14;
12
+ /**
13
+ * Build the tick list for the ruler strip.
14
+ *
15
+ * @param min Lower bound of the ruler in value units.
16
+ * @param max Upper bound of the ruler in value units.
17
+ */
12
18
  function useTicks(min, max) {
13
- return useMemo(() => {
14
- const out = [];
15
- for (let v = Math.ceil(min); v <= Math.floor(max); v += 1) {
16
- let kind = "minor";
17
- let height = TICK_HEIGHT_MINOR;
18
- if (v % 15 === 0) {
19
- kind = "major";
20
- height = TICK_HEIGHT_MAJOR;
21
- } else if (v % 5 === 0) {
22
- kind = "mid";
23
- height = TICK_HEIGHT_MID;
24
- }
25
- out.push({ value: v, kind, height });
26
- }
27
- return out;
28
- }, [min, max]);
19
+ return useMemo(() => {
20
+ const out = [];
21
+ for (let v = Math.ceil(min); v <= Math.floor(max); v += 1) {
22
+ let kind = "minor";
23
+ let height = TICK_HEIGHT_MINOR;
24
+ if (v % 15 === 0) {
25
+ kind = "major";
26
+ height = TICK_HEIGHT_MAJOR;
27
+ } else if (v % 5 === 0) {
28
+ kind = "mid";
29
+ height = TICK_HEIGHT_MID;
30
+ }
31
+ out.push({
32
+ value: v,
33
+ kind,
34
+ height
35
+ });
36
+ }
37
+ return out;
38
+ }, [min, max]);
29
39
  }
40
+ /**
41
+ * Format a numeric ruler value for display, trimming a trailing `.0`.
42
+ *
43
+ * @param value Value to format.
44
+ */
30
45
  function formatValue(value) {
31
- const rounded = Math.round(value * 10) / 10;
32
- return Number.isInteger(rounded) ? rounded.toFixed(0) : rounded.toFixed(1);
46
+ const rounded = Math.round(value * 10) / 10;
47
+ return Number.isInteger(rounded) ? rounded.toFixed(0) : rounded.toFixed(1);
33
48
  }
49
+ /**
50
+ * Horizontal "scrub-the-ruler" slider for fine-grained numeric input
51
+ * such as rotation in degrees.
52
+ *
53
+ * Renders a visually hidden `<input type="range">` for assistive
54
+ * technologies and keyboard input alongside a decorative tick strip
55
+ * that the user can drag with a pointer.
56
+ *
57
+ * @param props Component props. See `RotationRulerProps`.
58
+ */
34
59
  function RotationRuler(props) {
35
- const {
36
- value,
37
- onChange,
38
- min = -45,
39
- max = 45,
40
- step = 1,
41
- label,
42
- unit = "°",
43
- pixelsPerStep = 6,
44
- className,
45
- id,
46
- disabled = false
47
- } = props;
48
- const inputRef = useRef(null);
49
- const generatedId = useId();
50
- const inputId = id ?? generatedId;
51
- const dragHandlers = useRulerDrag({
52
- value,
53
- onChange,
54
- min,
55
- max,
56
- step,
57
- pixelsPerStep,
58
- disabled,
59
- onPointerDownStart: () => inputRef.current?.focus()
60
- });
61
- const handleKeyDown = (event) => {
62
- const isIncrement = event.key === "ArrowRight" || event.key === "ArrowUp";
63
- const isDecrement = event.key === "ArrowLeft" || event.key === "ArrowDown";
64
- if (!isIncrement && !isDecrement) {
65
- return;
66
- }
67
- event.preventDefault();
68
- if (disabled) {
69
- return;
70
- }
71
- const direction = isIncrement ? 1 : -1;
72
- const magnitude = event.shiftKey ? step / 2 : step;
73
- const next = clampValue(value + direction * magnitude, min, max);
74
- if (next !== value) {
75
- onChange(next);
76
- }
77
- };
78
- const display = `${formatValue(value)}${unit}`;
79
- const ticks = useTicks(min, max);
80
- const pxPerUnit = pixelsPerStep / step;
81
- const stripStyle = useMemo(() => {
82
- const offset = -value * pxPerUnit;
83
- return {
84
- transform: `translateX(calc(-50% + ${offset}px))`
85
- };
86
- }, [value, pxPerUnit]);
87
- const closestMajor = Math.round(value / MAJOR_INTERVAL) * MAJOR_INTERVAL;
88
- const onMajor = Math.abs(value - closestMajor) < 0.01;
89
- const numberText = onMajor ? `${closestMajor}` : formatValue(value);
90
- const isNegative = numberText.startsWith("-");
91
- const digits = isNegative ? numberText.slice(1) : numberText;
92
- const majorTicks = ticks.filter((tick) => tick.kind === "major");
93
- return /* @__PURE__ */ jsxs(
94
- "div",
95
- {
96
- className: clsx("rotation-ruler", className),
97
- role: "presentation",
98
- "data-testid": "rotation-ruler",
99
- "data-disabled": disabled || void 0,
100
- ...dragHandlers,
101
- children: [
102
- /* @__PURE__ */ jsx(
103
- "input",
104
- {
105
- ref: inputRef,
106
- id: inputId,
107
- type: "range",
108
- className: "rotation-ruler__input",
109
- min,
110
- max,
111
- step: "any",
112
- value,
113
- disabled,
114
- "aria-label": label,
115
- "aria-valuetext": display,
116
- onChange: (event) => onChange(
117
- clampValue(event.target.valueAsNumber, min, max)
118
- ),
119
- onKeyDown: handleKeyDown
120
- }
121
- ),
122
- /* @__PURE__ */ jsx("div", { className: "rotation-ruler__strip", "aria-hidden": "true", children: /* @__PURE__ */ jsxs(
123
- "svg",
124
- {
125
- className: "rotation-ruler__ticks",
126
- style: stripStyle,
127
- width: (max - min) * pxPerUnit,
128
- height: STRIP_HEIGHT,
129
- viewBox: `${min * pxPerUnit} 0 ${(max - min) * pxPerUnit} ${STRIP_HEIGHT}`,
130
- preserveAspectRatio: "xMidYMid meet",
131
- children: [
132
- ticks.map((tick) => /* @__PURE__ */ jsx(
133
- "line",
134
- {
135
- x1: tick.value * pxPerUnit,
136
- x2: tick.value * pxPerUnit,
137
- y1: STRIP_HEIGHT - tick.height,
138
- y2: STRIP_HEIGHT,
139
- className: `rotation-ruler__tick rotation-ruler__tick--${tick.kind}`
140
- },
141
- tick.value
142
- )),
143
- majorTicks.map((tick) => /* @__PURE__ */ jsxs(
144
- "text",
145
- {
146
- x: tick.value * pxPerUnit,
147
- y: LABEL_BASELINE_Y,
148
- textAnchor: "middle",
149
- className: "rotation-ruler__label",
150
- children: [
151
- tick.value,
152
- unit
153
- ]
154
- },
155
- tick.value
156
- ))
157
- ]
158
- }
159
- ) }),
160
- /* @__PURE__ */ jsx("div", { className: "rotation-ruler__active-label", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("span", { className: "rotation-ruler__active-label-number", children: [
161
- isNegative && /* @__PURE__ */ jsx("span", { className: "rotation-ruler__active-label-sign", children: "-" }),
162
- digits,
163
- /* @__PURE__ */ jsx("span", { className: "rotation-ruler__active-label-unit", children: unit })
164
- ] }) }),
165
- /* @__PURE__ */ jsx("div", { className: "rotation-ruler__pointer", "aria-hidden": "true" })
166
- ]
167
- }
168
- );
60
+ const { value, onChange, min = -45, max = 45, step = 1, label, unit = "°", pixelsPerStep = 6, className, id, disabled = false } = props;
61
+ const inputRef = useRef(null);
62
+ const generatedId = useId();
63
+ const inputId = id ?? generatedId;
64
+ const dragHandlers = useRulerDrag({
65
+ value,
66
+ onChange,
67
+ min,
68
+ max,
69
+ step,
70
+ pixelsPerStep,
71
+ disabled,
72
+ onPointerDownStart: () => inputRef.current?.focus()
73
+ });
74
+ const handleKeyDown = (event) => {
75
+ const isIncrement = event.key === "ArrowRight" || event.key === "ArrowUp";
76
+ const isDecrement = event.key === "ArrowLeft" || event.key === "ArrowDown";
77
+ if (!isIncrement && !isDecrement) return;
78
+ event.preventDefault();
79
+ if (disabled) return;
80
+ const direction = isIncrement ? 1 : -1;
81
+ const magnitude = event.shiftKey ? step / 2 : step;
82
+ const next = clampValue(value + direction * magnitude, min, max);
83
+ if (next !== value) onChange(next);
84
+ };
85
+ const display = `${formatValue(value)}${unit}`;
86
+ const ticks = useTicks(min, max);
87
+ const pxPerUnit = pixelsPerStep / step;
88
+ const stripStyle = useMemo(() => {
89
+ return { transform: `translateX(calc(-50% + ${-value * pxPerUnit}px))` };
90
+ }, [value, pxPerUnit]);
91
+ const closestMajor = Math.round(value / MAJOR_INTERVAL) * MAJOR_INTERVAL;
92
+ const numberText = Math.abs(value - closestMajor) < .01 ? `${closestMajor}` : formatValue(value);
93
+ const isNegative = numberText.startsWith("-");
94
+ const digits = isNegative ? numberText.slice(1) : numberText;
95
+ const majorTicks = ticks.filter((tick) => tick.kind === "major");
96
+ return /* @__PURE__ */ jsxs("div", {
97
+ className: clsx("rotation-ruler", className),
98
+ role: "presentation",
99
+ "data-testid": "rotation-ruler",
100
+ "data-disabled": disabled || void 0,
101
+ ...dragHandlers,
102
+ children: [
103
+ /* @__PURE__ */ jsx("input", {
104
+ ref: inputRef,
105
+ id: inputId,
106
+ type: "range",
107
+ className: "rotation-ruler__input",
108
+ min,
109
+ max,
110
+ step: "any",
111
+ value,
112
+ disabled,
113
+ "aria-label": label,
114
+ "aria-valuetext": display,
115
+ onChange: (event) => onChange(clampValue(event.target.valueAsNumber, min, max)),
116
+ onKeyDown: handleKeyDown
117
+ }),
118
+ /* @__PURE__ */ jsx("div", {
119
+ className: "rotation-ruler__strip",
120
+ "aria-hidden": "true",
121
+ children: /* @__PURE__ */ jsxs("svg", {
122
+ className: "rotation-ruler__ticks",
123
+ style: stripStyle,
124
+ width: (max - min) * pxPerUnit,
125
+ height: STRIP_HEIGHT,
126
+ viewBox: `${min * pxPerUnit} 0 ${(max - min) * pxPerUnit} ${STRIP_HEIGHT}`,
127
+ preserveAspectRatio: "xMidYMid meet",
128
+ children: [ticks.map((tick) => /* @__PURE__ */ jsx("line", {
129
+ x1: tick.value * pxPerUnit,
130
+ x2: tick.value * pxPerUnit,
131
+ y1: STRIP_HEIGHT - tick.height,
132
+ y2: STRIP_HEIGHT,
133
+ className: `rotation-ruler__tick rotation-ruler__tick--${tick.kind}`
134
+ }, tick.value)), majorTicks.map((tick) => /* @__PURE__ */ jsxs("text", {
135
+ x: tick.value * pxPerUnit,
136
+ y: LABEL_BASELINE_Y,
137
+ textAnchor: "middle",
138
+ className: "rotation-ruler__label",
139
+ children: [tick.value, unit]
140
+ }, tick.value))]
141
+ })
142
+ }),
143
+ /* @__PURE__ */ jsx("div", {
144
+ className: "rotation-ruler__active-label",
145
+ "aria-hidden": "true",
146
+ children: /* @__PURE__ */ jsxs("span", {
147
+ className: "rotation-ruler__active-label-number",
148
+ children: [
149
+ isNegative && /* @__PURE__ */ jsx("span", {
150
+ className: "rotation-ruler__active-label-sign",
151
+ children: "-"
152
+ }),
153
+ digits,
154
+ /* @__PURE__ */ jsx("span", {
155
+ className: "rotation-ruler__active-label-unit",
156
+ children: unit
157
+ })
158
+ ]
159
+ })
160
+ }),
161
+ /* @__PURE__ */ jsx("div", {
162
+ className: "rotation-ruler__pointer",
163
+ "aria-hidden": "true"
164
+ })
165
+ ]
166
+ });
169
167
  }
170
- export {
171
- RotationRuler as default
172
- };
173
- //# sourceMappingURL=index.mjs.map
168
+ export { RotationRuler as default };
169
+
170
+ //# sourceMappingURL=index.mjs.map