@archilogic/embed-api 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/embed.d.ts +93 -89
- package/dist/embed.js +1 -1
- package/dist/embed.modern.js +325 -1
- package/dist/embed.module.js +325 -1
- package/dist/embed.umd.js +1 -1
- package/dist/globals.d.ts +2 -2
- package/dist/iframe.d.ts +1 -1
- package/package.json +19 -12
- package/.idea/archilogic-embed-api.iml +0 -12
- package/.idea/codeStyles/Project.xml +0 -63
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -272
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -142
- package/.prettierrc +0 -10
- package/jest.config.js +0 -4
package/dist/embed.module.js
CHANGED
|
@@ -1 +1,325 @@
|
|
|
1
|
-
|
|
1
|
+
// ../../node_modules/penpal/lib/enums.js
|
|
2
|
+
var e;
|
|
3
|
+
(function(e) {
|
|
4
|
+
e.Call = "call", e.Reply = "reply", e.Syn = "syn", e.SynAck = "synAck", e.Ack = "ack";
|
|
5
|
+
})(e || (e = {}));
|
|
6
|
+
var t;
|
|
7
|
+
(function(e) {
|
|
8
|
+
e.Fulfilled = "fulfilled", e.Rejected = "rejected";
|
|
9
|
+
})(t || (t = {}));
|
|
10
|
+
var n;
|
|
11
|
+
(function(e) {
|
|
12
|
+
e.ConnectionDestroyed = "ConnectionDestroyed", e.ConnectionTimeout = "ConnectionTimeout", e.NotInIframe = "NotInIframe", e.NoIframeSrc = "NoIframeSrc";
|
|
13
|
+
})(n || (n = {}));
|
|
14
|
+
var r;
|
|
15
|
+
(function(e) {
|
|
16
|
+
e.DataCloneError = "DataCloneError";
|
|
17
|
+
})(r || (r = {}));
|
|
18
|
+
var i;
|
|
19
|
+
(function(e) {
|
|
20
|
+
e.Message = "message";
|
|
21
|
+
})(i || (i = {}));
|
|
22
|
+
// ../../node_modules/penpal/lib/createDestructor.js
|
|
23
|
+
var a = () => {
|
|
24
|
+
let e = [], t = !1;
|
|
25
|
+
return {
|
|
26
|
+
destroy(n) {
|
|
27
|
+
t = !0, e.forEach((e) => {
|
|
28
|
+
e(n);
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
onDestroy(n) {
|
|
32
|
+
t ? n() : e.push(n);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}, o = (e) => (...t) => {
|
|
36
|
+
e && console.log("[Penpal]", ...t);
|
|
37
|
+
}, s = {
|
|
38
|
+
"http:": "80",
|
|
39
|
+
"https:": "443"
|
|
40
|
+
}, c = /^(https?:)?\/\/([^/:]+)?(:(\d+))?/, l = ["file:", "data:"], u = (e) => {
|
|
41
|
+
if (e && l.find((t) => e.startsWith(t))) return "null";
|
|
42
|
+
let t = document.location, n = c.exec(e), r, i, a;
|
|
43
|
+
n ? (r = n[1] ? n[1] : t.protocol, i = n[2], a = n[4]) : (r = t.protocol, i = t.hostname, a = t.port);
|
|
44
|
+
let o = a && a !== s[r] ? `:${a}` : "";
|
|
45
|
+
return `${r}//${i}${o}`;
|
|
46
|
+
}, d = ({ name: e, message: t, stack: n }) => ({
|
|
47
|
+
name: e,
|
|
48
|
+
message: t,
|
|
49
|
+
stack: n
|
|
50
|
+
}), f = (e) => {
|
|
51
|
+
let t = /* @__PURE__ */ Error();
|
|
52
|
+
return Object.keys(e).forEach((n) => t[n] = e[n]), t;
|
|
53
|
+
}, p = (n, a, o) => {
|
|
54
|
+
let { localName: s, local: c, remote: l, originForSending: u, originForReceiving: f } = n, p = !1, m = (n) => {
|
|
55
|
+
if (n.source !== l || n.data.penpal !== e.Call) return;
|
|
56
|
+
if (n.origin !== f) {
|
|
57
|
+
o(`${s} received message from origin ${n.origin} which did not match expected origin ${f}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let { methodName: i, args: c, id: m } = n.data;
|
|
61
|
+
o(`${s}: Received ${i}() call`);
|
|
62
|
+
let h = (n) => (a) => {
|
|
63
|
+
if (o(`${s}: Sending ${i}() reply`), p) {
|
|
64
|
+
o(`${s}: Unable to send ${i}() reply due to destroyed connection`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let c = {
|
|
68
|
+
penpal: e.Reply,
|
|
69
|
+
id: m,
|
|
70
|
+
resolution: n,
|
|
71
|
+
returnValue: a
|
|
72
|
+
};
|
|
73
|
+
n === t.Rejected && a instanceof Error && (c.returnValue = d(a), c.returnValueIsError = !0);
|
|
74
|
+
try {
|
|
75
|
+
l.postMessage(c, u);
|
|
76
|
+
} catch (n) {
|
|
77
|
+
if (n.name === r.DataCloneError) {
|
|
78
|
+
let r = {
|
|
79
|
+
penpal: e.Reply,
|
|
80
|
+
id: m,
|
|
81
|
+
resolution: t.Rejected,
|
|
82
|
+
returnValue: d(n),
|
|
83
|
+
returnValueIsError: !0
|
|
84
|
+
};
|
|
85
|
+
l.postMessage(r, u);
|
|
86
|
+
}
|
|
87
|
+
throw n;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
new Promise((e) => e(a[i].apply(a, c))).then(h(t.Fulfilled), h(t.Rejected));
|
|
91
|
+
};
|
|
92
|
+
return c.addEventListener(i.Message, m), () => {
|
|
93
|
+
p = !0, c.removeEventListener(i.Message, m);
|
|
94
|
+
};
|
|
95
|
+
}, m = 0, h = () => ++m, g = (r, a, o, s, c) => {
|
|
96
|
+
let { localName: l, local: u, remote: d, originForSending: p, originForReceiving: m } = a, g = !1;
|
|
97
|
+
c(`${l}: Connecting call sender`);
|
|
98
|
+
let _ = (r) => (...a) => {
|
|
99
|
+
c(`${l}: Sending ${r}() call`);
|
|
100
|
+
let o;
|
|
101
|
+
try {
|
|
102
|
+
d.closed && (o = !0);
|
|
103
|
+
} catch {
|
|
104
|
+
o = !0;
|
|
105
|
+
}
|
|
106
|
+
if (o && s(), g) {
|
|
107
|
+
let e = /* @__PURE__ */ Error(`Unable to send ${r}() call due to destroyed connection`);
|
|
108
|
+
throw e.code = n.ConnectionDestroyed, e;
|
|
109
|
+
}
|
|
110
|
+
return new Promise((n, o) => {
|
|
111
|
+
let s = h(), g = (a) => {
|
|
112
|
+
if (a.source !== d || a.data.penpal !== e.Reply || a.data.id !== s) return;
|
|
113
|
+
if (a.origin !== m) {
|
|
114
|
+
c(`${l} received message from origin ${a.origin} which did not match expected origin ${m}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
let p = a.data;
|
|
118
|
+
c(`${l}: Received ${r}() reply`), u.removeEventListener(i.Message, g);
|
|
119
|
+
let h = p.returnValue;
|
|
120
|
+
p.returnValueIsError && (h = f(h)), (p.resolution === t.Fulfilled ? n : o)(h);
|
|
121
|
+
};
|
|
122
|
+
u.addEventListener(i.Message, g);
|
|
123
|
+
let _ = {
|
|
124
|
+
penpal: e.Call,
|
|
125
|
+
id: s,
|
|
126
|
+
methodName: r,
|
|
127
|
+
args: a
|
|
128
|
+
};
|
|
129
|
+
d.postMessage(_, p);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
return o.reduce((e, t) => (e[t] = _(t), e), r), () => {
|
|
133
|
+
g = !0;
|
|
134
|
+
};
|
|
135
|
+
}, _ = (e, t, n, r, i) => {
|
|
136
|
+
let { destroy: a, onDestroy: o } = r, s, c, l = {};
|
|
137
|
+
return (r) => {
|
|
138
|
+
if (r.origin !== t) {
|
|
139
|
+
i(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${t}`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
i("Parent: Handshake - Received ACK");
|
|
143
|
+
let u = {
|
|
144
|
+
localName: "Parent",
|
|
145
|
+
local: window,
|
|
146
|
+
remote: r.source,
|
|
147
|
+
originForSending: n,
|
|
148
|
+
originForReceiving: t
|
|
149
|
+
};
|
|
150
|
+
s && s(), s = p(u, e, i), o(s), c && c.forEach((e) => {
|
|
151
|
+
delete l[e];
|
|
152
|
+
}), c = r.data.methodNames;
|
|
153
|
+
let d = g(l, u, c, a, i);
|
|
154
|
+
return o(d), l;
|
|
155
|
+
};
|
|
156
|
+
}, v = (t, n, r, i) => (a) => {
|
|
157
|
+
if (a.origin !== r) {
|
|
158
|
+
t(`Parent: Handshake - Received SYN message from origin ${a.origin} which did not match expected origin ${r}`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
t("Parent: Handshake - Received SYN, responding with SYN-ACK");
|
|
162
|
+
let o = {
|
|
163
|
+
penpal: e.SynAck,
|
|
164
|
+
methodNames: Object.keys(n)
|
|
165
|
+
};
|
|
166
|
+
a.source.postMessage(o, i);
|
|
167
|
+
}, y = 6e4, b = (e, t) => {
|
|
168
|
+
let { destroy: n, onDestroy: r } = t, i = setInterval(() => {
|
|
169
|
+
e.isConnected || (clearInterval(i), n());
|
|
170
|
+
}, y);
|
|
171
|
+
r(() => {
|
|
172
|
+
clearInterval(i);
|
|
173
|
+
});
|
|
174
|
+
}, x = (e, t) => {
|
|
175
|
+
let r;
|
|
176
|
+
return e !== void 0 && (r = window.setTimeout(() => {
|
|
177
|
+
let r = /* @__PURE__ */ Error(`Connection timed out after ${e}ms`);
|
|
178
|
+
r.code = n.ConnectionTimeout, t(r);
|
|
179
|
+
}, e)), () => {
|
|
180
|
+
clearTimeout(r);
|
|
181
|
+
};
|
|
182
|
+
}, S = (e) => {
|
|
183
|
+
if (!e.src && !e.srcdoc) {
|
|
184
|
+
let e = /* @__PURE__ */ Error("Iframe must have src or srcdoc property defined.");
|
|
185
|
+
throw e.code = n.NoIframeSrc, e;
|
|
186
|
+
}
|
|
187
|
+
}, C = (t) => {
|
|
188
|
+
let { iframe: r, methods: s = {}, childOrigin: c, timeout: l, debug: d = !1 } = t, f = o(d), p = a(), { onDestroy: m, destroy: h } = p;
|
|
189
|
+
c || (S(r), c = u(r.src));
|
|
190
|
+
let g = c === "null" ? "*" : c, y = v(f, s, c, g), C = _(s, c, g, p, f);
|
|
191
|
+
return {
|
|
192
|
+
promise: new Promise((t, a) => {
|
|
193
|
+
let o = x(l, h), s = (n) => {
|
|
194
|
+
if (n.source === r.contentWindow && n.data) {
|
|
195
|
+
if (n.data.penpal === e.Syn) y(n);
|
|
196
|
+
else if (n.data.penpal === e.Ack) {
|
|
197
|
+
let e = C(n);
|
|
198
|
+
e && (o(), t(e));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
window.addEventListener(i.Message, s), f("Parent: Awaiting handshake"), b(r, p), m((e) => {
|
|
203
|
+
window.removeEventListener(i.Message, s), e || (e = /* @__PURE__ */ Error("Connection destroyed"), e.code = n.ConnectionDestroyed), a(e);
|
|
204
|
+
});
|
|
205
|
+
}),
|
|
206
|
+
destroy() {
|
|
207
|
+
h();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}, w = window.__A_EMBED_API_VERSION__ || "v2_1_1", T = `${window.__A_VIEWER_URL__ || "https://viewer.archilogic.com"}/${w}?embedType=api`;
|
|
211
|
+
// src/iframe.ts
|
|
212
|
+
function E(e = document.body) {
|
|
213
|
+
let t = document.createElement("iframe");
|
|
214
|
+
return Object.assign(t, {
|
|
215
|
+
src: T,
|
|
216
|
+
width: "100%",
|
|
217
|
+
height: "100%",
|
|
218
|
+
title: "Archilogic Embed",
|
|
219
|
+
frameBorder: "0",
|
|
220
|
+
scrolling: "no",
|
|
221
|
+
allowTransparency: "true",
|
|
222
|
+
allowFullscreen: "true",
|
|
223
|
+
style: "border: 0;"
|
|
224
|
+
}), e.appendChild(t), t;
|
|
225
|
+
}
|
|
226
|
+
// src/embed.ts
|
|
227
|
+
var D = 0, O = (e) => JSON.parse(JSON.stringify(e)), k = /* @__PURE__ */ function(e) {
|
|
228
|
+
return e[e.none = 0] = "none", e[e.goToCameraDefault = 1] = "goToCameraDefault", e[e.goToFirstBookmark = 2] = "goToFirstBookmark", e[e.jumpToCameraDefault = 3] = "jumpToCameraDefault", e[e.jumpToFirstBookmark = 4] = "jumpToFirstBookmark", e[e.tourOnce = 5] = "tourOnce", e[e.tourOnceAndGoBack = 6] = "tourOnceAndGoBack", e[e.tourLoop = 7] = "tourLoop", e;
|
|
229
|
+
}({}), A = {
|
|
230
|
+
transparentBackground: !0,
|
|
231
|
+
presentationMode: 3,
|
|
232
|
+
showTitle: !1,
|
|
233
|
+
showLogo: !1,
|
|
234
|
+
minimap: !1,
|
|
235
|
+
lowResTexturesOnly: !1,
|
|
236
|
+
bookmarksActive: !1,
|
|
237
|
+
uiButtons: {
|
|
238
|
+
birdMode: !1,
|
|
239
|
+
personMode: !1,
|
|
240
|
+
floorPlanMode: !1,
|
|
241
|
+
fullscreen: !1,
|
|
242
|
+
bookmarkStrip: !1,
|
|
243
|
+
share: !1,
|
|
244
|
+
help: !1,
|
|
245
|
+
presentation: !1,
|
|
246
|
+
units: !1,
|
|
247
|
+
exportImage: !1,
|
|
248
|
+
measureTool: !1
|
|
249
|
+
}
|
|
250
|
+
}, j = class {
|
|
251
|
+
constructor(e, t = {}) {
|
|
252
|
+
this.listeners = /* @__PURE__ */ new Map(), this.onFullscreenChange = () => {
|
|
253
|
+
this.viewer.onFullscreenChange && this.viewer.onFullscreenChange(this.getIsFullscreen());
|
|
254
|
+
}, this.toggleFullscreen = async () => (this.getIsFullscreen() ? await document.exitFullscreen() : await this.containerEl.requestFullscreen(), this.getIsFullscreen()), this.handleEvent = (e, t) => {
|
|
255
|
+
let n = this.listeners.get(e);
|
|
256
|
+
if (n) return n(t);
|
|
257
|
+
console.warn("Listener not found");
|
|
258
|
+
}, this.getIsFullscreen = () => !!(document.fullscreenElement && document.fullscreenElement === this.containerEl), this.options = O({
|
|
259
|
+
...A,
|
|
260
|
+
...t
|
|
261
|
+
}), this.containerEl = e, this.viewerEl = E(e), this.viewerConnection = C({
|
|
262
|
+
timeout: 1e4,
|
|
263
|
+
iframe: this.viewerEl,
|
|
264
|
+
methods: {
|
|
265
|
+
handleEvent: this.handleEvent,
|
|
266
|
+
getIsFullscreen: this.getIsFullscreen,
|
|
267
|
+
toggleFullscreen: this.toggleFullscreen
|
|
268
|
+
}
|
|
269
|
+
}), this.viewerReadyPromise = this.viewerConnection.promise.then(async (e) => (this.viewerInstance = e, document.addEventListener("fullscreenchange", this.onFullscreenChange), this.viewer.set(this.options), !0)).catch((e) => (console.error(e), !1));
|
|
270
|
+
}
|
|
271
|
+
get viewer() {
|
|
272
|
+
if (!this.viewerInstance) throw Error("Method called before viewer initialization. Wait for viewerReadyPromise to resolve before performing this action");
|
|
273
|
+
return this.viewerInstance;
|
|
274
|
+
}
|
|
275
|
+
async loadScene(e, t) {
|
|
276
|
+
return await this.viewerReadyPromise, this.viewer.loadSceneV2(e, t);
|
|
277
|
+
}
|
|
278
|
+
async listBookmarks() {
|
|
279
|
+
return this.viewer.listBookmarks();
|
|
280
|
+
}
|
|
281
|
+
async listSpaces() {
|
|
282
|
+
return this.viewer.listSpaces();
|
|
283
|
+
}
|
|
284
|
+
async startPresentation() {
|
|
285
|
+
return await this.viewerReadyPromise, this.viewer.startPresentation();
|
|
286
|
+
}
|
|
287
|
+
async goToBookmark({ bookmarkId: e, animate: t = !0 }) {
|
|
288
|
+
return this.viewer.goToBookmark({
|
|
289
|
+
bookmarkId: e,
|
|
290
|
+
animate: t
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async goToBirdMode({ animate: e = !0 } = {}) {
|
|
294
|
+
return this.viewer.goToBirdMode({ animate: e });
|
|
295
|
+
}
|
|
296
|
+
async goToPersonMode({ findSafeLanding: e = !0, animate: t = !0 } = {}) {
|
|
297
|
+
return this.viewer.goToPersonMode({
|
|
298
|
+
findSafeLanding: e,
|
|
299
|
+
animate: t
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
async zoomExtents({ spaceId: e = void 0, animate: t = !0, zoomMin: n = !1, zoomMax: r = !1 } = {}) {
|
|
303
|
+
let i = this.viewerEl.getBoundingClientRect(), a = i.width / i.height;
|
|
304
|
+
return this.viewer.zoomExtents({
|
|
305
|
+
spaceId: e,
|
|
306
|
+
animate: t,
|
|
307
|
+
aspect: a,
|
|
308
|
+
zoomMin: n,
|
|
309
|
+
zoomMax: r
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
set(e) {
|
|
313
|
+
this.viewer.set(O(e));
|
|
314
|
+
}
|
|
315
|
+
on(e, t) {
|
|
316
|
+
return D++, this.listeners.set(D, t), this.viewer.addListener(e, D), D;
|
|
317
|
+
}
|
|
318
|
+
off(e) {
|
|
319
|
+
return this.viewer.removeListener(e);
|
|
320
|
+
}
|
|
321
|
+
async destroy() {
|
|
322
|
+
return document.removeEventListener("fullscreenchange", this.onFullscreenChange), this.viewerConnection.destroy();
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
export { k as PresentationMode, j as default, A as defaultEmbedOptions };
|
package/dist/embed.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.embedApi={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t;(function(e){e.Call=`call`,e.Reply=`reply`,e.Syn=`syn`,e.SynAck=`synAck`,e.Ack=`ack`})(t||(t={}));var n;(function(e){e.Fulfilled=`fulfilled`,e.Rejected=`rejected`})(n||(n={}));var r;(function(e){e.ConnectionDestroyed=`ConnectionDestroyed`,e.ConnectionTimeout=`ConnectionTimeout`,e.NotInIframe=`NotInIframe`,e.NoIframeSrc=`NoIframeSrc`})(r||(r={}));var i;(function(e){e.DataCloneError=`DataCloneError`})(i||(i={}));var a;(function(e){e.Message=`message`})(a||(a={}));var o=()=>{let e=[],t=!1;return{destroy(n){t=!0,e.forEach(e=>{e(n)})},onDestroy(n){t?n():e.push(n)}}},s=e=>(...t)=>{e&&console.log(`[Penpal]`,...t)},c={"http:":`80`,"https:":`443`},l=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,u=[`file:`,`data:`],d=e=>{if(e&&u.find(t=>e.startsWith(t)))return`null`;let t=document.location,n=l.exec(e),r,i,a;n?(r=n[1]?n[1]:t.protocol,i=n[2],a=n[4]):(r=t.protocol,i=t.hostname,a=t.port);let o=a&&a!==c[r]?`:${a}`:``;return`${r}//${i}${o}`},f=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n}),p=e=>{let t=Error();return Object.keys(e).forEach(n=>t[n]=e[n]),t},m=(e,r,o)=>{let{localName:s,local:c,remote:l,originForSending:u,originForReceiving:d}=e,p=!1,m=e=>{if(e.source!==l||e.data.penpal!==t.Call)return;if(e.origin!==d){o(`${s} received message from origin ${e.origin} which did not match expected origin ${d}`);return}let{methodName:a,args:c,id:m}=e.data;o(`${s}: Received ${a}() call`);let h=e=>r=>{if(o(`${s}: Sending ${a}() reply`),p){o(`${s}: Unable to send ${a}() reply due to destroyed connection`);return}let c={penpal:t.Reply,id:m,resolution:e,returnValue:r};e===n.Rejected&&r instanceof Error&&(c.returnValue=f(r),c.returnValueIsError=!0);try{l.postMessage(c,u)}catch(e){if(e.name===i.DataCloneError){let r={penpal:t.Reply,id:m,resolution:n.Rejected,returnValue:f(e),returnValueIsError:!0};l.postMessage(r,u)}throw e}};new Promise(e=>e(r[a].apply(r,c))).then(h(n.Fulfilled),h(n.Rejected))};return c.addEventListener(a.Message,m),()=>{p=!0,c.removeEventListener(a.Message,m)}},h=0,g=()=>++h,_=(e,i,o,s,c)=>{let{localName:l,local:u,remote:d,originForSending:f,originForReceiving:m}=i,h=!1;c(`${l}: Connecting call sender`);let _=e=>(...i)=>{c(`${l}: Sending ${e}() call`);let o;try{d.closed&&(o=!0)}catch{o=!0}if(o&&s(),h){let t=Error(`Unable to send ${e}() call due to destroyed connection`);throw t.code=r.ConnectionDestroyed,t}return new Promise((r,o)=>{let s=g(),h=i=>{if(i.source!==d||i.data.penpal!==t.Reply||i.data.id!==s)return;if(i.origin!==m){c(`${l} received message from origin ${i.origin} which did not match expected origin ${m}`);return}let f=i.data;c(`${l}: Received ${e}() reply`),u.removeEventListener(a.Message,h);let g=f.returnValue;f.returnValueIsError&&(g=p(g)),(f.resolution===n.Fulfilled?r:o)(g)};u.addEventListener(a.Message,h);let _={penpal:t.Call,id:s,methodName:e,args:i};d.postMessage(_,f)})};return o.reduce((e,t)=>(e[t]=_(t),e),e),()=>{h=!0}},v=(e,t,n,r,i)=>{let{destroy:a,onDestroy:o}=r,s,c,l={};return r=>{if(r.origin!==t){i(`Parent: Handshake - Received ACK message from origin ${r.origin} which did not match expected origin ${t}`);return}i(`Parent: Handshake - Received ACK`);let u={localName:`Parent`,local:window,remote:r.source,originForSending:n,originForReceiving:t};s&&s(),s=m(u,e,i),o(s),c&&c.forEach(e=>{delete l[e]}),c=r.data.methodNames;let d=_(l,u,c,a,i);return o(d),l}},y=(e,n,r,i)=>a=>{if(a.origin!==r){e(`Parent: Handshake - Received SYN message from origin ${a.origin} which did not match expected origin ${r}`);return}e(`Parent: Handshake - Received SYN, responding with SYN-ACK`);let o={penpal:t.SynAck,methodNames:Object.keys(n)};a.source.postMessage(o,i)},b=6e4,x=(e,t)=>{let{destroy:n,onDestroy:r}=t,i=setInterval(()=>{e.isConnected||(clearInterval(i),n())},b);r(()=>{clearInterval(i)})},S=(e,t)=>{let n;return e!==void 0&&(n=window.setTimeout(()=>{let n=Error(`Connection timed out after ${e}ms`);n.code=r.ConnectionTimeout,t(n)},e)),()=>{clearTimeout(n)}},C=e=>{if(!e.src&&!e.srcdoc){let e=Error(`Iframe must have src or srcdoc property defined.`);throw e.code=r.NoIframeSrc,e}},w=e=>{let{iframe:n,methods:i={},childOrigin:c,timeout:l,debug:u=!1}=e,f=s(u),p=o(),{onDestroy:m,destroy:h}=p;c||(C(n),c=d(n.src));let g=c===`null`?`*`:c,_=y(f,i,c,g),b=v(i,c,g,p,f);return{promise:new Promise((e,i)=>{let o=S(l,h),s=r=>{if(r.source===n.contentWindow&&r.data){if(r.data.penpal===t.Syn)_(r);else if(r.data.penpal===t.Ack){let t=b(r);t&&(o(),e(t))}}};window.addEventListener(a.Message,s),f(`Parent: Awaiting handshake`),x(n,p),m(e=>{window.removeEventListener(a.Message,s),e||(e=Error(`Connection destroyed`),e.code=r.ConnectionDestroyed),i(e)})}),destroy(){h()}}},T=window.__A_EMBED_API_VERSION__||`v2_1_1`,E=`${window.__A_VIEWER_URL__||`https://viewer.archilogic.com`}/${T}?embedType=api`;function D(e=document.body){let t=document.createElement(`iframe`);return Object.assign(t,{src:E,width:`100%`,height:`100%`,title:`Archilogic Embed`,frameBorder:`0`,scrolling:`no`,allowTransparency:`true`,allowFullscreen:`true`,style:`border: 0;`}),e.appendChild(t),t}var O=0,k=e=>JSON.parse(JSON.stringify(e)),A=function(e){return e[e.none=0]=`none`,e[e.goToCameraDefault=1]=`goToCameraDefault`,e[e.goToFirstBookmark=2]=`goToFirstBookmark`,e[e.jumpToCameraDefault=3]=`jumpToCameraDefault`,e[e.jumpToFirstBookmark=4]=`jumpToFirstBookmark`,e[e.tourOnce=5]=`tourOnce`,e[e.tourOnceAndGoBack=6]=`tourOnceAndGoBack`,e[e.tourLoop=7]=`tourLoop`,e}({}),j={transparentBackground:!0,presentationMode:3,showTitle:!1,showLogo:!1,minimap:!1,lowResTexturesOnly:!1,bookmarksActive:!1,uiButtons:{birdMode:!1,personMode:!1,floorPlanMode:!1,fullscreen:!1,bookmarkStrip:!1,share:!1,help:!1,presentation:!1,units:!1,exportImage:!1,measureTool:!1}},M=class{constructor(e,t={}){this.listeners=new Map,this.onFullscreenChange=()=>{this.viewer.onFullscreenChange&&this.viewer.onFullscreenChange(this.getIsFullscreen())},this.toggleFullscreen=async()=>(this.getIsFullscreen()?await document.exitFullscreen():await this.containerEl.requestFullscreen(),this.getIsFullscreen()),this.handleEvent=(e,t)=>{let n=this.listeners.get(e);if(n)return n(t);console.warn(`Listener not found`)},this.getIsFullscreen=()=>!!(document.fullscreenElement&&document.fullscreenElement===this.containerEl),this.options=k({...j,...t}),this.containerEl=e,this.viewerEl=D(e),this.viewerConnection=w({timeout:1e4,iframe:this.viewerEl,methods:{handleEvent:this.handleEvent,getIsFullscreen:this.getIsFullscreen,toggleFullscreen:this.toggleFullscreen}}),this.viewerReadyPromise=this.viewerConnection.promise.then(async e=>(this.viewerInstance=e,document.addEventListener(`fullscreenchange`,this.onFullscreenChange),this.viewer.set(this.options),!0)).catch(e=>(console.error(e),!1))}get viewer(){if(!this.viewerInstance)throw Error(`Method called before viewer initialization. Wait for viewerReadyPromise to resolve before performing this action`);return this.viewerInstance}async loadScene(e,t){return await this.viewerReadyPromise,this.viewer.loadSceneV2(e,t)}async listBookmarks(){return this.viewer.listBookmarks()}async listSpaces(){return this.viewer.listSpaces()}async startPresentation(){return await this.viewerReadyPromise,this.viewer.startPresentation()}async goToBookmark({bookmarkId:e,animate:t=!0}){return this.viewer.goToBookmark({bookmarkId:e,animate:t})}async goToBirdMode({animate:e=!0}={}){return this.viewer.goToBirdMode({animate:e})}async goToPersonMode({findSafeLanding:e=!0,animate:t=!0}={}){return this.viewer.goToPersonMode({findSafeLanding:e,animate:t})}async zoomExtents({spaceId:e=void 0,animate:t=!0,zoomMin:n=!1,zoomMax:r=!1}={}){let i=this.viewerEl.getBoundingClientRect(),a=i.width/i.height;return this.viewer.zoomExtents({spaceId:e,animate:t,aspect:a,zoomMin:n,zoomMax:r})}set(e){this.viewer.set(k(e))}on(e,t){return O++,this.listeners.set(O,t),this.viewer.addListener(e,O),O}off(e){return this.viewer.removeListener(e)}async destroy(){return document.removeEventListener(`fullscreenchange`,this.onFullscreenChange),this.viewerConnection.destroy()}};e.PresentationMode=A,e.default=M,e.defaultEmbedOptions=j});
|
package/dist/globals.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const EMBED_API_VERSION: any;
|
|
2
|
-
export declare const VIEWER_URL: string;
|
|
1
|
+
export declare const EMBED_API_VERSION: any;
|
|
2
|
+
export declare const VIEWER_URL: string;
|
package/dist/iframe.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createViewerIframe(wrapperEl?: HTMLElement): HTMLIFrameElement;
|
|
1
|
+
export declare function createViewerIframe(wrapperEl?: HTMLElement): HTMLIFrameElement;
|
package/package.json
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@archilogic/embed-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "",
|
|
5
|
-
"source": "src/embed.ts",
|
|
6
5
|
"main": "dist/embed.js",
|
|
7
6
|
"module": "dist/embed.module.js",
|
|
8
|
-
"
|
|
7
|
+
"types": "dist/embed.d.ts",
|
|
8
|
+
"unpkg": "dist/embed.umd.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
9
12
|
"scripts": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
13
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
14
|
+
"dev": "tsc -p tsconfig.build.json && vite build --watch --emptyOutDir=false",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"typecheck": "tsc",
|
|
17
|
+
"lint": "eslint --fix src",
|
|
18
|
+
"format": "oxfmt",
|
|
19
|
+
"codecheck": "npm run typecheck && eslint src && oxfmt --check",
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"test:unit": "vitest run"
|
|
14
22
|
},
|
|
15
23
|
"author": "",
|
|
16
24
|
"license": "ISC",
|
|
17
25
|
"devDependencies": {
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"ts-jest": "^26.3.0"
|
|
26
|
+
"penpal": "^5.2.1"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
23
30
|
}
|
|
24
31
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$">
|
|
5
|
-
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
7
|
-
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
-
</content>
|
|
9
|
-
<orderEntry type="inheritedJdk" />
|
|
10
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
</component>
|
|
12
|
-
</module>
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
-
<code_scheme name="Project" version="173">
|
|
3
|
-
<HTMLCodeStyleSettings>
|
|
4
|
-
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
5
|
-
<option name="HTML_QUOTE_STYLE" value="Single" />
|
|
6
|
-
<option name="HTML_ENFORCE_QUOTES" value="true" />
|
|
7
|
-
</HTMLCodeStyleSettings>
|
|
8
|
-
<JSCodeStyleSettings version="0">
|
|
9
|
-
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
10
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
11
|
-
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
12
|
-
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
13
|
-
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
14
|
-
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
15
|
-
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
16
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
17
|
-
</JSCodeStyleSettings>
|
|
18
|
-
<TypeScriptCodeStyleSettings version="0">
|
|
19
|
-
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
|
20
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
21
|
-
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
22
|
-
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
23
|
-
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
24
|
-
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
25
|
-
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
26
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
27
|
-
</TypeScriptCodeStyleSettings>
|
|
28
|
-
<VueCodeStyleSettings>
|
|
29
|
-
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
30
|
-
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
31
|
-
</VueCodeStyleSettings>
|
|
32
|
-
<codeStyleSettings language="HTML">
|
|
33
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
34
|
-
<indentOptions>
|
|
35
|
-
<option name="INDENT_SIZE" value="2" />
|
|
36
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
37
|
-
<option name="TAB_SIZE" value="2" />
|
|
38
|
-
</indentOptions>
|
|
39
|
-
</codeStyleSettings>
|
|
40
|
-
<codeStyleSettings language="JavaScript">
|
|
41
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
42
|
-
<indentOptions>
|
|
43
|
-
<option name="INDENT_SIZE" value="2" />
|
|
44
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
45
|
-
<option name="TAB_SIZE" value="2" />
|
|
46
|
-
</indentOptions>
|
|
47
|
-
</codeStyleSettings>
|
|
48
|
-
<codeStyleSettings language="TypeScript">
|
|
49
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
50
|
-
<indentOptions>
|
|
51
|
-
<option name="INDENT_SIZE" value="2" />
|
|
52
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
53
|
-
<option name="TAB_SIZE" value="2" />
|
|
54
|
-
</indentOptions>
|
|
55
|
-
</codeStyleSettings>
|
|
56
|
-
<codeStyleSettings language="Vue">
|
|
57
|
-
<option name="SOFT_MARGINS" value="100" />
|
|
58
|
-
<indentOptions>
|
|
59
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
60
|
-
</indentOptions>
|
|
61
|
-
</codeStyleSettings>
|
|
62
|
-
</code_scheme>
|
|
63
|
-
</component>
|