@chili-publish/studio-sdk 1.44.0 → 1.44.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/_bundles/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(h,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(h=typeof globalThis<"u"?globalThis:h||self,D(h.StudioSDK=h.StudioSDK||{}))})(this,(function(h){"use strict";var rr=h=>{throw TypeError(h)};var ar=(h,D,V)=>D.has(h)||rr("Cannot "+V);var a=(h,D,V)=>(ar(h,D,"read from private field"),V?V.call(h):D.get(h)),g=(h,D,V)=>D.has(h)?rr("Cannot add the same private member more than once"):D instanceof WeakSet?D.add(h):D.set(h,V),y=(h,D,V,pe)=>(ar(h,D,"write to private field"),pe?pe.call(h,V):D.set(h,V),V);var R,M,z,P,kn,ot,U,ct,qt,k,B,Nt,mt,Gn,ft,St,tt,Rt,ht,Yt,dt,bt,G,lt,Mt,E,Vt,l,F,f,Zt,et,Qt,L,Xt,_n,_,vt,Bt,Z,K,te,ut,ee,Tt,se,ne,H,Jt,C,Ut,kt,Hn,Gt,gt,st,re,It,_t,ye,yt,Ht,x,At,ae,Pt,Q;const V={current:"2.27.
|
|
1
|
+
(function(h,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(h=typeof globalThis<"u"?globalThis:h||self,D(h.StudioSDK=h.StudioSDK||{}))})(this,(function(h){"use strict";var rr=h=>{throw TypeError(h)};var ar=(h,D,V)=>D.has(h)||rr("Cannot "+V);var a=(h,D,V)=>(ar(h,D,"read from private field"),V?V.call(h):D.get(h)),g=(h,D,V)=>D.has(h)?rr("Cannot add the same private member more than once"):D instanceof WeakSet?D.add(h):D.set(h,V),y=(h,D,V,pe)=>(ar(h,D,"write to private field"),pe?pe.call(h,V):D.set(h,V),V);var R,M,z,P,kn,ot,U,ct,qt,k,B,Nt,mt,Gn,ft,St,tt,Rt,ht,Yt,dt,bt,G,lt,Mt,E,Vt,l,F,f,Zt,et,Qt,L,Xt,_n,_,vt,Bt,Z,K,te,ut,ee,Tt,se,ne,H,Jt,C,Ut,kt,Hn,Gt,gt,st,re,It,_t,ye,yt,Ht,x,At,ae,Pt,Q;const V={current:"2.27.latest"},De={version:"1.44.1"};var W;(function(s){s.Call="call",s.Reply="reply",s.Syn="syn",s.SynAck="synAck",s.Ack="ack"})(W||(W={}));var pt;(function(s){s.Fulfilled="fulfilled",s.Rejected="rejected"})(pt||(pt={}));var jt;(function(s){s.ConnectionDestroyed="ConnectionDestroyed",s.ConnectionTimeout="ConnectionTimeout",s.NoIframeSrc="NoIframeSrc"})(jt||(jt={}));var we;(function(s){s.DataCloneError="DataCloneError"})(we||(we={}));var at;(function(s){s.Message="message"})(at||(at={}));const ir=(s,o)=>{const e=[];let t=!1;return{destroy(n){t||(t=!0,o(`${s}: Destroying connection`),e.forEach(r=>{r(n)}))},onDestroy(n){t?n():e.push(n)}}},or=s=>(...o)=>{s&&console.log("[Penpal]",...o)},cr={"http:":"80","https:":"443"},hr=/^(https?:)?\/\/([^/:]+)?(:(\d+))?/,dr=["file:","data:"],lr=s=>{if(s&&dr.find(d=>s.startsWith(d)))return"null";const o=document.location,e=hr.exec(s);let t,n,r;e?(t=e[1]?e[1]:o.protocol,n=e[2],r=e[4]):(t=o.protocol,n=o.hostname,r=o.port);const c=r&&r!==cr[t]?`:${r}`:"";return`${t}//${n}${c}`},Oe=({name:s,message:o,stack:e})=>({name:s,message:o,stack:e}),ur=s=>{const o=new Error;return Object.keys(s).forEach(e=>o[e]=s[e]),o},gr=(s,o,e)=>{const{localName:t,local:n,remote:r,originForSending:c,originForReceiving:d}=s;let u=!1;const w=p=>{if(p.source!==r||p.data.penpal!==W.Call)return;if(p.origin!==d){e(`${t} received message from origin ${p.origin} which did not match expected origin ${d}`);return}const v=p.data,{methodName:S,args:I,id:N}=v;e(`${t}: Received ${S}() call`);const O=b=>X=>{if(e(`${t}: Sending ${S}() reply`),u){e(`${t}: Unable to send ${S}() reply due to destroyed connection`);return}const $={penpal:W.Reply,id:N,resolution:b,returnValue:X};b===pt.Rejected&&X instanceof Error&&($.returnValue=Oe(X),$.returnValueIsError=!0);try{r.postMessage($,c)}catch(A){if(A.name===we.DataCloneError){const nt={penpal:W.Reply,id:N,resolution:pt.Rejected,returnValue:Oe(A),returnValueIsError:!0};r.postMessage(nt,c)}throw A}};new Promise(b=>b(o[S].apply(o,I))).then(O(pt.Fulfilled),O(pt.Rejected))};return n.addEventListener(at.Message,w),()=>{u=!0,n.removeEventListener(at.Message,w)}};let yr=0;const pr=()=>++yr,Fe=".",Le=s=>s?s.split(Fe):[],wr=s=>s.join(Fe),Cr=(s,o)=>{const e=Le(o||"");return e.push(s),wr(e)},mr=(s,o,e)=>{const t=Le(o);return t.reduce((n,r,c)=>(typeof n[r]>"u"&&(n[r]={}),c===t.length-1&&(n[r]=e),n[r]),s),s},Ne=(s,o)=>{const e={};return Object.keys(s).forEach(t=>{const n=s[t],r=Cr(t,o);typeof n=="object"&&Object.assign(e,Ne(n,r)),typeof n=="function"&&(e[r]=n)}),e},fr=s=>{const o={};for(const e in s)mr(o,e,s[e]);return o},Sr=(s,o,e,t,n)=>{const{localName:r,local:c,remote:d,originForSending:u,originForReceiving:w}=o;let p=!1;n(`${r}: Connecting call sender`);const v=I=>(...N)=>{n(`${r}: Sending ${I}() call`);let O;try{d.closed&&(O=!0)}catch{O=!0}if(O&&t(),p){const b=new Error(`Unable to send ${I}() call due to destroyed connection`);throw b.code=jt.ConnectionDestroyed,b}return new Promise((b,X)=>{const $=pr(),A=rt=>{if(rt.source!==d||rt.data.penpal!==W.Reply||rt.data.id!==$)return;if(rt.origin!==w){n(`${r} received message from origin ${rt.origin} which did not match expected origin ${w}`);return}const xt=rt.data;n(`${r}: Received ${I}() reply`),c.removeEventListener(at.Message,A);let $t=xt.returnValue;xt.returnValueIsError&&($t=ur($t)),(xt.resolution===pt.Fulfilled?b:X)($t)};c.addEventListener(at.Message,A);const nt={penpal:W.Call,id:$,methodName:I,args:N};d.postMessage(nt,u)})},S=e.reduce((I,N)=>(I[N]=v(N),I),{});return Object.assign(s,fr(S)),()=>{p=!0}},br=(s,o,e,t,n)=>{const{destroy:r,onDestroy:c}=t;let d,u;const w={};return p=>{if(p.origin!==o){n(`Parent: Handshake - Received ACK message from origin ${p.origin} which did not match expected origin ${o}`);return}n("Parent: Handshake - Received ACK");const v={localName:"Parent",local:window,remote:p.source,originForSending:e,originForReceiving:o};d&&d(),d=gr(v,s,n),c(d),u&&u.forEach(I=>{delete w[I]}),u=p.data.methodNames;const S=Sr(w,v,u,r,n);return c(S),w}},vr=(s,o,e,t)=>n=>{if(n.origin!==e){s(`Parent: Handshake - Received SYN message from origin ${n.origin} which did not match expected origin ${e}`);return}s("Parent: Handshake - Received SYN, responding with SYN-ACK");const r={penpal:W.SynAck,methodNames:Object.keys(o)};n.source.postMessage(r,t)},Ir=6e4,Ar=(s,o)=>{const{destroy:e,onDestroy:t}=o,n=setInterval(()=>{s.isConnected||(clearInterval(n),e())},Ir);t(()=>{clearInterval(n)})},Pr=(s,o)=>{let e;return s!==void 0&&(e=window.setTimeout(()=>{const t=new Error(`Connection timed out after ${s}ms`);t.code=jt.ConnectionTimeout,o(t)},s)),()=>{clearTimeout(e)}},Er=s=>{if(!s.src&&!s.srcdoc){const o=new Error("Iframe must have src or srcdoc property defined.");throw o.code=jt.NoIframeSrc,o}},Dr=s=>{let{iframe:o,methods:e={},childOrigin:t,timeout:n,debug:r=!1}=s;const c=or(r),d=ir("Parent",c),{onDestroy:u,destroy:w}=d;t||(Er(o),t=lr(o.src));const p=t==="null"?"*":t,v=Ne(e),S=vr(c,v,t,p),I=br(v,t,p,d,c);return{promise:new Promise((O,b)=>{const X=Pr(n,w),$=A=>{if(!(A.source!==o.contentWindow||!A.data)){if(A.data.penpal===W.Syn){S(A);return}if(A.data.penpal===W.Ack){const nt=I(A);nt&&(X(),O(nt));return}}};window.addEventListener(at.Message,$),c("Parent: Awaiting handshake"),Ar(o,d),u(A=>{window.removeEventListener(at.Message,$),A&&b(A)})}),destroy(){w()}}},Or=s=>{const o=new RegExp(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w]+\/$/);let e="";return o.test(s)?e=s:s.indexOf("/index.html")>-1?e=s.replace("/index.html","/"):s.charAt(-1)!=="/"&&(e=`${s}/`),e},Fr=(s,o,e)=>{const t=Or(o),r=`<html>
|
|
2
2
|
<head>
|
|
3
3
|
<base href="/" />
|
|
4
4
|
<meta charset="UTF-8"/>
|