@wordpress/media-editor 0.7.1-next.v.202604201441.0 → 0.8.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-canvas/index.cjs +54 -0
- package/build/components/media-editor-canvas/index.cjs.map +7 -0
- package/build/components/media-editor-crop-panel/index.cjs +116 -0
- package/build/components/media-editor-crop-panel/index.cjs.map +7 -0
- package/build/components/media-editor-modal/build-modifiers.cjs +91 -0
- package/build/components/media-editor-modal/build-modifiers.cjs.map +7 -0
- package/build/components/media-editor-modal/index.cjs +497 -0
- package/build/components/media-editor-modal/index.cjs.map +7 -0
- package/build/components/media-editor-toolbar/index.cjs +146 -0
- package/build/components/media-editor-toolbar/index.cjs.map +7 -0
- package/build/image-editor/core/camera.cjs +194 -0
- package/build/image-editor/core/camera.cjs.map +7 -0
- package/build/image-editor/core/constants.cjs +81 -0
- package/build/image-editor/core/constants.cjs.map +7 -0
- package/build/image-editor/core/containment.cjs +245 -0
- package/build/image-editor/core/containment.cjs.map +7 -0
- package/build/image-editor/core/export/canvas-renderer.cjs +151 -0
- package/build/image-editor/core/export/canvas-renderer.cjs.map +7 -0
- package/build/image-editor/core/index.cjs +50 -0
- package/build/image-editor/core/index.cjs.map +7 -0
- package/build/image-editor/core/interaction-controller.cjs +608 -0
- package/build/image-editor/core/interaction-controller.cjs.map +7 -0
- package/build/image-editor/core/math/rotation.cjs +41 -0
- package/build/image-editor/core/math/rotation.cjs.map +7 -0
- package/build/image-editor/core/source-region.cjs +95 -0
- package/build/image-editor/core/source-region.cjs.map +7 -0
- package/build/image-editor/core/state.cjs +269 -0
- package/build/image-editor/core/state.cjs.map +7 -0
- package/build/image-editor/core/stencil-math.cjs +197 -0
- package/build/image-editor/core/stencil-math.cjs.map +7 -0
- package/build/image-editor/core/transform-style.cjs +46 -0
- package/build/image-editor/core/transform-style.cjs.map +7 -0
- package/build/image-editor/core/transforms/pipeline.cjs +43 -0
- package/build/image-editor/core/transforms/pipeline.cjs.map +7 -0
- package/build/image-editor/core/types.cjs +19 -0
- package/build/image-editor/core/types.cjs.map +7 -0
- package/build/image-editor/index.cjs +57 -0
- package/build/image-editor/index.cjs.map +7 -0
- package/build/image-editor/react/components/cropper-provider.cjs +50 -0
- package/build/image-editor/react/components/cropper-provider.cjs.map +7 -0
- package/build/image-editor/react/components/cropper.cjs +365 -0
- package/build/image-editor/react/components/cropper.cjs.map +7 -0
- package/build/image-editor/react/components/index.cjs +36 -0
- package/build/image-editor/react/components/index.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs +58 -0
- package/build/image-editor/react/components/overlays/dimming-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs +91 -0
- package/build/image-editor/react/components/overlays/grid-overlay.cjs.map +7 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs +351 -0
- package/build/image-editor/react/components/stencils/rectangle-stencil.cjs.map +7 -0
- package/build/image-editor/react/hooks/index.cjs +31 -0
- package/build/image-editor/react/hooks/index.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs +68 -0
- package/build/image-editor/react/hooks/use-aria-announcer.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs +158 -0
- package/build/image-editor/react/hooks/use-cropper-state.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-interaction.cjs +161 -0
- package/build/image-editor/react/hooks/use-interaction.cjs.map +7 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs +38 -0
- package/build/image-editor/react/hooks/use-transform-style.cjs.map +7 -0
- package/build/index.cjs +5 -2
- package/build/index.cjs.map +2 -2
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/private-apis.cjs +38 -0
- package/build/private-apis.cjs.map +7 -0
- package/build/store/actions.cjs +45 -0
- package/build/store/actions.cjs.map +7 -0
- package/build/store/constants.cjs +31 -0
- package/build/store/constants.cjs.map +7 -0
- package/build/store/index.cjs +51 -0
- package/build/store/index.cjs.map +7 -0
- package/build/store/reducer.cjs +51 -0
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/selectors.cjs +43 -0
- package/build/store/selectors.cjs.map +7 -0
- package/build-module/components/media-editor-canvas/index.mjs +33 -0
- package/build-module/components/media-editor-canvas/index.mjs.map +7 -0
- package/build-module/components/media-editor-crop-panel/index.mjs +100 -0
- package/build-module/components/media-editor-crop-panel/index.mjs.map +7 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs +66 -0
- package/build-module/components/media-editor-modal/build-modifiers.mjs.map +7 -0
- package/build-module/components/media-editor-modal/index.mjs +483 -0
- package/build-module/components/media-editor-modal/index.mjs.map +7 -0
- package/build-module/components/media-editor-toolbar/index.mjs +130 -0
- package/build-module/components/media-editor-toolbar/index.mjs.map +7 -0
- package/build-module/image-editor/core/camera.mjs +163 -0
- package/build-module/image-editor/core/camera.mjs.map +7 -0
- package/build-module/image-editor/core/constants.mjs +51 -0
- package/build-module/image-editor/core/constants.mjs.map +7 -0
- package/build-module/image-editor/core/containment.mjs +218 -0
- package/build-module/image-editor/core/containment.mjs.map +7 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs +120 -0
- package/build-module/image-editor/core/export/canvas-renderer.mjs.map +7 -0
- package/build-module/image-editor/core/index.mjs +24 -0
- package/build-module/image-editor/core/index.mjs.map +7 -0
- package/build-module/image-editor/core/interaction-controller.mjs +583 -0
- package/build-module/image-editor/core/interaction-controller.mjs.map +7 -0
- package/build-module/image-editor/core/math/rotation.mjs +15 -0
- package/build-module/image-editor/core/math/rotation.mjs.map +7 -0
- package/build-module/image-editor/core/source-region.mjs +69 -0
- package/build-module/image-editor/core/source-region.mjs.map +7 -0
- package/build-module/image-editor/core/state.mjs +242 -0
- package/build-module/image-editor/core/state.mjs.map +7 -0
- package/build-module/image-editor/core/stencil-math.mjs +169 -0
- package/build-module/image-editor/core/stencil-math.mjs.map +7 -0
- package/build-module/image-editor/core/transform-style.mjs +21 -0
- package/build-module/image-editor/core/transform-style.mjs.map +7 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs +17 -0
- package/build-module/image-editor/core/transforms/pipeline.mjs.map +7 -0
- package/build-module/image-editor/core/types.mjs +1 -0
- package/build-module/image-editor/core/types.mjs.map +7 -0
- package/build-module/image-editor/index.mjs +30 -0
- package/build-module/image-editor/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs +26 -0
- package/build-module/image-editor/react/components/cropper-provider.mjs.map +7 -0
- package/build-module/image-editor/react/components/cropper.mjs +337 -0
- package/build-module/image-editor/react/components/cropper.mjs.map +7 -0
- package/build-module/image-editor/react/components/index.mjs +9 -0
- package/build-module/image-editor/react/components/index.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs +33 -0
- package/build-module/image-editor/react/components/overlays/dimming-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs +66 -0
- package/build-module/image-editor/react/components/overlays/grid-overlay.mjs.map +7 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs +330 -0
- package/build-module/image-editor/react/components/stencils/rectangle-stencil.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/index.mjs +6 -0
- package/build-module/image-editor/react/hooks/index.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs +43 -0
- package/build-module/image-editor/react/hooks/use-aria-announcer.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs +137 -0
- package/build-module/image-editor/react/hooks/use-cropper-state.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs +138 -0
- package/build-module/image-editor/react/hooks/use-interaction.mjs.map +7 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs +13 -0
- package/build-module/image-editor/react/hooks/use-transform-style.mjs.map +7 -0
- package/build-module/index.mjs +3 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/private-apis.mjs +13 -0
- package/build-module/private-apis.mjs.map +7 -0
- package/build-module/store/actions.mjs +19 -0
- package/build-module/store/actions.mjs.map +7 -0
- package/build-module/store/constants.mjs +6 -0
- package/build-module/store/constants.mjs.map +7 -0
- package/build-module/store/index.mjs +16 -0
- package/build-module/store/index.mjs.map +7 -0
- package/build-module/store/reducer.mjs +26 -0
- package/build-module/store/reducer.mjs.map +7 -0
- package/build-module/store/selectors.mjs +16 -0
- package/build-module/store/selectors.mjs.map +7 -0
- package/build-style/style-rtl.css +315 -0
- package/build-style/style.css +315 -0
- package/build-types/components/media-editor-canvas/index.d.ts +22 -0
- package/build-types/components/media-editor-canvas/index.d.ts.map +1 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts +45 -0
- package/build-types/components/media-editor-crop-panel/index.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts +83 -0
- package/build-types/components/media-editor-modal/build-modifiers.d.ts.map +1 -0
- package/build-types/components/media-editor-modal/index.d.ts +20 -0
- package/build-types/components/media-editor-modal/index.d.ts.map +1 -0
- package/build-types/components/media-editor-toolbar/index.d.ts +21 -0
- package/build-types/components/media-editor-toolbar/index.d.ts.map +1 -0
- package/build-types/image-editor/core/camera.d.ts +107 -0
- package/build-types/image-editor/core/camera.d.ts.map +1 -0
- package/build-types/image-editor/core/constants.d.ts +46 -0
- package/build-types/image-editor/core/constants.d.ts.map +1 -0
- package/build-types/image-editor/core/containment.d.ts +61 -0
- package/build-types/image-editor/core/containment.d.ts.map +1 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts +106 -0
- package/build-types/image-editor/core/export/canvas-renderer.d.ts.map +1 -0
- package/build-types/image-editor/core/index.d.ts +8 -0
- package/build-types/image-editor/core/index.d.ts.map +1 -0
- package/build-types/image-editor/core/interaction-controller.d.ts +178 -0
- package/build-types/image-editor/core/interaction-controller.d.ts.map +1 -0
- package/build-types/image-editor/core/math/rotation.d.ts +18 -0
- package/build-types/image-editor/core/math/rotation.d.ts.map +1 -0
- package/build-types/image-editor/core/source-region.d.ts +75 -0
- package/build-types/image-editor/core/source-region.d.ts.map +1 -0
- package/build-types/image-editor/core/state.d.ts +42 -0
- package/build-types/image-editor/core/state.d.ts.map +1 -0
- package/build-types/image-editor/core/stencil-math.d.ts +79 -0
- package/build-types/image-editor/core/stencil-math.d.ts.map +1 -0
- package/build-types/image-editor/core/transform-style.d.ts +23 -0
- package/build-types/image-editor/core/transform-style.d.ts.map +1 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts +27 -0
- package/build-types/image-editor/core/transforms/pipeline.d.ts.map +1 -0
- package/build-types/image-editor/core/types.d.ts +211 -0
- package/build-types/image-editor/core/types.d.ts.map +1 -0
- package/build-types/image-editor/index.d.ts +16 -0
- package/build-types/image-editor/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts +37 -0
- package/build-types/image-editor/react/components/cropper-provider.d.ts.map +1 -0
- package/build-types/image-editor/react/components/cropper.d.ts +59 -0
- package/build-types/image-editor/react/components/cropper.d.ts.map +1 -0
- package/build-types/image-editor/react/components/index.d.ts +4 -0
- package/build-types/image-editor/react/components/index.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/dimming-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts +30 -0
- package/build-types/image-editor/react/components/overlays/grid-overlay.d.ts.map +1 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts +32 -0
- package/build-types/image-editor/react/components/stencils/rectangle-stencil.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/index.d.ts +3 -0
- package/build-types/image-editor/react/hooks/index.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-aria-announcer.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts +68 -0
- package/build-types/image-editor/react/hooks/use-cropper-state.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts +60 -0
- package/build-types/image-editor/react/hooks/use-interaction.d.ts.map +1 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts +16 -0
- package/build-types/image-editor/react/hooks/use-transform-style.d.ts.map +1 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts +16 -0
- package/build-types/image-editor/stories/rectangle-crop.story.d.ts.map +1 -0
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +27 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +2 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +4 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +23 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +8 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/package.json +21 -7
- package/src/components/media-editor-canvas/index.tsx +56 -0
- package/src/components/media-editor-canvas/style.scss +9 -0
- package/src/components/media-editor-crop-panel/index.tsx +143 -0
- package/src/components/media-editor-modal/build-modifiers.ts +164 -0
- package/src/components/media-editor-modal/index.tsx +639 -0
- package/src/components/media-editor-modal/style.scss +139 -0
- package/src/components/media-editor-modal/test/build-modifiers.test.ts +343 -0
- package/src/components/media-editor-toolbar/index.tsx +150 -0
- package/src/components/media-editor-toolbar/style.scss +21 -0
- package/src/image-editor/README.md +162 -0
- package/src/image-editor/core/camera.ts +352 -0
- package/src/image-editor/core/constants.ts +93 -0
- package/src/image-editor/core/containment.ts +435 -0
- package/src/image-editor/core/export/canvas-renderer.ts +253 -0
- package/src/image-editor/core/export/test/canvas-renderer.ts +813 -0
- package/src/image-editor/core/index.ts +35 -0
- package/src/image-editor/core/interaction-controller.ts +889 -0
- package/src/image-editor/core/math/rotation.ts +26 -0
- package/src/image-editor/core/source-region.ts +166 -0
- package/src/image-editor/core/state.ts +428 -0
- package/src/image-editor/core/stencil-math.ts +330 -0
- package/src/image-editor/core/test/camera.ts +593 -0
- package/src/image-editor/core/test/interaction-controller.ts +996 -0
- package/src/image-editor/core/test/preview-export-parity.ts +242 -0
- package/src/image-editor/core/test/render-camera-bridge.ts +348 -0
- package/src/image-editor/core/test/state.ts +762 -0
- package/src/image-editor/core/test/stencil-math.ts +321 -0
- package/src/image-editor/core/transform-style.ts +44 -0
- package/src/image-editor/core/transforms/pipeline.ts +43 -0
- package/src/image-editor/core/transforms/test/pipeline.ts +269 -0
- package/src/image-editor/core/types.ts +177 -0
- package/src/image-editor/docs/architecture.md +96 -0
- package/src/image-editor/docs/recipes.md +720 -0
- package/src/image-editor/docs/roadmap.md +66 -0
- package/src/image-editor/index.ts +43 -0
- package/src/image-editor/react/components/cropper-provider.tsx +73 -0
- package/src/image-editor/react/components/cropper.scss +195 -0
- package/src/image-editor/react/components/cropper.tsx +534 -0
- package/src/image-editor/react/components/index.ts +3 -0
- package/src/image-editor/react/components/overlays/dimming-overlay.tsx +57 -0
- package/src/image-editor/react/components/overlays/grid-overlay.tsx +80 -0
- package/src/image-editor/react/components/stencils/rectangle-stencil.tsx +513 -0
- package/src/image-editor/react/components/stencils/test/rectangle-stencil.tsx +265 -0
- package/src/image-editor/react/components/test/cropper.tsx +140 -0
- package/src/image-editor/react/hooks/index.ts +2 -0
- package/src/image-editor/react/hooks/test/use-cropper-state.ts +913 -0
- package/src/image-editor/react/hooks/test/use-interaction.ts +218 -0
- package/src/image-editor/react/hooks/test/use-transform-style.ts +146 -0
- package/src/image-editor/react/hooks/use-aria-announcer.ts +64 -0
- package/src/image-editor/react/hooks/use-cropper-state.ts +238 -0
- package/src/image-editor/react/hooks/use-interaction.ts +223 -0
- package/src/image-editor/react/hooks/use-transform-style.ts +30 -0
- package/src/image-editor/stories/rectangle-crop.story.tsx +1085 -0
- package/src/image-editor/stories/style.css +94 -0
- package/src/image-editor/style.scss +1 -0
- package/src/index.ts +3 -0
- package/src/lock-unlock.ts +10 -0
- package/src/private-apis.ts +12 -0
- package/src/store/actions.ts +33 -0
- package/src/store/constants.ts +1 -0
- package/src/store/index.ts +20 -0
- package/src/store/reducer.ts +48 -0
- package/src/store/selectors.ts +16 -0
- package/src/store/test/reducer.ts +57 -0
- package/src/style.scss +4 -0
- package/tsconfig.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,608 @@
|
|
|
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/image-editor/core/interaction-controller.ts
|
|
21
|
+
var interaction_controller_exports = {};
|
|
22
|
+
__export(interaction_controller_exports, {
|
|
23
|
+
InteractionController: () => InteractionController
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(interaction_controller_exports);
|
|
26
|
+
var import_constants = require("./constants.cjs");
|
|
27
|
+
var import_containment = require("./containment.cjs");
|
|
28
|
+
var DOUBLE_TAP_TIME = 300;
|
|
29
|
+
var DOUBLE_TAP_DISTANCE = 30;
|
|
30
|
+
var ZOOM_ANIMATION_DURATION = 200;
|
|
31
|
+
function getImageSizeFromState(state) {
|
|
32
|
+
return state.image ? { width: state.image.naturalWidth, height: state.image.naturalHeight } : { width: 1, height: 1 };
|
|
33
|
+
}
|
|
34
|
+
function getTouchDistance(t1, t2) {
|
|
35
|
+
const dx = t1.clientX - t2.clientX;
|
|
36
|
+
const dy = t1.clientY - t2.clientY;
|
|
37
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
38
|
+
}
|
|
39
|
+
var InteractionController = class {
|
|
40
|
+
options;
|
|
41
|
+
/** Current drag/zoom status. */
|
|
42
|
+
isDragging = false;
|
|
43
|
+
isZooming = false;
|
|
44
|
+
/** Active drag state during pointer interactions. */
|
|
45
|
+
drag = null;
|
|
46
|
+
/** Active touch state during touch interactions. */
|
|
47
|
+
touch = null;
|
|
48
|
+
/** Cleanup function for active touch listeners on document. */
|
|
49
|
+
touchCleanup = null;
|
|
50
|
+
/**
|
|
51
|
+
* Cleanup function for active pointer-drag listeners on the
|
|
52
|
+
* captured element. Set while a pointer drag is in progress so
|
|
53
|
+
* `destroy()` can tear the drag down cleanly if the consumer
|
|
54
|
+
* unmounts mid-drag. Cleared on pointerup/lostpointercapture.
|
|
55
|
+
*/
|
|
56
|
+
pointerCleanup = null;
|
|
57
|
+
/** Last tap info for double-tap detection. */
|
|
58
|
+
lastTap = null;
|
|
59
|
+
/** Timer for the zoom animation state (double-tap). */
|
|
60
|
+
zoomTimer;
|
|
61
|
+
/** Timer for wheel gesture debounce. */
|
|
62
|
+
wheelGestureTimer;
|
|
63
|
+
/** Whether a wheel gesture is currently active. */
|
|
64
|
+
wheelGestureActive = false;
|
|
65
|
+
/** Current requestAnimationFrame ID. */
|
|
66
|
+
rafId = 0;
|
|
67
|
+
constructor(options) {
|
|
68
|
+
this.options = options;
|
|
69
|
+
}
|
|
70
|
+
/** Read minZoom lazily so option changes take effect immediately. */
|
|
71
|
+
get minZoom() {
|
|
72
|
+
return this.options.minZoom ?? import_constants.MIN_ZOOM;
|
|
73
|
+
}
|
|
74
|
+
/** Read maxZoom lazily so option changes take effect immediately. */
|
|
75
|
+
get maxZoom() {
|
|
76
|
+
return this.options.maxZoom ?? import_constants.MAX_ZOOM;
|
|
77
|
+
}
|
|
78
|
+
/** Read zoomSpeed lazily so option changes take effect immediately. */
|
|
79
|
+
get zoomSpeed() {
|
|
80
|
+
return this.options.zoomSpeed ?? 0.01;
|
|
81
|
+
}
|
|
82
|
+
/** Read keyboardStep lazily so option changes take effect immediately. */
|
|
83
|
+
get keyboardStep() {
|
|
84
|
+
return this.options.keyboardStep ?? 0.05;
|
|
85
|
+
}
|
|
86
|
+
/** Read doubleTapZoom lazily so option changes take effect immediately. */
|
|
87
|
+
get doubleTapZoom() {
|
|
88
|
+
return this.options.doubleTapZoom ?? 2;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Update the drag/zoom status and notify via callback if changed.
|
|
92
|
+
*
|
|
93
|
+
* @param update Partial status with isDragging and/or isZooming.
|
|
94
|
+
*/
|
|
95
|
+
setStatus(update) {
|
|
96
|
+
let changed = false;
|
|
97
|
+
if (update.isDragging !== void 0 && update.isDragging !== this.isDragging) {
|
|
98
|
+
this.isDragging = update.isDragging;
|
|
99
|
+
changed = true;
|
|
100
|
+
}
|
|
101
|
+
if (update.isZooming !== void 0 && update.isZooming !== this.isZooming) {
|
|
102
|
+
this.isZooming = update.isZooming;
|
|
103
|
+
changed = true;
|
|
104
|
+
}
|
|
105
|
+
if (changed) {
|
|
106
|
+
this.options.onStatusChange?.({
|
|
107
|
+
isDragging: this.isDragging,
|
|
108
|
+
isZooming: this.isZooming
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Handle a pointer-down event on the container element.
|
|
114
|
+
*
|
|
115
|
+
* Initiates a drag (pan) interaction. Captures the pointer on the
|
|
116
|
+
* provided element and registers pointermove/pointerup/lostpointercapture
|
|
117
|
+
* listeners for the duration of the drag.
|
|
118
|
+
*
|
|
119
|
+
* @param e The native PointerEvent.
|
|
120
|
+
* @param el The DOM element to capture the pointer on.
|
|
121
|
+
*/
|
|
122
|
+
handlePointerDown(e, el) {
|
|
123
|
+
if (e.button !== 0) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
const ownerDoc = el.ownerDocument;
|
|
128
|
+
if (ownerDoc?.activeElement instanceof HTMLElement && ownerDoc.activeElement !== el) {
|
|
129
|
+
ownerDoc.activeElement.blur();
|
|
130
|
+
}
|
|
131
|
+
el.focus();
|
|
132
|
+
el.setPointerCapture(e.pointerId);
|
|
133
|
+
this.setStatus({ isDragging: true });
|
|
134
|
+
this.options.onGestureStart?.();
|
|
135
|
+
const currentState = this.options.getState();
|
|
136
|
+
this.drag = {
|
|
137
|
+
startX: e.clientX,
|
|
138
|
+
startY: e.clientY,
|
|
139
|
+
startPanX: currentState.pan.x,
|
|
140
|
+
startPanY: currentState.pan.y
|
|
141
|
+
};
|
|
142
|
+
const onPointerMove = (moveEvent) => {
|
|
143
|
+
const drag = this.drag;
|
|
144
|
+
if (!drag) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const pe = moveEvent;
|
|
148
|
+
cancelAnimationFrame(this.rafId);
|
|
149
|
+
this.rafId = requestAnimationFrame(() => {
|
|
150
|
+
const s = this.options.getState();
|
|
151
|
+
const imgSize = this.options.getImageSize();
|
|
152
|
+
const containerSize = this.options.getContainerSize();
|
|
153
|
+
const panSize = imgSize ?? containerSize;
|
|
154
|
+
const deltaX = panSize.width > 0 ? (pe.clientX - drag.startX) / panSize.width : 0;
|
|
155
|
+
const deltaY = panSize.height > 0 ? (pe.clientY - drag.startY) / panSize.height : 0;
|
|
156
|
+
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
157
|
+
{
|
|
158
|
+
...s,
|
|
159
|
+
pan: {
|
|
160
|
+
x: drag.startPanX + deltaX,
|
|
161
|
+
y: drag.startPanY + deltaY
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
getImageSizeFromState(s),
|
|
165
|
+
s.cropRect
|
|
166
|
+
);
|
|
167
|
+
this.options.actions.setPan(newCrop);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
const removeListeners = () => {
|
|
171
|
+
el.removeEventListener("pointermove", onPointerMove);
|
|
172
|
+
el.removeEventListener("pointerup", onPointerUp);
|
|
173
|
+
el.removeEventListener("lostpointercapture", onPointerUp);
|
|
174
|
+
};
|
|
175
|
+
const onPointerUp = () => {
|
|
176
|
+
this.setStatus({ isDragging: false });
|
|
177
|
+
this.options.onGestureEnd?.();
|
|
178
|
+
this.drag = null;
|
|
179
|
+
cancelAnimationFrame(this.rafId);
|
|
180
|
+
removeListeners();
|
|
181
|
+
this.pointerCleanup = null;
|
|
182
|
+
};
|
|
183
|
+
el.addEventListener("pointermove", onPointerMove);
|
|
184
|
+
el.addEventListener("pointerup", onPointerUp);
|
|
185
|
+
el.addEventListener("lostpointercapture", onPointerUp);
|
|
186
|
+
this.pointerCleanup = removeListeners;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Handle a wheel event on the container element.
|
|
190
|
+
*
|
|
191
|
+
* Implements focal-point zoom: the point under the cursor stays
|
|
192
|
+
* stationary on screen while the zoom level changes.
|
|
193
|
+
*
|
|
194
|
+
* Must be registered with `{ passive: false }` to allow preventDefault.
|
|
195
|
+
*
|
|
196
|
+
* @param e The native WheelEvent.
|
|
197
|
+
*/
|
|
198
|
+
handleWheel(e) {
|
|
199
|
+
e.preventDefault();
|
|
200
|
+
if (!this.wheelGestureActive) {
|
|
201
|
+
this.wheelGestureActive = true;
|
|
202
|
+
this.options.onGestureStart?.();
|
|
203
|
+
}
|
|
204
|
+
clearTimeout(this.wheelGestureTimer);
|
|
205
|
+
this.wheelGestureTimer = setTimeout(() => {
|
|
206
|
+
this.wheelGestureActive = false;
|
|
207
|
+
this.options.onGestureEnd?.();
|
|
208
|
+
}, DOUBLE_TAP_TIME);
|
|
209
|
+
const s = this.options.getState();
|
|
210
|
+
const delta = -e.deltaY * this.zoomSpeed;
|
|
211
|
+
const newZoom = Math.min(
|
|
212
|
+
this.maxZoom,
|
|
213
|
+
Math.max(this.minZoom, s.zoom + delta)
|
|
214
|
+
);
|
|
215
|
+
if (newZoom === s.zoom) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const containerSize = this.options.getContainerSize();
|
|
219
|
+
const imgSize = this.options.getImageSize();
|
|
220
|
+
const visSize = imgSize ?? containerSize;
|
|
221
|
+
const target = e.currentTarget;
|
|
222
|
+
const rect = target instanceof Element ? target.getBoundingClientRect() : void 0;
|
|
223
|
+
if (visSize.width > 0 && visSize.height > 0 && rect) {
|
|
224
|
+
const fx = e.clientX - rect.left - containerSize.width / 2;
|
|
225
|
+
const fy = e.clientY - rect.top - containerSize.height / 2;
|
|
226
|
+
const zoomRatio = 1 - newZoom / s.zoom;
|
|
227
|
+
const focalNormX = fx / visSize.width;
|
|
228
|
+
const focalNormY = fy / visSize.height;
|
|
229
|
+
const newCropX = s.pan.x + (focalNormX - s.pan.x) * zoomRatio;
|
|
230
|
+
const newCropY = s.pan.y + (focalNormY - s.pan.y) * zoomRatio;
|
|
231
|
+
const { pan: clampedCrop } = (0, import_containment.restrictPanZoom)(
|
|
232
|
+
{ ...s, zoom: newZoom, pan: { x: newCropX, y: newCropY } },
|
|
233
|
+
getImageSizeFromState(s),
|
|
234
|
+
s.cropRect
|
|
235
|
+
);
|
|
236
|
+
this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
|
|
237
|
+
} else {
|
|
238
|
+
this.options.actions.setZoom(newZoom);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Handle a touch-start event on the container element.
|
|
243
|
+
*
|
|
244
|
+
* Supports single-finger pan, two-finger pinch zoom, and
|
|
245
|
+
* double-tap to toggle between fit and 2x zoom. Registers
|
|
246
|
+
* touchmove/touchend/touchcancel on the provided document for the
|
|
247
|
+
* duration of the gesture.
|
|
248
|
+
*
|
|
249
|
+
* @param e The native TouchEvent.
|
|
250
|
+
* @param containerRect The bounding rect of the container element.
|
|
251
|
+
* @param doc The document to register move/end listeners on.
|
|
252
|
+
* Defaults to globalThis.document. Pass the iframe's
|
|
253
|
+
* contentDocument when running inside an iframe.
|
|
254
|
+
*/
|
|
255
|
+
handleTouchStart(e, containerRect, doc = document) {
|
|
256
|
+
if (this.touch && e.touches.length === 2) {
|
|
257
|
+
const s = this.options.getState();
|
|
258
|
+
const distance = getTouchDistance(e.touches[0], e.touches[1]);
|
|
259
|
+
const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
|
|
260
|
+
const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
|
|
261
|
+
this.touch.didPinch = true;
|
|
262
|
+
this.touch.startDistance = distance;
|
|
263
|
+
this.touch.startZoom = s.zoom;
|
|
264
|
+
this.touch.startPanX = s.pan.x;
|
|
265
|
+
this.touch.startPanY = s.pan.y;
|
|
266
|
+
this.touch.startMidX = midX;
|
|
267
|
+
this.touch.startMidY = midY;
|
|
268
|
+
this.touch.containerRect = containerRect;
|
|
269
|
+
this.setStatus({ isDragging: false });
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (e.touches.length === 1) {
|
|
273
|
+
const tapX = e.touches[0].clientX;
|
|
274
|
+
const tapY = e.touches[0].clientY;
|
|
275
|
+
if (this.tryDoubleTap(e, tapX, tapY, containerRect)) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const currentState = this.options.getState();
|
|
279
|
+
this.touch = {
|
|
280
|
+
startDistance: 0,
|
|
281
|
+
startZoom: currentState.zoom,
|
|
282
|
+
lastTouchX: e.touches[0].clientX,
|
|
283
|
+
lastTouchY: e.touches[0].clientY,
|
|
284
|
+
startPanX: currentState.pan.x,
|
|
285
|
+
startPanY: currentState.pan.y,
|
|
286
|
+
containerRect,
|
|
287
|
+
startMidX: 0,
|
|
288
|
+
startMidY: 0,
|
|
289
|
+
didPinch: false,
|
|
290
|
+
moved: false
|
|
291
|
+
};
|
|
292
|
+
this.options.onGestureStart?.();
|
|
293
|
+
} else if (e.touches.length === 2) {
|
|
294
|
+
const currentState = this.options.getState();
|
|
295
|
+
const distance = getTouchDistance(e.touches[0], e.touches[1]);
|
|
296
|
+
const midX = (e.touches[0].clientX + e.touches[1].clientX) / 2;
|
|
297
|
+
const midY = (e.touches[0].clientY + e.touches[1].clientY) / 2;
|
|
298
|
+
this.touch = {
|
|
299
|
+
startDistance: distance,
|
|
300
|
+
startZoom: currentState.zoom,
|
|
301
|
+
lastTouchX: 0,
|
|
302
|
+
lastTouchY: 0,
|
|
303
|
+
startPanX: currentState.pan.x,
|
|
304
|
+
startPanY: currentState.pan.y,
|
|
305
|
+
containerRect,
|
|
306
|
+
startMidX: midX,
|
|
307
|
+
startMidY: midY,
|
|
308
|
+
didPinch: true,
|
|
309
|
+
moved: false
|
|
310
|
+
};
|
|
311
|
+
this.options.onGestureStart?.();
|
|
312
|
+
}
|
|
313
|
+
const onTouchEnd = () => {
|
|
314
|
+
this.touch = null;
|
|
315
|
+
this.touchCleanup = null;
|
|
316
|
+
cancelAnimationFrame(this.rafId);
|
|
317
|
+
doc.removeEventListener("touchmove", this.handleTouchMove);
|
|
318
|
+
doc.removeEventListener("touchend", onTouchEnd);
|
|
319
|
+
doc.removeEventListener("touchcancel", onTouchEnd);
|
|
320
|
+
this.setStatus({ isDragging: false });
|
|
321
|
+
this.options.onGestureEnd?.();
|
|
322
|
+
};
|
|
323
|
+
this.touchCleanup?.();
|
|
324
|
+
doc.addEventListener("touchmove", this.handleTouchMove, {
|
|
325
|
+
passive: false
|
|
326
|
+
});
|
|
327
|
+
doc.addEventListener("touchend", onTouchEnd);
|
|
328
|
+
doc.addEventListener("touchcancel", onTouchEnd);
|
|
329
|
+
this.touchCleanup = onTouchEnd;
|
|
330
|
+
}
|
|
331
|
+
// Handle a touchmove event during an active touch gesture. Decides pinch
|
|
332
|
+
// vs. pan based on current `moveEvent.touches.length`, so the gesture
|
|
333
|
+
// can transition between modes without timing sensitivity (e.g. fingers
|
|
334
|
+
// landing 0ms vs 200ms apart). Arrow-property binding so `this` stays
|
|
335
|
+
// attached when used as an event listener.
|
|
336
|
+
handleTouchMove = (moveEvent) => {
|
|
337
|
+
const touch = this.touch;
|
|
338
|
+
if (!touch) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
cancelAnimationFrame(this.rafId);
|
|
342
|
+
this.rafId = requestAnimationFrame(() => {
|
|
343
|
+
const s = this.options.getState();
|
|
344
|
+
if (moveEvent.touches.length === 2) {
|
|
345
|
+
if (!touch.didPinch) {
|
|
346
|
+
touch.didPinch = true;
|
|
347
|
+
touch.startDistance = getTouchDistance(
|
|
348
|
+
moveEvent.touches[0],
|
|
349
|
+
moveEvent.touches[1]
|
|
350
|
+
);
|
|
351
|
+
touch.startZoom = s.zoom;
|
|
352
|
+
touch.startPanX = s.pan.x;
|
|
353
|
+
touch.startPanY = s.pan.y;
|
|
354
|
+
touch.startMidX = (moveEvent.touches[0].clientX + moveEvent.touches[1].clientX) / 2;
|
|
355
|
+
touch.startMidY = (moveEvent.touches[0].clientY + moveEvent.touches[1].clientY) / 2;
|
|
356
|
+
this.setStatus({ isDragging: false });
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
const latestContainerSize = this.options.getContainerSize();
|
|
360
|
+
const latestImageSize = this.options.getImageSize();
|
|
361
|
+
const t0 = moveEvent.touches[0];
|
|
362
|
+
const t1 = moveEvent.touches[1];
|
|
363
|
+
const currentDistance = getTouchDistance(t0, t1);
|
|
364
|
+
const ratio = currentDistance / touch.startDistance;
|
|
365
|
+
const newZoom = Math.min(
|
|
366
|
+
this.maxZoom,
|
|
367
|
+
Math.max(this.minZoom, touch.startZoom * ratio)
|
|
368
|
+
);
|
|
369
|
+
const visSize = latestImageSize ?? latestContainerSize;
|
|
370
|
+
const rect = touch.containerRect;
|
|
371
|
+
if (visSize.width > 0 && visSize.height > 0 && rect) {
|
|
372
|
+
const mx = (t0.clientX + t1.clientX) / 2 - rect.left - latestContainerSize.width / 2;
|
|
373
|
+
const my = (t0.clientY + t1.clientY) / 2 - rect.top - latestContainerSize.height / 2;
|
|
374
|
+
const startMx = touch.startMidX - rect.left - latestContainerSize.width / 2;
|
|
375
|
+
const startMy = touch.startMidY - rect.top - latestContainerSize.height / 2;
|
|
376
|
+
const panDx = visSize.width > 0 ? (mx - startMx) / visSize.width : 0;
|
|
377
|
+
const panDy = visSize.height > 0 ? (my - startMy) / visSize.height : 0;
|
|
378
|
+
const zoomRatio = s.zoom !== 0 ? 1 - newZoom / s.zoom : 0;
|
|
379
|
+
const focalNormX = mx / visSize.width;
|
|
380
|
+
const focalNormY = my / visSize.height;
|
|
381
|
+
const zoomCropX = s.pan.x + (focalNormX - s.pan.x) * zoomRatio;
|
|
382
|
+
const zoomCropY = s.pan.y + (focalNormY - s.pan.y) * zoomRatio;
|
|
383
|
+
const newCropX = touch.startPanX + panDx + (zoomCropX - s.pan.x);
|
|
384
|
+
const newCropY = touch.startPanY + panDy + (zoomCropY - s.pan.y);
|
|
385
|
+
const { pan: clampedCrop } = (0, import_containment.restrictPanZoom)(
|
|
386
|
+
{
|
|
387
|
+
...s,
|
|
388
|
+
zoom: newZoom,
|
|
389
|
+
pan: { x: newCropX, y: newCropY }
|
|
390
|
+
},
|
|
391
|
+
getImageSizeFromState(s),
|
|
392
|
+
s.cropRect
|
|
393
|
+
);
|
|
394
|
+
this.options.actions.setZoomAtPoint(newZoom, clampedCrop);
|
|
395
|
+
} else if (newZoom !== s.zoom) {
|
|
396
|
+
this.options.actions.setZoom(newZoom);
|
|
397
|
+
}
|
|
398
|
+
} else if (moveEvent.touches.length === 1 && !touch.didPinch) {
|
|
399
|
+
if (!touch.moved) {
|
|
400
|
+
touch.moved = true;
|
|
401
|
+
this.setStatus({ isDragging: true });
|
|
402
|
+
}
|
|
403
|
+
const panImageSize = this.options.getImageSize();
|
|
404
|
+
const panContainerSize = this.options.getContainerSize();
|
|
405
|
+
const panSize = panImageSize ?? panContainerSize;
|
|
406
|
+
const deltaX = panSize.width > 0 ? (moveEvent.touches[0].clientX - touch.lastTouchX) / panSize.width : 0;
|
|
407
|
+
const deltaY = panSize.height > 0 ? (moveEvent.touches[0].clientY - touch.lastTouchY) / panSize.height : 0;
|
|
408
|
+
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
409
|
+
{
|
|
410
|
+
...s,
|
|
411
|
+
pan: {
|
|
412
|
+
x: touch.startPanX + deltaX,
|
|
413
|
+
y: touch.startPanY + deltaY
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
getImageSizeFromState(s),
|
|
417
|
+
s.cropRect
|
|
418
|
+
);
|
|
419
|
+
this.options.actions.setPan(newCrop);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
// Handle double-tap-to-toggle-zoom. On a second tap within the configured
|
|
424
|
+
// time/distance threshold, toggles zoom between `minZoom` and
|
|
425
|
+
// `doubleTapZoom` around the tap point and dispatches. Returns `true` if
|
|
426
|
+
// the tap was handled as a double-tap (caller should early-return),
|
|
427
|
+
// `false` otherwise (caller proceeds with normal single-tap handling).
|
|
428
|
+
// Either way, records the tap for next time.
|
|
429
|
+
tryDoubleTap(e, tapX, tapY, containerRect) {
|
|
430
|
+
const now = Date.now();
|
|
431
|
+
const lastTap = this.lastTap;
|
|
432
|
+
if (!lastTap) {
|
|
433
|
+
this.lastTap = { time: now, x: tapX, y: tapY };
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
const timeDelta = now - lastTap.time;
|
|
437
|
+
const distDelta = Math.sqrt(
|
|
438
|
+
(tapX - lastTap.x) ** 2 + (tapY - lastTap.y) ** 2
|
|
439
|
+
);
|
|
440
|
+
const isDoubleTap = timeDelta < DOUBLE_TAP_TIME && distDelta < DOUBLE_TAP_DISTANCE;
|
|
441
|
+
if (!isDoubleTap) {
|
|
442
|
+
this.lastTap = { time: now, x: tapX, y: tapY };
|
|
443
|
+
return false;
|
|
444
|
+
}
|
|
445
|
+
e.preventDefault();
|
|
446
|
+
this.lastTap = null;
|
|
447
|
+
const currentState = this.options.getState();
|
|
448
|
+
const containerSize = this.options.getContainerSize();
|
|
449
|
+
const imgSize = this.options.getImageSize();
|
|
450
|
+
const targetZoom = currentState.zoom > (this.minZoom + this.doubleTapZoom) / 2 ? this.minZoom : this.doubleTapZoom;
|
|
451
|
+
const visSize = imgSize ?? containerSize;
|
|
452
|
+
this.setStatus({ isZooming: true });
|
|
453
|
+
clearTimeout(this.zoomTimer);
|
|
454
|
+
this.zoomTimer = setTimeout(() => {
|
|
455
|
+
this.setStatus({ isZooming: false });
|
|
456
|
+
}, ZOOM_ANIMATION_DURATION);
|
|
457
|
+
if (visSize.width > 0 && visSize.height > 0) {
|
|
458
|
+
const fx = tapX - containerRect.left - containerSize.width / 2;
|
|
459
|
+
const fy = tapY - containerRect.top - containerSize.height / 2;
|
|
460
|
+
const zoomRatio = 1 - targetZoom / currentState.zoom;
|
|
461
|
+
const focalNormX = fx / visSize.width;
|
|
462
|
+
const focalNormY = fy / visSize.height;
|
|
463
|
+
const newCropX = currentState.pan.x + (focalNormX - currentState.pan.x) * zoomRatio;
|
|
464
|
+
const newCropY = currentState.pan.y + (focalNormY - currentState.pan.y) * zoomRatio;
|
|
465
|
+
const { pan: clampedCrop } = (0, import_containment.restrictPanZoom)(
|
|
466
|
+
{
|
|
467
|
+
...currentState,
|
|
468
|
+
zoom: targetZoom,
|
|
469
|
+
pan: { x: newCropX, y: newCropY }
|
|
470
|
+
},
|
|
471
|
+
getImageSizeFromState(currentState),
|
|
472
|
+
currentState.cropRect
|
|
473
|
+
);
|
|
474
|
+
this.options.actions.setZoomAtPoint(targetZoom, clampedCrop);
|
|
475
|
+
} else {
|
|
476
|
+
this.options.actions.setZoom(targetZoom);
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Handle a keydown event on the container element.
|
|
482
|
+
*
|
|
483
|
+
* Supports arrow keys for panning, +/- for zoom, and r/R for rotation.
|
|
484
|
+
*
|
|
485
|
+
* @param e The native KeyboardEvent.
|
|
486
|
+
*/
|
|
487
|
+
handleKeyDown(e) {
|
|
488
|
+
const currentState = this.options.getState();
|
|
489
|
+
switch (e.key) {
|
|
490
|
+
case "ArrowUp": {
|
|
491
|
+
e.preventDefault();
|
|
492
|
+
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
493
|
+
{
|
|
494
|
+
...currentState,
|
|
495
|
+
pan: {
|
|
496
|
+
x: currentState.pan.x,
|
|
497
|
+
y: currentState.pan.y + this.keyboardStep
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
getImageSizeFromState(currentState),
|
|
501
|
+
currentState.cropRect
|
|
502
|
+
);
|
|
503
|
+
this.options.actions.setPan(newCrop);
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
case "ArrowDown": {
|
|
507
|
+
e.preventDefault();
|
|
508
|
+
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
509
|
+
{
|
|
510
|
+
...currentState,
|
|
511
|
+
pan: {
|
|
512
|
+
x: currentState.pan.x,
|
|
513
|
+
y: currentState.pan.y - this.keyboardStep
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
getImageSizeFromState(currentState),
|
|
517
|
+
currentState.cropRect
|
|
518
|
+
);
|
|
519
|
+
this.options.actions.setPan(newCrop);
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
case "ArrowLeft": {
|
|
523
|
+
e.preventDefault();
|
|
524
|
+
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
525
|
+
{
|
|
526
|
+
...currentState,
|
|
527
|
+
pan: {
|
|
528
|
+
x: currentState.pan.x + this.keyboardStep,
|
|
529
|
+
y: currentState.pan.y
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
getImageSizeFromState(currentState),
|
|
533
|
+
currentState.cropRect
|
|
534
|
+
);
|
|
535
|
+
this.options.actions.setPan(newCrop);
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
case "ArrowRight": {
|
|
539
|
+
e.preventDefault();
|
|
540
|
+
const { pan: newCrop } = (0, import_containment.restrictPanZoom)(
|
|
541
|
+
{
|
|
542
|
+
...currentState,
|
|
543
|
+
pan: {
|
|
544
|
+
x: currentState.pan.x - this.keyboardStep,
|
|
545
|
+
y: currentState.pan.y
|
|
546
|
+
}
|
|
547
|
+
},
|
|
548
|
+
getImageSizeFromState(currentState),
|
|
549
|
+
currentState.cropRect
|
|
550
|
+
);
|
|
551
|
+
this.options.actions.setPan(newCrop);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
case "+":
|
|
555
|
+
case "=": {
|
|
556
|
+
e.preventDefault();
|
|
557
|
+
const newZoom = Math.min(
|
|
558
|
+
this.maxZoom,
|
|
559
|
+
Math.max(this.minZoom, currentState.zoom + 0.5)
|
|
560
|
+
);
|
|
561
|
+
this.options.actions.setZoom(newZoom);
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case "-":
|
|
565
|
+
case "_": {
|
|
566
|
+
e.preventDefault();
|
|
567
|
+
const newZoom = Math.min(
|
|
568
|
+
this.maxZoom,
|
|
569
|
+
Math.max(this.minZoom, currentState.zoom - 0.5)
|
|
570
|
+
);
|
|
571
|
+
this.options.actions.setZoom(newZoom);
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
case "r":
|
|
575
|
+
case "R": {
|
|
576
|
+
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) {
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
e.preventDefault();
|
|
580
|
+
this.options.actions.snapRotate90(1);
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Clean up all timers, animation frames, and active touch listeners.
|
|
587
|
+
*
|
|
588
|
+
* Must be called when the controller is no longer needed (e.g., on
|
|
589
|
+
* component unmount or element removal).
|
|
590
|
+
*/
|
|
591
|
+
destroy() {
|
|
592
|
+
cancelAnimationFrame(this.rafId);
|
|
593
|
+
clearTimeout(this.zoomTimer);
|
|
594
|
+
clearTimeout(this.wheelGestureTimer);
|
|
595
|
+
this.touchCleanup?.();
|
|
596
|
+
this.touchCleanup = null;
|
|
597
|
+
this.pointerCleanup?.();
|
|
598
|
+
this.pointerCleanup = null;
|
|
599
|
+
this.drag = null;
|
|
600
|
+
this.touch = null;
|
|
601
|
+
this.lastTap = null;
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
605
|
+
0 && (module.exports = {
|
|
606
|
+
InteractionController
|
|
607
|
+
});
|
|
608
|
+
//# sourceMappingURL=interaction-controller.cjs.map
|