@lumiscaphe/viewer 4.1.13 → 4.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/lib/index.cjs +25 -0
  2. package/dist/lib/index.d.ts +833 -0
  3. package/dist/lib/index.js +1771 -0
  4. package/package.json +18 -28
  5. package/.prettierrc +0 -6
  6. package/dist/Animation.d.ts +0 -7
  7. package/dist/Basis3.d.ts +0 -10
  8. package/dist/Canvas2D.d.ts +0 -19
  9. package/dist/Canvas3D.d.ts +0 -8
  10. package/dist/Database.d.ts +0 -25
  11. package/dist/Encoder.d.ts +0 -5
  12. package/dist/EventHelper.d.ts +0 -5
  13. package/dist/Hotspot.d.ts +0 -14
  14. package/dist/Inertia.d.ts +0 -14
  15. package/dist/InertiaPoint.d.ts +0 -6
  16. package/dist/InteractiveCamera.d.ts +0 -25
  17. package/dist/InteractivePosition.d.ts +0 -26
  18. package/dist/Loader.d.ts +0 -37
  19. package/dist/LoaderDelegate.d.ts +0 -5
  20. package/dist/Maths.d.ts +0 -11
  21. package/dist/Options.d.ts +0 -11
  22. package/dist/Parameters.d.ts +0 -9
  23. package/dist/Point.d.ts +0 -6
  24. package/dist/PointOfView.d.ts +0 -13
  25. package/dist/Position.d.ts +0 -4
  26. package/dist/Resolution.d.ts +0 -6
  27. package/dist/Scene.d.ts +0 -14
  28. package/dist/Size.d.ts +0 -5
  29. package/dist/Snapshot.d.ts +0 -10
  30. package/dist/Spherical.d.ts +0 -11
  31. package/dist/Transition.d.ts +0 -6
  32. package/dist/Video.d.ts +0 -8
  33. package/dist/View.d.ts +0 -20
  34. package/dist/Viewer.d.ts +0 -67
  35. package/dist/Viewport.d.ts +0 -19
  36. package/dist/WRAPIv1.d.ts +0 -37
  37. package/dist/WRAPIv2.d.ts +0 -355
  38. package/dist/WebRenderAPIv1.d.ts +0 -16
  39. package/dist/WebRenderAPIv1Requests.d.ts +0 -35
  40. package/dist/WebRenderAPIv2.d.ts +0 -14
  41. package/dist/WebRenderAPIv2Requests.d.ts +0 -220
  42. package/dist/WebRenderAPIv2Responses.d.ts +0 -3
  43. package/dist/WebRenderStatic.d.ts +0 -11
  44. package/dist/WebRenderV1.d.ts +0 -18
  45. package/dist/WebRenderV2.d.ts +0 -26
  46. package/dist/Widget.d.ts +0 -21
  47. package/dist/WidgetImage.d.ts +0 -32
  48. package/dist/WidgetVRCube.d.ts +0 -45
  49. package/dist/WidgetVRObject.d.ts +0 -40
  50. package/dist/WidgetVideo.d.ts +0 -30
  51. package/dist/index-full.js +0 -20
  52. package/dist/index-full.js.map +0 -1
  53. package/dist/index.d.ts +0 -16
  54. package/dist/index.es.js +0 -2
  55. package/dist/index.es.js.map +0 -1
  56. package/dist/index.js +0 -2
  57. package/dist/index.js.map +0 -1
  58. package/patches/twgl.js+5.5.3.patch +0 -27
@@ -0,0 +1,1771 @@
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".ls-viewer-container{display:block;position:relative;overflow:hidden;-webkit-user-select:none;user-select:none;width:100%;height:100%}.ls-viewer-container-image,.ls-viewer-container-video{cursor:default;pointer-events:none}.ls-viewer-container-vrcube{cursor:pointer;cursor:grab}.ls-viewer-container-vrcube-grabbing{cursor:move;cursor:grabbing}.ls-viewer-container-vrobject{cursor:move;cursor:grab}.ls-viewer-container-vrobject-grabbing{cursor:move;cursor:grabbing}.ls-viewer-container-loading{cursor:progress}.ls-viewer-canvas{position:absolute;opacity:0;transition:opacity .5s}.ls-viewer-video{position:absolute}")),document.head.appendChild(e)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
2
+ import k from "debounce-promise";
3
+ import * as M from "twgl.js";
4
+ import { v3 as h, m4 as l } from "twgl.js";
5
+ import U from "regression";
6
+ class b {
7
+ constructor(t, e) {
8
+ this.width = t, this.height = e;
9
+ }
10
+ get aspect() {
11
+ return this.width / this.height;
12
+ }
13
+ }
14
+ class p {
15
+ constructor(t, e, i, s) {
16
+ this.top = t, this.left = e, this.width = i, this.height = s;
17
+ }
18
+ static contains(t, e) {
19
+ return e.x >= 0 && e.x < t.width && e.y >= 0 && e.y < t.height;
20
+ }
21
+ static fit(t, e, i) {
22
+ const s = t.aspect, r = e.aspect;
23
+ let n = 0, a = 0;
24
+ switch (i) {
25
+ case "contain":
26
+ n = r < s ? e.width : e.height * s, a = r < s ? e.width / s : e.height;
27
+ break;
28
+ case "cover":
29
+ default:
30
+ n = r < s ? e.height * s : e.width, a = r < s ? e.height : e.width / s;
31
+ break;
32
+ case "fill":
33
+ n = e.width, a = e.height;
34
+ break;
35
+ }
36
+ const o = (e.height - a) / 2, d = (e.width - n) / 2;
37
+ return new p(o, d, n, a);
38
+ }
39
+ static project(t, e, i, s) {
40
+ const r = p.fit(t, e, i), n = r.width / t.width, a = r.height / t.height;
41
+ return {
42
+ x: Math.round(r.left + s.x * n),
43
+ y: Math.round(r.top + s.y * a)
44
+ };
45
+ }
46
+ static unproject(t, e, i, s) {
47
+ const r = p.fit(t, e, i), n = r.width / t.width, a = r.height / t.height;
48
+ return {
49
+ x: Math.round((s.x - r.left) / n),
50
+ y: Math.round((s.y - r.top) / a)
51
+ };
52
+ }
53
+ static getStandardAspectRatio(t, e) {
54
+ if (t === 0 || e === 0)
55
+ return 0;
56
+ const i = t / e;
57
+ if (t < e) {
58
+ const n = Math.abs(0.75 - i), a = Math.abs(9 / 16 - i);
59
+ return n < a ? 3 / 4 : 9 / 16;
60
+ }
61
+ const s = Math.abs(4 / 3 - i), r = Math.abs(16 / 9 - i);
62
+ return s < r ? 4 / 3 : 16 / 9;
63
+ }
64
+ static getStandardResolution(t, e) {
65
+ if (t === 0 || e === 0)
66
+ return new b(0, 0);
67
+ const i = p.getStandardAspectRatio(t, e);
68
+ if (t < e) {
69
+ const r = p.getStandardQuality(Math.max(e * i, t));
70
+ return new b(Math.round(r), Math.round(r / i));
71
+ }
72
+ const s = p.getStandardQuality(Math.max(t / i, e));
73
+ return new b(Math.round(s * i), Math.round(s));
74
+ }
75
+ static getStandardQuality(t) {
76
+ return t <= 240 ? 240 : t <= 360 ? 360 : t <= 480 ? 480 : t <= 720 ? 720 : 1080;
77
+ }
78
+ }
79
+ class N {
80
+ constructor(t) {
81
+ this.element = document.createElement("canvas"), this.element.classList.add("ls-viewer-canvas"), this.element.style.opacity = "0", this.element.width = 0, this.element.height = 0, this.context = this.element.getContext("2d"), this.backCanvas = document.createElement("canvas"), this.backContext = this.backCanvas.getContext("2d"), this.fit = t, this.pixelRatio = 1;
82
+ }
83
+ destroy() {
84
+ this.requestAnimationId && (cancelAnimationFrame(this.requestAnimationId), this.requestAnimationId = void 0);
85
+ }
86
+ show(t) {
87
+ t ? this.element.style.display = "block" : this.element.style.opacity = "1";
88
+ }
89
+ hide(t) {
90
+ t ? this.element.style.display = "none" : this.element.style.opacity = "0";
91
+ }
92
+ get resolution() {
93
+ return new b(this.element.width / this.pixelRatio, this.element.height / this.pixelRatio);
94
+ }
95
+ resize(t, e, i) {
96
+ this.element.width = t * i, this.element.height = e * i, this.element.style.width = `${t}px`, this.element.style.height = `${e}px`, this.backCanvas.width = t * i, this.backCanvas.height = e * i, this.pixelRatio = i;
97
+ }
98
+ draw(t, e, i) {
99
+ if (!t)
100
+ return;
101
+ this.requestAnimationId && (cancelAnimationFrame(this.requestAnimationId), this.requestAnimationId = void 0);
102
+ const s = p.fit(new b(t.width, t.height), new b(this.element.width, this.element.height), this.fit);
103
+ e ? (this.backContext.drawImage(this.element, 0, 0), this.context.globalAlpha = 0, this.fadeLoop(t, i || 0)) : (this.context.globalAlpha = 1, this.context.drawImage(t, s.left, s.top, s.width, s.height)), this.image = t;
104
+ }
105
+ fadeLoop(t, e) {
106
+ if (this.context.globalAlpha >= 1) {
107
+ cancelAnimationFrame(this.requestAnimationId), this.requestAnimationId = void 0;
108
+ return;
109
+ }
110
+ const i = Math.min(this.context.globalAlpha + e, 1), s = p.fit(new b(t.width, t.height), new b(this.element.width, this.element.height), this.fit);
111
+ this.context.clearRect(0, 0, this.element.width, this.element.height), this.context.globalAlpha = 1, this.context.drawImage(this.backCanvas, 0, 0), this.context.globalAlpha = i, this.context.drawImage(t, s.left, s.top, s.width, s.height), this.requestAnimationId = requestAnimationFrame(() => {
112
+ this.fadeLoop(t, e);
113
+ });
114
+ }
115
+ }
116
+ class B {
117
+ constructor() {
118
+ this.element = document.createElement("canvas"), this.element.classList.add("ls-viewer-canvas"), this.element.style.opacity = "0", this.element.width = 0, this.element.height = 0, this.context = M.getContext(this.element, { preserveDrawingBuffer: !0 }), this.context && this.context.isContextLost() && (this.context = void 0), M.setDefaults({ textureColor: [1, 1, 1, 1] });
119
+ }
120
+ show() {
121
+ this.element.style.opacity = "1";
122
+ }
123
+ hide() {
124
+ this.element.style.opacity = "0";
125
+ }
126
+ resize(t, e, i) {
127
+ this.element.width = t * i, this.element.height = e * i, this.element.style.width = `${t}px`, this.element.style.height = `${e}px`;
128
+ }
129
+ }
130
+ class w {
131
+ static accelerate(t, e) {
132
+ const i = e || 1.5;
133
+ return Math.abs(t) ** i * (t > 0 ? 1 : -1);
134
+ }
135
+ static clamp(t, e, i) {
136
+ return Math.max(Math.min(t, i), e);
137
+ }
138
+ static degreesToRadians(t) {
139
+ return t * (Math.PI / 180);
140
+ }
141
+ static radiansToDegrees(t) {
142
+ return t * (180 / Math.PI);
143
+ }
144
+ static mod(t, e) {
145
+ return t - e * Math.floor(t / e);
146
+ }
147
+ static perspectiveWithFovX(t, e, i, s, r) {
148
+ const n = Math.tan(t / 2), a = n / e;
149
+ return this.perspectiveWithLeft(-n, n, -a, a, i, s, r);
150
+ }
151
+ static perspectiveWithFovY(t, e, i, s, r) {
152
+ const n = i * Math.tan(t / 2), a = n * e;
153
+ return this.perspectiveWithLeft(-a, a, -n, n, i, s, r);
154
+ }
155
+ static perspectiveWithLeft(t, e, i, s, r, n, a) {
156
+ a = a || new Float32Array(16);
157
+ const o = e + t, d = e - t, u = s + i, f = s - i, c = n - r;
158
+ return a[0] = 2 * r / d, a[1] = 0, a[2] = 0, a[3] = 0, a[4] = 0, a[5] = 2 * r / f, a[6] = 0, a[7] = 0, a[8] = o / d, a[9] = u / f, a[10] = -n / c, a[11] = -1, a[12] = 0, a[13] = 0, a[14] = -n * r / c, a[15] = 0, a;
159
+ }
160
+ }
161
+ const A = class A {
162
+ static initCubeFace(t, e, i) {
163
+ let s = [0, 0, 0];
164
+ const r = h.subtract(e, t), n = h.mulScalar([0, 1, 0], h.length(r)), a = h.mulScalar(h.normalize(h.cross(r, n)), h.length(r)), o = h.mulScalar(h.normalize(h.cross(n, a)), h.length(r));
165
+ switch (i) {
166
+ case "front":
167
+ e = h.add(t, o), s = h.normalize(n);
168
+ break;
169
+ case "right":
170
+ e = h.add(t, a), s = h.normalize(n);
171
+ break;
172
+ case "back":
173
+ e = h.subtract(t, o), s = h.normalize(n);
174
+ break;
175
+ case "left":
176
+ e = h.subtract(t, a), s = h.normalize(n);
177
+ break;
178
+ case "up":
179
+ e = h.add(t, n), s = h.normalize(h.mulScalar(o, -1));
180
+ break;
181
+ case "down":
182
+ e = h.subtract(t, n), s = h.normalize(o);
183
+ break;
184
+ }
185
+ return new A(e, t, s);
186
+ }
187
+ constructor(t, e, i) {
188
+ this.target = h.copy(t), this.eye = h.copy(e), this.up = h.copy(i);
189
+ }
190
+ get viewVector() {
191
+ return h.subtract(this.target, this.eye);
192
+ }
193
+ get rightVector() {
194
+ return h.normalize(h.cross(this.viewVector, this.up));
195
+ }
196
+ get viewMatrix() {
197
+ return l.inverse(l.lookAt(this.eye, this.target, this.up));
198
+ }
199
+ clone() {
200
+ return new A(h.copy(this.target), h.copy(this.eye), h.copy(this.up));
201
+ }
202
+ };
203
+ A.default = new A([0, 0, 0], [2, 2, 2], [0, 1, 0]);
204
+ let L = A;
205
+ class X {
206
+ constructor(t) {
207
+ this.target = t.target;
208
+ const e = h.normalize(h.subtract(t.eye, t.target)), i = h.dot(e, [1, 0, 0]), s = h.dot(e, [0, 1, 0]), r = h.dot(e, [0, 0, 1]);
209
+ this.longitude = Math.atan2(i, r), this.latitude = Math.atan2(s, Math.sqrt(i * i + r * r)), h.dot(t.up, [0, 1, 0]) < 0 && (this.longitude = Math.PI + this.longitude, this.latitude = Math.PI - this.latitude), this.distance = h.length(h.subtract(t.target, t.eye));
210
+ }
211
+ get vector() {
212
+ const t = Math.cos(this.latitude) * this.distance, e = Math.sin(this.latitude) * this.distance, i = Math.cos(this.longitude) * t, s = Math.sin(this.longitude) * t;
213
+ return [i, e, s];
214
+ }
215
+ pointOfView(t) {
216
+ const e = l.rotationY(this.longitude), i = l.rotationX(-this.latitude), s = l.rotationZ(0), r = l.multiply(e, l.multiply(i, s));
217
+ let n = [0, 0, -1];
218
+ n = l.transformPoint(r, n);
219
+ let a = [0, 1, 0];
220
+ a = l.transformPoint(r, a);
221
+ const o = h.subtract(t, h.mulScalar(n, this.distance));
222
+ return new L(t, o, a);
223
+ }
224
+ }
225
+ class Y {
226
+ constructor() {
227
+ }
228
+ async animation(t) {
229
+ return t.scene;
230
+ }
231
+ async database(t) {
232
+ throw new Error("Unavailable");
233
+ }
234
+ async image(t) {
235
+ return t.scene;
236
+ }
237
+ async video(t) {
238
+ return t.scene;
239
+ }
240
+ async vrCube(t) {
241
+ return t.scene;
242
+ }
243
+ async vrObject(t) {
244
+ return t.scene;
245
+ }
246
+ }
247
+ class q {
248
+ constructor(t) {
249
+ this.xmlDoc = t;
250
+ }
251
+ get id() {
252
+ var t;
253
+ return (t = this.xmlDoc.getElementsByTagName("Database")[0]) == null ? void 0 : t.getAttribute("id");
254
+ }
255
+ getCameraId(t, e) {
256
+ var i, s;
257
+ return e ? (i = this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`)) == null ? void 0 : i.getAttribute("id") : (s = this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`)) == null ? void 0 : s.getAttribute("id");
258
+ }
259
+ getCameraById(t, e) {
260
+ let i;
261
+ return t && e ? i = this.xmlDoc.querySelector(`RootCameraGroup Group[id="${e}"] Camera[id="${t}"]`) : i = this.xmlDoc.querySelector(`RootCameraGroup Camera[id="${t}"]`), i ? this.mapElementToCamera(i) : null;
262
+ }
263
+ getCameraByName(t, e) {
264
+ let i;
265
+ return e && t ? i = this.xmlDoc.querySelector(`RootCameraGroup Group[name="${e}"] Camera[name="${t}"]`) : i = this.xmlDoc.querySelector(`RootCameraGroup Camera[name="${t}"]`), i ? this.mapElementToCamera(i) : null;
266
+ }
267
+ getCameraGroupId(t) {
268
+ var e;
269
+ return (e = this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`)) == null ? void 0 : e.getAttribute("id");
270
+ }
271
+ getCameraGroupById(t) {
272
+ const e = this.xmlDoc.querySelector(`RootCameraGroup Group[id="${t}"]`);
273
+ return e ? this.mapElementToCameraGroup(e) : null;
274
+ }
275
+ getCameraGroupByName(t) {
276
+ const e = this.xmlDoc.querySelector(`RootCameraGroup Group[name="${t}"]`);
277
+ return e ? this.mapElementToCameraGroup(e) : null;
278
+ }
279
+ mapElementToCamera(t) {
280
+ return {
281
+ id: t.getAttribute("id"),
282
+ name: t.getAttribute("name"),
283
+ pointOfView: new L(
284
+ [
285
+ parseFloat(t.querySelector("PointOfView Target").getAttribute("x")),
286
+ //
287
+ parseFloat(t.querySelector("PointOfView Target").getAttribute("y")),
288
+ parseFloat(t.querySelector("PointOfView Target").getAttribute("z"))
289
+ ],
290
+ [
291
+ parseFloat(t.querySelector("PointOfView Eye").getAttribute("x")),
292
+ //
293
+ parseFloat(t.querySelector("PointOfView Eye").getAttribute("y")),
294
+ parseFloat(t.querySelector("PointOfView Eye").getAttribute("z"))
295
+ ],
296
+ [
297
+ parseFloat(t.querySelector("PointOfView Up").getAttribute("x")),
298
+ //
299
+ parseFloat(t.querySelector("PointOfView Up").getAttribute("y")),
300
+ parseFloat(t.querySelector("PointOfView Up").getAttribute("z"))
301
+ ]
302
+ )
303
+ };
304
+ }
305
+ mapElementToCameraGroup(t) {
306
+ return {
307
+ id: t.getAttribute("id"),
308
+ name: t.getAttribute("name"),
309
+ cameras: [...t.querySelectorAll("Camera")].map((e) => this.mapElementToCamera(e))
310
+ };
311
+ }
312
+ }
313
+ const g = class g {
314
+ constructor(t) {
315
+ this.server = t;
316
+ }
317
+ static buildQuery(t) {
318
+ return Object.entries(t).filter(([e, i]) => i != null).map(([e, i]) => `${e}=${i}`).join("&");
319
+ }
320
+ static sceneParameters(t) {
321
+ var n, a;
322
+ const e = t.scene, i = e.length > 1 ? e.find((o) => o.accessory) : null, s = e.length > 1 ? e.find((o) => o.decor) : null, r = e.find((o) => o !== i && o !== s);
323
+ return {
324
+ databaseId: r.database,
325
+ configuration: r == null ? void 0 : r.configuration,
326
+ animations: (n = r == null ? void 0 : r.animations) == null ? void 0 : n.join("/"),
327
+ accessoryDatabaseId: i == null ? void 0 : i.database,
328
+ decorDatabaseId: s == null ? void 0 : s.database,
329
+ decorDeltaAltitude: (a = s == null ? void 0 : s.translation) == null ? void 0 : a.y
330
+ };
331
+ }
332
+ static renderParameters(t) {
333
+ const { parameters: e, view: i } = t;
334
+ return {
335
+ background: i.background,
336
+ width: e.width,
337
+ height: e.height,
338
+ softwareAntialiasing: e.antialiasing,
339
+ superSampling: e.superSampling
340
+ };
341
+ }
342
+ static encoderParameters(t) {
343
+ const { encoder: e } = t;
344
+ return {
345
+ imageFormat: e.format,
346
+ imageQuality: e.quality
347
+ };
348
+ }
349
+ static async fetch(t) {
350
+ return fetch(t).then((e) => e.text()).then((e) => {
351
+ const s = e.replace(/&amp;/g, "&").match(this.xmlRegex);
352
+ return s ? s.map((r) => r.replace(this.xmlRegex, "$1")) : Promise.reject();
353
+ });
354
+ }
355
+ async animation(t) {
356
+ const e = {
357
+ ...g.sceneParameters(t),
358
+ animation: t.view.animation,
359
+ bookmarkSet: t.view.camera.split("/")[0],
360
+ bookmark: t.view.camera.split("/")[1],
361
+ frames: t.view.frames,
362
+ loop: !!t.view.loop,
363
+ ...g.renderParameters(t),
364
+ ...g.encoderParameters(t)
365
+ }, i = g.buildQuery(e);
366
+ return g.fetch(`${this.server}/ImagesFromAnimation?${i}`);
367
+ }
368
+ async database(t) {
369
+ return fetch(`${this.server}/Database?databaseId=${t}`).then((e) => e.text()).then((e) => {
370
+ const i = new DOMParser().parseFromString(e, "application/xml");
371
+ return new q(i);
372
+ });
373
+ }
374
+ async image(t) {
375
+ const e = {
376
+ ...g.sceneParameters(t),
377
+ bookmarkSet: t.view.camera.split("/")[0],
378
+ bookmark: t.view.camera.split("/")[1],
379
+ ...g.renderParameters(t),
380
+ ...g.encoderParameters(t)
381
+ }, i = g.buildQuery(e);
382
+ return Promise.resolve(`${this.server}/ImageFromBookmark?${i}`);
383
+ }
384
+ async video(t) {
385
+ const e = {
386
+ ...g.sceneParameters(t),
387
+ animation: t.view.animation,
388
+ bookmarkSet: t.view.camera.split("/")[0],
389
+ bookmark: t.view.camera.split("/")[1],
390
+ duration: t.view.duration,
391
+ frames: t.view.frames,
392
+ loop: !!t.view.loop,
393
+ reverse: !!t.view.reverse,
394
+ ...g.renderParameters(t),
395
+ ...g.encoderParameters(t)
396
+ }, i = g.buildQuery(e);
397
+ return Promise.resolve(`${this.server}/ImagesFromAnimation?${i}`);
398
+ }
399
+ async vrCube(t) {
400
+ const e = {
401
+ ...g.sceneParameters(t),
402
+ bookmarkSet: t.view.camera.split("/")[0],
403
+ bookmark: t.view.camera.split("/")[1],
404
+ ...g.renderParameters(t),
405
+ ...g.encoderParameters(t)
406
+ };
407
+ e.width = Math.max(e.width, e.height), e.height = Math.max(e.width, e.height);
408
+ const i = g.buildQuery(e);
409
+ return g.fetch(`${this.server}/CubeFromBookmark?${i}`);
410
+ }
411
+ async vrObject(t) {
412
+ const e = {
413
+ ...g.sceneParameters(t),
414
+ bookmarkSet: t.view.camera,
415
+ ...g.renderParameters(t),
416
+ ...g.encoderParameters(t)
417
+ }, i = g.buildQuery(e);
418
+ return g.fetch(`${this.server}/ImagesFromBookmarkSet?${i}`);
419
+ }
420
+ };
421
+ g.xmlRegex = /directUrl="([^"]*)"/g;
422
+ let S = g;
423
+ class m {
424
+ constructor(t) {
425
+ this.server = t;
426
+ }
427
+ static scene(t) {
428
+ return t.scene.map((e) => {
429
+ const { accessory: i, decor: s, ...r } = e;
430
+ return r;
431
+ });
432
+ }
433
+ static renderParameters(t) {
434
+ return {
435
+ ...t.parameters,
436
+ superSampling: t.parameters.superSampling.toString()
437
+ };
438
+ }
439
+ static encoder(t) {
440
+ switch (t.encoder.format) {
441
+ case "jpeg":
442
+ return {
443
+ jpeg: {
444
+ quality: t.encoder.quality
445
+ }
446
+ };
447
+ case "png":
448
+ return {
449
+ png: {
450
+ compression: t.encoder.compression
451
+ }
452
+ };
453
+ case "webp":
454
+ return {
455
+ webp: {
456
+ quality: t.encoder.quality
457
+ }
458
+ };
459
+ }
460
+ return {
461
+ jpeg: {
462
+ quality: 80
463
+ }
464
+ };
465
+ }
466
+ static async fetchFrame(t, e) {
467
+ return fetch(t, { method: "POST", body: JSON.stringify(e) }).then((i) => i.json()).then((i) => i.url);
468
+ }
469
+ static async fetchFrameArray(t, e) {
470
+ return fetch(t, { method: "POST", body: JSON.stringify(e) }).then((i) => i.json()).then((i) => i.map((s) => s.url));
471
+ }
472
+ static async fetchHotspots(t, e) {
473
+ return fetch(t, { method: "POST", body: JSON.stringify(e) }).then((i) => i.json());
474
+ }
475
+ static async fetchHotspotsArray(t, e) {
476
+ return fetch(t, { method: "POST", body: JSON.stringify(e) }).then((i) => i.json());
477
+ }
478
+ static async fetchPick(t, e) {
479
+ return fetch(t, { method: "POST", body: JSON.stringify(e) }).then((i) => i.json()).then((i) => i[0]);
480
+ }
481
+ async database(t) {
482
+ return fetch(`${this.server}/Database?databaseId=${t}`).then((e) => e.text()).then((e) => {
483
+ const i = new DOMParser().parseFromString(e, "application/xml");
484
+ return new q(i);
485
+ });
486
+ }
487
+ async image(t) {
488
+ const e = {
489
+ scene: m.scene(t),
490
+ mode: {
491
+ image: {
492
+ camera: t.view.camera
493
+ }
494
+ },
495
+ renderParameters: m.renderParameters(t),
496
+ encoder: m.encoder(t)
497
+ };
498
+ return m.fetchFrame(`${this.server}/Snapshot`, e);
499
+ }
500
+ async vrCube(t) {
501
+ const e = {
502
+ scene: m.scene(t),
503
+ mode: {
504
+ vrCube: {
505
+ camera: t.view.camera
506
+ }
507
+ },
508
+ renderParameters: m.renderParameters(t),
509
+ encoder: m.encoder(t)
510
+ };
511
+ return e.renderParameters.width = Math.max(e.renderParameters.width, e.renderParameters.height), e.renderParameters.height = Math.max(e.renderParameters.width, e.renderParameters.height), m.fetchFrameArray(`${this.server}/Snapshot`, e);
512
+ }
513
+ async vrObject(t) {
514
+ let e;
515
+ t.view.cameraGroup ? e = {
516
+ images: {
517
+ cameraGroup: t.view.cameraGroup
518
+ }
519
+ } : t.view.frames ? e = {
520
+ vrObject: {
521
+ camera: t.view.camera,
522
+ frames: t.view.frames
523
+ }
524
+ } : e = {
525
+ vrObject: {
526
+ camera: t.view.camera,
527
+ panFrames: t.view.panFrames || 1,
528
+ panFrom: t.view.panFrom || 0,
529
+ panTo: t.view.panTo || 0,
530
+ panLoop: t.view.panLoop || !1,
531
+ tiltFrames: t.view.tiltFrames || 1,
532
+ tiltFrom: t.view.tiltFrom || 0,
533
+ tiltTo: t.view.tiltTo || 0,
534
+ tiltLoop: t.view.tiltLoop || !1
535
+ }
536
+ };
537
+ const i = {
538
+ scene: m.scene(t),
539
+ mode: e,
540
+ renderParameters: m.renderParameters(t),
541
+ encoder: m.encoder(t)
542
+ };
543
+ return m.fetchFrameArray(`${this.server}/Snapshot`, i);
544
+ }
545
+ async animation(t) {
546
+ const e = {
547
+ scene: m.scene(t),
548
+ mode: {
549
+ animation: {
550
+ id: t.view.animation,
551
+ camera: t.view.camera,
552
+ fps: t.view.fps
553
+ }
554
+ },
555
+ renderParameters: m.renderParameters(t),
556
+ encoder: m.encoder(t)
557
+ };
558
+ return m.fetchFrameArray(`${this.server}/Snapshot`, e);
559
+ }
560
+ async imageHotspots(t, e) {
561
+ const i = {
562
+ scene: m.scene(t),
563
+ mode: {
564
+ image: {
565
+ camera: t.view.camera
566
+ }
567
+ },
568
+ renderParameters: m.renderParameters(t),
569
+ ...this.hotspotsBody(e)
570
+ };
571
+ return await m.fetchHotspots(`${this.server}/Hotspot`, i);
572
+ }
573
+ async imagePick(t, e) {
574
+ const i = {
575
+ scene: m.scene(t),
576
+ camera: t.view.camera,
577
+ renderParameters: m.renderParameters(t),
578
+ positions: [e]
579
+ };
580
+ return await m.fetchPick(`${this.server}/Pick`, i);
581
+ }
582
+ async vrCubeHotspots(t, e) {
583
+ const i = {
584
+ scene: m.scene(t),
585
+ mode: {
586
+ vrCube: {
587
+ camera: t.view.camera
588
+ }
589
+ },
590
+ renderParameters: m.renderParameters(t),
591
+ ...this.hotspotsBody(e)
592
+ };
593
+ return i.renderParameters.width = Math.max(i.renderParameters.width, i.renderParameters.height), i.renderParameters.height = Math.max(i.renderParameters.width, i.renderParameters.height), await m.fetchHotspotsArray(`${this.server}/Hotspot`, i);
594
+ }
595
+ async vrObjectHotspots(t, e) {
596
+ let i;
597
+ t.view.cameraGroup ? i = {
598
+ images: {
599
+ cameraGroup: t.view.cameraGroup
600
+ }
601
+ } : t.view.frames ? i = {
602
+ vrObject: {
603
+ camera: t.view.camera,
604
+ frames: t.view.frames
605
+ }
606
+ } : i = {
607
+ vrObject: {
608
+ camera: t.view.camera,
609
+ panFrames: t.view.panFrames || 1,
610
+ panFrom: t.view.panFrom || 0,
611
+ panTo: t.view.panTo || 0,
612
+ panLoop: t.view.panLoop || !1,
613
+ tiltFrames: t.view.tiltFrames || 1,
614
+ tiltFrom: t.view.tiltFrom || 0,
615
+ tiltTo: t.view.tiltTo || 0,
616
+ tiltLoop: t.view.tiltLoop || !1
617
+ }
618
+ };
619
+ const s = {
620
+ scene: m.scene(t),
621
+ mode: i,
622
+ renderParameters: m.renderParameters(t),
623
+ ...this.hotspotsBody(e)
624
+ };
625
+ return await m.fetchHotspotsArray(`${this.server}/Hotspot`, s);
626
+ }
627
+ hotspotsBody(t) {
628
+ return {
629
+ positions: t.every((e) => typeof e != "string") ? t : void 0,
630
+ tags: t.every((e) => typeof e == "string") ? t : void 0
631
+ };
632
+ }
633
+ }
634
+ class D {
635
+ constructor(t, e, i) {
636
+ switch (e) {
637
+ case "static":
638
+ this.webrender = new Y();
639
+ break;
640
+ case "v1":
641
+ this.webrender = new S(t), this.webrenderV2 = new m(t);
642
+ break;
643
+ case "v2":
644
+ this.webrender = new m(t), this.webrenderV2 = new m(t);
645
+ break;
646
+ default:
647
+ this.webrender = new S(t), this.webrenderV2 = new m(t);
648
+ break;
649
+ }
650
+ this.delegate = i, this.loadingId = 0, this.loaded = 0, this.total = 0, this.databases = [], this.onLoadStart = i && i.onLoadStart ? i.onLoadStart : () => {
651
+ }, this.onLoadProgress = i && i.onLoadProgress ? i.onLoadProgress : () => {
652
+ }, this.onLoadEnd = i && i.onLoadEnd ? i.onLoadEnd : () => {
653
+ };
654
+ }
655
+ get progress() {
656
+ return this.total ? this.loaded / this.total : 0;
657
+ }
658
+ async loadImageSnapshot(t) {
659
+ this.loadingId += 1, this.loaded = 0, this.total = 1, this.onLoadStart(this.progress);
660
+ const { loadingId: e } = this;
661
+ return this.webrender.image(t).then((i) => this.loadImage(i, e)).then((i) => (this.onLoadEnd(this.progress), i));
662
+ }
663
+ async loadVideoSnapshot(t, e) {
664
+ this.loadingId += 1, this.loaded = 0, this.total = 1, this.onLoadStart(this.progress);
665
+ const { loadingId: i } = this;
666
+ return this.webrender.video(e).then((s) => this.loadVideo(t, s, !!e.view.loop, i)).then(() => (this.onLoadEnd(this.progress), t));
667
+ }
668
+ async loadVRCubeSnapshot(t) {
669
+ this.loadingId += 1, this.loaded = 0, this.total = 0, this.onLoadStart(this.progress);
670
+ const { loadingId: e } = this;
671
+ return this.webrender.vrCube(t).then((i) => {
672
+ this.total = i.length;
673
+ const s = i.map((r) => this.loadImage(r, e));
674
+ return Promise.all(s);
675
+ }).then((i) => (this.onLoadEnd(this.progress), i));
676
+ }
677
+ async loadVRObjectSnapshot(t, e) {
678
+ var s;
679
+ this.loadingId += 1, this.loaded = 0, this.total = 0, this.onLoadStart(this.progress);
680
+ const { loadingId: i } = this;
681
+ return t.view.animation ? ((s = t.encoder) == null ? void 0 : s.format) === "mp4" ? this.webrender.video(t).then((r) => this.loadVideoFrames(r, t.view.frames, 30, i)) : this.webrender.animation(t).then((r) => this.loadImageFrames(r, t.view.loop, e, i)) : this.webrender.vrObject(t).then((r) => this.loadImageFrames(r, t.view.loop, e, i));
682
+ }
683
+ async loadImage(t, e) {
684
+ const i = new Image();
685
+ i.crossOrigin = location.protocol === "file:" && !D.isValidHttpUrl(t) ? null : "anonymous";
686
+ const s = new Promise((r, n) => {
687
+ i.addEventListener(
688
+ "load",
689
+ () => {
690
+ e === this.loadingId && (this.loaded += 1, this.onLoadProgress(this.progress), r(i));
691
+ },
692
+ { once: !0 }
693
+ ), i.addEventListener(
694
+ "error",
695
+ (a) => {
696
+ e === this.loadingId && n(`${a.type} : ${t}`);
697
+ },
698
+ { once: !0 }
699
+ );
700
+ });
701
+ return i.src = t, s;
702
+ }
703
+ loadImageFrames(t, e, i, s) {
704
+ this.total = t.length;
705
+ const r = new Array(t.length), n = i || 0;
706
+ for (let a = 0, o = t.length; a < o; a += 1) {
707
+ const d = Math.ceil(a / 2) * (a % 2 === 0 ? 1 : -1), u = e ? w.mod(n + d, o) : a;
708
+ r[u] = this.loadImage(t[u], s);
709
+ }
710
+ return Promise.all(r).then(() => this.onLoadEnd(this.progress)).catch(() => {
711
+ }), r;
712
+ }
713
+ async loadVideo(t, e, i, s) {
714
+ t.loop = i;
715
+ const r = new Promise((n, a) => {
716
+ t.addEventListener(
717
+ "canplaythrough",
718
+ () => {
719
+ s === this.loadingId && (this.loaded += 1, this.onLoadProgress(this.progress), n());
720
+ },
721
+ { once: !0 }
722
+ ), t.addEventListener(
723
+ "error",
724
+ (o) => {
725
+ s === this.loadingId && a(`${o.type} : ${e}`);
726
+ },
727
+ { once: !0 }
728
+ );
729
+ });
730
+ return t.src = e, t.load(), r;
731
+ }
732
+ async loadVideoFrame(t, e, i, s, r) {
733
+ let n = 0;
734
+ return new Promise((a, o) => {
735
+ const d = () => {
736
+ if (r !== this.loadingId) return;
737
+ if (n !== s) {
738
+ n += 1;
739
+ return;
740
+ }
741
+ t.removeEventListener("seeked", d);
742
+ const u = document.createElement("canvas");
743
+ u.width = t.videoWidth, u.height = t.videoHeight, u.getContext("2d").drawImage(t, 0, 0);
744
+ const c = new Image();
745
+ c.src = u.toDataURL(), a(c), this.loaded += 1, this.onLoadProgress(this.progress), s !== i - 1 && (t.currentTime += 1 / e);
746
+ };
747
+ t.addEventListener("seeked", d), t.addEventListener(
748
+ "error",
749
+ (u) => {
750
+ r === this.loadingId && o(u);
751
+ },
752
+ { once: !0 }
753
+ );
754
+ });
755
+ }
756
+ loadVideoFrames(t, e, i, s) {
757
+ this.total = e;
758
+ const r = new Array(e), n = document.createElement("video");
759
+ for (let a = 0, o = e; a < o; a += 1)
760
+ r[a] = this.loadVideoFrame(n, i, e, a, s);
761
+ return n.addEventListener(
762
+ "canplaythrough",
763
+ () => {
764
+ s === this.loadingId && (n.currentTime = 1 / i / 2);
765
+ },
766
+ { once: !0 }
767
+ ), n.src = t, n.load(), Promise.all(r).then(() => this.onLoadEnd(this.progress)).catch(() => {
768
+ }), r;
769
+ }
770
+ async loadImageHotspots(t, e) {
771
+ return this.webrenderV2 ? await this.webrenderV2.imageHotspots(await this.convert(t), e) : Promise.reject(new Error("Hotspots only available with api V2"));
772
+ }
773
+ async loadVRCubeHotspots(t, e) {
774
+ return this.webrenderV2 ? await this.webrenderV2.vrCubeHotspots(await this.convert(t), e) : Promise.reject(new Error("Hotspots only available with api V2"));
775
+ }
776
+ async loadVRObjectHotspots(t, e) {
777
+ return this.webrenderV2 ? await this.webrenderV2.vrObjectHotspots(await this.convert(t), e) : Promise.reject(new Error("Hotspots only available with api V2"));
778
+ }
779
+ async loadImagePick(t, e) {
780
+ return this.webrenderV2 ? await this.webrenderV2.imagePick(await this.convert(t), e) : Promise.reject(new Error("Picking only available with api V2"));
781
+ }
782
+ async loadVRObjectPick(t, e, i, s) {
783
+ return this.webrenderV2 ? await this.webrenderV2.imagePick(await this.vrObjectFrameSnapshot(t, i, s), e) : Promise.reject(new Error("Picking only available with api V2"));
784
+ }
785
+ async loadVRCubePick(t, e, i) {
786
+ return this.webrenderV2 ? await this.webrenderV2.imagePick(await this.vrCubeFrameSnapshot(t, i), e) : Promise.reject(new Error("Picking only available with api V2"));
787
+ }
788
+ async convert(t) {
789
+ var o;
790
+ if (!this.webrenderV2 || this.webrender instanceof m || !t.view.camera)
791
+ return t;
792
+ const e = t.scene.find((d) => !d.decor && !d.accessory);
793
+ if (!e)
794
+ return t;
795
+ let i = this.databases.find((d) => d.id === e.database);
796
+ (!i || !i.xmlDoc) && (i = await this.webrender.database(e.database), this.databases.push(i));
797
+ const s = (o = t.view.camera) == null ? void 0 : o.split("/"), r = s.length === 2 ? s[0] : void 0, n = s.length === 2 ? s[1] : s[0], a = i.getCameraId(n, r);
798
+ if (a)
799
+ return { ...t, view: { ...t.view, camera: a } };
800
+ {
801
+ const d = i.getCameraGroupId(n);
802
+ return d ? { ...t, view: { ...t.view, cameraGroup: d } } : t;
803
+ }
804
+ }
805
+ async vrObjectFrameSnapshot(t, e, i) {
806
+ if (!this.webrenderV2)
807
+ return t;
808
+ const s = t.scene.find((n) => !n.decor && !n.accessory);
809
+ if (!s)
810
+ return t;
811
+ let r = this.databases.find((n) => n.id === s.database);
812
+ if (r || (r = await this.webrender.database(s.database), this.databases.push(r)), this.webrender instanceof S) {
813
+ if (!t.view.camera)
814
+ return t;
815
+ const n = r.getCameraGroupId(t.view.camera);
816
+ if (!n)
817
+ return t;
818
+ const a = r.getCameraGroupById(n);
819
+ if (!a)
820
+ return t;
821
+ const o = a.cameras[e];
822
+ return o ? { ...t, view: { ...t.view, camera: o.id } } : t;
823
+ } else if (this.webrender instanceof m)
824
+ if (t.view.camera) {
825
+ const n = r.getCameraById(t.view.camera);
826
+ if (!n)
827
+ return t;
828
+ const a = new X(n.pointOfView), o = 2 * Math.PI / i;
829
+ a.longitude += e * o % (2 * Math.PI);
830
+ const d = a.pointOfView(n.pointOfView.target);
831
+ return {
832
+ ...t,
833
+ view: {
834
+ ...t.view,
835
+ camera: {
836
+ id: n.id,
837
+ pov: {
838
+ target: {
839
+ x: d.target[0],
840
+ y: d.target[1],
841
+ z: d.target[2]
842
+ },
843
+ eye: {
844
+ x: d.eye[0],
845
+ y: d.eye[1],
846
+ z: d.eye[2]
847
+ },
848
+ up: {
849
+ x: d.up[0],
850
+ y: d.up[1],
851
+ z: d.up[2]
852
+ }
853
+ }
854
+ }
855
+ }
856
+ };
857
+ } else if (t.view.cameraGroup) {
858
+ const n = r.getCameraGroupById(t.view.cameraGroup);
859
+ if (!n)
860
+ return t;
861
+ const a = n.cameras[e];
862
+ return a ? { ...t, view: { ...t.view, camera: a.id } } : t;
863
+ } else
864
+ return t;
865
+ else
866
+ return t;
867
+ }
868
+ async vrCubeFrameSnapshot(t, e) {
869
+ const i = t.scene.find((o) => !o.decor && !o.accessory);
870
+ if (!i)
871
+ return t;
872
+ let s = this.databases.find((o) => o.id === i.database);
873
+ if (s || (s = await this.webrender.database(i.database), this.databases.push(s)), !t.view.camera)
874
+ return t;
875
+ let r;
876
+ if (this.webrender instanceof S) {
877
+ const o = t.view.camera.split("/"), d = o.length === 2 ? o[0] : void 0, u = o.length === 2 ? o[1] : o[0];
878
+ r = s.getCameraId(u, d);
879
+ } else this.webrender instanceof m && (r = t.view.camera);
880
+ if (!r)
881
+ return t;
882
+ const n = s.getCameraById(r);
883
+ if (!n)
884
+ return t;
885
+ const a = L.initCubeFace(n.pointOfView.eye, n.pointOfView.target, e);
886
+ return {
887
+ ...t,
888
+ view: {
889
+ ...t.view,
890
+ camera: {
891
+ id: n.id,
892
+ pov: {
893
+ target: {
894
+ x: a.target[0],
895
+ y: a.target[1],
896
+ z: a.target[2]
897
+ },
898
+ eye: {
899
+ x: a.eye[0],
900
+ y: a.eye[1],
901
+ z: a.eye[2]
902
+ },
903
+ up: {
904
+ x: a.up[0],
905
+ y: a.up[1],
906
+ z: a.up[2]
907
+ }
908
+ },
909
+ lens: {
910
+ fov: 90
911
+ }
912
+ }
913
+ },
914
+ parameters: {
915
+ ...t.parameters,
916
+ width: Math.max(t.parameters.width, t.parameters.height),
917
+ height: Math.max(t.parameters.width, t.parameters.height)
918
+ }
919
+ };
920
+ }
921
+ onLoadStart(t) {
922
+ this.delegate && this.delegate.onLoadStart(t);
923
+ }
924
+ onLoadProgress(t) {
925
+ this.delegate && this.delegate.onLoadProgress(t);
926
+ }
927
+ onLoadEnd(t) {
928
+ this.delegate && this.delegate.onLoadEnd(t);
929
+ }
930
+ static isValidHttpUrl(t) {
931
+ let e;
932
+ try {
933
+ e = new URL(t);
934
+ } catch {
935
+ return !1;
936
+ }
937
+ return e.protocol === "http:" || e.protocol === "https:";
938
+ }
939
+ }
940
+ class J {
941
+ constructor() {
942
+ this.element = document.createElement("video"), this.element.classList.add("ls-viewer-video"), this.element.style.opacity = "0", this.element.width = 0, this.element.height = 0, this.element.setAttribute("muted", ""), this.element.setAttribute("playsinline", ""), this.element.setAttribute("preload", "auto");
943
+ }
944
+ show() {
945
+ this.element.style.opacity = "1";
946
+ }
947
+ hide() {
948
+ this.element.style.opacity = "0";
949
+ }
950
+ resize(t, e, i, s) {
951
+ const r = p.fit(i, new b(t, e), s);
952
+ this.element.style.top = `${r.top}px`, this.element.style.left = `${r.left}px`, this.element.style.width = `${r.width}px`, this.element.style.height = `${r.height}px`, (i.width !== this.element.width || i.height !== this.element.height) && (this.element.width = i.width, this.element.height = i.height);
953
+ }
954
+ }
955
+ class Z {
956
+ constructor(t, e, i) {
957
+ this.container = t, this.canvas = e, this.loader = i, this.hotspotList = [];
958
+ }
959
+ destroy() {
960
+ }
961
+ show() {
962
+ this.canvas.show(!1), this.container.classList.add("ls-viewer-container-image");
963
+ }
964
+ hide() {
965
+ this.canvas.hide(!1), this.container.classList.remove("ls-viewer-container-image");
966
+ }
967
+ async load(t, e, i, s) {
968
+ let r = Promise.resolve();
969
+ const n = JSON.stringify(t);
970
+ n === this.snapshotHash && this.image ? r = r.then(() => this.canvas.draw(this.image, s, 0.05)) : r = r.then(
971
+ () => this.loader.loadImageSnapshot(t).then((o) => {
972
+ this.canvas.draw(o, s, 0.05), this.image = o;
973
+ })
974
+ );
975
+ const a = JSON.stringify(e);
976
+ return (n !== this.snapshotHash || a !== this.hotspotsHash) && (e.length ? r = r.then(
977
+ () => this.loader.loadImageHotspots(t, e).then((o) => {
978
+ this.hotspotList = o;
979
+ })
980
+ ) : this.hotspotList = []), this.hotspotsHash = a, this.snapshotHash = n, r;
981
+ }
982
+ async pick(t, e) {
983
+ const i = new b(t.parameters.width, t.parameters.height), s = p.unproject(i, this.canvas.resolution, this.canvas.fit, e);
984
+ return this.loader.loadImagePick(t, s);
985
+ }
986
+ hotspots(t) {
987
+ return this.hotspotList.map((e) => ({ ...e, position2D: p.project(t, this.canvas.resolution, this.canvas.fit, e.position2D) })).map((e) => ({ ...e, visibility: p.contains(this.canvas.resolution, e.position2D) ? e.visibility : "OutOfFrustum" }));
988
+ }
989
+ snapshot(t, e) {
990
+ return this.canvas.element.toDataURL(t, e);
991
+ }
992
+ onMouseDown(t) {
993
+ }
994
+ onMouseMove(t) {
995
+ }
996
+ onMouseUp(t) {
997
+ }
998
+ onMouseEnter(t) {
999
+ }
1000
+ onTouchStart(t) {
1001
+ }
1002
+ onTouchMove(t) {
1003
+ }
1004
+ onTouchEnd(t) {
1005
+ }
1006
+ onDeviceOrientation(t) {
1007
+ }
1008
+ }
1009
+ class I {
1010
+ constructor(t, e) {
1011
+ this.x = t, this.y = e;
1012
+ }
1013
+ clone() {
1014
+ return new I(this.x, this.y);
1015
+ }
1016
+ }
1017
+ class y {
1018
+ static pointFromMouseEvent(t) {
1019
+ return new I(t.screenX, t.screenY);
1020
+ }
1021
+ static pointFromTouchEvent(t) {
1022
+ const e = t.targetTouches[0] || t.changedTouches[0];
1023
+ return new I(e.screenX, e.screenY);
1024
+ }
1025
+ }
1026
+ class j {
1027
+ constructor(...t) {
1028
+ t.length === 3 ? ({ 0: this.u, 1: this.v, 2: this.o } = t, this.w = h.cross(this.u, this.v)) : t.length === 4 ? { 0: this.u, 1: this.v, 2: this.w, 3: this.o } = t : (this.u = [1, 0, 0], this.v = [0, 1, 0], this.w = [0, 0, 1], this.o = [0, 0, 0]);
1029
+ }
1030
+ get localToGlobalMatrix() {
1031
+ const t = [this.u[0], this.u[1], this.u[2], 0], e = [this.v[0], this.v[1], this.v[2], 0], i = [this.w[0], this.w[1], this.w[2], 0], s = [this.o[0], this.o[1], this.o[2], 1];
1032
+ return [...t, ...e, ...i, ...s];
1033
+ }
1034
+ get globalToLocalMatrix() {
1035
+ return l.inverse(this.localToGlobalMatrix);
1036
+ }
1037
+ }
1038
+ class Q {
1039
+ constructor(t, e, i) {
1040
+ this.x = t, this.y = e, this.time = i;
1041
+ }
1042
+ }
1043
+ class G {
1044
+ constructor(t) {
1045
+ this.points = [], this.onMotion = t, this.lastPoint = new I(0, 0), this.velocity = new I(0, 0), this.loop = this.loop.bind(this);
1046
+ }
1047
+ destroy() {
1048
+ this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = void 0);
1049
+ }
1050
+ track(t) {
1051
+ const e = Date.now();
1052
+ this.points = this.points.filter((i) => e - i.time <= 100), this.points.push(new Q(t.x, t.y, e)), this.lastPoint = t;
1053
+ }
1054
+ start() {
1055
+ if (this.points.length === 0)
1056
+ return;
1057
+ const t = this.points[0], e = this.points[this.points.length - 1], i = e.x - t.x, s = e.y - t.y, r = e.time - t.time;
1058
+ this.velocity = new I(r === 0 ? 0 : i / (r / 15), r === 0 ? 0 : s / (r / 15)), this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = void 0), this.animationFrameId = requestAnimationFrame(this.loop);
1059
+ }
1060
+ stop() {
1061
+ this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = void 0), this.points = [];
1062
+ }
1063
+ loop() {
1064
+ if (Math.abs(this.velocity.x) < 1 && Math.abs(this.velocity.y) < 1) {
1065
+ this.animationFrameId = void 0, this.points = [];
1066
+ return;
1067
+ }
1068
+ this.lastPoint.x += this.velocity.x, this.lastPoint.y += this.velocity.y, this.velocity.x *= 0.9, this.velocity.y *= 0.9, this.onMotion(this.lastPoint.clone()), this.animationFrameId = requestAnimationFrame(this.loop);
1069
+ }
1070
+ }
1071
+ class W {
1072
+ constructor(t, e, i) {
1073
+ this.isStarted = !1, this.pov = t, this.fov = w.degreesToRadians(e), this.orientationMatrix = l.identity(), this.inertia = new G(this.motion.bind(this)), this.onMotion = i, this.initPov = this.pov, this.initFov = this.fov, this.initOrientation = w.degreesToRadians(window.orientation) || 0, this.startPov = new L([0, 0, 1], [0, 0, 0], [0, 1, 0]), this.startSize = { width: 0, height: 0 }, this.previousPoint = new I(0, 0);
1074
+ }
1075
+ destroy() {
1076
+ this.inertia.destroy();
1077
+ }
1078
+ get orientedPov() {
1079
+ const t = h.normalize(h.cross(this.pov.up, this.pov.target)), e = new j(t, [0, 1, 0], this.pov.eye), i = l.identity();
1080
+ l.multiply(i, e.localToGlobalMatrix, i), l.multiply(i, this.orientationMatrix, i), l.multiply(i, e.globalToLocalMatrix, i);
1081
+ const s = l.transformDirection(i, this.pov.target), r = this.pov.eye, n = l.transformDirection(i, this.pov.up);
1082
+ return new L(s, r, n);
1083
+ }
1084
+ reset() {
1085
+ this.pov = this.initPov.clone(), this.fov = this.initFov;
1086
+ }
1087
+ start(t, e) {
1088
+ this.isStarted = !0, this.startPov = this.pov, this.startSize = e, this.previousPoint = t, this.inertia.stop();
1089
+ }
1090
+ motion(t) {
1091
+ this.isStarted && this.inertia.track(t);
1092
+ const e = {
1093
+ x: t.x - this.previousPoint.x,
1094
+ y: t.y - this.previousPoint.y
1095
+ }, i = w.accelerate(e.x, 1.3) / this.startSize.width * 0.2 * Math.PI * 1.5, s = w.accelerate(e.y, 1.3) / this.startSize.height * 0.2 * Math.PI, r = l.multiply(l.rotationY(i), l.rotationX(-s)), n = h.normalize(h.cross(this.pov.up, this.pov.target)), a = new j(n, [0, 1, 0], this.pov.eye), o = l.identity();
1096
+ l.multiply(o, a.localToGlobalMatrix, o), l.multiply(o, r, o), l.multiply(o, a.globalToLocalMatrix, o);
1097
+ const d = l.transformPoint(o, this.pov.target), u = l.transformDirection(o, this.pov.up);
1098
+ h.cross(u, [0, 0, 1])[0] >= 0 && (this.pov.target = d, this.pov.up = u), this.previousPoint = t, this.onMotion();
1099
+ }
1100
+ end(t, e) {
1101
+ this.isStarted = !1, e && (this.inertia.track(t), this.inertia.start());
1102
+ }
1103
+ orientation(t, e, i) {
1104
+ const s = w.degreesToRadians(window.orientation) || 0, r = w.degreesToRadians(t), n = w.degreesToRadians(-e), a = w.degreesToRadians(-i), o = l.rotationX(w.degreesToRadians(90));
1105
+ l.rotateZ(o, this.initOrientation, o), l.rotateZ(o, r, o), l.rotateX(o, n, o), l.rotateY(o, a, o), l.rotateZ(o, -s, o), this.orientationMatrix = o, this.onMotion();
1106
+ }
1107
+ }
1108
+ var _ = `precision mediump float;
1109
+
1110
+ uniform float u_mix;
1111
+ uniform samplerCube u_texture;
1112
+ uniform samplerCube u_texture_back;
1113
+
1114
+ varying vec3 direction;
1115
+
1116
+ void main() {
1117
+ vec4 backColor = textureCube(u_texture_back, direction);
1118
+ vec4 color = textureCube(u_texture, direction);
1119
+ gl_FragColor = mix(backColor, color, u_mix);
1120
+ }`, K = `attribute vec4 position;
1121
+
1122
+ uniform mat4 u_mvpi;
1123
+
1124
+ varying vec3 direction;
1125
+
1126
+ void main() {
1127
+ direction = (u_mvpi * position).xyz;
1128
+ gl_Position = position;
1129
+ }`;
1130
+ class tt {
1131
+ constructor(t, e, i, s) {
1132
+ this.container = t, this.canvas = e, this.loader = i, this.images = [], this.hotspotsList = [[]];
1133
+ const r = new L([0, 0, 1], [0, 0, 0], [0, 1, 0]), n = 60, a = l.rotationX(w.degreesToRadians(15));
1134
+ l.transformDirection(a, r.target, r.target), l.transformDirection(a, r.up, r.up), this.interaction = new W(r, n, () => {
1135
+ this.animationFrameId = requestAnimationFrame(this.render), this.onInteraction({
1136
+ pov: this.interaction.pov.clone(),
1137
+ fov: this.interaction.fov
1138
+ });
1139
+ }), this.onInteraction = s, this.gl = this.canvas.context, this.programInfo = M.createProgramInfo(this.gl, [`${K}
1140
+ `, `${_}
1141
+ `]), this.quad = M.primitives.createXYQuadBufferInfo(this.gl), this.uniforms = {
1142
+ u_mvpi: l.identity(),
1143
+ u_mix: 0,
1144
+ u_texture_back: M.createTexture(this.gl, {
1145
+ target: this.gl.TEXTURE_CUBE_MAP,
1146
+ minMag: this.gl.LINEAR,
1147
+ width: 1,
1148
+ height: 1
1149
+ }),
1150
+ u_texture: M.createTexture(this.gl, {
1151
+ target: this.gl.TEXTURE_CUBE_MAP,
1152
+ minMag: this.gl.LINEAR,
1153
+ width: 1,
1154
+ height: 1
1155
+ })
1156
+ }, this.render = this.render.bind(this);
1157
+ }
1158
+ destroy() {
1159
+ this.interaction.destroy(), this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = void 0);
1160
+ }
1161
+ show() {
1162
+ this.canvas.show(), this.container.classList.add("ls-viewer-container-vrcube");
1163
+ }
1164
+ hide() {
1165
+ this.canvas.hide(), this.container.classList.remove("ls-viewer-container-vrcube");
1166
+ }
1167
+ get pov() {
1168
+ return this.interaction.pov;
1169
+ }
1170
+ set pov(t) {
1171
+ this.interaction.pov.eye.every((e, i) => e === t.eye[i]) && this.interaction.pov.target.every((e, i) => e === t.target[i]) && this.interaction.pov.up.every((e, i) => e === t.up[i]) || (this.interaction.pov = t.clone(), this.animationFrameId = requestAnimationFrame(this.render));
1172
+ }
1173
+ get fov() {
1174
+ return w.radiansToDegrees(this.interaction.fov);
1175
+ }
1176
+ set fov(t) {
1177
+ this.interaction.fov !== t && (this.interaction.fov = w.degreesToRadians(t), this.animationFrameId = requestAnimationFrame(this.render));
1178
+ }
1179
+ async load(t, e, i, s) {
1180
+ let r = Promise.resolve();
1181
+ {
1182
+ const o = this.gl.getExtension("WEBGL_debug_renderer_info");
1183
+ o && navigator.platform === "MacIntel" && navigator.userAgent.includes("Chrome") && this.gl.getParameter(o.UNMASKED_RENDERER_WEBGL).includes("OpenGL") && (t.parameters.width = Math.min(t.parameters.width, 1812), t.parameters.height = Math.min(t.parameters.height, 1812));
1184
+ }
1185
+ const n = JSON.stringify(t);
1186
+ n === this.snapshotHash ? r = r.then(() => (this.animationFrameId = requestAnimationFrame(this.render), Promise.resolve())) : (this.images = [], this.animationFrameId = requestAnimationFrame(this.render), r = r.then(
1187
+ () => this.loader.loadVRCubeSnapshot(t).then((o) => {
1188
+ this.images = o, M.createTexture(
1189
+ this.gl,
1190
+ {
1191
+ target: this.gl.TEXTURE_CUBE_MAP,
1192
+ min: this.gl.LINEAR_MIPMAP_LINEAR,
1193
+ minMag: this.gl.LINEAR,
1194
+ cubeFaceOrder: [
1195
+ this.gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
1196
+ //
1197
+ this.gl.TEXTURE_CUBE_MAP_POSITIVE_X,
1198
+ this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,
1199
+ this.gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
1200
+ this.gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
1201
+ this.gl.TEXTURE_CUBE_MAP_NEGATIVE_Y
1202
+ ],
1203
+ src: o
1204
+ },
1205
+ (d, u) => {
1206
+ d || (i && this.interaction.reset(), this.uniforms.u_mix = s ? 0 : 1, this.uniforms.u_texture_back = this.uniforms.u_texture, this.uniforms.u_texture = u, this.animationFrameId = requestAnimationFrame(this.render));
1207
+ }
1208
+ );
1209
+ })
1210
+ ));
1211
+ const a = JSON.stringify(e);
1212
+ return (n !== this.snapshotHash || a !== this.hotspotsHash) && (e.length ? r = r.then(
1213
+ () => this.loader.loadVRCubeHotspots(t, e).then((o) => {
1214
+ this.hotspotsList = o;
1215
+ })
1216
+ ) : this.hotspotsList = [[]]), this.hotspotsHash = a, this.snapshotHash = n, r;
1217
+ }
1218
+ async pick(t, e) {
1219
+ const i = this.canvas.element.clientWidth, s = this.canvas.element.clientHeight, r = e.x, n = s - e.y, a = 2 * r / i - 1, o = 2 * n / s - 1, d = [a, o, 0], u = this.modelViewProjectionMatrix, f = l.inverse(u), c = h.normalize(l.transformPoint(f, d)), T = Math.max(Math.abs(c[0]), Math.abs(c[1]), Math.abs(c[2]));
1220
+ let F = "";
1221
+ Math.abs(c[0]) === T ? F = c[0] > 0 ? "XPOS" : "XNEG" : Math.abs(c[1]) === T ? F = c[1] > 0 ? "YPOS" : "YNEG" : F = c[2] > 0 ? "ZPOS" : "ZNEG";
1222
+ let P = 0, x = 0, E = "";
1223
+ switch (F) {
1224
+ case "XPOS":
1225
+ P = (-c[2] / Math.abs(c[0]) + 1) / 2, x = (-c[1] / Math.abs(c[0]) + 1) / 2, E = "right";
1226
+ break;
1227
+ case "XNEG":
1228
+ P = (c[2] / Math.abs(c[0]) + 1) / 2, x = (-c[1] / Math.abs(c[0]) + 1) / 2, E = "left";
1229
+ break;
1230
+ case "YPOS":
1231
+ P = (c[0] / Math.abs(c[1]) + 1) / 2, x = (c[2] / Math.abs(c[1]) + 1) / 2, E = "up";
1232
+ break;
1233
+ case "YNEG":
1234
+ P = (c[0] / Math.abs(c[1]) + 1) / 2, x = (-c[2] / Math.abs(c[1]) + 1) / 2, E = "down";
1235
+ break;
1236
+ case "ZPOS":
1237
+ P = (c[0] / Math.abs(c[2]) + 1) / 2, x = (-c[1] / Math.abs(c[2]) + 1) / 2, E = "front";
1238
+ break;
1239
+ case "ZNEG":
1240
+ P = (-c[0] / Math.abs(c[2]) + 1) / 2, x = (-c[1] / Math.abs(c[2]) + 1) / 2, E = "back";
1241
+ break;
1242
+ }
1243
+ const O = {
1244
+ x: Math.round(P * Math.max(t.parameters.width, t.parameters.height)),
1245
+ y: Math.round(x * Math.max(t.parameters.width, t.parameters.height))
1246
+ };
1247
+ return this.loader.loadVRCubePick(t, O, E);
1248
+ }
1249
+ hotspots() {
1250
+ var s;
1251
+ const t = [];
1252
+ if (this.hotspotsList.length === 0)
1253
+ return [];
1254
+ const e = ((s = this.hotspotsList[0]) == null ? void 0 : s.length) ?? 0, i = this.modelViewProjectionMatrix;
1255
+ for (let r = 0; r < e; r++) {
1256
+ const n = this.hotspotsList.findIndex(($) => $[r].visibility !== "OutOfFrustum");
1257
+ if (n === -1)
1258
+ continue;
1259
+ const a = { ...this.hotspotsList[n][r] }, o = a.position2D.x / this.images[0].width, d = a.position2D.y / this.images[0].height;
1260
+ let u = 0, f = 0, c = 0;
1261
+ switch (n) {
1262
+ case 0:
1263
+ this.pov.target[2] < 0 && (a.visibility = "OutOfFrustum"), u = 2 * o - 1, f = 1 - 2 * d, c = 1;
1264
+ break;
1265
+ case 1:
1266
+ this.pov.target[0] > 0 && (a.visibility = "OutOfFrustum"), u = 1, f = 1 - 2 * d, c = 1 - 2 * o;
1267
+ break;
1268
+ case 2:
1269
+ this.pov.target[2] > 0 && (a.visibility = "OutOfFrustum"), u = 1 - 2 * o, f = 1 - 2 * d, c = -1;
1270
+ break;
1271
+ case 3:
1272
+ this.pov.target[0] < 0 && (a.visibility = "OutOfFrustum"), u = -1, f = 1 - 2 * d, c = 2 * o - 1;
1273
+ break;
1274
+ case 4:
1275
+ this.pov.target[1] < 0 && (a.visibility = "OutOfFrustum"), u = 2 * o - 1, f = 1, c = 2 * d - 1;
1276
+ break;
1277
+ case 5:
1278
+ this.pov.target[1] > 0 && (a.visibility = "OutOfFrustum"), u = 2 * o - 1, f = -1, c = 1 - 2 * d;
1279
+ break;
1280
+ }
1281
+ const T = h.normalize([u, f, c]), F = l.transformPoint(i, T), P = this.canvas.element.clientWidth, x = this.canvas.element.clientHeight, E = 0.5 * P * (F[0] + 1), O = 0.5 * x * (F[1] + 1), V = {
1282
+ x: Math.round(E),
1283
+ y: Math.round(x - O)
1284
+ }, z = new b(P, x), R = p.contains(z, V) ? a.visibility : "OutOfFrustum";
1285
+ t.push({ ...a, position2D: V, visibility: R });
1286
+ }
1287
+ return t;
1288
+ }
1289
+ snapshot(t, e) {
1290
+ return this.canvas.element.toDataURL(t, e);
1291
+ }
1292
+ get modelViewProjectionMatrix() {
1293
+ const t = this.canvas.element.clientWidth, e = this.canvas.element.clientHeight, i = t > e ? t / e : e / t, s = p.getStandardAspectRatio(t, e), r = this.interaction.fov * (s / i), n = l.setAxis(l.identity(), [-1, 0, 0], 0), a = t > e ? w.perspectiveWithFovY(r, t / e, 0.5, 100) : w.perspectiveWithFovX(r, t / e, 0.5, 100), o = this.interaction.orientedPov, d = l.inverse(l.lookAt(o.eye, o.target, o.up));
1294
+ return l.multiply(l.multiply(a, d), n);
1295
+ }
1296
+ render() {
1297
+ this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height), this.uniforms.u_mvpi = l.inverse(this.modelViewProjectionMatrix), this.gl.useProgram(this.programInfo.program), M.setBuffersAndAttributes(this.gl, this.programInfo, this.quad), M.setUniforms(this.programInfo, this.uniforms), M.drawBufferInfo(this.gl, this.quad), this.uniforms.u_mix < 1 && (this.uniforms.u_mix = Math.min(this.uniforms.u_mix + 0.05, 1), this.animationFrameId = requestAnimationFrame(this.render));
1298
+ }
1299
+ onMouseDown(t) {
1300
+ this.container.classList.add("ls-viewer-container-vrcube-grabbing"), this.interaction.start(y.pointFromMouseEvent(t), {
1301
+ width: this.gl.canvas.width,
1302
+ height: this.gl.canvas.height
1303
+ });
1304
+ }
1305
+ onMouseMove(t) {
1306
+ this.interaction.isStarted && (this.interaction.motion(y.pointFromMouseEvent(t)), t.preventDefault());
1307
+ }
1308
+ onMouseUp(t) {
1309
+ this.interaction.isStarted && (this.container.classList.remove("ls-viewer-container-vrcube-grabbing"), this.interaction.end(y.pointFromMouseEvent(t), !0));
1310
+ }
1311
+ onMouseEnter(t) {
1312
+ this.interaction.isStarted && t.buttons === 0 && (this.container.classList.remove("ls-viewer-container-vrcube-grabbing"), this.interaction.end(y.pointFromMouseEvent(t), !1));
1313
+ }
1314
+ onTouchStart(t) {
1315
+ this.container.classList.add("ls-viewer-container-vrcube-grabbing"), this.interaction.start(y.pointFromTouchEvent(t), {
1316
+ width: this.gl.canvas.width,
1317
+ height: this.gl.canvas.height
1318
+ });
1319
+ }
1320
+ onTouchMove(t) {
1321
+ this.interaction.isStarted && (this.interaction.motion(y.pointFromTouchEvent(t)), t.preventDefault());
1322
+ }
1323
+ onTouchEnd(t) {
1324
+ this.interaction.isStarted && (this.container.classList.remove("ls-viewer-container-vrcube-grabbing"), this.interaction.end(y.pointFromTouchEvent(t), !0));
1325
+ }
1326
+ onDeviceOrientation(t) {
1327
+ this.interaction.orientation(t.alpha, t.beta, t.gamma);
1328
+ }
1329
+ }
1330
+ class et {
1331
+ constructor(t, e, i, s, r) {
1332
+ this.isStarted = !1, this.position = t, this.frames = e, this.rows = i, this.loop = s, this.onMotion = r, this.inertia = new G(this.motion.bind(this)), this.initPosition = { ...this.position }, this.startPosition = { x: 0, y: 0 }, this.startPoint = new I(0, 0), this.startSize = { width: 0, height: 0 }, this.lastPoints = [], this.lastPointsNumber = 20;
1333
+ }
1334
+ destroy() {
1335
+ this.inertia.destroy();
1336
+ }
1337
+ reset() {
1338
+ this.position = { ...this.initPosition };
1339
+ }
1340
+ get positionIndex() {
1341
+ return this.frames * this.position.y + this.position.x;
1342
+ }
1343
+ set positionIndex(t) {
1344
+ if (this.positionIndex === t)
1345
+ return;
1346
+ const e = this.loop ? w.mod(t, this.frames * this.rows) : Math.max(0, Math.min(t, this.frames * this.rows));
1347
+ this.position.x = w.mod(e, this.frames), this.position.y = Math.floor(e / this.frames);
1348
+ }
1349
+ start(t, e) {
1350
+ this.isStarted = !0, this.startPosition = { ...this.position }, this.startPoint = t, this.startSize = e, this.lastPoints = [], this.inertia.stop();
1351
+ }
1352
+ motion(t) {
1353
+ this.isStarted && this.inertia.track(t), this.lastPoints.push({ x: t.x, y: t.y }), this.lastPoints.splice(0, this.lastPoints.length - this.lastPointsNumber);
1354
+ const e = U.linear(this.lastPoints.map((s) => [s.x, s.y])), i = 25;
1355
+ if (Math.abs(e.equation[0]) < 1) {
1356
+ const s = w.accelerate(t.x - this.startPoint.x, 1.3) / this.startSize.width * (this.frames / 4);
1357
+ let r = this.startPosition.x - Math.round(s);
1358
+ r = this.loop ? w.mod(r, this.frames) : Math.max(0, Math.min(r, this.frames - 1)), r !== this.position.x && (this.position.x = r, this.onMotion());
1359
+ const n = Math.min(...this.lastPoints.map((o) => o.x));
1360
+ Math.max(...this.lastPoints.map((o) => o.x)) - n > i && (this.startPoint.y = t.y, this.startPosition.y = this.position.y);
1361
+ } else {
1362
+ const s = w.accelerate(t.y - this.startPoint.y, 1.7) / this.startSize.height * (this.rows / 4);
1363
+ let r = this.startPosition.y + Math.round(s);
1364
+ r = Math.max(0, Math.min(r, this.rows - 1)), r !== this.position.y && (this.position.y = r, this.onMotion());
1365
+ const n = Math.min(...this.lastPoints.map((o) => o.y));
1366
+ Math.max(...this.lastPoints.map((o) => o.y)) - n > i && (this.startPoint.x = t.x, this.startPosition.x = this.position.x);
1367
+ }
1368
+ }
1369
+ end(t, e) {
1370
+ this.isStarted = !1, e && (this.inertia.track(t), this.inertia.start());
1371
+ }
1372
+ }
1373
+ class C {
1374
+ constructor(t, e, i, s) {
1375
+ this.container = t, this.canvas = e, this.loader = i, this.images = [], this.frames = 24, this.hotspotsList = [[]], this.interaction = new et({ x: 0, y: 0 }, 1, 1, !1, () => {
1376
+ this.canvas.draw(this.image, !0, 0.5), this.onInteraction({
1377
+ position: this.interaction.positionIndex
1378
+ });
1379
+ }), this.onInteraction = s;
1380
+ }
1381
+ destroy() {
1382
+ this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = void 0);
1383
+ }
1384
+ show() {
1385
+ this.canvas.show(!1), this.container.classList.add("ls-viewer-container-vrobject");
1386
+ }
1387
+ hide() {
1388
+ this.canvas.hide(!1), this.container.classList.remove("ls-viewer-container-vrobject");
1389
+ }
1390
+ async goto(t) {
1391
+ return new Promise((e) => {
1392
+ let i = this.interaction.positionIndex;
1393
+ const s = () => {
1394
+ if (this.interaction.positionIndex === t)
1395
+ e();
1396
+ else {
1397
+ let r = i > t ? -1 : 1;
1398
+ this.interaction.loop && this.interaction.frames - i + t < Math.abs(t - i) && (r *= -1), i += 0.5 * r, this.position = Math.floor(i), this.animationFrameId = requestAnimationFrame(s);
1399
+ }
1400
+ };
1401
+ this.animationFrameId = requestAnimationFrame(s);
1402
+ });
1403
+ }
1404
+ get position() {
1405
+ return this.interaction.positionIndex;
1406
+ }
1407
+ set position(t) {
1408
+ this.interaction.positionIndex = t, this.canvas.draw(this.image, !0, 0.5);
1409
+ }
1410
+ get image() {
1411
+ return this.images[this.interaction.positionIndex];
1412
+ }
1413
+ async load(t, e, i, s) {
1414
+ let r = Promise.resolve();
1415
+ i && this.interaction.reset();
1416
+ const n = JSON.stringify(t);
1417
+ n === this.snapshotHash && this.image ? r = r.then(() => this.canvas.draw(this.image, s, 0.05)) : (this.images = [], r = r.then(
1418
+ () => this.loader.loadVRObjectSnapshot(t, this.interaction.positionIndex).then((o) => {
1419
+ const d = o.length;
1420
+ return this.images = new Array(d), this.interaction.frames = t.view.frames ?? t.view.panFrames ?? this.frames, this.interaction.rows = d / this.interaction.frames, this.interaction.loop = !!t.view.loop, i && this.interaction.reset(), o.forEach((u, f) => {
1421
+ u.then((c) => {
1422
+ this.images[f] = c, c === this.image && this.canvas.draw(this.image, s, 0.05);
1423
+ }).catch(() => {
1424
+ });
1425
+ }), o[this.interaction.positionIndex].then(() => Promise.resolve());
1426
+ })
1427
+ ));
1428
+ const a = JSON.stringify(e);
1429
+ return (n !== this.snapshotHash || a !== this.hotspotsHash) && (e.length ? r = r.then(
1430
+ () => this.loader.loadVRObjectHotspots(t, e).then((o) => {
1431
+ this.hotspotsList = o;
1432
+ })
1433
+ ) : this.hotspotsList = [[]]), this.hotspotsHash = a, this.snapshotHash = n, r;
1434
+ }
1435
+ async pick(t, e) {
1436
+ const i = new b(t.parameters.width, t.parameters.height), s = p.unproject(i, this.canvas.resolution, this.canvas.fit, e);
1437
+ return this.loader.loadVRObjectPick(t, s, this.position, this.frames);
1438
+ }
1439
+ hotspots(t) {
1440
+ return (this.hotspotsList[this.interaction.positionIndex] || []).map((i) => ({ ...i, position2D: p.project(t, this.canvas.resolution, this.canvas.fit, i.position2D) })).map((i) => ({ ...i, visibility: p.contains(this.canvas.resolution, i.position2D) ? i.visibility : "OutOfFrustum" }));
1441
+ }
1442
+ snapshot(t, e) {
1443
+ return this.canvas.element.toDataURL(t, e);
1444
+ }
1445
+ onMouseDown(t) {
1446
+ this.container.classList.add("ls-viewer-container-vrobject-grabbing"), this.interaction.start(y.pointFromMouseEvent(t), {
1447
+ width: this.canvas.element.width,
1448
+ height: this.canvas.element.height
1449
+ });
1450
+ }
1451
+ onMouseMove(t) {
1452
+ this.interaction.isStarted && (this.interaction.motion(y.pointFromMouseEvent(t)), t.preventDefault());
1453
+ }
1454
+ onMouseUp(t) {
1455
+ this.interaction.isStarted && (this.container.classList.remove("ls-viewer-container-vrobject-grabbing"), this.interaction.end(y.pointFromMouseEvent(t), !0));
1456
+ }
1457
+ onMouseEnter(t) {
1458
+ this.interaction.isStarted && t.buttons === 0 && (this.container.classList.remove("ls-viewer-container-vrobject-grabbing"), this.interaction.end(y.pointFromMouseEvent(t), !1));
1459
+ }
1460
+ onTouchStart(t) {
1461
+ this.container.classList.add("ls-viewer-container-vrobject-grabbing"), this.interaction.start(y.pointFromTouchEvent(t), {
1462
+ width: this.canvas.element.width,
1463
+ height: this.canvas.element.height
1464
+ });
1465
+ }
1466
+ onTouchMove(t) {
1467
+ this.interaction.isStarted && (this.interaction.motion(y.pointFromTouchEvent(t)), t.preventDefault());
1468
+ }
1469
+ onTouchEnd(t) {
1470
+ this.interaction.isStarted && (this.container.classList.remove("ls-viewer-container-vrobject-grabbing"), this.interaction.end(y.pointFromTouchEvent(t), !0));
1471
+ }
1472
+ onDeviceOrientation(t) {
1473
+ }
1474
+ }
1475
+ class it {
1476
+ constructor(t, e, i) {
1477
+ this.container = t, this.loader = i, this.video = e;
1478
+ }
1479
+ destroy() {
1480
+ }
1481
+ show() {
1482
+ this.video.show(), this.container.classList.add("ls-viewer-container-video");
1483
+ }
1484
+ hide() {
1485
+ this.video.hide(), this.container.classList.remove("ls-viewer-container-video");
1486
+ }
1487
+ async load(t) {
1488
+ const e = JSON.stringify(t);
1489
+ return e === this.hash ? (this.video.element.load(), Promise.resolve()) : (this.hash = e, this.loader.loadVideoSnapshot(this.video.element, t));
1490
+ }
1491
+ async pick(t, e) {
1492
+ return Promise.reject();
1493
+ }
1494
+ hotspots(t) {
1495
+ return [];
1496
+ }
1497
+ snapshot(t, e) {
1498
+ return "data:image/gif;base64,R0lGODlhAQABAIAAAP7//wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==";
1499
+ }
1500
+ async play() {
1501
+ return new Promise((t, e) => {
1502
+ this.video.element.addEventListener(
1503
+ "ended",
1504
+ () => {
1505
+ t();
1506
+ },
1507
+ { once: !0 }
1508
+ ), this.video.element.play().catch(e), this.show();
1509
+ });
1510
+ }
1511
+ onMouseDown(t) {
1512
+ }
1513
+ onMouseMove(t) {
1514
+ }
1515
+ onMouseUp(t) {
1516
+ }
1517
+ onMouseEnter(t) {
1518
+ }
1519
+ onTouchStart(t) {
1520
+ }
1521
+ onTouchMove(t) {
1522
+ }
1523
+ onTouchEnd(t) {
1524
+ }
1525
+ onDeviceOrientation(t) {
1526
+ }
1527
+ }
1528
+ class nt {
1529
+ constructor(t, e) {
1530
+ this.checkResize = this.checkResize.bind(this), this.onDeviceOrientation = this.onDeviceOrientation.bind(this), this.onResize = this.onResize.bind(this), this.onMouseDown = this.onMouseDown.bind(this), this.onMouseMove = this.onMouseMove.bind(this), this.onMouseUp = this.onMouseUp.bind(this), this.onMouseEnter = this.onMouseEnter.bind(this), this.onTouchStart = this.onTouchStart.bind(this), this.onTouchMove = this.onTouchMove.bind(this), this.onTouchEnd = this.onTouchEnd.bind(this), this.onLoadStart = this.onLoadStart.bind(this), this.onLoadProgress = this.onLoadProgress.bind(this), this.onLoadEnd = this.onLoadEnd.bind(this), this.onLoadError = this.onLoadError.bind(this), this.onHotspotsChange = this.onHotspotsChange.bind(this), this.onVrcubeInteraction = this.onVrcubeInteraction.bind(this), this.onVrobjectInteraction = this.onVrobjectInteraction.bind(this), this.options = {
1531
+ server: "localhost",
1532
+ api: "v1",
1533
+ autores: !0,
1534
+ fit: "cover",
1535
+ image: {},
1536
+ video: {},
1537
+ vrcube: {},
1538
+ vrobject: {},
1539
+ events: {},
1540
+ ...e
1541
+ }, this.options.events = {
1542
+ onLoadStart: () => {
1543
+ },
1544
+ onLoadProgress: () => {
1545
+ },
1546
+ onLoadEnd: () => {
1547
+ },
1548
+ onLoadError: () => {
1549
+ },
1550
+ onInteraction: () => {
1551
+ },
1552
+ onVrcubeInteraction: () => {
1553
+ },
1554
+ onVrobjectInteraction: () => {
1555
+ },
1556
+ onHotspotsChange: () => {
1557
+ },
1558
+ ...e.events
1559
+ }, this.options.events.onLoadError = k(this.options.events.onLoadError, 10), this.container = t, this.container.classList.add("ls-viewer-container"), this.containerWidth = 0, this.containerHeight = 0, this.canvas2D = new N(this.options.fit), this.container.prepend(this.canvas2D.element), this.canvas3D = new B(), this.container.prepend(this.canvas3D.element), this.video = new J(), this.container.prepend(this.video.element), this.loader = new D(this.options.server, this.options.api, this), this.resolution = new b(0, 0), this.parameters = {
1560
+ width: 0,
1561
+ height: 0,
1562
+ antialiasing: !1,
1563
+ superSampling: 2
1564
+ }, this.encoder = {
1565
+ format: "jpeg",
1566
+ quality: 80
1567
+ }, this.hotspots = [], this.widgetImage = new Z(t, this.canvas2D, this.loader), this.widgetVideo = new it(t, this.video, this.loader), this.widgetVRObject = new C(t, this.canvas2D, this.loader, this.onVrobjectInteraction), this.canvas3D.context && (this.widgetVRCube = new tt(t, this.canvas3D, this.loader, this.onVrcubeInteraction)), this.widget = this.widgetImage, this.isDestroyed = !1, this.container.addEventListener("mousedown", this.onMouseDown), this.container.addEventListener("mouseenter", this.onMouseEnter), this.container.addEventListener("touchstart", this.onTouchStart), document.addEventListener("mousemove", this.onMouseMove, { passive: !1 }), document.addEventListener("mouseup", this.onMouseUp), document.addEventListener("touchmove", this.onTouchMove, { passive: !1 }), document.addEventListener("touchend", this.onTouchEnd), this.loadWidget = k(this.loadWidget, 10), this.onResize = k(this.onResize, 250), requestAnimationFrame(this.checkResize);
1568
+ }
1569
+ destroy() {
1570
+ this.canvas2D.destroy(), this.container.removeEventListener("mousedown", this.onMouseDown), this.container.removeEventListener("mouseenter", this.onMouseEnter), this.container.removeEventListener("touchstart", this.onTouchStart), document.removeEventListener("mousemove", this.onMouseMove), document.removeEventListener("mouseup", this.onMouseUp), document.removeEventListener("touchmove", this.onTouchMove), document.removeEventListener("touchend", this.onTouchEnd), this.isDestroyed = !0;
1571
+ }
1572
+ async load(t, e) {
1573
+ let i = Promise.resolve();
1574
+ return e != null && e.animation && (i = i.then(() => this.loadAnimation(e.animation))), this.view && (e == null ? void 0 : e.fromPosition) !== void 0 && this.viewWidget instanceof C && (this.view.mode, i = i.then(() => this.viewWidget.goto(e.fromPosition))), e != null && e.animation && (i = i.then(() => this.widgetVideo.play())), i = i.then(() => (this.scene = Array.isArray(t) ? [...t] : [t], this.loadWidget(!1, !(e && e.animation)))), i.catch((s) => {
1575
+ this.onLoadError(s);
1576
+ }), i;
1577
+ }
1578
+ async setEncoder(t) {
1579
+ this.encoder = { ...t };
1580
+ let e = Promise.resolve();
1581
+ return e = e.then(() => this.loadWidget(!1, !0)), e.catch((i) => {
1582
+ this.onLoadError(i);
1583
+ }), e;
1584
+ }
1585
+ setParameters(t) {
1586
+ t.width && t.height && (this.resolution = new b(t.width, t.height)), this.parameters = { ...t }, this.parameters.width = this.resolution.width, this.parameters.height = this.resolution.height;
1587
+ let e = Promise.resolve();
1588
+ return e = e.then(() => this.loadWidget(!1, !0)), e.catch((i) => {
1589
+ this.onLoadError(i);
1590
+ }), e;
1591
+ }
1592
+ setHotspots(t) {
1593
+ this.hotspots = t, this.loadWidget(!1, !1);
1594
+ }
1595
+ async setView(t, e) {
1596
+ let i = Promise.resolve();
1597
+ return e != null && e.animation && (i = i.then(() => this.loadAnimation(e.animation))), this.view && (e == null ? void 0 : e.fromPosition) !== void 0 && this.viewWidget instanceof C && (i = i.then(() => this.viewWidget.goto(e.fromPosition))), e != null && e.animation && (i = i.then(() => this.widgetVideo.play())), i = i.then(() => {
1598
+ let s = !0;
1599
+ return this.view = { ...t }, this.view && this.viewWidget instanceof C && (e == null ? void 0 : e.toPosition) !== void 0 && (s = !1, this.viewWidget.position = e.toPosition), this.loadWidget(s, !(e && e.animation));
1600
+ }), i.catch((s) => {
1601
+ this.onLoadError(s);
1602
+ }), i;
1603
+ }
1604
+ setVrcube(t) {
1605
+ this.widgetVRCube && Object.assign(this.widgetVRCube, t);
1606
+ }
1607
+ setVrobject(t) {
1608
+ Object.assign(this.widgetVRObject, t);
1609
+ }
1610
+ async loadAnimation(t) {
1611
+ var i;
1612
+ const e = {
1613
+ scene: this.scene,
1614
+ view: {
1615
+ animation: t.name,
1616
+ camera: t.camera,
1617
+ duration: t.duration,
1618
+ loop: t.loop,
1619
+ reverse: t.reverse
1620
+ },
1621
+ parameters: this.parameters,
1622
+ encoder: {
1623
+ format: "mp4"
1624
+ }
1625
+ };
1626
+ return (i = e.view) != null && i.background || (e.view.background = "product"), this.widgetVideo.load(e).then(() => Promise.resolve());
1627
+ }
1628
+ async playAnimation(t) {
1629
+ return this.loadAnimation(t).then(() => this.widgetVideo.play()).catch((e) => {
1630
+ this.onLoadError(e);
1631
+ });
1632
+ }
1633
+ stopAnimation() {
1634
+ this.widgetVideo.hide();
1635
+ }
1636
+ async pick(t) {
1637
+ if (!this.scene)
1638
+ throw new Error("No scene set");
1639
+ if (!this.view)
1640
+ throw new Error("No view set");
1641
+ if (!this.view.camera && !this.view.cameraGroup)
1642
+ throw new Error("No camera set");
1643
+ const e = {
1644
+ scene: this.scene,
1645
+ view: this.view,
1646
+ parameters: this.parameters,
1647
+ encoder: this.encoder
1648
+ };
1649
+ return await this.viewWidget.pick(e, t);
1650
+ }
1651
+ async pickHotspot(t) {
1652
+ const e = await this.pick(t), i = Object.values(e.point), s = h.normalize(Object.values(e.normal)), r = h.add(i, h.mulScalar(s, 0.01));
1653
+ return e.point = { x: r[0], y: r[1], z: r[2] }, e;
1654
+ }
1655
+ snapshot(t, e) {
1656
+ return this.viewWidget.snapshot(t, e);
1657
+ }
1658
+ async loadWidget(t, e) {
1659
+ if (!this.scene || !this.view || !this.parameters.width || !this.parameters.height)
1660
+ return Promise.resolve();
1661
+ const i = this.viewWidget;
1662
+ if (!i)
1663
+ return Promise.reject(new Error("Unknown view mode"));
1664
+ const s = {
1665
+ scene: this.scene,
1666
+ view: this.view,
1667
+ parameters: this.parameters,
1668
+ encoder: this.encoder
1669
+ };
1670
+ return s.view.background || (s.view.background = "product"), i.load(s, this.hotspots, t, e).then(() => {
1671
+ this.widget.hide(), this.widget = i, this.widget.show(), this.widgetVideo.hide(), this.onHotspotsChange();
1672
+ });
1673
+ }
1674
+ get viewWidget() {
1675
+ var t;
1676
+ switch ((t = this.view) == null ? void 0 : t.mode) {
1677
+ case "image":
1678
+ return this.widgetImage;
1679
+ case "video":
1680
+ return this.widgetVideo;
1681
+ case "vrcube":
1682
+ return this.widgetVRCube ?? this.widgetImage;
1683
+ case "vrobject":
1684
+ return this.widgetVRObject;
1685
+ default:
1686
+ return this.widgetImage;
1687
+ }
1688
+ }
1689
+ checkResize() {
1690
+ if (this.isDestroyed)
1691
+ return;
1692
+ const t = this.container.clientWidth, e = this.container.clientHeight;
1693
+ (t !== this.containerWidth || e !== this.containerHeight) && (this.containerWidth = t, this.containerHeight = e, this.onResize()), this.isDestroyed || requestAnimationFrame(this.checkResize);
1694
+ }
1695
+ onMouseDown(t) {
1696
+ this.widget.onMouseDown(t);
1697
+ }
1698
+ onMouseEnter(t) {
1699
+ this.widget.onMouseEnter(t);
1700
+ }
1701
+ onMouseMove(t) {
1702
+ this.widget.onMouseMove(t);
1703
+ }
1704
+ onMouseUp(t) {
1705
+ this.widget.onMouseUp(t);
1706
+ }
1707
+ onTouchStart(t) {
1708
+ this.widget.onTouchStart(t);
1709
+ }
1710
+ onTouchMove(t) {
1711
+ this.widget.onTouchMove(t);
1712
+ }
1713
+ onTouchEnd(t) {
1714
+ this.widget.onTouchEnd(t);
1715
+ }
1716
+ onDeviceOrientation(t) {
1717
+ this.widget.onDeviceOrientation(t);
1718
+ }
1719
+ onResize() {
1720
+ const t = this.container.clientWidth, e = this.container.clientHeight;
1721
+ this.options.autores && (this.resolution = p.getStandardResolution(t * window.devicePixelRatio, e * window.devicePixelRatio), this.parameters.width = this.resolution.width, this.parameters.height = this.resolution.height), this.canvas2D.resize(t, e, window.devicePixelRatio), this.canvas3D.resize(t, e, window.devicePixelRatio), this.video.resize(t, e, this.resolution, this.options.fit), this.loadWidget(!1, !1).then(() => {
1722
+ this.onHotspotsChange();
1723
+ }).catch((i) => {
1724
+ this.onLoadError(i);
1725
+ });
1726
+ }
1727
+ onVrcubeInteraction(...t) {
1728
+ this.onHotspotsChange(), this.options.events.onInteraction(...t), this.options.events.onVrcubeInteraction(...t);
1729
+ }
1730
+ onVrobjectInteraction(t) {
1731
+ this.onHotspotsChange(), this.options.events.onInteraction(t.position), this.options.events.onVrobjectInteraction(t.position);
1732
+ }
1733
+ onHotspotsChange() {
1734
+ const t = this.widget.hotspots(this.resolution);
1735
+ t.length && this.options.events.onHotspotsChange(t);
1736
+ }
1737
+ onLoadStart(...t) {
1738
+ this.container.classList.add("ls-viewer-container-loading"), this.options.events.onLoadStart(...t);
1739
+ }
1740
+ onLoadProgress(...t) {
1741
+ this.options.events.onLoadProgress(...t);
1742
+ }
1743
+ onLoadEnd(...t) {
1744
+ this.container.classList.remove("ls-viewer-container-loading"), this.options.events.onLoadEnd(...t);
1745
+ }
1746
+ onLoadError(...t) {
1747
+ this.container.classList.remove("ls-viewer-container-loading"), this.options.events.onLoadError(...t);
1748
+ }
1749
+ }
1750
+ var H;
1751
+ ((v) => {
1752
+ ((t) => {
1753
+ t.Visible = "Visible", t.Occluded = "Occluded", t.Clipped = "Clipped", t.OutOfFrustum = "OutOfFrustum";
1754
+ })(v.HotspotVisibility || (v.HotspotVisibility = {})), ((t) => {
1755
+ t.VeryLow = "veryLow", t.Low = "low", t.Medium = "medium", t.Fine = "fine", t.Ultra = "ultra";
1756
+ })(v.SunShadowQualityMode || (v.SunShadowQualityMode = {})), ((t) => {
1757
+ t.None = "none", t.Weak = "weak", t.Normal = "normal", t.Fine = "fine", t.UltraFine = "ultraFine", t.Max = "max";
1758
+ })(v.SunShadowSmoothnessMode || (v.SunShadowSmoothnessMode = {})), ((t) => {
1759
+ t.Manual = "manual", t.ExtractedFromEnv = "extractedFromEnv";
1760
+ })(v.SunUseCaseMode || (v.SunUseCaseMode = {})), ((t) => {
1761
+ t.ShowOnly = "showOnly", t.HideOnly = "hideOnly";
1762
+ })(v.SurfacesFilterMode || (v.SurfacesFilterMode = {}));
1763
+ })(H || (H = {}));
1764
+ export {
1765
+ nt as Viewer,
1766
+ H as WRAPIv2,
1767
+ Z as WidgetImage,
1768
+ tt as WidgetVRCube,
1769
+ C as WidgetVRObject,
1770
+ it as WidgetVideo
1771
+ };