@wordpress/media-editor 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/build/components/media-editor/index.cjs +229 -126
- package/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs +4 -5
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor/use-save-media-editor.cjs +41 -11
- package/build/components/media-editor/use-save-media-editor.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +15 -18
- package/build/components/media-editor-canvas/index.cjs.map +1 -1
- package/build/components/media-editor-crop-panel/index.cjs +26 -8
- package/build/components/media-editor-crop-panel/index.cjs.map +1 -1
- package/build/components/media-editor-fine-rotation/index.cjs +13 -12
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +4 -6
- package/build/components/media-editor-image-controls/index.cjs.map +1 -1
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +33 -33
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +1 -1
- package/build/components/media-editor-modal/index.cjs +10 -7
- package/build/components/media-editor-modal/index.cjs.map +1 -1
- package/build/components/media-editor-panel/error-boundary.cjs +68 -0
- package/build/components/media-editor-panel/error-boundary.cjs.map +1 -0
- package/build/components/media-editor-panel/index.cjs +158 -0
- package/build/components/media-editor-panel/index.cjs.map +1 -0
- package/build/components/media-form/index.cjs +7 -1
- package/build/components/media-form/index.cjs.map +1 -1
- package/build/components/media-preview/index.cjs +143 -37
- package/build/components/media-preview/index.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +9 -7
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/hooks/use-crop-gesture-handlers.cjs.map +1 -1
- package/build/index.cjs +10 -8
- package/build/private-apis.cjs.map +1 -1
- package/build/state/aspect-ratio-presets.cjs +12 -6
- package/build/state/aspect-ratio-presets.cjs.map +1 -1
- package/build/state/composite-reducer.cjs +41 -74
- package/build/state/composite-reducer.cjs.map +1 -1
- package/build/state/index.cjs +0 -39
- package/build/state/types.cjs +1 -2
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +70 -106
- package/build/state/use-media-editor-state.cjs.map +1 -1
- package/build/store/index.cjs +11 -9
- package/build/store/index.cjs.map +1 -1
- package/build/utils/get-media-type.cjs +8 -0
- package/build/utils/get-media-type.cjs.map +1 -1
- package/build/utils/index.cjs +6 -0
- package/build-module/components/media-editor/index.mjs +217 -117
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs +4 -5
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor/use-save-media-editor.mjs +32 -4
- package/build-module/components/media-editor/use-save-media-editor.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +8 -13
- package/build-module/components/media-editor-canvas/index.mjs.map +1 -1
- package/build-module/components/media-editor-crop-panel/index.mjs +17 -1
- package/build-module/components/media-editor-crop-panel/index.mjs.map +1 -1
- package/build-module/components/media-editor-fine-rotation/index.mjs +4 -5
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +5 -7
- package/build-module/components/media-editor-image-controls/index.mjs.map +1 -1
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +33 -33
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-modal/index.mjs +1 -0
- package/build-module/components/media-editor-modal/index.mjs.map +1 -1
- package/build-module/components/media-editor-panel/error-boundary.mjs +63 -0
- package/build-module/components/media-editor-panel/error-boundary.mjs.map +1 -0
- package/build-module/components/media-editor-panel/index.mjs +123 -0
- package/build-module/components/media-editor-panel/index.mjs.map +1 -0
- package/build-module/components/media-form/index.mjs +7 -1
- package/build-module/components/media-form/index.mjs.map +1 -1
- package/build-module/components/media-preview/index.mjs +123 -41
- package/build-module/components/media-preview/index.mjs.map +1 -1
- package/build-module/state/aspect-ratio-presets.mjs +12 -7
- package/build-module/state/aspect-ratio-presets.mjs.map +1 -1
- package/build-module/state/composite-reducer.mjs +32 -67
- package/build-module/state/composite-reducer.mjs.map +1 -1
- package/build-module/state/index.mjs +2 -5
- package/build-module/state/types.mjs +1 -2
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +70 -105
- package/build-module/state/use-media-editor-state.mjs.map +1 -1
- package/build-module/utils/get-media-type.mjs +8 -1
- package/build-module/utils/get-media-type.mjs.map +1 -1
- package/build-module/utils/index.mjs +1 -1
- package/build-style/style-rtl.css +122 -87
- package/build-style/style.css +121 -87
- package/build-types/components/media-editor/index.d.ts +25 -3
- package/build-types/components/media-editor/index.d.ts.map +1 -1
- package/build-types/components/media-editor/use-crop-options.d.ts +2 -3
- package/build-types/components/media-editor/use-crop-options.d.ts.map +1 -1
- package/build-types/components/media-editor/use-save-media-editor.d.ts.map +1 -1
- package/build-types/components/media-editor-canvas/index.d.ts +3 -3
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-fine-rotation/index.d.ts.map +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts +1 -1
- package/build-types/components/media-editor-image-controls/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-modal/index.d.ts +1 -1
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-panel/error-boundary.d.ts +23 -0
- package/build-types/components/media-editor-panel/error-boundary.d.ts.map +1 -0
- package/build-types/components/media-editor-panel/index.d.ts +46 -0
- package/build-types/components/media-editor-panel/index.d.ts.map +1 -0
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/media-preview/index.d.ts.map +1 -1
- package/build-types/state/aspect-ratio-presets.d.ts +20 -3
- package/build-types/state/aspect-ratio-presets.d.ts.map +1 -1
- package/build-types/state/composite-reducer.d.ts +17 -19
- package/build-types/state/composite-reducer.d.ts.map +1 -1
- package/build-types/state/index.d.ts +2 -5
- package/build-types/state/index.d.ts.map +1 -1
- package/build-types/state/types.d.ts +20 -64
- package/build-types/state/types.d.ts.map +1 -1
- package/build-types/state/use-media-editor-state.d.ts +40 -54
- package/build-types/state/use-media-editor-state.d.ts.map +1 -1
- package/build-types/utils/get-media-type.d.ts +3 -1
- package/build-types/utils/get-media-type.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -1
- package/build-types/utils/index.d.ts.map +1 -1
- package/package.json +27 -24
- package/src/components/media-editor/index.tsx +372 -142
- package/src/components/media-editor/style.scss +21 -1
- package/src/components/media-editor/use-crop-options.ts +7 -11
- package/src/components/media-editor/use-save-media-editor.ts +48 -6
- package/src/components/media-editor-canvas/index.tsx +15 -26
- package/src/components/media-editor-canvas/style.scss +6 -6
- package/src/components/media-editor-crop-panel/index.tsx +38 -2
- package/src/components/media-editor-crop-panel/style.scss +21 -0
- package/src/components/media-editor-fine-rotation/index.tsx +6 -6
- package/src/components/media-editor-image-controls/index.tsx +11 -9
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +56 -63
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +1 -1
- package/src/components/media-editor-modal/index.tsx +4 -1
- package/src/components/media-editor-panel/error-boundary.tsx +88 -0
- package/src/components/media-editor-panel/index.tsx +211 -0
- package/src/components/media-form/index.tsx +7 -1
- package/src/components/media-preview/index.tsx +195 -37
- package/src/components/media-preview/style.scss +11 -32
- package/src/components/rotation-ruler/style.scss +3 -3
- package/src/state/README.md +34 -0
- package/src/state/aspect-ratio-presets.ts +22 -3
- package/src/state/composite-reducer.ts +42 -80
- package/src/state/index.ts +2 -18
- package/src/state/types.ts +18 -68
- package/src/state/use-media-editor-state.ts +162 -242
- package/src/style.scss +2 -1
- package/src/utils/get-media-type.ts +9 -1
- package/src/utils/index.ts +1 -1
- package/build/components/media-editor-modal/build-modifiers.cjs +0 -110
- package/build/components/media-editor-modal/build-modifiers.cjs.map +0 -1
- package/build/image-editor/core/camera.cjs +0 -277
- package/build/image-editor/core/camera.cjs.map +0 -1
- package/build/image-editor/core/constants.cjs +0 -133
- package/build/image-editor/core/constants.cjs.map +0 -1
- package/build/image-editor/core/containment.cjs +0 -289
- package/build/image-editor/core/containment.cjs.map +0 -1
- package/build/image-editor/core/crop-rect.cjs +0 -37
- package/build/image-editor/core/crop-rect.cjs.map +0 -1
- package/build/image-editor/core/export/canvas-renderer.cjs +0 -181
- package/build/image-editor/core/export/canvas-renderer.cjs.map +0 -1
- package/build/image-editor/core/index.cjs +0 -89
- package/build/image-editor/core/interaction-controller.cjs +0 -591
- package/build/image-editor/core/interaction-controller.cjs.map +0 -1
- package/build/image-editor/core/math/rotation.cjs +0 -32
- package/build/image-editor/core/math/rotation.cjs.map +0 -1
- package/build/image-editor/core/math/sanitize.cjs +0 -136
- package/build/image-editor/core/math/sanitize.cjs.map +0 -1
- package/build/image-editor/core/setter-helpers.cjs +0 -61
- package/build/image-editor/core/setter-helpers.cjs.map +0 -1
- package/build/image-editor/core/source-region.cjs +0 -236
- package/build/image-editor/core/source-region.cjs.map +0 -1
- package/build/image-editor/core/state.cjs +0 -296
- package/build/image-editor/core/state.cjs.map +0 -1
- package/build/image-editor/core/stencil-math.cjs +0 -203
- package/build/image-editor/core/stencil-math.cjs.map +0 -1
- package/build/image-editor/core/transform-style.cjs +0 -43
- package/build/image-editor/core/transform-style.cjs.map +0 -1
- package/build/image-editor/core/transforms/pipeline.cjs +0 -41
- package/build/image-editor/core/transforms/pipeline.cjs.map +0 -1
- package/build/image-editor/core/types.cjs +0 -5
- package/build/image-editor/core/viewport-state.cjs +0 -36
- package/build/image-editor/core/viewport-state.cjs.map +0 -1
- package/build/image-editor/index.cjs +0 -68
- package/build/image-editor/react/components/cropper-provider.cjs +0 -49
- package/build/image-editor/react/components/cropper-provider.cjs.map +0 -1
- package/build/image-editor/react/components/cropper.cjs +0 -595
- package/build/image-editor/react/components/cropper.cjs.map +0 -1
- package/build/image-editor/react/components/index.cjs +0 -25
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs +0 -147
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +0 -31
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +0 -61
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +0 -1
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +0 -367
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +0 -1
- package/build/image-editor/react/components/viewport-provider.cjs +0 -26
- package/build/image-editor/react/components/viewport-provider.cjs.map +0 -1
- package/build/image-editor/react/hooks/build-cropper-setters.cjs +0 -80
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +0 -1
- package/build/image-editor/react/hooks/index.cjs +0 -19
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +0 -104
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-cropper-controller.cjs +0 -80
- package/build/image-editor/react/hooks/use-cropper-controller.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-interaction.cjs +0 -187
- package/build/image-editor/react/hooks/use-interaction.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-transform-style.cjs +0 -24
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +0 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs +0 -40
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +0 -1
- package/build/image-editor/react/visually-hidden-style.cjs +0 -24
- package/build/image-editor/react/visually-hidden-style.cjs.map +0 -1
- package/build-module/components/media-editor-modal/build-modifiers.mjs +0 -105
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +0 -1
- package/build-module/image-editor/core/camera.mjs +0 -265
- package/build-module/image-editor/core/camera.mjs.map +0 -1
- package/build-module/image-editor/core/constants.mjs +0 -115
- package/build-module/image-editor/core/constants.mjs.map +0 -1
- package/build-module/image-editor/core/containment.mjs +0 -281
- package/build-module/image-editor/core/containment.mjs.map +0 -1
- package/build-module/image-editor/core/crop-rect.mjs +0 -32
- package/build-module/image-editor/core/crop-rect.mjs.map +0 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs +0 -170
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +0 -1
- package/build-module/image-editor/core/index.mjs +0 -7
- package/build-module/image-editor/core/interaction-controller.mjs +0 -586
- package/build-module/image-editor/core/interaction-controller.mjs.map +0 -1
- package/build-module/image-editor/core/math/rotation.mjs +0 -26
- package/build-module/image-editor/core/math/rotation.mjs.map +0 -1
- package/build-module/image-editor/core/math/sanitize.mjs +0 -127
- package/build-module/image-editor/core/math/sanitize.mjs.map +0 -1
- package/build-module/image-editor/core/setter-helpers.mjs +0 -56
- package/build-module/image-editor/core/setter-helpers.mjs.map +0 -1
- package/build-module/image-editor/core/source-region.mjs +0 -228
- package/build-module/image-editor/core/source-region.mjs.map +0 -1
- package/build-module/image-editor/core/state.mjs +0 -288
- package/build-module/image-editor/core/state.mjs.map +0 -1
- package/build-module/image-editor/core/stencil-math.mjs +0 -194
- package/build-module/image-editor/core/stencil-math.mjs.map +0 -1
- package/build-module/image-editor/core/transform-style.mjs +0 -38
- package/build-module/image-editor/core/transform-style.mjs.map +0 -1
- package/build-module/image-editor/core/transforms/pipeline.mjs +0 -35
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +0 -1
- package/build-module/image-editor/core/types.mjs +0 -0
- package/build-module/image-editor/core/viewport-state.mjs +0 -30
- package/build-module/image-editor/core/viewport-state.mjs.map +0 -1
- package/build-module/image-editor/index.mjs +0 -4
- package/build-module/image-editor/react/components/cropper-provider.mjs +0 -43
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +0 -1
- package/build-module/image-editor/react/components/cropper.mjs +0 -568
- package/build-module/image-editor/react/components/cropper.mjs.map +0 -1
- package/build-module/image-editor/react/components/index.mjs +0 -3
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs +0 -142
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +0 -26
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +0 -56
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +0 -1
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +0 -362
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +0 -1
- package/build-module/image-editor/react/components/viewport-provider.mjs +0 -20
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs +0 -75
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/index.mjs +0 -3
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +0 -99
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs +0 -75
- package/build-module/image-editor/react/hooks/use-cropper-controller.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-interaction.mjs +0 -182
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +0 -19
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +0 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +0 -35
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +0 -1
- package/build-module/image-editor/react/visually-hidden-style.mjs +0 -19
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +0 -1
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +0 -81
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +0 -1
- package/build-types/image-editor/core/camera.d.ts +0 -128
- package/build-types/image-editor/core/camera.d.ts.map +0 -1
- package/build-types/image-editor/core/constants.d.ts +0 -98
- package/build-types/image-editor/core/constants.d.ts.map +0 -1
- package/build-types/image-editor/core/containment.d.ts +0 -72
- package/build-types/image-editor/core/containment.d.ts.map +0 -1
- package/build-types/image-editor/core/crop-rect.d.ts +0 -16
- package/build-types/image-editor/core/crop-rect.d.ts.map +0 -1
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +0 -103
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +0 -1
- package/build-types/image-editor/core/index.d.ts +0 -10
- package/build-types/image-editor/core/index.d.ts.map +0 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +0 -191
- package/build-types/image-editor/core/interaction-controller.d.ts.map +0 -1
- package/build-types/image-editor/core/math/rotation.d.ts +0 -18
- package/build-types/image-editor/core/math/rotation.d.ts.map +0 -1
- package/build-types/image-editor/core/math/sanitize.d.ts +0 -67
- package/build-types/image-editor/core/math/sanitize.d.ts.map +0 -1
- package/build-types/image-editor/core/setter-helpers.d.ts +0 -21
- package/build-types/image-editor/core/setter-helpers.d.ts.map +0 -1
- package/build-types/image-editor/core/source-region.d.ts +0 -94
- package/build-types/image-editor/core/source-region.d.ts.map +0 -1
- package/build-types/image-editor/core/state.d.ts +0 -51
- package/build-types/image-editor/core/state.d.ts.map +0 -1
- package/build-types/image-editor/core/stencil-math.d.ts +0 -102
- package/build-types/image-editor/core/stencil-math.d.ts.map +0 -1
- package/build-types/image-editor/core/transform-style.d.ts +0 -20
- package/build-types/image-editor/core/transform-style.d.ts.map +0 -1
- package/build-types/image-editor/core/transforms/pipeline.d.ts +0 -24
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +0 -1
- package/build-types/image-editor/core/types.d.ts +0 -269
- package/build-types/image-editor/core/types.d.ts.map +0 -1
- package/build-types/image-editor/core/viewport-state.d.ts +0 -4
- package/build-types/image-editor/core/viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/index.d.ts +0 -17
- package/build-types/image-editor/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts +0 -38
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/components/cropper.d.ts +0 -54
- package/build-types/image-editor/react/components/cropper.d.ts.map +0 -1
- package/build-types/image-editor/react/components/index.d.ts +0 -4
- package/build-types/image-editor/react/components/index.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts +0 -33
- package/build-types/image-editor/react/components/overlays/dimensions-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +0 -17
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +0 -27
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +0 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +0 -33
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +0 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +0 -6
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts +0 -44
- package/build-types/image-editor/react/hooks/build-cropper-setters.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/index.d.ts +0 -5
- package/build-types/image-editor/react/hooks/index.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +0 -14
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts +0 -55
- package/build-types/image-editor/react/hooks/use-cropper-controller.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +0 -65
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +0 -13
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +0 -16
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +0 -1
- package/build-types/image-editor/react/visually-hidden-style.d.ts +0 -6
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +0 -1
- package/src/components/media-editor-modal/build-modifiers.ts +0 -167
- package/src/image-editor/README.md +0 -61
- package/src/image-editor/core/camera.ts +0 -429
- package/src/image-editor/core/constants.ts +0 -137
- package/src/image-editor/core/containment.ts +0 -469
- package/src/image-editor/core/crop-rect.ts +0 -42
- package/src/image-editor/core/export/canvas-renderer.ts +0 -250
- package/src/image-editor/core/index.ts +0 -43
- package/src/image-editor/core/interaction-controller.ts +0 -976
- package/src/image-editor/core/math/rotation.ts +0 -26
- package/src/image-editor/core/math/sanitize.ts +0 -155
- package/src/image-editor/core/setter-helpers.ts +0 -63
- package/src/image-editor/core/source-region.ts +0 -367
- package/src/image-editor/core/state.ts +0 -484
- package/src/image-editor/core/stencil-math.ts +0 -379
- package/src/image-editor/core/transform-style.ts +0 -56
- package/src/image-editor/core/transforms/pipeline.ts +0 -40
- package/src/image-editor/core/types.ts +0 -230
- package/src/image-editor/core/viewport-state.ts +0 -30
- package/src/image-editor/docs/architecture.md +0 -63
- package/src/image-editor/docs/recipes.md +0 -184
- package/src/image-editor/index.ts +0 -43
- package/src/image-editor/react/components/cropper-provider.tsx +0 -70
- package/src/image-editor/react/components/cropper.scss +0 -259
- package/src/image-editor/react/components/cropper.tsx +0 -1108
- package/src/image-editor/react/components/index.ts +0 -3
- package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +0 -262
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +0 -55
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +0 -77
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +0 -623
- package/src/image-editor/react/components/viewport-provider.tsx +0 -32
- package/src/image-editor/react/hooks/build-cropper-setters.ts +0 -102
- package/src/image-editor/react/hooks/index.ts +0 -4
- package/src/image-editor/react/hooks/use-aria-announcer.ts +0 -193
- package/src/image-editor/react/hooks/use-cropper-controller.ts +0 -197
- package/src/image-editor/react/hooks/use-interaction.ts +0 -294
- package/src/image-editor/react/hooks/use-transform-style.ts +0 -23
- package/src/image-editor/react/hooks/use-viewport-state.ts +0 -41
- package/src/image-editor/react/visually-hidden-style.ts +0 -15
- package/src/image-editor/style.scss +0 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
let fast_deep_equal_es6_index_js = require("fast-deep-equal/es6/index.js");
|
|
30
|
+
let _wordpress_components = require("@wordpress/components");
|
|
31
|
+
let _wordpress_element = require("@wordpress/element");
|
|
32
|
+
let _wordpress_warning = require("@wordpress/warning");
|
|
33
|
+
let ______utils_index_ts = require("../../utils/index.cjs");
|
|
34
|
+
let __error_boundary_tsx = require("./error-boundary.cjs");
|
|
35
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
fast_deep_equal_es6_index_js = __toESM(fast_deep_equal_es6_index_js);
|
|
37
|
+
_wordpress_warning = __toESM(_wordpress_warning);
|
|
38
|
+
__error_boundary_tsx = __toESM(__error_boundary_tsx);
|
|
39
|
+
// packages/media-editor/src/components/media-editor-panel/index.tsx
|
|
40
|
+
const MediaEditorPanelsContext = (0, _wordpress_element.createContext)(null);
|
|
41
|
+
const MediaEditorPanelsProvider = MediaEditorPanelsContext.Provider;
|
|
42
|
+
/** The `registerPlugin` scope the editor mounts. */
|
|
43
|
+
const MEDIA_EDITOR_PLUGIN_SCOPE = "media-editor";
|
|
44
|
+
/** `vendor/panel`: lowercase letters, digits and dashes, with one slash. */
|
|
45
|
+
const PANEL_NAME_PATTERN = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/;
|
|
46
|
+
function getPanelSlotName(name) {
|
|
47
|
+
return `MediaEditorPanel/${name}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The mounted panels of one editor.
|
|
51
|
+
*
|
|
52
|
+
* @return The panels, in the order they mounted, and the context value to provide to them.
|
|
53
|
+
*/
|
|
54
|
+
function useMediaEditorPanels() {
|
|
55
|
+
const [panels, setPanels] = (0, _wordpress_element.useState)({});
|
|
56
|
+
const ownersRef = (0, _wordpress_element.useRef)(/* @__PURE__ */ new Map());
|
|
57
|
+
const register = (0, _wordpress_element.useCallback)((panel, instance) => {
|
|
58
|
+
const owner = ownersRef.current.get(panel.name);
|
|
59
|
+
if (owner && owner !== instance) {
|
|
60
|
+
(0, _wordpress_warning.default)(`A media editor panel named "${panel.name}" is already registered, so this one is not shown. Give each panel a unique name.`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
ownersRef.current.set(panel.name, instance);
|
|
64
|
+
setPanels((current) => {
|
|
65
|
+
const entry = current[panel.name];
|
|
66
|
+
if (entry?.owner === instance && (0, fast_deep_equal_es6_index_js.default)(entry.registration, panel)) return current;
|
|
67
|
+
return {
|
|
68
|
+
...current,
|
|
69
|
+
[panel.name]: {
|
|
70
|
+
registration: panel,
|
|
71
|
+
owner: instance
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}, []);
|
|
76
|
+
const unregister = (0, _wordpress_element.useCallback)((name, instance) => {
|
|
77
|
+
if (ownersRef.current.get(name) !== instance) return;
|
|
78
|
+
ownersRef.current.delete(name);
|
|
79
|
+
setPanels((current) => {
|
|
80
|
+
if (!Object.hasOwn(current, name)) return current;
|
|
81
|
+
const next = { ...current };
|
|
82
|
+
delete next[name];
|
|
83
|
+
return next;
|
|
84
|
+
});
|
|
85
|
+
}, []);
|
|
86
|
+
const owners = (0, _wordpress_element.useMemo)(() => Object.fromEntries(Object.entries(panels).map(([name, { owner }]) => [name, owner])), [panels]);
|
|
87
|
+
const contextValue = (0, _wordpress_element.useMemo)(() => ({
|
|
88
|
+
register,
|
|
89
|
+
unregister,
|
|
90
|
+
owners
|
|
91
|
+
}), [
|
|
92
|
+
register,
|
|
93
|
+
unregister,
|
|
94
|
+
owners
|
|
95
|
+
]);
|
|
96
|
+
return {
|
|
97
|
+
panels: (0, _wordpress_element.useMemo)(() => Object.values(panels).map(({ registration }) => registration), [panels]),
|
|
98
|
+
contextValue
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** A tab in the media editor's sidebar, filled with its children. */
|
|
102
|
+
function MediaEditorPanel({ name, title, mediaTypes, children }) {
|
|
103
|
+
const context = (0, _wordpress_element.useContext)(MediaEditorPanelsContext);
|
|
104
|
+
if (!context) throw new Error("MediaEditorPanel is rendered outside the media editor.");
|
|
105
|
+
const { register, unregister, owners } = context;
|
|
106
|
+
const [instance] = (0, _wordpress_element.useState)(() => ({}));
|
|
107
|
+
const owner = owners[name];
|
|
108
|
+
(0, _wordpress_element.useLayoutEffect)(() => {
|
|
109
|
+
if (!PANEL_NAME_PATTERN.test(name)) (0, _wordpress_warning.default)(`The media editor panel name "${name}" should be namespaced, like "my-plugin/my-panel": lowercase letters, digits and dashes, with one slash.`);
|
|
110
|
+
mediaTypes?.forEach((type) => {
|
|
111
|
+
if (!______utils_index_ts.MEDIA_TYPES.includes(type)) (0, _wordpress_warning.default)(`The media editor panel "${name}" lists the media type "${type}", which the editor does not know, so the panel would never show for it. Known types: ${______utils_index_ts.MEDIA_TYPES.join(", ")}.`);
|
|
112
|
+
});
|
|
113
|
+
register({
|
|
114
|
+
name,
|
|
115
|
+
title,
|
|
116
|
+
mediaTypes
|
|
117
|
+
}, instance);
|
|
118
|
+
}, [
|
|
119
|
+
name,
|
|
120
|
+
title,
|
|
121
|
+
mediaTypes,
|
|
122
|
+
register,
|
|
123
|
+
owner,
|
|
124
|
+
instance
|
|
125
|
+
]);
|
|
126
|
+
(0, _wordpress_element.useLayoutEffect)(() => {
|
|
127
|
+
return () => unregister(name, instance);
|
|
128
|
+
}, [
|
|
129
|
+
name,
|
|
130
|
+
unregister,
|
|
131
|
+
instance
|
|
132
|
+
]);
|
|
133
|
+
if (owner !== instance) return null;
|
|
134
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Fill, {
|
|
135
|
+
name: getPanelSlotName(name),
|
|
136
|
+
children: (fillProps) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__error_boundary_tsx.default, {
|
|
137
|
+
title,
|
|
138
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaEditorPanelContent, {
|
|
139
|
+
fillProps,
|
|
140
|
+
children
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Calls a function child inside the error boundary, so one that throws is
|
|
147
|
+
* caught there.
|
|
148
|
+
*/
|
|
149
|
+
function MediaEditorPanelContent({ fillProps, children }) {
|
|
150
|
+
return typeof children === "function" ? children(fillProps) : children;
|
|
151
|
+
}
|
|
152
|
+
exports.MEDIA_EDITOR_PLUGIN_SCOPE = MEDIA_EDITOR_PLUGIN_SCOPE;
|
|
153
|
+
exports.MediaEditorPanelsProvider = MediaEditorPanelsProvider;
|
|
154
|
+
exports.default = MediaEditorPanel;
|
|
155
|
+
exports.getPanelSlotName = getPanelSlotName;
|
|
156
|
+
exports.useMediaEditorPanels = useMediaEditorPanels;
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createContext","useState","useRef","useCallback","warning","fastDeepEqual","useMemo","useContext","useLayoutEffect","MEDIA_TYPES","Fill","MediaEditorPanelErrorBoundary"],"sources":["../../../src/components/media-editor-panel/index.tsx"],"sourcesContent":["import fastDeepEqual from 'fast-deep-equal/es6/index.js';\nimport { Fill } from '@wordpress/components';\nimport {\n\tcreateContext,\n\tuseCallback,\n\tuseContext,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport warning from '@wordpress/warning';\nimport type { ReactNode } from 'react';\nimport { MEDIA_TYPES, type MediaType } from '../../utils';\nimport MediaEditorPanelErrorBoundary from './error-boundary';\n\nexport interface MediaEditorPanelFillProps {\n\t/** `true` while a save is running. */\n\tdisabled: boolean;\n}\n\nexport interface MediaEditorPanelRegistration {\n\t/** Unique, namespaced name, for example `core/crop`. */\n\tname: string;\n\t/** Tab label. */\n\ttitle: string;\n\t/** Omitted means every type. */\n\tmediaTypes?: readonly MediaType[ 'type' ][];\n}\n\nexport interface MediaEditorPanelProps extends MediaEditorPanelRegistration {\n\tchildren:\n\t\tReactNode | ( ( fillProps: MediaEditorPanelFillProps ) => ReactNode );\n}\n\ninterface MediaEditorPanelsContextValue {\n\tregister: ( panel: MediaEditorPanelRegistration, instance: object ) => void;\n\tunregister: ( name: string, instance: object ) => void;\n\t/** Panel name to the mounted panel that has it. */\n\towners: Record< string, object >;\n}\n\nconst MediaEditorPanelsContext =\n\tcreateContext< MediaEditorPanelsContextValue | null >( null );\n\nexport const MediaEditorPanelsProvider = MediaEditorPanelsContext.Provider;\n\n/** The `registerPlugin` scope the editor mounts. */\nexport const MEDIA_EDITOR_PLUGIN_SCOPE = 'media-editor';\n\n/** `vendor/panel`: lowercase letters, digits and dashes, with one slash. */\nconst PANEL_NAME_PATTERN = /^[a-z][a-z0-9-]*\\/[a-z][a-z0-9-]*$/;\n\nexport function getPanelSlotName( name: string ) {\n\treturn `MediaEditorPanel/${ name }`;\n}\n\n/**\n * The mounted panels of one editor.\n *\n * @return The panels, in the order they mounted, and the context value to provide to them.\n */\nexport function useMediaEditorPanels() {\n\tconst [ panels, setPanels ] = useState<\n\t\tRecord<\n\t\t\tstring,\n\t\t\t{ registration: MediaEditorPanelRegistration; owner: object }\n\t\t>\n\t>( {} );\n\t// The first panel to announce a name keeps it. A ref, so panels\n\t// announcing in the same commit see each other.\n\tconst ownersRef = useRef( new Map< string, object >() );\n\tconst register = useCallback(\n\t\t( panel: MediaEditorPanelRegistration, instance: object ) => {\n\t\t\tconst owner = ownersRef.current.get( panel.name );\n\t\t\tif ( owner && owner !== instance ) {\n\t\t\t\twarning(\n\t\t\t\t\t`A media editor panel named \"${ panel.name }\" is already registered, so this one is not shown. Give each panel a unique name.`\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\townersRef.current.set( panel.name, instance );\n\t\t\tsetPanels( ( current ) => {\n\t\t\t\t// Skip unchanged details: an inline `mediaTypes` array would\n\t\t\t\t// otherwise re-render the editor and the panel in a loop.\n\t\t\t\tconst entry = current[ panel.name ];\n\t\t\t\tif (\n\t\t\t\t\tentry?.owner === instance &&\n\t\t\t\t\tfastDeepEqual( entry.registration, panel )\n\t\t\t\t) {\n\t\t\t\t\treturn current;\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\t...current,\n\t\t\t\t\t[ panel.name ]: { registration: panel, owner: instance },\n\t\t\t\t};\n\t\t\t} );\n\t\t},\n\t\t[]\n\t);\n\tconst unregister = useCallback( ( name: string, instance: object ) => {\n\t\tif ( ownersRef.current.get( name ) !== instance ) {\n\t\t\treturn;\n\t\t}\n\t\townersRef.current.delete( name );\n\t\tsetPanels( ( current ) => {\n\t\t\tif ( ! Object.hasOwn( current, name ) ) {\n\t\t\t\treturn current;\n\t\t\t}\n\t\t\tconst next = { ...current };\n\t\t\tdelete next[ name ];\n\t\t\treturn next;\n\t\t} );\n\t}, [] );\n\tconst owners = useMemo(\n\t\t() =>\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries( panels ).map( ( [ name, { owner } ] ) => [\n\t\t\t\t\tname,\n\t\t\t\t\towner,\n\t\t\t\t] )\n\t\t\t),\n\t\t[ panels ]\n\t);\n\tconst contextValue = useMemo(\n\t\t() => ( { register, unregister, owners } ),\n\t\t[ register, unregister, owners ]\n\t);\n\tconst registrations = useMemo(\n\t\t() =>\n\t\t\tObject.values( panels ).map( ( { registration } ) => registration ),\n\t\t[ panels ]\n\t);\n\treturn { panels: registrations, contextValue };\n}\n\n/** A tab in the media editor's sidebar, filled with its children. */\nexport default function MediaEditorPanel( {\n\tname,\n\ttitle,\n\tmediaTypes,\n\tchildren,\n}: MediaEditorPanelProps ) {\n\tconst context = useContext( MediaEditorPanelsContext );\n\tif ( ! context ) {\n\t\tthrow new Error(\n\t\t\t'MediaEditorPanel is rendered outside the media editor.'\n\t\t);\n\t}\n\tconst { register, unregister, owners } = context;\n\t// Identifies this mounted panel.\n\tconst [ instance ] = useState( () => ( {} ) );\n\tconst owner = owners[ name ];\n\t// Layout effects, so the tab exists before the sidebar paints. Two of\n\t// them: details may change on any render, but the tab only goes when\n\t// the panel unmounts or changes its name.\n\tuseLayoutEffect( () => {\n\t\tif ( ! PANEL_NAME_PATTERN.test( name ) ) {\n\t\t\twarning(\n\t\t\t\t`The media editor panel name \"${ name }\" should be namespaced, like \"my-plugin/my-panel\": lowercase letters, digits and dashes, with one slash.`\n\t\t\t);\n\t\t}\n\t\tmediaTypes?.forEach( ( type ) => {\n\t\t\tif ( ! MEDIA_TYPES.includes( type ) ) {\n\t\t\t\twarning(\n\t\t\t\t\t`The media editor panel \"${ name }\" lists the media type \"${ type }\", which the editor does not know, so the panel would never show for it. Known types: ${ MEDIA_TYPES.join( ', ' ) }.`\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\t\tregister( { name, title, mediaTypes }, instance );\n\t\t// When two panels share a name, the second waits for the first to\n\t\t// unmount. `owner` changes at that point, which re-runs this effect\n\t\t// and gives the second panel the tab.\n\t}, [ name, title, mediaTypes, register, owner, instance ] );\n\tuseLayoutEffect( () => {\n\t\treturn () => unregister( name, instance );\n\t}, [ name, unregister, instance ] );\n\n\tif ( owner !== instance ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Fill name={ getPanelSlotName( name ) }>\n\t\t\t{ ( fillProps ) => (\n\t\t\t\t<MediaEditorPanelErrorBoundary title={ title }>\n\t\t\t\t\t<MediaEditorPanelContent\n\t\t\t\t\t\t// The slot passes exactly these props; `Fill` types them loosely.\n\t\t\t\t\t\tfillProps={ fillProps as MediaEditorPanelFillProps }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</MediaEditorPanelContent>\n\t\t\t\t</MediaEditorPanelErrorBoundary>\n\t\t\t) }\n\t\t</Fill>\n\t);\n}\n\n/**\n * Calls a function child inside the error boundary, so one that throws is\n * caught there.\n */\nfunction MediaEditorPanelContent( {\n\tfillProps,\n\tchildren,\n}: {\n\tfillProps: MediaEditorPanelFillProps;\n\tchildren: MediaEditorPanelProps[ 'children' ];\n} ) {\n\treturn typeof children === 'function' ? children( fillProps ) : children;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAM,4BAAA,GACLA,mBAAAA,cAAAA,CAAuD,IAAK;AAE7D,MAAa,4BAA4B,yBAAyB;;AAGlE,MAAa,4BAA4B;;AAGzC,MAAM,qBAAqB;AAE3B,SAAgB,iBAAkB,MAAe;CAChD,OAAO,oBAAqB;AAC7B;;;;;;AAOA,SAAgB,uBAAuB;CACtC,MAAM,CAAE,QAAQ,cAAA,GAAcC,mBAAAA,SAAAA,CAK3B,CAAC,CAAE;CAGN,MAAM,aAAA,GAAYC,mBAAAA,OAAAA,iBAAQ,IAAI,IAAsB,CAAE;CACtD,MAAM,YAAA,GAAWC,mBAAAA,YAAAA,EACd,OAAqC,aAAsB;EAC5D,MAAM,QAAQ,UAAU,QAAQ,IAAK,MAAM,IAAK;EAChD,IAAK,SAAS,UAAU,UAAW;GAClCC,CAAAA,GAAAA,mBAAAA,QAAAA,CACC,+BAAgC,MAAM,KAAM,kFAC7C;GACA;EACD;EACA,UAAU,QAAQ,IAAK,MAAM,MAAM,QAAS;EAC5C,WAAa,YAAa;GAGzB,MAAM,QAAQ,QAAS,MAAM;GAC7B,IACC,OAAO,UAAU,aAAA,GACjBC,6BAAAA,QAAAA,CAAe,MAAM,cAAc,KAAM,GAEzC,OAAO;GAER,OAAO;IACN,GAAG;KACD,MAAM,OAAQ;KAAE,cAAc;KAAO,OAAO;IAAS;GACxD;EACD,CAAE;CACH,GACA,CAAC,CACF;CACA,MAAM,cAAA,GAAaF,mBAAAA,YAAAA,EAAe,MAAc,aAAsB;EACrE,IAAK,UAAU,QAAQ,IAAK,IAAK,MAAM,UACtC;EAED,UAAU,QAAQ,OAAQ,IAAK;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EACF,SAAU;GAAE;GAAM;GAAO;EAAW,GAAG,QAAS;CAIjD,GAAG;EAAE;EAAM;EAAO;EAAY;EAAU;EAAO;CAAS,CAAE;CAC1DD,CAAAA,GAAAA,mBAAAA,gBAAAA,OAAuB;EACtB,aAAa,WAAY,MAAM,QAAS;CACzC,GAAG;EAAE;EAAM;EAAY;CAAS,CAAE;CAElC,IAAK,UAAU,UACd,OAAO;CAGR,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACE,sBAAAA,MAAD;EAAM,MAAO,iBAAkB,IAAK;EAC/B,WAAA,cACH,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,SAAD;GAAuC;GACtC,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,yBAAD;IAEa;IAEV;GACsB,CAAA;EACK,CAAA;CAE3B,CAAA;AAER;;;;;AAMA,SAAS,wBAAyB,EACjC,WACA,YAIG;CACH,OAAO,OAAO,aAAa,aAAa,SAAU,SAAU,IAAI;AACjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMediaEditorContext","WCSpinner","VStack","VisuallyHidden","__","DataForm"],"sources":["../../../src/components/media-form/index.tsx"],"sourcesContent":["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t'author',\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAM,eAAqB;CAC1B,QAAQ,EACP,MAAM,QACP;CACA,QAAQ;EACP,GAAG;GAAE;GAAS;GAAY;GAAW;EAAc,CAAC,CAAC,KAAO,QAAU;GACrE;GACA,QAAQ;IACP,MAAM;IACN,eAAe;GAChB;EACD,EAAI;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;CACD;AACD;;;;;;;;;;;;;;;AAwBA,SAAwB,UAAW,EAClC,MAAM,eACN,UACmB;CACnB,MAAM,EACL,OACA,QACA,MAAM,cACN,cAAA,GACGA,mCAAAA,sBAAAA,CAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAU;EACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAU;EACd,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,gBAAD;KAAgB,QAAS,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,CAAK,CAAA;KAC3BC,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,eAAgB;IACP,CAAA;IACd;IACF,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMediaEditorContext","WCSpinner","VStack","VisuallyHidden","__","DataForm"],"sources":["../../../src/components/media-form/index.tsx"],"sourcesContent":["import { DataForm } from '@wordpress/dataviews';\nimport type { Form } from '@wordpress/dataviews';\nimport {\n\tSpinner as WCSpinner,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { __ } from '@wordpress/i18n';\nimport type { ReactNode } from 'react';\nimport { useMediaEditorContext } from '../media-editor-provider';\n\n/*\n * The form used when neither the component nor the provider settings have\n * one, mirroring the `form` of the `attachment` view configuration on the\n * server. It lists the core attachment fields in a fixed order, so the layout\n * does not depend on the order the fields are passed in: the editable fields\n * first, in a regular layout, then the metadata and the file information, in\n * panels. A field it lists that is not passed renders nothing.\n */\nconst DEFAULT_FORM: Form = {\n\tlayout: {\n\t\ttype: 'panel',\n\t},\n\tfields: [\n\t\t...[ 'title', 'alt_text', 'caption', 'description' ].map( ( id ) => ( {\n\t\t\tid,\n\t\t\tlayout: {\n\t\t\t\ttype: 'regular' as const,\n\t\t\t\tlabelPosition: 'top' as const,\n\t\t\t},\n\t\t} ) ),\n\t\t'date',\n\t\t{\n\t\t\tid: 'author',\n\t\t\tlayout: {\n\t\t\t\ttype: 'panel' as const,\n\t\t\t\tshowPlaceholderIfEmpty: true,\n\t\t\t},\n\t\t},\n\t\t'filename',\n\t\t'mime_type',\n\t\t'filesize',\n\t\t'media_dimensions',\n\t\t'attached_to',\n\t],\n};\n\n/**\n * Props for MediaForm component.\n */\nexport interface MediaFormProps {\n\tform?: Form;\n\theader?: ReactNode;\n}\n\n/**\n * MediaForm component for editing media metadata.\n *\n * Renders a DataForm with fields for editing media properties like\n * title, alt text, caption, description, etc. The fields are laid out with\n * the `form` prop, else the form of the provider settings, else a default\n * form of the core attachment fields.\n *\n * @param props - Component props.\n * @param props.form - Optional form configuration, which takes precedence\n * over the form of the provider settings.\n * @param props.header - Optional header content to display above the form.\n * @return The MediaForm component.\n */\nexport default function MediaForm( {\n\tform: formOverrides,\n\theader,\n}: MediaFormProps ) {\n\tconst {\n\t\tmedia,\n\t\tfields,\n\t\tform: settingsForm,\n\t\tonChange,\n\t} = useMediaEditorContext();\n\n\tif ( ! media || ! onChange ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-form media-editor-form--loading\">\n\t\t\t\t<WCSpinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tconst form = formOverrides || settingsForm || DEFAULT_FORM;\n\n\treturn (\n\t\t<div className=\"media-editor-form\">\n\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t<VisuallyHidden render={ <h2 /> }>\n\t\t\t\t\t{ __( 'Media details' ) }\n\t\t\t\t</VisuallyHidden>\n\t\t\t\t{ header }\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ media }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ form }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,MAAM,eAAqB;CAC1B,QAAQ,EACP,MAAM,QACP;CACA,QAAQ;EACP,GAAG;GAAE;GAAS;GAAY;GAAW;EAAc,CAAC,CAAC,KAAO,QAAU;GACrE;GACA,QAAQ;IACP,MAAM;IACN,eAAe;GAChB;EACD,EAAI;EACJ;EACA;GACC,IAAI;GACJ,QAAQ;IACP,MAAM;IACN,wBAAwB;GACzB;EACD;EACA;EACA;EACA;EACA;EACA;CACD;AACD;;;;;;;;;;;;;;;AAwBA,SAAwB,UAAW,EAClC,MAAM,eACN,UACmB;CACnB,MAAM,EACL,OACA,QACA,MAAM,cACN,cAAA,GACGA,mCAAAA,sBAAAA,CAAsB;CAE1B,IAAK,CAAE,SAAS,CAAE,UACjB,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAU;EACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,SAAD,CAAY,CAAA;CACR,CAAA;CAIP,MAAM,OAAO,iBAAiB,gBAAgB;CAE9C,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,WAAU;EACd,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,sBAAD;GAAQ,SAAU;GAAlB,UAAA;IACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,gBAAD;KAAgB,QAAS,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,CAAK,CAAA;KAC3BC,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,eAAgB;IACP,CAAA;IACd;IACF,iBAAA,GAAA,kBAAA,IAAA,CAACC,qBAAAA,UAAD;KACC,MAAO;KACE;KACF;KACI;IACX,CAAA;GACM;;CACJ,CAAA;AAEP"}
|
|
@@ -3,36 +3,125 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
__esModule: { value: true },
|
|
4
4
|
[Symbol.toStringTag]: { value: "Module" }
|
|
5
5
|
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
let clsx = require("clsx");
|
|
30
|
+
let _wordpress_a11y = require("@wordpress/a11y");
|
|
6
31
|
let _wordpress_components = require("@wordpress/components");
|
|
32
|
+
let _wordpress_compose = require("@wordpress/compose");
|
|
7
33
|
let _wordpress_element = require("@wordpress/element");
|
|
8
34
|
let _wordpress_i18n = require("@wordpress/i18n");
|
|
35
|
+
let _wordpress_icons = require("@wordpress/icons");
|
|
36
|
+
let _wordpress_ui = require("@wordpress/ui");
|
|
9
37
|
let ___media_editor_provider_index_tsx = require("../media-editor-provider/index.cjs");
|
|
10
38
|
let ______utils_index_ts = require("../../utils/index.cjs");
|
|
11
39
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
clsx = __toESM(clsx);
|
|
12
41
|
// packages/media-editor/src/components/media-preview/index.tsx
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Returns the value of one of the attachment fields for the media, or an
|
|
44
|
+
* empty string if the field isn't available.
|
|
45
|
+
*
|
|
46
|
+
* @param fields The attachment fields.
|
|
47
|
+
* @param fieldId The id of the field to read.
|
|
48
|
+
* @param media The media record.
|
|
49
|
+
*/
|
|
50
|
+
function getFieldValue(fields, fieldId, media) {
|
|
51
|
+
const value = fields.find(({ id }) => id === fieldId)?.getValue?.({ item: media });
|
|
52
|
+
return typeof value === "string" ? value : "";
|
|
53
|
+
}
|
|
54
|
+
const COPY_FEEDBACK_TIMEOUT = 2e3;
|
|
55
|
+
const COPY_RESULT_ICONS = {
|
|
56
|
+
idle: _wordpress_icons.copy,
|
|
57
|
+
copied: _wordpress_icons.check,
|
|
58
|
+
error: _wordpress_icons.error
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Copies the text and shows the result on the copy button, following the
|
|
62
|
+
* Copy to Clipboard design system pattern.
|
|
63
|
+
*
|
|
64
|
+
* @param text The text to copy.
|
|
65
|
+
*/
|
|
66
|
+
function useCopyWithFeedback(text) {
|
|
67
|
+
const [feedback, setFeedback] = (0, _wordpress_element.useState)({
|
|
68
|
+
result: "idle",
|
|
69
|
+
id: 0
|
|
33
70
|
});
|
|
71
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
72
|
+
if (feedback.result === "idle") return;
|
|
73
|
+
const timeoutId = setTimeout(() => setFeedback({
|
|
74
|
+
result: "idle",
|
|
75
|
+
id: 0
|
|
76
|
+
}), COPY_FEEDBACK_TIMEOUT);
|
|
77
|
+
return () => clearTimeout(timeoutId);
|
|
78
|
+
}, [feedback]);
|
|
79
|
+
function report(result, message) {
|
|
80
|
+
setFeedback((current) => ({
|
|
81
|
+
result,
|
|
82
|
+
id: current.id + 1
|
|
83
|
+
}));
|
|
84
|
+
(0, _wordpress_a11y.speak)(message);
|
|
85
|
+
}
|
|
86
|
+
const ref = (0, _wordpress_compose.useCopyToClipboard)(text, () => report("copied", (0, _wordpress_i18n.__)("Copied URL to clipboard.")), () => report("error", (0, _wordpress_i18n.__)("Couldn't copy URL to clipboard.")));
|
|
87
|
+
return {
|
|
88
|
+
result: feedback.result,
|
|
89
|
+
ref
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function MediaPreviewFileActions({ mediaUrl }) {
|
|
93
|
+
const { result, ref } = useCopyWithFeedback(mediaUrl);
|
|
94
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
|
|
95
|
+
__next40pxDefaultSize: true,
|
|
96
|
+
variant: "primary",
|
|
97
|
+
href: mediaUrl,
|
|
98
|
+
target: "_blank",
|
|
99
|
+
download: true,
|
|
100
|
+
icon: _wordpress_icons.download,
|
|
101
|
+
children: (0, _wordpress_i18n.__)("Download")
|
|
102
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
|
|
103
|
+
__next40pxDefaultSize: true,
|
|
104
|
+
variant: "secondary",
|
|
105
|
+
ref,
|
|
106
|
+
icon: COPY_RESULT_ICONS[result],
|
|
107
|
+
children: (0, _wordpress_i18n.__)("Copy URL")
|
|
108
|
+
})] });
|
|
34
109
|
}
|
|
35
|
-
function
|
|
110
|
+
function MediaPreviewFileInfo({ mediaUrl, fileName, fileDetails }) {
|
|
111
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.EmptyState.Root, { children: [
|
|
112
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Icon, { icon: _wordpress_icons.folder }),
|
|
113
|
+
!!fileName && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Title, {
|
|
114
|
+
className: "media-editor-preview__file-name",
|
|
115
|
+
children: fileName
|
|
116
|
+
}),
|
|
117
|
+
!!fileDetails && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Description, { children: fileDetails }),
|
|
118
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Actions, {
|
|
119
|
+
className: "media-editor-preview__actions",
|
|
120
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileActions, { mediaUrl })
|
|
121
|
+
})
|
|
122
|
+
] });
|
|
123
|
+
}
|
|
124
|
+
function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, fileName, fileDetails, onLoad, onError, loadingState }) {
|
|
36
125
|
switch (previewType) {
|
|
37
126
|
case "image": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
38
127
|
className: loadingState === "loaded" ? "loaded" : "",
|
|
@@ -60,14 +149,14 @@ function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mim
|
|
|
60
149
|
"aria-label": (0, _wordpress_i18n.__)("Embed of the selected PDF file."),
|
|
61
150
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileInfo, {
|
|
62
151
|
mediaUrl,
|
|
63
|
-
|
|
64
|
-
|
|
152
|
+
fileName,
|
|
153
|
+
fileDetails
|
|
65
154
|
})
|
|
66
155
|
});
|
|
67
156
|
default: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileInfo, {
|
|
68
157
|
mediaUrl,
|
|
69
|
-
|
|
70
|
-
|
|
158
|
+
fileName,
|
|
159
|
+
fileDetails
|
|
71
160
|
});
|
|
72
161
|
}
|
|
73
162
|
}
|
|
@@ -80,25 +169,41 @@ function MediaPreviewContent({ previewType, mediaUrl, altText, displayTitle, mim
|
|
|
80
169
|
*/
|
|
81
170
|
function MediaPreview(props) {
|
|
82
171
|
const [loadingState, setLoadingState] = (0, _wordpress_element.useState)("loading");
|
|
83
|
-
const { media } = (0, ___media_editor_provider_index_tsx.useMediaEditorContext)();
|
|
172
|
+
const { media, fields } = (0, ___media_editor_provider_index_tsx.useMediaEditorContext)();
|
|
84
173
|
const { source_url: mediaUrl, mime_type: mimeType, alt_text: altText, title } = media || {};
|
|
85
174
|
const mediaType = (0, ______utils_index_ts.getMediaTypeFromMimeType)(mimeType);
|
|
86
175
|
const previewType = mimeType === "application/pdf" && window.navigator.pdfViewerEnabled ? "pdf" : mediaType.type;
|
|
87
176
|
if (!mediaUrl) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
88
|
-
className: "media-editor-preview media-editor-preview--empty",
|
|
89
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
90
|
-
});
|
|
91
|
-
if (loadingState === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
92
|
-
className: "media-editor-preview media-editor-preview--error",
|
|
93
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: (0, _wordpress_i18n.__)("Failed to load media file.") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
94
|
-
className: "media-editor-preview__url",
|
|
95
|
-
children: mediaUrl
|
|
96
|
-
})]
|
|
177
|
+
className: "media-editor-preview media-editor-preview--empty is-placeholder",
|
|
178
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.EmptyState.Root, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Icon, { icon: _wordpress_icons.folder }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Title, { children: (0, _wordpress_i18n.__)("No media file available.") })] })
|
|
97
179
|
});
|
|
98
180
|
const displayTitle = typeof title === "string" ? title : title?.rendered || title?.raw;
|
|
181
|
+
const fileName = media && getFieldValue(fields, "filename", media) || displayTitle;
|
|
182
|
+
const fileSize = media ? getFieldValue(fields, "filesize", media) : "";
|
|
183
|
+
const fileDetails = mimeType && fileSize ? (0, _wordpress_i18n.sprintf)(
|
|
184
|
+
/** translators: 1: File type, e.g. "application/zip". 2: File size, e.g. "2.4 MB". */
|
|
185
|
+
(0, _wordpress_i18n._x)("%1$s · %2$s", "file type and size"),
|
|
186
|
+
mimeType,
|
|
187
|
+
fileSize
|
|
188
|
+
) : mimeType || fileSize;
|
|
189
|
+
if (loadingState === "error") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
190
|
+
className: "media-editor-preview media-editor-preview--error is-placeholder",
|
|
191
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.EmptyState.Root, { children: [
|
|
192
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Icon, { icon: _wordpress_icons.folder }),
|
|
193
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Title, { children: (0, _wordpress_i18n.__)("Failed to load media file.") }),
|
|
194
|
+
!!fileName && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Description, {
|
|
195
|
+
className: "media-editor-preview__file-name",
|
|
196
|
+
children: fileName
|
|
197
|
+
}),
|
|
198
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.EmptyState.Actions, {
|
|
199
|
+
className: "media-editor-preview__actions",
|
|
200
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MediaPreviewFileActions, { mediaUrl })
|
|
201
|
+
})
|
|
202
|
+
] })
|
|
203
|
+
});
|
|
99
204
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
100
205
|
...props,
|
|
101
|
-
className:
|
|
206
|
+
className: (0, clsx.default)("media-editor-preview", `media-editor-preview--${previewType}`, { "is-placeholder": previewType === "application" }),
|
|
102
207
|
children: [previewType === "image" && loadingState === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
103
208
|
className: "media-editor-preview__spinner",
|
|
104
209
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Spinner, {})
|
|
@@ -107,7 +212,8 @@ function MediaPreview(props) {
|
|
|
107
212
|
mediaUrl,
|
|
108
213
|
altText,
|
|
109
214
|
displayTitle,
|
|
110
|
-
|
|
215
|
+
fileName,
|
|
216
|
+
fileDetails,
|
|
111
217
|
onLoad: () => setLoadingState("loaded"),
|
|
112
218
|
onError: () => setLoadingState("error"),
|
|
113
219
|
loadingState
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["__","useState","useMediaEditorContext","getMediaTypeFromMimeType","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,iBAAA,GAAA,kBAAA,KAAA,CAAC,OAAD;EAAK,WAAU;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":3,"file":"index.cjs","names":["copy","check","errorIcon","useState","useEffect","speak","useCopyToClipboard","__","Button","download","EmptyState","folder","useMediaEditorContext","getMediaTypeFromMimeType","sprintf","_x","clsx","WCSpinner"],"sources":["../../../src/components/media-preview/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { speak } from '@wordpress/a11y';\nimport { Button, Spinner as WCSpinner } from '@wordpress/components';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tcopy,\n\tdownload,\n\terror as errorIcon,\n\tfolder,\n} from '@wordpress/icons';\nimport { EmptyState } from '@wordpress/ui';\nimport { useMediaEditorContext } from '../media-editor-provider';\nimport type { Media } 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\tfileName?: string;\n\tfileDetails?: string;\n\tonLoad: () => void;\n\tonError: () => void;\n\tloadingState: 'loading' | 'loaded' | 'error';\n}\n\n/**\n * Returns the value of one of the attachment fields for the media, or an\n * empty string if the field isn't available.\n *\n * @param fields The attachment fields.\n * @param fieldId The id of the field to read.\n * @param media The media record.\n */\nfunction getFieldValue(\n\tfields: Array< {\n\t\tid: string;\n\t\tgetValue?: ( args: { item: Media } ) => unknown;\n\t} >,\n\tfieldId: string,\n\tmedia: Media\n): string {\n\tconst field = fields.find( ( { id } ) => id === fieldId );\n\tconst value = field?.getValue?.( { item: media } );\n\treturn typeof value === 'string' ? value : '';\n}\n\nconst COPY_FEEDBACK_TIMEOUT = 2000;\n\ntype CopyResult = 'idle' | 'copied' | 'error';\n\nconst COPY_RESULT_ICONS = {\n\tidle: copy,\n\tcopied: check,\n\terror: errorIcon,\n};\n\n/**\n * Copies the text and shows the result on the copy button, following the\n * Copy to Clipboard design system pattern.\n *\n * @param text The text to copy.\n */\nfunction useCopyWithFeedback( text: string ) {\n\t// Bump the id on every result, so a repeat of the same result restarts\n\t// the time the icon stays visible.\n\tconst [ feedback, setFeedback ] = useState< {\n\t\tresult: CopyResult;\n\t\tid: number;\n\t} >( { result: 'idle', id: 0 } );\n\n\tuseEffect( () => {\n\t\tif ( feedback.result === 'idle' ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeoutId = setTimeout(\n\t\t\t() => setFeedback( { result: 'idle', id: 0 } ),\n\t\t\tCOPY_FEEDBACK_TIMEOUT\n\t\t);\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ feedback ] );\n\n\tfunction report( result: Exclude< CopyResult, 'idle' >, message: string ) {\n\t\tsetFeedback( ( current ) => ( { result, id: current.id + 1 } ) );\n\t\tspeak( message );\n\t}\n\n\tconst ref = useCopyToClipboard(\n\t\ttext,\n\t\t() => report( 'copied', __( 'Copied URL to clipboard.' ) ),\n\t\t() => report( 'error', __( \"Couldn't copy URL to clipboard.\" ) )\n\t);\n\n\treturn { result: feedback.result, ref };\n}\n\nfunction MediaPreviewFileActions( { mediaUrl }: { mediaUrl: string } ) {\n\tconst { result, ref } = useCopyWithFeedback( mediaUrl );\n\n\treturn (\n\t\t<>\n\t\t\t{ /*\n\t\t\t * Browsers ignore `download` for cross-origin URLs, e.g. media\n\t\t\t * offloaded to a CDN, and show the file instead. Open it in a new\n\t\t\t * tab so it doesn't replace the editor.\n\t\t\t */ }\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvariant=\"primary\"\n\t\t\t\thref={ mediaUrl }\n\t\t\t\ttarget=\"_blank\"\n\t\t\t\tdownload\n\t\t\t\ticon={ download }\n\t\t\t>\n\t\t\t\t{ __( 'Download' ) }\n\t\t\t</Button>\n\t\t\t{ /* The label stays the same, and the icon shows the result. */ }\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tref={ ref }\n\t\t\t\ticon={ COPY_RESULT_ICONS[ result ] }\n\t\t\t>\n\t\t\t\t{ __( 'Copy URL' ) }\n\t\t\t</Button>\n\t\t</>\n\t);\n}\n\ninterface MediaPreviewFileInfoProps {\n\tmediaUrl: string;\n\tfileName?: string;\n\tfileDetails?: string;\n}\n\nfunction MediaPreviewFileInfo( {\n\tmediaUrl,\n\tfileName,\n\tfileDetails,\n}: MediaPreviewFileInfoProps ) {\n\treturn (\n\t\t<EmptyState.Root>\n\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t{ !! fileName && (\n\t\t\t\t<EmptyState.Title className=\"media-editor-preview__file-name\">\n\t\t\t\t\t{ fileName }\n\t\t\t\t</EmptyState.Title>\n\t\t\t) }\n\t\t\t{ !! fileDetails && (\n\t\t\t\t<EmptyState.Description>{ fileDetails }</EmptyState.Description>\n\t\t\t) }\n\t\t\t<EmptyState.Actions className=\"media-editor-preview__actions\">\n\t\t\t\t<MediaPreviewFileActions mediaUrl={ mediaUrl } />\n\t\t\t</EmptyState.Actions>\n\t\t</EmptyState.Root>\n\t);\n}\n\nfunction MediaPreviewContent( {\n\tpreviewType,\n\tmediaUrl,\n\taltText,\n\tdisplayTitle,\n\tfileName,\n\tfileDetails,\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\tfileName={ fileName }\n\t\t\t\t\t\tfileDetails={ fileDetails }\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\tfileName={ fileName }\n\t\t\t\t\tfileDetails={ fileDetails }\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, fields } = 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 is-placeholder\">\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'No media file available.' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t</EmptyState.Root>\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\t// Read through the attachment fields, so the values match the Details\n\t// panel. Without a filename field, fall back to the title.\n\tconst fileName =\n\t\t( media && getFieldValue( fields, 'filename', media ) ) || displayTitle;\n\tconst fileSize = media ? getFieldValue( fields, 'filesize', media ) : '';\n\tconst fileDetails =\n\t\tmimeType && fileSize\n\t\t\t? sprintf(\n\t\t\t\t\t/* translators: 1: File type, e.g. \"application/zip\". 2: File size, e.g. \"2.4 MB\". */\n\t\t\t\t\t_x( '%1$s · %2$s', 'file type and size' ),\n\t\t\t\t\tmimeType,\n\t\t\t\t\tfileSize\n\t\t\t\t)\n\t\t\t: mimeType || fileSize;\n\n\tif ( loadingState === 'error' ) {\n\t\treturn (\n\t\t\t<div className=\"media-editor-preview media-editor-preview--error is-placeholder\">\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ folder } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'Failed to load media file.' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t\t{ !! fileName && (\n\t\t\t\t\t\t<EmptyState.Description className=\"media-editor-preview__file-name\">\n\t\t\t\t\t\t\t{ fileName }\n\t\t\t\t\t\t</EmptyState.Description>\n\t\t\t\t\t) }\n\t\t\t\t\t<EmptyState.Actions className=\"media-editor-preview__actions\">\n\t\t\t\t\t\t<MediaPreviewFileActions mediaUrl={ mediaUrl } />\n\t\t\t\t\t</EmptyState.Actions>\n\t\t\t\t</EmptyState.Root>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\t{ ...props }\n\t\t\tclassName={ clsx(\n\t\t\t\t'media-editor-preview',\n\t\t\t\t`media-editor-preview--${ previewType }`,\n\t\t\t\t{\n\t\t\t\t\t// Media with no preview of its own shows the file info.\n\t\t\t\t\t'is-placeholder': previewType === 'application',\n\t\t\t\t}\n\t\t\t) }\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\tfileName={ fileName }\n\t\t\t\tfileDetails={ fileDetails }\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAS,cACR,QAIA,SACA,OACS;CAET,MAAM,QADQ,OAAO,MAAQ,EAAE,SAAU,OAAO,OAClC,CAAK,EAAE,WAAY,EAAE,MAAM,MAAM,CAAE;CACjD,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC5C;AAEA,MAAM,wBAAwB;AAI9B,MAAM,oBAAoB;CACzB,MAAMA,iBAAAA;CACN,QAAQC,i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+11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
11
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
12
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
15
|
-
key
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
+
desc = __getOwnPropDesc(from, key);
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
19
|
+
enumerable: !desc || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
return to;
|
|
22
24
|
};
|
|
@@ -25,10 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
27
|
enumerable: true
|
|
26
28
|
}) : target, mod));
|
|
27
29
|
let clsx = require("clsx");
|
|
28
|
-
clsx = __toESM(clsx);
|
|
29
30
|
let _wordpress_element = require("@wordpress/element");
|
|
30
31
|
let __use_ruler_drag_ts = require("./use-ruler-drag.cjs");
|
|
31
32
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
clsx = __toESM(clsx);
|
|
32
34
|
// packages/media-editor/src/components/rotation-ruler/index.tsx
|
|
33
35
|
const STRIP_HEIGHT = 32;
|
|
34
36
|
const LABEL_BASELINE_Y = 11;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["useMemo","useRef","useId","useRulerDrag","clampValue"],"sources":["../../../src/components/rotation-ruler/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\nimport { useId, useMemo, useRef } from '@wordpress/element';\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default: `°`.\n\t */\n\tunit?: string;\n\t/** CSS pixels of pointer travel per `step`. Default: 6. */\n\tpixelsPerStep?: number;\n\t/** Optional extra class for the wrapper. */\n\tclassName?: string;\n\t/**\n\t * Optional id for the underlying input; auto-generated when\n\t * omitted.\n\t */\n\tid?: string;\n\t/** When true, ignores all input. */\n\tdisabled?: boolean;\n}\n\nconst STRIP_HEIGHT = 32;\nconst LABEL_BASELINE_Y = 11;\nconst MAJOR_INTERVAL = 15;\nconst TICK_HEIGHT_MINOR = 4;\nconst TICK_HEIGHT_MID = 8;\nconst TICK_HEIGHT_MAJOR = 14;\n\ntype TickKind = 'minor' | 'mid' | 'major';\ninterface Tick {\n\tvalue: number;\n\tkind: TickKind;\n\theight: number;\n}\n\n/**\n * Build the tick list for the ruler strip.\n *\n * @param min Lower bound of the ruler in value units.\n * @param max Upper bound of the ruler in value units.\n */\nfunction useTicks( min: number, max: number ): Tick[] {\n\treturn useMemo( () => {\n\t\tconst out: Tick[] = [];\n\t\tfor ( let v = Math.ceil( min ); v <= Math.floor( max ); v += 1 ) {\n\t\t\tlet kind: TickKind = 'minor';\n\t\t\tlet height = TICK_HEIGHT_MINOR;\n\t\t\tif ( v % 15 === 0 ) {\n\t\t\t\tkind = 'major';\n\t\t\t\theight = TICK_HEIGHT_MAJOR;\n\t\t\t} else if ( v % 5 === 0 ) {\n\t\t\t\tkind = 'mid';\n\t\t\t\theight = TICK_HEIGHT_MID;\n\t\t\t}\n\t\t\tout.push( { value: v, kind, height } );\n\t\t}\n\t\treturn out;\n\t}, [ min, max ] );\n}\n\n/**\n * Format a numeric ruler value for display, trimming a trailing `.0`.\n *\n * @param value Value to format.\n */\nfunction formatValue( value: number ): string {\n\tconst rounded = Math.round( value * 10 ) / 10;\n\treturn Number.isInteger( rounded )\n\t\t? rounded.toFixed( 0 )\n\t\t: rounded.toFixed( 1 );\n}\n\n/**\n * Horizontal \"scrub-the-ruler\" slider for fine-grained numeric input\n * such as rotation in degrees.\n *\n * Renders a visually hidden `<input type=\"range\">` for assistive\n * technologies and keyboard input alongside a decorative tick strip\n * that the user can drag with a pointer.\n *\n * @param props Component props. See `RotationRulerProps`.\n */\nexport default function RotationRuler( props: RotationRulerProps ) {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin = -45,\n\t\tmax = 45,\n\t\tstep = 1,\n\t\tlabel,\n\t\tunit = '°',\n\t\tpixelsPerStep = 6,\n\t\tclassName,\n\t\tid,\n\t\tdisabled = false,\n\t} = props;\n\tconst inputRef = useRef< HTMLInputElement >( null );\n\tconst generatedId = useId();\n\tconst inputId = id ?? generatedId;\n\n\tconst dragHandlers = useRulerDrag( {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart: () => inputRef.current?.focus(),\n\t} );\n\n\tconst handleKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\t// WAI-ARIA slider keyboard pattern: Up/Right increment,\n\t\t// Down/Left decrement. Home / End / PageUp / PageDown fall\n\t\t// through to native input.\n\t\tconst isIncrement =\n\t\t\tevent.key === 'ArrowRight' || event.key === 'ArrowUp';\n\t\tconst isDecrement =\n\t\t\tevent.key === 'ArrowLeft' || event.key === 'ArrowDown';\n\t\tif ( ! isIncrement && ! isDecrement ) {\n\t\t\treturn;\n\t\t}\n\t\t// Always prevent default so the native input's own arrow-key\n\t\t// stepping doesn't double-fire `onChange` after our custom emit.\n\t\tevent.preventDefault();\n\t\tif ( disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst direction = isIncrement ? 1 : -1;\n\t\t// Shift halves the step for precision adjustment\n\t\t// (e.g. 0.5° rotation when step is 1°). Same modifier works\n\t\t// on drag — see `useRulerDrag`.\n\t\tconst magnitude = event.shiftKey ? step / 2 : step;\n\t\tconst next = clampValue( value + direction * magnitude, min, max );\n\t\tif ( next !== value ) {\n\t\t\tonChange( next );\n\t\t}\n\t};\n\n\tconst display = `${ formatValue( value ) }${ unit }`;\n\tconst ticks = useTicks( min, max );\n\t// Visual scale is locked to the gesture: 1 step of pointer travel\n\t// (`pixelsPerStep`) maps to `step` value units, so 1 value unit\n\t// renders at `pixelsPerStep / step` CSS pixels. This keeps the\n\t// ticks moving in lock-step with the pointer no matter what the\n\t// caller chooses for `pixelsPerStep` and `step`.\n\tconst pxPerUnit = pixelsPerStep / step;\n\t// `left: 50%` puts the SVG's left edge at the strip's centerline, so\n\t// without an additional `-50%` self-offset all ticks would render to\n\t// the right of the pointer. Combine the centering offset with the\n\t// value-driven offset so value=0 lands the SVG's center on the\n\t// pointer.\n\tconst stripStyle: CSSProperties = useMemo( () => {\n\t\tconst offset = -value * pxPerUnit;\n\t\treturn {\n\t\t\ttransform: `translateX(calc(-50% + ${ offset }px))`,\n\t\t};\n\t}, [ value, pxPerUnit ] );\n\n\t// Closest major (every 15°) to current value. Its normal label is\n\t// suppressed and replaced by the active label, which sits exactly\n\t// under the pointer and shows the precise current value when off-\n\t// major (e.g. \"-7°\") or the major itself when on-major (e.g. \"0°\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\t// Split the number into sign + digits so the sign is rendered in a\n\t// separate span and excluded from the active label's centering, the\n\t// same way the unit is.\n\tconst numberText = onMajor ? `${ closestMajor }` : formatValue( value );\n\tconst isNegative = numberText.startsWith( '-' );\n\tconst digits = isNegative ? numberText.slice( 1 ) : numberText;\n\tconst majorTicks = ticks.filter( ( tick ) => tick.kind === 'major' );\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'rotation-ruler', className ) }\n\t\t\trole=\"presentation\"\n\t\t\tdata-testid=\"rotation-ruler\"\n\t\t\tdata-disabled={ disabled || undefined }\n\t\t\t{ ...dragHandlers }\n\t\t>\n\t\t\t<input\n\t\t\t\tref={ inputRef }\n\t\t\t\tid={ inputId }\n\t\t\t\ttype=\"range\"\n\t\t\t\tclassName=\"rotation-ruler__input\"\n\t\t\t\tmin={ min }\n\t\t\t\tmax={ max }\n\t\t\t\tstep=\"any\"\n\t\t\t\tvalue={ value }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taria-label={ label }\n\t\t\t\taria-valuetext={ display }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tclampValue( event.target.valueAsNumber, min, max )\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tonKeyDown={ handleKeyDown }\n\t\t\t/>\n\t\t\t<div className=\"rotation-ruler__strip\" aria-hidden=\"true\">\n\t\t\t\t<svg\n\t\t\t\t\tclassName=\"rotation-ruler__ticks\"\n\t\t\t\t\tstyle={ stripStyle }\n\t\t\t\t\twidth={ ( max - min ) * pxPerUnit }\n\t\t\t\t\theight={ STRIP_HEIGHT }\n\t\t\t\t\tviewBox={ `${ min * pxPerUnit } 0 ${\n\t\t\t\t\t\t( max - min ) * pxPerUnit\n\t\t\t\t\t} ${ STRIP_HEIGHT }` }\n\t\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t>\n\t\t\t\t\t{ ticks.map( ( tick ) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx1={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\tx2={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty1={ STRIP_HEIGHT - tick.height }\n\t\t\t\t\t\t\ty2={ STRIP_HEIGHT }\n\t\t\t\t\t\t\tclassName={ `rotation-ruler__tick rotation-ruler__tick--${ tick.kind }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ majorTicks.map( ( tick ) => (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty={ LABEL_BASELINE_Y }\n\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\tclassName=\"rotation-ruler__label\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ tick.value }\n\t\t\t\t\t\t\t{ unit }\n\t\t\t\t\t\t</text>\n\t\t\t\t\t) ) }\n\t\t\t\t</svg>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__active-label\" aria-hidden=\"true\">\n\t\t\t\t<span className=\"rotation-ruler__active-label-number\">\n\t\t\t\t\t{ isNegative && (\n\t\t\t\t\t\t<span className=\"rotation-ruler__active-label-sign\">\n\t\t\t\t\t\t\t-\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ digits }\n\t\t\t\t\t<span className=\"rotation-ruler__active-label-unit\">\n\t\t\t\t\t\t{ unit }\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__pointer\" aria-hidden=\"true\" />\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,eAAe;AACrB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;;;;;;;AAe1B,SAAS,SAAU,KAAa,KAAsB;CACrD,QAAA,GA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OAAQ;KACR,QAAU,MAAM,OAAQ;KACxB,QAAS;KACT,SAAU,GAAI,MAAM,UAAW,MAC5B,MAAM,OAAQ,UAChB,GAAI;KACL,qBAAoB;KARrB,UAAA,CAUG,MAAM,KAAO,SACd,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;MAEC,IAAK,KAAK,QAAQ;MAClB,IAAK,KAAK,QAAQ;MAClB,IAAK,eAAe,KAAK;MACzB,IAAK;MACL,WAAY,8CAA+C,KAAK;KAChE,GANM,KAAK,KAMX,CACA,GACA,WAAW,KAAO,SACnB,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;MAEC,GAAI,KAAK,QAAQ;MACjB,GAAI;MACJ,YAAW;MACX,WAAU;MALX,UAAA,CAOG,KAAK,OACL,IACG;KARC,GAAA,KAAK,KAQN,CACL,CACE;;GACD,CAAA;GACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAA+B,eAAY;IACzD,UAAA,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;KAAM,WAAU;KAAhB,UAAA;MACG,cACD,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;OAAM,WAAU;OAAoC,UAAA;MAE9C,CAAA;MAEL;MACF,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;OAAM,WAAU;OACb,UAAA;MACG,CAAA;KACD;;GACF,CAAA;GACL,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IAA0B,eAAY;GAAQ,CAAA;EACzD;;AAEP"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useMemo","useRef","useId","useRulerDrag","clampValue","clsx"],"sources":["../../../src/components/rotation-ruler/index.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport type { CSSProperties, KeyboardEvent } from 'react';\nimport { useId, useMemo, useRef } from '@wordpress/element';\nimport { useRulerDrag, clampValue } from './use-ruler-drag';\n\nexport interface RotationRulerProps {\n\t/** Current value. */\n\tvalue: number;\n\t/** Called with the next value on each change. */\n\tonChange: ( value: number ) => void;\n\t/** Lower bound of the range. Default: -45. */\n\tmin?: number;\n\t/** Upper bound of the range. Default: 45. */\n\tmax?: number;\n\t/**\n\t * Value step for drag and keyboard arrows. Default: 1. Drag values\n\t * are quantized to multiples of `step`. Holding Shift during drag\n\t * or with arrow keys halves the step for precision adjustment.\n\t */\n\tstep?: number;\n\t/** Accessible label for the slider input. */\n\tlabel: string;\n\t/**\n\t * Unit suffix shown in the active label and `aria-valuetext`.\n\t * Default: `°`.\n\t */\n\tunit?: string;\n\t/** CSS pixels of pointer travel per `step`. Default: 6. */\n\tpixelsPerStep?: number;\n\t/** Optional extra class for the wrapper. */\n\tclassName?: string;\n\t/**\n\t * Optional id for the underlying input; auto-generated when\n\t * omitted.\n\t */\n\tid?: string;\n\t/** When true, ignores all input. */\n\tdisabled?: boolean;\n}\n\nconst STRIP_HEIGHT = 32;\nconst LABEL_BASELINE_Y = 11;\nconst MAJOR_INTERVAL = 15;\nconst TICK_HEIGHT_MINOR = 4;\nconst TICK_HEIGHT_MID = 8;\nconst TICK_HEIGHT_MAJOR = 14;\n\ntype TickKind = 'minor' | 'mid' | 'major';\ninterface Tick {\n\tvalue: number;\n\tkind: TickKind;\n\theight: number;\n}\n\n/**\n * Build the tick list for the ruler strip.\n *\n * @param min Lower bound of the ruler in value units.\n * @param max Upper bound of the ruler in value units.\n */\nfunction useTicks( min: number, max: number ): Tick[] {\n\treturn useMemo( () => {\n\t\tconst out: Tick[] = [];\n\t\tfor ( let v = Math.ceil( min ); v <= Math.floor( max ); v += 1 ) {\n\t\t\tlet kind: TickKind = 'minor';\n\t\t\tlet height = TICK_HEIGHT_MINOR;\n\t\t\tif ( v % 15 === 0 ) {\n\t\t\t\tkind = 'major';\n\t\t\t\theight = TICK_HEIGHT_MAJOR;\n\t\t\t} else if ( v % 5 === 0 ) {\n\t\t\t\tkind = 'mid';\n\t\t\t\theight = TICK_HEIGHT_MID;\n\t\t\t}\n\t\t\tout.push( { value: v, kind, height } );\n\t\t}\n\t\treturn out;\n\t}, [ min, max ] );\n}\n\n/**\n * Format a numeric ruler value for display, trimming a trailing `.0`.\n *\n * @param value Value to format.\n */\nfunction formatValue( value: number ): string {\n\tconst rounded = Math.round( value * 10 ) / 10;\n\treturn Number.isInteger( rounded )\n\t\t? rounded.toFixed( 0 )\n\t\t: rounded.toFixed( 1 );\n}\n\n/**\n * Horizontal \"scrub-the-ruler\" slider for fine-grained numeric input\n * such as rotation in degrees.\n *\n * Renders a visually hidden `<input type=\"range\">` for assistive\n * technologies and keyboard input alongside a decorative tick strip\n * that the user can drag with a pointer.\n *\n * @param props Component props. See `RotationRulerProps`.\n */\nexport default function RotationRuler( props: RotationRulerProps ) {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin = -45,\n\t\tmax = 45,\n\t\tstep = 1,\n\t\tlabel,\n\t\tunit = '°',\n\t\tpixelsPerStep = 6,\n\t\tclassName,\n\t\tid,\n\t\tdisabled = false,\n\t} = props;\n\tconst inputRef = useRef< HTMLInputElement >( null );\n\tconst generatedId = useId();\n\tconst inputId = id ?? generatedId;\n\n\tconst dragHandlers = useRulerDrag( {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart: () => inputRef.current?.focus(),\n\t} );\n\n\tconst handleKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {\n\t\t// WAI-ARIA slider keyboard pattern: Up/Right increment,\n\t\t// Down/Left decrement. Home / End / PageUp / PageDown fall\n\t\t// through to native input.\n\t\tconst isIncrement =\n\t\t\tevent.key === 'ArrowRight' || event.key === 'ArrowUp';\n\t\tconst isDecrement =\n\t\t\tevent.key === 'ArrowLeft' || event.key === 'ArrowDown';\n\t\tif ( ! isIncrement && ! isDecrement ) {\n\t\t\treturn;\n\t\t}\n\t\t// Always prevent default so the native input's own arrow-key\n\t\t// stepping doesn't double-fire `onChange` after our custom emit.\n\t\tevent.preventDefault();\n\t\tif ( disabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst direction = isIncrement ? 1 : -1;\n\t\t// Shift halves the step for precision adjustment\n\t\t// (e.g. 0.5° rotation when step is 1°). Same modifier works\n\t\t// on drag — see `useRulerDrag`.\n\t\tconst magnitude = event.shiftKey ? step / 2 : step;\n\t\tconst next = clampValue( value + direction * magnitude, min, max );\n\t\tif ( next !== value ) {\n\t\t\tonChange( next );\n\t\t}\n\t};\n\n\tconst display = `${ formatValue( value ) }${ unit }`;\n\tconst ticks = useTicks( min, max );\n\t// Visual scale is locked to the gesture: 1 step of pointer travel\n\t// (`pixelsPerStep`) maps to `step` value units, so 1 value unit\n\t// renders at `pixelsPerStep / step` CSS pixels. This keeps the\n\t// ticks moving in lock-step with the pointer no matter what the\n\t// caller chooses for `pixelsPerStep` and `step`.\n\tconst pxPerUnit = pixelsPerStep / step;\n\t// `left: 50%` puts the SVG's left edge at the strip's centerline, so\n\t// without an additional `-50%` self-offset all ticks would render to\n\t// the right of the pointer. Combine the centering offset with the\n\t// value-driven offset so value=0 lands the SVG's center on the\n\t// pointer.\n\tconst stripStyle: CSSProperties = useMemo( () => {\n\t\tconst offset = -value * pxPerUnit;\n\t\treturn {\n\t\t\ttransform: `translateX(calc(-50% + ${ offset }px))`,\n\t\t};\n\t}, [ value, pxPerUnit ] );\n\n\t// Closest major (every 15°) to current value. Its normal label is\n\t// suppressed and replaced by the active label, which sits exactly\n\t// under the pointer and shows the precise current value when off-\n\t// major (e.g. \"-7°\") or the major itself when on-major (e.g. \"0°\").\n\tconst closestMajor = Math.round( value / MAJOR_INTERVAL ) * MAJOR_INTERVAL;\n\tconst onMajor = Math.abs( value - closestMajor ) < 0.01;\n\t// Split the number into sign + digits so the sign is rendered in a\n\t// separate span and excluded from the active label's centering, the\n\t// same way the unit is.\n\tconst numberText = onMajor ? `${ closestMajor }` : formatValue( value );\n\tconst isNegative = numberText.startsWith( '-' );\n\tconst digits = isNegative ? numberText.slice( 1 ) : numberText;\n\tconst majorTicks = ticks.filter( ( tick ) => tick.kind === 'major' );\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'rotation-ruler', className ) }\n\t\t\trole=\"presentation\"\n\t\t\tdata-testid=\"rotation-ruler\"\n\t\t\tdata-disabled={ disabled || undefined }\n\t\t\t{ ...dragHandlers }\n\t\t>\n\t\t\t<input\n\t\t\t\tref={ inputRef }\n\t\t\t\tid={ inputId }\n\t\t\t\ttype=\"range\"\n\t\t\t\tclassName=\"rotation-ruler__input\"\n\t\t\t\tmin={ min }\n\t\t\t\tmax={ max }\n\t\t\t\tstep=\"any\"\n\t\t\t\tvalue={ value }\n\t\t\t\tdisabled={ disabled }\n\t\t\t\taria-label={ label }\n\t\t\t\taria-valuetext={ display }\n\t\t\t\tonChange={ ( event ) =>\n\t\t\t\t\tonChange(\n\t\t\t\t\t\tclampValue( event.target.valueAsNumber, min, max )\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tonKeyDown={ handleKeyDown }\n\t\t\t/>\n\t\t\t<div className=\"rotation-ruler__strip\" aria-hidden=\"true\">\n\t\t\t\t<svg\n\t\t\t\t\tclassName=\"rotation-ruler__ticks\"\n\t\t\t\t\tstyle={ stripStyle }\n\t\t\t\t\twidth={ ( max - min ) * pxPerUnit }\n\t\t\t\t\theight={ STRIP_HEIGHT }\n\t\t\t\t\tviewBox={ `${ min * pxPerUnit } 0 ${\n\t\t\t\t\t\t( max - min ) * pxPerUnit\n\t\t\t\t\t} ${ STRIP_HEIGHT }` }\n\t\t\t\t\tpreserveAspectRatio=\"xMidYMid meet\"\n\t\t\t\t>\n\t\t\t\t\t{ ticks.map( ( tick ) => (\n\t\t\t\t\t\t<line\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx1={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\tx2={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty1={ STRIP_HEIGHT - tick.height }\n\t\t\t\t\t\t\ty2={ STRIP_HEIGHT }\n\t\t\t\t\t\t\tclassName={ `rotation-ruler__tick rotation-ruler__tick--${ tick.kind }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t\t{ majorTicks.map( ( tick ) => (\n\t\t\t\t\t\t<text\n\t\t\t\t\t\t\tkey={ tick.value }\n\t\t\t\t\t\t\tx={ tick.value * pxPerUnit }\n\t\t\t\t\t\t\ty={ LABEL_BASELINE_Y }\n\t\t\t\t\t\t\ttextAnchor=\"middle\"\n\t\t\t\t\t\t\tclassName=\"rotation-ruler__label\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ tick.value }\n\t\t\t\t\t\t\t{ unit }\n\t\t\t\t\t\t</text>\n\t\t\t\t\t) ) }\n\t\t\t\t</svg>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__active-label\" aria-hidden=\"true\">\n\t\t\t\t<span className=\"rotation-ruler__active-label-number\">\n\t\t\t\t\t{ isNegative && (\n\t\t\t\t\t\t<span className=\"rotation-ruler__active-label-sign\">\n\t\t\t\t\t\t\t-\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ digits }\n\t\t\t\t\t<span className=\"rotation-ruler__active-label-unit\">\n\t\t\t\t\t\t{ unit }\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t</div>\n\t\t\t<div className=\"rotation-ruler__pointer\" aria-hidden=\"true\" />\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,eAAe;AACrB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;;;;;;;AAe1B,SAAS,SAAU,KAAa,KAAsB;CACrD,QAAA,GAAOA,mBAAAA,QAAAA,OAAe;EACrB,MAAM,MAAc,CAAC;EACrB,KAAM,IAAI,IAAI,KA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