@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/README.md
ADDED
package/dist/embed.d.ts
CHANGED
|
@@ -1,89 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
animate?: boolean;
|
|
73
|
-
}): Promise<any>;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
animate?: boolean;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
type CallSender = {
|
|
2
|
+
[index: string]: Function;
|
|
3
|
+
};
|
|
4
|
+
type Connection = {
|
|
5
|
+
promise: Promise<CallSender>;
|
|
6
|
+
destroy: Function;
|
|
7
|
+
};
|
|
8
|
+
export type TemporaryAccessToken = {
|
|
9
|
+
authorization: string;
|
|
10
|
+
expiresAt: number;
|
|
11
|
+
};
|
|
12
|
+
interface TokenOptions {
|
|
13
|
+
publishableAccessToken?: string;
|
|
14
|
+
temporaryAccessToken?: TemporaryAccessToken;
|
|
15
|
+
}
|
|
16
|
+
export declare enum PresentationMode {
|
|
17
|
+
none = 0,
|
|
18
|
+
goToCameraDefault = 1,
|
|
19
|
+
goToFirstBookmark = 2,
|
|
20
|
+
jumpToCameraDefault = 3,
|
|
21
|
+
jumpToFirstBookmark = 4,
|
|
22
|
+
tourOnce = 5,
|
|
23
|
+
tourOnceAndGoBack = 6,
|
|
24
|
+
tourLoop = 7
|
|
25
|
+
}
|
|
26
|
+
export type EmbedEvent = 'sceneDefined' | 'loadingStart' | 'loadingDone';
|
|
27
|
+
export type EmbedUIOptions = {
|
|
28
|
+
birdMode: boolean;
|
|
29
|
+
personMode: boolean;
|
|
30
|
+
floorPlanMode: boolean;
|
|
31
|
+
fullscreen: boolean;
|
|
32
|
+
bookmarkStrip: boolean;
|
|
33
|
+
shareMenu: boolean;
|
|
34
|
+
help: boolean;
|
|
35
|
+
share: boolean;
|
|
36
|
+
presentation: boolean;
|
|
37
|
+
units: boolean;
|
|
38
|
+
exportImage: boolean;
|
|
39
|
+
measureTool: boolean;
|
|
40
|
+
};
|
|
41
|
+
export type EmbedOptions = {
|
|
42
|
+
transparentBackground: boolean;
|
|
43
|
+
showTitle: boolean;
|
|
44
|
+
showLogo: boolean;
|
|
45
|
+
presentationMode: PresentationMode;
|
|
46
|
+
minimap: boolean;
|
|
47
|
+
lowResTexturesOnly: boolean;
|
|
48
|
+
bookmarksActive: boolean;
|
|
49
|
+
uiButtons: boolean | Partial<EmbedUIOptions>;
|
|
50
|
+
};
|
|
51
|
+
export type EmbedOptionsUpdate = Partial<EmbedOptions>;
|
|
52
|
+
export declare const defaultEmbedOptions: EmbedOptions;
|
|
53
|
+
export default class ArchilogicEmbed {
|
|
54
|
+
constructor(el: HTMLElement, options?: EmbedOptionsUpdate);
|
|
55
|
+
viewerConnection: Connection;
|
|
56
|
+
viewerInstance: CallSender;
|
|
57
|
+
options: EmbedOptions;
|
|
58
|
+
listeners: Map<any, any>;
|
|
59
|
+
get viewer(): CallSender;
|
|
60
|
+
readonly containerEl: HTMLElement;
|
|
61
|
+
readonly viewerEl: HTMLIFrameElement;
|
|
62
|
+
readonly viewerReadyPromise: Promise<boolean>;
|
|
63
|
+
loadScene(id: string, tokenOptions: TokenOptions): Promise<any>;
|
|
64
|
+
listBookmarks(): Promise<any>;
|
|
65
|
+
listSpaces(): Promise<any>;
|
|
66
|
+
startPresentation(): Promise<any>;
|
|
67
|
+
goToBookmark({ bookmarkId, animate }: {
|
|
68
|
+
bookmarkId: any;
|
|
69
|
+
animate?: boolean;
|
|
70
|
+
}): Promise<any>;
|
|
71
|
+
goToBirdMode({ animate }?: {
|
|
72
|
+
animate?: boolean;
|
|
73
|
+
}): Promise<any>;
|
|
74
|
+
goToPersonMode({ findSafeLanding, animate }?: {
|
|
75
|
+
findSafeLanding?: boolean;
|
|
76
|
+
animate?: boolean;
|
|
77
|
+
}): Promise<any>;
|
|
78
|
+
zoomExtents({ spaceId, animate, zoomMin, zoomMax }?: {
|
|
79
|
+
spaceId?: any;
|
|
80
|
+
animate?: boolean;
|
|
81
|
+
zoomMin?: boolean;
|
|
82
|
+
zoomMax?: boolean;
|
|
83
|
+
}): Promise<any>;
|
|
84
|
+
onFullscreenChange: () => void;
|
|
85
|
+
set(options: EmbedOptionsUpdate): void;
|
|
86
|
+
on(event: EmbedEvent, callback: any): number;
|
|
87
|
+
off(eventId: string): any;
|
|
88
|
+
destroy(): Promise<any>;
|
|
89
|
+
toggleFullscreen: () => Promise<boolean>;
|
|
90
|
+
handleEvent: (eventId: any, payload: any) => any;
|
|
91
|
+
getIsFullscreen: () => boolean;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
package/dist/embed.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e;(function(e){e.Call=`call`,e.Reply=`reply`,e.Syn=`syn`,e.SynAck=`synAck`,e.Ack=`ack`})(e||(e={}));var t;(function(e){e.Fulfilled=`fulfilled`,e.Rejected=`rejected`})(t||(t={}));var n;(function(e){e.ConnectionDestroyed=`ConnectionDestroyed`,e.ConnectionTimeout=`ConnectionTimeout`,e.NotInIframe=`NotInIframe`,e.NoIframeSrc=`NoIframeSrc`})(n||(n={}));var r;(function(e){e.DataCloneError=`DataCloneError`})(r||(r={}));var i;(function(e){e.Message=`message`})(i||(i={}));var a=()=>{let e=[],t=!1;return{destroy(n){t=!0,e.forEach(e=>{e(n)})},onDestroy(n){t?n():e.push(n)}}},o=e=>(...t)=>{e&&console.log(`[Penpal]`,...t)},s={"http:":`80`,"https:":`443`},c=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,l=[`file:`,`data:`],u=e=>{if(e&&l.find(t=>e.startsWith(t)))return`null`;let t=document.location,n=c.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!==s[r]?`:${a}`:``;return`${r}//${i}${o}`},d=({name:e,message:t,stack:n})=>({name:e,message:t,stack:n}),f=e=>{let t=Error();return Object.keys(e).forEach(n=>t[n]=e[n]),t},p=(n,a,o)=>{let{localName:s,local:c,remote:l,originForSending:u,originForReceiving:f}=n,p=!1,m=n=>{if(n.source!==l||n.data.penpal!==e.Call)return;if(n.origin!==f){o(`${s} received message from origin ${n.origin} which did not match expected origin ${f}`);return}let{methodName:i,args:c,id:m}=n.data;o(`${s}: Received ${i}() call`);let h=n=>a=>{if(o(`${s}: Sending ${i}() reply`),p){o(`${s}: Unable to send ${i}() reply due to destroyed connection`);return}let c={penpal:e.Reply,id:m,resolution:n,returnValue:a};n===t.Rejected&&a instanceof Error&&(c.returnValue=d(a),c.returnValueIsError=!0);try{l.postMessage(c,u)}catch(n){if(n.name===r.DataCloneError){let r={penpal:e.Reply,id:m,resolution:t.Rejected,returnValue:d(n),returnValueIsError:!0};l.postMessage(r,u)}throw n}};new Promise(e=>e(a[i].apply(a,c))).then(h(t.Fulfilled),h(t.Rejected))};return c.addEventListener(i.Message,m),()=>{p=!0,c.removeEventListener(i.Message,m)}},m=0,h=()=>++m,g=(r,a,o,s,c)=>{let{localName:l,local:u,remote:d,originForSending:p,originForReceiving:m}=a,g=!1;c(`${l}: Connecting call sender`);let _=r=>(...a)=>{c(`${l}: Sending ${r}() call`);let o;try{d.closed&&(o=!0)}catch{o=!0}if(o&&s(),g){let e=Error(`Unable to send ${r}() call due to destroyed connection`);throw e.code=n.ConnectionDestroyed,e}return new Promise((n,o)=>{let s=h(),g=a=>{if(a.source!==d||a.data.penpal!==e.Reply||a.data.id!==s)return;if(a.origin!==m){c(`${l} received message from origin ${a.origin} which did not match expected origin ${m}`);return}let p=a.data;c(`${l}: Received ${r}() reply`),u.removeEventListener(i.Message,g);let h=p.returnValue;p.returnValueIsError&&(h=f(h)),(p.resolution===t.Fulfilled?n:o)(h)};u.addEventListener(i.Message,g);let _={penpal:e.Call,id:s,methodName:r,args:a};d.postMessage(_,p)})};return o.reduce((e,t)=>(e[t]=_(t),e),r),()=>{g=!0}},_=(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=p(u,e,i),o(s),c&&c.forEach(e=>{delete l[e]}),c=r.data.methodNames;let d=g(l,u,c,a,i);return o(d),l}},v=(t,n,r,i)=>a=>{if(a.origin!==r){t(`Parent: Handshake - Received SYN message from origin ${a.origin} which did not match expected origin ${r}`);return}t(`Parent: Handshake - Received SYN, responding with SYN-ACK`);let o={penpal:e.SynAck,methodNames:Object.keys(n)};a.source.postMessage(o,i)},y=6e4,b=(e,t)=>{let{destroy:n,onDestroy:r}=t,i=setInterval(()=>{e.isConnected||(clearInterval(i),n())},y);r(()=>{clearInterval(i)})},x=(e,t)=>{let r;return e!==void 0&&(r=window.setTimeout(()=>{let r=Error(`Connection timed out after ${e}ms`);r.code=n.ConnectionTimeout,t(r)},e)),()=>{clearTimeout(r)}},S=e=>{if(!e.src&&!e.srcdoc){let e=Error(`Iframe must have src or srcdoc property defined.`);throw e.code=n.NoIframeSrc,e}},C=t=>{let{iframe:r,methods:s={},childOrigin:c,timeout:l,debug:d=!1}=t,f=o(d),p=a(),{onDestroy:m,destroy:h}=p;c||(S(r),c=u(r.src));let g=c===`null`?`*`:c,y=v(f,s,c,g),C=_(s,c,g,p,f);return{promise:new Promise((t,a)=>{let o=x(l,h),s=n=>{if(n.source===r.contentWindow&&n.data){if(n.data.penpal===e.Syn)y(n);else if(n.data.penpal===e.Ack){let e=C(n);e&&(o(),t(e))}}};window.addEventListener(i.Message,s),f(`Parent: Awaiting handshake`),b(r,p),m(e=>{window.removeEventListener(i.Message,s),e||(e=Error(`Connection destroyed`),e.code=n.ConnectionDestroyed),a(e)})}),destroy(){h()}}},w=window.__A_EMBED_API_VERSION__||`v2_1_1`,T=`${window.__A_VIEWER_URL__||`https://viewer.archilogic.com`}/${w}?embedType=api`;function E(e=document.body){let t=document.createElement(`iframe`);return Object.assign(t,{src:T,width:`100%`,height:`100%`,title:`Archilogic Embed`,frameBorder:`0`,scrolling:`no`,allowTransparency:`true`,allowFullscreen:`true`,style:`border: 0;`}),e.appendChild(t),t}var D=0,O=e=>JSON.parse(JSON.stringify(e)),k=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}({}),A={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}},j=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=O({...A,...t}),this.containerEl=e,this.viewerEl=E(e),this.viewerConnection=C({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(O(e))}on(e,t){return D++,this.listeners.set(D,t),this.viewer.addListener(e,D),D}off(e){return this.viewer.removeListener(e)}async destroy(){return document.removeEventListener(`fullscreenchange`,this.onFullscreenChange),this.viewerConnection.destroy()}};exports.PresentationMode=k,exports.default=j,exports.defaultEmbedOptions=A;
|
package/dist/embed.modern.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 };
|