@wordpress/media-editor 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +7 -7
  3. package/build/components/media-editor/index.cjs.map +2 -2
  4. package/build/components/media-editor/use-save-media-editor.cjs.map +2 -2
  5. package/build/components/media-editor-crop-panel/index.cjs.map +3 -3
  6. package/build/image-editor/core/interaction-controller.cjs.map +2 -2
  7. package/build/image-editor/core/setter-helpers.cjs.map +2 -2
  8. package/build/image-editor/react/components/overlays/dimensions-overlay.cjs.map +2 -2
  9. package/build-module/components/media-editor/index.mjs.map +2 -2
  10. package/build-module/components/media-editor/use-save-media-editor.mjs.map +2 -2
  11. package/build-module/components/media-editor-crop-panel/index.mjs +2 -2
  12. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  13. package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
  14. package/build-module/image-editor/core/setter-helpers.mjs.map +2 -2
  15. package/build-module/image-editor/react/components/overlays/dimensions-overlay.mjs.map +2 -2
  16. package/build-style/style-rtl.css +21 -22
  17. package/build-style/style.css +6 -0
  18. package/global.d.ts +0 -1
  19. package/package.json +23 -24
  20. package/src/components/media-editor/index.tsx +2 -2
  21. package/src/components/media-editor/use-save-media-editor.ts +5 -5
  22. package/src/components/media-editor-crop-panel/index.tsx +2 -2
  23. package/src/components/media-editor-modal/test/index.jsdom.test.tsx +7 -7
  24. package/src/components/rotation-ruler/stories/index.story.tsx +2 -2
  25. package/src/components/rotation-ruler/style.scss +9 -0
  26. package/src/image-editor/core/interaction-controller.ts +2 -2
  27. package/src/image-editor/core/setter-helpers.ts +1 -1
  28. package/src/image-editor/react/components/cropper.scss +6 -0
  29. package/src/image-editor/react/components/overlays/dimensions-overlay.tsx +1 -1
  30. package/src/image-editor/react/components/stencils/test/{rectangle-stencil.jsdom.test.tsx → rectangle-stencil.browser.test.tsx} +80 -98
  31. package/src/image-editor/react/components/test/{cropper.jsdom.test.tsx → cropper.browser.test.tsx} +230 -221
  32. package/src/image-editor/react/hooks/test/use-aria-announcer.jsdom.test.ts +1 -1
  33. package/src/image-editor/stories/rectangle-crop.story.tsx +24 -23
  34. package/src/image-editor/stories/{style.css → style.module.css} +8 -37
  35. package/tsconfig.build.json +1 -1
  36. package/tsconfig.build.tsbuildinfo +1 -1
  37. package/tsconfig.json +1 -2
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/image-editor/core/setter-helpers.ts"],
4
- "sourcesContent": ["import type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom — zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperReducer` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0–1), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t }\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],
5
- "mappings": ";AACA,SAAS,gBAAgB;AACzB,SAAS,YAAY,uBAAuB;AAoBrC,SAAS,0BACf,OACA,eACuB;AACvB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,IAAK,WAAY,KAAM,GAAG,aAAc;AAAA,EAC9C;AACA,MAAK,gBAAgB,MAAM,MAAO;AACjC,WAAO;AAAA,EACR;AAKA,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;AACrD,QAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;AACtD,QAAM,YAAY,IAAI,cAAc,MAAM;AAC1C,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,YAA+C,MAAM,QACxD;AAAA,IACA,OAAO,MAAM,MAAM;AAAA,IACnB,QAAQ,MAAM,MAAM;AAAA,EACpB,IACA,EAAE,OAAO,GAAG,QAAQ,EAAE;AACzB,QAAM,EAAE,KAAK,WAAW,IAA8B;AAAA,IACrD;AAAA,MACC,GAAG;AAAA,MACH,MAAM;AAAA,MACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACP;AACA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS,EAAE,MAAM,aAAa,KAAK,WAAW;AAAA,EAC/C;AACD;",
4
+ "sourcesContent": ["import type { CropperState, NormalizedPoint, CropperAction } from './types';\nimport { MAX_ZOOM } from './constants';\nimport { getMinZoom, restrictPanZoom } from './containment';\n\n/**\n * Build the reducer action that produces a \"cursorless\" zoom — zoom\n * anchored at the current crop-rect center, with pan clamped to keep\n * the image covering the crop.\n *\n * The slider, the `+`/`-` keys, and the toolbar buttons have no\n * natural focal point (unlike wheel/pinch zoom), so they default to\n * the crop center. Returns `null` when the clamped zoom matches the\n * current zoom (no-op).\n *\n * Extracted so multiple hooks (the pure `useCropperReducer` and the\n * composite `useMediaEditorState`) can share the math without\n * duplicating it.\n *\n * @param state The current cropper state.\n * @param requestedZoom The zoom value the caller asked for.\n * @return A `SET_ZOOM_AT_POINT` action, or `null` if no change is required.\n */\nexport function buildFocalPointZoomAction(\n\tstate: CropperState,\n\trequestedZoom: number\n): CropperAction | null {\n\tconst clampedZoom = Math.min(\n\t\tMAX_ZOOM,\n\t\tMath.max( getMinZoom( state ), requestedZoom )\n\t);\n\tif ( clampedZoom === state.zoom ) {\n\t\treturn null;\n\t}\n\t// Crop center expressed in the same coord system as `state.pan`:\n\t// container-center-relative, normalized by image rendered size.\n\t// `cropRect` is image-top-left-origin (0–1), so subtract 0.5\n\t// to recenter.\n\tconst { cropRect } = state;\n\tconst focalNormX = cropRect.x + cropRect.width / 2 - 0.5;\n\tconst focalNormY = cropRect.y + cropRect.height / 2 - 0.5;\n\tconst zoomRatio = 1 - clampedZoom / state.zoom;\n\tconst newPanX = state.pan.x + ( focalNormX - state.pan.x ) * zoomRatio;\n\tconst newPanY = state.pan.y + ( focalNormY - state.pan.y ) * zoomRatio;\n\tconst imageSize: { width: number; height: number } = state.image\n\t\t? {\n\t\t\t\twidth: state.image.naturalWidth,\n\t\t\t\theight: state.image.naturalHeight,\n\t\t\t}\n\t\t: { width: 1, height: 1 };\n\tconst { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(\n\t\t{\n\t\t\t...state,\n\t\t\tzoom: clampedZoom,\n\t\t\tpan: { x: newPanX, y: newPanY },\n\t\t},\n\t\timageSize,\n\t\tstate.cropRect\n\t);\n\treturn {\n\t\ttype: 'SET_ZOOM_AT_POINT',\n\t\tpayload: { zoom: clampedZoom, pan: clampedPan },\n\t};\n}\n"],
5
+ "mappings": ";AACA,SAAS,gBAAgB;AACzB,SAAS,YAAY,uBAAuB;AAoBrC,SAAS,0BACf,OACA,eACuB;AACvB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,IACA,KAAK,IAAK,WAAY,KAAM,GAAG,aAAc;AAAA,EAC9C;AACA,MAAK,gBAAgB,MAAM,MAAO;AACjC,WAAO;AAAA,EACR;AAKA,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,aAAa,SAAS,IAAI,SAAS,QAAQ,IAAI;AACrD,QAAM,aAAa,SAAS,IAAI,SAAS,SAAS,IAAI;AACtD,QAAM,YAAY,IAAI,cAAc,MAAM;AAC1C,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,UAAU,MAAM,IAAI,KAAM,aAAa,MAAM,IAAI,KAAM;AAC7D,QAAM,YAA+C,MAAM,QACxD;AAAA,IACA,OAAO,MAAM,MAAM;AAAA,IACnB,QAAQ,MAAM,MAAM;AAAA,EACrB,IACC,EAAE,OAAO,GAAG,QAAQ,EAAE;AACzB,QAAM,EAAE,KAAK,WAAW,IAA8B;AAAA,IACrD;AAAA,MACC,GAAG;AAAA,MACH,MAAM;AAAA,MACN,KAAK,EAAE,GAAG,SAAS,GAAG,QAAQ;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACP;AACA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS,EAAE,MAAM,aAAa,KAAK,WAAW;AAAA,EAC/C;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/image-editor/react/components/overlays/dimensions-overlay.tsx"],
4
- "sourcesContent": ["import { useLayoutEffect, useRef, useState } from '@wordpress/element';\nimport type { HandlePosition, NormalizedRect, Size } from '../../../core/types';\n\nconst HANDLE_GAP_PX = 12;\n\n/**\n * Which side of the handle a tooltip axis sits on. `before` places the\n * tooltip on the negative side of the handle (above for Y, left for X),\n * `after` on the positive side, `center` keeps it aligned with the handle.\n */\ntype AxisSide = 'before' | 'center' | 'after';\n\ninterface Anchor {\n\tx: AxisSide;\n\ty: AxisSide;\n}\n\nconst TRANSLATE_PERCENT: Record< AxisSide, string > = {\n\tbefore: '-100%',\n\tcenter: '-50%',\n\tafter: '0',\n};\n\nconst GAP_DIRECTION: Record< AxisSide, number > = {\n\tbefore: -1,\n\tcenter: 0,\n\tafter: 1,\n};\n\nconst OPPOSITE_SIDE: Record< AxisSide, AxisSide > = {\n\tbefore: 'after',\n\tcenter: 'center',\n\tafter: 'before',\n};\n\n/**\n * Preferred anchor for a handle, before edge-clipping is considered:\n * tooltip sits outward from the crop rectangle's center.\n *\n * @param handle\n */\nfunction preferredAnchor( handle: HandlePosition ): Anchor {\n\tlet x: AxisSide = 'center';\n\tif ( handle.includes( 'w' ) ) {\n\t\tx = 'before';\n\t} else if ( handle.includes( 'e' ) ) {\n\t\tx = 'after';\n\t}\n\n\tlet y: AxisSide = 'center';\n\tif ( handle.includes( 'n' ) ) {\n\t\ty = 'before';\n\t} else if ( handle.includes( 's' ) ) {\n\t\ty = 'after';\n\t}\n\n\treturn { x, y };\n}\n\n/**\n * Start coordinate of a tooltip placed on the given side of `handlePos`,\n * accounting for the per-side handle gap and the tooltip's own length.\n *\n * @param side\n * @param handlePos\n * @param length\n */\nfunction sideStart(\n\tside: AxisSide,\n\thandlePos: number,\n\tlength: number\n): number {\n\tif ( side === 'before' ) {\n\t\treturn handlePos - HANDLE_GAP_PX - length;\n\t}\n\tif ( side === 'after' ) {\n\t\treturn handlePos + HANDLE_GAP_PX;\n\t}\n\treturn handlePos - length / 2;\n}\n\n/**\n * Picks a side that keeps the tooltip inside the container along one\n * axis, preferring the supplied side and falling back to its opposite,\n * then center.\n *\n * @param preferred\n * @param handlePos\n * @param length\n * @param containerLength\n */\nfunction fittingSide(\n\tpreferred: AxisSide,\n\thandlePos: number,\n\tlength: number,\n\tcontainerLength: number\n): AxisSide {\n\tconst fits = ( side: AxisSide ) => {\n\t\tconst start = sideStart( side, handlePos, length );\n\t\treturn start >= 0 && start + length <= containerLength;\n\t};\n\n\tif ( fits( preferred ) ) {\n\t\treturn preferred;\n\t}\n\tconst opposite = OPPOSITE_SIDE[ preferred ];\n\tif ( opposite !== preferred && fits( opposite ) ) {\n\t\treturn opposite;\n\t}\n\tif ( preferred !== 'center' && fits( 'center' ) ) {\n\t\treturn 'center';\n\t}\n\t// None of the candidates fully fit — pick the one that pushes the\n\t// least past the container edge. Without this, the chain falls back\n\t// to `preferred`, which is the off-canvas side that triggered the\n\t// flip in the first place, so the tooltip ends up clipped.\n\tconst overflow = ( side: AxisSide ) => {\n\t\tconst start = sideStart( side, handlePos, length );\n\t\treturn (\n\t\t\tMath.max( 0, -start ) +\n\t\t\tMath.max( 0, start + length - containerLength )\n\t\t);\n\t};\n\tconst candidates: AxisSide[] = [ preferred, opposite, 'center' ];\n\treturn candidates.reduce( ( best, side ) =>\n\t\toverflow( side ) < overflow( best ) ? side : best\n\t);\n}\n\ninterface DimensionsOverlayProps {\n\t/** Crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** Container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** Rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n\t/** Currently-dragged handle, or null when no pointer drag is active. */\n\tactiveHandle: HandlePosition | null;\n\t/** Output crop width in source pixels. */\n\toutputWidth: number;\n\t/** Output crop height in source pixels. */\n\toutputHeight: number;\n}\n\n/**\n * Tooltip that follows the active resize handle during a pointer drag,\n * showing the current output dimensions of the crop in source pixels.\n *\n * Renders nothing outside of a pointer-driven resize, so keyboard\n * arrow-key adjustments and pan/zoom gestures stay quiet.\n *\n * @param props\n * @param props.cropRect\n * @param props.containerSize\n * @param props.imageSize\n * @param props.activeHandle\n * @param props.outputWidth\n * @param props.outputHeight\n */\nexport function DimensionsOverlay( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tactiveHandle,\n\toutputWidth,\n\toutputHeight,\n}: DimensionsOverlayProps ) {\n\tconst tooltipRef = useRef< HTMLDivElement >( null );\n\tconst [ tooltipSize, setTooltipSize ] = useState< Size | null >( null );\n\n\t// Measure the rendered tooltip so we can flip its anchor when it\n\t// would otherwise be clipped by the cropper's `overflow: hidden`\n\t// root. Runs synchronously before paint, so the user never sees\n\t// the un-flipped position. Tracks `outputWidth`/`outputHeight`\n\t// because they drive the digit count, the only thing that changes\n\t// the tooltip's intrinsic size during a drag.\n\tuseLayoutEffect( () => {\n\t\tif ( ! tooltipRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = tooltipRef.current.getBoundingClientRect();\n\t\tsetTooltipSize( ( prev ) => {\n\t\t\tif (\n\t\t\t\tprev &&\n\t\t\t\tprev.width === rect.width &&\n\t\t\t\tprev.height === rect.height\n\t\t\t) {\n\t\t\t\treturn prev;\n\t\t\t}\n\t\t\treturn { width: rect.width, height: rect.height };\n\t\t} );\n\t}, [ outputWidth, outputHeight ] );\n\n\tif (\n\t\t! activeHandle ||\n\t\tcontainerSize.width === 0 ||\n\t\tcontainerSize.height === 0\n\t) {\n\t\treturn null;\n\t}\n\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// Handle pixel position within the container. Same math as the\n\t// stencil's handle layout, just keyed by direction here so the\n\t// tooltip can anchor to any of the eight.\n\tlet handleX = left + width / 2;\n\tif ( activeHandle.includes( 'w' ) ) {\n\t\thandleX = left;\n\t} else if ( activeHandle.includes( 'e' ) ) {\n\t\thandleX = left + width;\n\t}\n\tlet handleY = top + height / 2;\n\tif ( activeHandle.includes( 'n' ) ) {\n\t\thandleY = top;\n\t} else if ( activeHandle.includes( 's' ) ) {\n\t\thandleY = top + height;\n\t}\n\n\tconst preferred = preferredAnchor( activeHandle );\n\tconst anchor: Anchor = tooltipSize\n\t\t? {\n\t\t\t\tx: fittingSide(\n\t\t\t\t\tpreferred.x,\n\t\t\t\t\thandleX,\n\t\t\t\t\ttooltipSize.width,\n\t\t\t\t\tcontainerSize.width\n\t\t\t\t),\n\t\t\t\ty: fittingSide(\n\t\t\t\t\tpreferred.y,\n\t\t\t\t\thandleY,\n\t\t\t\t\ttooltipSize.height,\n\t\t\t\t\tcontainerSize.height\n\t\t\t\t),\n\t\t }\n\t\t: preferred;\n\n\treturn (\n\t\t<div\n\t\t\tref={ tooltipRef }\n\t\t\tclassName=\"wp-media-editor-image-editor__dimensions-tooltip\"\n\t\t\tdata-testid=\"cropper-dimensions-tooltip\"\n\t\t\tstyle={ {\n\t\t\t\tleft: handleX + GAP_DIRECTION[ anchor.x ] * HANDLE_GAP_PX,\n\t\t\t\ttop: handleY + GAP_DIRECTION[ anchor.y ] * HANDLE_GAP_PX,\n\t\t\t\ttransform: `translate(${ TRANSLATE_PERCENT[ anchor.x ] }, ${\n\t\t\t\t\tTRANSLATE_PERCENT[ anchor.y ]\n\t\t\t\t})`,\n\t\t\t} }\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t{ `W: ${ Math.round( outputWidth ) }px H: ${ Math.round(\n\t\t\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,SAAU,GAAI,GAAI;AACnC,cAAU;AAAA,EACX,WAAY,aAAa,SAAU,GAAI,GAAI;AAC1C,cAAU,OAAO;AAAA,EAClB;AACA,MAAI,UAAU,MAAM,SAAS;AAC7B,MAAK,aAAa,SAAU,GAAI,GAAI;AACnC,cAAU;AAAA,EACX,WAAY,aAAa,SAAU,GAAI,GAAI;AAC1C,cAAU,MAAM;AAAA,EACjB;AAEA,QAAM,YAAY,gBAAiB,YAAa;AAChD,QAAM,SAAiB,cACpB;AAAA,IACA,GAAG;AAAA,MACF,UAAU;AAAA,MACV;AAAA,MACA,YAAY;AAAA,MACZ,cAAc;AAAA,IACf;AAAA,IACA,GAAG;AAAA,MACF,UAAU;AAAA,MACV;AAAA,MACA,YAAY;AAAA,MACZ,cAAc;AAAA,IACf;AAAA,EACA,IACA;AAEH,SACC;AAAA,IAAC;AAAA;AAAA,MACA,KAAM;AAAA,MACN,WAAU;AAAA,MACV,eAAY;AAAA,MACZ,OAAQ;AAAA,QACP,MAAM,UAAU,cAAe,OAAO,CAAE,IAAI;AAAA,QAC5C,KAAK,UAAU,cAAe,OAAO,CAAE,IAAI;AAAA,QAC3C,WAAW,aAAc,kBAAmB,OAAO,CAAE,CAAE,KACtD,kBAAmB,OAAO,CAAE,CAC7B;AAAA,MACD;AAAA,MACA,eAAY;AAAA,MAEV,gBAAO,KAAK,MAAO,WAAY,CAAE,SAAU,KAAK;AAAA,QACjD;AAAA,MACD,CAAE;AAAA;AAAA,EACH;AAEF;",
4
+ "sourcesContent": ["import { useLayoutEffect, useRef, useState } from '@wordpress/element';\nimport type { HandlePosition, NormalizedRect, Size } from '../../../core/types';\n\nconst HANDLE_GAP_PX = 12;\n\n/**\n * Which side of the handle a tooltip axis sits on. `before` places the\n * tooltip on the negative side of the handle (above for Y, left for X),\n * `after` on the positive side, `center` keeps it aligned with the handle.\n */\ntype AxisSide = 'before' | 'center' | 'after';\n\ninterface Anchor {\n\tx: AxisSide;\n\ty: AxisSide;\n}\n\nconst TRANSLATE_PERCENT: Record< AxisSide, string > = {\n\tbefore: '-100%',\n\tcenter: '-50%',\n\tafter: '0',\n};\n\nconst GAP_DIRECTION: Record< AxisSide, number > = {\n\tbefore: -1,\n\tcenter: 0,\n\tafter: 1,\n};\n\nconst OPPOSITE_SIDE: Record< AxisSide, AxisSide > = {\n\tbefore: 'after',\n\tcenter: 'center',\n\tafter: 'before',\n};\n\n/**\n * Preferred anchor for a handle, before edge-clipping is considered:\n * tooltip sits outward from the crop rectangle's center.\n *\n * @param handle\n */\nfunction preferredAnchor( handle: HandlePosition ): Anchor {\n\tlet x: AxisSide = 'center';\n\tif ( handle.includes( 'w' ) ) {\n\t\tx = 'before';\n\t} else if ( handle.includes( 'e' ) ) {\n\t\tx = 'after';\n\t}\n\n\tlet y: AxisSide = 'center';\n\tif ( handle.includes( 'n' ) ) {\n\t\ty = 'before';\n\t} else if ( handle.includes( 's' ) ) {\n\t\ty = 'after';\n\t}\n\n\treturn { x, y };\n}\n\n/**\n * Start coordinate of a tooltip placed on the given side of `handlePos`,\n * accounting for the per-side handle gap and the tooltip's own length.\n *\n * @param side\n * @param handlePos\n * @param length\n */\nfunction sideStart(\n\tside: AxisSide,\n\thandlePos: number,\n\tlength: number\n): number {\n\tif ( side === 'before' ) {\n\t\treturn handlePos - HANDLE_GAP_PX - length;\n\t}\n\tif ( side === 'after' ) {\n\t\treturn handlePos + HANDLE_GAP_PX;\n\t}\n\treturn handlePos - length / 2;\n}\n\n/**\n * Picks a side that keeps the tooltip inside the container along one\n * axis, preferring the supplied side and falling back to its opposite,\n * then center.\n *\n * @param preferred\n * @param handlePos\n * @param length\n * @param containerLength\n */\nfunction fittingSide(\n\tpreferred: AxisSide,\n\thandlePos: number,\n\tlength: number,\n\tcontainerLength: number\n): AxisSide {\n\tconst fits = ( side: AxisSide ) => {\n\t\tconst start = sideStart( side, handlePos, length );\n\t\treturn start >= 0 && start + length <= containerLength;\n\t};\n\n\tif ( fits( preferred ) ) {\n\t\treturn preferred;\n\t}\n\tconst opposite = OPPOSITE_SIDE[ preferred ];\n\tif ( opposite !== preferred && fits( opposite ) ) {\n\t\treturn opposite;\n\t}\n\tif ( preferred !== 'center' && fits( 'center' ) ) {\n\t\treturn 'center';\n\t}\n\t// None of the candidates fully fit — pick the one that pushes the\n\t// least past the container edge. Without this, the chain falls back\n\t// to `preferred`, which is the off-canvas side that triggered the\n\t// flip in the first place, so the tooltip ends up clipped.\n\tconst overflow = ( side: AxisSide ) => {\n\t\tconst start = sideStart( side, handlePos, length );\n\t\treturn (\n\t\t\tMath.max( 0, -start ) +\n\t\t\tMath.max( 0, start + length - containerLength )\n\t\t);\n\t};\n\tconst candidates: AxisSide[] = [ preferred, opposite, 'center' ];\n\treturn candidates.reduce( ( best, side ) =>\n\t\toverflow( side ) < overflow( best ) ? side : best\n\t);\n}\n\ninterface DimensionsOverlayProps {\n\t/** Crop rectangle in normalized coordinates. */\n\tcropRect: NormalizedRect;\n\t/** Container element dimensions in pixels. */\n\tcontainerSize: Size;\n\t/** Rendered image dimensions in pixels within the container. */\n\timageSize: Size;\n\t/** Currently-dragged handle, or null when no pointer drag is active. */\n\tactiveHandle: HandlePosition | null;\n\t/** Output crop width in source pixels. */\n\toutputWidth: number;\n\t/** Output crop height in source pixels. */\n\toutputHeight: number;\n}\n\n/**\n * Tooltip that follows the active resize handle during a pointer drag,\n * showing the current output dimensions of the crop in source pixels.\n *\n * Renders nothing outside of a pointer-driven resize, so keyboard\n * arrow-key adjustments and pan/zoom gestures stay quiet.\n *\n * @param props\n * @param props.cropRect\n * @param props.containerSize\n * @param props.imageSize\n * @param props.activeHandle\n * @param props.outputWidth\n * @param props.outputHeight\n */\nexport function DimensionsOverlay( {\n\tcropRect,\n\tcontainerSize,\n\timageSize,\n\tactiveHandle,\n\toutputWidth,\n\toutputHeight,\n}: DimensionsOverlayProps ) {\n\tconst tooltipRef = useRef< HTMLDivElement >( null );\n\tconst [ tooltipSize, setTooltipSize ] = useState< Size | null >( null );\n\n\t// Measure the rendered tooltip so we can flip its anchor when it\n\t// would otherwise be clipped by the cropper's `overflow: hidden`\n\t// root. Runs synchronously before paint, so the user never sees\n\t// the un-flipped position. Tracks `outputWidth`/`outputHeight`\n\t// because they drive the digit count, the only thing that changes\n\t// the tooltip's intrinsic size during a drag.\n\tuseLayoutEffect( () => {\n\t\tif ( ! tooltipRef.current ) {\n\t\t\treturn;\n\t\t}\n\t\tconst rect = tooltipRef.current.getBoundingClientRect();\n\t\tsetTooltipSize( ( prev ) => {\n\t\t\tif (\n\t\t\t\tprev &&\n\t\t\t\tprev.width === rect.width &&\n\t\t\t\tprev.height === rect.height\n\t\t\t) {\n\t\t\t\treturn prev;\n\t\t\t}\n\t\t\treturn { width: rect.width, height: rect.height };\n\t\t} );\n\t}, [ outputWidth, outputHeight ] );\n\n\tif (\n\t\t! activeHandle ||\n\t\tcontainerSize.width === 0 ||\n\t\tcontainerSize.height === 0\n\t) {\n\t\treturn null;\n\t}\n\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// Handle pixel position within the container. Same math as the\n\t// stencil's handle layout, just keyed by direction here so the\n\t// tooltip can anchor to any of the eight.\n\tlet handleX = left + width / 2;\n\tif ( activeHandle.includes( 'w' ) ) {\n\t\thandleX = left;\n\t} else if ( activeHandle.includes( 'e' ) ) {\n\t\thandleX = left + width;\n\t}\n\tlet handleY = top + height / 2;\n\tif ( activeHandle.includes( 'n' ) ) {\n\t\thandleY = top;\n\t} else if ( activeHandle.includes( 's' ) ) {\n\t\thandleY = top + height;\n\t}\n\n\tconst preferred = preferredAnchor( activeHandle );\n\tconst anchor: Anchor = tooltipSize\n\t\t? {\n\t\t\t\tx: fittingSide(\n\t\t\t\t\tpreferred.x,\n\t\t\t\t\thandleX,\n\t\t\t\t\ttooltipSize.width,\n\t\t\t\t\tcontainerSize.width\n\t\t\t\t),\n\t\t\t\ty: fittingSide(\n\t\t\t\t\tpreferred.y,\n\t\t\t\t\thandleY,\n\t\t\t\t\ttooltipSize.height,\n\t\t\t\t\tcontainerSize.height\n\t\t\t\t),\n\t\t\t}\n\t\t: preferred;\n\n\treturn (\n\t\t<div\n\t\t\tref={ tooltipRef }\n\t\t\tclassName=\"wp-media-editor-image-editor__dimensions-tooltip\"\n\t\t\tdata-testid=\"cropper-dimensions-tooltip\"\n\t\t\tstyle={ {\n\t\t\t\tleft: handleX + GAP_DIRECTION[ anchor.x ] * HANDLE_GAP_PX,\n\t\t\t\ttop: handleY + GAP_DIRECTION[ anchor.y ] * HANDLE_GAP_PX,\n\t\t\t\ttransform: `translate(${ TRANSLATE_PERCENT[ anchor.x ] }, ${\n\t\t\t\t\tTRANSLATE_PERCENT[ anchor.y ]\n\t\t\t\t})`,\n\t\t\t} }\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t{ `W: ${ Math.round( outputWidth ) }px H: ${ Math.round(\n\t\t\t\toutputHeight\n\t\t\t) }px` }\n\t\t</div>\n\t);\n}\n"],
5
+ "mappings": ";AAAA,SAAS,iBAAiB,QAAQ,gBAAgB;AAmPhD;AAhPF,IAAM,gBAAgB;AActB,IAAM,oBAAgD;AAAA,EACrD,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AACR;AAEA,IAAM,gBAA4C;AAAA,EACjD,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AACR;AAEA,IAAM,gBAA8C;AAAA,EACnD,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AACR;AAQA,SAAS,gBAAiB,QAAiC;AAC1D,MAAI,IAAc;AAClB,MAAK,OAAO,SAAU,GAAI,GAAI;AAC7B,QAAI;AAAA,EACL,WAAY,OAAO,SAAU,GAAI,GAAI;AACpC,QAAI;AAAA,EACL;AAEA,MAAI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AAA,MACA,KAAM;AAAA,MACN,WAAU;AAAA,MACV,eAAY;AAAA,MACZ,OAAQ;AAAA,QACP,MAAM,UAAU,cAAe,OAAO,CAAE,IAAI;AAAA,QAC5C,KAAK,UAAU,cAAe,OAAO,CAAE,IAAI;AAAA,QAC3C,WAAW,aAAc,kBAAmB,OAAO,CAAE,CAAE,KACtD,kBAAmB,OAAO,CAAE,CAC7B;AAAA,MACD;AAAA,MACA,eAAY;AAAA,MAEV,gBAAO,KAAK,MAAO,WAAY,CAAE,SAAU,KAAK;AAAA,QACjD;AAAA,MACD,CAAE;AAAA;AAAA,EACH;AAEF;",
6
6
  "names": []
7
7
  }
@@ -125,7 +125,6 @@
125
125
  word-break: break-all;
126
126
  margin-top: 8px;
127
127
  }
128
-
129
128
  .wp-media-editor-image-editor {
130
129
  position: relative;
131
130
  overflow: hidden;
@@ -155,7 +154,7 @@
155
154
  .wp-media-editor-image-editor__image {
156
155
  position: absolute;
157
156
  top: 0;
158
- right: 0;
157
+ left: 0;
159
158
  will-change: transform;
160
159
  transform-origin: center center;
161
160
  }
@@ -199,7 +198,7 @@
199
198
  background: rgba(255, 255, 255, 0.4);
200
199
  }
201
200
  .wp-media-editor-image-editor__grid-line--horizontal {
202
- right: 0;
201
+ left: 0;
203
202
  width: 100%;
204
203
  height: 1px;
205
204
  }
@@ -260,59 +259,58 @@
260
259
  content: "";
261
260
  position: absolute;
262
261
  top: 50%;
263
- right: 50%;
262
+ left: 50%;
264
263
  width: 44px;
265
264
  height: 44px;
266
- transform: translate(50%, -50%);
265
+ transform: translate(-50%, -50%);
267
266
  }
268
267
  .wp-media-editor-image-editor__handle {
269
268
  /* Offset by half the handle width (12px / 2 = 6px) to center on crop edge */
270
269
  }
271
270
  .wp-media-editor-image-editor__handle--n {
272
271
  top: -6px;
273
- right: 50%;
274
- margin-right: -6px;
272
+ left: 50%;
273
+ margin-left: -6px;
275
274
  cursor: ns-resize;
276
275
  }
277
276
  .wp-media-editor-image-editor__handle--s {
278
277
  bottom: -6px;
279
- right: 50%;
280
- margin-right: -6px;
278
+ left: 50%;
279
+ margin-left: -6px;
281
280
  cursor: ns-resize;
282
281
  }
283
282
  .wp-media-editor-image-editor__handle--e {
284
283
  top: 50%;
285
- left: -6px;
284
+ right: -6px;
286
285
  margin-top: -6px;
287
286
  cursor: ew-resize;
288
287
  }
289
288
  .wp-media-editor-image-editor__handle--w {
290
289
  top: 50%;
291
- right: -6px;
290
+ left: -6px;
292
291
  margin-top: -6px;
293
292
  cursor: ew-resize;
294
293
  }
295
294
  .wp-media-editor-image-editor__handle--nw {
296
295
  top: -6px;
297
- right: -6px;
298
- cursor: nesw-resize;
296
+ left: -6px;
297
+ cursor: nwse-resize;
299
298
  }
300
299
  .wp-media-editor-image-editor__handle--ne {
301
300
  top: -6px;
302
- left: -6px;
303
- cursor: nwse-resize;
301
+ right: -6px;
302
+ cursor: nesw-resize;
304
303
  }
305
304
  .wp-media-editor-image-editor__handle--sw {
306
305
  bottom: -6px;
307
- right: -6px;
308
- cursor: nwse-resize;
306
+ left: -6px;
307
+ cursor: nesw-resize;
309
308
  }
310
309
  .wp-media-editor-image-editor__handle--se {
311
310
  bottom: -6px;
312
- left: -6px;
313
- cursor: nesw-resize;
311
+ right: -6px;
312
+ cursor: nwse-resize;
314
313
  }
315
-
316
314
  /**
317
315
  * Breakpoints & Media Queries
318
316
  */
@@ -692,6 +690,7 @@
692
690
  user-select: none;
693
691
  touch-action: none;
694
692
  cursor: ew-resize;
693
+ direction: ltr;
695
694
  container-type: inline-size;
696
695
  }
697
696
  .rotation-ruler[data-disabled] {
@@ -797,13 +796,13 @@
797
796
  .rotation-ruler__active-label-sign {
798
797
  position: absolute;
799
798
  top: 0;
800
- left: 100%;
799
+ right: 100%;
801
800
  }
802
801
 
803
802
  .rotation-ruler__active-label-unit {
804
803
  position: absolute;
805
804
  top: 0;
806
- right: 100%;
805
+ left: 100%;
807
806
  }
808
807
 
809
808
  @container (max-width: 220px) {
@@ -126,6 +126,7 @@
126
126
  margin-top: 8px;
127
127
  }
128
128
 
129
+ /*!rtl:begin:ignore*/
129
130
  .wp-media-editor-image-editor {
130
131
  position: relative;
131
132
  overflow: hidden;
@@ -313,6 +314,7 @@
313
314
  cursor: nwse-resize;
314
315
  }
315
316
 
317
+ /*!rtl:end:ignore*/
316
318
  /**
317
319
  * Breakpoints & Media Queries
318
320
  */
@@ -692,6 +694,8 @@
692
694
  user-select: none;
693
695
  touch-action: none;
694
696
  cursor: ew-resize;
697
+ /*rtl:ignore*/
698
+ direction: ltr;
695
699
  container-type: inline-size;
696
700
  }
697
701
  .rotation-ruler[data-disabled] {
@@ -798,12 +802,14 @@
798
802
  .rotation-ruler__active-label-sign {
799
803
  position: absolute;
800
804
  top: 0;
805
+ /*rtl:ignore*/
801
806
  right: 100%;
802
807
  }
803
808
 
804
809
  .rotation-ruler__active-label-unit {
805
810
  position: absolute;
806
811
  top: 0;
812
+ /*rtl:ignore*/
807
813
  left: 100%;
808
814
  }
809
815
 
package/global.d.ts CHANGED
@@ -2,5 +2,4 @@
2
2
  * With typeRoots set in tsconfig, global types outside those directories,
3
3
  * like the jest-dom matchers, must be referenced explicitly.
4
4
  */
5
- import '@testing-library/jest-dom';
6
5
  import '@testing-library/jest-dom/vitest';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/media-editor",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Media editor components for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -21,8 +21,7 @@
21
21
  "url": "https://github.com/WordPress/gutenberg/issues"
22
22
  },
23
23
  "engines": {
24
- "node": ">=18.12.0",
25
- "npm": ">=8.19.2"
24
+ "node": ">=18.12.0"
26
25
  },
27
26
  "main": "build/index.cjs",
28
27
  "module": "build-module/index.mjs",
@@ -43,34 +42,34 @@
43
42
  "build-module/store/index.mjs"
44
43
  ],
45
44
  "dependencies": {
46
- "@wordpress/a11y": "^4.55.0",
47
- "@wordpress/admin-ui": "^2.10.0",
48
- "@wordpress/api-fetch": "^7.55.0",
49
- "@wordpress/base-styles": "^13.1.0",
50
- "@wordpress/components": "^40.1.0",
51
- "@wordpress/compose": "^8.8.0",
52
- "@wordpress/core-data": "^8.0.0",
53
- "@wordpress/data": "^10.55.0",
54
- "@wordpress/dataviews": "^19.0.0",
55
- "@wordpress/element": "^8.7.0",
56
- "@wordpress/i18n": "^6.28.0",
57
- "@wordpress/icons": "^16.0.0",
58
- "@wordpress/keyboard-shortcuts": "^5.55.0",
59
- "@wordpress/keycodes": "^4.55.0",
60
- "@wordpress/notices": "^5.55.0",
61
- "@wordpress/private-apis": "^1.55.0",
62
- "@wordpress/ui": "^0.22.0",
45
+ "@wordpress/a11y": "^4.56.0",
46
+ "@wordpress/admin-ui": "^2.11.0",
47
+ "@wordpress/api-fetch": "^7.56.0",
48
+ "@wordpress/base-styles": "^13.2.0",
49
+ "@wordpress/components": "^41.0.0",
50
+ "@wordpress/compose": "^8.9.0",
51
+ "@wordpress/core-data": "^8.1.0",
52
+ "@wordpress/data": "^10.56.0",
53
+ "@wordpress/dataviews": "^19.1.0",
54
+ "@wordpress/element": "^8.8.0",
55
+ "@wordpress/i18n": "^6.29.0",
56
+ "@wordpress/icons": "^17.0.0",
57
+ "@wordpress/keyboard-shortcuts": "^5.56.0",
58
+ "@wordpress/keycodes": "^4.56.0",
59
+ "@wordpress/notices": "^5.56.0",
60
+ "@wordpress/private-apis": "^1.56.0",
61
+ "@wordpress/ui": "^0.23.0",
63
62
  "clsx": "^2.1.1",
64
63
  "gl-matrix": "^3.4.3"
65
64
  },
66
65
  "devDependencies": {
67
66
  "@storybook/react-vite": "^10.5.3",
68
- "@testing-library/dom": "^10.4.1",
67
+ "@testing-library/dom": "^10.4.2",
69
68
  "@testing-library/jest-dom": "^7.0.1",
70
69
  "@testing-library/react": "^16.3.3",
71
70
  "@testing-library/user-event": "^14.6.1",
72
- "@types/jest": "^30.0.0",
73
- "vitest": "^5.0.0"
71
+ "vitest": "^5.0.0",
72
+ "vitest-browser-react": "^2.3.0"
74
73
  },
75
74
  "peerDependencies": {
76
75
  "@types/react": "^18 || ^19",
@@ -84,5 +83,5 @@
84
83
  "publishConfig": {
85
84
  "access": "public"
86
85
  },
87
- "gitHead": "485f42ae8a1c58ceea18371a507fd4acfa86fbd8"
86
+ "gitHead": "56d8058eda6e30c4cc8bfc37818fa6ed972f7dc2"
88
87
  }
@@ -717,7 +717,7 @@ function MediaEditorContent( {
717
717
  />
718
718
  ),
719
719
  },
720
- ]
720
+ ]
721
721
  : [] ),
722
722
  {
723
723
  id: DETAILS_PANEL,
@@ -746,7 +746,7 @@ function MediaEditorContent( {
746
746
  ? fields.map( ( field ) => ( {
747
747
  ...field,
748
748
  isDisabled: true,
749
- } ) )
749
+ } ) )
750
750
  : fields,
751
751
  } }
752
752
  >
@@ -106,7 +106,7 @@ export function useSaveMediaEditor( {
106
106
  ? {
107
107
  id,
108
108
  url: media.source_url,
109
- }
109
+ }
110
110
  : undefined;
111
111
 
112
112
  if ( modifiers.length > 0 ) {
@@ -167,20 +167,20 @@ export function useSaveMediaEditor( {
167
167
  const message =
168
168
  error instanceof Error
169
169
  ? error.message
170
- : ( error as { message?: string } )?.message ??
171
- __( 'An unknown error occurred.' );
170
+ : ( ( error as { message?: string } )?.message ??
171
+ __( 'An unknown error occurred.' ) );
172
172
  createErrorNotice(
173
173
  isImage
174
174
  ? sprintf(
175
175
  /* translators: %s: Error message. */
176
176
  __( 'Could not save image. %s' ),
177
177
  message
178
- )
178
+ )
179
179
  : sprintf(
180
180
  /* translators: %s: Error message. */
181
181
  __( 'Could not save media. %s' ),
182
182
  message
183
- ),
183
+ ),
184
184
  {
185
185
  type: 'snackbar',
186
186
  context: MEDIA_EDITOR_NOTICES_CONTEXT,
@@ -1,4 +1,4 @@
1
- import { SelectControl } from '@wordpress/components';
1
+ import { SelectControl as WCSelectControl } from '@wordpress/components';
2
2
  import { Stack, VisuallyHidden } from '@wordpress/ui';
3
3
  import { __ } from '@wordpress/i18n';
4
4
  import { CROP_CONTROL_ATTR } from '../../hooks/use-crop-gesture-handlers';
@@ -49,7 +49,7 @@ export default function MediaEditorCropPanel( {
49
49
  { __( 'Crop options' ) }
50
50
  </VisuallyHidden>
51
51
  <MediaEditorImageControls withLabels disabled={ disabled } />
52
- <SelectControl
52
+ <WCSelectControl
53
53
  label={ __( 'Aspect ratio' ) }
54
54
  value={ aspectRatioValue }
55
55
  onChange={ onAspectRatioChange }
@@ -30,7 +30,7 @@ vi.mock(
30
30
  ( {
31
31
  useDispatch: vi.fn(),
32
32
  useSelect: vi.fn(),
33
- } ) as unknown as typeof import('@wordpress/data')
33
+ } ) as unknown as typeof import( '@wordpress/data' )
34
34
  );
35
35
 
36
36
  vi.mock(
@@ -38,7 +38,7 @@ vi.mock(
38
38
  () =>
39
39
  ( {
40
40
  Modal: ( { children }: { children: ReactNode } ) => children,
41
- } ) as unknown as typeof import('@wordpress/components')
41
+ } ) as unknown as typeof import( '@wordpress/components' )
42
42
  );
43
43
 
44
44
  vi.mock(
@@ -47,7 +47,7 @@ vi.mock(
47
47
  ( {
48
48
  ShortcutProvider: ( { children }: { children: ReactNode } ) =>
49
49
  children,
50
- } ) as unknown as typeof import('@wordpress/keyboard-shortcuts')
50
+ } ) as unknown as typeof import( '@wordpress/keyboard-shortcuts' )
51
51
  );
52
52
 
53
53
  vi.mock(
@@ -55,7 +55,7 @@ vi.mock(
55
55
  () =>
56
56
  ( {
57
57
  store: { name: 'notices' },
58
- } ) as unknown as typeof import('@wordpress/notices')
58
+ } ) as unknown as typeof import( '@wordpress/notices' )
59
59
  );
60
60
 
61
61
  vi.mock(
@@ -63,12 +63,12 @@ vi.mock(
63
63
  () =>
64
64
  ( {
65
65
  store: { name: 'media-editor' },
66
- } ) as unknown as typeof import('../../../store')
66
+ } ) as unknown as typeof import( '../../../store' )
67
67
  );
68
68
 
69
69
  vi.mock( import( '../../media-editor' ), async () => {
70
70
  const { createElement } =
71
- await vi.importActual< typeof import('@wordpress/element') >(
71
+ await vi.importActual< typeof import( '@wordpress/element' ) >(
72
72
  '@wordpress/element'
73
73
  );
74
74
 
@@ -80,7 +80,7 @@ vi.mock( import( '../../media-editor' ), async () => {
80
80
  'Save result'
81
81
  )
82
82
  ),
83
- } as unknown as typeof import('../../media-editor');
83
+ } as unknown as typeof import( '../../media-editor' );
84
84
  } );
85
85
 
86
86
  describe( 'MediaEditorModal', () => {
@@ -2,10 +2,10 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
2
2
  import { useState } from '@wordpress/element';
3
3
  import { __ } from '@wordpress/i18n';
4
4
  import RotationRuler from '../index';
5
- import '../style.scss';
6
5
 
7
6
  const meta: Meta< typeof RotationRuler > = {
8
- title: 'MediaEditor/RotationRuler',
7
+ id: 'mediaeditor-rotationruler',
8
+ title: 'Editor/Media Editor/RotationRuler',
9
9
  component: RotationRuler,
10
10
  args: {
11
11
  label: __( 'Fine rotation' ),
@@ -22,6 +22,11 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
22
22
  user-select: none;
23
23
  touch-action: none;
24
24
  cursor: ew-resize;
25
+ // A number line, not prose: `__ticks` keeps negatives on the left in
26
+ // every locale, so the numerals must read that way too. Inherited `rtl`
27
+ // sends each tick label through bidi and `-45°` comes out `45°-`.
28
+ /*rtl:ignore*/
29
+ direction: ltr;
25
30
  // Always declare the container so the inline-size query below can
26
31
  // match. Cheap; only affects layout if a child uses cqw/cqh.
27
32
  container-type: inline-size;
@@ -162,9 +167,12 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
162
167
  // Sign sits flush to the left of the number (mirror of the unit).
163
168
  // Rendered only for negative values, and removed from flow so the
164
169
  // leading `-` does not nudge the digits off the marker line.
170
+ // Both spans are out of flow, so bidi never reorders them: their sides are
171
+ // whatever `left`/`right` say. Mirrored, the label reads `°45-`.
165
172
  .rotation-ruler__active-label-sign {
166
173
  position: absolute;
167
174
  top: 0;
175
+ /*rtl:ignore*/
168
176
  right: 100%;
169
177
  }
170
178
 
@@ -173,6 +181,7 @@ $rotation-ruler-accent: var(--wp-admin-theme-color, #3858e9);
173
181
  .rotation-ruler__active-label-unit {
174
182
  position: absolute;
175
183
  top: 0;
184
+ /*rtl:ignore*/
176
185
  left: 100%;
177
186
  }
178
187
 
@@ -696,13 +696,13 @@ export class InteractionController {
696
696
  panSize.width > 0
697
697
  ? ( moveEvent.touches[ 0 ].clientX -
698
698
  touch.lastTouchX ) /
699
- panSize.width
699
+ panSize.width
700
700
  : 0;
701
701
  const deltaY =
702
702
  panSize.height > 0
703
703
  ? ( moveEvent.touches[ 0 ].clientY -
704
704
  touch.lastTouchY ) /
705
- panSize.height
705
+ panSize.height
706
706
  : 0;
707
707
 
708
708
  const { pan: newCrop } = restrictPanZoom(
@@ -45,7 +45,7 @@ export function buildFocalPointZoomAction(
45
45
  ? {
46
46
  width: state.image.naturalWidth,
47
47
  height: state.image.naturalHeight,
48
- }
48
+ }
49
49
  : { width: 1, height: 1 };
50
50
  const { pan: clampedPan }: { pan: NormalizedPoint } = restrictPanZoom(
51
51
  {
@@ -6,6 +6,11 @@
6
6
  // reach isn't clipped by the root.
7
7
  $handle-touch-target-size: 44px;
8
8
 
9
+ // Geometry, not text direction: the camera and `stencil-math.ts` address
10
+ // this canvas in physical pixels, and JS sets the image's `left` inline.
11
+ // Mirrored, `nw` would resize the right edge and the image would pin to the
12
+ // stage edge. ResizableBox ignores its own handle offsets for the same reason.
13
+ /*!rtl:begin:ignore*/
9
14
  .wp-media-editor-image-editor {
10
15
  position: relative;
11
16
  overflow: hidden;
@@ -251,3 +256,4 @@ $handle-touch-target-size: 44px;
251
256
  }
252
257
 
253
258
  }
259
+ /*!rtl:end:ignore*/
@@ -237,7 +237,7 @@ export function DimensionsOverlay( {
237
237
  tooltipSize.height,
238
238
  containerSize.height
239
239
  ),
240
- }
240
+ }
241
241
  : preferred;
242
242
 
243
243
  return (