@wordpress/media-editor 0.11.1 → 0.11.2-next.v.202606191442.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/build/components/media-editor/index.cjs.map +1 -1
- package/build/components/media-editor/use-crop-options.cjs.map +1 -1
- package/build/components/media-editor-canvas/index.cjs +63 -15
- package/build/components/media-editor-canvas/index.cjs.map +3 -3
- package/build/components/media-editor-fine-rotation/index.cjs.map +1 -1
- package/build/components/media-editor-image-controls/index.cjs +2 -2
- package/build/components/media-editor-image-controls/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +4 -4
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +2 -2
- package/build/components/media-editor-modal/build-modifiers.cjs.map +1 -1
- package/build/components/rotation-ruler/index.cjs +1 -1
- package/build/components/rotation-ruler/index.cjs.map +1 -1
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +1 -1
- package/build/image-editor/core/camera.cjs +13 -0
- package/build/image-editor/core/camera.cjs.map +2 -2
- package/build/image-editor/core/constants.cjs +12 -3
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs.map +1 -1
- package/build/image-editor/core/crop-rect.cjs.map +1 -1
- package/build/image-editor/core/export/canvas-renderer.cjs.map +1 -1
- package/build/image-editor/core/interaction-controller.cjs +9 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/math/sanitize.cjs.map +1 -1
- package/build/image-editor/core/setter-helpers.cjs.map +1 -1
- package/build/image-editor/core/source-region.cjs +111 -2
- package/build/image-editor/core/source-region.cjs.map +2 -2
- package/build/image-editor/core/state.cjs.map +1 -1
- package/build/image-editor/core/stencil-math.cjs +3 -4
- package/build/image-editor/core/stencil-math.cjs.map +2 -2
- package/build/image-editor/core/transform-style.cjs.map +1 -1
- package/build/image-editor/core/types.cjs.map +1 -1
- package/build/image-editor/react/components/cropper.cjs +232 -55
- package/build/image-editor/react/components/cropper.cjs.map +2 -2
- package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +1 -1
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +1 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +65 -19
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/hooks/build-cropper-setters.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs +1 -1
- package/build/image-editor/react/hooks/use-cropper-reducer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs.map +1 -1
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +1 -1
- package/build/index.cjs.map +1 -1
- package/build/state/types.cjs.map +1 -1
- package/build/state/use-media-editor-state.cjs +1 -1
- package/build/state/use-media-editor-state.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs.map +1 -1
- package/build-module/components/media-editor/use-crop-options.mjs.map +1 -1
- package/build-module/components/media-editor-canvas/index.mjs +55 -17
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-fine-rotation/index.mjs.map +1 -1
- package/build-module/components/media-editor-image-controls/index.mjs +2 -2
- package/build-module/components/media-editor-image-controls/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +4 -4
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +1 -1
- package/build-module/components/rotation-ruler/index.mjs +1 -1
- package/build-module/components/rotation-ruler/index.mjs.map +1 -1
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +1 -1
- package/build-module/image-editor/core/camera.mjs +12 -0
- package/build-module/image-editor/core/camera.mjs.map +2 -2
- package/build-module/image-editor/core/constants.mjs +8 -2
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs.map +1 -1
- package/build-module/image-editor/core/crop-rect.mjs.map +1 -1
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +1 -1
- package/build-module/image-editor/core/interaction-controller.mjs +9 -7
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/math/sanitize.mjs.map +1 -1
- package/build-module/image-editor/core/setter-helpers.mjs.map +1 -1
- package/build-module/image-editor/core/source-region.mjs +108 -1
- package/build-module/image-editor/core/source-region.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs.map +1 -1
- package/build-module/image-editor/core/stencil-math.mjs +3 -4
- package/build-module/image-editor/core/stencil-math.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/react/components/cropper.mjs +242 -57
- package/build-module/image-editor/react/components/cropper.mjs.map +2 -2
- package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +1 -1
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +1 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +2 -2
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +65 -19
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/build-cropper-setters.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs +1 -1
- package/build-module/image-editor/react/hooks/use-cropper-reducer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +1 -1
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-module/state/types.mjs.map +1 -1
- package/build-module/state/use-media-editor-state.mjs +1 -1
- package/build-module/state/use-media-editor-state.mjs.map +2 -2
- package/build-style/style-rtl.css +49 -6
- package/build-style/style.css +49 -6
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/image-editor/core/camera.d.ts +25 -1
- package/build-types/image-editor/core/camera.d.ts.map +1 -1
- package/build-types/image-editor/core/constants.d.ts +20 -1
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/source-region.d.ts +23 -1
- package/build-types/image-editor/core/source-region.d.ts.map +1 -1
- package/build-types/image-editor/core/stencil-math.d.ts +10 -5
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -1
- package/build-types/image-editor/core/types.d.ts +14 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +17 -14
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/package.json +25 -20
- package/src/components/media-editor/style.scss +21 -9
- package/src/components/media-editor-canvas/index.tsx +82 -13
- package/src/components/media-editor-canvas/style.scss +41 -0
- package/src/image-editor/core/camera.ts +60 -1
- package/src/image-editor/core/constants.ts +23 -1
- package/src/image-editor/core/interaction-controller.ts +25 -11
- package/src/image-editor/core/source-region.ts +202 -1
- package/src/image-editor/core/stencil-math.ts +23 -14
- package/src/image-editor/core/test/camera.ts +272 -1
- package/src/image-editor/core/test/interaction-controller.ts +100 -0
- package/src/image-editor/core/test/stencil-math.ts +120 -6
- package/src/image-editor/core/types.ts +17 -0
- package/src/image-editor/react/components/cropper.tsx +362 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +1 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +101 -32
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +169 -17
- package/src/image-editor/react/components/test/cropper.tsx +689 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +0 -24
- package/build-types/components/media-editor-toolbar/index.d.ts.map +0 -1
- package/build-types/components/media-editor-transform-controls/index.d.ts +0 -21
- package/build-types/components/media-editor-transform-controls/index.d.ts.map +0 -1
- package/build-types/components/media-form/sidebar-datetime-view.d.ts +0 -10
- package/build-types/components/media-form/sidebar-datetime-view.d.ts.map +0 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +0 -108
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/image-editor/react/components/stencils/rectangle-stencil.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseMemo,\n\tuseRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { StencilProps, NormalizedRect } from '../../../core/types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n} from '../../../core/constants';\nimport {\n\tcomputeFreeResizeRect,\n\tcomputeLockedResizeRect,\n\tcomputeShiftLockedResizeRect,\n\ttype HandlePosition,\n\ttype CropBounds,\n\ttype ResizeDragState,\n} from '../../../core/stencil-math';\nimport { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';\n\n/**\n * Corner handle positions only \u2014 used when aspect ratio is locked.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst CORNER_POSITIONS: HandlePosition[] = [ 'nw', 'ne', 'se', 'sw' ];\n\n/**\n * All handle positions rendered by the stencil.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst ALL_POSITIONS: HandlePosition[] = [\n\t'nw',\n\t'n',\n\t'ne',\n\t'e',\n\t'se',\n\t's',\n\t'sw',\n\t'w',\n];\n\n/**\n * Get the translated aria-label for a resize handle position.\n *\n * @param pos The handle position identifier.\n * @return The translated label string.\n */\nfunction getHandleLabel( pos: HandlePosition ): string {\n\tswitch ( pos ) {\n\t\tcase 'n':\n\t\t\treturn __( 'Resize top edge' );\n\t\tcase 's':\n\t\t\treturn __( 'Resize bottom edge' );\n\t\tcase 'e':\n\t\t\treturn __( 'Resize right edge' );\n\t\tcase 'w':\n\t\t\treturn __( 'Resize left edge' );\n\t\tcase 'nw':\n\t\t\treturn __( 'Resize top-left corner' );\n\t\tcase 'ne':\n\t\t\treturn __( 'Resize top-right corner' );\n\t\tcase 'sw':\n\t\t\treturn __( 'Resize bottom-left corner' );\n\t\tcase 'se':\n\t\t\treturn __( 'Resize bottom-right corner' );\n\t}\n}\n\n/** Delay before keyboard resize triggers settle (ms). */\nconst KEYBOARD_SETTLE_DELAY = 500;\n\n/**\n * Props for the RectangleStencil component.\n */\ntype RectangleStencilProps = StencilProps;\n\n/**\n * A rectangular crop stencil with resize handles.\n *\n * In freeform mode, handles resize the crop area. Clicks inside the\n * crop pass through to the container for image panning. The crop\n * auto-centers after resize via SETTLE_CROP.\n *\n * @param props Component props implementing StencilProps.\n * @param props.cropRect The crop rectangle in normalized coordinates.\n * @param props.containerSize The container element dimensions in pixels.\n * @param props.imageSize The rendered image dimensions in pixels.\n * @param props.onCropChange Callback fired when the crop rect changes.\n * @param props.onResizeStart Callback fired when a resize drag starts.\n * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).\n * @param props.aspectRatio Optional fixed aspect ratio (width / height).\n * @param props.freeformCrop Whether resize handles are shown.\n * @param props.stencilTransition CSS transition string for settle animation.\n * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).\n * @param props.onEscape Called when Escape is pressed on a resize handle.\n * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @return The rectangle stencil element.\n */\nexport function RectangleStencil( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tonCropChange,\n\tonResizeStart,\n\tonResizeEnd,\n\taspectRatio,\n\tfreeformCrop = false,\n\tstencilTransition,\n\tcropBounds,\n\tonEscape,\n\tminCropSize,\n}: RectangleStencilProps ) {\n\t// Use cropBounds from the camera if available, otherwise default to [0,1].\n\tconst boundsMinX = cropBounds?.minX ?? 0;\n\tconst boundsMinY = cropBounds?.minY ?? 0;\n\tconst boundsMaxX = cropBounds?.maxX ?? 1;\n\tconst boundsMaxY = cropBounds?.maxY ?? 1;\n\tconst bounds: CropBounds = useMemo(\n\t\t() => ( {\n\t\t\tminX: boundsMinX,\n\t\t\tminY: boundsMinY,\n\t\t\tmaxX: boundsMaxX,\n\t\t\tmaxY: boundsMaxY,\n\t\t} ),\n\t\t[ boundsMinX, boundsMinY, boundsMaxX, boundsMaxY ]\n\t);\n\tconst keyboardSettleTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\tconst keyboardResizeActiveRef = useRef( false );\n\tconst resizeHandleDescriptionId = useId();\n\tconst hasLockedRatio = !! ( aspectRatio && aspectRatio > 0 );\n\n\t// Clear the pending keyboard settle timer on unmount so it can't\n\t// fire onResizeEnd / dispatch onto an unmounted parent.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t};\n\t}, [] );\n\n\t// Latest callbacks for the drag listeners. The drag closure in\n\t// handlePointerDown reads from this ref so it always sees current\n\t// props without having to re-attach listeners mid-drag. Previously,\n\t// drag listeners lived in a useEffect that re-ran whenever `bounds`\n\t// changed (every SET_CROP_RECT dispatch), creating a window where\n\t// pointerup could be missed and the crop would never settle.\n\tconst latestHandlersRef = useRef< {\n\t\thasLockedRatio: boolean;\n\t\tcomputeLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tcomputeFreeRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tcomputeShiftLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tonCropChange: ( rect: NormalizedRect ) => void;\n\t\tonResizeEnd?: () => void;\n\t} | null >( null );\n\n\t// The normalized aspect ratio: the w/h ratio in normalized space that\n\t// produces the desired pixel aspect ratio.\n\t// pixelW = w * imageSize.width, pixelH = h * imageSize.height\n\t// pixelW / pixelH = aspectRatio => w / h = aspectRatio * imageSize.height / imageSize.width\n\tconst normalizedRatio = useMemo( () => {\n\t\tif ( ! hasLockedRatio || imageSize.width === 0 ) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn ( aspectRatio * imageSize.height ) / imageSize.width;\n\t}, [ aspectRatio, hasLockedRatio, imageSize.width, imageSize.height ] );\n\n\t// Convert normalized crop rect to pixel bounds, accounting for the\n\t// image offset within the container.\n\tconst offsetX = ( containerSize.width - imageSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - imageSize.height ) / 2;\n\tconst left = offsetX + cropRect.x * imageSize.width;\n\tconst top = offsetY + cropRect.y * imageSize.height;\n\tconst width = cropRect.width * imageSize.width;\n\tconst height = cropRect.height * imageSize.height;\n\n\t/**\n\t * Start a resize drag on a handle. Registers pointer listeners\n\t * synchronously so no events are missed between capture and the\n\t * next React commit.\n\t */\n\tconst handlePointerDown = useCallback(\n\t\t( handle: HandlePosition, event: React.PointerEvent ) => {\n\t\t\tif ( event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t\t// Blur any previously focused handle.\n\t\t\tconst ownerDoc = event.currentTarget.ownerDocument;\n\t\t\tif ( ownerDoc.activeElement instanceof HTMLElement ) {\n\t\t\t\townerDoc.activeElement.blur();\n\t\t\t}\n\t\t\t// Capture pointer so drag works across iframe boundaries.\n\t\t\tconst el = event.currentTarget as HTMLButtonElement;\n\t\t\tel.setPointerCapture( event.pointerId );\n\n\t\t\tconst drag: ResizeDragState = {\n\t\t\t\thandle,\n\t\t\t\tstartX: event.clientX,\n\t\t\t\tstartY: event.clientY,\n\t\t\t\tstartRect: { ...cropRect },\n\t\t\t};\n\n\t\t\t// RAF-throttle: stash the latest pointer position and\n\t\t\t// process it once per animation frame. Avoids dispatching\n\t\t\t// on every pointermove (which fires at much higher than\n\t\t\t// screen refresh rate) and matches the pan-drag path in\n\t\t\t// InteractionController.\n\t\t\tlet rafId = 0;\n\t\t\tlet latestX = event.clientX;\n\t\t\tlet latestY = event.clientY;\n\t\t\tlet latestShift = event.shiftKey;\n\n\t\t\tconst onMove = ( e: Event ) => {\n\t\t\t\tconst pe = e as PointerEvent;\n\t\t\t\tlatestX = pe.clientX;\n\t\t\t\tlatestY = pe.clientY;\n\t\t\t\tlatestShift = pe.shiftKey;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trafId = requestAnimationFrame( () => {\n\t\t\t\t\trafId = 0;\n\t\t\t\t\tconst h = latestHandlersRef.current;\n\t\t\t\t\tif ( ! h ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet newRect: NormalizedRect;\n\t\t\t\t\tif ( h.hasLockedRatio ) {\n\t\t\t\t\t\tnewRect = h.computeLockedRect( drag, latestX, latestY );\n\t\t\t\t\t} else if ( latestShift ) {\n\t\t\t\t\t\tnewRect = h.computeShiftLockedRect(\n\t\t\t\t\t\t\tdrag,\n\t\t\t\t\t\t\tlatestX,\n\t\t\t\t\t\t\tlatestY\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewRect = h.computeFreeRect( drag, latestX, latestY );\n\t\t\t\t\t}\n\t\t\t\t\th.onCropChange( newRect );\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Guard against duplicate firing: pointerup and\n\t\t\t// lostpointercapture both fire on normal release.\n\t\t\tlet ended = false;\n\t\t\tconst onEnd = () => {\n\t\t\t\tif ( ended ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tended = true;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\tcancelAnimationFrame( rafId );\n\t\t\t\t\trafId = 0;\n\t\t\t\t}\n\t\t\t\tel.removeEventListener( 'pointermove', onMove );\n\t\t\t\tel.removeEventListener( 'pointerup', onEnd );\n\t\t\t\tel.removeEventListener( 'lostpointercapture', onEnd );\n\t\t\t\tlatestHandlersRef.current?.onResizeEnd?.();\n\t\t\t\t// Restore focus to the handle so arrow keys work\n\t\t\t\t// immediately after a mouse drag. Browsers suppress\n\t\t\t\t// :focus-visible after pointer interactions, so the\n\t\t\t\t// focus ring stays hidden until the user presses a key.\n\t\t\t\tel.focus( { preventScroll: true } );\n\t\t\t};\n\n\t\t\tel.addEventListener( 'pointermove', onMove );\n\t\t\tel.addEventListener( 'pointerup', onEnd );\n\t\t\tel.addEventListener( 'lostpointercapture', onEnd );\n\n\t\t\tonResizeStart?.( handle );\n\t\t\t// Cancel any pending keyboard settle so it can't fire onResizeEnd\n\t\t\t// mid-drag if the user switches from keyboard to pointer within\n\t\t\t// the settle window.\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t},\n\t\t[ cropRect, onResizeStart ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a free (no aspect ratio) resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeFreeRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeFreeResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a locked-aspect-ratio corner resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tnormalizedRatio,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, normalizedRatio, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect when Shift is held during a freeform\n\t * resize \u2014 preserves the start rect's aspect ratio.\n\t */\n\tconst computeShiftLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeShiftLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\tlatestHandlersRef.current = {\n\t\thasLockedRatio,\n\t\tcomputeLockedRect,\n\t\tcomputeFreeRect,\n\t\tcomputeShiftLockedRect,\n\t\tonCropChange,\n\t\tonResizeEnd,\n\t};\n\n\t/**\n\t * Handle keyboard events on a resize handle.\n\t * Arrow keys resize; Escape returns focus to the canvas.\n\t * Shift multiplies the step size by 10 for coarser movement.\n\t */\n\tconst handleKeyDown = useCallback(\n\t\t( handle: HandlePosition, event: React.KeyboardEvent ) => {\n\t\t\tconst key = event.key;\n\n\t\t\tif ( key === 'Escape' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tonEscape?.();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tkey !== 'ArrowUp' &&\n\t\t\t\tkey !== 'ArrowDown' &&\n\t\t\t\tkey !== 'ArrowLeft' &&\n\t\t\t\tkey !== 'ArrowRight'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\n\t\t\tif ( ! keyboardResizeActiveRef.current ) {\n\t\t\t\tkeyboardResizeActiveRef.current = true;\n\t\t\t\tonResizeStart?.( handle );\n\t\t\t}\n\n\t\t\tconst scheduleKeyboardResizeEnd = () => {\n\t\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\t\tkeyboardSettleTimerRef.current = setTimeout( () => {\n\t\t\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\t\t\tonResizeEnd?.();\n\t\t\t\t}, KEYBOARD_SETTLE_DELAY );\n\t\t\t};\n\n\t\t\tconst step = event.shiftKey\n\t\t\t\t? DEFAULT_KEYBOARD_STEP * KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t\t: DEFAULT_KEYBOARD_STEP;\n\n\t\t\t// Determine the normalized delta from the arrow key.\n\t\t\tlet dx = 0;\n\t\t\tlet dy = 0;\n\t\t\tif ( key === 'ArrowLeft' ) {\n\t\t\t\tdx = -step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowRight' ) {\n\t\t\t\tdx = step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowUp' ) {\n\t\t\t\tdy = -step;\n\t\t\t}\n\t\t\tif ( key === 'ArrowDown' ) {\n\t\t\t\tdy = step;\n\t\t\t}\n\n\t\t\tif ( hasLockedRatio ) {\n\t\t\t\t// For locked aspect ratio, synthesize a drag from the\n\t\t\t\t// current rect and apply the delta via computeLockedRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tonCropChange(\n\t\t\t\t\tcomputeLockedRect( syntheticDrag, clientX, clientY )\n\t\t\t\t);\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t} else {\n\t\t\t\t// For freeform resize, synthesize a drag via computeFreeRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tonCropChange(\n\t\t\t\t\tcomputeFreeRect( syntheticDrag, clientX, clientY )\n\t\t\t\t);\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tcropRect,\n\t\t\thasLockedRatio,\n\t\t\timageSize.width,\n\t\t\timageSize.height,\n\t\t\tcomputeLockedRect,\n\t\t\tcomputeFreeRect,\n\t\t\tonCropChange,\n\t\t\tonResizeStart,\n\t\t\tonResizeEnd,\n\t\t\tonEscape,\n\t\t]\n\t);\n\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__stencil\"\n\t\t\tstyle={ {\n\t\t\t\tleft,\n\t\t\t\ttop,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\ttransition: stencilTransition,\n\t\t\t} }\n\t\t>\n\t\t\t{ freeformCrop && (\n\t\t\t\t<div\n\t\t\t\t\tid={ resizeHandleDescriptionId }\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Use arrow keys to resize the crop area. Hold Shift for larger steps.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /* The crop rectangle border. pointer-events: none is set in\n\t\t\t\t CSS so clicks pass through to the container for panning. */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__stencil-rect\"\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\theight: '100%',\n\t\t\t\t\ttop: 0,\n\t\t\t\t\tleft: 0,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ /* Resize handles \u2014 only in freeform mode.\n\t\t\t\t Semantics: role=\"button\" with aria-label describing\n\t\t\t\t which edge/corner. Arrow keys resize (onKeyDown).\n\t\t\t\t role=\"slider\" would be more precise but requires\n\t\t\t\t per-handle aria-valuemin/max/now which don't map\n\t\t\t\t cleanly to a 2D crop rect. */ }\n\t\t\t{ freeformCrop &&\n\t\t\t\thandles.map( ( pos ) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\tkey={ pos }\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName={ `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${ pos }` }\n\t\t\t\t\t\tonPointerDown={ ( event ) =>\n\t\t\t\t\t\t\thandlePointerDown( pos, event )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonTouchStart={ ( event ) => event.stopPropagation() }\n\t\t\t\t\t\tonKeyDown={ ( event ) => handleKeyDown( pos, event ) }\n\t\t\t\t\t\taria-label={ getHandleLabel( pos ) }\n\t\t\t\t\t\taria-describedby={ resizeHandleDescriptionId }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AAMnB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseMemo,\n\tuseRef,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { StencilProps, NormalizedRect } from '../../../core/types';\nimport {\n\tDEFAULT_KEYBOARD_STEP,\n\tKEYBOARD_SHIFT_STEP_MULTIPLIER,\n} from '../../../core/constants';\nimport {\n\tcomputeFreeResizeRect,\n\tcomputeLockedResizeRect,\n\tcomputeShiftLockedResizeRect,\n\ttype HandlePosition,\n\ttype CropBounds,\n\ttype ResizeDragState,\n\ttype ResizeDriverAxis,\n} from '../../../core/stencil-math';\nimport { VISUALLY_HIDDEN_STYLE } from '../../visually-hidden-style';\n\n/**\n * Corner handle positions only — used when aspect ratio is locked.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst CORNER_POSITIONS: HandlePosition[] = [ 'nw', 'ne', 'se', 'sw' ];\n\n/**\n * All handle positions rendered by the stencil.\n * Ordered clockwise from top-left for logical tab order.\n */\nconst ALL_POSITIONS: HandlePosition[] = [\n\t'nw',\n\t'n',\n\t'ne',\n\t'e',\n\t'se',\n\t's',\n\t'sw',\n\t'w',\n];\n\n/**\n * Get the translated aria-label for a resize handle position.\n *\n * @param pos The handle position identifier.\n * @return The translated label string.\n */\nfunction getHandleLabel( pos: HandlePosition ): string {\n\tswitch ( pos ) {\n\t\tcase 'n':\n\t\t\treturn __( 'Resize top edge' );\n\t\tcase 's':\n\t\t\treturn __( 'Resize bottom edge' );\n\t\tcase 'e':\n\t\t\treturn __( 'Resize right edge' );\n\t\tcase 'w':\n\t\t\treturn __( 'Resize left edge' );\n\t\tcase 'nw':\n\t\t\treturn __( 'Resize top-left corner' );\n\t\tcase 'ne':\n\t\t\treturn __( 'Resize top-right corner' );\n\t\tcase 'sw':\n\t\t\treturn __( 'Resize bottom-left corner' );\n\t\tcase 'se':\n\t\t\treturn __( 'Resize bottom-right corner' );\n\t}\n}\n\n/** Delay before keyboard resize triggers settle (ms). */\nconst KEYBOARD_SETTLE_DELAY = 500;\n\n/**\n * Props for the RectangleStencil component.\n */\ntype RectangleStencilProps = StencilProps;\n\n/**\n * A rectangular crop stencil with resize handles.\n *\n * In freeform mode, handles resize the crop area. Clicks inside the\n * crop pass through to the container for image panning. The crop\n * auto-centers after resize via SETTLE_CROP.\n *\n * @param props Component props implementing StencilProps.\n * @param props.cropRect The crop rectangle in normalized coordinates.\n * @param props.containerSize The container element dimensions in pixels.\n * @param props.imageSize The rendered image dimensions in pixels.\n * @param props.onCropChange Callback fired when the crop rect changes.\n * @param props.onResizeStart Callback fired when a resize drag starts.\n * @param props.onResizeEnd Callback fired when a resize drag ends (mouseup).\n * @param props.aspectRatio Optional fixed aspect ratio (width / height).\n * @param props.freeformCrop Whether resize handles are shown.\n * @param props.isResizeDisabled Whether resize handles should ignore pointer and keyboard input.\n * @param props.stencilTransition CSS transition string for settle animation.\n * @param props.cropBounds Maximum crop rect bounds from camera (zoom/rotation-aware).\n * @param props.onEscape Called when Escape is pressed on a resize handle.\n * @param props.minCropSize Minimum crop rect dimension in normalized space, per axis.\n * @param props.snapCropRect Optional post-processor for freeform resize output.\n * @param props.keyboardResizeStep Optional keyboard resize step in normalized space, per axis.\n * @return The rectangle stencil element.\n */\nexport function RectangleStencil( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tonCropChange,\n\tonResizeStart,\n\tonResizeEnd,\n\taspectRatio,\n\tfreeformCrop = false,\n\tisResizeDisabled = false,\n\tstencilTransition,\n\tcropBounds,\n\tonEscape,\n\tminCropSize,\n\tsnapCropRect,\n\tkeyboardResizeStep,\n}: RectangleStencilProps ) {\n\t// Use cropBounds from the camera if available, otherwise default to [0,1].\n\tconst boundsMinX = cropBounds?.minX ?? 0;\n\tconst boundsMinY = cropBounds?.minY ?? 0;\n\tconst boundsMaxX = cropBounds?.maxX ?? 1;\n\tconst boundsMaxY = cropBounds?.maxY ?? 1;\n\tconst bounds: CropBounds = useMemo(\n\t\t() => ( {\n\t\t\tminX: boundsMinX,\n\t\t\tminY: boundsMinY,\n\t\t\tmaxX: boundsMaxX,\n\t\t\tmaxY: boundsMaxY,\n\t\t} ),\n\t\t[ boundsMinX, boundsMinY, boundsMaxX, boundsMaxY ]\n\t);\n\tconst keyboardSettleTimerRef = useRef< ReturnType< typeof setTimeout > >();\n\tconst keyboardResizeActiveRef = useRef( false );\n\tconst resizeHandleDescriptionId = useId();\n\tconst hasLockedRatio = !! ( aspectRatio && aspectRatio > 0 );\n\tconst activePointerResizeRef = useRef< {\n\t\tcancel: ( notifyResizeEnd?: boolean ) => void;\n\t} | null >( null );\n\n\t// Clear the pending keyboard settle timer on unmount so it can't\n\t// fire onResizeEnd / dispatch onto an unmounted parent.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\tactivePointerResizeRef.current?.cancel( false );\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( isResizeDisabled ) {\n\t\t\tactivePointerResizeRef.current?.cancel();\n\t\t}\n\t}, [ isResizeDisabled ] );\n\n\t// Latest callbacks for the drag listeners. The drag closure in\n\t// handlePointerDown reads from this ref so it always sees current\n\t// props without having to re-attach listeners mid-drag. Previously,\n\t// drag listeners lived in a useEffect that re-ran whenever `bounds`\n\t// changed (every SET_CROP_RECT dispatch), creating a window where\n\t// pointerup could be missed and the crop would never settle.\n\tconst latestHandlersRef = useRef< {\n\t\thasLockedRatio: boolean;\n\t\tcomputeLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t) => NormalizedRect;\n\t\tcomputeFreeRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tcomputeShiftLockedRect: (\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t) => NormalizedRect;\n\t\tonCropChange: ( rect: NormalizedRect ) => void;\n\t\tonResizeEnd?: () => void;\n\t\tsnapCropRect?: (\n\t\t\trect: NormalizedRect,\n\t\t\thandle: HandlePosition\n\t\t) => NormalizedRect;\n\t} | null >( null );\n\n\t// The normalized aspect ratio: the w/h ratio in normalized space that\n\t// produces the desired pixel aspect ratio.\n\t// pixelW = w * imageSize.width, pixelH = h * imageSize.height\n\t// pixelW / pixelH = aspectRatio => w / h = aspectRatio * imageSize.height / imageSize.width\n\tconst normalizedRatio = useMemo( () => {\n\t\tif ( ! hasLockedRatio || imageSize.width === 0 ) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn ( aspectRatio * imageSize.height ) / imageSize.width;\n\t}, [ aspectRatio, hasLockedRatio, imageSize.width, imageSize.height ] );\n\n\t// Convert normalized crop rect to pixel bounds, accounting for the\n\t// image offset within the container.\n\tconst offsetX = ( containerSize.width - imageSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - imageSize.height ) / 2;\n\tconst left = offsetX + cropRect.x * imageSize.width;\n\tconst top = offsetY + cropRect.y * imageSize.height;\n\tconst width = cropRect.width * imageSize.width;\n\tconst height = cropRect.height * imageSize.height;\n\n\t/**\n\t * Start a resize drag on a handle. Registers pointer listeners\n\t * synchronously so no events are missed between capture and the\n\t * next React commit.\n\t */\n\tconst handlePointerDown = useCallback(\n\t\t( handle: HandlePosition, event: React.PointerEvent ) => {\n\t\t\tif (\n\t\t\t\tisResizeDisabled ||\n\t\t\t\t( event.pointerType === 'touch' && event.isPrimary === false )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t\t// Blur any previously focused handle.\n\t\t\tconst ownerDoc = event.currentTarget.ownerDocument;\n\t\t\tif ( ownerDoc.activeElement instanceof HTMLElement ) {\n\t\t\t\townerDoc.activeElement.blur();\n\t\t\t}\n\t\t\t// Capture pointer so drag works across iframe boundaries.\n\t\t\tconst el = event.currentTarget as HTMLButtonElement;\n\t\t\tel.setPointerCapture( event.pointerId );\n\n\t\t\tconst drag: ResizeDragState = {\n\t\t\t\thandle,\n\t\t\t\tstartX: event.clientX,\n\t\t\t\tstartY: event.clientY,\n\t\t\t\tstartRect: { ...cropRect },\n\t\t\t};\n\n\t\t\t// RAF-throttle: stash the latest pointer position and\n\t\t\t// process it once per animation frame. Avoids dispatching\n\t\t\t// on every pointermove (which fires at much higher than\n\t\t\t// screen refresh rate) and matches the pan-drag path in\n\t\t\t// InteractionController.\n\t\t\tlet rafId = 0;\n\t\t\tlet latestX = event.clientX;\n\t\t\tlet latestY = event.clientY;\n\t\t\tlet latestShift = event.shiftKey;\n\n\t\t\tconst onMove = ( e: Event ) => {\n\t\t\t\tconst pe = e as PointerEvent;\n\t\t\t\tlatestX = pe.clientX;\n\t\t\t\tlatestY = pe.clientY;\n\t\t\t\tlatestShift = pe.shiftKey;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trafId = requestAnimationFrame( () => {\n\t\t\t\t\trafId = 0;\n\t\t\t\t\tconst h = latestHandlersRef.current;\n\t\t\t\t\tif ( ! h ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlet newRect: NormalizedRect;\n\t\t\t\t\tif ( h.hasLockedRatio ) {\n\t\t\t\t\t\tnewRect = h.computeLockedRect( drag, latestX, latestY );\n\t\t\t\t\t} else if ( latestShift ) {\n\t\t\t\t\t\tnewRect = h.computeShiftLockedRect(\n\t\t\t\t\t\t\tdrag,\n\t\t\t\t\t\t\tlatestX,\n\t\t\t\t\t\t\tlatestY\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewRect = h.computeFreeRect( drag, latestX, latestY );\n\t\t\t\t\t\tnewRect =\n\t\t\t\t\t\t\th.snapCropRect?.( newRect, drag.handle ) ?? newRect;\n\t\t\t\t\t}\n\t\t\t\t\th.onCropChange( newRect );\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Guard against duplicate firing: pointerup and\n\t\t\t// lostpointercapture both fire on normal release.\n\t\t\tlet ended = false;\n\t\t\tconst endResize = (\n\t\t\t\tnotifyResizeEnd = true,\n\t\t\t\trestoreFocus = true\n\t\t\t) => {\n\t\t\t\tif ( ended ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tended = true;\n\t\t\t\tif ( rafId ) {\n\t\t\t\t\tcancelAnimationFrame( rafId );\n\t\t\t\t\trafId = 0;\n\t\t\t\t}\n\t\t\t\tel.removeEventListener( 'pointermove', onMove );\n\t\t\t\tel.removeEventListener( 'pointerup', onEnd );\n\t\t\t\tel.removeEventListener( 'lostpointercapture', onEnd );\n\t\t\t\tactivePointerResizeRef.current = null;\n\t\t\t\tif ( notifyResizeEnd ) {\n\t\t\t\t\tlatestHandlersRef.current?.onResizeEnd?.();\n\t\t\t\t}\n\t\t\t\t// Restore focus to the handle so arrow keys work\n\t\t\t\t// immediately after a mouse drag. Browsers suppress\n\t\t\t\t// :focus-visible after pointer interactions, so the\n\t\t\t\t// focus ring stays hidden until the user presses a key.\n\t\t\t\tif ( restoreFocus ) {\n\t\t\t\t\tel.focus( { preventScroll: true } );\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst cancelResize = ( notifyResizeEnd = true ) =>\n\t\t\t\tendResize( notifyResizeEnd, false );\n\t\t\tconst onEnd = () => endResize();\n\n\t\t\tel.addEventListener( 'pointermove', onMove );\n\t\t\tel.addEventListener( 'pointerup', onEnd );\n\t\t\tel.addEventListener( 'lostpointercapture', onEnd );\n\t\t\tactivePointerResizeRef.current = { cancel: cancelResize };\n\n\t\t\tonResizeStart?.( handle );\n\t\t\t// Cancel any pending keyboard settle so it can't fire onResizeEnd\n\t\t\t// mid-drag if the user switches from keyboard to pointer within\n\t\t\t// the settle window.\n\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t},\n\t\t[ cropRect, isResizeDisabled, onResizeStart ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a free (no aspect ratio) resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeFreeRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeFreeResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect for a locked-aspect-ratio corner resize.\n\t * Delegates to the pure function in core/stencil-math.ts.\n\t */\n\tconst computeLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number,\n\t\t\tdriverAxis?: ResizeDriverAxis\n\t\t): NormalizedRect =>\n\t\t\tcomputeLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tnormalizedRatio,\n\t\t\t\tminCropSize,\n\t\t\t\tdriverAxis\n\t\t\t),\n\t\t[ imageSize, bounds, normalizedRatio, minCropSize ]\n\t);\n\n\t/**\n\t * Compute the new crop rect when Shift is held during a freeform\n\t * resize — preserves the start rect's aspect ratio.\n\t */\n\tconst computeShiftLockedRect = useCallback(\n\t\t(\n\t\t\tdrag: ResizeDragState,\n\t\t\tclientX: number,\n\t\t\tclientY: number\n\t\t): NormalizedRect =>\n\t\t\tcomputeShiftLockedResizeRect(\n\t\t\t\tdrag,\n\t\t\t\tclientX,\n\t\t\t\tclientY,\n\t\t\t\timageSize,\n\t\t\t\tbounds,\n\t\t\t\tminCropSize\n\t\t\t),\n\t\t[ imageSize, bounds, minCropSize ]\n\t);\n\n\tlatestHandlersRef.current = {\n\t\thasLockedRatio,\n\t\tcomputeLockedRect,\n\t\tcomputeFreeRect,\n\t\tcomputeShiftLockedRect,\n\t\tonCropChange,\n\t\tonResizeEnd,\n\t\tsnapCropRect,\n\t};\n\n\t/**\n\t * Handle keyboard events on a resize handle.\n\t * Arrow keys resize; Escape returns focus to the canvas.\n\t * Shift multiplies the step size by 10 for coarser movement.\n\t */\n\tconst handleKeyDown = useCallback(\n\t\t( handle: HandlePosition, event: React.KeyboardEvent ) => {\n\t\t\tconst key = event.key;\n\n\t\t\tif ( isResizeDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( key === 'Escape' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tonEscape?.();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tkey !== 'ArrowUp' &&\n\t\t\t\tkey !== 'ArrowDown' &&\n\t\t\t\tkey !== 'ArrowLeft' &&\n\t\t\t\tkey !== 'ArrowRight'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\n\t\t\tif ( ! keyboardResizeActiveRef.current ) {\n\t\t\t\tkeyboardResizeActiveRef.current = true;\n\t\t\t\tonResizeStart?.( handle );\n\t\t\t}\n\n\t\t\tconst scheduleKeyboardResizeEnd = () => {\n\t\t\t\tclearTimeout( keyboardSettleTimerRef.current );\n\t\t\t\tkeyboardSettleTimerRef.current = setTimeout( () => {\n\t\t\t\t\tkeyboardResizeActiveRef.current = false;\n\t\t\t\t\tonResizeEnd?.();\n\t\t\t\t}, KEYBOARD_SETTLE_DELAY );\n\t\t\t};\n\n\t\t\tconst stepMultiplier = event.shiftKey\n\t\t\t\t? KEYBOARD_SHIFT_STEP_MULTIPLIER\n\t\t\t\t: 1;\n\t\t\tconst stepX = keyboardResizeStep?.width ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst stepY = keyboardResizeStep?.height ?? DEFAULT_KEYBOARD_STEP;\n\t\t\tconst adjustedStepX = stepX * stepMultiplier;\n\t\t\tconst adjustedStepY = stepY * stepMultiplier;\n\n\t\t\t// Determine the normalized delta from the arrow key.\n\t\t\tlet dx = 0;\n\t\t\tlet dy = 0;\n\t\t\tif ( key === 'ArrowLeft' ) {\n\t\t\t\tdx = -adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowRight' ) {\n\t\t\t\tdx = adjustedStepX;\n\t\t\t}\n\t\t\tif ( key === 'ArrowUp' ) {\n\t\t\t\tdy = -adjustedStepY;\n\t\t\t}\n\t\t\tif ( key === 'ArrowDown' ) {\n\t\t\t\tdy = adjustedStepY;\n\t\t\t}\n\t\t\tconst keyboardDriverAxis: ResizeDriverAxis =\n\t\t\t\tdx !== 0 ? 'width' : 'height';\n\n\t\t\tif ( hasLockedRatio ) {\n\t\t\t\t// For locked aspect ratio, synthesize a drag from the\n\t\t\t\t// current rect and apply the delta via computeLockedRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tonCropChange(\n\t\t\t\t\tcomputeLockedRect(\n\t\t\t\t\t\tsyntheticDrag,\n\t\t\t\t\t\tclientX,\n\t\t\t\t\t\tclientY,\n\t\t\t\t\t\tkeyboardDriverAxis\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t} else {\n\t\t\t\t// For freeform resize, synthesize a drag via computeFreeRect.\n\t\t\t\tconst syntheticDrag: ResizeDragState = {\n\t\t\t\t\thandle,\n\t\t\t\t\tstartX: 0,\n\t\t\t\t\tstartY: 0,\n\t\t\t\t\tstartRect: { ...cropRect },\n\t\t\t\t};\n\t\t\t\tconst clientX = dx * imageSize.width;\n\t\t\t\tconst clientY = dy * imageSize.height;\n\t\t\t\tconst rect = computeFreeRect( syntheticDrag, clientX, clientY );\n\t\t\t\tonCropChange( snapCropRect?.( rect, handle ) ?? rect );\n\t\t\t\tscheduleKeyboardResizeEnd();\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tcropRect,\n\t\t\thasLockedRatio,\n\t\t\timageSize.width,\n\t\t\timageSize.height,\n\t\t\tcomputeLockedRect,\n\t\t\tcomputeFreeRect,\n\t\t\tonCropChange,\n\t\t\tonResizeStart,\n\t\t\tonResizeEnd,\n\t\t\tonEscape,\n\t\t\tkeyboardResizeStep,\n\t\t\tsnapCropRect,\n\t\t\tisResizeDisabled,\n\t\t]\n\t);\n\n\tif ( containerSize.width === 0 || containerSize.height === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst handles = hasLockedRatio ? CORNER_POSITIONS : ALL_POSITIONS;\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"wp-media-editor-image-editor__stencil\"\n\t\t\tdata-testid=\"cropper-stencil\"\n\t\t\tstyle={ {\n\t\t\t\tleft,\n\t\t\t\ttop,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\ttransition: stencilTransition,\n\t\t\t} }\n\t\t>\n\t\t\t{ freeformCrop && (\n\t\t\t\t<div\n\t\t\t\t\tid={ resizeHandleDescriptionId }\n\t\t\t\t\tstyle={ VISUALLY_HIDDEN_STYLE }\n\t\t\t\t>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Use arrow keys to resize the crop area. Hold Shift for larger steps.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ /* The crop rectangle border. pointer-events: none is set in\n\t\t\t\t CSS so clicks pass through to the container for panning. */ }\n\t\t\t<div\n\t\t\t\tclassName=\"wp-media-editor-image-editor__stencil-rect\"\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth: '100%',\n\t\t\t\t\theight: '100%',\n\t\t\t\t\ttop: 0,\n\t\t\t\t\tleft: 0,\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ /* Resize handles — only in freeform mode.\n\t\t\t\t Semantics: role=\"button\" with aria-label describing\n\t\t\t\t which edge/corner. Arrow keys resize (onKeyDown).\n\t\t\t\t role=\"slider\" would be more precise but requires\n\t\t\t\t per-handle aria-valuemin/max/now which don't map\n\t\t\t\t cleanly to a 2D crop rect. */ }\n\t\t\t{ freeformCrop &&\n\t\t\t\thandles.map( ( pos ) => (\n\t\t\t\t\t<button\n\t\t\t\t\t\tkey={ pos }\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName={ `wp-media-editor-image-editor__handle wp-media-editor-image-editor__handle--${ pos }` }\n\t\t\t\t\t\tonPointerDown={ ( event ) =>\n\t\t\t\t\t\t\thandlePointerDown( pos, event )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonTouchStart={ ( event ) => {\n\t\t\t\t\t\t\tif ( event.touches.length < 2 ) {\n\t\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonKeyDown={ ( event ) => handleKeyDown( pos, event ) }\n\t\t\t\t\t\taria-label={ getHandleLabel( pos ) }\n\t\t\t\t\t\taria-describedby={ resizeHandleDescriptionId }\n\t\t\t\t\t/>\n\t\t\t\t) ) }\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AAMnB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP,SAAS,6BAA6B;AA2gBpC,SAYE,KAZF;AArgBF,IAAM,mBAAqC,CAAE,MAAM,MAAM,MAAM,IAAK;AAMpE,IAAM,gBAAkC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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;AAAA,UAbb;AAAA,QAcP,CACC;AAAA;AAAA;AAAA,EACJ;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/build-cropper-setters.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tCropperAction,\n\tCropperState,\n\tFlip,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tTransformOperation,\n} from '../../core/types';\nimport { buildFocalPointZoomAction } from '../../core/setter-helpers';\n\n/**\n * The named cropper setters shared by every hook that drives the\n * cropper reducer
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tCropperAction,\n\tCropperState,\n\tFlip,\n\tNormalizedPoint,\n\tNormalizedRect,\n\tTransformOperation,\n} from '../../core/types';\nimport { buildFocalPointZoomAction } from '../../core/setter-helpers';\n\n/**\n * The named cropper setters shared by every hook that drives the\n * cropper reducer — the pure `useCropperReducer` and any composite\n * store that delegates cropper actions (e.g. `useMediaEditorState`).\n *\n * `setImage` and `reset` are intentionally NOT included: each hook\n * has additional bookkeeping for them (dirty-baseline, history clear)\n * that doesn't fit a shared factory.\n */\nexport interface CropperSetters {\n\tsetPan: ( pan: NormalizedPoint ) => void;\n\tsetZoom: ( zoom: number ) => void;\n\tsetZoomAtPoint: ( zoom: number, pan: NormalizedPoint ) => void;\n\tsetRotation: ( rotation: number ) => void;\n\tsetFlip: ( flip: Flip ) => void;\n\ttoggleFlip: ( direction: 'horizontal' | 'vertical' ) => void;\n\tsnapRotate90: ( direction: 1 | -1 ) => void;\n\tsetCropRect: ( rect: NormalizedRect ) => void;\n\tsettleCrop: () => void;\n\tapplyOperation: ( op: TransformOperation ) => void;\n}\n\n/**\n * Build the named cropper setters from a dispatch function and a\n * state getter. The two consuming hooks differ in how they dispatch:\n *\n * - `useCropperReducer` dispatches directly into its `useReducer`.\n * - `useMediaEditorState` wraps cropper actions in a composite\n * `CROPPER` envelope so the history machinery can record them.\n *\n * Both pass their own dispatch function and a getter that returns\n * the current `CropperState`. The factory shape keeps the two hooks\n * in lockstep — add a setter here once, both hooks get it.\n *\n * @param dispatchCropperAction Apply a `CropperAction` to the\n * underlying reducer.\n * @param getCropperState Return the current `CropperState`.\n * Used by setters that need to read\n * the latest state to compute their\n * payload (focal-point zoom, flip toggle).\n * @return The named cropper setters.\n */\nexport function buildCropperSetters(\n\tdispatchCropperAction: ( action: CropperAction ) => void,\n\tgetCropperState: () => CropperState\n): CropperSetters {\n\treturn {\n\t\tsetPan: ( pan ) =>\n\t\t\tdispatchCropperAction( { type: 'SET_PAN', payload: pan } ),\n\t\tsetZoom: ( zoom ) => {\n\t\t\tconst action = buildFocalPointZoomAction( getCropperState(), zoom );\n\t\t\tif ( action ) {\n\t\t\t\tdispatchCropperAction( action );\n\t\t\t}\n\t\t},\n\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\t\t\tpayload: { zoom, pan },\n\t\t\t} ),\n\t\tsetRotation: ( rotation ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_ROTATION',\n\t\t\t\tpayload: rotation,\n\t\t\t} ),\n\t\tsetFlip: ( flip ) =>\n\t\t\tdispatchCropperAction( { type: 'SET_FLIP', payload: flip } ),\n\t\ttoggleFlip: ( direction ) => {\n\t\t\tconst { flip } = getCropperState();\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_FLIP',\n\t\t\t\tpayload: { ...flip, [ direction ]: ! flip[ direction ] },\n\t\t\t} );\n\t\t},\n\t\tsnapRotate90: ( direction ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SNAP_ROTATE_90',\n\t\t\t\tpayload: { direction },\n\t\t\t} ),\n\t\tsetCropRect: ( rect ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'SET_CROP_RECT',\n\t\t\t\tpayload: rect,\n\t\t\t} ),\n\t\tsettleCrop: () => dispatchCropperAction( { type: 'SETTLE_CROP' } ),\n\t\tapplyOperation: ( op ) =>\n\t\t\tdispatchCropperAction( {\n\t\t\t\ttype: 'APPLY_OPERATION',\n\t\t\t\tpayload: op,\n\t\t\t} ),\n\t};\n}\n"],
|
|
5
5
|
"mappings": ";AAWA,SAAS,iCAAiC;AA4CnC,SAAS,oBACf,uBACA,iBACiB;AACjB,SAAO;AAAA,IACN,QAAQ,CAAE,QACT,sBAAuB,EAAE,MAAM,WAAW,SAAS,IAAI,CAAE;AAAA,IAC1D,SAAS,CAAE,SAAU;AACpB,YAAM,SAAS,0BAA2B,gBAAgB,GAAG,IAAK;AAClE,UAAK,QAAS;AACb,8BAAuB,MAAO;AAAA,MAC/B;AAAA,IACD;AAAA,IACA,gBAAgB,CAAE,MAAM,QACvB,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS,EAAE,MAAM,IAAI;AAAA,IACtB,CAAE;AAAA,IACH,aAAa,CAAE,aACd,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA,IACV,CAAE;AAAA,IACH,SAAS,CAAE,SACV,sBAAuB,EAAE,MAAM,YAAY,SAAS,KAAK,CAAE;AAAA,IAC5D,YAAY,CAAE,cAAe;AAC5B,YAAM,EAAE,KAAK,IAAI,gBAAgB;AACjC,4BAAuB;AAAA,QACtB,MAAM;AAAA,QACN,SAAS,EAAE,GAAG,MAAM,CAAE,SAAU,GAAG,CAAE,KAAM,SAAU,EAAE;AAAA,MACxD,CAAE;AAAA,IACH;AAAA,IACA,cAAc,CAAE,cACf,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS,EAAE,UAAU;AAAA,IACtB,CAAE;AAAA,IACH,aAAa,CAAE,SACd,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA,IACV,CAAE;AAAA,IACH,YAAY,MAAM,sBAAuB,EAAE,MAAM,cAAc,CAAE;AAAA,IACjE,gBAAgB,CAAE,OACjB,sBAAuB;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA,IACV,CAAE;AAAA,EACJ;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -67,7 +67,7 @@ function useCropperReducer(initialState) {
|
|
|
67
67
|
(mimeType, quality) => {
|
|
68
68
|
if (!state.image) {
|
|
69
69
|
return Promise.reject(
|
|
70
|
-
new Error("No image loaded
|
|
70
|
+
new Error("No image loaded — call setImage first.")
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
return exportCroppedImage(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-cropper-reducer.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseReducer,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tCropperAction,\n\tNormalizedRect,\n\tSize,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\nimport {\n\tbuildCropperSetters,\n\ttype CropperSetters,\n} from './build-cropper-setters';\n\n/**\n * The cropper controller surface
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAWP,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,OAEM;AA0CP,SAAS,sBACR,GACA,GACU;AACV,SACC,GAAG,QAAQ,GAAG,OACd,GAAG,i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AA,UACd,IAAI,MAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseReducer,\n\tuseCallback,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tCropperState,\n\tCropperAction,\n\tNormalizedRect,\n\tSize,\n} from '../../core/types';\nimport { DEFAULT_STATE } from '../../core/constants';\nimport { exportCroppedImage } from '../../core/export/canvas-renderer';\nimport {\n\tcropperReducer,\n\tenforceContainment,\n\tisStateDirty,\n} from '../../core/state';\nimport {\n\tbuildCropperSetters,\n\ttype CropperSetters,\n} from './build-cropper-setters';\n\n/**\n * The cropper controller surface — the contract the Cropper component\n * and its interaction hooks consume.\n *\n * History (undo / redo / commitHistory) is intentionally NOT part of\n * this interface. The cropper is a pure state machine; history is a\n * higher-layer concern owned by a composite store\n * (see media-editor/src/state).\n */\nexport interface CropperController extends CropperSetters {\n\t/** The current cropper state (read-only). */\n\tstate: CropperState;\n\t/** Set the loaded image (natural size and src). */\n\tsetImage: ( image: CropperState[ 'image' ] ) => void;\n\t/** Reset the state. Optionally merge partial state overrides. */\n\treset: ( resetState?: Partial< CropperState > ) => void;\n\t/** Whether the current state differs from the initial state. */\n\tisDirty: boolean;\n\t/**\n\t * Export the cropped image as a Blob. Throws on failure — see\n\t * `exportCroppedImage` for error semantics.\n\t */\n\tgetCroppedImage: ( mimeType?: string, quality?: number ) => Promise< Blob >;\n\t/**\n\t * Report the current rendered image size to the controller. The\n\t * Cropper component calls this on visualSize changes; composite\n\t * controllers use it to compute aspect-ratio reshapes. The pure\n\t * cropper hook ignores it (no-op).\n\t */\n\tsetVisualSize: ( size: Size ) => void;\n\t/**\n\t * Adjust the cropRect in response to a viewport change (window\n\t * resize, canvas resize). Behaves like `setCropRect` but, in\n\t * composite controllers, does NOT record an undo entry — viewport\n\t * reshapes aren't editor actions. The pure cropper hook aliases\n\t * this to `setCropRect` (history is a composite concern).\n\t */\n\tadjustCropRectForViewport: ( rect: NormalizedRect ) => void;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * Pure reducer hook for the image cropper.\n *\n * Wraps the framework-agnostic `cropperReducer` and exposes named\n * setters (built from the shared `buildCropperSetters` factory).\n * Does NOT manage undo/redo history — that responsibility belongs to\n * the surrounding application (see `useMediaEditorState` for the\n * composite store used by the media editor).\n *\n * @param initialState Optional partial state to merge with DEFAULT_STATE.\n * @return The cropper controller — state, setters, and helpers.\n */\nexport function useCropperReducer(\n\tinitialState?: Partial< CropperState >\n): CropperController {\n\tconst [ state, dispatch ] = useReducer(\n\t\tcropperReducer,\n\t\tinitialState,\n\t\t( init ) => enforceContainment( { ...DEFAULT_STATE, ...init } )\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setImage` and `reset` refresh\n\t// this when the consumer establishes a new baseline.\n\tconst [ initialBaseline, setInitialBaseline ] = useState< CropperState >(\n\t\t() => enforceContainment( { ...DEFAULT_STATE, ...initialState } )\n\t);\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, toggleFlip, reset, setImage). Updated\n\t// synchronously inside `dispatchAndSync` so multiple actions in\n\t// one event see each other's output before React commits.\n\tconst stateRef = useRef( state );\n\n\tconst dispatchAndSync = useCallback( ( action: CropperAction ) => {\n\t\tconst next = cropperReducer( stateRef.current, action );\n\t\tstateRef.current = next;\n\t\tdispatch( action );\n\t\treturn next;\n\t}, [] );\n\n\tconst setImage = useCallback(\n\t\t( image: CropperState[ 'image' ] ) => {\n\t\t\tif ( areCropperImagesEqual( stateRef.current.image, image ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst next = dispatchAndSync( {\n\t\t\t\ttype: 'SET_IMAGE',\n\t\t\t\tpayload: image,\n\t\t\t} );\n\t\t\t// Refresh the \"clean\" snapshot to match the post-load state\n\t\t\t// produced by the reducer. Otherwise containment can nudge\n\t\t\t// pan/zoom by tiny amounts on load and `isDirty` would\n\t\t\t// report true from the start.\n\t\t\tsetInitialBaseline( next );\n\t\t},\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tconst nextInitialState = dispatchAndSync( {\n\t\t\t\ttype: 'RESET',\n\t\t\t\tpayload: resetState,\n\t\t\t} );\n\t\t\t// Mirror the reducer's RESET exactly so isDirty stays in\n\t\t\t// sync. The containment step can tweak pan/zoom/cropRect by\n\t\t\t// float ulp; fold those into the \"initial\" snapshot or\n\t\t\t// isDirty would report true after a reset.\n\t\t\tsetInitialBaseline( nextInitialState );\n\t\t},\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst setters = useMemo(\n\t\t() => buildCropperSetters( dispatchAndSync, () => stateRef.current ),\n\t\t[ dispatchAndSync ]\n\t);\n\n\tconst isDirty = isStateDirty( state, initialBaseline );\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded — call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.image.src,\n\t\t\t\tstate,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state ]\n\t);\n\n\t// No-op for the pure hook — visualSize matters only when a\n\t// composite store needs to compute aspect-ratio reshapes\n\t// (see useMediaEditorState). Typed to accept a Size so it\n\t// satisfies the controller surface; the value is intentionally\n\t// ignored.\n\tconst setVisualSize = useCallback( () => {}, [] );\n\n\t// In the pure hook, history isn't a concern — viewport-driven\n\t// reshape is identical to setCropRect.\n\tconst adjustCropRectForViewport = setters.setCropRect;\n\n\tconst controller: CropperController = {\n\t\t...setters,\n\t\tstate,\n\t\tsetImage,\n\t\treset,\n\t\tisDirty,\n\t\tgetCroppedImage,\n\t\tsetVisualSize,\n\t\tadjustCropRectForViewport,\n\t};\n\treturn controller;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAWP,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,OAEM;AA0CP,SAAS,sBACR,GACA,GACU;AACV,SACC,GAAG,QAAQ,GAAG,OACd,GAAG,iBAAiB,GAAG,gBACvB,GAAG,kBAAkB,GAAG;AAE1B;AAcO,SAAS,kBACf,cACoB;AACpB,QAAM,CAAE,OAAO,QAAS,IAAI;AAAA,IAC3B;AAAA,IACA;AAAA,IACA,CAAE,SAAU,mBAAoB,EAAE,GAAG,eAAe,GAAG,KAAK,CAAE;AAAA,EAC/D;AAMA,QAAM,CAAE,iBAAiB,kBAAmB,IAAI;AAAA,IAC/C,MAAM,mBAAoB,EAAE,GAAG,eAAe,GAAG,aAAa,CAAE;AAAA,EACjE;AAKA,QAAM,WAAW,OAAQ,KAAM;AAE/B,QAAM,kBAAkB,YAAa,CAAE,WAA2B;AACjE,UAAM,OAAO,eAAgB,SAAS,SAAS,MAAO;AACtD,aAAS,UAAU;AACnB,aAAU,MAAO;AACjB,WAAO;AAAA,EACR,GAAG,CAAC,CAAE;AAEN,QAAM,WAAW;AAAA,IAChB,CAAE,UAAoC;AACrC,UAAK,sBAAuB,SAAS,QAAQ,OAAO,KAAM,GAAI;AAC7D;AAAA,MACD;AACA,YAAM,OAAO,gBAAiB;AAAA,QAC7B,MAAM;AAAA,QACN,SAAS;AAAA,MACV,CAAE;AAKF,yBAAoB,IAAK;AAAA,IAC1B;AAAA,IACA,CAAE,eAAgB;AAAA,EACnB;AAEA,QAAM,QAAQ;AAAA,IACb,CAAE,eAA0C;AAC3C,YAAM,mBAAmB,gBAAiB;AAAA,QACzC,MAAM;AAAA,QACN,SAAS;AAAA,MACV,CAAE;AAKF,yBAAoB,gBAAiB;AAAA,IACtC;AAAA,IACA,CAAE,eAAgB;AAAA,EACnB;AAEA,QAAM,UAAU;AAAA,IACf,MAAM,oBAAqB,iBAAiB,MAAM,SAAS,OAAQ;AAAA,IACnE,CAAE,eAAgB;AAAA,EACnB;AAEA,QAAM,UAAU,aAAc,OAAO,eAAgB;AAErD,QAAM,kBAAkB;AAAA,IACvB,CAAE,UAAmB,YAAuC;AAC3D,UAAK,CAAE,MAAM,OAAQ;AACpB,eAAO,QAAQ;AAAA,UACd,IAAI,MAAO,wCAAyC;AAAA,QACrD;AAAA,MACD;AACA,aAAO;AAAA,QACN,MAAM,MAAM;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,KAAM;AAAA,EACT;AAOA,QAAM,gBAAgB,YAAa,MAAM;AAAA,EAAC,GAAG,CAAC,CAAE;AAIhD,QAAM,4BAA4B,QAAQ;AAE1C,QAAM,aAAgC;AAAA,IACrC,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-interaction.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, Size } from '../../core/types';\nimport {\n\tInteractionController,\n\ttype CropperInteractionActions,\n} from '../../core/interaction-controller';\n\n/**\n * The return type of the useInteraction hook.\n */\nexport interface UseInteractionReturn {\n\t/** Event handler props to spread on the container element. */\n\thandlers: {\n\t\tonPointerDown: ( e: React.PointerEvent ) => void;\n\t\tonTouchStart: ( e: React.TouchEvent ) => void;\n\t\tonKeyDown: ( e: React.KeyboardEvent ) => void;\n\t};\n\t/** Native wheel handler — must be registered with { passive: false }. */\n\tonWheelNative: ( e: WheelEvent ) => void;\n\t/** Whether a drag (pan) interaction is in progress. */\n\tisDragging: boolean;\n\t/** Whether a double-tap zoom animation is in progress. */\n\tisZooming: boolean;\n\t/** Whether the user is currently performing a placement interaction. */\n\tisPlacementActive: boolean;\n}\n\n/**\n * Options for the useInteraction hook.\n */\nexport interface UseInteractionOptions {\n\t/** Minimum zoom level. Defaults to MIN_ZOOM. */\n\tminZoom?: number;\n\t/** Maximum zoom level. Defaults to MAX_ZOOM. */\n\tmaxZoom?: number;\n\t/** Zoom speed multiplier for wheel events. Defaults to 0.0025. */\n\tzoomSpeed?: number;\n\t/**\n\t * Pan step size in normalized coords for keyboard events.\n\t * Defaults to 0.01. Shift multiplies it by 10.\n\t */\n\tkeyboardStep?: number;\n\t/** Zoom level for double-tap zoom. Defaults to 2. */\n\tdoubleTapZoom?: number;\n\t/** Fires when a continuous gesture begins (pan drag, pinch zoom). */\n\tonGestureStart?: () => void;\n\t/** Fires when a continuous gesture ends (pointer release). */\n\tonGestureEnd?: () => void;\n}\n\n/** How long keyboard placement stays active after the latest handled key. */\nconst KEYBOARD_INTERACTION_IDLE_MS = 300;\n\nfunction isHandledKeyboardPan( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase 'ArrowUp':\n\t\tcase 'ArrowDown':\n\t\tcase 'ArrowLeft':\n\t\tcase 'ArrowRight':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction isHandledKeyboardZoom( event: KeyboardEvent ): boolean {\n\tswitch ( event.key ) {\n\t\tcase '+':\n\t\tcase '=':\n\t\tcase '-':\n\t\tcase '_':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * Mouse, touch, and keyboard event handling for pan, zoom,\n * and crop manipulation.\n *\n * Returns event handler props to spread on the container element.\n * Uses requestAnimationFrame for drag/pinch updates to avoid\n * layout thrashing.\n *\n * @param state The current cropper state.\n * @param actions Named state updates for cropper interactions.\n * @param containerSize The container dimensions in pixels.\n * @param imageSize The rendered image dimensions in pixels.\n * @param options Optional configuration for zoom and keyboard behavior.\n * @return Event handler props for the container element.\n */\nexport function useInteraction(\n\tstate: CropperState,\n\tactions: CropperInteractionActions,\n\tcontainerSize: Size,\n\timageSize?: Size,\n\toptions?: UseInteractionOptions\n): UseInteractionReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\tconst [ isZooming, setIsZooming ] = useState( false );\n\tconst [ isGestureActive, setIsGestureActive ] = useState( false );\n\tconst [ isKeyboardPanning, setIsKeyboardPanning ] = useState( false );\n\tconst keyboardInteractionTimerRef =\n\t\tuseRef< ReturnType< typeof setTimeout > >();\n\t// Tracks whether a keyboard gesture (pan or zoom) is currently active so\n\t// onGestureStart is only fired once per gesture, not on every key repeat.\n\tconst isKeyboardGestureActiveRef = useRef( false );\n\n\t// Keep mutable refs so the controller always reads fresh values\n\t// without needing to be recreated.\n\tconst stateRef = useRef( state );\n\tstateRef.current = state;\n\tconst containerSizeRef = useRef( containerSize );\n\tcontainerSizeRef.current = containerSize;\n\tconst imageSizeRef = useRef( imageSize );\n\timageSizeRef.current = imageSize;\n\tconst optionsRef = useRef( options );\n\toptionsRef.current = options;\n\tconst actionsRef = useRef( actions );\n\tactionsRef.current = actions;\n\n\tconst controllerRef = useRef< InteractionController | null >( null );\n\tconst startPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( true );\n\t}, [] );\n\tconst stopPlacementGesture = useCallback( () => {\n\t\tsetIsGestureActive( false );\n\t}, [] );\n\t// Shared timer logic for any keyboard gesture (pan or zoom): fires\n\t// onGestureStart once per burst and onGestureEnd after the idle window.\n\tconst signalKeyboardGesture = useCallback( () => {\n\t\tif ( ! isKeyboardGestureActiveRef.current ) {\n\t\t\tisKeyboardGestureActiveRef.current = true;\n\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t}\n\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\tkeyboardInteractionTimerRef.current = setTimeout( () => {\n\t\t\tisKeyboardGestureActiveRef.current = false;\n\t\t\tsetIsKeyboardPanning( false );\n\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t}, KEYBOARD_INTERACTION_IDLE_MS );\n\t}, [] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tclearTimeout( keyboardInteractionTimerRef.current );\n\t\t};\n\t}, [] );\n\n\t// Create / destroy the controller. The controller reads all volatile\n\t// values through refs, so it can stay mounted across render updates.\n\tuseEffect( () => {\n\t\tconst controller = new InteractionController( {\n\t\t\tgetState: () => stateRef.current,\n\t\t\tactions: {\n\t\t\t\tsetPan: ( pan ) => actionsRef.current.setPan( pan ),\n\t\t\t\tsetZoom: ( zoom ) => actionsRef.current.setZoom( zoom ),\n\t\t\t\tsetZoomAtPoint: ( zoom, pan ) =>\n\t\t\t\t\tactionsRef.current.setZoomAtPoint( zoom, pan ),\n\t\t\t\tsnapRotate90: ( direction ) =>\n\t\t\t\t\tactionsRef.current.snapRotate90( direction ),\n\t\t\t\ttoggleFlip: ( direction ) =>\n\t\t\t\t\tactionsRef.current.toggleFlip?.( direction ),\n\t\t\t},\n\t\t\tgetContainerSize: () => containerSizeRef.current,\n\t\t\tgetImageSize: () => imageSizeRef.current,\n\t\t\tget minZoom() {\n\t\t\t\treturn optionsRef.current?.minZoom;\n\t\t\t},\n\t\t\tget maxZoom() {\n\t\t\t\treturn optionsRef.current?.maxZoom;\n\t\t\t},\n\t\t\tget zoomSpeed() {\n\t\t\t\treturn optionsRef.current?.zoomSpeed;\n\t\t\t},\n\t\t\tget keyboardStep() {\n\t\t\t\treturn optionsRef.current?.keyboardStep;\n\t\t\t},\n\t\t\tget doubleTapZoom() {\n\t\t\t\treturn optionsRef.current?.doubleTapZoom;\n\t\t\t},\n\t\t\tonGestureStart: () => {\n\t\t\t\tstartPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureStart?.();\n\t\t\t},\n\t\t\tonGestureEnd: () => {\n\t\t\t\tstopPlacementGesture();\n\t\t\t\toptionsRef.current?.onGestureEnd?.();\n\t\t\t},\n\t\t\tonStatusChange: ( status ) => {\n\t\t\t\tsetIsDragging( status.isDragging );\n\t\t\t\tsetIsZooming( status.isZooming );\n\t\t\t},\n\t\t} );\n\t\tcontrollerRef.current = controller;\n\t\treturn () => {\n\t\t\tcontroller.destroy();\n\t\t\tcontrollerRef.current = null;\n\t\t};\n\t}, [ startPlacementGesture, stopPlacementGesture ] );\n\n\tconst onPointerDown = useCallback( ( e: React.PointerEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tcontrollerRef.current?.handlePointerDown( e.nativeEvent, el );\n\t}, [] );\n\n\tconst onTouchStart = useCallback( ( e: React.TouchEvent ) => {\n\t\tconst el = e.currentTarget as HTMLElement;\n\t\tconst rect = el.getBoundingClientRect();\n\t\tcontrollerRef.current?.handleTouchStart(\n\t\t\te.nativeEvent,\n\t\t\trect,\n\t\t\tel.ownerDocument\n\t\t);\n\t}, [] );\n\n\tconst onKeyDown = useCallback(\n\t\t( e: React.KeyboardEvent ) => {\n\t\t\tif ( isHandledKeyboardPan( e.nativeEvent ) ) {\n\t\t\t\tsetIsKeyboardPanning( true );\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t} else if ( isHandledKeyboardZoom( e.nativeEvent ) ) {\n\t\t\t\tsignalKeyboardGesture();\n\t\t\t}\n\t\t\tcontrollerRef.current?.handleKeyDown( e.nativeEvent );\n\t\t},\n\t\t[ signalKeyboardGesture ]\n\t);\n\n\tconst onWheelNative = useCallback( ( e: WheelEvent ) => {\n\t\tcontrollerRef.current?.handleWheel( e );\n\t}, [] );\n\n\treturn {\n\t\thandlers: {\n\t\t\tonPointerDown,\n\t\t\tonTouchStart,\n\t\t\tonKeyDown,\n\t\t},\n\t\tonWheelNative,\n\t\tisDragging,\n\t\tisZooming,\n\t\tisPlacementActive: isGestureActive || isKeyboardPanning || isZooming,\n\t};\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAMzD;AAAA,EACC;AAAA,OAEM;AA8CP,IAAM,+BAA+B;AAErC,SAAS,qBAAsB,OAAgC;AAC9D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAEA,SAAS,sBAAuB,OAAgC;AAC/D,UAAS,MAAM,KAAM;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IACR;AACC,aAAO;AAAA,EACT;AACD;AAiBO,SAAS,eACf,OACA,SACA,eACA,WACA,SACuB;AACvB,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,KAAM;AACtD,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AACpD,QAAM,CAAE,iBAAiB,kBAAm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;AAAA,MACA,GAAG;AAAA,IACJ;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,YAAY;AAAA,IACjB,CAAE,MAA4B;AAC7B,UAAK,qBAAsB,EAAE,WAAY,GAAI;AAC5C,6BAAsB,IAAK;AAC3B,8BAAsB;AAAA,MACvB,WAAY,sBAAuB,EAAE,WAAY,GAAI;AACpD,8BAAsB;AAAA,MACvB;AACA,oBAAc,SAAS,cAAe,EAAE,WAAY;AAAA,IACrD;AAAA,IACA,CAAE,qBAAsB;AAAA,EACzB;AAEA,QAAM,gBAAgB,YAAa,CAAE,MAAmB;AACvD,kBAAc,SAAS,YAAa,CAAE;AAAA,EACvC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,UAAU;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB,mBAAmB,qBAAqB;AAAA,EAC5D;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/image-editor/react/hooks/use-viewport-state.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useReducer, useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ViewportState } from '../../core/types';\nimport {\n\tviewportReducer,\n\tDEFAULT_VIEWPORT_STATE,\n} from '../../core/viewport-state';\n\nexport interface UseViewportStateReturn {\n\tviewport: ViewportState;\n\t/**\n\t * Unused in the current Cropper implementation
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useReducer, useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ViewportState } from '../../core/types';\nimport {\n\tviewportReducer,\n\tDEFAULT_VIEWPORT_STATE,\n} from '../../core/viewport-state';\n\nexport interface UseViewportStateReturn {\n\tviewport: ViewportState;\n\t/**\n\t * Unused in the current Cropper implementation — scaffolded for the\n\t * upcoming navigator panel (viewport zoom slider).\n\t */\n\tsetViewportZoom: ( zoom: number ) => void;\n\tsetViewportPan: ( pan: { x: number; y: number } ) => void;\n\tresetViewport: () => void;\n}\n\nexport function useViewportState(): UseViewportStateReturn {\n\tconst [ viewport, dispatch ] = useReducer(\n\t\tviewportReducer,\n\t\tDEFAULT_VIEWPORT_STATE\n\t);\n\n\tconst setViewportZoom = useCallback( ( zoom: number ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_ZOOM', payload: zoom } );\n\t}, [] );\n\n\tconst setViewportPan = useCallback( ( pan: { x: number; y: number } ) => {\n\t\tdispatch( { type: 'SET_VIEWPORT_PAN', payload: pan } );\n\t}, [] );\n\n\tconst resetViewport = useCallback( () => {\n\t\tdispatch( { type: 'RESET_VIEWPORT' } );\n\t}, [] );\n\n\treturn useMemo(\n\t\t() => ( { viewport, setViewportZoom, setViewportPan, resetViewport } ),\n\t\t[ viewport, setViewportZoom, setViewportPan, resetViewport ]\n\t);\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,YAAY,aAAa,eAAe;AAMjD;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAaA,SAAS,mBAA2C;AAC1D,QAAM,CAAE,UAAU,QAAS,IAAI;AAAA,IAC9B;AAAA,IACA;AAAA,EACD;AAEA,QAAM,kBAAkB,YAAa,CAAE,SAAkB;AACxD,aAAU,EAAE,MAAM,qBAAqB,SAAS,KAAK,CAAE;AAAA,EACxD,GAAG,CAAC,CAAE;AAEN,QAAM,iBAAiB,YAAa,CAAE,QAAmC;AACxE,aAAU,EAAE,MAAM,oBAAoB,SAAS,IAAI,CAAE;AAAA,EACtD,GAAG,CAAC,CAAE;AAEN,QAAM,gBAAgB,YAAa,MAAM;AACxC,aAAU,EAAE,MAAM,iBAAiB,CAAE;AAAA,EACtC,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,OAAQ,EAAE,UAAU,iBAAiB,gBAAgB,cAAc;AAAA,IACnE,CAAE,UAAU,iBAAiB,gBAAgB,aAAc;AAAA,EAC5D;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Components\nexport { MediaEditorProvider } from './components/media-editor-provider';\nexport { default as MediaPreview } from './components/media-preview';\nexport { default as MediaForm } from './components/media-form';\n\n// Types\nexport type {\n\tMedia,\n\tMediaEditorProviderProps,\n} from './components/media-editor-provider';\nexport type { MediaPreviewProps } from './components/media-preview';\nexport type { MediaFormProps } from './components/media-form';\n\n// Re-export commonly used dataviews types for convenience\nexport type { Field, Form } from '@wordpress/dataviews';\n\n// Private APIs (experimental
|
|
4
|
+
"sourcesContent": ["// Components\nexport { MediaEditorProvider } from './components/media-editor-provider';\nexport { default as MediaPreview } from './components/media-preview';\nexport { default as MediaForm } from './components/media-form';\n\n// Types\nexport type {\n\tMedia,\n\tMediaEditorProviderProps,\n} from './components/media-editor-provider';\nexport type { MediaPreviewProps } from './components/media-preview';\nexport type { MediaFormProps } from './components/media-form';\n\n// Re-export commonly used dataviews types for convenience\nexport type { Field, Form } from '@wordpress/dataviews';\n\n// Private APIs (experimental — not for use outside of core packages).\nexport { privateApis } from './private-apis';\n"],
|
|
5
5
|
"mappings": ";AACA,SAAS,2BAA2B;AACpC,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,gBAA4B;AAcrC,SAAS,mBAAmB;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/state/types.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tCropperAction,\n\tCropperState,\n\tNormalizedRect,\n\tSize,\n} from '../image-editor';\n\n/**\n * Sidebar control state for the cropper. Lives in the composite store\n * so it participates in the same undo history as cropper geometry.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * Default values for the crop-options slice. Mirrors the initial state\n * used by the sidebar before the user has touched anything.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * The full composite state for the media editor
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tCropperAction,\n\tCropperState,\n\tNormalizedRect,\n\tSize,\n} from '../image-editor';\n\n/**\n * Sidebar control state for the cropper. Lives in the composite store\n * so it participates in the same undo history as cropper geometry.\n */\nexport interface CropOptionsSlice {\n\t/**\n\t * Selected aspect-ratio preset as a string (round-trippable through\n\t * `<SelectControl>`). `'0'` = Free, `'-1'` = Original, any positive\n\t * decimal = fixed ratio.\n\t */\n\taspectRatioValue: string;\n}\n\n/**\n * Default values for the crop-options slice. Mirrors the initial state\n * used by the sidebar before the user has touched anything.\n */\nexport const DEFAULT_CROP_OPTIONS: CropOptionsSlice = {\n\taspectRatioValue: '0',\n};\n\n/**\n * The full composite state for the media editor — cropper geometry\n * plus the sidebar control slice. Future feature slices (text\n * overlays, filters, …) extend this object.\n *\n * Every undo/redo snapshot is a full `MediaEditorState`. Slices stay\n * referentially equal across actions that don't touch them.\n */\nexport interface MediaEditorState {\n\tcropper: CropperState;\n\tcropOptions: CropOptionsSlice;\n}\n\n/**\n * Composite reducer action union.\n *\n * Cropper geometry actions are wrapped in a `CROPPER` envelope and\n * delegated to the pure `cropperReducer`. Sidebar and history\n * concerns are first-class actions on this reducer.\n */\nexport type MediaEditorAction =\n\t/**\n\t * Delegate to the underlying cropper reducer. Used for every\n\t * geometry transition (pan / zoom / rotation / flip / cropRect /\n\t * settle / etc.).\n\t */\n\t| {\n\t\t\ttype: 'CROPPER';\n\t\t\taction: CropperAction;\n\t }\n\t/**\n\t * Set the aspect-ratio preset. Atomically updates the preset key\n\t * and the cropRect (computed from the resolved ratio and the\n\t * current visualSize). One transaction = one undo entry.\n\t */\n\t| {\n\t\t\ttype: 'SET_ASPECT_RATIO_VALUE';\n\t\t\tpayload: {\n\t\t\t\t/** Preset key as it appears in the dropdown. */\n\t\t\t\tpresetKey: string;\n\t\t\t\t/**\n\t\t\t\t * Resolved width/height ratio. `undefined` = Free\n\t\t\t\t * (no lock; cropRect stays where it is).\n\t\t\t\t */\n\t\t\t\tresolved: number | undefined;\n\t\t\t\t/**\n\t\t\t\t * Rendered image size used to compute the inscribed\n\t\t\t\t * rect. Caller supplies it because the reducer is\n\t\t\t\t * framework-agnostic and has no DOM access.\n\t\t\t\t */\n\t\t\t\tvisualSize: Size;\n\t\t\t};\n\t }\n\t/** Reset cropOptions to defaults. */\n\t| { type: 'RESET_CROP_OPTIONS' }\n\t/**\n\t * Replace the entire composite state with `payload`. Used by\n\t * undo/redo to restore a full snapshot atomically.\n\t */\n\t| { type: 'RESTORE_SNAPSHOT'; payload: MediaEditorState }\n\t/**\n\t * Adjust the cropper's cropRect in response to a viewport change\n\t * (e.g., window resize). Behaviorally identical to a `CROPPER\n\t * SET_CROP_RECT` dispatch, but tagged so the hook layer can skip\n\t * history recording — viewport reshapes aren't editor actions.\n\t */\n\t| {\n\t\t\ttype: 'VIEWPORT_ADJUST_CROP_RECT';\n\t\t\tpayload: NormalizedRect;\n\t };\n"],
|
|
5
5
|
"mappings": ";AA2BO,IAAM,uBAAyC;AAAA,EACrD,kBAAkB;AACnB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -212,7 +212,7 @@ function useMediaEditorState(initialState) {
|
|
|
212
212
|
(mimeType, quality) => {
|
|
213
213
|
if (!state.cropper.image) {
|
|
214
214
|
return Promise.reject(
|
|
215
|
-
new Error("No image loaded
|
|
215
|
+
new Error("No image loaded — call setImage first.")
|
|
216
216
|
);
|
|
217
217
|
}
|
|
218
218
|
return exportCroppedImage(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/state/use-media-editor-state.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tDEFAULT_STATE,\n\tORIGINAL_ASPECT_RATIO,\n\tareCropperStatesEqual,\n\tbuildCropperSetters,\n\tenforceContainment,\n\texportCroppedImage,\n\ttype CropperAction,\n\ttype CropperController,\n\ttype CropperState,\n\ttype NormalizedRect,\n\ttype Size,\n} from '../image-editor';\nimport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nimport type {\n\tCropOptionsSlice,\n\tMediaEditorAction,\n\tMediaEditorState,\n} from './types';\n\n/**\n * Resolve an aspect-ratio preset value (the string the dropdown\n * round-trips) into a numeric width/height ratio for the cropper.\n *\n * - `'0'` \u2192 `undefined` (Free; no lock)\n * - `'-1'` (Original) \u2192 image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal \u2192 the parsed number.\n *\n * Centralizing here means the dropdown, the action dispatcher, and\n * the test harness all resolve the same way.\n *\n * @param presetKey Preset value from the dropdown.\n * @param cropperImage The cropper's loaded image, or `null`.\n * @return The resolved ratio, or `undefined` for Free / unresolvable.\n */\nexport function resolveAspectRatio(\n\tpresetKey: string,\n\tcropperImage: CropperState[ 'image' ] | null\n): number | undefined {\n\tconst num = parseFloat( presetKey );\n\tif ( num === 0 || Number.isNaN( num ) ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO ) {\n\t\tif (\n\t\t\tcropperImage &&\n\t\t\tcropperImage.naturalWidth > 0 &&\n\t\t\tcropperImage.naturalHeight > 0\n\t\t) {\n\t\t\treturn cropperImage.naturalWidth / cropperImage.naturalHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * The composite controller exposed by `useMediaEditorState`.\n *\n * Satisfies `CropperController` (so a `<Cropper>` can take this\n * controller directly via the `controller` prop) and adds slice\n * setters, undo/redo, gesture boundaries, and viewport reporting.\n */\nexport interface MediaEditorController extends CropperController {\n\t/** The cropOptions slice. */\n\tcropOptions: CropOptionsSlice;\n\t/** Set the aspect-ratio preset. Atomic with the cropRect reshape. */\n\tsetAspectRatioValue: ( presetKey: string ) => void;\n\t/** Reset cropOptions to defaults. */\n\tresetCropOptions: () => void;\n\t/**\n\t * Whether the cropper geometry differs from the initial baseline.\n\t */\n\tisCropperDirty: boolean;\n\t/** Whether there's an undoable change in history. */\n\thasUndo: boolean;\n\t/** Whether there's a redoable change in history. */\n\thasRedo: boolean;\n\t/** Undo the last committed action across all slices. */\n\tundo: () => void;\n\t/** Redo the last undone action across all slices. */\n\tredo: () => void;\n\t/**\n\t * Open a gesture boundary. During a gesture all state-changing\n\t * actions coalesce into one undo entry \u2014 the snapshot taken at\n\t * `beginGesture`. Pair with `endGesture` on pointer-up / key-up.\n\t */\n\tbeginGesture: () => void;\n\t/** Close a gesture boundary and commit the pre-gesture snapshot. */\n\tendGesture: () => void;\n\t/**\n\t * Report the current rendered image size to the controller. The\n\t * Cropper component calls this whenever its visualSize changes;\n\t * the controller needs it to compute aspect-ratio reshapes.\n\t */\n\tsetVisualSize: ( size: Size ) => void;\n\t/**\n\t * Reshape the cropRect in response to a viewport change. Behaves\n\t * like `setCropRect` but does NOT record an undo entry \u2014 window\n\t * resizes aren't editor actions.\n\t */\n\tadjustCropRectForViewport: ( rect: NormalizedRect ) => void;\n}\n\ninterface InitialMediaEditorState {\n\tcropper?: Partial< CropperState >;\n\tcropOptions?: Partial< CropOptionsSlice >;\n}\n\n/**\n * Composite store for the media editor.\n *\n * Owns the only undo/redo history for the editor. Cropper geometry\n * actions and sidebar cropOptions actions flow through the same\n * reducer and the same history stack.\n *\n * History semantics:\n * - Each action's pre-state is pushed to the undo stack before the\n * action commits, unless a gesture is open or the action is a\n * no-op (post-state value-equal to pre-state).\n * - During a gesture (`beginGesture` \u2192 `endGesture`) all mutations\n * coalesce: only the pre-gesture snapshot is pushed, at gesture\n * end. Any pending gesture is flushed on undo/redo.\n * - Viewport-driven cropRect reshapes (window resize) use a\n * dedicated non-recording dispatch path so they never produce\n * undo entries.\n *\n * `isDirty` tracks the full editor session, including undoable UI\n * state. Use `isCropperDirty` when deciding whether the image output\n * needs saving.\n *\n * @param initialState Optional seed for the cropper and cropOptions slices.\n * @return The composite controller.\n */\nexport function useMediaEditorState(\n\tinitialState?: InitialMediaEditorState\n): MediaEditorController {\n\tconst [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>\n\t\tbuildInitialMediaEditorState(\n\t\t\tenforceContainment( {\n\t\t\t\t...DEFAULT_STATE,\n\t\t\t\t...initialState?.cropper,\n\t\t\t} ),\n\t\t\tinitialState?.cropOptions\n\t\t)\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setImage` refreshes this when\n\t// a new image establishes a fresh baseline.\n\tconst [ initialBaseline, setInitialBaseline ] =\n\t\tuseState< MediaEditorState >( () => state );\n\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, dispatch wrapper). Every mutation path\n\t// (`dispatchWithHistory`, `setImage`, `undo`, `redo`) writes this\n\t// synchronously, so multiple actions in one event see the latest\n\t// reducer output before React commits.\n\tconst stateRef = useRef( state );\n\tconst visualSizeRef = useRef< Size >( { width: 0, height: 0 } );\n\n\t// History stacks: full composite snapshots. Refs avoid re-renders\n\t// on every push; a boolean state pair drives the enabled/disabled\n\t// indicators for undo/redo buttons.\n\tconst historyRef = useRef< MediaEditorState[] >( [] );\n\tconst redoStackRef = useRef< MediaEditorState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Gesture state. While open, the first non-no-op action captures\n\t// the pre-gesture snapshot; subsequent actions don't push.\n\t// `endGesture` pushes the captured snapshot (or nothing, if the\n\t// gesture produced no changes).\n\tconst isGestureOpenRef = useRef( false );\n\tconst gestureSnapshotRef = useRef< MediaEditorState | null >( null );\n\n\tconst pushSnapshot = useCallback( ( snapshot: MediaEditorState ) => {\n\t\tconst last = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( last && areMediaEditorStatesEqual( last, snapshot ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, snapshot ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\t// Core dispatch wrapper. Synchronously computes the post-state via\n\t// the pure reducer so we can skip history pushes for no-op actions\n\t// and keep `stateRef` in lockstep with React's pending state.\n\tconst dispatchWithHistory = useCallback(\n\t\t( action: MediaEditorAction, recordHistory = true ) => {\n\t\t\tconst preState = stateRef.current;\n\t\t\tconst postState = mediaEditorReducer( preState, action );\n\t\t\tif ( recordHistory ) {\n\t\t\t\tif ( ! areMediaEditorStatesEqual( preState, postState ) ) {\n\t\t\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\t\t\tif ( gestureSnapshotRef.current === null ) {\n\t\t\t\t\t\t\tgestureSnapshotRef.current = preState;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpushSnapshot( preState );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tstateRef.current = postState;\n\t\t\tdispatch( action );\n\t\t},\n\t\t[ pushSnapshot ]\n\t);\n\n\tconst beginGesture = useCallback( () => {\n\t\tif ( isGestureOpenRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tisGestureOpenRef.current = true;\n\t\tgestureSnapshotRef.current = null;\n\t}, [] );\n\n\t// Close a gesture (or flush a pending one before undo/redo).\n\t// Pushes the pre-gesture snapshot only if it differs from current\n\t// state. Safe to call when no gesture is open.\n\tconst endGesture = useCallback( () => {\n\t\tconst snapshot = gestureSnapshotRef.current;\n\t\tif (\n\t\t\tsnapshot &&\n\t\t\t! areMediaEditorStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushSnapshot( snapshot );\n\t\t}\n\t\tgestureSnapshotRef.current = null;\n\t\tisGestureOpenRef.current = false;\n\t}, [ pushSnapshot ] );\n\n\t// =====================================================================\n\t// Cropper-slice setters (built from the shared factory so the pure\n\t// hook and this composite stay in lockstep \u2014 add a setter in\n\t// `buildCropperSetters` once and both hooks get it).\n\t// =====================================================================\n\n\tconst dispatchCropperAction = useCallback(\n\t\t( action: CropperAction ) => {\n\t\t\tdispatchWithHistory( { type: 'CROPPER', action } );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst cropperSetters = useMemo(\n\t\t() =>\n\t\t\tbuildCropperSetters(\n\t\t\t\tdispatchCropperAction,\n\t\t\t\t() => stateRef.current.cropper\n\t\t\t),\n\t\t[ dispatchCropperAction ]\n\t);\n\n\tconst setImage = useCallback( ( image: CropperState[ 'image' ] ) => {\n\t\tif ( areCropperImagesEqual( stateRef.current.cropper.image, image ) ) {\n\t\t\treturn;\n\t\t}\n\t\t// New image = fresh canvas: clear history, refresh the\n\t\t// initial snapshot so isDirty starts at false.\n\t\tconst action = {\n\t\t\ttype: 'CROPPER' as const,\n\t\t\taction: { type: 'SET_IMAGE' as const, payload: image },\n\t\t};\n\t\tconst next = mediaEditorReducer( stateRef.current, action );\n\t\tstateRef.current = next;\n\t\tdispatch( action );\n\t\tsetInitialBaseline( next );\n\t\tisGestureOpenRef.current = false;\n\t\tgestureSnapshotRef.current = null;\n\t\thistoryRef.current = [];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( false );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'CROPPER',\n\t\t\t\taction: { type: 'RESET', payload: resetState },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// CropOptions-slice setters\n\t// =====================================================================\n\n\tconst setAspectRatioValue = useCallback(\n\t\t( presetKey: string ) => {\n\t\t\tconst resolved = resolveAspectRatio(\n\t\t\t\tpresetKey,\n\t\t\t\tstateRef.current.cropper.image\n\t\t\t);\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_ASPECT_RATIO_VALUE',\n\t\t\t\tpayload: {\n\t\t\t\t\tpresetKey,\n\t\t\t\t\tresolved,\n\t\t\t\t\tvisualSize: visualSizeRef.current,\n\t\t\t\t},\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst resetCropOptions = useCallback( () => {\n\t\tdispatchWithHistory( { type: 'RESET_CROP_OPTIONS' } );\n\t}, [ dispatchWithHistory ] );\n\n\t// =====================================================================\n\t// History\n\t// =====================================================================\n\n\tconst undo = useCallback( () => {\n\t\tendGesture();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tstateRef.current = prev;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: prev } );\n\t}, [ endGesture ] );\n\n\tconst redo = useCallback( () => {\n\t\tendGesture();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t}, [ endGesture ] );\n\n\t// =====================================================================\n\t// Viewport\n\t// =====================================================================\n\n\tconst setVisualSize = useCallback( ( size: Size ) => {\n\t\tvisualSizeRef.current = size;\n\t}, [] );\n\n\tconst adjustCropRectForViewport = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatchWithHistory(\n\t\t\t\t{ type: 'VIEWPORT_ADJUST_CROP_RECT', payload: rect },\n\t\t\t\tfalse\n\t\t\t);\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// Derived\n\t// =====================================================================\n\n\tconst isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );\n\tconst isCropperDirty = ! areCropperStatesEqual(\n\t\tstate.cropper,\n\t\tinitialBaseline.cropper\n\t);\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.cropper.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded \u2014 call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.cropper.image.src,\n\t\t\t\tstate.cropper,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state.cropper ]\n\t);\n\n\tconst controller = useMemo< MediaEditorController >(\n\t\t() => ( {\n\t\t\t// CropperController surface (state is the cropper slice so a\n\t\t\t// <Cropper> takes this controller as-is).\n\t\t\t...cropperSetters,\n\t\t\tstate: state.cropper,\n\t\t\tsetImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\tgetCroppedImage,\n\t\t\t// Composite extensions\n\t\t\tcropOptions: state.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tresetCropOptions,\n\t\t\tisCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t} ),\n\t\t[\n\t\t\tcropperSetters,\n\t\t\tstate.cropper,\n\t\t\tsetImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\tgetCroppedImage,\n\t\t\tstate.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tresetCropOptions,\n\t\t\tisCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t]\n\t);\n\treturn controller;\n}\n"],
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAuBA,SAAS,mBACf,WACA,cACqB;AACrB,QAAM,MAAM,WAAY,SAAU;AAClC,MAAK,QAAQ,KAAK,OAAO,MAAO,GAAI,GAAI;AACvC,WAAO;AAAA,EACR;AACA,MAAK,QAAQ,uBAAwB;AACpC,QACC,gBACA,aAAa,eAAe,KAC5B,aAAa,gBAAgB,GAC5B;AACD,aAAO,aAAa,eAAe,aAAa;AAAA,IACjD;AACA,WAAO;AAAA,EACR;AAC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AO,aAAa,QAAS,CAAE;AACrC,QAAK,CAAE,MAAO;AACb;AAAA,IACD;AACA,eAAW,UAAU,CAAE,GAAG,WAAW,SAAS,SAAS,OAAQ;AAC/D,iBAAa,UAAU,aAAa,QAAQ,MAAO,CAAE;AACrD,eAAY,IAAK;AACjB,eAAY,aAAa,QAAQ,SAAS,CAAE;AAC5C,aAAS,UAAU;AACnB,aAAU,EAAE,MAAM,oBAAoB,SAAS,KAAK,CAAE;AAAA,EACvD,GAAG,CAAE,UAAW,CAAE;AAMlB,QAAM,gBAAgB,YAAa,CAAE,SAAgB;AACpD,kBAAc,UAAU;AAAA,EACzB,GAAG,CAAC,CAAE;AAEN,QAAM,4BAA4B;AAAA,IACjC,CAAE,SAA0B;AAC3B;AAAA,QACC,EAAE,MAAM,6BAA6B,SAAS,KAAK;AAAA,QACnD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,mBAAoB;AAAA,EACvB;AAMA,QAAM,UAAU,CAAE,0BAA2B,OAAO,eAAgB;AACpE,QAAM,iBAAiB,CAAE;AAAA,IACxB,MAAM;AAAA,IACN,gBAAgB;AAAA,EACjB;AAEA,QAAM,kBAAkB;AAAA,IACvB,CAAE,UAAmB,YAAuC;AAC3D,UAAK,CAAE,MAAM,QAAQ,OAAQ;AAC5B,eAAO,QAAQ;AAAA,UACd,IAAI,MAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseMemo,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tDEFAULT_STATE,\n\tORIGINAL_ASPECT_RATIO,\n\tareCropperStatesEqual,\n\tbuildCropperSetters,\n\tenforceContainment,\n\texportCroppedImage,\n\ttype CropperAction,\n\ttype CropperController,\n\ttype CropperState,\n\ttype NormalizedRect,\n\ttype Size,\n} from '../image-editor';\nimport {\n\tmediaEditorReducer,\n\tareMediaEditorStatesEqual,\n\tbuildInitialMediaEditorState,\n} from './composite-reducer';\nimport type {\n\tCropOptionsSlice,\n\tMediaEditorAction,\n\tMediaEditorState,\n} from './types';\n\n/**\n * Resolve an aspect-ratio preset value (the string the dropdown\n * round-trips) into a numeric width/height ratio for the cropper.\n *\n * - `'0'` → `undefined` (Free; no lock)\n * - `'-1'` (Original) → image's natural width / height, or `undefined`\n * if no image is loaded.\n * - Any positive decimal → the parsed number.\n *\n * Centralizing here means the dropdown, the action dispatcher, and\n * the test harness all resolve the same way.\n *\n * @param presetKey Preset value from the dropdown.\n * @param cropperImage The cropper's loaded image, or `null`.\n * @return The resolved ratio, or `undefined` for Free / unresolvable.\n */\nexport function resolveAspectRatio(\n\tpresetKey: string,\n\tcropperImage: CropperState[ 'image' ] | null\n): number | undefined {\n\tconst num = parseFloat( presetKey );\n\tif ( num === 0 || Number.isNaN( num ) ) {\n\t\treturn undefined;\n\t}\n\tif ( num === ORIGINAL_ASPECT_RATIO ) {\n\t\tif (\n\t\t\tcropperImage &&\n\t\t\tcropperImage.naturalWidth > 0 &&\n\t\t\tcropperImage.naturalHeight > 0\n\t\t) {\n\t\t\treturn cropperImage.naturalWidth / cropperImage.naturalHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\tif ( num > 0 ) {\n\t\treturn num;\n\t}\n\treturn undefined;\n}\n\nfunction areCropperImagesEqual(\n\ta: CropperState[ 'image' ],\n\tb: CropperState[ 'image' ]\n): boolean {\n\treturn (\n\t\ta?.src === b?.src &&\n\t\ta?.naturalWidth === b?.naturalWidth &&\n\t\ta?.naturalHeight === b?.naturalHeight\n\t);\n}\n\n/**\n * The composite controller exposed by `useMediaEditorState`.\n *\n * Satisfies `CropperController` (so a `<Cropper>` can take this\n * controller directly via the `controller` prop) and adds slice\n * setters, undo/redo, gesture boundaries, and viewport reporting.\n */\nexport interface MediaEditorController extends CropperController {\n\t/** The cropOptions slice. */\n\tcropOptions: CropOptionsSlice;\n\t/** Set the aspect-ratio preset. Atomic with the cropRect reshape. */\n\tsetAspectRatioValue: ( presetKey: string ) => void;\n\t/** Reset cropOptions to defaults. */\n\tresetCropOptions: () => void;\n\t/**\n\t * Whether the cropper geometry differs from the initial baseline.\n\t */\n\tisCropperDirty: boolean;\n\t/** Whether there's an undoable change in history. */\n\thasUndo: boolean;\n\t/** Whether there's a redoable change in history. */\n\thasRedo: boolean;\n\t/** Undo the last committed action across all slices. */\n\tundo: () => void;\n\t/** Redo the last undone action across all slices. */\n\tredo: () => void;\n\t/**\n\t * Open a gesture boundary. During a gesture all state-changing\n\t * actions coalesce into one undo entry — the snapshot taken at\n\t * `beginGesture`. Pair with `endGesture` on pointer-up / key-up.\n\t */\n\tbeginGesture: () => void;\n\t/** Close a gesture boundary and commit the pre-gesture snapshot. */\n\tendGesture: () => void;\n\t/**\n\t * Report the current rendered image size to the controller. The\n\t * Cropper component calls this whenever its visualSize changes;\n\t * the controller needs it to compute aspect-ratio reshapes.\n\t */\n\tsetVisualSize: ( size: Size ) => void;\n\t/**\n\t * Reshape the cropRect in response to a viewport change. Behaves\n\t * like `setCropRect` but does NOT record an undo entry — window\n\t * resizes aren't editor actions.\n\t */\n\tadjustCropRectForViewport: ( rect: NormalizedRect ) => void;\n}\n\ninterface InitialMediaEditorState {\n\tcropper?: Partial< CropperState >;\n\tcropOptions?: Partial< CropOptionsSlice >;\n}\n\n/**\n * Composite store for the media editor.\n *\n * Owns the only undo/redo history for the editor. Cropper geometry\n * actions and sidebar cropOptions actions flow through the same\n * reducer and the same history stack.\n *\n * History semantics:\n * - Each action's pre-state is pushed to the undo stack before the\n * action commits, unless a gesture is open or the action is a\n * no-op (post-state value-equal to pre-state).\n * - During a gesture (`beginGesture` → `endGesture`) all mutations\n * coalesce: only the pre-gesture snapshot is pushed, at gesture\n * end. Any pending gesture is flushed on undo/redo.\n * - Viewport-driven cropRect reshapes (window resize) use a\n * dedicated non-recording dispatch path so they never produce\n * undo entries.\n *\n * `isDirty` tracks the full editor session, including undoable UI\n * state. Use `isCropperDirty` when deciding whether the image output\n * needs saving.\n *\n * @param initialState Optional seed for the cropper and cropOptions slices.\n * @return The composite controller.\n */\nexport function useMediaEditorState(\n\tinitialState?: InitialMediaEditorState\n): MediaEditorController {\n\tconst [ state, dispatch ] = useReducer( mediaEditorReducer, null, () =>\n\t\tbuildInitialMediaEditorState(\n\t\t\tenforceContainment( {\n\t\t\t\t...DEFAULT_STATE,\n\t\t\t\t...initialState?.cropper,\n\t\t\t} ),\n\t\t\tinitialState?.cropOptions\n\t\t)\n\t);\n\n\t// The \"clean\" snapshot the current state is compared against for\n\t// `isDirty`. Stored in state (not a ref) so the comparison reads\n\t// a value, not a ref's `current`. `setImage` refreshes this when\n\t// a new image establishes a fresh baseline.\n\tconst [ initialBaseline, setInitialBaseline ] =\n\t\tuseState< MediaEditorState >( () => state );\n\n\t// Latest-state ref used by setters that need to read fresh state\n\t// (focal-point zoom, dispatch wrapper). Every mutation path\n\t// (`dispatchWithHistory`, `setImage`, `undo`, `redo`) writes this\n\t// synchronously, so multiple actions in one event see the latest\n\t// reducer output before React commits.\n\tconst stateRef = useRef( state );\n\tconst visualSizeRef = useRef< Size >( { width: 0, height: 0 } );\n\n\t// History stacks: full composite snapshots. Refs avoid re-renders\n\t// on every push; a boolean state pair drives the enabled/disabled\n\t// indicators for undo/redo buttons.\n\tconst historyRef = useRef< MediaEditorState[] >( [] );\n\tconst redoStackRef = useRef< MediaEditorState[] >( [] );\n\tconst [ hasUndo, setHasUndo ] = useState( false );\n\tconst [ hasRedo, setHasRedo ] = useState( false );\n\n\t// Gesture state. While open, the first non-no-op action captures\n\t// the pre-gesture snapshot; subsequent actions don't push.\n\t// `endGesture` pushes the captured snapshot (or nothing, if the\n\t// gesture produced no changes).\n\tconst isGestureOpenRef = useRef( false );\n\tconst gestureSnapshotRef = useRef< MediaEditorState | null >( null );\n\n\tconst pushSnapshot = useCallback( ( snapshot: MediaEditorState ) => {\n\t\tconst last = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( last && areMediaEditorStatesEqual( last, snapshot ) ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, snapshot ];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\t// Core dispatch wrapper. Synchronously computes the post-state via\n\t// the pure reducer so we can skip history pushes for no-op actions\n\t// and keep `stateRef` in lockstep with React's pending state.\n\tconst dispatchWithHistory = useCallback(\n\t\t( action: MediaEditorAction, recordHistory = true ) => {\n\t\t\tconst preState = stateRef.current;\n\t\t\tconst postState = mediaEditorReducer( preState, action );\n\t\t\tif ( recordHistory ) {\n\t\t\t\tif ( ! areMediaEditorStatesEqual( preState, postState ) ) {\n\t\t\t\t\tif ( isGestureOpenRef.current ) {\n\t\t\t\t\t\tif ( gestureSnapshotRef.current === null ) {\n\t\t\t\t\t\t\tgestureSnapshotRef.current = preState;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpushSnapshot( preState );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tstateRef.current = postState;\n\t\t\tdispatch( action );\n\t\t},\n\t\t[ pushSnapshot ]\n\t);\n\n\tconst beginGesture = useCallback( () => {\n\t\tif ( isGestureOpenRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tisGestureOpenRef.current = true;\n\t\tgestureSnapshotRef.current = null;\n\t}, [] );\n\n\t// Close a gesture (or flush a pending one before undo/redo).\n\t// Pushes the pre-gesture snapshot only if it differs from current\n\t// state. Safe to call when no gesture is open.\n\tconst endGesture = useCallback( () => {\n\t\tconst snapshot = gestureSnapshotRef.current;\n\t\tif (\n\t\t\tsnapshot &&\n\t\t\t! areMediaEditorStatesEqual( snapshot, stateRef.current )\n\t\t) {\n\t\t\tpushSnapshot( snapshot );\n\t\t}\n\t\tgestureSnapshotRef.current = null;\n\t\tisGestureOpenRef.current = false;\n\t}, [ pushSnapshot ] );\n\n\t// =====================================================================\n\t// Cropper-slice setters (built from the shared factory so the pure\n\t// hook and this composite stay in lockstep — add a setter in\n\t// `buildCropperSetters` once and both hooks get it).\n\t// =====================================================================\n\n\tconst dispatchCropperAction = useCallback(\n\t\t( action: CropperAction ) => {\n\t\t\tdispatchWithHistory( { type: 'CROPPER', action } );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst cropperSetters = useMemo(\n\t\t() =>\n\t\t\tbuildCropperSetters(\n\t\t\t\tdispatchCropperAction,\n\t\t\t\t() => stateRef.current.cropper\n\t\t\t),\n\t\t[ dispatchCropperAction ]\n\t);\n\n\tconst setImage = useCallback( ( image: CropperState[ 'image' ] ) => {\n\t\tif ( areCropperImagesEqual( stateRef.current.cropper.image, image ) ) {\n\t\t\treturn;\n\t\t}\n\t\t// New image = fresh canvas: clear history, refresh the\n\t\t// initial snapshot so isDirty starts at false.\n\t\tconst action = {\n\t\t\ttype: 'CROPPER' as const,\n\t\t\taction: { type: 'SET_IMAGE' as const, payload: image },\n\t\t};\n\t\tconst next = mediaEditorReducer( stateRef.current, action );\n\t\tstateRef.current = next;\n\t\tdispatch( action );\n\t\tsetInitialBaseline( next );\n\t\tisGestureOpenRef.current = false;\n\t\tgestureSnapshotRef.current = null;\n\t\thistoryRef.current = [];\n\t\tredoStackRef.current = [];\n\t\tsetHasUndo( false );\n\t\tsetHasRedo( false );\n\t}, [] );\n\n\tconst reset = useCallback(\n\t\t( resetState?: Partial< CropperState > ) => {\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'CROPPER',\n\t\t\t\taction: { type: 'RESET', payload: resetState },\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// CropOptions-slice setters\n\t// =====================================================================\n\n\tconst setAspectRatioValue = useCallback(\n\t\t( presetKey: string ) => {\n\t\t\tconst resolved = resolveAspectRatio(\n\t\t\t\tpresetKey,\n\t\t\t\tstateRef.current.cropper.image\n\t\t\t);\n\t\t\tdispatchWithHistory( {\n\t\t\t\ttype: 'SET_ASPECT_RATIO_VALUE',\n\t\t\t\tpayload: {\n\t\t\t\t\tpresetKey,\n\t\t\t\t\tresolved,\n\t\t\t\t\tvisualSize: visualSizeRef.current,\n\t\t\t\t},\n\t\t\t} );\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\tconst resetCropOptions = useCallback( () => {\n\t\tdispatchWithHistory( { type: 'RESET_CROP_OPTIONS' } );\n\t}, [ dispatchWithHistory ] );\n\n\t// =====================================================================\n\t// History\n\t// =====================================================================\n\n\tconst undo = useCallback( () => {\n\t\tendGesture();\n\t\tconst prev = historyRef.current[ historyRef.current.length - 1 ];\n\t\tif ( ! prev ) {\n\t\t\treturn;\n\t\t}\n\t\tredoStackRef.current = [ stateRef.current, ...redoStackRef.current ];\n\t\thistoryRef.current = historyRef.current.slice( 0, -1 );\n\t\tsetHasUndo( historyRef.current.length > 0 );\n\t\tsetHasRedo( true );\n\t\tstateRef.current = prev;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: prev } );\n\t}, [ endGesture ] );\n\n\tconst redo = useCallback( () => {\n\t\tendGesture();\n\t\tconst next = redoStackRef.current[ 0 ];\n\t\tif ( ! next ) {\n\t\t\treturn;\n\t\t}\n\t\thistoryRef.current = [ ...historyRef.current, stateRef.current ];\n\t\tredoStackRef.current = redoStackRef.current.slice( 1 );\n\t\tsetHasUndo( true );\n\t\tsetHasRedo( redoStackRef.current.length > 0 );\n\t\tstateRef.current = next;\n\t\tdispatch( { type: 'RESTORE_SNAPSHOT', payload: next } );\n\t}, [ endGesture ] );\n\n\t// =====================================================================\n\t// Viewport\n\t// =====================================================================\n\n\tconst setVisualSize = useCallback( ( size: Size ) => {\n\t\tvisualSizeRef.current = size;\n\t}, [] );\n\n\tconst adjustCropRectForViewport = useCallback(\n\t\t( rect: NormalizedRect ) => {\n\t\t\tdispatchWithHistory(\n\t\t\t\t{ type: 'VIEWPORT_ADJUST_CROP_RECT', payload: rect },\n\t\t\t\tfalse\n\t\t\t);\n\t\t},\n\t\t[ dispatchWithHistory ]\n\t);\n\n\t// =====================================================================\n\t// Derived\n\t// =====================================================================\n\n\tconst isDirty = ! areMediaEditorStatesEqual( state, initialBaseline );\n\tconst isCropperDirty = ! areCropperStatesEqual(\n\t\tstate.cropper,\n\t\tinitialBaseline.cropper\n\t);\n\n\tconst getCroppedImage = useCallback(\n\t\t( mimeType?: string, quality?: number ): Promise< Blob > => {\n\t\t\tif ( ! state.cropper.image ) {\n\t\t\t\treturn Promise.reject(\n\t\t\t\t\tnew Error( 'No image loaded — call setImage first.' )\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn exportCroppedImage(\n\t\t\t\tstate.cropper.image.src,\n\t\t\t\tstate.cropper,\n\t\t\t\tmimeType,\n\t\t\t\tquality\n\t\t\t);\n\t\t},\n\t\t[ state.cropper ]\n\t);\n\n\tconst controller = useMemo< MediaEditorController >(\n\t\t() => ( {\n\t\t\t// CropperController surface (state is the cropper slice so a\n\t\t\t// <Cropper> takes this controller as-is).\n\t\t\t...cropperSetters,\n\t\t\tstate: state.cropper,\n\t\t\tsetImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\tgetCroppedImage,\n\t\t\t// Composite extensions\n\t\t\tcropOptions: state.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tresetCropOptions,\n\t\t\tisCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t} ),\n\t\t[\n\t\t\tcropperSetters,\n\t\t\tstate.cropper,\n\t\t\tsetImage,\n\t\t\treset,\n\t\t\tisDirty,\n\t\t\tgetCroppedImage,\n\t\t\tstate.cropOptions,\n\t\t\tsetAspectRatioValue,\n\t\t\tresetCropOptions,\n\t\t\tisCropperDirty,\n\t\t\thasUndo,\n\t\t\thasRedo,\n\t\t\tundo,\n\t\t\tredo,\n\t\t\tbeginGesture,\n\t\t\tendGesture,\n\t\t\tsetVisualSize,\n\t\t\tadjustCropRectForViewport,\n\t\t]\n\t);\n\treturn controller;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAKP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAuBA,SAAS,mBACf,WACA,cACqB;AACrB,QAAM,MAAM,WAAY,SAAU;AAClC,MAAK,QAAQ,KAAK,OAAO,MAAO,GAAI,GAAI;AACvC,WAAO;AAAA,EACR;AACA,MAAK,QAAQ,uBAAwB;AACpC,QACC,gBACA,aAAa,eAAe,KAC5B,aAAa,gBAAgB,GAC5B;AACD,aAAO,aAAa,eAAe,aAAa;AAAA,IACjD;AACA,WAAO;AAAA,EACR;AACA,MAAK,MAAM,GAAI;AACd,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAEA,SAAS,sBACR,GACA,GACU;AACV,SACC,GAAG,QAAQ,GAAG,OACd,GAAG,iBAAiB,GAAG,gBACvB,GAAG,kBAAkB,GAAG;AAE1B;AAgFO,SAAS,oBACf,cACwB;AACxB,QAAM,CAAE,OAAO,QAAS,IAAI;AAAA,IAAY;AAAA,IAAoB;AAAA,IAAM,MACjE;AAAA,MACC,mBAAoB;AAAA,QACnB,GAAG;AAAA,QACH,GAAG,cAAc;AAAA,MAClB,CAAE;AAAA,MACF,cAAc;AAAA,IACf;AAAA,EACD;AAMA,QAAM,CAAE,iBAAiB,kBAAmB,IAC3C,SAA8B,MAAM,KAAM;AAO3C,QAAM,WAAW,OAAQ,KAAM;AAC/B,QAAM,gBAAgB,OAAgB,EAAE,OAAO,GAAG,QAAQ,EAAE,CAAE;AAK9D,QAAM,aAAa,OAA8B,CAAC,CAAE;AACpD,QAAM,eAAe,OAA8B,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AAgB;AACpE,QAAM,iBAAiB,CAAE;AAAA,IACxB,MAAM;AAAA,IACN,gBAAgB;AAAA,EACjB;AAEA,QAAM,kBAAkB;AAAA,IACvB,CAAE,UAAmB,YAAuC;AAC3D,UAAK,CAAE,MAAM,QAAQ,OAAQ;AAC5B,eAAO,QAAQ;AAAA,UACd,IAAI,MAAO,wCAAyC;AAAA,QACrD;AAAA,MACD;AACA,aAAO;AAAA,QACN,MAAM,QAAQ,MAAM;AAAA,QACpB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,MAAM,OAAQ;AAAA,EACjB;AAEA,QAAM,aAAa;AAAA,IAClB,OAAQ;AAAA;AAAA;AAAA,MAGP,GAAG;AAAA,MACH,OAAO,MAAM;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,aAAa,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -386,6 +386,9 @@
|
|
|
386
386
|
flex: 1;
|
|
387
387
|
flex-direction: column;
|
|
388
388
|
}
|
|
389
|
+
.media-editor-modal .media-editor .interface-interface-skeleton.interface-interface-skeleton {
|
|
390
|
+
top: auto;
|
|
391
|
+
}
|
|
389
392
|
.media-editor .interface-interface-skeleton__editor {
|
|
390
393
|
min-width: 0;
|
|
391
394
|
flex: 1;
|
|
@@ -399,11 +402,6 @@
|
|
|
399
402
|
border-radius: 8px;
|
|
400
403
|
overflow: hidden;
|
|
401
404
|
}
|
|
402
|
-
@media (min-width: 600px) {
|
|
403
|
-
.media-editor .media-editor__content {
|
|
404
|
-
margin-left: 16px;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
405
|
.media-editor .media-editor__canvas-toolbar {
|
|
408
406
|
display: flex;
|
|
409
407
|
flex-shrink: 0;
|
|
@@ -444,7 +442,7 @@
|
|
|
444
442
|
}
|
|
445
443
|
@media (min-width: 600px) {
|
|
446
444
|
.media-editor .media-editor__sidebar {
|
|
447
|
-
padding-right:
|
|
445
|
+
padding-right: 1px;
|
|
448
446
|
}
|
|
449
447
|
}
|
|
450
448
|
.media-editor .media-editor__sidebar-panel {
|
|
@@ -467,6 +465,12 @@
|
|
|
467
465
|
padding-right: 0;
|
|
468
466
|
padding-left: 8px;
|
|
469
467
|
margin-left: 24px;
|
|
468
|
+
margin-left: 0;
|
|
469
|
+
}
|
|
470
|
+
@media (min-width: 600px) {
|
|
471
|
+
.media-editor .components-panel__header.media-editor__sidebar-header {
|
|
472
|
+
margin-left: 24px;
|
|
473
|
+
}
|
|
470
474
|
}
|
|
471
475
|
.media-editor .components-panel__header.media-editor__sidebar-header .components-button.has-icon {
|
|
472
476
|
padding: 0;
|
|
@@ -594,6 +598,45 @@
|
|
|
594
598
|
width: 100%;
|
|
595
599
|
height: 100%;
|
|
596
600
|
}
|
|
601
|
+
.media-editor-canvas__cropper {
|
|
602
|
+
width: 100%;
|
|
603
|
+
height: 100%;
|
|
604
|
+
opacity: 0;
|
|
605
|
+
pointer-events: none;
|
|
606
|
+
}
|
|
607
|
+
.media-editor-canvas__cropper.is-loaded {
|
|
608
|
+
opacity: 1;
|
|
609
|
+
pointer-events: auto;
|
|
610
|
+
}
|
|
611
|
+
@keyframes __wp-base-styles-fade-in {
|
|
612
|
+
from {
|
|
613
|
+
opacity: 0;
|
|
614
|
+
}
|
|
615
|
+
to {
|
|
616
|
+
opacity: 1;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
@media not (prefers-reduced-motion) {
|
|
620
|
+
.media-editor-canvas__cropper.is-loaded {
|
|
621
|
+
animation: __wp-base-styles-fade-in 0.2s linear 0s;
|
|
622
|
+
animation-fill-mode: forwards;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
.media-editor-canvas__spinner {
|
|
626
|
+
position: absolute;
|
|
627
|
+
top: 50%;
|
|
628
|
+
right: 50%;
|
|
629
|
+
transform: translate(50%, -50%);
|
|
630
|
+
}
|
|
631
|
+
.media-editor-canvas__error {
|
|
632
|
+
display: flex;
|
|
633
|
+
align-items: center;
|
|
634
|
+
justify-content: center;
|
|
635
|
+
width: 100%;
|
|
636
|
+
height: 100%;
|
|
637
|
+
color: #757575;
|
|
638
|
+
text-align: center;
|
|
639
|
+
}
|
|
597
640
|
|
|
598
641
|
.media-editor-image-controls {
|
|
599
642
|
display: flex;
|