@hyper-proto/iv-viewer 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +249 -0
- package/dist/iv-viewer.css +221 -0
- package/dist/iv-viewer.es.js +1432 -0
- package/dist/iv-viewer.js +1442 -0
- package/dist/iv-viewer.min.css +1 -0
- package/dist/iv-viewer.min.js +1 -0
- package/iv-viewer.d.ts +54 -0
- package/lib/FullScreen.js +114 -0
- package/lib/ImageViewer.js +962 -0
- package/lib/Slider.js +109 -0
- package/lib/dist.js +11 -0
- package/lib/index.js +22 -0
- package/lib/iv-viewer.css +221 -0
- package/lib/util.js +174 -0
- package/package.json +60 -0
- package/src/FullScreen.js +76 -0
- package/src/ImageViewer.js +988 -0
- package/src/Slider.js +97 -0
- package/src/dist.js +6 -0
- package/src/index.js +5 -0
- package/src/scss/_iv-viewer.scss +268 -0
- package/src/scss/_variables.scss +43 -0
- package/src/scss/build.scss +1 -0
- package/src/util.js +158 -0
package/lib/Slider.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _util = require("./util");
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
10
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
11
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
12
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
var Slider = /*#__PURE__*/function () {
|
|
16
|
+
function Slider(container, _ref) {
|
|
17
|
+
var _this = this;
|
|
18
|
+
var _onStart = _ref.onStart,
|
|
19
|
+
_onMove = _ref.onMove,
|
|
20
|
+
onEnd = _ref.onEnd,
|
|
21
|
+
isSliderEnabled = _ref.isSliderEnabled;
|
|
22
|
+
_classCallCheck(this, Slider);
|
|
23
|
+
_defineProperty(this, "startHandler", function (eStart) {
|
|
24
|
+
if (!_this.isSliderEnabled()) return;
|
|
25
|
+
_this.removeListeners();
|
|
26
|
+
eStart.preventDefault();
|
|
27
|
+
var moveHandler = _this.moveHandler,
|
|
28
|
+
endHandler = _this.endHandler,
|
|
29
|
+
onStart = _this.onStart;
|
|
30
|
+
var isTouchEvent = eStart.type === 'touchstart' || eStart.type === 'touchend';
|
|
31
|
+
_this.touchMoveEvent = isTouchEvent ? 'touchmove' : 'mousemove';
|
|
32
|
+
_this.touchEndEvent = isTouchEvent ? 'touchend' : 'mouseup';
|
|
33
|
+
_this.sx = isTouchEvent ? eStart.touches[0].clientX : eStart.clientX;
|
|
34
|
+
_this.sy = isTouchEvent ? eStart.touches[0].clientY : eStart.clientY;
|
|
35
|
+
onStart(eStart, {
|
|
36
|
+
x: _this.sx,
|
|
37
|
+
y: _this.sy
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// add listeners
|
|
41
|
+
document.addEventListener(_this.touchMoveEvent, moveHandler);
|
|
42
|
+
document.addEventListener(_this.touchEndEvent, endHandler);
|
|
43
|
+
/*
|
|
44
|
+
add end handler in context menu as well.
|
|
45
|
+
As mouseup event is not trigger on context menu open
|
|
46
|
+
https://bugs.chromium.org/p/chromium/issues/detail?id=506801
|
|
47
|
+
*/
|
|
48
|
+
document.addEventListener('contextmenu', endHandler);
|
|
49
|
+
});
|
|
50
|
+
_defineProperty(this, "moveHandler", function (eMove) {
|
|
51
|
+
if (!_this.isSliderEnabled()) return;
|
|
52
|
+
eMove.preventDefault();
|
|
53
|
+
var sx = _this.sx,
|
|
54
|
+
sy = _this.sy,
|
|
55
|
+
onMove = _this.onMove;
|
|
56
|
+
var isTouchEvent = _this.touchMoveEvent === 'touchmove';
|
|
57
|
+
|
|
58
|
+
// get the coordinates
|
|
59
|
+
var mx = isTouchEvent ? eMove.touches[0].clientX : eMove.clientX;
|
|
60
|
+
var my = isTouchEvent ? eMove.touches[0].clientY : eMove.clientY;
|
|
61
|
+
onMove(eMove, {
|
|
62
|
+
dx: mx - sx,
|
|
63
|
+
dy: my - sy,
|
|
64
|
+
mx: mx,
|
|
65
|
+
my: my
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
_defineProperty(this, "endHandler", function () {
|
|
69
|
+
if (!_this.isSliderEnabled()) return;
|
|
70
|
+
_this.removeListeners();
|
|
71
|
+
_this.onEnd();
|
|
72
|
+
});
|
|
73
|
+
this.container = container;
|
|
74
|
+
this.isSliderEnabled = isSliderEnabled;
|
|
75
|
+
this.onStart = _onStart || _util.noop;
|
|
76
|
+
this.onMove = _onMove || _util.noop;
|
|
77
|
+
this.onEnd = onEnd || _util.noop;
|
|
78
|
+
}
|
|
79
|
+
return _createClass(Slider, [{
|
|
80
|
+
key: "removeListeners",
|
|
81
|
+
value:
|
|
82
|
+
// remove previous events if it's not removed
|
|
83
|
+
// - Case when while sliding mouse moved out of document and released there
|
|
84
|
+
function removeListeners() {
|
|
85
|
+
if (!this.touchMoveEvent) return;
|
|
86
|
+
document.removeEventListener(this.touchMoveEvent, this.moveHandler);
|
|
87
|
+
document.removeEventListener(this.touchEndEvent, this.endHandler);
|
|
88
|
+
document.removeEventListener('contextmenu', this.endHandler);
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "init",
|
|
92
|
+
value: function init() {
|
|
93
|
+
var _this2 = this;
|
|
94
|
+
['touchstart', 'mousedown'].forEach(function (evt) {
|
|
95
|
+
_this2.container.addEventListener(evt, _this2.startHandler);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
key: "destroy",
|
|
100
|
+
value: function destroy() {
|
|
101
|
+
var _this3 = this;
|
|
102
|
+
['touchstart', 'mousedown'].forEach(function (evt) {
|
|
103
|
+
_this3.container.removeEventListener(evt, _this3.startHandler);
|
|
104
|
+
});
|
|
105
|
+
this.removeListeners();
|
|
106
|
+
}
|
|
107
|
+
}]);
|
|
108
|
+
}();
|
|
109
|
+
var _default = exports["default"] = Slider;
|
package/lib/dist.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _ImageViewer = _interopRequireDefault(require("./ImageViewer"));
|
|
8
|
+
var _FullScreen = _interopRequireDefault(require("./FullScreen"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
_ImageViewer["default"].FullScreenViewer = _FullScreen["default"];
|
|
11
|
+
var _default = exports["default"] = _ImageViewer["default"];
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FullScreenViewer", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _FullScreen["default"];
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ImageViewer", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _ImageViewer["default"];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports["default"] = void 0;
|
|
19
|
+
var _ImageViewer = _interopRequireDefault(require("./ImageViewer"));
|
|
20
|
+
var _FullScreen = _interopRequireDefault(require("./FullScreen"));
|
|
21
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
22
|
+
var _default = exports["default"] = _ImageViewer["default"];
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
.iv-container {
|
|
2
|
+
overflow: hidden;
|
|
3
|
+
position: relative;
|
|
4
|
+
-webkit-user-select: none;
|
|
5
|
+
-moz-user-select: none;
|
|
6
|
+
user-select: none;
|
|
7
|
+
}
|
|
8
|
+
.iv-fullscreen {
|
|
9
|
+
position: fixed;
|
|
10
|
+
background: #0d0d0d;
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
display: none;
|
|
16
|
+
z-index: 1000;
|
|
17
|
+
}
|
|
18
|
+
.iv-fullscreen-container {
|
|
19
|
+
position: relative;
|
|
20
|
+
height: 100%;
|
|
21
|
+
width: 100%;
|
|
22
|
+
}
|
|
23
|
+
.iv-fullscreen-close {
|
|
24
|
+
position: absolute;
|
|
25
|
+
width: 24px;
|
|
26
|
+
height: 24px;
|
|
27
|
+
right: 10px;
|
|
28
|
+
top: 10px;
|
|
29
|
+
padding: 10px;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
text-align: center;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
text-shadow: 0 0 3px #6d6d6d;
|
|
34
|
+
transition: all ease 200ms;
|
|
35
|
+
}
|
|
36
|
+
.iv-fullscreen-close:after, .iv-fullscreen-close:before {
|
|
37
|
+
content: "";
|
|
38
|
+
height: 4px;
|
|
39
|
+
width: 24px;
|
|
40
|
+
background: #fff;
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: 50%;
|
|
43
|
+
left: 50%;
|
|
44
|
+
}
|
|
45
|
+
.iv-fullscreen-close:before {
|
|
46
|
+
transform: translate(-50%, -50%) rotate(45deg);
|
|
47
|
+
}
|
|
48
|
+
.iv-fullscreen-close:after {
|
|
49
|
+
transform: translate(-50%, -50%) rotate(-45deg);
|
|
50
|
+
}
|
|
51
|
+
.iv-fullscreen-close:hover {
|
|
52
|
+
transform: rotate(90deg);
|
|
53
|
+
transform-origin: 50% 50%;
|
|
54
|
+
}
|
|
55
|
+
.iv {
|
|
56
|
+
/***** snap view css *****/
|
|
57
|
+
}
|
|
58
|
+
.iv-snap-view {
|
|
59
|
+
width: 152px;
|
|
60
|
+
height: 152px;
|
|
61
|
+
position: absolute;
|
|
62
|
+
top: 20px;
|
|
63
|
+
border: 1px solid #aaa;
|
|
64
|
+
background: black;
|
|
65
|
+
z-index: 100;
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
transition: opacity ease 400ms;
|
|
68
|
+
opacity: 0;
|
|
69
|
+
left: 20px;
|
|
70
|
+
}
|
|
71
|
+
.iv-snap-image-wrap {
|
|
72
|
+
display: inline-block;
|
|
73
|
+
position: absolute;
|
|
74
|
+
max-width: 150px;
|
|
75
|
+
max-height: 150px;
|
|
76
|
+
top: 50%;
|
|
77
|
+
left: 50%;
|
|
78
|
+
transform: translate(-50%, -50%);
|
|
79
|
+
overflow: hidden;
|
|
80
|
+
}
|
|
81
|
+
.iv-snap-image {
|
|
82
|
+
position: relative;
|
|
83
|
+
touch-action: none;
|
|
84
|
+
}
|
|
85
|
+
.iv-snap-handle {
|
|
86
|
+
box-sizing: border-box;
|
|
87
|
+
position: absolute;
|
|
88
|
+
border: 1px solid #aaa;
|
|
89
|
+
transform: translate3d(0, 0, 0);
|
|
90
|
+
box-shadow: 0 0 0 200px rgba(0, 0, 0, 0.5);
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
cursor: grab;
|
|
93
|
+
}
|
|
94
|
+
.iv-snap-handle:active {
|
|
95
|
+
cursor: grabbing;
|
|
96
|
+
}
|
|
97
|
+
.iv {
|
|
98
|
+
/*** zoom actions ***/
|
|
99
|
+
}
|
|
100
|
+
.iv-zoom-actions {
|
|
101
|
+
width: 100%;
|
|
102
|
+
box-sizing: content-box;
|
|
103
|
+
position: absolute;
|
|
104
|
+
top: 150px;
|
|
105
|
+
left: -1px;
|
|
106
|
+
height: 20px;
|
|
107
|
+
border: 1px solid #aaa;
|
|
108
|
+
border-top: 0;
|
|
109
|
+
background: rgba(0, 0, 0, 0.3);
|
|
110
|
+
}
|
|
111
|
+
.iv-zoom-actions--has-buttons .iv-zoom-slider {
|
|
112
|
+
left: 24px;
|
|
113
|
+
right: 24px;
|
|
114
|
+
}
|
|
115
|
+
.iv-zoom-handle {
|
|
116
|
+
width: 20px;
|
|
117
|
+
height: 20px;
|
|
118
|
+
background: #fff;
|
|
119
|
+
position: absolute;
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
cursor: grab;
|
|
122
|
+
}
|
|
123
|
+
.iv-zoom-handle:active {
|
|
124
|
+
cursor: grabbing;
|
|
125
|
+
}
|
|
126
|
+
.iv-zoom-slider {
|
|
127
|
+
box-sizing: inherit;
|
|
128
|
+
position: absolute;
|
|
129
|
+
top: 0;
|
|
130
|
+
bottom: 0;
|
|
131
|
+
left: 0;
|
|
132
|
+
right: 0;
|
|
133
|
+
}
|
|
134
|
+
.iv-button-zoom, .iv-button-zoom--in, .iv-button-zoom--out {
|
|
135
|
+
position: absolute;
|
|
136
|
+
top: 0;
|
|
137
|
+
bottom: 0;
|
|
138
|
+
width: 24px;
|
|
139
|
+
cursor: pointer;
|
|
140
|
+
display: flex;
|
|
141
|
+
align-items: center;
|
|
142
|
+
justify-content: center;
|
|
143
|
+
}
|
|
144
|
+
.iv-button-zoom:before, .iv-button-zoom--in:before, .iv-button-zoom--out:before, .iv-button-zoom:after, .iv-button-zoom--in:after, .iv-button-zoom--out:after {
|
|
145
|
+
content: "";
|
|
146
|
+
height: 2px;
|
|
147
|
+
width: 10px;
|
|
148
|
+
background: #fff;
|
|
149
|
+
position: absolute;
|
|
150
|
+
}
|
|
151
|
+
.iv-button-zoom--in {
|
|
152
|
+
right: 0;
|
|
153
|
+
}
|
|
154
|
+
.iv-button-zoom--in:after {
|
|
155
|
+
transform: rotate(90deg);
|
|
156
|
+
}
|
|
157
|
+
.iv-button-zoom--out {
|
|
158
|
+
left: 0;
|
|
159
|
+
}
|
|
160
|
+
.iv {
|
|
161
|
+
/**** snap view css end *****/
|
|
162
|
+
}
|
|
163
|
+
.iv-image-mode {
|
|
164
|
+
display: inline-block;
|
|
165
|
+
}
|
|
166
|
+
.iv-image-view {
|
|
167
|
+
position: absolute;
|
|
168
|
+
height: 100%;
|
|
169
|
+
width: 100%;
|
|
170
|
+
top: 0;
|
|
171
|
+
left: 0;
|
|
172
|
+
}
|
|
173
|
+
.iv-image-wrap {
|
|
174
|
+
display: inline-block;
|
|
175
|
+
}
|
|
176
|
+
.iv-image-wrap:active {
|
|
177
|
+
cursor: move;
|
|
178
|
+
}
|
|
179
|
+
.iv-image {
|
|
180
|
+
max-width: 100%;
|
|
181
|
+
max-height: 100%;
|
|
182
|
+
position: absolute;
|
|
183
|
+
touch-action: none;
|
|
184
|
+
transform: translate3d(0, 0, 0);
|
|
185
|
+
}
|
|
186
|
+
.iv-loader {
|
|
187
|
+
top: 50%;
|
|
188
|
+
left: 50%;
|
|
189
|
+
border-radius: 50%;
|
|
190
|
+
width: 32px;
|
|
191
|
+
height: 32px;
|
|
192
|
+
z-index: 100;
|
|
193
|
+
margin-top: -16px;
|
|
194
|
+
margin-left: -16px;
|
|
195
|
+
font-size: 5px;
|
|
196
|
+
position: absolute;
|
|
197
|
+
text-indent: -9999em;
|
|
198
|
+
border: 1.1em solid rgba(0, 0, 0, 0.2);
|
|
199
|
+
border-left: 1.1em solid #fff;
|
|
200
|
+
transform: translateZ(0);
|
|
201
|
+
animation: loading-icon 1.1s infinite linear;
|
|
202
|
+
}
|
|
203
|
+
.iv-loader:after {
|
|
204
|
+
width: 10em;
|
|
205
|
+
height: 10em;
|
|
206
|
+
border-radius: 50%;
|
|
207
|
+
}
|
|
208
|
+
@keyframes loading-icon {
|
|
209
|
+
0% {
|
|
210
|
+
transform: rotate(0deg);
|
|
211
|
+
}
|
|
212
|
+
100% {
|
|
213
|
+
transform: rotate(360deg);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
@media screen and (max-width: 767px) {
|
|
217
|
+
.iv-snap-view {
|
|
218
|
+
z-index: -1;
|
|
219
|
+
visibility: hidden;
|
|
220
|
+
}
|
|
221
|
+
}
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ZOOM_CONSTANT = exports.MOUSE_WHEEL_COUNT = void 0;
|
|
7
|
+
exports.addClass = addClass;
|
|
8
|
+
exports.assign = assign;
|
|
9
|
+
exports.assignEvent = assignEvent;
|
|
10
|
+
exports.clamp = clamp;
|
|
11
|
+
exports.createElement = createElement;
|
|
12
|
+
exports.css = css;
|
|
13
|
+
exports.easeOutQuart = easeOutQuart;
|
|
14
|
+
exports.getTouchPointsDistance = getTouchPointsDistance;
|
|
15
|
+
exports.imageLoaded = imageLoaded;
|
|
16
|
+
exports.noop = noop;
|
|
17
|
+
exports.preventDefault = preventDefault;
|
|
18
|
+
exports.remove = remove;
|
|
19
|
+
exports.removeClass = removeClass;
|
|
20
|
+
exports.removeCss = removeCss;
|
|
21
|
+
exports.toArray = toArray;
|
|
22
|
+
exports.unwrap = unwrap;
|
|
23
|
+
exports.wrap = wrap;
|
|
24
|
+
// constants
|
|
25
|
+
var ZOOM_CONSTANT = exports.ZOOM_CONSTANT = 15; // increase or decrease value for zoom on mouse wheel
|
|
26
|
+
var MOUSE_WHEEL_COUNT = exports.MOUSE_WHEEL_COUNT = 5; // A mouse delta after which it should stop preventing default behaviour of mouse wheel
|
|
27
|
+
|
|
28
|
+
function noop() {}
|
|
29
|
+
function preventDefault(e) {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ease out method
|
|
34
|
+
/*
|
|
35
|
+
t : current time,
|
|
36
|
+
b : initial value,
|
|
37
|
+
c : changed value,
|
|
38
|
+
d : duration
|
|
39
|
+
*/
|
|
40
|
+
function easeOutQuart(t, b, c, d) {
|
|
41
|
+
t /= d;
|
|
42
|
+
t -= 1;
|
|
43
|
+
return -c * (t * t * t * t - 1) + b;
|
|
44
|
+
}
|
|
45
|
+
function createElement(options) {
|
|
46
|
+
var elem = document.createElement(options.tagName);
|
|
47
|
+
if (options.id) elem.id = options.id;
|
|
48
|
+
if (options.html) elem.innerHTML = options.html;
|
|
49
|
+
if (options.className) elem.className = options.className;
|
|
50
|
+
if (options.src) elem.src = options.src;
|
|
51
|
+
if (options.style) elem.style.cssText = options.style;
|
|
52
|
+
if (options.child) elem.appendChild(options.child);
|
|
53
|
+
|
|
54
|
+
// Insert before
|
|
55
|
+
if (options.insertBefore) {
|
|
56
|
+
options.parent.insertBefore(elem, options.insertBefore);
|
|
57
|
+
|
|
58
|
+
// Standard append
|
|
59
|
+
} else {
|
|
60
|
+
options.parent.appendChild(elem);
|
|
61
|
+
}
|
|
62
|
+
return elem;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// method to add class
|
|
66
|
+
function addClass(el, className) {
|
|
67
|
+
var classNameAry = className.split(' ');
|
|
68
|
+
if (classNameAry.length > 1) {
|
|
69
|
+
classNameAry.forEach(function (classItem) {
|
|
70
|
+
return addClass(el, classItem);
|
|
71
|
+
});
|
|
72
|
+
} else if (el.classList) {
|
|
73
|
+
el.classList.add(className);
|
|
74
|
+
} else {
|
|
75
|
+
el.className += " ".concat(className);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// method to remove class
|
|
80
|
+
function removeClass(el, className) {
|
|
81
|
+
var classNameAry = className.split(' ');
|
|
82
|
+
if (classNameAry.length > 1) {
|
|
83
|
+
classNameAry.forEach(function (classItem) {
|
|
84
|
+
return removeClass(el, classItem);
|
|
85
|
+
});
|
|
86
|
+
} else if (el.classList) {
|
|
87
|
+
el.classList.remove(className);
|
|
88
|
+
} else {
|
|
89
|
+
el.className = el.className.replace(new RegExp("(^|\\b)".concat(className.split(' ').join('|'), "(\\b|$)"), 'gi'), ' ');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// function to check if image is loaded
|
|
94
|
+
function imageLoaded(img) {
|
|
95
|
+
return img.complete && (typeof img.naturalWidth === 'undefined' || img.naturalWidth !== 0);
|
|
96
|
+
}
|
|
97
|
+
function toArray(list) {
|
|
98
|
+
if (!(list instanceof NodeList || list instanceof HTMLCollection)) return [list];
|
|
99
|
+
return Array.prototype.slice.call(list);
|
|
100
|
+
}
|
|
101
|
+
function assign(target) {
|
|
102
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
103
|
+
rest[_key - 1] = arguments[_key];
|
|
104
|
+
}
|
|
105
|
+
rest.forEach(function (obj) {
|
|
106
|
+
Object.keys(obj).forEach(function (key) {
|
|
107
|
+
target[key] = obj[key];
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
return target;
|
|
111
|
+
}
|
|
112
|
+
function css(elements, properties) {
|
|
113
|
+
var elmArray = toArray(elements);
|
|
114
|
+
if (typeof properties === 'string') {
|
|
115
|
+
return window.getComputedStyle(elmArray[0])[properties];
|
|
116
|
+
}
|
|
117
|
+
elmArray.forEach(function (element) {
|
|
118
|
+
Object.keys(properties).forEach(function (key) {
|
|
119
|
+
var value = properties[key];
|
|
120
|
+
element.style[key] = value;
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
function removeCss(element, property) {
|
|
126
|
+
element.style.removeProperty(property);
|
|
127
|
+
}
|
|
128
|
+
function wrap(element, _ref) {
|
|
129
|
+
var _ref$tag = _ref.tag,
|
|
130
|
+
tag = _ref$tag === void 0 ? 'div' : _ref$tag,
|
|
131
|
+
className = _ref.className,
|
|
132
|
+
id = _ref.id,
|
|
133
|
+
style = _ref.style;
|
|
134
|
+
var wrapper = document.createElement(tag);
|
|
135
|
+
if (className) wrapper.className = className;
|
|
136
|
+
if (id) wrapper.id = id;
|
|
137
|
+
if (style) wrapper.style = style;
|
|
138
|
+
element.parentNode.insertBefore(wrapper, element);
|
|
139
|
+
element.parentNode.removeChild(element);
|
|
140
|
+
wrapper.appendChild(element);
|
|
141
|
+
return wrapper;
|
|
142
|
+
}
|
|
143
|
+
function unwrap(element) {
|
|
144
|
+
var parent = element.parentNode;
|
|
145
|
+
if (parent !== document.body) {
|
|
146
|
+
parent.parentNode.insertBefore(element, parent);
|
|
147
|
+
parent.parentNode.removeChild(parent);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function remove(elements) {
|
|
151
|
+
var elmArray = toArray(elements);
|
|
152
|
+
elmArray.forEach(function (element) {
|
|
153
|
+
element.parentNode.removeChild(element);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function clamp(num, min, max) {
|
|
157
|
+
return Math.min(Math.max(num, min), max);
|
|
158
|
+
}
|
|
159
|
+
function assignEvent(element, events, handler) {
|
|
160
|
+
if (typeof events === 'string') events = [events];
|
|
161
|
+
events.forEach(function (event) {
|
|
162
|
+
element.addEventListener(event, handler);
|
|
163
|
+
});
|
|
164
|
+
return function () {
|
|
165
|
+
events.forEach(function (event) {
|
|
166
|
+
element.removeEventListener(event, handler);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function getTouchPointsDistance(touches) {
|
|
171
|
+
var touch0 = touches[0];
|
|
172
|
+
var touch1 = touches[1];
|
|
173
|
+
return Math.sqrt(Math.pow(touch1.pageX - touch0.pageX, 2) + Math.pow(touch1.pageY - touch0.pageY, 2));
|
|
174
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hyper-proto/iv-viewer",
|
|
3
|
+
"author": "HyperProto",
|
|
4
|
+
"version": "2.3.0",
|
|
5
|
+
"description": "A zooming and panning plugin inspired by google photos for your web images.",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "iv-viewer.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"lib",
|
|
11
|
+
"src",
|
|
12
|
+
"iv-viewer.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/hyperproto-gh/iv-viewer.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"image",
|
|
20
|
+
"zooming",
|
|
21
|
+
"panning",
|
|
22
|
+
"google",
|
|
23
|
+
"photos"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/hyperproto-gh/iv-viewer/issues"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/hyperproto-gh/iv-viewer#readme",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"start": "npm run copy-assets & parcel example/index.html",
|
|
32
|
+
"copy-assets": "cp -R example/ temp",
|
|
33
|
+
"bundle": "cross-env npm run compile && npm run build-css && npm run bundle-dist",
|
|
34
|
+
"bundle-dist": "cross-env rollup -c rollup.config.mjs",
|
|
35
|
+
"build-css": "node build-css.cjs",
|
|
36
|
+
"compile": "cross-env NODE_ENV=production babel src --out-dir lib"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@babel/cli": "^7.28.6",
|
|
40
|
+
"@babel/core": "^7.29.0",
|
|
41
|
+
"@babel/plugin-transform-class-properties": "^7.28.6",
|
|
42
|
+
"@babel/plugin-transform-object-rest-spread": "^7.28.6",
|
|
43
|
+
"@babel/preset-env": "^7.29.2",
|
|
44
|
+
"@eslint/js": "^10.0.1",
|
|
45
|
+
"@parcel/transformer-sass": "2.16.4",
|
|
46
|
+
"@rollup/plugin-babel": "^7.0.0",
|
|
47
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
48
|
+
"autoprefixer": "^10.4.27",
|
|
49
|
+
"cross-env": "^10.1.0",
|
|
50
|
+
"cssnano": "^7.1.4",
|
|
51
|
+
"eslint": "^10.2.0",
|
|
52
|
+
"globals": "^17.4.0",
|
|
53
|
+
"parcel": "^2.16.4",
|
|
54
|
+
"postcss": "^8.5.9",
|
|
55
|
+
"rollup": "^4.60.1",
|
|
56
|
+
"rollup-plugin-filesize": "^10.0.0",
|
|
57
|
+
"rollup-plugin-license": "^3.7.1",
|
|
58
|
+
"sass": "^1.99.0"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createElement, assignEvent, css, remove, removeCss } from './util';
|
|
2
|
+
import ImageViewer from './ImageViewer';
|
|
3
|
+
|
|
4
|
+
const fullScreenHtml = `
|
|
5
|
+
<div class="iv-fullscreen-container"></div>
|
|
6
|
+
<div class="iv-fullscreen-close"></div>
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
class FullScreenViewer extends ImageViewer {
|
|
10
|
+
constructor (options = {}) {
|
|
11
|
+
const fullScreenElem = createElement({
|
|
12
|
+
tagName: 'div',
|
|
13
|
+
className: 'iv-fullscreen',
|
|
14
|
+
html: fullScreenHtml,
|
|
15
|
+
parent: document.body,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const container = fullScreenElem.querySelector('.iv-fullscreen-container');
|
|
19
|
+
|
|
20
|
+
// call the ImageViewer constructor
|
|
21
|
+
super(container, { ...options, refreshOnResize: false });
|
|
22
|
+
|
|
23
|
+
// add fullScreenElem on element list
|
|
24
|
+
this._elements.fullScreen = fullScreenElem;
|
|
25
|
+
|
|
26
|
+
this._initFullScreenEvents();
|
|
27
|
+
}
|
|
28
|
+
_initFullScreenEvents () {
|
|
29
|
+
const { fullScreen } = this._elements;
|
|
30
|
+
const closeBtn = fullScreen.querySelector('.iv-fullscreen-close');
|
|
31
|
+
|
|
32
|
+
// add close button event
|
|
33
|
+
this._events.onCloseBtnClick = assignEvent(closeBtn, 'click', this.hide);
|
|
34
|
+
}
|
|
35
|
+
show (imageSrc, hiResImageSrc) {
|
|
36
|
+
// show the element
|
|
37
|
+
css(this._elements.fullScreen, { display: 'block' });
|
|
38
|
+
|
|
39
|
+
// if image source is provide load image source
|
|
40
|
+
if (imageSrc) {
|
|
41
|
+
this.load(imageSrc, hiResImageSrc);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// handle window resize
|
|
45
|
+
this._events.onWindowResize = assignEvent(window, 'resize', this.refresh);
|
|
46
|
+
|
|
47
|
+
// disable scroll on html
|
|
48
|
+
css(document.querySelector('html'), { overflow: 'hidden' });
|
|
49
|
+
}
|
|
50
|
+
hide = () => {
|
|
51
|
+
// hide the fullscreen
|
|
52
|
+
css(this._elements.fullScreen, { display: 'none' });
|
|
53
|
+
|
|
54
|
+
// enable scroll
|
|
55
|
+
removeCss(document.querySelector('html'), 'overflow');
|
|
56
|
+
|
|
57
|
+
// remove window event
|
|
58
|
+
if (this._events.onWindowResize) {
|
|
59
|
+
this._events.onWindowResize();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
destroy () {
|
|
63
|
+
const { fullScreen } = this._elements;
|
|
64
|
+
|
|
65
|
+
// restore scroll before removing elements
|
|
66
|
+
this.hide();
|
|
67
|
+
|
|
68
|
+
// destroy image viewer
|
|
69
|
+
super.destroy();
|
|
70
|
+
|
|
71
|
+
// remove the element
|
|
72
|
+
remove(fullScreen);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default FullScreenViewer;
|