@wordpress/media-editor 0.8.0 → 0.8.1-next.v.202605131006.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 +560 -0
- package/build/components/media-editor/index.cjs.map +7 -0
- package/build/components/media-editor-canvas/index.cjs +14 -2
- package/build/components/media-editor-canvas/index.cjs.map +2 -2
- package/build/components/media-editor-crop-panel/index.cjs +34 -27
- package/build/components/media-editor-crop-panel/index.cjs.map +2 -2
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs +162 -0
- package/build/components/media-editor-keyboard-shortcuts-modal/index.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +42 -430
- package/build/components/media-editor-modal/index.cjs.map +3 -3
- package/build/components/media-editor-toolbar/index.cjs +143 -75
- package/build/components/media-editor-toolbar/index.cjs.map +3 -3
- package/build/components/media-form/index.cjs +3 -0
- package/build/components/media-form/index.cjs.map +2 -2
- package/build/components/rotation-ruler/index.cjs +197 -0
- package/build/components/rotation-ruler/index.cjs.map +7 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs +154 -0
- package/build/components/rotation-ruler/use-ruler-drag.cjs.map +7 -0
- package/build/hooks/use-crop-gesture-handlers.cjs +43 -0
- package/build/hooks/use-crop-gesture-handlers.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +9 -0
- package/build/image-editor/core/constants.cjs.map +2 -2
- package/build/image-editor/core/containment.cjs +7 -13
- package/build/image-editor/core/containment.cjs.map +2 -2
- package/build/image-editor/core/interaction-controller.cjs +43 -7
- package/build/image-editor/core/interaction-controller.cjs.map +2 -2
- package/build/image-editor/core/state.cjs +5 -1
- package/build/image-editor/core/state.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/core/viewport-state.cjs +50 -0
- package/build/image-editor/core/viewport-state.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +192 -72
- package/build/image-editor/react/components/cropper.cjs.map +3 -3
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +5 -2
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +2 -2
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +16 -4
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +2 -2
- package/build/image-editor/react/components/viewport-provider.cjs +51 -0
- package/build/image-editor/react/components/viewport-provider.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +53 -6
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-cropper-state.cjs +127 -8
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-interaction.cjs +26 -5
- package/build/image-editor/react/hooks/use-interaction.cjs.map +2 -2
- package/build/image-editor/react/hooks/use-viewport-state.cjs +51 -0
- package/build/image-editor/react/hooks/use-viewport-state.cjs.map +7 -0
- package/build/image-editor/react/visually-hidden-style.cjs +41 -0
- package/build/image-editor/react/visually-hidden-style.cjs.map +7 -0
- package/build/private-apis.cjs +2 -0
- package/build/private-apis.cjs.map +2 -2
- package/build-module/components/media-editor/index.mjs +545 -0
- package/build-module/components/media-editor/index.mjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +14 -2
- package/build-module/components/media-editor-canvas/index.mjs.map +2 -2
- package/build-module/components/media-editor-crop-panel/index.mjs +35 -28
- package/build-module/components/media-editor-crop-panel/index.mjs.map +2 -2
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs +144 -0
- package/build-module/components/media-editor-keyboard-shortcuts-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +46 -455
- package/build-module/components/media-editor-modal/index.mjs.map +2 -2
- package/build-module/components/media-editor-toolbar/index.mjs +137 -77
- package/build-module/components/media-editor-toolbar/index.mjs.map +2 -2
- package/build-module/components/media-form/index.mjs +3 -0
- package/build-module/components/media-form/index.mjs.map +2 -2
- package/build-module/components/rotation-ruler/index.mjs +166 -0
- package/build-module/components/rotation-ruler/index.mjs.map +7 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs +126 -0
- package/build-module/components/rotation-ruler/use-ruler-drag.mjs.map +7 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs +17 -0
- package/build-module/hooks/use-crop-gesture-handlers.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +6 -0
- package/build-module/image-editor/core/constants.mjs.map +2 -2
- package/build-module/image-editor/core/containment.mjs +6 -12
- package/build-module/image-editor/core/containment.mjs.map +2 -2
- package/build-module/image-editor/core/interaction-controller.mjs +50 -8
- package/build-module/image-editor/core/interaction-controller.mjs.map +2 -2
- package/build-module/image-editor/core/state.mjs +5 -1
- package/build-module/image-editor/core/state.mjs.map +2 -2
- package/build-module/image-editor/core/transform-style.mjs.map +1 -1
- package/build-module/image-editor/core/viewport-state.mjs +24 -0
- package/build-module/image-editor/core/viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +195 -73
- package/build-module/image-editor/react/components/cropper.mjs.map +3 -3
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +5 -2
- 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 +26 -5
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +2 -2
- package/build-module/image-editor/react/components/viewport-provider.mjs +27 -0
- package/build-module/image-editor/react/components/viewport-provider.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +59 -7
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +134 -9
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-interaction.mjs +26 -5
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +2 -2
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs +29 -0
- package/build-module/image-editor/react/hooks/use-viewport-state.mjs.map +7 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs +16 -0
- package/build-module/image-editor/react/visually-hidden-style.mjs.map +7 -0
- package/build-module/private-apis.mjs +2 -0
- package/build-module/private-apis.mjs.map +2 -2
- package/build-style/style-rtl.css +254 -29
- package/build-style/style.css +254 -29
- package/build-types/components/media-editor/index.d.ts +34 -0
- package/build-types/components/media-editor/index.d.ts.map +1 -0
- package/build-types/components/media-editor-canvas/index.d.ts +10 -1
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts +1 -1
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -1
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts +6 -0
- package/build-types/components/media-editor-keyboard-shortcuts-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +2 -2
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -1
- package/build-types/components/media-editor-provider/index.d.ts +1 -1
- package/build-types/components/media-editor-provider/index.d.ts.map +1 -1
- package/build-types/components/media-editor-toolbar/index.d.ts +4 -1
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -1
- package/build-types/components/media-form/index.d.ts +1 -1
- package/build-types/components/media-form/index.d.ts.map +1 -1
- package/build-types/components/rotation-ruler/index.d.ts +46 -0
- package/build-types/components/rotation-ruler/index.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts +14 -0
- package/build-types/components/rotation-ruler/stories/index.story.d.ts.map +1 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts +61 -0
- package/build-types/components/rotation-ruler/use-ruler-drag.d.ts.map +1 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts +42 -0
- package/build-types/hooks/use-crop-gesture-handlers.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +9 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -1
- package/build-types/image-editor/core/containment.d.ts +11 -7
- package/build-types/image-editor/core/containment.d.ts.map +1 -1
- package/build-types/image-editor/core/interaction-controller.d.ts +14 -2
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -1
- package/build-types/image-editor/core/state.d.ts.map +1 -1
- package/build-types/image-editor/core/transform-style.d.ts +1 -1
- package/build-types/image-editor/core/types.d.ts +25 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -1
- package/build-types/image-editor/core/viewport-state.d.ts +7 -0
- package/build-types/image-editor/core/viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +1 -1
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -1
- package/build-types/image-editor/react/components/cropper.d.ts +2 -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 +3 -13
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +1 -1
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +1 -1
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -1
- package/build-types/image-editor/react/components/viewport-provider.d.ts +9 -0
- package/build-types/image-editor/react/components/viewport-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +29 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +5 -2
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -1
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts +19 -0
- package/build-types/image-editor/react/hooks/use-viewport-state.d.ts.map +1 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts +6 -0
- package/build-types/image-editor/react/visually-hidden-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +3 -3
- package/build-types/store/actions.d.ts.map +1 -1
- package/package.json +16 -15
- package/src/components/media-editor/index.tsx +709 -0
- package/src/components/media-editor/style.scss +89 -0
- package/src/components/media-editor-canvas/index.tsx +24 -0
- package/src/components/media-editor-crop-panel/index.tsx +39 -27
- package/src/components/media-editor-crop-panel/test/index.tsx +109 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/index.tsx +177 -0
- package/src/components/media-editor-keyboard-shortcuts-modal/style.scss +53 -0
- package/src/components/media-editor-modal/index.tsx +49 -589
- package/src/components/media-editor-modal/style.scss +13 -112
- package/src/components/media-editor-toolbar/index.tsx +122 -63
- package/src/components/media-editor-toolbar/style.scss +39 -11
- package/src/components/media-form/index.tsx +5 -0
- package/src/components/rotation-ruler/README.md +37 -0
- package/src/components/rotation-ruler/index.tsx +266 -0
- package/src/components/rotation-ruler/stories/index.story.tsx +54 -0
- package/src/components/rotation-ruler/style.scss +147 -0
- package/src/components/rotation-ruler/test/index.tsx +109 -0
- package/src/components/rotation-ruler/use-ruler-drag.ts +230 -0
- package/src/hooks/use-crop-gesture-handlers.ts +54 -0
- package/src/image-editor/core/constants.ts +12 -0
- package/src/image-editor/core/containment.ts +16 -28
- package/src/image-editor/core/interaction-controller.ts +66 -10
- package/src/image-editor/core/state.ts +15 -8
- package/src/image-editor/core/test/camera.ts +15 -26
- package/src/image-editor/core/test/interaction-controller.ts +158 -7
- package/src/image-editor/core/test/state.ts +21 -1
- package/src/image-editor/core/transform-style.ts +1 -1
- package/src/image-editor/core/types.ts +16 -0
- package/src/image-editor/core/viewport-state.ts +33 -0
- package/src/image-editor/docs/architecture.md +1 -1
- package/src/image-editor/docs/recipes.md +2 -2
- package/src/image-editor/react/components/cropper.scss +28 -0
- package/src/image-editor/react/components/cropper.tsx +268 -72
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +12 -12
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +27 -8
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +29 -3
- package/src/image-editor/react/components/test/cropper.tsx +294 -5
- package/src/image-editor/react/components/viewport-provider.tsx +39 -0
- package/src/image-editor/react/hooks/test/use-aria-announcer.ts +81 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +286 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +1 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +68 -7
- package/src/image-editor/react/hooks/use-cropper-state.ts +230 -11
- package/src/image-editor/react/hooks/use-interaction.ts +36 -6
- package/src/image-editor/react/hooks/use-viewport-state.ts +48 -0
- package/src/image-editor/react/visually-hidden-style.ts +15 -0
- package/src/private-apis.ts +2 -0
- package/src/style.scss +3 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/components/rotation-ruler/use-ruler-drag.ts
|
|
21
|
+
var use_ruler_drag_exports = {};
|
|
22
|
+
__export(use_ruler_drag_exports, {
|
|
23
|
+
clampValue: () => clampValue,
|
|
24
|
+
pxToValueDelta: () => pxToValueDelta,
|
|
25
|
+
quantize: () => quantize,
|
|
26
|
+
useRulerDrag: () => useRulerDrag
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(use_ruler_drag_exports);
|
|
29
|
+
var import_element = require("@wordpress/element");
|
|
30
|
+
function pxToValueDelta(deltaPx, pixelsPerStep, step) {
|
|
31
|
+
return -deltaPx / pixelsPerStep * step;
|
|
32
|
+
}
|
|
33
|
+
function clampValue(value, min, max) {
|
|
34
|
+
if (value < min) {
|
|
35
|
+
return min;
|
|
36
|
+
}
|
|
37
|
+
if (value > max) {
|
|
38
|
+
return max;
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function quantize(value, step) {
|
|
43
|
+
return Math.round(value / step) * step;
|
|
44
|
+
}
|
|
45
|
+
function useRulerDrag(options) {
|
|
46
|
+
const {
|
|
47
|
+
value,
|
|
48
|
+
onChange,
|
|
49
|
+
min,
|
|
50
|
+
max,
|
|
51
|
+
step,
|
|
52
|
+
pixelsPerStep,
|
|
53
|
+
disabled,
|
|
54
|
+
onPointerDownStart
|
|
55
|
+
} = options;
|
|
56
|
+
const latestRef = (0, import_element.useRef)({
|
|
57
|
+
value,
|
|
58
|
+
startX: 0,
|
|
59
|
+
startValue: 0,
|
|
60
|
+
activeStep: step,
|
|
61
|
+
dragging: false,
|
|
62
|
+
captureElement: null,
|
|
63
|
+
capturePointerId: 0,
|
|
64
|
+
windowPointerUp: null
|
|
65
|
+
});
|
|
66
|
+
(0, import_element.useEffect)(() => {
|
|
67
|
+
latestRef.current.value = value;
|
|
68
|
+
}, [value]);
|
|
69
|
+
const endDrag = (0, import_element.useCallback)(() => {
|
|
70
|
+
const state = latestRef.current;
|
|
71
|
+
if (!state.dragging) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
state.dragging = false;
|
|
75
|
+
if (state.captureElement && state.captureElement.hasPointerCapture(state.capturePointerId)) {
|
|
76
|
+
state.captureElement.releasePointerCapture(
|
|
77
|
+
state.capturePointerId
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
state.captureElement = null;
|
|
81
|
+
if (state.windowPointerUp) {
|
|
82
|
+
window.removeEventListener("pointerup", state.windowPointerUp);
|
|
83
|
+
window.removeEventListener(
|
|
84
|
+
"pointercancel",
|
|
85
|
+
state.windowPointerUp
|
|
86
|
+
);
|
|
87
|
+
state.windowPointerUp = null;
|
|
88
|
+
}
|
|
89
|
+
}, []);
|
|
90
|
+
(0, import_element.useEffect)(() => endDrag, [endDrag]);
|
|
91
|
+
const onPointerDown = (0, import_element.useCallback)(
|
|
92
|
+
(event) => {
|
|
93
|
+
if (disabled || event.button !== 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const state = latestRef.current;
|
|
97
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
98
|
+
state.captureElement = event.currentTarget;
|
|
99
|
+
state.capturePointerId = event.pointerId;
|
|
100
|
+
state.startX = event.clientX;
|
|
101
|
+
state.startValue = state.value;
|
|
102
|
+
state.activeStep = event.shiftKey ? step / 2 : step;
|
|
103
|
+
state.dragging = true;
|
|
104
|
+
onPointerDownStart?.();
|
|
105
|
+
const onWindowUp = () => endDrag();
|
|
106
|
+
state.windowPointerUp = onWindowUp;
|
|
107
|
+
window.addEventListener("pointerup", onWindowUp);
|
|
108
|
+
window.addEventListener("pointercancel", onWindowUp);
|
|
109
|
+
},
|
|
110
|
+
[disabled, onPointerDownStart, endDrag, step]
|
|
111
|
+
);
|
|
112
|
+
const onPointerMove = (0, import_element.useCallback)(
|
|
113
|
+
(event) => {
|
|
114
|
+
const state = latestRef.current;
|
|
115
|
+
if (!state.dragging) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const requestedStep = event.shiftKey ? step / 2 : step;
|
|
119
|
+
if (requestedStep !== state.activeStep) {
|
|
120
|
+
state.startX = event.clientX;
|
|
121
|
+
state.startValue = state.value;
|
|
122
|
+
state.activeStep = requestedStep;
|
|
123
|
+
}
|
|
124
|
+
const deltaPx = event.clientX - state.startX;
|
|
125
|
+
const deltaValue = pxToValueDelta(
|
|
126
|
+
deltaPx,
|
|
127
|
+
pixelsPerStep,
|
|
128
|
+
state.activeStep
|
|
129
|
+
);
|
|
130
|
+
const raw = state.startValue + deltaValue;
|
|
131
|
+
const stepped = quantize(raw, state.activeStep);
|
|
132
|
+
const next = clampValue(stepped, min, max);
|
|
133
|
+
if (next !== state.value) {
|
|
134
|
+
state.value = next;
|
|
135
|
+
onChange(next);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[onChange, min, max, step, pixelsPerStep]
|
|
139
|
+
);
|
|
140
|
+
return {
|
|
141
|
+
onPointerDown,
|
|
142
|
+
onPointerMove,
|
|
143
|
+
onPointerUp: endDrag,
|
|
144
|
+
onPointerCancel: endDrag
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
clampValue,
|
|
150
|
+
pxToValueDelta,
|
|
151
|
+
quantize,
|
|
152
|
+
useRulerDrag
|
|
153
|
+
});
|
|
154
|
+
//# sourceMappingURL=use-ruler-drag.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/rotation-ruler/use-ruler-drag.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Convert a horizontal pointer delta (px) into a value delta.\n *\n * Negative because dragging the ruler to the right should expose\n * smaller values to the left of the fixed center pointer (and vice\n * versa) \u2014 the ruler scrubs *under* the pointer.\n *\n * @param deltaPx Pointer movement in CSS pixels.\n * @param pixelsPerStep CSS pixels of pointer travel per `step`.\n * @param step Value units per step.\n */\nexport function pxToValueDelta(\n\tdeltaPx: number,\n\tpixelsPerStep: number,\n\tstep: number\n): number {\n\treturn ( -deltaPx / pixelsPerStep ) * step;\n}\n\n/**\n * Clamp `value` to the inclusive `[min, max]` interval.\n *\n * @param value Value to clamp.\n * @param min Lower bound (inclusive).\n * @param max Upper bound (inclusive).\n */\nexport function clampValue( value: number, min: number, max: number ): number {\n\tif ( value < min ) {\n\t\treturn min;\n\t}\n\tif ( value > max ) {\n\t\treturn max;\n\t}\n\treturn value;\n}\n\n/**\n * Round `value` to the nearest multiple of `step`.\n *\n * @param value Value to quantize.\n * @param step Step granularity (must be > 0).\n */\nexport function quantize( value: number, step: number ): number {\n\treturn Math.round( value / step ) * step;\n}\n\nexport interface UseRulerDragOptions {\n\tvalue: number;\n\tonChange: ( next: number ) => void;\n\tmin: number;\n\tmax: number;\n\tstep: number;\n\tpixelsPerStep: number;\n\tdisabled: boolean;\n\t/** Called once on pointerdown so the caller can focus the input. */\n\tonPointerDownStart?: () => void;\n}\n\nexport interface RulerDragHandlers {\n\tonPointerDown: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerMove: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerUp: ( event: React.PointerEvent< HTMLElement > ) => void;\n\tonPointerCancel: ( event: React.PointerEvent< HTMLElement > ) => void;\n}\n\n/**\n * Drag-the-ruler gesture for a horizontal slider. Translates pointer\n * movement into value changes quantized to `step`; the caller renders\n * the visuals and holds the value.\n *\n * The hook owns no state of its own \u2014 every value change is reported\n * through the supplied `onChange`. The \"current value\" is read from a\n * ref so closure staleness during a drag is impossible. Drag continues\n * past the wrapper's bounds (standard slider behaviour); a window-level\n * `pointerup` listener guarantees the drag ends and pointer capture\n * releases even if the underlying captured event never fires on the\n * wrapper.\n *\n * @param options Ruler-drag configuration. See `UseRulerDragOptions`.\n */\nexport function useRulerDrag(\n\toptions: UseRulerDragOptions\n): RulerDragHandlers {\n\tconst {\n\t\tvalue,\n\t\tonChange,\n\t\tmin,\n\t\tmax,\n\t\tstep,\n\t\tpixelsPerStep,\n\t\tdisabled,\n\t\tonPointerDownStart,\n\t} = options;\n\n\t// Mutable mirror of the latest committed value plus per-drag state.\n\t// Pointermove handlers fire far faster than React commits, so we\n\t// cannot read `value` from closure. The `value` write happens in an\n\t// effect (not at render time) to satisfy `react-hooks/refs`; the\n\t// effect flushes after commit, so by the time any pointer handler\n\t// runs, the ref reflects the latest committed `value`.\n\tconst latestRef = useRef< {\n\t\tvalue: number;\n\t\tstartX: number;\n\t\tstartValue: number;\n\t\tactiveStep: number;\n\t\tdragging: boolean;\n\t\tcaptureElement: HTMLElement | null;\n\t\tcapturePointerId: number;\n\t\twindowPointerUp: ( () => void ) | null;\n\t} >( {\n\t\tvalue,\n\t\tstartX: 0,\n\t\tstartValue: 0,\n\t\tactiveStep: step,\n\t\tdragging: false,\n\t\tcaptureElement: null,\n\t\tcapturePointerId: 0,\n\t\twindowPointerUp: null,\n\t} );\n\tuseEffect( () => {\n\t\tlatestRef.current.value = value;\n\t}, [ value ] );\n\n\tconst endDrag = useCallback( () => {\n\t\tconst state = latestRef.current;\n\t\tif ( ! state.dragging ) {\n\t\t\treturn;\n\t\t}\n\t\tstate.dragging = false;\n\t\tif (\n\t\t\tstate.captureElement &&\n\t\t\tstate.captureElement.hasPointerCapture( state.capturePointerId )\n\t\t) {\n\t\t\tstate.captureElement.releasePointerCapture(\n\t\t\t\tstate.capturePointerId\n\t\t\t);\n\t\t}\n\t\tstate.captureElement = null;\n\t\tif ( state.windowPointerUp ) {\n\t\t\twindow.removeEventListener( 'pointerup', state.windowPointerUp );\n\t\t\twindow.removeEventListener(\n\t\t\t\t'pointercancel',\n\t\t\t\tstate.windowPointerUp\n\t\t\t);\n\t\t\tstate.windowPointerUp = null;\n\t\t}\n\t}, [] );\n\n\t// Cleanup any in-flight drag on unmount so we never leak window\n\t// listeners or stale pointer capture.\n\tuseEffect( () => endDrag, [ endDrag ] );\n\n\tconst onPointerDown = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tif ( disabled || event.button !== 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst state = latestRef.current;\n\t\t\tevent.currentTarget.setPointerCapture( event.pointerId );\n\t\t\tstate.captureElement = event.currentTarget;\n\t\t\tstate.capturePointerId = event.pointerId;\n\t\t\tstate.startX = event.clientX;\n\t\t\tstate.startValue = state.value;\n\t\t\tstate.activeStep = event.shiftKey ? step / 2 : step;\n\t\t\tstate.dragging = true;\n\t\t\tonPointerDownStart?.();\n\n\t\t\t// Window-level backstop. With `setPointerCapture`, the\n\t\t\t// element should always receive `pointerup` even when the\n\t\t\t// cursor is released outside its bounds \u2014 but in practice\n\t\t\t// some browsers / window-blur sequences drop the event. The\n\t\t\t// window listener guarantees the drag ends and capture\n\t\t\t// releases.\n\t\t\tconst onWindowUp = () => endDrag();\n\t\t\tstate.windowPointerUp = onWindowUp;\n\t\t\twindow.addEventListener( 'pointerup', onWindowUp );\n\t\t\twindow.addEventListener( 'pointercancel', onWindowUp );\n\t\t},\n\t\t[ disabled, onPointerDownStart, endDrag, step ]\n\t);\n\n\tconst onPointerMove = useCallback(\n\t\t( event: React.PointerEvent< HTMLElement > ) => {\n\t\t\tconst state = latestRef.current;\n\t\t\tif ( ! state.dragging ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Shift toggles fine mode mid-drag. The drag math computes\n\t\t\t// from `startX` / `startValue`, so naively swapping `step`\n\t\t\t// would yank the value backward. Rebase to the current\n\t\t\t// pointer + value so the granularity changes without a\n\t\t\t// jump.\n\t\t\tconst requestedStep = event.shiftKey ? step / 2 : step;\n\t\t\tif ( requestedStep !== state.activeStep ) {\n\t\t\t\tstate.startX = event.clientX;\n\t\t\t\tstate.startValue = state.value;\n\t\t\t\tstate.activeStep = requestedStep;\n\t\t\t}\n\t\t\tconst deltaPx = event.clientX - state.startX;\n\t\t\tconst deltaValue = pxToValueDelta(\n\t\t\t\tdeltaPx,\n\t\t\t\tpixelsPerStep,\n\t\t\t\tstate.activeStep\n\t\t\t);\n\t\t\tconst raw = state.startValue + deltaValue;\n\t\t\tconst stepped = quantize( raw, state.activeStep );\n\t\t\tconst next = clampValue( stepped, min, max );\n\t\t\tif ( next !== state.value ) {\n\t\t\t\t// Update the ref synchronously so consecutive pointermove\n\t\t\t\t// events that fire before React commits still see the\n\t\t\t\t// last *emitted* value as `previous` for the next math.\n\t\t\t\tstate.value = next;\n\t\t\t\tonChange( next );\n\t\t\t}\n\t\t},\n\t\t[ onChange, min, max, step, pixelsPerStep ]\n\t);\n\n\treturn {\n\t\tonPointerDown,\n\t\tonPointerMove,\n\t\tonPointerUp: endDrag,\n\t\tonPointerCancel: endDrag,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAaxC,SAAS,eACf,SACA,eACA,MACS;AACT,SAAS,CAAC,UAAU,gBAAkB;AACvC;AASO,SAAS,WAAY,OAAe,KAAa,KAAsB;AAC7E,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,MAAK,QAAQ,KAAM;AAClB,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAQO,SAAS,SAAU,OAAe,MAAuB;AAC/D,SAAO,KAAK,MAAO,QAAQ,IAAK,IAAI;AACrC;AAoCO,SAAS,aACf,SACoB;AACpB,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI;AAQJ,QAAM,gBAAY,uBASb;AAAA,IACJ;AAAA,IACA,QAAQ;AAAA,IACR,YAAY;AAA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AA,IACrB,CAAE,UAA8C;AAC/C,YAAM,QAAQ,UAAU;AACxB,UAAK,CAAE,MAAM,UAAW;AACvB;AAAA,MACD;AAMA,YAAM,gBAAgB,MAAM,WAAW,OAAO,IAAI;AAClD,UAAK,kBAAkB,MAAM,YAAa;AACzC,cAAM,SAAS,MAAM;AACrB,cAAM,aAAa,MAAM;AACzB,cAAM,aAAa;AAAA,MACpB;AACA,YAAM,UAAU,MAAM,UAAU,MAAM;AACtC,YAAM,aAAa;AAAA,QAClB;AAAA,QACA;AAAA,QACA,MAAM;AAAA,MACP;AACA,YAAM,MAAM,MAAM,aAAa;AAC/B,YAAM,UAAU,SAAU,KAAK,MAAM,UAAW;AAChD,YAAM,OAAO,WAAY,SAAS,KAAK,GAAI;AAC3C,UAAK,SAAS,MAAM,OAAQ;AAI3B,cAAM,QAAQ;AACd,iBAAU,IAAK;AAAA,MAChB;AAAA,IACD;AAAA,IACA,CAAE,UAAU,KAAK,KAAK,MAAM,aAAc;AAAA,EAC3C;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,iBAAiB;AAAA,EAClB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-editor/src/hooks/use-crop-gesture-handlers.ts
|
|
21
|
+
var use_crop_gesture_handlers_exports = {};
|
|
22
|
+
__export(use_crop_gesture_handlers_exports, {
|
|
23
|
+
CROP_CONTROL_ATTR: () => CROP_CONTROL_ATTR,
|
|
24
|
+
useCropGestureHandlers: () => useCropGestureHandlers
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(use_crop_gesture_handlers_exports);
|
|
27
|
+
var import_image_editor = require("../image-editor/index.cjs");
|
|
28
|
+
var CROP_CONTROL_ATTR = "data-crop-control";
|
|
29
|
+
function useCropGestureHandlers(options = {}) {
|
|
30
|
+
const { commitOnKeyUp = true } = options;
|
|
31
|
+
const { commitHistory } = (0, import_image_editor.useCropper)();
|
|
32
|
+
return {
|
|
33
|
+
[CROP_CONTROL_ATTR]: true,
|
|
34
|
+
onPointerUp: commitHistory,
|
|
35
|
+
...commitOnKeyUp ? { onKeyUp: commitHistory } : {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
CROP_CONTROL_ATTR,
|
|
41
|
+
useCropGestureHandlers
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=use-crop-gesture-handlers.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-crop-gesture-handlers.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { useCropper } from '../image-editor';\n\n/**\n * Data attribute applied to crop control wrappers. The modal's keyboard\n * shortcut handler uses this to distinguish crop controls (where custom\n * undo/redo should fire) from metadata text fields (where the browser's\n * native undo should be preserved).\n */\nexport const CROP_CONTROL_ATTR = 'data-crop-control';\n\nexport interface UseCropGestureHandlersOptions {\n\t/**\n\t * When `true` (default), key-up triggers an immediate history commit so\n\t * each discrete keypress becomes its own undo step. Set to `false` for\n\t * continuous-input controls (e.g. the rotation ruler) where rapid\n\t * keypresses should coalesce into a single history entry via the\n\t * state-change debounce.\n\t */\n\tcommitOnKeyUp?: boolean;\n}\n\n/**\n * Returns event handler props to spread onto a wrapper element around a\n * crop control. Marks the wrapper as a crop control (via `data-crop-control`)\n * so the modal's Cmd+Z handler can identify it, and wires up immediate-flush\n * signals on pointer-up and (optionally) key-up so history is committed as\n * soon as the user releases rather than waiting for the debounce window to\n * expire.\n *\n * The history entry itself is recorded by the state-change debounce in\n * `useCropperState` \u2014 no explicit gesture-start signal is needed.\n *\n * Usage:\n * const gestureHandlers = useCropGestureHandlers();\n * <div role=\"presentation\" { ...gestureHandlers }>\n * <RangeControl ... />\n * </div>\n *\n * @param options Optional behavior flags.\n */\nexport function useCropGestureHandlers(\n\toptions: UseCropGestureHandlersOptions = {}\n) {\n\tconst { commitOnKeyUp = true } = options;\n\tconst { commitHistory } = useCropper();\n\treturn {\n\t\t[ CROP_CONTROL_ATTR ]: true,\n\t\tonPointerUp: commitHistory,\n\t\t...( commitOnKeyUp ? { onKeyUp: commitHistory } : {} ),\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA2B;AAQpB,IAAM,oBAAoB;AAgC1B,SAAS,uBACf,UAAyC,CAAC,GACzC;AACD,QAAM,EAAE,gBAAgB,KAAK,IAAI;AACjC,QAAM,EAAE,cAAc,QAAI,gCAAW;AACrC,SAAO;AAAA,IACN,CAAE,iBAAkB,GAAG;AAAA,IACvB,aAAa;AAAA,IACb,GAAK,gBAAgB,EAAE,SAAS,cAAc,IAAI,CAAC;AAAA,EACpD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -21,7 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var constants_exports = {};
|
|
22
22
|
__export(constants_exports, {
|
|
23
23
|
DEFAULT_ASPECT_RATIOS: () => DEFAULT_ASPECT_RATIOS,
|
|
24
|
+
DEFAULT_KEYBOARD_STEP: () => DEFAULT_KEYBOARD_STEP,
|
|
24
25
|
DEFAULT_STATE: () => DEFAULT_STATE,
|
|
26
|
+
DEFAULT_WHEEL_ZOOM_SPEED: () => DEFAULT_WHEEL_ZOOM_SPEED,
|
|
27
|
+
KEYBOARD_SHIFT_STEP_MULTIPLIER: () => KEYBOARD_SHIFT_STEP_MULTIPLIER,
|
|
25
28
|
MAX_ROTATION_OFFSET: () => MAX_ROTATION_OFFSET,
|
|
26
29
|
MAX_ZOOM: () => MAX_ZOOM,
|
|
27
30
|
MIN_ZOOM: () => MIN_ZOOM,
|
|
@@ -31,6 +34,9 @@ module.exports = __toCommonJS(constants_exports);
|
|
|
31
34
|
var import_i18n = require("@wordpress/i18n");
|
|
32
35
|
var MIN_ZOOM = 1;
|
|
33
36
|
var MAX_ZOOM = 10;
|
|
37
|
+
var DEFAULT_WHEEL_ZOOM_SPEED = 25e-4;
|
|
38
|
+
var DEFAULT_KEYBOARD_STEP = 0.01;
|
|
39
|
+
var KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;
|
|
34
40
|
var MAX_ROTATION_OFFSET = 45;
|
|
35
41
|
var DEFAULT_CROP_RECT = {
|
|
36
42
|
x: 0,
|
|
@@ -72,7 +78,10 @@ var DEFAULT_ASPECT_RATIOS = [
|
|
|
72
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
73
79
|
0 && (module.exports = {
|
|
74
80
|
DEFAULT_ASPECT_RATIOS,
|
|
81
|
+
DEFAULT_KEYBOARD_STEP,
|
|
75
82
|
DEFAULT_STATE,
|
|
83
|
+
DEFAULT_WHEEL_ZOOM_SPEED,
|
|
84
|
+
KEYBOARD_SHIFT_STEP_MULTIPLIER,
|
|
76
85
|
MAX_ROTATION_OFFSET,
|
|
77
86
|
MAX_ZOOM,
|
|
78
87
|
MIN_ZOOM,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/constants.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Flip, CropperState } from './types';\n\nexport const MIN_ZOOM = 1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90\u00B0 step.\n * The rotation slider allows \u00B145\u00B0 around the current cardinal angle.\n */\nexport const MAX_ROTATION_OFFSET = 45;\n\nconst DEFAULT_CROP_RECT: NormalizedRect = {\n\tx: 0,\n\ty: 0,\n\twidth: 1,\n\theight: 1,\n};\n\nconst DEFAULT_FLIP: Flip = {\n\thorizontal: false,\n\tvertical: false,\n};\n\nconst DEFAULT_PAN: { x: number; y: number } = {\n\tx: 0,\n\ty: 0,\n};\n\nexport const DEFAULT_STATE: CropperState = {\n\timage: null,\n\tpan: { ...DEFAULT_PAN },\n\tzoom: MIN_ZOOM,\n\trotation: 0,\n\tbasePan: { ...DEFAULT_PAN },\n\tbaseZoom: MIN_ZOOM,\n\tbaseRotation: 0,\n\tflip: { ...DEFAULT_FLIP },\n\tcropRect: { ...DEFAULT_CROP_RECT },\n};\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/** The aspect ratio value (width / height). 0 = free / original. */\n\tvalue: number;\n}\n\n/**\n * Default aspect ratio presets. Consumers can use these as-is, override\n * with their own list, or extend with additional presets.\n *\n * @example\n * // Use defaults:\n * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />\n *\n * // Custom presets:\n * const socialPresets = [\n * { label: 'Instagram Post', value: 1 },\n * { label: 'Instagram Story', value: 9 / 16 },\n * { label: 'YouTube Thumbnail', value: 16 / 9 },\n * ];\n *\n * // Extend defaults:\n * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];\n */\n/**\n * Sentinel value for \"Original\" aspect ratio \u2014 resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AAOZ,IAAM,WAAW;AACjB,IAAM,WAAW;AAMjB,IAAM,sBAAsB;AAEnC,IAAM,oBAAoC;AAAA,EACzC,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,EACP,QAAQ;AACT;AAEA,IAAM,eAAqB;AAAA,EAC1B,YAAY;AAAA,EACZ,UAAU;AACX;AAEA,IAAM,cAAwC;AAAA,EAC7C,GAAG;AAAA,EACH,GAAG;AACJ;AAEO,IAAM,gBAA8B;AAAA,EAC1C,OAAO;AAAA,EACP,KAAK,EAAE,GAAG,YAAY;AAAA,EACtB,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS,EAAE,GAAG,YAAY;AAAA,EAC1B,UAAU;AAAA,EACV,cAAc;AAAA,EACd,MAAM,EAAE,GAAG,aAAa;AAAA,EACxB,UAAU,EAAE,GAAG,kBAAkB;AAClC;AAkCO,IAAM,wBAAwB;AAE9B,IAAM,wBAA6C;AAAA,EACzD,EAAE,WAAO,gBAAI,MAAO,GAAG,OAAO,EAAE;AAAA,EAChC,EAAE,WAAO,gBAAI,UAAW,GAAG,OAAO,sBAAsB;AAAA,EACxD,EAAE,WAAO,gBAAI,cAAe,GAAG,OAAO,EAAE;AAAA,EACxC,EAAE,WAAO,gBAAI,kBAAmB,GAAG,OAAO,KAAK,EAAE;AAAA,EACjD,EAAE,WAAO,gBAAI,iBAAkB,GAAG,OAAO,IAAI,GAAG;AAAA,EAChD,EAAE,WAAO,gBAAI,eAAgB,GAAG,OAAO,IAAI,EAAE;AAAA,EAC7C,EAAE,WAAO,gBAAI,wBAAyB,GAAG,OAAO,IAAI,EAAE;AAAA,EACtD,EAAE,WAAO,gBAAI,aAAc,GAAG,OAAO,IAAI,EAAE;AAAA,EAC3C,EAAE,WAAO,gBAAI,sBAAuB,GAAG,OAAO,IAAI,EAAE;AACrD;",
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedRect, Flip, CropperState } from './types';\n\nexport const MIN_ZOOM = 1;\nexport const MAX_ZOOM = 10;\n\n/**\n * Wheel zoom sensitivity. A deltaY of 100 changes zoom by 0.25.\n * This could be made configurable as a prop to the Cropper component.\n */\nexport const DEFAULT_WHEEL_ZOOM_SPEED = 0.0025;\n\n/** Fine step for keyboard-driven cropper movement, in normalized coordinates. */\nexport const DEFAULT_KEYBOARD_STEP = 0.01;\n\n/** Coarse keyboard movement multiplier when Shift is held. */\nexport const KEYBOARD_SHIFT_STEP_MULTIPLIER = 10;\n\n/**\n * Maximum free-rotation offset in degrees from the nearest 90\u00B0 step.\n * The rotation slider allows \u00B145\u00B0 around the current cardinal angle.\n */\nexport const MAX_ROTATION_OFFSET = 45;\n\nconst DEFAULT_CROP_RECT: NormalizedRect = {\n\tx: 0,\n\ty: 0,\n\twidth: 1,\n\theight: 1,\n};\n\nconst DEFAULT_FLIP: Flip = {\n\thorizontal: false,\n\tvertical: false,\n};\n\nconst DEFAULT_PAN: { x: number; y: number } = {\n\tx: 0,\n\ty: 0,\n};\n\nexport const DEFAULT_STATE: CropperState = {\n\timage: null,\n\tpan: { ...DEFAULT_PAN },\n\tzoom: MIN_ZOOM,\n\trotation: 0,\n\tbasePan: { ...DEFAULT_PAN },\n\tbaseZoom: MIN_ZOOM,\n\tbaseRotation: 0,\n\tflip: { ...DEFAULT_FLIP },\n\tcropRect: { ...DEFAULT_CROP_RECT },\n};\n\n/**\n * An aspect ratio preset with a human-readable label.\n */\nexport interface AspectRatioPreset {\n\t/** Display label (e.g., \"Square (1:1)\"). */\n\tlabel: string;\n\t/** The aspect ratio value (width / height). 0 = free / original. */\n\tvalue: number;\n}\n\n/**\n * Default aspect ratio presets. Consumers can use these as-is, override\n * with their own list, or extend with additional presets.\n *\n * @example\n * // Use defaults:\n * <CropControls presets={ DEFAULT_ASPECT_RATIOS } />\n *\n * // Custom presets:\n * const socialPresets = [\n * { label: 'Instagram Post', value: 1 },\n * { label: 'Instagram Story', value: 9 / 16 },\n * { label: 'YouTube Thumbnail', value: 16 / 9 },\n * ];\n *\n * // Extend defaults:\n * const extended = [ ...DEFAULT_ASPECT_RATIOS, { label: 'Cinema (21:9)', value: 21 / 9 } ];\n */\n/**\n * Sentinel value for \"Original\" aspect ratio \u2014 resolved at runtime\n * to the image's natural width / height.\n */\nexport const ORIGINAL_ASPECT_RATIO = -1;\n\nexport const DEFAULT_ASPECT_RATIOS: AspectRatioPreset[] = [\n\t{ label: __( 'Free' ), value: 0 },\n\t{ label: __( 'Original' ), value: ORIGINAL_ASPECT_RATIO },\n\t{ label: __( 'Square (1:1)' ), value: 1 },\n\t{ label: __( 'Landscape (16:9)' ), value: 16 / 9 },\n\t{ label: __( 'Portrait (9:16)' ), value: 9 / 16 },\n\t{ label: __( 'Classic (4:3)' ), value: 4 / 3 },\n\t{ label: __( 'Classic portrait (3:4)' ), value: 3 / 4 },\n\t{ label: __( 'Photo (3:2)' ), value: 3 / 2 },\n\t{ label: __( 'Photo portrait (2:3)' ), value: 2 / 3 },\n];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AAOZ,IAAM,WAAW;AACjB,IAAM,WAAW;AAMjB,IAAM,2BAA2B;AAGjC,IAAM,wBAAwB;AAG9B,IAAM,iCAAiC;AAMvC,IAAM,sBAAsB;AAEnC,IAAM,oBAAoC;AAAA,EACzC,GAAG;AAAA,EACH,GAAG;AAAA,EACH,OAAO;AAAA,EACP,QAAQ;AACT;AAEA,IAAM,eAAqB;AAAA,EAC1B,YAAY;AAAA,EACZ,UAAU;AACX;AAEA,IAAM,cAAwC;AAAA,EAC7C,GAAG;AAAA,EACH,GAAG;AACJ;AAEO,IAAM,gBAA8B;AAAA,EAC1C,OAAO;AAAA,EACP,KAAK,EAAE,GAAG,YAAY;AAAA,EACtB,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS,EAAE,GAAG,YAAY;AAAA,EAC1B,UAAU;AAAA,EACV,cAAc;AAAA,EACd,MAAM,EAAE,GAAG,aAAa;AAAA,EACxB,UAAU,EAAE,GAAG,kBAAkB;AAClC;AAkCO,IAAM,wBAAwB;AAE9B,IAAM,wBAA6C;AAAA,EACzD,EAAE,WAAO,gBAAI,MAAO,GAAG,OAAO,EAAE;AAAA,EAChC,EAAE,WAAO,gBAAI,UAAW,GAAG,OAAO,sBAAsB;AAAA,EACxD,EAAE,WAAO,gBAAI,cAAe,GAAG,OAAO,EAAE;AAAA,EACxC,EAAE,WAAO,gBAAI,kBAAmB,GAAG,OAAO,KAAK,EAAE;AAAA,EACjD,EAAE,WAAO,gBAAI,iBAAkB,GAAG,OAAO,IAAI,GAAG;AAAA,EAChD,EAAE,WAAO,gBAAI,eAAgB,GAAG,OAAO,IAAI,EAAE;AAAA,EAC7C,EAAE,WAAO,gBAAI,wBAAyB,GAAG,OAAO,IAAI,EAAE;AAAA,EACtD,EAAE,WAAO,gBAAI,aAAc,GAAG,OAAO,IAAI,EAAE;AAAA,EAC3C,EAAE,WAAO,gBAAI,sBAAuB,GAAG,OAAO,IAAI,EAAE;AACrD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// packages/media-editor/src/image-editor/core/containment.ts
|
|
21
21
|
var containment_exports = {};
|
|
22
22
|
__export(containment_exports, {
|
|
23
|
-
|
|
23
|
+
getImageCropBounds: () => getImageCropBounds,
|
|
24
24
|
restrictCropRect: () => restrictCropRect,
|
|
25
25
|
restrictPanZoom: () => restrictPanZoom
|
|
26
26
|
});
|
|
@@ -57,7 +57,7 @@ function getMinZoomForCover(rotation, imageAspectRatio, cropRect) {
|
|
|
57
57
|
const zoomFromBeta = 2 * spanBeta;
|
|
58
58
|
return Math.max(1, zoomFromAlpha, zoomFromBeta);
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function getImageCropBounds(state, elementSize, visualSize) {
|
|
61
61
|
if (elementSize.width === 0 || elementSize.height === 0 || visualSize.width === 0 || visualSize.height === 0) {
|
|
62
62
|
return { minX: 0, minY: 0, maxX: 1, maxY: 1 };
|
|
63
63
|
}
|
|
@@ -81,8 +81,6 @@ function getCropBounds(state, elementSize, visualSize, containerSize) {
|
|
|
81
81
|
[hw, hh],
|
|
82
82
|
[-hw, hh]
|
|
83
83
|
];
|
|
84
|
-
const offsetX = (containerSize.width - visualSize.width) / 2;
|
|
85
|
-
const offsetY = (containerSize.height - visualSize.height) / 2;
|
|
86
84
|
let imgMinX = Infinity;
|
|
87
85
|
let imgMaxX = -Infinity;
|
|
88
86
|
let imgMinY = Infinity;
|
|
@@ -97,15 +95,11 @@ function getCropBounds(state, elementSize, visualSize, containerSize) {
|
|
|
97
95
|
imgMinY = Math.min(imgMinY, ny);
|
|
98
96
|
imgMaxY = Math.max(imgMaxY, ny);
|
|
99
97
|
}
|
|
100
|
-
const containerMinX = -offsetX / visualSize.width;
|
|
101
|
-
const containerMaxX = (containerSize.width - offsetX) / visualSize.width;
|
|
102
|
-
const containerMinY = -offsetY / visualSize.height;
|
|
103
|
-
const containerMaxY = (containerSize.height - offsetY) / visualSize.height;
|
|
104
98
|
return {
|
|
105
|
-
minX:
|
|
106
|
-
minY:
|
|
107
|
-
maxX:
|
|
108
|
-
maxY:
|
|
99
|
+
minX: imgMinX,
|
|
100
|
+
minY: imgMinY,
|
|
101
|
+
maxX: imgMaxX,
|
|
102
|
+
maxY: imgMaxY
|
|
109
103
|
};
|
|
110
104
|
}
|
|
111
105
|
function restrictCropRect(cropRect, zoom, rotation, imageAspectRatio) {
|
|
@@ -238,7 +232,7 @@ function restrictPanZoom(state, imageSize, cropRect) {
|
|
|
238
232
|
}
|
|
239
233
|
// Annotate the CommonJS export names for ESM import in node:
|
|
240
234
|
0 && (module.exports = {
|
|
241
|
-
|
|
235
|
+
getImageCropBounds,
|
|
242
236
|
restrictCropRect,
|
|
243
237
|
restrictPanZoom
|
|
244
238
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/image-editor/core/containment.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\n\n/** Floating-point epsilon for \"close enough to equal\" comparisons. */\nconst EPSILON = 1e-9;\n\n/**\n * Compute the visual (rotated) bounding-box dimensions in pixel-proportional\n * units where the unrotated image is `a \u00D7 1` (renderedW = a, renderedH = 1).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @return Visual dimensions and trig helpers.\n */\nfunction getVisualDimensions(\n\trotation: number,\n\timageAspectRatio: number\n): { visualW: number; visualH: number; absC: number; absS: number } {\n\tconst rad = degreesToRadians( rotation );\n\tconst absC = Math.abs( Math.cos( rad ) );\n\tconst absS = Math.abs( Math.sin( rad ) );\n\tconst bbox = getRotatedBBox( imageAspectRatio, 1, rotation );\n\treturn {\n\t\tvisualW: bbox.width,\n\t\tvisualH: bbox.height,\n\t\tabsC,\n\t\tabsS,\n\t};\n}\n\n/**\n * Calculates the minimum zoom factor needed for the rotated image to fully cover\n * the crop rectangle, using normalized coordinates and imageAspectRatio.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n * The crop rect is in visual-normalized space and must be scaled by the\n * rotation-dependent visual dimensions before projecting into the image-local\n * frame.\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The minimum zoom factor (always >= 1).\n */\nfunction getMinZoomForCover(\n\trotation: number,\n\timageAspectRatio: number,\n\tcropRect: NormalizedRect\n): number {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// The crop rect lives in the SNAP-rotation visual bbox \u2014 that's how the\n\t// stencil and preview position it (see createCamera / getImageFit). Use\n\t// the snap-rotation dimensions to convert crop fractions to pixels.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\t// Projection into the image-local frame uses the TRUE rotation angle \u2014\n\t// that's the actual orientation of the image under the stencil.\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\n\t// Crop half-extents in pixel-proportional space.\n\tconst cropHalfW = ( cropRect.width * snapVisualW ) / 2;\n\tconst cropHalfH = ( cropRect.height * snapVisualH ) / 2;\n\n\t// AABB of the crop rect projected into the image-local (unrotated) frame.\n\tconst spanAlpha = cropHalfW * absC + cropHalfH * absS;\n\tconst spanBeta = cropHalfW * absS + cropHalfH * absC;\n\n\t// Image half-extents at zoom z: (aspectRatio*z/2, z/2).\n\t// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.\n\tconst zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;\n\tconst zoomFromBeta = 2 * spanBeta;\n\n\treturn Math.max( 1, zoomFromAlpha, zoomFromBeta );\n}\n\n/**\n * Compute the crop handle bounds in normalized visual space by finding the\n * axis-aligned bounding box (AABB) of the actual image footprint at the\n * current pan/zoom/rotation, then intersecting with the container viewport.\n *\n * Unlike a static centerline-based calculation, this accounts for the\n * current pan position \u2014 if the user pans right, the left bound tightens\n * because the image's left edge has moved right.\n *\n * @param state The current cropper state (crop, zoom, rotation, flip).\n * @param elementSize The fitted (unrotated) image element dimensions in pixels.\n * @param visualSize The visual (rotated) image bounding box in pixels.\n * @param containerSize The container dimensions in pixels.\n * @return The min/max x and y that a crop rect edge can reach in normalized space.\n */\nexport function getCropBounds(\n\tstate: CropperState,\n\telementSize: Size,\n\tvisualSize: Size,\n\tcontainerSize: Size\n): { minX: number; minY: number; maxX: number; maxY: number } {\n\tif (\n\t\telementSize.width === 0 ||\n\t\telementSize.height === 0 ||\n\t\tvisualSize.width === 0 ||\n\t\tvisualSize.height === 0\n\t) {\n\t\treturn { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n\t}\n\n\t// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.\n\t// Flip is outside rotation so it acts in viewport axes (see createCamera).\n\tconst tx = state.pan.x * visualSize.width;\n\tconst ty = state.pan.y * visualSize.height;\n\tconst rad = degreesToRadians( state.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = state.flip.horizontal ? -1 : 1;\n\tconst sy = state.flip.vertical ? -1 : 1;\n\tconst z = state.zoom;\n\tconst ma = sx * cos * z;\n\tconst mb = sy * sin * z;\n\tconst mc = -sx * sin * z;\n\tconst md = sy * cos * z;\n\n\t// Image element corners relative to element center.\n\tconst hw = elementSize.width / 2;\n\tconst hh = elementSize.height / 2;\n\tconst corners = [\n\t\t[ -hw, -hh ],\n\t\t[ hw, -hh ],\n\t\t[ hw, hh ],\n\t\t[ -hw, hh ],\n\t];\n\n\t// Transform corners through CSS matrix \u2192 screen offsets from element center.\n\t// Screen position = element_center + transformed_offset.\n\t// Element center is at (containerW/2, containerH/2) after CSS centering.\n\t// But we want normalized coords, so work relative to the visual image origin.\n\tconst offsetX = ( containerSize.width - visualSize.width ) / 2;\n\tconst offsetY = ( containerSize.height - visualSize.height ) / 2;\n\n\tlet imgMinX = Infinity;\n\tlet imgMaxX = -Infinity;\n\tlet imgMinY = Infinity;\n\tlet imgMaxY = -Infinity;\n\n\tfor ( const [ cx, cy ] of corners ) {\n\t\t// Screen offset from element center after CSS matrix.\n\t\tconst screenX = ma * cx + mc * cy + tx;\n\t\tconst screenY = mb * cx + md * cy + ty;\n\t\t// Convert to normalized visual space.\n\t\t// The element center is at the visual image center, which is at\n\t\t// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.\n\t\tconst nx = screenX / visualSize.width + 0.5;\n\t\tconst ny = screenY / visualSize.height + 0.5;\n\t\timgMinX = Math.min( imgMinX, nx );\n\t\timgMaxX = Math.max( imgMaxX, nx );\n\t\timgMinY = Math.min( imgMinY, ny );\n\t\timgMaxY = Math.max( imgMaxY, ny );\n\t}\n\n\t// Container bounds in normalized space.\n\tconst containerMinX = -offsetX / visualSize.width;\n\tconst containerMaxX = ( containerSize.width - offsetX ) / visualSize.width;\n\tconst containerMinY = -offsetY / visualSize.height;\n\tconst containerMaxY =\n\t\t( containerSize.height - offsetY ) / visualSize.height;\n\n\t// Crop bounds = intersection of image AABB and container bounds.\n\treturn {\n\t\tminX: Math.max( imgMinX, containerMinX ),\n\t\tminY: Math.max( imgMinY, containerMinY ),\n\t\tmaxX: Math.min( imgMaxX, containerMaxX ),\n\t\tmaxY: Math.min( imgMaxY, containerMaxY ),\n\t};\n}\n\n/**\n * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.\n * If the crop rect is too large for the current zoom and rotation, it is scaled\n * down proportionally and re-centered.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n *\n * @param cropRect The crop rectangle in normalized coordinates.\n * @param zoom The current zoom factor.\n * @param rotation The rotation angle in degrees.\n * @param imageAspectRatio The image width / height ratio.\n * @return The restricted crop rectangle.\n */\nexport function restrictCropRect(\n\tcropRect: NormalizedRect,\n\tzoom: number,\n\trotation: number,\n\timageAspectRatio: number\n): NormalizedRect {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil\n\t// layout); projection into the image-local frame uses the TRUE rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW, visualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\tconst W = cropRect.width;\n\tconst H = cropRect.height;\n\n\t// Crop full-extents in pixel-proportional space, projected to image-local frame.\n\tconst cropWPx = W * visualW;\n\tconst cropHPx = H * visualH;\n\tconst spanAlpha = cropWPx * absC + cropHPx * absS;\n\tconst spanBeta = cropWPx * absS + cropHPx * absC;\n\n\t// Image full-extents at zoom z: (aspectRatio*z, z).\n\tconst limitAlpha = aspectRatio * zoom;\n\tconst limitBeta = zoom;\n\n\tlet t = 1;\n\tif ( spanAlpha > 0 ) {\n\t\tt = Math.min( t, limitAlpha / spanAlpha );\n\t}\n\tif ( spanBeta > 0 ) {\n\t\tt = Math.min( t, limitBeta / spanBeta );\n\t}\n\tif ( t >= 1 - EPSILON ) {\n\t\t// Crop fits at the current zoom \u2014 no size change needed.\n\t\t// Position is handled by restrictPanZoom, not here.\n\t\treturn cropRect;\n\t}\n\tconst newW = W * t;\n\tconst newH = H * t;\n\tconst centerX = cropRect.x + W / 2;\n\tconst centerY = cropRect.y + H / 2;\n\tlet newX = centerX - newW / 2;\n\tlet newY = centerY - newH / 2;\n\tnewX = Math.max( 0, Math.min( newX, 1 - newW ) );\n\tnewY = Math.max( 0, Math.min( newY, 1 - newH ) );\n\treturn { x: newX, y: newY, width: newW, height: newH };\n}\n\n/**\n * Canonical container used internally by restrictPanZoom.\n * Containment is scale-invariant, so the actual size doesn't matter \u2014\n * only the relative geometry between stencil and image matters.\n */\nconst CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };\n\n// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on\n// every pointermove) to avoid Float32Array allocation per call.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers\n * the crop rectangle.\n *\n * Uses the camera matrix to project: builds a camera from the candidate state,\n * maps the stencil corners (axis-aligned in the visual bounding box) to world\n * space via the inverse camera, and checks that all world points lie within\n * [0,1]\u00D7[0,1]. If any point is outside, computes the minimal pan correction.\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the image in pixels.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The restricted crop pan and zoom values.\n */\nexport function restrictPanZoom(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): { pan: { x: number; y: number }; zoom: number } {\n\t// Algorithm overview:\n\t// 1. Ensure zoom is high enough for the rotated image to cover the crop.\n\t// 2. Build a camera (world\u2192screen matrix) with the candidate state.\n\t// 3. Build a base camera (no pan, zoom=1) to find where the stencil\n\t// sits in screen space \u2014 the stencil is anchored to the container,\n\t// not the image, so it doesn't move with pan or scale with zoom.\n\t// 4. Project the 4 stencil corners through the INVERSE of the main\n\t// camera to get world-space positions. A world point outside [0,1]\n\t// means that corner of the stencil isn't covered by the image.\n\t// 5. Compute the minimal translation in world space to push all corners\n\t// back inside [0,1].\n\t// 6. Convert the world-space correction to a pan-field correction by\n\t// mapping it through the camera's linear part back to screen space,\n\t// then dividing by the visual bounds.\n\tconst aspectRatio =\n\t\timageSize.width > 0 && imageSize.height > 0\n\t\t\t? imageSize.width / imageSize.height\n\t\t\t: 1;\n\tconst minZoom = getMinZoomForCover( state.rotation, aspectRatio, cropRect );\n\tconst zoom = Math.max( state.zoom, minZoom );\n\n\t// Step 2: build camera with candidate pan and corrected zoom.\n\tconst candidateState = { ...state, zoom };\n\tconst camera = createCamera(\n\t\tcandidateState,\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\n\t// Build a base camera (zero pan, zoom=1) to get stencil positions.\n\t// The stencil is anchored to the container and laid out using the\n\t// nearest 90\u00B0 rotation (matching `getImageFit`), so it's stable\n\t// through fine rotation. CSS zoom only affects the <img> element,\n\t// not the stencil.\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst baseCamera = createCamera(\n\t\t{\n\t\t\t...candidateState,\n\t\t\tpan: { x: 0, y: 0 },\n\t\t\tzoom: 1,\n\t\t\trotation: snapRotation,\n\t\t},\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\t// Stencil corners in screen space (axis-aligned rect within visual bounds).\n\tconst stencilCorners: [ number, number ][] = [\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t];\n\n\t// Map stencil corners to world space via inverse camera.\n\t// If a world point is outside [0,1], the image doesn't cover that spot.\n\t// Reuse module-level scratch buffers to avoid allocation per frame.\n\tmat2d.invert( _scratchMat, camera );\n\n\tlet minWx = Infinity;\n\tlet maxWx = -Infinity;\n\tlet minWy = Infinity;\n\tlet maxWy = -Infinity;\n\n\tfor ( const corner of stencilCorners ) {\n\t\tvec2.transformMat2d( _scratchVec, corner, _scratchMat );\n\t\tconst w = _scratchVec;\n\t\tif ( w[ 0 ] < minWx ) {\n\t\t\tminWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 0 ] > maxWx ) {\n\t\t\tmaxWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 1 ] < minWy ) {\n\t\t\tminWy = w[ 1 ];\n\t\t}\n\t\tif ( w[ 1 ] > maxWy ) {\n\t\t\tmaxWy = w[ 1 ];\n\t\t}\n\t}\n\n\t// If all world points are in [0,1], no correction needed.\n\tif (\n\t\tminWx >= -EPSILON &&\n\t\tmaxWx <= 1 + EPSILON &&\n\t\tminWy >= -EPSILON &&\n\t\tmaxWy <= 1 + EPSILON\n\t) {\n\t\treturn { pan: state.pan, zoom };\n\t}\n\n\t// Compute world-space correction needed.\n\t// If minWx < 0, we need to shift world points right by |minWx|.\n\t// If maxWx > 1, we need to shift world points left by (maxWx - 1).\n\t// If both, we're over-constrained (crop too big) \u2014 getMinZoomForCover\n\t// should have prevented this.\n\tlet dwx = 0;\n\tlet dwy = 0;\n\n\tif ( minWx < 0 && maxWx <= 1 + EPSILON ) {\n\t\tdwx = -minWx;\n\t} else if ( maxWx > 1 && minWx >= -EPSILON ) {\n\t\tdwx = 1 - maxWx;\n\t} else if ( minWx < 0 && maxWx > 1 ) {\n\t\t// Over-constrained: center it.\n\t\tdwx = ( 1 - maxWx - minWx ) / 2;\n\t}\n\n\tif ( minWy < 0 && maxWy <= 1 + EPSILON ) {\n\t\tdwy = -minWy;\n\t} else if ( maxWy > 1 && minWy >= -EPSILON ) {\n\t\tdwy = 1 - maxWy;\n\t} else if ( minWy < 0 && maxWy > 1 ) {\n\t\tdwy = ( 1 - maxWy - minWy ) / 2;\n\t}\n\n\t// Convert world-space correction to screen-space correction.\n\t// The camera's 2\u00D72 linear part (indices [0,1,2,3]) maps world deltas\n\t// to screen deltas: screenDelta = linear * worldDelta.\n\tconst dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;\n\tconst dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;\n\n\t// Convert screen-space correction to pan-field correction.\n\t// Pan in screen pixels = pan.x * visualW, pan.y * visualH.\n\t// The correction is subtractive: a positive world shift (dw > 0) means\n\t// the image needs to move opposite to pan direction, so pan decreases.\n\tconst newPanX =\n\t\tstate.pan.x -\n\t\t( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );\n\tconst newPanY =\n\t\tstate.pan.y -\n\t\t( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );\n\n\treturn {\n\t\tpan: { x: newPanX, y: newPanY },\n\t\tzoom,\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAA4B;AAM5B,sBAAiC;AACjC,oBAA+D;AAG/D,IAAM,UAAU;AAUhB,SAAS,oBACR,UACA,kBACmE;AACnE,QAAM,UAAM,kCAAkB,QAAS;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,OAAO,KAAK,IAAK,KAAK,IAAK,GAAI,CAAE;AACvC,QAAM,WAAO,8BAAgB,kBAAkB,GAAG,QAAS;AAC3D,SAAO;AAAA,IACN,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,IACd;AAAA,IACA;AAAA,EACD;AACD;AAgBA,SAAS,mBACR,UACA,kBACA,UACS;AACT,QAAM,cAAc,KAAK,IAAK,kBAAkB,OAAO,OAAQ;AAI/D,QAAM,eAAe,KAAK,MAAO,WAAW,EAAG,IAAI;AACnD,QAAM,EAAE,SAAS,aAAa,SAAS,YAAY,IAAI;AAAA,IACtD;AAAA,IACA;AAAA,EACD;AAGA,QAAM,EAAE,MAAM,KAAK,IAAI,oBAAqB,UAAU,WAAY;AAGlE,QAAM,YAAc,SAAS,QAAQ,cAAgB;AACrD,QAAM,YAAc,SAAS,SAAS,cAAgB;AAGtD,QAAM,YAAY,YAAY,OAAO,YAAY;AACjD,QAAM,WAAW,YAAY,OAAO,YAAY;AAIhD,QAAM,gBAAkB,IAAI,YAAc;AAC1C,QAAM,eAAe,IAAI;AAEzB,SAAO,KAAK,IAAK,GAAG,eAAe,YAAa;AACjD;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { mat2d, vec2 } from 'gl-matrix';\n\n/**\n * Internal dependencies\n */\nimport type { CropperState, NormalizedRect, Size } from './types';\nimport { degreesToRadians } from './math/rotation';\nimport { createCamera, getRotatedBBox, getVisibleBounds } from './camera';\n\n/** Floating-point epsilon for \"close enough to equal\" comparisons. */\nconst EPSILON = 1e-9;\n\n/**\n * Compute the visual (rotated) bounding-box dimensions in pixel-proportional\n * units where the unrotated image is `a \u00D7 1` (renderedW = a, renderedH = 1).\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @return Visual dimensions and trig helpers.\n */\nfunction getVisualDimensions(\n\trotation: number,\n\timageAspectRatio: number\n): { visualW: number; visualH: number; absC: number; absS: number } {\n\tconst rad = degreesToRadians( rotation );\n\tconst absC = Math.abs( Math.cos( rad ) );\n\tconst absS = Math.abs( Math.sin( rad ) );\n\tconst bbox = getRotatedBBox( imageAspectRatio, 1, rotation );\n\treturn {\n\t\tvisualW: bbox.width,\n\t\tvisualH: bbox.height,\n\t\tabsC,\n\t\tabsS,\n\t};\n}\n\n/**\n * Calculates the minimum zoom factor needed for the rotated image to fully cover\n * the crop rectangle, using normalized coordinates and imageAspectRatio.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n * The crop rect is in visual-normalized space and must be scaled by the\n * rotation-dependent visual dimensions before projecting into the image-local\n * frame.\n *\n * @param rotation Rotation angle in degrees.\n * @param imageAspectRatio Image width / height ratio.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The minimum zoom factor (always >= 1).\n */\nfunction getMinZoomForCover(\n\trotation: number,\n\timageAspectRatio: number,\n\tcropRect: NormalizedRect\n): number {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// The crop rect lives in the SNAP-rotation visual bbox \u2014 that's how the\n\t// stencil and preview position it (see createCamera / getImageFit). Use\n\t// the snap-rotation dimensions to convert crop fractions to pixels.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW: snapVisualW, visualH: snapVisualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\t// Projection into the image-local frame uses the TRUE rotation angle \u2014\n\t// that's the actual orientation of the image under the stencil.\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\n\t// Crop half-extents in pixel-proportional space.\n\tconst cropHalfW = ( cropRect.width * snapVisualW ) / 2;\n\tconst cropHalfH = ( cropRect.height * snapVisualH ) / 2;\n\n\t// AABB of the crop rect projected into the image-local (unrotated) frame.\n\tconst spanAlpha = cropHalfW * absC + cropHalfH * absS;\n\tconst spanBeta = cropHalfW * absS + cropHalfH * absC;\n\n\t// Image half-extents at zoom z: (aspectRatio*z/2, z/2).\n\t// Coverage requires: aspectRatio*z/2 >= spanAlpha AND z/2 >= spanBeta.\n\tconst zoomFromAlpha = ( 2 * spanAlpha ) / aspectRatio;\n\tconst zoomFromBeta = 2 * spanBeta;\n\n\treturn Math.max( 1, zoomFromAlpha, zoomFromBeta );\n}\n\n/**\n * Compute the crop handle bounds in normalized visual space \u2014 the\n * axis-aligned bounding box (AABB) of the actual image footprint at the\n * current pan/zoom/rotation.\n *\n * Returns the full image AABB without intersecting with the container\n * viewport. The viewport pan mechanism in the Cropper component allows\n * the canvas to scroll so handles can reach the image edge even when it\n * lies outside the visible canvas area.\n *\n * Unlike a static centerline-based calculation, this accounts for the\n * current pan position \u2014 if the user pans right, the left bound tightens\n * because the image's left edge has moved right.\n *\n * @param state The current cropper state (crop, zoom, rotation, flip).\n * @param elementSize The fitted (unrotated) image element dimensions in pixels.\n * @param visualSize The visual (rotated) image bounding box in pixels.\n * @return The min/max x and y that a crop rect edge can reach in normalized space.\n */\nexport function getImageCropBounds(\n\tstate: CropperState,\n\telementSize: Size,\n\tvisualSize: Size\n): { minX: number; minY: number; maxX: number; maxY: number } {\n\tif (\n\t\telementSize.width === 0 ||\n\t\telementSize.height === 0 ||\n\t\tvisualSize.width === 0 ||\n\t\tvisualSize.height === 0\n\t) {\n\t\treturn { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n\t}\n\n\t// Build the same CSS matrix as use-transform-style: flip * rotate * zoom.\n\t// Flip is outside rotation so it acts in viewport axes (see createCamera).\n\tconst tx = state.pan.x * visualSize.width;\n\tconst ty = state.pan.y * visualSize.height;\n\tconst rad = degreesToRadians( state.rotation );\n\tconst cos = Math.cos( rad );\n\tconst sin = Math.sin( rad );\n\tconst sx = state.flip.horizontal ? -1 : 1;\n\tconst sy = state.flip.vertical ? -1 : 1;\n\tconst z = state.zoom;\n\tconst ma = sx * cos * z;\n\tconst mb = sy * sin * z;\n\tconst mc = -sx * sin * z;\n\tconst md = sy * cos * z;\n\n\t// Image element corners relative to element center.\n\tconst hw = elementSize.width / 2;\n\tconst hh = elementSize.height / 2;\n\tconst corners = [\n\t\t[ -hw, -hh ],\n\t\t[ hw, -hh ],\n\t\t[ hw, hh ],\n\t\t[ -hw, hh ],\n\t];\n\n\tlet imgMinX = Infinity;\n\tlet imgMaxX = -Infinity;\n\tlet imgMinY = Infinity;\n\tlet imgMaxY = -Infinity;\n\n\tfor ( const [ cx, cy ] of corners ) {\n\t\t// Screen offset from element center after CSS matrix.\n\t\tconst screenX = ma * cx + mc * cy + tx;\n\t\tconst screenY = mb * cx + md * cy + ty;\n\t\t// Convert to normalized visual space.\n\t\t// The element center is at the visual image center, which is at\n\t\t// normalized (0.5, 0.5). So screen offset / visualSize + 0.5.\n\t\tconst nx = screenX / visualSize.width + 0.5;\n\t\tconst ny = screenY / visualSize.height + 0.5;\n\t\timgMinX = Math.min( imgMinX, nx );\n\t\timgMaxX = Math.max( imgMaxX, nx );\n\t\timgMinY = Math.min( imgMinY, ny );\n\t\timgMaxY = Math.max( imgMaxY, ny );\n\t}\n\n\treturn {\n\t\tminX: imgMinX,\n\t\tminY: imgMinY,\n\t\tmaxX: imgMaxX,\n\t\tmaxY: imgMaxY,\n\t};\n}\n\n/**\n * Restricts a crop rectangle so that the rotated, zoomed image can fully cover it.\n * If the crop rect is too large for the current zoom and rotation, it is scaled\n * down proportionally and re-centered.\n *\n * Works in pixel-proportional space where the unrotated image is a\u00D71.\n *\n * @param cropRect The crop rectangle in normalized coordinates.\n * @param zoom The current zoom factor.\n * @param rotation The rotation angle in degrees.\n * @param imageAspectRatio The image width / height ratio.\n * @return The restricted crop rectangle.\n */\nexport function restrictCropRect(\n\tcropRect: NormalizedRect,\n\tzoom: number,\n\trotation: number,\n\timageAspectRatio: number\n): NormalizedRect {\n\tconst aspectRatio = Math.max( imageAspectRatio, Number.EPSILON );\n\t// Crop rect lives in the SNAP-rotation visual bbox (matching the stencil\n\t// layout); projection into the image-local frame uses the TRUE rotation.\n\tconst snapRotation = Math.round( rotation / 90 ) * 90;\n\tconst { visualW, visualH } = getVisualDimensions(\n\t\tsnapRotation,\n\t\taspectRatio\n\t);\n\tconst { absC, absS } = getVisualDimensions( rotation, aspectRatio );\n\tconst W = cropRect.width;\n\tconst H = cropRect.height;\n\n\t// Crop full-extents in pixel-proportional space, projected to image-local frame.\n\tconst cropWPx = W * visualW;\n\tconst cropHPx = H * visualH;\n\tconst spanAlpha = cropWPx * absC + cropHPx * absS;\n\tconst spanBeta = cropWPx * absS + cropHPx * absC;\n\n\t// Image full-extents at zoom z: (aspectRatio*z, z).\n\tconst limitAlpha = aspectRatio * zoom;\n\tconst limitBeta = zoom;\n\n\tlet t = 1;\n\tif ( spanAlpha > 0 ) {\n\t\tt = Math.min( t, limitAlpha / spanAlpha );\n\t}\n\tif ( spanBeta > 0 ) {\n\t\tt = Math.min( t, limitBeta / spanBeta );\n\t}\n\tif ( t >= 1 - EPSILON ) {\n\t\t// Crop fits at the current zoom \u2014 no size change needed.\n\t\t// Position is handled by restrictPanZoom, not here.\n\t\treturn cropRect;\n\t}\n\tconst newW = W * t;\n\tconst newH = H * t;\n\tconst centerX = cropRect.x + W / 2;\n\tconst centerY = cropRect.y + H / 2;\n\tlet newX = centerX - newW / 2;\n\tlet newY = centerY - newH / 2;\n\tnewX = Math.max( 0, Math.min( newX, 1 - newW ) );\n\tnewY = Math.max( 0, Math.min( newY, 1 - newH ) );\n\treturn { x: newX, y: newY, width: newW, height: newH };\n}\n\n/**\n * Canonical container used internally by restrictPanZoom.\n * Containment is scale-invariant, so the actual size doesn't matter \u2014\n * only the relative geometry between stencil and image matters.\n */\nconst CANONICAL_CONTAINER: Size = { width: 1000, height: 1000 };\n\n// Pre-allocated scratch buffers for restrictPanZoom's hot path (runs on\n// every pointermove) to avoid Float32Array allocation per call.\nconst _scratchMat = mat2d.create();\nconst _scratchVec = vec2.create();\n\n/**\n * Clamps pan and adjusts zoom so that the zoomed, rotated image fully covers\n * the crop rectangle.\n *\n * Uses the camera matrix to project: builds a camera from the candidate state,\n * maps the stencil corners (axis-aligned in the visual bounding box) to world\n * space via the inverse camera, and checks that all world points lie within\n * [0,1]\u00D7[0,1]. If any point is outside, computes the minimal pan correction.\n *\n * @param state The current cropper state.\n * @param imageSize The natural size of the image in pixels.\n * @param cropRect The crop rectangle in normalized coordinates.\n * @return The restricted crop pan and zoom values.\n */\nexport function restrictPanZoom(\n\tstate: CropperState,\n\timageSize: Size,\n\tcropRect: NormalizedRect\n): { pan: { x: number; y: number }; zoom: number } {\n\t// Algorithm overview:\n\t// 1. Ensure zoom is high enough for the rotated image to cover the crop.\n\t// 2. Build a camera (world\u2192screen matrix) with the candidate state.\n\t// 3. Build a base camera (no pan, zoom=1) to find where the stencil\n\t// sits in screen space \u2014 the stencil is anchored to the container,\n\t// not the image, so it doesn't move with pan or scale with zoom.\n\t// 4. Project the 4 stencil corners through the INVERSE of the main\n\t// camera to get world-space positions. A world point outside [0,1]\n\t// means that corner of the stencil isn't covered by the image.\n\t// 5. Compute the minimal translation in world space to push all corners\n\t// back inside [0,1].\n\t// 6. Convert the world-space correction to a pan-field correction by\n\t// mapping it through the camera's linear part back to screen space,\n\t// then dividing by the visual bounds.\n\tconst aspectRatio =\n\t\timageSize.width > 0 && imageSize.height > 0\n\t\t\t? imageSize.width / imageSize.height\n\t\t\t: 1;\n\tconst minZoom = getMinZoomForCover( state.rotation, aspectRatio, cropRect );\n\tconst zoom = Math.max( state.zoom, minZoom );\n\n\t// Step 2: build camera with candidate pan and corrected zoom.\n\tconst candidateState = { ...state, zoom };\n\tconst camera = createCamera(\n\t\tcandidateState,\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\n\t// Build a base camera (zero pan, zoom=1) to get stencil positions.\n\t// The stencil is anchored to the container and laid out using the\n\t// nearest 90\u00B0 rotation (matching `getImageFit`), so it's stable\n\t// through fine rotation. CSS zoom only affects the <img> element,\n\t// not the stencil.\n\tconst snapRotation = Math.round( state.rotation / 90 ) * 90;\n\tconst baseCamera = createCamera(\n\t\t{\n\t\t\t...candidateState,\n\t\t\tpan: { x: 0, y: 0 },\n\t\t\tzoom: 1,\n\t\t\trotation: snapRotation,\n\t\t},\n\t\tCANONICAL_CONTAINER,\n\t\timageSize\n\t);\n\tconst visibleBounds = getVisibleBounds( baseCamera );\n\n\t// Stencil corners in screen space (axis-aligned rect within visual bounds).\n\tconst stencilCorners: [ number, number ][] = [\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top + cropRect.y * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left +\n\t\t\t\t( cropRect.x + cropRect.width ) * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t\t[\n\t\t\tvisibleBounds.left + cropRect.x * visibleBounds.width,\n\t\t\tvisibleBounds.top +\n\t\t\t\t( cropRect.y + cropRect.height ) * visibleBounds.height,\n\t\t],\n\t];\n\n\t// Map stencil corners to world space via inverse camera.\n\t// If a world point is outside [0,1], the image doesn't cover that spot.\n\t// Reuse module-level scratch buffers to avoid allocation per frame.\n\tmat2d.invert( _scratchMat, camera );\n\n\tlet minWx = Infinity;\n\tlet maxWx = -Infinity;\n\tlet minWy = Infinity;\n\tlet maxWy = -Infinity;\n\n\tfor ( const corner of stencilCorners ) {\n\t\tvec2.transformMat2d( _scratchVec, corner, _scratchMat );\n\t\tconst w = _scratchVec;\n\t\tif ( w[ 0 ] < minWx ) {\n\t\t\tminWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 0 ] > maxWx ) {\n\t\t\tmaxWx = w[ 0 ];\n\t\t}\n\t\tif ( w[ 1 ] < minWy ) {\n\t\t\tminWy = w[ 1 ];\n\t\t}\n\t\tif ( w[ 1 ] > maxWy ) {\n\t\t\tmaxWy = w[ 1 ];\n\t\t}\n\t}\n\n\t// If all world points are in [0,1], no correction needed.\n\tif (\n\t\tminWx >= -EPSILON &&\n\t\tmaxWx <= 1 + EPSILON &&\n\t\tminWy >= -EPSILON &&\n\t\tmaxWy <= 1 + EPSILON\n\t) {\n\t\treturn { pan: state.pan, zoom };\n\t}\n\n\t// Compute world-space correction needed.\n\t// If minWx < 0, we need to shift world points right by |minWx|.\n\t// If maxWx > 1, we need to shift world points left by (maxWx - 1).\n\t// If both, we're over-constrained (crop too big) \u2014 getMinZoomForCover\n\t// should have prevented this.\n\tlet dwx = 0;\n\tlet dwy = 0;\n\n\tif ( minWx < 0 && maxWx <= 1 + EPSILON ) {\n\t\tdwx = -minWx;\n\t} else if ( maxWx > 1 && minWx >= -EPSILON ) {\n\t\tdwx = 1 - maxWx;\n\t} else if ( minWx < 0 && maxWx > 1 ) {\n\t\t// Over-constrained: center it.\n\t\tdwx = ( 1 - maxWx - minWx ) / 2;\n\t}\n\n\tif ( minWy < 0 && maxWy <= 1 + EPSILON ) {\n\t\tdwy = -minWy;\n\t} else if ( maxWy > 1 && minWy >= -EPSILON ) {\n\t\tdwy = 1 - maxWy;\n\t} else if ( minWy < 0 && maxWy > 1 ) {\n\t\tdwy = ( 1 - maxWy - minWy ) / 2;\n\t}\n\n\t// Convert world-space correction to screen-space correction.\n\t// The camera's 2\u00D72 linear part (indices [0,1,2,3]) maps world deltas\n\t// to screen deltas: screenDelta = linear * worldDelta.\n\tconst dsx = camera[ 0 ] * dwx + camera[ 2 ] * dwy;\n\tconst dsy = camera[ 1 ] * dwx + camera[ 3 ] * dwy;\n\n\t// Convert screen-space correction to pan-field correction.\n\t// Pan in screen pixels = pan.x * visualW, pan.y * visualH.\n\t// The correction is subtractive: a positive world shift (dw > 0) means\n\t// the image needs to move opposite to pan direction, so pan decreases.\n\tconst newPanX =\n\t\tstate.pan.x -\n\t\t( visibleBounds.width > 0 ? dsx / visibleBounds.width : 0 );\n\tconst newPanY =\n\t\tstate.pan.y -\n\t\t( visibleBounds.height > 0 ? dsy / visibleBounds.height : 0 );\n\n\treturn {\n\t\tpan: { x: newPanX, y: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AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -77,11 +77,20 @@ var InteractionController = class {
|
|
|
77
77
|
}
|
|
78
78
|
/** Read zoomSpeed lazily so option changes take effect immediately. */
|
|
79
79
|
get zoomSpeed() {
|
|
80
|
-
return this.options.zoomSpeed ??
|
|
80
|
+
return this.options.zoomSpeed ?? import_constants.DEFAULT_WHEEL_ZOOM_SPEED;
|
|
81
81
|
}
|
|
82
82
|
/** Read keyboardStep lazily so option changes take effect immediately. */
|
|
83
83
|
get keyboardStep() {
|
|
84
|
-
return this.options.keyboardStep ??
|
|
84
|
+
return this.options.keyboardStep ?? import_constants.DEFAULT_KEYBOARD_STEP;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the keyboard pan step, including modifier-based coarse movement.
|
|
88
|
+
*
|
|
89
|
+
* @param event The native KeyboardEvent.
|
|
90
|
+
* @return The normalized pan step.
|
|
91
|
+
*/
|
|
92
|
+
getKeyboardStep(event) {
|
|
93
|
+
return event.shiftKey ? this.keyboardStep * import_constants.KEYBOARD_SHIFT_STEP_MULTIPLIER : this.keyboardStep;
|
|
85
94
|
}
|
|
86
95
|
/** Read doubleTapZoom lazily so option changes take effect immediately. */
|
|
87
96
|
get doubleTapZoom() {
|
|
@@ -197,6 +206,9 @@ var InteractionController = class {
|
|
|
197
206
|
*/
|
|
198
207
|
handleWheel(e) {
|
|
199
208
|
e.preventDefault();
|
|
209
|
+
if (this.drag) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
200
212
|
if (!this.wheelGestureActive) {
|
|
201
213
|
this.wheelGestureActive = true;
|
|
202
214
|
this.options.onGestureStart?.();
|
|
@@ -454,6 +466,7 @@ var InteractionController = class {
|
|
|
454
466
|
this.zoomTimer = setTimeout(() => {
|
|
455
467
|
this.setStatus({ isZooming: false });
|
|
456
468
|
}, ZOOM_ANIMATION_DURATION);
|
|
469
|
+
this.options.onGestureStart?.();
|
|
457
470
|
if (visSize.width > 0 && visSize.height > 0) {
|
|
458
471
|
const fx = tapX - containerRect.left - containerSize.width / 2;
|
|
459
472
|
const fy = tapY - containerRect.top - containerSize.height / 2;
|
|
@@ -475,6 +488,7 @@ var InteractionController = class {
|
|
|
475
488
|
} else {
|
|
476
489
|
this.options.actions.setZoom(targetZoom);
|
|
477
490
|
}
|
|
491
|
+
this.options.onGestureEnd?.();
|
|
478
492
|
return true;
|
|
479
493
|
}
|
|
480
494
|
/**
|
|
@@ -489,12 +503,13 @@ var InteractionController = class {
|
|
|
489
503
|
switch (e.key) {
|
|
490
504
|
case "ArrowUp": {
|
|
491
505
|
e.preventDefault();
|
|
506
|
+
const keyboardStep = this.getKeyboardStep(e);
|
|
492
507
|
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
493
508
|
{
|
|
494
509
|
...currentState,
|
|
495
510
|
pan: {
|
|
496
511
|
x: currentState.pan.x,
|
|
497
|
-
y: currentState.pan.y +
|
|
512
|
+
y: currentState.pan.y + keyboardStep
|
|
498
513
|
}
|
|
499
514
|
},
|
|
500
515
|
getImageSizeFromState(currentState),
|
|
@@ -505,12 +520,13 @@ var InteractionController = class {
|
|
|
505
520
|
}
|
|
506
521
|
case "ArrowDown": {
|
|
507
522
|
e.preventDefault();
|
|
523
|
+
const keyboardStep = this.getKeyboardStep(e);
|
|
508
524
|
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
509
525
|
{
|
|
510
526
|
...currentState,
|
|
511
527
|
pan: {
|
|
512
528
|
x: currentState.pan.x,
|
|
513
|
-
y: currentState.pan.y -
|
|
529
|
+
y: currentState.pan.y - keyboardStep
|
|
514
530
|
}
|
|
515
531
|
},
|
|
516
532
|
getImageSizeFromState(currentState),
|
|
@@ -521,11 +537,12 @@ var InteractionController = class {
|
|
|
521
537
|
}
|
|
522
538
|
case "ArrowLeft": {
|
|
523
539
|
e.preventDefault();
|
|
540
|
+
const keyboardStep = this.getKeyboardStep(e);
|
|
524
541
|
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
525
542
|
{
|
|
526
543
|
...currentState,
|
|
527
544
|
pan: {
|
|
528
|
-
x: currentState.pan.x +
|
|
545
|
+
x: currentState.pan.x + keyboardStep,
|
|
529
546
|
y: currentState.pan.y
|
|
530
547
|
}
|
|
531
548
|
},
|
|
@@ -537,11 +554,12 @@ var InteractionController = class {
|
|
|
537
554
|
}
|
|
538
555
|
case "ArrowRight": {
|
|
539
556
|
e.preventDefault();
|
|
557
|
+
const keyboardStep = this.getKeyboardStep(e);
|
|
540
558
|
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
541
559
|
{
|
|
542
560
|
...currentState,
|
|
543
561
|
pan: {
|
|
544
|
-
x: currentState.pan.x -
|
|
562
|
+
x: currentState.pan.x - keyboardStep,
|
|
545
563
|
y: currentState.pan.y
|
|
546
564
|
}
|
|
547
565
|
},
|
|
@@ -573,11 +591,29 @@ var InteractionController = class {
|
|
|
573
591
|
}
|
|
574
592
|
case "r":
|
|
575
593
|
case "R": {
|
|
594
|
+
if (e.metaKey || e.ctrlKey || e.altKey) {
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
e.preventDefault();
|
|
598
|
+
this.options.actions.snapRotate90(e.shiftKey ? -1 : 1);
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
case "h":
|
|
602
|
+
case "H": {
|
|
603
|
+
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
e.preventDefault();
|
|
607
|
+
this.options.actions.toggleFlip?.("horizontal");
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
case "v":
|
|
611
|
+
case "V": {
|
|
576
612
|
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
|
|
577
613
|
break;
|
|
578
614
|
}
|
|
579
615
|
e.preventDefault();
|
|
580
|
-
this.options.actions.
|
|
616
|
+
this.options.actions.toggleFlip?.("vertical");
|
|
581
617
|
break;
|
|
582
618
|
}
|
|
583
619
|
}
|