viewerjs 1.10.0 → 1.10.4
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/README.md +6 -4
- package/dist/viewer.common.js +112 -60
- package/dist/viewer.css +164 -190
- package/dist/viewer.esm.js +113 -61
- package/dist/viewer.js +114 -62
- package/dist/viewer.min.css +3 -3
- package/dist/viewer.min.js +3 -3
- package/package.json +30 -44
- package/src/css/viewer.css +1 -1
- package/src/css/viewer.scss +1 -1
- package/src/index.css +1 -1
- package/src/index.scss +1 -1
- package/src/js/constants.js +1 -0
- package/src/js/handlers.js +9 -4
- package/src/js/methods.js +51 -9
- package/src/js/render.js +29 -7
- package/CHANGELOG.md +0 -261
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Viewer.js
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/viewerjs) [](https://www.npmjs.com/package/viewerjs) [](https://unpkg.com/viewerjs/dist/viewer.common.js)
|
|
4
4
|
|
|
5
5
|
> JavaScript image viewer.
|
|
6
6
|
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
- Supports keyboard
|
|
37
37
|
- Cross-browser support
|
|
38
38
|
|
|
39
|
-
## Main
|
|
39
|
+
## Main files
|
|
40
40
|
|
|
41
41
|
```text
|
|
42
42
|
dist/
|
|
@@ -206,8 +206,8 @@ new Viewer(image, {
|
|
|
206
206
|
- `{ key: String }`: customize the size of the button.
|
|
207
207
|
- `{ key: Function }`: customize the click handler of the button.
|
|
208
208
|
- `{ key: { show: Boolean | Number, size: String, click: Function }`: customize each property of the button.
|
|
209
|
-
- Available keys: "zoomIn", "zoomOut", "oneToOne", "reset", "prev", "play", "next", "rotateLeft", "rotateRight", "flipHorizontal"
|
|
210
|
-
- Available sizes: "small", "medium" (default) and "large".
|
|
209
|
+
- Available built-in keys: "zoomIn", "zoomOut", "oneToOne", "reset", "prev", "play", "next", "rotateLeft", "rotateRight", "flipHorizontal", "flipVertical".
|
|
210
|
+
- Available built-in sizes: "small", "medium" (default) and "large".
|
|
211
211
|
|
|
212
212
|
Specify the visibility and layout of the toolbar its buttons.
|
|
213
213
|
|
|
@@ -234,6 +234,8 @@ new Viewer(image, {
|
|
|
234
234
|
});
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
+
> see more for [custom toolbar](docs/examples/custom-toolbar.html).
|
|
238
|
+
|
|
237
239
|
### className
|
|
238
240
|
|
|
239
241
|
- Type: `String`
|
package/dist/viewer.common.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Viewer.js v1.10.
|
|
2
|
+
* Viewer.js v1.10.4
|
|
3
3
|
* https://fengyuanchen.github.io/viewerjs
|
|
4
4
|
*
|
|
5
5
|
* Copyright 2015-present Chen Fengyuan
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
*
|
|
8
|
-
* Date:
|
|
8
|
+
* Date: 2022-02-13T08:40:00.127Z
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
@@ -15,14 +15,9 @@ function ownKeys(object, enumerableOnly) {
|
|
|
15
15
|
|
|
16
16
|
if (Object.getOwnPropertySymbols) {
|
|
17
17
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
keys.push.apply(keys, symbols);
|
|
18
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
19
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
20
|
+
})), keys.push.apply(keys, symbols);
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
return keys;
|
|
@@ -30,19 +25,12 @@ function ownKeys(object, enumerableOnly) {
|
|
|
30
25
|
|
|
31
26
|
function _objectSpread2(target) {
|
|
32
27
|
for (var i = 1; i < arguments.length; i++) {
|
|
33
|
-
var source = arguments[i]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
40
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
41
|
-
} else {
|
|
42
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
43
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
28
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
29
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
30
|
+
_defineProperty(target, key, source[key]);
|
|
31
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
32
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
33
|
+
});
|
|
46
34
|
}
|
|
47
35
|
|
|
48
36
|
return target;
|
|
@@ -51,17 +39,11 @@ function _objectSpread2(target) {
|
|
|
51
39
|
function _typeof(obj) {
|
|
52
40
|
"@babel/helpers - typeof";
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
_typeof = function (obj) {
|
|
60
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return _typeof(obj);
|
|
42
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
43
|
+
return typeof obj;
|
|
44
|
+
} : function (obj) {
|
|
45
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
46
|
+
}, _typeof(obj);
|
|
65
47
|
}
|
|
66
48
|
|
|
67
49
|
function _classCallCheck(instance, Constructor) {
|
|
@@ -83,6 +65,9 @@ function _defineProperties(target, props) {
|
|
|
83
65
|
function _createClass(Constructor, protoProps, staticProps) {
|
|
84
66
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
85
67
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
68
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
69
|
+
writable: false
|
|
70
|
+
});
|
|
86
71
|
return Constructor;
|
|
87
72
|
}
|
|
88
73
|
|
|
@@ -374,6 +359,7 @@ var EVENT_DRAG_START = 'dragstart';
|
|
|
374
359
|
var EVENT_FOCUSIN = 'focusin';
|
|
375
360
|
var EVENT_KEY_DOWN = 'keydown';
|
|
376
361
|
var EVENT_LOAD = 'load';
|
|
362
|
+
var EVENT_ERROR = 'error';
|
|
377
363
|
var EVENT_TOUCH_END = IS_TOUCH_DEVICE ? 'touchend touchcancel' : 'mouseup';
|
|
378
364
|
var EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? 'touchmove' : 'mousemove';
|
|
379
365
|
var EVENT_TOUCH_START = IS_TOUCH_DEVICE ? 'touchstart' : 'mousedown';
|
|
@@ -490,15 +476,15 @@ function forEach(data, callback) {
|
|
|
490
476
|
if (Array.isArray(data) || isNumber(data.length)
|
|
491
477
|
/* array-like */
|
|
492
478
|
) {
|
|
493
|
-
|
|
494
|
-
|
|
479
|
+
var length = data.length;
|
|
480
|
+
var i;
|
|
495
481
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
482
|
+
for (i = 0; i < length; i += 1) {
|
|
483
|
+
if (callback.call(data, data[i], i, data) === false) {
|
|
484
|
+
break;
|
|
500
485
|
}
|
|
501
|
-
}
|
|
486
|
+
}
|
|
487
|
+
} else if (isObject(data)) {
|
|
502
488
|
Object.keys(data).forEach(function (key) {
|
|
503
489
|
callback.call(data, data[key], key, data);
|
|
504
490
|
});
|
|
@@ -1123,13 +1109,17 @@ var render = {
|
|
|
1123
1109
|
this.items = items;
|
|
1124
1110
|
forEach(items, function (item) {
|
|
1125
1111
|
var image = item.firstElementChild;
|
|
1112
|
+
var onLoad;
|
|
1113
|
+
var onError;
|
|
1126
1114
|
setData(image, 'filled', true);
|
|
1127
1115
|
|
|
1128
1116
|
if (options.loading) {
|
|
1129
1117
|
addClass(item, CLASS_LOADING);
|
|
1130
1118
|
}
|
|
1131
1119
|
|
|
1132
|
-
addListener(image, EVENT_LOAD, function (event) {
|
|
1120
|
+
addListener(image, EVENT_LOAD, onLoad = function onLoad(event) {
|
|
1121
|
+
removeListener(image, EVENT_ERROR, onError);
|
|
1122
|
+
|
|
1133
1123
|
if (options.loading) {
|
|
1134
1124
|
removeClass(item, CLASS_LOADING);
|
|
1135
1125
|
}
|
|
@@ -1138,6 +1128,15 @@ var render = {
|
|
|
1138
1128
|
}, {
|
|
1139
1129
|
once: true
|
|
1140
1130
|
});
|
|
1131
|
+
addListener(image, EVENT_ERROR, onError = function onError() {
|
|
1132
|
+
removeListener(image, EVENT_LOAD, onLoad);
|
|
1133
|
+
|
|
1134
|
+
if (options.loading) {
|
|
1135
|
+
removeClass(item, CLASS_LOADING);
|
|
1136
|
+
}
|
|
1137
|
+
}, {
|
|
1138
|
+
once: true
|
|
1139
|
+
});
|
|
1141
1140
|
});
|
|
1142
1141
|
|
|
1143
1142
|
if (options.transition) {
|
|
@@ -1148,16 +1147,23 @@ var render = {
|
|
|
1148
1147
|
});
|
|
1149
1148
|
}
|
|
1150
1149
|
},
|
|
1151
|
-
renderList: function renderList(
|
|
1152
|
-
var
|
|
1153
|
-
var
|
|
1154
|
-
|
|
1155
|
-
|
|
1150
|
+
renderList: function renderList() {
|
|
1151
|
+
var index = this.index;
|
|
1152
|
+
var item = this.items[index];
|
|
1153
|
+
|
|
1154
|
+
if (!item) {
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
var next = item.nextElementSibling;
|
|
1159
|
+
var gutter = parseInt(window.getComputedStyle(next || item).marginLeft, 10);
|
|
1160
|
+
var offsetWidth = item.offsetWidth;
|
|
1161
|
+
var outerWidth = offsetWidth + gutter; // Place the active item in the center of the screen
|
|
1156
1162
|
|
|
1157
1163
|
setStyle(this.list, assign({
|
|
1158
|
-
width: outerWidth * this.length
|
|
1164
|
+
width: outerWidth * this.length - gutter
|
|
1159
1165
|
}, getTransforms({
|
|
1160
|
-
translateX: (this.viewerData.width -
|
|
1166
|
+
translateX: (this.viewerData.width - offsetWidth) / 2 - outerWidth * index
|
|
1161
1167
|
})));
|
|
1162
1168
|
},
|
|
1163
1169
|
resetList: function resetList() {
|
|
@@ -1433,9 +1439,10 @@ var handlers = {
|
|
|
1433
1439
|
// Cancel the emulated double click when the native dblclick event was triggered.
|
|
1434
1440
|
if (IS_TOUCH_DEVICE && event.isTrusted) {
|
|
1435
1441
|
clearTimeout(this.doubleClickImageTimeout);
|
|
1436
|
-
}
|
|
1442
|
+
} // XXX: No pageX/Y properties in custom event, fallback to the original event.
|
|
1443
|
+
|
|
1437
1444
|
|
|
1438
|
-
this.toggle(event);
|
|
1445
|
+
this.toggle(event.isTrusted ? event : event.detail && event.detail.originalEvent);
|
|
1439
1446
|
}
|
|
1440
1447
|
},
|
|
1441
1448
|
load: function load() {
|
|
@@ -1457,7 +1464,7 @@ var handlers = {
|
|
|
1457
1464
|
removeClass(this.canvas, CLASS_LOADING);
|
|
1458
1465
|
}
|
|
1459
1466
|
|
|
1460
|
-
image.style.cssText = 'height:0;' + "margin-left:".concat(viewerData.width / 2, "px;") + "margin-top:".concat(viewerData.height / 2, "px;") + 'max-width:none!important;' + 'position:
|
|
1467
|
+
image.style.cssText = 'height:0;' + "margin-left:".concat(viewerData.width / 2, "px;") + "margin-top:".concat(viewerData.height / 2, "px;") + 'max-width:none!important;' + 'position:relative;' + 'width:0;';
|
|
1461
1468
|
this.initImage(function () {
|
|
1462
1469
|
toggleClass(image, CLASS_MOVE, options.movable);
|
|
1463
1470
|
toggleClass(image, CLASS_TRANSITION, options.transition);
|
|
@@ -1702,7 +1709,9 @@ var handlers = {
|
|
|
1702
1709
|
this.imageClicked = false; // This timeout will be cleared later when a native dblclick event is triggering
|
|
1703
1710
|
|
|
1704
1711
|
this.doubleClickImageTimeout = setTimeout(function () {
|
|
1705
|
-
dispatchEvent(_this2.image, EVENT_DBLCLICK
|
|
1712
|
+
dispatchEvent(_this2.image, EVENT_DBLCLICK, {
|
|
1713
|
+
originalEvent: event
|
|
1714
|
+
});
|
|
1706
1715
|
}, 50);
|
|
1707
1716
|
} else {
|
|
1708
1717
|
this.imageClicked = true; // The default timing of a double click in Windows is 500 ms
|
|
@@ -1717,7 +1726,9 @@ var handlers = {
|
|
|
1717
1726
|
if (options.backdrop && options.backdrop !== 'static' && event.target === this.canvas) {
|
|
1718
1727
|
// This timeout will be cleared later when a native click event is triggering
|
|
1719
1728
|
this.clickCanvasTimeout = setTimeout(function () {
|
|
1720
|
-
dispatchEvent(_this2.canvas, EVENT_CLICK
|
|
1729
|
+
dispatchEvent(_this2.canvas, EVENT_CLICK, {
|
|
1730
|
+
originalEvent: event
|
|
1731
|
+
});
|
|
1721
1732
|
}, 50);
|
|
1722
1733
|
}
|
|
1723
1734
|
}
|
|
@@ -2014,8 +2025,12 @@ var methods = {
|
|
|
2014
2025
|
}
|
|
2015
2026
|
|
|
2016
2027
|
var activeItem = this.items[this.index];
|
|
2017
|
-
|
|
2018
|
-
activeItem
|
|
2028
|
+
|
|
2029
|
+
if (activeItem) {
|
|
2030
|
+
removeClass(activeItem, CLASS_ACTIVE);
|
|
2031
|
+
activeItem.removeAttribute('aria-selected');
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2019
2034
|
addClass(item, CLASS_ACTIVE);
|
|
2020
2035
|
item.setAttribute('aria-selected', true);
|
|
2021
2036
|
|
|
@@ -2047,6 +2062,7 @@ var methods = {
|
|
|
2047
2062
|
};
|
|
2048
2063
|
|
|
2049
2064
|
var onLoad;
|
|
2065
|
+
var onError;
|
|
2050
2066
|
addListener(element, EVENT_VIEWED, onViewed, {
|
|
2051
2067
|
once: true
|
|
2052
2068
|
});
|
|
@@ -2075,7 +2091,27 @@ var methods = {
|
|
|
2075
2091
|
if (image.complete) {
|
|
2076
2092
|
this.load();
|
|
2077
2093
|
} else {
|
|
2078
|
-
addListener(image, EVENT_LOAD, onLoad =
|
|
2094
|
+
addListener(image, EVENT_LOAD, onLoad = function onLoad() {
|
|
2095
|
+
removeListener(image, EVENT_ERROR, onError);
|
|
2096
|
+
|
|
2097
|
+
_this2.load();
|
|
2098
|
+
}, {
|
|
2099
|
+
once: true
|
|
2100
|
+
});
|
|
2101
|
+
addListener(image, EVENT_ERROR, onError = function onError() {
|
|
2102
|
+
removeListener(image, EVENT_LOAD, onLoad);
|
|
2103
|
+
|
|
2104
|
+
if (_this2.timeout) {
|
|
2105
|
+
clearTimeout(_this2.timeout);
|
|
2106
|
+
_this2.timeout = false;
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
removeClass(image, CLASS_INVISIBLE);
|
|
2110
|
+
|
|
2111
|
+
if (options.loading) {
|
|
2112
|
+
removeClass(_this2.canvas, CLASS_LOADING);
|
|
2113
|
+
}
|
|
2114
|
+
}, {
|
|
2079
2115
|
once: true
|
|
2080
2116
|
});
|
|
2081
2117
|
|
|
@@ -2446,8 +2482,24 @@ var methods = {
|
|
|
2446
2482
|
ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio);
|
|
2447
2483
|
}
|
|
2448
2484
|
|
|
2449
|
-
if (_originalEvent
|
|
2450
|
-
|
|
2485
|
+
if (_originalEvent) {
|
|
2486
|
+
switch (_originalEvent.type) {
|
|
2487
|
+
case 'wheel':
|
|
2488
|
+
if (options.zoomRatio >= 0.055 && ratio > 0.95 && ratio < 1.05) {
|
|
2489
|
+
ratio = 1;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
break;
|
|
2493
|
+
|
|
2494
|
+
case 'pointermove':
|
|
2495
|
+
case 'touchmove':
|
|
2496
|
+
case 'mousemove':
|
|
2497
|
+
if (ratio > 0.99 && ratio < 1.01) {
|
|
2498
|
+
ratio = 1;
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
break;
|
|
2502
|
+
}
|
|
2451
2503
|
}
|
|
2452
2504
|
|
|
2453
2505
|
var newWidth = naturalWidth * ratio;
|
|
@@ -2474,7 +2526,7 @@ var methods = {
|
|
|
2474
2526
|
|
|
2475
2527
|
if (_originalEvent) {
|
|
2476
2528
|
var offset = getOffset(this.viewer);
|
|
2477
|
-
var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {
|
|
2529
|
+
var center = pointers && Object.keys(pointers).length > 0 ? getPointersCenter(pointers) : {
|
|
2478
2530
|
pageX: _originalEvent.pageX,
|
|
2479
2531
|
pageY: _originalEvent.pageY
|
|
2480
2532
|
}; // Zoom from the triggering point of the event
|