@wordpress/media-editor 0.17.0 → 0.17.2-next.v.202609031004.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 (53) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/build/components/media-editor/index.cjs +152 -133
  3. package/build/components/media-editor/index.cjs.map +3 -3
  4. package/build/components/media-editor-crop-panel/index.cjs +2 -3
  5. package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
  6. package/build/components/media-editor-modal/index.cjs +7 -21
  7. package/build/components/media-editor-modal/index.cjs.map +2 -2
  8. package/build-module/components/media-editor/index.mjs +154 -140
  9. package/build-module/components/media-editor/index.mjs.map +2 -2
  10. package/build-module/components/media-editor-crop-panel/index.mjs +2 -3
  11. package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
  12. package/build-module/components/media-editor-modal/index.mjs +9 -23
  13. package/build-module/components/media-editor-modal/index.mjs.map +2 -2
  14. package/build-style/style-rtl.css +66 -106
  15. package/build-style/style.css +66 -106
  16. package/build-types/components/media-editor/index.d.ts +7 -14
  17. package/build-types/components/media-editor/index.d.ts.map +1 -1
  18. package/build-types/components/media-editor-crop-panel/index.d.ts +4 -11
  19. package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
  20. package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
  21. package/package.json +21 -21
  22. package/src/components/media-editor/index.tsx +276 -200
  23. package/src/components/media-editor/style.scss +136 -134
  24. package/src/components/media-editor-crop-panel/index.tsx +4 -12
  25. package/src/components/media-editor-crop-panel/test/{index.tsx → index.jsdom.test.tsx} +2 -10
  26. package/src/components/media-editor-modal/index.tsx +9 -29
  27. package/src/components/media-editor-modal/style.scss +8 -49
  28. package/src/components/media-editor-modal/test/build-modifiers.test.ts +24 -14
  29. package/src/components/rotation-ruler/style.scss +1 -1
  30. package/src/image-editor/core/math/test/sanitize.ts +1 -0
  31. package/src/image-editor/core/test/camera.ts +2 -3
  32. package/src/image-editor/core/test/interaction-controller.ts +50 -40
  33. package/src/image-editor/core/test/preview-export-parity.ts +31 -23
  34. package/src/image-editor/core/test/render-camera-bridge.ts +1 -0
  35. package/src/image-editor/core/test/state.ts +1 -0
  36. package/src/image-editor/core/test/stencil-math.ts +1 -0
  37. package/src/image-editor/core/transforms/test/pipeline.ts +1 -0
  38. package/src/store/test/reducer.ts +9 -8
  39. package/tsconfig.build.json +1 -1
  40. package/tsconfig.build.tsbuildinfo +1 -1
  41. package/tsconfig.json +3 -3
  42. /package/src/components/media-editor/test/{use-crop-options.tsx → use-crop-options.jsdom.test.tsx} +0 -0
  43. /package/src/components/media-editor-image-controls/test/{index.tsx → index.jsdom.test.tsx} +0 -0
  44. /package/src/components/media-editor-modal/test/{index.tsx → index.jsdom.test.tsx} +0 -0
  45. /package/src/components/rotation-ruler/test/{index.tsx → index.jsdom.test.tsx} +0 -0
  46. /package/src/image-editor/core/export/test/{canvas-renderer.ts → canvas-renderer.jsdom.test.ts} +0 -0
  47. /package/src/image-editor/react/components/stencils/test/{rectangle-stencil.tsx → rectangle-stencil.jsdom.test.tsx} +0 -0
  48. /package/src/image-editor/react/components/test/{cropper.tsx → cropper.jsdom.test.tsx} +0 -0
  49. /package/src/image-editor/react/hooks/test/{use-aria-announcer.ts → use-aria-announcer.jsdom.test.ts} +0 -0
  50. /package/src/image-editor/react/hooks/test/{use-cropper-reducer.ts → use-cropper-reducer.jsdom.test.ts} +0 -0
  51. /package/src/image-editor/react/hooks/test/{use-interaction.ts → use-interaction.jsdom.test.ts} +0 -0
  52. /package/src/image-editor/react/hooks/test/{use-transform-style.ts → use-transform-style.jsdom.test.ts} +0 -0
  53. /package/src/state/test/{use-media-editor-state.ts → use-media-editor-state.jsdom.test.ts} +0 -0
@@ -1,3 +1,13 @@
1
+ import {
2
+ afterAll,
3
+ beforeAll,
4
+ beforeEach,
5
+ describe,
6
+ expect,
7
+ it,
8
+ vi,
9
+ type Mocked,
10
+ } from 'vitest';
1
11
  import {
2
12
  InteractionController,
3
13
  type CropperInteractionActions,
@@ -52,7 +62,7 @@ function createPointerEvent(
52
62
  clientX: 0,
53
63
  clientY: 0,
54
64
  pointerId: 1,
55
- preventDefault: jest.fn(),
65
+ preventDefault: vi.fn(),
56
66
  ...overrides,
57
67
  } as unknown as PointerEvent;
58
68
  }
@@ -67,16 +77,16 @@ function createMockElement(): HTMLElement & {
67
77
  } {
68
78
  const listeners: Record< string, EventListener[] > = {};
69
79
  return {
70
- focus: jest.fn(),
71
- setPointerCapture: jest.fn(),
72
- releasePointerCapture: jest.fn(),
73
- addEventListener: jest.fn( ( type: string, fn: EventListener ) => {
80
+ focus: vi.fn(),
81
+ setPointerCapture: vi.fn(),
82
+ releasePointerCapture: vi.fn(),
83
+ addEventListener: vi.fn( ( type: string, fn: EventListener ) => {
74
84
  if ( ! listeners[ type ] ) {
75
85
  listeners[ type ] = [];
76
86
  }
77
87
  listeners[ type ].push( fn );
78
88
  } ),
79
- removeEventListener: jest.fn( ( type: string, fn: EventListener ) => {
89
+ removeEventListener: vi.fn( ( type: string, fn: EventListener ) => {
80
90
  if ( listeners[ type ] ) {
81
91
  listeners[ type ] = listeners[ type ].filter(
82
92
  ( l ) => l !== fn
@@ -106,7 +116,7 @@ function createWheelEvent(
106
116
  overrides: Partial< WheelEvent > & { currentTarget?: unknown } = {}
107
117
  ): WheelEvent {
108
118
  return {
109
- preventDefault: jest.fn(),
119
+ preventDefault: vi.fn(),
110
120
  deltaY: 0,
111
121
  clientX: 0,
112
122
  clientY: 0,
@@ -127,7 +137,7 @@ function createKeyboardEvent(
127
137
  ): KeyboardEvent {
128
138
  return {
129
139
  key,
130
- preventDefault: jest.fn(),
140
+ preventDefault: vi.fn(),
131
141
  ...overrides,
132
142
  } as unknown as KeyboardEvent;
133
143
  }
@@ -144,7 +154,7 @@ function createTouchEvent(
144
154
  overrides: Partial< TouchEvent > = {}
145
155
  ): TouchEvent {
146
156
  return {
147
- preventDefault: jest.fn(),
157
+ preventDefault: vi.fn(),
148
158
  touches,
149
159
  ...overrides,
150
160
  } as unknown as TouchEvent;
@@ -166,7 +176,7 @@ function createContainerRect( overrides: Partial< DOMRect > = {} ): DOMRect {
166
176
  bottom: 300,
167
177
  x: 0,
168
178
  y: 0,
169
- toJSON: jest.fn(),
179
+ toJSON: vi.fn(),
170
180
  ...overrides,
171
181
  } as DOMRect;
172
182
  }
@@ -182,13 +192,13 @@ function createMockDocument(): Document & {
182
192
  } {
183
193
  const listeners: Record< string, EventListener[] > = {};
184
194
  return {
185
- addEventListener: jest.fn( ( type: string, fn: EventListener ) => {
195
+ addEventListener: vi.fn( ( type: string, fn: EventListener ) => {
186
196
  if ( ! listeners[ type ] ) {
187
197
  listeners[ type ] = [];
188
198
  }
189
199
  listeners[ type ].push( fn );
190
200
  } ),
191
- removeEventListener: jest.fn( ( type: string, fn: EventListener ) => {
201
+ removeEventListener: vi.fn( ( type: string, fn: EventListener ) => {
192
202
  if ( listeners[ type ] ) {
193
203
  listeners[ type ] = listeners[ type ].filter(
194
204
  ( l ) => l !== fn
@@ -208,7 +218,7 @@ function createMockDocument(): Document & {
208
218
  describe( 'InteractionController', () => {
209
219
  const containerSize: Size = { width: 500, height: 300 };
210
220
  const imageSize: Size = { width: 500, height: 300 };
211
- let actionMocks: jest.Mocked< CropperInteractionActions >;
221
+ let actionMocks: Mocked< CropperInteractionActions >;
212
222
 
213
223
  // Store original requestAnimationFrame so we can restore it.
214
224
  const originalRAF = globalThis.requestAnimationFrame;
@@ -220,7 +230,7 @@ describe( 'InteractionController', () => {
220
230
  cb( 0 );
221
231
  return 0;
222
232
  };
223
- globalThis.cancelAnimationFrame = jest.fn();
233
+ globalThis.cancelAnimationFrame = vi.fn();
224
234
  } );
225
235
 
226
236
  afterAll( () => {
@@ -230,11 +240,11 @@ describe( 'InteractionController', () => {
230
240
 
231
241
  beforeEach( () => {
232
242
  actionMocks = {
233
- setPan: jest.fn(),
234
- setZoom: jest.fn(),
235
- setZoomAtPoint: jest.fn(),
236
- snapRotate90: jest.fn(),
237
- toggleFlip: jest.fn(),
243
+ setPan: vi.fn(),
244
+ setZoom: vi.fn(),
245
+ setZoomAtPoint: vi.fn(),
246
+ snapRotate90: vi.fn(),
247
+ toggleFlip: vi.fn(),
238
248
  };
239
249
  } );
240
250
 
@@ -290,8 +300,8 @@ describe( 'InteractionController', () => {
290
300
 
291
301
  it( 'ignores touch pointerdown so touch gestures own touch input', () => {
292
302
  const state = makeState( { zoom: 2 } );
293
- const onGestureStart = jest.fn();
294
- const onStatusChange = jest.fn();
303
+ const onGestureStart = vi.fn();
304
+ const onStatusChange = vi.fn();
295
305
  const { controller } = createController( state, {
296
306
  onGestureStart,
297
307
  onStatusChange,
@@ -333,7 +343,7 @@ describe( 'InteractionController', () => {
333
343
  // Simulate pointerup.
334
344
  el._fire( 'pointerup', createPointerEvent() );
335
345
 
336
- jest.clearAllMocks();
346
+ vi.clearAllMocks();
337
347
 
338
348
  // Another pointermove should not dispatch because the listener
339
349
  // was removed after pointerup.
@@ -350,8 +360,8 @@ describe( 'InteractionController', () => {
350
360
 
351
361
  it( 'calls onGestureStart on pointerdown and onGestureEnd on pointerup', () => {
352
362
  const state = makeState( { zoom: 2 } );
353
- const onGestureStart = jest.fn();
354
- const onGestureEnd = jest.fn();
363
+ const onGestureStart = vi.fn();
364
+ const onGestureEnd = vi.fn();
355
365
  const { controller } = createController( state, {
356
366
  onGestureStart,
357
367
  onGestureEnd,
@@ -380,7 +390,7 @@ describe( 'InteractionController', () => {
380
390
 
381
391
  it( 'reports isDragging via onStatusChange', () => {
382
392
  const state = makeState( { zoom: 2 } );
383
- const onStatusChange = jest.fn();
393
+ const onStatusChange = vi.fn();
384
394
  const { controller } = createController( state, {
385
395
  onStatusChange,
386
396
  } );
@@ -505,7 +515,7 @@ describe( 'InteractionController', () => {
505
515
  el
506
516
  );
507
517
 
508
- jest.clearAllMocks();
518
+ vi.clearAllMocks();
509
519
 
510
520
  const wheelEvent = createWheelEvent( {
511
521
  deltaY: -100,
@@ -521,12 +531,12 @@ describe( 'InteractionController', () => {
521
531
  } );
522
532
 
523
533
  it( 'calls onGestureStart on first wheel, onGestureEnd after debounce', () => {
524
- jest.useFakeTimers( {
525
- doNotFake: [ 'requestAnimationFrame', 'cancelAnimationFrame' ],
534
+ vi.useFakeTimers( {
535
+ toFake: [ 'setTimeout', 'clearTimeout' ],
526
536
  } );
527
537
  const state = makeState( { zoom: 2 } );
528
- const onGestureStart = jest.fn();
529
- const onGestureEnd = jest.fn();
538
+ const onGestureStart = vi.fn();
539
+ const onGestureEnd = vi.fn();
530
540
  const { controller } = createController( state, {
531
541
  onGestureStart,
532
542
  onGestureEnd,
@@ -546,11 +556,11 @@ describe( 'InteractionController', () => {
546
556
  expect( onGestureStart ).toHaveBeenCalledTimes( 1 );
547
557
 
548
558
  // Advance past the 300ms debounce.
549
- jest.advanceTimersByTime( 350 );
559
+ vi.advanceTimersByTime( 350 );
550
560
 
551
561
  expect( onGestureEnd ).toHaveBeenCalledTimes( 1 );
552
562
 
553
- jest.useRealTimers();
563
+ vi.useRealTimers();
554
564
  } );
555
565
  } );
556
566
 
@@ -848,8 +858,8 @@ describe( 'InteractionController', () => {
848
858
 
849
859
  it( 'calls onGestureStart/onGestureEnd for single-finger pan', () => {
850
860
  const state = makeState( { zoom: 2 } );
851
- const onGestureStart = jest.fn();
852
- const onGestureEnd = jest.fn();
861
+ const onGestureStart = vi.fn();
862
+ const onGestureEnd = vi.fn();
853
863
  const { controller } = createController( state, {
854
864
  onGestureStart,
855
865
  onGestureEnd,
@@ -873,7 +883,7 @@ describe( 'InteractionController', () => {
873
883
 
874
884
  it( 'reports isDragging on first single-finger move', () => {
875
885
  const state = makeState( { zoom: 2 } );
876
- const onStatusChange = jest.fn();
886
+ const onStatusChange = vi.fn();
877
887
  const { controller } = createController( state, {
878
888
  onStatusChange,
879
889
  } );
@@ -987,8 +997,8 @@ describe( 'InteractionController', () => {
987
997
 
988
998
  it( 'calls onGestureStart for pinch, onGestureEnd on touchend', () => {
989
999
  const state = makeState( { zoom: 1 } );
990
- const onGestureStart = jest.fn();
991
- const onGestureEnd = jest.fn();
1000
+ const onGestureStart = vi.fn();
1001
+ const onGestureEnd = vi.fn();
992
1002
  const { controller } = createController( state, {
993
1003
  onGestureStart,
994
1004
  onGestureEnd,
@@ -1031,7 +1041,7 @@ describe( 'InteractionController', () => {
1031
1041
  createTouchEvent( [ { clientX: 210, clientY: 155 } ] )
1032
1042
  );
1033
1043
  expect( actionMocks.setPan ).toHaveBeenCalled();
1034
- jest.clearAllMocks();
1044
+ vi.clearAllMocks();
1035
1045
 
1036
1046
  // Second finger arrives via touchstart.
1037
1047
  controller.handleTouchStart(
@@ -1122,7 +1132,7 @@ describe( 'InteractionController', () => {
1122
1132
  ] )
1123
1133
  );
1124
1134
 
1125
- jest.clearAllMocks();
1135
+ vi.clearAllMocks();
1126
1136
 
1127
1137
  // One finger lifts — move with 1 touch should NOT pan
1128
1138
  // because didPinch is true.
@@ -1225,7 +1235,7 @@ describe( 'InteractionController', () => {
1225
1235
  createPointerEvent( { clientX: 100, clientY: 100 } ),
1226
1236
  el
1227
1237
  );
1228
- jest.clearAllMocks();
1238
+ vi.clearAllMocks();
1229
1239
 
1230
1240
  controller.destroy();
1231
1241
 
@@ -28,6 +28,7 @@
28
28
  * sideways during fine rotation would have been caught by this test —
29
29
  * the center would agree (symmetric bug) but the corners would drift.
30
30
  */
31
+ import { describe, expect, it } from 'vitest';
31
32
  import { mat2d, vec2 } from 'gl-matrix';
32
33
  import {
33
34
  createCamera,
@@ -124,8 +125,8 @@ const PROBES: { label: string; u: number; v: number }[] = [
124
125
  { label: 'interior-2', u: 0.8, v: 0.25 },
125
126
  ];
126
127
 
127
- // All (state × output-size × probe) combinations flattened into rows
128
- // for `it.each`. Each row is self-describing; on failure, the label
128
+ // All (state × output-size × probe) combinations flattened into rows.
129
+ // Each row is self-describing; on failure, the label
129
130
  // pinpoints the exact state and probe point where preview / export
130
131
  // disagreed.
131
132
  interface ParityRow {
@@ -216,26 +217,33 @@ describe( 'Preview ↔ Export parity', () => {
216
217
  // miss.
217
218
  const rows = buildRows();
218
219
 
219
- it.each( rows )( '$label', ( { state, outputSize, u, v } ) => {
220
- const screen = stencilScreenPoint( state, CONTAINER, IMAGE, u, v );
221
- const outputPoint = {
222
- x: u * outputSize.width,
223
- y: v * outputSize.height,
224
- };
225
- const preview = previewSourcePixel( state, CONTAINER, IMAGE, screen );
226
- const exported = exportSourcePixel(
227
- state,
228
- IMAGE,
229
- outputSize,
230
- outputPoint
231
- );
220
+ for ( const { label, state, outputSize, u, v } of rows ) {
221
+ it( label, () => {
222
+ const screen = stencilScreenPoint( state, CONTAINER, IMAGE, u, v );
223
+ const outputPoint = {
224
+ x: u * outputSize.width,
225
+ y: v * outputSize.height,
226
+ };
227
+ const preview = previewSourcePixel(
228
+ state,
229
+ CONTAINER,
230
+ IMAGE,
231
+ screen
232
+ );
233
+ const exported = exportSourcePixel(
234
+ state,
235
+ IMAGE,
236
+ outputSize,
237
+ outputPoint
238
+ );
232
239
 
233
- // Tolerance of 1 source pixel. Intermediate scale factors differ
234
- // between the preview (container pixels) and export (output
235
- // pixels) paths, so sub-pixel agreement is unrealistic. A drift
236
- // of ~1px is still visibly correct; anything larger is a real
237
- // coordinate-system mismatch.
238
- expect( preview.x ).toBeCloseTo( exported.x, 0 );
239
- expect( preview.y ).toBeCloseTo( exported.y, 0 );
240
- } );
240
+ // Tolerance of 1 source pixel. Intermediate scale factors differ
241
+ // between the preview (container pixels) and export (output
242
+ // pixels) paths, so sub-pixel agreement is unrealistic. A drift
243
+ // of ~1px is still visibly correct; anything larger is a real
244
+ // coordinate-system mismatch.
245
+ expect( preview.x ).toBeCloseTo( exported.x, 0 );
246
+ expect( preview.y ).toBeCloseTo( exported.y, 0 );
247
+ } );
248
+ }
241
249
  } );
@@ -24,6 +24,7 @@
24
24
  *
25
25
  * ...run these tests to verify the two paths still agree.
26
26
  */
27
+ import { describe, expect, it } from 'vitest';
27
28
  import {
28
29
  createCamera,
29
30
  worldToScreen,
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import type { CropperState, Size } from '../types';
2
3
  import { ABSOLUTE_MIN_ZOOM, DEFAULT_STATE, MAX_ZOOM } from '../constants';
3
4
  import { cropperReducer, enforceContainment, isStateDirty } from '../state';
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import {
2
3
  computeFreeResizeRect,
3
4
  computeLockedResizeRect,
@@ -1,3 +1,4 @@
1
+ import { beforeEach, describe, expect, it } from 'vitest';
1
2
  import type { CropperState, TransformOperation } from '../../types';
2
3
  import { DEFAULT_STATE } from '../../constants';
3
4
  import { applyOperationToState, stateFromPipeline } from '../pipeline';
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it, vi } from 'vitest';
1
2
  import reducer, { DEFAULT_STATE } from '../reducer';
2
3
 
3
4
  describe( 'core/media-editor reducer', () => {
@@ -7,8 +8,8 @@ describe( 'core/media-editor reducer', () => {
7
8
  } );
8
9
 
9
10
  it( 'opens the modal with id and onUpdate', () => {
10
- const onUpdate = jest.fn();
11
- const onClose = jest.fn();
11
+ const onUpdate = vi.fn();
12
+ const onClose = vi.fn();
12
13
  const state = reducer( undefined, {
13
14
  type: 'OPEN_MEDIA_EDITOR_MODAL',
14
15
  id: 42,
@@ -24,10 +25,10 @@ describe( 'core/media-editor reducer', () => {
24
25
  } );
25
26
 
26
27
  it( 'replaces state on a subsequent open (new onUpdate)', () => {
27
- const firstOnUpdate = jest.fn();
28
- const firstOnClose = jest.fn();
29
- const secondOnUpdate = jest.fn();
30
- const secondOnClose = jest.fn();
28
+ const firstOnUpdate = vi.fn();
29
+ const firstOnClose = vi.fn();
30
+ const secondOnUpdate = vi.fn();
31
+ const secondOnClose = vi.fn();
31
32
  const first = reducer( undefined, {
32
33
  type: 'OPEN_MEDIA_EDITOR_MODAL',
33
34
  id: 42,
@@ -52,8 +53,8 @@ describe( 'core/media-editor reducer', () => {
52
53
  const opened = reducer( undefined, {
53
54
  type: 'OPEN_MEDIA_EDITOR_MODAL',
54
55
  id: 42,
55
- onUpdate: jest.fn(),
56
- onClose: jest.fn(),
56
+ onUpdate: vi.fn(),
57
+ onClose: vi.fn(),
57
58
  } );
58
59
  const closed = reducer( opened, {
59
60
  type: 'CLOSE_MEDIA_EDITOR_MODAL',
@@ -7,13 +7,13 @@
7
7
  },
8
8
  "references": [
9
9
  { "path": "../a11y/tsconfig.build.json" },
10
+ { "path": "../admin-ui/tsconfig.build.json" },
10
11
  { "path": "../api-fetch/tsconfig.build.json" },
11
12
  { "path": "../components/tsconfig.build.json" },
12
13
  { "path": "../compose/tsconfig.build.json" },
13
14
  { "path": "../core-data/tsconfig.build.json" },
14
15
  { "path": "../data" },
15
16
  { "path": "../dataviews/tsconfig.build.json" },
16
- { "path": "../date" },
17
17
  { "path": "../element/tsconfig.build.json" },
18
18
  { "path": "../i18n/tsconfig.build.json" },
19
19
  { "path": "../icons/tsconfig.build.json" },