@tachybase/components 0.23.8
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/.turbo/turbo-build.log +9 -0
- package/LICENSE +201 -0
- package/lib/__builtins__/dayjs.d.ts +4 -0
- package/lib/__builtins__/dayjs.js +95 -0
- package/lib/__builtins__/hooks/index.d.ts +4 -0
- package/lib/__builtins__/hooks/index.js +27 -0
- package/lib/__builtins__/hooks/useClickAway.d.ts +5 -0
- package/lib/__builtins__/hooks/useClickAway.js +64 -0
- package/lib/__builtins__/hooks/useConfig.d.ts +1 -0
- package/lib/__builtins__/hooks/useConfig.js +31 -0
- package/lib/__builtins__/hooks/usePrefixCls.d.ts +3 -0
- package/lib/__builtins__/hooks/usePrefixCls.js +38 -0
- package/lib/__builtins__/hooks/useToken.d.ts +6 -0
- package/lib/__builtins__/hooks/useToken.js +28 -0
- package/lib/__builtins__/index.d.ts +7 -0
- package/lib/__builtins__/index.js +33 -0
- package/lib/__builtins__/loading.d.ts +1 -0
- package/lib/__builtins__/loading.js +40 -0
- package/lib/__builtins__/pickDataProps.d.ts +1 -0
- package/lib/__builtins__/pickDataProps.js +36 -0
- package/lib/__builtins__/portal.d.ts +10 -0
- package/lib/__builtins__/portal.js +89 -0
- package/lib/__builtins__/render.d.ts +9 -0
- package/lib/__builtins__/render.js +99 -0
- package/lib/__builtins__/sort.d.ts +73 -0
- package/lib/__builtins__/sort.js +126 -0
- package/lib/__builtins__/style.d.ts +23 -0
- package/lib/__builtins__/style.js +88 -0
- package/lib/array-base/index.d.ts +64 -0
- package/lib/array-base/index.js +345 -0
- package/lib/array-base/style.d.ts +2 -0
- package/lib/array-base/style.js +68 -0
- package/lib/array-cards/index.d.ts +5 -0
- package/lib/array-cards/index.js +166 -0
- package/lib/array-cards/style.d.ts +2 -0
- package/lib/array-cards/style.js +37 -0
- package/lib/array-collapse/index.d.ts +10 -0
- package/lib/array-collapse/index.js +199 -0
- package/lib/array-collapse/style.d.ts +2 -0
- package/lib/array-collapse/style.js +33 -0
- package/lib/array-items/index.d.ts +8 -0
- package/lib/array-items/index.js +122 -0
- package/lib/array-items/style.d.ts +2 -0
- package/lib/array-items/style.js +82 -0
- package/lib/array-table/index.d.ts +9 -0
- package/lib/array-table/index.js +376 -0
- package/lib/array-table/style.d.ts +2 -0
- package/lib/array-table/style.js +71 -0
- package/lib/array-tabs/index.d.ts +4 -0
- package/lib/array-tabs/index.js +102 -0
- package/lib/cascader/index.d.ts +12 -0
- package/lib/cascader/index.js +58 -0
- package/lib/checkbox/index.d.ts +5 -0
- package/lib/checkbox/index.js +51 -0
- package/lib/code-mirror/index.d.ts +3 -0
- package/lib/code-mirror/index.js +91 -0
- package/lib/date-picker/index.d.ts +2 -0
- package/lib/date-picker/index.js +70 -0
- package/lib/date-picker/style.d.ts +1 -0
- package/lib/date-picker/style.js +1 -0
- package/lib/editable/index.d.ts +8 -0
- package/lib/editable/index.js +181 -0
- package/lib/editable/style.d.ts +2 -0
- package/lib/editable/style.js +69 -0
- package/lib/form/index.d.ts +12 -0
- package/lib/form/index.js +71 -0
- package/lib/form-button-group/index.d.ts +27 -0
- package/lib/form-button-group/index.js +148 -0
- package/lib/form-button-group/style.d.ts +2 -0
- package/lib/form-button-group/style.js +41 -0
- package/lib/form-collapse/index.d.ts +28 -0
- package/lib/form-collapse/index.js +150 -0
- package/lib/form-dialog/index.d.ts +26 -0
- package/lib/form-dialog/index.js +194 -0
- package/lib/form-drawer/index.d.ts +25 -0
- package/lib/form-drawer/index.js +187 -0
- package/lib/form-grid/index.d.ts +34 -0
- package/lib/form-grid/index.js +108 -0
- package/lib/form-grid/style.d.ts +2 -0
- package/lib/form-grid/style.js +31 -0
- package/lib/form-item/hooks/index.d.ts +2 -0
- package/lib/form-item/hooks/index.js +23 -0
- package/lib/form-item/hooks/useFormItemLayout.d.ts +37 -0
- package/lib/form-item/hooks/useFormItemLayout.js +66 -0
- package/lib/form-item/hooks/useOverflow.d.ts +5 -0
- package/lib/form-item/hooks/useOverflow.js +55 -0
- package/lib/form-item/index.d.ts +11 -0
- package/lib/form-item/index.js +303 -0
- package/lib/form-item/style/animation.d.ts +2 -0
- package/lib/form-item/style/animation.js +57 -0
- package/lib/form-item/style/grid.d.ts +2 -0
- package/lib/form-item/style/grid.js +50 -0
- package/lib/form-item/style/index.d.ts +2 -0
- package/lib/form-item/style/index.js +387 -0
- package/lib/form-item/style/other.d.ts +2 -0
- package/lib/form-item/style/other.js +490 -0
- package/lib/form-item/types.d.ts +35 -0
- package/lib/form-item/types.js +15 -0
- package/lib/form-layout/index.d.ts +74 -0
- package/lib/form-layout/index.js +96 -0
- package/lib/form-layout/useResponsiveFormLayout.d.ts +17 -0
- package/lib/form-layout/useResponsiveFormLayout.js +89 -0
- package/lib/form-step/index.d.ts +27 -0
- package/lib/form-step/index.js +154 -0
- package/lib/form-tab/index.d.ts +19 -0
- package/lib/form-tab/index.js +150 -0
- package/lib/index.d.ts +38 -0
- package/lib/index.js +95 -0
- package/lib/input/index.d.ts +7 -0
- package/lib/input/index.js +57 -0
- package/lib/lightbox/constant.d.ts +21 -0
- package/lib/lightbox/constant.js +79 -0
- package/lib/lightbox/index.d.ts +2 -0
- package/lib/lightbox/index.js +37 -0
- package/lib/lightbox/interface.d.ts +43 -0
- package/lib/lightbox/interface.js +15 -0
- package/lib/lightbox/react-image-lightbox.d.ts +197 -0
- package/lib/lightbox/react-image-lightbox.js +1431 -0
- package/lib/lightbox/style.css +305 -0
- package/lib/lightbox/util.d.ts +7 -0
- package/lib/lightbox/util.js +71 -0
- package/lib/number-picker/index.d.ts +4 -0
- package/lib/number-picker/index.js +32 -0
- package/lib/password/PasswordStrength.d.ts +9 -0
- package/lib/password/PasswordStrength.js +188 -0
- package/lib/password/index.d.ts +7 -0
- package/lib/password/index.js +85 -0
- package/lib/preview-text/index.d.ts +12 -0
- package/lib/preview-text/index.js +263 -0
- package/lib/preview-text/style.d.ts +2 -0
- package/lib/preview-text/style.js +37 -0
- package/lib/radio/index.d.ts +8 -0
- package/lib/radio/index.js +51 -0
- package/lib/reset/index.d.ts +10 -0
- package/lib/reset/index.js +67 -0
- package/lib/select/index.d.ts +4 -0
- package/lib/select/index.js +59 -0
- package/lib/select-table/hooks/index.d.ts +5 -0
- package/lib/select-table/hooks/index.js +29 -0
- package/lib/select-table/hooks/useCheckSlackly.d.ts +16 -0
- package/lib/select-table/hooks/useCheckSlackly.js +57 -0
- package/lib/select-table/hooks/useFilterOptions.d.ts +3 -0
- package/lib/select-table/hooks/useFilterOptions.js +97 -0
- package/lib/select-table/hooks/useFlatOptions.d.ts +3 -0
- package/lib/select-table/hooks/useFlatOptions.js +46 -0
- package/lib/select-table/hooks/useSize.d.ts +9 -0
- package/lib/select-table/hooks/useSize.js +48 -0
- package/lib/select-table/hooks/useTitleAddon.d.ts +7 -0
- package/lib/select-table/hooks/useTitleAddon.js +90 -0
- package/lib/select-table/index.d.ts +27 -0
- package/lib/select-table/index.js +339 -0
- package/lib/select-table/style.d.ts +2 -0
- package/lib/select-table/style.js +33 -0
- package/lib/select-table/utils.d.ts +78 -0
- package/lib/select-table/utils.js +166 -0
- package/lib/space/index.d.ts +4 -0
- package/lib/space/index.js +49 -0
- package/lib/submit/index.d.ts +11 -0
- package/lib/submit/index.js +67 -0
- package/lib/switch/index.d.ts +2 -0
- package/lib/switch/index.js +44 -0
- package/lib/time-picker/index.d.ts +2 -0
- package/lib/time-picker/index.js +60 -0
- package/lib/time-picker/style.d.ts +1 -0
- package/lib/time-picker/style.js +1 -0
- package/lib/transfer/index.d.ts +2 -0
- package/lib/transfer/index.js +56 -0
- package/lib/tree-select/index.d.ts +2 -0
- package/lib/tree-select/index.js +58 -0
- package/lib/upload/index.d.ts +18 -0
- package/lib/upload/index.js +159 -0
- package/lib/upload/placeholder.d.ts +4 -0
- package/lib/upload/placeholder.js +88 -0
- package/package.json +31 -0
|
@@ -0,0 +1,1431 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
|
+
var react_image_lightbox_exports = {};
|
|
32
|
+
__export(react_image_lightbox_exports, {
|
|
33
|
+
default: () => react_image_lightbox_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(react_image_lightbox_exports);
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var import_prop_types = __toESM(require("prop-types"));
|
|
38
|
+
var import_react_modal = __toESM(require("react-modal"));
|
|
39
|
+
var import_constant = require("./constant");
|
|
40
|
+
var import_util = require("./util");
|
|
41
|
+
var import_style = require("./style.css");
|
|
42
|
+
const _ReactImageLightbox = class _ReactImageLightbox extends import_react.Component {
|
|
43
|
+
moveRequested;
|
|
44
|
+
imageCache;
|
|
45
|
+
listeners;
|
|
46
|
+
timeouts;
|
|
47
|
+
didUnmount;
|
|
48
|
+
windowContext;
|
|
49
|
+
outerEl;
|
|
50
|
+
zoomInBtn;
|
|
51
|
+
zoomOutBtn;
|
|
52
|
+
caption;
|
|
53
|
+
currentAction;
|
|
54
|
+
eventsSource;
|
|
55
|
+
pointerList;
|
|
56
|
+
preventInnerClose;
|
|
57
|
+
preventInnerCloseTimeout;
|
|
58
|
+
keyPressed;
|
|
59
|
+
lastKeyDownTime;
|
|
60
|
+
resizeTimeout;
|
|
61
|
+
wheelActionTimeout;
|
|
62
|
+
resetScrollTimeout;
|
|
63
|
+
scrollX;
|
|
64
|
+
scrollY;
|
|
65
|
+
moveStartX;
|
|
66
|
+
moveStartY;
|
|
67
|
+
moveStartOffsetX;
|
|
68
|
+
moveStartOffsetY;
|
|
69
|
+
swipeStartX;
|
|
70
|
+
swipeStartY;
|
|
71
|
+
swipeEndX;
|
|
72
|
+
swipeEndY;
|
|
73
|
+
pinchTouchList;
|
|
74
|
+
pinchDistance;
|
|
75
|
+
keyCounter;
|
|
76
|
+
static isTargetMatchImage(target) {
|
|
77
|
+
return target && /ril-image-current/.test(target.className);
|
|
78
|
+
}
|
|
79
|
+
static parseMouseEvent(mouseEvent) {
|
|
80
|
+
return {
|
|
81
|
+
id: "mouse",
|
|
82
|
+
source: import_constant.SOURCE_MOUSE,
|
|
83
|
+
x: parseInt(mouseEvent.clientX, 10),
|
|
84
|
+
y: parseInt(mouseEvent.clientY, 10)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
static parseTouchPointer(touchPointer) {
|
|
88
|
+
return {
|
|
89
|
+
id: touchPointer.identifier,
|
|
90
|
+
source: import_constant.SOURCE_TOUCH,
|
|
91
|
+
x: parseInt(touchPointer.clientX, 10),
|
|
92
|
+
y: parseInt(touchPointer.clientY, 10)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
static parsePointerEvent(pointerEvent) {
|
|
96
|
+
return {
|
|
97
|
+
id: pointerEvent.pointerId,
|
|
98
|
+
source: import_constant.SOURCE_POINTER,
|
|
99
|
+
x: parseInt(pointerEvent.clientX, 10),
|
|
100
|
+
y: parseInt(pointerEvent.clientY, 10)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// Request to transition to the previous image
|
|
104
|
+
static getTransform({ x = 0, y = 0, zoom = 1, width, targetWidth }) {
|
|
105
|
+
let nextX = x;
|
|
106
|
+
const windowWidth = (0, import_util.getWindowWidth)();
|
|
107
|
+
if (width > windowWidth) {
|
|
108
|
+
nextX += (windowWidth - width) / 2;
|
|
109
|
+
}
|
|
110
|
+
const scaleFactor = zoom * (targetWidth / width);
|
|
111
|
+
return {
|
|
112
|
+
transform: `translate3d(${nextX}px,${y}px,0) scale3d(${scaleFactor},${scaleFactor},1)`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
constructor(props) {
|
|
116
|
+
super(props);
|
|
117
|
+
this.state = {
|
|
118
|
+
//-----------------------------
|
|
119
|
+
// Animation
|
|
120
|
+
//-----------------------------
|
|
121
|
+
// Lightbox is closing
|
|
122
|
+
// When Lightbox is mounted, if animation is enabled it will open with the reverse of the closing animation
|
|
123
|
+
isClosing: !props.animationDisabled,
|
|
124
|
+
// Component parts should animate (e.g., when images are moving, or image is being zoomed)
|
|
125
|
+
shouldAnimate: false,
|
|
126
|
+
//-----------------------------
|
|
127
|
+
// Zoom settings
|
|
128
|
+
//-----------------------------
|
|
129
|
+
// Zoom level of image
|
|
130
|
+
zoomLevel: import_constant.MIN_ZOOM_LEVEL,
|
|
131
|
+
//-----------------------------
|
|
132
|
+
// Image position settings
|
|
133
|
+
//-----------------------------
|
|
134
|
+
// Horizontal offset from center
|
|
135
|
+
offsetX: 0,
|
|
136
|
+
// Vertical offset from center
|
|
137
|
+
offsetY: 0,
|
|
138
|
+
// image load error for srcType
|
|
139
|
+
loadErrorStatus: {}
|
|
140
|
+
};
|
|
141
|
+
this.outerEl = import_react.default.createRef();
|
|
142
|
+
this.zoomInBtn = import_react.default.createRef();
|
|
143
|
+
this.zoomOutBtn = import_react.default.createRef();
|
|
144
|
+
this.caption = import_react.default.createRef();
|
|
145
|
+
this.closeIfClickInner = this.closeIfClickInner.bind(this);
|
|
146
|
+
this.handleImageDoubleClick = this.handleImageDoubleClick.bind(this);
|
|
147
|
+
this.handleImageMouseWheel = this.handleImageMouseWheel.bind(this);
|
|
148
|
+
this.handleKeyInput = this.handleKeyInput.bind(this);
|
|
149
|
+
this.handleMouseUp = this.handleMouseUp.bind(this);
|
|
150
|
+
this.handleMouseDown = this.handleMouseDown.bind(this);
|
|
151
|
+
this.handleMouseMove = this.handleMouseMove.bind(this);
|
|
152
|
+
this.handleOuterMousewheel = this.handleOuterMousewheel.bind(this);
|
|
153
|
+
this.handleTouchStart = this.handleTouchStart.bind(this);
|
|
154
|
+
this.handleTouchMove = this.handleTouchMove.bind(this);
|
|
155
|
+
this.handleTouchEnd = this.handleTouchEnd.bind(this);
|
|
156
|
+
this.handlePointerEvent = this.handlePointerEvent.bind(this);
|
|
157
|
+
this.handleCaptionMousewheel = this.handleCaptionMousewheel.bind(this);
|
|
158
|
+
this.handleWindowResize = this.handleWindowResize.bind(this);
|
|
159
|
+
this.handleZoomInButtonClick = this.handleZoomInButtonClick.bind(this);
|
|
160
|
+
this.handleZoomOutButtonClick = this.handleZoomOutButtonClick.bind(this);
|
|
161
|
+
this.requestClose = this.requestClose.bind(this);
|
|
162
|
+
this.requestMoveNext = this.requestMoveNext.bind(this);
|
|
163
|
+
this.requestMovePrev = this.requestMovePrev.bind(this);
|
|
164
|
+
this.timeouts = [];
|
|
165
|
+
this.currentAction = import_constant.ACTION_NONE;
|
|
166
|
+
this.eventsSource = import_constant.SOURCE_ANY;
|
|
167
|
+
this.pointerList = [];
|
|
168
|
+
this.preventInnerClose = false;
|
|
169
|
+
this.preventInnerCloseTimeout = null;
|
|
170
|
+
this.keyPressed = false;
|
|
171
|
+
this.imageCache = {};
|
|
172
|
+
this.lastKeyDownTime = 0;
|
|
173
|
+
this.resizeTimeout = null;
|
|
174
|
+
this.wheelActionTimeout = null;
|
|
175
|
+
this.resetScrollTimeout = null;
|
|
176
|
+
this.scrollX = 0;
|
|
177
|
+
this.scrollY = 0;
|
|
178
|
+
this.moveStartX = 0;
|
|
179
|
+
this.moveStartY = 0;
|
|
180
|
+
this.moveStartOffsetX = 0;
|
|
181
|
+
this.moveStartOffsetY = 0;
|
|
182
|
+
this.swipeStartX = 0;
|
|
183
|
+
this.swipeStartY = 0;
|
|
184
|
+
this.swipeEndX = 0;
|
|
185
|
+
this.swipeEndY = 0;
|
|
186
|
+
this.pinchTouchList = null;
|
|
187
|
+
this.pinchDistance = 0;
|
|
188
|
+
this.keyCounter = 0;
|
|
189
|
+
this.moveRequested = false;
|
|
190
|
+
}
|
|
191
|
+
componentDidMount() {
|
|
192
|
+
if (!this.props.animationDisabled) {
|
|
193
|
+
this.setState({ isClosing: false });
|
|
194
|
+
}
|
|
195
|
+
this.windowContext = (0, import_util.getHighestSafeWindowContext)();
|
|
196
|
+
this.listeners = {
|
|
197
|
+
resize: this.handleWindowResize,
|
|
198
|
+
mouseup: this.handleMouseUp,
|
|
199
|
+
touchend: this.handleTouchEnd,
|
|
200
|
+
touchcancel: this.handleTouchEnd,
|
|
201
|
+
pointerdown: this.handlePointerEvent,
|
|
202
|
+
pointermove: this.handlePointerEvent,
|
|
203
|
+
pointerup: this.handlePointerEvent,
|
|
204
|
+
pointercancel: this.handlePointerEvent
|
|
205
|
+
};
|
|
206
|
+
Object.keys(this.listeners).forEach((type) => {
|
|
207
|
+
this.windowContext.addEventListener(type, this.listeners[type]);
|
|
208
|
+
});
|
|
209
|
+
this.loadAllImages();
|
|
210
|
+
}
|
|
211
|
+
shouldComponentUpdate(nextProps) {
|
|
212
|
+
this.getSrcTypes().forEach((srcType) => {
|
|
213
|
+
if (this.props[srcType.name] !== nextProps[srcType.name]) {
|
|
214
|
+
this.moveRequested = false;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
return !this.moveRequested;
|
|
218
|
+
}
|
|
219
|
+
componentDidUpdate(prevProps) {
|
|
220
|
+
let sourcesChanged = false;
|
|
221
|
+
const prevSrcDict = {};
|
|
222
|
+
const nextSrcDict = {};
|
|
223
|
+
this.getSrcTypes().forEach((srcType) => {
|
|
224
|
+
if (prevProps[srcType.name] !== this.props[srcType.name]) {
|
|
225
|
+
sourcesChanged = true;
|
|
226
|
+
prevSrcDict[prevProps[srcType.name]] = true;
|
|
227
|
+
nextSrcDict[this.props[srcType.name]] = true;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if (sourcesChanged || this.moveRequested) {
|
|
231
|
+
Object.keys(prevSrcDict).forEach((prevSrc) => {
|
|
232
|
+
if (!(prevSrc in nextSrcDict) && prevSrc in this.imageCache) {
|
|
233
|
+
this.imageCache[prevSrc].loaded = false;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
this.moveRequested = false;
|
|
237
|
+
this.loadAllImages(this.props);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
componentWillUnmount() {
|
|
241
|
+
this.didUnmount = true;
|
|
242
|
+
Object.keys(this.listeners).forEach((type) => {
|
|
243
|
+
this.windowContext.removeEventListener(type, this.listeners[type]);
|
|
244
|
+
});
|
|
245
|
+
this.timeouts.forEach((tid) => clearTimeout(tid));
|
|
246
|
+
}
|
|
247
|
+
setTimeout(func, time) {
|
|
248
|
+
const id = setTimeout(() => {
|
|
249
|
+
this.timeouts = this.timeouts.filter((tid) => tid !== id);
|
|
250
|
+
func();
|
|
251
|
+
}, time);
|
|
252
|
+
this.timeouts.push(id);
|
|
253
|
+
return id;
|
|
254
|
+
}
|
|
255
|
+
setPreventInnerClose() {
|
|
256
|
+
if (this.preventInnerCloseTimeout) {
|
|
257
|
+
this.clearTimeout(this.preventInnerCloseTimeout);
|
|
258
|
+
}
|
|
259
|
+
this.preventInnerClose = true;
|
|
260
|
+
this.preventInnerCloseTimeout = this.setTimeout(() => {
|
|
261
|
+
this.preventInnerClose = false;
|
|
262
|
+
this.preventInnerCloseTimeout = null;
|
|
263
|
+
}, 100);
|
|
264
|
+
}
|
|
265
|
+
// Get info for the best suited image to display with the given srcType
|
|
266
|
+
getBestImageForType(srcType, fileSrc) {
|
|
267
|
+
let imageSrc = fileSrc || this.props[srcType];
|
|
268
|
+
let fitSizes = {};
|
|
269
|
+
if (this.isImageLoaded(imageSrc)) {
|
|
270
|
+
fitSizes = this.getFitSizes(this.imageCache[imageSrc].width, this.imageCache[imageSrc].height);
|
|
271
|
+
} else if (this.isImageLoaded(this.props[`${srcType}Thumbnail`])) {
|
|
272
|
+
imageSrc = this.props[`${srcType}Thumbnail`];
|
|
273
|
+
fitSizes = this.getFitSizes(this.imageCache[imageSrc].width, this.imageCache[imageSrc].height, true);
|
|
274
|
+
} else {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
src: imageSrc,
|
|
279
|
+
height: this.imageCache[imageSrc].height,
|
|
280
|
+
width: this.imageCache[imageSrc].width,
|
|
281
|
+
targetHeight: fitSizes.height,
|
|
282
|
+
targetWidth: fitSizes.width
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
// Get sizing for when an image is larger than the window
|
|
286
|
+
getFitSizes(width, height, stretch = false) {
|
|
287
|
+
const boxSize = this.getLightboxRect();
|
|
288
|
+
let maxHeight = boxSize.height - this.props.imagePadding * 2;
|
|
289
|
+
let maxWidth = boxSize.width - this.props.imagePadding * 2;
|
|
290
|
+
if (!stretch) {
|
|
291
|
+
maxHeight = Math.min(maxHeight, height);
|
|
292
|
+
maxWidth = Math.min(maxWidth, width);
|
|
293
|
+
}
|
|
294
|
+
const maxRatio = maxWidth / maxHeight;
|
|
295
|
+
const srcRatio = width / height;
|
|
296
|
+
if (maxRatio > srcRatio) {
|
|
297
|
+
return {
|
|
298
|
+
width: width * maxHeight / height,
|
|
299
|
+
height: maxHeight
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
width: maxWidth,
|
|
304
|
+
height: height * maxWidth / width
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
getMaxOffsets(zoomLevel = this.state.zoomLevel) {
|
|
308
|
+
const currentImageInfo = this.getBestImageForType("mainSrc");
|
|
309
|
+
if (currentImageInfo === null) {
|
|
310
|
+
return { maxX: 0, minX: 0, maxY: 0, minY: 0 };
|
|
311
|
+
}
|
|
312
|
+
const boxSize = this.getLightboxRect();
|
|
313
|
+
const zoomMultiplier = this.getZoomMultiplier(zoomLevel);
|
|
314
|
+
let maxX = 0;
|
|
315
|
+
if (zoomMultiplier * currentImageInfo.width - boxSize.width < 0) {
|
|
316
|
+
maxX = (boxSize.width - zoomMultiplier * currentImageInfo.width) / 2;
|
|
317
|
+
} else {
|
|
318
|
+
maxX = (zoomMultiplier * currentImageInfo.width - boxSize.width) / 2;
|
|
319
|
+
}
|
|
320
|
+
let maxY = 0;
|
|
321
|
+
if (zoomMultiplier * currentImageInfo.height - boxSize.height < 0) {
|
|
322
|
+
maxY = (boxSize.height - zoomMultiplier * currentImageInfo.height) / 2;
|
|
323
|
+
} else {
|
|
324
|
+
maxY = (zoomMultiplier * currentImageInfo.height - boxSize.height) / 2;
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
maxX,
|
|
328
|
+
maxY,
|
|
329
|
+
minX: -1 * maxX,
|
|
330
|
+
minY: -1 * maxY
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
// Get image src types
|
|
334
|
+
getSrcTypes() {
|
|
335
|
+
return [
|
|
336
|
+
{
|
|
337
|
+
name: "mainSrc",
|
|
338
|
+
keyEnding: `i${this.keyCounter}`
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
name: "mainSrcThumbnail",
|
|
342
|
+
keyEnding: `t${this.keyCounter}`
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
name: "nextSrc",
|
|
346
|
+
keyEnding: `i${this.keyCounter + 1}`
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: "nextSrcThumbnail",
|
|
350
|
+
keyEnding: `t${this.keyCounter + 1}`
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "prevSrc",
|
|
354
|
+
keyEnding: `i${this.keyCounter - 1}`
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: "prevSrcThumbnail",
|
|
358
|
+
keyEnding: `t${this.keyCounter - 1}`
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
name: "mainFile",
|
|
362
|
+
keyEnding: `i${this.keyCounter}`
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: "mainSrcThumbnail",
|
|
366
|
+
keyEnding: `t${this.keyCounter}`
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: "nextFile",
|
|
370
|
+
keyEnding: `i${this.keyCounter + 1}`
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: "nextFileThumbnail",
|
|
374
|
+
keyEnding: `t${this.keyCounter + 1}`
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
name: "prevFile",
|
|
378
|
+
keyEnding: `i${this.keyCounter - 1}`
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: "prevFileThumbnail",
|
|
382
|
+
keyEnding: `t${this.keyCounter - 1}`
|
|
383
|
+
}
|
|
384
|
+
];
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Get sizing when the image is scaled
|
|
388
|
+
*/
|
|
389
|
+
getZoomMultiplier(zoomLevel = this.state.zoomLevel) {
|
|
390
|
+
return import_constant.ZOOM_RATIO ** zoomLevel;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Get the size of the lightbox in pixels
|
|
394
|
+
*/
|
|
395
|
+
getLightboxRect() {
|
|
396
|
+
if (this.outerEl.current) {
|
|
397
|
+
return this.outerEl.current.getBoundingClientRect();
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
width: (0, import_util.getWindowWidth)(),
|
|
401
|
+
height: (0, import_util.getWindowHeight)(),
|
|
402
|
+
top: 0,
|
|
403
|
+
right: 0,
|
|
404
|
+
bottom: 0,
|
|
405
|
+
left: 0
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
clearTimeout(id) {
|
|
409
|
+
this.timeouts = this.timeouts.filter((tid) => tid !== id);
|
|
410
|
+
clearTimeout(id);
|
|
411
|
+
}
|
|
412
|
+
// Change zoom level
|
|
413
|
+
changeZoom(zoomLevel, clientX, clientY) {
|
|
414
|
+
if (!this.props.enableZoom) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const nextZoomLevel = Math.max(import_constant.MIN_ZOOM_LEVEL, Math.min(import_constant.MAX_ZOOM_LEVEL, zoomLevel));
|
|
418
|
+
if (nextZoomLevel === this.state.zoomLevel) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (nextZoomLevel === import_constant.MIN_ZOOM_LEVEL) {
|
|
422
|
+
this.setState({
|
|
423
|
+
zoomLevel: nextZoomLevel,
|
|
424
|
+
offsetX: 0,
|
|
425
|
+
offsetY: 0
|
|
426
|
+
});
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const imageBaseSize = this.getBestImageForType("mainSrc");
|
|
430
|
+
if (imageBaseSize === null) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
const currentZoomMultiplier = this.getZoomMultiplier();
|
|
434
|
+
const nextZoomMultiplier = this.getZoomMultiplier(nextZoomLevel);
|
|
435
|
+
const boxRect = this.getLightboxRect();
|
|
436
|
+
const pointerX = typeof clientX !== "undefined" ? clientX - boxRect.left : boxRect.width / 2;
|
|
437
|
+
const pointerY = typeof clientY !== "undefined" ? clientY - boxRect.top : boxRect.height / 2;
|
|
438
|
+
const currentImageOffsetX = (boxRect.width - imageBaseSize.width * currentZoomMultiplier) / 2;
|
|
439
|
+
const currentImageOffsetY = (boxRect.height - imageBaseSize.height * currentZoomMultiplier) / 2;
|
|
440
|
+
const currentImageRealOffsetX = currentImageOffsetX - this.state.offsetX;
|
|
441
|
+
const currentImageRealOffsetY = currentImageOffsetY - this.state.offsetY;
|
|
442
|
+
const currentPointerXRelativeToImage = (pointerX - currentImageRealOffsetX) / currentZoomMultiplier;
|
|
443
|
+
const currentPointerYRelativeToImage = (pointerY - currentImageRealOffsetY) / currentZoomMultiplier;
|
|
444
|
+
const nextImageRealOffsetX = pointerX - currentPointerXRelativeToImage * nextZoomMultiplier;
|
|
445
|
+
const nextImageRealOffsetY = pointerY - currentPointerYRelativeToImage * nextZoomMultiplier;
|
|
446
|
+
const nextImageOffsetX = (boxRect.width - imageBaseSize.width * nextZoomMultiplier) / 2;
|
|
447
|
+
const nextImageOffsetY = (boxRect.height - imageBaseSize.height * nextZoomMultiplier) / 2;
|
|
448
|
+
let nextOffsetX = nextImageOffsetX - nextImageRealOffsetX;
|
|
449
|
+
let nextOffsetY = nextImageOffsetY - nextImageRealOffsetY;
|
|
450
|
+
if (this.currentAction !== import_constant.ACTION_PINCH) {
|
|
451
|
+
const maxOffsets = this.getMaxOffsets();
|
|
452
|
+
if (this.state.zoomLevel > nextZoomLevel) {
|
|
453
|
+
nextOffsetX = Math.max(maxOffsets.minX, Math.min(maxOffsets.maxX, nextOffsetX));
|
|
454
|
+
nextOffsetY = Math.max(maxOffsets.minY, Math.min(maxOffsets.maxY, nextOffsetY));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
this.setState({
|
|
458
|
+
zoomLevel: nextZoomLevel,
|
|
459
|
+
offsetX: nextOffsetX,
|
|
460
|
+
offsetY: nextOffsetY
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
closeIfClickInner(event) {
|
|
464
|
+
if (!this.preventInnerClose && event.target.className.search(/\bril-inner\b/) > -1) {
|
|
465
|
+
this.requestClose(event);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Handle user keyboard actions
|
|
470
|
+
*/
|
|
471
|
+
handleKeyInput(event) {
|
|
472
|
+
event.stopPropagation();
|
|
473
|
+
if (this.isAnimating()) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (event.type === "keyup") {
|
|
477
|
+
this.lastKeyDownTime -= this.props.keyRepeatKeyupBonus;
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const keyCode = event.which || event.keyCode;
|
|
481
|
+
const currentTime = /* @__PURE__ */ new Date();
|
|
482
|
+
if (currentTime.getTime() - this.lastKeyDownTime < this.props.keyRepeatLimit && keyCode !== import_constant.KEYS.ESC) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
this.lastKeyDownTime = currentTime.getTime();
|
|
486
|
+
switch (keyCode) {
|
|
487
|
+
// ESC key closes the lightbox
|
|
488
|
+
case import_constant.KEYS.ESC:
|
|
489
|
+
event.preventDefault();
|
|
490
|
+
this.requestClose(event);
|
|
491
|
+
break;
|
|
492
|
+
// Left arrow key moves to previous image
|
|
493
|
+
case import_constant.KEYS.LEFT_ARROW:
|
|
494
|
+
if (!this.props.prevSrc) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
event.preventDefault();
|
|
498
|
+
this.keyPressed = true;
|
|
499
|
+
this.requestMovePrev(event);
|
|
500
|
+
break;
|
|
501
|
+
// Right arrow key moves to next image
|
|
502
|
+
case import_constant.KEYS.RIGHT_ARROW:
|
|
503
|
+
if (!this.props.nextSrc) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
event.preventDefault();
|
|
507
|
+
this.keyPressed = true;
|
|
508
|
+
this.requestMoveNext(event);
|
|
509
|
+
break;
|
|
510
|
+
default:
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Handle a mouse wheel event over the lightbox container
|
|
515
|
+
*/
|
|
516
|
+
handleOuterMousewheel(event) {
|
|
517
|
+
event.stopPropagation();
|
|
518
|
+
const xThreshold = import_constant.WHEEL_MOVE_X_THRESHOLD;
|
|
519
|
+
let actionDelay = 0;
|
|
520
|
+
const imageMoveDelay = 500;
|
|
521
|
+
this.clearTimeout(this.resetScrollTimeout);
|
|
522
|
+
this.resetScrollTimeout = this.setTimeout(() => {
|
|
523
|
+
this.scrollX = 0;
|
|
524
|
+
this.scrollY = 0;
|
|
525
|
+
}, 300);
|
|
526
|
+
if (this.wheelActionTimeout !== null || this.isAnimating()) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (Math.abs(event.deltaY) < Math.abs(event.deltaX)) {
|
|
530
|
+
this.scrollY = 0;
|
|
531
|
+
this.scrollX += event.deltaX;
|
|
532
|
+
const bigLeapX = xThreshold / 2;
|
|
533
|
+
if (this.scrollX >= xThreshold || event.deltaX >= bigLeapX) {
|
|
534
|
+
this.requestMoveNext(event);
|
|
535
|
+
actionDelay = imageMoveDelay;
|
|
536
|
+
this.scrollX = 0;
|
|
537
|
+
} else if (this.scrollX <= -1 * xThreshold || event.deltaX <= -1 * bigLeapX) {
|
|
538
|
+
this.requestMovePrev(event);
|
|
539
|
+
actionDelay = imageMoveDelay;
|
|
540
|
+
this.scrollX = 0;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (actionDelay !== 0) {
|
|
544
|
+
this.wheelActionTimeout = this.setTimeout(() => {
|
|
545
|
+
this.wheelActionTimeout = null;
|
|
546
|
+
}, actionDelay);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
handleImageMouseWheel(event) {
|
|
550
|
+
const yThreshold = import_constant.WHEEL_MOVE_Y_THRESHOLD;
|
|
551
|
+
if (Math.abs(event.deltaY) >= Math.abs(event.deltaX)) {
|
|
552
|
+
event.stopPropagation();
|
|
553
|
+
if (Math.abs(event.deltaY) < yThreshold) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
this.scrollX = 0;
|
|
557
|
+
this.scrollY += event.deltaY;
|
|
558
|
+
this.changeZoom(this.state.zoomLevel - event.deltaY, event.clientX, event.clientY);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Handle a double click on the current image
|
|
563
|
+
*/
|
|
564
|
+
handleImageDoubleClick(event) {
|
|
565
|
+
if (this.state.zoomLevel > import_constant.MIN_ZOOM_LEVEL) {
|
|
566
|
+
this.changeZoom(import_constant.MIN_ZOOM_LEVEL, event.clientX, event.clientY);
|
|
567
|
+
} else {
|
|
568
|
+
this.changeZoom(this.state.zoomLevel + import_constant.ZOOM_BUTTON_INCREMENT_SIZE, event.clientX, event.clientY);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
shouldHandleEvent(source) {
|
|
572
|
+
if (this.eventsSource === source) {
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
if (this.eventsSource === import_constant.SOURCE_ANY) {
|
|
576
|
+
this.eventsSource = source;
|
|
577
|
+
return true;
|
|
578
|
+
}
|
|
579
|
+
switch (source) {
|
|
580
|
+
case import_constant.SOURCE_MOUSE:
|
|
581
|
+
return false;
|
|
582
|
+
case import_constant.SOURCE_TOUCH:
|
|
583
|
+
this.eventsSource = import_constant.SOURCE_TOUCH;
|
|
584
|
+
this.filterPointersBySource();
|
|
585
|
+
return true;
|
|
586
|
+
case import_constant.SOURCE_POINTER:
|
|
587
|
+
if (this.eventsSource === import_constant.SOURCE_MOUSE) {
|
|
588
|
+
this.eventsSource = import_constant.SOURCE_POINTER;
|
|
589
|
+
this.filterPointersBySource();
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
return false;
|
|
593
|
+
default:
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
addPointer(pointer) {
|
|
598
|
+
this.pointerList.push(pointer);
|
|
599
|
+
}
|
|
600
|
+
removePointer(pointer) {
|
|
601
|
+
this.pointerList = this.pointerList.filter(({ id }) => id !== pointer.id);
|
|
602
|
+
}
|
|
603
|
+
filterPointersBySource() {
|
|
604
|
+
this.pointerList = this.pointerList.filter(({ source }) => source === this.eventsSource);
|
|
605
|
+
}
|
|
606
|
+
handleMouseDown(event) {
|
|
607
|
+
if (this.shouldHandleEvent(import_constant.SOURCE_MOUSE) && _ReactImageLightbox.isTargetMatchImage(event.target)) {
|
|
608
|
+
this.addPointer(_ReactImageLightbox.parseMouseEvent(event));
|
|
609
|
+
this.multiPointerStart(event);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
handleMouseMove(event) {
|
|
613
|
+
if (this.shouldHandleEvent(import_constant.SOURCE_MOUSE)) {
|
|
614
|
+
this.multiPointerMove(event, [_ReactImageLightbox.parseMouseEvent(event)]);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
handleMouseUp(event) {
|
|
618
|
+
if (this.shouldHandleEvent(import_constant.SOURCE_MOUSE)) {
|
|
619
|
+
this.removePointer(_ReactImageLightbox.parseMouseEvent(event));
|
|
620
|
+
this.multiPointerEnd(event);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
handlePointerEvent(event) {
|
|
624
|
+
if (this.shouldHandleEvent(import_constant.SOURCE_POINTER)) {
|
|
625
|
+
switch (event.type) {
|
|
626
|
+
case "pointerdown":
|
|
627
|
+
if (_ReactImageLightbox.isTargetMatchImage(event.target)) {
|
|
628
|
+
this.addPointer(_ReactImageLightbox.parsePointerEvent(event));
|
|
629
|
+
this.multiPointerStart(event);
|
|
630
|
+
}
|
|
631
|
+
break;
|
|
632
|
+
case "pointermove":
|
|
633
|
+
this.multiPointerMove(event, [_ReactImageLightbox.parsePointerEvent(event)]);
|
|
634
|
+
break;
|
|
635
|
+
case "pointerup":
|
|
636
|
+
case "pointercancel":
|
|
637
|
+
this.removePointer(_ReactImageLightbox.parsePointerEvent(event));
|
|
638
|
+
this.multiPointerEnd(event);
|
|
639
|
+
break;
|
|
640
|
+
default:
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
handleTouchStart(event) {
|
|
646
|
+
if (this.shouldHandleEvent(import_constant.SOURCE_TOUCH) && _ReactImageLightbox.isTargetMatchImage(event.target)) {
|
|
647
|
+
[].forEach.call(
|
|
648
|
+
event.changedTouches,
|
|
649
|
+
(eventTouch) => this.addPointer(_ReactImageLightbox.parseTouchPointer(eventTouch))
|
|
650
|
+
);
|
|
651
|
+
this.multiPointerStart(event);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
handleTouchMove(event) {
|
|
655
|
+
if (this.shouldHandleEvent(import_constant.SOURCE_TOUCH)) {
|
|
656
|
+
this.multiPointerMove(
|
|
657
|
+
event,
|
|
658
|
+
[].map.call(event.changedTouches, (eventTouch) => _ReactImageLightbox.parseTouchPointer(eventTouch))
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
handleTouchEnd(event) {
|
|
663
|
+
if (this.shouldHandleEvent(import_constant.SOURCE_TOUCH)) {
|
|
664
|
+
[].map.call(event.changedTouches, (touch) => this.removePointer(_ReactImageLightbox.parseTouchPointer(touch)));
|
|
665
|
+
this.multiPointerEnd(event);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
decideMoveOrSwipe(pointer) {
|
|
669
|
+
if (this.state.zoomLevel <= import_constant.MIN_ZOOM_LEVEL) {
|
|
670
|
+
this.handleSwipeStart(pointer);
|
|
671
|
+
} else {
|
|
672
|
+
this.handleMoveStart(pointer);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
multiPointerStart(event) {
|
|
676
|
+
this.handleEnd(null);
|
|
677
|
+
switch (this.pointerList.length) {
|
|
678
|
+
case 1: {
|
|
679
|
+
event.preventDefault();
|
|
680
|
+
this.decideMoveOrSwipe(this.pointerList[0]);
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
case 2: {
|
|
684
|
+
event.preventDefault();
|
|
685
|
+
this.handlePinchStart(this.pointerList);
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
default:
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
multiPointerMove(event, pointerList) {
|
|
693
|
+
switch (this.currentAction) {
|
|
694
|
+
case import_constant.ACTION_MOVE: {
|
|
695
|
+
event.preventDefault();
|
|
696
|
+
this.handleMove(pointerList[0]);
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
case import_constant.ACTION_SWIPE: {
|
|
700
|
+
event.preventDefault();
|
|
701
|
+
this.handleSwipe(pointerList[0]);
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
case import_constant.ACTION_PINCH: {
|
|
705
|
+
event.preventDefault();
|
|
706
|
+
this.handlePinch(pointerList);
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
default:
|
|
710
|
+
break;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
multiPointerEnd(event) {
|
|
714
|
+
if (this.currentAction !== import_constant.ACTION_NONE) {
|
|
715
|
+
this.setPreventInnerClose();
|
|
716
|
+
this.handleEnd(event);
|
|
717
|
+
}
|
|
718
|
+
switch (this.pointerList.length) {
|
|
719
|
+
case 0: {
|
|
720
|
+
this.eventsSource = import_constant.SOURCE_ANY;
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
723
|
+
case 1: {
|
|
724
|
+
event.preventDefault();
|
|
725
|
+
this.decideMoveOrSwipe(this.pointerList[0]);
|
|
726
|
+
break;
|
|
727
|
+
}
|
|
728
|
+
case 2: {
|
|
729
|
+
event.preventDefault();
|
|
730
|
+
this.handlePinchStart(this.pointerList);
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
default:
|
|
734
|
+
break;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
handleEnd(event) {
|
|
738
|
+
switch (this.currentAction) {
|
|
739
|
+
case import_constant.ACTION_MOVE:
|
|
740
|
+
this.handleMoveEnd(event);
|
|
741
|
+
break;
|
|
742
|
+
case import_constant.ACTION_SWIPE:
|
|
743
|
+
this.handleSwipeEnd(event);
|
|
744
|
+
break;
|
|
745
|
+
case import_constant.ACTION_PINCH:
|
|
746
|
+
this.handlePinchEnd(event);
|
|
747
|
+
break;
|
|
748
|
+
default:
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
// Handle move start over the lightbox container
|
|
753
|
+
// This happens:
|
|
754
|
+
// - On a mouseDown event
|
|
755
|
+
// - On a touchstart event
|
|
756
|
+
handleMoveStart({ x: clientX, y: clientY }) {
|
|
757
|
+
if (!this.props.enableZoom) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
this.currentAction = import_constant.ACTION_MOVE;
|
|
761
|
+
this.moveStartX = clientX;
|
|
762
|
+
this.moveStartY = clientY;
|
|
763
|
+
this.moveStartOffsetX = this.state.offsetX;
|
|
764
|
+
this.moveStartOffsetY = this.state.offsetY;
|
|
765
|
+
}
|
|
766
|
+
// Handle dragging over the lightbox container
|
|
767
|
+
// This happens:
|
|
768
|
+
// - After a mouseDown and before a mouseUp event
|
|
769
|
+
// - After a touchstart and before a touchend event
|
|
770
|
+
handleMove({ x: clientX, y: clientY }) {
|
|
771
|
+
const newOffsetX = this.moveStartX - clientX + this.moveStartOffsetX;
|
|
772
|
+
const newOffsetY = this.moveStartY - clientY + this.moveStartOffsetY;
|
|
773
|
+
if (this.state.offsetX !== newOffsetX || this.state.offsetY !== newOffsetY) {
|
|
774
|
+
this.setState({
|
|
775
|
+
offsetX: newOffsetX,
|
|
776
|
+
offsetY: newOffsetY
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
handleMoveEnd(event) {
|
|
781
|
+
this.currentAction = import_constant.ACTION_NONE;
|
|
782
|
+
this.moveStartX = 0;
|
|
783
|
+
this.moveStartY = 0;
|
|
784
|
+
this.moveStartOffsetX = 0;
|
|
785
|
+
this.moveStartOffsetY = 0;
|
|
786
|
+
const maxOffsets = this.getMaxOffsets();
|
|
787
|
+
const nextOffsetX = Math.max(maxOffsets.minX, Math.min(maxOffsets.maxX, this.state.offsetX));
|
|
788
|
+
const nextOffsetY = Math.max(maxOffsets.minY, Math.min(maxOffsets.maxY, this.state.offsetY));
|
|
789
|
+
if (nextOffsetX !== this.state.offsetX || nextOffsetY !== this.state.offsetY) {
|
|
790
|
+
this.setState({
|
|
791
|
+
offsetX: nextOffsetX,
|
|
792
|
+
offsetY: nextOffsetY,
|
|
793
|
+
shouldAnimate: true
|
|
794
|
+
});
|
|
795
|
+
this.setTimeout(() => {
|
|
796
|
+
this.setState({ shouldAnimate: false });
|
|
797
|
+
}, this.props.animationDuration);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
handleSwipeStart({ x: clientX, y: clientY }) {
|
|
801
|
+
this.currentAction = import_constant.ACTION_SWIPE;
|
|
802
|
+
this.swipeStartX = clientX;
|
|
803
|
+
this.swipeStartY = clientY;
|
|
804
|
+
this.swipeEndX = clientX;
|
|
805
|
+
this.swipeEndY = clientY;
|
|
806
|
+
}
|
|
807
|
+
handleSwipe({ x: clientX, y: clientY }) {
|
|
808
|
+
this.swipeEndX = clientX;
|
|
809
|
+
this.swipeEndY = clientY;
|
|
810
|
+
}
|
|
811
|
+
handleSwipeEnd(event) {
|
|
812
|
+
const xDiff = this.swipeEndX - this.swipeStartX;
|
|
813
|
+
const xDiffAbs = Math.abs(xDiff);
|
|
814
|
+
const yDiffAbs = Math.abs(this.swipeEndY - this.swipeStartY);
|
|
815
|
+
this.currentAction = import_constant.ACTION_NONE;
|
|
816
|
+
this.swipeStartX = 0;
|
|
817
|
+
this.swipeStartY = 0;
|
|
818
|
+
this.swipeEndX = 0;
|
|
819
|
+
this.swipeEndY = 0;
|
|
820
|
+
if (!event || this.isAnimating() || xDiffAbs < yDiffAbs * 1.5) {
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
if (xDiffAbs < import_constant.MIN_SWIPE_DISTANCE) {
|
|
824
|
+
const boxRect = this.getLightboxRect();
|
|
825
|
+
if (xDiffAbs < boxRect.width / 4) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
if (xDiff > 0 && this.props.prevSrc) {
|
|
830
|
+
event.preventDefault();
|
|
831
|
+
this.requestMovePrev();
|
|
832
|
+
} else if (xDiff < 0 && this.props.nextSrc) {
|
|
833
|
+
event.preventDefault();
|
|
834
|
+
this.requestMoveNext();
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
calculatePinchDistance([a, b] = this.pinchTouchList) {
|
|
838
|
+
return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
|
|
839
|
+
}
|
|
840
|
+
calculatePinchCenter([a, b] = this.pinchTouchList) {
|
|
841
|
+
return {
|
|
842
|
+
x: a.x - (a.x - b.x) / 2,
|
|
843
|
+
y: a.y - (a.y - b.y) / 2
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
handlePinchStart(pointerList) {
|
|
847
|
+
if (!this.props.enableZoom) {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
this.currentAction = import_constant.ACTION_PINCH;
|
|
851
|
+
this.pinchTouchList = pointerList.map(({ id, x, y }) => ({ id, x, y }));
|
|
852
|
+
this.pinchDistance = this.calculatePinchDistance();
|
|
853
|
+
}
|
|
854
|
+
handlePinch(pointerList) {
|
|
855
|
+
this.pinchTouchList = this.pinchTouchList.map((oldPointer) => {
|
|
856
|
+
for (let i = 0; i < pointerList.length; i += 1) {
|
|
857
|
+
if (pointerList[i].id === oldPointer.id) {
|
|
858
|
+
return pointerList[i];
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return oldPointer;
|
|
862
|
+
});
|
|
863
|
+
const newDistance = this.calculatePinchDistance();
|
|
864
|
+
const zoomLevel = this.state.zoomLevel + newDistance - this.pinchDistance;
|
|
865
|
+
this.pinchDistance = newDistance;
|
|
866
|
+
const { x: clientX, y: clientY } = this.calculatePinchCenter(this.pinchTouchList);
|
|
867
|
+
this.changeZoom(zoomLevel, clientX, clientY);
|
|
868
|
+
}
|
|
869
|
+
handlePinchEnd(event) {
|
|
870
|
+
this.currentAction = import_constant.ACTION_NONE;
|
|
871
|
+
this.pinchTouchList = null;
|
|
872
|
+
this.pinchDistance = 0;
|
|
873
|
+
}
|
|
874
|
+
// Handle the window resize event
|
|
875
|
+
handleWindowResize() {
|
|
876
|
+
this.clearTimeout(this.resizeTimeout);
|
|
877
|
+
this.resizeTimeout = this.setTimeout(this.forceUpdate.bind(this), 100);
|
|
878
|
+
}
|
|
879
|
+
handleZoomInButtonClick() {
|
|
880
|
+
const nextZoomLevel = this.state.zoomLevel + import_constant.ZOOM_BUTTON_INCREMENT_SIZE;
|
|
881
|
+
this.changeZoom(nextZoomLevel);
|
|
882
|
+
if (nextZoomLevel === import_constant.MAX_ZOOM_LEVEL) {
|
|
883
|
+
this.zoomOutBtn.current.focus();
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
handleZoomOutButtonClick() {
|
|
887
|
+
const nextZoomLevel = this.state.zoomLevel - import_constant.ZOOM_BUTTON_INCREMENT_SIZE;
|
|
888
|
+
this.changeZoom(nextZoomLevel);
|
|
889
|
+
if (nextZoomLevel === import_constant.MIN_ZOOM_LEVEL) {
|
|
890
|
+
this.zoomInBtn.current.focus();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
handleCaptionMousewheel(event) {
|
|
894
|
+
event.stopPropagation();
|
|
895
|
+
if (!this.caption.current) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const { height } = this.caption.current.getBoundingClientRect();
|
|
899
|
+
const { scrollHeight, scrollTop } = this.caption.current;
|
|
900
|
+
if (event.deltaY > 0 && height + scrollTop >= scrollHeight || event.deltaY < 0 && scrollTop <= 0) {
|
|
901
|
+
event.preventDefault();
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
// Detach key and mouse input events
|
|
905
|
+
isAnimating() {
|
|
906
|
+
return this.state.shouldAnimate || this.state.isClosing;
|
|
907
|
+
}
|
|
908
|
+
// Check if image is loaded
|
|
909
|
+
isImageLoaded(imageSrc) {
|
|
910
|
+
return imageSrc && imageSrc in this.imageCache && this.imageCache[imageSrc].loaded;
|
|
911
|
+
}
|
|
912
|
+
// Load image from src and call callback with image width and height on load
|
|
913
|
+
loadImage(srcType, imageSrc, done) {
|
|
914
|
+
if (this.isImageLoaded(imageSrc)) {
|
|
915
|
+
this.setTimeout(() => {
|
|
916
|
+
done();
|
|
917
|
+
}, 1);
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
const inMemoryImage = new global.Image();
|
|
921
|
+
if (this.props.imageCrossOrigin) {
|
|
922
|
+
inMemoryImage.crossOrigin = this.props.imageCrossOrigin;
|
|
923
|
+
}
|
|
924
|
+
inMemoryImage.onerror = (errorEvent) => {
|
|
925
|
+
this.props.onImageLoadError(imageSrc, srcType, errorEvent);
|
|
926
|
+
this.setState((prevState) => ({
|
|
927
|
+
loadErrorStatus: { ...prevState.loadErrorStatus, [srcType]: true }
|
|
928
|
+
}));
|
|
929
|
+
done(errorEvent);
|
|
930
|
+
};
|
|
931
|
+
inMemoryImage.onload = () => {
|
|
932
|
+
this.props.onImageLoad(imageSrc, srcType, inMemoryImage);
|
|
933
|
+
this.imageCache[imageSrc] = {
|
|
934
|
+
loaded: true,
|
|
935
|
+
width: inMemoryImage.width,
|
|
936
|
+
height: inMemoryImage.height
|
|
937
|
+
};
|
|
938
|
+
done();
|
|
939
|
+
};
|
|
940
|
+
inMemoryImage.src = imageSrc;
|
|
941
|
+
}
|
|
942
|
+
// Load all images and their thumbnails
|
|
943
|
+
loadAllImages(props = this.props) {
|
|
944
|
+
const generateLoadDoneCallback = /* @__PURE__ */ __name((srcType, imageSrc) => (err) => {
|
|
945
|
+
if (err) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
if (this.props[srcType] !== imageSrc || this.didUnmount) {
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
this.forceUpdate();
|
|
952
|
+
}, "generateLoadDoneCallback");
|
|
953
|
+
this.getSrcTypes().forEach((srcType) => {
|
|
954
|
+
const type = srcType.name;
|
|
955
|
+
if (props[type] && this.state.loadErrorStatus[type]) {
|
|
956
|
+
this.setState((prevState) => ({
|
|
957
|
+
loadErrorStatus: { ...prevState.loadErrorStatus, [type]: false }
|
|
958
|
+
}));
|
|
959
|
+
}
|
|
960
|
+
if (props[type] && !this.isImageLoaded(props[type])) {
|
|
961
|
+
this.loadImage(type, props[type], generateLoadDoneCallback(type, props[type]));
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
// Request that the lightbox be closed
|
|
966
|
+
requestClose(event) {
|
|
967
|
+
const closeLightbox = /* @__PURE__ */ __name(() => this.props.onCloseRequest(event), "closeLightbox");
|
|
968
|
+
if (this.props.animationDisabled || event.type === "keydown" && !this.props.animationOnKeyInput) {
|
|
969
|
+
closeLightbox();
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
this.setState({ isClosing: true });
|
|
973
|
+
this.setTimeout(closeLightbox, this.props.animationDuration);
|
|
974
|
+
}
|
|
975
|
+
requestMove(direction, event) {
|
|
976
|
+
const nextState = {
|
|
977
|
+
zoomLevel: import_constant.MIN_ZOOM_LEVEL,
|
|
978
|
+
offsetX: 0,
|
|
979
|
+
offsetY: 0
|
|
980
|
+
};
|
|
981
|
+
if (!this.props.animationDisabled && (!this.keyPressed || this.props.animationOnKeyInput)) {
|
|
982
|
+
nextState.shouldAnimate = true;
|
|
983
|
+
this.setTimeout(() => this.setState({ shouldAnimate: false }), this.props.animationDuration);
|
|
984
|
+
}
|
|
985
|
+
this.keyPressed = false;
|
|
986
|
+
this.moveRequested = true;
|
|
987
|
+
if (direction === "prev") {
|
|
988
|
+
this.keyCounter -= 1;
|
|
989
|
+
this.setState(nextState);
|
|
990
|
+
this.props.onMovePrevRequest(event);
|
|
991
|
+
} else {
|
|
992
|
+
this.keyCounter += 1;
|
|
993
|
+
this.setState(nextState);
|
|
994
|
+
this.props.onMoveNextRequest(event);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
// Request to transition to the next image
|
|
998
|
+
requestMoveNext(event) {
|
|
999
|
+
this.requestMove("next", event);
|
|
1000
|
+
}
|
|
1001
|
+
// Request to transition to the previous image
|
|
1002
|
+
requestMovePrev(event) {
|
|
1003
|
+
this.requestMove("prev", event);
|
|
1004
|
+
}
|
|
1005
|
+
render() {
|
|
1006
|
+
const {
|
|
1007
|
+
animationDisabled,
|
|
1008
|
+
animationDuration,
|
|
1009
|
+
clickOutsideToClose,
|
|
1010
|
+
discourageDownloads,
|
|
1011
|
+
enableZoom,
|
|
1012
|
+
imageTitle,
|
|
1013
|
+
nextSrc,
|
|
1014
|
+
prevSrc,
|
|
1015
|
+
mainFile,
|
|
1016
|
+
nextFile,
|
|
1017
|
+
prevFile,
|
|
1018
|
+
previewList,
|
|
1019
|
+
toolbarButtons,
|
|
1020
|
+
reactModalStyle,
|
|
1021
|
+
onAfterOpen,
|
|
1022
|
+
imageCrossOrigin,
|
|
1023
|
+
reactModalProps,
|
|
1024
|
+
loader
|
|
1025
|
+
} = this.props;
|
|
1026
|
+
const { zoomLevel, offsetX, offsetY, isClosing, loadErrorStatus } = this.state;
|
|
1027
|
+
const boxSize = this.getLightboxRect();
|
|
1028
|
+
let transitionStyle = {};
|
|
1029
|
+
if (!animationDisabled && this.isAnimating()) {
|
|
1030
|
+
transitionStyle = {
|
|
1031
|
+
...transitionStyle,
|
|
1032
|
+
transition: `transform ${animationDuration}ms`
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
const keyEndings = {};
|
|
1036
|
+
this.getSrcTypes().forEach(({ name, keyEnding }) => {
|
|
1037
|
+
keyEndings[name] = keyEnding;
|
|
1038
|
+
});
|
|
1039
|
+
const images = [];
|
|
1040
|
+
const addImage = /* @__PURE__ */ __name((srcType, imageClass, transforms) => {
|
|
1041
|
+
var _a, _b, _c;
|
|
1042
|
+
const fieldType = (_a = this.props[srcType]) == null ? void 0 : _a.mimetype;
|
|
1043
|
+
const { checkedComponent } = previewList[fieldType] || previewList["default"];
|
|
1044
|
+
const bestImageInfo = ((_b = this.props[srcType]) == null ? void 0 : _b.mimetype).includes("image") ? this.getBestImageForType(srcType, (_c = this.props[srcType]) == null ? void 0 : _c.imageUrl) : {};
|
|
1045
|
+
const imageStyle = {
|
|
1046
|
+
...transitionStyle,
|
|
1047
|
+
..._ReactImageLightbox.getTransform({
|
|
1048
|
+
...transforms,
|
|
1049
|
+
height: boxSize.height - 20,
|
|
1050
|
+
width: boxSize.width - 20,
|
|
1051
|
+
targetWidth: boxSize.width - 50,
|
|
1052
|
+
targeHeight: boxSize.height - 50,
|
|
1053
|
+
...bestImageInfo
|
|
1054
|
+
})
|
|
1055
|
+
};
|
|
1056
|
+
if (zoomLevel > import_constant.MIN_ZOOM_LEVEL) {
|
|
1057
|
+
imageStyle.cursor = "move";
|
|
1058
|
+
}
|
|
1059
|
+
images.push(
|
|
1060
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
1061
|
+
"div",
|
|
1062
|
+
{
|
|
1063
|
+
className: `${imageClass} ril__image`,
|
|
1064
|
+
style: {
|
|
1065
|
+
...imageStyle,
|
|
1066
|
+
width: (bestImageInfo == null ? void 0 : bestImageInfo.width) || "90%",
|
|
1067
|
+
height: "90%",
|
|
1068
|
+
display: "flex",
|
|
1069
|
+
justifyContent: "center",
|
|
1070
|
+
alignItems: "center"
|
|
1071
|
+
}
|
|
1072
|
+
},
|
|
1073
|
+
checkedComponent({
|
|
1074
|
+
key: `${fieldType + keyEndings[srcType]}`,
|
|
1075
|
+
onDoubleClick: this.handleImageDoubleClick,
|
|
1076
|
+
onWheel: this.handleImageMouseWheel,
|
|
1077
|
+
onDragStart: /* @__PURE__ */ __name((e) => e.preventDefault(), "onDragStart"),
|
|
1078
|
+
file: this.props[srcType],
|
|
1079
|
+
bestImageInfo,
|
|
1080
|
+
mimetype: fieldType
|
|
1081
|
+
})
|
|
1082
|
+
)
|
|
1083
|
+
);
|
|
1084
|
+
}, "addImage");
|
|
1085
|
+
const zoomMultiplier = this.getZoomMultiplier();
|
|
1086
|
+
addImage("nextFile", "ril-image-next ril__imageNext", {
|
|
1087
|
+
x: boxSize.width
|
|
1088
|
+
});
|
|
1089
|
+
addImage("mainFile", "ril-image-current", {
|
|
1090
|
+
x: -1 * offsetX,
|
|
1091
|
+
y: -1 * offsetY,
|
|
1092
|
+
zoom: zoomMultiplier
|
|
1093
|
+
});
|
|
1094
|
+
addImage("prevFile", "ril-image-prev ril__imagePrev", {
|
|
1095
|
+
x: -1 * boxSize.width
|
|
1096
|
+
});
|
|
1097
|
+
const modalStyle = {
|
|
1098
|
+
overlay: {
|
|
1099
|
+
zIndex: 1e3,
|
|
1100
|
+
backgroundColor: "transparent",
|
|
1101
|
+
...reactModalStyle.overlay
|
|
1102
|
+
// Allow style overrides via props
|
|
1103
|
+
},
|
|
1104
|
+
content: {
|
|
1105
|
+
backgroundColor: "transparent",
|
|
1106
|
+
overflow: "hidden",
|
|
1107
|
+
// Needed, otherwise keyboard shortcuts scroll the page
|
|
1108
|
+
border: "none",
|
|
1109
|
+
borderRadius: 0,
|
|
1110
|
+
padding: 0,
|
|
1111
|
+
top: 0,
|
|
1112
|
+
left: 0,
|
|
1113
|
+
right: 0,
|
|
1114
|
+
bottom: 0,
|
|
1115
|
+
...reactModalStyle.content
|
|
1116
|
+
// Allow style overrides via props
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
1120
|
+
import_react_modal.default,
|
|
1121
|
+
{
|
|
1122
|
+
isOpen: true,
|
|
1123
|
+
onRequestClose: clickOutsideToClose ? this.requestClose : void 0,
|
|
1124
|
+
onAfterOpen: () => {
|
|
1125
|
+
if (this.outerEl.current) {
|
|
1126
|
+
this.outerEl.current.focus();
|
|
1127
|
+
}
|
|
1128
|
+
onAfterOpen();
|
|
1129
|
+
},
|
|
1130
|
+
style: modalStyle,
|
|
1131
|
+
contentLabel: (0, import_util.translate)("Lightbox"),
|
|
1132
|
+
appElement: typeof global.window !== "undefined" ? global.window.document.body : void 0,
|
|
1133
|
+
...reactModalProps
|
|
1134
|
+
},
|
|
1135
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
1136
|
+
"div",
|
|
1137
|
+
{
|
|
1138
|
+
className: `ril-outer ril__outer ril__outerAnimating ${this.props.wrapperClassName} ${isClosing ? "ril-closing ril__outerClosing" : ""}`,
|
|
1139
|
+
style: {
|
|
1140
|
+
transition: `opacity ${animationDuration}ms`,
|
|
1141
|
+
animationDuration: `${animationDuration}ms`,
|
|
1142
|
+
animationDirection: isClosing ? "normal" : "reverse"
|
|
1143
|
+
},
|
|
1144
|
+
ref: this.outerEl,
|
|
1145
|
+
onWheel: this.handleOuterMousewheel,
|
|
1146
|
+
onMouseMove: this.handleMouseMove,
|
|
1147
|
+
onMouseDown: this.handleMouseDown,
|
|
1148
|
+
onTouchStart: this.handleTouchStart,
|
|
1149
|
+
onTouchMove: this.handleTouchMove,
|
|
1150
|
+
tabIndex: "-1",
|
|
1151
|
+
onKeyDown: this.handleKeyInput,
|
|
1152
|
+
onKeyUp: this.handleKeyInput
|
|
1153
|
+
},
|
|
1154
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
1155
|
+
"div",
|
|
1156
|
+
{
|
|
1157
|
+
className: "ril-inner ril__inner",
|
|
1158
|
+
onClick: clickOutsideToClose ? this.closeIfClickInner : void 0
|
|
1159
|
+
},
|
|
1160
|
+
images
|
|
1161
|
+
),
|
|
1162
|
+
prevSrc && /* @__PURE__ */ import_react.default.createElement(
|
|
1163
|
+
"button",
|
|
1164
|
+
{
|
|
1165
|
+
type: "button",
|
|
1166
|
+
className: "ril-prev-button ril__navButtons ril__navButtonPrev",
|
|
1167
|
+
key: "prev",
|
|
1168
|
+
"aria-label": this.props.prevLabel,
|
|
1169
|
+
title: this.props.prevLabel,
|
|
1170
|
+
onClick: !this.isAnimating() ? this.requestMovePrev : void 0
|
|
1171
|
+
}
|
|
1172
|
+
),
|
|
1173
|
+
nextSrc && /* @__PURE__ */ import_react.default.createElement(
|
|
1174
|
+
"button",
|
|
1175
|
+
{
|
|
1176
|
+
type: "button",
|
|
1177
|
+
className: "ril-next-button ril__navButtons ril__navButtonNext",
|
|
1178
|
+
key: "next",
|
|
1179
|
+
"aria-label": this.props.nextLabel,
|
|
1180
|
+
title: this.props.nextLabel,
|
|
1181
|
+
onClick: !this.isAnimating() ? this.requestMoveNext : void 0
|
|
1182
|
+
}
|
|
1183
|
+
),
|
|
1184
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
1185
|
+
"div",
|
|
1186
|
+
{
|
|
1187
|
+
className: "ril-toolbar ril__toolbar"
|
|
1188
|
+
},
|
|
1189
|
+
/* @__PURE__ */ import_react.default.createElement("ul", { className: "ril-toolbar-left ril__toolbarSide ril__toolbarLeftSide" }, /* @__PURE__ */ import_react.default.createElement("li", { className: "ril-toolbar__item ril__toolbarItem" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "ril-toolbar__item__child ril__toolbarItemChild" }, imageTitle))),
|
|
1190
|
+
/* @__PURE__ */ import_react.default.createElement("ul", { className: "ril-toolbar-right ril__toolbarSide ril__toolbarRightSide" }, toolbarButtons && toolbarButtons.map((button, i) => /* @__PURE__ */ import_react.default.createElement("li", { key: `button_${i + 1}`, className: "ril-toolbar__item ril__toolbarItem" }, button)), enableZoom && /* @__PURE__ */ import_react.default.createElement("li", { className: "ril-toolbar__item ril__toolbarItem" }, /* @__PURE__ */ import_react.default.createElement(
|
|
1191
|
+
"button",
|
|
1192
|
+
{
|
|
1193
|
+
type: "button",
|
|
1194
|
+
key: "zoom-in",
|
|
1195
|
+
"aria-label": this.props.zoomInLabel,
|
|
1196
|
+
title: this.props.zoomInLabel,
|
|
1197
|
+
className: [
|
|
1198
|
+
"ril-zoom-in",
|
|
1199
|
+
"ril__toolbarItemChild",
|
|
1200
|
+
"ril__builtinButton",
|
|
1201
|
+
"ril__zoomInButton",
|
|
1202
|
+
...zoomLevel === import_constant.MAX_ZOOM_LEVEL ? ["ril__builtinButtonDisabled"] : []
|
|
1203
|
+
].join(" "),
|
|
1204
|
+
ref: this.zoomInBtn,
|
|
1205
|
+
disabled: this.isAnimating() || zoomLevel === import_constant.MAX_ZOOM_LEVEL,
|
|
1206
|
+
onClick: !this.isAnimating() && zoomLevel !== import_constant.MAX_ZOOM_LEVEL ? this.handleZoomInButtonClick : void 0
|
|
1207
|
+
}
|
|
1208
|
+
)), enableZoom && /* @__PURE__ */ import_react.default.createElement("li", { className: "ril-toolbar__item ril__toolbarItem" }, /* @__PURE__ */ import_react.default.createElement(
|
|
1209
|
+
"button",
|
|
1210
|
+
{
|
|
1211
|
+
type: "button",
|
|
1212
|
+
key: "zoom-out",
|
|
1213
|
+
"aria-label": this.props.zoomOutLabel,
|
|
1214
|
+
title: this.props.zoomOutLabel,
|
|
1215
|
+
className: [
|
|
1216
|
+
"ril-zoom-out",
|
|
1217
|
+
"ril__toolbarItemChild",
|
|
1218
|
+
"ril__builtinButton",
|
|
1219
|
+
"ril__zoomOutButton",
|
|
1220
|
+
...zoomLevel === import_constant.MIN_ZOOM_LEVEL ? ["ril__builtinButtonDisabled"] : []
|
|
1221
|
+
].join(" "),
|
|
1222
|
+
ref: this.zoomOutBtn,
|
|
1223
|
+
disabled: this.isAnimating() || zoomLevel === import_constant.MIN_ZOOM_LEVEL,
|
|
1224
|
+
onClick: !this.isAnimating() && zoomLevel !== import_constant.MIN_ZOOM_LEVEL ? this.handleZoomOutButtonClick : void 0
|
|
1225
|
+
}
|
|
1226
|
+
)), /* @__PURE__ */ import_react.default.createElement("li", { className: "ril-toolbar__item ril__toolbarItem" }, /* @__PURE__ */ import_react.default.createElement(
|
|
1227
|
+
"button",
|
|
1228
|
+
{
|
|
1229
|
+
type: "button",
|
|
1230
|
+
key: "close",
|
|
1231
|
+
"aria-label": this.props.closeLabel,
|
|
1232
|
+
title: this.props.closeLabel,
|
|
1233
|
+
className: "ril-close ril-toolbar__item__child ril__toolbarItemChild ril__builtinButton ril__closeButton",
|
|
1234
|
+
onClick: !this.isAnimating() ? this.requestClose : void 0
|
|
1235
|
+
}
|
|
1236
|
+
)))
|
|
1237
|
+
),
|
|
1238
|
+
this.props.imageCaption && /* @__PURE__ */ import_react.default.createElement(
|
|
1239
|
+
"div",
|
|
1240
|
+
{
|
|
1241
|
+
onWheel: this.handleCaptionMousewheel,
|
|
1242
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
1243
|
+
className: "ril-caption ril__caption",
|
|
1244
|
+
ref: this.caption
|
|
1245
|
+
},
|
|
1246
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: "ril-caption-content ril__captionContent" }, this.props.imageCaption)
|
|
1247
|
+
)
|
|
1248
|
+
)
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
__name(_ReactImageLightbox, "ReactImageLightbox");
|
|
1253
|
+
__publicField(_ReactImageLightbox, "defaultProps", {
|
|
1254
|
+
animationDisabled: false,
|
|
1255
|
+
clickOutsideToClose: true,
|
|
1256
|
+
enableZoom: true,
|
|
1257
|
+
imageCountSeparator: "of",
|
|
1258
|
+
nextSrc: null,
|
|
1259
|
+
prevSrc: null,
|
|
1260
|
+
mainSrc: null,
|
|
1261
|
+
onCloseRequest: /* @__PURE__ */ __name(() => {
|
|
1262
|
+
}, "onCloseRequest"),
|
|
1263
|
+
onMovePrevRequest: /* @__PURE__ */ __name(() => {
|
|
1264
|
+
}, "onMovePrevRequest"),
|
|
1265
|
+
onMoveNextRequest: /* @__PURE__ */ __name(() => {
|
|
1266
|
+
}, "onMoveNextRequest"),
|
|
1267
|
+
onImageLoad: /* @__PURE__ */ __name(() => {
|
|
1268
|
+
}, "onImageLoad"),
|
|
1269
|
+
onImageLoadError: /* @__PURE__ */ __name(() => {
|
|
1270
|
+
}, "onImageLoadError"),
|
|
1271
|
+
onZoomChange: /* @__PURE__ */ __name(() => {
|
|
1272
|
+
}, "onZoomChange"),
|
|
1273
|
+
reactModalStyle: {},
|
|
1274
|
+
showZoomButtons: true,
|
|
1275
|
+
zoomStep: import_constant.ZOOM_RATIO,
|
|
1276
|
+
zoomButtonsContainerStyle: {},
|
|
1277
|
+
zoomButtonsStyle: {},
|
|
1278
|
+
zoomContainerStyle: {},
|
|
1279
|
+
zoomLevel: import_constant.MIN_ZOOM_LEVEL,
|
|
1280
|
+
zoomTransitionDuration: 300
|
|
1281
|
+
});
|
|
1282
|
+
let ReactImageLightbox = _ReactImageLightbox;
|
|
1283
|
+
ReactImageLightbox.propTypes = {
|
|
1284
|
+
previewList: import_prop_types.default.object,
|
|
1285
|
+
//-----------------------------
|
|
1286
|
+
// Image sources
|
|
1287
|
+
//-----------------------------
|
|
1288
|
+
// Main display image url
|
|
1289
|
+
mainSrc: import_prop_types.default.string.isRequired,
|
|
1290
|
+
mainFile: import_prop_types.default.object,
|
|
1291
|
+
// Previous display image url (displayed to the left)
|
|
1292
|
+
// If left undefined, movePrev actions will not be performed, and the button not displayed
|
|
1293
|
+
prevSrc: import_prop_types.default.string,
|
|
1294
|
+
prevFile: import_prop_types.default.object,
|
|
1295
|
+
// Next display image url (displayed to the right)
|
|
1296
|
+
// If left undefined, moveNext actions will not be performed, and the button not displayed
|
|
1297
|
+
nextSrc: import_prop_types.default.string,
|
|
1298
|
+
nextFile: import_prop_types.default.object,
|
|
1299
|
+
//-----------------------------
|
|
1300
|
+
// Image thumbnail sources
|
|
1301
|
+
//-----------------------------
|
|
1302
|
+
// Thumbnail image url corresponding to props.mainSrc
|
|
1303
|
+
mainSrcThumbnail: import_prop_types.default.string,
|
|
1304
|
+
// Thumbnail image url corresponding to props.prevSrc
|
|
1305
|
+
prevSrcThumbnail: import_prop_types.default.string,
|
|
1306
|
+
// Thumbnail image url corresponding to props.nextSrc
|
|
1307
|
+
nextSrcThumbnail: import_prop_types.default.string,
|
|
1308
|
+
//-----------------------------
|
|
1309
|
+
// Event Handlers
|
|
1310
|
+
//-----------------------------
|
|
1311
|
+
// Close window event
|
|
1312
|
+
// Should change the parent state such that the lightbox is not rendered
|
|
1313
|
+
onCloseRequest: import_prop_types.default.func.isRequired,
|
|
1314
|
+
// Move to previous image event
|
|
1315
|
+
// Should change the parent state such that props.prevSrc becomes props.mainSrc,
|
|
1316
|
+
// props.mainSrc becomes props.nextSrc, etc.
|
|
1317
|
+
onMovePrevRequest: import_prop_types.default.func,
|
|
1318
|
+
// Move to next image event
|
|
1319
|
+
// Should change the parent state such that props.nextSrc becomes props.mainSrc,
|
|
1320
|
+
// props.mainSrc becomes props.prevSrc, etc.
|
|
1321
|
+
onMoveNextRequest: import_prop_types.default.func,
|
|
1322
|
+
// Called when an image fails to load
|
|
1323
|
+
// (imageSrc: string, srcType: string, errorEvent: object): void
|
|
1324
|
+
onImageLoadError: import_prop_types.default.func,
|
|
1325
|
+
// Called when image successfully loads
|
|
1326
|
+
onImageLoad: import_prop_types.default.func,
|
|
1327
|
+
// Open window event
|
|
1328
|
+
onAfterOpen: import_prop_types.default.func,
|
|
1329
|
+
//-----------------------------
|
|
1330
|
+
// Download discouragement settings
|
|
1331
|
+
//-----------------------------
|
|
1332
|
+
// Enable download discouragement (prevents [right-click -> Save Image As...])
|
|
1333
|
+
discourageDownloads: import_prop_types.default.bool,
|
|
1334
|
+
//-----------------------------
|
|
1335
|
+
// Animation settings
|
|
1336
|
+
//-----------------------------
|
|
1337
|
+
// Disable all animation
|
|
1338
|
+
animationDisabled: import_prop_types.default.bool,
|
|
1339
|
+
// Disable animation on actions performed with keyboard shortcuts
|
|
1340
|
+
animationOnKeyInput: import_prop_types.default.bool,
|
|
1341
|
+
// Animation duration (ms)
|
|
1342
|
+
animationDuration: import_prop_types.default.number,
|
|
1343
|
+
//-----------------------------
|
|
1344
|
+
// Keyboard shortcut settings
|
|
1345
|
+
//-----------------------------
|
|
1346
|
+
// Required interval of time (ms) between key actions
|
|
1347
|
+
// (prevents excessively fast navigation of images)
|
|
1348
|
+
keyRepeatLimit: import_prop_types.default.number,
|
|
1349
|
+
// Amount of time (ms) restored after each keyup
|
|
1350
|
+
// (makes rapid key presses slightly faster than holding down the key to navigate images)
|
|
1351
|
+
keyRepeatKeyupBonus: import_prop_types.default.number,
|
|
1352
|
+
//-----------------------------
|
|
1353
|
+
// Image info
|
|
1354
|
+
//-----------------------------
|
|
1355
|
+
// Image title
|
|
1356
|
+
imageTitle: import_prop_types.default.node,
|
|
1357
|
+
// Image caption
|
|
1358
|
+
imageCaption: import_prop_types.default.node,
|
|
1359
|
+
// Optional crossOrigin attribute
|
|
1360
|
+
imageCrossOrigin: import_prop_types.default.string,
|
|
1361
|
+
//-----------------------------
|
|
1362
|
+
// Lightbox style
|
|
1363
|
+
//-----------------------------
|
|
1364
|
+
// Set z-index style, etc., for the parent react-modal (format: https://github.com/reactjs/react-modal#styles )
|
|
1365
|
+
reactModalStyle: import_prop_types.default.shape({}),
|
|
1366
|
+
// Padding (px) between the edge of the window and the lightbox
|
|
1367
|
+
imagePadding: import_prop_types.default.number,
|
|
1368
|
+
wrapperClassName: import_prop_types.default.string,
|
|
1369
|
+
//-----------------------------
|
|
1370
|
+
// Other
|
|
1371
|
+
//-----------------------------
|
|
1372
|
+
// Array of custom toolbar buttons
|
|
1373
|
+
toolbarButtons: import_prop_types.default.arrayOf(import_prop_types.default.node),
|
|
1374
|
+
// When true, clicks outside of the image close the lightbox
|
|
1375
|
+
clickOutsideToClose: import_prop_types.default.bool,
|
|
1376
|
+
// Set to false to disable zoom functionality and hide zoom buttons
|
|
1377
|
+
enableZoom: import_prop_types.default.bool,
|
|
1378
|
+
// Override props set on react-modal (https://github.com/reactjs/react-modal)
|
|
1379
|
+
reactModalProps: import_prop_types.default.shape({}),
|
|
1380
|
+
// Aria-labels
|
|
1381
|
+
nextLabel: import_prop_types.default.string,
|
|
1382
|
+
prevLabel: import_prop_types.default.string,
|
|
1383
|
+
zoomInLabel: import_prop_types.default.string,
|
|
1384
|
+
zoomOutLabel: import_prop_types.default.string,
|
|
1385
|
+
closeLabel: import_prop_types.default.string,
|
|
1386
|
+
imageLoadErrorMessage: import_prop_types.default.node,
|
|
1387
|
+
// custom loader
|
|
1388
|
+
loader: import_prop_types.default.node
|
|
1389
|
+
};
|
|
1390
|
+
ReactImageLightbox.defaultProps = {
|
|
1391
|
+
// @ts-ignore
|
|
1392
|
+
imageTitle: null,
|
|
1393
|
+
imageCaption: null,
|
|
1394
|
+
toolbarButtons: null,
|
|
1395
|
+
reactModalProps: {},
|
|
1396
|
+
animationDisabled: false,
|
|
1397
|
+
animationDuration: 300,
|
|
1398
|
+
animationOnKeyInput: false,
|
|
1399
|
+
clickOutsideToClose: true,
|
|
1400
|
+
closeLabel: "Close lightbox",
|
|
1401
|
+
discourageDownloads: false,
|
|
1402
|
+
enableZoom: true,
|
|
1403
|
+
imagePadding: 10,
|
|
1404
|
+
imageCrossOrigin: null,
|
|
1405
|
+
keyRepeatKeyupBonus: 40,
|
|
1406
|
+
keyRepeatLimit: 180,
|
|
1407
|
+
mainSrcThumbnail: null,
|
|
1408
|
+
nextLabel: "Next image",
|
|
1409
|
+
nextSrc: null,
|
|
1410
|
+
nextSrcThumbnail: null,
|
|
1411
|
+
onAfterOpen: /* @__PURE__ */ __name(() => {
|
|
1412
|
+
}, "onAfterOpen"),
|
|
1413
|
+
onImageLoadError: /* @__PURE__ */ __name(() => {
|
|
1414
|
+
}, "onImageLoadError"),
|
|
1415
|
+
onImageLoad: /* @__PURE__ */ __name(() => {
|
|
1416
|
+
}, "onImageLoad"),
|
|
1417
|
+
onMoveNextRequest: /* @__PURE__ */ __name(() => {
|
|
1418
|
+
}, "onMoveNextRequest"),
|
|
1419
|
+
onMovePrevRequest: /* @__PURE__ */ __name(() => {
|
|
1420
|
+
}, "onMovePrevRequest"),
|
|
1421
|
+
prevLabel: "Previous image",
|
|
1422
|
+
prevSrc: null,
|
|
1423
|
+
prevSrcThumbnail: null,
|
|
1424
|
+
reactModalStyle: {},
|
|
1425
|
+
wrapperClassName: "",
|
|
1426
|
+
zoomInLabel: "Zoom in",
|
|
1427
|
+
zoomOutLabel: "Zoom out",
|
|
1428
|
+
imageLoadErrorMessage: "This image failed to load",
|
|
1429
|
+
loader: void 0
|
|
1430
|
+
};
|
|
1431
|
+
var react_image_lightbox_default = ReactImageLightbox;
|