1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | (function (global, factory) {
|
10 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
11 | typeof define === 'function' && define.amd ? define(factory) :
|
12 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, (global.eg = global.eg || {}, global.eg.view360 = factory()));
|
13 | }(this, (function () { 'use strict';
|
14 |
|
15 | var VERSION = "3.6.1";
|
16 |
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | var extendStatics = function (d, b) {
|
34 | extendStatics = Object.setPrototypeOf || {
|
35 | __proto__: []
|
36 | } instanceof Array && function (d, b) {
|
37 | d.__proto__ = b;
|
38 | } || function (d, b) {
|
39 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
40 | };
|
41 |
|
42 | return extendStatics(d, b);
|
43 | };
|
44 |
|
45 | function __extends(d, b) {
|
46 | extendStatics(d, b);
|
47 |
|
48 | function __() {
|
49 | this.constructor = d;
|
50 | }
|
51 |
|
52 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
53 | }
|
54 | var __assign = function () {
|
55 | __assign = Object.assign || function __assign(t) {
|
56 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
57 | s = arguments[i];
|
58 |
|
59 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
60 | }
|
61 |
|
62 | return t;
|
63 | };
|
64 |
|
65 | return __assign.apply(this, arguments);
|
66 | };
|
67 | function __awaiter(thisArg, _arguments, P, generator) {
|
68 | function adopt(value) {
|
69 | return value instanceof P ? value : new P(function (resolve) {
|
70 | resolve(value);
|
71 | });
|
72 | }
|
73 |
|
74 | return new (P || (P = Promise))(function (resolve, reject) {
|
75 | function fulfilled(value) {
|
76 | try {
|
77 | step(generator.next(value));
|
78 | } catch (e) {
|
79 | reject(e);
|
80 | }
|
81 | }
|
82 |
|
83 | function rejected(value) {
|
84 | try {
|
85 | step(generator["throw"](value));
|
86 | } catch (e) {
|
87 | reject(e);
|
88 | }
|
89 | }
|
90 |
|
91 | function step(result) {
|
92 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
93 | }
|
94 |
|
95 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
96 | });
|
97 | }
|
98 | function __generator(thisArg, body) {
|
99 | var _ = {
|
100 | label: 0,
|
101 | sent: function () {
|
102 | if (t[0] & 1) throw t[1];
|
103 | return t[1];
|
104 | },
|
105 | trys: [],
|
106 | ops: []
|
107 | },
|
108 | f,
|
109 | y,
|
110 | t,
|
111 | g;
|
112 | return g = {
|
113 | next: verb(0),
|
114 | "throw": verb(1),
|
115 | "return": verb(2)
|
116 | }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
117 | return this;
|
118 | }), g;
|
119 |
|
120 | function verb(n) {
|
121 | return function (v) {
|
122 | return step([n, v]);
|
123 | };
|
124 | }
|
125 |
|
126 | function step(op) {
|
127 | if (f) throw new TypeError("Generator is already executing.");
|
128 |
|
129 | while (_) try {
|
130 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
131 | if (y = 0, t) op = [op[0] & 2, t.value];
|
132 |
|
133 | switch (op[0]) {
|
134 | case 0:
|
135 | case 1:
|
136 | t = op;
|
137 | break;
|
138 |
|
139 | case 4:
|
140 | _.label++;
|
141 | return {
|
142 | value: op[1],
|
143 | done: false
|
144 | };
|
145 |
|
146 | case 5:
|
147 | _.label++;
|
148 | y = op[1];
|
149 | op = [0];
|
150 | continue;
|
151 |
|
152 | case 7:
|
153 | op = _.ops.pop();
|
154 |
|
155 | _.trys.pop();
|
156 |
|
157 | continue;
|
158 |
|
159 | default:
|
160 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
161 | _ = 0;
|
162 | continue;
|
163 | }
|
164 |
|
165 | if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
166 | _.label = op[1];
|
167 | break;
|
168 | }
|
169 |
|
170 | if (op[0] === 6 && _.label < t[1]) {
|
171 | _.label = t[1];
|
172 | t = op;
|
173 | break;
|
174 | }
|
175 |
|
176 | if (t && _.label < t[2]) {
|
177 | _.label = t[2];
|
178 |
|
179 | _.ops.push(op);
|
180 |
|
181 | break;
|
182 | }
|
183 |
|
184 | if (t[2]) _.ops.pop();
|
185 |
|
186 | _.trys.pop();
|
187 |
|
188 | continue;
|
189 | }
|
190 |
|
191 | op = body.call(thisArg, _);
|
192 | } catch (e) {
|
193 | op = [6, e];
|
194 | y = 0;
|
195 | } finally {
|
196 | f = t = 0;
|
197 | }
|
198 |
|
199 | if (op[0] & 5) throw op[1];
|
200 | return {
|
201 | value: op[0] ? op[1] : void 0,
|
202 | done: true
|
203 | };
|
204 | }
|
205 | }
|
206 | function __values(o) {
|
207 | var s = typeof Symbol === "function" && Symbol.iterator,
|
208 | m = s && o[s],
|
209 | i = 0;
|
210 | if (m) return m.call(o);
|
211 | if (o && typeof o.length === "number") return {
|
212 | next: function () {
|
213 | if (o && i >= o.length) o = void 0;
|
214 | return {
|
215 | value: o && o[i++],
|
216 | done: !o
|
217 | };
|
218 | }
|
219 | };
|
220 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
221 | }
|
222 | function __read(o, n) {
|
223 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
224 | if (!m) return o;
|
225 | var i = m.call(o),
|
226 | r,
|
227 | ar = [],
|
228 | e;
|
229 |
|
230 | try {
|
231 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
232 | } catch (error) {
|
233 | e = {
|
234 | error: error
|
235 | };
|
236 | } finally {
|
237 | try {
|
238 | if (r && !r.done && (m = i["return"])) m.call(i);
|
239 | } finally {
|
240 | if (e) throw e.error;
|
241 | }
|
242 | }
|
243 |
|
244 | return ar;
|
245 | }
|
246 | function __spread() {
|
247 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
248 |
|
249 | return ar;
|
250 | }
|
251 |
|
252 | |
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | |
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | function __values$1(o) {
|
275 | var s = typeof Symbol === "function" && Symbol.iterator,
|
276 | m = s && o[s],
|
277 | i = 0;
|
278 | if (m) return m.call(o);
|
279 | if (o && typeof o.length === "number") return {
|
280 | next: function () {
|
281 | if (o && i >= o.length) o = void 0;
|
282 | return {
|
283 | value: o && o[i++],
|
284 | done: !o
|
285 | };
|
286 | }
|
287 | };
|
288 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
289 | }
|
290 | function __read$1(o, n) {
|
291 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
292 | if (!m) return o;
|
293 | var i = m.call(o),
|
294 | r,
|
295 | ar = [],
|
296 | e;
|
297 |
|
298 | try {
|
299 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
300 | } catch (error) {
|
301 | e = {
|
302 | error: error
|
303 | };
|
304 | } finally {
|
305 | try {
|
306 | if (r && !r.done && (m = i["return"])) m.call(i);
|
307 | } finally {
|
308 | if (e) throw e.error;
|
309 | }
|
310 | }
|
311 |
|
312 | return ar;
|
313 | }
|
314 | function __spread$1() {
|
315 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read$1(arguments[i]));
|
316 |
|
317 | return ar;
|
318 | }
|
319 |
|
320 | |
321 |
|
322 |
|
323 |
|
324 | var isUndefined = function (value) {
|
325 | return typeof value === "undefined";
|
326 | };
|
327 |
|
328 | |
329 |
|
330 |
|
331 |
|
332 |
|
333 | var ComponentEvent =
|
334 |
|
335 | function () {
|
336 | |
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 | function ComponentEvent(eventType, props) {
|
343 | var e_1, _a;
|
344 |
|
345 | this.eventType = eventType;
|
346 | this._canceled = false;
|
347 | if (!props) return;
|
348 |
|
349 | try {
|
350 | for (var _b = __values$1(Object.keys(props)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
351 | var key = _c.value;
|
352 |
|
353 | this[key] = props[key];
|
354 | }
|
355 | } catch (e_1_1) {
|
356 | e_1 = {
|
357 | error: e_1_1
|
358 | };
|
359 | } finally {
|
360 | try {
|
361 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
362 | } finally {
|
363 | if (e_1) throw e_1.error;
|
364 | }
|
365 | }
|
366 | }
|
367 | |
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | var __proto = ComponentEvent.prototype;
|
374 |
|
375 | __proto.stop = function () {
|
376 | this._canceled = true;
|
377 | };
|
378 | |
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 | __proto.isCanceled = function () {
|
386 | return this._canceled;
|
387 | };
|
388 |
|
389 | return ComponentEvent;
|
390 | }();
|
391 |
|
392 | |
393 |
|
394 |
|
395 |
|
396 |
|
397 | var Component =
|
398 |
|
399 | function () {
|
400 | |
401 |
|
402 |
|
403 | function Component() {
|
404 | this._eventHandler = {};
|
405 | }
|
406 | |
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 | var __proto = Component.prototype;
|
450 |
|
451 | __proto.trigger = function (event) {
|
452 | var params = [];
|
453 |
|
454 | for (var _i = 1; _i < arguments.length; _i++) {
|
455 | params[_i - 1] = arguments[_i];
|
456 | }
|
457 |
|
458 | var eventName = event instanceof ComponentEvent ? event.eventType : event;
|
459 |
|
460 | var handlers = __spread$1(this._eventHandler[eventName] || []);
|
461 |
|
462 | if (handlers.length <= 0) {
|
463 | return this;
|
464 | }
|
465 |
|
466 | if (event instanceof ComponentEvent) {
|
467 | event.currentTarget = this;
|
468 | handlers.forEach(function (handler) {
|
469 | handler(event);
|
470 | });
|
471 | } else {
|
472 | handlers.forEach(function (handler) {
|
473 |
|
474 | handler.apply(void 0, __spread$1(params));
|
475 | });
|
476 | }
|
477 |
|
478 | return this;
|
479 | };
|
480 | |
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 | __proto.once = function (eventName, handlerToAttach) {
|
512 | var _this = this;
|
513 |
|
514 | if (typeof eventName === "object" && isUndefined(handlerToAttach)) {
|
515 | var eventHash = eventName;
|
516 |
|
517 | for (var key in eventHash) {
|
518 | this.once(key, eventHash[key]);
|
519 | }
|
520 |
|
521 | return this;
|
522 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
523 | var listener_1 = function () {
|
524 | var args = [];
|
525 |
|
526 | for (var _i = 0; _i < arguments.length; _i++) {
|
527 | args[_i] = arguments[_i];
|
528 | }
|
529 |
|
530 |
|
531 | handlerToAttach.apply(void 0, __spread$1(args));
|
532 |
|
533 | _this.off(eventName, listener_1);
|
534 | };
|
535 |
|
536 | this.on(eventName, listener_1);
|
537 | }
|
538 |
|
539 | return this;
|
540 | };
|
541 | |
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 | __proto.hasOn = function (eventName) {
|
562 | return !!this._eventHandler[eventName];
|
563 | };
|
564 | |
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 | __proto.on = function (eventName, handlerToAttach) {
|
589 | if (typeof eventName === "object" && isUndefined(handlerToAttach)) {
|
590 | var eventHash = eventName;
|
591 |
|
592 | for (var name in eventHash) {
|
593 | this.on(name, eventHash[name]);
|
594 | }
|
595 |
|
596 | return this;
|
597 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
598 | var handlerList = this._eventHandler[eventName];
|
599 |
|
600 | if (isUndefined(handlerList)) {
|
601 | this._eventHandler[eventName] = [];
|
602 | handlerList = this._eventHandler[eventName];
|
603 | }
|
604 |
|
605 | handlerList.push(handlerToAttach);
|
606 | }
|
607 |
|
608 | return this;
|
609 | };
|
610 | |
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 | __proto.off = function (eventName, handlerToDetach) {
|
635 | var e_1, _a;
|
636 |
|
637 |
|
638 | if (isUndefined(eventName)) {
|
639 | this._eventHandler = {};
|
640 | return this;
|
641 | }
|
642 |
|
643 |
|
644 | if (isUndefined(handlerToDetach)) {
|
645 | if (typeof eventName === "string") {
|
646 | delete this._eventHandler[eventName];
|
647 | return this;
|
648 | } else {
|
649 | var eventHash = eventName;
|
650 |
|
651 | for (var name in eventHash) {
|
652 | this.off(name, eventHash[name]);
|
653 | }
|
654 |
|
655 | return this;
|
656 | }
|
657 | }
|
658 |
|
659 |
|
660 | var handlerList = this._eventHandler[eventName];
|
661 |
|
662 | if (handlerList) {
|
663 | var idx = 0;
|
664 |
|
665 | try {
|
666 | for (var handlerList_1 = __values$1(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
667 | var handlerFunction = handlerList_1_1.value;
|
668 |
|
669 | if (handlerFunction === handlerToDetach) {
|
670 | handlerList.splice(idx, 1);
|
671 |
|
672 | if (handlerList.length <= 0) {
|
673 | delete this._eventHandler[eventName];
|
674 | }
|
675 |
|
676 | break;
|
677 | }
|
678 |
|
679 | idx++;
|
680 | }
|
681 | } catch (e_1_1) {
|
682 | e_1 = {
|
683 | error: e_1_1
|
684 | };
|
685 | } finally {
|
686 | try {
|
687 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
688 | } finally {
|
689 | if (e_1) throw e_1.error;
|
690 | }
|
691 | }
|
692 | }
|
693 |
|
694 | return this;
|
695 | };
|
696 | |
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 | Component.VERSION = "3.0.1";
|
708 | return Component;
|
709 | }();
|
710 |
|
711 | |
712 |
|
713 |
|
714 |
|
715 |
|
716 | var ComponentEvent$1 = ComponentEvent;
|
717 |
|
718 | |
719 |
|
720 |
|
721 | function finallyConstructor(callback) {
|
722 | var constructor = this.constructor;
|
723 | return this.then(
|
724 | function(value) {
|
725 |
|
726 | return constructor.resolve(callback()).then(function() {
|
727 | return value;
|
728 | });
|
729 | },
|
730 | function(reason) {
|
731 |
|
732 | return constructor.resolve(callback()).then(function() {
|
733 |
|
734 | return constructor.reject(reason);
|
735 | });
|
736 | }
|
737 | );
|
738 | }
|
739 |
|
740 | function allSettled(arr) {
|
741 | var P = this;
|
742 | return new P(function(resolve, reject) {
|
743 | if (!(arr && typeof arr.length !== 'undefined')) {
|
744 | return reject(
|
745 | new TypeError(
|
746 | typeof arr +
|
747 | ' ' +
|
748 | arr +
|
749 | ' is not iterable(cannot read property Symbol(Symbol.iterator))'
|
750 | )
|
751 | );
|
752 | }
|
753 | var args = Array.prototype.slice.call(arr);
|
754 | if (args.length === 0) return resolve([]);
|
755 | var remaining = args.length;
|
756 |
|
757 | function res(i, val) {
|
758 | if (val && (typeof val === 'object' || typeof val === 'function')) {
|
759 | var then = val.then;
|
760 | if (typeof then === 'function') {
|
761 | then.call(
|
762 | val,
|
763 | function(val) {
|
764 | res(i, val);
|
765 | },
|
766 | function(e) {
|
767 | args[i] = { status: 'rejected', reason: e };
|
768 | if (--remaining === 0) {
|
769 | resolve(args);
|
770 | }
|
771 | }
|
772 | );
|
773 | return;
|
774 | }
|
775 | }
|
776 | args[i] = { status: 'fulfilled', value: val };
|
777 | if (--remaining === 0) {
|
778 | resolve(args);
|
779 | }
|
780 | }
|
781 |
|
782 | for (var i = 0; i < args.length; i++) {
|
783 | res(i, args[i]);
|
784 | }
|
785 | });
|
786 | }
|
787 |
|
788 |
|
789 |
|
790 | var setTimeoutFunc = setTimeout;
|
791 |
|
792 | function isArray(x) {
|
793 | return Boolean(x && typeof x.length !== 'undefined');
|
794 | }
|
795 |
|
796 | function noop() {}
|
797 |
|
798 |
|
799 | function bind(fn, thisArg) {
|
800 | return function() {
|
801 | fn.apply(thisArg, arguments);
|
802 | };
|
803 | }
|
804 |
|
805 | |
806 |
|
807 |
|
808 |
|
809 | function Promise$1(fn) {
|
810 | if (!(this instanceof Promise$1))
|
811 | throw new TypeError('Promises must be constructed via new');
|
812 | if (typeof fn !== 'function') throw new TypeError('not a function');
|
813 |
|
814 | this._state = 0;
|
815 |
|
816 | this._handled = false;
|
817 |
|
818 | this._value = undefined;
|
819 |
|
820 | this._deferreds = [];
|
821 |
|
822 | doResolve(fn, this);
|
823 | }
|
824 |
|
825 | function handle(self, deferred) {
|
826 | while (self._state === 3) {
|
827 | self = self._value;
|
828 | }
|
829 | if (self._state === 0) {
|
830 | self._deferreds.push(deferred);
|
831 | return;
|
832 | }
|
833 | self._handled = true;
|
834 | Promise$1._immediateFn(function() {
|
835 | var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
|
836 | if (cb === null) {
|
837 | (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
|
838 | return;
|
839 | }
|
840 | var ret;
|
841 | try {
|
842 | ret = cb(self._value);
|
843 | } catch (e) {
|
844 | reject(deferred.promise, e);
|
845 | return;
|
846 | }
|
847 | resolve(deferred.promise, ret);
|
848 | });
|
849 | }
|
850 |
|
851 | function resolve(self, newValue) {
|
852 | try {
|
853 |
|
854 | if (newValue === self)
|
855 | throw new TypeError('A promise cannot be resolved with itself.');
|
856 | if (
|
857 | newValue &&
|
858 | (typeof newValue === 'object' || typeof newValue === 'function')
|
859 | ) {
|
860 | var then = newValue.then;
|
861 | if (newValue instanceof Promise$1) {
|
862 | self._state = 3;
|
863 | self._value = newValue;
|
864 | finale(self);
|
865 | return;
|
866 | } else if (typeof then === 'function') {
|
867 | doResolve(bind(then, newValue), self);
|
868 | return;
|
869 | }
|
870 | }
|
871 | self._state = 1;
|
872 | self._value = newValue;
|
873 | finale(self);
|
874 | } catch (e) {
|
875 | reject(self, e);
|
876 | }
|
877 | }
|
878 |
|
879 | function reject(self, newValue) {
|
880 | self._state = 2;
|
881 | self._value = newValue;
|
882 | finale(self);
|
883 | }
|
884 |
|
885 | function finale(self) {
|
886 | if (self._state === 2 && self._deferreds.length === 0) {
|
887 | Promise$1._immediateFn(function() {
|
888 | if (!self._handled) {
|
889 | Promise$1._unhandledRejectionFn(self._value);
|
890 | }
|
891 | });
|
892 | }
|
893 |
|
894 | for (var i = 0, len = self._deferreds.length; i < len; i++) {
|
895 | handle(self, self._deferreds[i]);
|
896 | }
|
897 | self._deferreds = null;
|
898 | }
|
899 |
|
900 | |
901 |
|
902 |
|
903 | function Handler(onFulfilled, onRejected, promise) {
|
904 | this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
905 | this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
906 | this.promise = promise;
|
907 | }
|
908 |
|
909 | |
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 | function doResolve(fn, self) {
|
916 | var done = false;
|
917 | try {
|
918 | fn(
|
919 | function(value) {
|
920 | if (done) return;
|
921 | done = true;
|
922 | resolve(self, value);
|
923 | },
|
924 | function(reason) {
|
925 | if (done) return;
|
926 | done = true;
|
927 | reject(self, reason);
|
928 | }
|
929 | );
|
930 | } catch (ex) {
|
931 | if (done) return;
|
932 | done = true;
|
933 | reject(self, ex);
|
934 | }
|
935 | }
|
936 |
|
937 | Promise$1.prototype['catch'] = function(onRejected) {
|
938 | return this.then(null, onRejected);
|
939 | };
|
940 |
|
941 | Promise$1.prototype.then = function(onFulfilled, onRejected) {
|
942 |
|
943 | var prom = new this.constructor(noop);
|
944 |
|
945 | handle(this, new Handler(onFulfilled, onRejected, prom));
|
946 | return prom;
|
947 | };
|
948 |
|
949 | Promise$1.prototype['finally'] = finallyConstructor;
|
950 |
|
951 | Promise$1.all = function(arr) {
|
952 | return new Promise$1(function(resolve, reject) {
|
953 | if (!isArray(arr)) {
|
954 | return reject(new TypeError('Promise.all accepts an array'));
|
955 | }
|
956 |
|
957 | var args = Array.prototype.slice.call(arr);
|
958 | if (args.length === 0) return resolve([]);
|
959 | var remaining = args.length;
|
960 |
|
961 | function res(i, val) {
|
962 | try {
|
963 | if (val && (typeof val === 'object' || typeof val === 'function')) {
|
964 | var then = val.then;
|
965 | if (typeof then === 'function') {
|
966 | then.call(
|
967 | val,
|
968 | function(val) {
|
969 | res(i, val);
|
970 | },
|
971 | reject
|
972 | );
|
973 | return;
|
974 | }
|
975 | }
|
976 | args[i] = val;
|
977 | if (--remaining === 0) {
|
978 | resolve(args);
|
979 | }
|
980 | } catch (ex) {
|
981 | reject(ex);
|
982 | }
|
983 | }
|
984 |
|
985 | for (var i = 0; i < args.length; i++) {
|
986 | res(i, args[i]);
|
987 | }
|
988 | });
|
989 | };
|
990 |
|
991 | Promise$1.allSettled = allSettled;
|
992 |
|
993 | Promise$1.resolve = function(value) {
|
994 | if (value && typeof value === 'object' && value.constructor === Promise$1) {
|
995 | return value;
|
996 | }
|
997 |
|
998 | return new Promise$1(function(resolve) {
|
999 | resolve(value);
|
1000 | });
|
1001 | };
|
1002 |
|
1003 | Promise$1.reject = function(value) {
|
1004 | return new Promise$1(function(resolve, reject) {
|
1005 | reject(value);
|
1006 | });
|
1007 | };
|
1008 |
|
1009 | Promise$1.race = function(arr) {
|
1010 | return new Promise$1(function(resolve, reject) {
|
1011 | if (!isArray(arr)) {
|
1012 | return reject(new TypeError('Promise.race accepts an array'));
|
1013 | }
|
1014 |
|
1015 | for (var i = 0, len = arr.length; i < len; i++) {
|
1016 | Promise$1.resolve(arr[i]).then(resolve, reject);
|
1017 | }
|
1018 | });
|
1019 | };
|
1020 |
|
1021 |
|
1022 | Promise$1._immediateFn =
|
1023 |
|
1024 | (typeof setImmediate === 'function' &&
|
1025 | function(fn) {
|
1026 |
|
1027 | setImmediate(fn);
|
1028 | }) ||
|
1029 | function(fn) {
|
1030 | setTimeoutFunc(fn, 0);
|
1031 | };
|
1032 |
|
1033 | Promise$1._unhandledRejectionFn = function _unhandledRejectionFn(err) {
|
1034 | if (typeof console !== 'undefined' && console) {
|
1035 | console.warn('Possible Unhandled Promise Rejection:', err);
|
1036 | }
|
1037 | };
|
1038 |
|
1039 | |
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 | function some(arr, callback) {
|
1048 | var length = arr.length;
|
1049 |
|
1050 | for (var i = 0; i < length; ++i) {
|
1051 | if (callback(arr[i], i)) {
|
1052 | return true;
|
1053 | }
|
1054 | }
|
1055 |
|
1056 | return false;
|
1057 | }
|
1058 | function find(arr, callback) {
|
1059 | var length = arr.length;
|
1060 |
|
1061 | for (var i = 0; i < length; ++i) {
|
1062 | if (callback(arr[i], i)) {
|
1063 | return arr[i];
|
1064 | }
|
1065 | }
|
1066 |
|
1067 | return null;
|
1068 | }
|
1069 | function getUserAgent(agent) {
|
1070 | var userAgent = agent;
|
1071 |
|
1072 | if (typeof userAgent === "undefined") {
|
1073 | if (typeof navigator === "undefined" || !navigator) {
|
1074 | return "";
|
1075 | }
|
1076 |
|
1077 | userAgent = navigator.userAgent || "";
|
1078 | }
|
1079 |
|
1080 | return userAgent.toLowerCase();
|
1081 | }
|
1082 | function execRegExp(pattern, text) {
|
1083 | try {
|
1084 | return new RegExp(pattern, "g").exec(text);
|
1085 | } catch (e) {
|
1086 | return null;
|
1087 | }
|
1088 | }
|
1089 | function hasUserAgentData() {
|
1090 | if (typeof navigator === "undefined" || !navigator || !navigator.userAgentData) {
|
1091 | return false;
|
1092 | }
|
1093 |
|
1094 | var userAgentData = navigator.userAgentData;
|
1095 | var brands = userAgentData.brands || userAgentData.uaList;
|
1096 | return !!(brands && brands.length);
|
1097 | }
|
1098 | function findVersion(versionTest, userAgent) {
|
1099 | var result = execRegExp("(" + versionTest + ")((?:\\/|\\s|:)([0-9|\\.|_]+))?", userAgent);
|
1100 | return result ? result[3] : "";
|
1101 | }
|
1102 | function convertVersion(text) {
|
1103 | return text.replace(/_/g, ".");
|
1104 | }
|
1105 | function findPreset(presets, userAgent) {
|
1106 | var userPreset = null;
|
1107 | var version = "-1";
|
1108 | some(presets, function (preset) {
|
1109 | var result = execRegExp("(" + preset.test + ")((?:\\/|\\s|:)([0-9|\\.|_]+))?", userAgent);
|
1110 |
|
1111 | if (!result || preset.brand) {
|
1112 | return false;
|
1113 | }
|
1114 |
|
1115 | userPreset = preset;
|
1116 | version = result[3] || "-1";
|
1117 |
|
1118 | if (preset.versionAlias) {
|
1119 | version = preset.versionAlias;
|
1120 | } else if (preset.versionTest) {
|
1121 | version = findVersion(preset.versionTest.toLowerCase(), userAgent) || version;
|
1122 | }
|
1123 |
|
1124 | version = convertVersion(version);
|
1125 | return true;
|
1126 | });
|
1127 | return {
|
1128 | preset: userPreset,
|
1129 | version: version
|
1130 | };
|
1131 | }
|
1132 | function findBrand(brands, preset) {
|
1133 | return find(brands, function (_a) {
|
1134 | var brand = _a.brand;
|
1135 | return execRegExp("" + preset.test, brand.toLowerCase());
|
1136 | });
|
1137 | }
|
1138 |
|
1139 | var BROWSER_PRESETS = [{
|
1140 | test: "phantomjs",
|
1141 | id: "phantomjs"
|
1142 | }, {
|
1143 | test: "whale",
|
1144 | id: "whale"
|
1145 | }, {
|
1146 | test: "edgios|edge|edg",
|
1147 | id: "edge"
|
1148 | }, {
|
1149 | test: "msie|trident|windows phone",
|
1150 | id: "ie",
|
1151 | versionTest: "iemobile|msie|rv"
|
1152 | }, {
|
1153 | test: "miuibrowser",
|
1154 | id: "miui browser"
|
1155 | }, {
|
1156 | test: "samsungbrowser",
|
1157 | id: "samsung internet"
|
1158 | }, {
|
1159 | test: "samsung",
|
1160 | id: "samsung internet",
|
1161 | versionTest: "version"
|
1162 | }, {
|
1163 | test: "chrome|crios",
|
1164 | id: "chrome"
|
1165 | }, {
|
1166 | test: "firefox|fxios",
|
1167 | id: "firefox"
|
1168 | }, {
|
1169 | test: "android",
|
1170 | id: "android browser",
|
1171 | versionTest: "version"
|
1172 | }, {
|
1173 | test: "safari|iphone|ipad|ipod",
|
1174 | id: "safari",
|
1175 | versionTest: "version"
|
1176 | }];
|
1177 |
|
1178 | var CHROMIUM_PRESETS = [{
|
1179 | test: "(?=.*applewebkit/(53[0-7]|5[0-2]|[0-4]))(?=.*\\schrome)",
|
1180 | id: "chrome"
|
1181 | }, {
|
1182 | test: "chromium",
|
1183 | id: "chrome"
|
1184 | }, {
|
1185 | test: "whale",
|
1186 | id: "chrome",
|
1187 | brand: true
|
1188 | }];
|
1189 | var WEBKIT_PRESETS = [{
|
1190 | test: "applewebkit",
|
1191 | id: "webkit"
|
1192 | }];
|
1193 | var WEBVIEW_PRESETS = [{
|
1194 | test: "(?=(iphone|ipad))(?!(.*version))",
|
1195 | id: "webview"
|
1196 | }, {
|
1197 | test: "(?=(android|iphone|ipad))(?=.*(naver|daum|; wv))",
|
1198 | id: "webview"
|
1199 | }, {
|
1200 |
|
1201 | test: "webview",
|
1202 | id: "webview"
|
1203 | }];
|
1204 | var OS_PRESETS = [{
|
1205 | test: "windows phone",
|
1206 | id: "windows phone"
|
1207 | }, {
|
1208 | test: "windows 2000",
|
1209 | id: "window",
|
1210 | versionAlias: "5.0"
|
1211 | }, {
|
1212 | test: "windows nt",
|
1213 | id: "window"
|
1214 | }, {
|
1215 | test: "iphone|ipad|ipod",
|
1216 | id: "ios",
|
1217 | versionTest: "iphone os|cpu os"
|
1218 | }, {
|
1219 | test: "mac os x",
|
1220 | id: "mac"
|
1221 | }, {
|
1222 | test: "android",
|
1223 | id: "android"
|
1224 | }, {
|
1225 | test: "tizen",
|
1226 | id: "tizen"
|
1227 | }, {
|
1228 | test: "webos|web0s",
|
1229 | id: "webos"
|
1230 | }];
|
1231 |
|
1232 | function parseUserAgentData(osData) {
|
1233 | var userAgentData = navigator.userAgentData;
|
1234 | var brands = (userAgentData.uaList || userAgentData.brands).slice();
|
1235 | var isMobile = userAgentData.mobile || false;
|
1236 | var firstBrand = brands[0];
|
1237 | var browser = {
|
1238 | name: firstBrand.brand,
|
1239 | version: firstBrand.version,
|
1240 | majorVersion: -1,
|
1241 | webkit: false,
|
1242 | webview: some(WEBVIEW_PRESETS, function (preset) {
|
1243 | return findBrand(brands, preset);
|
1244 | }),
|
1245 | chromium: some(CHROMIUM_PRESETS, function (preset) {
|
1246 | return findBrand(brands, preset);
|
1247 | })
|
1248 | };
|
1249 | var os = {
|
1250 | name: "unknown",
|
1251 | version: "-1",
|
1252 | majorVersion: -1
|
1253 | };
|
1254 | browser.webkit = !browser.chromium && some(WEBKIT_PRESETS, function (preset) {
|
1255 | return findBrand(brands, preset);
|
1256 | });
|
1257 |
|
1258 | if (osData) {
|
1259 | var platform_1 = osData.platform.toLowerCase();
|
1260 | var result = find(OS_PRESETS, function (preset) {
|
1261 | return new RegExp("" + preset.test, "g").exec(platform_1);
|
1262 | });
|
1263 | os.name = result ? result.id : platform_1;
|
1264 | os.version = osData.platformVersion;
|
1265 | }
|
1266 |
|
1267 | some(BROWSER_PRESETS, function (preset) {
|
1268 | var result = findBrand(brands, preset);
|
1269 |
|
1270 | if (!result) {
|
1271 | return false;
|
1272 | }
|
1273 |
|
1274 | browser.name = preset.id;
|
1275 | browser.version = osData ? osData.uaFullVersion : result.version;
|
1276 | return true;
|
1277 | });
|
1278 |
|
1279 | if (navigator.platform === "Linux armv8l") {
|
1280 | os.name = "android";
|
1281 | } else if (browser.webkit) {
|
1282 | os.name = isMobile ? "ios" : "mac";
|
1283 | }
|
1284 |
|
1285 | if (os.name === "ios" && browser.webview) {
|
1286 | browser.version = "-1";
|
1287 | }
|
1288 |
|
1289 | os.version = convertVersion(os.version);
|
1290 | browser.version = convertVersion(browser.version);
|
1291 | os.majorVersion = parseInt(os.version, 10);
|
1292 | browser.majorVersion = parseInt(browser.version, 10);
|
1293 | return {
|
1294 | browser: browser,
|
1295 | os: os,
|
1296 | isMobile: isMobile,
|
1297 | isHints: true
|
1298 | };
|
1299 | }
|
1300 |
|
1301 | function parseUserAgent(userAgent) {
|
1302 | var nextAgent = getUserAgent(userAgent);
|
1303 | var isMobile = !!/mobi/g.exec(nextAgent);
|
1304 | var browser = {
|
1305 | name: "unknown",
|
1306 | version: "-1",
|
1307 | majorVersion: -1,
|
1308 | webview: !!findPreset(WEBVIEW_PRESETS, nextAgent).preset,
|
1309 | chromium: !!findPreset(CHROMIUM_PRESETS, nextAgent).preset,
|
1310 | webkit: false
|
1311 | };
|
1312 | var os = {
|
1313 | name: "unknown",
|
1314 | version: "-1",
|
1315 | majorVersion: -1
|
1316 | };
|
1317 |
|
1318 | var _a = findPreset(BROWSER_PRESETS, nextAgent),
|
1319 | browserPreset = _a.preset,
|
1320 | browserVersion = _a.version;
|
1321 |
|
1322 | var _b = findPreset(OS_PRESETS, nextAgent),
|
1323 | osPreset = _b.preset,
|
1324 | osVersion = _b.version;
|
1325 |
|
1326 | browser.webkit = !browser.chromium && !!findPreset(WEBKIT_PRESETS, nextAgent).preset;
|
1327 |
|
1328 | if (osPreset) {
|
1329 | os.name = osPreset.id;
|
1330 | os.version = osVersion;
|
1331 | os.majorVersion = parseInt(osVersion, 10);
|
1332 | }
|
1333 |
|
1334 | if (browserPreset) {
|
1335 | browser.name = browserPreset.id;
|
1336 | browser.version = browserVersion;
|
1337 |
|
1338 | if (browser.webview && os.name === "ios" && browser.name !== "safari") {
|
1339 | browser.webview = false;
|
1340 | }
|
1341 | }
|
1342 |
|
1343 | browser.majorVersion = parseInt(browser.version, 10);
|
1344 | return {
|
1345 | browser: browser,
|
1346 | os: os,
|
1347 | isMobile: isMobile,
|
1348 | isHints: false
|
1349 | };
|
1350 | }
|
1351 | |
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 |
|
1363 | function agent(userAgent) {
|
1364 | if (typeof userAgent === "undefined" && hasUserAgentData()) {
|
1365 | return parseUserAgentData();
|
1366 | } else {
|
1367 | return parseUserAgent(userAgent);
|
1368 | }
|
1369 | }
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 | var win = typeof window !== "undefined" && window.Math === Math ? window : typeof self !== "undefined" && self.Math === Math ? self : Function("return this")();
|
1375 |
|
1376 |
|
1377 | var doc = win.document;
|
1378 | var nav = win.navigator;
|
1379 | var agent$1 = agent();
|
1380 | var osName = agent$1.os.name;
|
1381 | var browserName = agent$1.browser.name;
|
1382 | var IS_IOS = osName === "ios";
|
1383 | var IS_SAFARI_ON_DESKTOP = osName === "mac" && browserName === "safari";
|
1384 |
|
1385 |
|
1386 | win.Float32Array = typeof win.Float32Array !== "undefined" ? win.Float32Array : win.Array;
|
1387 | var Float32Array$1 = win.Float32Array;
|
1388 | var getComputedStyle = win.getComputedStyle;
|
1389 | var userAgent = win.navigator && win.navigator.userAgent;
|
1390 | var SUPPORT_TOUCH = ("ontouchstart" in win);
|
1391 | var SUPPORT_DEVICEMOTION = ("ondevicemotion" in win);
|
1392 | var DeviceMotionEvent = win.DeviceMotionEvent;
|
1393 | var devicePixelRatio = win.devicePixelRatio;
|
1394 |
|
1395 | var TRANSFORM = function () {
|
1396 | var _a;
|
1397 |
|
1398 | var docStyle = (_a = doc === null || doc === void 0 ? void 0 : doc.documentElement.style) !== null && _a !== void 0 ? _a : {};
|
1399 | var target = ["transform", "webkitTransform", "msTransform", "mozTransform"];
|
1400 |
|
1401 | for (var i = 0, len = target.length; i < len; i++) {
|
1402 | if (target[i] in docStyle) {
|
1403 | return target[i];
|
1404 | }
|
1405 | }
|
1406 |
|
1407 | return "";
|
1408 | }();
|
1409 |
|
1410 |
|
1411 | var SUPPORT_WILLCHANGE = win.CSS && win.CSS.supports && win.CSS.supports("will-change", "transform");
|
1412 | var WEBXR_SUPPORTED = false;
|
1413 |
|
1414 | var checkXRSupport = function () {
|
1415 | var navigator = window.navigator;
|
1416 |
|
1417 | if (!navigator.xr) {
|
1418 | return;
|
1419 | }
|
1420 |
|
1421 | if (navigator.xr.isSessionSupported) {
|
1422 | navigator.xr.isSessionSupported("immersive-vr").then(function (res) {
|
1423 | WEBXR_SUPPORTED = res;
|
1424 | }).catch(function () {
|
1425 | return void 0;
|
1426 | });
|
1427 | } else if (navigator.xr.supportsSession) {
|
1428 | navigator.xr.supportsSession("immersive-vr").then(function (res) {
|
1429 | WEBXR_SUPPORTED = res;
|
1430 | }).catch(function () {
|
1431 | return void 0;
|
1432 | });
|
1433 | }
|
1434 | };
|
1435 |
|
1436 | |
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 | function _extends() {
|
1443 | _extends = Object.assign || function (target) {
|
1444 | for (var i = 1; i < arguments.length; i++) {
|
1445 | var source = arguments[i];
|
1446 |
|
1447 | for (var key in source) {
|
1448 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1449 | target[key] = source[key];
|
1450 | }
|
1451 | }
|
1452 | }
|
1453 |
|
1454 | return target;
|
1455 | };
|
1456 |
|
1457 | return _extends.apply(this, arguments);
|
1458 | }
|
1459 |
|
1460 | function _inheritsLoose(subClass, superClass) {
|
1461 | subClass.prototype = Object.create(superClass.prototype);
|
1462 | subClass.prototype.constructor = subClass;
|
1463 | subClass.__proto__ = superClass;
|
1464 | }
|
1465 |
|
1466 | function _assertThisInitialized(self) {
|
1467 | if (self === void 0) {
|
1468 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
1469 | }
|
1470 |
|
1471 | return self;
|
1472 | }
|
1473 |
|
1474 | |
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 | var assign;
|
1483 |
|
1484 | if (typeof Object.assign !== 'function') {
|
1485 | assign = function assign(target) {
|
1486 | if (target === undefined || target === null) {
|
1487 | throw new TypeError('Cannot convert undefined or null to object');
|
1488 | }
|
1489 |
|
1490 | var output = Object(target);
|
1491 |
|
1492 | for (var index = 1; index < arguments.length; index++) {
|
1493 | var source = arguments[index];
|
1494 |
|
1495 | if (source !== undefined && source !== null) {
|
1496 | for (var nextKey in source) {
|
1497 | if (source.hasOwnProperty(nextKey)) {
|
1498 | output[nextKey] = source[nextKey];
|
1499 | }
|
1500 | }
|
1501 | }
|
1502 | }
|
1503 |
|
1504 | return output;
|
1505 | };
|
1506 | } else {
|
1507 | assign = Object.assign;
|
1508 | }
|
1509 |
|
1510 | var assign$1 = assign;
|
1511 |
|
1512 | var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
|
1513 | var TEST_ELEMENT = typeof document === "undefined" ? {
|
1514 | style: {}
|
1515 | } : document.createElement('div');
|
1516 | var TYPE_FUNCTION = 'function';
|
1517 | var round = Math.round,
|
1518 | abs = Math.abs;
|
1519 | var now = Date.now;
|
1520 |
|
1521 | |
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 | function prefixed(obj, property) {
|
1530 | var prefix;
|
1531 | var prop;
|
1532 | var camelProp = property[0].toUpperCase() + property.slice(1);
|
1533 | var i = 0;
|
1534 |
|
1535 | while (i < VENDOR_PREFIXES.length) {
|
1536 | prefix = VENDOR_PREFIXES[i];
|
1537 | prop = prefix ? prefix + camelProp : property;
|
1538 |
|
1539 | if (prop in obj) {
|
1540 | return prop;
|
1541 | }
|
1542 |
|
1543 | i++;
|
1544 | }
|
1545 |
|
1546 | return undefined;
|
1547 | }
|
1548 |
|
1549 |
|
1550 | var win$1;
|
1551 |
|
1552 | if (typeof window === "undefined") {
|
1553 |
|
1554 | win$1 = {};
|
1555 | } else {
|
1556 | win$1 = window;
|
1557 | }
|
1558 |
|
1559 | var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
|
1560 | var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
|
1561 | function getTouchActionProps() {
|
1562 | if (!NATIVE_TOUCH_ACTION) {
|
1563 | return false;
|
1564 | }
|
1565 |
|
1566 | var touchMap = {};
|
1567 | var cssSupports = win$1.CSS && win$1.CSS.supports;
|
1568 | ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function (val) {
|
1569 |
|
1570 |
|
1571 | return touchMap[val] = cssSupports ? win$1.CSS.supports('touch-action', val) : true;
|
1572 | });
|
1573 | return touchMap;
|
1574 | }
|
1575 |
|
1576 | var TOUCH_ACTION_COMPUTE = 'compute';
|
1577 | var TOUCH_ACTION_AUTO = 'auto';
|
1578 | var TOUCH_ACTION_MANIPULATION = 'manipulation';
|
1579 |
|
1580 | var TOUCH_ACTION_NONE = 'none';
|
1581 | var TOUCH_ACTION_PAN_X = 'pan-x';
|
1582 | var TOUCH_ACTION_PAN_Y = 'pan-y';
|
1583 | var TOUCH_ACTION_MAP = getTouchActionProps();
|
1584 |
|
1585 | var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
1586 | var SUPPORT_TOUCH$1 = 'ontouchstart' in win$1;
|
1587 | var SUPPORT_POINTER_EVENTS = prefixed(win$1, 'PointerEvent') !== undefined;
|
1588 | var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH$1 && MOBILE_REGEX.test(navigator.userAgent);
|
1589 | var INPUT_TYPE_TOUCH = 'touch';
|
1590 | var INPUT_TYPE_PEN = 'pen';
|
1591 | var INPUT_TYPE_MOUSE = 'mouse';
|
1592 | var INPUT_TYPE_KINECT = 'kinect';
|
1593 | var COMPUTE_INTERVAL = 25;
|
1594 | var INPUT_START = 1;
|
1595 | var INPUT_MOVE = 2;
|
1596 | var INPUT_END = 4;
|
1597 | var INPUT_CANCEL = 8;
|
1598 | var DIRECTION_NONE = 1;
|
1599 | var DIRECTION_LEFT = 2;
|
1600 | var DIRECTION_RIGHT = 4;
|
1601 | var DIRECTION_UP = 8;
|
1602 | var DIRECTION_DOWN = 16;
|
1603 | var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
|
1604 | var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
|
1605 | var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
|
1606 | var PROPS_XY = ['x', 'y'];
|
1607 | var PROPS_CLIENT_XY = ['clientX', 'clientY'];
|
1608 |
|
1609 | |
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 | function each(obj, iterator, context) {
|
1617 | var i;
|
1618 |
|
1619 | if (!obj) {
|
1620 | return;
|
1621 | }
|
1622 |
|
1623 | if (obj.forEach) {
|
1624 | obj.forEach(iterator, context);
|
1625 | } else if (obj.length !== undefined) {
|
1626 | i = 0;
|
1627 |
|
1628 | while (i < obj.length) {
|
1629 | iterator.call(context, obj[i], i, obj);
|
1630 | i++;
|
1631 | }
|
1632 | } else {
|
1633 | for (i in obj) {
|
1634 | obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
|
1635 | }
|
1636 | }
|
1637 | }
|
1638 |
|
1639 | |
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 | function boolOrFn(val, args) {
|
1649 | if (typeof val === TYPE_FUNCTION) {
|
1650 | return val.apply(args ? args[0] || undefined : undefined, args);
|
1651 | }
|
1652 |
|
1653 | return val;
|
1654 | }
|
1655 |
|
1656 | |
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 | function inStr(str, find) {
|
1664 | return str.indexOf(find) > -1;
|
1665 | }
|
1666 |
|
1667 | |
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 | function cleanTouchActions(actions) {
|
1675 |
|
1676 | if (inStr(actions, TOUCH_ACTION_NONE)) {
|
1677 | return TOUCH_ACTION_NONE;
|
1678 | }
|
1679 |
|
1680 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
|
1681 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
|
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 | if (hasPanX && hasPanY) {
|
1687 | return TOUCH_ACTION_NONE;
|
1688 | }
|
1689 |
|
1690 |
|
1691 | if (hasPanX || hasPanY) {
|
1692 | return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
|
1693 | }
|
1694 |
|
1695 |
|
1696 | if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
|
1697 | return TOUCH_ACTION_MANIPULATION;
|
1698 | }
|
1699 |
|
1700 | return TOUCH_ACTION_AUTO;
|
1701 | }
|
1702 |
|
1703 | |
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 | var TouchAction =
|
1713 |
|
1714 | function () {
|
1715 | function TouchAction(manager, value) {
|
1716 | this.manager = manager;
|
1717 | this.set(value);
|
1718 | }
|
1719 | |
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 | var _proto = TouchAction.prototype;
|
1727 |
|
1728 | _proto.set = function set(value) {
|
1729 |
|
1730 | if (value === TOUCH_ACTION_COMPUTE) {
|
1731 | value = this.compute();
|
1732 | }
|
1733 |
|
1734 | if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
|
1735 | this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
|
1736 | }
|
1737 |
|
1738 | this.actions = value.toLowerCase().trim();
|
1739 | };
|
1740 | |
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 | _proto.update = function update() {
|
1747 | this.set(this.manager.options.touchAction);
|
1748 | };
|
1749 | |
1750 |
|
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 | _proto.compute = function compute() {
|
1757 | var actions = [];
|
1758 | each(this.manager.recognizers, function (recognizer) {
|
1759 | if (boolOrFn(recognizer.options.enable, [recognizer])) {
|
1760 | actions = actions.concat(recognizer.getTouchAction());
|
1761 | }
|
1762 | });
|
1763 | return cleanTouchActions(actions.join(' '));
|
1764 | };
|
1765 | |
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 | _proto.preventDefaults = function preventDefaults(input) {
|
1773 | var srcEvent = input.srcEvent;
|
1774 | var direction = input.offsetDirection;
|
1775 |
|
1776 | if (this.manager.session.prevented) {
|
1777 | srcEvent.preventDefault();
|
1778 | return;
|
1779 | }
|
1780 |
|
1781 | var actions = this.actions;
|
1782 | var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
|
1783 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
|
1784 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
|
1785 |
|
1786 | if (hasNone) {
|
1787 |
|
1788 | var isTapPointer = input.pointers.length === 1;
|
1789 | var isTapMovement = input.distance < 2;
|
1790 | var isTapTouchTime = input.deltaTime < 250;
|
1791 |
|
1792 | if (isTapPointer && isTapMovement && isTapTouchTime) {
|
1793 | return;
|
1794 | }
|
1795 | }
|
1796 |
|
1797 | if (hasPanX && hasPanY) {
|
1798 |
|
1799 | return;
|
1800 | }
|
1801 |
|
1802 | if (hasNone || hasPanY && direction & DIRECTION_HORIZONTAL || hasPanX && direction & DIRECTION_VERTICAL) {
|
1803 | return this.preventSrc(srcEvent);
|
1804 | }
|
1805 | };
|
1806 | |
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 | _proto.preventSrc = function preventSrc(srcEvent) {
|
1814 | this.manager.session.prevented = true;
|
1815 | srcEvent.preventDefault();
|
1816 | };
|
1817 |
|
1818 | return TouchAction;
|
1819 | }();
|
1820 |
|
1821 | |
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 | function hasParent(node, parent) {
|
1830 | while (node) {
|
1831 | if (node === parent) {
|
1832 | return true;
|
1833 | }
|
1834 |
|
1835 | node = node.parentNode;
|
1836 | }
|
1837 |
|
1838 | return false;
|
1839 | }
|
1840 |
|
1841 | |
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 | function getCenter(pointers) {
|
1849 | var pointersLength = pointers.length;
|
1850 |
|
1851 | if (pointersLength === 1) {
|
1852 | return {
|
1853 | x: round(pointers[0].clientX),
|
1854 | y: round(pointers[0].clientY)
|
1855 | };
|
1856 | }
|
1857 |
|
1858 | var x = 0;
|
1859 | var y = 0;
|
1860 | var i = 0;
|
1861 |
|
1862 | while (i < pointersLength) {
|
1863 | x += pointers[i].clientX;
|
1864 | y += pointers[i].clientY;
|
1865 | i++;
|
1866 | }
|
1867 |
|
1868 | return {
|
1869 | x: round(x / pointersLength),
|
1870 | y: round(y / pointersLength)
|
1871 | };
|
1872 | }
|
1873 |
|
1874 | |
1875 |
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 |
|
1881 | function simpleCloneInputData(input) {
|
1882 |
|
1883 |
|
1884 | var pointers = [];
|
1885 | var i = 0;
|
1886 |
|
1887 | while (i < input.pointers.length) {
|
1888 | pointers[i] = {
|
1889 | clientX: round(input.pointers[i].clientX),
|
1890 | clientY: round(input.pointers[i].clientY)
|
1891 | };
|
1892 | i++;
|
1893 | }
|
1894 |
|
1895 | return {
|
1896 | timeStamp: now(),
|
1897 | pointers: pointers,
|
1898 | center: getCenter(pointers),
|
1899 | deltaX: input.deltaX,
|
1900 | deltaY: input.deltaY
|
1901 | };
|
1902 | }
|
1903 |
|
1904 | |
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 | function getDistance(p1, p2, props) {
|
1914 | if (!props) {
|
1915 | props = PROPS_XY;
|
1916 | }
|
1917 |
|
1918 | var x = p2[props[0]] - p1[props[0]];
|
1919 | var y = p2[props[1]] - p1[props[1]];
|
1920 | return Math.sqrt(x * x + y * y);
|
1921 | }
|
1922 |
|
1923 | |
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 | function getAngle(p1, p2, props) {
|
1933 | if (!props) {
|
1934 | props = PROPS_XY;
|
1935 | }
|
1936 |
|
1937 | var x = p2[props[0]] - p1[props[0]];
|
1938 | var y = p2[props[1]] - p1[props[1]];
|
1939 | return Math.atan2(y, x) * 180 / Math.PI;
|
1940 | }
|
1941 |
|
1942 | |
1943 |
|
1944 |
|
1945 |
|
1946 |
|
1947 |
|
1948 |
|
1949 |
|
1950 | function getDirection(x, y) {
|
1951 | if (x === y) {
|
1952 | return DIRECTION_NONE;
|
1953 | }
|
1954 |
|
1955 | if (abs(x) >= abs(y)) {
|
1956 | return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
1957 | }
|
1958 |
|
1959 | return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
1960 | }
|
1961 |
|
1962 | function computeDeltaXY(session, input) {
|
1963 | var center = input.center;
|
1964 |
|
1965 |
|
1966 | var offset = session.offsetDelta || {};
|
1967 | var prevDelta = session.prevDelta || {};
|
1968 | var prevInput = session.prevInput || {};
|
1969 |
|
1970 | if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
|
1971 | prevDelta = session.prevDelta = {
|
1972 | x: prevInput.deltaX || 0,
|
1973 | y: prevInput.deltaY || 0
|
1974 | };
|
1975 | offset = session.offsetDelta = {
|
1976 | x: center.x,
|
1977 | y: center.y
|
1978 | };
|
1979 | }
|
1980 |
|
1981 | input.deltaX = prevDelta.x + (center.x - offset.x);
|
1982 | input.deltaY = prevDelta.y + (center.y - offset.y);
|
1983 | }
|
1984 |
|
1985 | |
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 | function getVelocity(deltaTime, x, y) {
|
1994 | return {
|
1995 | x: x / deltaTime || 0,
|
1996 | y: y / deltaTime || 0
|
1997 | };
|
1998 | }
|
1999 |
|
2000 | |
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 | function getScale(start, end) {
|
2010 | return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
|
2011 | }
|
2012 |
|
2013 | |
2014 |
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 | function getRotation(start, end) {
|
2022 | return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
|
2023 | }
|
2024 |
|
2025 | |
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 | function computeIntervalInputData(session, input) {
|
2033 | var last = session.lastInterval || input;
|
2034 | var deltaTime = input.timeStamp - last.timeStamp;
|
2035 | var velocity;
|
2036 | var velocityX;
|
2037 | var velocityY;
|
2038 | var direction;
|
2039 |
|
2040 | if (input.eventType !== INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
|
2041 | var deltaX = input.deltaX - last.deltaX;
|
2042 | var deltaY = input.deltaY - last.deltaY;
|
2043 | var v = getVelocity(deltaTime, deltaX, deltaY);
|
2044 | velocityX = v.x;
|
2045 | velocityY = v.y;
|
2046 | velocity = abs(v.x) > abs(v.y) ? v.x : v.y;
|
2047 | direction = getDirection(deltaX, deltaY);
|
2048 | session.lastInterval = input;
|
2049 | } else {
|
2050 |
|
2051 | velocity = last.velocity;
|
2052 | velocityX = last.velocityX;
|
2053 | velocityY = last.velocityY;
|
2054 | direction = last.direction;
|
2055 | }
|
2056 |
|
2057 | input.velocity = velocity;
|
2058 | input.velocityX = velocityX;
|
2059 | input.velocityY = velocityY;
|
2060 | input.direction = direction;
|
2061 | }
|
2062 |
|
2063 | |
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 | function computeInputData(manager, input) {
|
2071 | var session = manager.session;
|
2072 | var pointers = input.pointers;
|
2073 | var pointersLength = pointers.length;
|
2074 |
|
2075 | if (!session.firstInput) {
|
2076 | session.firstInput = simpleCloneInputData(input);
|
2077 | }
|
2078 |
|
2079 |
|
2080 | if (pointersLength > 1 && !session.firstMultiple) {
|
2081 | session.firstMultiple = simpleCloneInputData(input);
|
2082 | } else if (pointersLength === 1) {
|
2083 | session.firstMultiple = false;
|
2084 | }
|
2085 |
|
2086 | var firstInput = session.firstInput,
|
2087 | firstMultiple = session.firstMultiple;
|
2088 | var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
|
2089 | var center = input.center = getCenter(pointers);
|
2090 | input.timeStamp = now();
|
2091 | input.deltaTime = input.timeStamp - firstInput.timeStamp;
|
2092 | input.angle = getAngle(offsetCenter, center);
|
2093 | input.distance = getDistance(offsetCenter, center);
|
2094 | computeDeltaXY(session, input);
|
2095 | input.offsetDirection = getDirection(input.deltaX, input.deltaY);
|
2096 | var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
|
2097 | input.overallVelocityX = overallVelocity.x;
|
2098 | input.overallVelocityY = overallVelocity.y;
|
2099 | input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
|
2100 | input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
|
2101 | input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
|
2102 | input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
|
2103 | computeIntervalInputData(session, input);
|
2104 |
|
2105 | var target = manager.element;
|
2106 | var srcEvent = input.srcEvent;
|
2107 | var srcEventTarget;
|
2108 |
|
2109 | if (srcEvent.composedPath) {
|
2110 | srcEventTarget = srcEvent.composedPath()[0];
|
2111 | } else if (srcEvent.path) {
|
2112 | srcEventTarget = srcEvent.path[0];
|
2113 | } else {
|
2114 | srcEventTarget = srcEvent.target;
|
2115 | }
|
2116 |
|
2117 | if (hasParent(srcEventTarget, target)) {
|
2118 | target = srcEventTarget;
|
2119 | }
|
2120 |
|
2121 | input.target = target;
|
2122 | }
|
2123 |
|
2124 | |
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 | function inputHandler(manager, eventType, input) {
|
2133 | var pointersLen = input.pointers.length;
|
2134 | var changedPointersLen = input.changedPointers.length;
|
2135 | var isFirst = eventType & INPUT_START && pointersLen - changedPointersLen === 0;
|
2136 | var isFinal = eventType & (INPUT_END | INPUT_CANCEL) && pointersLen - changedPointersLen === 0;
|
2137 | input.isFirst = !!isFirst;
|
2138 | input.isFinal = !!isFinal;
|
2139 |
|
2140 | if (isFirst) {
|
2141 | manager.session = {};
|
2142 | }
|
2143 |
|
2144 |
|
2145 |
|
2146 | input.eventType = eventType;
|
2147 |
|
2148 | computeInputData(manager, input);
|
2149 |
|
2150 | manager.emit('hammer.input', input);
|
2151 | manager.recognize(input);
|
2152 | manager.session.prevInput = input;
|
2153 | }
|
2154 |
|
2155 | |
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 | function splitStr(str) {
|
2162 | return str.trim().split(/\s+/g);
|
2163 | }
|
2164 |
|
2165 | |
2166 |
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 | function addEventListeners(target, types, handler) {
|
2174 | each(splitStr(types), function (type) {
|
2175 | target.addEventListener(type, handler, false);
|
2176 | });
|
2177 | }
|
2178 |
|
2179 | |
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 | function removeEventListeners(target, types, handler) {
|
2188 | each(splitStr(types), function (type) {
|
2189 | target.removeEventListener(type, handler, false);
|
2190 | });
|
2191 | }
|
2192 |
|
2193 | |
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 | function getWindowForElement(element) {
|
2200 | var doc = element.ownerDocument || element;
|
2201 | return doc.defaultView || doc.parentWindow || window;
|
2202 | }
|
2203 |
|
2204 | |
2205 |
|
2206 |
|
2207 |
|
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 | var Input =
|
2214 |
|
2215 | function () {
|
2216 | function Input(manager, callback) {
|
2217 | var self = this;
|
2218 | this.manager = manager;
|
2219 | this.callback = callback;
|
2220 | this.element = manager.element;
|
2221 | this.target = manager.options.inputTarget;
|
2222 |
|
2223 |
|
2224 | this.domHandler = function (ev) {
|
2225 | if (boolOrFn(manager.options.enable, [manager])) {
|
2226 | self.handler(ev);
|
2227 | }
|
2228 | };
|
2229 |
|
2230 | this.init();
|
2231 | }
|
2232 | |
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 |
|
2239 | var _proto = Input.prototype;
|
2240 |
|
2241 | _proto.handler = function handler() {};
|
2242 | |
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 |
|
2248 | _proto.init = function init() {
|
2249 | this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
|
2250 | this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
|
2251 | this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
2252 | };
|
2253 | |
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 | _proto.destroy = function destroy() {
|
2260 | this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
|
2261 | this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
|
2262 | this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
2263 | };
|
2264 |
|
2265 | return Input;
|
2266 | }();
|
2267 |
|
2268 | |
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 | function inArray(src, find, findByKey) {
|
2277 | if (src.indexOf && !findByKey) {
|
2278 | return src.indexOf(find);
|
2279 | } else {
|
2280 | var i = 0;
|
2281 |
|
2282 | while (i < src.length) {
|
2283 | if (findByKey && src[i][findByKey] == find || !findByKey && src[i] === find) {
|
2284 |
|
2285 | return i;
|
2286 | }
|
2287 |
|
2288 | i++;
|
2289 | }
|
2290 |
|
2291 | return -1;
|
2292 | }
|
2293 | }
|
2294 |
|
2295 | var POINTER_INPUT_MAP = {
|
2296 | pointerdown: INPUT_START,
|
2297 | pointermove: INPUT_MOVE,
|
2298 | pointerup: INPUT_END,
|
2299 | pointercancel: INPUT_CANCEL,
|
2300 | pointerout: INPUT_CANCEL
|
2301 | };
|
2302 |
|
2303 | var IE10_POINTER_TYPE_ENUM = {
|
2304 | 2: INPUT_TYPE_TOUCH,
|
2305 | 3: INPUT_TYPE_PEN,
|
2306 | 4: INPUT_TYPE_MOUSE,
|
2307 | 5: INPUT_TYPE_KINECT
|
2308 |
|
2309 | };
|
2310 | var POINTER_ELEMENT_EVENTS = 'pointerdown';
|
2311 | var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
|
2312 |
|
2313 | if (win$1.MSPointerEvent && !win$1.PointerEvent) {
|
2314 | POINTER_ELEMENT_EVENTS = 'MSPointerDown';
|
2315 | POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
|
2316 | }
|
2317 | |
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 | var PointerEventInput =
|
2326 |
|
2327 | function (_Input) {
|
2328 | _inheritsLoose(PointerEventInput, _Input);
|
2329 |
|
2330 | function PointerEventInput() {
|
2331 | var _this;
|
2332 |
|
2333 | var proto = PointerEventInput.prototype;
|
2334 | proto.evEl = POINTER_ELEMENT_EVENTS;
|
2335 | proto.evWin = POINTER_WINDOW_EVENTS;
|
2336 | _this = _Input.apply(this, arguments) || this;
|
2337 | _this.store = _this.manager.session.pointerEvents = [];
|
2338 | return _this;
|
2339 | }
|
2340 | |
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 |
|
2347 | var _proto = PointerEventInput.prototype;
|
2348 |
|
2349 | _proto.handler = function handler(ev) {
|
2350 | var store = this.store;
|
2351 | var removePointer = false;
|
2352 | var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
|
2353 | var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
|
2354 | var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
|
2355 | var isTouch = pointerType === INPUT_TYPE_TOUCH;
|
2356 |
|
2357 | var storeIndex = inArray(store, ev.pointerId, 'pointerId');
|
2358 |
|
2359 | if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
|
2360 | if (storeIndex < 0) {
|
2361 | store.push(ev);
|
2362 | storeIndex = store.length - 1;
|
2363 | }
|
2364 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
2365 | removePointer = true;
|
2366 | }
|
2367 |
|
2368 |
|
2369 | if (storeIndex < 0) {
|
2370 | return;
|
2371 | }
|
2372 |
|
2373 |
|
2374 | store[storeIndex] = ev;
|
2375 | this.callback(this.manager, eventType, {
|
2376 | pointers: store,
|
2377 | changedPointers: [ev],
|
2378 | pointerType: pointerType,
|
2379 | srcEvent: ev
|
2380 | });
|
2381 |
|
2382 | if (removePointer) {
|
2383 |
|
2384 | store.splice(storeIndex, 1);
|
2385 | }
|
2386 | };
|
2387 |
|
2388 | return PointerEventInput;
|
2389 | }(Input);
|
2390 |
|
2391 | |
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 | function toArray(obj) {
|
2398 | return Array.prototype.slice.call(obj, 0);
|
2399 | }
|
2400 |
|
2401 | |
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 |
|
2410 | function uniqueArray(src, key, sort) {
|
2411 | var results = [];
|
2412 | var values = [];
|
2413 | var i = 0;
|
2414 |
|
2415 | while (i < src.length) {
|
2416 | var val = key ? src[i][key] : src[i];
|
2417 |
|
2418 | if (inArray(values, val) < 0) {
|
2419 | results.push(src[i]);
|
2420 | }
|
2421 |
|
2422 | values[i] = val;
|
2423 | i++;
|
2424 | }
|
2425 |
|
2426 | if (sort) {
|
2427 | if (!key) {
|
2428 | results = results.sort();
|
2429 | } else {
|
2430 | results = results.sort(function (a, b) {
|
2431 | return a[key] > b[key];
|
2432 | });
|
2433 | }
|
2434 | }
|
2435 |
|
2436 | return results;
|
2437 | }
|
2438 |
|
2439 | var TOUCH_INPUT_MAP = {
|
2440 | touchstart: INPUT_START,
|
2441 | touchmove: INPUT_MOVE,
|
2442 | touchend: INPUT_END,
|
2443 | touchcancel: INPUT_CANCEL
|
2444 | };
|
2445 | var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
|
2446 | |
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 | var TouchInput =
|
2454 |
|
2455 | function (_Input) {
|
2456 | _inheritsLoose(TouchInput, _Input);
|
2457 |
|
2458 | function TouchInput() {
|
2459 | var _this;
|
2460 |
|
2461 | TouchInput.prototype.evTarget = TOUCH_TARGET_EVENTS;
|
2462 | _this = _Input.apply(this, arguments) || this;
|
2463 | _this.targetIds = {};
|
2464 |
|
2465 | return _this;
|
2466 | }
|
2467 |
|
2468 | var _proto = TouchInput.prototype;
|
2469 |
|
2470 | _proto.handler = function handler(ev) {
|
2471 | var type = TOUCH_INPUT_MAP[ev.type];
|
2472 | var touches = getTouches.call(this, ev, type);
|
2473 |
|
2474 | if (!touches) {
|
2475 | return;
|
2476 | }
|
2477 |
|
2478 | this.callback(this.manager, type, {
|
2479 | pointers: touches[0],
|
2480 | changedPointers: touches[1],
|
2481 | pointerType: INPUT_TYPE_TOUCH,
|
2482 | srcEvent: ev
|
2483 | });
|
2484 | };
|
2485 |
|
2486 | return TouchInput;
|
2487 | }(Input);
|
2488 |
|
2489 | function getTouches(ev, type) {
|
2490 | var allTouches = toArray(ev.touches);
|
2491 | var targetIds = this.targetIds;
|
2492 |
|
2493 | if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
|
2494 | targetIds[allTouches[0].identifier] = true;
|
2495 | return [allTouches, allTouches];
|
2496 | }
|
2497 |
|
2498 | var i;
|
2499 | var targetTouches;
|
2500 | var changedTouches = toArray(ev.changedTouches);
|
2501 | var changedTargetTouches = [];
|
2502 | var target = this.target;
|
2503 |
|
2504 | targetTouches = allTouches.filter(function (touch) {
|
2505 | return hasParent(touch.target, target);
|
2506 | });
|
2507 |
|
2508 | if (type === INPUT_START) {
|
2509 | i = 0;
|
2510 |
|
2511 | while (i < targetTouches.length) {
|
2512 | targetIds[targetTouches[i].identifier] = true;
|
2513 | i++;
|
2514 | }
|
2515 | }
|
2516 |
|
2517 |
|
2518 | i = 0;
|
2519 |
|
2520 | while (i < changedTouches.length) {
|
2521 | if (targetIds[changedTouches[i].identifier]) {
|
2522 | changedTargetTouches.push(changedTouches[i]);
|
2523 | }
|
2524 |
|
2525 |
|
2526 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
2527 | delete targetIds[changedTouches[i].identifier];
|
2528 | }
|
2529 |
|
2530 | i++;
|
2531 | }
|
2532 |
|
2533 | if (!changedTargetTouches.length) {
|
2534 | return;
|
2535 | }
|
2536 |
|
2537 | return [
|
2538 | uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true), changedTargetTouches];
|
2539 | }
|
2540 |
|
2541 | var MOUSE_INPUT_MAP = {
|
2542 | mousedown: INPUT_START,
|
2543 | mousemove: INPUT_MOVE,
|
2544 | mouseup: INPUT_END
|
2545 | };
|
2546 | var MOUSE_ELEMENT_EVENTS = 'mousedown';
|
2547 | var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
|
2548 | |
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 | var MouseInput =
|
2556 |
|
2557 | function (_Input) {
|
2558 | _inheritsLoose(MouseInput, _Input);
|
2559 |
|
2560 | function MouseInput() {
|
2561 | var _this;
|
2562 |
|
2563 | var proto = MouseInput.prototype;
|
2564 | proto.evEl = MOUSE_ELEMENT_EVENTS;
|
2565 | proto.evWin = MOUSE_WINDOW_EVENTS;
|
2566 | _this = _Input.apply(this, arguments) || this;
|
2567 | _this.pressed = false;
|
2568 |
|
2569 | return _this;
|
2570 | }
|
2571 | |
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 | var _proto = MouseInput.prototype;
|
2579 |
|
2580 | _proto.handler = function handler(ev) {
|
2581 | var eventType = MOUSE_INPUT_MAP[ev.type];
|
2582 |
|
2583 | if (eventType & INPUT_START && ev.button === 0) {
|
2584 | this.pressed = true;
|
2585 | }
|
2586 |
|
2587 | if (eventType & INPUT_MOVE && ev.which !== 1) {
|
2588 | eventType = INPUT_END;
|
2589 | }
|
2590 |
|
2591 |
|
2592 | if (!this.pressed) {
|
2593 | return;
|
2594 | }
|
2595 |
|
2596 | if (eventType & INPUT_END) {
|
2597 | this.pressed = false;
|
2598 | }
|
2599 |
|
2600 | this.callback(this.manager, eventType, {
|
2601 | pointers: [ev],
|
2602 | changedPointers: [ev],
|
2603 | pointerType: INPUT_TYPE_MOUSE,
|
2604 | srcEvent: ev
|
2605 | });
|
2606 | };
|
2607 |
|
2608 | return MouseInput;
|
2609 | }(Input);
|
2610 |
|
2611 | |
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 | var DEDUP_TIMEOUT = 2500;
|
2623 | var DEDUP_DISTANCE = 25;
|
2624 |
|
2625 | function setLastTouch(eventData) {
|
2626 | var _eventData$changedPoi = eventData.changedPointers,
|
2627 | touch = _eventData$changedPoi[0];
|
2628 |
|
2629 | if (touch.identifier === this.primaryTouch) {
|
2630 | var lastTouch = {
|
2631 | x: touch.clientX,
|
2632 | y: touch.clientY
|
2633 | };
|
2634 | var lts = this.lastTouches;
|
2635 | this.lastTouches.push(lastTouch);
|
2636 |
|
2637 | var removeLastTouch = function removeLastTouch() {
|
2638 | var i = lts.indexOf(lastTouch);
|
2639 |
|
2640 | if (i > -1) {
|
2641 | lts.splice(i, 1);
|
2642 | }
|
2643 | };
|
2644 |
|
2645 | setTimeout(removeLastTouch, DEDUP_TIMEOUT);
|
2646 | }
|
2647 | }
|
2648 |
|
2649 | function recordTouches(eventType, eventData) {
|
2650 | if (eventType & INPUT_START) {
|
2651 | this.primaryTouch = eventData.changedPointers[0].identifier;
|
2652 | setLastTouch.call(this, eventData);
|
2653 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
2654 | setLastTouch.call(this, eventData);
|
2655 | }
|
2656 | }
|
2657 |
|
2658 | function isSyntheticEvent(eventData) {
|
2659 | var x = eventData.srcEvent.clientX;
|
2660 | var y = eventData.srcEvent.clientY;
|
2661 |
|
2662 | for (var i = 0; i < this.lastTouches.length; i++) {
|
2663 | var t = this.lastTouches[i];
|
2664 | var dx = Math.abs(x - t.x);
|
2665 | var dy = Math.abs(y - t.y);
|
2666 |
|
2667 | if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
|
2668 | return true;
|
2669 | }
|
2670 | }
|
2671 |
|
2672 | return false;
|
2673 | }
|
2674 |
|
2675 | var TouchMouseInput =
|
2676 |
|
2677 | function () {
|
2678 | var TouchMouseInput =
|
2679 |
|
2680 | function (_Input) {
|
2681 | _inheritsLoose(TouchMouseInput, _Input);
|
2682 |
|
2683 | function TouchMouseInput(_manager, callback) {
|
2684 | var _this;
|
2685 |
|
2686 | _this = _Input.call(this, _manager, callback) || this;
|
2687 |
|
2688 | _this.handler = function (manager, inputEvent, inputData) {
|
2689 | var isTouch = inputData.pointerType === INPUT_TYPE_TOUCH;
|
2690 | var isMouse = inputData.pointerType === INPUT_TYPE_MOUSE;
|
2691 |
|
2692 | if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
|
2693 | return;
|
2694 | }
|
2695 |
|
2696 |
|
2697 | if (isTouch) {
|
2698 | recordTouches.call(_assertThisInitialized(_assertThisInitialized(_this)), inputEvent, inputData);
|
2699 | } else if (isMouse && isSyntheticEvent.call(_assertThisInitialized(_assertThisInitialized(_this)), inputData)) {
|
2700 | return;
|
2701 | }
|
2702 |
|
2703 | _this.callback(manager, inputEvent, inputData);
|
2704 | };
|
2705 |
|
2706 | _this.touch = new TouchInput(_this.manager, _this.handler);
|
2707 | _this.mouse = new MouseInput(_this.manager, _this.handler);
|
2708 | _this.primaryTouch = null;
|
2709 | _this.lastTouches = [];
|
2710 | return _this;
|
2711 | }
|
2712 | |
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 | var _proto = TouchMouseInput.prototype;
|
2722 |
|
2723 | |
2724 |
|
2725 |
|
2726 |
|
2727 | _proto.destroy = function destroy() {
|
2728 | this.touch.destroy();
|
2729 | this.mouse.destroy();
|
2730 | };
|
2731 |
|
2732 | return TouchMouseInput;
|
2733 | }(Input);
|
2734 |
|
2735 | return TouchMouseInput;
|
2736 | }();
|
2737 |
|
2738 | |
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 | function createInputInstance(manager) {
|
2747 | var Type;
|
2748 |
|
2749 | var inputClass = manager.options.inputClass;
|
2750 |
|
2751 | if (inputClass) {
|
2752 | Type = inputClass;
|
2753 | } else if (SUPPORT_POINTER_EVENTS) {
|
2754 | Type = PointerEventInput;
|
2755 | } else if (SUPPORT_ONLY_TOUCH) {
|
2756 | Type = TouchInput;
|
2757 | } else if (!SUPPORT_TOUCH$1) {
|
2758 | Type = MouseInput;
|
2759 | } else {
|
2760 | Type = TouchMouseInput;
|
2761 | }
|
2762 |
|
2763 | return new Type(manager, inputHandler);
|
2764 | }
|
2765 |
|
2766 | |
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 | function invokeArrayArg(arg, fn, context) {
|
2778 | if (Array.isArray(arg)) {
|
2779 | each(arg, context[fn], context);
|
2780 | return true;
|
2781 | }
|
2782 |
|
2783 | return false;
|
2784 | }
|
2785 |
|
2786 | var STATE_POSSIBLE = 1;
|
2787 | var STATE_BEGAN = 2;
|
2788 | var STATE_CHANGED = 4;
|
2789 | var STATE_ENDED = 8;
|
2790 | var STATE_RECOGNIZED = STATE_ENDED;
|
2791 | var STATE_CANCELLED = 16;
|
2792 | var STATE_FAILED = 32;
|
2793 |
|
2794 | |
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 | var _uniqueId = 1;
|
2800 | function uniqueId() {
|
2801 | return _uniqueId++;
|
2802 | }
|
2803 |
|
2804 | |
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 | function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
|
2812 | var manager = recognizer.manager;
|
2813 |
|
2814 | if (manager) {
|
2815 | return manager.get(otherRecognizer);
|
2816 | }
|
2817 |
|
2818 | return otherRecognizer;
|
2819 | }
|
2820 |
|
2821 | |
2822 |
|
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 | function stateStr(state) {
|
2829 | if (state & STATE_CANCELLED) {
|
2830 | return 'cancel';
|
2831 | } else if (state & STATE_ENDED) {
|
2832 | return 'end';
|
2833 | } else if (state & STATE_CHANGED) {
|
2834 | return 'move';
|
2835 | } else if (state & STATE_BEGAN) {
|
2836 | return 'start';
|
2837 | }
|
2838 |
|
2839 | return '';
|
2840 | }
|
2841 |
|
2842 | |
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 |
|
2858 |
|
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 | |
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 |
|
2879 | var Recognizer =
|
2880 |
|
2881 | function () {
|
2882 | function Recognizer(options) {
|
2883 | if (options === void 0) {
|
2884 | options = {};
|
2885 | }
|
2886 |
|
2887 | this.options = _extends({
|
2888 | enable: true
|
2889 | }, options);
|
2890 | this.id = uniqueId();
|
2891 | this.manager = null;
|
2892 |
|
2893 | this.state = STATE_POSSIBLE;
|
2894 | this.simultaneous = {};
|
2895 | this.requireFail = [];
|
2896 | }
|
2897 | |
2898 |
|
2899 |
|
2900 |
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 | var _proto = Recognizer.prototype;
|
2906 |
|
2907 | _proto.set = function set(options) {
|
2908 | assign$1(this.options, options);
|
2909 |
|
2910 | this.manager && this.manager.touchAction.update();
|
2911 | return this;
|
2912 | };
|
2913 | |
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 | _proto.recognizeWith = function recognizeWith(otherRecognizer) {
|
2922 | if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
|
2923 | return this;
|
2924 | }
|
2925 |
|
2926 | var simultaneous = this.simultaneous;
|
2927 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2928 |
|
2929 | if (!simultaneous[otherRecognizer.id]) {
|
2930 | simultaneous[otherRecognizer.id] = otherRecognizer;
|
2931 | otherRecognizer.recognizeWith(this);
|
2932 | }
|
2933 |
|
2934 | return this;
|
2935 | };
|
2936 | |
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 |
|
2942 |
|
2943 |
|
2944 | _proto.dropRecognizeWith = function dropRecognizeWith(otherRecognizer) {
|
2945 | if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
|
2946 | return this;
|
2947 | }
|
2948 |
|
2949 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2950 | delete this.simultaneous[otherRecognizer.id];
|
2951 | return this;
|
2952 | };
|
2953 | |
2954 |
|
2955 |
|
2956 |
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 | _proto.requireFailure = function requireFailure(otherRecognizer) {
|
2962 | if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
|
2963 | return this;
|
2964 | }
|
2965 |
|
2966 | var requireFail = this.requireFail;
|
2967 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2968 |
|
2969 | if (inArray(requireFail, otherRecognizer) === -1) {
|
2970 | requireFail.push(otherRecognizer);
|
2971 | otherRecognizer.requireFailure(this);
|
2972 | }
|
2973 |
|
2974 | return this;
|
2975 | };
|
2976 | |
2977 |
|
2978 |
|
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 |
|
2984 | _proto.dropRequireFailure = function dropRequireFailure(otherRecognizer) {
|
2985 | if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
|
2986 | return this;
|
2987 | }
|
2988 |
|
2989 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2990 | var index = inArray(this.requireFail, otherRecognizer);
|
2991 |
|
2992 | if (index > -1) {
|
2993 | this.requireFail.splice(index, 1);
|
2994 | }
|
2995 |
|
2996 | return this;
|
2997 | };
|
2998 | |
2999 |
|
3000 |
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 | _proto.hasRequireFailures = function hasRequireFailures() {
|
3006 | return this.requireFail.length > 0;
|
3007 | };
|
3008 | |
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 | _proto.canRecognizeWith = function canRecognizeWith(otherRecognizer) {
|
3017 | return !!this.simultaneous[otherRecognizer.id];
|
3018 | };
|
3019 | |
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 |
|
3026 |
|
3027 | _proto.emit = function emit(input) {
|
3028 | var self = this;
|
3029 | var state = this.state;
|
3030 |
|
3031 | function emit(event) {
|
3032 | self.manager.emit(event, input);
|
3033 | }
|
3034 |
|
3035 |
|
3036 | if (state < STATE_ENDED) {
|
3037 | emit(self.options.event + stateStr(state));
|
3038 | }
|
3039 |
|
3040 | emit(self.options.event);
|
3041 |
|
3042 | if (input.additionalEvent) {
|
3043 |
|
3044 | emit(input.additionalEvent);
|
3045 | }
|
3046 |
|
3047 |
|
3048 | if (state >= STATE_ENDED) {
|
3049 | emit(self.options.event + stateStr(state));
|
3050 | }
|
3051 | };
|
3052 | |
3053 |
|
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 | _proto.tryEmit = function tryEmit(input) {
|
3062 | if (this.canEmit()) {
|
3063 | return this.emit(input);
|
3064 | }
|
3065 |
|
3066 |
|
3067 | this.state = STATE_FAILED;
|
3068 | };
|
3069 | |
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 | _proto.canEmit = function canEmit() {
|
3077 | var i = 0;
|
3078 |
|
3079 | while (i < this.requireFail.length) {
|
3080 | if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
|
3081 | return false;
|
3082 | }
|
3083 |
|
3084 | i++;
|
3085 | }
|
3086 |
|
3087 | return true;
|
3088 | };
|
3089 | |
3090 |
|
3091 |
|
3092 |
|
3093 |
|
3094 |
|
3095 |
|
3096 | _proto.recognize = function recognize(inputData) {
|
3097 |
|
3098 |
|
3099 | var inputDataClone = assign$1({}, inputData);
|
3100 |
|
3101 | if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
|
3102 | this.reset();
|
3103 | this.state = STATE_FAILED;
|
3104 | return;
|
3105 | }
|
3106 |
|
3107 |
|
3108 | if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
|
3109 | this.state = STATE_POSSIBLE;
|
3110 | }
|
3111 |
|
3112 | this.state = this.process(inputDataClone);
|
3113 |
|
3114 |
|
3115 | if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
|
3116 | this.tryEmit(inputDataClone);
|
3117 | }
|
3118 | };
|
3119 | |
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 |
|
3131 | _proto.process = function process(inputData) {};
|
3132 |
|
3133 |
|
3134 | |
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 | _proto.getTouchAction = function getTouchAction() {};
|
3143 | |
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 |
|
3151 | _proto.reset = function reset() {};
|
3152 |
|
3153 | return Recognizer;
|
3154 | }();
|
3155 |
|
3156 | |
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 | var AttrRecognizer =
|
3164 |
|
3165 | function (_Recognizer) {
|
3166 | _inheritsLoose(AttrRecognizer, _Recognizer);
|
3167 |
|
3168 | function AttrRecognizer(options) {
|
3169 | if (options === void 0) {
|
3170 | options = {};
|
3171 | }
|
3172 |
|
3173 | return _Recognizer.call(this, _extends({
|
3174 | pointers: 1
|
3175 | }, options)) || this;
|
3176 | }
|
3177 | |
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 | var _proto = AttrRecognizer.prototype;
|
3187 |
|
3188 | _proto.attrTest = function attrTest(input) {
|
3189 | var optionPointers = this.options.pointers;
|
3190 | return optionPointers === 0 || input.pointers.length === optionPointers;
|
3191 | };
|
3192 | |
3193 |
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 | _proto.process = function process(input) {
|
3202 | var state = this.state;
|
3203 | var eventType = input.eventType;
|
3204 | var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
|
3205 | var isValid = this.attrTest(input);
|
3206 |
|
3207 | if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
|
3208 | return state | STATE_CANCELLED;
|
3209 | } else if (isRecognized || isValid) {
|
3210 | if (eventType & INPUT_END) {
|
3211 | return state | STATE_ENDED;
|
3212 | } else if (!(state & STATE_BEGAN)) {
|
3213 | return STATE_BEGAN;
|
3214 | }
|
3215 |
|
3216 | return state | STATE_CHANGED;
|
3217 | }
|
3218 |
|
3219 | return STATE_FAILED;
|
3220 | };
|
3221 |
|
3222 | return AttrRecognizer;
|
3223 | }(Recognizer);
|
3224 |
|
3225 | |
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 | function directionStr(direction) {
|
3233 | if (direction === DIRECTION_DOWN) {
|
3234 | return 'down';
|
3235 | } else if (direction === DIRECTION_UP) {
|
3236 | return 'up';
|
3237 | } else if (direction === DIRECTION_LEFT) {
|
3238 | return 'left';
|
3239 | } else if (direction === DIRECTION_RIGHT) {
|
3240 | return 'right';
|
3241 | }
|
3242 |
|
3243 | return '';
|
3244 | }
|
3245 |
|
3246 | |
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 | var PanRecognizer =
|
3255 |
|
3256 | function (_AttrRecognizer) {
|
3257 | _inheritsLoose(PanRecognizer, _AttrRecognizer);
|
3258 |
|
3259 | function PanRecognizer(options) {
|
3260 | var _this;
|
3261 |
|
3262 | if (options === void 0) {
|
3263 | options = {};
|
3264 | }
|
3265 |
|
3266 | _this = _AttrRecognizer.call(this, _extends({
|
3267 | event: 'pan',
|
3268 | threshold: 10,
|
3269 | pointers: 1,
|
3270 | direction: DIRECTION_ALL
|
3271 | }, options)) || this;
|
3272 | _this.pX = null;
|
3273 | _this.pY = null;
|
3274 | return _this;
|
3275 | }
|
3276 |
|
3277 | var _proto = PanRecognizer.prototype;
|
3278 |
|
3279 | _proto.getTouchAction = function getTouchAction() {
|
3280 | var direction = this.options.direction;
|
3281 | var actions = [];
|
3282 |
|
3283 | if (direction & DIRECTION_HORIZONTAL) {
|
3284 | actions.push(TOUCH_ACTION_PAN_Y);
|
3285 | }
|
3286 |
|
3287 | if (direction & DIRECTION_VERTICAL) {
|
3288 | actions.push(TOUCH_ACTION_PAN_X);
|
3289 | }
|
3290 |
|
3291 | return actions;
|
3292 | };
|
3293 |
|
3294 | _proto.directionTest = function directionTest(input) {
|
3295 | var options = this.options;
|
3296 | var hasMoved = true;
|
3297 | var distance = input.distance;
|
3298 | var direction = input.direction;
|
3299 | var x = input.deltaX;
|
3300 | var y = input.deltaY;
|
3301 |
|
3302 | if (!(direction & options.direction)) {
|
3303 | if (options.direction & DIRECTION_HORIZONTAL) {
|
3304 | direction = x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
3305 | hasMoved = x !== this.pX;
|
3306 | distance = Math.abs(input.deltaX);
|
3307 | } else {
|
3308 | direction = y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
3309 | hasMoved = y !== this.pY;
|
3310 | distance = Math.abs(input.deltaY);
|
3311 | }
|
3312 | }
|
3313 |
|
3314 | input.direction = direction;
|
3315 | return hasMoved && distance > options.threshold && direction & options.direction;
|
3316 | };
|
3317 |
|
3318 | _proto.attrTest = function attrTest(input) {
|
3319 | return AttrRecognizer.prototype.attrTest.call(this, input) && (
|
3320 | this.state & STATE_BEGAN || !(this.state & STATE_BEGAN) && this.directionTest(input));
|
3321 | };
|
3322 |
|
3323 | _proto.emit = function emit(input) {
|
3324 | this.pX = input.deltaX;
|
3325 | this.pY = input.deltaY;
|
3326 | var direction = directionStr(input.direction);
|
3327 |
|
3328 | if (direction) {
|
3329 | input.additionalEvent = this.options.event + direction;
|
3330 | }
|
3331 |
|
3332 | _AttrRecognizer.prototype.emit.call(this, input);
|
3333 | };
|
3334 |
|
3335 | return PanRecognizer;
|
3336 | }(AttrRecognizer);
|
3337 |
|
3338 | |
3339 |
|
3340 |
|
3341 |
|
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 | var PinchRecognizer =
|
3347 |
|
3348 | function (_AttrRecognizer) {
|
3349 | _inheritsLoose(PinchRecognizer, _AttrRecognizer);
|
3350 |
|
3351 | function PinchRecognizer(options) {
|
3352 | if (options === void 0) {
|
3353 | options = {};
|
3354 | }
|
3355 |
|
3356 | return _AttrRecognizer.call(this, _extends({
|
3357 | event: 'pinch',
|
3358 | threshold: 0,
|
3359 | pointers: 2
|
3360 | }, options)) || this;
|
3361 | }
|
3362 |
|
3363 | var _proto = PinchRecognizer.prototype;
|
3364 |
|
3365 | _proto.getTouchAction = function getTouchAction() {
|
3366 | return [TOUCH_ACTION_NONE];
|
3367 | };
|
3368 |
|
3369 | _proto.attrTest = function attrTest(input) {
|
3370 | return _AttrRecognizer.prototype.attrTest.call(this, input) && (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
|
3371 | };
|
3372 |
|
3373 | _proto.emit = function emit(input) {
|
3374 | if (input.scale !== 1) {
|
3375 | var inOut = input.scale < 1 ? 'in' : 'out';
|
3376 | input.additionalEvent = this.options.event + inOut;
|
3377 | }
|
3378 |
|
3379 | _AttrRecognizer.prototype.emit.call(this, input);
|
3380 | };
|
3381 |
|
3382 | return PinchRecognizer;
|
3383 | }(AttrRecognizer);
|
3384 |
|
3385 | var defaults = {
|
3386 | |
3387 |
|
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 | domEvents: false,
|
3394 |
|
3395 | |
3396 |
|
3397 |
|
3398 |
|
3399 |
|
3400 |
|
3401 |
|
3402 | touchAction: TOUCH_ACTION_COMPUTE,
|
3403 |
|
3404 | |
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 | enable: true,
|
3410 |
|
3411 | |
3412 |
|
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 | inputTarget: null,
|
3420 |
|
3421 | |
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 | inputClass: null,
|
3428 |
|
3429 | |
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 | cssProps: {
|
3436 | |
3437 |
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 | userSelect: "none",
|
3443 |
|
3444 | |
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 | touchSelect: "none",
|
3451 |
|
3452 | |
3453 |
|
3454 |
|
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 | touchCallout: "none",
|
3461 |
|
3462 | |
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 | contentZooming: "none",
|
3469 |
|
3470 | |
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 |
|
3476 | userDrag: "none",
|
3477 |
|
3478 | |
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 |
|
3485 | tapHighlightColor: "rgba(0,0,0,0)"
|
3486 | }
|
3487 | };
|
3488 |
|
3489 | var STOP = 1;
|
3490 | var FORCED_STOP = 2;
|
3491 | |
3492 |
|
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 | function toggleCssProps(manager, add) {
|
3499 | var element = manager.element;
|
3500 |
|
3501 | if (!element.style) {
|
3502 | return;
|
3503 | }
|
3504 |
|
3505 | var prop;
|
3506 | each(manager.options.cssProps, function (value, name) {
|
3507 | prop = prefixed(element.style, name);
|
3508 |
|
3509 | if (add) {
|
3510 | manager.oldCssProps[prop] = element.style[prop];
|
3511 | element.style[prop] = value;
|
3512 | } else {
|
3513 | element.style[prop] = manager.oldCssProps[prop] || "";
|
3514 | }
|
3515 | });
|
3516 |
|
3517 | if (!add) {
|
3518 | manager.oldCssProps = {};
|
3519 | }
|
3520 | }
|
3521 | |
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 | function triggerDomEvent(event, data) {
|
3530 | var gestureEvent = document.createEvent("Event");
|
3531 | gestureEvent.initEvent(event, true, true);
|
3532 | gestureEvent.gesture = data;
|
3533 | data.target.dispatchEvent(gestureEvent);
|
3534 | }
|
3535 | |
3536 |
|
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 | var Manager =
|
3545 |
|
3546 | function () {
|
3547 | function Manager(element, options) {
|
3548 | var _this = this;
|
3549 |
|
3550 | this.options = assign$1({}, defaults, options || {});
|
3551 | this.options.inputTarget = this.options.inputTarget || element;
|
3552 | this.handlers = {};
|
3553 | this.session = {};
|
3554 | this.recognizers = [];
|
3555 | this.oldCssProps = {};
|
3556 | this.element = element;
|
3557 | this.input = createInputInstance(this);
|
3558 | this.touchAction = new TouchAction(this, this.options.touchAction);
|
3559 | toggleCssProps(this, true);
|
3560 | each(this.options.recognizers, function (item) {
|
3561 | var recognizer = _this.add(new item[0](item[1]));
|
3562 |
|
3563 | item[2] && recognizer.recognizeWith(item[2]);
|
3564 | item[3] && recognizer.requireFailure(item[3]);
|
3565 | }, this);
|
3566 | }
|
3567 | |
3568 |
|
3569 |
|
3570 |
|
3571 |
|
3572 |
|
3573 |
|
3574 |
|
3575 | var _proto = Manager.prototype;
|
3576 |
|
3577 | _proto.set = function set(options) {
|
3578 | assign$1(this.options, options);
|
3579 |
|
3580 | if (options.touchAction) {
|
3581 | this.touchAction.update();
|
3582 | }
|
3583 |
|
3584 | if (options.inputTarget) {
|
3585 |
|
3586 | this.input.destroy();
|
3587 | this.input.target = options.inputTarget;
|
3588 | this.input.init();
|
3589 | }
|
3590 |
|
3591 | return this;
|
3592 | };
|
3593 | |
3594 |
|
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 | _proto.stop = function stop(force) {
|
3603 | this.session.stopped = force ? FORCED_STOP : STOP;
|
3604 | };
|
3605 | |
3606 |
|
3607 |
|
3608 |
|
3609 |
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 | _proto.recognize = function recognize(inputData) {
|
3615 | var session = this.session;
|
3616 |
|
3617 | if (session.stopped) {
|
3618 | return;
|
3619 | }
|
3620 |
|
3621 |
|
3622 | this.touchAction.preventDefaults(inputData);
|
3623 | var recognizer;
|
3624 | var recognizers = this.recognizers;
|
3625 |
|
3626 |
|
3627 |
|
3628 | var curRecognizer = session.curRecognizer;
|
3629 |
|
3630 |
|
3631 | if (!curRecognizer || curRecognizer && curRecognizer.state & STATE_RECOGNIZED) {
|
3632 | session.curRecognizer = null;
|
3633 | curRecognizer = null;
|
3634 | }
|
3635 |
|
3636 | var i = 0;
|
3637 |
|
3638 | while (i < recognizers.length) {
|
3639 | recognizer = recognizers[i];
|
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 | if (session.stopped !== FORCED_STOP && (
|
3647 | !curRecognizer || recognizer === curRecognizer ||
|
3648 | recognizer.canRecognizeWith(curRecognizer))) {
|
3649 |
|
3650 | recognizer.recognize(inputData);
|
3651 | } else {
|
3652 | recognizer.reset();
|
3653 | }
|
3654 |
|
3655 |
|
3656 |
|
3657 | if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
|
3658 | session.curRecognizer = recognizer;
|
3659 | curRecognizer = recognizer;
|
3660 | }
|
3661 |
|
3662 | i++;
|
3663 | }
|
3664 | };
|
3665 | |
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 | _proto.get = function get(recognizer) {
|
3674 | if (recognizer instanceof Recognizer) {
|
3675 | return recognizer;
|
3676 | }
|
3677 |
|
3678 | var recognizers = this.recognizers;
|
3679 |
|
3680 | for (var i = 0; i < recognizers.length; i++) {
|
3681 | if (recognizers[i].options.event === recognizer) {
|
3682 | return recognizers[i];
|
3683 | }
|
3684 | }
|
3685 |
|
3686 | return null;
|
3687 | };
|
3688 | |
3689 |
|
3690 |
|
3691 |
|
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 | _proto.add = function add(recognizer) {
|
3697 | if (invokeArrayArg(recognizer, "add", this)) {
|
3698 | return this;
|
3699 | }
|
3700 |
|
3701 |
|
3702 | var existing = this.get(recognizer.options.event);
|
3703 |
|
3704 | if (existing) {
|
3705 | this.remove(existing);
|
3706 | }
|
3707 |
|
3708 | this.recognizers.push(recognizer);
|
3709 | recognizer.manager = this;
|
3710 | this.touchAction.update();
|
3711 | return recognizer;
|
3712 | };
|
3713 | |
3714 |
|
3715 |
|
3716 |
|
3717 |
|
3718 |
|
3719 |
|
3720 |
|
3721 | _proto.remove = function remove(recognizer) {
|
3722 | if (invokeArrayArg(recognizer, "remove", this)) {
|
3723 | return this;
|
3724 | }
|
3725 |
|
3726 | var targetRecognizer = this.get(recognizer);
|
3727 |
|
3728 | if (recognizer) {
|
3729 | var recognizers = this.recognizers;
|
3730 | var index = inArray(recognizers, targetRecognizer);
|
3731 |
|
3732 | if (index !== -1) {
|
3733 | recognizers.splice(index, 1);
|
3734 | this.touchAction.update();
|
3735 | }
|
3736 | }
|
3737 |
|
3738 | return this;
|
3739 | };
|
3740 | |
3741 |
|
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 | _proto.on = function on(events, handler) {
|
3750 | if (events === undefined || handler === undefined) {
|
3751 | return this;
|
3752 | }
|
3753 |
|
3754 | var handlers = this.handlers;
|
3755 | each(splitStr(events), function (event) {
|
3756 | handlers[event] = handlers[event] || [];
|
3757 | handlers[event].push(handler);
|
3758 | });
|
3759 | return this;
|
3760 | };
|
3761 | |
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 | _proto.off = function off(events, handler) {
|
3770 | if (events === undefined) {
|
3771 | return this;
|
3772 | }
|
3773 |
|
3774 | var handlers = this.handlers;
|
3775 | each(splitStr(events), function (event) {
|
3776 | if (!handler) {
|
3777 | delete handlers[event];
|
3778 | } else {
|
3779 | handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
|
3780 | }
|
3781 | });
|
3782 | return this;
|
3783 | };
|
3784 | |
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 | _proto.emit = function emit(event, data) {
|
3792 |
|
3793 | if (this.options.domEvents) {
|
3794 | triggerDomEvent(event, data);
|
3795 | }
|
3796 |
|
3797 |
|
3798 | var handlers = this.handlers[event] && this.handlers[event].slice();
|
3799 |
|
3800 | if (!handlers || !handlers.length) {
|
3801 | return;
|
3802 | }
|
3803 |
|
3804 | data.type = event;
|
3805 |
|
3806 | data.preventDefault = function () {
|
3807 | data.srcEvent.preventDefault();
|
3808 | };
|
3809 |
|
3810 | var i = 0;
|
3811 |
|
3812 | while (i < handlers.length) {
|
3813 | handlers[i](data);
|
3814 | i++;
|
3815 | }
|
3816 | };
|
3817 | |
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 | _proto.destroy = function destroy() {
|
3825 | this.element && toggleCssProps(this, false);
|
3826 | this.handlers = {};
|
3827 | this.session = {};
|
3828 | this.input.destroy();
|
3829 | this.element = null;
|
3830 | };
|
3831 |
|
3832 | return Manager;
|
3833 | }();
|
3834 |
|
3835 | |
3836 |
|
3837 |
|
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 | |
3844 |
|
3845 |
|
3846 |
|
3847 |
|
3848 |
|
3849 |
|
3850 |
|
3851 |
|
3852 |
|
3853 |
|
3854 |
|
3855 |
|
3856 |
|
3857 | function __values$2(o) {
|
3858 | var s = typeof Symbol === "function" && Symbol.iterator,
|
3859 | m = s && o[s],
|
3860 | i = 0;
|
3861 | if (m) return m.call(o);
|
3862 | if (o && typeof o.length === "number") return {
|
3863 | next: function () {
|
3864 | if (o && i >= o.length) o = void 0;
|
3865 | return {
|
3866 | value: o && o[i++],
|
3867 | done: !o
|
3868 | };
|
3869 | }
|
3870 | };
|
3871 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
3872 | }
|
3873 |
|
3874 | |
3875 |
|
3876 |
|
3877 |
|
3878 |
|
3879 | function isUndefined$1(value) {
|
3880 | return typeof value === "undefined";
|
3881 | }
|
3882 | |
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 |
|
3889 | var Component$1 =
|
3890 |
|
3891 | function () {
|
3892 | |
3893 |
|
3894 |
|
3895 | function Component() {
|
3896 | |
3897 |
|
3898 |
|
3899 |
|
3900 | this.options = {};
|
3901 | this._eventHandler = {};
|
3902 | }
|
3903 | |
3904 |
|
3905 |
|
3906 |
|
3907 |
|
3908 |
|
3909 |
|
3910 |
|
3911 |
|
3912 |
|
3913 |
|
3914 |
|
3915 |
|
3916 |
|
3917 |
|
3918 |
|
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 |
|
3929 |
|
3930 |
|
3931 |
|
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 | var __proto = Component.prototype;
|
3937 |
|
3938 | __proto.trigger = function (eventName) {
|
3939 | var _this = this;
|
3940 |
|
3941 | var params = [];
|
3942 |
|
3943 | for (var _i = 1; _i < arguments.length; _i++) {
|
3944 | params[_i - 1] = arguments[_i];
|
3945 | }
|
3946 |
|
3947 | var handlerList = this._eventHandler[eventName] || [];
|
3948 | var hasHandlerList = handlerList.length > 0;
|
3949 |
|
3950 | if (!hasHandlerList) {
|
3951 | return true;
|
3952 | }
|
3953 |
|
3954 | var customEvent = params[0] || {};
|
3955 | var restParams = params.slice(1);
|
3956 |
|
3957 | handlerList = handlerList.concat();
|
3958 | var isCanceled = false;
|
3959 |
|
3960 | customEvent.eventType = eventName;
|
3961 |
|
3962 | customEvent.stop = function () {
|
3963 | isCanceled = true;
|
3964 | };
|
3965 |
|
3966 | customEvent.currentTarget = this;
|
3967 | var arg = [customEvent];
|
3968 |
|
3969 | if (restParams.length >= 1) {
|
3970 | arg = arg.concat(restParams);
|
3971 | }
|
3972 |
|
3973 | handlerList.forEach(function (handler) {
|
3974 | handler.apply(_this, arg);
|
3975 | });
|
3976 | return !isCanceled;
|
3977 | };
|
3978 | |
3979 |
|
3980 |
|
3981 |
|
3982 |
|
3983 |
|
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 |
|
4003 |
|
4004 | __proto.once = function (eventName, handlerToAttach) {
|
4005 | var _this = this;
|
4006 |
|
4007 | if (typeof eventName === "object" && isUndefined$1(handlerToAttach)) {
|
4008 | var eventHash = eventName;
|
4009 |
|
4010 | for (var key in eventHash) {
|
4011 | this.once(key, eventHash[key]);
|
4012 | }
|
4013 |
|
4014 | return this;
|
4015 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
4016 | var listener_1 = function () {
|
4017 | var args = [];
|
4018 |
|
4019 | for (var _i = 0; _i < arguments.length; _i++) {
|
4020 | args[_i] = arguments[_i];
|
4021 | }
|
4022 |
|
4023 | handlerToAttach.apply(_this, args);
|
4024 |
|
4025 | _this.off(eventName, listener_1);
|
4026 | };
|
4027 |
|
4028 | this.on(eventName, listener_1);
|
4029 | }
|
4030 |
|
4031 | return this;
|
4032 | };
|
4033 | |
4034 |
|
4035 |
|
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 | __proto.hasOn = function (eventName) {
|
4050 | return !!this._eventHandler[eventName];
|
4051 | };
|
4052 | |
4053 |
|
4054 |
|
4055 |
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 |
|
4067 |
|
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 | __proto.on = function (eventName, handlerToAttach) {
|
4073 | if (typeof eventName === "object" && isUndefined$1(handlerToAttach)) {
|
4074 | var eventHash = eventName;
|
4075 |
|
4076 | for (var name in eventHash) {
|
4077 | this.on(name, eventHash[name]);
|
4078 | }
|
4079 |
|
4080 | return this;
|
4081 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
4082 | var handlerList = this._eventHandler[eventName];
|
4083 |
|
4084 | if (isUndefined$1(handlerList)) {
|
4085 | this._eventHandler[eventName] = [];
|
4086 | handlerList = this._eventHandler[eventName];
|
4087 | }
|
4088 |
|
4089 | handlerList.push(handlerToAttach);
|
4090 | }
|
4091 |
|
4092 | return this;
|
4093 | };
|
4094 | |
4095 |
|
4096 |
|
4097 |
|
4098 |
|
4099 |
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 |
|
4105 |
|
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 |
|
4112 |
|
4113 |
|
4114 | __proto.off = function (eventName, handlerToDetach) {
|
4115 | var e_1, _a;
|
4116 |
|
4117 |
|
4118 | if (isUndefined$1(eventName)) {
|
4119 | this._eventHandler = {};
|
4120 | return this;
|
4121 | }
|
4122 |
|
4123 |
|
4124 | if (isUndefined$1(handlerToDetach)) {
|
4125 | if (typeof eventName === "string") {
|
4126 | delete this._eventHandler[eventName];
|
4127 | return this;
|
4128 | } else {
|
4129 | var eventHash = eventName;
|
4130 |
|
4131 | for (var name in eventHash) {
|
4132 | this.off(name, eventHash[name]);
|
4133 | }
|
4134 |
|
4135 | return this;
|
4136 | }
|
4137 | }
|
4138 |
|
4139 |
|
4140 | var handlerList = this._eventHandler[eventName];
|
4141 |
|
4142 | if (handlerList) {
|
4143 | var idx = 0;
|
4144 |
|
4145 | try {
|
4146 | for (var handlerList_1 = __values$2(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
4147 | var handlerFunction = handlerList_1_1.value;
|
4148 |
|
4149 | if (handlerFunction === handlerToDetach) {
|
4150 | handlerList.splice(idx, 1);
|
4151 | break;
|
4152 | }
|
4153 |
|
4154 | idx++;
|
4155 | }
|
4156 | } catch (e_1_1) {
|
4157 | e_1 = {
|
4158 | error: e_1_1
|
4159 | };
|
4160 | } finally {
|
4161 | try {
|
4162 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
4163 | } finally {
|
4164 | if (e_1) throw e_1.error;
|
4165 | }
|
4166 | }
|
4167 | }
|
4168 |
|
4169 | return this;
|
4170 | };
|
4171 | |
4172 |
|
4173 |
|
4174 |
|
4175 |
|
4176 |
|
4177 |
|
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 | Component.VERSION = "2.2.2";
|
4183 | return Component;
|
4184 | }();
|
4185 |
|
4186 | |
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 |
|
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 | |
4197 |
|
4198 |
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 |
|
4210 |
|
4211 |
|
4212 | var extendStatics$1 = function (d, b) {
|
4213 | extendStatics$1 = Object.setPrototypeOf || {
|
4214 | __proto__: []
|
4215 | } instanceof Array && function (d, b) {
|
4216 | d.__proto__ = b;
|
4217 | } || function (d, b) {
|
4218 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
4219 | };
|
4220 |
|
4221 | return extendStatics$1(d, b);
|
4222 | };
|
4223 |
|
4224 | function __extends$1(d, b) {
|
4225 | extendStatics$1(d, b);
|
4226 |
|
4227 | function __() {
|
4228 | this.constructor = d;
|
4229 | }
|
4230 |
|
4231 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
4232 | }
|
4233 | var __assign$1 = function () {
|
4234 | __assign$1 = Object.assign || function __assign(t) {
|
4235 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4236 | s = arguments[i];
|
4237 |
|
4238 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
4239 | }
|
4240 |
|
4241 | return t;
|
4242 | };
|
4243 |
|
4244 | return __assign$1.apply(this, arguments);
|
4245 | };
|
4246 |
|
4247 | function getInsidePosition(destPos, range, circular, bounce) {
|
4248 | var toDestPos = destPos;
|
4249 | var targetRange = [circular[0] ? range[0] : bounce ? range[0] - bounce[0] : range[0], circular[1] ? range[1] : bounce ? range[1] + bounce[1] : range[1]];
|
4250 | toDestPos = Math.max(targetRange[0], toDestPos);
|
4251 | toDestPos = Math.min(targetRange[1], toDestPos);
|
4252 | return toDestPos;
|
4253 | }
|
4254 |
|
4255 | function isOutside(pos, range) {
|
4256 | return pos < range[0] || pos > range[1];
|
4257 | }
|
4258 | function getDuration(distance, deceleration) {
|
4259 | var duration = Math.sqrt(distance / deceleration * 2);
|
4260 |
|
4261 | return duration < 100 ? 0 : duration;
|
4262 | }
|
4263 | function isCircularable(destPos, range, circular) {
|
4264 | return circular[1] && destPos > range[1] || circular[0] && destPos < range[0];
|
4265 | }
|
4266 | function getCirculatedPos(pos, range, circular) {
|
4267 | var toPos = pos;
|
4268 | var min = range[0];
|
4269 | var max = range[1];
|
4270 | var length = max - min;
|
4271 |
|
4272 | if (circular[1] && pos > max) {
|
4273 |
|
4274 | toPos = (toPos - max) % length + min;
|
4275 | }
|
4276 |
|
4277 | if (circular[0] && pos < min) {
|
4278 |
|
4279 | toPos = (toPos - min) % length + max;
|
4280 | }
|
4281 |
|
4282 | return toPos;
|
4283 | }
|
4284 |
|
4285 |
|
4286 | var win$2;
|
4287 |
|
4288 | if (typeof window === "undefined") {
|
4289 |
|
4290 | win$2 = {
|
4291 | navigator: {
|
4292 | userAgent: ""
|
4293 | }
|
4294 | };
|
4295 | } else {
|
4296 | win$2 = window;
|
4297 | }
|
4298 |
|
4299 | function toArray$1(nodes) {
|
4300 |
|
4301 |
|
4302 | var el = [];
|
4303 |
|
4304 | for (var i = 0, len = nodes.length; i < len; i++) {
|
4305 | el.push(nodes[i]);
|
4306 | }
|
4307 |
|
4308 | return el;
|
4309 | }
|
4310 | function $(param, multi) {
|
4311 | if (multi === void 0) {
|
4312 | multi = false;
|
4313 | }
|
4314 |
|
4315 | var el;
|
4316 |
|
4317 | if (typeof param === "string") {
|
4318 |
|
4319 |
|
4320 | var match = param.match(/^<([a-z]+)\s*([^>]*)>/);
|
4321 |
|
4322 | if (match) {
|
4323 |
|
4324 | var dummy = document.createElement("div");
|
4325 | dummy.innerHTML = param;
|
4326 | el = toArray$1(dummy.childNodes);
|
4327 | } else {
|
4328 |
|
4329 | el = toArray$1(document.querySelectorAll(param));
|
4330 | }
|
4331 |
|
4332 | if (!multi) {
|
4333 | el = el.length >= 1 ? el[0] : undefined;
|
4334 | }
|
4335 | } else if (param === win$2) {
|
4336 |
|
4337 | el = param;
|
4338 | } else if (param.nodeName && (param.nodeType === 1 || param.nodeType === 9)) {
|
4339 |
|
4340 | el = param;
|
4341 | } else if ("jQuery" in win$2 && param instanceof jQuery || param.constructor.prototype.jquery) {
|
4342 |
|
4343 | el = multi ? param.toArray() : param.get(0);
|
4344 | } else if (Array.isArray(param)) {
|
4345 | el = param.map(function (v) {
|
4346 | return $(v);
|
4347 | });
|
4348 |
|
4349 | if (!multi) {
|
4350 | el = el.length >= 1 ? el[0] : undefined;
|
4351 | }
|
4352 | }
|
4353 |
|
4354 | return el;
|
4355 | }
|
4356 | var raf = win$2.requestAnimationFrame || win$2.webkitRequestAnimationFrame;
|
4357 | var caf = win$2.cancelAnimationFrame || win$2.webkitCancelAnimationFrame;
|
4358 |
|
4359 | if (raf && !caf) {
|
4360 | var keyInfo_1 = {};
|
4361 | var oldraf_1 = raf;
|
4362 |
|
4363 | raf = function (callback) {
|
4364 | function wrapCallback(timestamp) {
|
4365 | if (keyInfo_1[key]) {
|
4366 | callback(timestamp);
|
4367 | }
|
4368 | }
|
4369 |
|
4370 | var key = oldraf_1(wrapCallback);
|
4371 | keyInfo_1[key] = true;
|
4372 | return key;
|
4373 | };
|
4374 |
|
4375 | caf = function (key) {
|
4376 | delete keyInfo_1[key];
|
4377 | };
|
4378 | } else if (!(raf && caf)) {
|
4379 | raf = function (callback) {
|
4380 | return win$2.setTimeout(function () {
|
4381 | callback(win$2.performance && win$2.performance.now && win$2.performance.now() || new Date().getTime());
|
4382 | }, 16);
|
4383 | };
|
4384 |
|
4385 | caf = win$2.clearTimeout;
|
4386 | }
|
4387 | |
4388 |
|
4389 |
|
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 | function requestAnimationFrame(fp) {
|
4395 | return raf(fp);
|
4396 | }
|
4397 | |
4398 |
|
4399 |
|
4400 |
|
4401 |
|
4402 |
|
4403 |
|
4404 | function cancelAnimationFrame(key) {
|
4405 | caf(key);
|
4406 | }
|
4407 | function map(obj, callback) {
|
4408 | var tranformed = {};
|
4409 |
|
4410 | for (var k in obj) {
|
4411 | k && (tranformed[k] = callback(obj[k], k));
|
4412 | }
|
4413 |
|
4414 | return tranformed;
|
4415 | }
|
4416 | function filter(obj, callback) {
|
4417 | var filtered = {};
|
4418 |
|
4419 | for (var k in obj) {
|
4420 | k && callback(obj[k], k) && (filtered[k] = obj[k]);
|
4421 | }
|
4422 |
|
4423 | return filtered;
|
4424 | }
|
4425 | function every(obj, callback) {
|
4426 | for (var k in obj) {
|
4427 | if (k && !callback(obj[k], k)) {
|
4428 | return false;
|
4429 | }
|
4430 | }
|
4431 |
|
4432 | return true;
|
4433 | }
|
4434 | function equal(target, base) {
|
4435 | return every(target, function (v, k) {
|
4436 | return v === base[k];
|
4437 | });
|
4438 | }
|
4439 | var roundNumFunc = {};
|
4440 | function roundNumber(num, roundUnit) {
|
4441 |
|
4442 | if (!roundNumFunc[roundUnit]) {
|
4443 | roundNumFunc[roundUnit] = getRoundFunc(roundUnit);
|
4444 | }
|
4445 |
|
4446 | return roundNumFunc[roundUnit](num);
|
4447 | }
|
4448 | function roundNumbers(num, roundUnit) {
|
4449 | if (!num || !roundUnit) {
|
4450 | return num;
|
4451 | }
|
4452 |
|
4453 | var isNumber = typeof roundUnit === "number";
|
4454 | return map(num, function (value, key) {
|
4455 | return roundNumber(value, isNumber ? roundUnit : roundUnit[key]);
|
4456 | });
|
4457 | }
|
4458 | function getDecimalPlace(val) {
|
4459 | if (!isFinite(val)) {
|
4460 | return 0;
|
4461 | }
|
4462 |
|
4463 | var v = val + "";
|
4464 |
|
4465 | if (v.indexOf("e") >= 0) {
|
4466 |
|
4467 |
|
4468 | var p = 0;
|
4469 | var e = 1;
|
4470 |
|
4471 | while (Math.round(val * e) / e !== val) {
|
4472 | e *= 10;
|
4473 | p++;
|
4474 | }
|
4475 |
|
4476 | return p;
|
4477 | }
|
4478 |
|
4479 |
|
4480 |
|
4481 | return v.indexOf(".") >= 0 ? v.length - v.indexOf(".") - 1 : 0;
|
4482 | }
|
4483 | function inversePow(n) {
|
4484 |
|
4485 |
|
4486 | return 1 / Math.pow(10, n);
|
4487 | }
|
4488 | function getRoundFunc(v) {
|
4489 | var p = v < 1 ? Math.pow(10, getDecimalPlace(v)) : 1;
|
4490 | return function (n) {
|
4491 | if (v === 0) {
|
4492 | return 0;
|
4493 | }
|
4494 |
|
4495 | return Math.round(Math.round(n / v) * v * p) / p;
|
4496 | };
|
4497 | }
|
4498 |
|
4499 | function minMax(value, min, max) {
|
4500 | return Math.max(Math.min(value, max), min);
|
4501 | }
|
4502 |
|
4503 | var AnimationManager =
|
4504 |
|
4505 | function () {
|
4506 | function AnimationManager(_a) {
|
4507 | var options = _a.options,
|
4508 | itm = _a.itm,
|
4509 | em = _a.em,
|
4510 | axm = _a.axm;
|
4511 | this.options = options;
|
4512 | this.itm = itm;
|
4513 | this.em = em;
|
4514 | this.axm = axm;
|
4515 | this.animationEnd = this.animationEnd.bind(this);
|
4516 | }
|
4517 |
|
4518 | var __proto = AnimationManager.prototype;
|
4519 |
|
4520 | __proto.getDuration = function (depaPos, destPos, wishDuration) {
|
4521 | var _this = this;
|
4522 |
|
4523 | var duration;
|
4524 |
|
4525 | if (typeof wishDuration !== "undefined") {
|
4526 | duration = wishDuration;
|
4527 | } else {
|
4528 | var durations_1 = map(destPos, function (v, k) {
|
4529 | return getDuration(Math.abs(v - depaPos[k]), _this.options.deceleration);
|
4530 | });
|
4531 | duration = Object.keys(durations_1).reduce(function (max, v) {
|
4532 | return Math.max(max, durations_1[v]);
|
4533 | }, -Infinity);
|
4534 | }
|
4535 |
|
4536 | return minMax(duration, this.options.minimumDuration, this.options.maximumDuration);
|
4537 | };
|
4538 |
|
4539 | __proto.createAnimationParam = function (pos, duration, option) {
|
4540 | var depaPos = this.axm.get();
|
4541 | var destPos = pos;
|
4542 | var inputEvent = option && option.event || null;
|
4543 | return {
|
4544 | depaPos: depaPos,
|
4545 | destPos: destPos,
|
4546 | duration: minMax(duration, this.options.minimumDuration, this.options.maximumDuration),
|
4547 | delta: this.axm.getDelta(depaPos, destPos),
|
4548 | inputEvent: inputEvent,
|
4549 | input: option && option.input || null,
|
4550 | isTrusted: !!inputEvent,
|
4551 | done: this.animationEnd
|
4552 | };
|
4553 | };
|
4554 |
|
4555 | __proto.grab = function (axes, option) {
|
4556 | if (this._animateParam && axes.length) {
|
4557 | var orgPos_1 = this.axm.get(axes);
|
4558 | var pos = this.axm.map(orgPos_1, function (v, opt) {
|
4559 | return getCirculatedPos(v, opt.range, opt.circular);
|
4560 | });
|
4561 |
|
4562 | if (!every(pos, function (v, k) {
|
4563 | return orgPos_1[k] === v;
|
4564 | })) {
|
4565 | this.em.triggerChange(pos, false, orgPos_1, option, !!option);
|
4566 | }
|
4567 |
|
4568 | this._animateParam = null;
|
4569 | this._raf && cancelAnimationFrame(this._raf);
|
4570 | this._raf = null;
|
4571 | this.em.triggerAnimationEnd(!!(option && option.event));
|
4572 | }
|
4573 | };
|
4574 |
|
4575 | __proto.getEventInfo = function () {
|
4576 | if (this._animateParam && this._animateParam.input && this._animateParam.inputEvent) {
|
4577 | return {
|
4578 | input: this._animateParam.input,
|
4579 | event: this._animateParam.inputEvent
|
4580 | };
|
4581 | } else {
|
4582 | return null;
|
4583 | }
|
4584 | };
|
4585 |
|
4586 | __proto.restore = function (option) {
|
4587 | var pos = this.axm.get();
|
4588 | var destPos = this.axm.map(pos, function (v, opt) {
|
4589 | return Math.min(opt.range[1], Math.max(opt.range[0], v));
|
4590 | });
|
4591 | this.animateTo(destPos, this.getDuration(pos, destPos), option);
|
4592 | };
|
4593 |
|
4594 | __proto.animationEnd = function () {
|
4595 | var beforeParam = this.getEventInfo();
|
4596 | this._animateParam = null;
|
4597 |
|
4598 | var circularTargets = this.axm.filter(this.axm.get(), function (v, opt) {
|
4599 | return isCircularable(v, opt.range, opt.circular);
|
4600 | });
|
4601 | Object.keys(circularTargets).length > 0 && this.setTo(this.axm.map(circularTargets, function (v, opt) {
|
4602 | return getCirculatedPos(v, opt.range, opt.circular);
|
4603 | }));
|
4604 | this.itm.setInterrupt(false);
|
4605 | this.em.triggerAnimationEnd(!!beforeParam);
|
4606 |
|
4607 | if (this.axm.isOutside()) {
|
4608 | this.restore(beforeParam);
|
4609 | } else {
|
4610 | this.finish(!!beforeParam);
|
4611 | }
|
4612 | };
|
4613 |
|
4614 | __proto.finish = function (isTrusted) {
|
4615 | this._animateParam = null;
|
4616 | this.itm.setInterrupt(false);
|
4617 | this.em.triggerFinish(isTrusted);
|
4618 | };
|
4619 |
|
4620 | __proto.animateLoop = function (param, complete) {
|
4621 | if (param.duration) {
|
4622 | this._animateParam = __assign$1({}, param);
|
4623 | var info_1 = this._animateParam;
|
4624 | var self_1 = this;
|
4625 | var destPos_1 = info_1.destPos;
|
4626 | var prevPos_1 = info_1.depaPos;
|
4627 | var prevEasingPer_1 = 0;
|
4628 | var directions_1 = map(prevPos_1, function (value, key) {
|
4629 | return value <= destPos_1[key] ? 1 : -1;
|
4630 | });
|
4631 | var originalIntendedPos_1 = map(destPos_1, function (v) {
|
4632 | return v;
|
4633 | });
|
4634 | var prevTime_1 = new Date().getTime();
|
4635 | info_1.startTime = prevTime_1;
|
4636 |
|
4637 | (function loop() {
|
4638 | self_1._raf = null;
|
4639 | var currentTime = new Date().getTime();
|
4640 | var ratio = (currentTime - info_1.startTime) / param.duration;
|
4641 | var easingPer = self_1.easing(ratio);
|
4642 | var toPos = self_1.axm.map(prevPos_1, function (pos, options, key) {
|
4643 | var nextPos = ratio >= 1 ? destPos_1[key] : pos + info_1.delta[key] * (easingPer - prevEasingPer_1);
|
4644 |
|
4645 |
|
4646 |
|
4647 | var circulatedPos = getCirculatedPos(nextPos, options.range, options.circular);
|
4648 |
|
4649 | if (nextPos !== circulatedPos) {
|
4650 |
|
4651 | var rangeOffset = directions_1[key] * (options.range[1] - options.range[0]);
|
4652 | destPos_1[key] -= rangeOffset;
|
4653 | prevPos_1[key] -= rangeOffset;
|
4654 | }
|
4655 |
|
4656 | return circulatedPos;
|
4657 | });
|
4658 | var isCanceled = !self_1.em.triggerChange(toPos, false, prevPos_1);
|
4659 | prevPos_1 = toPos;
|
4660 | prevTime_1 = currentTime;
|
4661 | prevEasingPer_1 = easingPer;
|
4662 |
|
4663 | if (easingPer >= 1) {
|
4664 | destPos_1 = self_1.getFinalPos(destPos_1, originalIntendedPos_1);
|
4665 |
|
4666 | if (!equal(destPos_1, self_1.axm.get(Object.keys(destPos_1)))) {
|
4667 | self_1.em.triggerChange(destPos_1, true, prevPos_1);
|
4668 | }
|
4669 |
|
4670 | complete();
|
4671 | return;
|
4672 | } else if (isCanceled) {
|
4673 | self_1.finish(false);
|
4674 | } else {
|
4675 |
|
4676 | self_1._raf = requestAnimationFrame(loop);
|
4677 | }
|
4678 | })();
|
4679 | } else {
|
4680 | this.em.triggerChange(param.destPos, true);
|
4681 | complete();
|
4682 | }
|
4683 | };
|
4684 | |
4685 |
|
4686 |
|
4687 |
|
4688 |
|
4689 |
|
4690 |
|
4691 |
|
4692 |
|
4693 |
|
4694 |
|
4695 |
|
4696 |
|
4697 | __proto.getFinalPos = function (destPos, originalIntendedPos) {
|
4698 | var _this = this;
|
4699 |
|
4700 |
|
4701 | var ERROR_LIMIT = 0.000001;
|
4702 | var finalPos = map(destPos, function (value, key) {
|
4703 | if (value >= originalIntendedPos[key] - ERROR_LIMIT && value <= originalIntendedPos[key] + ERROR_LIMIT) {
|
4704 |
|
4705 | return originalIntendedPos[key];
|
4706 | } else {
|
4707 |
|
4708 | var roundUnit = _this.getRoundUnit(value, key);
|
4709 |
|
4710 | var result = roundNumber(value, roundUnit);
|
4711 | return result;
|
4712 | }
|
4713 | });
|
4714 | return finalPos;
|
4715 | };
|
4716 |
|
4717 | __proto.getRoundUnit = function (val, key) {
|
4718 | var roundUnit = this.options.round;
|
4719 |
|
4720 | var minRoundUnit = null;
|
4721 |
|
4722 |
|
4723 | if (!roundUnit) {
|
4724 |
|
4725 | var options = this.axm.getAxisOptions(key);
|
4726 | minRoundUnit = inversePow(Math.max(getDecimalPlace(options.range[0]), getDecimalPlace(options.range[1]), getDecimalPlace(val)));
|
4727 | }
|
4728 |
|
4729 | return minRoundUnit || roundUnit;
|
4730 | };
|
4731 |
|
4732 | __proto.getUserControll = function (param) {
|
4733 | var userWish = param.setTo();
|
4734 | userWish.destPos = this.axm.get(userWish.destPos);
|
4735 | userWish.duration = minMax(userWish.duration, this.options.minimumDuration, this.options.maximumDuration);
|
4736 | return userWish;
|
4737 | };
|
4738 |
|
4739 | __proto.animateTo = function (destPos, duration, option) {
|
4740 | var _this = this;
|
4741 |
|
4742 | var param = this.createAnimationParam(destPos, duration, option);
|
4743 |
|
4744 | var depaPos = __assign$1({}, param.depaPos);
|
4745 |
|
4746 | var retTrigger = this.em.triggerAnimationStart(param);
|
4747 |
|
4748 | var userWish = this.getUserControll(param);
|
4749 |
|
4750 | if (!retTrigger && this.axm.every(userWish.destPos, function (v, opt) {
|
4751 | return isCircularable(v, opt.range, opt.circular);
|
4752 | })) {
|
4753 | console.warn("You can't stop the 'animation' event when 'circular' is true.");
|
4754 | }
|
4755 |
|
4756 | if (retTrigger && !equal(userWish.destPos, depaPos)) {
|
4757 | var inputEvent = option && option.event || null;
|
4758 | this.animateLoop({
|
4759 | depaPos: depaPos,
|
4760 | destPos: userWish.destPos,
|
4761 | duration: userWish.duration,
|
4762 | delta: this.axm.getDelta(depaPos, userWish.destPos),
|
4763 | isTrusted: !!inputEvent,
|
4764 | inputEvent: inputEvent,
|
4765 | input: option && option.input || null
|
4766 | }, function () {
|
4767 | return _this.animationEnd();
|
4768 | });
|
4769 | }
|
4770 | };
|
4771 |
|
4772 | __proto.easing = function (p) {
|
4773 | return p > 1 ? 1 : this.options.easing(p);
|
4774 | };
|
4775 |
|
4776 | __proto.setTo = function (pos, duration) {
|
4777 | if (duration === void 0) {
|
4778 | duration = 0;
|
4779 | }
|
4780 |
|
4781 | var axes = Object.keys(pos);
|
4782 | this.grab(axes);
|
4783 | var orgPos = this.axm.get(axes);
|
4784 |
|
4785 | if (equal(pos, orgPos)) {
|
4786 | return this;
|
4787 | }
|
4788 |
|
4789 | this.itm.setInterrupt(true);
|
4790 | var movedPos = filter(pos, function (v, k) {
|
4791 | return orgPos[k] !== v;
|
4792 | });
|
4793 |
|
4794 | if (!Object.keys(movedPos).length) {
|
4795 | return this;
|
4796 | }
|
4797 |
|
4798 | movedPos = this.axm.map(movedPos, function (v, opt) {
|
4799 | var range = opt.range,
|
4800 | circular = opt.circular;
|
4801 |
|
4802 | if (circular && (circular[0] || circular[1])) {
|
4803 | return v;
|
4804 | } else {
|
4805 | return getInsidePosition(v, range, circular);
|
4806 | }
|
4807 | });
|
4808 |
|
4809 | if (equal(movedPos, orgPos)) {
|
4810 | return this;
|
4811 | }
|
4812 |
|
4813 | if (duration > 0) {
|
4814 | this.animateTo(movedPos, duration);
|
4815 | } else {
|
4816 | this.em.triggerChange(movedPos);
|
4817 | this.finish(false);
|
4818 | }
|
4819 |
|
4820 | return this;
|
4821 | };
|
4822 |
|
4823 | __proto.setBy = function (pos, duration) {
|
4824 | if (duration === void 0) {
|
4825 | duration = 0;
|
4826 | }
|
4827 |
|
4828 | return this.setTo(map(this.axm.get(Object.keys(pos)), function (v, k) {
|
4829 | return v + pos[k];
|
4830 | }), duration);
|
4831 | };
|
4832 |
|
4833 | return AnimationManager;
|
4834 | }();
|
4835 |
|
4836 | var EventManager =
|
4837 |
|
4838 | function () {
|
4839 | function EventManager(axes) {
|
4840 | this.axes = axes;
|
4841 | }
|
4842 | |
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 |
|
4849 |
|
4850 |
|
4851 |
|
4852 |
|
4853 |
|
4854 |
|
4855 |
|
4856 |
|
4857 |
|
4858 |
|
4859 |
|
4860 |
|
4861 |
|
4862 |
|
4863 |
|
4864 |
|
4865 |
|
4866 |
|
4867 |
|
4868 |
|
4869 |
|
4870 | var __proto = EventManager.prototype;
|
4871 |
|
4872 | __proto.triggerHold = function (pos, option) {
|
4873 | var roundPos = this.getRoundPos(pos).roundPos;
|
4874 | this.axes.trigger("hold", {
|
4875 | pos: roundPos,
|
4876 | input: option.input || null,
|
4877 | inputEvent: option.event || null,
|
4878 | isTrusted: true
|
4879 | });
|
4880 | };
|
4881 | |
4882 |
|
4883 |
|
4884 |
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 |
|
4900 | |
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 |
|
4906 |
|
4907 |
|
4908 |
|
4909 |
|
4910 |
|
4911 |
|
4912 |
|
4913 |
|
4914 |
|
4915 |
|
4916 |
|
4917 |
|
4918 |
|
4919 | |
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 |
|
4938 |
|
4939 |
|
4940 |
|
4941 |
|
4942 |
|
4943 |
|
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 | __proto.triggerRelease = function (param) {
|
4957 | var _a = this.getRoundPos(param.destPos, param.depaPos),
|
4958 | roundPos = _a.roundPos,
|
4959 | roundDepa = _a.roundDepa;
|
4960 |
|
4961 | param.destPos = roundPos;
|
4962 | param.depaPos = roundDepa;
|
4963 | param.setTo = this.createUserControll(param.destPos, param.duration);
|
4964 | this.axes.trigger("release", param);
|
4965 | };
|
4966 | |
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 |
|
4974 |
|
4975 |
|
4976 |
|
4977 |
|
4978 |
|
4979 |
|
4980 |
|
4981 |
|
4982 |
|
4983 |
|
4984 |
|
4985 |
|
4986 |
|
4987 |
|
4988 |
|
4989 |
|
4990 |
|
4991 |
|
4992 |
|
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 |
|
5004 | __proto.triggerChange = function (pos, isAccurate, depaPos, option, holding) {
|
5005 | if (holding === void 0) {
|
5006 | holding = false;
|
5007 | }
|
5008 |
|
5009 | var am = this.am;
|
5010 | var axm = am.axm;
|
5011 | var eventInfo = am.getEventInfo();
|
5012 |
|
5013 | var _a = this.getRoundPos(pos, depaPos),
|
5014 | roundPos = _a.roundPos,
|
5015 | roundDepa = _a.roundDepa;
|
5016 |
|
5017 | var moveTo = axm.moveTo(roundPos, roundDepa);
|
5018 | var inputEvent = option && option.event || eventInfo && eventInfo.event || null;
|
5019 | var param = {
|
5020 | pos: moveTo.pos,
|
5021 | delta: moveTo.delta,
|
5022 | holding: holding,
|
5023 | inputEvent: inputEvent,
|
5024 | isTrusted: !!inputEvent,
|
5025 | input: option && option.input || eventInfo && eventInfo.input || null,
|
5026 | set: inputEvent ? this.createUserControll(moveTo.pos) : function () {}
|
5027 | };
|
5028 | var result = this.axes.trigger("change", param);
|
5029 | inputEvent && axm.set(param.set()["destPos"]);
|
5030 | return result;
|
5031 | };
|
5032 | |
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 |
|
5069 |
|
5070 | __proto.triggerAnimationStart = function (param) {
|
5071 | var _a = this.getRoundPos(param.destPos, param.depaPos),
|
5072 | roundPos = _a.roundPos,
|
5073 | roundDepa = _a.roundDepa;
|
5074 |
|
5075 | param.destPos = roundPos;
|
5076 | param.depaPos = roundDepa;
|
5077 | param.setTo = this.createUserControll(param.destPos, param.duration);
|
5078 | return this.axes.trigger("animationStart", param);
|
5079 | };
|
5080 | |
5081 |
|
5082 |
|
5083 |
|
5084 |
|
5085 |
|
5086 |
|
5087 |
|
5088 |
|
5089 |
|
5090 |
|
5091 |
|
5092 |
|
5093 |
|
5094 |
|
5095 |
|
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 | __proto.triggerAnimationEnd = function (isTrusted) {
|
5103 | if (isTrusted === void 0) {
|
5104 | isTrusted = false;
|
5105 | }
|
5106 |
|
5107 | this.axes.trigger("animationEnd", {
|
5108 | isTrusted: isTrusted
|
5109 | });
|
5110 | };
|
5111 | |
5112 |
|
5113 |
|
5114 |
|
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 |
|
5127 |
|
5128 |
|
5129 |
|
5130 |
|
5131 |
|
5132 |
|
5133 | __proto.triggerFinish = function (isTrusted) {
|
5134 | if (isTrusted === void 0) {
|
5135 | isTrusted = false;
|
5136 | }
|
5137 |
|
5138 | this.axes.trigger("finish", {
|
5139 | isTrusted: isTrusted
|
5140 | });
|
5141 | };
|
5142 |
|
5143 | __proto.createUserControll = function (pos, duration) {
|
5144 | if (duration === void 0) {
|
5145 | duration = 0;
|
5146 | }
|
5147 |
|
5148 |
|
5149 | var userControl = {
|
5150 | destPos: __assign$1({}, pos),
|
5151 | duration: duration
|
5152 | };
|
5153 | return function (toPos, userDuration) {
|
5154 | toPos && (userControl.destPos = __assign$1({}, toPos));
|
5155 | userDuration !== undefined && (userControl.duration = userDuration);
|
5156 | return userControl;
|
5157 | };
|
5158 | };
|
5159 |
|
5160 | __proto.setAnimationManager = function (am) {
|
5161 | this.am = am;
|
5162 | };
|
5163 |
|
5164 | __proto.destroy = function () {
|
5165 | this.axes.off();
|
5166 | };
|
5167 |
|
5168 | __proto.getRoundPos = function (pos, depaPos) {
|
5169 |
|
5170 | var roundUnit = this.axes.options.round;
|
5171 |
|
5172 |
|
5173 |
|
5174 | return {
|
5175 | roundPos: roundNumbers(pos, roundUnit),
|
5176 | roundDepa: roundNumbers(depaPos, roundUnit)
|
5177 | };
|
5178 | };
|
5179 |
|
5180 | return EventManager;
|
5181 | }();
|
5182 |
|
5183 | var InterruptManager =
|
5184 |
|
5185 | function () {
|
5186 | function InterruptManager(options) {
|
5187 | this.options = options;
|
5188 | this._prevented = false;
|
5189 | }
|
5190 |
|
5191 | var __proto = InterruptManager.prototype;
|
5192 |
|
5193 | __proto.isInterrupting = function () {
|
5194 |
|
5195 | return this.options.interruptable || this._prevented;
|
5196 | };
|
5197 |
|
5198 | __proto.isInterrupted = function () {
|
5199 | return !this.options.interruptable && this._prevented;
|
5200 | };
|
5201 |
|
5202 | __proto.setInterrupt = function (prevented) {
|
5203 | !this.options.interruptable && (this._prevented = prevented);
|
5204 | };
|
5205 |
|
5206 | return InterruptManager;
|
5207 | }();
|
5208 |
|
5209 | var AxisManager =
|
5210 |
|
5211 | function () {
|
5212 | function AxisManager(axis, options) {
|
5213 | var _this = this;
|
5214 |
|
5215 | this.axis = axis;
|
5216 | this.options = options;
|
5217 |
|
5218 | this._complementOptions();
|
5219 |
|
5220 | this._pos = Object.keys(this.axis).reduce(function (acc, v) {
|
5221 | acc[v] = _this.axis[v].range[0];
|
5222 | return acc;
|
5223 | }, {});
|
5224 | }
|
5225 | |
5226 |
|
5227 |
|
5228 |
|
5229 |
|
5230 |
|
5231 | var __proto = AxisManager.prototype;
|
5232 |
|
5233 | __proto._complementOptions = function () {
|
5234 | var _this = this;
|
5235 |
|
5236 | Object.keys(this.axis).forEach(function (axis) {
|
5237 | _this.axis[axis] = __assign$1({
|
5238 | range: [0, 100],
|
5239 | bounce: [0, 0],
|
5240 | circular: [false, false]
|
5241 | }, _this.axis[axis]);
|
5242 | ["bounce", "circular"].forEach(function (v) {
|
5243 | var axisOption = _this.axis;
|
5244 | var key = axisOption[axis][v];
|
5245 |
|
5246 | if (/string|number|boolean/.test(typeof key)) {
|
5247 | axisOption[axis][v] = [key, key];
|
5248 | }
|
5249 | });
|
5250 | });
|
5251 | };
|
5252 |
|
5253 | __proto.getDelta = function (depaPos, destPos) {
|
5254 | var fullDepaPos = this.get(depaPos);
|
5255 | return map(this.get(destPos), function (v, k) {
|
5256 | return v - fullDepaPos[k];
|
5257 | });
|
5258 | };
|
5259 |
|
5260 | __proto.get = function (axes) {
|
5261 | var _this = this;
|
5262 |
|
5263 | if (axes && Array.isArray(axes)) {
|
5264 | return axes.reduce(function (acc, v) {
|
5265 | if (v && v in _this._pos) {
|
5266 | acc[v] = _this._pos[v];
|
5267 | }
|
5268 |
|
5269 | return acc;
|
5270 | }, {});
|
5271 | } else {
|
5272 | return __assign$1(__assign$1({}, this._pos), axes || {});
|
5273 | }
|
5274 | };
|
5275 |
|
5276 | __proto.moveTo = function (pos, depaPos) {
|
5277 | if (depaPos === void 0) {
|
5278 | depaPos = this._pos;
|
5279 | }
|
5280 |
|
5281 | var delta = map(this._pos, function (v, key) {
|
5282 | return key in pos && key in depaPos ? pos[key] - depaPos[key] : 0;
|
5283 | });
|
5284 | this.set(this.map(pos, function (v, opt) {
|
5285 | return opt ? getCirculatedPos(v, opt.range, opt.circular) : 0;
|
5286 | }));
|
5287 | return {
|
5288 | pos: __assign$1({}, this._pos),
|
5289 | delta: delta
|
5290 | };
|
5291 | };
|
5292 |
|
5293 | __proto.set = function (pos) {
|
5294 | for (var k in pos) {
|
5295 | if (k && k in this._pos) {
|
5296 | this._pos[k] = pos[k];
|
5297 | }
|
5298 | }
|
5299 | };
|
5300 |
|
5301 | __proto.every = function (pos, callback) {
|
5302 | var axisOptions = this.axis;
|
5303 | return every(pos, function (value, key) {
|
5304 | return callback(value, axisOptions[key], key);
|
5305 | });
|
5306 | };
|
5307 |
|
5308 | __proto.filter = function (pos, callback) {
|
5309 | var axisOptions = this.axis;
|
5310 | return filter(pos, function (value, key) {
|
5311 | return callback(value, axisOptions[key], key);
|
5312 | });
|
5313 | };
|
5314 |
|
5315 | __proto.map = function (pos, callback) {
|
5316 | var axisOptions = this.axis;
|
5317 | return map(pos, function (value, key) {
|
5318 | return callback(value, axisOptions[key], key);
|
5319 | });
|
5320 | };
|
5321 |
|
5322 | __proto.isOutside = function (axes) {
|
5323 | return !this.every(axes ? this.get(axes) : this._pos, function (v, opt) {
|
5324 | return !isOutside(v, opt.range);
|
5325 | });
|
5326 | };
|
5327 |
|
5328 | __proto.getAxisOptions = function (key) {
|
5329 | return this.axis[key];
|
5330 | };
|
5331 |
|
5332 | return AxisManager;
|
5333 | }();
|
5334 |
|
5335 | var InputObserver =
|
5336 |
|
5337 | function () {
|
5338 | function InputObserver(_a) {
|
5339 | var options = _a.options,
|
5340 | itm = _a.itm,
|
5341 | em = _a.em,
|
5342 | axm = _a.axm,
|
5343 | am = _a.am;
|
5344 | this.isOutside = false;
|
5345 | this.moveDistance = null;
|
5346 | this.isStopped = false;
|
5347 | this.options = options;
|
5348 | this.itm = itm;
|
5349 | this.em = em;
|
5350 | this.axm = axm;
|
5351 | this.am = am;
|
5352 | }
|
5353 |
|
5354 |
|
5355 | var __proto = InputObserver.prototype;
|
5356 |
|
5357 | __proto.atOutside = function (pos) {
|
5358 | var _this = this;
|
5359 |
|
5360 | if (this.isOutside) {
|
5361 | return this.axm.map(pos, function (v, opt) {
|
5362 | var tn = opt.range[0] - opt.bounce[0];
|
5363 | var tx = opt.range[1] + opt.bounce[1];
|
5364 | return v > tx ? tx : v < tn ? tn : v;
|
5365 | });
|
5366 | } else {
|
5367 |
|
5368 |
|
5369 | var initSlope_1 = this.am.easing(0.00001) / 0.00001;
|
5370 | return this.axm.map(pos, function (v, opt) {
|
5371 | var min = opt.range[0];
|
5372 | var max = opt.range[1];
|
5373 | var out = opt.bounce;
|
5374 | var circular = opt.circular;
|
5375 |
|
5376 | if (circular && (circular[0] || circular[1])) {
|
5377 | return v;
|
5378 | } else if (v < min) {
|
5379 |
|
5380 | return min - _this.am.easing((min - v) / (out[0] * initSlope_1)) * out[0];
|
5381 | } else if (v > max) {
|
5382 |
|
5383 | return max + _this.am.easing((v - max) / (out[1] * initSlope_1)) * out[1];
|
5384 | }
|
5385 |
|
5386 | return v;
|
5387 | });
|
5388 | }
|
5389 | };
|
5390 |
|
5391 | __proto.get = function (input) {
|
5392 | return this.axm.get(input.axes);
|
5393 | };
|
5394 |
|
5395 | __proto.hold = function (input, event) {
|
5396 | if (this.itm.isInterrupted() || !input.axes.length) {
|
5397 | return;
|
5398 | }
|
5399 |
|
5400 | var changeOption = {
|
5401 | input: input,
|
5402 | event: event
|
5403 | };
|
5404 | this.isStopped = false;
|
5405 | this.itm.setInterrupt(true);
|
5406 | this.am.grab(input.axes, changeOption);
|
5407 | !this.moveDistance && this.em.triggerHold(this.axm.get(), changeOption);
|
5408 | this.isOutside = this.axm.isOutside(input.axes);
|
5409 | this.moveDistance = this.axm.get(input.axes);
|
5410 | };
|
5411 |
|
5412 | __proto.change = function (input, event, offset) {
|
5413 | if (this.isStopped || !this.itm.isInterrupting() || this.axm.every(offset, function (v) {
|
5414 | return v === 0;
|
5415 | })) {
|
5416 | return;
|
5417 | }
|
5418 |
|
5419 | var depaPos = this.moveDistance || this.axm.get(input.axes);
|
5420 | var destPos;
|
5421 |
|
5422 | destPos = map(depaPos, function (v, k) {
|
5423 | return v + (offset[k] || 0);
|
5424 | });
|
5425 | this.moveDistance && (this.moveDistance = destPos);
|
5426 |
|
5427 | if (this.isOutside && this.axm.every(depaPos, function (v, opt) {
|
5428 | return !isOutside(v, opt.range);
|
5429 | })) {
|
5430 | this.isOutside = false;
|
5431 | }
|
5432 |
|
5433 | depaPos = this.atOutside(depaPos);
|
5434 | destPos = this.atOutside(destPos);
|
5435 | var isCanceled = !this.em.triggerChange(destPos, false, depaPos, {
|
5436 | input: input,
|
5437 | event: event
|
5438 | }, true);
|
5439 |
|
5440 | if (isCanceled) {
|
5441 | this.isStopped = true;
|
5442 | this.moveDistance = null;
|
5443 | this.am.finish(false);
|
5444 | }
|
5445 | };
|
5446 |
|
5447 | __proto.release = function (input, event, offset, inputDuration) {
|
5448 | if (this.isStopped || !this.itm.isInterrupting() || !this.moveDistance) {
|
5449 | return;
|
5450 | }
|
5451 |
|
5452 | var pos = this.axm.get(input.axes);
|
5453 | var depaPos = this.axm.get();
|
5454 | var destPos = this.axm.get(this.axm.map(offset, function (v, opt, k) {
|
5455 | if (opt.circular && (opt.circular[0] || opt.circular[1])) {
|
5456 | return pos[k] + v;
|
5457 | } else {
|
5458 | return getInsidePosition(pos[k] + v, opt.range, opt.circular, opt.bounce);
|
5459 | }
|
5460 | }));
|
5461 | var duration = this.am.getDuration(destPos, pos, inputDuration);
|
5462 |
|
5463 | if (duration === 0) {
|
5464 | destPos = __assign$1({}, depaPos);
|
5465 | }
|
5466 |
|
5467 |
|
5468 | var param = {
|
5469 | depaPos: depaPos,
|
5470 | destPos: destPos,
|
5471 | duration: duration,
|
5472 | delta: this.axm.getDelta(depaPos, destPos),
|
5473 | inputEvent: event,
|
5474 | input: input,
|
5475 | isTrusted: true
|
5476 | };
|
5477 | this.em.triggerRelease(param);
|
5478 | this.moveDistance = null;
|
5479 |
|
5480 | var userWish = this.am.getUserControll(param);
|
5481 | var isEqual = equal(userWish.destPos, depaPos);
|
5482 | var changeOption = {
|
5483 | input: input,
|
5484 | event: event
|
5485 | };
|
5486 |
|
5487 | if (isEqual || userWish.duration === 0) {
|
5488 | !isEqual && this.em.triggerChange(userWish.destPos, false, depaPos, changeOption, true);
|
5489 | this.itm.setInterrupt(false);
|
5490 |
|
5491 | if (this.axm.isOutside()) {
|
5492 | this.am.restore(changeOption);
|
5493 | } else {
|
5494 | this.em.triggerFinish(true);
|
5495 | }
|
5496 | } else {
|
5497 | this.am.animateTo(userWish.destPos, userWish.duration, changeOption);
|
5498 | }
|
5499 | };
|
5500 |
|
5501 | return InputObserver;
|
5502 | }();
|
5503 |
|
5504 |
|
5505 | var IOS_EDGE_THRESHOLD = 30;
|
5506 | var IS_IOS_SAFARI = "ontouchstart" in win$2 && agent().browser.name === "safari";
|
5507 | var TRANSFORM$1 = function () {
|
5508 | if (typeof document === "undefined") {
|
5509 | return "";
|
5510 | }
|
5511 |
|
5512 | var bodyStyle = (document.head || document.getElementsByTagName("head")[0]).style;
|
5513 | var target = ["transform", "webkitTransform", "msTransform", "mozTransform"];
|
5514 |
|
5515 | for (var i = 0, len = target.length; i < len; i++) {
|
5516 | if (target[i] in bodyStyle) {
|
5517 | return target[i];
|
5518 | }
|
5519 | }
|
5520 |
|
5521 | return "";
|
5522 | }();
|
5523 |
|
5524 | |
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 | |
5539 |
|
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 | |
5550 |
|
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 |
|
5556 |
|
5557 |
|
5558 |
|
5559 |
|
5560 |
|
5561 |
|
5562 |
|
5563 |
|
5564 |
|
5565 |
|
5566 |
|
5567 |
|
5568 |
|
5569 |
|
5570 |
|
5571 |
|
5572 |
|
5573 |
|
5574 |
|
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 |
|
5588 |
|
5589 |
|
5590 |
|
5591 |
|
5592 |
|
5593 |
|
5594 |
|
5595 |
|
5596 |
|
5597 |
|
5598 |
|
5599 |
|
5600 |
|
5601 |
|
5602 |
|
5603 |
|
5604 |
|
5605 |
|
5606 |
|
5607 |
|
5608 |
|
5609 |
|
5610 |
|
5611 |
|
5612 |
|
5613 |
|
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 |
|
5619 | var Axes =
|
5620 |
|
5621 | function (_super) {
|
5622 | __extends$1(Axes, _super);
|
5623 |
|
5624 | function Axes(axis, options, startPos) {
|
5625 | if (axis === void 0) {
|
5626 | axis = {};
|
5627 | }
|
5628 |
|
5629 | if (options === void 0) {
|
5630 | options = {};
|
5631 | }
|
5632 |
|
5633 | var _this = _super.call(this) || this;
|
5634 |
|
5635 | _this.axis = axis;
|
5636 | _this._inputs = [];
|
5637 | _this.options = __assign$1({
|
5638 | easing: function easeOutCubic(x) {
|
5639 | return 1 - Math.pow(1 - x, 3);
|
5640 | },
|
5641 | interruptable: true,
|
5642 | maximumDuration: Infinity,
|
5643 | minimumDuration: 0,
|
5644 | deceleration: 0.0006,
|
5645 | round: null
|
5646 | }, options);
|
5647 | _this.itm = new InterruptManager(_this.options);
|
5648 | _this.axm = new AxisManager(_this.axis, _this.options);
|
5649 | _this.em = new EventManager(_this);
|
5650 | _this.am = new AnimationManager(_this);
|
5651 | _this.io = new InputObserver(_this);
|
5652 |
|
5653 | _this.em.setAnimationManager(_this.am);
|
5654 |
|
5655 | startPos && _this.em.triggerChange(startPos);
|
5656 | return _this;
|
5657 | }
|
5658 | |
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 |
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 | var __proto = Axes.prototype;
|
5685 |
|
5686 | __proto.connect = function (axes, inputType) {
|
5687 | var mapped;
|
5688 |
|
5689 | if (typeof axes === "string") {
|
5690 | mapped = axes.split(" ");
|
5691 | } else {
|
5692 | mapped = axes.concat();
|
5693 | }
|
5694 |
|
5695 |
|
5696 | if (~this._inputs.indexOf(inputType)) {
|
5697 | this.disconnect(inputType);
|
5698 | }
|
5699 |
|
5700 |
|
5701 | if ("hammer" in inputType) {
|
5702 | var targets = this._inputs.filter(function (v) {
|
5703 | return v.hammer && v.element === inputType.element;
|
5704 | });
|
5705 |
|
5706 | if (targets.length) {
|
5707 | inputType.hammer = targets[0].hammer;
|
5708 | }
|
5709 | }
|
5710 |
|
5711 | inputType.mapAxes(mapped);
|
5712 | inputType.connect(this.io);
|
5713 |
|
5714 | this._inputs.push(inputType);
|
5715 |
|
5716 | return this;
|
5717 | };
|
5718 | |
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 |
|
5734 |
|
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 |
|
5744 |
|
5745 |
|
5746 |
|
5747 | __proto.disconnect = function (inputType) {
|
5748 | if (inputType) {
|
5749 | var index = this._inputs.indexOf(inputType);
|
5750 |
|
5751 | if (index >= 0) {
|
5752 | this._inputs[index].disconnect();
|
5753 |
|
5754 | this._inputs.splice(index, 1);
|
5755 | }
|
5756 | } else {
|
5757 | this._inputs.forEach(function (v) {
|
5758 | return v.disconnect();
|
5759 | });
|
5760 |
|
5761 | this._inputs = [];
|
5762 | }
|
5763 |
|
5764 | return this;
|
5765 | };
|
5766 | |
5767 |
|
5768 |
|
5769 |
|
5770 |
|
5771 |
|
5772 |
|
5773 |
|
5774 |
|
5775 |
|
5776 |
|
5777 |
|
5778 |
|
5779 |
|
5780 |
|
5781 |
|
5782 |
|
5783 |
|
5784 |
|
5785 |
|
5786 |
|
5787 |
|
5788 |
|
5789 |
|
5790 | __proto.get = function (axes) {
|
5791 | return this.axm.get(axes);
|
5792 | };
|
5793 | |
5794 |
|
5795 |
|
5796 |
|
5797 |
|
5798 |
|
5799 |
|
5800 |
|
5801 |
|
5802 |
|
5803 |
|
5804 |
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 |
|
5810 |
|
5811 |
|
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 |
|
5822 |
|
5823 | __proto.setTo = function (pos, duration) {
|
5824 | if (duration === void 0) {
|
5825 | duration = 0;
|
5826 | }
|
5827 |
|
5828 | this.am.setTo(pos, duration);
|
5829 | return this;
|
5830 | };
|
5831 | |
5832 |
|
5833 |
|
5834 |
|
5835 |
|
5836 |
|
5837 |
|
5838 |
|
5839 |
|
5840 |
|
5841 |
|
5842 |
|
5843 |
|
5844 |
|
5845 |
|
5846 |
|
5847 |
|
5848 |
|
5849 |
|
5850 |
|
5851 |
|
5852 |
|
5853 |
|
5854 |
|
5855 |
|
5856 |
|
5857 |
|
5858 |
|
5859 |
|
5860 |
|
5861 | __proto.setBy = function (pos, duration) {
|
5862 | if (duration === void 0) {
|
5863 | duration = 0;
|
5864 | }
|
5865 |
|
5866 | this.am.setBy(pos, duration);
|
5867 | return this;
|
5868 | };
|
5869 | |
5870 |
|
5871 |
|
5872 |
|
5873 |
|
5874 |
|
5875 |
|
5876 |
|
5877 |
|
5878 |
|
5879 |
|
5880 |
|
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 |
|
5887 |
|
5888 |
|
5889 |
|
5890 |
|
5891 |
|
5892 |
|
5893 |
|
5894 | __proto.isBounceArea = function (axes) {
|
5895 | return this.axm.isOutside(axes);
|
5896 | };
|
5897 | |
5898 |
|
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 | __proto.destroy = function () {
|
5905 | this.disconnect();
|
5906 | this.em.destroy();
|
5907 | };
|
5908 | |
5909 |
|
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 |
|
5917 |
|
5918 |
|
5919 |
|
5920 | Axes.VERSION = "2.7.2";
|
5921 | |
5922 |
|
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 |
|
5928 |
|
5929 |
|
5930 |
|
5931 |
|
5932 | Axes.TRANSFORM = TRANSFORM$1;
|
5933 | |
5934 |
|
5935 |
|
5936 |
|
5937 |
|
5938 |
|
5939 | Axes.DIRECTION_NONE = DIRECTION_NONE;
|
5940 | |
5941 |
|
5942 |
|
5943 |
|
5944 |
|
5945 |
|
5946 | Axes.DIRECTION_LEFT = DIRECTION_LEFT;
|
5947 | |
5948 |
|
5949 |
|
5950 |
|
5951 |
|
5952 |
|
5953 | Axes.DIRECTION_RIGHT = DIRECTION_RIGHT;
|
5954 | |
5955 |
|
5956 |
|
5957 |
|
5958 |
|
5959 |
|
5960 | Axes.DIRECTION_UP = DIRECTION_UP;
|
5961 | |
5962 |
|
5963 |
|
5964 |
|
5965 |
|
5966 |
|
5967 | Axes.DIRECTION_DOWN = DIRECTION_DOWN;
|
5968 | |
5969 |
|
5970 |
|
5971 |
|
5972 |
|
5973 |
|
5974 | Axes.DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL;
|
5975 | |
5976 |
|
5977 |
|
5978 |
|
5979 |
|
5980 |
|
5981 | Axes.DIRECTION_VERTICAL = DIRECTION_VERTICAL;
|
5982 | |
5983 |
|
5984 |
|
5985 |
|
5986 |
|
5987 |
|
5988 | Axes.DIRECTION_ALL = DIRECTION_ALL;
|
5989 | return Axes;
|
5990 | }(Component$1);
|
5991 |
|
5992 | var SUPPORT_POINTER_EVENTS$1 = "PointerEvent" in win$2 || "MSPointerEvent" in win$2;
|
5993 | var SUPPORT_TOUCH$2 = ("ontouchstart" in win$2);
|
5994 | var UNIQUEKEY = "_EGJS_AXES_INPUTTYPE_";
|
5995 | function toAxis(source, offset) {
|
5996 | return offset.reduce(function (acc, v, i) {
|
5997 | if (source[i]) {
|
5998 | acc[source[i]] = v;
|
5999 | }
|
6000 |
|
6001 | return acc;
|
6002 | }, {});
|
6003 | }
|
6004 | function createHammer(element, options) {
|
6005 | try {
|
6006 |
|
6007 | return new Manager(element, __assign$1({}, options));
|
6008 | } catch (e) {
|
6009 | return null;
|
6010 | }
|
6011 | }
|
6012 | function convertInputType(inputType) {
|
6013 | if (inputType === void 0) {
|
6014 | inputType = [];
|
6015 | }
|
6016 |
|
6017 | var hasTouch = false;
|
6018 | var hasMouse = false;
|
6019 | var hasPointer = false;
|
6020 | inputType.forEach(function (v) {
|
6021 | switch (v) {
|
6022 | case "mouse":
|
6023 | hasMouse = true;
|
6024 | break;
|
6025 |
|
6026 | case "touch":
|
6027 | hasTouch = SUPPORT_TOUCH$2;
|
6028 | break;
|
6029 |
|
6030 | case "pointer":
|
6031 | hasPointer = SUPPORT_POINTER_EVENTS$1;
|
6032 |
|
6033 | }
|
6034 | });
|
6035 |
|
6036 | if (hasPointer) {
|
6037 | return PointerEventInput;
|
6038 | } else if (hasTouch && hasMouse) {
|
6039 | return TouchMouseInput;
|
6040 | } else if (hasTouch) {
|
6041 | return TouchInput;
|
6042 | } else if (hasMouse) {
|
6043 | return MouseInput;
|
6044 | }
|
6045 |
|
6046 | return null;
|
6047 | }
|
6048 |
|
6049 | function getDirectionByAngle(angle, thresholdAngle) {
|
6050 | if (thresholdAngle < 0 || thresholdAngle > 90) {
|
6051 | return DIRECTION_NONE;
|
6052 | }
|
6053 |
|
6054 | var toAngle = Math.abs(angle);
|
6055 | return toAngle > thresholdAngle && toAngle < 180 - thresholdAngle ? DIRECTION_VERTICAL : DIRECTION_HORIZONTAL;
|
6056 | }
|
6057 | function getNextOffset(speeds, deceleration) {
|
6058 | var normalSpeed = Math.sqrt(speeds[0] * speeds[0] + speeds[1] * speeds[1]);
|
6059 | var duration = Math.abs(normalSpeed / -deceleration);
|
6060 | return [speeds[0] / 2 * duration, speeds[1] / 2 * duration];
|
6061 | }
|
6062 | function useDirection(checkType, direction, userDirection) {
|
6063 | if (userDirection) {
|
6064 | return !!(direction === DIRECTION_ALL || direction & checkType && userDirection & checkType);
|
6065 | } else {
|
6066 | return !!(direction & checkType);
|
6067 | }
|
6068 | }
|
6069 | |
6070 |
|
6071 |
|
6072 |
|
6073 |
|
6074 |
|
6075 |
|
6076 |
|
6077 |
|
6078 |
|
6079 |
|
6080 |
|
6081 |
|
6082 | |
6083 |
|
6084 |
|
6085 |
|
6086 |
|
6087 |
|
6088 |
|
6089 |
|
6090 |
|
6091 |
|
6092 |
|
6093 |
|
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 |
|
6099 |
|
6100 |
|
6101 |
|
6102 |
|
6103 |
|
6104 |
|
6105 |
|
6106 |
|
6107 | var PanInput =
|
6108 |
|
6109 | function () {
|
6110 | function PanInput(el, options) {
|
6111 | this.axes = [];
|
6112 | this.hammer = null;
|
6113 | this.element = null;
|
6114 | this.panRecognizer = null;
|
6115 | this.isRightEdge = false;
|
6116 | this.rightEdgeTimer = 0;
|
6117 | this.panFlag = false;
|
6118 | |
6119 |
|
6120 |
|
6121 |
|
6122 |
|
6123 |
|
6124 |
|
6125 |
|
6126 |
|
6127 | if (typeof Manager === "undefined") {
|
6128 | throw new Error("The Hammerjs must be loaded before eg.Axes.PanInput.\nhttp://hammerjs.github.io/");
|
6129 | }
|
6130 |
|
6131 | this.element = $(el);
|
6132 | this.options = __assign$1({
|
6133 | inputType: ["touch", "mouse", "pointer"],
|
6134 | scale: [1, 1],
|
6135 | thresholdAngle: 45,
|
6136 | threshold: 0,
|
6137 | iOSEdgeSwipeThreshold: IOS_EDGE_THRESHOLD,
|
6138 | hammerManagerOptions: {
|
6139 |
|
6140 |
|
6141 | cssProps: {
|
6142 | userSelect: "none",
|
6143 | touchSelect: "none",
|
6144 | touchCallout: "none",
|
6145 | userDrag: "none"
|
6146 | }
|
6147 | }
|
6148 | }, options);
|
6149 | this.onHammerInput = this.onHammerInput.bind(this);
|
6150 | this.onPanmove = this.onPanmove.bind(this);
|
6151 | this.onPanend = this.onPanend.bind(this);
|
6152 | }
|
6153 |
|
6154 | var __proto = PanInput.prototype;
|
6155 |
|
6156 | __proto.mapAxes = function (axes) {
|
6157 | var useHorizontal = !!axes[0];
|
6158 | var useVertical = !!axes[1];
|
6159 |
|
6160 | if (useHorizontal && useVertical) {
|
6161 | this._direction = DIRECTION_ALL;
|
6162 | } else if (useHorizontal) {
|
6163 | this._direction = DIRECTION_HORIZONTAL;
|
6164 | } else if (useVertical) {
|
6165 | this._direction = DIRECTION_VERTICAL;
|
6166 | } else {
|
6167 | this._direction = DIRECTION_NONE;
|
6168 | }
|
6169 |
|
6170 | this.axes = axes;
|
6171 | };
|
6172 |
|
6173 | __proto.connect = function (observer) {
|
6174 | var hammerOption = {
|
6175 | direction: this._direction,
|
6176 | threshold: this.options.threshold
|
6177 | };
|
6178 |
|
6179 | if (this.hammer) {
|
6180 |
|
6181 |
|
6182 | this.removeRecognizer();
|
6183 | this.dettachEvent();
|
6184 | } else {
|
6185 | var keyValue = this.element[UNIQUEKEY];
|
6186 |
|
6187 | if (!keyValue) {
|
6188 | keyValue = String(Math.round(Math.random() * new Date().getTime()));
|
6189 | }
|
6190 |
|
6191 | var inputClass = convertInputType(this.options.inputType);
|
6192 |
|
6193 | if (!inputClass) {
|
6194 | throw new Error("Wrong inputType parameter!");
|
6195 | }
|
6196 |
|
6197 | this.hammer = createHammer(this.element, __assign$1({
|
6198 | inputClass: inputClass
|
6199 | }, this.options.hammerManagerOptions));
|
6200 | this.element[UNIQUEKEY] = keyValue;
|
6201 | }
|
6202 |
|
6203 | this.panRecognizer = new PanRecognizer(hammerOption);
|
6204 | this.hammer.add(this.panRecognizer);
|
6205 | this.attachEvent(observer);
|
6206 | return this;
|
6207 | };
|
6208 |
|
6209 | __proto.disconnect = function () {
|
6210 | this.removeRecognizer();
|
6211 |
|
6212 | if (this.hammer) {
|
6213 | this.dettachEvent();
|
6214 | }
|
6215 |
|
6216 | this._direction = DIRECTION_NONE;
|
6217 | return this;
|
6218 | };
|
6219 | |
6220 |
|
6221 |
|
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 | __proto.destroy = function () {
|
6227 | this.disconnect();
|
6228 |
|
6229 | if (this.hammer && this.hammer.recognizers.length === 0) {
|
6230 | this.hammer.destroy();
|
6231 | }
|
6232 |
|
6233 | delete this.element[UNIQUEKEY];
|
6234 | this.element = null;
|
6235 | this.hammer = null;
|
6236 | };
|
6237 | |
6238 |
|
6239 |
|
6240 |
|
6241 |
|
6242 |
|
6243 |
|
6244 |
|
6245 | __proto.enable = function () {
|
6246 | this.hammer && (this.hammer.get("pan").options.enable = true);
|
6247 | return this;
|
6248 | };
|
6249 | |
6250 |
|
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 | __proto.disable = function () {
|
6258 | this.hammer && (this.hammer.get("pan").options.enable = false);
|
6259 | return this;
|
6260 | };
|
6261 | |
6262 |
|
6263 |
|
6264 |
|
6265 |
|
6266 |
|
6267 |
|
6268 |
|
6269 | __proto.isEnable = function () {
|
6270 | return !!(this.hammer && this.hammer.get("pan").options.enable);
|
6271 | };
|
6272 |
|
6273 | __proto.removeRecognizer = function () {
|
6274 | if (this.hammer && this.panRecognizer) {
|
6275 | this.hammer.remove(this.panRecognizer);
|
6276 | this.panRecognizer = null;
|
6277 | }
|
6278 | };
|
6279 |
|
6280 | __proto.onHammerInput = function (event) {
|
6281 | if (this.isEnable()) {
|
6282 | if (event.isFirst) {
|
6283 | this.panFlag = false;
|
6284 |
|
6285 | if (event.srcEvent.cancelable !== false) {
|
6286 | var edgeThreshold = this.options.iOSEdgeSwipeThreshold;
|
6287 | this.observer.hold(this, event);
|
6288 | this.isRightEdge = IS_IOS_SAFARI && event.center.x > window.innerWidth - edgeThreshold;
|
6289 | this.panFlag = true;
|
6290 | }
|
6291 | } else if (event.isFinal) {
|
6292 | this.onPanend(event);
|
6293 | }
|
6294 | }
|
6295 | };
|
6296 |
|
6297 | __proto.onPanmove = function (event) {
|
6298 | var _this = this;
|
6299 |
|
6300 | if (!this.panFlag) {
|
6301 | return;
|
6302 | }
|
6303 |
|
6304 | var userDirection = getDirectionByAngle(event.angle, this.options.thresholdAngle);
|
6305 |
|
6306 | var prevInput = this.hammer.session.prevInput;
|
6307 |
|
6308 | if (prevInput && IS_IOS_SAFARI) {
|
6309 | var swipeLeftToRight = event.center.x < 0;
|
6310 |
|
6311 | if (swipeLeftToRight) {
|
6312 |
|
6313 | this.onPanend(__assign$1(__assign$1({}, prevInput), {
|
6314 | velocityX: 0,
|
6315 | velocityY: 0,
|
6316 | offsetX: 0,
|
6317 | offsetY: 0
|
6318 | }));
|
6319 | return;
|
6320 | } else if (this.isRightEdge) {
|
6321 | clearTimeout(this.rightEdgeTimer);
|
6322 |
|
6323 | var edgeThreshold = this.options.iOSEdgeSwipeThreshold;
|
6324 | var swipeRightToLeft = event.deltaX < -edgeThreshold;
|
6325 |
|
6326 | if (swipeRightToLeft) {
|
6327 | this.isRightEdge = false;
|
6328 | } else {
|
6329 |
|
6330 | this.rightEdgeTimer = window.setTimeout(function () {
|
6331 | _this.onPanend(__assign$1(__assign$1({}, prevInput), {
|
6332 | velocityX: 0,
|
6333 | velocityY: 0,
|
6334 | offsetX: 0,
|
6335 | offsetY: 0
|
6336 | }));
|
6337 | }, 100);
|
6338 | }
|
6339 | }
|
6340 | }
|
6341 |
|
6342 |
|
6343 |
|
6344 | if (prevInput) {
|
6345 | event.offsetX = event.deltaX - prevInput.deltaX;
|
6346 | event.offsetY = event.deltaY - prevInput.deltaY;
|
6347 | } else {
|
6348 | event.offsetX = 0;
|
6349 | event.offsetY = 0;
|
6350 | }
|
6351 |
|
6352 | var offset = this.getOffset([event.offsetX, event.offsetY], [useDirection(DIRECTION_HORIZONTAL, this._direction, userDirection), useDirection(DIRECTION_VERTICAL, this._direction, userDirection)]);
|
6353 | var prevent = offset.some(function (v) {
|
6354 | return v !== 0;
|
6355 | });
|
6356 |
|
6357 | if (prevent) {
|
6358 | var srcEvent = event.srcEvent;
|
6359 |
|
6360 | if (srcEvent.cancelable !== false) {
|
6361 | srcEvent.preventDefault();
|
6362 | }
|
6363 |
|
6364 | srcEvent.stopPropagation();
|
6365 | }
|
6366 |
|
6367 | event.preventSystemEvent = prevent;
|
6368 | prevent && this.observer.change(this, event, toAxis(this.axes, offset));
|
6369 | };
|
6370 |
|
6371 | __proto.onPanend = function (event) {
|
6372 | if (!this.panFlag) {
|
6373 | return;
|
6374 | }
|
6375 |
|
6376 | clearTimeout(this.rightEdgeTimer);
|
6377 | this.panFlag = false;
|
6378 | var offset = this.getOffset([Math.abs(event.velocityX) * (event.deltaX < 0 ? -1 : 1), Math.abs(event.velocityY) * (event.deltaY < 0 ? -1 : 1)], [useDirection(DIRECTION_HORIZONTAL, this._direction), useDirection(DIRECTION_VERTICAL, this._direction)]);
|
6379 | offset = getNextOffset(offset, this.observer.options.deceleration);
|
6380 | this.observer.release(this, event, toAxis(this.axes, offset));
|
6381 | };
|
6382 |
|
6383 | __proto.attachEvent = function (observer) {
|
6384 | this.observer = observer;
|
6385 | this.hammer.on("hammer.input", this.onHammerInput).on("panstart panmove", this.onPanmove);
|
6386 | };
|
6387 |
|
6388 | __proto.dettachEvent = function () {
|
6389 | this.hammer.off("hammer.input", this.onHammerInput).off("panstart panmove", this.onPanmove);
|
6390 | this.observer = null;
|
6391 | };
|
6392 |
|
6393 | __proto.getOffset = function (properties, direction) {
|
6394 | var offset = [0, 0];
|
6395 | var scale = this.options.scale;
|
6396 |
|
6397 | if (direction[0]) {
|
6398 | offset[0] = properties[0] * scale[0];
|
6399 | }
|
6400 |
|
6401 | if (direction[1]) {
|
6402 | offset[1] = properties[1] * scale[1];
|
6403 | }
|
6404 |
|
6405 | return offset;
|
6406 | };
|
6407 |
|
6408 | return PanInput;
|
6409 | }();
|
6410 |
|
6411 | |
6412 |
|
6413 |
|
6414 |
|
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 | |
6420 |
|
6421 |
|
6422 |
|
6423 |
|
6424 |
|
6425 |
|
6426 |
|
6427 |
|
6428 |
|
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 |
|
6434 |
|
6435 | var PinchInput =
|
6436 |
|
6437 | function () {
|
6438 | function PinchInput(el, options) {
|
6439 | this.axes = [];
|
6440 | this.hammer = null;
|
6441 | this.element = null;
|
6442 | this._base = null;
|
6443 | this._prev = null;
|
6444 | this.pinchRecognizer = null;
|
6445 | |
6446 |
|
6447 |
|
6448 |
|
6449 |
|
6450 |
|
6451 |
|
6452 |
|
6453 |
|
6454 | if (typeof Manager === "undefined") {
|
6455 | throw new Error("The Hammerjs must be loaded before eg.Axes.PinchInput.\nhttp://hammerjs.github.io/");
|
6456 | }
|
6457 |
|
6458 | this.element = $(el);
|
6459 | this.options = __assign$1({
|
6460 | scale: 1,
|
6461 | threshold: 0,
|
6462 | inputType: ["touch", "pointer"],
|
6463 | hammerManagerOptions: {
|
6464 |
|
6465 |
|
6466 | cssProps: {
|
6467 | userSelect: "none",
|
6468 | touchSelect: "none",
|
6469 | touchCallout: "none",
|
6470 | userDrag: "none"
|
6471 | }
|
6472 | }
|
6473 | }, options);
|
6474 | this.onPinchStart = this.onPinchStart.bind(this);
|
6475 | this.onPinchMove = this.onPinchMove.bind(this);
|
6476 | this.onPinchEnd = this.onPinchEnd.bind(this);
|
6477 | }
|
6478 |
|
6479 | var __proto = PinchInput.prototype;
|
6480 |
|
6481 | __proto.mapAxes = function (axes) {
|
6482 | this.axes = axes;
|
6483 | };
|
6484 |
|
6485 | __proto.connect = function (observer) {
|
6486 | var hammerOption = {
|
6487 | threshold: this.options.threshold
|
6488 | };
|
6489 |
|
6490 | if (this.hammer) {
|
6491 |
|
6492 |
|
6493 | this.removeRecognizer();
|
6494 | this.dettachEvent();
|
6495 | } else {
|
6496 | var keyValue = this.element[UNIQUEKEY];
|
6497 |
|
6498 | if (!keyValue) {
|
6499 | keyValue = String(Math.round(Math.random() * new Date().getTime()));
|
6500 | }
|
6501 |
|
6502 | var inputClass = convertInputType(this.options.inputType);
|
6503 |
|
6504 | if (!inputClass) {
|
6505 | throw new Error("Wrong inputType parameter!");
|
6506 | }
|
6507 |
|
6508 | this.hammer = createHammer(this.element, __assign$1({
|
6509 | inputClass: inputClass
|
6510 | }, this.options.hammerManagerOptions));
|
6511 | this.element[UNIQUEKEY] = keyValue;
|
6512 | }
|
6513 |
|
6514 | this.pinchRecognizer = new PinchRecognizer(hammerOption);
|
6515 | this.hammer.add(this.pinchRecognizer);
|
6516 | this.attachEvent(observer);
|
6517 | return this;
|
6518 | };
|
6519 |
|
6520 | __proto.disconnect = function () {
|
6521 | this.removeRecognizer();
|
6522 |
|
6523 | if (this.hammer) {
|
6524 | this.hammer.remove(this.pinchRecognizer);
|
6525 | this.pinchRecognizer = null;
|
6526 | this.dettachEvent();
|
6527 | }
|
6528 |
|
6529 | return this;
|
6530 | };
|
6531 | |
6532 |
|
6533 |
|
6534 |
|
6535 |
|
6536 |
|
6537 |
|
6538 | __proto.destroy = function () {
|
6539 | this.disconnect();
|
6540 |
|
6541 | if (this.hammer && this.hammer.recognizers.length === 0) {
|
6542 | this.hammer.destroy();
|
6543 | }
|
6544 |
|
6545 | delete this.element[UNIQUEKEY];
|
6546 | this.element = null;
|
6547 | this.hammer = null;
|
6548 | };
|
6549 |
|
6550 | __proto.removeRecognizer = function () {
|
6551 | if (this.hammer && this.pinchRecognizer) {
|
6552 | this.hammer.remove(this.pinchRecognizer);
|
6553 | this.pinchRecognizer = null;
|
6554 | }
|
6555 | };
|
6556 |
|
6557 | __proto.onPinchStart = function (event) {
|
6558 | this._base = this.observer.get(this)[this.axes[0]];
|
6559 | var offset = this.getOffset(event.scale);
|
6560 | this.observer.hold(this, event);
|
6561 | this.observer.change(this, event, toAxis(this.axes, [offset]));
|
6562 | this._prev = event.scale;
|
6563 | };
|
6564 |
|
6565 | __proto.onPinchMove = function (event) {
|
6566 | var offset = this.getOffset(event.scale, this._prev);
|
6567 | this.observer.change(this, event, toAxis(this.axes, [offset]));
|
6568 | this._prev = event.scale;
|
6569 | };
|
6570 |
|
6571 | __proto.onPinchEnd = function (event) {
|
6572 | var offset = this.getOffset(event.scale, this._prev);
|
6573 | this.observer.change(this, event, toAxis(this.axes, [offset]));
|
6574 | this.observer.release(this, event, toAxis(this.axes, [0]), 0);
|
6575 | this._base = null;
|
6576 | this._prev = null;
|
6577 | };
|
6578 |
|
6579 | __proto.getOffset = function (pinchScale, prev) {
|
6580 | if (prev === void 0) {
|
6581 | prev = 1;
|
6582 | }
|
6583 |
|
6584 | return this._base * (pinchScale - prev) * this.options.scale;
|
6585 | };
|
6586 |
|
6587 | __proto.attachEvent = function (observer) {
|
6588 | this.observer = observer;
|
6589 | this.hammer.on("pinchstart", this.onPinchStart).on("pinchmove", this.onPinchMove).on("pinchend", this.onPinchEnd);
|
6590 | };
|
6591 |
|
6592 | __proto.dettachEvent = function () {
|
6593 | this.hammer.off("pinchstart", this.onPinchStart).off("pinchmove", this.onPinchMove).off("pinchend", this.onPinchEnd);
|
6594 | this.observer = null;
|
6595 | this._prev = null;
|
6596 | };
|
6597 | |
6598 |
|
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 | __proto.enable = function () {
|
6606 | this.hammer && (this.hammer.get("pinch").options.enable = true);
|
6607 | return this;
|
6608 | };
|
6609 | |
6610 |
|
6611 |
|
6612 |
|
6613 |
|
6614 |
|
6615 |
|
6616 |
|
6617 | __proto.disable = function () {
|
6618 | this.hammer && (this.hammer.get("pinch").options.enable = false);
|
6619 | return this;
|
6620 | };
|
6621 | |
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 | __proto.isEnable = function () {
|
6630 | return !!(this.hammer && this.hammer.get("pinch").options.enable);
|
6631 | };
|
6632 |
|
6633 | return PinchInput;
|
6634 | }();
|
6635 |
|
6636 | |
6637 |
|
6638 |
|
6639 |
|
6640 |
|
6641 |
|
6642 | |
6643 |
|
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 |
|
6650 |
|
6651 |
|
6652 |
|
6653 |
|
6654 |
|
6655 |
|
6656 |
|
6657 |
|
6658 |
|
6659 | var WheelInput =
|
6660 |
|
6661 | function () {
|
6662 | function WheelInput(el, options) {
|
6663 | this.axes = [];
|
6664 | this.element = null;
|
6665 | this._isEnabled = false;
|
6666 | this._isHolded = false;
|
6667 | this._timer = null;
|
6668 | this.element = $(el);
|
6669 | this.options = __assign$1({
|
6670 | scale: 1,
|
6671 | useNormalized: true
|
6672 | }, options);
|
6673 | this.onWheel = this.onWheel.bind(this);
|
6674 | }
|
6675 |
|
6676 | var __proto = WheelInput.prototype;
|
6677 |
|
6678 | __proto.mapAxes = function (axes) {
|
6679 | this.axes = axes;
|
6680 | };
|
6681 |
|
6682 | __proto.connect = function (observer) {
|
6683 | this.dettachEvent();
|
6684 | this.attachEvent(observer);
|
6685 | return this;
|
6686 | };
|
6687 |
|
6688 | __proto.disconnect = function () {
|
6689 | this.dettachEvent();
|
6690 | return this;
|
6691 | };
|
6692 | |
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 | __proto.destroy = function () {
|
6700 | this.disconnect();
|
6701 | this.element = null;
|
6702 | };
|
6703 |
|
6704 | __proto.onWheel = function (event) {
|
6705 | var _this = this;
|
6706 |
|
6707 | if (!this._isEnabled) {
|
6708 | return;
|
6709 | }
|
6710 |
|
6711 | event.preventDefault();
|
6712 |
|
6713 | if (event.deltaY === 0) {
|
6714 | return;
|
6715 | }
|
6716 |
|
6717 | if (!this._isHolded) {
|
6718 | this.observer.hold(this, event);
|
6719 | this._isHolded = true;
|
6720 | }
|
6721 |
|
6722 | var offset = (event.deltaY > 0 ? -1 : 1) * this.options.scale * (this.options.useNormalized ? 1 : Math.abs(event.deltaY));
|
6723 | this.observer.change(this, event, toAxis(this.axes, [offset]));
|
6724 | clearTimeout(this._timer);
|
6725 | this._timer = setTimeout(function () {
|
6726 | if (_this._isHolded) {
|
6727 | _this._isHolded = false;
|
6728 |
|
6729 | _this.observer.release(_this, event, toAxis(_this.axes, [0]));
|
6730 | }
|
6731 | }, 50);
|
6732 | };
|
6733 |
|
6734 | __proto.attachEvent = function (observer) {
|
6735 | this.observer = observer;
|
6736 | this.element.addEventListener("wheel", this.onWheel);
|
6737 | this._isEnabled = true;
|
6738 | };
|
6739 |
|
6740 | __proto.dettachEvent = function () {
|
6741 | this.element.removeEventListener("wheel", this.onWheel);
|
6742 | this._isEnabled = false;
|
6743 | this.observer = null;
|
6744 |
|
6745 | if (this._timer) {
|
6746 | clearTimeout(this._timer);
|
6747 | this._timer = null;
|
6748 | }
|
6749 | };
|
6750 | |
6751 |
|
6752 |
|
6753 |
|
6754 |
|
6755 |
|
6756 |
|
6757 |
|
6758 | __proto.enable = function () {
|
6759 | this._isEnabled = true;
|
6760 | return this;
|
6761 | };
|
6762 | |
6763 |
|
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 |
|
6769 |
|
6770 | __proto.disable = function () {
|
6771 | this._isEnabled = false;
|
6772 | return this;
|
6773 | };
|
6774 | |
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 | __proto.isEnable = function () {
|
6783 | return this._isEnabled;
|
6784 | };
|
6785 |
|
6786 | return WheelInput;
|
6787 | }();
|
6788 |
|
6789 | var KEY_LEFT_ARROW = 37;
|
6790 | var KEY_A = 65;
|
6791 | var KEY_UP_ARROW = 38;
|
6792 | var KEY_W = 87;
|
6793 | var KEY_RIGHT_ARROW = 39;
|
6794 | var KEY_D = 68;
|
6795 | var KEY_DOWN_ARROW = 40;
|
6796 | var KEY_S = 83;
|
6797 | var DIRECTION_REVERSE = -1;
|
6798 | var DIRECTION_FORWARD = 1;
|
6799 | var DIRECTION_HORIZONTAL$1 = -1;
|
6800 | var DIRECTION_VERTICAL$1 = 1;
|
6801 | var DELAY = 80;
|
6802 | |
6803 |
|
6804 |
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 | |
6811 |
|
6812 |
|
6813 |
|
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 |
|
6827 | var MoveKeyInput =
|
6828 |
|
6829 | function () {
|
6830 | function MoveKeyInput(el, options) {
|
6831 | this.axes = [];
|
6832 | this.element = null;
|
6833 | this._isEnabled = false;
|
6834 | this._isHolded = false;
|
6835 | this._timer = null;
|
6836 | this.element = $(el);
|
6837 | this.options = __assign$1({
|
6838 | scale: [1, 1]
|
6839 | }, options);
|
6840 | this.onKeydown = this.onKeydown.bind(this);
|
6841 | this.onKeyup = this.onKeyup.bind(this);
|
6842 | }
|
6843 |
|
6844 | var __proto = MoveKeyInput.prototype;
|
6845 |
|
6846 | __proto.mapAxes = function (axes) {
|
6847 | this.axes = axes;
|
6848 | };
|
6849 |
|
6850 | __proto.connect = function (observer) {
|
6851 | this.dettachEvent();
|
6852 |
|
6853 | if (this.element.getAttribute("tabindex") !== "0") {
|
6854 | this.element.setAttribute("tabindex", "0");
|
6855 | }
|
6856 |
|
6857 | this.attachEvent(observer);
|
6858 | return this;
|
6859 | };
|
6860 |
|
6861 | __proto.disconnect = function () {
|
6862 | this.dettachEvent();
|
6863 | return this;
|
6864 | };
|
6865 | |
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 | __proto.destroy = function () {
|
6873 | this.disconnect();
|
6874 | this.element = null;
|
6875 | };
|
6876 |
|
6877 | __proto.onKeydown = function (e) {
|
6878 | if (!this._isEnabled) {
|
6879 | return;
|
6880 | }
|
6881 |
|
6882 | var isMoveKey = true;
|
6883 | var direction = DIRECTION_FORWARD;
|
6884 | var move = DIRECTION_HORIZONTAL$1;
|
6885 |
|
6886 | switch (e.keyCode) {
|
6887 | case KEY_LEFT_ARROW:
|
6888 | case KEY_A:
|
6889 | direction = DIRECTION_REVERSE;
|
6890 | break;
|
6891 |
|
6892 | case KEY_RIGHT_ARROW:
|
6893 | case KEY_D:
|
6894 | break;
|
6895 |
|
6896 | case KEY_DOWN_ARROW:
|
6897 | case KEY_S:
|
6898 | direction = DIRECTION_REVERSE;
|
6899 | move = DIRECTION_VERTICAL$1;
|
6900 | break;
|
6901 |
|
6902 | case KEY_UP_ARROW:
|
6903 | case KEY_W:
|
6904 | move = DIRECTION_VERTICAL$1;
|
6905 | break;
|
6906 |
|
6907 | default:
|
6908 | isMoveKey = false;
|
6909 | }
|
6910 |
|
6911 | if (move === DIRECTION_HORIZONTAL$1 && !this.axes[0] || move === DIRECTION_VERTICAL$1 && !this.axes[1]) {
|
6912 | isMoveKey = false;
|
6913 | }
|
6914 |
|
6915 | if (!isMoveKey) {
|
6916 | return;
|
6917 | }
|
6918 |
|
6919 | var offsets = move === DIRECTION_HORIZONTAL$1 ? [+this.options.scale[0] * direction, 0] : [0, +this.options.scale[1] * direction];
|
6920 |
|
6921 | if (!this._isHolded) {
|
6922 | this.observer.hold(this, event);
|
6923 | this._isHolded = true;
|
6924 | }
|
6925 |
|
6926 | clearTimeout(this._timer);
|
6927 | this.observer.change(this, event, toAxis(this.axes, offsets));
|
6928 | };
|
6929 |
|
6930 | __proto.onKeyup = function (e) {
|
6931 | var _this = this;
|
6932 |
|
6933 | if (!this._isHolded) {
|
6934 | return;
|
6935 | }
|
6936 |
|
6937 | clearTimeout(this._timer);
|
6938 | this._timer = setTimeout(function () {
|
6939 | _this.observer.release(_this, e, toAxis(_this.axes, [0, 0]));
|
6940 |
|
6941 | _this._isHolded = false;
|
6942 | }, DELAY);
|
6943 | };
|
6944 |
|
6945 | __proto.attachEvent = function (observer) {
|
6946 | this.observer = observer;
|
6947 | this.element.addEventListener("keydown", this.onKeydown, false);
|
6948 | this.element.addEventListener("keypress", this.onKeydown, false);
|
6949 | this.element.addEventListener("keyup", this.onKeyup, false);
|
6950 | this._isEnabled = true;
|
6951 | };
|
6952 |
|
6953 | __proto.dettachEvent = function () {
|
6954 | this.element.removeEventListener("keydown", this.onKeydown, false);
|
6955 | this.element.removeEventListener("keypress", this.onKeydown, false);
|
6956 | this.element.removeEventListener("keyup", this.onKeyup, false);
|
6957 | this._isEnabled = false;
|
6958 | this.observer = null;
|
6959 | };
|
6960 | |
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 | __proto.enable = function () {
|
6969 | this._isEnabled = true;
|
6970 | return this;
|
6971 | };
|
6972 | |
6973 |
|
6974 |
|
6975 |
|
6976 |
|
6977 |
|
6978 |
|
6979 |
|
6980 | __proto.disable = function () {
|
6981 | this._isEnabled = false;
|
6982 | return this;
|
6983 | };
|
6984 | |
6985 |
|
6986 |
|
6987 |
|
6988 |
|
6989 |
|
6990 |
|
6991 |
|
6992 | __proto.isEnable = function () {
|
6993 | return this._isEnabled;
|
6994 | };
|
6995 |
|
6996 | return MoveKeyInput;
|
6997 | }();
|
6998 |
|
6999 | |
7000 |
|
7001 |
|
7002 |
|
7003 |
|
7004 | var EPSILON = 0.000001;
|
7005 | var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
7006 | var degree = Math.PI / 180;
|
7007 | |
7008 |
|
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 | function toRadian(a) {
|
7014 | return a * degree;
|
7015 | }
|
7016 | if (!Math.hypot) Math.hypot = function () {
|
7017 | var y = 0,
|
7018 | i = arguments.length;
|
7019 |
|
7020 | while (i--) {
|
7021 | y += arguments[i] * arguments[i];
|
7022 | }
|
7023 |
|
7024 | return Math.sqrt(y);
|
7025 | };
|
7026 |
|
7027 | |
7028 |
|
7029 |
|
7030 |
|
7031 |
|
7032 | |
7033 |
|
7034 |
|
7035 |
|
7036 |
|
7037 |
|
7038 | function create() {
|
7039 | var out = new ARRAY_TYPE(9);
|
7040 |
|
7041 | if (ARRAY_TYPE != Float32Array) {
|
7042 | out[1] = 0;
|
7043 | out[2] = 0;
|
7044 | out[3] = 0;
|
7045 | out[5] = 0;
|
7046 | out[6] = 0;
|
7047 | out[7] = 0;
|
7048 | }
|
7049 |
|
7050 | out[0] = 1;
|
7051 | out[4] = 1;
|
7052 | out[8] = 1;
|
7053 | return out;
|
7054 | }
|
7055 | |
7056 |
|
7057 |
|
7058 |
|
7059 |
|
7060 |
|
7061 |
|
7062 |
|
7063 | function fromMat4(out, a) {
|
7064 | out[0] = a[0];
|
7065 | out[1] = a[1];
|
7066 | out[2] = a[2];
|
7067 | out[3] = a[4];
|
7068 | out[4] = a[5];
|
7069 | out[5] = a[6];
|
7070 | out[6] = a[8];
|
7071 | out[7] = a[9];
|
7072 | out[8] = a[10];
|
7073 | return out;
|
7074 | }
|
7075 | |
7076 |
|
7077 |
|
7078 |
|
7079 |
|
7080 |
|
7081 |
|
7082 |
|
7083 | function invert(out, a) {
|
7084 | var a00 = a[0],
|
7085 | a01 = a[1],
|
7086 | a02 = a[2];
|
7087 | var a10 = a[3],
|
7088 | a11 = a[4],
|
7089 | a12 = a[5];
|
7090 | var a20 = a[6],
|
7091 | a21 = a[7],
|
7092 | a22 = a[8];
|
7093 | var b01 = a22 * a11 - a12 * a21;
|
7094 | var b11 = -a22 * a10 + a12 * a20;
|
7095 | var b21 = a21 * a10 - a11 * a20;
|
7096 |
|
7097 | var det = a00 * b01 + a01 * b11 + a02 * b21;
|
7098 |
|
7099 | if (!det) {
|
7100 | return null;
|
7101 | }
|
7102 |
|
7103 | det = 1.0 / det;
|
7104 | out[0] = b01 * det;
|
7105 | out[1] = (-a22 * a01 + a02 * a21) * det;
|
7106 | out[2] = (a12 * a01 - a02 * a11) * det;
|
7107 | out[3] = b11 * det;
|
7108 | out[4] = (a22 * a00 - a02 * a20) * det;
|
7109 | out[5] = (-a12 * a00 + a02 * a10) * det;
|
7110 | out[6] = b21 * det;
|
7111 | out[7] = (-a21 * a00 + a01 * a20) * det;
|
7112 | out[8] = (a11 * a00 - a01 * a10) * det;
|
7113 | return out;
|
7114 | }
|
7115 |
|
7116 | |
7117 |
|
7118 |
|
7119 |
|
7120 |
|
7121 | |
7122 |
|
7123 |
|
7124 |
|
7125 |
|
7126 |
|
7127 | function create$1() {
|
7128 | var out = new ARRAY_TYPE(16);
|
7129 |
|
7130 | if (ARRAY_TYPE != Float32Array) {
|
7131 | out[1] = 0;
|
7132 | out[2] = 0;
|
7133 | out[3] = 0;
|
7134 | out[4] = 0;
|
7135 | out[6] = 0;
|
7136 | out[7] = 0;
|
7137 | out[8] = 0;
|
7138 | out[9] = 0;
|
7139 | out[11] = 0;
|
7140 | out[12] = 0;
|
7141 | out[13] = 0;
|
7142 | out[14] = 0;
|
7143 | }
|
7144 |
|
7145 | out[0] = 1;
|
7146 | out[5] = 1;
|
7147 | out[10] = 1;
|
7148 | out[15] = 1;
|
7149 | return out;
|
7150 | }
|
7151 | |
7152 |
|
7153 |
|
7154 |
|
7155 |
|
7156 |
|
7157 |
|
7158 | function identity(out) {
|
7159 | out[0] = 1;
|
7160 | out[1] = 0;
|
7161 | out[2] = 0;
|
7162 | out[3] = 0;
|
7163 | out[4] = 0;
|
7164 | out[5] = 1;
|
7165 | out[6] = 0;
|
7166 | out[7] = 0;
|
7167 | out[8] = 0;
|
7168 | out[9] = 0;
|
7169 | out[10] = 1;
|
7170 | out[11] = 0;
|
7171 | out[12] = 0;
|
7172 | out[13] = 0;
|
7173 | out[14] = 0;
|
7174 | out[15] = 1;
|
7175 | return out;
|
7176 | }
|
7177 | |
7178 |
|
7179 |
|
7180 |
|
7181 |
|
7182 |
|
7183 |
|
7184 |
|
7185 |
|
7186 | function rotateX(out, a, rad) {
|
7187 | var s = Math.sin(rad);
|
7188 | var c = Math.cos(rad);
|
7189 | var a10 = a[4];
|
7190 | var a11 = a[5];
|
7191 | var a12 = a[6];
|
7192 | var a13 = a[7];
|
7193 | var a20 = a[8];
|
7194 | var a21 = a[9];
|
7195 | var a22 = a[10];
|
7196 | var a23 = a[11];
|
7197 |
|
7198 | if (a !== out) {
|
7199 |
|
7200 | out[0] = a[0];
|
7201 | out[1] = a[1];
|
7202 | out[2] = a[2];
|
7203 | out[3] = a[3];
|
7204 | out[12] = a[12];
|
7205 | out[13] = a[13];
|
7206 | out[14] = a[14];
|
7207 | out[15] = a[15];
|
7208 | }
|
7209 |
|
7210 |
|
7211 | out[4] = a10 * c + a20 * s;
|
7212 | out[5] = a11 * c + a21 * s;
|
7213 | out[6] = a12 * c + a22 * s;
|
7214 | out[7] = a13 * c + a23 * s;
|
7215 | out[8] = a20 * c - a10 * s;
|
7216 | out[9] = a21 * c - a11 * s;
|
7217 | out[10] = a22 * c - a12 * s;
|
7218 | out[11] = a23 * c - a13 * s;
|
7219 | return out;
|
7220 | }
|
7221 | |
7222 |
|
7223 |
|
7224 |
|
7225 |
|
7226 |
|
7227 |
|
7228 |
|
7229 |
|
7230 | function rotateY(out, a, rad) {
|
7231 | var s = Math.sin(rad);
|
7232 | var c = Math.cos(rad);
|
7233 | var a00 = a[0];
|
7234 | var a01 = a[1];
|
7235 | var a02 = a[2];
|
7236 | var a03 = a[3];
|
7237 | var a20 = a[8];
|
7238 | var a21 = a[9];
|
7239 | var a22 = a[10];
|
7240 | var a23 = a[11];
|
7241 |
|
7242 | if (a !== out) {
|
7243 |
|
7244 | out[4] = a[4];
|
7245 | out[5] = a[5];
|
7246 | out[6] = a[6];
|
7247 | out[7] = a[7];
|
7248 | out[12] = a[12];
|
7249 | out[13] = a[13];
|
7250 | out[14] = a[14];
|
7251 | out[15] = a[15];
|
7252 | }
|
7253 |
|
7254 |
|
7255 | out[0] = a00 * c - a20 * s;
|
7256 | out[1] = a01 * c - a21 * s;
|
7257 | out[2] = a02 * c - a22 * s;
|
7258 | out[3] = a03 * c - a23 * s;
|
7259 | out[8] = a00 * s + a20 * c;
|
7260 | out[9] = a01 * s + a21 * c;
|
7261 | out[10] = a02 * s + a22 * c;
|
7262 | out[11] = a03 * s + a23 * c;
|
7263 | return out;
|
7264 | }
|
7265 | |
7266 |
|
7267 |
|
7268 |
|
7269 |
|
7270 |
|
7271 |
|
7272 |
|
7273 |
|
7274 | function fromQuat(out, q) {
|
7275 | var x = q[0],
|
7276 | y = q[1],
|
7277 | z = q[2],
|
7278 | w = q[3];
|
7279 | var x2 = x + x;
|
7280 | var y2 = y + y;
|
7281 | var z2 = z + z;
|
7282 | var xx = x * x2;
|
7283 | var yx = y * x2;
|
7284 | var yy = y * y2;
|
7285 | var zx = z * x2;
|
7286 | var zy = z * y2;
|
7287 | var zz = z * z2;
|
7288 | var wx = w * x2;
|
7289 | var wy = w * y2;
|
7290 | var wz = w * z2;
|
7291 | out[0] = 1 - yy - zz;
|
7292 | out[1] = yx + wz;
|
7293 | out[2] = zx - wy;
|
7294 | out[3] = 0;
|
7295 | out[4] = yx - wz;
|
7296 | out[5] = 1 - xx - zz;
|
7297 | out[6] = zy + wx;
|
7298 | out[7] = 0;
|
7299 | out[8] = zx + wy;
|
7300 | out[9] = zy - wx;
|
7301 | out[10] = 1 - xx - yy;
|
7302 | out[11] = 0;
|
7303 | out[12] = 0;
|
7304 | out[13] = 0;
|
7305 | out[14] = 0;
|
7306 | out[15] = 1;
|
7307 | return out;
|
7308 | }
|
7309 | |
7310 |
|
7311 |
|
7312 |
|
7313 |
|
7314 |
|
7315 |
|
7316 |
|
7317 |
|
7318 |
|
7319 |
|
7320 |
|
7321 | function perspective(out, fovy, aspect, near, far) {
|
7322 | var f = 1.0 / Math.tan(fovy / 2),
|
7323 | nf;
|
7324 | out[0] = f / aspect;
|
7325 | out[1] = 0;
|
7326 | out[2] = 0;
|
7327 | out[3] = 0;
|
7328 | out[4] = 0;
|
7329 | out[5] = f;
|
7330 | out[6] = 0;
|
7331 | out[7] = 0;
|
7332 | out[8] = 0;
|
7333 | out[9] = 0;
|
7334 | out[11] = -1;
|
7335 | out[12] = 0;
|
7336 | out[13] = 0;
|
7337 | out[15] = 0;
|
7338 |
|
7339 | if (far != null && far !== Infinity) {
|
7340 | nf = 1 / (near - far);
|
7341 | out[10] = (far + near) * nf;
|
7342 | out[14] = 2 * far * near * nf;
|
7343 | } else {
|
7344 | out[10] = -1;
|
7345 | out[14] = -2 * near;
|
7346 | }
|
7347 |
|
7348 | return out;
|
7349 | }
|
7350 |
|
7351 | |
7352 |
|
7353 |
|
7354 |
|
7355 |
|
7356 | |
7357 |
|
7358 |
|
7359 |
|
7360 |
|
7361 |
|
7362 | function create$2() {
|
7363 | var out = new ARRAY_TYPE(3);
|
7364 |
|
7365 | if (ARRAY_TYPE != Float32Array) {
|
7366 | out[0] = 0;
|
7367 | out[1] = 0;
|
7368 | out[2] = 0;
|
7369 | }
|
7370 |
|
7371 | return out;
|
7372 | }
|
7373 | |
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 | function length(a) {
|
7381 | var x = a[0];
|
7382 | var y = a[1];
|
7383 | var z = a[2];
|
7384 | return Math.hypot(x, y, z);
|
7385 | }
|
7386 | |
7387 |
|
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 |
|
7394 |
|
7395 | function fromValues(x, y, z) {
|
7396 | var out = new ARRAY_TYPE(3);
|
7397 | out[0] = x;
|
7398 | out[1] = y;
|
7399 | out[2] = z;
|
7400 | return out;
|
7401 | }
|
7402 | |
7403 |
|
7404 |
|
7405 |
|
7406 |
|
7407 |
|
7408 |
|
7409 |
|
7410 | function copy(out, a) {
|
7411 | out[0] = a[0];
|
7412 | out[1] = a[1];
|
7413 | out[2] = a[2];
|
7414 | return out;
|
7415 | }
|
7416 | |
7417 |
|
7418 |
|
7419 |
|
7420 |
|
7421 |
|
7422 |
|
7423 |
|
7424 |
|
7425 |
|
7426 | function set(out, x, y, z) {
|
7427 | out[0] = x;
|
7428 | out[1] = y;
|
7429 | out[2] = z;
|
7430 | return out;
|
7431 | }
|
7432 | |
7433 |
|
7434 |
|
7435 |
|
7436 |
|
7437 |
|
7438 |
|
7439 |
|
7440 |
|
7441 | function subtract(out, a, b) {
|
7442 | out[0] = a[0] - b[0];
|
7443 | out[1] = a[1] - b[1];
|
7444 | out[2] = a[2] - b[2];
|
7445 | return out;
|
7446 | }
|
7447 | |
7448 |
|
7449 |
|
7450 |
|
7451 |
|
7452 |
|
7453 |
|
7454 |
|
7455 |
|
7456 | function scale(out, a, b) {
|
7457 | out[0] = a[0] * b;
|
7458 | out[1] = a[1] * b;
|
7459 | out[2] = a[2] * b;
|
7460 | return out;
|
7461 | }
|
7462 | |
7463 |
|
7464 |
|
7465 |
|
7466 |
|
7467 |
|
7468 |
|
7469 |
|
7470 | function normalize(out, a) {
|
7471 | var x = a[0];
|
7472 | var y = a[1];
|
7473 | var z = a[2];
|
7474 | var len = x * x + y * y + z * z;
|
7475 |
|
7476 | if (len > 0) {
|
7477 |
|
7478 | len = 1 / Math.sqrt(len);
|
7479 | }
|
7480 |
|
7481 | out[0] = a[0] * len;
|
7482 | out[1] = a[1] * len;
|
7483 | out[2] = a[2] * len;
|
7484 | return out;
|
7485 | }
|
7486 | |
7487 |
|
7488 |
|
7489 |
|
7490 |
|
7491 |
|
7492 |
|
7493 |
|
7494 | function dot(a, b) {
|
7495 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
7496 | }
|
7497 | |
7498 |
|
7499 |
|
7500 |
|
7501 |
|
7502 |
|
7503 |
|
7504 |
|
7505 |
|
7506 | function cross(out, a, b) {
|
7507 | var ax = a[0],
|
7508 | ay = a[1],
|
7509 | az = a[2];
|
7510 | var bx = b[0],
|
7511 | by = b[1],
|
7512 | bz = b[2];
|
7513 | out[0] = ay * bz - az * by;
|
7514 | out[1] = az * bx - ax * bz;
|
7515 | out[2] = ax * by - ay * bx;
|
7516 | return out;
|
7517 | }
|
7518 | |
7519 |
|
7520 |
|
7521 |
|
7522 |
|
7523 |
|
7524 |
|
7525 |
|
7526 |
|
7527 | function transformMat3(out, a, m) {
|
7528 | var x = a[0],
|
7529 | y = a[1],
|
7530 | z = a[2];
|
7531 | out[0] = x * m[0] + y * m[3] + z * m[6];
|
7532 | out[1] = x * m[1] + y * m[4] + z * m[7];
|
7533 | out[2] = x * m[2] + y * m[5] + z * m[8];
|
7534 | return out;
|
7535 | }
|
7536 | |
7537 |
|
7538 |
|
7539 |
|
7540 |
|
7541 |
|
7542 |
|
7543 |
|
7544 |
|
7545 |
|
7546 | function transformQuat(out, a, q) {
|
7547 |
|
7548 | var qx = q[0],
|
7549 | qy = q[1],
|
7550 | qz = q[2],
|
7551 | qw = q[3];
|
7552 | var x = a[0],
|
7553 | y = a[1],
|
7554 | z = a[2];
|
7555 |
|
7556 |
|
7557 | var uvx = qy * z - qz * y,
|
7558 | uvy = qz * x - qx * z,
|
7559 | uvz = qx * y - qy * x;
|
7560 |
|
7561 | var uuvx = qy * uvz - qz * uvy,
|
7562 | uuvy = qz * uvx - qx * uvz,
|
7563 | uuvz = qx * uvy - qy * uvx;
|
7564 |
|
7565 | var w2 = qw * 2;
|
7566 | uvx *= w2;
|
7567 | uvy *= w2;
|
7568 | uvz *= w2;
|
7569 |
|
7570 | uuvx *= 2;
|
7571 | uuvy *= 2;
|
7572 | uuvz *= 2;
|
7573 |
|
7574 | out[0] = x + uvx + uuvx;
|
7575 | out[1] = y + uvy + uuvy;
|
7576 | out[2] = z + uvz + uuvz;
|
7577 | return out;
|
7578 | }
|
7579 | |
7580 |
|
7581 |
|
7582 |
|
7583 |
|
7584 | var len = length;
|
7585 | |
7586 |
|
7587 |
|
7588 |
|
7589 |
|
7590 |
|
7591 |
|
7592 |
|
7593 |
|
7594 |
|
7595 |
|
7596 |
|
7597 |
|
7598 | var forEach = function () {
|
7599 | var vec = create$2();
|
7600 | return function (a, stride, offset, count, fn, arg) {
|
7601 | var i, l;
|
7602 |
|
7603 | if (!stride) {
|
7604 | stride = 3;
|
7605 | }
|
7606 |
|
7607 | if (!offset) {
|
7608 | offset = 0;
|
7609 | }
|
7610 |
|
7611 | if (count) {
|
7612 | l = Math.min(count * stride + offset, a.length);
|
7613 | } else {
|
7614 | l = a.length;
|
7615 | }
|
7616 |
|
7617 | for (i = offset; i < l; i += stride) {
|
7618 | vec[0] = a[i];
|
7619 | vec[1] = a[i + 1];
|
7620 | vec[2] = a[i + 2];
|
7621 | fn(vec, vec, arg);
|
7622 | a[i] = vec[0];
|
7623 | a[i + 1] = vec[1];
|
7624 | a[i + 2] = vec[2];
|
7625 | }
|
7626 |
|
7627 | return a;
|
7628 | };
|
7629 | }();
|
7630 |
|
7631 | |
7632 |
|
7633 |
|
7634 |
|
7635 |
|
7636 | |
7637 |
|
7638 |
|
7639 |
|
7640 |
|
7641 |
|
7642 | function create$3() {
|
7643 | var out = new ARRAY_TYPE(4);
|
7644 |
|
7645 | if (ARRAY_TYPE != Float32Array) {
|
7646 | out[0] = 0;
|
7647 | out[1] = 0;
|
7648 | out[2] = 0;
|
7649 | out[3] = 0;
|
7650 | }
|
7651 |
|
7652 | return out;
|
7653 | }
|
7654 | |
7655 |
|
7656 |
|
7657 |
|
7658 |
|
7659 |
|
7660 |
|
7661 | function clone(a) {
|
7662 | var out = new ARRAY_TYPE(4);
|
7663 | out[0] = a[0];
|
7664 | out[1] = a[1];
|
7665 | out[2] = a[2];
|
7666 | out[3] = a[3];
|
7667 | return out;
|
7668 | }
|
7669 | |
7670 |
|
7671 |
|
7672 |
|
7673 |
|
7674 |
|
7675 |
|
7676 |
|
7677 |
|
7678 |
|
7679 | function fromValues$1(x, y, z, w) {
|
7680 | var out = new ARRAY_TYPE(4);
|
7681 | out[0] = x;
|
7682 | out[1] = y;
|
7683 | out[2] = z;
|
7684 | out[3] = w;
|
7685 | return out;
|
7686 | }
|
7687 | |
7688 |
|
7689 |
|
7690 |
|
7691 |
|
7692 |
|
7693 |
|
7694 |
|
7695 | function copy$1(out, a) {
|
7696 | out[0] = a[0];
|
7697 | out[1] = a[1];
|
7698 | out[2] = a[2];
|
7699 | out[3] = a[3];
|
7700 | return out;
|
7701 | }
|
7702 | |
7703 |
|
7704 |
|
7705 |
|
7706 |
|
7707 |
|
7708 |
|
7709 |
|
7710 | function normalize$1(out, a) {
|
7711 | var x = a[0];
|
7712 | var y = a[1];
|
7713 | var z = a[2];
|
7714 | var w = a[3];
|
7715 | var len = x * x + y * y + z * z + w * w;
|
7716 |
|
7717 | if (len > 0) {
|
7718 | len = 1 / Math.sqrt(len);
|
7719 | }
|
7720 |
|
7721 | out[0] = x * len;
|
7722 | out[1] = y * len;
|
7723 | out[2] = z * len;
|
7724 | out[3] = w * len;
|
7725 | return out;
|
7726 | }
|
7727 | |
7728 |
|
7729 |
|
7730 |
|
7731 |
|
7732 |
|
7733 |
|
7734 |
|
7735 | function exactEquals(a, b) {
|
7736 | return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
7737 | }
|
7738 | |
7739 |
|
7740 |
|
7741 |
|
7742 |
|
7743 |
|
7744 |
|
7745 |
|
7746 | function equals(a, b) {
|
7747 | var a0 = a[0],
|
7748 | a1 = a[1],
|
7749 | a2 = a[2],
|
7750 | a3 = a[3];
|
7751 | var b0 = b[0],
|
7752 | b1 = b[1],
|
7753 | b2 = b[2],
|
7754 | b3 = b[3];
|
7755 | return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));
|
7756 | }
|
7757 | |
7758 |
|
7759 |
|
7760 |
|
7761 |
|
7762 |
|
7763 |
|
7764 |
|
7765 |
|
7766 |
|
7767 |
|
7768 |
|
7769 |
|
7770 | var forEach$1 = function () {
|
7771 | var vec = create$3();
|
7772 | return function (a, stride, offset, count, fn, arg) {
|
7773 | var i, l;
|
7774 |
|
7775 | if (!stride) {
|
7776 | stride = 4;
|
7777 | }
|
7778 |
|
7779 | if (!offset) {
|
7780 | offset = 0;
|
7781 | }
|
7782 |
|
7783 | if (count) {
|
7784 | l = Math.min(count * stride + offset, a.length);
|
7785 | } else {
|
7786 | l = a.length;
|
7787 | }
|
7788 |
|
7789 | for (i = offset; i < l; i += stride) {
|
7790 | vec[0] = a[i];
|
7791 | vec[1] = a[i + 1];
|
7792 | vec[2] = a[i + 2];
|
7793 | vec[3] = a[i + 3];
|
7794 | fn(vec, vec, arg);
|
7795 | a[i] = vec[0];
|
7796 | a[i + 1] = vec[1];
|
7797 | a[i + 2] = vec[2];
|
7798 | a[i + 3] = vec[3];
|
7799 | }
|
7800 |
|
7801 | return a;
|
7802 | };
|
7803 | }();
|
7804 |
|
7805 | |
7806 |
|
7807 |
|
7808 |
|
7809 |
|
7810 | |
7811 |
|
7812 |
|
7813 |
|
7814 |
|
7815 |
|
7816 | function create$4() {
|
7817 | var out = new ARRAY_TYPE(4);
|
7818 |
|
7819 | if (ARRAY_TYPE != Float32Array) {
|
7820 | out[0] = 0;
|
7821 | out[1] = 0;
|
7822 | out[2] = 0;
|
7823 | }
|
7824 |
|
7825 | out[3] = 1;
|
7826 | return out;
|
7827 | }
|
7828 | |
7829 |
|
7830 |
|
7831 |
|
7832 |
|
7833 |
|
7834 |
|
7835 |
|
7836 |
|
7837 |
|
7838 | function setAxisAngle(out, axis, rad) {
|
7839 | rad = rad * 0.5;
|
7840 | var s = Math.sin(rad);
|
7841 | out[0] = s * axis[0];
|
7842 | out[1] = s * axis[1];
|
7843 | out[2] = s * axis[2];
|
7844 | out[3] = Math.cos(rad);
|
7845 | return out;
|
7846 | }
|
7847 | |
7848 |
|
7849 |
|
7850 |
|
7851 |
|
7852 |
|
7853 |
|
7854 |
|
7855 |
|
7856 | function multiply(out, a, b) {
|
7857 | var ax = a[0],
|
7858 | ay = a[1],
|
7859 | az = a[2],
|
7860 | aw = a[3];
|
7861 | var bx = b[0],
|
7862 | by = b[1],
|
7863 | bz = b[2],
|
7864 | bw = b[3];
|
7865 | out[0] = ax * bw + aw * bx + ay * bz - az * by;
|
7866 | out[1] = ay * bw + aw * by + az * bx - ax * bz;
|
7867 | out[2] = az * bw + aw * bz + ax * by - ay * bx;
|
7868 | out[3] = aw * bw - ax * bx - ay * by - az * bz;
|
7869 | return out;
|
7870 | }
|
7871 | |
7872 |
|
7873 |
|
7874 |
|
7875 |
|
7876 |
|
7877 |
|
7878 |
|
7879 |
|
7880 |
|
7881 | function slerp(out, a, b, t) {
|
7882 |
|
7883 |
|
7884 | var ax = a[0],
|
7885 | ay = a[1],
|
7886 | az = a[2],
|
7887 | aw = a[3];
|
7888 | var bx = b[0],
|
7889 | by = b[1],
|
7890 | bz = b[2],
|
7891 | bw = b[3];
|
7892 | var omega, cosom, sinom, scale0, scale1;
|
7893 |
|
7894 | cosom = ax * bx + ay * by + az * bz + aw * bw;
|
7895 |
|
7896 | if (cosom < 0.0) {
|
7897 | cosom = -cosom;
|
7898 | bx = -bx;
|
7899 | by = -by;
|
7900 | bz = -bz;
|
7901 | bw = -bw;
|
7902 | }
|
7903 |
|
7904 |
|
7905 | if (1.0 - cosom > EPSILON) {
|
7906 |
|
7907 | omega = Math.acos(cosom);
|
7908 | sinom = Math.sin(omega);
|
7909 | scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
7910 | scale1 = Math.sin(t * omega) / sinom;
|
7911 | } else {
|
7912 |
|
7913 |
|
7914 | scale0 = 1.0 - t;
|
7915 | scale1 = t;
|
7916 | }
|
7917 |
|
7918 |
|
7919 | out[0] = scale0 * ax + scale1 * bx;
|
7920 | out[1] = scale0 * ay + scale1 * by;
|
7921 | out[2] = scale0 * az + scale1 * bz;
|
7922 | out[3] = scale0 * aw + scale1 * bw;
|
7923 | return out;
|
7924 | }
|
7925 | |
7926 |
|
7927 |
|
7928 |
|
7929 |
|
7930 |
|
7931 |
|
7932 |
|
7933 |
|
7934 | function conjugate(out, a) {
|
7935 | out[0] = -a[0];
|
7936 | out[1] = -a[1];
|
7937 | out[2] = -a[2];
|
7938 | out[3] = a[3];
|
7939 | return out;
|
7940 | }
|
7941 | |
7942 |
|
7943 |
|
7944 |
|
7945 |
|
7946 |
|
7947 |
|
7948 |
|
7949 |
|
7950 |
|
7951 |
|
7952 |
|
7953 | function fromMat3(out, m) {
|
7954 |
|
7955 |
|
7956 | var fTrace = m[0] + m[4] + m[8];
|
7957 | var fRoot;
|
7958 |
|
7959 | if (fTrace > 0.0) {
|
7960 |
|
7961 | fRoot = Math.sqrt(fTrace + 1.0);
|
7962 |
|
7963 | out[3] = 0.5 * fRoot;
|
7964 | fRoot = 0.5 / fRoot;
|
7965 |
|
7966 | out[0] = (m[5] - m[7]) * fRoot;
|
7967 | out[1] = (m[6] - m[2]) * fRoot;
|
7968 | out[2] = (m[1] - m[3]) * fRoot;
|
7969 | } else {
|
7970 |
|
7971 | var i = 0;
|
7972 | if (m[4] > m[0]) i = 1;
|
7973 | if (m[8] > m[i * 3 + i]) i = 2;
|
7974 | var j = (i + 1) % 3;
|
7975 | var k = (i + 2) % 3;
|
7976 | fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
|
7977 | out[i] = 0.5 * fRoot;
|
7978 | fRoot = 0.5 / fRoot;
|
7979 | out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
|
7980 | out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
|
7981 | out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
|
7982 | }
|
7983 |
|
7984 | return out;
|
7985 | }
|
7986 | |
7987 |
|
7988 |
|
7989 |
|
7990 |
|
7991 |
|
7992 |
|
7993 |
|
7994 | var clone$1 = clone;
|
7995 | |
7996 |
|
7997 |
|
7998 |
|
7999 |
|
8000 |
|
8001 |
|
8002 |
|
8003 |
|
8004 |
|
8005 |
|
8006 | var fromValues$2 = fromValues$1;
|
8007 | |
8008 |
|
8009 |
|
8010 |
|
8011 |
|
8012 |
|
8013 |
|
8014 |
|
8015 |
|
8016 | var copy$2 = copy$1;
|
8017 | |
8018 |
|
8019 |
|
8020 |
|
8021 |
|
8022 |
|
8023 |
|
8024 |
|
8025 |
|
8026 | var normalize$2 = normalize$1;
|
8027 | |
8028 |
|
8029 |
|
8030 |
|
8031 |
|
8032 |
|
8033 |
|
8034 |
|
8035 | var exactEquals$1 = exactEquals;
|
8036 | |
8037 |
|
8038 |
|
8039 |
|
8040 |
|
8041 |
|
8042 |
|
8043 |
|
8044 | var equals$1 = equals;
|
8045 | |
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 |
|
8051 |
|
8052 |
|
8053 |
|
8054 |
|
8055 |
|
8056 |
|
8057 | var rotationTo = function () {
|
8058 | var tmpvec3 = create$2();
|
8059 | var xUnitVec3 = fromValues(1, 0, 0);
|
8060 | var yUnitVec3 = fromValues(0, 1, 0);
|
8061 | return function (out, a, b) {
|
8062 | var dot$1 = dot(a, b);
|
8063 |
|
8064 | if (dot$1 < -0.999999) {
|
8065 | cross(tmpvec3, xUnitVec3, a);
|
8066 | if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
|
8067 | normalize(tmpvec3, tmpvec3);
|
8068 | setAxisAngle(out, tmpvec3, Math.PI);
|
8069 | return out;
|
8070 | } else if (dot$1 > 0.999999) {
|
8071 | out[0] = 0;
|
8072 | out[1] = 0;
|
8073 | out[2] = 0;
|
8074 | out[3] = 1;
|
8075 | return out;
|
8076 | } else {
|
8077 | cross(tmpvec3, a, b);
|
8078 | out[0] = tmpvec3[0];
|
8079 | out[1] = tmpvec3[1];
|
8080 | out[2] = tmpvec3[2];
|
8081 | out[3] = 1 + dot$1;
|
8082 | return normalize$2(out, out);
|
8083 | }
|
8084 | };
|
8085 | }();
|
8086 | |
8087 |
|
8088 |
|
8089 |
|
8090 |
|
8091 |
|
8092 |
|
8093 |
|
8094 |
|
8095 |
|
8096 |
|
8097 |
|
8098 | var sqlerp = function () {
|
8099 | var temp1 = create$4();
|
8100 | var temp2 = create$4();
|
8101 | return function (out, a, b, c, d, t) {
|
8102 | slerp(temp1, a, d, t);
|
8103 | slerp(temp2, b, c, t);
|
8104 | slerp(out, temp1, temp2, 2 * t * (1 - t));
|
8105 | return out;
|
8106 | };
|
8107 | }();
|
8108 | |
8109 |
|
8110 |
|
8111 |
|
8112 |
|
8113 |
|
8114 |
|
8115 |
|
8116 |
|
8117 |
|
8118 |
|
8119 | var setAxes = function () {
|
8120 | var matr = create();
|
8121 | return function (out, view, right, up) {
|
8122 | matr[0] = right[0];
|
8123 | matr[3] = right[1];
|
8124 | matr[6] = right[2];
|
8125 | matr[1] = up[0];
|
8126 | matr[4] = up[1];
|
8127 | matr[7] = up[2];
|
8128 | matr[2] = -view[0];
|
8129 | matr[5] = -view[1];
|
8130 | matr[8] = -view[2];
|
8131 | return normalize$2(out, fromMat3(out, matr));
|
8132 | };
|
8133 | }();
|
8134 |
|
8135 | |
8136 |
|
8137 |
|
8138 |
|
8139 |
|
8140 | |
8141 |
|
8142 |
|
8143 |
|
8144 |
|
8145 |
|
8146 | function create$5() {
|
8147 | var out = new ARRAY_TYPE(2);
|
8148 |
|
8149 | if (ARRAY_TYPE != Float32Array) {
|
8150 | out[0] = 0;
|
8151 | out[1] = 0;
|
8152 | }
|
8153 |
|
8154 | return out;
|
8155 | }
|
8156 | |
8157 |
|
8158 |
|
8159 |
|
8160 |
|
8161 |
|
8162 |
|
8163 |
|
8164 | function fromValues$3(x, y) {
|
8165 | var out = new ARRAY_TYPE(2);
|
8166 | out[0] = x;
|
8167 | out[1] = y;
|
8168 | return out;
|
8169 | }
|
8170 | |
8171 |
|
8172 |
|
8173 |
|
8174 |
|
8175 |
|
8176 |
|
8177 |
|
8178 | function copy$3(out, a) {
|
8179 | out[0] = a[0];
|
8180 | out[1] = a[1];
|
8181 | return out;
|
8182 | }
|
8183 | |
8184 |
|
8185 |
|
8186 |
|
8187 |
|
8188 |
|
8189 |
|
8190 |
|
8191 | function normalize$3(out, a) {
|
8192 | var x = a[0],
|
8193 | y = a[1];
|
8194 | var len = x * x + y * y;
|
8195 |
|
8196 | if (len > 0) {
|
8197 |
|
8198 | len = 1 / Math.sqrt(len);
|
8199 | }
|
8200 |
|
8201 | out[0] = a[0] * len;
|
8202 | out[1] = a[1] * len;
|
8203 | return out;
|
8204 | }
|
8205 | |
8206 |
|
8207 |
|
8208 |
|
8209 |
|
8210 |
|
8211 |
|
8212 |
|
8213 | function dot$1(a, b) {
|
8214 | return a[0] * b[0] + a[1] * b[1];
|
8215 | }
|
8216 | |
8217 |
|
8218 |
|
8219 |
|
8220 |
|
8221 |
|
8222 |
|
8223 |
|
8224 |
|
8225 |
|
8226 |
|
8227 |
|
8228 |
|
8229 | var forEach$2 = function () {
|
8230 | var vec = create$5();
|
8231 | return function (a, stride, offset, count, fn, arg) {
|
8232 | var i, l;
|
8233 |
|
8234 | if (!stride) {
|
8235 | stride = 2;
|
8236 | }
|
8237 |
|
8238 | if (!offset) {
|
8239 | offset = 0;
|
8240 | }
|
8241 |
|
8242 | if (count) {
|
8243 | l = Math.min(count * stride + offset, a.length);
|
8244 | } else {
|
8245 | l = a.length;
|
8246 | }
|
8247 |
|
8248 | for (i = offset; i < l; i += stride) {
|
8249 | vec[0] = a[i];
|
8250 | vec[1] = a[i + 1];
|
8251 | fn(vec, vec, arg);
|
8252 | a[i] = vec[0];
|
8253 | a[i + 1] = vec[1];
|
8254 | }
|
8255 |
|
8256 | return a;
|
8257 | };
|
8258 | }();
|
8259 |
|
8260 | |
8261 |
|
8262 |
|
8263 |
|
8264 |
|
8265 |
|
8266 |
|
8267 | var quatToVec3 = function (quaternion) {
|
8268 | var baseV = fromValues(0, 0, 1);
|
8269 | transformQuat(baseV, baseV, quaternion);
|
8270 | return baseV;
|
8271 | };
|
8272 |
|
8273 | var toDegree = function (a) {
|
8274 | return a * 180 / Math.PI;
|
8275 | };
|
8276 |
|
8277 | var util = {};
|
8278 |
|
8279 | util.isPowerOfTwo = function (n) {
|
8280 | return n && (n & n - 1) === 0;
|
8281 | };
|
8282 |
|
8283 | util.extractPitchFromQuat = function (quaternion) {
|
8284 | var baseV = quatToVec3(quaternion);
|
8285 | return -1 * Math.atan2(baseV[1], Math.sqrt(Math.pow(baseV[0], 2) + Math.pow(baseV[2], 2)));
|
8286 | };
|
8287 |
|
8288 | util.hypot = Math.hypot || function (x, y) {
|
8289 | return Math.sqrt(x * x + y * y);
|
8290 | };
|
8291 |
|
8292 |
|
8293 |
|
8294 |
|
8295 | var ROTATE_CONSTANT = {
|
8296 | PITCH_DELTA: 1,
|
8297 | YAW_DELTA_BY_ROLL: 2,
|
8298 | YAW_DELTA_BY_YAW: 3
|
8299 | };
|
8300 | ROTATE_CONSTANT[ROTATE_CONSTANT.PITCH_DELTA] = {
|
8301 | targetAxis: [0, 1, 0],
|
8302 | meshPoint: [0, 0, 1]
|
8303 | };
|
8304 | ROTATE_CONSTANT[ROTATE_CONSTANT.YAW_DELTA_BY_ROLL] = {
|
8305 | targetAxis: [0, 1, 0],
|
8306 | meshPoint: [1, 0, 0]
|
8307 | };
|
8308 | ROTATE_CONSTANT[ROTATE_CONSTANT.YAW_DELTA_BY_YAW] = {
|
8309 | targetAxis: [1, 0, 0],
|
8310 | meshPoint: [0, 0, 1]
|
8311 | };
|
8312 |
|
8313 | var getRotationDelta = function (prevQ, curQ, rotateKind) {
|
8314 | var targetAxis = fromValues(ROTATE_CONSTANT[rotateKind].targetAxis[0], ROTATE_CONSTANT[rotateKind].targetAxis[1], ROTATE_CONSTANT[rotateKind].targetAxis[2]);
|
8315 | var meshPoint = ROTATE_CONSTANT[rotateKind].meshPoint;
|
8316 | var prevQuaternion = clone$1(prevQ);
|
8317 | var curQuaternion = clone$1(curQ);
|
8318 | normalize$2(prevQuaternion, prevQuaternion);
|
8319 | normalize$2(curQuaternion, curQuaternion);
|
8320 | var prevPoint = fromValues(0, 0, 1);
|
8321 | var curPoint = fromValues(0, 0, 1);
|
8322 | transformQuat(prevPoint, prevPoint, prevQuaternion);
|
8323 | transformQuat(curPoint, curPoint, curQuaternion);
|
8324 | transformQuat(targetAxis, targetAxis, curQuaternion);
|
8325 | var rotateDistance = dot(targetAxis, cross(create$2(), prevPoint, curPoint));
|
8326 | var rotateDirection = rotateDistance > 0 ? 1 : -1;
|
8327 |
|
8328 |
|
8329 |
|
8330 | var meshPoint2 = fromValues(meshPoint[0], meshPoint[1], meshPoint[2]);
|
8331 | var meshPoint3;
|
8332 |
|
8333 | if (rotateKind !== ROTATE_CONSTANT.YAW_DELTA_BY_YAW) {
|
8334 | meshPoint3 = fromValues(0, rotateDirection, 0);
|
8335 | } else {
|
8336 | meshPoint3 = fromValues(rotateDirection, 0, 0);
|
8337 | }
|
8338 |
|
8339 | transformQuat(meshPoint2, meshPoint2, curQuaternion);
|
8340 | transformQuat(meshPoint3, meshPoint3, curQuaternion);
|
8341 | var vecU = meshPoint2;
|
8342 | var vecV = meshPoint3;
|
8343 | var vecN = create$2();
|
8344 | cross(vecN, vecU, vecV);
|
8345 | normalize(vecN, vecN);
|
8346 | var coefficientA = vecN[0];
|
8347 | var coefficientB = vecN[1];
|
8348 | var coefficientC = vecN[2];
|
8349 |
|
8350 |
|
8351 | curPoint = fromValues(meshPoint[0], meshPoint[1], meshPoint[2]);
|
8352 | transformQuat(curPoint, curPoint, curQuaternion);
|
8353 |
|
8354 | prevPoint = fromValues(meshPoint[0], meshPoint[1], meshPoint[2]);
|
8355 | transformQuat(prevPoint, prevPoint, prevQuaternion);
|
8356 |
|
8357 | var distance = Math.abs(prevPoint[0] * coefficientA + prevPoint[1] * coefficientB + prevPoint[2] * coefficientC);
|
8358 | var projectedPrevPoint = create$2();
|
8359 | subtract(projectedPrevPoint, prevPoint, scale(create$2(), vecN, distance));
|
8360 | var trigonometricRatio = (projectedPrevPoint[0] * curPoint[0] + projectedPrevPoint[1] * curPoint[1] + projectedPrevPoint[2] * curPoint[2]) / (length(projectedPrevPoint) * length(curPoint));
|
8361 |
|
8362 | if (trigonometricRatio > 1) {
|
8363 | trigonometricRatio = 1;
|
8364 | }
|
8365 |
|
8366 | var theta = Math.acos(trigonometricRatio);
|
8367 | var crossVec = cross(create$2(), curPoint, projectedPrevPoint);
|
8368 | distance = coefficientA * crossVec[0] + coefficientB * crossVec[1] + coefficientC * crossVec[2];
|
8369 | var thetaDirection;
|
8370 |
|
8371 | if (rotateKind !== ROTATE_CONSTANT.YAW_DELTA_BY_YAW) {
|
8372 | thetaDirection = distance > 0 ? 1 : -1;
|
8373 | } else {
|
8374 | thetaDirection = distance < 0 ? 1 : -1;
|
8375 | }
|
8376 |
|
8377 | var deltaRadian = theta * thetaDirection * rotateDirection;
|
8378 | return toDegree(deltaRadian);
|
8379 | };
|
8380 |
|
8381 | var angleBetweenVec2 = function (v1, v2) {
|
8382 | var det = v1[0] * v2[1] - v2[0] * v1[1];
|
8383 | var theta = -Math.atan2(det, dot$1(v1, v2));
|
8384 | return theta;
|
8385 | };
|
8386 |
|
8387 | util.yawOffsetBetween = function (viewDir, targetDir) {
|
8388 | var viewDirXZ = fromValues$3(viewDir[0], viewDir[2]);
|
8389 | var targetDirXZ = fromValues$3(targetDir[0], targetDir[2]);
|
8390 | normalize$3(viewDirXZ, viewDirXZ);
|
8391 | normalize$3(targetDirXZ, targetDirXZ);
|
8392 | var theta = -angleBetweenVec2(viewDirXZ, targetDirXZ);
|
8393 | return theta;
|
8394 | };
|
8395 |
|
8396 | util.sign = function (x) {
|
8397 | return Math.sign ? Math.sign(x) : Number(x > 0) - Number(x < 0) || +x;
|
8398 | };
|
8399 |
|
8400 | util.toDegree = toDegree;
|
8401 | util.getRotationDelta = getRotationDelta;
|
8402 | util.angleBetweenVec2 = angleBetweenVec2;
|
8403 |
|
8404 | var toAxis$1 = function (source, offset) {
|
8405 | return offset.reduce(function (acc, v, i) {
|
8406 | if (source[i]) {
|
8407 | acc[source[i]] = v;
|
8408 | }
|
8409 |
|
8410 | return acc;
|
8411 | }, {});
|
8412 | };
|
8413 |
|
8414 | |
8415 |
|
8416 |
|
8417 |
|
8418 |
|
8419 |
|
8420 |
|
8421 | |
8422 |
|
8423 |
|
8424 |
|
8425 |
|
8426 |
|
8427 |
|
8428 |
|
8429 | var version = -1;
|
8430 |
|
8431 | var branch = null;
|
8432 | var build = null;
|
8433 | var match = /Chrome\/([0-9]+)\.(?:[0-9]*)\.([0-9]*)\.([0-9]*)/i.exec(userAgent);
|
8434 |
|
8435 | if (match) {
|
8436 | version = parseInt(match[1], 10);
|
8437 | branch = match[2];
|
8438 | build = match[3];
|
8439 | }
|
8440 |
|
8441 | var CHROME_VERSION = version;
|
8442 | var IS_CHROME_WITHOUT_DEVICE_MOTION = version === 65 && branch === "3325" && parseInt(build, 10) < 148;
|
8443 | var IS_ANDROID = /Android/i.test(userAgent);
|
8444 | var CONTROL_MODE_VR = 1;
|
8445 | var CONTROL_MODE_YAWPITCH = 2;
|
8446 | var TOUCH_DIRECTION_NONE = 1;
|
8447 | var TOUCH_DIRECTION_YAW = 2;
|
8448 | var TOUCH_DIRECTION_PITCH = 4;
|
8449 | var TOUCH_DIRECTION_ALL = TOUCH_DIRECTION_YAW | TOUCH_DIRECTION_PITCH;
|
8450 |
|
8451 |
|
8452 | var MC_DECELERATION = 0.0014;
|
8453 | var MC_MAXIMUM_DURATION = 1000;
|
8454 | var MC_BIND_SCALE = [0.20, 0.20];
|
8455 | var MAX_FIELD_OF_VIEW = 110;
|
8456 | var PAN_SCALE = 320;
|
8457 |
|
8458 | var YAW_RANGE_HALF = 180;
|
8459 | var PITCH_RANGE_HALF = 90;
|
8460 | var CIRCULAR_PITCH_RANGE_HALF = 180;
|
8461 | var GYRO_MODE = {
|
8462 | NONE: "none",
|
8463 | YAWPITCH: "yawPitch",
|
8464 | VR: "VR"
|
8465 | };
|
8466 |
|
8467 |
|
8468 | var MathUtil = win.MathUtil || {};
|
8469 | MathUtil.degToRad = Math.PI / 180;
|
8470 | MathUtil.radToDeg = 180 / Math.PI;
|
8471 |
|
8472 |
|
8473 | MathUtil.Vector2 = function (x, y) {
|
8474 | this.x = x || 0;
|
8475 | this.y = y || 0;
|
8476 | };
|
8477 |
|
8478 | MathUtil.Vector2.prototype = {
|
8479 | constructor: MathUtil.Vector2,
|
8480 | set: function (x, y) {
|
8481 | this.x = x;
|
8482 | this.y = y;
|
8483 | return this;
|
8484 | },
|
8485 | copy: function (v) {
|
8486 | this.x = v.x;
|
8487 | this.y = v.y;
|
8488 | return this;
|
8489 | },
|
8490 | subVectors: function (a, b) {
|
8491 | this.x = a.x - b.x;
|
8492 | this.y = a.y - b.y;
|
8493 | return this;
|
8494 | }
|
8495 | };
|
8496 |
|
8497 | MathUtil.Vector3 = function (x, y, z) {
|
8498 | this.x = x || 0;
|
8499 | this.y = y || 0;
|
8500 | this.z = z || 0;
|
8501 | };
|
8502 |
|
8503 | MathUtil.Vector3.prototype = {
|
8504 | constructor: MathUtil.Vector3,
|
8505 | set: function (x, y, z) {
|
8506 | this.x = x;
|
8507 | this.y = y;
|
8508 | this.z = z;
|
8509 | return this;
|
8510 | },
|
8511 | copy: function (v) {
|
8512 | this.x = v.x;
|
8513 | this.y = v.y;
|
8514 | this.z = v.z;
|
8515 | return this;
|
8516 | },
|
8517 | length: function () {
|
8518 | return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
8519 | },
|
8520 | normalize: function () {
|
8521 | var scalar = this.length();
|
8522 |
|
8523 | if (scalar !== 0) {
|
8524 | var invScalar = 1 / scalar;
|
8525 | this.multiplyScalar(invScalar);
|
8526 | } else {
|
8527 | this.x = 0;
|
8528 | this.y = 0;
|
8529 | this.z = 0;
|
8530 | }
|
8531 |
|
8532 | return this;
|
8533 | },
|
8534 | multiplyScalar: function (scalar) {
|
8535 | this.x *= scalar;
|
8536 | this.y *= scalar;
|
8537 | this.z *= scalar;
|
8538 | },
|
8539 | applyQuaternion: function (q) {
|
8540 | var x = this.x;
|
8541 | var y = this.y;
|
8542 | var z = this.z;
|
8543 | var qx = q.x;
|
8544 | var qy = q.y;
|
8545 | var qz = q.z;
|
8546 | var qw = q.w;
|
8547 |
|
8548 | var ix = qw * x + qy * z - qz * y;
|
8549 | var iy = qw * y + qz * x - qx * z;
|
8550 | var iz = qw * z + qx * y - qy * x;
|
8551 | var iw = -qx * x - qy * y - qz * z;
|
8552 |
|
8553 | this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
|
8554 | this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
|
8555 | this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
|
8556 | return this;
|
8557 | },
|
8558 | dot: function (v) {
|
8559 | return this.x * v.x + this.y * v.y + this.z * v.z;
|
8560 | },
|
8561 | crossVectors: function (a, b) {
|
8562 | var ax = a.x;
|
8563 | var ay = a.y;
|
8564 | var az = a.z;
|
8565 | var bx = b.x;
|
8566 | var by = b.y;
|
8567 | var bz = b.z;
|
8568 | this.x = ay * bz - az * by;
|
8569 | this.y = az * bx - ax * bz;
|
8570 | this.z = ax * by - ay * bx;
|
8571 | return this;
|
8572 | }
|
8573 | };
|
8574 |
|
8575 | MathUtil.Quaternion = function (x, y, z, w) {
|
8576 | this.x = x || 0;
|
8577 | this.y = y || 0;
|
8578 | this.z = z || 0;
|
8579 | this.w = w !== undefined ? w : 1;
|
8580 | };
|
8581 |
|
8582 | MathUtil.Quaternion.prototype = {
|
8583 | constructor: MathUtil.Quaternion,
|
8584 | set: function (x, y, z, w) {
|
8585 | this.x = x;
|
8586 | this.y = y;
|
8587 | this.z = z;
|
8588 | this.w = w;
|
8589 | return this;
|
8590 | },
|
8591 | copy: function (quaternion) {
|
8592 | this.x = quaternion.x;
|
8593 | this.y = quaternion.y;
|
8594 | this.z = quaternion.z;
|
8595 | this.w = quaternion.w;
|
8596 | return this;
|
8597 | },
|
8598 | setFromEulerXYZ: function (x, y, z) {
|
8599 | var c1 = Math.cos(x / 2);
|
8600 | var c2 = Math.cos(y / 2);
|
8601 | var c3 = Math.cos(z / 2);
|
8602 | var s1 = Math.sin(x / 2);
|
8603 | var s2 = Math.sin(y / 2);
|
8604 | var s3 = Math.sin(z / 2);
|
8605 | this.x = s1 * c2 * c3 + c1 * s2 * s3;
|
8606 | this.y = c1 * s2 * c3 - s1 * c2 * s3;
|
8607 | this.z = c1 * c2 * s3 + s1 * s2 * c3;
|
8608 | this.w = c1 * c2 * c3 - s1 * s2 * s3;
|
8609 | return this;
|
8610 | },
|
8611 | setFromEulerYXZ: function (x, y, z) {
|
8612 | var c1 = Math.cos(x / 2);
|
8613 | var c2 = Math.cos(y / 2);
|
8614 | var c3 = Math.cos(z / 2);
|
8615 | var s1 = Math.sin(x / 2);
|
8616 | var s2 = Math.sin(y / 2);
|
8617 | var s3 = Math.sin(z / 2);
|
8618 | this.x = s1 * c2 * c3 + c1 * s2 * s3;
|
8619 | this.y = c1 * s2 * c3 - s1 * c2 * s3;
|
8620 | this.z = c1 * c2 * s3 - s1 * s2 * c3;
|
8621 | this.w = c1 * c2 * c3 + s1 * s2 * s3;
|
8622 | return this;
|
8623 | },
|
8624 | setFromAxisAngle: function (axis, angle) {
|
8625 |
|
8626 |
|
8627 | var halfAngle = angle / 2;
|
8628 | var s = Math.sin(halfAngle);
|
8629 | this.x = axis.x * s;
|
8630 | this.y = axis.y * s;
|
8631 | this.z = axis.z * s;
|
8632 | this.w = Math.cos(halfAngle);
|
8633 | return this;
|
8634 | },
|
8635 | multiply: function (q) {
|
8636 | return this.multiplyQuaternions(this, q);
|
8637 | },
|
8638 | multiplyQuaternions: function (a, b) {
|
8639 |
|
8640 | var qax = a.x;
|
8641 | var qay = a.y;
|
8642 | var qaz = a.z;
|
8643 | var qaw = a.w;
|
8644 | var qbx = b.x;
|
8645 | var qby = b.y;
|
8646 | var qbz = b.z;
|
8647 | var qbw = b.w;
|
8648 | this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
|
8649 | this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
|
8650 | this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
|
8651 | this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
|
8652 | return this;
|
8653 | },
|
8654 | inverse: function () {
|
8655 | this.x *= -1;
|
8656 | this.y *= -1;
|
8657 | this.z *= -1;
|
8658 | this.normalize();
|
8659 | return this;
|
8660 | },
|
8661 | normalize: function () {
|
8662 | var l = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
|
8663 |
|
8664 | if (l === 0) {
|
8665 | this.x = 0;
|
8666 | this.y = 0;
|
8667 | this.z = 0;
|
8668 | this.w = 1;
|
8669 | } else {
|
8670 | l = 1 / l;
|
8671 | this.x = this.x * l;
|
8672 | this.y = this.y * l;
|
8673 | this.z = this.z * l;
|
8674 | this.w = this.w * l;
|
8675 | }
|
8676 |
|
8677 | return this;
|
8678 | },
|
8679 | slerp: function (qb, t) {
|
8680 | if (t === 0) return this;
|
8681 | if (t === 1) return this.copy(qb);
|
8682 | var x = this.x;
|
8683 | var y = this.y;
|
8684 | var z = this.z;
|
8685 | var w = this.w;
|
8686 |
|
8687 | var cosHalfTheta = w * qb.w + x * qb.x + y * qb.y + z * qb.z;
|
8688 |
|
8689 | if (cosHalfTheta < 0) {
|
8690 | this.w = -qb.w;
|
8691 | this.x = -qb.x;
|
8692 | this.y = -qb.y;
|
8693 | this.z = -qb.z;
|
8694 | cosHalfTheta = -cosHalfTheta;
|
8695 | } else {
|
8696 | this.copy(qb);
|
8697 | }
|
8698 |
|
8699 | if (cosHalfTheta >= 1.0) {
|
8700 | this.w = w;
|
8701 | this.x = x;
|
8702 | this.y = y;
|
8703 | this.z = z;
|
8704 | return this;
|
8705 | }
|
8706 |
|
8707 | var halfTheta = Math.acos(cosHalfTheta);
|
8708 | var sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);
|
8709 |
|
8710 | if (Math.abs(sinHalfTheta) < 0.001) {
|
8711 | this.w = 0.5 * (w + this.w);
|
8712 | this.x = 0.5 * (x + this.x);
|
8713 | this.y = 0.5 * (y + this.y);
|
8714 | this.z = 0.5 * (z + this.z);
|
8715 | return this;
|
8716 | }
|
8717 |
|
8718 | var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
|
8719 | var ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
|
8720 | this.w = w * ratioA + this.w * ratioB;
|
8721 | this.x = x * ratioA + this.x * ratioB;
|
8722 | this.y = y * ratioA + this.y * ratioB;
|
8723 | this.z = z * ratioA + this.z * ratioB;
|
8724 | return this;
|
8725 | },
|
8726 | setFromUnitVectors: function () {
|
8727 |
|
8728 |
|
8729 | var v1;
|
8730 | var r;
|
8731 | var EPS = 0.000001;
|
8732 | return function (vFrom, vTo) {
|
8733 | if (v1 === undefined) v1 = new MathUtil.Vector3();
|
8734 | r = vFrom.dot(vTo) + 1;
|
8735 |
|
8736 | if (r < EPS) {
|
8737 | r = 0;
|
8738 |
|
8739 | if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
|
8740 | v1.set(-vFrom.y, vFrom.x, 0);
|
8741 | } else {
|
8742 | v1.set(0, -vFrom.z, vFrom.y);
|
8743 | }
|
8744 | } else {
|
8745 | v1.crossVectors(vFrom, vTo);
|
8746 | }
|
8747 |
|
8748 | this.x = v1.x;
|
8749 | this.y = v1.y;
|
8750 | this.z = v1.z;
|
8751 | this.w = r;
|
8752 | this.normalize();
|
8753 | return this;
|
8754 | };
|
8755 | }()
|
8756 | };
|
8757 |
|
8758 |
|
8759 |
|
8760 | |
8761 |
|
8762 |
|
8763 |
|
8764 |
|
8765 |
|
8766 |
|
8767 |
|
8768 |
|
8769 |
|
8770 |
|
8771 |
|
8772 |
|
8773 |
|
8774 | var _a;
|
8775 | var userAgent$1 = (_a = nav === null || nav === void 0 ? void 0 : nav.userAgent) !== null && _a !== void 0 ? _a : "";
|
8776 | var Util = win.Util || {};
|
8777 | Util.MIN_TIMESTEP = 0.001;
|
8778 | Util.MAX_TIMESTEP = 1;
|
8779 |
|
8780 | Util.base64 = function (mimeType, base64) {
|
8781 | return "data:" + mimeType + ";base64," + base64;
|
8782 | };
|
8783 |
|
8784 | Util.clamp = function (value, min, max) {
|
8785 | return Math.min(Math.max(min, value), max);
|
8786 | };
|
8787 |
|
8788 | Util.lerp = function (a, b, t) {
|
8789 | return a + (b - a) * t;
|
8790 | };
|
8791 |
|
8792 | Util.isIOS = function () {
|
8793 | var isIOS = /iPad|iPhone|iPod/.test(nav === null || nav === void 0 ? void 0 : nav.platform);
|
8794 | return function () {
|
8795 | return isIOS;
|
8796 | };
|
8797 | }();
|
8798 |
|
8799 | Util.isWebViewAndroid = function () {
|
8800 | var isWebViewAndroid = userAgent$1.indexOf("Version") !== -1 && userAgent$1.indexOf("Android") !== -1 && userAgent$1.indexOf("Chrome") !== -1;
|
8801 | return function () {
|
8802 | return isWebViewAndroid;
|
8803 | };
|
8804 | }();
|
8805 |
|
8806 | Util.isSafari = function () {
|
8807 | var isSafari = /^((?!chrome|android).)*safari/i.test(userAgent$1);
|
8808 | return function () {
|
8809 | return isSafari;
|
8810 | };
|
8811 | }();
|
8812 |
|
8813 | Util.isFirefoxAndroid = function () {
|
8814 | var isFirefoxAndroid = userAgent$1.indexOf("Firefox") !== -1 && userAgent$1.indexOf("Android") !== -1;
|
8815 | return function () {
|
8816 | return isFirefoxAndroid;
|
8817 | };
|
8818 | }();
|
8819 |
|
8820 | Util.isR7 = function () {
|
8821 | var isR7 = userAgent$1.indexOf("R7 Build") !== -1;
|
8822 | return function () {
|
8823 | return isR7;
|
8824 | };
|
8825 | }();
|
8826 |
|
8827 | Util.isLandscapeMode = function () {
|
8828 | var rtn = win.orientation === 90 || win.orientation === -90;
|
8829 | return Util.isR7() ? !rtn : rtn;
|
8830 | };
|
8831 |
|
8832 |
|
8833 | Util.isTimestampDeltaValid = function (timestampDeltaS) {
|
8834 | if (isNaN(timestampDeltaS)) {
|
8835 | return false;
|
8836 | }
|
8837 |
|
8838 | if (timestampDeltaS <= Util.MIN_TIMESTEP) {
|
8839 | return false;
|
8840 | }
|
8841 |
|
8842 | if (timestampDeltaS > Util.MAX_TIMESTEP) {
|
8843 | return false;
|
8844 | }
|
8845 |
|
8846 | return true;
|
8847 | };
|
8848 |
|
8849 | Util.getScreenWidth = function () {
|
8850 | return Math.max(win.screen.width, win.screen.height) * win.devicePixelRatio;
|
8851 | };
|
8852 |
|
8853 | Util.getScreenHeight = function () {
|
8854 | return Math.min(win.screen.width, win.screen.height) * win.devicePixelRatio;
|
8855 | };
|
8856 |
|
8857 | Util.requestFullscreen = function (element) {
|
8858 | if (Util.isWebViewAndroid()) {
|
8859 | return false;
|
8860 | }
|
8861 |
|
8862 | if (element.requestFullscreen) {
|
8863 | element.requestFullscreen();
|
8864 | } else if (element.webkitRequestFullscreen) {
|
8865 | element.webkitRequestFullscreen();
|
8866 | } else if (element.mozRequestFullScreen) {
|
8867 | element.mozRequestFullScreen();
|
8868 | } else if (element.msRequestFullscreen) {
|
8869 | element.msRequestFullscreen();
|
8870 | } else {
|
8871 | return false;
|
8872 | }
|
8873 |
|
8874 | return true;
|
8875 | };
|
8876 |
|
8877 | Util.exitFullscreen = function () {
|
8878 | if (doc.exitFullscreen) {
|
8879 | doc.exitFullscreen();
|
8880 | } else if (doc.webkitExitFullscreen) {
|
8881 | doc.webkitExitFullscreen();
|
8882 | } else if (doc.mozCancelFullScreen) {
|
8883 | doc.mozCancelFullScreen();
|
8884 | } else if (doc.msExitFullscreen) {
|
8885 | doc.msExitFullscreen();
|
8886 | } else {
|
8887 | return false;
|
8888 | }
|
8889 |
|
8890 | return true;
|
8891 | };
|
8892 |
|
8893 | Util.getFullscreenElement = function () {
|
8894 | return doc.fullscreenElement || doc.webkitFullscreenElement || doc.mozFullScreenElement || doc.msFullscreenElement;
|
8895 | };
|
8896 |
|
8897 | Util.linkProgram = function (gl, vertexSource, fragmentSource, attribLocationMap) {
|
8898 |
|
8899 | var vertexShader = gl.createShader(gl.VERTEX_SHADER);
|
8900 | gl.shaderSource(vertexShader, vertexSource);
|
8901 | gl.compileShader(vertexShader);
|
8902 | var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
|
8903 | gl.shaderSource(fragmentShader, fragmentSource);
|
8904 | gl.compileShader(fragmentShader);
|
8905 | var program = gl.createProgram();
|
8906 | gl.attachShader(program, vertexShader);
|
8907 | gl.attachShader(program, fragmentShader);
|
8908 |
|
8909 | for (var attribName in attribLocationMap) gl.bindAttribLocation(program, attribLocationMap[attribName], attribName);
|
8910 |
|
8911 | gl.linkProgram(program);
|
8912 | gl.deleteShader(vertexShader);
|
8913 | gl.deleteShader(fragmentShader);
|
8914 | return program;
|
8915 | };
|
8916 |
|
8917 | Util.getProgramUniforms = function (gl, program) {
|
8918 | var uniforms = {};
|
8919 | var uniformCount = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
8920 | var uniformName = "";
|
8921 |
|
8922 | for (var i = 0; i < uniformCount; i++) {
|
8923 | var uniformInfo = gl.getActiveUniform(program, i);
|
8924 | uniformName = uniformInfo.name.replace("[0]", "");
|
8925 | uniforms[uniformName] = gl.getUniformLocation(program, uniformName);
|
8926 | }
|
8927 |
|
8928 | return uniforms;
|
8929 | };
|
8930 |
|
8931 | Util.orthoMatrix = function (out, left, right, bottom, top, near, far) {
|
8932 | var lr = 1 / (left - right);
|
8933 | var bt = 1 / (bottom - top);
|
8934 | var nf = 1 / (near - far);
|
8935 | out[0] = -2 * lr;
|
8936 | out[1] = 0;
|
8937 | out[2] = 0;
|
8938 | out[3] = 0;
|
8939 | out[4] = 0;
|
8940 | out[5] = -2 * bt;
|
8941 | out[6] = 0;
|
8942 | out[7] = 0;
|
8943 | out[8] = 0;
|
8944 | out[9] = 0;
|
8945 | out[10] = 2 * nf;
|
8946 | out[11] = 0;
|
8947 | out[12] = (left + right) * lr;
|
8948 | out[13] = (top + bottom) * bt;
|
8949 | out[14] = (far + near) * nf;
|
8950 | out[15] = 1;
|
8951 | return out;
|
8952 | };
|
8953 |
|
8954 | Util.copyArray = function (source, dest) {
|
8955 | for (var i = 0, n = source.length; i < n; i++) {
|
8956 | dest[i] = source[i];
|
8957 | }
|
8958 | };
|
8959 |
|
8960 | Util.isMobile = function () {
|
8961 | var check = false;
|
8962 |
|
8963 | (function (a) {
|
8964 | if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true;
|
8965 | })(userAgent$1 || (nav === null || nav === void 0 ? void 0 : nav.vendor) || win.opera);
|
8966 |
|
8967 | return check;
|
8968 | };
|
8969 |
|
8970 | Util.extend = function (dest, src) {
|
8971 | for (var key in src) {
|
8972 | if (src.hasOwnProperty(key)) {
|
8973 | dest[key] = src[key];
|
8974 | }
|
8975 | }
|
8976 |
|
8977 | return dest;
|
8978 | };
|
8979 |
|
8980 | Util.safariCssSizeWorkaround = function (canvas) {
|
8981 |
|
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 |
|
8987 |
|
8988 | if (Util.isIOS()) {
|
8989 | var width_1 = canvas.style.width;
|
8990 | var height_1 = canvas.style.height;
|
8991 | canvas.style.width = parseInt(width_1) + 1 + "px";
|
8992 | canvas.style.height = parseInt(height_1) + "px";
|
8993 | setTimeout(function () {
|
8994 | canvas.style.width = width_1;
|
8995 | canvas.style.height = height_1;
|
8996 | }, 100);
|
8997 | }
|
8998 |
|
8999 |
|
9000 | win.Util = Util;
|
9001 | win.canvas = canvas;
|
9002 | };
|
9003 |
|
9004 | Util.isDebug = function () {
|
9005 | return Util.getQueryParameter("debug");
|
9006 | };
|
9007 |
|
9008 | Util.getQueryParameter = function (name) {
|
9009 | name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
9010 | var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
|
9011 | var results = regex.exec(location.search);
|
9012 | return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
9013 | };
|
9014 |
|
9015 | Util.frameDataFromPose = function () {
|
9016 | var piOver180 = Math.PI / 180.0;
|
9017 | var rad45 = Math.PI * 0.25;
|
9018 |
|
9019 | function mat4_perspectiveFromFieldOfView(out, fov, near, far) {
|
9020 | var upTan = Math.tan(fov ? fov.upDegrees * piOver180 : rad45);
|
9021 | var downTan = Math.tan(fov ? fov.downDegrees * piOver180 : rad45);
|
9022 | var leftTan = Math.tan(fov ? fov.leftDegrees * piOver180 : rad45);
|
9023 | var rightTan = Math.tan(fov ? fov.rightDegrees * piOver180 : rad45);
|
9024 | var xScale = 2.0 / (leftTan + rightTan);
|
9025 | var yScale = 2.0 / (upTan + downTan);
|
9026 | out[0] = xScale;
|
9027 | out[1] = 0.0;
|
9028 | out[2] = 0.0;
|
9029 | out[3] = 0.0;
|
9030 | out[4] = 0.0;
|
9031 | out[5] = yScale;
|
9032 | out[6] = 0.0;
|
9033 | out[7] = 0.0;
|
9034 | out[8] = -((leftTan - rightTan) * xScale * 0.5);
|
9035 | out[9] = (upTan - downTan) * yScale * 0.5;
|
9036 | out[10] = far / (near - far);
|
9037 | out[11] = -1.0;
|
9038 | out[12] = 0.0;
|
9039 | out[13] = 0.0;
|
9040 | out[14] = far * near / (near - far);
|
9041 | out[15] = 0.0;
|
9042 | return out;
|
9043 | }
|
9044 |
|
9045 | function mat4_fromRotationTranslation(out, q, v) {
|
9046 |
|
9047 | var x = q[0];
|
9048 | var y = q[1];
|
9049 | var z = q[2];
|
9050 | var w = q[3];
|
9051 | var x2 = x + x;
|
9052 | var y2 = y + y;
|
9053 | var z2 = z + z;
|
9054 | var xx = x * x2;
|
9055 | var xy = x * y2;
|
9056 | var xz = x * z2;
|
9057 | var yy = y * y2;
|
9058 | var yz = y * z2;
|
9059 | var zz = z * z2;
|
9060 | var wx = w * x2;
|
9061 | var wy = w * y2;
|
9062 | var wz = w * z2;
|
9063 | out[0] = 1 - (yy + zz);
|
9064 | out[1] = xy + wz;
|
9065 | out[2] = xz - wy;
|
9066 | out[3] = 0;
|
9067 | out[4] = xy - wz;
|
9068 | out[5] = 1 - (xx + zz);
|
9069 | out[6] = yz + wx;
|
9070 | out[7] = 0;
|
9071 | out[8] = xz + wy;
|
9072 | out[9] = yz - wx;
|
9073 | out[10] = 1 - (xx + yy);
|
9074 | out[11] = 0;
|
9075 | out[12] = v[0];
|
9076 | out[13] = v[1];
|
9077 | out[14] = v[2];
|
9078 | out[15] = 1;
|
9079 | return out;
|
9080 | }
|
9081 |
|
9082 | function mat4_translate(out, a, v) {
|
9083 | var x = v[0];
|
9084 | var y = v[1];
|
9085 | var z = v[2];
|
9086 | var a00;
|
9087 | var a01;
|
9088 | var a02;
|
9089 | var a03;
|
9090 | var a10;
|
9091 | var a11;
|
9092 | var a12;
|
9093 | var a13;
|
9094 | var a20;
|
9095 | var a21;
|
9096 | var a22;
|
9097 | var a23;
|
9098 |
|
9099 | if (a === out) {
|
9100 | out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
9101 | out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
9102 | out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
9103 | out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
9104 | } else {
|
9105 | a00 = a[0];
|
9106 | a01 = a[1];
|
9107 | a02 = a[2];
|
9108 | a03 = a[3];
|
9109 | a10 = a[4];
|
9110 | a11 = a[5];
|
9111 | a12 = a[6];
|
9112 | a13 = a[7];
|
9113 | a20 = a[8];
|
9114 | a21 = a[9];
|
9115 | a22 = a[10];
|
9116 | a23 = a[11];
|
9117 | out[0] = a00;
|
9118 | out[1] = a01;
|
9119 | out[2] = a02;
|
9120 | out[3] = a03;
|
9121 | out[4] = a10;
|
9122 | out[5] = a11;
|
9123 | out[6] = a12;
|
9124 | out[7] = a13;
|
9125 | out[8] = a20;
|
9126 | out[9] = a21;
|
9127 | out[10] = a22;
|
9128 | out[11] = a23;
|
9129 | out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
9130 | out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
9131 | out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
9132 | out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
9133 | }
|
9134 |
|
9135 | return out;
|
9136 | }
|
9137 |
|
9138 | function mat4_invert(out, a) {
|
9139 | var a00 = a[0];
|
9140 | var a01 = a[1];
|
9141 | var a02 = a[2];
|
9142 | var a03 = a[3];
|
9143 | var a10 = a[4];
|
9144 | var a11 = a[5];
|
9145 | var a12 = a[6];
|
9146 | var a13 = a[7];
|
9147 | var a20 = a[8];
|
9148 | var a21 = a[9];
|
9149 | var a22 = a[10];
|
9150 | var a23 = a[11];
|
9151 | var a30 = a[12];
|
9152 | var a31 = a[13];
|
9153 | var a32 = a[14];
|
9154 | var a33 = a[15];
|
9155 | var b00 = a00 * a11 - a01 * a10;
|
9156 | var b01 = a00 * a12 - a02 * a10;
|
9157 | var b02 = a00 * a13 - a03 * a10;
|
9158 | var b03 = a01 * a12 - a02 * a11;
|
9159 | var b04 = a01 * a13 - a03 * a11;
|
9160 | var b05 = a02 * a13 - a03 * a12;
|
9161 | var b06 = a20 * a31 - a21 * a30;
|
9162 | var b07 = a20 * a32 - a22 * a30;
|
9163 | var b08 = a20 * a33 - a23 * a30;
|
9164 | var b09 = a21 * a32 - a22 * a31;
|
9165 | var b10 = a21 * a33 - a23 * a31;
|
9166 | var b11 = a22 * a33 - a23 * a32;
|
9167 |
|
9168 | var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
9169 |
|
9170 | if (!det) {
|
9171 | return null;
|
9172 | }
|
9173 |
|
9174 | det = 1.0 / det;
|
9175 | out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
9176 | out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
9177 | out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
9178 | out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
9179 | out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
9180 | out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
9181 | out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
9182 | out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
9183 | out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
9184 | out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
9185 | out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
9186 | out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
9187 | out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
9188 | out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
9189 | out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
9190 | out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
9191 | return out;
|
9192 | }
|
9193 |
|
9194 | var defaultOrientation = new Float32Array([0, 0, 0, 1]);
|
9195 | var defaultPosition = new Float32Array([0, 0, 0]);
|
9196 |
|
9197 | function updateEyeMatrices(projection, view, pose, parameters, vrDisplay) {
|
9198 | mat4_perspectiveFromFieldOfView(projection, parameters ? parameters.fieldOfView : null, vrDisplay.depthNear, vrDisplay.depthFar);
|
9199 | var orientation = pose.orientation || defaultOrientation;
|
9200 | var position = pose.position || defaultPosition;
|
9201 | mat4_fromRotationTranslation(view, orientation, position);
|
9202 | if (parameters) mat4_translate(view, view, parameters.offset);
|
9203 | mat4_invert(view, view);
|
9204 | }
|
9205 |
|
9206 | return function (frameData, pose, vrDisplay) {
|
9207 | if (!frameData || !pose) return false;
|
9208 | frameData.pose = pose;
|
9209 | frameData.timestamp = pose.timestamp;
|
9210 | updateEyeMatrices(frameData.leftProjectionMatrix, frameData.leftViewMatrix, pose, vrDisplay.getEyeParameters("left"), vrDisplay);
|
9211 | updateEyeMatrices(frameData.rightProjectionMatrix, frameData.rightViewMatrix, pose, vrDisplay.getEyeParameters("right"), vrDisplay);
|
9212 | return true;
|
9213 | };
|
9214 | }();
|
9215 |
|
9216 | Util.isInsideCrossDomainIFrame = function () {
|
9217 | var isFramed = win.self !== win.top;
|
9218 | var refDomain = Util.getDomainFromUrl(doc.referrer);
|
9219 | var thisDomain = Util.getDomainFromUrl(win.location.href);
|
9220 | return isFramed && refDomain !== thisDomain;
|
9221 | };
|
9222 |
|
9223 |
|
9224 | Util.getDomainFromUrl = function (url) {
|
9225 | var domain;
|
9226 |
|
9227 | if (url.indexOf("://") > -1) {
|
9228 | domain = url.split("/")[2];
|
9229 | } else {
|
9230 | domain = url.split("/")[0];
|
9231 | }
|
9232 |
|
9233 |
|
9234 | domain = domain.split(":")[0];
|
9235 | return domain;
|
9236 | };
|
9237 |
|
9238 |
|
9239 | |
9240 |
|
9241 |
|
9242 |
|
9243 |
|
9244 |
|
9245 |
|
9246 |
|
9247 |
|
9248 | var PosePredictor =
|
9249 |
|
9250 | function () {
|
9251 | function PosePredictor(predictionTimeS) {
|
9252 | this.predictionTimeS = predictionTimeS;
|
9253 |
|
9254 | this.previousQ = new MathUtil.Quaternion();
|
9255 |
|
9256 | this.previousTimestampS = null;
|
9257 |
|
9258 | this.deltaQ = new MathUtil.Quaternion();
|
9259 |
|
9260 | this.outQ = new MathUtil.Quaternion();
|
9261 | }
|
9262 |
|
9263 | var __proto = PosePredictor.prototype;
|
9264 |
|
9265 | __proto.getPrediction = function (currentQ, gyro, timestampS) {
|
9266 | if (!this.previousTimestampS) {
|
9267 | this.previousQ.copy(currentQ);
|
9268 | this.previousTimestampS = timestampS;
|
9269 | return currentQ;
|
9270 | }
|
9271 |
|
9272 |
|
9273 | var axis = new MathUtil.Vector3();
|
9274 | axis.copy(gyro);
|
9275 | axis.normalize();
|
9276 | var angularSpeed = gyro.length();
|
9277 |
|
9278 | if (angularSpeed < MathUtil.degToRad * 20) {
|
9279 | if (Util.isDebug()) {
|
9280 | console.log("Moving slowly, at %s deg/s: no prediction", (MathUtil.radToDeg * angularSpeed).toFixed(1));
|
9281 | }
|
9282 |
|
9283 | this.outQ.copy(currentQ);
|
9284 | this.previousQ.copy(currentQ);
|
9285 | return this.outQ;
|
9286 | }
|
9287 |
|
9288 |
|
9289 | var deltaT = timestampS - this.previousTimestampS;
|
9290 | var predictAngle = angularSpeed * this.predictionTimeS;
|
9291 | this.deltaQ.setFromAxisAngle(axis, predictAngle);
|
9292 | this.outQ.copy(this.previousQ);
|
9293 | this.outQ.multiply(this.deltaQ);
|
9294 | this.previousQ.copy(currentQ);
|
9295 | this.previousTimestampS = timestampS;
|
9296 | return this.outQ;
|
9297 | };
|
9298 |
|
9299 | return PosePredictor;
|
9300 | }();
|
9301 |
|
9302 | var STILLNESS_THRESHOLD = 200;
|
9303 |
|
9304 | var DeviceMotion =
|
9305 |
|
9306 | function (_super) {
|
9307 | __extends(DeviceMotion, _super);
|
9308 |
|
9309 | function DeviceMotion() {
|
9310 | var _this = _super.call(this) || this;
|
9311 |
|
9312 | _this._onDeviceMotion = _this._onDeviceMotion.bind(_this);
|
9313 | _this._onDeviceOrientation = _this._onDeviceOrientation.bind(_this);
|
9314 | _this._onChromeWithoutDeviceMotion = _this._onChromeWithoutDeviceMotion.bind(_this);
|
9315 | _this.isWithoutDeviceMotion = IS_CHROME_WITHOUT_DEVICE_MOTION;
|
9316 | _this.isAndroid = IS_ANDROID;
|
9317 | _this.stillGyroVec = create$2();
|
9318 | _this.rawGyroVec = create$2();
|
9319 | _this.adjustedGyroVec = create$2();
|
9320 | _this._timer = -1;
|
9321 | _this.lastDevicemotionTimestamp = 0;
|
9322 | _this._isEnabled = false;
|
9323 |
|
9324 | _this.enable();
|
9325 |
|
9326 | return _this;
|
9327 | }
|
9328 |
|
9329 | var __proto = DeviceMotion.prototype;
|
9330 |
|
9331 | __proto.enable = function () {
|
9332 | if (this.isAndroid) {
|
9333 | win.addEventListener("deviceorientation", this._onDeviceOrientation);
|
9334 | }
|
9335 |
|
9336 | if (this.isWithoutDeviceMotion) {
|
9337 | win.addEventListener("deviceorientation", this._onChromeWithoutDeviceMotion);
|
9338 | } else {
|
9339 | win.addEventListener("devicemotion", this._onDeviceMotion);
|
9340 | }
|
9341 |
|
9342 | this._isEnabled = true;
|
9343 | };
|
9344 |
|
9345 | __proto.disable = function () {
|
9346 | win.removeEventListener("deviceorientation", this._onDeviceOrientation);
|
9347 | win.removeEventListener("deviceorientation", this._onChromeWithoutDeviceMotion);
|
9348 | win.removeEventListener("devicemotion", this._onDeviceMotion);
|
9349 | this._isEnabled = false;
|
9350 | };
|
9351 |
|
9352 | __proto._onChromeWithoutDeviceMotion = function (e) {
|
9353 | var alpha = e.alpha,
|
9354 | beta = e.beta,
|
9355 | gamma = e.gamma;
|
9356 |
|
9357 |
|
9358 | if (alpha === null) {
|
9359 | return;
|
9360 | }
|
9361 |
|
9362 |
|
9363 | alpha = (alpha || 0) * Math.PI / 180;
|
9364 | beta = (beta || 0) * Math.PI / 180;
|
9365 | gamma = (gamma || 0) * Math.PI / 180;
|
9366 | this.trigger(new ComponentEvent$1("devicemotion", {
|
9367 | inputEvent: {
|
9368 | deviceorientation: {
|
9369 | alpha: alpha,
|
9370 | beta: beta,
|
9371 | gamma: -gamma
|
9372 | }
|
9373 | }
|
9374 | }));
|
9375 | };
|
9376 |
|
9377 | __proto._onDeviceOrientation = function () {
|
9378 | var _this = this;
|
9379 |
|
9380 | if (this._timer) {
|
9381 | clearTimeout(this._timer);
|
9382 | }
|
9383 |
|
9384 | this._timer = win.setTimeout(function () {
|
9385 | if (new Date().getTime() - _this.lastDevicemotionTimestamp < STILLNESS_THRESHOLD) {
|
9386 | copy(_this.stillGyroVec, _this.rawGyroVec);
|
9387 | }
|
9388 | }, STILLNESS_THRESHOLD);
|
9389 | };
|
9390 |
|
9391 | __proto._onDeviceMotion = function (e) {
|
9392 |
|
9393 |
|
9394 | var isGyroSensorAvailable = !(e.rotationRate.alpha == null);
|
9395 | var isGravitySensorAvailable = !(e.accelerationIncludingGravity.x == null);
|
9396 |
|
9397 | if (e.interval === 0 || !(isGyroSensorAvailable && isGravitySensorAvailable)) {
|
9398 | return;
|
9399 | }
|
9400 |
|
9401 | var devicemotionEvent = __assign({}, e);
|
9402 |
|
9403 | devicemotionEvent.interval = e.interval;
|
9404 | devicemotionEvent.timeStamp = e.timeStamp;
|
9405 | devicemotionEvent.type = e.type;
|
9406 | devicemotionEvent.rotationRate = {
|
9407 | alpha: e.rotationRate.alpha,
|
9408 | beta: e.rotationRate.beta,
|
9409 | gamma: e.rotationRate.gamma
|
9410 | };
|
9411 | devicemotionEvent.accelerationIncludingGravity = {
|
9412 | x: e.accelerationIncludingGravity.x,
|
9413 | y: e.accelerationIncludingGravity.y,
|
9414 | z: e.accelerationIncludingGravity.z
|
9415 | };
|
9416 | devicemotionEvent.acceleration = {
|
9417 | x: e.acceleration.x,
|
9418 | y: e.acceleration.y,
|
9419 | z: e.acceleration.z
|
9420 | };
|
9421 |
|
9422 | if (this.isAndroid) {
|
9423 | set(this.rawGyroVec, e.rotationRate.alpha || 0, e.rotationRate.beta || 0, e.rotationRate.gamma || 0);
|
9424 | subtract(this.adjustedGyroVec, this.rawGyroVec, this.stillGyroVec);
|
9425 | this.lastDevicemotionTimestamp = new Date().getTime();
|
9426 | devicemotionEvent.adjustedRotationRate = {
|
9427 | alpha: this.adjustedGyroVec[0],
|
9428 | beta: this.adjustedGyroVec[1],
|
9429 | gamma: this.adjustedGyroVec[2]
|
9430 | };
|
9431 | }
|
9432 |
|
9433 | this.trigger(new ComponentEvent$1("devicemotion", {
|
9434 | inputEvent: devicemotionEvent
|
9435 | }));
|
9436 | };
|
9437 |
|
9438 | return DeviceMotion;
|
9439 | }(Component);
|
9440 |
|
9441 | var SensorSample =
|
9442 |
|
9443 | function () {
|
9444 | function SensorSample(sample, timestampS) {
|
9445 | this.set(sample, timestampS);
|
9446 | }
|
9447 |
|
9448 | var __proto = SensorSample.prototype;
|
9449 |
|
9450 | __proto.set = function (sample, timestampS) {
|
9451 | this.sample = sample;
|
9452 | this.timestampS = timestampS;
|
9453 | };
|
9454 |
|
9455 | __proto.copy = function (sensorSample) {
|
9456 | this.set(sensorSample.sample, sensorSample.timestampS);
|
9457 | };
|
9458 |
|
9459 | return SensorSample;
|
9460 | }();
|
9461 |
|
9462 |
|
9463 | |
9464 |
|
9465 |
|
9466 |
|
9467 |
|
9468 |
|
9469 |
|
9470 |
|
9471 |
|
9472 |
|
9473 |
|
9474 |
|
9475 |
|
9476 |
|
9477 |
|
9478 | var ComplementaryFilter =
|
9479 |
|
9480 | function () {
|
9481 | function ComplementaryFilter(kFilter) {
|
9482 | this.addGyroMeasurement = function (vector, timestampS) {
|
9483 | this.currentGyroMeasurement.set(vector, timestampS);
|
9484 | var deltaT = timestampS - this.previousGyroMeasurement.timestampS;
|
9485 |
|
9486 | if (Util.isTimestampDeltaValid(deltaT)) {
|
9487 | this.run_();
|
9488 | }
|
9489 |
|
9490 | this.previousGyroMeasurement.copy(this.currentGyroMeasurement);
|
9491 | };
|
9492 |
|
9493 | this.kFilter = kFilter;
|
9494 |
|
9495 | this.currentAccelMeasurement = new SensorSample();
|
9496 | this.currentGyroMeasurement = new SensorSample();
|
9497 | this.previousGyroMeasurement = new SensorSample();
|
9498 |
|
9499 | if (Util.isIOS()) {
|
9500 | this.filterQ = new MathUtil.Quaternion(-1, 0, 0, 1);
|
9501 | } else {
|
9502 | this.filterQ = new MathUtil.Quaternion(1, 0, 0, 1);
|
9503 | }
|
9504 |
|
9505 | this.previousFilterQ = new MathUtil.Quaternion();
|
9506 | this.previousFilterQ.copy(this.filterQ);
|
9507 |
|
9508 | this.accelQ = new MathUtil.Quaternion();
|
9509 |
|
9510 | this.isOrientationInitialized = false;
|
9511 |
|
9512 | this.estimatedGravity = new MathUtil.Vector3();
|
9513 |
|
9514 | this.measuredGravity = new MathUtil.Vector3();
|
9515 |
|
9516 | this.gyroIntegralQ = new MathUtil.Quaternion();
|
9517 | }
|
9518 |
|
9519 | var __proto = ComplementaryFilter.prototype;
|
9520 |
|
9521 | __proto.addAccelMeasurement = function (vector, timestampS) {
|
9522 | this.currentAccelMeasurement.set(vector, timestampS);
|
9523 | };
|
9524 |
|
9525 | __proto.getOrientation = function () {
|
9526 | return this.filterQ;
|
9527 | };
|
9528 |
|
9529 | __proto.run_ = function () {
|
9530 | if (!this.isOrientationInitialized) {
|
9531 | this.accelQ = this.accelToQuaternion_(this.currentAccelMeasurement.sample);
|
9532 | this.previousFilterQ.copy(this.accelQ);
|
9533 | this.isOrientationInitialized = true;
|
9534 | return;
|
9535 | }
|
9536 |
|
9537 | var deltaT = this.currentGyroMeasurement.timestampS - this.previousGyroMeasurement.timestampS;
|
9538 |
|
9539 | var gyroDeltaQ = this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample, deltaT);
|
9540 | this.gyroIntegralQ.multiply(gyroDeltaQ);
|
9541 |
|
9542 | this.filterQ.copy(this.previousFilterQ);
|
9543 | this.filterQ.multiply(gyroDeltaQ);
|
9544 |
|
9545 |
|
9546 | var invFilterQ = new MathUtil.Quaternion();
|
9547 | invFilterQ.copy(this.filterQ);
|
9548 | invFilterQ.inverse();
|
9549 | this.estimatedGravity.set(0, 0, -1);
|
9550 | this.estimatedGravity.applyQuaternion(invFilterQ);
|
9551 | this.estimatedGravity.normalize();
|
9552 | this.measuredGravity.copy(this.currentAccelMeasurement.sample);
|
9553 | this.measuredGravity.normalize();
|
9554 |
|
9555 |
|
9556 | var deltaQ = new MathUtil.Quaternion();
|
9557 | deltaQ.setFromUnitVectors(this.estimatedGravity, this.measuredGravity);
|
9558 | deltaQ.inverse();
|
9559 |
|
9560 | if (Util.isDebug()) {
|
9561 | console.log("Delta: %d deg, G_est: (%s, %s, %s), G_meas: (%s, %s, %s)", MathUtil.radToDeg * Util.getQuaternionAngle(deltaQ), this.estimatedGravity.x.toFixed(1), this.estimatedGravity.y.toFixed(1), this.estimatedGravity.z.toFixed(1), this.measuredGravity.x.toFixed(1), this.measuredGravity.y.toFixed(1), this.measuredGravity.z.toFixed(1));
|
9562 | }
|
9563 |
|
9564 |
|
9565 |
|
9566 | var targetQ = new MathUtil.Quaternion();
|
9567 | targetQ.copy(this.filterQ);
|
9568 | targetQ.multiply(deltaQ);
|
9569 |
|
9570 | this.filterQ.slerp(targetQ, 1 - this.kFilter);
|
9571 | this.previousFilterQ.copy(this.filterQ);
|
9572 | };
|
9573 |
|
9574 | __proto.accelToQuaternion_ = function (accel) {
|
9575 | var normAccel = new MathUtil.Vector3();
|
9576 | normAccel.copy(accel);
|
9577 | normAccel.normalize();
|
9578 | var quat = new MathUtil.Quaternion();
|
9579 | quat.setFromUnitVectors(new MathUtil.Vector3(0, 0, -1), normAccel);
|
9580 | quat.inverse();
|
9581 | return quat;
|
9582 | };
|
9583 |
|
9584 | __proto.gyroToQuaternionDelta_ = function (gyro, dt) {
|
9585 |
|
9586 | var quat = new MathUtil.Quaternion();
|
9587 | var axis = new MathUtil.Vector3();
|
9588 | axis.copy(gyro);
|
9589 | axis.normalize();
|
9590 | quat.setFromAxisAngle(axis, gyro.length() * dt);
|
9591 | return quat;
|
9592 | };
|
9593 |
|
9594 | return ComplementaryFilter;
|
9595 | }();
|
9596 |
|
9597 | ComplementaryFilter.prototype.run_ = function () {
|
9598 | if (!this.isOrientationInitialized) {
|
9599 | this.accelQ = this.accelToQuaternion_(this.currentAccelMeasurement.sample);
|
9600 | this.previousFilterQ.copy(this.accelQ);
|
9601 | this.isOrientationInitialized = true;
|
9602 | return;
|
9603 | }
|
9604 |
|
9605 | var deltaT = this.currentGyroMeasurement.timestampS - this.previousGyroMeasurement.timestampS;
|
9606 |
|
9607 | var gyroDeltaQ = this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample, deltaT);
|
9608 | this.gyroIntegralQ.multiply(gyroDeltaQ);
|
9609 |
|
9610 | this.filterQ.copy(this.previousFilterQ);
|
9611 | this.filterQ.multiply(gyroDeltaQ);
|
9612 |
|
9613 |
|
9614 | var invFilterQ = new MathUtil.Quaternion();
|
9615 | invFilterQ.copy(this.filterQ);
|
9616 | invFilterQ.inverse();
|
9617 | this.estimatedGravity.set(0, 0, -1);
|
9618 | this.estimatedGravity.applyQuaternion(invFilterQ);
|
9619 | this.estimatedGravity.normalize();
|
9620 | this.measuredGravity.copy(this.currentAccelMeasurement.sample);
|
9621 | this.measuredGravity.normalize();
|
9622 |
|
9623 |
|
9624 | var deltaQ = new MathUtil.Quaternion();
|
9625 | deltaQ.setFromUnitVectors(this.estimatedGravity, this.measuredGravity);
|
9626 | deltaQ.inverse();
|
9627 |
|
9628 |
|
9629 | var targetQ = new MathUtil.Quaternion();
|
9630 | targetQ.copy(this.filterQ);
|
9631 | targetQ.multiply(deltaQ);
|
9632 |
|
9633 | this.filterQ.slerp(targetQ, 1 - this.kFilter);
|
9634 | this.previousFilterQ.copy(this.filterQ);
|
9635 |
|
9636 | if (!this.isFilterQuaternionInitialized) {
|
9637 | this.isFilterQuaternionInitialized = true;
|
9638 | }
|
9639 | };
|
9640 |
|
9641 | ComplementaryFilter.prototype.getOrientation = function () {
|
9642 | if (this.isFilterQuaternionInitialized) {
|
9643 | return this.filterQ;
|
9644 | } else {
|
9645 | return null;
|
9646 | }
|
9647 | };
|
9648 |
|
9649 | var K_FILTER = 0.98;
|
9650 | var PREDICTION_TIME_S = 0.040;
|
9651 |
|
9652 | var FusionPoseSensor =
|
9653 |
|
9654 | function (_super) {
|
9655 | __extends(FusionPoseSensor, _super);
|
9656 |
|
9657 | function FusionPoseSensor() {
|
9658 | var _this = _super.call(this) || this;
|
9659 |
|
9660 | _this.deviceMotion = new DeviceMotion();
|
9661 | _this.accelerometer = new MathUtil.Vector3();
|
9662 | _this.gyroscope = new MathUtil.Vector3();
|
9663 | _this._onDeviceMotionChange = _this._onDeviceMotionChange.bind(_this);
|
9664 | _this._onScreenOrientationChange = _this._onScreenOrientationChange.bind(_this);
|
9665 | _this.filter = new ComplementaryFilter(K_FILTER);
|
9666 | _this.posePredictor = new PosePredictor(PREDICTION_TIME_S);
|
9667 | _this.filterToWorldQ = new MathUtil.Quaternion();
|
9668 | _this.isFirefoxAndroid = Util.isFirefoxAndroid();
|
9669 |
|
9670 | _this.isIOS = IS_IOS || IS_SAFARI_ON_DESKTOP;
|
9671 |
|
9672 | _this.isChromeUsingDegrees = CHROME_VERSION >= 66;
|
9673 | _this._isEnabled = false;
|
9674 |
|
9675 | if (_this.isIOS) {
|
9676 | _this.filterToWorldQ.setFromAxisAngle(new MathUtil.Vector3(1, 0, 0), Math.PI / 2);
|
9677 | } else {
|
9678 | _this.filterToWorldQ.setFromAxisAngle(new MathUtil.Vector3(1, 0, 0), -Math.PI / 2);
|
9679 | }
|
9680 |
|
9681 | _this.inverseWorldToScreenQ = new MathUtil.Quaternion();
|
9682 | _this.worldToScreenQ = new MathUtil.Quaternion();
|
9683 | _this.originalPoseAdjustQ = new MathUtil.Quaternion();
|
9684 |
|
9685 | _this.originalPoseAdjustQ.setFromAxisAngle(new MathUtil.Vector3(0, 0, 1), -win.orientation * Math.PI / 180);
|
9686 |
|
9687 | _this._setScreenTransform();
|
9688 |
|
9689 |
|
9690 | if (Util.isLandscapeMode()) {
|
9691 | _this.filterToWorldQ.multiply(_this.inverseWorldToScreenQ);
|
9692 | }
|
9693 |
|
9694 |
|
9695 | _this.resetQ = new MathUtil.Quaternion();
|
9696 |
|
9697 | _this.deviceMotion.on("devicemotion", _this._onDeviceMotionChange);
|
9698 |
|
9699 | _this.enable();
|
9700 |
|
9701 | return _this;
|
9702 | }
|
9703 |
|
9704 | var __proto = FusionPoseSensor.prototype;
|
9705 |
|
9706 | __proto.enable = function () {
|
9707 | if (this.isEnabled()) {
|
9708 | return;
|
9709 | }
|
9710 |
|
9711 | this.deviceMotion.enable();
|
9712 | this._isEnabled = true;
|
9713 | win.addEventListener("orientationchange", this._onScreenOrientationChange);
|
9714 | };
|
9715 |
|
9716 | __proto.disable = function () {
|
9717 | if (!this.isEnabled()) {
|
9718 | return;
|
9719 | }
|
9720 |
|
9721 | this.deviceMotion.disable();
|
9722 | this._isEnabled = false;
|
9723 | win.removeEventListener("orientationchange", this._onScreenOrientationChange);
|
9724 | };
|
9725 |
|
9726 | __proto.isEnabled = function () {
|
9727 | return this._isEnabled;
|
9728 | };
|
9729 |
|
9730 | __proto.destroy = function () {
|
9731 | this.disable();
|
9732 | this.deviceMotion = null;
|
9733 | };
|
9734 |
|
9735 | __proto.getOrientation = function () {
|
9736 | var _this = this;
|
9737 |
|
9738 | var orientation;
|
9739 |
|
9740 | if (this.deviceMotion.isWithoutDeviceMotion && this._deviceOrientationQ) {
|
9741 | this.deviceOrientationFixQ = this.deviceOrientationFixQ || function () {
|
9742 | var y = new MathUtil.Quaternion().setFromAxisAngle(new MathUtil.Vector3(0, 1, 0), -_this._alpha);
|
9743 | return y;
|
9744 | }();
|
9745 |
|
9746 | orientation = this._deviceOrientationQ;
|
9747 | var out = new MathUtil.Quaternion();
|
9748 | out.copy(orientation);
|
9749 | out.multiply(this.filterToWorldQ);
|
9750 | out.multiply(this.resetQ);
|
9751 | out.multiply(this.worldToScreenQ);
|
9752 | out.multiplyQuaternions(this.deviceOrientationFixQ, out);
|
9753 |
|
9754 | var outQuat = fromValues$2(out.x, out.y, out.z, out.w);
|
9755 | return normalize$2(outQuat, outQuat);
|
9756 | } else {
|
9757 |
|
9758 |
|
9759 | orientation = this.filter.getOrientation();
|
9760 |
|
9761 | if (!orientation) {
|
9762 | return null;
|
9763 | }
|
9764 |
|
9765 | var out = this._convertFusionToPredicted(orientation);
|
9766 |
|
9767 |
|
9768 | var outQuat = fromValues$2(out.x, out.y, out.z, out.w);
|
9769 | return normalize$2(outQuat, outQuat);
|
9770 | }
|
9771 | };
|
9772 |
|
9773 | __proto._triggerChange = function () {
|
9774 | var orientation = this.getOrientation();
|
9775 |
|
9776 | if (!orientation) {
|
9777 | return;
|
9778 | }
|
9779 |
|
9780 | if (!this._prevOrientation) {
|
9781 | this._prevOrientation = orientation;
|
9782 | return;
|
9783 | }
|
9784 |
|
9785 | if (equals$1(this._prevOrientation, orientation)) {
|
9786 | return;
|
9787 | }
|
9788 |
|
9789 | this.trigger(new ComponentEvent$1("change", {
|
9790 | quaternion: orientation
|
9791 | }));
|
9792 | };
|
9793 |
|
9794 | __proto._convertFusionToPredicted = function (orientation) {
|
9795 |
|
9796 | this.predictedQ = this.posePredictor.getPrediction(orientation, this.gyroscope, this.previousTimestampS);
|
9797 |
|
9798 | var out = new MathUtil.Quaternion();
|
9799 | out.copy(this.filterToWorldQ);
|
9800 | out.multiply(this.resetQ);
|
9801 | out.multiply(this.predictedQ);
|
9802 | out.multiply(this.worldToScreenQ);
|
9803 | return out;
|
9804 | };
|
9805 |
|
9806 | __proto._onDeviceMotionChange = function (_a) {
|
9807 | var inputEvent = _a.inputEvent;
|
9808 | var deviceorientation = inputEvent.deviceorientation;
|
9809 | var deviceMotion = inputEvent;
|
9810 | var accGravity = deviceMotion.accelerationIncludingGravity;
|
9811 | var rotRate = deviceMotion.adjustedRotationRate || deviceMotion.rotationRate;
|
9812 | var timestampS = deviceMotion.timeStamp / 1000;
|
9813 |
|
9814 | if (deviceorientation) {
|
9815 | if (!this._alpha) {
|
9816 | this._alpha = deviceorientation.alpha;
|
9817 | }
|
9818 |
|
9819 | this._deviceOrientationQ = this._deviceOrientationQ || new MathUtil.Quaternion();
|
9820 |
|
9821 | this._deviceOrientationQ.setFromEulerYXZ(deviceorientation.beta, deviceorientation.alpha, deviceorientation.gamma);
|
9822 |
|
9823 | this._triggerChange();
|
9824 | } else {
|
9825 |
|
9826 | if (this.isFirefoxAndroid) {
|
9827 | timestampS /= 1000;
|
9828 | }
|
9829 |
|
9830 | this.accelerometer.set(-accGravity.x, -accGravity.y, -accGravity.z);
|
9831 | this.gyroscope.set(rotRate.alpha, rotRate.beta, rotRate.gamma);
|
9832 |
|
9833 |
|
9834 | if (this.isIOS || this.isFirefoxAndroid || this.isChromeUsingDegrees) {
|
9835 | this.gyroscope.multiplyScalar(Math.PI / 180);
|
9836 | }
|
9837 |
|
9838 | this.filter.addAccelMeasurement(this.accelerometer, timestampS);
|
9839 | this.filter.addGyroMeasurement(this.gyroscope, timestampS);
|
9840 |
|
9841 | this._triggerChange();
|
9842 |
|
9843 | this.previousTimestampS = timestampS;
|
9844 | }
|
9845 | };
|
9846 |
|
9847 | __proto._onScreenOrientationChange = function () {
|
9848 | this._setScreenTransform();
|
9849 | };
|
9850 |
|
9851 | __proto._setScreenTransform = function () {
|
9852 | this.worldToScreenQ.set(0, 0, 0, 1);
|
9853 | var orientation = win.orientation;
|
9854 |
|
9855 | switch (orientation) {
|
9856 | case 0:
|
9857 | break;
|
9858 |
|
9859 | case 90:
|
9860 | case -90:
|
9861 | case 180:
|
9862 | this.worldToScreenQ.setFromAxisAngle(new MathUtil.Vector3(0, 0, 1), orientation / -180 * Math.PI);
|
9863 | break;
|
9864 | }
|
9865 |
|
9866 | this.inverseWorldToScreenQ.copy(this.worldToScreenQ);
|
9867 | this.inverseWorldToScreenQ.inverse();
|
9868 | };
|
9869 |
|
9870 | return FusionPoseSensor;
|
9871 | }(Component);
|
9872 |
|
9873 | var getDeltaYaw = function (prvQ, curQ) {
|
9874 | var yawDeltaByYaw = util.getRotationDelta(prvQ, curQ, ROTATE_CONSTANT.YAW_DELTA_BY_YAW);
|
9875 | var yawDeltaByRoll = util.getRotationDelta(prvQ, curQ, ROTATE_CONSTANT.YAW_DELTA_BY_ROLL) * Math.sin(util.extractPitchFromQuat(curQ));
|
9876 | return yawDeltaByRoll + yawDeltaByYaw;
|
9877 | };
|
9878 |
|
9879 | var getDeltaPitch = function (prvQ, curQ) {
|
9880 | var pitchDelta = util.getRotationDelta(prvQ, curQ, ROTATE_CONSTANT.PITCH_DELTA);
|
9881 | return pitchDelta;
|
9882 | };
|
9883 |
|
9884 |
|
9885 | var TiltMotionInput =
|
9886 |
|
9887 | function (_super) {
|
9888 | __extends(TiltMotionInput, _super);
|
9889 |
|
9890 | function TiltMotionInput(el, options) {
|
9891 | if (options === void 0) {
|
9892 | options = {};
|
9893 | }
|
9894 |
|
9895 | var _this = _super.call(this) || this;
|
9896 |
|
9897 | _this.element = el;
|
9898 | _this._prevQuaternion = null;
|
9899 | _this._quaternion = null;
|
9900 | _this.fusionPoseSensor = null;
|
9901 | _this.options = __assign({
|
9902 | scale: 1,
|
9903 | threshold: 0
|
9904 | }, options);
|
9905 | _this._onPoseChange = _this._onPoseChange.bind(_this);
|
9906 | return _this;
|
9907 | }
|
9908 |
|
9909 | var __proto = TiltMotionInput.prototype;
|
9910 |
|
9911 | __proto.mapAxes = function (axes) {
|
9912 | this.axes = axes;
|
9913 | };
|
9914 |
|
9915 | __proto.connect = function (observer) {
|
9916 | if (this.observer) {
|
9917 | return this;
|
9918 | }
|
9919 |
|
9920 | this.observer = observer;
|
9921 | this.fusionPoseSensor = new FusionPoseSensor();
|
9922 | this.fusionPoseSensor.enable();
|
9923 |
|
9924 | this._attachEvent();
|
9925 |
|
9926 | return this;
|
9927 | };
|
9928 |
|
9929 | __proto.disconnect = function () {
|
9930 | if (!this.observer) {
|
9931 | return this;
|
9932 | }
|
9933 |
|
9934 | this._dettachEvent();
|
9935 |
|
9936 | this.fusionPoseSensor.disable();
|
9937 | this.fusionPoseSensor.destroy();
|
9938 | this.fusionPoseSensor = null;
|
9939 | this.observer = null;
|
9940 | return this;
|
9941 | };
|
9942 |
|
9943 | __proto.destroy = function () {
|
9944 | this.disconnect();
|
9945 | this.element = null;
|
9946 | this.options = null;
|
9947 | this.axes = null;
|
9948 | this._prevQuaternion = null;
|
9949 | this._quaternion = null;
|
9950 | };
|
9951 |
|
9952 | __proto._onPoseChange = function (event) {
|
9953 | if (!this._prevQuaternion) {
|
9954 | this._prevQuaternion = clone$1(event.quaternion);
|
9955 | this._quaternion = clone$1(event.quaternion);
|
9956 | return;
|
9957 | }
|
9958 |
|
9959 | copy$2(this._prevQuaternion, this._quaternion);
|
9960 | copy$2(this._quaternion, event.quaternion);
|
9961 | this.observer.change(this, event, toAxis$1(this.axes, [getDeltaYaw(this._prevQuaternion, this._quaternion), getDeltaPitch(this._prevQuaternion, this._quaternion)]));
|
9962 | };
|
9963 |
|
9964 | __proto._attachEvent = function () {
|
9965 | this.fusionPoseSensor.on("change", this._onPoseChange);
|
9966 | };
|
9967 |
|
9968 | __proto._dettachEvent = function () {
|
9969 | this.fusionPoseSensor.off("change", this._onPoseChange);
|
9970 | };
|
9971 |
|
9972 | return TiltMotionInput;
|
9973 | }(Component);
|
9974 |
|
9975 | var screenRotationAngleInst = null;
|
9976 | var refCount = 0;
|
9977 |
|
9978 | var ScreenRotationAngle =
|
9979 |
|
9980 | function () {
|
9981 | function ScreenRotationAngle() {
|
9982 | refCount++;
|
9983 |
|
9984 | if (screenRotationAngleInst) {
|
9985 | return screenRotationAngleInst;
|
9986 | }
|
9987 |
|
9988 |
|
9989 |
|
9990 | screenRotationAngleInst = this;
|
9991 |
|
9992 |
|
9993 | this._onDeviceOrientation = this._onDeviceOrientation.bind(this);
|
9994 | this._onOrientationChange = this._onOrientationChange.bind(this);
|
9995 | this._spinR = 0;
|
9996 | this._screenOrientationAngle = 0;
|
9997 | win.addEventListener("deviceorientation", this._onDeviceOrientation);
|
9998 | win.addEventListener("orientationchange", this._onOrientationChange);
|
9999 | }
|
10000 |
|
10001 | var __proto = ScreenRotationAngle.prototype;
|
10002 |
|
10003 | __proto.getRadian = function () {
|
10004 |
|
10005 |
|
10006 | return this._spinR + toRadian(this._screenOrientationAngle);
|
10007 | };
|
10008 |
|
10009 | __proto.unref = function () {
|
10010 | if (--refCount > 0) {
|
10011 | return;
|
10012 | }
|
10013 |
|
10014 | win.removeEventListener("deviceorientation", this._onDeviceOrientation);
|
10015 | win.removeEventListener("orientationchange", this._onOrientationChange);
|
10016 | this._spinR = 0;
|
10017 | this._screenOrientationAngle = 0;
|
10018 |
|
10019 |
|
10020 | screenRotationAngleInst = null;
|
10021 |
|
10022 |
|
10023 | refCount = 0;
|
10024 | };
|
10025 |
|
10026 | __proto._onDeviceOrientation = function (e) {
|
10027 | if (e.beta === null || e.gamma === null) {
|
10028 |
|
10029 | return;
|
10030 | }
|
10031 |
|
10032 |
|
10033 | var betaR = toRadian(e.beta);
|
10034 | var gammaR = toRadian(e.gamma);
|
10035 |
|
10036 |
|
10037 | this._spinR = Math.atan2(Math.cos(betaR) * Math.sin(gammaR), Math.sin(betaR));
|
10038 | };
|
10039 |
|
10040 | __proto._onOrientationChange = function () {
|
10041 | if (win.screen && win.screen.orientation && win.screen.orientation.angle !== undefined) {
|
10042 | this._screenOrientationAngle = screen.orientation.angle;
|
10043 | } else if (win.orientation !== undefined) {
|
10044 |
|
10045 | this._screenOrientationAngle = win.orientation >= 0 ? win.orientation : 360 + win.orientation;
|
10046 | }
|
10047 | };
|
10048 |
|
10049 | return ScreenRotationAngle;
|
10050 | }();
|
10051 |
|
10052 | |
10053 |
|
10054 |
|
10055 |
|
10056 |
|
10057 |
|
10058 |
|
10059 |
|
10060 |
|
10061 |
|
10062 |
|
10063 | var RotationPanInput =
|
10064 |
|
10065 | function (_super) {
|
10066 | __extends(RotationPanInput, _super);
|
10067 | |
10068 |
|
10069 |
|
10070 |
|
10071 |
|
10072 |
|
10073 |
|
10074 |
|
10075 |
|
10076 | function RotationPanInput(el, options) {
|
10077 | if (options === void 0) {
|
10078 | options = {};
|
10079 | }
|
10080 |
|
10081 | var _this = _super.call(this, el, options) || this;
|
10082 |
|
10083 | _this._useRotation = false;
|
10084 | _this._screenRotationAngle = null;
|
10085 |
|
10086 | _this.setUseRotation(!!(options && options.useRotation));
|
10087 |
|
10088 | _this._userDirection = Axes.DIRECTION_ALL;
|
10089 | return _this;
|
10090 | }
|
10091 |
|
10092 | var __proto = RotationPanInput.prototype;
|
10093 |
|
10094 | __proto.setUseRotation = function (useRotation) {
|
10095 | this._useRotation = useRotation;
|
10096 |
|
10097 | if (this._screenRotationAngle) {
|
10098 | this._screenRotationAngle.unref();
|
10099 |
|
10100 | this._screenRotationAngle = null;
|
10101 | }
|
10102 |
|
10103 | if (this._useRotation) {
|
10104 | this._screenRotationAngle = new ScreenRotationAngle();
|
10105 | }
|
10106 | };
|
10107 |
|
10108 | __proto.connect = function (observer) {
|
10109 |
|
10110 | this._userDirection = this._direction;
|
10111 |
|
10112 |
|
10113 |
|
10114 | if (this._useRotation && this._direction & Axes.DIRECTION_ALL) {
|
10115 | this._direction = Axes.DIRECTION_HORIZONTAL;
|
10116 | }
|
10117 |
|
10118 | return _super.prototype.connect.call(this, observer);
|
10119 | };
|
10120 |
|
10121 | __proto.destroy = function () {
|
10122 | if (this._useRotation && this._screenRotationAngle) {
|
10123 | this._screenRotationAngle.unref();
|
10124 | }
|
10125 |
|
10126 | _super.prototype.destroy.call(this);
|
10127 | };
|
10128 |
|
10129 |
|
10130 | __proto.getOffset = function (properties, useDirection) {
|
10131 | if (this._useRotation === false) {
|
10132 |
|
10133 | return _super.prototype.getOffset.call(this, properties, useDirection);
|
10134 | }
|
10135 |
|
10136 |
|
10137 | var offset = _super.prototype.getOffset.call(this, properties, [true, true]);
|
10138 |
|
10139 | var newOffset = [0, 0];
|
10140 |
|
10141 | var theta = this._screenRotationAngle.getRadian();
|
10142 |
|
10143 | var cosTheta = Math.cos(theta);
|
10144 | var sinTheta = Math.sin(theta);
|
10145 |
|
10146 | newOffset[0] = offset[0] * cosTheta - offset[1] * sinTheta;
|
10147 | newOffset[1] = offset[1] * cosTheta + offset[0] * sinTheta;
|
10148 |
|
10149 | if (!(this._userDirection & Axes.DIRECTION_HORIZONTAL)) {
|
10150 | newOffset[0] = 0;
|
10151 | } else if (!(this._userDirection & Axes.DIRECTION_VERTICAL)) {
|
10152 | newOffset[1] = 0;
|
10153 | }
|
10154 |
|
10155 | return newOffset;
|
10156 | };
|
10157 |
|
10158 | return RotationPanInput;
|
10159 | }(PanInput);
|
10160 | |
10161 |
|
10162 |
|
10163 |
|
10164 |
|
10165 |
|
10166 |
|
10167 |
|
10168 |
|
10169 |
|
10170 | var Y_AXIS_VECTOR = fromValues(0, 1, 0);
|
10171 |
|
10172 | var DeviceQuaternion =
|
10173 |
|
10174 | function (_super) {
|
10175 | __extends(DeviceQuaternion, _super);
|
10176 |
|
10177 | function DeviceQuaternion() {
|
10178 | var _this = _super.call(this) || this;
|
10179 |
|
10180 | _this._fusionPoseSensor = new FusionPoseSensor();
|
10181 | _this._quaternion = create$4();
|
10182 |
|
10183 | _this._fusionPoseSensor.enable();
|
10184 |
|
10185 | _this._fusionPoseSensor.on("change", function (e) {
|
10186 | _this._quaternion = e.quaternion;
|
10187 |
|
10188 | _this.trigger(new ComponentEvent$1("change", {
|
10189 | isTrusted: true
|
10190 | }));
|
10191 | });
|
10192 |
|
10193 | return _this;
|
10194 | }
|
10195 |
|
10196 | var __proto = DeviceQuaternion.prototype;
|
10197 |
|
10198 | __proto.getCombinedQuaternion = function (yaw) {
|
10199 | var yawQ = setAxisAngle(create$4(), Y_AXIS_VECTOR, toRadian(-yaw));
|
10200 | var conj = conjugate(create$4(), this._quaternion);
|
10201 |
|
10202 | var outQ = multiply(create$4(), conj, yawQ);
|
10203 | return outQ;
|
10204 | };
|
10205 |
|
10206 | __proto.destroy = function () {
|
10207 |
|
10208 | this.off();
|
10209 |
|
10210 | if (this._fusionPoseSensor) {
|
10211 | this._fusionPoseSensor.off();
|
10212 |
|
10213 | this._fusionPoseSensor.destroy();
|
10214 |
|
10215 | this._fusionPoseSensor = null;
|
10216 | }
|
10217 | };
|
10218 |
|
10219 | return DeviceQuaternion;
|
10220 | }(Component);
|
10221 |
|
10222 | var DEFAULT_YAW_RANGE = [-YAW_RANGE_HALF, YAW_RANGE_HALF];
|
10223 | var DEFAULT_PITCH_RANGE = [-PITCH_RANGE_HALF, PITCH_RANGE_HALF];
|
10224 | var CIRCULAR_PITCH_RANGE = [-CIRCULAR_PITCH_RANGE_HALF, CIRCULAR_PITCH_RANGE_HALF];
|
10225 | |
10226 |
|
10227 |
|
10228 |
|
10229 |
|
10230 |
|
10231 |
|
10232 |
|
10233 | var YawPitchControl =
|
10234 |
|
10235 | function (_super) {
|
10236 | __extends(YawPitchControl, _super);
|
10237 | |
10238 |
|
10239 |
|
10240 |
|
10241 |
|
10242 |
|
10243 |
|
10244 |
|
10245 |
|
10246 |
|
10247 |
|
10248 |
|
10249 |
|
10250 |
|
10251 |
|
10252 |
|
10253 |
|
10254 |
|
10255 | function YawPitchControl(options) {
|
10256 | var _this = _super.call(this) || this;
|
10257 |
|
10258 | _this.options = {};
|
10259 |
|
10260 | var opt = __assign({
|
10261 | element: null,
|
10262 | yaw: 0,
|
10263 | pitch: 0,
|
10264 | fov: 65,
|
10265 | showPolePoint: false,
|
10266 | useZoom: true,
|
10267 | useKeyboard: true,
|
10268 | gyroMode: GYRO_MODE.YAWPITCH,
|
10269 | touchDirection: TOUCH_DIRECTION_ALL,
|
10270 | yawRange: DEFAULT_YAW_RANGE,
|
10271 | pitchRange: DEFAULT_PITCH_RANGE,
|
10272 | fovRange: [30, 110],
|
10273 | aspectRatio: 1
|
10274 |
|
10275 |
|
10276 | }, options);
|
10277 |
|
10278 | _this._element = opt.element;
|
10279 | _this._initialFov = opt.fov;
|
10280 | _this._enabled = false;
|
10281 | _this._isAnimating = false;
|
10282 | _this._deviceQuaternion = null;
|
10283 |
|
10284 | _this._initAxes(opt);
|
10285 |
|
10286 | _this.option(opt);
|
10287 |
|
10288 | return _this;
|
10289 | }
|
10290 | |
10291 |
|
10292 |
|
10293 |
|
10294 |
|
10295 |
|
10296 |
|
10297 |
|
10298 |
|
10299 | var __proto = YawPitchControl.prototype;
|
10300 |
|
10301 | __proto.updatePanScale = function (param) {
|
10302 | if (param === void 0) {
|
10303 | param = {};
|
10304 | }
|
10305 |
|
10306 | var fov = this._axes.get().fov;
|
10307 |
|
10308 | var areaHeight = param.height || parseInt(window.getComputedStyle(this._element).height, 10);
|
10309 | var scale = MC_BIND_SCALE[0] * fov / this._initialFov * PAN_SCALE / areaHeight;
|
10310 | this._axesPanInput.options.scale = [scale, scale];
|
10311 | this._axes.options.deceleration = MC_DECELERATION * fov / MAX_FIELD_OF_VIEW;
|
10312 | return this;
|
10313 | };
|
10314 | |
10315 |
|
10316 |
|
10317 |
|
10318 |
|
10319 |
|
10320 |
|
10321 |
|
10322 | __proto.option = function (key, newValue) {
|
10323 |
|
10324 | if (!key) {
|
10325 | return this._getOptions();
|
10326 | } else if (key && typeof key === "string" && typeof newValue === "undefined") {
|
10327 | return this._getOptions(key);
|
10328 | }
|
10329 |
|
10330 |
|
10331 | var newOptions = {};
|
10332 | var changedKeyList = [];
|
10333 |
|
10334 | if (typeof key === "string") {
|
10335 | changedKeyList.push(key);
|
10336 | newOptions[key] = newValue;
|
10337 | } else {
|
10338 | var options = key;
|
10339 |
|
10340 | changedKeyList = Object.keys(options);
|
10341 | newOptions = __assign({}, options);
|
10342 | }
|
10343 |
|
10344 | this._setOptions(this._getValidatedOptions(newOptions));
|
10345 |
|
10346 | this._applyOptions(changedKeyList);
|
10347 |
|
10348 | return this;
|
10349 | };
|
10350 | |
10351 |
|
10352 |
|
10353 |
|
10354 |
|
10355 |
|
10356 | __proto.enable = function () {
|
10357 | if (this._enabled) {
|
10358 | return this;
|
10359 | }
|
10360 |
|
10361 | this._enabled = true;
|
10362 |
|
10363 | this._applyOptions(Object.keys(this.options));
|
10364 |
|
10365 |
|
10366 | this.updatePanScale();
|
10367 | return this;
|
10368 | };
|
10369 | |
10370 |
|
10371 |
|
10372 |
|
10373 |
|
10374 |
|
10375 | __proto.disable = function (persistOrientation) {
|
10376 | if (persistOrientation === void 0) {
|
10377 | persistOrientation = false;
|
10378 | }
|
10379 |
|
10380 | if (!this._enabled) {
|
10381 | return this;
|
10382 | }
|
10383 |
|
10384 |
|
10385 | if (!persistOrientation) {
|
10386 | this._resetOrientation();
|
10387 | }
|
10388 |
|
10389 | this._axes.disconnect();
|
10390 |
|
10391 | this._enabled = false;
|
10392 | return this;
|
10393 | };
|
10394 | |
10395 |
|
10396 |
|
10397 |
|
10398 |
|
10399 |
|
10400 |
|
10401 | __proto.lookAt = function (_a, duration) {
|
10402 | var yaw = _a.yaw,
|
10403 | pitch = _a.pitch,
|
10404 | fov = _a.fov;
|
10405 |
|
10406 | var pos = this._axes.get();
|
10407 |
|
10408 | var y = yaw === undefined ? 0 : yaw - pos.yaw;
|
10409 | var p = pitch === undefined ? 0 : pitch - pos.pitch;
|
10410 | var f = fov === undefined ? 0 : fov - pos.fov;
|
10411 |
|
10412 | this._axes.options.maximumDuration = Infinity;
|
10413 |
|
10414 | this._axes.setBy({
|
10415 | yaw: y,
|
10416 | pitch: p,
|
10417 | fov: f
|
10418 | }, duration);
|
10419 | };
|
10420 |
|
10421 | __proto.getYawPitch = function () {
|
10422 | var yawPitch = this._axes.get();
|
10423 |
|
10424 | return {
|
10425 | yaw: yawPitch.yaw,
|
10426 | pitch: yawPitch.pitch
|
10427 | };
|
10428 | };
|
10429 |
|
10430 | __proto.getFov = function () {
|
10431 | return this._axes.get().fov;
|
10432 | };
|
10433 |
|
10434 | __proto.getQuaternion = function () {
|
10435 | var pos = this._axes.get();
|
10436 |
|
10437 | return this._deviceQuaternion.getCombinedQuaternion(pos.yaw);
|
10438 | };
|
10439 |
|
10440 | __proto.shouldRenderWithQuaternion = function () {
|
10441 | return this.options.gyroMode === GYRO_MODE.VR;
|
10442 | };
|
10443 | |
10444 |
|
10445 |
|
10446 |
|
10447 |
|
10448 | __proto.destroy = function () {
|
10449 |
|
10450 | this._axes && this._axes.destroy();
|
10451 | this._axesPanInput && this._axesPanInput.destroy();
|
10452 | this._axesWheelInput && this._axesWheelInput.destroy();
|
10453 | this._axesTiltMotionInput && this._axesTiltMotionInput.destroy();
|
10454 | this._axesPinchInput && this._axesPinchInput.destroy();
|
10455 | this._axesMoveKeyInput && this._axesMoveKeyInput.destroy();
|
10456 | this._deviceQuaternion && this._deviceQuaternion.destroy();
|
10457 |
|
10458 | };
|
10459 |
|
10460 | __proto._initAxes = function (opt) {
|
10461 | var _this = this;
|
10462 |
|
10463 | var yRange = this._updateYawRange(opt.yawRange, opt.fov, opt.aspectRatio);
|
10464 |
|
10465 | var pRange = this._updatePitchRange(opt.pitchRange, opt.fov, opt.showPolePoint);
|
10466 |
|
10467 | var useRotation = opt.gyroMode === GYRO_MODE.VR;
|
10468 | this._axesPanInput = new RotationPanInput(this._element, {
|
10469 | useRotation: useRotation
|
10470 | });
|
10471 | this._axesWheelInput = new WheelInput(this._element, {
|
10472 | scale: -4
|
10473 | });
|
10474 | this._axesTiltMotionInput = null;
|
10475 | this._axesPinchInput = SUPPORT_TOUCH ? new PinchInput(this._element, {
|
10476 | scale: -1
|
10477 | }) : null;
|
10478 | this._axesMoveKeyInput = new MoveKeyInput(this._element, {
|
10479 | scale: [-6, 6]
|
10480 | });
|
10481 | this._axes = new Axes({
|
10482 | yaw: {
|
10483 | range: yRange,
|
10484 | circular: this._isCircular(yRange),
|
10485 | bounce: [0, 0]
|
10486 | },
|
10487 | pitch: {
|
10488 | range: pRange,
|
10489 | circular: this._isCircular(pRange),
|
10490 | bounce: [0, 0]
|
10491 | },
|
10492 | fov: {
|
10493 | range: opt.fovRange,
|
10494 | circular: [false, false],
|
10495 | bounce: [0, 0]
|
10496 | }
|
10497 | }, {
|
10498 | deceleration: MC_DECELERATION,
|
10499 | maximumDuration: MC_MAXIMUM_DURATION
|
10500 | }, {
|
10501 | yaw: opt.yaw,
|
10502 | pitch: opt.pitch,
|
10503 | fov: opt.fov
|
10504 | }).on({
|
10505 |
|
10506 | hold: function (evt) {
|
10507 |
|
10508 | _this._axes.options.maximumDuration = MC_MAXIMUM_DURATION;
|
10509 |
|
10510 | _this.trigger(new ComponentEvent$1("hold", {
|
10511 | isTrusted: evt.isTrusted
|
10512 | }));
|
10513 | },
|
10514 | change: function (evt) {
|
10515 | if (evt.delta.fov !== 0) {
|
10516 | _this._updateControlScale(evt);
|
10517 |
|
10518 | _this.updatePanScale();
|
10519 | }
|
10520 |
|
10521 | _this._triggerChange(evt);
|
10522 | },
|
10523 | release: function (evt) {
|
10524 | _this._triggerChange(evt);
|
10525 | },
|
10526 | animationEnd: function (evt) {
|
10527 | _this.trigger(new ComponentEvent$1("animationEnd", {
|
10528 | isTrusted: evt.isTrusted
|
10529 | }));
|
10530 | }
|
10531 | });
|
10532 | };
|
10533 |
|
10534 | __proto._getValidatedOptions = function (newOptions) {
|
10535 | if (newOptions.yawRange) {
|
10536 | newOptions.yawRange = this._getValidYawRange(newOptions.yawRange, newOptions.fov, newOptions.aspectRatio);
|
10537 | }
|
10538 |
|
10539 | if (newOptions.pitchRange) {
|
10540 | newOptions.pitchRange = this._getValidPitchRange(newOptions.pitchRange, newOptions.fov);
|
10541 | }
|
10542 |
|
10543 | return newOptions;
|
10544 | };
|
10545 |
|
10546 | __proto._getOptions = function (key) {
|
10547 | var value;
|
10548 |
|
10549 | if (typeof key === "string") {
|
10550 | value = this.options[key];
|
10551 | } else if (arguments.length === 0) {
|
10552 | value = this.options;
|
10553 | }
|
10554 |
|
10555 | return value;
|
10556 | };
|
10557 |
|
10558 | __proto._setOptions = function (options) {
|
10559 | for (var key in options) {
|
10560 | this.options[key] = options[key];
|
10561 | }
|
10562 | };
|
10563 |
|
10564 | __proto._applyOptions = function (keys) {
|
10565 | var options = this.options;
|
10566 | var axes = this._axes;
|
10567 | var isVR = options.gyroMode === GYRO_MODE.VR;
|
10568 | var isYawPitch = options.gyroMode === GYRO_MODE.YAWPITCH;
|
10569 |
|
10570 | var touchDirection = isVR ? TOUCH_DIRECTION_YAW & options.touchDirection : options.touchDirection;
|
10571 |
|
10572 | if (keys.some(function (key) {
|
10573 | return key === "showPolePoint" || key === "fov" || key === "aspectRatio" || key === "yawRange" || key === "pitchRange";
|
10574 | })) {
|
10575 |
|
10576 | if (keys.indexOf("fov") >= 0) {
|
10577 | axes.setTo({
|
10578 | "fov": options.fov
|
10579 | });
|
10580 | this.updatePanScale();
|
10581 | }
|
10582 |
|
10583 | this._updateControlScale();
|
10584 | }
|
10585 |
|
10586 | if (keys.some(function (key) {
|
10587 | return key === "fovRange";
|
10588 | })) {
|
10589 | var fovRange = options.fovRange;
|
10590 | var prevFov = axes.get().fov;
|
10591 | var nextFov = axes.get().fov;
|
10592 | copy$3(axes.axis.fov.range, fovRange);
|
10593 |
|
10594 | if (nextFov < fovRange[0]) {
|
10595 | nextFov = fovRange[0];
|
10596 | } else if (prevFov > fovRange[1]) {
|
10597 | nextFov = fovRange[1];
|
10598 | }
|
10599 |
|
10600 | if (prevFov !== nextFov) {
|
10601 | axes.setTo({
|
10602 | fov: nextFov
|
10603 | }, 0);
|
10604 |
|
10605 | this._updateControlScale();
|
10606 |
|
10607 | this.updatePanScale();
|
10608 | }
|
10609 | }
|
10610 |
|
10611 | if (keys.some(function (key) {
|
10612 | return key === "gyroMode";
|
10613 | }) && SUPPORT_DEVICEMOTION) {
|
10614 |
|
10615 | if (this._axesTiltMotionInput) {
|
10616 | this._axes.disconnect(this._axesTiltMotionInput);
|
10617 |
|
10618 | this._axesTiltMotionInput.destroy();
|
10619 |
|
10620 | this._axesTiltMotionInput = null;
|
10621 | }
|
10622 |
|
10623 | if (this._deviceQuaternion) {
|
10624 | this._deviceQuaternion.destroy();
|
10625 |
|
10626 | this._deviceQuaternion = null;
|
10627 | }
|
10628 |
|
10629 | if (isVR) {
|
10630 | this._initDeviceQuaternion();
|
10631 | } else if (isYawPitch) {
|
10632 | this._axesTiltMotionInput = new TiltMotionInput(this._element);
|
10633 |
|
10634 | this._axes.connect(["yaw", "pitch"], this._axesTiltMotionInput);
|
10635 | }
|
10636 |
|
10637 | this._axesPanInput.setUseRotation(isVR);
|
10638 | }
|
10639 |
|
10640 | if (keys.some(function (key) {
|
10641 | return key === "useKeyboard";
|
10642 | })) {
|
10643 | var useKeyboard = options.useKeyboard;
|
10644 |
|
10645 | if (useKeyboard) {
|
10646 | axes.connect(["yaw", "pitch"], this._axesMoveKeyInput);
|
10647 | } else {
|
10648 | axes.disconnect(this._axesMoveKeyInput);
|
10649 | }
|
10650 | }
|
10651 |
|
10652 | if (keys.some(function (key) {
|
10653 | return key === "useZoom";
|
10654 | })) {
|
10655 | var useZoom = options.useZoom;
|
10656 |
|
10657 | axes.disconnect(this._axesWheelInput);
|
10658 |
|
10659 | if (useZoom) {
|
10660 | axes.connect(["fov"], this._axesWheelInput);
|
10661 | }
|
10662 | }
|
10663 |
|
10664 | this._togglePinchInputByOption(options.touchDirection, options.useZoom);
|
10665 |
|
10666 | if (keys.some(function (key) {
|
10667 | return key === "touchDirection";
|
10668 | }) && this._enabled) {
|
10669 | this._enableTouch(touchDirection);
|
10670 | }
|
10671 | };
|
10672 |
|
10673 | __proto._togglePinchInputByOption = function (touchDirection, useZoom) {
|
10674 | if (this._axesPinchInput) {
|
10675 |
|
10676 | this._axes.disconnect(this._axesPinchInput);
|
10677 |
|
10678 |
|
10679 | if (useZoom && touchDirection === TOUCH_DIRECTION_ALL &&
|
10680 | this._axes._inputs.indexOf(this._axesPinchInput) === -1) {
|
10681 | this._axes.connect(["fov"], this._axesPinchInput);
|
10682 | }
|
10683 | }
|
10684 | };
|
10685 |
|
10686 | __proto._enableTouch = function (direction) {
|
10687 |
|
10688 | if (this._axesPanInput) {
|
10689 | this._axes.disconnect(this._axesPanInput);
|
10690 | }
|
10691 |
|
10692 | var yawEnabled = direction & TOUCH_DIRECTION_YAW ? "yaw" : null;
|
10693 | var pitchEnabled = direction & TOUCH_DIRECTION_PITCH ? "pitch" : null;
|
10694 |
|
10695 | this._axes.connect([yawEnabled, pitchEnabled], this._axesPanInput);
|
10696 | };
|
10697 |
|
10698 | __proto._initDeviceQuaternion = function () {
|
10699 | var _this = this;
|
10700 |
|
10701 | this._deviceQuaternion = new DeviceQuaternion();
|
10702 |
|
10703 | this._deviceQuaternion.on("change", function (e) {
|
10704 | _this._triggerChange(e);
|
10705 | });
|
10706 | };
|
10707 |
|
10708 | __proto._getValidYawRange = function (newYawRange, newFov, newAspectRatio) {
|
10709 | var ratio = this._adjustAspectRatio(newAspectRatio || this.options.aspectRatio || 1);
|
10710 |
|
10711 | var fov = newFov || this._axes.get().fov;
|
10712 |
|
10713 | var horizontalFov = fov * ratio;
|
10714 | var isValid = newYawRange[1] - newYawRange[0] >= horizontalFov;
|
10715 |
|
10716 | if (isValid) {
|
10717 | return newYawRange;
|
10718 | } else {
|
10719 | return this.options.yawRange || DEFAULT_YAW_RANGE;
|
10720 | }
|
10721 | };
|
10722 |
|
10723 | __proto._getValidPitchRange = function (newPitchRange, newFov) {
|
10724 | var fov = newFov || this._axes.get().fov;
|
10725 |
|
10726 | var isValid = newPitchRange[1] - newPitchRange[0] >= fov;
|
10727 |
|
10728 | if (isValid) {
|
10729 | return newPitchRange;
|
10730 | } else {
|
10731 | return this.options.pitchRange || DEFAULT_PITCH_RANGE;
|
10732 | }
|
10733 | };
|
10734 |
|
10735 | __proto._isCircular = function (range) {
|
10736 | return range[1] - range[0] < 360 ? [false, false] : [true, true];
|
10737 | };
|
10738 | |
10739 |
|
10740 |
|
10741 |
|
10742 |
|
10743 |
|
10744 |
|
10745 |
|
10746 |
|
10747 |
|
10748 |
|
10749 |
|
10750 |
|
10751 | __proto._updateControlScale = function (changeEvt) {
|
10752 | var opt = this.options;
|
10753 |
|
10754 | var fov = this._axes.get().fov;
|
10755 |
|
10756 | var pRange = this._updatePitchRange(opt.pitchRange, fov, opt.showPolePoint);
|
10757 |
|
10758 | var yRange = this._updateYawRange(opt.yawRange, fov, opt.aspectRatio);
|
10759 |
|
10760 |
|
10761 | var pos = this._axes.get();
|
10762 |
|
10763 | var y = pos.yaw;
|
10764 | var p = pos.pitch;
|
10765 | copy$3(this._axes.axis.yaw.range, yRange);
|
10766 | copy$3(this._axes.axis.pitch.range, pRange);
|
10767 | this._axes.axis.yaw.circular = this._isCircular(yRange);
|
10768 | this._axes.axis.pitch.circular = this._isCircular(pRange);
|
10769 | |
10770 |
|
10771 |
|
10772 |
|
10773 | if (y < yRange[0]) {
|
10774 | y = yRange[0];
|
10775 | } else if (y > yRange[1]) {
|
10776 | y = yRange[1];
|
10777 | }
|
10778 |
|
10779 | if (p < pRange[0]) {
|
10780 | p = pRange[0];
|
10781 | } else if (p > pRange[1]) {
|
10782 | p = pRange[1];
|
10783 | }
|
10784 |
|
10785 | if (changeEvt) {
|
10786 | changeEvt.set({
|
10787 | yaw: y,
|
10788 | pitch: p
|
10789 | });
|
10790 | }
|
10791 |
|
10792 | this._axes.setTo({
|
10793 | yaw: y,
|
10794 | pitch: p
|
10795 | }, 0);
|
10796 |
|
10797 | return this;
|
10798 | };
|
10799 |
|
10800 | __proto._updatePitchRange = function (pitchRange, fov, showPolePoint) {
|
10801 | if (this.options.gyroMode === GYRO_MODE.VR) {
|
10802 |
|
10803 | return CIRCULAR_PITCH_RANGE;
|
10804 | }
|
10805 |
|
10806 | var verticalAngle = pitchRange[1] - pitchRange[0];
|
10807 | var halfFov = fov / 2;
|
10808 | var isPanorama = verticalAngle < 180;
|
10809 |
|
10810 | if (showPolePoint && !isPanorama) {
|
10811 |
|
10812 | return pitchRange.concat();
|
10813 | }
|
10814 |
|
10815 |
|
10816 | return [pitchRange[0] + halfFov, pitchRange[1] - halfFov];
|
10817 | };
|
10818 |
|
10819 | __proto._updateYawRange = function (yawRange, fov, aspectRatio) {
|
10820 | if (this.options.gyroMode === GYRO_MODE.VR) {
|
10821 | return DEFAULT_YAW_RANGE;
|
10822 | }
|
10823 |
|
10824 | var horizontalAngle = yawRange[1] - yawRange[0];
|
10825 | |
10826 |
|
10827 |
|
10828 |
|
10829 | if (horizontalAngle >= 360) {
|
10830 |
|
10831 | return yawRange.concat();
|
10832 | }
|
10833 | |
10834 |
|
10835 |
|
10836 |
|
10837 |
|
10838 |
|
10839 | var halfHorizontalFov = util.toDegree(Math.atan2(aspectRatio, 1 / Math.tan(toRadian(fov / 2))));
|
10840 |
|
10841 | return [yawRange[0] + halfHorizontalFov, yawRange[1] - halfHorizontalFov];
|
10842 | };
|
10843 |
|
10844 |
|
10845 | __proto._triggerChange = function (evt) {
|
10846 | var pos = this._axes.get();
|
10847 |
|
10848 | var opt = this.options;
|
10849 | var event = {
|
10850 | targetElement: opt.element,
|
10851 | isTrusted: evt.isTrusted,
|
10852 | yaw: pos.yaw,
|
10853 | pitch: pos.pitch,
|
10854 | fov: pos.fov,
|
10855 | quaternion: null
|
10856 | };
|
10857 |
|
10858 | if (opt.gyroMode === GYRO_MODE.VR && this._deviceQuaternion) {
|
10859 | event.quaternion = this._deviceQuaternion.getCombinedQuaternion(pos.yaw);
|
10860 | }
|
10861 |
|
10862 | this.trigger(new ComponentEvent$1("change", event));
|
10863 | };
|
10864 |
|
10865 |
|
10866 | __proto._adjustAspectRatio = function (input) {
|
10867 | var inputRange = [0.520, 0.540, 0.563, 0.570, 0.584, 0.590, 0.609, 0.670, 0.702, 0.720, 0.760, 0.780, 0.820, 0.920, 0.970, 1.00, 1.07, 1.14, 1.19, 1.25, 1.32, 1.38, 1.40, 1.43, 1.53, 1.62, 1.76, 1.77, 1.86, 1.96, 2.26, 2.30, 2.60, 3.00, 5.00, 6.00];
|
10868 | var outputRange = [0.510, 0.540, 0.606, 0.560, 0.628, 0.630, 0.647, 0.710, 0.736, 0.757, 0.780, 0.770, 0.800, 0.890, 0.975, 1.00, 1.07, 1.10, 1.15, 1.18, 1.22, 1.27, 1.30, 1.33, 1.39, 1.45, 1.54, 1.55, 1.58, 1.62, 1.72, 1.82, 1.92, 2.00, 2.24, 2.30];
|
10869 | var rangeIdx = -1;
|
10870 |
|
10871 | for (var i = 0; i < inputRange.length - 1; i++) {
|
10872 | if (inputRange[i] <= input && inputRange[i + 1] >= input) {
|
10873 | rangeIdx = i;
|
10874 | break;
|
10875 | }
|
10876 | }
|
10877 |
|
10878 | if (rangeIdx === -1) {
|
10879 | if (inputRange[0] > input) {
|
10880 | return outputRange[0];
|
10881 | } else {
|
10882 |
|
10883 | return outputRange[outputRange[0].length - 1];
|
10884 | }
|
10885 | }
|
10886 |
|
10887 | var inputA = inputRange[rangeIdx];
|
10888 | var inputB = inputRange[rangeIdx + 1];
|
10889 | var outputA = outputRange[rangeIdx];
|
10890 | var outputB = outputRange[rangeIdx + 1];
|
10891 | return this._lerp(outputA, outputB, (input - inputA) / (inputB - inputA));
|
10892 | };
|
10893 |
|
10894 | __proto._lerp = function (a, b, fraction) {
|
10895 | return a + fraction * (b - a);
|
10896 | };
|
10897 |
|
10898 | __proto._resetOrientation = function () {
|
10899 | var opt = this.options;
|
10900 |
|
10901 | this._axes.setTo({
|
10902 | yaw: opt.yaw,
|
10903 | pitch: opt.pitch,
|
10904 | fov: opt.fov
|
10905 | }, 0);
|
10906 |
|
10907 | return this;
|
10908 | };
|
10909 |
|
10910 | YawPitchControl.VERSION = VERSION;
|
10911 |
|
10912 | YawPitchControl.CONTROL_MODE_VR = CONTROL_MODE_VR;
|
10913 | YawPitchControl.CONTROL_MODE_YAWPITCH = CONTROL_MODE_YAWPITCH;
|
10914 | YawPitchControl.TOUCH_DIRECTION_ALL = TOUCH_DIRECTION_ALL;
|
10915 | YawPitchControl.TOUCH_DIRECTION_YAW = TOUCH_DIRECTION_YAW;
|
10916 | YawPitchControl.TOUCH_DIRECTION_PITCH = TOUCH_DIRECTION_PITCH;
|
10917 | YawPitchControl.TOUCH_DIRECTION_NONE = TOUCH_DIRECTION_NONE;
|
10918 | return YawPitchControl;
|
10919 | }(Component);
|
10920 |
|
10921 | |
10922 |
|
10923 |
|
10924 |
|
10925 |
|
10926 |
|
10927 |
|
10928 |
|
10929 | |
10930 |
|
10931 |
|
10932 |
|
10933 |
|
10934 |
|
10935 |
|
10936 |
|
10937 |
|
10938 |
|
10939 |
|
10940 |
|
10941 |
|
10942 |
|
10943 | function __values$3(o) {
|
10944 | var s = typeof Symbol === "function" && Symbol.iterator,
|
10945 | m = s && o[s],
|
10946 | i = 0;
|
10947 | if (m) return m.call(o);
|
10948 | if (o && typeof o.length === "number") return {
|
10949 | next: function () {
|
10950 | if (o && i >= o.length) o = void 0;
|
10951 | return {
|
10952 | value: o && o[i++],
|
10953 | done: !o
|
10954 | };
|
10955 | }
|
10956 | };
|
10957 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
10958 | }
|
10959 |
|
10960 | |
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 | function isUndefined$2(value) {
|
10966 | return typeof value === "undefined";
|
10967 | }
|
10968 | |
10969 |
|
10970 |
|
10971 |
|
10972 |
|
10973 |
|
10974 |
|
10975 | var Component$2 =
|
10976 |
|
10977 | function () {
|
10978 | |
10979 |
|
10980 |
|
10981 | function Component() {
|
10982 | |
10983 |
|
10984 |
|
10985 |
|
10986 | this.options = {};
|
10987 | this._eventHandler = {};
|
10988 | }
|
10989 | |
10990 |
|
10991 |
|
10992 |
|
10993 |
|
10994 |
|
10995 |
|
10996 |
|
10997 |
|
10998 |
|
10999 |
|
11000 |
|
11001 |
|
11002 |
|
11003 |
|
11004 |
|
11005 |
|
11006 |
|
11007 |
|
11008 |
|
11009 |
|
11010 |
|
11011 |
|
11012 |
|
11013 |
|
11014 |
|
11015 |
|
11016 |
|
11017 |
|
11018 |
|
11019 |
|
11020 |
|
11021 |
|
11022 | var __proto = Component.prototype;
|
11023 |
|
11024 | __proto.trigger = function (eventName) {
|
11025 | var _this = this;
|
11026 |
|
11027 | var params = [];
|
11028 |
|
11029 | for (var _i = 1; _i < arguments.length; _i++) {
|
11030 | params[_i - 1] = arguments[_i];
|
11031 | }
|
11032 |
|
11033 | var handlerList = this._eventHandler[eventName] || [];
|
11034 | var hasHandlerList = handlerList.length > 0;
|
11035 |
|
11036 | if (!hasHandlerList) {
|
11037 | return true;
|
11038 | }
|
11039 |
|
11040 | var customEvent = params[0] || {};
|
11041 | var restParams = params.slice(1);
|
11042 |
|
11043 | handlerList = handlerList.concat();
|
11044 | var isCanceled = false;
|
11045 |
|
11046 | customEvent.eventType = eventName;
|
11047 |
|
11048 | customEvent.stop = function () {
|
11049 | isCanceled = true;
|
11050 | };
|
11051 |
|
11052 | customEvent.currentTarget = this;
|
11053 | var arg = [customEvent];
|
11054 |
|
11055 | if (restParams.length >= 1) {
|
11056 | arg = arg.concat(restParams);
|
11057 | }
|
11058 |
|
11059 | handlerList.forEach(function (handler) {
|
11060 | handler.apply(_this, arg);
|
11061 | });
|
11062 | return !isCanceled;
|
11063 | };
|
11064 | |
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 |
|
11070 |
|
11071 |
|
11072 |
|
11073 |
|
11074 |
|
11075 |
|
11076 |
|
11077 |
|
11078 |
|
11079 |
|
11080 |
|
11081 |
|
11082 |
|
11083 |
|
11084 |
|
11085 |
|
11086 |
|
11087 |
|
11088 |
|
11089 |
|
11090 | __proto.once = function (eventName, handlerToAttach) {
|
11091 | var _this = this;
|
11092 |
|
11093 | if (typeof eventName === "object" && isUndefined$2(handlerToAttach)) {
|
11094 | var eventHash = eventName;
|
11095 |
|
11096 | for (var key in eventHash) {
|
11097 | this.once(key, eventHash[key]);
|
11098 | }
|
11099 |
|
11100 | return this;
|
11101 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
11102 | var listener_1 = function () {
|
11103 | var args = [];
|
11104 |
|
11105 | for (var _i = 0; _i < arguments.length; _i++) {
|
11106 | args[_i] = arguments[_i];
|
11107 | }
|
11108 |
|
11109 | handlerToAttach.apply(_this, args);
|
11110 |
|
11111 | _this.off(eventName, listener_1);
|
11112 | };
|
11113 |
|
11114 | this.on(eventName, listener_1);
|
11115 | }
|
11116 |
|
11117 | return this;
|
11118 | };
|
11119 | |
11120 |
|
11121 |
|
11122 |
|
11123 |
|
11124 |
|
11125 |
|
11126 |
|
11127 |
|
11128 |
|
11129 |
|
11130 |
|
11131 |
|
11132 |
|
11133 |
|
11134 |
|
11135 | __proto.hasOn = function (eventName) {
|
11136 | return !!this._eventHandler[eventName];
|
11137 | };
|
11138 | |
11139 |
|
11140 |
|
11141 |
|
11142 |
|
11143 |
|
11144 |
|
11145 |
|
11146 |
|
11147 |
|
11148 |
|
11149 |
|
11150 |
|
11151 |
|
11152 |
|
11153 |
|
11154 |
|
11155 |
|
11156 |
|
11157 |
|
11158 | __proto.on = function (eventName, handlerToAttach) {
|
11159 | if (typeof eventName === "object" && isUndefined$2(handlerToAttach)) {
|
11160 | var eventHash = eventName;
|
11161 |
|
11162 | for (var name in eventHash) {
|
11163 | this.on(name, eventHash[name]);
|
11164 | }
|
11165 |
|
11166 | return this;
|
11167 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
11168 | var handlerList = this._eventHandler[eventName];
|
11169 |
|
11170 | if (isUndefined$2(handlerList)) {
|
11171 | this._eventHandler[eventName] = [];
|
11172 | handlerList = this._eventHandler[eventName];
|
11173 | }
|
11174 |
|
11175 | handlerList.push(handlerToAttach);
|
11176 | }
|
11177 |
|
11178 | return this;
|
11179 | };
|
11180 | |
11181 |
|
11182 |
|
11183 |
|
11184 |
|
11185 |
|
11186 |
|
11187 |
|
11188 |
|
11189 |
|
11190 |
|
11191 |
|
11192 |
|
11193 |
|
11194 |
|
11195 |
|
11196 |
|
11197 |
|
11198 |
|
11199 |
|
11200 | __proto.off = function (eventName, handlerToDetach) {
|
11201 | var e_1, _a;
|
11202 |
|
11203 |
|
11204 | if (isUndefined$2(eventName)) {
|
11205 | this._eventHandler = {};
|
11206 | return this;
|
11207 | }
|
11208 |
|
11209 |
|
11210 | if (isUndefined$2(handlerToDetach)) {
|
11211 | if (typeof eventName === "string") {
|
11212 | delete this._eventHandler[eventName];
|
11213 | return this;
|
11214 | } else {
|
11215 | var eventHash = eventName;
|
11216 |
|
11217 | for (var name in eventHash) {
|
11218 | this.off(name, eventHash[name]);
|
11219 | }
|
11220 |
|
11221 | return this;
|
11222 | }
|
11223 | }
|
11224 |
|
11225 |
|
11226 | var handlerList = this._eventHandler[eventName];
|
11227 |
|
11228 | if (handlerList) {
|
11229 | var idx = 0;
|
11230 |
|
11231 | try {
|
11232 | for (var handlerList_1 = __values$3(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
11233 | var handlerFunction = handlerList_1_1.value;
|
11234 |
|
11235 | if (handlerFunction === handlerToDetach) {
|
11236 | handlerList.splice(idx, 1);
|
11237 | break;
|
11238 | }
|
11239 |
|
11240 | idx++;
|
11241 | }
|
11242 | } catch (e_1_1) {
|
11243 | e_1 = {
|
11244 | error: e_1_1
|
11245 | };
|
11246 | } finally {
|
11247 | try {
|
11248 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
11249 | } finally {
|
11250 | if (e_1) throw e_1.error;
|
11251 | }
|
11252 | }
|
11253 | }
|
11254 |
|
11255 | return this;
|
11256 | };
|
11257 | |
11258 |
|
11259 |
|
11260 |
|
11261 |
|
11262 |
|
11263 |
|
11264 |
|
11265 |
|
11266 |
|
11267 |
|
11268 | Component.VERSION = "2.2.2";
|
11269 | return Component;
|
11270 | }();
|
11271 |
|
11272 | |
11273 |
|
11274 |
|
11275 |
|
11276 |
|
11277 |
|
11278 |
|
11279 |
|
11280 |
|
11281 | |
11282 |
|
11283 |
|
11284 |
|
11285 |
|
11286 |
|
11287 |
|
11288 |
|
11289 |
|
11290 |
|
11291 |
|
11292 |
|
11293 |
|
11294 |
|
11295 |
|
11296 |
|
11297 | var extendStatics$2 = function (d, b) {
|
11298 | extendStatics$2 = Object.setPrototypeOf || {
|
11299 | __proto__: []
|
11300 | } instanceof Array && function (d, b) {
|
11301 | d.__proto__ = b;
|
11302 | } || function (d, b) {
|
11303 | for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
11304 | };
|
11305 |
|
11306 | return extendStatics$2(d, b);
|
11307 | };
|
11308 |
|
11309 | function __extends$2(d, b) {
|
11310 | extendStatics$2(d, b);
|
11311 |
|
11312 | function __() {
|
11313 | this.constructor = d;
|
11314 | }
|
11315 |
|
11316 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
11317 | }
|
11318 | var __assign$2 = function () {
|
11319 | __assign$2 = Object.assign || function __assign(t) {
|
11320 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
11321 | s = arguments[i];
|
11322 |
|
11323 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
11324 | }
|
11325 |
|
11326 | return t;
|
11327 | };
|
11328 |
|
11329 | return __assign$2.apply(this, arguments);
|
11330 | };
|
11331 | function __spreadArrays() {
|
11332 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
11333 |
|
11334 | for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
|
11335 |
|
11336 | return r;
|
11337 | }
|
11338 |
|
11339 | |
11340 |
|
11341 |
|
11342 |
|
11343 |
|
11344 | var isWindow = typeof window !== "undefined";
|
11345 | var ua = isWindow ? window.navigator.userAgent : "";
|
11346 | var SUPPORT_COMPUTEDSTYLE = isWindow ? !!("getComputedStyle" in window) : false;
|
11347 | var IS_IE = /MSIE|Trident|Windows Phone|Edge/.test(ua);
|
11348 | var SUPPORT_ADDEVENTLISTENER = isWindow ? !!("addEventListener" in document) : false;
|
11349 | var WIDTH = "width";
|
11350 | var HEIGHT = "height";
|
11351 |
|
11352 | function getAttribute(el, name) {
|
11353 | return el.getAttribute(name) || "";
|
11354 | }
|
11355 | function toArray$2(arr) {
|
11356 | return [].slice.call(arr);
|
11357 | }
|
11358 | function hasSizeAttribute(target, prefix) {
|
11359 | if (prefix === void 0) {
|
11360 | prefix = "data-";
|
11361 | }
|
11362 |
|
11363 | return !!target.getAttribute(prefix + "width");
|
11364 | }
|
11365 | function hasLoadingAttribute(target) {
|
11366 | return "loading" in target && target.getAttribute("loading") === "lazy";
|
11367 | }
|
11368 | function hasSkipAttribute(target, prefix) {
|
11369 | if (prefix === void 0) {
|
11370 | prefix = "data-";
|
11371 | }
|
11372 |
|
11373 | return !!target.getAttribute(prefix + "skip");
|
11374 | }
|
11375 | function addEvent(element, type, handler) {
|
11376 | if (SUPPORT_ADDEVENTLISTENER) {
|
11377 | element.addEventListener(type, handler, false);
|
11378 | } else if (element.attachEvent) {
|
11379 | element.attachEvent("on" + type, handler);
|
11380 | } else {
|
11381 | element["on" + type] = handler;
|
11382 | }
|
11383 | }
|
11384 | function removeEvent(element, type, handler) {
|
11385 | if (element.removeEventListener) {
|
11386 | element.removeEventListener(type, handler, false);
|
11387 | } else if (element.detachEvent) {
|
11388 | element.detachEvent("on" + type, handler);
|
11389 | } else {
|
11390 | element["on" + type] = null;
|
11391 | }
|
11392 | }
|
11393 | function innerWidth(el) {
|
11394 | return getSize(el, "Width");
|
11395 | }
|
11396 | function innerHeight(el) {
|
11397 | return getSize(el, "Height");
|
11398 | }
|
11399 | function getStyles(el) {
|
11400 | return (SUPPORT_COMPUTEDSTYLE ? window.getComputedStyle(el) : el.currentStyle) || {};
|
11401 | }
|
11402 |
|
11403 | function getSize(el, name) {
|
11404 | var size = el["client" + name] || el["offset" + name];
|
11405 | return parseFloat(size || getStyles(el)[name.toLowerCase()]) || 0;
|
11406 | }
|
11407 |
|
11408 | function getContentElements(element, tags, prefix) {
|
11409 | var skipElements = toArray$2(element.querySelectorAll(__spreadArrays(["[" + prefix + "skip] [" + prefix + "width]"], tags.map(function (tag) {
|
11410 | return ["[" + prefix + "skip] " + tag, tag + "[" + prefix + "skip]", "[" + prefix + "width] " + tag].join(", ");
|
11411 | })).join(", ")));
|
11412 | return toArray$2(element.querySelectorAll("[" + prefix + "width], " + tags.join(", "))).filter(function (el) {
|
11413 | return skipElements.indexOf(el) === -1;
|
11414 | });
|
11415 | }
|
11416 |
|
11417 | |
11418 |
|
11419 |
|
11420 |
|
11421 |
|
11422 | var elements = [];
|
11423 | function addAutoSizer(element, prefix) {
|
11424 | !elements.length && addEvent(window, "resize", resizeAllAutoSizers);
|
11425 | element.__PREFIX__ = prefix;
|
11426 | elements.push(element);
|
11427 | resize(element);
|
11428 | }
|
11429 | function removeAutoSizer(element, prefix) {
|
11430 | var index = elements.indexOf(element);
|
11431 |
|
11432 | if (index < 0) {
|
11433 | return;
|
11434 | }
|
11435 |
|
11436 | var fixed = getAttribute(element, prefix + "fixed");
|
11437 | delete element.__PREFIX__;
|
11438 | element.style[fixed === HEIGHT ? WIDTH : HEIGHT] = "";
|
11439 | elements.splice(index, 1);
|
11440 | !elements.length && removeEvent(window, "resize", resizeAllAutoSizers);
|
11441 | }
|
11442 |
|
11443 | function resize(element, prefix) {
|
11444 | if (prefix === void 0) {
|
11445 | prefix = "data-";
|
11446 | }
|
11447 |
|
11448 | var elementPrefix = element.__PREFIX__ || prefix;
|
11449 | var dataWidth = parseInt(getAttribute(element, "" + elementPrefix + WIDTH), 10) || 0;
|
11450 | var dataHeight = parseInt(getAttribute(element, "" + elementPrefix + HEIGHT), 10) || 0;
|
11451 | var fixed = getAttribute(element, elementPrefix + "fixed");
|
11452 |
|
11453 | if (fixed === HEIGHT) {
|
11454 | var size = innerHeight(element) || dataHeight;
|
11455 | element.style[WIDTH] = dataWidth / dataHeight * size + "px";
|
11456 | } else {
|
11457 | var size = innerWidth(element) || dataWidth;
|
11458 | element.style[HEIGHT] = dataHeight / dataWidth * size + "px";
|
11459 | }
|
11460 | }
|
11461 |
|
11462 | function resizeAllAutoSizers() {
|
11463 | elements.forEach(function (element) {
|
11464 | resize(element);
|
11465 | });
|
11466 | }
|
11467 |
|
11468 | var Loader =
|
11469 |
|
11470 | function (_super) {
|
11471 | __extends$2(Loader, _super);
|
11472 |
|
11473 | function Loader(element, options) {
|
11474 | if (options === void 0) {
|
11475 | options = {};
|
11476 | }
|
11477 |
|
11478 | var _this = _super.call(this) || this;
|
11479 |
|
11480 | _this.isReady = false;
|
11481 | _this.isPreReady = false;
|
11482 | _this.hasDataSize = false;
|
11483 | _this.hasLoading = false;
|
11484 | _this.isSkip = false;
|
11485 |
|
11486 | _this.onCheck = function (e) {
|
11487 | _this.clear();
|
11488 |
|
11489 | if (e && e.type === "error") {
|
11490 | _this.onError(_this.element);
|
11491 | }
|
11492 |
|
11493 |
|
11494 | var withPreReady = !_this.hasDataSize && !_this.hasLoading;
|
11495 |
|
11496 | _this.onReady(withPreReady);
|
11497 | };
|
11498 |
|
11499 | _this.options = __assign$2({
|
11500 | prefix: "data-"
|
11501 | }, options);
|
11502 | _this.element = element;
|
11503 | _this.hasDataSize = hasSizeAttribute(element, _this.options.prefix);
|
11504 | _this.hasLoading = hasLoadingAttribute(element);
|
11505 | _this.isSkip = hasSkipAttribute(_this.element);
|
11506 | return _this;
|
11507 | }
|
11508 |
|
11509 | var __proto = Loader.prototype;
|
11510 |
|
11511 | __proto.check = function () {
|
11512 | if (this.isSkip || !this.checkElement()) {
|
11513 |
|
11514 | this.onAlreadyReady(true);
|
11515 | return false;
|
11516 | }
|
11517 |
|
11518 | if (this.hasDataSize) {
|
11519 | addAutoSizer(this.element, this.options.prefix);
|
11520 | }
|
11521 |
|
11522 | if (this.hasDataSize || this.hasLoading) {
|
11523 |
|
11524 | this.onAlreadyPreReady();
|
11525 | }
|
11526 |
|
11527 |
|
11528 | return true;
|
11529 | };
|
11530 |
|
11531 | __proto.addEvents = function () {
|
11532 | var _this = this;
|
11533 |
|
11534 | var element = this.element;
|
11535 | this.constructor.EVENTS.forEach(function (name) {
|
11536 | addEvent(element, name, _this.onCheck);
|
11537 | });
|
11538 | };
|
11539 |
|
11540 | __proto.clear = function () {
|
11541 | var _this = this;
|
11542 |
|
11543 | var element = this.element;
|
11544 | this.constructor.EVENTS.forEach(function (name) {
|
11545 | removeEvent(element, name, _this.onCheck);
|
11546 | });
|
11547 | this.removeAutoSizer();
|
11548 | };
|
11549 |
|
11550 | __proto.destroy = function () {
|
11551 | this.clear();
|
11552 | this.off();
|
11553 | };
|
11554 |
|
11555 | __proto.removeAutoSizer = function () {
|
11556 | if (this.hasDataSize) {
|
11557 |
|
11558 | var prefix = this.options.prefix;
|
11559 | removeAutoSizer(this.element, prefix);
|
11560 | }
|
11561 | };
|
11562 |
|
11563 | __proto.onError = function (target) {
|
11564 | this.trigger("error", {
|
11565 | element: this.element,
|
11566 | target: target
|
11567 | });
|
11568 | };
|
11569 |
|
11570 | __proto.onPreReady = function () {
|
11571 | if (this.isPreReady) {
|
11572 | return;
|
11573 | }
|
11574 |
|
11575 | this.isPreReady = true;
|
11576 | this.trigger("preReady", {
|
11577 | element: this.element,
|
11578 | hasLoading: this.hasLoading,
|
11579 | isSkip: this.isSkip
|
11580 | });
|
11581 | };
|
11582 |
|
11583 | __proto.onReady = function (withPreReady) {
|
11584 | if (this.isReady) {
|
11585 | return;
|
11586 | }
|
11587 |
|
11588 | if (withPreReady) {
|
11589 | this.isPreReady = true;
|
11590 | }
|
11591 |
|
11592 | this.removeAutoSizer();
|
11593 | this.isReady = true;
|
11594 | this.trigger("ready", {
|
11595 | element: this.element,
|
11596 | withPreReady: withPreReady,
|
11597 | hasLoading: this.hasLoading,
|
11598 | isSkip: this.isSkip
|
11599 | });
|
11600 | };
|
11601 |
|
11602 | __proto.onAlreadyError = function (target) {
|
11603 | var _this = this;
|
11604 |
|
11605 | setTimeout(function () {
|
11606 | _this.onError(target);
|
11607 | });
|
11608 | };
|
11609 |
|
11610 | __proto.onAlreadyPreReady = function () {
|
11611 | var _this = this;
|
11612 |
|
11613 | setTimeout(function () {
|
11614 | _this.onPreReady();
|
11615 | });
|
11616 | };
|
11617 |
|
11618 | __proto.onAlreadyReady = function (withPreReady) {
|
11619 | var _this = this;
|
11620 |
|
11621 | setTimeout(function () {
|
11622 | _this.onReady(withPreReady);
|
11623 | });
|
11624 | };
|
11625 |
|
11626 | Loader.EVENTS = [];
|
11627 | return Loader;
|
11628 | }(Component$2);
|
11629 |
|
11630 | var ElementLoader =
|
11631 |
|
11632 | function (_super) {
|
11633 | __extends$2(ElementLoader, _super);
|
11634 |
|
11635 | function ElementLoader() {
|
11636 | return _super !== null && _super.apply(this, arguments) || this;
|
11637 | }
|
11638 |
|
11639 | var __proto = ElementLoader.prototype;
|
11640 |
|
11641 | __proto.setHasLoading = function (hasLoading) {
|
11642 | this.hasLoading = hasLoading;
|
11643 | };
|
11644 |
|
11645 | __proto.check = function () {
|
11646 | if (this.isSkip) {
|
11647 |
|
11648 | this.onAlreadyReady(true);
|
11649 | return false;
|
11650 | }
|
11651 |
|
11652 | if (this.hasDataSize) {
|
11653 | addAutoSizer(this.element, this.options.prefix);
|
11654 | this.onAlreadyPreReady();
|
11655 | } else {
|
11656 |
|
11657 | this.trigger("requestChildren");
|
11658 | }
|
11659 |
|
11660 | return true;
|
11661 | };
|
11662 |
|
11663 | __proto.checkElement = function () {
|
11664 | return true;
|
11665 | };
|
11666 |
|
11667 | __proto.destroy = function () {
|
11668 | this.clear();
|
11669 | this.trigger("requestDestroy");
|
11670 | this.off();
|
11671 | };
|
11672 |
|
11673 | __proto.onAlreadyPreReady = function () {
|
11674 |
|
11675 | _super.prototype.onAlreadyPreReady.call(this);
|
11676 |
|
11677 | this.trigger("reqeustReadyChildren");
|
11678 | };
|
11679 |
|
11680 | ElementLoader.EVENTS = [];
|
11681 | return ElementLoader;
|
11682 | }(Loader);
|
11683 |
|
11684 | |
11685 |
|
11686 |
|
11687 |
|
11688 |
|
11689 | var ImReadyManager =
|
11690 |
|
11691 | function (_super) {
|
11692 | __extends$2(ImReadyManager, _super);
|
11693 | |
11694 |
|
11695 |
|
11696 |
|
11697 |
|
11698 | function ImReadyManager(options) {
|
11699 | if (options === void 0) {
|
11700 | options = {};
|
11701 | }
|
11702 |
|
11703 | var _this = _super.call(this) || this;
|
11704 |
|
11705 | _this.readyCount = 0;
|
11706 | _this.preReadyCount = 0;
|
11707 | _this.totalCount = 0;
|
11708 | _this.totalErrorCount = 0;
|
11709 | _this.isPreReadyOver = true;
|
11710 | _this.elementInfos = [];
|
11711 | _this.options = __assign$2({
|
11712 | loaders: {},
|
11713 | prefix: "data-"
|
11714 | }, options);
|
11715 | return _this;
|
11716 | }
|
11717 | |
11718 |
|
11719 |
|
11720 |
|
11721 |
|
11722 |
|
11723 |
|
11724 |
|
11725 |
|
11726 |
|
11727 |
|
11728 |
|
11729 |
|
11730 |
|
11731 |
|
11732 |
|
11733 |
|
11734 |
|
11735 |
|
11736 |
|
11737 |
|
11738 |
|
11739 |
|
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 |
|
11745 |
|
11746 | var __proto = ImReadyManager.prototype;
|
11747 |
|
11748 | __proto.check = function (elements) {
|
11749 | var _this = this;
|
11750 |
|
11751 | var prefix = this.options.prefix;
|
11752 | this.clear();
|
11753 | this.elementInfos = toArray$2(elements).map(function (element, index) {
|
11754 | var loader = _this.getLoader(element, {
|
11755 | prefix: prefix
|
11756 | });
|
11757 |
|
11758 | loader.check();
|
11759 | loader.on("error", function (e) {
|
11760 | _this.onError(index, e.target);
|
11761 | }).on("preReady", function (e) {
|
11762 | var info = _this.elementInfos[index];
|
11763 | info.hasLoading = e.hasLoading;
|
11764 | info.isSkip = e.isSkip;
|
11765 |
|
11766 | var isPreReady = _this.checkPreReady(index);
|
11767 |
|
11768 | _this.onPreReadyElement(index);
|
11769 |
|
11770 | isPreReady && _this.onPreReady();
|
11771 | }).on("ready", function (_a) {
|
11772 | var withPreReady = _a.withPreReady,
|
11773 | hasLoading = _a.hasLoading,
|
11774 | isSkip = _a.isSkip;
|
11775 | var info = _this.elementInfos[index];
|
11776 | info.hasLoading = hasLoading;
|
11777 | info.isSkip = isSkip;
|
11778 |
|
11779 | var isPreReady = withPreReady && _this.checkPreReady(index);
|
11780 |
|
11781 | var isReady = _this.checkReady(index);
|
11782 |
|
11783 |
|
11784 | withPreReady && _this.onPreReadyElement(index);
|
11785 |
|
11786 | _this.onReadyElement(index);
|
11787 |
|
11788 | isPreReady && _this.onPreReady();
|
11789 | isReady && _this.onReady();
|
11790 | });
|
11791 | return {
|
11792 | loader: loader,
|
11793 | element: element,
|
11794 | hasLoading: false,
|
11795 | hasError: false,
|
11796 | isPreReady: false,
|
11797 | isReady: false,
|
11798 | isSkip: false
|
11799 | };
|
11800 | });
|
11801 | var length = this.elementInfos.length;
|
11802 | this.totalCount = length;
|
11803 |
|
11804 | if (!length) {
|
11805 | setTimeout(function () {
|
11806 | _this.onPreReady();
|
11807 |
|
11808 | _this.onReady();
|
11809 | });
|
11810 | }
|
11811 |
|
11812 | return this;
|
11813 | };
|
11814 | |
11815 |
|
11816 |
|
11817 |
|
11818 |
|
11819 |
|
11820 | __proto.getTotalCount = function () {
|
11821 | return this.totalCount;
|
11822 | };
|
11823 | |
11824 |
|
11825 |
|
11826 |
|
11827 |
|
11828 |
|
11829 | __proto.isPreReady = function () {
|
11830 | return this.elementInfos.every(function (info) {
|
11831 | return info.isPreReady;
|
11832 | });
|
11833 | };
|
11834 | |
11835 |
|
11836 |
|
11837 |
|
11838 |
|
11839 |
|
11840 | __proto.isReady = function () {
|
11841 | return this.elementInfos.every(function (info) {
|
11842 | return info.isReady;
|
11843 | });
|
11844 | };
|
11845 | |
11846 |
|
11847 |
|
11848 |
|
11849 |
|
11850 |
|
11851 | __proto.hasError = function () {
|
11852 | return this.totalErrorCount > 0;
|
11853 | };
|
11854 | |
11855 |
|
11856 |
|
11857 |
|
11858 |
|
11859 |
|
11860 | __proto.clear = function () {
|
11861 | this.isPreReadyOver = false;
|
11862 | this.totalCount = 0;
|
11863 | this.preReadyCount = 0;
|
11864 | this.readyCount = 0;
|
11865 | this.totalErrorCount = 0;
|
11866 | this.elementInfos.forEach(function (info) {
|
11867 | if (!info.isReady && info.loader) {
|
11868 | info.loader.destroy();
|
11869 | }
|
11870 | });
|
11871 | this.elementInfos = [];
|
11872 | };
|
11873 | |
11874 |
|
11875 |
|
11876 |
|
11877 |
|
11878 |
|
11879 | __proto.destroy = function () {
|
11880 | this.clear();
|
11881 | this.off();
|
11882 | };
|
11883 |
|
11884 | __proto.getLoader = function (element, options) {
|
11885 | var _this = this;
|
11886 |
|
11887 | var tagName = element.tagName.toLowerCase();
|
11888 | var loaders = this.options.loaders;
|
11889 | var tags = Object.keys(loaders);
|
11890 |
|
11891 | if (loaders[tagName]) {
|
11892 | return new loaders[tagName](element, options);
|
11893 | }
|
11894 |
|
11895 | var loader = new ElementLoader(element, options);
|
11896 | var children = toArray$2(element.querySelectorAll(tags.join(", ")));
|
11897 | loader.setHasLoading(children.some(function (el) {
|
11898 | return hasLoadingAttribute(el);
|
11899 | }));
|
11900 | var withPreReady = false;
|
11901 | var childrenImReady = this.clone().on("error", function (e) {
|
11902 | loader.onError(e.target);
|
11903 | }).on("ready", function () {
|
11904 | loader.onReady(withPreReady);
|
11905 | });
|
11906 | loader.on("requestChildren", function () {
|
11907 |
|
11908 | var contentElements = getContentElements(element, tags, _this.options.prefix);
|
11909 | childrenImReady.check(contentElements).on("preReady", function (e) {
|
11910 | withPreReady = e.isReady;
|
11911 |
|
11912 | if (!withPreReady) {
|
11913 | loader.onPreReady();
|
11914 | }
|
11915 | });
|
11916 | }).on("reqeustReadyChildren", function () {
|
11917 |
|
11918 |
|
11919 |
|
11920 | childrenImReady.check(children);
|
11921 | }).on("requestDestroy", function () {
|
11922 | childrenImReady.destroy();
|
11923 | });
|
11924 | return loader;
|
11925 | };
|
11926 |
|
11927 | __proto.clone = function () {
|
11928 | return new ImReadyManager(__assign$2({}, this.options));
|
11929 | };
|
11930 |
|
11931 | __proto.checkPreReady = function (index) {
|
11932 | this.elementInfos[index].isPreReady = true;
|
11933 | ++this.preReadyCount;
|
11934 |
|
11935 | if (this.preReadyCount < this.totalCount) {
|
11936 | return false;
|
11937 | }
|
11938 |
|
11939 | return true;
|
11940 | };
|
11941 |
|
11942 | __proto.checkReady = function (index) {
|
11943 | this.elementInfos[index].isReady = true;
|
11944 | ++this.readyCount;
|
11945 |
|
11946 | if (this.readyCount < this.totalCount) {
|
11947 | return false;
|
11948 | }
|
11949 |
|
11950 | return true;
|
11951 | };
|
11952 |
|
11953 | __proto.onError = function (index, target) {
|
11954 | var info = this.elementInfos[index];
|
11955 | info.hasError = true;
|
11956 | |
11957 |
|
11958 |
|
11959 |
|
11960 |
|
11961 |
|
11962 |
|
11963 |
|
11964 |
|
11965 |
|
11966 |
|
11967 |
|
11968 |
|
11969 |
|
11970 |
|
11971 |
|
11972 |
|
11973 |
|
11974 |
|
11975 |
|
11976 |
|
11977 |
|
11978 |
|
11979 |
|
11980 |
|
11981 |
|
11982 |
|
11983 |
|
11984 |
|
11985 |
|
11986 |
|
11987 |
|
11988 | this.trigger("error", {
|
11989 | element: info.element,
|
11990 | index: index,
|
11991 | target: target,
|
11992 | errorCount: this.getErrorCount(),
|
11993 | totalErrorCount: ++this.totalErrorCount
|
11994 | });
|
11995 | };
|
11996 |
|
11997 | __proto.onPreReadyElement = function (index) {
|
11998 | var info = this.elementInfos[index];
|
11999 | |
12000 |
|
12001 |
|
12002 |
|
12003 |
|
12004 |
|
12005 |
|
12006 |
|
12007 |
|
12008 |
|
12009 |
|
12010 |
|
12011 |
|
12012 |
|
12013 |
|
12014 |
|
12015 |
|
12016 |
|
12017 |
|
12018 |
|
12019 |
|
12020 |
|
12021 |
|
12022 |
|
12023 |
|
12024 |
|
12025 |
|
12026 |
|
12027 |
|
12028 |
|
12029 |
|
12030 |
|
12031 |
|
12032 |
|
12033 |
|
12034 |
|
12035 |
|
12036 |
|
12037 | this.trigger("preReadyElement", {
|
12038 | element: info.element,
|
12039 | index: index,
|
12040 | preReadyCount: this.preReadyCount,
|
12041 | readyCount: this.readyCount,
|
12042 | totalCount: this.totalCount,
|
12043 | isPreReady: this.isPreReady(),
|
12044 | isReady: this.isReady(),
|
12045 | hasLoading: info.hasLoading,
|
12046 | isSkip: info.isSkip
|
12047 | });
|
12048 | };
|
12049 |
|
12050 | __proto.onPreReady = function () {
|
12051 | this.isPreReadyOver = true;
|
12052 | |
12053 |
|
12054 |
|
12055 |
|
12056 |
|
12057 |
|
12058 |
|
12059 |
|
12060 |
|
12061 |
|
12062 |
|
12063 |
|
12064 |
|
12065 |
|
12066 |
|
12067 |
|
12068 |
|
12069 |
|
12070 |
|
12071 |
|
12072 |
|
12073 |
|
12074 |
|
12075 |
|
12076 |
|
12077 |
|
12078 |
|
12079 |
|
12080 |
|
12081 |
|
12082 |
|
12083 | this.trigger("preReady", {
|
12084 | readyCount: this.readyCount,
|
12085 | totalCount: this.totalCount,
|
12086 | isReady: this.isReady(),
|
12087 | hasLoading: this.hasLoading()
|
12088 | });
|
12089 | };
|
12090 |
|
12091 | __proto.onReadyElement = function (index) {
|
12092 | var info = this.elementInfos[index];
|
12093 | |
12094 |
|
12095 |
|
12096 |
|
12097 |
|
12098 |
|
12099 |
|
12100 |
|
12101 |
|
12102 |
|
12103 |
|
12104 |
|
12105 |
|
12106 |
|
12107 |
|
12108 |
|
12109 |
|
12110 |
|
12111 |
|
12112 |
|
12113 |
|
12114 |
|
12115 |
|
12116 |
|
12117 |
|
12118 |
|
12119 |
|
12120 |
|
12121 |
|
12122 |
|
12123 |
|
12124 |
|
12125 |
|
12126 |
|
12127 |
|
12128 |
|
12129 |
|
12130 |
|
12131 |
|
12132 |
|
12133 |
|
12134 |
|
12135 | this.trigger("readyElement", {
|
12136 | index: index,
|
12137 | element: info.element,
|
12138 | hasError: info.hasError,
|
12139 | errorCount: this.getErrorCount(),
|
12140 | totalErrorCount: this.totalErrorCount,
|
12141 | preReadyCount: this.preReadyCount,
|
12142 | readyCount: this.readyCount,
|
12143 | totalCount: this.totalCount,
|
12144 | isPreReady: this.isPreReady(),
|
12145 | isReady: this.isReady(),
|
12146 | hasLoading: info.hasLoading,
|
12147 | isPreReadyOver: this.isPreReadyOver,
|
12148 | isSkip: info.isSkip
|
12149 | });
|
12150 | };
|
12151 |
|
12152 | __proto.onReady = function () {
|
12153 | |
12154 |
|
12155 |
|
12156 |
|
12157 |
|
12158 |
|
12159 |
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 |
|
12165 |
|
12166 |
|
12167 |
|
12168 |
|
12169 |
|
12170 |
|
12171 |
|
12172 |
|
12173 |
|
12174 |
|
12175 |
|
12176 |
|
12177 |
|
12178 |
|
12179 |
|
12180 |
|
12181 |
|
12182 |
|
12183 |
|
12184 |
|
12185 |
|
12186 | this.trigger("ready", {
|
12187 | errorCount: this.getErrorCount(),
|
12188 | totalErrorCount: this.totalErrorCount,
|
12189 | totalCount: this.totalCount
|
12190 | });
|
12191 | };
|
12192 |
|
12193 | __proto.getErrorCount = function () {
|
12194 | return this.elementInfos.filter(function (info) {
|
12195 | return info.hasError;
|
12196 | }).length;
|
12197 | };
|
12198 |
|
12199 | __proto.hasLoading = function () {
|
12200 | return this.elementInfos.some(function (info) {
|
12201 | return info.hasLoading;
|
12202 | });
|
12203 | };
|
12204 |
|
12205 | return ImReadyManager;
|
12206 | }(Component$2);
|
12207 |
|
12208 | var ImageLoader =
|
12209 |
|
12210 | function (_super) {
|
12211 | __extends$2(ImageLoader, _super);
|
12212 |
|
12213 | function ImageLoader() {
|
12214 | return _super !== null && _super.apply(this, arguments) || this;
|
12215 | }
|
12216 |
|
12217 | var __proto = ImageLoader.prototype;
|
12218 |
|
12219 | __proto.checkElement = function () {
|
12220 | var element = this.element;
|
12221 | var src = element.getAttribute("src");
|
12222 |
|
12223 | if (element.complete && src) {
|
12224 | if (!element.naturalWidth) {
|
12225 | this.onAlreadyError(element);
|
12226 | }
|
12227 |
|
12228 | return false;
|
12229 | }
|
12230 |
|
12231 | this.addEvents();
|
12232 | IS_IE && element.setAttribute("src", src);
|
12233 | return true;
|
12234 | };
|
12235 |
|
12236 | ImageLoader.EVENTS = ["load", "error"];
|
12237 | return ImageLoader;
|
12238 | }(Loader);
|
12239 |
|
12240 | var VideoLoader =
|
12241 |
|
12242 | function (_super) {
|
12243 | __extends$2(VideoLoader, _super);
|
12244 |
|
12245 | function VideoLoader() {
|
12246 | return _super !== null && _super.apply(this, arguments) || this;
|
12247 | }
|
12248 |
|
12249 | var __proto = VideoLoader.prototype;
|
12250 |
|
12251 | __proto.checkElement = function () {
|
12252 | var element = this.element;
|
12253 |
|
12254 |
|
12255 |
|
12256 |
|
12257 |
|
12258 | if (element.readyState >= 1) {
|
12259 | return false;
|
12260 | }
|
12261 |
|
12262 | if (element.error) {
|
12263 | this.onAlreadyError(element);
|
12264 | return false;
|
12265 | }
|
12266 |
|
12267 | this.addEvents();
|
12268 | return true;
|
12269 | };
|
12270 |
|
12271 | VideoLoader.EVENTS = ["loadedmetadata", "error"];
|
12272 | return VideoLoader;
|
12273 | }(Loader);
|
12274 |
|
12275 | var ImReady =
|
12276 |
|
12277 | function (_super) {
|
12278 | __extends$2(ImReady, _super);
|
12279 |
|
12280 | function ImReady(options) {
|
12281 | if (options === void 0) {
|
12282 | options = {};
|
12283 | }
|
12284 |
|
12285 | return _super.call(this, __assign$2({
|
12286 | loaders: {
|
12287 | img: ImageLoader,
|
12288 | video: VideoLoader
|
12289 | }
|
12290 | }, options)) || this;
|
12291 | }
|
12292 |
|
12293 | return ImReady;
|
12294 | }(ImReadyManager);
|
12295 |
|
12296 | |
12297 |
|
12298 |
|
12299 |
|
12300 |
|
12301 |
|
12302 |
|
12303 |
|
12304 | var ERROR_TYPE = {
|
12305 | |
12306 |
|
12307 |
|
12308 |
|
12309 |
|
12310 |
|
12311 |
|
12312 |
|
12313 |
|
12314 | INVALID_DEVICE: 10,
|
12315 |
|
12316 | |
12317 |
|
12318 |
|
12319 |
|
12320 |
|
12321 |
|
12322 |
|
12323 |
|
12324 |
|
12325 | NO_WEBGL: 11,
|
12326 |
|
12327 | |
12328 |
|
12329 |
|
12330 |
|
12331 |
|
12332 |
|
12333 |
|
12334 |
|
12335 |
|
12336 | FAIL_IMAGE_LOAD: 12,
|
12337 |
|
12338 | |
12339 |
|
12340 |
|
12341 |
|
12342 |
|
12343 |
|
12344 |
|
12345 |
|
12346 |
|
12347 | FAIL_BIND_TEXTURE: 13,
|
12348 |
|
12349 | |
12350 |
|
12351 |
|
12352 |
|
12353 |
|
12354 |
|
12355 |
|
12356 |
|
12357 |
|
12358 | INVALID_RESOURCE: 14,
|
12359 |
|
12360 | |
12361 |
|
12362 |
|
12363 |
|
12364 |
|
12365 |
|
12366 |
|
12367 |
|
12368 |
|
12369 | RENDERING_CONTEXT_LOST: 15
|
12370 | };
|
12371 | |
12372 |
|
12373 |
|
12374 |
|
12375 |
|
12376 |
|
12377 |
|
12378 |
|
12379 | var PANOVIEWER_EVENTS = {
|
12380 | |
12381 |
|
12382 |
|
12383 |
|
12384 |
|
12385 |
|
12386 |
|
12387 |
|
12388 |
|
12389 | READY: "ready",
|
12390 |
|
12391 | |
12392 |
|
12393 |
|
12394 |
|
12395 |
|
12396 |
|
12397 |
|
12398 |
|
12399 |
|
12400 | VIEW_CHANGE: "viewChange",
|
12401 |
|
12402 | |
12403 |
|
12404 |
|
12405 |
|
12406 |
|
12407 |
|
12408 |
|
12409 |
|
12410 |
|
12411 | ANIMATION_END: "animationEnd",
|
12412 |
|
12413 | |
12414 |
|
12415 |
|
12416 |
|
12417 |
|
12418 |
|
12419 |
|
12420 |
|
12421 |
|
12422 | ERROR: "error"
|
12423 | };
|
12424 | |
12425 |
|
12426 |
|
12427 |
|
12428 |
|
12429 |
|
12430 |
|
12431 |
|
12432 | var PROJECTION_TYPE = {
|
12433 | |
12434 |
|
12435 |
|
12436 |
|
12437 |
|
12438 |
|
12439 |
|
12440 |
|
12441 |
|
12442 | EQUIRECTANGULAR: "equirectangular",
|
12443 |
|
12444 | |
12445 |
|
12446 |
|
12447 |
|
12448 |
|
12449 |
|
12450 |
|
12451 |
|
12452 |
|
12453 | CUBEMAP: "cubemap",
|
12454 |
|
12455 | |
12456 |
|
12457 |
|
12458 |
|
12459 |
|
12460 |
|
12461 |
|
12462 |
|
12463 |
|
12464 |
|
12465 | CUBESTRIP: "cubestrip",
|
12466 |
|
12467 | |
12468 |
|
12469 |
|
12470 |
|
12471 |
|
12472 |
|
12473 |
|
12474 |
|
12475 |
|
12476 |
|
12477 |
|
12478 |
|
12479 | PANORAMA: "panorama",
|
12480 |
|
12481 | |
12482 |
|
12483 |
|
12484 |
|
12485 |
|
12486 |
|
12487 |
|
12488 |
|
12489 |
|
12490 |
|
12491 |
|
12492 |
|
12493 | STEREOSCOPIC_EQUI: "stereoequi"
|
12494 | };
|
12495 | |
12496 |
|
12497 |
|
12498 |
|
12499 |
|
12500 |
|
12501 |
|
12502 |
|
12503 | var STEREO_FORMAT = {
|
12504 | |
12505 |
|
12506 |
|
12507 |
|
12508 |
|
12509 |
|
12510 |
|
12511 |
|
12512 |
|
12513 | TOP_BOTTOM: "3dv",
|
12514 |
|
12515 | |
12516 |
|
12517 |
|
12518 |
|
12519 |
|
12520 |
|
12521 |
|
12522 |
|
12523 |
|
12524 | LEFT_RIGHT: "3dh",
|
12525 |
|
12526 | |
12527 |
|
12528 |
|
12529 |
|
12530 |
|
12531 |
|
12532 |
|
12533 |
|
12534 |
|
12535 | NONE: ""
|
12536 | };
|
12537 |
|
12538 | var PANOVIEWER_OPTIONS = {
|
12539 | image: true,
|
12540 | video: true,
|
12541 | projectionType: true,
|
12542 | cubemapConfig: true,
|
12543 | stereoFormat: true,
|
12544 | width: true,
|
12545 | height: true,
|
12546 | yaw: true,
|
12547 | pitch: true,
|
12548 | fov: true,
|
12549 | showPolePoint: true,
|
12550 | useZoom: true,
|
12551 | useKeyboard: true,
|
12552 | gyroMode: true,
|
12553 | yawRange: true,
|
12554 | pitchRange: true,
|
12555 | fovRange: true,
|
12556 | touchDirection: true,
|
12557 | canvasClass: true
|
12558 | };
|
12559 | var DEFAULT_CANVAS_CLASS = "view360-canvas";
|
12560 |
|
12561 | var merge = function (target) {
|
12562 | var srcs = [];
|
12563 |
|
12564 | for (var _i = 1; _i < arguments.length; _i++) {
|
12565 | srcs[_i - 1] = arguments[_i];
|
12566 | }
|
12567 |
|
12568 | srcs.forEach(function (source) {
|
12569 | Object.keys(source).forEach(function (key) {
|
12570 | var value = source[key];
|
12571 |
|
12572 | if (Array.isArray(target[key]) && Array.isArray(value)) {
|
12573 | target[key] = __spread(target[key], value);
|
12574 | } else {
|
12575 | target[key] = value;
|
12576 | }
|
12577 | });
|
12578 | });
|
12579 | return target;
|
12580 | };
|
12581 | var toImageElement = function (image) {
|
12582 | var images = image instanceof Array ? image : [image];
|
12583 | var parsedImages = images.map(function (img) {
|
12584 | var imgEl = img;
|
12585 |
|
12586 | if (typeof img === "string") {
|
12587 | imgEl = new Image();
|
12588 | imgEl.crossOrigin = "anonymous";
|
12589 | imgEl.src = img;
|
12590 | }
|
12591 |
|
12592 | return imgEl;
|
12593 | });
|
12594 | return parsedImages.length === 1 ? parsedImages[0] : parsedImages;
|
12595 | };
|
12596 | var toVideoElement = function (videoCandidate) {
|
12597 | if (videoCandidate instanceof HTMLVideoElement) {
|
12598 | return videoCandidate;
|
12599 | } else {
|
12600 |
|
12601 | var video_1 = document.createElement("video");
|
12602 | video_1.setAttribute("crossorigin", "anonymous");
|
12603 | video_1.setAttribute("webkit-playsinline", "");
|
12604 | video_1.setAttribute("playsinline", "");
|
12605 |
|
12606 | if (videoCandidate instanceof Array) {
|
12607 | videoCandidate.forEach(function (v) {
|
12608 | return appendSourceElement(video_1, v);
|
12609 | });
|
12610 | } else {
|
12611 | appendSourceElement(video_1, videoCandidate);
|
12612 | }
|
12613 |
|
12614 | var sourceCount = video_1.querySelectorAll("source").length;
|
12615 |
|
12616 | if (sourceCount > 0) {
|
12617 | if (video_1.readyState < 1) {
|
12618 | video_1.load();
|
12619 | }
|
12620 | }
|
12621 |
|
12622 | return video_1;
|
12623 | }
|
12624 | };
|
12625 | |
12626 |
|
12627 |
|
12628 |
|
12629 |
|
12630 | var appendSourceElement = function (video, videoUrl) {
|
12631 | var videoSrc;
|
12632 | var videoType;
|
12633 |
|
12634 | if (typeof videoUrl === "object") {
|
12635 | videoSrc = videoUrl.src;
|
12636 | videoType = videoUrl.type;
|
12637 | } else if (typeof videoUrl === "string") {
|
12638 | videoSrc = videoUrl;
|
12639 | }
|
12640 |
|
12641 | if (!videoSrc) {
|
12642 | return false;
|
12643 | }
|
12644 |
|
12645 | var sourceElement = document.createElement("source");
|
12646 | sourceElement.src = videoSrc;
|
12647 |
|
12648 | if (videoType) {
|
12649 | sourceElement.type = videoType;
|
12650 | }
|
12651 |
|
12652 | video.appendChild(sourceElement);
|
12653 | };
|
12654 |
|
12655 | var WEBGL_ERROR_CODE = {
|
12656 | "0": "NO_ERROR",
|
12657 | "1280": "INVALID_ENUM",
|
12658 | "1281": "INVALID_VALUE",
|
12659 | "1282": "INVALID_OPERATION",
|
12660 | "1285": "OUT_OF_MEMORY",
|
12661 | "1286": "INVALID_FRAMEBUFFER_OPERATION",
|
12662 | "37442": "CONTEXT_LOST_WEBGL"
|
12663 | };
|
12664 | var webglAvailability = null;
|
12665 |
|
12666 | var WebGLUtils =
|
12667 |
|
12668 | function () {
|
12669 | function WebGLUtils() {}
|
12670 |
|
12671 | WebGLUtils.createShader = function (gl, type, source) {
|
12672 | var shader = gl.createShader(type);
|
12673 | gl.shaderSource(shader, source);
|
12674 | gl.compileShader(shader);
|
12675 | var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
12676 |
|
12677 | if (success) {
|
12678 | return shader;
|
12679 | }
|
12680 |
|
12681 |
|
12682 | console.error(gl.getShaderInfoLog(shader));
|
12683 | return null;
|
12684 | };
|
12685 |
|
12686 | WebGLUtils.createProgram = function (gl, vertexShader, fragmentShader) {
|
12687 | var program = gl.createProgram();
|
12688 | gl.attachShader(program, vertexShader);
|
12689 | gl.attachShader(program, fragmentShader);
|
12690 | gl.linkProgram(program);
|
12691 | gl.deleteShader(vertexShader);
|
12692 | gl.deleteShader(fragmentShader);
|
12693 | var success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
12694 |
|
12695 | if (success) {
|
12696 | return program;
|
12697 | }
|
12698 |
|
12699 | gl.deleteProgram(program);
|
12700 | return null;
|
12701 | };
|
12702 |
|
12703 | WebGLUtils.initBuffer = function (gl, target
|
12704 | /* bind point */
|
12705 | , data, itemSize, attr) {
|
12706 | var buffer = gl.createBuffer();
|
12707 | gl.bindBuffer(target, buffer);
|
12708 | gl.bufferData(target, data, gl.STATIC_DRAW);
|
12709 |
|
12710 | if (buffer) {
|
12711 | buffer.itemSize = itemSize;
|
12712 | buffer.numItems = data.length / itemSize;
|
12713 | }
|
12714 |
|
12715 | if (attr !== undefined) {
|
12716 | gl.enableVertexAttribArray(attr);
|
12717 | gl.vertexAttribPointer(attr, buffer.itemSize, gl.FLOAT, false, 0, 0);
|
12718 | }
|
12719 |
|
12720 | return buffer;
|
12721 | };
|
12722 |
|
12723 | WebGLUtils.getWebglContext = function (canvas, userContextAttributes) {
|
12724 | var e_1, _a;
|
12725 |
|
12726 | var webglIdentifiers = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
|
12727 | var context = null;
|
12728 |
|
12729 | var contextAttributes = __assign({
|
12730 | preserveDrawingBuffer: false,
|
12731 | antialias: false
|
12732 | }, userContextAttributes);
|
12733 |
|
12734 | var onWebglcontextcreationerror = function (e) {
|
12735 | return e.statusMessage;
|
12736 | };
|
12737 |
|
12738 | canvas.addEventListener("webglcontextcreationerror", onWebglcontextcreationerror);
|
12739 |
|
12740 | try {
|
12741 | for (var webglIdentifiers_1 = __values(webglIdentifiers), webglIdentifiers_1_1 = webglIdentifiers_1.next(); !webglIdentifiers_1_1.done; webglIdentifiers_1_1 = webglIdentifiers_1.next()) {
|
12742 | var identifier = webglIdentifiers_1_1.value;
|
12743 |
|
12744 | try {
|
12745 | context = canvas.getContext(identifier, contextAttributes);
|
12746 | } catch (t) {}
|
12747 |
|
12748 |
|
12749 | if (context) {
|
12750 | break;
|
12751 | }
|
12752 | }
|
12753 | } catch (e_1_1) {
|
12754 | e_1 = {
|
12755 | error: e_1_1
|
12756 | };
|
12757 | } finally {
|
12758 | try {
|
12759 | if (webglIdentifiers_1_1 && !webglIdentifiers_1_1.done && (_a = webglIdentifiers_1.return)) _a.call(webglIdentifiers_1);
|
12760 | } finally {
|
12761 | if (e_1) throw e_1.error;
|
12762 | }
|
12763 | }
|
12764 |
|
12765 | canvas.removeEventListener("webglcontextcreationerror", onWebglcontextcreationerror);
|
12766 | return context;
|
12767 | };
|
12768 |
|
12769 | WebGLUtils.createTexture = function (gl, textureTarget) {
|
12770 | var texture = gl.createTexture();
|
12771 | gl.bindTexture(textureTarget, texture);
|
12772 | gl.texParameteri(textureTarget, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
12773 | gl.texParameteri(textureTarget, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
12774 | gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
12775 | gl.texParameteri(textureTarget, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
12776 | gl.bindTexture(textureTarget, null);
|
12777 | return texture;
|
12778 | };
|
12779 | |
12780 |
|
12781 |
|
12782 |
|
12783 |
|
12784 |
|
12785 |
|
12786 | WebGLUtils.isWebGLAvailable = function () {
|
12787 | if (webglAvailability === null) {
|
12788 | var canvas = document.createElement("canvas");
|
12789 | var webglContext = WebGLUtils.getWebglContext(canvas);
|
12790 | webglAvailability = !!webglContext;
|
12791 |
|
12792 | if (webglContext) {
|
12793 | var loseContextExtension = webglContext.getExtension("WEBGL_lose_context");
|
12794 |
|
12795 | if (loseContextExtension) {
|
12796 | loseContextExtension.loseContext();
|
12797 | }
|
12798 | }
|
12799 | }
|
12800 |
|
12801 | return !!webglAvailability;
|
12802 | };
|
12803 | |
12804 |
|
12805 |
|
12806 |
|
12807 |
|
12808 |
|
12809 |
|
12810 | WebGLUtils.isStableWebGL = function () {
|
12811 | var agentInfo = agent();
|
12812 | var isStableWebgl = true;
|
12813 |
|
12814 | if (agentInfo.os.name === "android") {
|
12815 | var version = parseFloat(agentInfo.os.version);
|
12816 |
|
12817 | if (version <= 4.3 && version >= 1) {
|
12818 | isStableWebgl = false;
|
12819 | } else if (version === 4.4) {
|
12820 | if (agentInfo.browser.name !== "chrome") {
|
12821 | isStableWebgl = false;
|
12822 | }
|
12823 | }
|
12824 | }
|
12825 |
|
12826 | return isStableWebgl;
|
12827 | };
|
12828 |
|
12829 | WebGLUtils.getErrorNameFromWebGLErrorCode = function (code) {
|
12830 | if (!(code in WEBGL_ERROR_CODE)) {
|
12831 | return "UNKNOWN_ERROR";
|
12832 | }
|
12833 |
|
12834 | return WEBGL_ERROR_CODE[code];
|
12835 | };
|
12836 | |
12837 |
|
12838 |
|
12839 |
|
12840 |
|
12841 |
|
12842 | WebGLUtils.texImage2D = function (gl, target, pixels) {
|
12843 | try {
|
12844 | gl.texImage2D(target, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
12845 | } catch (error) {
|
12846 |
|
12847 | console.error("WebGLUtils.texImage2D error:", error);
|
12848 |
|
12849 | }
|
12850 | };
|
12851 |
|
12852 | WebGLUtils.getMaxTextureSize = function (gl) {
|
12853 |
|
12854 | return gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
12855 | };
|
12856 |
|
12857 | return WebGLUtils;
|
12858 | }();
|
12859 |
|
12860 | var agentInfo = agent();
|
12861 | var isIE11 = agentInfo.browser.name === "ie" && agentInfo.browser.majorVersion === 11;
|
12862 | var EVENTS = {
|
12863 | ERROR: "error"
|
12864 | };
|
12865 | |
12866 |
|
12867 |
|
12868 |
|
12869 |
|
12870 | var Renderer =
|
12871 |
|
12872 | function (_super) {
|
12873 | __extends(Renderer, _super);
|
12874 |
|
12875 | function Renderer() {
|
12876 | var _this = _super.call(this) || this;
|
12877 |
|
12878 | _this._forceDimension = null;
|
12879 | _this._pixelCanvas = null;
|
12880 | _this._pixelContext = null;
|
12881 | return _this;
|
12882 | }
|
12883 |
|
12884 | var __proto = Renderer.prototype;
|
12885 |
|
12886 | __proto.render = function (_a) {
|
12887 | var gl = _a.gl,
|
12888 | shaderProgram = _a.shaderProgram,
|
12889 | indexBuffer = _a.indexBuffer,
|
12890 | mvMatrix = _a.mvMatrix,
|
12891 | pMatrix = _a.pMatrix;
|
12892 | gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix);
|
12893 | gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);
|
12894 |
|
12895 | if (indexBuffer) {
|
12896 | gl.drawElements(gl.TRIANGLES, indexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
|
12897 | }
|
12898 | };
|
12899 |
|
12900 | |
12901 |
|
12902 |
|
12903 |
|
12904 |
|
12905 |
|
12906 |
|
12907 |
|
12908 |
|
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 |
|
12920 | __proto.getDimension = function (pixelSource) {
|
12921 | var width = pixelSource.naturalWidth || pixelSource.videoWidth;
|
12922 | var height = pixelSource.naturalHeight || pixelSource.videoHeight;
|
12923 | return {
|
12924 | width: width,
|
12925 | height: height
|
12926 | };
|
12927 | };
|
12928 | |
12929 |
|
12930 |
|
12931 |
|
12932 |
|
12933 | __proto.updateShaderData = function (param) {
|
12934 | |
12935 |
|
12936 |
|
12937 |
|
12938 |
|
12939 |
|
12940 |
|
12941 |
|
12942 | };
|
12943 | |
12944 |
|
12945 |
|
12946 |
|
12947 |
|
12948 |
|
12949 |
|
12950 | __proto._initPixelSource = function (image, forceDimension) {
|
12951 | if (forceDimension === void 0) {
|
12952 | forceDimension = null;
|
12953 | }
|
12954 |
|
12955 | var isIE11Video = isIE11 && image instanceof HTMLVideoElement;
|
12956 |
|
12957 | if (isIE11Video || forceDimension) {
|
12958 | var _a = forceDimension || this.getDimension(image),
|
12959 | width = _a.width,
|
12960 | height = _a.height;
|
12961 |
|
12962 | this._pixelCanvas = document.createElement("canvas");
|
12963 | this._pixelCanvas.width = width;
|
12964 | this._pixelCanvas.height = height;
|
12965 | this._pixelContext = this._pixelCanvas.getContext("2d");
|
12966 | }
|
12967 |
|
12968 | this._forceDimension = forceDimension;
|
12969 | };
|
12970 |
|
12971 | __proto._getPixelSource = function (image) {
|
12972 | if (!this._pixelCanvas) {
|
12973 | return image;
|
12974 | }
|
12975 | |
12976 |
|
12977 |
|
12978 |
|
12979 |
|
12980 |
|
12981 |
|
12982 | var contentDimension = this.getDimension(image);
|
12983 | var textureDimension = this._forceDimension || contentDimension;
|
12984 |
|
12985 | if (this._pixelCanvas.width !== textureDimension.width) {
|
12986 | this._pixelCanvas.width = textureDimension.width;
|
12987 | }
|
12988 |
|
12989 | if (this._pixelCanvas.height !== textureDimension.height) {
|
12990 | this._pixelCanvas.height = textureDimension.height;
|
12991 | }
|
12992 |
|
12993 | if (this._forceDimension) {
|
12994 | this._pixelContext.drawImage(image, 0, 0, contentDimension.width, contentDimension.height, 0, 0, textureDimension.width, textureDimension.height);
|
12995 | } else {
|
12996 | this._pixelContext.drawImage(image, 0, 0);
|
12997 | }
|
12998 |
|
12999 | return this._pixelCanvas;
|
13000 | };
|
13001 |
|
13002 | __proto._extractTileConfig = function (imageConfig) {
|
13003 | var tileConfig = Array.isArray(imageConfig.tileConfig) ? imageConfig.tileConfig : Array.apply(void 0, __spread(Array(6))).map(function () {
|
13004 | return imageConfig.tileConfig;
|
13005 | });
|
13006 | tileConfig = tileConfig.map(function (config) {
|
13007 | return __assign({
|
13008 | flipHorizontal: false,
|
13009 | rotation: 0
|
13010 | }, config);
|
13011 | });
|
13012 | return tileConfig;
|
13013 | };
|
13014 |
|
13015 | __proto._triggerError = function (error) {
|
13016 |
|
13017 | console.error("Renderer Error:", error);
|
13018 |
|
13019 |
|
13020 | this.trigger(new ComponentEvent$1(EVENTS.ERROR, {
|
13021 | message: typeof error === "string" ? error : error.message
|
13022 | }));
|
13023 | };
|
13024 |
|
13025 | Renderer.EVENTS = EVENTS;
|
13026 | return Renderer;
|
13027 | }(Component);
|
13028 |
|
13029 | var CubeRenderer =
|
13030 |
|
13031 | function (_super) {
|
13032 | __extends(CubeRenderer, _super);
|
13033 |
|
13034 | function CubeRenderer() {
|
13035 | return _super !== null && _super.apply(this, arguments) || this;
|
13036 | }
|
13037 |
|
13038 | var __proto = CubeRenderer.prototype;
|
13039 |
|
13040 | CubeRenderer.extractOrder = function (imageConfig) {
|
13041 | return imageConfig.order || "RLUDBF";
|
13042 | };
|
13043 |
|
13044 | __proto.getVertexPositionData = function () {
|
13045 | CubeRenderer._VERTEX_POSITION_DATA = CubeRenderer._VERTEX_POSITION_DATA !== null ? CubeRenderer._VERTEX_POSITION_DATA : [
|
13046 | 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1,
|
13047 | -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1,
|
13048 | -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1,
|
13049 | 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1,
|
13050 | 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1,
|
13051 | -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1];
|
13052 | return CubeRenderer._VERTEX_POSITION_DATA;
|
13053 | };
|
13054 |
|
13055 | __proto.getIndexData = function () {
|
13056 | if (CubeRenderer._INDEX_DATA) {
|
13057 | return CubeRenderer._INDEX_DATA;
|
13058 | }
|
13059 |
|
13060 | var indexData = [];
|
13061 | var vertexPositionData = this.getVertexPositionData();
|
13062 |
|
13063 | for (var i = 0; i < vertexPositionData.length / 3; i += 4) {
|
13064 | indexData.push(i, i + 2, i + 1, i, i + 3, i + 2);
|
13065 | }
|
13066 |
|
13067 | CubeRenderer._INDEX_DATA = indexData;
|
13068 | return indexData;
|
13069 | };
|
13070 |
|
13071 | __proto.getTextureCoordData = function (_a) {
|
13072 | var _this = this;
|
13073 |
|
13074 | var image = _a.image,
|
13075 | imageConfig = _a.imageConfig;
|
13076 | var vertexOrder = "BFUDRL";
|
13077 | var order = CubeRenderer.extractOrder(imageConfig);
|
13078 | var base = this.getVertexPositionData();
|
13079 |
|
13080 | var tileConfig = this._extractTileConfig(imageConfig);
|
13081 |
|
13082 | var elemSize = 3;
|
13083 | var vertexPerTile = 4;
|
13084 | var trim = imageConfig.trim;
|
13085 | var texCoords = vertexOrder.split("").map(function (face) {
|
13086 | return tileConfig[order.indexOf(face)];
|
13087 | }).map(function (config, i) {
|
13088 | var rotation = Math.floor(config.rotation / 90);
|
13089 | var ordermap = config.flipHorizontal ? [0, 1, 2, 3] : [1, 0, 3, 2];
|
13090 |
|
13091 | for (var r = 0; r < Math.abs(rotation); r++) {
|
13092 | if (config.flipHorizontal && rotation > 0 || !config.flipHorizontal && rotation < 0) {
|
13093 | ordermap.push(ordermap.shift());
|
13094 | } else {
|
13095 | ordermap.unshift(ordermap.pop());
|
13096 | }
|
13097 | }
|
13098 |
|
13099 | var elemPerTile = elemSize * vertexPerTile;
|
13100 | var tileVertex = base.slice(i * elemPerTile, i * elemPerTile + elemPerTile);
|
13101 | var tileTemp = [];
|
13102 |
|
13103 | for (var j = 0; j < vertexPerTile; j++) {
|
13104 | tileTemp[ordermap[j]] = tileVertex.splice(0, elemSize);
|
13105 | }
|
13106 |
|
13107 | return tileTemp;
|
13108 | }).map(function (coord) {
|
13109 | return _this._shrinkCoord({
|
13110 | image: image,
|
13111 | faceCoords: coord,
|
13112 | trim: trim
|
13113 | });
|
13114 | }).reduce(function (acc, val) {
|
13115 | return __spread(acc, val.reduce(function (coords, coord) {
|
13116 | return __spread(coords, coord);
|
13117 | }, []));
|
13118 | }, []);
|
13119 | return texCoords;
|
13120 | };
|
13121 |
|
13122 | __proto.getVertexShaderSource = function () {
|
13123 | return "\nattribute vec3 aVertexPosition;\nattribute vec3 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvarying highp vec3 vVertexDirectionVector;\nvoid main(void) {\n vVertexDirectionVector = aTextureCoord;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
13124 | };
|
13125 |
|
13126 | __proto.getFragmentShaderSource = function () {
|
13127 | return "\nprecision highp float;\nuniform samplerCube uSampler;\nvarying highp vec3 vVertexDirectionVector;\nvoid main(void) {\n gl_FragColor = textureCube(uSampler, vVertexDirectionVector);\n}";
|
13128 | };
|
13129 |
|
13130 | __proto.updateTexture = function (gl, image, imageConfig) {
|
13131 | var baseOrder = "RLUDBF";
|
13132 | var order = CubeRenderer.extractOrder(imageConfig);
|
13133 | var orderMap = {};
|
13134 | order.split("").forEach(function (v, i) {
|
13135 | orderMap[v] = i;
|
13136 | });
|
13137 |
|
13138 | try {
|
13139 | if (image instanceof Array) {
|
13140 | for (var surfaceIdx = 0; surfaceIdx < 6; surfaceIdx++) {
|
13141 | var tileIdx = orderMap[baseOrder[surfaceIdx]];
|
13142 | WebGLUtils.texImage2D(gl, gl.TEXTURE_CUBE_MAP_POSITIVE_X + surfaceIdx, image[tileIdx]);
|
13143 | }
|
13144 | } else {
|
13145 | var maxCubeMapTextureSize = this.getMaxCubeMapTextureSize(gl, image);
|
13146 |
|
13147 | for (var surfaceIdx = 0; surfaceIdx < 6; surfaceIdx++) {
|
13148 | var tileIdx = orderMap[baseOrder[surfaceIdx]];
|
13149 | var tile = this.extractTileFromImage(image, tileIdx, maxCubeMapTextureSize);
|
13150 | WebGLUtils.texImage2D(gl, gl.TEXTURE_CUBE_MAP_POSITIVE_X + surfaceIdx, tile);
|
13151 | }
|
13152 | }
|
13153 | } catch (e) {
|
13154 | this._triggerError(e);
|
13155 | }
|
13156 | };
|
13157 |
|
13158 | __proto.bindTexture = function (gl, texture, image, imageConfig) {
|
13159 | gl.bindTexture(gl.TEXTURE_CUBE_MAP, texture);
|
13160 | this.updateTexture(gl, image, imageConfig);
|
13161 | };
|
13162 |
|
13163 | __proto.getSourceTileSize = function (image) {
|
13164 | var _a = this.getDimension(image),
|
13165 | width = _a.width,
|
13166 | height = _a.height;
|
13167 |
|
13168 | var aspectRatio = width / height;
|
13169 | var inputTextureSize;
|
13170 |
|
13171 | if (aspectRatio === 1 / 6) {
|
13172 | inputTextureSize = width;
|
13173 | } else if (aspectRatio === 6) {
|
13174 | inputTextureSize = height;
|
13175 | } else if (aspectRatio === 2 / 3) {
|
13176 | inputTextureSize = width / 2;
|
13177 | } else {
|
13178 | inputTextureSize = width / 3;
|
13179 | }
|
13180 |
|
13181 | return inputTextureSize;
|
13182 | };
|
13183 |
|
13184 | __proto.extractTileFromImage = function (image, tileIdx, outputTextureSize) {
|
13185 | var width = this.getDimension(image).width;
|
13186 | var inputTextureSize = this.getSourceTileSize(image);
|
13187 | var canvas = document.createElement("canvas");
|
13188 | canvas.width = outputTextureSize;
|
13189 | canvas.height = outputTextureSize;
|
13190 | var context = canvas.getContext("2d");
|
13191 | var tilePerRow = width / inputTextureSize;
|
13192 | var x = inputTextureSize * tileIdx % (inputTextureSize * tilePerRow);
|
13193 | var y = Math.floor(tileIdx / tilePerRow) * inputTextureSize;
|
13194 | context.drawImage(image, x, y, inputTextureSize, inputTextureSize, 0, 0, outputTextureSize, outputTextureSize);
|
13195 | return canvas;
|
13196 | };
|
13197 |
|
13198 | __proto.getMaxCubeMapTextureSize = function (gl, image) {
|
13199 | var agentInfo = agent();
|
13200 | var maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE);
|
13201 | var imageWidth = this.getSourceTileSize(image);
|
13202 |
|
13203 | if (agentInfo.browser.name === "ie" && agentInfo.browser.majorVersion === 11) {
|
13204 | if (!util.isPowerOfTwo(imageWidth)) {
|
13205 | for (var i = 1; i < maxCubeMapTextureSize; i *= 2) {
|
13206 | if (i < imageWidth) {
|
13207 | continue;
|
13208 | } else {
|
13209 | imageWidth = i;
|
13210 | break;
|
13211 | }
|
13212 | }
|
13213 | }
|
13214 | }
|
13215 |
|
13216 | if (agentInfo.os.name === "ios") {
|
13217 | var majorVersion = agentInfo.os.majorVersion;
|
13218 |
|
13219 | if (majorVersion === 9) {
|
13220 | imageWidth = 1024;
|
13221 | }
|
13222 |
|
13223 |
|
13224 | if (majorVersion === 8) {
|
13225 | imageWidth = 512;
|
13226 | }
|
13227 | }
|
13228 |
|
13229 |
|
13230 | return Math.min(maxCubeMapTextureSize, imageWidth);
|
13231 | };
|
13232 |
|
13233 | __proto._shrinkCoord = function (coordData) {
|
13234 | var image = coordData.image,
|
13235 | faceCoords = coordData.faceCoords,
|
13236 | trim = coordData.trim;
|
13237 | var inputTextureSize = Array.isArray(image) ? this.getDimension(image[0]).width : this.getSourceTileSize(image);
|
13238 |
|
13239 | var SHRINK_MULTIPLIER = 1 - trim * (2 / inputTextureSize);
|
13240 | var axisMultipliers = [0, 1, 2].map(function (axisIndex) {
|
13241 | var axisDir = util.sign(faceCoords[0][axisIndex]);
|
13242 | var notSameDir = faceCoords.some(function (coord) {
|
13243 | return util.sign(coord[axisIndex]) !== axisDir;
|
13244 | });
|
13245 | return notSameDir;
|
13246 | }).map(function (notSameDir) {
|
13247 | return notSameDir ? SHRINK_MULTIPLIER : 1;
|
13248 | });
|
13249 | return faceCoords.map(function (coords) {
|
13250 | return coords.map(function (coord, axisIndex) {
|
13251 | return coord * axisMultipliers[axisIndex];
|
13252 | });
|
13253 | });
|
13254 | };
|
13255 |
|
13256 | CubeRenderer._VERTEX_POSITION_DATA = null;
|
13257 | CubeRenderer._INDEX_DATA = null;
|
13258 | return CubeRenderer;
|
13259 | }(Renderer);
|
13260 |
|
13261 | var CubeStripRenderer =
|
13262 |
|
13263 | function (_super) {
|
13264 | __extends(CubeStripRenderer, _super);
|
13265 |
|
13266 | function CubeStripRenderer() {
|
13267 | return _super !== null && _super.apply(this, arguments) || this;
|
13268 | }
|
13269 |
|
13270 | var __proto = CubeStripRenderer.prototype;
|
13271 |
|
13272 | __proto.getVertexShaderSource = function () {
|
13273 | return "\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvarying highp vec2 vTextureCoord;\nvoid main(void) {\n vTextureCoord = aTextureCoord;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
13274 | };
|
13275 |
|
13276 | __proto.getFragmentShaderSource = function () {
|
13277 | return "\n#define PI 3.14159265359\nprecision highp float;\nvarying highp vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform bool uIsEAC;\nconst vec2 OPERATE_COORDS_RANGE = vec2(-1.0, 1.0);\nconst vec2 TEXTURE_COORDS_RANGE = vec2(0.0, 1.0);\n// vector type is used for initializing values instead of array.\nconst vec4 TEXTURE_DIVISION_X = vec4(0.0, 1.0 / 3.0, 2.0 / 3.0, 1.0);\nconst vec3 TEXTURE_DIVISION_Y = vec3(0.0, 1.0 / 2.0, 1.0);\nconst float EAC_CONST = 2.0 / PI;\nfloat scale(vec2 domainRange, vec2 targetRange, float val) {\n float unit = 1.0 / (domainRange[1] - domainRange[0]);\n return targetRange[0] + (targetRange[1] - targetRange[0]) * (val - domainRange[0]) * unit;\n}\nvoid main(void) {\n float transformedCoordX;\n float transformedCoordY;\n\n if (uIsEAC) {\n vec2 orgTextureRangeX;\n vec2 orgTextureRangeY;\n\n // Apply EAC transform\n if (vTextureCoord.s >= TEXTURE_DIVISION_X[2]) {\n orgTextureRangeX = vec2(TEXTURE_DIVISION_X[2], TEXTURE_DIVISION_X[3]);\n } else if (vTextureCoord.s >= TEXTURE_DIVISION_X[1]) {\n orgTextureRangeX = vec2(TEXTURE_DIVISION_X[1], TEXTURE_DIVISION_X[2]);\n } else {\n orgTextureRangeX = vec2(TEXTURE_DIVISION_X[0], TEXTURE_DIVISION_X[1]);\n }\n\n if (vTextureCoord.t >= TEXTURE_DIVISION_Y[1]) {\n orgTextureRangeY = vec2(TEXTURE_DIVISION_Y[1], TEXTURE_DIVISION_Y[2]);\n } else {\n orgTextureRangeY = vec2(TEXTURE_DIVISION_Y[0], TEXTURE_DIVISION_Y[1]);\n }\n\n // scaling coors by the coordinates following the range from -1.0 to 1.0.\n float px = scale(orgTextureRangeX, OPERATE_COORDS_RANGE, vTextureCoord.s);\n float py = scale(orgTextureRangeY, OPERATE_COORDS_RANGE, vTextureCoord.t);\n\n float qu = EAC_CONST * atan(px) + 0.5;\n float qv = EAC_CONST * atan(py) + 0.5;\n\n // re-scaling coors by original coordinates ranges\n transformedCoordX = scale(TEXTURE_COORDS_RANGE, orgTextureRangeX, qu);\n transformedCoordY = scale(TEXTURE_COORDS_RANGE, orgTextureRangeY, qv);\n } else {\n // normal cubemap\n transformedCoordX = vTextureCoord.s;\n transformedCoordY = vTextureCoord.t;\n }\n\n gl_FragColor = texture2D(uSampler, vec2(transformedCoordX, transformedCoordY));\n}";
|
13278 | };
|
13279 |
|
13280 | __proto.getVertexPositionData = function () {
|
13281 | if (!this._vertices) {
|
13282 | this._vertices = [
|
13283 | 1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1,
|
13284 | -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1,
|
13285 | -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1,
|
13286 | -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1,
|
13287 | 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1,
|
13288 | -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1];
|
13289 | }
|
13290 |
|
13291 | return this._vertices;
|
13292 | };
|
13293 |
|
13294 | __proto.getIndexData = function () {
|
13295 | var _this = this;
|
13296 |
|
13297 |
|
13298 | var indices = function () {
|
13299 | var indexData = [];
|
13300 |
|
13301 | for (var i = 0; i < _this._vertices.length / 3; i += 4) {
|
13302 | indexData.push(i, i + 1, i + 2, i, i + 2, i + 3);
|
13303 | }
|
13304 |
|
13305 | return indexData;
|
13306 | }();
|
13307 |
|
13308 | return indices;
|
13309 | };
|
13310 |
|
13311 | __proto.getTextureCoordData = function (_a) {
|
13312 | var _this = this;
|
13313 |
|
13314 | var image = _a.image,
|
13315 | imageConfig = _a.imageConfig;
|
13316 |
|
13317 | var cols = 3;
|
13318 | var rows = 2;
|
13319 | var textureSize = this.getDimension(image);
|
13320 | var trim = imageConfig.trim;
|
13321 | var order = imageConfig.order || "RLUDFB";
|
13322 | var coords = [];
|
13323 |
|
13324 | for (var r = rows - 1; r >= 0; r--) {
|
13325 | for (var c = 0; c < cols; c++) {
|
13326 | var coord = [c / cols, r / rows, (c + 1) / cols, r / rows, (c + 1) / cols, (r + 1) / rows, c / cols, (r + 1) / rows];
|
13327 | coords.push(coord);
|
13328 | }
|
13329 | }
|
13330 |
|
13331 | var tileConfigs = this._extractTileConfig(imageConfig);
|
13332 |
|
13333 |
|
13334 | coords = coords
|
13335 | .map(function (coord) {
|
13336 | return _this._shrinkCoord(coord, textureSize, trim);
|
13337 | }).map(function (coord, i) {
|
13338 | return _this._transformCoord(coord, tileConfigs[i]);
|
13339 | });
|
13340 |
|
13341 | return "BFUDRL".split("").map(function (face) {
|
13342 | return order.indexOf(face);
|
13343 | }).map(function (index) {
|
13344 | return coords[index];
|
13345 | }).reduce(function (acc, val) {
|
13346 | return acc.concat(val);
|
13347 | }, []);
|
13348 | };
|
13349 |
|
13350 | __proto.updateTexture = function (gl, image) {
|
13351 | WebGLUtils.texImage2D(gl, gl.TEXTURE_2D, this._getPixelSource(image));
|
13352 | };
|
13353 |
|
13354 | __proto.bindTexture = function (gl, texture, image) {
|
13355 |
|
13356 | var _a = this.getDimension(image),
|
13357 | width = _a.width,
|
13358 | height = _a.height;
|
13359 |
|
13360 | var size = Math.max(width, height);
|
13361 | var maxSize = WebGLUtils.getMaxTextureSize(gl);
|
13362 |
|
13363 | if (size > maxSize) {
|
13364 | this._triggerError("Image width(" + width + ") exceeds device limit(" + maxSize + "))");
|
13365 |
|
13366 | return;
|
13367 | }
|
13368 |
|
13369 |
|
13370 | this._initPixelSource(image);
|
13371 |
|
13372 | gl.activeTexture(gl.TEXTURE0);
|
13373 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
13374 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
13375 | this.updateTexture(gl, image);
|
13376 | };
|
13377 |
|
13378 | __proto._transformCoord = function (coord, tileConfig) {
|
13379 | var newCoord = coord.slice();
|
13380 |
|
13381 | if (tileConfig.flipHorizontal) {
|
13382 | newCoord = this._flipHorizontalCoord(newCoord);
|
13383 | }
|
13384 |
|
13385 | if (tileConfig.rotation) {
|
13386 | newCoord = this._rotateCoord(newCoord, tileConfig.rotation);
|
13387 | }
|
13388 |
|
13389 | return newCoord;
|
13390 | };
|
13391 |
|
13392 | __proto._shrinkCoord = function (coord, textureSize, trim) {
|
13393 | var width = textureSize.width,
|
13394 | height = textureSize.height;
|
13395 |
|
13396 | var SHRINK_Y = trim * (1 / height);
|
13397 | var SHRINK_X = trim * (1 / width);
|
13398 | return [coord[0] + SHRINK_X, coord[1] + SHRINK_Y, coord[2] - SHRINK_X, coord[3] + SHRINK_Y, coord[4] - SHRINK_X, coord[5] - SHRINK_Y, coord[6] + SHRINK_X, coord[7] - SHRINK_Y];
|
13399 | };
|
13400 |
|
13401 | __proto._rotateCoord = function (coord, rotationAngle) {
|
13402 | var SIZE = 2;
|
13403 |
|
13404 | var shiftCount = Math.floor(rotationAngle / 90) % 4;
|
13405 |
|
13406 | if (shiftCount === 0) {
|
13407 | return coord;
|
13408 | }
|
13409 |
|
13410 | var moved;
|
13411 | var rotatedCoord = [];
|
13412 |
|
13413 | if (shiftCount > 0) {
|
13414 | moved = coord.splice(0, shiftCount * SIZE);
|
13415 | rotatedCoord = coord.concat(moved);
|
13416 | } else {
|
13417 | moved = coord.splice((4 + shiftCount) * SIZE, -shiftCount * SIZE);
|
13418 | rotatedCoord = moved.concat(coord);
|
13419 | }
|
13420 |
|
13421 | return rotatedCoord;
|
13422 | };
|
13423 |
|
13424 | __proto._flipHorizontalCoord = function (coord) {
|
13425 | return [coord[2], coord[3], coord[0], coord[1], coord[6], coord[7], coord[4], coord[5]];
|
13426 | };
|
13427 |
|
13428 | return CubeStripRenderer;
|
13429 | }(Renderer);
|
13430 |
|
13431 | var latitudeBands = 60;
|
13432 | var longitudeBands = 60;
|
13433 | var radius = 2;
|
13434 | var ANGLE_CORRECTION_FOR_CENTER_ALIGN = -0.5 * Math.PI;
|
13435 | var textureCoordData = [];
|
13436 | var vertexPositionData = [];
|
13437 | var indexData = [];
|
13438 | var latIdx;
|
13439 | var lngIdx;
|
13440 |
|
13441 | for (latIdx = 0; latIdx <= latitudeBands; latIdx++) {
|
13442 | var theta = (latIdx / latitudeBands - 0.5) * Math.PI;
|
13443 | var sinTheta = Math.sin(theta);
|
13444 | var cosTheta = Math.cos(theta);
|
13445 |
|
13446 | for (lngIdx = 0; lngIdx <= longitudeBands; lngIdx++) {
|
13447 | var phi = (lngIdx / longitudeBands - 0.5) * 2 * Math.PI + ANGLE_CORRECTION_FOR_CENTER_ALIGN;
|
13448 | var sinPhi = Math.sin(phi);
|
13449 | var cosPhi = Math.cos(phi);
|
13450 | var x = cosPhi * cosTheta;
|
13451 | var y = sinTheta;
|
13452 | var z = sinPhi * cosTheta;
|
13453 | var u = lngIdx / longitudeBands;
|
13454 | var v = latIdx / latitudeBands;
|
13455 | textureCoordData.push(u, v);
|
13456 | vertexPositionData.push(radius * x, radius * y, radius * z);
|
13457 |
|
13458 | if (lngIdx !== longitudeBands && latIdx !== latitudeBands) {
|
13459 | var a = latIdx * (longitudeBands + 1) + lngIdx;
|
13460 | var b = a + longitudeBands + 1;
|
13461 | indexData.push(a, b, a + 1, b, b + 1, a + 1);
|
13462 | }
|
13463 | }
|
13464 | }
|
13465 |
|
13466 | var SphereRenderer =
|
13467 |
|
13468 | function (_super) {
|
13469 | __extends(SphereRenderer, _super);
|
13470 |
|
13471 | function SphereRenderer(format) {
|
13472 | var _this = _super.call(this) || this;
|
13473 |
|
13474 | _this._stereoFormat = format;
|
13475 | return _this;
|
13476 | }
|
13477 |
|
13478 | var __proto = SphereRenderer.prototype;
|
13479 |
|
13480 | __proto.render = function (ctx) {
|
13481 | var gl = ctx.gl,
|
13482 | shaderProgram = ctx.shaderProgram;
|
13483 | var leftEyeScaleOffset;
|
13484 | var rightEyeScaleOffset;
|
13485 |
|
13486 | switch (this._stereoFormat) {
|
13487 | case STEREO_FORMAT.TOP_BOTTOM:
|
13488 | leftEyeScaleOffset = [1, 0.5, 0, 0];
|
13489 | rightEyeScaleOffset = [1, 0.5, 0, 0.5];
|
13490 | break;
|
13491 |
|
13492 | case STEREO_FORMAT.LEFT_RIGHT:
|
13493 | leftEyeScaleOffset = [0.5, 1, 0, 0];
|
13494 | rightEyeScaleOffset = [0.5, 1, 0.5, 0];
|
13495 | break;
|
13496 |
|
13497 | default:
|
13498 | leftEyeScaleOffset = [1, 1, 0, 0];
|
13499 | rightEyeScaleOffset = [1, 1, 0, 0];
|
13500 | }
|
13501 |
|
13502 | var uTexScaleOffset = gl.getUniformLocation(shaderProgram, "uTexScaleOffset");
|
13503 | gl.uniform4fv(uTexScaleOffset, __spread(leftEyeScaleOffset, rightEyeScaleOffset));
|
13504 |
|
13505 | _super.prototype.render.call(this, ctx);
|
13506 | };
|
13507 |
|
13508 | __proto.getVertexPositionData = function () {
|
13509 | return SphereRenderer._VERTEX_POSITION_DATA;
|
13510 | };
|
13511 |
|
13512 | __proto.getIndexData = function () {
|
13513 | return SphereRenderer._INDEX_DATA;
|
13514 | };
|
13515 |
|
13516 | __proto.getTextureCoordData = function () {
|
13517 | return SphereRenderer._TEXTURE_COORD_DATA;
|
13518 | };
|
13519 |
|
13520 | __proto.getVertexShaderSource = function () {
|
13521 | return "\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nuniform float uEye;\nuniform vec4 uTexScaleOffset[2];\nvarying highp vec2 vTextureCoord;\nvoid main(void) {\n vec4 scaleOffset = uTexScaleOffset[int(uEye)];\n vTextureCoord = aTextureCoord.xy * scaleOffset.xy + scaleOffset.zw;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
13522 | };
|
13523 |
|
13524 | __proto.getFragmentShaderSource = function () {
|
13525 | return "\nprecision highp float;\nvarying highp vec2 vTextureCoord;\nuniform sampler2D uSampler;\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vTextureCoord.st);\n}";
|
13526 | };
|
13527 |
|
13528 | __proto.updateTexture = function (gl, image) {
|
13529 | WebGLUtils.texImage2D(gl, gl.TEXTURE_2D, this._getPixelSource(image));
|
13530 | };
|
13531 |
|
13532 | __proto.bindTexture = function (gl, texture, image) {
|
13533 |
|
13534 | var _a = this.getDimension(image),
|
13535 | width = _a.width,
|
13536 | height = _a.height;
|
13537 |
|
13538 | var size = Math.max(width, height);
|
13539 | var maxSize = WebGLUtils.getMaxTextureSize(gl);
|
13540 |
|
13541 | if (size > maxSize) {
|
13542 | this._triggerError("Image width(" + width + ") exceeds device limit(" + maxSize + "))");
|
13543 |
|
13544 | return;
|
13545 | }
|
13546 |
|
13547 |
|
13548 | this._initPixelSource(image);
|
13549 |
|
13550 | gl.activeTexture(gl.TEXTURE0);
|
13551 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
13552 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
13553 | this.updateTexture(gl, image);
|
13554 | };
|
13555 |
|
13556 | SphereRenderer._VERTEX_POSITION_DATA = vertexPositionData;
|
13557 | SphereRenderer._TEXTURE_COORD_DATA = textureCoordData;
|
13558 | SphereRenderer._INDEX_DATA = indexData;
|
13559 | return SphereRenderer;
|
13560 | }(Renderer);
|
13561 |
|
13562 | var MIN_ASPECT_RATIO_FOR_FULL_PANORAMA = 6;
|
13563 | var longitudeBands$1 = 60;
|
13564 | var textureCoordData$1 = [];
|
13565 | var vertexPositionData$1 = [];
|
13566 | var indexData$1 = [];
|
13567 |
|
13568 | var CylinderRenderer =
|
13569 |
|
13570 | function (_super) {
|
13571 | __extends(CylinderRenderer, _super);
|
13572 |
|
13573 | function CylinderRenderer() {
|
13574 | return _super !== null && _super.apply(this, arguments) || this;
|
13575 | }
|
13576 |
|
13577 | var __proto = CylinderRenderer.prototype;
|
13578 |
|
13579 | __proto.getVertexPositionData = function () {
|
13580 | return CylinderRenderer._VERTEX_POSITION_DATA;
|
13581 | };
|
13582 |
|
13583 | __proto.getIndexData = function () {
|
13584 | return CylinderRenderer._INDEX_DATA;
|
13585 | };
|
13586 |
|
13587 | __proto.getTextureCoordData = function () {
|
13588 | return CylinderRenderer._TEXTURE_COORD_DATA;
|
13589 | };
|
13590 |
|
13591 | __proto.getVertexShaderSource = function () {
|
13592 | return "\nattribute vec3 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform mat4 uMVMatrix;\nuniform mat4 uPMatrix;\nvarying highp vec2 vTextureCoord;\nvoid main(void) {\n vTextureCoord = aTextureCoord;\n gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);\n}";
|
13593 | };
|
13594 |
|
13595 | __proto.getFragmentShaderSource = function () {
|
13596 | return "\nprecision highp float;\nvarying highp vec2 vTextureCoord;\nuniform sampler2D uSampler;\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));\n}";
|
13597 | };
|
13598 |
|
13599 | __proto.updateTexture = function (gl, image) {
|
13600 | WebGLUtils.texImage2D(gl, gl.TEXTURE_2D, this._getPixelSource(image));
|
13601 | };
|
13602 |
|
13603 | __proto.bindTexture = function (gl, texture, image) {
|
13604 |
|
13605 | var _a = this.getDimension(image),
|
13606 | width = _a.width,
|
13607 | height = _a.height;
|
13608 |
|
13609 | var size = Math.max(width, height);
|
13610 | var maxSize = WebGLUtils.getMaxTextureSize(gl);
|
13611 | var resizeDimension;
|
13612 |
|
13613 | if (size > maxSize) {
|
13614 | this._triggerError("Image width(" + width + ") exceeds device texture limit(" + maxSize + "))");
|
13615 |
|
13616 | |
13617 |
|
13618 |
|
13619 |
|
13620 |
|
13621 | resizeDimension = width > height ? {
|
13622 | width: maxSize,
|
13623 | height: maxSize * height / width
|
13624 | } : {
|
13625 | width: maxSize * width / height,
|
13626 | height: maxSize
|
13627 | };
|
13628 | }
|
13629 |
|
13630 |
|
13631 | this._initPixelSource(image, resizeDimension);
|
13632 |
|
13633 | gl.activeTexture(gl.TEXTURE0);
|
13634 | gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
13635 | gl.bindTexture(gl.TEXTURE_2D, texture);
|
13636 | this.updateTexture(gl, image);
|
13637 | };
|
13638 |
|
13639 | __proto.updateShaderData = function (_a) {
|
13640 | var _b = _a.imageAspectRatio,
|
13641 | imageAspectRatio = _b === void 0 ? MIN_ASPECT_RATIO_FOR_FULL_PANORAMA : _b;
|
13642 | var lngIdx;
|
13643 | var cylinderMaxRadian;
|
13644 | var halfCylinderY;
|
13645 | var rotated;
|
13646 | var aspectRatio;
|
13647 |
|
13648 | if (imageAspectRatio < 1) {
|
13649 | |
13650 |
|
13651 |
|
13652 |
|
13653 | rotated = true;
|
13654 | aspectRatio = 1 / imageAspectRatio;
|
13655 | } else {
|
13656 | rotated = false;
|
13657 | aspectRatio = imageAspectRatio;
|
13658 | }
|
13659 |
|
13660 | if (aspectRatio >= MIN_ASPECT_RATIO_FOR_FULL_PANORAMA) {
|
13661 | var fov = 360 / aspectRatio;
|
13662 | cylinderMaxRadian = 2 * Math.PI;
|
13663 |
|
13664 | halfCylinderY = Math.tan(toRadian(fov / 2));
|
13665 | } else {
|
13666 | cylinderMaxRadian = aspectRatio;
|
13667 | halfCylinderY = 0.5;
|
13668 | }
|
13669 |
|
13670 |
|
13671 | textureCoordData$1.length = 0;
|
13672 | vertexPositionData$1.length = 0;
|
13673 | indexData$1.length = 0;
|
13674 | var CYLIDER_Y = [-halfCylinderY, halfCylinderY];
|
13675 | var startAngleForCenterAlign = Math.PI / 2 + (2 * Math.PI - cylinderMaxRadian) / 2;
|
13676 |
|
13677 |
|
13678 | for (var yIdx = 0, yLength = CYLIDER_Y.length; yIdx < yLength
|
13679 |
|
13680 | ; yIdx++) {
|
13681 | for (lngIdx = 0; lngIdx <= longitudeBands$1; lngIdx++) {
|
13682 | var angle = startAngleForCenterAlign + lngIdx / longitudeBands$1 * cylinderMaxRadian;
|
13683 | var x = Math.cos(angle);
|
13684 | var y = CYLIDER_Y[yIdx];
|
13685 | var z = Math.sin(angle);
|
13686 | var u = void 0;
|
13687 | var v = void 0;
|
13688 |
|
13689 | if (rotated) {
|
13690 |
|
13691 | u = 1 - yIdx;
|
13692 |
|
13693 | v = lngIdx / longitudeBands$1;
|
13694 | } else {
|
13695 |
|
13696 | u = lngIdx / longitudeBands$1;
|
13697 | v = yIdx;
|
13698 | }
|
13699 |
|
13700 | textureCoordData$1.push(u, v);
|
13701 | vertexPositionData$1.push(x, y, z);
|
13702 |
|
13703 | if (yIdx === 0 && lngIdx < longitudeBands$1) {
|
13704 | var a = lngIdx;
|
13705 | var b = a + longitudeBands$1 + 1;
|
13706 | indexData$1.push(a, b, a + 1, b, b + 1, a + 1);
|
13707 | }
|
13708 | }
|
13709 | }
|
13710 | };
|
13711 |
|
13712 | CylinderRenderer._VERTEX_POSITION_DATA = vertexPositionData$1;
|
13713 | CylinderRenderer._TEXTURE_COORD_DATA = textureCoordData$1;
|
13714 | CylinderRenderer._INDEX_DATA = indexData$1;
|
13715 | return CylinderRenderer;
|
13716 | }(Renderer);
|
13717 |
|
13718 | var VR_DISPLAY_PRESENT_CHANGE = "vrdisplaypresentchange";
|
13719 | var DEFAULT_LEFT_BOUNDS = [0, 0, 0.5, 1];
|
13720 | var DEFAULT_RIGHT_BOUNDS = [0.5, 0, 0.5, 1];
|
13721 | var EYES = {
|
13722 | LEFT: "left",
|
13723 | RIGHT: "right"
|
13724 | };
|
13725 |
|
13726 | var VRManager =
|
13727 |
|
13728 | function () {
|
13729 | function VRManager() {
|
13730 | var _this = this;
|
13731 |
|
13732 | this.destroy = function () {
|
13733 | var vrDisplay = _this._vrDisplay;
|
13734 |
|
13735 | _this.removeEndCallback(_this.destroy);
|
13736 |
|
13737 | if (vrDisplay && vrDisplay.isPresenting) {
|
13738 | void vrDisplay.exitPresent();
|
13739 | }
|
13740 |
|
13741 | _this._clear();
|
13742 | };
|
13743 |
|
13744 | this._frameData = new window.VRFrameData();
|
13745 |
|
13746 | this._clear();
|
13747 | }
|
13748 |
|
13749 | var __proto = VRManager.prototype;
|
13750 | Object.defineProperty(__proto, "context", {
|
13751 | get: function () {
|
13752 | return this._vrDisplay;
|
13753 | },
|
13754 | enumerable: false,
|
13755 | configurable: true
|
13756 | });
|
13757 |
|
13758 | __proto.canRender = function () {
|
13759 | return Boolean(this._vrDisplay);
|
13760 | };
|
13761 |
|
13762 | __proto.beforeRender = function (gl) {
|
13763 |
|
13764 | gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
13765 | };
|
13766 |
|
13767 | __proto.afterRender = function () {
|
13768 | this._vrDisplay.submitFrame();
|
13769 | };
|
13770 |
|
13771 | __proto.getEyeParams = function (gl) {
|
13772 | var display = this._vrDisplay;
|
13773 | var halfWidth = gl.drawingBufferWidth * 0.5;
|
13774 | var height = gl.drawingBufferHeight;
|
13775 | var frameData = this._frameData;
|
13776 | display.getFrameData(frameData);
|
13777 | var leftMVMatrix = frameData.leftViewMatrix;
|
13778 | var rightMVMatrix = frameData.rightViewMatrix;
|
13779 | rotateY(leftMVMatrix, leftMVMatrix, this._yawOffset);
|
13780 | rotateY(rightMVMatrix, rightMVMatrix, this._yawOffset);
|
13781 | return [{
|
13782 | viewport: [0, 0, halfWidth, height],
|
13783 | mvMatrix: leftMVMatrix,
|
13784 | pMatrix: frameData.leftProjectionMatrix
|
13785 | }, {
|
13786 | viewport: [halfWidth, 0, halfWidth, height],
|
13787 | mvMatrix: rightMVMatrix,
|
13788 | pMatrix: frameData.rightProjectionMatrix
|
13789 | }];
|
13790 | };
|
13791 |
|
13792 | __proto.isPresenting = function () {
|
13793 | return Boolean(this._vrDisplay && this._vrDisplay.isPresenting);
|
13794 | };
|
13795 |
|
13796 | __proto.addEndCallback = function (callback) {
|
13797 | window.addEventListener(VR_DISPLAY_PRESENT_CHANGE, callback);
|
13798 | };
|
13799 |
|
13800 | __proto.removeEndCallback = function (callback) {
|
13801 | window.removeEventListener(VR_DISPLAY_PRESENT_CHANGE, callback);
|
13802 | };
|
13803 |
|
13804 | __proto.requestPresent = function (canvas) {
|
13805 | var _this = this;
|
13806 |
|
13807 | return navigator.getVRDisplays().then(function (displays) {
|
13808 | var vrDisplay = displays.length && displays[0];
|
13809 |
|
13810 | if (!vrDisplay) {
|
13811 | return Promise$1.reject(new Error("No displays available."));
|
13812 | }
|
13813 |
|
13814 | if (!vrDisplay.capabilities.canPresent) {
|
13815 | return Promise$1.reject(new Error("Display lacking capability to present."));
|
13816 | }
|
13817 |
|
13818 | return vrDisplay.requestPresent([{
|
13819 | source: canvas
|
13820 | }]).then(function () {
|
13821 | var leftEye = vrDisplay.getEyeParameters(EYES.LEFT);
|
13822 | var rightEye = vrDisplay.getEyeParameters(EYES.RIGHT);
|
13823 | canvas.width = Math.max(leftEye.renderWidth, rightEye.renderWidth) * 2;
|
13824 | canvas.height = Math.max(leftEye.renderHeight, rightEye.renderHeight);
|
13825 |
|
13826 | _this._setDisplay(vrDisplay);
|
13827 | });
|
13828 | });
|
13829 | };
|
13830 |
|
13831 | __proto.setYawOffset = function (offset) {
|
13832 | this._yawOffset = offset;
|
13833 | };
|
13834 |
|
13835 | __proto._setDisplay = function (vrDisplay) {
|
13836 | this._vrDisplay = vrDisplay;
|
13837 | var layers = vrDisplay.getLayers();
|
13838 |
|
13839 | if (layers.length) {
|
13840 | var layer = layers[0];
|
13841 | this._leftBounds = layer.leftBounds;
|
13842 | this._rightBounds = layer.rightBounds;
|
13843 | }
|
13844 |
|
13845 | this.addEndCallback(this.destroy);
|
13846 | };
|
13847 |
|
13848 | __proto._clear = function () {
|
13849 | this._vrDisplay = null;
|
13850 | this._leftBounds = DEFAULT_LEFT_BOUNDS;
|
13851 | this._rightBounds = DEFAULT_RIGHT_BOUNDS;
|
13852 | this._yawOffset = 0;
|
13853 | };
|
13854 |
|
13855 | return VRManager;
|
13856 | }();
|
13857 |
|
13858 | var XR_REFERENCE_SPACE = "local";
|
13859 |
|
13860 | var XRManager =
|
13861 |
|
13862 | function () {
|
13863 | function XRManager(options) {
|
13864 | var _this = this;
|
13865 |
|
13866 | if (options === void 0) {
|
13867 | options = {};
|
13868 | }
|
13869 |
|
13870 | this.destroy = function () {
|
13871 | var xrSession = _this._xrSession;
|
13872 |
|
13873 | _this.removeEndCallback(_this.destroy);
|
13874 |
|
13875 | if (xrSession) {
|
13876 |
|
13877 | xrSession.end().then(function () {
|
13878 | return void 0;
|
13879 | }, function () {
|
13880 | return void 0;
|
13881 | });
|
13882 | }
|
13883 |
|
13884 | _this._clear();
|
13885 | };
|
13886 |
|
13887 | this._clear();
|
13888 |
|
13889 | this._options = options;
|
13890 | }
|
13891 |
|
13892 | var __proto = XRManager.prototype;
|
13893 | Object.defineProperty(__proto, "context", {
|
13894 | get: function () {
|
13895 | return this._xrSession;
|
13896 | },
|
13897 | enumerable: false,
|
13898 | configurable: true
|
13899 | });
|
13900 |
|
13901 | __proto.canRender = function (frame) {
|
13902 | var pose = frame.getViewerPose(this._xrRefSpace);
|
13903 | return Boolean(pose);
|
13904 | };
|
13905 |
|
13906 | __proto.beforeRender = function (gl, frame) {
|
13907 | var session = frame.session;
|
13908 | var baseLayer = session.renderState.baseLayer;
|
13909 | gl.bindFramebuffer(gl.FRAMEBUFFER, baseLayer.framebuffer);
|
13910 | };
|
13911 |
|
13912 |
|
13913 | __proto.afterRender = function () {};
|
13914 |
|
13915 | __proto.getEyeParams = function (gl, frame) {
|
13916 | var _this = this;
|
13917 |
|
13918 | var session = frame.session;
|
13919 | var pose = frame.getViewerPose(this._xrRefSpace);
|
13920 |
|
13921 | if (!pose) {
|
13922 |
|
13923 | return null;
|
13924 | }
|
13925 |
|
13926 | var glLayer = session.renderState.baseLayer;
|
13927 | return pose.views.map(function (view) {
|
13928 | var viewport = glLayer.getViewport(view);
|
13929 | var mvMatrix = view.transform.inverse.matrix;
|
13930 |
|
13931 | if (IS_SAFARI_ON_DESKTOP) {
|
13932 | rotateX(mvMatrix, mvMatrix, toRadian(180));
|
13933 | }
|
13934 |
|
13935 | rotateY(mvMatrix, mvMatrix, _this._yawOffset);
|
13936 | return {
|
13937 | viewport: [viewport.x, viewport.y, viewport.width, viewport.height],
|
13938 | mvMatrix: mvMatrix,
|
13939 | pMatrix: view.projectionMatrix
|
13940 | };
|
13941 | });
|
13942 | };
|
13943 |
|
13944 | __proto.isPresenting = function () {
|
13945 | return this._presenting;
|
13946 | };
|
13947 |
|
13948 | __proto.addEndCallback = function (callback) {
|
13949 | var _a;
|
13950 |
|
13951 | (_a = this._xrSession) === null || _a === void 0 ? void 0 : _a.addEventListener("end", callback);
|
13952 | };
|
13953 |
|
13954 | __proto.removeEndCallback = function (callback) {
|
13955 | var _a;
|
13956 |
|
13957 | (_a = this._xrSession) === null || _a === void 0 ? void 0 : _a.removeEventListener("end", callback);
|
13958 | };
|
13959 |
|
13960 | __proto.requestPresent = function (canvas, gl) {
|
13961 | return __awaiter(this, void 0, void 0, function () {
|
13962 | var options, attributes;
|
13963 |
|
13964 | var _this = this;
|
13965 |
|
13966 | return __generator(this, function (_a) {
|
13967 | switch (_a.label) {
|
13968 | case 0:
|
13969 | options = merge({
|
13970 | requiredFeatures: [XR_REFERENCE_SPACE]
|
13971 | }, this._options);
|
13972 | attributes = gl.getContextAttributes();
|
13973 | if (!(attributes && attributes.xrCompatible !== true)) return [3
|
13974 |
|
13975 | , 2];
|
13976 | return [4
|
13977 |
|
13978 | , gl.makeXRCompatible()];
|
13979 |
|
13980 | case 1:
|
13981 | _a.sent();
|
13982 |
|
13983 | _a.label = 2;
|
13984 |
|
13985 | case 2:
|
13986 | return [2
|
13987 |
|
13988 | , navigator.xr.requestSession("immersive-vr", options).then(function (session) {
|
13989 | var xrLayer = new window.XRWebGLLayer(session, gl);
|
13990 | session.updateRenderState({
|
13991 | baseLayer: xrLayer
|
13992 | });
|
13993 | return session.requestReferenceSpace(XR_REFERENCE_SPACE).then(function (refSpace) {
|
13994 | _this._setSession(session, xrLayer, refSpace);
|
13995 | });
|
13996 | })];
|
13997 | }
|
13998 | });
|
13999 | });
|
14000 | };
|
14001 |
|
14002 | __proto.setYawOffset = function (offset) {
|
14003 | this._yawOffset = offset;
|
14004 | };
|
14005 |
|
14006 | __proto._setSession = function (session, xrLayer, refSpace) {
|
14007 | this._xrSession = session;
|
14008 | this._xrLayer = xrLayer;
|
14009 | this._xrRefSpace = refSpace;
|
14010 | this._presenting = true;
|
14011 | this.addEndCallback(this.destroy);
|
14012 | };
|
14013 |
|
14014 | __proto._clear = function () {
|
14015 | this._xrSession = null;
|
14016 | this._xrLayer = null;
|
14017 | this._xrRefSpace = null;
|
14018 | this._presenting = false;
|
14019 | this._yawOffset = 0;
|
14020 | this._options = {};
|
14021 | };
|
14022 |
|
14023 | return XRManager;
|
14024 | }();
|
14025 |
|
14026 | var WebGLAnimator =
|
14027 |
|
14028 | function () {
|
14029 | function WebGLAnimator() {
|
14030 | var _this = this;
|
14031 | |
14032 |
|
14033 |
|
14034 |
|
14035 |
|
14036 | this._onLoop = function () {
|
14037 | var args = [];
|
14038 |
|
14039 | for (var _i = 0; _i < arguments.length; _i++) {
|
14040 | args[_i] = arguments[_i];
|
14041 | }
|
14042 |
|
14043 | _this._callback.apply(_this, __spread(args));
|
14044 |
|
14045 | _this._rafId = _this._context.requestAnimationFrame(_this._onLoop);
|
14046 | };
|
14047 | |
14048 |
|
14049 |
|
14050 |
|
14051 |
|
14052 |
|
14053 |
|
14054 |
|
14055 |
|
14056 |
|
14057 |
|
14058 | this._onLoopNextTick = function () {
|
14059 | var args = [];
|
14060 |
|
14061 | for (var _i = 0; _i < arguments.length; _i++) {
|
14062 | args[_i] = arguments[_i];
|
14063 | }
|
14064 |
|
14065 | var before = performance.now();
|
14066 |
|
14067 | _this._callback.apply(_this, __spread(args));
|
14068 |
|
14069 | var diff = performance.now() - before;
|
14070 |
|
14071 | if (_this._rafTimer >= 0) {
|
14072 | clearTimeout(_this._rafTimer);
|
14073 | _this._rafTimer = -1;
|
14074 | }
|
14075 |
|
14076 |
|
14077 |
|
14078 | if (diff < 16) {
|
14079 | _this._rafId = _this._context.requestAnimationFrame(_this._onLoop);
|
14080 | } else {
|
14081 |
|
14082 | _this._rafTimer = window.setTimeout(_this._onLoop, 0);
|
14083 | }
|
14084 | };
|
14085 |
|
14086 | this._callback = null;
|
14087 | this._context = window;
|
14088 | this._rafId = -1;
|
14089 | this._rafTimer = -1;
|
14090 | }
|
14091 |
|
14092 | var __proto = WebGLAnimator.prototype;
|
14093 |
|
14094 | __proto.setCallback = function (callback) {
|
14095 | this._callback = callback;
|
14096 | };
|
14097 |
|
14098 | __proto.setContext = function (context) {
|
14099 | this._context = context;
|
14100 | };
|
14101 |
|
14102 | __proto.start = function () {
|
14103 | var context = this._context;
|
14104 | var callback = this._callback;
|
14105 |
|
14106 | if (!context || !callback) return;
|
14107 |
|
14108 | if (this._rafId >= 0 || this._rafTimer >= 0) return;
|
14109 |
|
14110 | if (IS_SAFARI_ON_DESKTOP) {
|
14111 | this._rafId = context.requestAnimationFrame(this._onLoopNextTick);
|
14112 | } else {
|
14113 | this._rafId = context.requestAnimationFrame(this._onLoop);
|
14114 | }
|
14115 | };
|
14116 |
|
14117 | __proto.stop = function () {
|
14118 | if (this._rafId >= 0) {
|
14119 | this._context.cancelAnimationFrame(this._rafId);
|
14120 | }
|
14121 |
|
14122 | if (this._rafTimer >= 0) {
|
14123 | clearTimeout(this._rafTimer);
|
14124 | }
|
14125 |
|
14126 | this._rafId = -1;
|
14127 | this._rafTimer = -1;
|
14128 | };
|
14129 |
|
14130 | return WebGLAnimator;
|
14131 | }();
|
14132 |
|
14133 | var ImageType = PROJECTION_TYPE;
|
14134 |
|
14135 | var DEVICE_PIXEL_RATIO = devicePixelRatio || 1;
|
14136 |
|
14137 | if (DEVICE_PIXEL_RATIO > 2) {
|
14138 | DEVICE_PIXEL_RATIO = 2;
|
14139 | }
|
14140 |
|
14141 | |
14142 |
|
14143 |
|
14144 |
|
14145 |
|
14146 |
|
14147 |
|
14148 | var EVENTS$1 = {
|
14149 | BIND_TEXTURE: "bindTexture",
|
14150 | IMAGE_LOADED: "imageLoaded",
|
14151 | ERROR: "error",
|
14152 | RENDERING_CONTEXT_LOST: "renderingContextLost",
|
14153 | RENDERING_CONTEXT_RESTORE: "renderingContextRestore"
|
14154 | };
|
14155 | var ERROR_TYPE$1 = {
|
14156 | INVALID_DEVICE: 10,
|
14157 | NO_WEBGL: 11,
|
14158 | FAIL_IMAGE_LOAD: 12,
|
14159 | RENDERER_ERROR: 13
|
14160 | };
|
14161 |
|
14162 | var PanoImageRenderer =
|
14163 |
|
14164 | function (_super) {
|
14165 | __extends(PanoImageRenderer, _super);
|
14166 |
|
14167 | function PanoImageRenderer(image, width, height, isVideo, container, canvasClass, sphericalConfig, renderingContextAttributes) {
|
14168 | var _this =
|
14169 | _super.call(this) || this;
|
14170 |
|
14171 | _this.textureCoordBuffer = null;
|
14172 | _this.vertexBuffer = null;
|
14173 | _this.indexBuffer = null;
|
14174 |
|
14175 | _this.exitVR = function () {
|
14176 | var vr = _this._vr;
|
14177 | var gl = _this.context;
|
14178 | var animator = _this._animator;
|
14179 | if (!vr) return;
|
14180 | vr.removeEndCallback(_this.exitVR);
|
14181 | vr.destroy();
|
14182 | _this._vr = null;
|
14183 |
|
14184 | if (IS_IOS) {
|
14185 | _this._restoreStyle();
|
14186 | }
|
14187 |
|
14188 | _this.updateViewportDimensions(_this.width, _this.height);
|
14189 |
|
14190 | _this._updateViewport();
|
14191 |
|
14192 | gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
14193 |
|
14194 | _this._bindBuffers();
|
14195 |
|
14196 | _this._shouldForceDraw = true;
|
14197 | animator.stop();
|
14198 | animator.setContext(window);
|
14199 | animator.setCallback(_this._render.bind(_this));
|
14200 | animator.start();
|
14201 | };
|
14202 |
|
14203 | _this._renderStereo = function (time, frame) {
|
14204 | var e_1, _a;
|
14205 |
|
14206 | var vr = _this._vr;
|
14207 | var gl = _this.context;
|
14208 | var eyeParams = vr.getEyeParams(gl, frame);
|
14209 | if (!eyeParams) return;
|
14210 | vr.beforeRender(gl, frame);
|
14211 |
|
14212 | try {
|
14213 |
|
14214 | for (var _b = __values([0, 1]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
14215 | var eyeIndex = _c.value;
|
14216 | var eyeParam = eyeParams[eyeIndex];
|
14217 | _this.mvMatrix = eyeParam.mvMatrix;
|
14218 | _this.pMatrix = eyeParam.pMatrix;
|
14219 | gl.viewport.apply(gl, __spread(eyeParam.viewport));
|
14220 | gl.uniform1f(_this.shaderProgram.uEye, eyeIndex);
|
14221 |
|
14222 | _this._bindBuffers();
|
14223 |
|
14224 | _this._draw();
|
14225 | }
|
14226 | } catch (e_1_1) {
|
14227 | e_1 = {
|
14228 | error: e_1_1
|
14229 | };
|
14230 | } finally {
|
14231 | try {
|
14232 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
14233 | } finally {
|
14234 | if (e_1) throw e_1.error;
|
14235 | }
|
14236 | }
|
14237 |
|
14238 | vr.afterRender();
|
14239 | };
|
14240 |
|
14241 | _this._onFirstVRFrame = function (time, frame) {
|
14242 | var vr = _this._vr;
|
14243 | var gl = _this.context;
|
14244 | var animator = _this._animator;
|
14245 |
|
14246 | if (!vr.canRender(frame)) return;
|
14247 | var minusZDir = fromValues(0, 0, -1);
|
14248 | var eyeParam = vr.getEyeParams(gl, frame)[0];
|
14249 |
|
14250 | var mvMatrix = fromMat4(create(), eyeParam.mvMatrix);
|
14251 | var pMatrix = fromMat4(create(), eyeParam.pMatrix);
|
14252 | var mvInv = invert(create(), mvMatrix);
|
14253 | var pInv = invert(create(), pMatrix);
|
14254 | var viewDir = transformMat3(create$2(), minusZDir, pInv);
|
14255 | transformMat3(viewDir, viewDir, mvInv);
|
14256 | var yawOffset = util.yawOffsetBetween(viewDir, fromValues(0, 0, 1));
|
14257 |
|
14258 | if (yawOffset === 0) {
|
14259 |
|
14260 |
|
14261 | return;
|
14262 | }
|
14263 |
|
14264 | vr.setYawOffset(yawOffset);
|
14265 | animator.setCallback(_this._renderStereo);
|
14266 | };
|
14267 |
|
14268 | _this.sphericalConfig = sphericalConfig;
|
14269 | _this.fieldOfView = sphericalConfig.fieldOfView;
|
14270 | _this.width = width;
|
14271 | _this.height = height;
|
14272 | _this._lastQuaternion = null;
|
14273 | _this._lastYaw = null;
|
14274 | _this._lastPitch = null;
|
14275 | _this._lastFieldOfView = null;
|
14276 | _this.pMatrix = create$1();
|
14277 | _this.mvMatrix = create$1();
|
14278 |
|
14279 | perspective(_this.pMatrix, toRadian(_this.fieldOfView), width / height, 0.1, 100);
|
14280 | _this.textureCoordBuffer = null;
|
14281 | _this.vertexBuffer = null;
|
14282 | _this.indexBuffer = null;
|
14283 | _this.canvas = _this._initCanvas(container, canvasClass, width, height);
|
14284 |
|
14285 | _this._setDefaultCanvasStyle();
|
14286 |
|
14287 | _this._wrapper = null;
|
14288 |
|
14289 | _this._wrapperOrigStyle = null;
|
14290 | _this._renderingContextAttributes = renderingContextAttributes;
|
14291 | _this._image = null;
|
14292 | _this._imageConfig = null;
|
14293 | _this._imageIsReady = false;
|
14294 | _this._shouldForceDraw = false;
|
14295 | _this._keepUpdate = false;
|
14296 |
|
14297 | _this._onContentLoad = _this._onContentLoad.bind(_this);
|
14298 | _this._onContentError = _this._onContentError.bind(_this);
|
14299 | _this._animator = new WebGLAnimator();
|
14300 |
|
14301 | _this._vr = null;
|
14302 |
|
14303 | if (image) {
|
14304 | _this.setImage({
|
14305 | image: image,
|
14306 | imageType: sphericalConfig.imageType,
|
14307 | isVideo: isVideo,
|
14308 | cubemapConfig: sphericalConfig.cubemapConfig
|
14309 | });
|
14310 | }
|
14311 |
|
14312 | return _this;
|
14313 | }
|
14314 |
|
14315 |
|
14316 | var __proto = PanoImageRenderer.prototype;
|
14317 |
|
14318 | __proto.setYawPitchControl = function (yawPitchControl) {
|
14319 | this._yawPitchControl = yawPitchControl;
|
14320 | };
|
14321 |
|
14322 | __proto.getContent = function () {
|
14323 | return this._image;
|
14324 | };
|
14325 |
|
14326 | __proto.setImage = function (_a) {
|
14327 | var image = _a.image,
|
14328 | imageType = _a.imageType,
|
14329 | _b = _a.isVideo,
|
14330 | isVideo = _b === void 0 ? false : _b,
|
14331 | cubemapConfig = _a.cubemapConfig;
|
14332 | this._imageIsReady = false;
|
14333 | this._isVideo = isVideo;
|
14334 | this._imageConfig = __assign({
|
14335 |
|
14336 | order: imageType === ImageType.CUBEMAP ? "RLUDBF" : "RLUDFB",
|
14337 | tileConfig: {
|
14338 | flipHorizontal: false,
|
14339 | rotation: 0
|
14340 | },
|
14341 | trim: 0
|
14342 | }, cubemapConfig);
|
14343 |
|
14344 | this._setImageType(imageType);
|
14345 |
|
14346 | if (this._contentLoader) {
|
14347 | this._contentLoader.destroy();
|
14348 | }
|
14349 |
|
14350 | this._contentLoader = new ImReady().on("ready", this._onContentLoad).on("error", this._onContentError);
|
14351 |
|
14352 | if (isVideo) {
|
14353 | this._image = toVideoElement(image);
|
14354 |
|
14355 | this._contentLoader.check([this._image]);
|
14356 |
|
14357 | this._keepUpdate = true;
|
14358 | } else {
|
14359 | this._image = toImageElement(image);
|
14360 |
|
14361 | this._contentLoader.check(Array.isArray(this._image) ? this._image : [this._image]);
|
14362 |
|
14363 | this._keepUpdate = false;
|
14364 | }
|
14365 | };
|
14366 |
|
14367 | __proto.isImageLoaded = function () {
|
14368 | return !!this._image && this._imageIsReady && (!this._isVideo || this._image.readyState >= 2
|
14369 |
|
14370 | );
|
14371 | };
|
14372 |
|
14373 | __proto.bindTexture = function () {
|
14374 | var _this = this;
|
14375 |
|
14376 | return new Promise$1(function (res, rej) {
|
14377 | var contentLoader = _this._contentLoader;
|
14378 |
|
14379 | if (!_this._image) {
|
14380 | return rej("Image is not defined");
|
14381 | }
|
14382 |
|
14383 | if (!contentLoader) {
|
14384 | return rej("ImageLoader is not initialized");
|
14385 | }
|
14386 |
|
14387 | if (contentLoader.isReady()) {
|
14388 | _this._bindTexture();
|
14389 |
|
14390 | res();
|
14391 | } else {
|
14392 | contentLoader.check(Array.isArray(_this._image) ? _this._image : [_this._image]);
|
14393 | contentLoader.once("ready", function (e) {
|
14394 | if (e.errorCount > 0) {
|
14395 | rej("Failed to load images.");
|
14396 | } else {
|
14397 | _this._bindTexture();
|
14398 |
|
14399 | res();
|
14400 | }
|
14401 | });
|
14402 | }
|
14403 | });
|
14404 | };
|
14405 |
|
14406 |
|
14407 | __proto.attachTo = function (parentElement) {
|
14408 | if (!this._hasExternalCanvas) {
|
14409 | this.detach();
|
14410 | parentElement.appendChild(this.canvas);
|
14411 | }
|
14412 |
|
14413 | this._wrapper = parentElement;
|
14414 | };
|
14415 |
|
14416 | __proto.forceContextLoss = function () {
|
14417 | if (this.hasRenderingContext()) {
|
14418 | var loseContextExtension = this.context.getExtension("WEBGL_lose_context");
|
14419 |
|
14420 | if (loseContextExtension) {
|
14421 | loseContextExtension.loseContext();
|
14422 | }
|
14423 | }
|
14424 | };
|
14425 |
|
14426 |
|
14427 | __proto.detach = function () {
|
14428 | if (!this._hasExternalCanvas && this.canvas.parentElement) {
|
14429 | this.canvas.parentElement.removeChild(this.canvas);
|
14430 | }
|
14431 | };
|
14432 |
|
14433 | __proto.destroy = function () {
|
14434 | if (this._contentLoader) {
|
14435 | this._contentLoader.destroy();
|
14436 | }
|
14437 |
|
14438 | this._animator.stop();
|
14439 |
|
14440 | this.detach();
|
14441 | this.forceContextLoss();
|
14442 | this.off();
|
14443 | this.canvas.removeEventListener("webglcontextlost", this._onWebglcontextlost);
|
14444 | this.canvas.removeEventListener("webglcontextrestored", this._onWebglcontextrestored);
|
14445 | };
|
14446 |
|
14447 | __proto.hasRenderingContext = function () {
|
14448 | var ctx = this.context;
|
14449 |
|
14450 | if (!ctx || ctx.isContextLost() || !ctx.getProgramParameter(this.shaderProgram, ctx.LINK_STATUS)) {
|
14451 | return false;
|
14452 | }
|
14453 |
|
14454 | return true;
|
14455 | };
|
14456 |
|
14457 | __proto.updateFieldOfView = function (fieldOfView) {
|
14458 | this.fieldOfView = fieldOfView;
|
14459 |
|
14460 | this._updateViewport();
|
14461 | };
|
14462 |
|
14463 | __proto.updateViewportDimensions = function (width, height) {
|
14464 | var viewPortChanged = false;
|
14465 | this.width = width;
|
14466 | this.height = height;
|
14467 | var w = width * DEVICE_PIXEL_RATIO;
|
14468 | var h = height * DEVICE_PIXEL_RATIO;
|
14469 |
|
14470 | if (w !== this.canvas.width) {
|
14471 | this.canvas.width = w;
|
14472 | viewPortChanged = true;
|
14473 | }
|
14474 |
|
14475 | if (h !== this.canvas.height) {
|
14476 | this.canvas.height = h;
|
14477 | viewPortChanged = true;
|
14478 | }
|
14479 |
|
14480 | if (!viewPortChanged) {
|
14481 | return;
|
14482 | }
|
14483 |
|
14484 | this._updateViewport();
|
14485 |
|
14486 | this._shouldForceDraw = true;
|
14487 | };
|
14488 |
|
14489 | __proto.keepUpdate = function (doUpdate) {
|
14490 | if (doUpdate && this.isImageLoaded() === false) {
|
14491 |
|
14492 | this._shouldForceDraw = true;
|
14493 | }
|
14494 |
|
14495 | this._keepUpdate = doUpdate;
|
14496 | };
|
14497 |
|
14498 | __proto.startRender = function () {
|
14499 | this._animator.setCallback(this._render.bind(this));
|
14500 |
|
14501 | this._animator.start();
|
14502 | };
|
14503 |
|
14504 | __proto.stopRender = function () {
|
14505 | this._animator.stop();
|
14506 | };
|
14507 |
|
14508 | __proto.renderWithQuaternion = function (quaternion, fieldOfView) {
|
14509 | if (!this.isImageLoaded()) {
|
14510 | return;
|
14511 | }
|
14512 |
|
14513 | if (this._keepUpdate === false && this._lastQuaternion && exactEquals$1(this._lastQuaternion, quaternion) && this.fieldOfView && this.fieldOfView === fieldOfView && this._shouldForceDraw === false) {
|
14514 | return;
|
14515 | }
|
14516 |
|
14517 |
|
14518 | if (fieldOfView !== undefined && fieldOfView !== this.fieldOfView) {
|
14519 | this.updateFieldOfView(fieldOfView);
|
14520 | }
|
14521 |
|
14522 | this.mvMatrix = fromQuat(create$1(), quaternion);
|
14523 |
|
14524 | this._draw();
|
14525 |
|
14526 | this._lastQuaternion = clone$1(quaternion);
|
14527 |
|
14528 | if (this._shouldForceDraw) {
|
14529 | this._shouldForceDraw = false;
|
14530 | }
|
14531 | };
|
14532 |
|
14533 | __proto.renderWithYawPitch = function (yaw, pitch, fieldOfView) {
|
14534 | if (!this.isImageLoaded()) {
|
14535 | return;
|
14536 | }
|
14537 |
|
14538 | if (this._keepUpdate === false && this._lastYaw !== null && this._lastYaw === yaw && this._lastPitch !== null && this._lastPitch === pitch && this.fieldOfView && this.fieldOfView === fieldOfView && this._shouldForceDraw === false) {
|
14539 | return;
|
14540 | }
|
14541 |
|
14542 |
|
14543 | if (fieldOfView !== undefined && fieldOfView !== this.fieldOfView) {
|
14544 | this.updateFieldOfView(fieldOfView);
|
14545 | }
|
14546 |
|
14547 | identity(this.mvMatrix);
|
14548 | rotateX(this.mvMatrix, this.mvMatrix, -toRadian(pitch));
|
14549 | rotateY(this.mvMatrix, this.mvMatrix, -toRadian(yaw));
|
14550 |
|
14551 | this._draw();
|
14552 |
|
14553 | this._lastYaw = yaw;
|
14554 | this._lastPitch = pitch;
|
14555 |
|
14556 | if (this._shouldForceDraw) {
|
14557 | this._shouldForceDraw = false;
|
14558 | }
|
14559 | };
|
14560 | |
14561 |
|
14562 |
|
14563 |
|
14564 |
|
14565 | __proto.getProjectionRenderer = function () {
|
14566 | return this._renderer;
|
14567 | };
|
14568 | |
14569 |
|
14570 |
|
14571 |
|
14572 |
|
14573 | __proto.enterVR = function (options) {
|
14574 | var vr = this._vr;
|
14575 |
|
14576 | if (!WEBXR_SUPPORTED && !navigator.getVRDisplays) {
|
14577 | return Promise$1.reject("VR is not available on this browser.");
|
14578 | }
|
14579 |
|
14580 | if (vr && vr.isPresenting()) {
|
14581 | return Promise$1.resolve("VR already enabled.");
|
14582 | }
|
14583 |
|
14584 | return this._requestPresent(options);
|
14585 | };
|
14586 |
|
14587 | __proto._setImageType = function (imageType) {
|
14588 | var _this = this;
|
14589 |
|
14590 | if (!imageType || this._imageType === imageType) {
|
14591 | return;
|
14592 | }
|
14593 |
|
14594 | this._imageType = imageType;
|
14595 | this._isCubeMap = imageType === ImageType.CUBEMAP;
|
14596 |
|
14597 | if (this._renderer) {
|
14598 | this._renderer.off();
|
14599 | }
|
14600 |
|
14601 | switch (imageType) {
|
14602 | case ImageType.CUBEMAP:
|
14603 | this._renderer = new CubeRenderer();
|
14604 | break;
|
14605 |
|
14606 | case ImageType.CUBESTRIP:
|
14607 | this._renderer = new CubeStripRenderer();
|
14608 | break;
|
14609 |
|
14610 | case ImageType.PANORAMA:
|
14611 | this._renderer = new CylinderRenderer();
|
14612 | break;
|
14613 |
|
14614 | case ImageType.STEREOSCOPIC_EQUI:
|
14615 | this._renderer = new SphereRenderer(this.sphericalConfig.stereoFormat);
|
14616 | break;
|
14617 |
|
14618 | default:
|
14619 | this._renderer = new SphereRenderer(STEREO_FORMAT.NONE);
|
14620 | break;
|
14621 | }
|
14622 |
|
14623 | this._renderer.on(Renderer.EVENTS.ERROR, function (e) {
|
14624 | _this.trigger(new ComponentEvent$1(EVENTS$1.ERROR, {
|
14625 | type: ERROR_TYPE$1.RENDERER_ERROR,
|
14626 | message: e.message
|
14627 | }));
|
14628 | });
|
14629 |
|
14630 | this._initWebGL();
|
14631 | };
|
14632 |
|
14633 | __proto._initCanvas = function (container, canvasClass, width, height) {
|
14634 | var canvasInContainer = container.querySelector("." + canvasClass);
|
14635 |
|
14636 | var canvas = canvasInContainer || this._createCanvas(canvasClass);
|
14637 |
|
14638 | this._hasExternalCanvas = !!canvasInContainer;
|
14639 | canvas.width = width;
|
14640 | canvas.height = height;
|
14641 | this._onWebglcontextlost = this._onWebglcontextlost.bind(this);
|
14642 | this._onWebglcontextrestored = this._onWebglcontextrestored.bind(this);
|
14643 | canvas.addEventListener("webglcontextlost", this._onWebglcontextlost);
|
14644 | canvas.addEventListener("webglcontextrestored", this._onWebglcontextrestored);
|
14645 | return canvas;
|
14646 | };
|
14647 |
|
14648 | __proto._createCanvas = function (className) {
|
14649 | var canvas = document.createElement("canvas");
|
14650 | canvas.className = className;
|
14651 | return canvas;
|
14652 | };
|
14653 |
|
14654 | __proto._setDefaultCanvasStyle = function () {
|
14655 | var canvas = this.canvas;
|
14656 | canvas.style.bottom = "0";
|
14657 | canvas.style.left = "0";
|
14658 | canvas.style.right = "0";
|
14659 | canvas.style.top = "0";
|
14660 | canvas.style.margin = "auto";
|
14661 | canvas.style.maxHeight = "100%";
|
14662 | canvas.style.maxWidth = "100%";
|
14663 | canvas.style.outline = "none";
|
14664 | canvas.style.position = "absolute";
|
14665 | };
|
14666 |
|
14667 | __proto._onContentError = function () {
|
14668 | this._imageIsReady = false;
|
14669 | this._image = null;
|
14670 | this.trigger(new ComponentEvent$1(EVENTS$1.ERROR, {
|
14671 | type: ERROR_TYPE$1.FAIL_IMAGE_LOAD,
|
14672 | message: "failed to load image"
|
14673 | }));
|
14674 | return false;
|
14675 | };
|
14676 |
|
14677 | __proto._triggerContentLoad = function () {
|
14678 | this.trigger(new ComponentEvent$1(EVENTS$1.IMAGE_LOADED, {
|
14679 | content: this._image,
|
14680 | isVideo: this._isVideo,
|
14681 | projectionType: this._imageType
|
14682 | }));
|
14683 | };
|
14684 |
|
14685 | __proto._onContentLoad = function (e) {
|
14686 | if (e.errorCount > 0) return;
|
14687 | this._imageIsReady = true;
|
14688 |
|
14689 | this._triggerContentLoad();
|
14690 | };
|
14691 |
|
14692 | __proto._initShaderProgram = function () {
|
14693 | var gl = this.context;
|
14694 |
|
14695 | if (this.shaderProgram) {
|
14696 | gl.deleteProgram(this.shaderProgram);
|
14697 | this.shaderProgram = null;
|
14698 | }
|
14699 |
|
14700 | var renderer = this._renderer;
|
14701 | var vsSource = renderer.getVertexShaderSource();
|
14702 | var fsSource = renderer.getFragmentShaderSource();
|
14703 | var vertexShader = WebGLUtils.createShader(gl, gl.VERTEX_SHADER, vsSource);
|
14704 | var fragmentShader = WebGLUtils.createShader(gl, gl.FRAGMENT_SHADER, fsSource);
|
14705 | var shaderProgram = WebGLUtils.createProgram(gl, vertexShader, fragmentShader);
|
14706 |
|
14707 | if (!shaderProgram) {
|
14708 | throw new Error("Failed to initialize shaders: " + WebGLUtils.getErrorNameFromWebGLErrorCode(gl.getError()));
|
14709 | }
|
14710 |
|
14711 | gl.useProgram(shaderProgram);
|
14712 | shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
|
14713 | shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
|
14714 | shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
|
14715 | shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler");
|
14716 | shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
|
14717 | shaderProgram.uEye = gl.getUniformLocation(shaderProgram, "uEye");
|
14718 | gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
|
14719 | gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
|
14720 |
|
14721 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
|
14722 |
|
14723 | gl.uniform1i(shaderProgram.samplerUniform, 0);
|
14724 | this.shaderProgram = shaderProgram;
|
14725 | };
|
14726 |
|
14727 | __proto._onWebglcontextlost = function (e) {
|
14728 | e.preventDefault();
|
14729 | this.trigger(new ComponentEvent$1(EVENTS$1.RENDERING_CONTEXT_LOST));
|
14730 | };
|
14731 |
|
14732 | __proto._onWebglcontextrestored = function () {
|
14733 | this._initWebGL();
|
14734 |
|
14735 | this.trigger(new ComponentEvent$1(EVENTS$1.RENDERING_CONTEXT_RESTORE));
|
14736 | };
|
14737 |
|
14738 | __proto._updateViewport = function () {
|
14739 | perspective(this.pMatrix, toRadian(this.fieldOfView), this.canvas.width / this.canvas.height, 0.1, 100);
|
14740 | this.context.viewport(0, 0, this.context.drawingBufferWidth, this.context.drawingBufferHeight);
|
14741 | };
|
14742 |
|
14743 | __proto._initWebGL = function () {
|
14744 | var gl;
|
14745 |
|
14746 | try {
|
14747 | this._initRenderingContext();
|
14748 |
|
14749 | gl = this.context;
|
14750 | this.updateViewportDimensions(this.width, this.height);
|
14751 |
|
14752 | this._initShaderProgram();
|
14753 | } catch (e) {
|
14754 | this.trigger(new ComponentEvent$1(EVENTS$1.ERROR, {
|
14755 | type: ERROR_TYPE$1.NO_WEBGL,
|
14756 | message: "no webgl support"
|
14757 | }));
|
14758 | this.destroy();
|
14759 | console.error(e);
|
14760 |
|
14761 | return;
|
14762 | }
|
14763 |
|
14764 |
|
14765 | gl.clearColor(0, 0, 0, 0);
|
14766 | var textureTarget = this._isCubeMap ? gl.TEXTURE_CUBE_MAP : gl.TEXTURE_2D;
|
14767 |
|
14768 | if (this.texture) {
|
14769 | gl.deleteTexture(this.texture);
|
14770 | }
|
14771 |
|
14772 | this.texture = WebGLUtils.createTexture(gl, textureTarget);
|
14773 |
|
14774 | if (this._imageType === ImageType.CUBESTRIP) {
|
14775 |
|
14776 | gl.enable(gl.CULL_FACE);
|
14777 | }
|
14778 | };
|
14779 |
|
14780 | __proto._initRenderingContext = function () {
|
14781 | if (this.hasRenderingContext()) {
|
14782 | return;
|
14783 | }
|
14784 |
|
14785 | if (!window.WebGLRenderingContext) {
|
14786 | throw new Error("WebGLRenderingContext not available.");
|
14787 | }
|
14788 |
|
14789 | this.context = WebGLUtils.getWebglContext(this.canvas, this._renderingContextAttributes);
|
14790 |
|
14791 | if (!this.context) {
|
14792 | throw new Error("Failed to acquire 3D rendering context");
|
14793 | }
|
14794 | };
|
14795 |
|
14796 | __proto._initBuffers = function () {
|
14797 | var image = this._image;
|
14798 |
|
14799 | var vertexPositionData = this._renderer.getVertexPositionData();
|
14800 |
|
14801 | var indexData = this._renderer.getIndexData();
|
14802 |
|
14803 | var textureCoordData = this._renderer.getTextureCoordData({
|
14804 | image: image,
|
14805 | imageConfig: this._imageConfig
|
14806 | });
|
14807 |
|
14808 | var gl = this.context;
|
14809 | this.vertexBuffer = WebGLUtils.initBuffer(gl, gl.ARRAY_BUFFER, new Float32Array(vertexPositionData), 3, this.shaderProgram.vertexPositionAttribute);
|
14810 | this.indexBuffer = WebGLUtils.initBuffer(gl, gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), 1);
|
14811 | this.textureCoordBuffer = WebGLUtils.initBuffer(gl, gl.ARRAY_BUFFER, new Float32Array(textureCoordData), this._isCubeMap ? 3 : 2, this.shaderProgram.textureCoordAttribute);
|
14812 |
|
14813 | this._bindBuffers();
|
14814 | };
|
14815 |
|
14816 | __proto._bindTexture = function () {
|
14817 |
|
14818 |
|
14819 | if (this._imageType === ImageType.CUBESTRIP) {
|
14820 | var _a = this._renderer.getDimension(this._image),
|
14821 | width = _a.width,
|
14822 | height = _a.height;
|
14823 |
|
14824 | var isEAC = width && height && width / height !== 1.5 ? 1 : 0;
|
14825 | this.context.uniform1f(this.context.getUniformLocation(this.shaderProgram, "uIsEAC"), isEAC);
|
14826 | } else if (this._imageType === ImageType.PANORAMA) {
|
14827 | var _b = this._renderer.getDimension(this._image),
|
14828 | width = _b.width,
|
14829 | height = _b.height;
|
14830 |
|
14831 | var imageAspectRatio = width && height && width / height;
|
14832 |
|
14833 | this._renderer.updateShaderData({
|
14834 | imageAspectRatio: imageAspectRatio
|
14835 | });
|
14836 | }
|
14837 |
|
14838 |
|
14839 |
|
14840 | this._initBuffers();
|
14841 |
|
14842 | this._renderer.bindTexture(this.context, this.texture, this._image, this._imageConfig);
|
14843 |
|
14844 | this._shouldForceDraw = true;
|
14845 | this.trigger(new ComponentEvent$1(EVENTS$1.BIND_TEXTURE));
|
14846 | };
|
14847 |
|
14848 | __proto._updateTexture = function () {
|
14849 | this._renderer.updateTexture(this.context, this._image, this._imageConfig);
|
14850 | };
|
14851 |
|
14852 | __proto._render = function () {
|
14853 | var yawPitchControl = this._yawPitchControl;
|
14854 | var fov = yawPitchControl.getFov();
|
14855 |
|
14856 | if (yawPitchControl.shouldRenderWithQuaternion()) {
|
14857 | var quaternion = yawPitchControl.getQuaternion();
|
14858 | this.renderWithQuaternion(quaternion, fov);
|
14859 | } else {
|
14860 | var yawPitch = yawPitchControl.getYawPitch();
|
14861 | this.renderWithYawPitch(yawPitch.yaw, yawPitch.pitch, fov);
|
14862 | }
|
14863 | };
|
14864 |
|
14865 | __proto._bindBuffers = function () {
|
14866 | var gl = this.context;
|
14867 | var program = this.shaderProgram;
|
14868 | var vertexBuffer = this.vertexBuffer;
|
14869 | var textureCoordBuffer = this.textureCoordBuffer;
|
14870 | gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
14871 | gl.enableVertexAttribArray(program.vertexPositionAttribute);
|
14872 | gl.vertexAttribPointer(program.vertexPositionAttribute, vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
14873 | gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
|
14874 | gl.bindBuffer(gl.ARRAY_BUFFER, textureCoordBuffer);
|
14875 | gl.enableVertexAttribArray(program.textureCoordAttribute);
|
14876 | gl.vertexAttribPointer(program.textureCoordAttribute, textureCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
|
14877 | };
|
14878 |
|
14879 | __proto._draw = function () {
|
14880 | if (this._isVideo && this._keepUpdate) {
|
14881 | this._updateTexture();
|
14882 | }
|
14883 |
|
14884 | this._renderer.render({
|
14885 | gl: this.context,
|
14886 | shaderProgram: this.shaderProgram,
|
14887 | indexBuffer: this.indexBuffer,
|
14888 | mvMatrix: this.mvMatrix,
|
14889 | pMatrix: this.pMatrix
|
14890 | });
|
14891 | };
|
14892 |
|
14893 | __proto._requestPresent = function (options) {
|
14894 | var _this = this;
|
14895 |
|
14896 | var gl = this.context;
|
14897 | var canvas = this.canvas;
|
14898 | var animator = this._animator;
|
14899 | this._vr = WEBXR_SUPPORTED ? new XRManager(options) : new VRManager();
|
14900 | var vr = this._vr;
|
14901 | animator.stop();
|
14902 | return new Promise$1(function (resolve, reject) {
|
14903 | vr.requestPresent(canvas, gl).then(function () {
|
14904 | vr.addEndCallback(_this.exitVR);
|
14905 | animator.setContext(vr.context);
|
14906 | animator.setCallback(_this._onFirstVRFrame);
|
14907 |
|
14908 | if (IS_IOS) {
|
14909 | _this._setWrapperFullscreen();
|
14910 | }
|
14911 |
|
14912 | _this._shouldForceDraw = true;
|
14913 | animator.start();
|
14914 | resolve("success");
|
14915 | }).catch(function (e) {
|
14916 | vr.destroy();
|
14917 | _this._vr = null;
|
14918 | animator.start();
|
14919 | reject(e);
|
14920 | });
|
14921 | });
|
14922 | };
|
14923 |
|
14924 | __proto._setWrapperFullscreen = function () {
|
14925 | var wrapper = this._wrapper;
|
14926 | if (!wrapper) return;
|
14927 | this._wrapperOrigStyle = wrapper.getAttribute("style");
|
14928 | var wrapperStyle = wrapper.style;
|
14929 | wrapperStyle.width = "100vw";
|
14930 | wrapperStyle.height = "100vh";
|
14931 | wrapperStyle.position = "fixed";
|
14932 | wrapperStyle.left = "0";
|
14933 | wrapperStyle.top = "0";
|
14934 | wrapperStyle.zIndex = "9999";
|
14935 | };
|
14936 |
|
14937 | __proto._restoreStyle = function () {
|
14938 | var wrapper = this._wrapper;
|
14939 | var canvas = this.canvas;
|
14940 | if (!wrapper) return;
|
14941 |
|
14942 | if (this._wrapperOrigStyle) {
|
14943 | wrapper.setAttribute("style", this._wrapperOrigStyle);
|
14944 | } else {
|
14945 | wrapper.removeAttribute("style");
|
14946 | }
|
14947 |
|
14948 | this._wrapperOrigStyle = null;
|
14949 |
|
14950 | canvas.removeAttribute("style");
|
14951 |
|
14952 | this._setDefaultCanvasStyle();
|
14953 | };
|
14954 |
|
14955 | PanoImageRenderer.EVENTS = EVENTS$1;
|
14956 | PanoImageRenderer.ERROR_TYPE = ERROR_TYPE$1;
|
14957 | return PanoImageRenderer;
|
14958 | }(Component);
|
14959 |
|
14960 | |
14961 |
|
14962 |
|
14963 |
|
14964 |
|
14965 |
|
14966 | var PanoViewer =
|
14967 |
|
14968 | function (_super) {
|
14969 | __extends(PanoViewer, _super);
|
14970 | |
14971 |
|
14972 |
|
14973 |
|
14974 |
|
14975 |
|
14976 |
|
14977 |
|
14978 |
|
14979 |
|
14980 |
|
14981 |
|
14982 |
|
14983 |
|
14984 |
|
14985 |
|
14986 |
|
14987 |
|
14988 |
|
14989 |
|
14990 |
|
14991 |
|
14992 |
|
14993 |
|
14994 |
|
14995 |
|
14996 |
|
14997 |
|
14998 |
|
14999 |
|
15000 |
|
15001 |
|
15002 |
|
15003 |
|
15004 |
|
15005 |
|
15006 |
|
15007 |
|
15008 |
|
15009 |
|
15010 |
|
15011 |
|
15012 |
|
15013 |
|
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 |
|
15021 |
|
15022 |
|
15023 |
|
15024 |
|
15025 |
|
15026 |
|
15027 | function PanoViewer(container, options) {
|
15028 | if (options === void 0) {
|
15029 | options = {};
|
15030 | }
|
15031 |
|
15032 | var _this = _super.call(this) || this;
|
15033 |
|
15034 |
|
15035 | if (!WebGLUtils.isWebGLAvailable()) {
|
15036 | setTimeout(function () {
|
15037 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.ERROR, {
|
15038 | type: ERROR_TYPE.NO_WEBGL,
|
15039 | message: "no webgl support"
|
15040 | }));
|
15041 | }, 0);
|
15042 | return _this;
|
15043 | }
|
15044 |
|
15045 | if (!WebGLUtils.isStableWebGL()) {
|
15046 | setTimeout(function () {
|
15047 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.ERROR, {
|
15048 | type: ERROR_TYPE.INVALID_DEVICE,
|
15049 | message: "blacklisted browser"
|
15050 | }));
|
15051 | }, 0);
|
15052 | return _this;
|
15053 | }
|
15054 |
|
15055 | if (!!options.image && !!options.video) {
|
15056 | setTimeout(function () {
|
15057 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.ERROR, {
|
15058 | type: ERROR_TYPE.INVALID_RESOURCE,
|
15059 | message: "Specifying multi resouces(both image and video) is not valid."
|
15060 | }));
|
15061 | }, 0);
|
15062 | return _this;
|
15063 | }
|
15064 |
|
15065 |
|
15066 |
|
15067 | checkXRSupport();
|
15068 | _this._container = container;
|
15069 | _this._image = options.image || options.video;
|
15070 | _this._isVideo = !!options.video;
|
15071 | _this._projectionType = options.projectionType || PROJECTION_TYPE.EQUIRECTANGULAR;
|
15072 | _this._cubemapConfig = __assign({
|
15073 |
|
15074 | order: _this._projectionType === PROJECTION_TYPE.CUBEMAP ? "RLUDBF" : "RLUDFB",
|
15075 | tileConfig: {
|
15076 | flipHorizontal: false,
|
15077 | rotation: 0
|
15078 | },
|
15079 | trim: 0
|
15080 | }, options.cubemapConfig);
|
15081 | _this._stereoFormat = options.stereoFormat || STEREO_FORMAT.TOP_BOTTOM;
|
15082 |
|
15083 | _this._width = options.width || parseInt(window.getComputedStyle(container).width, 10);
|
15084 | _this._height = options.height || parseInt(window.getComputedStyle(container).height, 10);
|
15085 | |
15086 |
|
15087 |
|
15088 |
|
15089 |
|
15090 |
|
15091 | _this._yaw = options.yaw || 0;
|
15092 | _this._pitch = options.pitch || 0;
|
15093 | _this._fov = options.fov || 65;
|
15094 | _this._gyroMode = options.gyroMode || GYRO_MODE.YAWPITCH;
|
15095 | _this._quaternion = null;
|
15096 | _this._aspectRatio = _this._height !== 0 ? _this._width / _this._height : 1;
|
15097 | _this._canvasClass = options.canvasClass || DEFAULT_CANVAS_CLASS;
|
15098 | var fovRange = options.fovRange || [30, 110];
|
15099 | var touchDirection = PanoViewer._isValidTouchDirection(options.touchDirection) ? options.touchDirection : YawPitchControl.TOUCH_DIRECTION_ALL;
|
15100 |
|
15101 | var yawPitchConfig = __assign(__assign({}, options), {
|
15102 | element: container,
|
15103 | yaw: _this._yaw,
|
15104 | pitch: _this._pitch,
|
15105 | fov: _this._fov,
|
15106 | gyroMode: _this._gyroMode,
|
15107 | fovRange: fovRange,
|
15108 | aspectRatio: _this._aspectRatio,
|
15109 | touchDirection: touchDirection
|
15110 | });
|
15111 |
|
15112 | _this._isReady = false;
|
15113 |
|
15114 | _this._initYawPitchControl(yawPitchConfig);
|
15115 |
|
15116 | _this._initRenderer(_this._yaw, _this._pitch, _this._fov, _this._projectionType, _this._cubemapConfig);
|
15117 |
|
15118 | return _this;
|
15119 | }
|
15120 | |
15121 |
|
15122 |
|
15123 |
|
15124 |
|
15125 |
|
15126 |
|
15127 | var __proto = PanoViewer.prototype;
|
15128 |
|
15129 | PanoViewer.isSupported = function () {
|
15130 | return WebGLUtils.isWebGLAvailable() && WebGLUtils.isStableWebGL();
|
15131 | };
|
15132 | |
15133 |
|
15134 |
|
15135 |
|
15136 |
|
15137 |
|
15138 |
|
15139 | PanoViewer.isWebGLAvailable = function () {
|
15140 | return WebGLUtils.isWebGLAvailable();
|
15141 | };
|
15142 | |
15143 |
|
15144 |
|
15145 |
|
15146 |
|
15147 |
|
15148 |
|
15149 | PanoViewer.isGyroSensorAvailable = function (callback) {
|
15150 | if (!DeviceMotionEvent && callback) {
|
15151 | callback(false);
|
15152 | return;
|
15153 | }
|
15154 |
|
15155 | var onDeviceMotionChange;
|
15156 |
|
15157 | var checkGyro = function () {
|
15158 | return new Promise$1(function (res) {
|
15159 | onDeviceMotionChange = function (deviceMotion) {
|
15160 | var isGyroSensorAvailable = !(deviceMotion.rotationRate.alpha == null);
|
15161 | res(isGyroSensorAvailable);
|
15162 | };
|
15163 |
|
15164 | window.addEventListener("devicemotion", onDeviceMotionChange);
|
15165 | });
|
15166 | };
|
15167 |
|
15168 | var timeout = function () {
|
15169 | return new Promise$1(function (res) {
|
15170 | setTimeout(function () {
|
15171 | return res(false);
|
15172 | }, 1000);
|
15173 | });
|
15174 | };
|
15175 |
|
15176 | Promise$1.race([checkGyro(), timeout()]).then(function (isGyroSensorAvailable) {
|
15177 | window.removeEventListener("devicemotion", onDeviceMotionChange);
|
15178 |
|
15179 | if (callback) {
|
15180 | callback(isGyroSensorAvailable);
|
15181 | }
|
15182 |
|
15183 | PanoViewer.isGyroSensorAvailable = function (fb) {
|
15184 | if (fb) {
|
15185 | fb(isGyroSensorAvailable);
|
15186 | }
|
15187 |
|
15188 | return isGyroSensorAvailable;
|
15189 | };
|
15190 | });
|
15191 | };
|
15192 |
|
15193 | PanoViewer._isValidTouchDirection = function (direction) {
|
15194 | return direction === PanoViewer.TOUCH_DIRECTION.NONE || direction === PanoViewer.TOUCH_DIRECTION.YAW || direction === PanoViewer.TOUCH_DIRECTION.PITCH || direction === PanoViewer.TOUCH_DIRECTION.ALL;
|
15195 | };
|
15196 | |
15197 |
|
15198 |
|
15199 |
|
15200 |
|
15201 |
|
15202 |
|
15203 |
|
15204 |
|
15205 |
|
15206 |
|
15207 |
|
15208 | __proto.getVideo = function () {
|
15209 | if (!this._isVideo) {
|
15210 | return null;
|
15211 | }
|
15212 |
|
15213 | return this._photoSphereRenderer.getContent();
|
15214 | };
|
15215 | |
15216 |
|
15217 |
|
15218 |
|
15219 |
|
15220 |
|
15221 |
|
15222 |
|
15223 |
|
15224 |
|
15225 |
|
15226 |
|
15227 |
|
15228 |
|
15229 |
|
15230 |
|
15231 |
|
15232 |
|
15233 |
|
15234 | __proto.setVideo = function (video, param) {
|
15235 | if (param === void 0) {
|
15236 | param = {};
|
15237 | }
|
15238 |
|
15239 | if (video) {
|
15240 | this.setImage(video, {
|
15241 | projectionType: param.projectionType,
|
15242 | isVideo: true,
|
15243 | cubemapConfig: param.cubemapConfig,
|
15244 | stereoFormat: param.stereoFormat
|
15245 | });
|
15246 | }
|
15247 |
|
15248 | return this;
|
15249 | };
|
15250 | |
15251 |
|
15252 |
|
15253 |
|
15254 |
|
15255 |
|
15256 |
|
15257 |
|
15258 |
|
15259 | __proto.getImage = function () {
|
15260 | if (this._isVideo) {
|
15261 | return null;
|
15262 | }
|
15263 |
|
15264 | return this._photoSphereRenderer.getContent();
|
15265 | };
|
15266 | |
15267 |
|
15268 |
|
15269 |
|
15270 |
|
15271 |
|
15272 |
|
15273 |
|
15274 |
|
15275 |
|
15276 |
|
15277 |
|
15278 |
|
15279 |
|
15280 |
|
15281 |
|
15282 |
|
15283 |
|
15284 |
|
15285 |
|
15286 | __proto.setImage = function (image, param) {
|
15287 | if (param === void 0) {
|
15288 | param = {};
|
15289 | }
|
15290 |
|
15291 | var cubemapConfig = __assign({
|
15292 | order: "RLUDBF",
|
15293 | tileConfig: {
|
15294 | flipHorizontal: false,
|
15295 | rotation: 0
|
15296 | },
|
15297 | trim: 0
|
15298 | }, param.cubemapConfig);
|
15299 |
|
15300 | var stereoFormat = param.stereoFormat || STEREO_FORMAT.TOP_BOTTOM;
|
15301 | var isVideo = !!param.isVideo;
|
15302 |
|
15303 | if (this._image && this._isVideo !== isVideo) {
|
15304 |
|
15305 | console.warn("PanoViewer is not currently supporting content type changes. (Image <--> Video)");
|
15306 |
|
15307 |
|
15308 | return this;
|
15309 | }
|
15310 |
|
15311 | if (image) {
|
15312 | this._deactivate();
|
15313 |
|
15314 | this._image = image;
|
15315 | this._isVideo = isVideo;
|
15316 | this._projectionType = param.projectionType || PROJECTION_TYPE.EQUIRECTANGULAR;
|
15317 | this._cubemapConfig = cubemapConfig;
|
15318 | this._stereoFormat = stereoFormat;
|
15319 |
|
15320 | this._initRenderer(this._yaw, this._pitch, this._fov, this._projectionType, this._cubemapConfig);
|
15321 | }
|
15322 |
|
15323 | return this;
|
15324 | };
|
15325 | |
15326 |
|
15327 |
|
15328 |
|
15329 |
|
15330 |
|
15331 |
|
15332 |
|
15333 | __proto.keepUpdate = function (doUpdate) {
|
15334 | this._photoSphereRenderer.keepUpdate(doUpdate);
|
15335 |
|
15336 | return this;
|
15337 | };
|
15338 | |
15339 |
|
15340 |
|
15341 |
|
15342 |
|
15343 |
|
15344 |
|
15345 | __proto.getProjectionType = function () {
|
15346 | return this._projectionType;
|
15347 | };
|
15348 | |
15349 |
|
15350 |
|
15351 |
|
15352 |
|
15353 |
|
15354 |
|
15355 |
|
15356 |
|
15357 | __proto.enableSensor = function () {
|
15358 | return new Promise$1(function (resolve, reject) {
|
15359 | if (DeviceMotionEvent && typeof DeviceMotionEvent.requestPermission === "function") {
|
15360 | DeviceMotionEvent.requestPermission().then(function (permissionState) {
|
15361 | if (permissionState === "granted") {
|
15362 | resolve();
|
15363 | } else {
|
15364 | reject(new Error("permission denied"));
|
15365 | }
|
15366 | }).catch(function (e) {
|
15367 |
|
15368 | reject(e);
|
15369 | });
|
15370 | } else {
|
15371 | resolve();
|
15372 | }
|
15373 | });
|
15374 | };
|
15375 | |
15376 |
|
15377 |
|
15378 |
|
15379 |
|
15380 |
|
15381 |
|
15382 |
|
15383 | __proto.disableSensor = function () {
|
15384 | return this;
|
15385 | };
|
15386 | |
15387 |
|
15388 |
|
15389 |
|
15390 |
|
15391 |
|
15392 |
|
15393 |
|
15394 |
|
15395 |
|
15396 |
|
15397 |
|
15398 | __proto.enterVR = function (options) {
|
15399 | var _this = this;
|
15400 |
|
15401 | if (options === void 0) {
|
15402 | options = {};
|
15403 | }
|
15404 |
|
15405 | if (!this._isReady) {
|
15406 | return Promise$1.reject(new Error("PanoViewer is not ready to show image."));
|
15407 | }
|
15408 |
|
15409 | return new Promise$1(function (resolve, reject) {
|
15410 | _this.enableSensor().then(function () {
|
15411 | return _this._photoSphereRenderer.enterVR(options);
|
15412 | }).then(function (res) {
|
15413 | return resolve(res);
|
15414 | }).catch(function (e) {
|
15415 | return reject(e);
|
15416 | });
|
15417 | });
|
15418 | };
|
15419 | |
15420 |
|
15421 |
|
15422 |
|
15423 |
|
15424 |
|
15425 |
|
15426 | __proto.exitVR = function () {
|
15427 | this._photoSphereRenderer.exitVR();
|
15428 |
|
15429 | return this;
|
15430 | };
|
15431 | |
15432 |
|
15433 |
|
15434 |
|
15435 |
|
15436 |
|
15437 |
|
15438 |
|
15439 | __proto.setUseZoom = function (useZoom) {
|
15440 | if (typeof useZoom === "boolean") {
|
15441 | this._yawPitchControl.option("useZoom", useZoom);
|
15442 | }
|
15443 |
|
15444 | return this;
|
15445 | };
|
15446 | |
15447 |
|
15448 |
|
15449 |
|
15450 |
|
15451 |
|
15452 |
|
15453 |
|
15454 | __proto.setUseKeyboard = function (useKeyboard) {
|
15455 | this._yawPitchControl.option("useKeyboard", useKeyboard);
|
15456 |
|
15457 | return this;
|
15458 | };
|
15459 | |
15460 |
|
15461 |
|
15462 |
|
15463 |
|
15464 |
|
15465 |
|
15466 |
|
15467 |
|
15468 |
|
15469 |
|
15470 |
|
15471 |
|
15472 |
|
15473 | __proto.setGyroMode = function (gyroMode) {
|
15474 | this._yawPitchControl.option("gyroMode", gyroMode);
|
15475 |
|
15476 | return this;
|
15477 | };
|
15478 | |
15479 |
|
15480 |
|
15481 |
|
15482 |
|
15483 |
|
15484 |
|
15485 |
|
15486 |
|
15487 |
|
15488 | __proto.setFovRange = function (range) {
|
15489 | this._yawPitchControl.option("fovRange", range);
|
15490 |
|
15491 | return this;
|
15492 | };
|
15493 | |
15494 |
|
15495 |
|
15496 |
|
15497 |
|
15498 |
|
15499 |
|
15500 |
|
15501 |
|
15502 | __proto.getFovRange = function () {
|
15503 | return this._yawPitchControl.option("fovRange");
|
15504 | };
|
15505 | |
15506 |
|
15507 |
|
15508 |
|
15509 |
|
15510 |
|
15511 |
|
15512 |
|
15513 |
|
15514 |
|
15515 | __proto.updateViewportDimensions = function (size) {
|
15516 | if (size === void 0) {
|
15517 | size = {};
|
15518 | }
|
15519 |
|
15520 | if (!this._isReady) {
|
15521 | return this;
|
15522 | }
|
15523 |
|
15524 | var containerSize;
|
15525 |
|
15526 | if (size.width === undefined || size.height === undefined) {
|
15527 | containerSize = window.getComputedStyle(this._container);
|
15528 | }
|
15529 |
|
15530 | var width = size.width || parseInt(containerSize.width, 10);
|
15531 | var height = size.height || parseInt(containerSize.height, 10);
|
15532 |
|
15533 | if (width === this._width && height === this._height) {
|
15534 | return this;
|
15535 | }
|
15536 |
|
15537 | this._width = width;
|
15538 | this._height = height;
|
15539 | this._aspectRatio = width / height;
|
15540 |
|
15541 | this._photoSphereRenderer.updateViewportDimensions(width, height);
|
15542 |
|
15543 | this._yawPitchControl.option("aspectRatio", this._aspectRatio);
|
15544 |
|
15545 | this._yawPitchControl.updatePanScale({
|
15546 | height: height
|
15547 | });
|
15548 |
|
15549 | this.lookAt({}, 0);
|
15550 | return this;
|
15551 | };
|
15552 | |
15553 |
|
15554 |
|
15555 |
|
15556 |
|
15557 |
|
15558 | __proto.getFov = function () {
|
15559 | return this._fov;
|
15560 | };
|
15561 | |
15562 |
|
15563 |
|
15564 |
|
15565 |
|
15566 |
|
15567 | __proto.getYaw = function () {
|
15568 | return this._yaw;
|
15569 | };
|
15570 | |
15571 |
|
15572 |
|
15573 |
|
15574 |
|
15575 |
|
15576 | __proto.getPitch = function () {
|
15577 | return this._pitch;
|
15578 | };
|
15579 | |
15580 |
|
15581 |
|
15582 |
|
15583 |
|
15584 |
|
15585 | __proto.getYawRange = function () {
|
15586 | return this._yawPitchControl.option("yawRange");
|
15587 | };
|
15588 | |
15589 |
|
15590 |
|
15591 |
|
15592 |
|
15593 |
|
15594 | __proto.getPitchRange = function () {
|
15595 | return this._yawPitchControl.option("pitchRange");
|
15596 | };
|
15597 | |
15598 |
|
15599 |
|
15600 |
|
15601 |
|
15602 |
|
15603 |
|
15604 |
|
15605 |
|
15606 |
|
15607 | __proto.setYawRange = function (yawRange) {
|
15608 | this._yawPitchControl.option("yawRange", yawRange);
|
15609 |
|
15610 | return this;
|
15611 | };
|
15612 | |
15613 |
|
15614 |
|
15615 |
|
15616 |
|
15617 |
|
15618 |
|
15619 |
|
15620 |
|
15621 |
|
15622 | __proto.setPitchRange = function (pitchRange) {
|
15623 | this._yawPitchControl.option("pitchRange", pitchRange);
|
15624 |
|
15625 | return this;
|
15626 | };
|
15627 | |
15628 |
|
15629 |
|
15630 |
|
15631 |
|
15632 |
|
15633 |
|
15634 |
|
15635 | __proto.setShowPolePoint = function (showPolePoint) {
|
15636 | this._yawPitchControl.option("showPolePoint", showPolePoint);
|
15637 |
|
15638 | return this;
|
15639 | };
|
15640 | |
15641 |
|
15642 |
|
15643 |
|
15644 |
|
15645 |
|
15646 |
|
15647 |
|
15648 |
|
15649 |
|
15650 |
|
15651 |
|
15652 |
|
15653 |
|
15654 |
|
15655 |
|
15656 |
|
15657 | __proto.lookAt = function (orientation, duration) {
|
15658 | if (duration === void 0) {
|
15659 | duration = 0;
|
15660 | }
|
15661 |
|
15662 | if (!this._isReady) {
|
15663 | return this;
|
15664 | }
|
15665 |
|
15666 | var yaw = orientation.yaw !== undefined ? orientation.yaw : this._yaw;
|
15667 | var pitch = orientation.pitch !== undefined ? orientation.pitch : this._pitch;
|
15668 |
|
15669 | var pitchRange = this._yawPitchControl.option("pitchRange");
|
15670 |
|
15671 | var verticalAngleOfImage = pitchRange[1] - pitchRange[0];
|
15672 | var fov = orientation.fov !== undefined ? orientation.fov : this._fov;
|
15673 |
|
15674 | if (verticalAngleOfImage < fov) {
|
15675 | fov = verticalAngleOfImage;
|
15676 | }
|
15677 |
|
15678 | this._yawPitchControl.lookAt({
|
15679 | yaw: yaw,
|
15680 | pitch: pitch,
|
15681 | fov: fov
|
15682 | }, duration);
|
15683 |
|
15684 | if (duration === 0) {
|
15685 | this._photoSphereRenderer.renderWithYawPitch(yaw, pitch, fov);
|
15686 | }
|
15687 |
|
15688 | return this;
|
15689 | };
|
15690 | |
15691 |
|
15692 |
|
15693 |
|
15694 |
|
15695 |
|
15696 |
|
15697 |
|
15698 |
|
15699 |
|
15700 |
|
15701 |
|
15702 |
|
15703 |
|
15704 | __proto.setTouchDirection = function (direction) {
|
15705 | if (PanoViewer._isValidTouchDirection(direction)) {
|
15706 | this._yawPitchControl.option("touchDirection", direction);
|
15707 | }
|
15708 |
|
15709 | return this;
|
15710 | };
|
15711 | |
15712 |
|
15713 |
|
15714 |
|
15715 |
|
15716 |
|
15717 |
|
15718 |
|
15719 |
|
15720 |
|
15721 |
|
15722 |
|
15723 |
|
15724 | __proto.getTouchDirection = function () {
|
15725 | return this._yawPitchControl.option("touchDirection");
|
15726 | };
|
15727 | |
15728 |
|
15729 |
|
15730 |
|
15731 |
|
15732 |
|
15733 |
|
15734 | __proto.destroy = function () {
|
15735 | this._deactivate();
|
15736 |
|
15737 | if (this._yawPitchControl) {
|
15738 | this._yawPitchControl.destroy();
|
15739 |
|
15740 | this._yawPitchControl = null;
|
15741 | }
|
15742 |
|
15743 | return this;
|
15744 | };
|
15745 |
|
15746 |
|
15747 | __proto._initRenderer = function (yaw, pitch, fov, projectionType, cubemapConfig) {
|
15748 | var _this = this;
|
15749 |
|
15750 | this._photoSphereRenderer = new PanoImageRenderer(this._image, this._width, this._height, this._isVideo, this._container, this._canvasClass, {
|
15751 | initialYaw: yaw,
|
15752 | initialPitch: pitch,
|
15753 | fieldOfView: fov,
|
15754 | imageType: projectionType,
|
15755 | cubemapConfig: cubemapConfig,
|
15756 | stereoFormat: this._stereoFormat
|
15757 | });
|
15758 |
|
15759 | this._photoSphereRenderer.setYawPitchControl(this._yawPitchControl);
|
15760 |
|
15761 | this._bindRendererHandler();
|
15762 |
|
15763 | this._photoSphereRenderer.bindTexture().then(function () {
|
15764 | return _this._activate();
|
15765 | }).catch(function () {
|
15766 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.ERROR, {
|
15767 | type: ERROR_TYPE.FAIL_BIND_TEXTURE,
|
15768 | message: "failed to bind texture"
|
15769 | }));
|
15770 | });
|
15771 | };
|
15772 | |
15773 |
|
15774 |
|
15775 |
|
15776 |
|
15777 |
|
15778 |
|
15779 |
|
15780 |
|
15781 | __proto._updateYawPitchIfNeeded = function () {
|
15782 | if (this._projectionType === PanoViewer.ProjectionType.PANORAMA) {
|
15783 |
|
15784 | var image = this._photoSphereRenderer.getContent();
|
15785 |
|
15786 | var imageAspectRatio = image.naturalWidth / image.naturalHeight;
|
15787 | var yawSize = void 0;
|
15788 | var maxFov = void 0;
|
15789 |
|
15790 | if (imageAspectRatio < 1) {
|
15791 |
|
15792 | imageAspectRatio = 1 / imageAspectRatio;
|
15793 | }
|
15794 |
|
15795 | if (imageAspectRatio < 6) {
|
15796 | yawSize = util.toDegree(imageAspectRatio);
|
15797 |
|
15798 | maxFov = util.toDegree(Math.atan(0.5)) * 2;
|
15799 | } else {
|
15800 | yawSize = 360;
|
15801 | maxFov = 360 / imageAspectRatio;
|
15802 | }
|
15803 |
|
15804 |
|
15805 | var minFov = this._yawPitchControl.option("fovRange")[0];
|
15806 |
|
15807 |
|
15808 | this._yawPitchControl.option({
|
15809 | "fov": maxFov,
|
15810 | "yawRange": [-yawSize / 2, yawSize / 2],
|
15811 | "pitchRange": [-maxFov / 2, maxFov / 2],
|
15812 | "fovRange": [minFov, maxFov]
|
15813 | });
|
15814 |
|
15815 | this.lookAt({
|
15816 | fov: maxFov
|
15817 | });
|
15818 | }
|
15819 | };
|
15820 |
|
15821 | __proto._bindRendererHandler = function () {
|
15822 | var _this = this;
|
15823 |
|
15824 | this._photoSphereRenderer.on(PanoImageRenderer.EVENTS.ERROR, function (e) {
|
15825 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.ERROR, e));
|
15826 | });
|
15827 |
|
15828 | this._photoSphereRenderer.on(PanoImageRenderer.EVENTS.RENDERING_CONTEXT_LOST, function () {
|
15829 | _this._deactivate();
|
15830 |
|
15831 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.ERROR, {
|
15832 | type: ERROR_TYPE.RENDERING_CONTEXT_LOST,
|
15833 | message: "webgl rendering context lost"
|
15834 | }));
|
15835 | });
|
15836 | };
|
15837 |
|
15838 | __proto._initYawPitchControl = function (yawPitchConfig) {
|
15839 | var _this = this;
|
15840 |
|
15841 | this._yawPitchControl = new YawPitchControl(yawPitchConfig);
|
15842 |
|
15843 | this._yawPitchControl.on(PANOVIEWER_EVENTS.ANIMATION_END, function (e) {
|
15844 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.ANIMATION_END, e));
|
15845 | });
|
15846 |
|
15847 | this._yawPitchControl.on("change", function (e) {
|
15848 | _this._yaw = e.yaw;
|
15849 | _this._pitch = e.pitch;
|
15850 | _this._fov = e.fov;
|
15851 | _this._quaternion = e.quaternion;
|
15852 |
|
15853 | _this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.VIEW_CHANGE, e));
|
15854 | });
|
15855 | };
|
15856 |
|
15857 | __proto._activate = function () {
|
15858 | this._photoSphereRenderer.attachTo(this._container);
|
15859 |
|
15860 | this._yawPitchControl.enable();
|
15861 |
|
15862 | this.updateViewportDimensions();
|
15863 | this._isReady = true;
|
15864 |
|
15865 | this._updateYawPitchIfNeeded();
|
15866 |
|
15867 | this.trigger(new ComponentEvent$1(PANOVIEWER_EVENTS.READY));
|
15868 |
|
15869 | this._photoSphereRenderer.startRender();
|
15870 | };
|
15871 | |
15872 |
|
15873 |
|
15874 |
|
15875 |
|
15876 | __proto._deactivate = function () {
|
15877 |
|
15878 | var video = this.getVideo();
|
15879 |
|
15880 | if (video) {
|
15881 | video.pause();
|
15882 | }
|
15883 |
|
15884 | if (this._isReady) {
|
15885 | this._photoSphereRenderer.stopRender();
|
15886 |
|
15887 | this._yawPitchControl.disable();
|
15888 |
|
15889 | this._isReady = false;
|
15890 | }
|
15891 |
|
15892 | if (this._photoSphereRenderer) {
|
15893 | this._photoSphereRenderer.destroy();
|
15894 |
|
15895 | this._photoSphereRenderer = null;
|
15896 | }
|
15897 | };
|
15898 | |
15899 |
|
15900 |
|
15901 |
|
15902 |
|
15903 |
|
15904 |
|
15905 |
|
15906 |
|
15907 |
|
15908 |
|
15909 |
|
15910 | PanoViewer.VERSION = VERSION;
|
15911 | PanoViewer.ERROR_TYPE = ERROR_TYPE;
|
15912 | PanoViewer.EVENTS = PANOVIEWER_EVENTS;
|
15913 | PanoViewer.PROJECTION_TYPE = PROJECTION_TYPE;
|
15914 | PanoViewer.GYRO_MODE = GYRO_MODE;
|
15915 |
|
15916 |
|
15917 | PanoViewer.ProjectionType = PROJECTION_TYPE;
|
15918 | PanoViewer.STEREO_FORMAT = STEREO_FORMAT;
|
15919 | |
15920 |
|
15921 |
|
15922 |
|
15923 |
|
15924 |
|
15925 |
|
15926 | PanoViewer.TOUCH_DIRECTION = {
|
15927 | |
15928 |
|
15929 |
|
15930 |
|
15931 |
|
15932 |
|
15933 |
|
15934 |
|
15935 |
|
15936 | NONE: YawPitchControl.TOUCH_DIRECTION_NONE,
|
15937 |
|
15938 | |
15939 |
|
15940 |
|
15941 |
|
15942 |
|
15943 |
|
15944 |
|
15945 |
|
15946 |
|
15947 | YAW: YawPitchControl.TOUCH_DIRECTION_YAW,
|
15948 |
|
15949 | |
15950 |
|
15951 |
|
15952 |
|
15953 |
|
15954 |
|
15955 |
|
15956 |
|
15957 |
|
15958 | PITCH: YawPitchControl.TOUCH_DIRECTION_PITCH,
|
15959 |
|
15960 | |
15961 |
|
15962 |
|
15963 |
|
15964 |
|
15965 |
|
15966 |
|
15967 |
|
15968 |
|
15969 | ALL: YawPitchControl.TOUCH_DIRECTION_ALL
|
15970 | };
|
15971 | return PanoViewer;
|
15972 | }(Component);
|
15973 |
|
15974 | var PanoViewer$1 = {
|
15975 | __proto__: null,
|
15976 | PanoViewer: PanoViewer,
|
15977 | VERSION: VERSION,
|
15978 | GYRO_MODE: GYRO_MODE,
|
15979 | PANOVIEWER_EVENTS: PANOVIEWER_EVENTS,
|
15980 | ERROR_TYPE: ERROR_TYPE,
|
15981 | PROJECTION_TYPE: PROJECTION_TYPE,
|
15982 | STEREO_FORMAT: STEREO_FORMAT,
|
15983 | PANOVIEWER_OPTIONS: PANOVIEWER_OPTIONS,
|
15984 | DEFAULT_CANVAS_CLASS: DEFAULT_CANVAS_CLASS
|
15985 | };
|
15986 |
|
15987 |
|
15988 | var SPINVIEWER_OPTIONS = {
|
15989 | imageUrl: true,
|
15990 | rowCount: true,
|
15991 | colCount: true,
|
15992 | width: true,
|
15993 | height: true,
|
15994 | autoHeight: true,
|
15995 | colRow: true,
|
15996 | scale: true,
|
15997 | frameIndex: true,
|
15998 | wrapperClass: true,
|
15999 | imageClass: true
|
16000 | };
|
16001 | var SPINVIEWER_EVENTS = {
|
16002 | LOAD: "load",
|
16003 | IMAGE_ERROR: "imageError",
|
16004 | CHANGE: "change",
|
16005 | ANIMATION_END: "animationEnd"
|
16006 | };
|
16007 | var DEFAULT_WRAPPER_CLASS = "view360-wrapper";
|
16008 | var DEFAULT_IMAGE_CLASS = "view360-image";
|
16009 |
|
16010 | |
16011 |
|
16012 |
|
16013 |
|
16014 |
|
16015 |
|
16016 | var SpriteImage =
|
16017 |
|
16018 | function (_super) {
|
16019 | __extends(SpriteImage, _super);
|
16020 | |
16021 |
|
16022 |
|
16023 |
|
16024 |
|
16025 |
|
16026 |
|
16027 |
|
16028 |
|
16029 |
|
16030 |
|
16031 |
|
16032 |
|
16033 |
|
16034 |
|
16035 |
|
16036 |
|
16037 |
|
16038 |
|
16039 |
|
16040 |
|
16041 |
|
16042 |
|
16043 |
|
16044 |
|
16045 |
|
16046 |
|
16047 |
|
16048 |
|
16049 |
|
16050 |
|
16051 | function SpriteImage(element, options) {
|
16052 | if (options === void 0) {
|
16053 | options = {};
|
16054 | }
|
16055 |
|
16056 | var _this = _super.call(this) || this;
|
16057 |
|
16058 | var opt = options || {};
|
16059 | _this._el = element;
|
16060 | _this._rowCount = opt.rowCount || 1;
|
16061 | _this._colCount = opt.colCount || 1;
|
16062 | _this._totalCount = _this._rowCount * _this._colCount;
|
16063 |
|
16064 | _this._width = opt.width || "auto";
|
16065 | _this._height = opt.height || "auto";
|
16066 | _this._autoHeight = opt.autoHeight != null ? opt.autoHeight : true;
|
16067 |
|
16068 | _this._colRow = [0, 0];
|
16069 |
|
16070 | if (opt.colRow) {
|
16071 | _this._colRow = opt.colRow;
|
16072 | } else if (opt.frameIndex) {
|
16073 | _this.setFrameIndex(opt.frameIndex);
|
16074 | }
|
16075 |
|
16076 | _this._el.style.width = SpriteImage._getSizeString(_this._width);
|
16077 | _this._el.style.height = SpriteImage._getSizeString(_this._height);
|
16078 | var wrapperClass = opt.wrapperClass || DEFAULT_WRAPPER_CLASS;
|
16079 | var imageClass = opt.imageClass || DEFAULT_IMAGE_CLASS;
|
16080 |
|
16081 | if (!opt.imageUrl) {
|
16082 | setTimeout(function () {
|
16083 | _this.trigger(new ComponentEvent$1("imageError", {
|
16084 | imageUrl: opt.imageUrl
|
16085 | }));
|
16086 | }, 0);
|
16087 | return _this;
|
16088 | }
|
16089 |
|
16090 | var imageInContainer = element.querySelector("." + imageClass);
|
16091 | var wrapperInContainer = element.querySelector("." + wrapperClass);
|
16092 |
|
16093 | if (wrapperInContainer && imageInContainer) {
|
16094 |
|
16095 | imageInContainer.style.display = "none";
|
16096 | }
|
16097 |
|
16098 | _this._image = imageInContainer || new Image();
|
16099 | |
16100 |
|
16101 |
|
16102 |
|
16103 | var image = _this._image;
|
16104 |
|
16105 | image.onload = function () {
|
16106 | if (wrapperInContainer && imageInContainer) {
|
16107 | imageInContainer.style.display = "";
|
16108 | }
|
16109 |
|
16110 | _this._bg = SpriteImage._createBgDiv(wrapperInContainer, image, _this._rowCount, _this._colCount, _this._autoHeight);
|
16111 |
|
16112 | _this._el.appendChild(_this._bg);
|
16113 |
|
16114 | _this.setColRow(_this._colRow[0], _this._colRow[1]);
|
16115 |
|
16116 | _this.trigger(new ComponentEvent$1("load", {
|
16117 | target: _this._el,
|
16118 | bgElement: _this._bg
|
16119 | }));
|
16120 |
|
16121 | if (_this._autoPlayReservedInfo) {
|
16122 | _this.play(_this._autoPlayReservedInfo);
|
16123 |
|
16124 | _this._autoPlayReservedInfo = null;
|
16125 | }
|
16126 | };
|
16127 |
|
16128 | image.onerror = function () {
|
16129 | _this.trigger(new ComponentEvent$1("imageError", {
|
16130 | imageUrl: opt.imageUrl
|
16131 | }));
|
16132 | };
|
16133 |
|
16134 | image.src = opt.imageUrl;
|
16135 | return _this;
|
16136 | }
|
16137 |
|
16138 | var __proto = SpriteImage.prototype;
|
16139 |
|
16140 | SpriteImage._createBgDiv = function (wrapperInContainer, img, rowCount, colCount, autoHeight) {
|
16141 | var el = wrapperInContainer || document.createElement("div");
|
16142 | el.style.position = "relative";
|
16143 | el.style.overflow = "hidden";
|
16144 | img.style.position = "absolute";
|
16145 | img.style.width = colCount * 100 + "%";
|
16146 | img.style.height = rowCount * 100 + "%";
|
16147 |
|
16148 |
|
16149 | img.ondragstart = function () {
|
16150 | return false;
|
16151 | };
|
16152 |
|
16153 |
|
16154 |
|
16155 | if (SUPPORT_WILLCHANGE) {
|
16156 | img.style.willChange = "transform";
|
16157 | }
|
16158 |
|
16159 | el.appendChild(img);
|
16160 | var unitWidth = img.naturalWidth / colCount;
|
16161 | var unitHeight = img.naturalHeight / rowCount;
|
16162 |
|
16163 | if (autoHeight) {
|
16164 | var r = unitHeight / unitWidth;
|
16165 | el.style.paddingBottom = r * 100 + "%";
|
16166 | } else {
|
16167 | el.style.height = "100%";
|
16168 | }
|
16169 |
|
16170 | return el;
|
16171 | };
|
16172 |
|
16173 | SpriteImage._getSizeString = function (size) {
|
16174 | if (typeof size === "number") {
|
16175 | return size + "px";
|
16176 | }
|
16177 |
|
16178 | return size;
|
16179 | };
|
16180 | |
16181 |
|
16182 |
|
16183 |
|
16184 |
|
16185 |
|
16186 |
|
16187 |
|
16188 |
|
16189 |
|
16190 |
|
16191 |
|
16192 | __proto.setFrameIndex = function (index) {
|
16193 | var colRow = this.toColRow(index);
|
16194 | this.setColRow(colRow[0], colRow[1]);
|
16195 | };
|
16196 | |
16197 |
|
16198 |
|
16199 |
|
16200 |
|
16201 |
|
16202 |
|
16203 |
|
16204 |
|
16205 |
|
16206 |
|
16207 |
|
16208 |
|
16209 | __proto.getFrameIndex = function () {
|
16210 | return this._colRow[1] * this._colCount + this._colRow[0];
|
16211 | };
|
16212 | |
16213 |
|
16214 |
|
16215 |
|
16216 |
|
16217 |
|
16218 |
|
16219 |
|
16220 |
|
16221 |
|
16222 |
|
16223 |
|
16224 |
|
16225 | __proto.setColRow = function (col, row) {
|
16226 | if (row > this._rowCount - 1 || col > this._colCount - 1) {
|
16227 | return;
|
16228 | }
|
16229 |
|
16230 | if (this._image && TRANSFORM) {
|
16231 |
|
16232 | this._image.style[TRANSFORM] = "translate(" + -(col / this._colCount * 100) + "%, " + -(row / this._rowCount * 100) + "%)";
|
16233 | }
|
16234 |
|
16235 | this._colRow = [col, row];
|
16236 | };
|
16237 | |
16238 |
|
16239 |
|
16240 |
|
16241 |
|
16242 |
|
16243 |
|
16244 |
|
16245 |
|
16246 |
|
16247 |
|
16248 |
|
16249 |
|
16250 |
|
16251 | __proto.getColRow = function () {
|
16252 | return this._colRow;
|
16253 | };
|
16254 | |
16255 |
|
16256 |
|
16257 |
|
16258 |
|
16259 |
|
16260 |
|
16261 |
|
16262 |
|
16263 |
|
16264 |
|
16265 |
|
16266 | __proto.stop = function () {
|
16267 | if (this._autoPlayTimer) {
|
16268 | clearInterval(this._autoPlayTimer);
|
16269 | this._autoPlayTimer = -1;
|
16270 | }
|
16271 | };
|
16272 | |
16273 |
|
16274 |
|
16275 |
|
16276 |
|
16277 |
|
16278 |
|
16279 |
|
16280 |
|
16281 |
|
16282 |
|
16283 |
|
16284 |
|
16285 |
|
16286 |
|
16287 | __proto.play = function (_a) {
|
16288 | var _this = this;
|
16289 |
|
16290 | var _b = _a === void 0 ? {
|
16291 | interval: 1000 / this._totalCount,
|
16292 | playCount: 0
|
16293 | } : _a,
|
16294 | interval = _b.interval,
|
16295 | playCount = _b.playCount;
|
16296 |
|
16297 | if (!this._bg) {
|
16298 | this._autoPlayReservedInfo = {
|
16299 | interval: interval,
|
16300 | playCount: playCount
|
16301 | };
|
16302 | return;
|
16303 | }
|
16304 |
|
16305 | if (this._autoPlayTimer) {
|
16306 | clearInterval(this._autoPlayTimer);
|
16307 | this._autoPlayTimer = -1;
|
16308 | }
|
16309 |
|
16310 | var frameIndex = this.getFrameIndex();
|
16311 | var count = 0;
|
16312 | var frameCount = 0;
|
16313 |
|
16314 | this._autoPlayTimer = window.setInterval(function () {
|
16315 | frameIndex %= _this._totalCount;
|
16316 |
|
16317 | var colRow = _this.toColRow(frameIndex);
|
16318 |
|
16319 | _this.setColRow(colRow[0], colRow[1]);
|
16320 |
|
16321 | frameIndex++;
|
16322 |
|
16323 | if (++frameCount === _this._totalCount) {
|
16324 | frameCount = 0;
|
16325 | count++;
|
16326 | }
|
16327 |
|
16328 | if (playCount > 0 && count === playCount) {
|
16329 | clearInterval(_this._autoPlayTimer);
|
16330 | }
|
16331 | }, interval);
|
16332 | };
|
16333 |
|
16334 | __proto.toColRow = function (frameIndex) {
|
16335 | var colCount = this._colCount;
|
16336 | var rowCount = this._rowCount;
|
16337 |
|
16338 | if (frameIndex < 0) {
|
16339 | return [0, 0];
|
16340 | } else if (frameIndex >= this._totalCount) {
|
16341 | return [colCount - 1, rowCount - 1];
|
16342 | }
|
16343 |
|
16344 | var col = frameIndex % colCount;
|
16345 | var row = Math.floor(frameIndex / colCount);
|
16346 |
|
16347 | return [col, row];
|
16348 | };
|
16349 |
|
16350 | SpriteImage.VERSION = VERSION;
|
16351 | return SpriteImage;
|
16352 | }(Component);
|
16353 |
|
16354 | var DEFAULT_PAN_SCALE = 0.21;
|
16355 | |
16356 |
|
16357 |
|
16358 |
|
16359 |
|
16360 |
|
16361 | var SpinViewer =
|
16362 |
|
16363 | function (_super) {
|
16364 | __extends(SpinViewer, _super);
|
16365 | |
16366 |
|
16367 |
|
16368 |
|
16369 |
|
16370 |
|
16371 |
|
16372 |
|
16373 |
|
16374 |
|
16375 |
|
16376 |
|
16377 |
|
16378 |
|
16379 |
|
16380 |
|
16381 |
|
16382 |
|
16383 |
|
16384 |
|
16385 |
|
16386 |
|
16387 |
|
16388 |
|
16389 |
|
16390 |
|
16391 |
|
16392 |
|
16393 |
|
16394 |
|
16395 | function SpinViewer(element, options) {
|
16396 | if (options === void 0) {
|
16397 | options = {};
|
16398 | }
|
16399 |
|
16400 | var _this = _super.call(this) || this;
|
16401 |
|
16402 | _this._el = element;
|
16403 |
|
16404 | var opt = __assign({}, options);
|
16405 |
|
16406 | var colCount = opt.colCount || 1;
|
16407 | var rowCount = opt.rowCount || 1;
|
16408 | _this._scale = opt.scale || 1;
|
16409 | _this._panScale = _this._scale * DEFAULT_PAN_SCALE;
|
16410 | _this._frameCount = colCount * rowCount;
|
16411 |
|
16412 | _this._sprites = new SpriteImage(element, opt).on({
|
16413 | "load": function (evt) {
|
16414 | _this.trigger(new ComponentEvent$1("load", evt));
|
16415 | },
|
16416 | "imageError": function (evt) {
|
16417 | _this.trigger(new ComponentEvent$1("imageError", {
|
16418 | imageUrl: evt.imageUrl
|
16419 | }));
|
16420 | }
|
16421 | });
|
16422 |
|
16423 | _this._panInput = new PanInput(_this._el, {
|
16424 | scale: [_this._panScale, _this._panScale]
|
16425 | });
|
16426 | _this._axes = new Axes({
|
16427 | angle: {
|
16428 | range: [0, 359],
|
16429 | circular: true
|
16430 | }
|
16431 | }).on({
|
16432 | "change": function (evt) {
|
16433 | var curr = Math.floor(evt.pos.angle / (360 / _this._frameCount));
|
16434 | var frameIndex = _this._frameCount - curr - 1;
|
16435 |
|
16436 | _this._sprites.setFrameIndex(frameIndex);
|
16437 |
|
16438 | _this.trigger(new ComponentEvent$1("change", {
|
16439 | frameIndex: frameIndex,
|
16440 | colRow: _this._sprites.getColRow(),
|
16441 | angle: evt.pos.angle
|
16442 | }));
|
16443 | },
|
16444 | "animationEnd": function (evt) {
|
16445 | _this.trigger(new ComponentEvent$1("animationEnd", {
|
16446 | isTrusted: evt.isTrusted
|
16447 | }));
|
16448 | }
|
16449 | });
|
16450 |
|
16451 | _this._axes.connect("angle", _this._panInput);
|
16452 |
|
16453 | return _this;
|
16454 | }
|
16455 | |
16456 |
|
16457 |
|
16458 |
|
16459 |
|
16460 |
|
16461 |
|
16462 |
|
16463 |
|
16464 |
|
16465 |
|
16466 |
|
16467 | var __proto = SpinViewer.prototype;
|
16468 |
|
16469 | __proto.setScale = function (scale) {
|
16470 | if (isNaN(scale) || scale < 0) {
|
16471 | return this;
|
16472 | }
|
16473 |
|
16474 | this._scale = scale;
|
16475 | this._panScale = scale * DEFAULT_PAN_SCALE;
|
16476 | this._panInput.options.scale = [this._panScale, this._panScale];
|
16477 | return this;
|
16478 | };
|
16479 | |
16480 |
|
16481 |
|
16482 |
|
16483 |
|
16484 |
|
16485 |
|
16486 |
|
16487 |
|
16488 |
|
16489 |
|
16490 | __proto.getScale = function () {
|
16491 | return this._scale;
|
16492 | };
|
16493 | |
16494 |
|
16495 |
|
16496 |
|
16497 |
|
16498 |
|
16499 |
|
16500 |
|
16501 |
|
16502 |
|
16503 |
|
16504 |
|
16505 |
|
16506 |
|
16507 | __proto.spinBy = function (angle, param) {
|
16508 | if (angle === void 0) {
|
16509 | angle = 0;
|
16510 | }
|
16511 |
|
16512 | if (param === void 0) {
|
16513 | param = {
|
16514 | duration: 0
|
16515 | };
|
16516 | }
|
16517 |
|
16518 | this._axes.setBy({
|
16519 | angle: angle
|
16520 | }, param.duration);
|
16521 |
|
16522 | return this;
|
16523 | };
|
16524 | |
16525 |
|
16526 |
|
16527 |
|
16528 |
|
16529 |
|
16530 |
|
16531 |
|
16532 |
|
16533 |
|
16534 |
|
16535 |
|
16536 |
|
16537 |
|
16538 | __proto.spinTo = function (angle, param) {
|
16539 | if (angle === void 0) {
|
16540 | angle = 0;
|
16541 | }
|
16542 |
|
16543 | if (param === void 0) {
|
16544 | param = {
|
16545 | duration: 0
|
16546 | };
|
16547 | }
|
16548 |
|
16549 | this._axes.setTo({
|
16550 | angle: angle
|
16551 | }, param.duration);
|
16552 |
|
16553 | return this;
|
16554 | };
|
16555 | |
16556 |
|
16557 |
|
16558 |
|
16559 |
|
16560 |
|
16561 |
|
16562 |
|
16563 | __proto.getAngle = function () {
|
16564 | return this._axes.get().angle || 0;
|
16565 | };
|
16566 | |
16567 |
|
16568 |
|
16569 |
|
16570 |
|
16571 |
|
16572 |
|
16573 |
|
16574 |
|
16575 |
|
16576 | SpinViewer.VERSION = VERSION;
|
16577 | return SpinViewer;
|
16578 | }(Component);
|
16579 |
|
16580 | var SpinViewer$1 = {
|
16581 | __proto__: null,
|
16582 | SpinViewer: SpinViewer,
|
16583 | SpriteImage: SpriteImage,
|
16584 | VERSION: VERSION,
|
16585 | SPINVIEWER_OPTIONS: SPINVIEWER_OPTIONS,
|
16586 | SPINVIEWER_EVENTS: SPINVIEWER_EVENTS,
|
16587 | DEFAULT_WRAPPER_CLASS: DEFAULT_WRAPPER_CLASS,
|
16588 | DEFAULT_IMAGE_CLASS: DEFAULT_IMAGE_CLASS
|
16589 | };
|
16590 |
|
16591 | var withMethods = function (component, prototype, vanillaInstance) {
|
16592 | [Component.prototype, component.prototype].forEach(function (proto) {
|
16593 | Object.getOwnPropertyNames(proto).filter(function (name) {
|
16594 | return !prototype[name] && !name.startsWith("_") && name !== "constructor";
|
16595 | }).forEach(function (name) {
|
16596 | var descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
16597 |
|
16598 | if (descriptor.value) {
|
16599 |
|
16600 | Object.defineProperty(prototype, name, {
|
16601 | value: function () {
|
16602 | var _a;
|
16603 |
|
16604 | var args = [];
|
16605 |
|
16606 | for (var _i = 0; _i < arguments.length; _i++) {
|
16607 | args[_i] = arguments[_i];
|
16608 | }
|
16609 |
|
16610 | return (_a = descriptor.value).call.apply(_a, __spread([this[vanillaInstance]], args));
|
16611 | }
|
16612 | });
|
16613 | } else {
|
16614 | var getterDescriptor = {};
|
16615 |
|
16616 | if (descriptor.get) {
|
16617 | getterDescriptor.get = function () {
|
16618 | var _a;
|
16619 |
|
16620 | return (_a = descriptor.get) === null || _a === void 0 ? void 0 : _a.call(this[vanillaInstance]);
|
16621 | };
|
16622 | }
|
16623 |
|
16624 | if (descriptor.set) {
|
16625 | getterDescriptor.set = function () {
|
16626 | var _a;
|
16627 |
|
16628 | var args = [];
|
16629 |
|
16630 | for (var _i = 0; _i < arguments.length; _i++) {
|
16631 | args[_i] = arguments[_i];
|
16632 | }
|
16633 |
|
16634 | return (_a = descriptor.set) === null || _a === void 0 ? void 0 : _a.call.apply(_a, __spread([this[vanillaInstance]], args));
|
16635 | };
|
16636 | }
|
16637 |
|
16638 | Object.defineProperty(prototype, name, getterDescriptor);
|
16639 | }
|
16640 | });
|
16641 | });
|
16642 | };
|
16643 |
|
16644 | var withPanoViewerMethods = function (prototype, name) {
|
16645 | withMethods(PanoViewer, prototype, name);
|
16646 | };
|
16647 |
|
16648 | var withSpinViewerMethods = function (prototype, name) {
|
16649 | withMethods(SpinViewer, prototype, name);
|
16650 | };
|
16651 |
|
16652 | var updatePanoViewer = (function (panoViewer, newProps, prevProps) {
|
16653 | if (isPropChanged(newProps.image, prevProps.image)) {
|
16654 | panoViewer.setImage(newProps.image, {
|
16655 | projectionType: newProps.projectionType,
|
16656 | cubemapConfig: newProps.cubemapConfig,
|
16657 | stereoFormat: newProps.stereoFormat,
|
16658 | isVideo: false
|
16659 | });
|
16660 | } else if (isPropChanged(newProps.video, prevProps.video)) {
|
16661 | panoViewer.setVideo(newProps.video, {
|
16662 | projectionType: newProps.projectionType,
|
16663 | cubemapConfig: newProps.cubemapConfig,
|
16664 | stereoFormat: newProps.stereoFormat
|
16665 | });
|
16666 | }
|
16667 |
|
16668 | var singleUpdateOptions = ["fovRange", "gyroMode", "pitchRange", "showPolePoint", "touchDirection", "useKeyboard", "useZoom", "yawRange"];
|
16669 | singleUpdateOptions.forEach(function (optionName) {
|
16670 | updateOption(panoViewer, optionName, newProps, prevProps);
|
16671 | });
|
16672 | });
|
16673 |
|
16674 | var isPropChanged = function (val, prevVal) {
|
16675 | return val != null && val !== prevVal;
|
16676 | };
|
16677 |
|
16678 | var updateOption = function (panoViewer, optionName, newProps, prevProps) {
|
16679 | if (isPropChanged(newProps[optionName], prevProps[optionName])) {
|
16680 | panoViewer["set" + optionName[0].toUpperCase() + optionName.slice(1)](newProps[optionName]);
|
16681 | }
|
16682 | };
|
16683 |
|
16684 | var CFC = {
|
16685 | __proto__: null,
|
16686 | withMethods: withMethods,
|
16687 | withPanoViewerMethods: withPanoViewerMethods,
|
16688 | withSpinViewerMethods: withSpinViewerMethods,
|
16689 | updatePanoViewer: updatePanoViewer
|
16690 | };
|
16691 |
|
16692 | |
16693 |
|
16694 |
|
16695 |
|
16696 | var View360 = {};
|
16697 | merge(View360, PanoViewer$1);
|
16698 | merge(View360, SpinViewer$1);
|
16699 | merge(View360, CFC);
|
16700 |
|
16701 | return View360;
|
16702 |
|
16703 | })));
|
16704 |
|