@aglyn/shared-ui-jsx 1.0.0-beta.143
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/LICENSE +201 -0
- package/README.md +7 -0
- package/package.json +63 -0
- package/src/index.d.ts +48 -0
- package/src/index.js +179 -0
- package/src/index.js.map +1 -0
- package/src/lib/components/aglyn-text.d.ts +86 -0
- package/src/lib/components/aglyn-text.js +44 -0
- package/src/lib/components/aglyn-text.js.map +1 -0
- package/src/lib/components/app-link.d.ts +74 -0
- package/src/lib/components/app-link.js +139 -0
- package/src/lib/components/app-link.js.map +1 -0
- package/src/lib/components/aspect-ratio.d.ts +59 -0
- package/src/lib/components/aspect-ratio.js +153 -0
- package/src/lib/components/aspect-ratio.js.map +1 -0
- package/src/lib/components/background-image.component.d.ts +30 -0
- package/src/lib/components/background-image.component.js +42 -0
- package/src/lib/components/background-image.component.js.map +1 -0
- package/src/lib/components/card-columns.d.ts +86 -0
- package/src/lib/components/card-columns.js +148 -0
- package/src/lib/components/card-columns.js.map +1 -0
- package/src/lib/components/card-display.d.ts +36 -0
- package/src/lib/components/card-display.js +158 -0
- package/src/lib/components/card-display.js.map +1 -0
- package/src/lib/components/card-list-item.d.ts +35 -0
- package/src/lib/components/card-list-item.js +137 -0
- package/src/lib/components/card-list-item.js.map +1 -0
- package/src/lib/components/children-function-prop.d.ts +25 -0
- package/src/lib/components/children-function-prop.js +29 -0
- package/src/lib/components/children-function-prop.js.map +1 -0
- package/src/lib/components/confirmation-provider.component.d.ts +19 -0
- package/src/lib/components/confirmation-provider.component.js +83 -0
- package/src/lib/components/confirmation-provider.component.js.map +1 -0
- package/src/lib/components/container.d.ts +25 -0
- package/src/lib/components/container.js +62 -0
- package/src/lib/components/container.js.map +1 -0
- package/src/lib/components/data-table.component.d.ts +54 -0
- package/src/lib/components/data-table.component.js +211 -0
- package/src/lib/components/data-table.component.js.map +1 -0
- package/src/lib/components/dialog-confirm.d.ts +36 -0
- package/src/lib/components/dialog-confirm.js +74 -0
- package/src/lib/components/dialog-confirm.js.map +1 -0
- package/src/lib/components/ellipsis-pulse.component.d.ts +22 -0
- package/src/lib/components/ellipsis-pulse.component.js +51 -0
- package/src/lib/components/ellipsis-pulse.component.js.map +1 -0
- package/src/lib/components/emotion-cache-provider.d.ts +31 -0
- package/src/lib/components/emotion-cache-provider.js +40 -0
- package/src/lib/components/emotion-cache-provider.js.map +1 -0
- package/src/lib/components/empty-state.component.d.ts +63 -0
- package/src/lib/components/empty-state.component.js +214 -0
- package/src/lib/components/empty-state.component.js.map +1 -0
- package/src/lib/components/error-boundary.component.d.ts +28 -0
- package/src/lib/components/error-boundary.component.js +86 -0
- package/src/lib/components/error-boundary.component.js.map +1 -0
- package/src/lib/components/grid-buttons.d.ts +26 -0
- package/src/lib/components/grid-buttons.js +45 -0
- package/src/lib/components/grid-buttons.js.map +1 -0
- package/src/lib/components/grid-items.d.ts +103 -0
- package/src/lib/components/grid-items.js +336 -0
- package/src/lib/components/grid-items.js.map +1 -0
- package/src/lib/components/grid-list.d.ts +37 -0
- package/src/lib/components/grid-list.js +156 -0
- package/src/lib/components/grid-list.js.map +1 -0
- package/src/lib/components/help-tip.component.d.ts +30 -0
- package/src/lib/components/help-tip.component.js +139 -0
- package/src/lib/components/help-tip.component.js.map +1 -0
- package/src/lib/components/link-navigation-reporter.d.ts +24 -0
- package/src/lib/components/link-navigation-reporter.js +64 -0
- package/src/lib/components/link-navigation-reporter.js.map +1 -0
- package/src/lib/components/list-pagination.component.d.ts +57 -0
- package/src/lib/components/list-pagination.component.js +90 -0
- package/src/lib/components/list-pagination.component.js.map +1 -0
- package/src/lib/components/list-table.component.d.ts +155 -0
- package/src/lib/components/list-table.component.js +369 -0
- package/src/lib/components/list-table.component.js.map +1 -0
- package/src/lib/components/loading-layout-app.component.d.ts +35 -0
- package/src/lib/components/loading-layout-app.component.js +42 -0
- package/src/lib/components/loading-layout-app.component.js.map +1 -0
- package/src/lib/components/loading-modal-overlay.d.ts +30 -0
- package/src/lib/components/loading-modal-overlay.js +156 -0
- package/src/lib/components/loading-modal-overlay.js.map +1 -0
- package/src/lib/components/loading-modal.d.ts +19 -0
- package/src/lib/components/loading-modal.js +113 -0
- package/src/lib/components/loading-modal.js.map +1 -0
- package/src/lib/components/loading-text.component.d.ts +21 -0
- package/src/lib/components/loading-text.component.js +40 -0
- package/src/lib/components/loading-text.component.js.map +1 -0
- package/src/lib/components/mdi-icon/index.d.ts +2 -0
- package/src/lib/components/mdi-icon/index.js +4 -0
- package/src/lib/components/mdi-icon/index.js.map +1 -0
- package/src/lib/components/mdi-icon/md-icon-stack.d.ts +31 -0
- package/src/lib/components/mdi-icon/md-icon-stack.js +101 -0
- package/src/lib/components/mdi-icon/md-icon-stack.js.map +1 -0
- package/src/lib/components/mdi-icon/md-icon.d.ts +32 -0
- package/src/lib/components/mdi-icon/md-icon.js +147 -0
- package/src/lib/components/mdi-icon/md-icon.js.map +1 -0
- package/src/lib/components/mdi-icon/mdi-icon-from-id.d.ts +23 -0
- package/src/lib/components/mdi-icon/mdi-icon-from-id.js +35 -0
- package/src/lib/components/mdi-icon/mdi-icon-from-id.js.map +1 -0
- package/src/lib/components/mdi-icon/mdi-icon.d.ts +24 -0
- package/src/lib/components/mdi-icon/mdi-icon.js +46 -0
- package/src/lib/components/mdi-icon/mdi-icon.js.map +1 -0
- package/src/lib/components/measured-figures.component.d.ts +64 -0
- package/src/lib/components/measured-figures.component.js +161 -0
- package/src/lib/components/measured-figures.component.js.map +1 -0
- package/src/lib/components/menu.d.ts +45 -0
- package/src/lib/components/menu.js +229 -0
- package/src/lib/components/menu.js.map +1 -0
- package/src/lib/components/mui-shadow-dom.d.ts +38 -0
- package/src/lib/components/mui-shadow-dom.js +161 -0
- package/src/lib/components/mui-shadow-dom.js.map +1 -0
- package/src/lib/components/navigation-drawer.component.d.ts +31 -0
- package/src/lib/components/navigation-drawer.component.js +76 -0
- package/src/lib/components/navigation-drawer.component.js.map +1 -0
- package/src/lib/components/navigation-intent.d.ts +18 -0
- package/src/lib/components/navigation-intent.js +56 -0
- package/src/lib/components/navigation-intent.js.map +1 -0
- package/src/lib/components/navigation-view/index.d.ts +18 -0
- package/src/lib/components/navigation-view/index.js +19 -0
- package/src/lib/components/navigation-view/index.js.map +1 -0
- package/src/lib/components/navigation-view/navigation-view.d.ts +35 -0
- package/src/lib/components/navigation-view/navigation-view.js +175 -0
- package/src/lib/components/navigation-view/navigation-view.js.map +1 -0
- package/src/lib/components/next-link.d.ts +27 -0
- package/src/lib/components/next-link.js +88 -0
- package/src/lib/components/next-link.js.map +1 -0
- package/src/lib/components/popper-styled.component.d.ts +25 -0
- package/src/lib/components/popper-styled.component.js +129 -0
- package/src/lib/components/popper-styled.component.js.map +1 -0
- package/src/lib/components/quota-readout.component.d.ts +69 -0
- package/src/lib/components/quota-readout.component.js +52 -0
- package/src/lib/components/quota-readout.component.js.map +1 -0
- package/src/lib/components/resizeable-stack.d.ts +4 -0
- package/src/lib/components/resizeable-stack.js +23 -0
- package/src/lib/components/resizeable-stack.js.map +1 -0
- package/src/lib/components/row-actions-menu.component.d.ts +53 -0
- package/src/lib/components/row-actions-menu.component.js +132 -0
- package/src/lib/components/row-actions-menu.component.js.map +1 -0
- package/src/lib/components/ruler-guides.component.d.ts +35 -0
- package/src/lib/components/ruler-guides.component.js +166 -0
- package/src/lib/components/ruler-guides.component.js.map +1 -0
- package/src/lib/components/sandbox-frame.d.ts +42 -0
- package/src/lib/components/sandbox-frame.js +122 -0
- package/src/lib/components/sandbox-frame.js.map +1 -0
- package/src/lib/components/scroll-reaction.d.ts +59 -0
- package/src/lib/components/scroll-reaction.js +43 -0
- package/src/lib/components/scroll-reaction.js.map +1 -0
- package/src/lib/components/scroll-table.component.d.ts +124 -0
- package/src/lib/components/scroll-table.component.js +103 -0
- package/src/lib/components/scroll-table.component.js.map +1 -0
- package/src/lib/components/shadow-dom/index.d.ts +18 -0
- package/src/lib/components/shadow-dom/index.js +19 -0
- package/src/lib/components/shadow-dom/index.js.map +1 -0
- package/src/lib/components/shadow-dom/shadow-dom.d.ts +42 -0
- package/src/lib/components/shadow-dom/shadow-dom.js +123 -0
- package/src/lib/components/shadow-dom/shadow-dom.js.map +1 -0
- package/src/lib/components/splash-screen.d.ts +33 -0
- package/src/lib/components/splash-screen.js +105 -0
- package/src/lib/components/splash-screen.js.map +1 -0
- package/src/lib/components/sr-only.d.ts +20 -0
- package/src/lib/components/sr-only.js +25 -0
- package/src/lib/components/sr-only.js.map +1 -0
- package/src/lib/components/status-screen-plain.component.d.ts +27 -0
- package/src/lib/components/status-screen-plain.component.js +178 -0
- package/src/lib/components/status-screen-plain.component.js.map +1 -0
- package/src/lib/components/usage-meter.component.d.ts +30 -0
- package/src/lib/components/usage-meter.component.js +92 -0
- package/src/lib/components/usage-meter.component.js.map +1 -0
- package/src/lib/components/variable-text-field.component.d.ts +50 -0
- package/src/lib/components/variable-text-field.component.js +188 -0
- package/src/lib/components/variable-text-field.component.js.map +1 -0
- package/src/lib/components/zoomable-panning-component/index.d.ts +1 -0
- package/src/lib/components/zoomable-panning-component/index.js +3 -0
- package/src/lib/components/zoomable-panning-component/index.js.map +1 -0
- package/src/lib/components/zoomable-panning-component/util.d.ts +58 -0
- package/src/lib/components/zoomable-panning-component/util.js +114 -0
- package/src/lib/components/zoomable-panning-component/util.js.map +1 -0
- package/src/lib/components/zoomable-panning-component/zoomable-panning-component.d.ts +132 -0
- package/src/lib/components/zoomable-panning-component/zoomable-panning-component.js +728 -0
- package/src/lib/components/zoomable-panning-component/zoomable-panning-component.js.map +1 -0
- package/src/lib/const/aglyn-besigner-logo-full.d.ts +39 -0
- package/src/lib/const/aglyn-besigner-logo-full.js +146 -0
- package/src/lib/const/aglyn-besigner-logo-full.js.map +1 -0
- package/src/lib/const/aglyn-console-logo-full.d.ts +34 -0
- package/src/lib/const/aglyn-console-logo-full.js +142 -0
- package/src/lib/const/aglyn-console-logo-full.js.map +1 -0
- package/src/lib/const/aglyn-logo-class-keys.d.ts +30 -0
- package/src/lib/const/aglyn-logo-class-keys.js +32 -0
- package/src/lib/const/aglyn-logo-class-keys.js.map +1 -0
- package/src/lib/const/aglyn-logo-full.d.ts +29 -0
- package/src/lib/const/aglyn-logo-full.js +111 -0
- package/src/lib/const/aglyn-logo-full.js.map +1 -0
- package/src/lib/const/list-filter.d.ts +260 -0
- package/src/lib/const/list-filter.js +409 -0
- package/src/lib/const/list-filter.js.map +1 -0
- package/src/lib/const/prebuilt-components.d.ts +17 -0
- package/src/lib/const/prebuilt-components.js +22 -0
- package/src/lib/const/prebuilt-components.js.map +1 -0
- package/src/lib/const/svg-icons.d.ts +75 -0
- package/src/lib/const/svg-icons.js +313 -0
- package/src/lib/const/svg-icons.js.map +1 -0
- package/src/lib/const/table-pagination.d.ts +106 -0
- package/src/lib/const/table-pagination.js +106 -0
- package/src/lib/const/table-pagination.js.map +1 -0
- package/src/lib/contexts/confirmation.context.d.ts +996 -0
- package/src/lib/contexts/confirmation.context.js +49 -0
- package/src/lib/contexts/confirmation.context.js.map +1 -0
- package/src/lib/contexts/loading.context.d.ts +93 -0
- package/src/lib/contexts/loading.context.js +126 -0
- package/src/lib/contexts/loading.context.js.map +1 -0
- package/src/lib/hocs/create-hoc-with-context-consumer.d.ts +36 -0
- package/src/lib/hocs/create-hoc-with-context-consumer.js +44 -0
- package/src/lib/hocs/create-hoc-with-context-consumer.js.map +1 -0
- package/src/lib/hocs/with-hoc.d.ts +32 -0
- package/src/lib/hocs/with-hoc.js +37 -0
- package/src/lib/hocs/with-hoc.js.map +1 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icon.d.ts +20 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icon.js +48 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icon.js.map +1 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons-fuzzy.d.ts +26 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons-fuzzy.js +73 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons-fuzzy.js.map +1 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons.d.ts +19 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons.js +49 -0
- package/src/lib/hooks/mdi-icon/use-mdi-icons.js.map +1 -0
- package/src/lib/hooks/router-events.d.ts +56 -0
- package/src/lib/hooks/router-events.js +88 -0
- package/src/lib/hooks/router-events.js.map +1 -0
- package/src/lib/hooks/use-async-effect.d.ts +24 -0
- package/src/lib/hooks/use-async-effect.js +44 -0
- package/src/lib/hooks/use-async-effect.js.map +1 -0
- package/src/lib/hooks/use-callback-param-ref.d.ts +19 -0
- package/src/lib/hooks/use-callback-param-ref.js +29 -0
- package/src/lib/hooks/use-callback-param-ref.js.map +1 -0
- package/src/lib/hooks/use-id.d.ts +21 -0
- package/src/lib/hooks/use-id.js +28 -0
- package/src/lib/hooks/use-id.js.map +1 -0
- package/src/lib/hooks/use-isomorphic-layout-effect.d.ts +19 -0
- package/src/lib/hooks/use-isomorphic-layout-effect.js +20 -0
- package/src/lib/hooks/use-isomorphic-layout-effect.js.map +1 -0
- package/src/lib/hooks/use-merge-refs.d.ts +38 -0
- package/src/lib/hooks/use-merge-refs.js +52 -0
- package/src/lib/hooks/use-merge-refs.js.map +1 -0
- package/src/lib/hooks/use-subscribable.d.ts +29 -0
- package/src/lib/hooks/use-subscribable.js +50 -0
- package/src/lib/hooks/use-subscribable.js.map +1 -0
- package/src/lib/types.d.ts +18 -0
- package/src/lib/types.js +18 -0
- package/src/lib/types.js.map +1 -0
- package/src/lib/utils/make-link-elements.d.ts +24 -0
- package/src/lib/utils/make-link-elements.js +32 -0
- package/src/lib/utils/make-link-elements.js.map +1 -0
- package/src/lib/utils/make-meta-elements.d.ts +24 -0
- package/src/lib/utils/make-meta-elements.js +32 -0
- package/src/lib/utils/make-meta-elements.js.map +1 -0
- package/src/lib/utils/scroll-overflow.d.ts +120 -0
- package/src/lib/utils/scroll-overflow.js +115 -0
- package/src/lib/utils/scroll-overflow.js.map +1 -0
- package/src/lib/utils/vendor.d.ts +17 -0
- package/src/lib/utils/vendor.js +18 -0
- package/src/lib/utils/vendor.js.map +1 -0
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2021 Aglyn LLC
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/ import { Component, createRef } from "react";
|
|
20
|
+
import warning from "warning";
|
|
21
|
+
import { boundCoordinates, captureTextSelection, getScaleMultiplier, getTransformedBoundingBox, releaseTextSelection, TransformMatrix } from "./util.js";
|
|
22
|
+
const getTransformMatrixString = (transformationMatrix)=>{
|
|
23
|
+
const { a, b, c, d, x, y } = transformationMatrix;
|
|
24
|
+
return `matrix(${a}, ${b}, ${c}, ${d}, ${x}, ${y})`;
|
|
25
|
+
};
|
|
26
|
+
export class ZoomablePanningComponent extends Component {
|
|
27
|
+
componentDidMount() {
|
|
28
|
+
const { autoCenter, autoCenterZoomLevel, minZoom, maxZoom } = this.props;
|
|
29
|
+
if (this.container.current) {
|
|
30
|
+
this.container.current.addEventListener('wheel', this.onWheel, {
|
|
31
|
+
passive: false
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (maxZoom < minZoom) {
|
|
35
|
+
throw new Error('[PanZoom]: maxZoom props cannot be inferior to minZoom');
|
|
36
|
+
}
|
|
37
|
+
if (autoCenter) {
|
|
38
|
+
this.autoCenter(autoCenterZoomLevel, false);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
componentDidUpdate(prevProps, prevState) {
|
|
42
|
+
if (prevProps.autoCenter !== this.props.autoCenter && this.props.autoCenter) {
|
|
43
|
+
this.autoCenter(this.props.autoCenterZoomLevel);
|
|
44
|
+
}
|
|
45
|
+
if ((prevState.x !== this.state.x || prevState.y !== this.state.y || prevState.scale !== this.state.scale || prevState.angle !== this.state.angle) && this.props.onStateChange) {
|
|
46
|
+
this.props.onStateChange({
|
|
47
|
+
x: this.state.x,
|
|
48
|
+
y: this.state.y,
|
|
49
|
+
scale: this.state.scale,
|
|
50
|
+
angle: this.state.angle
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
componentWillUnmount() {
|
|
55
|
+
this.cleanMouseListeners();
|
|
56
|
+
this.cleanTouchListeners();
|
|
57
|
+
releaseTextSelection();
|
|
58
|
+
if (this.container.current) {
|
|
59
|
+
this.container.current.removeEventListener('wheel', this.onWheel, {
|
|
60
|
+
passive: false
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
const _this_props = this.props, { children, autoCenter, autoCenterZoomLevel, zoomSpeed, doubleZoomSpeed, disabled, disableDoubleClickZoom, disableScrollZoom, disableKeyInteraction, realPinch, keyMapping, minZoom, maxZoom, enableBoundingBox, boundaryRatioVertical, boundaryRatioHorizontal, noStateUpdate, onPanStart, onPan, onPanEnd, preventPan, style, onDoubleClick, onMouseDown, onKeyDown, onKeyUp, onTouchStart, onStateChange } = _this_props, restPassThroughProps = _object_without_properties_loose(_this_props, [
|
|
66
|
+
"children",
|
|
67
|
+
"autoCenter",
|
|
68
|
+
"autoCenterZoomLevel",
|
|
69
|
+
"zoomSpeed",
|
|
70
|
+
"doubleZoomSpeed",
|
|
71
|
+
"disabled",
|
|
72
|
+
"disableDoubleClickZoom",
|
|
73
|
+
"disableScrollZoom",
|
|
74
|
+
"disableKeyInteraction",
|
|
75
|
+
"realPinch",
|
|
76
|
+
"keyMapping",
|
|
77
|
+
"minZoom",
|
|
78
|
+
"maxZoom",
|
|
79
|
+
"enableBoundingBox",
|
|
80
|
+
"boundaryRatioVertical",
|
|
81
|
+
"boundaryRatioHorizontal",
|
|
82
|
+
"noStateUpdate",
|
|
83
|
+
"onPanStart",
|
|
84
|
+
"onPan",
|
|
85
|
+
"onPanEnd",
|
|
86
|
+
"preventPan",
|
|
87
|
+
"style",
|
|
88
|
+
"onDoubleClick",
|
|
89
|
+
"onMouseDown",
|
|
90
|
+
"onKeyDown",
|
|
91
|
+
"onKeyUp",
|
|
92
|
+
"onTouchStart",
|
|
93
|
+
"onStateChange"
|
|
94
|
+
]);
|
|
95
|
+
const { x, y, scale, angle } = this.state;
|
|
96
|
+
const transform = getTransformMatrixString(this.getTransformMatrix(x, y, scale, angle));
|
|
97
|
+
if (process.env['NODE_ENV'] !== 'production') {
|
|
98
|
+
warning(onDoubleClick === undefined || typeof onDoubleClick === 'function', 'Expected `onDoubleClick` listener to be a function, instead got a value of `%s` type.', typeof onDoubleClick);
|
|
99
|
+
warning(onMouseDown === undefined || typeof onMouseDown === 'function', 'Expected `onMouseDown` listener to be a function, instead got a value of `%s` type.', typeof onMouseDown);
|
|
100
|
+
warning(onKeyDown === undefined || typeof onKeyDown === 'function', 'Expected `onKeyDown` listener to be a function, instead got a value of `%s` type.', typeof onKeyDown);
|
|
101
|
+
warning(onKeyUp === undefined || typeof onKeyUp === 'function', 'Expected `onKeyUp` listener to be a function, instead got a value of `%s` type.', typeof onKeyUp);
|
|
102
|
+
warning(onTouchStart === undefined || typeof onTouchStart === 'function', 'Expected `onTouchStart` listener to be a function, instead got a value of `%s` type.', typeof onTouchStart);
|
|
103
|
+
}
|
|
104
|
+
return /*#__PURE__*/ _jsx("div", _extends({
|
|
105
|
+
ref: this.container
|
|
106
|
+
}, disableKeyInteraction ? {} : {
|
|
107
|
+
tabIndex: 0
|
|
108
|
+
}, {
|
|
109
|
+
onDoubleClick: this.onDoubleClick,
|
|
110
|
+
onMouseDown: this.onMouseDown,
|
|
111
|
+
// React onWheel event listener is broken on Chrome 73
|
|
112
|
+
// The default options for the wheel event listener has been defaulted to passive
|
|
113
|
+
// but this behaviour breaks the zoom feature of PanZoom.
|
|
114
|
+
// Until further research onWheel listener is replaced by
|
|
115
|
+
// this.container.addEventListener('mousewheel', this.onWheel, { passive: false })
|
|
116
|
+
// see Chrome motivations
|
|
117
|
+
// https://developers.google.com/web/updates/2019/02/scrolling-intervention
|
|
118
|
+
// onWheel={this.onWheel}
|
|
119
|
+
onKeyDown: this.onKeyDown,
|
|
120
|
+
onKeyUp: this.onKeyUp,
|
|
121
|
+
onTouchStart: this.onTouchStart,
|
|
122
|
+
style: _extends({
|
|
123
|
+
cursor: disabled ? 'initial' : 'pointer'
|
|
124
|
+
}, style)
|
|
125
|
+
}, restPassThroughProps, {
|
|
126
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
127
|
+
ref: this.dragContainer,
|
|
128
|
+
style: {
|
|
129
|
+
display: 'inline-block',
|
|
130
|
+
transformOrigin: '0 0 0',
|
|
131
|
+
transform,
|
|
132
|
+
transition: 'all 0.10s linear',
|
|
133
|
+
willChange: 'transform'
|
|
134
|
+
},
|
|
135
|
+
children: children
|
|
136
|
+
})
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
constructor(...args){
|
|
140
|
+
super(...args), this.container = /*#__PURE__*/ createRef(), this.dragContainer = /*#__PURE__*/ createRef(), this.mousePos = {
|
|
141
|
+
x: 0,
|
|
142
|
+
y: 0
|
|
143
|
+
}, this.panning = false, this.touchInProgress = false, this.panStartTriggered = false, this.pinchZoomLength = 0, this.prevPanPosition = {
|
|
144
|
+
x: 0,
|
|
145
|
+
y: 0
|
|
146
|
+
}, this.frameAnimation = 0, this.intermediateFrameAnimation = 0, this.transformMatrixString = `matrix(1, 0, 0, 1, 0, 0)`, this.intermediateTransformMatrixString = `matrix(1, 0, 0, 1, 0, 0)`, this.state = {
|
|
147
|
+
x: 0,
|
|
148
|
+
y: 0,
|
|
149
|
+
scale: 1,
|
|
150
|
+
angle: 0
|
|
151
|
+
}, this.onDoubleClick = (e)=>{
|
|
152
|
+
const { onDoubleClick, disableDoubleClickZoom, doubleZoomSpeed } = this.props;
|
|
153
|
+
if (typeof onDoubleClick === 'function') {
|
|
154
|
+
onDoubleClick(e);
|
|
155
|
+
}
|
|
156
|
+
if (disableDoubleClickZoom) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const offset = this.getOffset(e);
|
|
160
|
+
this.zoomTo(offset.x, offset.y, doubleZoomSpeed);
|
|
161
|
+
}, this.onMouseDown = (e)=>{
|
|
162
|
+
const { preventPan, onMouseDown } = this.props;
|
|
163
|
+
if (typeof onMouseDown === 'function') {
|
|
164
|
+
onMouseDown(e);
|
|
165
|
+
}
|
|
166
|
+
if (this.props.disabled) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// Touch events fire mousedown on modern browsers, but it should not
|
|
170
|
+
// be considered as we will handle touch event separately
|
|
171
|
+
if (this.touchInProgress) {
|
|
172
|
+
e.stopPropagation();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const isLeftButton = e.button === 1 && window.event !== null || e.button === 0;
|
|
176
|
+
if (!isLeftButton) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const offset = this.getOffset(e);
|
|
180
|
+
// check if there is nothing preventing the pan
|
|
181
|
+
if (preventPan && preventPan(e, offset.x, offset.y)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.mousePos = {
|
|
185
|
+
x: offset.x,
|
|
186
|
+
y: offset.y
|
|
187
|
+
};
|
|
188
|
+
// keep the current pan value in memory to allow noStateUpdate panning
|
|
189
|
+
this.prevPanPosition = {
|
|
190
|
+
x: this.state.x,
|
|
191
|
+
y: this.state.y
|
|
192
|
+
};
|
|
193
|
+
this.panning = true;
|
|
194
|
+
this.setMouseListeners();
|
|
195
|
+
// Prevent text selection
|
|
196
|
+
captureTextSelection();
|
|
197
|
+
}, this.onMouseMove = (e)=>{
|
|
198
|
+
if (this.panning) {
|
|
199
|
+
const { noStateUpdate } = this.props;
|
|
200
|
+
// TODO disable if using touch event
|
|
201
|
+
this.triggerOnPanStart(e);
|
|
202
|
+
const offset = this.getOffset(e);
|
|
203
|
+
const dx = offset.x - this.mousePos.x;
|
|
204
|
+
const dy = offset.y - this.mousePos.y;
|
|
205
|
+
this.mousePos = {
|
|
206
|
+
x: offset.x,
|
|
207
|
+
y: offset.y
|
|
208
|
+
};
|
|
209
|
+
this.moveBy(dx, dy, noStateUpdate);
|
|
210
|
+
this.triggerOnPan(e);
|
|
211
|
+
}
|
|
212
|
+
}, this.onMouseUp = (e)=>{
|
|
213
|
+
const { noStateUpdate } = this.props;
|
|
214
|
+
// if using noStateUpdate we still need to set the new values in the state
|
|
215
|
+
if (noStateUpdate) {
|
|
216
|
+
this.setState({
|
|
217
|
+
x: this.prevPanPosition.x,
|
|
218
|
+
y: this.prevPanPosition.y
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
this.triggerOnPanEnd(e);
|
|
222
|
+
this.cleanMouseListeners();
|
|
223
|
+
this.panning = false;
|
|
224
|
+
releaseTextSelection();
|
|
225
|
+
}, this.onWheel = (e)=>{
|
|
226
|
+
const { disableScrollZoom, disabled, zoomSpeed } = this.props;
|
|
227
|
+
if (disableScrollZoom || disabled) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const scale = getScaleMultiplier(e.deltaY, zoomSpeed);
|
|
231
|
+
const offset = this.getOffset(e);
|
|
232
|
+
this.zoomTo(offset.x, offset.y, scale);
|
|
233
|
+
e.preventDefault();
|
|
234
|
+
}, this.onKeyDown = (e)=>{
|
|
235
|
+
const { keyMapping, disableKeyInteraction, onKeyDown } = this.props;
|
|
236
|
+
if (typeof onKeyDown === 'function') {
|
|
237
|
+
onKeyDown(e);
|
|
238
|
+
}
|
|
239
|
+
if (disableKeyInteraction) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const keys = _extends({
|
|
243
|
+
'38': {
|
|
244
|
+
x: 0,
|
|
245
|
+
y: -1,
|
|
246
|
+
z: 0
|
|
247
|
+
},
|
|
248
|
+
'40': {
|
|
249
|
+
x: 0,
|
|
250
|
+
y: 1,
|
|
251
|
+
z: 0
|
|
252
|
+
},
|
|
253
|
+
'37': {
|
|
254
|
+
x: -1,
|
|
255
|
+
y: 0,
|
|
256
|
+
z: 0
|
|
257
|
+
},
|
|
258
|
+
'39': {
|
|
259
|
+
x: 1,
|
|
260
|
+
y: 0,
|
|
261
|
+
z: 0
|
|
262
|
+
},
|
|
263
|
+
'189': {
|
|
264
|
+
x: 0,
|
|
265
|
+
y: 0,
|
|
266
|
+
z: 1
|
|
267
|
+
},
|
|
268
|
+
'109': {
|
|
269
|
+
x: 0,
|
|
270
|
+
y: 0,
|
|
271
|
+
z: 1
|
|
272
|
+
},
|
|
273
|
+
'187': {
|
|
274
|
+
x: 0,
|
|
275
|
+
y: 0,
|
|
276
|
+
z: -1
|
|
277
|
+
},
|
|
278
|
+
'107': {
|
|
279
|
+
x: 0,
|
|
280
|
+
y: 0,
|
|
281
|
+
z: -1
|
|
282
|
+
}
|
|
283
|
+
}, keyMapping);
|
|
284
|
+
const mappedCoords = keys[String(e.keyCode)];
|
|
285
|
+
if (mappedCoords) {
|
|
286
|
+
const { x, y, z } = mappedCoords;
|
|
287
|
+
e.preventDefault();
|
|
288
|
+
e.stopPropagation();
|
|
289
|
+
if ((x || y) && this.container.current) {
|
|
290
|
+
const containerRect = this.container.current.getBoundingClientRect();
|
|
291
|
+
const offset = Math.min(containerRect.width, containerRect.height);
|
|
292
|
+
const moveSpeedRatio = 0.05;
|
|
293
|
+
const dx = offset * moveSpeedRatio * x;
|
|
294
|
+
const dy = offset * moveSpeedRatio * y;
|
|
295
|
+
this.moveBy(dx, dy);
|
|
296
|
+
}
|
|
297
|
+
if (z) {
|
|
298
|
+
this.centeredZoom(z);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}, this.onKeyUp = (e)=>{
|
|
302
|
+
const { disableKeyInteraction, onKeyUp } = this.props;
|
|
303
|
+
if (typeof onKeyUp === 'function') {
|
|
304
|
+
onKeyUp(e);
|
|
305
|
+
}
|
|
306
|
+
if (disableKeyInteraction) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (this.prevPanPosition && (this.prevPanPosition.x !== this.state.x || this.prevPanPosition.y !== this.state.y)) {
|
|
310
|
+
this.setState({
|
|
311
|
+
x: this.prevPanPosition.x,
|
|
312
|
+
y: this.prevPanPosition.y
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}, this.onTouchStart = (e)=>{
|
|
316
|
+
const { preventPan, onTouchStart, disabled } = this.props;
|
|
317
|
+
if (typeof onTouchStart === 'function') {
|
|
318
|
+
onTouchStart(e);
|
|
319
|
+
}
|
|
320
|
+
if (disabled) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (e.touches.length === 1) {
|
|
324
|
+
// Drag
|
|
325
|
+
const touch = e.touches[0];
|
|
326
|
+
const offset = this.getOffset(touch);
|
|
327
|
+
if (preventPan && preventPan(e, offset.x, offset.y)) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this.mousePos = {
|
|
331
|
+
x: offset.x,
|
|
332
|
+
y: offset.y
|
|
333
|
+
};
|
|
334
|
+
// keep the current pan value in memory to allow noStateUpdate panning
|
|
335
|
+
this.prevPanPosition = {
|
|
336
|
+
x: this.state.x,
|
|
337
|
+
y: this.state.y
|
|
338
|
+
};
|
|
339
|
+
this.touchInProgress = true;
|
|
340
|
+
this.setTouchListeners();
|
|
341
|
+
} else if (e.touches.length === 2) {
|
|
342
|
+
// pinch
|
|
343
|
+
this.pinchZoomLength = this.getPinchZoomLength(e.touches[0], e.touches[1]);
|
|
344
|
+
this.touchInProgress = true;
|
|
345
|
+
this.setTouchListeners();
|
|
346
|
+
}
|
|
347
|
+
}, this.onToucheMove = (e)=>{
|
|
348
|
+
const { realPinch, noStateUpdate, zoomSpeed } = this.props;
|
|
349
|
+
if (e.touches.length === 1) {
|
|
350
|
+
e.stopPropagation();
|
|
351
|
+
const touch = e.touches[0];
|
|
352
|
+
const offset = this.getOffset(touch);
|
|
353
|
+
const dx = offset.x - this.mousePos.x;
|
|
354
|
+
const dy = offset.y - this.mousePos.y;
|
|
355
|
+
if (dx !== 0 || dy !== 0) {
|
|
356
|
+
this.triggerOnPanStart(e);
|
|
357
|
+
}
|
|
358
|
+
this.mousePos = {
|
|
359
|
+
x: offset.x,
|
|
360
|
+
y: offset.y
|
|
361
|
+
};
|
|
362
|
+
this.moveBy(dx, dy, noStateUpdate);
|
|
363
|
+
this.triggerOnPan(e);
|
|
364
|
+
} else if (e.touches.length === 2) {
|
|
365
|
+
const finger1 = e.touches[0];
|
|
366
|
+
const finger2 = e.touches[1];
|
|
367
|
+
const currentPinZoomLength = this.getPinchZoomLength(finger1, finger2);
|
|
368
|
+
let scaleMultiplier;
|
|
369
|
+
if (realPinch) {
|
|
370
|
+
scaleMultiplier = currentPinZoomLength / this.pinchZoomLength;
|
|
371
|
+
} else {
|
|
372
|
+
let delta = 0;
|
|
373
|
+
if (currentPinZoomLength < this.pinchZoomLength) {
|
|
374
|
+
delta = 1;
|
|
375
|
+
} else if (currentPinZoomLength > this.pinchZoomLength) {
|
|
376
|
+
delta = -1;
|
|
377
|
+
}
|
|
378
|
+
scaleMultiplier = getScaleMultiplier(delta, zoomSpeed);
|
|
379
|
+
}
|
|
380
|
+
this.mousePos = {
|
|
381
|
+
x: (finger1.clientX + finger2.clientX) / 2,
|
|
382
|
+
y: (finger1.clientY + finger2.clientY) / 2
|
|
383
|
+
};
|
|
384
|
+
this.zoomTo(this.mousePos.x, this.mousePos.y, scaleMultiplier);
|
|
385
|
+
this.pinchZoomLength = currentPinZoomLength;
|
|
386
|
+
e.stopPropagation();
|
|
387
|
+
}
|
|
388
|
+
}, this.onTouchEnd = (e)=>{
|
|
389
|
+
if (e.touches.length > 0) {
|
|
390
|
+
const offset = this.getOffset(e.touches[0]);
|
|
391
|
+
this.mousePos = {
|
|
392
|
+
x: offset.x,
|
|
393
|
+
y: offset.y
|
|
394
|
+
};
|
|
395
|
+
// when removing a finger we don't go through onTouchStart
|
|
396
|
+
// thus we need to set the prevPanPosition here
|
|
397
|
+
this.prevPanPosition = {
|
|
398
|
+
x: this.state.x,
|
|
399
|
+
y: this.state.y
|
|
400
|
+
};
|
|
401
|
+
} else {
|
|
402
|
+
const { noStateUpdate } = this.props;
|
|
403
|
+
if (noStateUpdate) {
|
|
404
|
+
this.setState({
|
|
405
|
+
x: this.prevPanPosition.x,
|
|
406
|
+
y: this.prevPanPosition.y
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
this.touchInProgress = false;
|
|
410
|
+
this.triggerOnPanEnd(e);
|
|
411
|
+
this.cleanTouchListeners();
|
|
412
|
+
}
|
|
413
|
+
}, this.setMouseListeners = ()=>{
|
|
414
|
+
document.addEventListener('mousemove', this.onMouseMove);
|
|
415
|
+
document.addEventListener('mouseup', this.onMouseUp);
|
|
416
|
+
}, this.cleanMouseListeners = ()=>{
|
|
417
|
+
document.removeEventListener('mousemove', this.onMouseMove);
|
|
418
|
+
document.removeEventListener('mouseup', this.onMouseUp);
|
|
419
|
+
if (this.frameAnimation) {
|
|
420
|
+
window.cancelAnimationFrame(this.frameAnimation);
|
|
421
|
+
this.frameAnimation = 0;
|
|
422
|
+
}
|
|
423
|
+
if (this.intermediateFrameAnimation) {
|
|
424
|
+
window.cancelAnimationFrame(this.intermediateFrameAnimation);
|
|
425
|
+
this.intermediateFrameAnimation = 0;
|
|
426
|
+
}
|
|
427
|
+
}, this.setTouchListeners = ()=>{
|
|
428
|
+
document.addEventListener('touchmove', this.onToucheMove);
|
|
429
|
+
document.addEventListener('touchend', this.onTouchEnd);
|
|
430
|
+
document.addEventListener('touchcancel', this.onTouchEnd);
|
|
431
|
+
}, this.cleanTouchListeners = ()=>{
|
|
432
|
+
document.removeEventListener('touchmove', this.onToucheMove);
|
|
433
|
+
document.removeEventListener('touchend', this.onTouchEnd);
|
|
434
|
+
document.removeEventListener('touchcancel', this.onTouchEnd);
|
|
435
|
+
if (this.frameAnimation) {
|
|
436
|
+
window.cancelAnimationFrame(this.frameAnimation);
|
|
437
|
+
this.frameAnimation = 0;
|
|
438
|
+
}
|
|
439
|
+
if (this.intermediateFrameAnimation) {
|
|
440
|
+
window.cancelAnimationFrame(this.intermediateFrameAnimation);
|
|
441
|
+
this.intermediateFrameAnimation = 0;
|
|
442
|
+
}
|
|
443
|
+
}, this.triggerOnPanStart = (e)=>{
|
|
444
|
+
const { onPanStart } = this.props;
|
|
445
|
+
if (!this.panStartTriggered && onPanStart && typeof onPanStart === 'function') {
|
|
446
|
+
onPanStart(e);
|
|
447
|
+
}
|
|
448
|
+
this.panStartTriggered = true;
|
|
449
|
+
}, this.triggerOnPan = (e)=>{
|
|
450
|
+
const { onPan } = this.props;
|
|
451
|
+
if (typeof onPan === 'function') {
|
|
452
|
+
onPan(e);
|
|
453
|
+
}
|
|
454
|
+
}, this.triggerOnPanEnd = (e)=>{
|
|
455
|
+
const { onPanEnd } = this.props;
|
|
456
|
+
this.panStartTriggered = false;
|
|
457
|
+
if (typeof onPanEnd === 'function') {
|
|
458
|
+
onPanEnd(e);
|
|
459
|
+
}
|
|
460
|
+
}, this.getPinchZoomLength = (finger1, finger2)=>{
|
|
461
|
+
return Math.sqrt((finger1.clientX - finger2.clientX) * (finger1.clientX - finger2.clientX) + (finger1.clientY - finger2.clientY) * (finger1.clientY - finger2.clientY));
|
|
462
|
+
}, this.getContainer = ()=>{
|
|
463
|
+
const { current: container } = this.container;
|
|
464
|
+
if (!container) {
|
|
465
|
+
throw new Error('Could not find container DOM element.');
|
|
466
|
+
}
|
|
467
|
+
return container;
|
|
468
|
+
}, this.getDragContainer = ()=>{
|
|
469
|
+
const { current: dragContainer } = this.dragContainer;
|
|
470
|
+
if (!dragContainer) {
|
|
471
|
+
throw new Error('Could not find dragContainer DOM element.');
|
|
472
|
+
}
|
|
473
|
+
return dragContainer;
|
|
474
|
+
}, this.autoCenter = (zoomLevel = 1, animate = true)=>{
|
|
475
|
+
const container = this.getContainer();
|
|
476
|
+
const dragContainer = this.getDragContainer();
|
|
477
|
+
const { minZoom, maxZoom } = this.props;
|
|
478
|
+
const containerRect = container.getBoundingClientRect();
|
|
479
|
+
const { clientWidth, clientHeight } = dragContainer;
|
|
480
|
+
const widthRatio = containerRect.width / clientWidth;
|
|
481
|
+
const heightRatio = containerRect.height / clientHeight;
|
|
482
|
+
let scale = Math.min(widthRatio, heightRatio) * zoomLevel;
|
|
483
|
+
if (scale < minZoom) {
|
|
484
|
+
console.warn(`[PanZoom]: initial zoomLevel produces a scale inferior to minZoom, reverted to default: ${minZoom}. Consider using a zoom level > ${minZoom}`);
|
|
485
|
+
scale = minZoom;
|
|
486
|
+
} else if (scale > maxZoom) {
|
|
487
|
+
console.warn(`[PanZoom]: initial zoomLevel produces a scale superior to maxZoom, reverted to default: ${maxZoom}. Consider using a zoom level < ${maxZoom}`);
|
|
488
|
+
scale = maxZoom;
|
|
489
|
+
}
|
|
490
|
+
const x = (containerRect.width - clientWidth * scale) / 2;
|
|
491
|
+
const y = (containerRect.height - clientHeight * scale) / 2;
|
|
492
|
+
let afterStateUpdate = undefined;
|
|
493
|
+
if (!animate) {
|
|
494
|
+
const transition = dragContainer.style.transition;
|
|
495
|
+
dragContainer.style.transition = 'none';
|
|
496
|
+
afterStateUpdate = ()=>{
|
|
497
|
+
setTimeout(()=>{
|
|
498
|
+
const dragContainer = this.getDragContainer();
|
|
499
|
+
dragContainer.style.transition = transition;
|
|
500
|
+
}, 0);
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
this.prevPanPosition = {
|
|
504
|
+
x,
|
|
505
|
+
y
|
|
506
|
+
};
|
|
507
|
+
this.setState({
|
|
508
|
+
x,
|
|
509
|
+
y,
|
|
510
|
+
scale,
|
|
511
|
+
angle: 0
|
|
512
|
+
}, afterStateUpdate);
|
|
513
|
+
}, this.moveByRatio = (x, y, moveSpeedRatio = 0.05)=>{
|
|
514
|
+
const container = this.getContainer();
|
|
515
|
+
const containerRect = container.getBoundingClientRect();
|
|
516
|
+
const offset = Math.min(containerRect.width, containerRect.height);
|
|
517
|
+
const dx = offset * moveSpeedRatio * x;
|
|
518
|
+
const dy = offset * moveSpeedRatio * y;
|
|
519
|
+
this.moveBy(dx, dy, false);
|
|
520
|
+
}, this.moveBy = (dx, dy, noStateUpdate = true)=>{
|
|
521
|
+
const { x, y, scale, angle } = this.state;
|
|
522
|
+
// Allow better performance by not updating the state on every change
|
|
523
|
+
if (noStateUpdate) {
|
|
524
|
+
const { x: prevTransformX, y: prevTransformY } = this.getTransformMatrix(this.prevPanPosition.x, this.prevPanPosition.y, scale, angle);
|
|
525
|
+
const { a, b, c, d, x: transformX, y: transformY } = this.getTransformMatrix(this.prevPanPosition.x + dx, this.prevPanPosition.y + dy, scale, angle);
|
|
526
|
+
const { boundX, boundY, offsetX, offsetY } = this.getBoundCoordinates({
|
|
527
|
+
x: transformX,
|
|
528
|
+
y: transformY
|
|
529
|
+
}, {
|
|
530
|
+
angle,
|
|
531
|
+
scale,
|
|
532
|
+
offsetX: this.prevPanPosition.x + dx,
|
|
533
|
+
offsetY: this.prevPanPosition.y + dy
|
|
534
|
+
});
|
|
535
|
+
const intermediateX = prevTransformX + (prevTransformX - boundX) / 2;
|
|
536
|
+
const intermediateY = prevTransformY + (prevTransformY - boundY) / 2;
|
|
537
|
+
this.intermediateTransformMatrixString = getTransformMatrixString({
|
|
538
|
+
a,
|
|
539
|
+
b,
|
|
540
|
+
c,
|
|
541
|
+
d,
|
|
542
|
+
x: intermediateX,
|
|
543
|
+
y: intermediateY
|
|
544
|
+
});
|
|
545
|
+
this.transformMatrixString = getTransformMatrixString({
|
|
546
|
+
a,
|
|
547
|
+
b,
|
|
548
|
+
c,
|
|
549
|
+
d,
|
|
550
|
+
x: boundX,
|
|
551
|
+
y: boundY
|
|
552
|
+
});
|
|
553
|
+
// get bound x / y coords without the rotation offset
|
|
554
|
+
this.prevPanPosition = {
|
|
555
|
+
x: offsetX,
|
|
556
|
+
y: offsetY
|
|
557
|
+
};
|
|
558
|
+
// only apply intermediate animation if it is different from the end result
|
|
559
|
+
if (this.intermediateTransformMatrixString !== this.transformMatrixString) {
|
|
560
|
+
this.intermediateFrameAnimation = window.requestAnimationFrame(this.applyIntermediateTransform);
|
|
561
|
+
}
|
|
562
|
+
this.frameAnimation = window.requestAnimationFrame(this.applyTransform);
|
|
563
|
+
} else {
|
|
564
|
+
const { x: transformX, y: transformY } = this.getTransformMatrix(x + dx, y + dy, scale, angle);
|
|
565
|
+
const { boundX, boundY } = this.getBoundCoordinates({
|
|
566
|
+
x: transformX,
|
|
567
|
+
y: transformY
|
|
568
|
+
}, {
|
|
569
|
+
angle,
|
|
570
|
+
scale,
|
|
571
|
+
offsetX: x + dx,
|
|
572
|
+
offsetY: y + dy
|
|
573
|
+
});
|
|
574
|
+
this.setState({
|
|
575
|
+
x: x + dx - (transformX - boundX),
|
|
576
|
+
y: y + dy - (transformY - boundY)
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}, this.rotate = (value)=>{
|
|
580
|
+
const { angle } = this.state;
|
|
581
|
+
let newAngle;
|
|
582
|
+
if (typeof value === 'function') {
|
|
583
|
+
newAngle = value(angle);
|
|
584
|
+
} else {
|
|
585
|
+
newAngle = value;
|
|
586
|
+
}
|
|
587
|
+
this.setState({
|
|
588
|
+
angle: newAngle
|
|
589
|
+
});
|
|
590
|
+
}, this.zoomAbs = (x, y, zoomLevel)=>{
|
|
591
|
+
this.zoomTo(x, y, zoomLevel / this.state.scale);
|
|
592
|
+
}, this.zoomTo = (x, y, ratio)=>{
|
|
593
|
+
const { minZoom, maxZoom } = this.props;
|
|
594
|
+
const { x: transformX, y: transformY, scale, angle } = this.state;
|
|
595
|
+
let newScale = scale * ratio;
|
|
596
|
+
if (newScale < minZoom) {
|
|
597
|
+
if (scale === minZoom) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
ratio = minZoom / scale;
|
|
601
|
+
newScale = minZoom;
|
|
602
|
+
} else if (newScale > maxZoom) {
|
|
603
|
+
if (scale === maxZoom) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
ratio = maxZoom / scale;
|
|
607
|
+
newScale = maxZoom;
|
|
608
|
+
}
|
|
609
|
+
const newX = x - ratio * (x - transformX);
|
|
610
|
+
const newY = y - ratio * (y - transformY);
|
|
611
|
+
const { boundX, boundY } = this.getBoundCoordinates({
|
|
612
|
+
x: newX,
|
|
613
|
+
y: newY
|
|
614
|
+
}, {
|
|
615
|
+
angle,
|
|
616
|
+
scale,
|
|
617
|
+
offsetX: newX,
|
|
618
|
+
offsetY: newY
|
|
619
|
+
});
|
|
620
|
+
this.prevPanPosition = {
|
|
621
|
+
x: boundX,
|
|
622
|
+
y: boundY
|
|
623
|
+
};
|
|
624
|
+
this.setState({
|
|
625
|
+
x: boundX,
|
|
626
|
+
y: boundY,
|
|
627
|
+
scale: newScale
|
|
628
|
+
});
|
|
629
|
+
}, this.centeredZoom = (delta, zoomSpeed)=>{
|
|
630
|
+
const container = this.getContainer();
|
|
631
|
+
const scaleMultiplier = getScaleMultiplier(delta, zoomSpeed || this.props.zoomSpeed);
|
|
632
|
+
const containerRect = container.getBoundingClientRect();
|
|
633
|
+
this.zoomTo(containerRect.width / 2, containerRect.height / 2, scaleMultiplier);
|
|
634
|
+
}, this.zoomIn = (zoomSpeed)=>{
|
|
635
|
+
this.centeredZoom(-1, zoomSpeed);
|
|
636
|
+
}, this.zoomOut = (zoomSpeed)=>{
|
|
637
|
+
this.centeredZoom(1, zoomSpeed);
|
|
638
|
+
}, this.reset = ()=>{
|
|
639
|
+
this.setState({
|
|
640
|
+
x: 0,
|
|
641
|
+
y: 0,
|
|
642
|
+
scale: 1,
|
|
643
|
+
angle: 0
|
|
644
|
+
});
|
|
645
|
+
}, this.getContainerBoundingRect = ()=>{
|
|
646
|
+
return this.getContainer().getBoundingClientRect();
|
|
647
|
+
}, this.getOffset = (e)=>{
|
|
648
|
+
const containerRect = this.getContainerBoundingRect();
|
|
649
|
+
const offsetX = e.clientX - containerRect.left;
|
|
650
|
+
const offsetY = e.clientY - containerRect.top;
|
|
651
|
+
return {
|
|
652
|
+
x: offsetX,
|
|
653
|
+
y: offsetY
|
|
654
|
+
};
|
|
655
|
+
}, this.getTransformMatrix = (x, y, scale, angle)=>{
|
|
656
|
+
if (!this.dragContainer.current) {
|
|
657
|
+
return {
|
|
658
|
+
a: scale,
|
|
659
|
+
b: 0,
|
|
660
|
+
c: 0,
|
|
661
|
+
d: scale,
|
|
662
|
+
x,
|
|
663
|
+
y
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
const { clientWidth, clientHeight } = this.getDragContainer();
|
|
667
|
+
const centerX = clientWidth / 2;
|
|
668
|
+
const centerY = clientHeight / 2;
|
|
669
|
+
return TransformMatrix({
|
|
670
|
+
angle,
|
|
671
|
+
scale,
|
|
672
|
+
offsetX: x,
|
|
673
|
+
offsetY: y
|
|
674
|
+
}, {
|
|
675
|
+
x: centerX,
|
|
676
|
+
y: centerY
|
|
677
|
+
});
|
|
678
|
+
}, // Apply transform through rAF
|
|
679
|
+
this.applyTransform = ()=>{
|
|
680
|
+
this.getDragContainer().style.transform = this.transformMatrixString;
|
|
681
|
+
this.frameAnimation = 0;
|
|
682
|
+
}, // Apply intermediate transform through rAF
|
|
683
|
+
this.applyIntermediateTransform = ()=>{
|
|
684
|
+
this.getDragContainer().style.transform = this.intermediateTransformMatrixString;
|
|
685
|
+
this.intermediateFrameAnimation = 0;
|
|
686
|
+
}, this.getBoundCoordinates = (coordinates, transformationParameters)=>{
|
|
687
|
+
const { x, y } = coordinates;
|
|
688
|
+
const { enableBoundingBox, boundaryRatioVertical, boundaryRatioHorizontal } = this.props;
|
|
689
|
+
const { offsetX = 0, offsetY = 0 } = transformationParameters;
|
|
690
|
+
if (!enableBoundingBox) {
|
|
691
|
+
return {
|
|
692
|
+
boundX: x,
|
|
693
|
+
boundY: y,
|
|
694
|
+
offsetX: x,
|
|
695
|
+
offsetY: y
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
const { height: containerHeight, width: containerWidth } = this.getContainerBoundingRect();
|
|
699
|
+
const { clientTop, clientLeft, clientWidth, clientHeight } = this.getDragContainer();
|
|
700
|
+
const clientBoundingBox = {
|
|
701
|
+
top: clientTop,
|
|
702
|
+
left: clientLeft,
|
|
703
|
+
width: clientWidth,
|
|
704
|
+
height: clientHeight
|
|
705
|
+
};
|
|
706
|
+
return boundCoordinates(x, y, {
|
|
707
|
+
vertical: boundaryRatioVertical,
|
|
708
|
+
horizontal: boundaryRatioHorizontal
|
|
709
|
+
}, getTransformedBoundingBox(transformationParameters, clientBoundingBox), containerHeight, containerWidth, offsetX, offsetY);
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
ZoomablePanningComponent.defaultProps = {
|
|
714
|
+
zoomSpeed: 1,
|
|
715
|
+
doubleZoomSpeed: 1.75,
|
|
716
|
+
disabled: false,
|
|
717
|
+
minZoom: 0,
|
|
718
|
+
maxZoom: Infinity,
|
|
719
|
+
noStateUpdate: true,
|
|
720
|
+
boundaryRatioVertical: 0.8,
|
|
721
|
+
boundaryRatioHorizontal: 0.8,
|
|
722
|
+
disableDoubleClickZoom: false,
|
|
723
|
+
disableScrollZoom: false,
|
|
724
|
+
preventPan: ()=>false
|
|
725
|
+
};
|
|
726
|
+
export default ZoomablePanningComponent;
|
|
727
|
+
|
|
728
|
+
//# sourceMappingURL=zoomable-panning-component.js.map
|