@iebh/tera-fy 1.0.19 → 1.0.21

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.
@@ -1,5 +1,5 @@
1
- var mr=Object.defineProperty;var ur=(t,e,r)=>e in t?mr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var F=(t,e,r)=>(ur(t,typeof e!="symbol"?e+"":e,r),r);function St(t,e,r){if(!t||typeof t!="object"||!e||typeof e!="object")throw new Error("both arguments must be objects or arrays");r||(r=function(s){return s});function o({obj1:s,obj2:p,basePath:m,basePathForRemoves:w,diffs:h}){var y=Object.keys(s),b=y.length,c=Object.keys(p),L=c.length,g,v=s.length-p.length;if(cr(s,p)){for(var d=0;d<b;d++){var D=Array.isArray(s)?Number(y[d]):y[d];D in p||(g=w.concat(D),h.remove.push({op:"remove",path:r(g)}))}for(var d=0;d<L;d++){var D=Array.isArray(p)?Number(c[d]):c[d];i({key:D,obj1:s,obj2:p,path:m.concat(D),pathForRemoves:m.concat(D),diffs:h})}}else{for(var d=0;d<v;d++)g=w.concat(d),h.remove.push({op:"remove",path:r(g)});for(var lr=s.slice(v),d=0;d<L;d++)i({key:d,obj1:lr,obj2:p,path:m.concat(d),pathForRemoves:m.concat(d+v),diffs:h})}}var a={remove:[],replace:[],add:[]};return o({obj1:t,obj2:e,basePath:[],basePathForRemoves:[],diffs:a}),a.remove.reverse().concat(a.replace).concat(a.add);function i({key:s,obj1:p,obj2:m,path:w,pathForRemoves:h,diffs:y}){var b=p[s],c=m[s];if(!(s in p)&&s in m){var L=c;y.add.push({op:"add",path:r(w),value:L})}else b!==c&&(Object(b)!==b||Object(c)!==c||dr(b,c)||!Object.keys(b).length&&!Object.keys(c).length&&String(b)!=String(c)?f(w,y,c):o({obj1:p[s],obj2:m[s],basePath:w,basePathForRemoves:h,diffs:y}))}function f(s,p,m){p.replace.push({op:"replace",path:r(s),value:m})}}function Pt(t){return[""].concat(t).join("/")}function dr(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function cr(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,i=0;i<e.length&&String(t[i])===String(e[i]);i++)o++;for(var f=e.length;f>0&&String(t[f+r])===String(e[f]);f--)a++;return o>=a}return!0}var xr=typeof global=="object"&&global&&global.Object===Object&&global,Z=xr;var hr=typeof self=="object"&&self&&self.Object===Object&&self,gr=Z||hr||Function("return this")(),u=gr;var yr=u.Symbol,A=yr;var It=Object.prototype,br=It.hasOwnProperty,vr=It.toString,J=A?A.toStringTag:void 0;function wr(t){var e=br.call(t,J),r=t[J];try{t[J]=void 0;var o=!0}catch{}var a=vr.call(t);return o&&(e?t[J]=r:delete t[J]),a}var Ct=wr;var jr=Object.prototype,Tr=jr.toString;function Ar(t){return Tr.call(t)}var Et=Ar;var Or="[object Null]",_r="[object Undefined]",Mt=A?A.toStringTag:void 0;function Sr(t){return t==null?t===void 0?_r:Or:Mt&&Mt in Object(t)?Ct(t):Et(t)}var O=Sr;function Pr(t){return t!=null&&typeof t=="object"}var j=Pr;var Ir=Array.isArray,k=Ir;function Cr(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var T=Cr;var Er="[object AsyncFunction]",Mr="[object Function]",Rr="[object GeneratorFunction]",Lr="[object Proxy]";function Fr(t){if(!T(t))return!1;var e=O(t);return e==Mr||e==Rr||e==Er||e==Lr}var Q=Fr;var Br=u["__core-js_shared__"],tt=Br;var Rt=function(){var t=/[^.]+$/.exec(tt&&tt.keys&&tt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Dr(t){return!!Rt&&Rt in t}var Lt=Dr;var kr=Function.prototype,Ur=kr.toString;function Nr(t){if(t!=null){try{return Ur.call(t)}catch{}try{return t+""}catch{}}return""}var _=Nr;var Wr=/[\\^$.*+?()[\]{}|]/g,Gr=/^\[object .+?Constructor\]$/,Kr=Function.prototype,zr=Object.prototype,Hr=Kr.toString,Vr=zr.hasOwnProperty,qr=RegExp("^"+Hr.call(Vr).replace(Wr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function $r(t){if(!T(t)||Lt(t))return!1;var e=Q(t)?qr:Gr;return e.test(_(t))}var Ft=$r;function Yr(t,e){return t==null?void 0:t[e]}var Bt=Yr;function Jr(t,e){var r=Bt(t,e);return Ft(r)?r:void 0}var x=Jr;var Xr=x(u,"WeakMap"),et=Xr;var Dt=Object.create,Zr=function(){function t(){}return function(e){if(!T(e))return{};if(Dt)return Dt(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),kt=Zr;function Qr(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var Ut=Qr;var to=function(){try{var t=x(Object,"defineProperty");return t({},"",{}),t}catch{}}(),bt=to;function eo(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var Nt=eo;var ro=9007199254740991,oo=/^(?:0|[1-9]\d*)$/;function ao(t,e){var r=typeof t;return e=e==null?ro:e,!!e&&(r=="number"||r!="symbol"&&oo.test(t))&&t>-1&&t%1==0&&t<e}var Wt=ao;function so(t,e,r){e=="__proto__"&&bt?bt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var rt=so;function fo(t,e){return t===e||t!==t&&e!==e}var ot=fo;var io=Object.prototype,no=io.hasOwnProperty;function po(t,e,r){var o=t[e];(!(no.call(t,e)&&ot(o,r))||r===void 0&&!(e in t))&&rt(t,e,r)}var at=po;function lo(t,e,r,o){var a=!r;r||(r={});for(var i=-1,f=e.length;++i<f;){var s=e[i],p=o?o(r[s],t[s],s,r,t):void 0;p===void 0&&(p=t[s]),a?rt(r,s,p):at(r,s,p)}return r}var I=lo;var mo=9007199254740991;function uo(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=mo}var st=uo;function co(t){return t!=null&&st(t.length)&&!Q(t)}var ft=co;var xo=Object.prototype;function ho(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||xo;return t===r}var U=ho;function go(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var Gt=go;var yo="[object Arguments]";function bo(t){return j(t)&&O(t)==yo}var vt=bo;var Kt=Object.prototype,vo=Kt.hasOwnProperty,wo=Kt.propertyIsEnumerable,jo=vt(function(){return arguments}())?vt:function(t){return j(t)&&vo.call(t,"callee")&&!wo.call(t,"callee")},zt=jo;function To(){return!1}var Ht=To;var $t=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Vt=$t&&typeof module=="object"&&module&&!module.nodeType&&module,Ao=Vt&&Vt.exports===$t,qt=Ao?u.Buffer:void 0,Oo=qt?qt.isBuffer:void 0,_o=Oo||Ht,it=_o;var So="[object Arguments]",Po="[object Array]",Io="[object Boolean]",Co="[object Date]",Eo="[object Error]",Mo="[object Function]",Ro="[object Map]",Lo="[object Number]",Fo="[object Object]",Bo="[object RegExp]",Do="[object Set]",ko="[object String]",Uo="[object WeakMap]",No="[object ArrayBuffer]",Wo="[object DataView]",Go="[object Float32Array]",Ko="[object Float64Array]",zo="[object Int8Array]",Ho="[object Int16Array]",Vo="[object Int32Array]",qo="[object Uint8Array]",$o="[object Uint8ClampedArray]",Yo="[object Uint16Array]",Jo="[object Uint32Array]",l={};l[Go]=l[Ko]=l[zo]=l[Ho]=l[Vo]=l[qo]=l[$o]=l[Yo]=l[Jo]=!0;l[So]=l[Po]=l[No]=l[Io]=l[Wo]=l[Co]=l[Eo]=l[Mo]=l[Ro]=l[Lo]=l[Fo]=l[Bo]=l[Do]=l[ko]=l[Uo]=!1;function Xo(t){return j(t)&&st(t.length)&&!!l[O(t)]}var Yt=Xo;function Zo(t){return function(e){return t(e)}}var N=Zo;var Jt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,X=Jt&&typeof module=="object"&&module&&!module.nodeType&&module,Qo=X&&X.exports===Jt,wt=Qo&&Z.process,ta=function(){try{var t=X&&X.require&&X.require("util").types;return t||wt&&wt.binding&&wt.binding("util")}catch{}}(),S=ta;var Xt=S&&S.isTypedArray,ea=Xt?N(Xt):Yt,Zt=ea;var ra=Object.prototype,oa=ra.hasOwnProperty;function aa(t,e){var r=k(t),o=!r&&zt(t),a=!r&&!o&&it(t),i=!r&&!o&&!a&&Zt(t),f=r||o||a||i,s=f?Gt(t.length,String):[],p=s.length;for(var m in t)(e||oa.call(t,m))&&!(f&&(m=="length"||a&&(m=="offset"||m=="parent")||i&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||Wt(m,p)))&&s.push(m);return s}var nt=aa;function sa(t,e){return function(r){return t(e(r))}}var pt=sa;var fa=pt(Object.keys,Object),Qt=fa;var ia=Object.prototype,na=ia.hasOwnProperty;function pa(t){if(!U(t))return Qt(t);var e=[];for(var r in Object(t))na.call(t,r)&&r!="constructor"&&e.push(r);return e}var te=pa;function la(t){return ft(t)?nt(t):te(t)}var W=la;function ma(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var ee=ma;var ua=Object.prototype,da=ua.hasOwnProperty;function ca(t){if(!T(t))return ee(t);var e=U(t),r=[];for(var o in t)o=="constructor"&&(e||!da.call(t,o))||r.push(o);return r}var re=ca;function xa(t){return ft(t)?nt(t,!0):re(t)}var G=xa;var ha=x(Object,"create"),P=ha;function ga(){this.__data__=P?P(null):{},this.size=0}var oe=ga;function ya(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var ae=ya;var ba="__lodash_hash_undefined__",va=Object.prototype,wa=va.hasOwnProperty;function ja(t){var e=this.__data__;if(P){var r=e[t];return r===ba?void 0:r}return wa.call(e,t)?e[t]:void 0}var se=ja;var Ta=Object.prototype,Aa=Ta.hasOwnProperty;function Oa(t){var e=this.__data__;return P?e[t]!==void 0:Aa.call(e,t)}var fe=Oa;var _a="__lodash_hash_undefined__";function Sa(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=P&&e===void 0?_a:e,this}var ie=Sa;function K(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}K.prototype.clear=oe;K.prototype.delete=ae;K.prototype.get=se;K.prototype.has=fe;K.prototype.set=ie;var jt=K;function Pa(){this.__data__=[],this.size=0}var ne=Pa;function Ia(t,e){for(var r=t.length;r--;)if(ot(t[r][0],e))return r;return-1}var C=Ia;var Ca=Array.prototype,Ea=Ca.splice;function Ma(t){var e=this.__data__,r=C(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Ea.call(e,r,1),--this.size,!0}var pe=Ma;function Ra(t){var e=this.__data__,r=C(e,t);return r<0?void 0:e[r][1]}var le=Ra;function La(t){return C(this.__data__,t)>-1}var me=La;function Fa(t,e){var r=this.__data__,o=C(r,t);return o<0?(++this.size,r.push([t,e])):r[o][1]=e,this}var ue=Fa;function z(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}z.prototype.clear=ne;z.prototype.delete=pe;z.prototype.get=le;z.prototype.has=me;z.prototype.set=ue;var E=z;var Ba=x(u,"Map"),M=Ba;function Da(){this.size=0,this.__data__={hash:new jt,map:new(M||E),string:new jt}}var de=Da;function ka(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var ce=ka;function Ua(t,e){var r=t.__data__;return ce(e)?r[typeof e=="string"?"string":"hash"]:r.map}var R=Ua;function Na(t){var e=R(this,t).delete(t);return this.size-=e?1:0,e}var xe=Na;function Wa(t){return R(this,t).get(t)}var he=Wa;function Ga(t){return R(this,t).has(t)}var ge=Ga;function Ka(t,e){var r=R(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var ye=Ka;function H(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}H.prototype.clear=de;H.prototype.delete=xe;H.prototype.get=he;H.prototype.has=ge;H.prototype.set=ye;var be=H;function za(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var lt=za;var Ha=pt(Object.getPrototypeOf,Object),mt=Ha;function Va(){this.__data__=new E,this.size=0}var ve=Va;function qa(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var we=qa;function $a(t){return this.__data__.get(t)}var je=$a;function Ya(t){return this.__data__.has(t)}var Te=Ya;var Ja=200;function Xa(t,e){var r=this.__data__;if(r instanceof E){var o=r.__data__;if(!M||o.length<Ja-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new be(o)}return r.set(t,e),this.size=r.size,this}var Ae=Xa;function V(t){var e=this.__data__=new E(t);this.size=e.size}V.prototype.clear=ve;V.prototype.delete=we;V.prototype.get=je;V.prototype.has=Te;V.prototype.set=Ae;var Oe=V;function Za(t,e){return t&&I(e,W(e),t)}var _e=Za;function Qa(t,e){return t&&I(e,G(e),t)}var Se=Qa;var Ee=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Pe=Ee&&typeof module=="object"&&module&&!module.nodeType&&module,ts=Pe&&Pe.exports===Ee,Ie=ts?u.Buffer:void 0,Ce=Ie?Ie.allocUnsafe:void 0;function es(t,e){if(e)return t.slice();var r=t.length,o=Ce?Ce(r):new t.constructor(r);return t.copy(o),o}var Me=es;function rs(t,e){for(var r=-1,o=t==null?0:t.length,a=0,i=[];++r<o;){var f=t[r];e(f,r,t)&&(i[a++]=f)}return i}var Re=rs;function os(){return[]}var ut=os;var as=Object.prototype,ss=as.propertyIsEnumerable,Le=Object.getOwnPropertySymbols,fs=Le?function(t){return t==null?[]:(t=Object(t),Re(Le(t),function(e){return ss.call(t,e)}))}:ut,q=fs;function is(t,e){return I(t,q(t),e)}var Fe=is;var ns=Object.getOwnPropertySymbols,ps=ns?function(t){for(var e=[];t;)lt(e,q(t)),t=mt(t);return e}:ut,dt=ps;function ls(t,e){return I(t,dt(t),e)}var Be=ls;function ms(t,e,r){var o=e(t);return k(t)?o:lt(o,r(t))}var ct=ms;function us(t){return ct(t,W,q)}var De=us;function ds(t){return ct(t,G,dt)}var ke=ds;var cs=x(u,"DataView"),xt=cs;var xs=x(u,"Promise"),ht=xs;var hs=x(u,"Set"),gt=hs;var Ue="[object Map]",gs="[object Object]",Ne="[object Promise]",We="[object Set]",Ge="[object WeakMap]",Ke="[object DataView]",ys=_(xt),bs=_(M),vs=_(ht),ws=_(gt),js=_(et),B=O;(xt&&B(new xt(new ArrayBuffer(1)))!=Ke||M&&B(new M)!=Ue||ht&&B(ht.resolve())!=Ne||gt&&B(new gt)!=We||et&&B(new et)!=Ge)&&(B=function(t){var e=O(t),r=e==gs?t.constructor:void 0,o=r?_(r):"";if(o)switch(o){case ys:return Ke;case bs:return Ue;case vs:return Ne;case ws:return We;case js:return Ge}return e});var $=B;var Ts=Object.prototype,As=Ts.hasOwnProperty;function Os(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&As.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var ze=Os;var _s=u.Uint8Array,Tt=_s;function Ss(t){var e=new t.constructor(t.byteLength);return new Tt(e).set(new Tt(t)),e}var Y=Ss;function Ps(t,e){var r=e?Y(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var He=Ps;var Is=/\w*$/;function Cs(t){var e=new t.constructor(t.source,Is.exec(t));return e.lastIndex=t.lastIndex,e}var Ve=Cs;var qe=A?A.prototype:void 0,$e=qe?qe.valueOf:void 0;function Es(t){return $e?Object($e.call(t)):{}}var Ye=Es;function Ms(t,e){var r=e?Y(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var Je=Ms;var Rs="[object Boolean]",Ls="[object Date]",Fs="[object Map]",Bs="[object Number]",Ds="[object RegExp]",ks="[object Set]",Us="[object String]",Ns="[object Symbol]",Ws="[object ArrayBuffer]",Gs="[object DataView]",Ks="[object Float32Array]",zs="[object Float64Array]",Hs="[object Int8Array]",Vs="[object Int16Array]",qs="[object Int32Array]",$s="[object Uint8Array]",Ys="[object Uint8ClampedArray]",Js="[object Uint16Array]",Xs="[object Uint32Array]";function Zs(t,e,r){var o=t.constructor;switch(e){case Ws:return Y(t);case Rs:case Ls:return new o(+t);case Gs:return He(t,r);case Ks:case zs:case Hs:case Vs:case qs:case $s:case Ys:case Js:case Xs:return Je(t,r);case Fs:return new o;case Bs:case Us:return new o(t);case Ds:return Ve(t);case ks:return new o;case Ns:return Ye(t)}}var Xe=Zs;function Qs(t){return typeof t.constructor=="function"&&!U(t)?kt(mt(t)):{}}var Ze=Qs;var tf="[object Map]";function ef(t){return j(t)&&$(t)==tf}var Qe=ef;var tr=S&&S.isMap,rf=tr?N(tr):Qe,er=rf;var of="[object Set]";function af(t){return j(t)&&$(t)==of}var rr=af;var or=S&&S.isSet,sf=or?N(or):rr,ar=sf;var ff=1,nf=2,pf=4,sr="[object Arguments]",lf="[object Array]",mf="[object Boolean]",uf="[object Date]",df="[object Error]",fr="[object Function]",cf="[object GeneratorFunction]",xf="[object Map]",hf="[object Number]",ir="[object Object]",gf="[object RegExp]",yf="[object Set]",bf="[object String]",vf="[object Symbol]",wf="[object WeakMap]",jf="[object ArrayBuffer]",Tf="[object DataView]",Af="[object Float32Array]",Of="[object Float64Array]",_f="[object Int8Array]",Sf="[object Int16Array]",Pf="[object Int32Array]",If="[object Uint8Array]",Cf="[object Uint8ClampedArray]",Ef="[object Uint16Array]",Mf="[object Uint32Array]",n={};n[sr]=n[lf]=n[jf]=n[Tf]=n[mf]=n[uf]=n[Af]=n[Of]=n[_f]=n[Sf]=n[Pf]=n[xf]=n[hf]=n[ir]=n[gf]=n[yf]=n[bf]=n[vf]=n[If]=n[Cf]=n[Ef]=n[Mf]=!0;n[df]=n[fr]=n[wf]=!1;function yt(t,e,r,o,a,i){var f,s=e&ff,p=e&nf,m=e&pf;if(r&&(f=a?r(t,o,a,i):r(t)),f!==void 0)return f;if(!T(t))return t;var w=k(t);if(w){if(f=ze(t),!s)return Ut(t,f)}else{var h=$(t),y=h==fr||h==cf;if(it(t))return Me(t,s);if(h==ir||h==sr||y&&!a){if(f=p||y?{}:Ze(t),!s)return p?Be(t,Se(f,t)):Fe(t,_e(f,t))}else{if(!n[h])return a?t:{};f=Xe(t,h,s)}}i||(i=new Oe);var b=i.get(t);if(b)return b;i.set(t,f),ar(t)?t.forEach(function(g){f.add(yt(g,e,r,g,t,i))}):er(t)&&t.forEach(function(g,v){f.set(v,yt(g,e,r,v,t,i))});var c=m?p?ke:De:p?G:W,L=w?void 0:c(t);return Nt(L||t,function(g,v){L&&(v=g,g=t[v]),at(f,v,yt(g,e,r,v,t,i))}),f}var nr=yt;var Rf=1,Lf=4;function Ff(t){return nr(t,Rf|Lf)}var At=Ff;function pr(t){return{all:t=t||new Map,on:function(e,r){var o=t.get(e);o?o.push(r):t.set(e,[r])},off:function(e,r){var o=t.get(e);o&&(r?o.splice(o.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var o=t.get(e);o&&o.slice().map(function(a){a(r)}),(o=t.get("*"))&&o.slice().map(function(a){a(e,r)})}}}var Ot=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((e,r)=>(r&=63,r<36?e+=r.toString(36):r<62?e+=(r-26).toString(36).toUpperCase():r>62?e+="-":e+="_",e),"");var _t=class{constructor(e){F(this,"settings",{devMode:!0,mode:"detect",modeTimeout:300,modeFallback:"child",siteUrl:"https://tera-tools.com/embed",restrictOrigin:"*",frameSandbox:["allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-top-navigation"],handshakeInterval:1e3});F(this,"events",pr());F(this,"dom",{el:null,iframe:null,popup:null,stylesheet:null});F(this,"methods",["handshake","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","saveProjectState","replaceProjectState","applyProjectStatePatch","selectProjectFile","getProjectFiles","selectProjectLibrary","parseProjectLibrary","setProjectLibrary","uiAlert","uiSplat","uiWindow"]);F(this,"plugins",[]);F(this,"acceptPostboxes",{});e&&this.set(e)}send(e){let r=Ot();return this.acceptPostboxes[r]={},this.acceptPostboxes[r].promise=new Promise((o,a)=>{Object.assign(this.acceptPostboxes[r],{resolve:o,reject:a}),this.sendRaw({id:r,...e})}),this.acceptPostboxes[r].promise}sendRaw(e){let r;try{if(r={TERA:1,id:e.id||Ot(),...At(e)},this.settings.mode=="parent")window.parent.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="child")this.dom.iframe.contentWindow.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="popup")this.dom.popup.postMessage(r,this.settings.restrictOrigin);else throw this.settings.mode=="detect"?new Error("Call init() or detectMode() before trying to send data to determine the mode"):new Error(`Unknown TERA communication mode "${this.settings.mode}"`)}catch(o){throw this.debug("ERROR","Message compose client->server:",o),this.debug("ERROR","Attempted to dispatch payload client->server",r),o}}rpc(e,...r){return this.send({action:"rpc",method:e,args:r})}acceptMessage(e){if(e.origin==window.location.origin)return;let r=e.data;if(!(!r.TERA||!r.id))if(this.debug("Recieved",r),(r==null?void 0:r.action)=="response"&&this.acceptPostboxes[r.id])r.isError===!0?this.acceptPostboxes[r.id].reject(r.response):this.acceptPostboxes[r.id].resolve(r.response);else{if((r==null?void 0:r.action)=="rpc")return Promise.resolve().then(()=>this[r.method].apply(this,r.args)).then(o=>this.sendRaw({id:r.id,action:"response",response:o})).catch(o=>{console.warn(`TERA-FY client threw on RPC:${r.method}:`,o),this.sendRaw({id:r.id,action:"response",isError:!0,response:o.toString()})});if((r==null?void 0:r.action)=="event")return Promise.resolve().then(()=>this.events.emit(r.event,...r.payload)).catch(o=>{throw console.warn(`TERA-FY client threw while handling emitted event "${r.event}"`,{message:r}),o});r!=null&&r.id?this.debug(`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("Unexpected incoming TERA-FY CLIENT message",{message:r})}}createProjectStatePatch(e,r){let o=St(r,e,Pt);return this.debug("INFO","Created project patch",{newState:e,oldState:r}),this.applyProjectStatePatch(o)}applyProjectStatePatchLocal(e){throw new Error("applyProjectStatePatchLocal() has not been sub-classed by a plugin")}init(e){if(e&&this.set(e),this.init.promise)return this.init.promise;window.addEventListener("message",this.acceptMessage.bind(this));let r=this;return this.init.promise=Promise.resolve().then(()=>this.detectMode()).then(o=>this.settings.mode=o).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>this.rpc("setServerMode",this.settings.mode=="child"?"embedded":this.settings.mode=="parent"?"frame":this.settings.mode=="popup"?"popup":(()=>{throw`Unknown server mode "${this.settings.mode}"`})())).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings))))}detectMode(){return this.settings.mode!="detect"?this.settings.mode:window.self===window.parent?this.settings.modeFallback:Promise.resolve().then(()=>this.settings.mode="parent").then(()=>new Promise((e,r)=>{let o=setTimeout(()=>r(),this.settings.modeTimeout);this.rpc("handshake").then(()=>clearTimeout(o)).then(()=>e())})).then(()=>"parent").catch(()=>this.settings.modeFallback)}injectComms(){return new Promise(e=>{switch(this.settings.mode){case"child":this.debug("Injecting TERA site as iFrame child"),this.dom.el=document.createElement("div"),this.dom.el.id="tera-fy",this.dom.el.classList.toggle("dev-mode",this.settings.devMode),document.body.append(this.dom.el),this.dom.iframe=document.createElement("iframe"),this.dom.iframe.setAttribute("sandbox",this.settings.frameSandbox.join(" ")),this.dom.iframe.addEventListener("load",()=>{this.debug("Embed frame ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("Using TERA window parent"),e();break;case"popup":this.debug("Injecting TERA site as a popup window"),this.dom.popup=window.open(this.settings.siteUrl,"_blank","popup=1, location=0, menubar=0, status=0, scrollbars=0, width=500, height=600"),(()=>{let r=0,o,a=()=>{this.debug("Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("Popup window accepted handshake"),e()})};a()})();break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when calling injectComms()`)}})}injectStylesheet(){switch(this.settings.mode){case"child":this.dom.stylesheet=document.createElement("style"),this.dom.stylesheet.innerHTML=[":root {","--TERA-accent: #4d659c;","}","#tera-fy {","display: none;","position: fixed;","right: 50px;","bottom: 50px;","width: 300px;","height: 150px;","background: transparent;","&.dev-mode {","display: flex;","border: 5px solid var(--TERA-accent);","background: #FFF;","}","& > iframe {","width: 100%;","height: 100%;","}","}","body.tera-fy-focus {","overflow: hidden;","& #tera-fy {","display: flex !important;","position: fixed !important;","top: 0px !important;","width: 100vw !important;","height: 100vh !important;","left: 0px !important;","z-index: 10000 !important;","}","}"].join(`
2
- `),document.head.appendChild(this.dom.stylesheet);break;case"parent":case"popup":break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when injectStylesheet()`)}}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){let r="log";typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),!(["INFO","LOG"].includes(r)&&!this.settings.devMode)&&console[r]("%c[TERA-FY CLIENT]","font-weight: bold; color: #ff5722;",...e)}set(e,r){return typeof e=="string"?this.settings[e]=r:Object.assign(this.settings,e),this.toggleDevMode(this.settings.devMode)}setIfDev(e,r){return!this.settings.devMode||r===void 0?this:this.set(e,r)}use(e,r){if(typeof e!="function")throw new Error("Expected use() call to be provided with a class initalizer");let o=new e(this,r);return this.mixin(this,o),this.plugins.push(o),this}mixin(e,r){Object.getOwnPropertyNames(Object.getPrototypeOf(r)).filter(o=>!["constructor","prototype","name"].includes(o)).filter(o=>o!="init").forEach(o=>{Object.defineProperty(e,o,{value:r[o].bind(e),enumerable:!1})})}toggleDevMode(e="toggle"){return this.settings.devMode=e==="toggle"?!this.settings.devMode:e,this.dom.el&&this.dom.el.classList.toggle("dev-mode",this.settings.devMode),this}toggleFocus(e="toggle"){this.debug("Request focus",{isFocused:e}),globalThis.document.body.classList.toggle("tera-fy-focus",e==="toggle"?void 0:e)}};export{_t as default};
1
+ var Er=Object.defineProperty;var Cr=(t,e,r)=>e in t?Er(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var h=(t,e,r)=>(Cr(t,typeof e!="symbol"?e+"":e,r),r);function Ut(t,e,r){if(!t||typeof t!="object"||!e||typeof e!="object")throw new Error("both arguments must be objects or arrays");r||(r=function(s){return s});function o({obj1:s,obj2:l,basePath:c,basePathForRemoves:x,diffs:v}){var T=Object.keys(s),w=T.length,b=Object.keys(l),P=b.length,y,i=s.length-l.length;if(Rr(s,l)){for(var m=0;m<w;m++){var f=Array.isArray(s)?Number(T[m]):T[m];f in l||(y=x.concat(f),v.remove.push({op:"remove",path:r(y)}))}for(var m=0;m<P;m++){var f=Array.isArray(l)?Number(b[m]):b[m];p({key:f,obj1:s,obj2:l,path:c.concat(f),pathForRemoves:c.concat(f),diffs:v})}}else{for(var m=0;m<i;m++)y=x.concat(m),v.remove.push({op:"remove",path:r(y)});for(var S=s.slice(i),m=0;m<P;m++)p({key:m,obj1:S,obj2:l,path:c.concat(m),pathForRemoves:c.concat(m+i),diffs:v})}}var a={remove:[],replace:[],add:[]};return o({obj1:t,obj2:e,basePath:[],basePathForRemoves:[],diffs:a}),a.remove.reverse().concat(a.replace).concat(a.add);function p({key:s,obj1:l,obj2:c,path:x,pathForRemoves:v,diffs:T}){var w=l[s],b=c[s];if(!(s in l)&&s in c){var P=b;T.add.push({op:"add",path:r(x),value:P})}else w!==b&&(Object(w)!==w||Object(b)!==b||Mr(w,b)||!Object.keys(w).length&&!Object.keys(b).length&&String(w)!=String(b)?n(x,T,b):o({obj1:l[s],obj2:c[s],basePath:x,basePathForRemoves:v,diffs:T}))}function n(s,l,c){l.replace.push({op:"replace",path:r(s),value:c})}}function Gt(t){return[""].concat(t).join("/")}function Mr(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function Rr(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,p=0;p<e.length&&String(t[p])===String(e[p]);p++)o++;for(var n=e.length;n>0&&String(t[n+r])===String(e[n]);n--)a++;return o>=a}return!0}var Br=typeof global=="object"&&global&&global.Object===Object&&global,ot=Br;var Lr=typeof self=="object"&&self&&self.Object===Object&&self,Fr=ot||Lr||Function("return this")(),g=Fr;var Nr=g.Symbol,_=Nr;var Kt=Object.prototype,Dr=Kt.hasOwnProperty,kr=Kt.toString,tt=_?_.toStringTag:void 0;function Ur(t){var e=Dr.call(t,tt),r=t[tt];try{t[tt]=void 0;var o=!0}catch{}var a=kr.call(t);return o&&(e?t[tt]=r:delete t[tt]),a}var Wt=Ur;var Gr=Object.prototype,Kr=Gr.toString;function Wr(t){return Kr.call(t)}var zt=Wr;var zr="[object Null]",Vr="[object Undefined]",Vt=_?_.toStringTag:void 0;function qr(t){return t==null?t===void 0?Vr:zr:Vt&&Vt in Object(t)?Wt(t):zt(t)}var I=qr;function Hr(t){return t!=null&&typeof t=="object"}var A=Hr;var $r=Array.isArray,U=$r;function Yr(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var O=Yr;var Zr="[object AsyncFunction]",Jr="[object Function]",Xr="[object GeneratorFunction]",Qr="[object Proxy]";function to(t){if(!O(t))return!1;var e=I(t);return e==Jr||e==Xr||e==Zr||e==Qr}var at=to;var eo=g["__core-js_shared__"],st=eo;var qt=function(){var t=/[^.]+$/.exec(st&&st.keys&&st.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function ro(t){return!!qt&&qt in t}var Ht=ro;var oo=Function.prototype,ao=oo.toString;function so(t){if(t!=null){try{return ao.call(t)}catch{}try{return t+""}catch{}}return""}var E=so;var io=/[\\^$.*+?()[\]{}|]/g,fo=/^\[object .+?Constructor\]$/,no=Function.prototype,po=Object.prototype,lo=no.toString,mo=po.hasOwnProperty,uo=RegExp("^"+lo.call(mo).replace(io,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function co(t){if(!O(t)||Ht(t))return!1;var e=at(t)?uo:fo;return e.test(E(t))}var $t=co;function ho(t,e){return t==null?void 0:t[e]}var Yt=ho;function xo(t,e){var r=Yt(t,e);return $t(r)?r:void 0}var j=xo;var go=j(g,"WeakMap"),it=go;var Zt=Object.create,bo=function(){function t(){}return function(e){if(!O(e))return{};if(Zt)return Zt(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Jt=bo;function yo(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var Xt=yo;var vo=function(){try{var t=j(Object,"defineProperty");return t({},"",{}),t}catch{}}(),Ot=vo;function wo(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var Qt=wo;var jo=9007199254740991,To=/^(?:0|[1-9]\d*)$/;function Ao(t,e){var r=typeof t;return e=e==null?jo:e,!!e&&(r=="number"||r!="symbol"&&To.test(t))&&t>-1&&t%1==0&&t<e}var te=Ao;function Oo(t,e,r){e=="__proto__"&&Ot?Ot(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var ft=Oo;function Po(t,e){return t===e||t!==t&&e!==e}var nt=Po;var So=Object.prototype,_o=So.hasOwnProperty;function Io(t,e,r){var o=t[e];(!(_o.call(t,e)&&nt(o,r))||r===void 0&&!(e in t))&&ft(t,e,r)}var pt=Io;function Eo(t,e,r,o){var a=!r;r||(r={});for(var p=-1,n=e.length;++p<n;){var s=e[p],l=o?o(r[s],t[s],s,r,t):void 0;l===void 0&&(l=t[s]),a?ft(r,s,l):pt(r,s,l)}return r}var R=Eo;var Co=9007199254740991;function Mo(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Co}var lt=Mo;function Ro(t){return t!=null&&lt(t.length)&&!at(t)}var mt=Ro;var Bo=Object.prototype;function Lo(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Bo;return t===r}var G=Lo;function Fo(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var ee=Fo;var No="[object Arguments]";function Do(t){return A(t)&&I(t)==No}var Pt=Do;var re=Object.prototype,ko=re.hasOwnProperty,Uo=re.propertyIsEnumerable,Go=Pt(function(){return arguments}())?Pt:function(t){return A(t)&&ko.call(t,"callee")&&!Uo.call(t,"callee")},oe=Go;function Ko(){return!1}var ae=Ko;var fe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,se=fe&&typeof module=="object"&&module&&!module.nodeType&&module,Wo=se&&se.exports===fe,ie=Wo?g.Buffer:void 0,zo=ie?ie.isBuffer:void 0,Vo=zo||ae,ut=Vo;var qo="[object Arguments]",Ho="[object Array]",$o="[object Boolean]",Yo="[object Date]",Zo="[object Error]",Jo="[object Function]",Xo="[object Map]",Qo="[object Number]",ta="[object Object]",ea="[object RegExp]",ra="[object Set]",oa="[object String]",aa="[object WeakMap]",sa="[object ArrayBuffer]",ia="[object DataView]",fa="[object Float32Array]",na="[object Float64Array]",pa="[object Int8Array]",la="[object Int16Array]",ma="[object Int32Array]",ua="[object Uint8Array]",da="[object Uint8ClampedArray]",ca="[object Uint16Array]",ha="[object Uint32Array]",d={};d[fa]=d[na]=d[pa]=d[la]=d[ma]=d[ua]=d[da]=d[ca]=d[ha]=!0;d[qo]=d[Ho]=d[sa]=d[$o]=d[ia]=d[Yo]=d[Zo]=d[Jo]=d[Xo]=d[Qo]=d[ta]=d[ea]=d[ra]=d[oa]=d[aa]=!1;function xa(t){return A(t)&&lt(t.length)&&!!d[I(t)]}var ne=xa;function ga(t){return function(e){return t(e)}}var K=ga;var pe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,et=pe&&typeof module=="object"&&module&&!module.nodeType&&module,ba=et&&et.exports===pe,St=ba&&ot.process,ya=function(){try{var t=et&&et.require&&et.require("util").types;return t||St&&St.binding&&St.binding("util")}catch{}}(),C=ya;var le=C&&C.isTypedArray,va=le?K(le):ne,me=va;var wa=Object.prototype,ja=wa.hasOwnProperty;function Ta(t,e){var r=U(t),o=!r&&oe(t),a=!r&&!o&&ut(t),p=!r&&!o&&!a&&me(t),n=r||o||a||p,s=n?ee(t.length,String):[],l=s.length;for(var c in t)(e||ja.call(t,c))&&!(n&&(c=="length"||a&&(c=="offset"||c=="parent")||p&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||te(c,l)))&&s.push(c);return s}var dt=Ta;function Aa(t,e){return function(r){return t(e(r))}}var ct=Aa;var Oa=ct(Object.keys,Object),ue=Oa;var Pa=Object.prototype,Sa=Pa.hasOwnProperty;function _a(t){if(!G(t))return ue(t);var e=[];for(var r in Object(t))Sa.call(t,r)&&r!="constructor"&&e.push(r);return e}var de=_a;function Ia(t){return mt(t)?dt(t):de(t)}var W=Ia;function Ea(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var ce=Ea;var Ca=Object.prototype,Ma=Ca.hasOwnProperty;function Ra(t){if(!O(t))return ce(t);var e=G(t),r=[];for(var o in t)o=="constructor"&&(e||!Ma.call(t,o))||r.push(o);return r}var he=Ra;function Ba(t){return mt(t)?dt(t,!0):he(t)}var z=Ba;var La=j(Object,"create"),M=La;function Fa(){this.__data__=M?M(null):{},this.size=0}var xe=Fa;function Na(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var ge=Na;var Da="__lodash_hash_undefined__",ka=Object.prototype,Ua=ka.hasOwnProperty;function Ga(t){var e=this.__data__;if(M){var r=e[t];return r===Da?void 0:r}return Ua.call(e,t)?e[t]:void 0}var be=Ga;var Ka=Object.prototype,Wa=Ka.hasOwnProperty;function za(t){var e=this.__data__;return M?e[t]!==void 0:Wa.call(e,t)}var ye=za;var Va="__lodash_hash_undefined__";function qa(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=M&&e===void 0?Va:e,this}var ve=qa;function V(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}V.prototype.clear=xe;V.prototype.delete=ge;V.prototype.get=be;V.prototype.has=ye;V.prototype.set=ve;var _t=V;function Ha(){this.__data__=[],this.size=0}var we=Ha;function $a(t,e){for(var r=t.length;r--;)if(nt(t[r][0],e))return r;return-1}var B=$a;var Ya=Array.prototype,Za=Ya.splice;function Ja(t){var e=this.__data__,r=B(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Za.call(e,r,1),--this.size,!0}var je=Ja;function Xa(t){var e=this.__data__,r=B(e,t);return r<0?void 0:e[r][1]}var Te=Xa;function Qa(t){return B(this.__data__,t)>-1}var Ae=Qa;function ts(t,e){var r=this.__data__,o=B(r,t);return o<0?(++this.size,r.push([t,e])):r[o][1]=e,this}var Oe=ts;function q(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}q.prototype.clear=we;q.prototype.delete=je;q.prototype.get=Te;q.prototype.has=Ae;q.prototype.set=Oe;var L=q;var es=j(g,"Map"),F=es;function rs(){this.size=0,this.__data__={hash:new _t,map:new(F||L),string:new _t}}var Pe=rs;function os(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var Se=os;function as(t,e){var r=t.__data__;return Se(e)?r[typeof e=="string"?"string":"hash"]:r.map}var N=as;function ss(t){var e=N(this,t).delete(t);return this.size-=e?1:0,e}var _e=ss;function is(t){return N(this,t).get(t)}var Ie=is;function fs(t){return N(this,t).has(t)}var Ee=fs;function ns(t,e){var r=N(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var Ce=ns;function H(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}H.prototype.clear=Pe;H.prototype.delete=_e;H.prototype.get=Ie;H.prototype.has=Ee;H.prototype.set=Ce;var Me=H;function ps(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var ht=ps;var ls=ct(Object.getPrototypeOf,Object),xt=ls;function ms(){this.__data__=new L,this.size=0}var Re=ms;function us(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var Be=us;function ds(t){return this.__data__.get(t)}var Le=ds;function cs(t){return this.__data__.has(t)}var Fe=cs;var hs=200;function xs(t,e){var r=this.__data__;if(r instanceof L){var o=r.__data__;if(!F||o.length<hs-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new Me(o)}return r.set(t,e),this.size=r.size,this}var Ne=xs;function $(t){var e=this.__data__=new L(t);this.size=e.size}$.prototype.clear=Re;$.prototype.delete=Be;$.prototype.get=Le;$.prototype.has=Fe;$.prototype.set=Ne;var De=$;function gs(t,e){return t&&R(e,W(e),t)}var ke=gs;function bs(t,e){return t&&R(e,z(e),t)}var Ue=bs;var ze=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ge=ze&&typeof module=="object"&&module&&!module.nodeType&&module,ys=Ge&&Ge.exports===ze,Ke=ys?g.Buffer:void 0,We=Ke?Ke.allocUnsafe:void 0;function vs(t,e){if(e)return t.slice();var r=t.length,o=We?We(r):new t.constructor(r);return t.copy(o),o}var Ve=vs;function ws(t,e){for(var r=-1,o=t==null?0:t.length,a=0,p=[];++r<o;){var n=t[r];e(n,r,t)&&(p[a++]=n)}return p}var qe=ws;function js(){return[]}var gt=js;var Ts=Object.prototype,As=Ts.propertyIsEnumerable,He=Object.getOwnPropertySymbols,Os=He?function(t){return t==null?[]:(t=Object(t),qe(He(t),function(e){return As.call(t,e)}))}:gt,Y=Os;function Ps(t,e){return R(t,Y(t),e)}var $e=Ps;var Ss=Object.getOwnPropertySymbols,_s=Ss?function(t){for(var e=[];t;)ht(e,Y(t)),t=xt(t);return e}:gt,bt=_s;function Is(t,e){return R(t,bt(t),e)}var Ye=Is;function Es(t,e,r){var o=e(t);return U(t)?o:ht(o,r(t))}var yt=Es;function Cs(t){return yt(t,W,Y)}var Ze=Cs;function Ms(t){return yt(t,z,bt)}var Je=Ms;var Rs=j(g,"DataView"),vt=Rs;var Bs=j(g,"Promise"),wt=Bs;var Ls=j(g,"Set"),jt=Ls;var Xe="[object Map]",Fs="[object Object]",Qe="[object Promise]",tr="[object Set]",er="[object WeakMap]",rr="[object DataView]",Ns=E(vt),Ds=E(F),ks=E(wt),Us=E(jt),Gs=E(it),D=I;(vt&&D(new vt(new ArrayBuffer(1)))!=rr||F&&D(new F)!=Xe||wt&&D(wt.resolve())!=Qe||jt&&D(new jt)!=tr||it&&D(new it)!=er)&&(D=function(t){var e=I(t),r=e==Fs?t.constructor:void 0,o=r?E(r):"";if(o)switch(o){case Ns:return rr;case Ds:return Xe;case ks:return Qe;case Us:return tr;case Gs:return er}return e});var Z=D;var Ks=Object.prototype,Ws=Ks.hasOwnProperty;function zs(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&Ws.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var or=zs;var Vs=g.Uint8Array,It=Vs;function qs(t){var e=new t.constructor(t.byteLength);return new It(e).set(new It(t)),e}var J=qs;function Hs(t,e){var r=e?J(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var ar=Hs;var $s=/\w*$/;function Ys(t){var e=new t.constructor(t.source,$s.exec(t));return e.lastIndex=t.lastIndex,e}var sr=Ys;var ir=_?_.prototype:void 0,fr=ir?ir.valueOf:void 0;function Zs(t){return fr?Object(fr.call(t)):{}}var nr=Zs;function Js(t,e){var r=e?J(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var pr=Js;var Xs="[object Boolean]",Qs="[object Date]",ti="[object Map]",ei="[object Number]",ri="[object RegExp]",oi="[object Set]",ai="[object String]",si="[object Symbol]",ii="[object ArrayBuffer]",fi="[object DataView]",ni="[object Float32Array]",pi="[object Float64Array]",li="[object Int8Array]",mi="[object Int16Array]",ui="[object Int32Array]",di="[object Uint8Array]",ci="[object Uint8ClampedArray]",hi="[object Uint16Array]",xi="[object Uint32Array]";function gi(t,e,r){var o=t.constructor;switch(e){case ii:return J(t);case Xs:case Qs:return new o(+t);case fi:return ar(t,r);case ni:case pi:case li:case mi:case ui:case di:case ci:case hi:case xi:return pr(t,r);case ti:return new o;case ei:case ai:return new o(t);case ri:return sr(t);case oi:return new o;case si:return nr(t)}}var lr=gi;function bi(t){return typeof t.constructor=="function"&&!G(t)?Jt(xt(t)):{}}var mr=bi;var yi="[object Map]";function vi(t){return A(t)&&Z(t)==yi}var ur=vi;var dr=C&&C.isMap,wi=dr?K(dr):ur,cr=wi;var ji="[object Set]";function Ti(t){return A(t)&&Z(t)==ji}var hr=Ti;var xr=C&&C.isSet,Ai=xr?K(xr):hr,gr=Ai;var Oi=1,Pi=2,Si=4,br="[object Arguments]",_i="[object Array]",Ii="[object Boolean]",Ei="[object Date]",Ci="[object Error]",yr="[object Function]",Mi="[object GeneratorFunction]",Ri="[object Map]",Bi="[object Number]",vr="[object Object]",Li="[object RegExp]",Fi="[object Set]",Ni="[object String]",Di="[object Symbol]",ki="[object WeakMap]",Ui="[object ArrayBuffer]",Gi="[object DataView]",Ki="[object Float32Array]",Wi="[object Float64Array]",zi="[object Int8Array]",Vi="[object Int16Array]",qi="[object Int32Array]",Hi="[object Uint8Array]",$i="[object Uint8ClampedArray]",Yi="[object Uint16Array]",Zi="[object Uint32Array]",u={};u[br]=u[_i]=u[Ui]=u[Gi]=u[Ii]=u[Ei]=u[Ki]=u[Wi]=u[zi]=u[Vi]=u[qi]=u[Ri]=u[Bi]=u[vr]=u[Li]=u[Fi]=u[Ni]=u[Di]=u[Hi]=u[$i]=u[Yi]=u[Zi]=!0;u[Ci]=u[yr]=u[ki]=!1;function Tt(t,e,r,o,a,p){var n,s=e&Oi,l=e&Pi,c=e&Si;if(r&&(n=a?r(t,o,a,p):r(t)),n!==void 0)return n;if(!O(t))return t;var x=U(t);if(x){if(n=or(t),!s)return Xt(t,n)}else{var v=Z(t),T=v==yr||v==Mi;if(ut(t))return Ve(t,s);if(v==vr||v==br||T&&!a){if(n=l||T?{}:mr(t),!s)return l?Ye(t,Ue(n,t)):$e(t,ke(n,t))}else{if(!u[v])return a?t:{};n=lr(t,v,s)}}p||(p=new De);var w=p.get(t);if(w)return w;p.set(t,n),gr(t)?t.forEach(function(y){n.add(Tt(y,e,r,y,t,p))}):cr(t)&&t.forEach(function(y,i){n.set(i,Tt(y,e,r,i,t,p))});var b=c?l?Je:Ze:l?z:W,P=x?void 0:b(t);return Qt(P||t,function(y,i){P&&(i=y,y=t[i]),pt(n,i,Tt(y,e,r,i,t,p))}),n}var wr=Tt;var Ji=1,Xi=4;function Qi(t){return wr(t,Ji|Xi)}var Et=Qi;function jr(t){return{all:t=t||new Map,on:function(e,r){var o=t.get(e);o?o.push(r):t.set(e,[r])},off:function(e,r){var o=t.get(e);o&&(r?o.splice(o.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var o=t.get(e);o&&o.slice().map(function(a){a(r)}),(o=t.get("*"))&&o.slice().map(function(a){a(e,r)})}}}var Ct=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((e,r)=>(r&=63,r<36?e+=r.toString(36):r<62?e+=(r-26).toString(36).toUpperCase():r>62?e+="-":e+="_",e),"");var tf="array",ef="bit",Tr="bits",rf="byte",Ar="bytes",X="",of="exponent",af="function",Or="iec",sf="Invalid number",ff="Invalid rounding method",Mt="jedec",nf="object",Pr=".",pf="round",lf="s",mf="si",uf="kbit",df="kB",cf=" ",hf="string",xf="0",Rt={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}};function Sr(t,{bits:e=!1,pad:r=!1,base:o=-1,round:a=2,locale:p=X,localeOptions:n={},separator:s=X,spacer:l=cf,symbols:c={},standard:x=X,output:v=hf,fullform:T=!1,fullforms:w=[],exponent:b=-1,roundingMethod:P=pf,precision:y=0}={}){let i=b,m=Number(t),f=[],S=0,At=X;x===mf?(o=10,x=Mt):x===Or||x===Mt?o=2:o===2?x=Or:(o=10,x=Mt);let rt=o===10?1e3:1024,_r=T===!0,Lt=m<0,Ft=Math[P];if(typeof t!="bigint"&&isNaN(t))throw new TypeError(sf);if(typeof Ft!==af)throw new TypeError(ff);if(Lt&&(m=-m),(i===-1||isNaN(i))&&(i=Math.floor(Math.log(m)/Math.log(rt)),i<0&&(i=0)),i>8&&(y>0&&(y+=8-i),i=8),v===of)return i;if(m===0)f[0]=0,At=f[1]=Rt.symbol[x][e?Tr:Ar][i];else{S=m/(o===2?Math.pow(2,i*10):Math.pow(1e3,i)),e&&(S=S*8,S>=rt&&i<8&&(S=S/rt,i++));let Q=Math.pow(10,i>0?a:0);f[0]=Ft(S*Q)/Q,f[0]===rt&&i<8&&b===-1&&(f[0]=1,i++),At=f[1]=o===10&&i===1?e?uf:df:Rt.symbol[x][e?Tr:Ar][i]}if(Lt&&(f[0]=-f[0]),y>0&&(f[0]=f[0].toPrecision(y)),f[1]=c[f[1]]||f[1],p===!0?f[0]=f[0].toLocaleString():p.length>0?f[0]=f[0].toLocaleString(p,n):s.length>0&&(f[0]=f[0].toString().replace(Pr,s)),r&&Number.isInteger(f[0])===!1&&a>0){let Q=s||Pr,Nt=f[0].toString().split(Q),Dt=Nt[1]||X,kt=Dt.length,Ir=a-kt;f[0]=`${Nt[0]}${Q}${Dt.padEnd(kt+Ir,xf)}`}return _r&&(f[1]=w[i]?w[i]:Rt.fullform[x][i]+(e?ef:rf)+(f[0]===1?X:lf)),v===tf?f:v===nf?{value:f[0],symbol:f[1],exponent:i,unit:At}:f.join(l)}var k=class{constructor(e){h(this,"tera");h(this,"id");h(this,"name");h(this,"path");h(this,"parsedName");h(this,"created");h(this,"createdFormatted");h(this,"modified");h(this,"modifiedFormatted");h(this,"accessed");h(this,"accessedFormatted");h(this,"size");h(this,"sizeFormatted");h(this,"mime");if(!e.tera)throw new Error("Basic file requires a `tera` key to access the Tera instance");Object.assign(this,e),this.sizeFormatted=Sr(this.size||0,{spacer:""}),this.createdFormatted=this.created.toLocaleDateString(),this.modifiedFormatted=this.modified.toLocaleDateString(),this.accessedFormatted=this.accessed.toLocaleDateString()}getContents(){return this.tera.getProjectFile(this.path)}setContents(e){return this.tera.setProjectFile(this.path,e)}getRefs(){return this.tera.parseProjectLibrary(this.path)}setRefs(e){return this.tera.setProjectLibrary(this.path,e)}};var Bt=class{constructor(e){h(this,"settings",{devMode:!0,mode:"detect",modeTimeout:300,modeFallback:"child",siteUrl:"https://tera-tools.com/embed",restrictOrigin:"*",frameSandbox:["allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-top-navigation"],handshakeInterval:1e3});h(this,"events",jr());h(this,"dom",{el:null,iframe:null,popup:null,stylesheet:null});h(this,"methods",["handshake","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","saveProjectState","replaceProjectState","applyProjectStatePatch","setProjectFile","selectProjectLibrary","parseProjectLibrary","setProjectLibrary","uiAlert","uiSplat","uiWindow"]);h(this,"plugins",[]);h(this,"acceptPostboxes",{});e&&this.set(e)}send(e){let r=Ct();return this.acceptPostboxes[r]={},this.acceptPostboxes[r].promise=new Promise((o,a)=>{Object.assign(this.acceptPostboxes[r],{resolve:o,reject:a}),this.sendRaw({id:r,...e})}),this.acceptPostboxes[r].promise}sendRaw(e){let r;try{if(r={TERA:1,id:e.id||Ct(),...Et(e)},this.settings.mode=="parent")window.parent.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="child")this.dom.iframe.contentWindow.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="popup")this.dom.popup.postMessage(r,this.settings.restrictOrigin);else throw this.settings.mode=="detect"?new Error("Call init() or detectMode() before trying to send data to determine the mode"):new Error(`Unknown TERA communication mode "${this.settings.mode}"`)}catch(o){throw this.debug("ERROR","Message compose client->server:",o),this.debug("ERROR","Attempted to dispatch payload client->server",r),o}}rpc(e,...r){return this.send({action:"rpc",method:e,args:r})}acceptMessage(e){if(e.origin==window.location.origin)return;let r=e.data;if(!(!r.TERA||!r.id))if(this.debug("Recieved",r),(r==null?void 0:r.action)=="response"&&this.acceptPostboxes[r.id])r.isError===!0?this.acceptPostboxes[r.id].reject(r.response):this.acceptPostboxes[r.id].resolve(r.response);else{if((r==null?void 0:r.action)=="rpc")return Promise.resolve().then(()=>this[r.method].apply(this,r.args)).then(o=>this.sendRaw({id:r.id,action:"response",response:o})).catch(o=>{console.warn(`TERA-FY client threw on RPC:${r.method}:`,o),this.sendRaw({id:r.id,action:"response",isError:!0,response:o.toString()})});if((r==null?void 0:r.action)=="event")return Promise.resolve().then(()=>this.events.emit(r.event,...r.payload)).catch(o=>{throw console.warn(`TERA-FY client threw while handling emitted event "${r.event}"`,{message:r}),o});r!=null&&r.id?this.debug(`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("Unexpected incoming TERA-FY CLIENT message",{message:r})}}createProjectStatePatch(e,r){let o=Ut(r,e,Gt);return this.debug("INFO","Created project patch",{newState:e,oldState:r}),this.applyProjectStatePatch(o)}applyProjectStatePatchLocal(e){throw new Error("applyProjectStatePatchLocal() has not been sub-classed by a plugin")}init(e){if(e&&this.set(e),this.init.promise)return this.init.promise;window.addEventListener("message",this.acceptMessage.bind(this));let r=this;return this.init.promise=Promise.resolve().then(()=>this.detectMode()).then(o=>this.settings.mode=o).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>this.rpc("setServerMode",this.settings.mode=="child"?"embedded":this.settings.mode=="parent"?"frame":this.settings.mode=="popup"?"popup":(()=>{throw`Unknown server mode "${this.settings.mode}"`})())).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings))))}detectMode(){return this.settings.mode!="detect"?this.settings.mode:window.self===window.parent?this.settings.modeFallback:Promise.resolve().then(()=>this.settings.mode="parent").then(()=>new Promise((e,r)=>{let o=setTimeout(()=>r(),this.settings.modeTimeout);this.rpc("handshake").then(()=>clearTimeout(o)).then(()=>e())})).then(()=>"parent").catch(()=>this.settings.modeFallback)}injectComms(){return new Promise(e=>{switch(this.settings.mode){case"child":this.debug("Injecting TERA site as iFrame child"),this.dom.el=document.createElement("div"),this.dom.el.id="tera-fy",this.dom.el.classList.toggle("dev-mode",this.settings.devMode),document.body.append(this.dom.el),this.dom.iframe=document.createElement("iframe"),this.dom.iframe.setAttribute("sandbox",this.settings.frameSandbox.join(" ")),this.dom.iframe.addEventListener("load",()=>{this.debug("Embed frame ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("Using TERA window parent"),e();break;case"popup":this.debug("Injecting TERA site as a popup window"),this.dom.popup=window.open(this.settings.siteUrl,"_blank","popup=1, location=0, menubar=0, status=0, scrollbars=0, width=500, height=600"),(()=>{let r=0,o,a=()=>{this.debug("Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("Popup window accepted handshake"),e()})};a()})();break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when calling injectComms()`)}})}injectStylesheet(){switch(this.settings.mode){case"child":this.dom.stylesheet=document.createElement("style"),this.dom.stylesheet.innerHTML=[":root {","--TERA-accent: #4d659c;","}","#tera-fy {","display: none;","position: fixed;","right: 50px;","bottom: 50px;","width: 300px;","height: 150px;","background: transparent;","&.dev-mode {","display: flex;","border: 5px solid var(--TERA-accent);","background: #FFF;","}","& > iframe {","width: 100%;","height: 100%;","}","}","body.tera-fy-focus {","overflow: hidden;","& #tera-fy {","display: flex !important;","position: fixed !important;","top: 0px !important;","width: 100vw !important;","height: 100vh !important;","left: 0px !important;","z-index: 10000 !important;","}","}"].join(`
2
+ `),document.head.appendChild(this.dom.stylesheet);break;case"parent":case"popup":break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when injectStylesheet()`)}}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){let r="log";typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),!(["INFO","LOG"].includes(r)&&!this.settings.devMode)&&console[r]("%c[TERA-FY CLIENT]","font-weight: bold; color: #ff5722;",...e)}set(e,r){return typeof e=="string"?this.settings[e]=r:Object.assign(this.settings,e),this.toggleDevMode(this.settings.devMode)}setIfDev(e,r){return!this.settings.devMode||r===void 0?this:this.set(e,r)}use(e,r){if(typeof e!="function")throw new Error("Expected use() call to be provided with a class initalizer");let o=new e(this,r);return this.mixin(this,o),this.plugins.push(o),this}mixin(e,r){Object.getOwnPropertyNames(Object.getPrototypeOf(r)).filter(o=>!["constructor","prototype","name"].includes(o)).filter(o=>o!="init").forEach(o=>{Object.defineProperty(e,o,{value:r[o].bind(e),enumerable:!1})})}toggleDevMode(e="toggle"){return this.settings.devMode=e==="toggle"?!this.settings.devMode:e,this.dom.el&&this.dom.el.classList.toggle("dev-mode",this.settings.devMode),this}toggleFocus(e="toggle"){this.debug("Request focus",{isFocused:e}),globalThis.document.body.classList.toggle("tera-fy-focus",e==="toggle"?void 0:e)}selectProjectFile(e){return this.rpc("selectProjectFile",e).then(r=>r&&new k({tera:this,...r}))}getProjectFiles(e){return this.rpc("getProjectFiles",e).then(r=>r.map(o=>new k({tera:this,...o})))}getProjectFile(e){return this.rpc("getProjectFile",e).then(r=>r&&new k({tera:this,...r}))}};export{Bt as default};
3
3
  /*! Bundled license information:
4
4
 
5
5
  lodash-es/lodash.js:
@@ -12,4 +12,13 @@ lodash-es/lodash.js:
12
12
  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
13
13
  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
14
14
  *)
15
+
16
+ filesize/dist/filesize.esm.js:
17
+ (**
18
+ * filesize
19
+ *
20
+ * @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
21
+ * @license BSD-3-Clause
22
+ * @version 10.1.1
23
+ *)
15
24
  */
package/dist/terafy.js CHANGED
@@ -1,5 +1,5 @@
1
- function _t(t,e,r){if(!t||typeof t!="object"||!e||typeof e!="object")throw new Error("both arguments must be objects or arrays");r||(r=function(s){return s});function o({obj1:s,obj2:p,basePath:m,basePathForRemoves:w,diffs:h}){var y=Object.keys(s),b=y.length,c=Object.keys(p),L=c.length,g,v=s.length-p.length;if(mr(s,p)){for(var d=0;d<b;d++){var B=Array.isArray(s)?Number(y[d]):y[d];B in p||(g=w.concat(B),h.remove.push({op:"remove",path:r(g)}))}for(var d=0;d<L;d++){var B=Array.isArray(p)?Number(c[d]):c[d];i({key:B,obj1:s,obj2:p,path:m.concat(B),pathForRemoves:m.concat(B),diffs:h})}}else{for(var d=0;d<v;d++)g=w.concat(d),h.remove.push({op:"remove",path:r(g)});for(var pr=s.slice(v),d=0;d<L;d++)i({key:d,obj1:pr,obj2:p,path:m.concat(d),pathForRemoves:m.concat(d+v),diffs:h})}}var a={remove:[],replace:[],add:[]};return o({obj1:t,obj2:e,basePath:[],basePathForRemoves:[],diffs:a}),a.remove.reverse().concat(a.replace).concat(a.add);function i({key:s,obj1:p,obj2:m,path:w,pathForRemoves:h,diffs:y}){var b=p[s],c=m[s];if(!(s in p)&&s in m){var L=c;y.add.push({op:"add",path:r(w),value:L})}else b!==c&&(Object(b)!==b||Object(c)!==c||lr(b,c)||!Object.keys(b).length&&!Object.keys(c).length&&String(b)!=String(c)?f(w,y,c):o({obj1:p[s],obj2:m[s],basePath:w,basePathForRemoves:h,diffs:y}))}function f(s,p,m){p.replace.push({op:"replace",path:r(s),value:m})}}function St(t){return[""].concat(t).join("/")}function lr(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function mr(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,i=0;i<e.length&&String(t[i])===String(e[i]);i++)o++;for(var f=e.length;f>0&&String(t[f+r])===String(e[f]);f--)a++;return o>=a}return!0}var ur=typeof global=="object"&&global&&global.Object===Object&&global,X=ur;var dr=typeof self=="object"&&self&&self.Object===Object&&self,cr=X||dr||Function("return this")(),u=cr;var xr=u.Symbol,A=xr;var Pt=Object.prototype,hr=Pt.hasOwnProperty,gr=Pt.toString,Y=A?A.toStringTag:void 0;function yr(t){var e=hr.call(t,Y),r=t[Y];try{t[Y]=void 0;var o=!0}catch{}var a=gr.call(t);return o&&(e?t[Y]=r:delete t[Y]),a}var It=yr;var br=Object.prototype,vr=br.toString;function wr(t){return vr.call(t)}var Ct=wr;var jr="[object Null]",Tr="[object Undefined]",Et=A?A.toStringTag:void 0;function Ar(t){return t==null?t===void 0?Tr:jr:Et&&Et in Object(t)?It(t):Ct(t)}var O=Ar;function Or(t){return t!=null&&typeof t=="object"}var j=Or;var _r=Array.isArray,D=_r;function Sr(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var T=Sr;var Pr="[object AsyncFunction]",Ir="[object Function]",Cr="[object GeneratorFunction]",Er="[object Proxy]";function Mr(t){if(!T(t))return!1;var e=O(t);return e==Ir||e==Cr||e==Pr||e==Er}var Z=Mr;var Rr=u["__core-js_shared__"],Q=Rr;var Mt=function(){var t=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Lr(t){return!!Mt&&Mt in t}var Rt=Lr;var Fr=Function.prototype,Br=Fr.toString;function Dr(t){if(t!=null){try{return Br.call(t)}catch{}try{return t+""}catch{}}return""}var _=Dr;var kr=/[\\^$.*+?()[\]{}|]/g,Ur=/^\[object .+?Constructor\]$/,Nr=Function.prototype,Wr=Object.prototype,Gr=Nr.toString,Kr=Wr.hasOwnProperty,zr=RegExp("^"+Gr.call(Kr).replace(kr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Hr(t){if(!T(t)||Rt(t))return!1;var e=Z(t)?zr:Ur;return e.test(_(t))}var Lt=Hr;function Vr(t,e){return t?.[e]}var Ft=Vr;function qr(t,e){var r=Ft(t,e);return Lt(r)?r:void 0}var x=qr;var $r=x(u,"WeakMap"),tt=$r;var Bt=Object.create,Yr=function(){function t(){}return function(e){if(!T(e))return{};if(Bt)return Bt(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Dt=Yr;function Jr(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var kt=Jr;var Xr=function(){try{var t=x(Object,"defineProperty");return t({},"",{}),t}catch{}}(),yt=Xr;function Zr(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var Ut=Zr;var Qr=9007199254740991,to=/^(?:0|[1-9]\d*)$/;function eo(t,e){var r=typeof t;return e=e??Qr,!!e&&(r=="number"||r!="symbol"&&to.test(t))&&t>-1&&t%1==0&&t<e}var Nt=eo;function ro(t,e,r){e=="__proto__"&&yt?yt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var et=ro;function oo(t,e){return t===e||t!==t&&e!==e}var rt=oo;var ao=Object.prototype,so=ao.hasOwnProperty;function fo(t,e,r){var o=t[e];(!(so.call(t,e)&&rt(o,r))||r===void 0&&!(e in t))&&et(t,e,r)}var ot=fo;function io(t,e,r,o){var a=!r;r||(r={});for(var i=-1,f=e.length;++i<f;){var s=e[i],p=o?o(r[s],t[s],s,r,t):void 0;p===void 0&&(p=t[s]),a?et(r,s,p):ot(r,s,p)}return r}var I=io;var no=9007199254740991;function po(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=no}var at=po;function lo(t){return t!=null&&at(t.length)&&!Z(t)}var st=lo;var mo=Object.prototype;function uo(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||mo;return t===r}var k=uo;function co(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var Wt=co;var xo="[object Arguments]";function ho(t){return j(t)&&O(t)==xo}var bt=ho;var Gt=Object.prototype,go=Gt.hasOwnProperty,yo=Gt.propertyIsEnumerable,bo=bt(function(){return arguments}())?bt:function(t){return j(t)&&go.call(t,"callee")&&!yo.call(t,"callee")},Kt=bo;function vo(){return!1}var zt=vo;var qt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ht=qt&&typeof module=="object"&&module&&!module.nodeType&&module,wo=Ht&&Ht.exports===qt,Vt=wo?u.Buffer:void 0,jo=Vt?Vt.isBuffer:void 0,To=jo||zt,ft=To;var Ao="[object Arguments]",Oo="[object Array]",_o="[object Boolean]",So="[object Date]",Po="[object Error]",Io="[object Function]",Co="[object Map]",Eo="[object Number]",Mo="[object Object]",Ro="[object RegExp]",Lo="[object Set]",Fo="[object String]",Bo="[object WeakMap]",Do="[object ArrayBuffer]",ko="[object DataView]",Uo="[object Float32Array]",No="[object Float64Array]",Wo="[object Int8Array]",Go="[object Int16Array]",Ko="[object Int32Array]",zo="[object Uint8Array]",Ho="[object Uint8ClampedArray]",Vo="[object Uint16Array]",qo="[object Uint32Array]",l={};l[Uo]=l[No]=l[Wo]=l[Go]=l[Ko]=l[zo]=l[Ho]=l[Vo]=l[qo]=!0;l[Ao]=l[Oo]=l[Do]=l[_o]=l[ko]=l[So]=l[Po]=l[Io]=l[Co]=l[Eo]=l[Mo]=l[Ro]=l[Lo]=l[Fo]=l[Bo]=!1;function $o(t){return j(t)&&at(t.length)&&!!l[O(t)]}var $t=$o;function Yo(t){return function(e){return t(e)}}var U=Yo;var Yt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,J=Yt&&typeof module=="object"&&module&&!module.nodeType&&module,Jo=J&&J.exports===Yt,vt=Jo&&X.process,Xo=function(){try{var t=J&&J.require&&J.require("util").types;return t||vt&&vt.binding&&vt.binding("util")}catch{}}(),S=Xo;var Jt=S&&S.isTypedArray,Zo=Jt?U(Jt):$t,Xt=Zo;var Qo=Object.prototype,ta=Qo.hasOwnProperty;function ea(t,e){var r=D(t),o=!r&&Kt(t),a=!r&&!o&&ft(t),i=!r&&!o&&!a&&Xt(t),f=r||o||a||i,s=f?Wt(t.length,String):[],p=s.length;for(var m in t)(e||ta.call(t,m))&&!(f&&(m=="length"||a&&(m=="offset"||m=="parent")||i&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||Nt(m,p)))&&s.push(m);return s}var it=ea;function ra(t,e){return function(r){return t(e(r))}}var nt=ra;var oa=nt(Object.keys,Object),Zt=oa;var aa=Object.prototype,sa=aa.hasOwnProperty;function fa(t){if(!k(t))return Zt(t);var e=[];for(var r in Object(t))sa.call(t,r)&&r!="constructor"&&e.push(r);return e}var Qt=fa;function ia(t){return st(t)?it(t):Qt(t)}var N=ia;function na(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var te=na;var pa=Object.prototype,la=pa.hasOwnProperty;function ma(t){if(!T(t))return te(t);var e=k(t),r=[];for(var o in t)o=="constructor"&&(e||!la.call(t,o))||r.push(o);return r}var ee=ma;function ua(t){return st(t)?it(t,!0):ee(t)}var W=ua;var da=x(Object,"create"),P=da;function ca(){this.__data__=P?P(null):{},this.size=0}var re=ca;function xa(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var oe=xa;var ha="__lodash_hash_undefined__",ga=Object.prototype,ya=ga.hasOwnProperty;function ba(t){var e=this.__data__;if(P){var r=e[t];return r===ha?void 0:r}return ya.call(e,t)?e[t]:void 0}var ae=ba;var va=Object.prototype,wa=va.hasOwnProperty;function ja(t){var e=this.__data__;return P?e[t]!==void 0:wa.call(e,t)}var se=ja;var Ta="__lodash_hash_undefined__";function Aa(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=P&&e===void 0?Ta:e,this}var fe=Aa;function G(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}G.prototype.clear=re;G.prototype.delete=oe;G.prototype.get=ae;G.prototype.has=se;G.prototype.set=fe;var wt=G;function Oa(){this.__data__=[],this.size=0}var ie=Oa;function _a(t,e){for(var r=t.length;r--;)if(rt(t[r][0],e))return r;return-1}var C=_a;var Sa=Array.prototype,Pa=Sa.splice;function Ia(t){var e=this.__data__,r=C(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Pa.call(e,r,1),--this.size,!0}var ne=Ia;function Ca(t){var e=this.__data__,r=C(e,t);return r<0?void 0:e[r][1]}var pe=Ca;function Ea(t){return C(this.__data__,t)>-1}var le=Ea;function Ma(t,e){var r=this.__data__,o=C(r,t);return o<0?(++this.size,r.push([t,e])):r[o][1]=e,this}var me=Ma;function K(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}K.prototype.clear=ie;K.prototype.delete=ne;K.prototype.get=pe;K.prototype.has=le;K.prototype.set=me;var E=K;var Ra=x(u,"Map"),M=Ra;function La(){this.size=0,this.__data__={hash:new wt,map:new(M||E),string:new wt}}var ue=La;function Fa(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var de=Fa;function Ba(t,e){var r=t.__data__;return de(e)?r[typeof e=="string"?"string":"hash"]:r.map}var R=Ba;function Da(t){var e=R(this,t).delete(t);return this.size-=e?1:0,e}var ce=Da;function ka(t){return R(this,t).get(t)}var xe=ka;function Ua(t){return R(this,t).has(t)}var he=Ua;function Na(t,e){var r=R(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var ge=Na;function z(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}z.prototype.clear=ue;z.prototype.delete=ce;z.prototype.get=xe;z.prototype.has=he;z.prototype.set=ge;var ye=z;function Wa(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var pt=Wa;var Ga=nt(Object.getPrototypeOf,Object),lt=Ga;function Ka(){this.__data__=new E,this.size=0}var be=Ka;function za(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var ve=za;function Ha(t){return this.__data__.get(t)}var we=Ha;function Va(t){return this.__data__.has(t)}var je=Va;var qa=200;function $a(t,e){var r=this.__data__;if(r instanceof E){var o=r.__data__;if(!M||o.length<qa-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new ye(o)}return r.set(t,e),this.size=r.size,this}var Te=$a;function H(t){var e=this.__data__=new E(t);this.size=e.size}H.prototype.clear=be;H.prototype.delete=ve;H.prototype.get=we;H.prototype.has=je;H.prototype.set=Te;var Ae=H;function Ya(t,e){return t&&I(e,N(e),t)}var Oe=Ya;function Ja(t,e){return t&&I(e,W(e),t)}var _e=Ja;var Ce=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Se=Ce&&typeof module=="object"&&module&&!module.nodeType&&module,Xa=Se&&Se.exports===Ce,Pe=Xa?u.Buffer:void 0,Ie=Pe?Pe.allocUnsafe:void 0;function Za(t,e){if(e)return t.slice();var r=t.length,o=Ie?Ie(r):new t.constructor(r);return t.copy(o),o}var Ee=Za;function Qa(t,e){for(var r=-1,o=t==null?0:t.length,a=0,i=[];++r<o;){var f=t[r];e(f,r,t)&&(i[a++]=f)}return i}var Me=Qa;function ts(){return[]}var mt=ts;var es=Object.prototype,rs=es.propertyIsEnumerable,Re=Object.getOwnPropertySymbols,os=Re?function(t){return t==null?[]:(t=Object(t),Me(Re(t),function(e){return rs.call(t,e)}))}:mt,V=os;function as(t,e){return I(t,V(t),e)}var Le=as;var ss=Object.getOwnPropertySymbols,fs=ss?function(t){for(var e=[];t;)pt(e,V(t)),t=lt(t);return e}:mt,ut=fs;function is(t,e){return I(t,ut(t),e)}var Fe=is;function ns(t,e,r){var o=e(t);return D(t)?o:pt(o,r(t))}var dt=ns;function ps(t){return dt(t,N,V)}var Be=ps;function ls(t){return dt(t,W,ut)}var De=ls;var ms=x(u,"DataView"),ct=ms;var us=x(u,"Promise"),xt=us;var ds=x(u,"Set"),ht=ds;var ke="[object Map]",cs="[object Object]",Ue="[object Promise]",Ne="[object Set]",We="[object WeakMap]",Ge="[object DataView]",xs=_(ct),hs=_(M),gs=_(xt),ys=_(ht),bs=_(tt),F=O;(ct&&F(new ct(new ArrayBuffer(1)))!=Ge||M&&F(new M)!=ke||xt&&F(xt.resolve())!=Ue||ht&&F(new ht)!=Ne||tt&&F(new tt)!=We)&&(F=function(t){var e=O(t),r=e==cs?t.constructor:void 0,o=r?_(r):"";if(o)switch(o){case xs:return Ge;case hs:return ke;case gs:return Ue;case ys:return Ne;case bs:return We}return e});var q=F;var vs=Object.prototype,ws=vs.hasOwnProperty;function js(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&ws.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var Ke=js;var Ts=u.Uint8Array,jt=Ts;function As(t){var e=new t.constructor(t.byteLength);return new jt(e).set(new jt(t)),e}var $=As;function Os(t,e){var r=e?$(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var ze=Os;var _s=/\w*$/;function Ss(t){var e=new t.constructor(t.source,_s.exec(t));return e.lastIndex=t.lastIndex,e}var He=Ss;var Ve=A?A.prototype:void 0,qe=Ve?Ve.valueOf:void 0;function Ps(t){return qe?Object(qe.call(t)):{}}var $e=Ps;function Is(t,e){var r=e?$(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var Ye=Is;var Cs="[object Boolean]",Es="[object Date]",Ms="[object Map]",Rs="[object Number]",Ls="[object RegExp]",Fs="[object Set]",Bs="[object String]",Ds="[object Symbol]",ks="[object ArrayBuffer]",Us="[object DataView]",Ns="[object Float32Array]",Ws="[object Float64Array]",Gs="[object Int8Array]",Ks="[object Int16Array]",zs="[object Int32Array]",Hs="[object Uint8Array]",Vs="[object Uint8ClampedArray]",qs="[object Uint16Array]",$s="[object Uint32Array]";function Ys(t,e,r){var o=t.constructor;switch(e){case ks:return $(t);case Cs:case Es:return new o(+t);case Us:return ze(t,r);case Ns:case Ws:case Gs:case Ks:case zs:case Hs:case Vs:case qs:case $s:return Ye(t,r);case Ms:return new o;case Rs:case Bs:return new o(t);case Ls:return He(t);case Fs:return new o;case Ds:return $e(t)}}var Je=Ys;function Js(t){return typeof t.constructor=="function"&&!k(t)?Dt(lt(t)):{}}var Xe=Js;var Xs="[object Map]";function Zs(t){return j(t)&&q(t)==Xs}var Ze=Zs;var Qe=S&&S.isMap,Qs=Qe?U(Qe):Ze,tr=Qs;var tf="[object Set]";function ef(t){return j(t)&&q(t)==tf}var er=ef;var rr=S&&S.isSet,rf=rr?U(rr):er,or=rf;var of=1,af=2,sf=4,ar="[object Arguments]",ff="[object Array]",nf="[object Boolean]",pf="[object Date]",lf="[object Error]",sr="[object Function]",mf="[object GeneratorFunction]",uf="[object Map]",df="[object Number]",fr="[object Object]",cf="[object RegExp]",xf="[object Set]",hf="[object String]",gf="[object Symbol]",yf="[object WeakMap]",bf="[object ArrayBuffer]",vf="[object DataView]",wf="[object Float32Array]",jf="[object Float64Array]",Tf="[object Int8Array]",Af="[object Int16Array]",Of="[object Int32Array]",_f="[object Uint8Array]",Sf="[object Uint8ClampedArray]",Pf="[object Uint16Array]",If="[object Uint32Array]",n={};n[ar]=n[ff]=n[bf]=n[vf]=n[nf]=n[pf]=n[wf]=n[jf]=n[Tf]=n[Af]=n[Of]=n[uf]=n[df]=n[fr]=n[cf]=n[xf]=n[hf]=n[gf]=n[_f]=n[Sf]=n[Pf]=n[If]=!0;n[lf]=n[sr]=n[yf]=!1;function gt(t,e,r,o,a,i){var f,s=e&of,p=e&af,m=e&sf;if(r&&(f=a?r(t,o,a,i):r(t)),f!==void 0)return f;if(!T(t))return t;var w=D(t);if(w){if(f=Ke(t),!s)return kt(t,f)}else{var h=q(t),y=h==sr||h==mf;if(ft(t))return Ee(t,s);if(h==fr||h==ar||y&&!a){if(f=p||y?{}:Xe(t),!s)return p?Fe(t,_e(f,t)):Le(t,Oe(f,t))}else{if(!n[h])return a?t:{};f=Je(t,h,s)}}i||(i=new Ae);var b=i.get(t);if(b)return b;i.set(t,f),or(t)?t.forEach(function(g){f.add(gt(g,e,r,g,t,i))}):tr(t)&&t.forEach(function(g,v){f.set(v,gt(g,e,r,v,t,i))});var c=m?p?De:Be:p?W:N,L=w?void 0:c(t);return Ut(L||t,function(g,v){L&&(v=g,g=t[v]),ot(f,v,gt(g,e,r,v,t,i))}),f}var ir=gt;var Cf=1,Ef=4;function Mf(t){return ir(t,Cf|Ef)}var Tt=Mf;function nr(t){return{all:t=t||new Map,on:function(e,r){var o=t.get(e);o?o.push(r):t.set(e,[r])},off:function(e,r){var o=t.get(e);o&&(r?o.splice(o.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var o=t.get(e);o&&o.slice().map(function(a){a(r)}),(o=t.get("*"))&&o.slice().map(function(a){a(e,r)})}}}var At=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((e,r)=>(r&=63,r<36?e+=r.toString(36):r<62?e+=(r-26).toString(36).toUpperCase():r>62?e+="-":e+="_",e),"");var Ot=class{settings={devMode:!0,mode:"detect",modeTimeout:300,modeFallback:"child",siteUrl:"https://tera-tools.com/embed",restrictOrigin:"*",frameSandbox:["allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-top-navigation"],handshakeInterval:1e3};events=nr();dom={el:null,iframe:null,popup:null,stylesheet:null};methods=["handshake","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","saveProjectState","replaceProjectState","applyProjectStatePatch","selectProjectFile","getProjectFiles","selectProjectLibrary","parseProjectLibrary","setProjectLibrary","uiAlert","uiSplat","uiWindow"];plugins=[];send(e){let r=At();return this.acceptPostboxes[r]={},this.acceptPostboxes[r].promise=new Promise((o,a)=>{Object.assign(this.acceptPostboxes[r],{resolve:o,reject:a}),this.sendRaw({id:r,...e})}),this.acceptPostboxes[r].promise}sendRaw(e){let r;try{if(r={TERA:1,id:e.id||At(),...Tt(e)},this.settings.mode=="parent")window.parent.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="child")this.dom.iframe.contentWindow.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="popup")this.dom.popup.postMessage(r,this.settings.restrictOrigin);else throw this.settings.mode=="detect"?new Error("Call init() or detectMode() before trying to send data to determine the mode"):new Error(`Unknown TERA communication mode "${this.settings.mode}"`)}catch(o){throw this.debug("ERROR","Message compose client->server:",o),this.debug("ERROR","Attempted to dispatch payload client->server",r),o}}rpc(e,...r){return this.send({action:"rpc",method:e,args:r})}acceptMessage(e){if(e.origin==window.location.origin)return;let r=e.data;if(!(!r.TERA||!r.id))if(this.debug("Recieved",r),r?.action=="response"&&this.acceptPostboxes[r.id])r.isError===!0?this.acceptPostboxes[r.id].reject(r.response):this.acceptPostboxes[r.id].resolve(r.response);else{if(r?.action=="rpc")return Promise.resolve().then(()=>this[r.method].apply(this,r.args)).then(o=>this.sendRaw({id:r.id,action:"response",response:o})).catch(o=>{console.warn(`TERA-FY client threw on RPC:${r.method}:`,o),this.sendRaw({id:r.id,action:"response",isError:!0,response:o.toString()})});if(r?.action=="event")return Promise.resolve().then(()=>this.events.emit(r.event,...r.payload)).catch(o=>{throw console.warn(`TERA-FY client threw while handling emitted event "${r.event}"`,{message:r}),o});r?.id?this.debug(`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("Unexpected incoming TERA-FY CLIENT message",{message:r})}}acceptPostboxes={};createProjectStatePatch(e,r){let o=_t(r,e,St);return this.debug("INFO","Created project patch",{newState:e,oldState:r}),this.applyProjectStatePatch(o)}applyProjectStatePatchLocal(e){throw new Error("applyProjectStatePatchLocal() has not been sub-classed by a plugin")}constructor(e){e&&this.set(e)}init(e){if(e&&this.set(e),this.init.promise)return this.init.promise;window.addEventListener("message",this.acceptMessage.bind(this));let r=this;return this.init.promise=Promise.resolve().then(()=>this.detectMode()).then(o=>this.settings.mode=o).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>this.rpc("setServerMode",this.settings.mode=="child"?"embedded":this.settings.mode=="parent"?"frame":this.settings.mode=="popup"?"popup":(()=>{throw`Unknown server mode "${this.settings.mode}"`})())).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings))))}detectMode(){return this.settings.mode!="detect"?this.settings.mode:window.self===window.parent?this.settings.modeFallback:Promise.resolve().then(()=>this.settings.mode="parent").then(()=>new Promise((e,r)=>{let o=setTimeout(()=>r(),this.settings.modeTimeout);this.rpc("handshake").then(()=>clearTimeout(o)).then(()=>e())})).then(()=>"parent").catch(()=>this.settings.modeFallback)}injectComms(){return new Promise(e=>{switch(this.settings.mode){case"child":this.debug("Injecting TERA site as iFrame child"),this.dom.el=document.createElement("div"),this.dom.el.id="tera-fy",this.dom.el.classList.toggle("dev-mode",this.settings.devMode),document.body.append(this.dom.el),this.dom.iframe=document.createElement("iframe"),this.dom.iframe.setAttribute("sandbox",this.settings.frameSandbox.join(" ")),this.dom.iframe.addEventListener("load",()=>{this.debug("Embed frame ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("Using TERA window parent"),e();break;case"popup":this.debug("Injecting TERA site as a popup window"),this.dom.popup=window.open(this.settings.siteUrl,"_blank","popup=1, location=0, menubar=0, status=0, scrollbars=0, width=500, height=600"),(()=>{let r=0,o,a=()=>{this.debug("Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("Popup window accepted handshake"),e()})};a()})();break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when calling injectComms()`)}})}injectStylesheet(){switch(this.settings.mode){case"child":this.dom.stylesheet=document.createElement("style"),this.dom.stylesheet.innerHTML=[":root {","--TERA-accent: #4d659c;","}","#tera-fy {","display: none;","position: fixed;","right: 50px;","bottom: 50px;","width: 300px;","height: 150px;","background: transparent;","&.dev-mode {","display: flex;","border: 5px solid var(--TERA-accent);","background: #FFF;","}","& > iframe {","width: 100%;","height: 100%;","}","}","body.tera-fy-focus {","overflow: hidden;","& #tera-fy {","display: flex !important;","position: fixed !important;","top: 0px !important;","width: 100vw !important;","height: 100vh !important;","left: 0px !important;","z-index: 10000 !important;","}","}"].join(`
2
- `),document.head.appendChild(this.dom.stylesheet);break;case"parent":case"popup":break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when injectStylesheet()`)}}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){let r="log";typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),!(["INFO","LOG"].includes(r)&&!this.settings.devMode)&&console[r]("%c[TERA-FY CLIENT]","font-weight: bold; color: #ff5722;",...e)}set(e,r){return typeof e=="string"?this.settings[e]=r:Object.assign(this.settings,e),this.toggleDevMode(this.settings.devMode)}setIfDev(e,r){return!this.settings.devMode||r===void 0?this:this.set(e,r)}use(e,r){if(typeof e!="function")throw new Error("Expected use() call to be provided with a class initalizer");let o=new e(this,r);return this.mixin(this,o),this.plugins.push(o),this}mixin(e,r){Object.getOwnPropertyNames(Object.getPrototypeOf(r)).filter(o=>!["constructor","prototype","name"].includes(o)).filter(o=>o!="init").forEach(o=>{Object.defineProperty(e,o,{value:r[o].bind(e),enumerable:!1})})}toggleDevMode(e="toggle"){return this.settings.devMode=e==="toggle"?!this.settings.devMode:e,this.dom.el&&this.dom.el.classList.toggle("dev-mode",this.settings.devMode),this}toggleFocus(e="toggle"){this.debug("Request focus",{isFocused:e}),globalThis.document.body.classList.toggle("tera-fy-focus",e==="toggle"?void 0:e)}};export{Ot as default};
1
+ function kt(t,e,r){if(!t||typeof t!="object"||!e||typeof e!="object")throw new Error("both arguments must be objects or arrays");r||(r=function(s){return s});function o({obj1:s,obj2:l,basePath:c,basePathForRemoves:h,diffs:y}){var j=Object.keys(s),v=j.length,g=Object.keys(l),O=g.length,b,i=s.length-l.length;if(Er(s,l)){for(var m=0;m<v;m++){var f=Array.isArray(s)?Number(j[m]):j[m];f in l||(b=h.concat(f),y.remove.push({op:"remove",path:r(b)}))}for(var m=0;m<O;m++){var f=Array.isArray(l)?Number(g[m]):g[m];p({key:f,obj1:s,obj2:l,path:c.concat(f),pathForRemoves:c.concat(f),diffs:y})}}else{for(var m=0;m<i;m++)b=h.concat(m),y.remove.push({op:"remove",path:r(b)});for(var P=s.slice(i),m=0;m<O;m++)p({key:m,obj1:P,obj2:l,path:c.concat(m),pathForRemoves:c.concat(m+i),diffs:y})}}var a={remove:[],replace:[],add:[]};return o({obj1:t,obj2:e,basePath:[],basePathForRemoves:[],diffs:a}),a.remove.reverse().concat(a.replace).concat(a.add);function p({key:s,obj1:l,obj2:c,path:h,pathForRemoves:y,diffs:j}){var v=l[s],g=c[s];if(!(s in l)&&s in c){var O=g;j.add.push({op:"add",path:r(h),value:O})}else v!==g&&(Object(v)!==v||Object(g)!==g||Ir(v,g)||!Object.keys(v).length&&!Object.keys(g).length&&String(v)!=String(g)?n(h,j,g):o({obj1:l[s],obj2:c[s],basePath:h,basePathForRemoves:y,diffs:j}))}function n(s,l,c){l.replace.push({op:"replace",path:r(s),value:c})}}function Ut(t){return[""].concat(t).join("/")}function Ir(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function Er(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,p=0;p<e.length&&String(t[p])===String(e[p]);p++)o++;for(var n=e.length;n>0&&String(t[n+r])===String(e[n]);n--)a++;return o>=a}return!0}var Cr=typeof global=="object"&&global&&global.Object===Object&&global,rt=Cr;var Mr=typeof self=="object"&&self&&self.Object===Object&&self,Rr=rt||Mr||Function("return this")(),x=Rr;var Br=x.Symbol,S=Br;var Gt=Object.prototype,Lr=Gt.hasOwnProperty,Fr=Gt.toString,Q=S?S.toStringTag:void 0;function Nr(t){var e=Lr.call(t,Q),r=t[Q];try{t[Q]=void 0;var o=!0}catch{}var a=Fr.call(t);return o&&(e?t[Q]=r:delete t[Q]),a}var Kt=Nr;var Dr=Object.prototype,kr=Dr.toString;function Ur(t){return kr.call(t)}var Wt=Ur;var Gr="[object Null]",Kr="[object Undefined]",zt=S?S.toStringTag:void 0;function Wr(t){return t==null?t===void 0?Kr:Gr:zt&&zt in Object(t)?Kt(t):Wt(t)}var _=Wr;function zr(t){return t!=null&&typeof t=="object"}var T=zr;var Vr=Array.isArray,k=Vr;function qr(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var A=qr;var Hr="[object AsyncFunction]",$r="[object Function]",Yr="[object GeneratorFunction]",Zr="[object Proxy]";function Jr(t){if(!A(t))return!1;var e=_(t);return e==$r||e==Yr||e==Hr||e==Zr}var ot=Jr;var Xr=x["__core-js_shared__"],at=Xr;var Vt=function(){var t=/[^.]+$/.exec(at&&at.keys&&at.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Qr(t){return!!Vt&&Vt in t}var qt=Qr;var to=Function.prototype,eo=to.toString;function ro(t){if(t!=null){try{return eo.call(t)}catch{}try{return t+""}catch{}}return""}var I=ro;var oo=/[\\^$.*+?()[\]{}|]/g,ao=/^\[object .+?Constructor\]$/,so=Function.prototype,io=Object.prototype,fo=so.toString,no=io.hasOwnProperty,po=RegExp("^"+fo.call(no).replace(oo,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function lo(t){if(!A(t)||qt(t))return!1;var e=ot(t)?po:ao;return e.test(I(t))}var Ht=lo;function mo(t,e){return t?.[e]}var $t=mo;function uo(t,e){var r=$t(t,e);return Ht(r)?r:void 0}var w=uo;var co=w(x,"WeakMap"),st=co;var Yt=Object.create,ho=function(){function t(){}return function(e){if(!A(e))return{};if(Yt)return Yt(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Zt=ho;function xo(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var Jt=xo;var go=function(){try{var t=w(Object,"defineProperty");return t({},"",{}),t}catch{}}(),At=go;function bo(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var Xt=bo;var yo=9007199254740991,vo=/^(?:0|[1-9]\d*)$/;function wo(t,e){var r=typeof t;return e=e??yo,!!e&&(r=="number"||r!="symbol"&&vo.test(t))&&t>-1&&t%1==0&&t<e}var Qt=wo;function jo(t,e,r){e=="__proto__"&&At?At(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var it=jo;function To(t,e){return t===e||t!==t&&e!==e}var ft=To;var Ao=Object.prototype,Oo=Ao.hasOwnProperty;function Po(t,e,r){var o=t[e];(!(Oo.call(t,e)&&ft(o,r))||r===void 0&&!(e in t))&&it(t,e,r)}var nt=Po;function So(t,e,r,o){var a=!r;r||(r={});for(var p=-1,n=e.length;++p<n;){var s=e[p],l=o?o(r[s],t[s],s,r,t):void 0;l===void 0&&(l=t[s]),a?it(r,s,l):nt(r,s,l)}return r}var M=So;var _o=9007199254740991;function Io(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=_o}var pt=Io;function Eo(t){return t!=null&&pt(t.length)&&!ot(t)}var lt=Eo;var Co=Object.prototype;function Mo(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Co;return t===r}var U=Mo;function Ro(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var te=Ro;var Bo="[object Arguments]";function Lo(t){return T(t)&&_(t)==Bo}var Ot=Lo;var ee=Object.prototype,Fo=ee.hasOwnProperty,No=ee.propertyIsEnumerable,Do=Ot(function(){return arguments}())?Ot:function(t){return T(t)&&Fo.call(t,"callee")&&!No.call(t,"callee")},re=Do;function ko(){return!1}var oe=ko;var ie=typeof exports=="object"&&exports&&!exports.nodeType&&exports,ae=ie&&typeof module=="object"&&module&&!module.nodeType&&module,Uo=ae&&ae.exports===ie,se=Uo?x.Buffer:void 0,Go=se?se.isBuffer:void 0,Ko=Go||oe,mt=Ko;var Wo="[object Arguments]",zo="[object Array]",Vo="[object Boolean]",qo="[object Date]",Ho="[object Error]",$o="[object Function]",Yo="[object Map]",Zo="[object Number]",Jo="[object Object]",Xo="[object RegExp]",Qo="[object Set]",ta="[object String]",ea="[object WeakMap]",ra="[object ArrayBuffer]",oa="[object DataView]",aa="[object Float32Array]",sa="[object Float64Array]",ia="[object Int8Array]",fa="[object Int16Array]",na="[object Int32Array]",pa="[object Uint8Array]",la="[object Uint8ClampedArray]",ma="[object Uint16Array]",ua="[object Uint32Array]",d={};d[aa]=d[sa]=d[ia]=d[fa]=d[na]=d[pa]=d[la]=d[ma]=d[ua]=!0;d[Wo]=d[zo]=d[ra]=d[Vo]=d[oa]=d[qo]=d[Ho]=d[$o]=d[Yo]=d[Zo]=d[Jo]=d[Xo]=d[Qo]=d[ta]=d[ea]=!1;function da(t){return T(t)&&pt(t.length)&&!!d[_(t)]}var fe=da;function ca(t){return function(e){return t(e)}}var G=ca;var ne=typeof exports=="object"&&exports&&!exports.nodeType&&exports,tt=ne&&typeof module=="object"&&module&&!module.nodeType&&module,ha=tt&&tt.exports===ne,Pt=ha&&rt.process,xa=function(){try{var t=tt&&tt.require&&tt.require("util").types;return t||Pt&&Pt.binding&&Pt.binding("util")}catch{}}(),E=xa;var pe=E&&E.isTypedArray,ga=pe?G(pe):fe,le=ga;var ba=Object.prototype,ya=ba.hasOwnProperty;function va(t,e){var r=k(t),o=!r&&re(t),a=!r&&!o&&mt(t),p=!r&&!o&&!a&&le(t),n=r||o||a||p,s=n?te(t.length,String):[],l=s.length;for(var c in t)(e||ya.call(t,c))&&!(n&&(c=="length"||a&&(c=="offset"||c=="parent")||p&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||Qt(c,l)))&&s.push(c);return s}var ut=va;function wa(t,e){return function(r){return t(e(r))}}var dt=wa;var ja=dt(Object.keys,Object),me=ja;var Ta=Object.prototype,Aa=Ta.hasOwnProperty;function Oa(t){if(!U(t))return me(t);var e=[];for(var r in Object(t))Aa.call(t,r)&&r!="constructor"&&e.push(r);return e}var ue=Oa;function Pa(t){return lt(t)?ut(t):ue(t)}var K=Pa;function Sa(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var de=Sa;var _a=Object.prototype,Ia=_a.hasOwnProperty;function Ea(t){if(!A(t))return de(t);var e=U(t),r=[];for(var o in t)o=="constructor"&&(e||!Ia.call(t,o))||r.push(o);return r}var ce=Ea;function Ca(t){return lt(t)?ut(t,!0):ce(t)}var W=Ca;var Ma=w(Object,"create"),C=Ma;function Ra(){this.__data__=C?C(null):{},this.size=0}var he=Ra;function Ba(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var xe=Ba;var La="__lodash_hash_undefined__",Fa=Object.prototype,Na=Fa.hasOwnProperty;function Da(t){var e=this.__data__;if(C){var r=e[t];return r===La?void 0:r}return Na.call(e,t)?e[t]:void 0}var ge=Da;var ka=Object.prototype,Ua=ka.hasOwnProperty;function Ga(t){var e=this.__data__;return C?e[t]!==void 0:Ua.call(e,t)}var be=Ga;var Ka="__lodash_hash_undefined__";function Wa(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=C&&e===void 0?Ka:e,this}var ye=Wa;function z(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}z.prototype.clear=he;z.prototype.delete=xe;z.prototype.get=ge;z.prototype.has=be;z.prototype.set=ye;var St=z;function za(){this.__data__=[],this.size=0}var ve=za;function Va(t,e){for(var r=t.length;r--;)if(ft(t[r][0],e))return r;return-1}var R=Va;var qa=Array.prototype,Ha=qa.splice;function $a(t){var e=this.__data__,r=R(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Ha.call(e,r,1),--this.size,!0}var we=$a;function Ya(t){var e=this.__data__,r=R(e,t);return r<0?void 0:e[r][1]}var je=Ya;function Za(t){return R(this.__data__,t)>-1}var Te=Za;function Ja(t,e){var r=this.__data__,o=R(r,t);return o<0?(++this.size,r.push([t,e])):r[o][1]=e,this}var Ae=Ja;function V(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}V.prototype.clear=ve;V.prototype.delete=we;V.prototype.get=je;V.prototype.has=Te;V.prototype.set=Ae;var B=V;var Xa=w(x,"Map"),L=Xa;function Qa(){this.size=0,this.__data__={hash:new St,map:new(L||B),string:new St}}var Oe=Qa;function ts(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var Pe=ts;function es(t,e){var r=t.__data__;return Pe(e)?r[typeof e=="string"?"string":"hash"]:r.map}var F=es;function rs(t){var e=F(this,t).delete(t);return this.size-=e?1:0,e}var Se=rs;function os(t){return F(this,t).get(t)}var _e=os;function as(t){return F(this,t).has(t)}var Ie=as;function ss(t,e){var r=F(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var Ee=ss;function q(t){var e=-1,r=t==null?0:t.length;for(this.clear();++e<r;){var o=t[e];this.set(o[0],o[1])}}q.prototype.clear=Oe;q.prototype.delete=Se;q.prototype.get=_e;q.prototype.has=Ie;q.prototype.set=Ee;var Ce=q;function is(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var ct=is;var fs=dt(Object.getPrototypeOf,Object),ht=fs;function ns(){this.__data__=new B,this.size=0}var Me=ns;function ps(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var Re=ps;function ls(t){return this.__data__.get(t)}var Be=ls;function ms(t){return this.__data__.has(t)}var Le=ms;var us=200;function ds(t,e){var r=this.__data__;if(r instanceof B){var o=r.__data__;if(!L||o.length<us-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new Ce(o)}return r.set(t,e),this.size=r.size,this}var Fe=ds;function H(t){var e=this.__data__=new B(t);this.size=e.size}H.prototype.clear=Me;H.prototype.delete=Re;H.prototype.get=Be;H.prototype.has=Le;H.prototype.set=Fe;var Ne=H;function cs(t,e){return t&&M(e,K(e),t)}var De=cs;function hs(t,e){return t&&M(e,W(e),t)}var ke=hs;var We=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ue=We&&typeof module=="object"&&module&&!module.nodeType&&module,xs=Ue&&Ue.exports===We,Ge=xs?x.Buffer:void 0,Ke=Ge?Ge.allocUnsafe:void 0;function gs(t,e){if(e)return t.slice();var r=t.length,o=Ke?Ke(r):new t.constructor(r);return t.copy(o),o}var ze=gs;function bs(t,e){for(var r=-1,o=t==null?0:t.length,a=0,p=[];++r<o;){var n=t[r];e(n,r,t)&&(p[a++]=n)}return p}var Ve=bs;function ys(){return[]}var xt=ys;var vs=Object.prototype,ws=vs.propertyIsEnumerable,qe=Object.getOwnPropertySymbols,js=qe?function(t){return t==null?[]:(t=Object(t),Ve(qe(t),function(e){return ws.call(t,e)}))}:xt,$=js;function Ts(t,e){return M(t,$(t),e)}var He=Ts;var As=Object.getOwnPropertySymbols,Os=As?function(t){for(var e=[];t;)ct(e,$(t)),t=ht(t);return e}:xt,gt=Os;function Ps(t,e){return M(t,gt(t),e)}var $e=Ps;function Ss(t,e,r){var o=e(t);return k(t)?o:ct(o,r(t))}var bt=Ss;function _s(t){return bt(t,K,$)}var Ye=_s;function Is(t){return bt(t,W,gt)}var Ze=Is;var Es=w(x,"DataView"),yt=Es;var Cs=w(x,"Promise"),vt=Cs;var Ms=w(x,"Set"),wt=Ms;var Je="[object Map]",Rs="[object Object]",Xe="[object Promise]",Qe="[object Set]",tr="[object WeakMap]",er="[object DataView]",Bs=I(yt),Ls=I(L),Fs=I(vt),Ns=I(wt),Ds=I(st),N=_;(yt&&N(new yt(new ArrayBuffer(1)))!=er||L&&N(new L)!=Je||vt&&N(vt.resolve())!=Xe||wt&&N(new wt)!=Qe||st&&N(new st)!=tr)&&(N=function(t){var e=_(t),r=e==Rs?t.constructor:void 0,o=r?I(r):"";if(o)switch(o){case Bs:return er;case Ls:return Je;case Fs:return Xe;case Ns:return Qe;case Ds:return tr}return e});var Y=N;var ks=Object.prototype,Us=ks.hasOwnProperty;function Gs(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&Us.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var rr=Gs;var Ks=x.Uint8Array,_t=Ks;function Ws(t){var e=new t.constructor(t.byteLength);return new _t(e).set(new _t(t)),e}var Z=Ws;function zs(t,e){var r=e?Z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var or=zs;var Vs=/\w*$/;function qs(t){var e=new t.constructor(t.source,Vs.exec(t));return e.lastIndex=t.lastIndex,e}var ar=qs;var sr=S?S.prototype:void 0,ir=sr?sr.valueOf:void 0;function Hs(t){return ir?Object(ir.call(t)):{}}var fr=Hs;function $s(t,e){var r=e?Z(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var nr=$s;var Ys="[object Boolean]",Zs="[object Date]",Js="[object Map]",Xs="[object Number]",Qs="[object RegExp]",ti="[object Set]",ei="[object String]",ri="[object Symbol]",oi="[object ArrayBuffer]",ai="[object DataView]",si="[object Float32Array]",ii="[object Float64Array]",fi="[object Int8Array]",ni="[object Int16Array]",pi="[object Int32Array]",li="[object Uint8Array]",mi="[object Uint8ClampedArray]",ui="[object Uint16Array]",di="[object Uint32Array]";function ci(t,e,r){var o=t.constructor;switch(e){case oi:return Z(t);case Ys:case Zs:return new o(+t);case ai:return or(t,r);case si:case ii:case fi:case ni:case pi:case li:case mi:case ui:case di:return nr(t,r);case Js:return new o;case Xs:case ei:return new o(t);case Qs:return ar(t);case ti:return new o;case ri:return fr(t)}}var pr=ci;function hi(t){return typeof t.constructor=="function"&&!U(t)?Zt(ht(t)):{}}var lr=hi;var xi="[object Map]";function gi(t){return T(t)&&Y(t)==xi}var mr=gi;var ur=E&&E.isMap,bi=ur?G(ur):mr,dr=bi;var yi="[object Set]";function vi(t){return T(t)&&Y(t)==yi}var cr=vi;var hr=E&&E.isSet,wi=hr?G(hr):cr,xr=wi;var ji=1,Ti=2,Ai=4,gr="[object Arguments]",Oi="[object Array]",Pi="[object Boolean]",Si="[object Date]",_i="[object Error]",br="[object Function]",Ii="[object GeneratorFunction]",Ei="[object Map]",Ci="[object Number]",yr="[object Object]",Mi="[object RegExp]",Ri="[object Set]",Bi="[object String]",Li="[object Symbol]",Fi="[object WeakMap]",Ni="[object ArrayBuffer]",Di="[object DataView]",ki="[object Float32Array]",Ui="[object Float64Array]",Gi="[object Int8Array]",Ki="[object Int16Array]",Wi="[object Int32Array]",zi="[object Uint8Array]",Vi="[object Uint8ClampedArray]",qi="[object Uint16Array]",Hi="[object Uint32Array]",u={};u[gr]=u[Oi]=u[Ni]=u[Di]=u[Pi]=u[Si]=u[ki]=u[Ui]=u[Gi]=u[Ki]=u[Wi]=u[Ei]=u[Ci]=u[yr]=u[Mi]=u[Ri]=u[Bi]=u[Li]=u[zi]=u[Vi]=u[qi]=u[Hi]=!0;u[_i]=u[br]=u[Fi]=!1;function jt(t,e,r,o,a,p){var n,s=e&ji,l=e&Ti,c=e&Ai;if(r&&(n=a?r(t,o,a,p):r(t)),n!==void 0)return n;if(!A(t))return t;var h=k(t);if(h){if(n=rr(t),!s)return Jt(t,n)}else{var y=Y(t),j=y==br||y==Ii;if(mt(t))return ze(t,s);if(y==yr||y==gr||j&&!a){if(n=l||j?{}:lr(t),!s)return l?$e(t,ke(n,t)):He(t,De(n,t))}else{if(!u[y])return a?t:{};n=pr(t,y,s)}}p||(p=new Ne);var v=p.get(t);if(v)return v;p.set(t,n),xr(t)?t.forEach(function(b){n.add(jt(b,e,r,b,t,p))}):dr(t)&&t.forEach(function(b,i){n.set(i,jt(b,e,r,i,t,p))});var g=c?l?Ze:Ye:l?W:K,O=h?void 0:g(t);return Xt(O||t,function(b,i){O&&(i=b,b=t[i]),nt(n,i,jt(b,e,r,i,t,p))}),n}var vr=jt;var $i=1,Yi=4;function Zi(t){return vr(t,$i|Yi)}var It=Zi;function wr(t){return{all:t=t||new Map,on:function(e,r){var o=t.get(e);o?o.push(r):t.set(e,[r])},off:function(e,r){var o=t.get(e);o&&(r?o.splice(o.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var o=t.get(e);o&&o.slice().map(function(a){a(r)}),(o=t.get("*"))&&o.slice().map(function(a){a(e,r)})}}}var Et=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((e,r)=>(r&=63,r<36?e+=r.toString(36):r<62?e+=(r-26).toString(36).toUpperCase():r>62?e+="-":e+="_",e),"");var Ji="array",Xi="bit",jr="bits",Qi="byte",Tr="bytes",J="",tf="exponent",ef="function",Ar="iec",rf="Invalid number",of="Invalid rounding method",Ct="jedec",af="object",Or=".",sf="round",ff="s",nf="si",pf="kbit",lf="kB",mf=" ",uf="string",df="0",Mt={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}};function Pr(t,{bits:e=!1,pad:r=!1,base:o=-1,round:a=2,locale:p=J,localeOptions:n={},separator:s=J,spacer:l=mf,symbols:c={},standard:h=J,output:y=uf,fullform:j=!1,fullforms:v=[],exponent:g=-1,roundingMethod:O=sf,precision:b=0}={}){let i=g,m=Number(t),f=[],P=0,Tt=J;h===nf?(o=10,h=Ct):h===Ar||h===Ct?o=2:o===2?h=Ar:(o=10,h=Ct);let et=o===10?1e3:1024,Sr=j===!0,Bt=m<0,Lt=Math[O];if(typeof t!="bigint"&&isNaN(t))throw new TypeError(rf);if(typeof Lt!==ef)throw new TypeError(of);if(Bt&&(m=-m),(i===-1||isNaN(i))&&(i=Math.floor(Math.log(m)/Math.log(et)),i<0&&(i=0)),i>8&&(b>0&&(b+=8-i),i=8),y===tf)return i;if(m===0)f[0]=0,Tt=f[1]=Mt.symbol[h][e?jr:Tr][i];else{P=m/(o===2?Math.pow(2,i*10):Math.pow(1e3,i)),e&&(P=P*8,P>=et&&i<8&&(P=P/et,i++));let X=Math.pow(10,i>0?a:0);f[0]=Lt(P*X)/X,f[0]===et&&i<8&&g===-1&&(f[0]=1,i++),Tt=f[1]=o===10&&i===1?e?pf:lf:Mt.symbol[h][e?jr:Tr][i]}if(Bt&&(f[0]=-f[0]),b>0&&(f[0]=f[0].toPrecision(b)),f[1]=c[f[1]]||f[1],p===!0?f[0]=f[0].toLocaleString():p.length>0?f[0]=f[0].toLocaleString(p,n):s.length>0&&(f[0]=f[0].toString().replace(Or,s)),r&&Number.isInteger(f[0])===!1&&a>0){let X=s||Or,Ft=f[0].toString().split(X),Nt=Ft[1]||J,Dt=Nt.length,_r=a-Dt;f[0]=`${Ft[0]}${X}${Nt.padEnd(Dt+_r,df)}`}return Sr&&(f[1]=v[i]?v[i]:Mt.fullform[h][i]+(e?Xi:Qi)+(f[0]===1?J:ff)),y===Ji?f:y===af?{value:f[0],symbol:f[1],exponent:i,unit:Tt}:f.join(l)}var D=class{tera;id;name;path;parsedName;created;createdFormatted;modified;modifiedFormatted;accessed;accessedFormatted;size;sizeFormatted;mime;constructor(e){if(!e.tera)throw new Error("Basic file requires a `tera` key to access the Tera instance");Object.assign(this,e),this.sizeFormatted=Pr(this.size||0,{spacer:""}),this.createdFormatted=this.created.toLocaleDateString(),this.modifiedFormatted=this.modified.toLocaleDateString(),this.accessedFormatted=this.accessed.toLocaleDateString()}getContents(){return this.tera.getProjectFile(this.path)}setContents(e){return this.tera.setProjectFile(this.path,e)}getRefs(){return this.tera.parseProjectLibrary(this.path)}setRefs(e){return this.tera.setProjectLibrary(this.path,e)}};var Rt=class{settings={devMode:!0,mode:"detect",modeTimeout:300,modeFallback:"child",siteUrl:"https://tera-tools.com/embed",restrictOrigin:"*",frameSandbox:["allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-top-navigation"],handshakeInterval:1e3};events=wr();dom={el:null,iframe:null,popup:null,stylesheet:null};methods=["handshake","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","saveProjectState","replaceProjectState","applyProjectStatePatch","setProjectFile","selectProjectLibrary","parseProjectLibrary","setProjectLibrary","uiAlert","uiSplat","uiWindow"];plugins=[];send(e){let r=Et();return this.acceptPostboxes[r]={},this.acceptPostboxes[r].promise=new Promise((o,a)=>{Object.assign(this.acceptPostboxes[r],{resolve:o,reject:a}),this.sendRaw({id:r,...e})}),this.acceptPostboxes[r].promise}sendRaw(e){let r;try{if(r={TERA:1,id:e.id||Et(),...It(e)},this.settings.mode=="parent")window.parent.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="child")this.dom.iframe.contentWindow.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="popup")this.dom.popup.postMessage(r,this.settings.restrictOrigin);else throw this.settings.mode=="detect"?new Error("Call init() or detectMode() before trying to send data to determine the mode"):new Error(`Unknown TERA communication mode "${this.settings.mode}"`)}catch(o){throw this.debug("ERROR","Message compose client->server:",o),this.debug("ERROR","Attempted to dispatch payload client->server",r),o}}rpc(e,...r){return this.send({action:"rpc",method:e,args:r})}acceptMessage(e){if(e.origin==window.location.origin)return;let r=e.data;if(!(!r.TERA||!r.id))if(this.debug("Recieved",r),r?.action=="response"&&this.acceptPostboxes[r.id])r.isError===!0?this.acceptPostboxes[r.id].reject(r.response):this.acceptPostboxes[r.id].resolve(r.response);else{if(r?.action=="rpc")return Promise.resolve().then(()=>this[r.method].apply(this,r.args)).then(o=>this.sendRaw({id:r.id,action:"response",response:o})).catch(o=>{console.warn(`TERA-FY client threw on RPC:${r.method}:`,o),this.sendRaw({id:r.id,action:"response",isError:!0,response:o.toString()})});if(r?.action=="event")return Promise.resolve().then(()=>this.events.emit(r.event,...r.payload)).catch(o=>{throw console.warn(`TERA-FY client threw while handling emitted event "${r.event}"`,{message:r}),o});r?.id?this.debug(`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("Unexpected incoming TERA-FY CLIENT message",{message:r})}}acceptPostboxes={};createProjectStatePatch(e,r){let o=kt(r,e,Ut);return this.debug("INFO","Created project patch",{newState:e,oldState:r}),this.applyProjectStatePatch(o)}applyProjectStatePatchLocal(e){throw new Error("applyProjectStatePatchLocal() has not been sub-classed by a plugin")}constructor(e){e&&this.set(e)}init(e){if(e&&this.set(e),this.init.promise)return this.init.promise;window.addEventListener("message",this.acceptMessage.bind(this));let r=this;return this.init.promise=Promise.resolve().then(()=>this.detectMode()).then(o=>this.settings.mode=o).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>this.rpc("setServerMode",this.settings.mode=="child"?"embedded":this.settings.mode=="parent"?"frame":this.settings.mode=="popup"?"popup":(()=>{throw`Unknown server mode "${this.settings.mode}"`})())).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings))))}detectMode(){return this.settings.mode!="detect"?this.settings.mode:window.self===window.parent?this.settings.modeFallback:Promise.resolve().then(()=>this.settings.mode="parent").then(()=>new Promise((e,r)=>{let o=setTimeout(()=>r(),this.settings.modeTimeout);this.rpc("handshake").then(()=>clearTimeout(o)).then(()=>e())})).then(()=>"parent").catch(()=>this.settings.modeFallback)}injectComms(){return new Promise(e=>{switch(this.settings.mode){case"child":this.debug("Injecting TERA site as iFrame child"),this.dom.el=document.createElement("div"),this.dom.el.id="tera-fy",this.dom.el.classList.toggle("dev-mode",this.settings.devMode),document.body.append(this.dom.el),this.dom.iframe=document.createElement("iframe"),this.dom.iframe.setAttribute("sandbox",this.settings.frameSandbox.join(" ")),this.dom.iframe.addEventListener("load",()=>{this.debug("Embed frame ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("Using TERA window parent"),e();break;case"popup":this.debug("Injecting TERA site as a popup window"),this.dom.popup=window.open(this.settings.siteUrl,"_blank","popup=1, location=0, menubar=0, status=0, scrollbars=0, width=500, height=600"),(()=>{let r=0,o,a=()=>{this.debug("Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("Popup window accepted handshake"),e()})};a()})();break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when calling injectComms()`)}})}injectStylesheet(){switch(this.settings.mode){case"child":this.dom.stylesheet=document.createElement("style"),this.dom.stylesheet.innerHTML=[":root {","--TERA-accent: #4d659c;","}","#tera-fy {","display: none;","position: fixed;","right: 50px;","bottom: 50px;","width: 300px;","height: 150px;","background: transparent;","&.dev-mode {","display: flex;","border: 5px solid var(--TERA-accent);","background: #FFF;","}","& > iframe {","width: 100%;","height: 100%;","}","}","body.tera-fy-focus {","overflow: hidden;","& #tera-fy {","display: flex !important;","position: fixed !important;","top: 0px !important;","width: 100vw !important;","height: 100vh !important;","left: 0px !important;","z-index: 10000 !important;","}","}"].join(`
2
+ `),document.head.appendChild(this.dom.stylesheet);break;case"parent":case"popup":break;default:throw new Error(`Unsupported mode "${this.settings.mode}" when injectStylesheet()`)}}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){let r="log";typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),!(["INFO","LOG"].includes(r)&&!this.settings.devMode)&&console[r]("%c[TERA-FY CLIENT]","font-weight: bold; color: #ff5722;",...e)}set(e,r){return typeof e=="string"?this.settings[e]=r:Object.assign(this.settings,e),this.toggleDevMode(this.settings.devMode)}setIfDev(e,r){return!this.settings.devMode||r===void 0?this:this.set(e,r)}use(e,r){if(typeof e!="function")throw new Error("Expected use() call to be provided with a class initalizer");let o=new e(this,r);return this.mixin(this,o),this.plugins.push(o),this}mixin(e,r){Object.getOwnPropertyNames(Object.getPrototypeOf(r)).filter(o=>!["constructor","prototype","name"].includes(o)).filter(o=>o!="init").forEach(o=>{Object.defineProperty(e,o,{value:r[o].bind(e),enumerable:!1})})}toggleDevMode(e="toggle"){return this.settings.devMode=e==="toggle"?!this.settings.devMode:e,this.dom.el&&this.dom.el.classList.toggle("dev-mode",this.settings.devMode),this}toggleFocus(e="toggle"){this.debug("Request focus",{isFocused:e}),globalThis.document.body.classList.toggle("tera-fy-focus",e==="toggle"?void 0:e)}selectProjectFile(e){return this.rpc("selectProjectFile",e).then(r=>r&&new D({tera:this,...r}))}getProjectFiles(e){return this.rpc("getProjectFiles",e).then(r=>r.map(o=>new D({tera:this,...o})))}getProjectFile(e){return this.rpc("getProjectFile",e).then(r=>r&&new D({tera:this,...r}))}};export{Rt as default};
3
3
  /*! Bundled license information:
4
4
 
5
5
  lodash-es/lodash.js:
@@ -12,4 +12,13 @@ lodash-es/lodash.js:
12
12
  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
13
13
  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
14
14
  *)
15
+
16
+ filesize/dist/filesize.esm.js:
17
+ (**
18
+ * filesize
19
+ *
20
+ * @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
21
+ * @license BSD-3-Clause
22
+ * @version 10.1.1
23
+ *)
15
24
  */
@@ -0,0 +1,179 @@
1
+ import {filesize} from 'filesize';
2
+
3
+ /**
4
+ * A project file fetched from TERA
5
+ * @class ProjectFile
6
+ */
7
+ export default class ProjectFile {
8
+
9
+ /**
10
+ * Parent TeraClient instance used by all helper functions
11
+ * @param {TeraClient}
12
+ */
13
+ tera;
14
+
15
+
16
+ /**
17
+ * A UUID string representing the unique ID of the file
18
+ * @type {String}
19
+ */
20
+ id;
21
+
22
+
23
+ /**
24
+ * Relative name path (can contain prefix directories) for the human readable file name
25
+ * @type {String}
26
+ */
27
+ name;
28
+
29
+
30
+ /**
31
+ * Full path to the file
32
+ * This is also used as the unique identifier within the project
33
+ * @type {String}
34
+ */
35
+ path;
36
+
37
+
38
+ /**
39
+ * An object representing meta file parts of a file name
40
+ * @type {Object}
41
+ * @property {String} basename The filename + extention (i.e. everything without directory name)
42
+ * @property {String} filename The file portion of the name (basename without the extension)
43
+ * @property {String} ext The extension portion of the name (always lower case)
44
+ * @property {String} dirName The directory path portion of the name
45
+ */
46
+ parsedName;
47
+
48
+
49
+ /**
50
+ * A date representing when the file was created
51
+ * @type {Date}
52
+ */
53
+ created;
54
+
55
+
56
+ /**
57
+ * A human readable, formatted version of "created"
58
+ * @type {String}
59
+ */
60
+ createdFormatted;
61
+
62
+
63
+ /**
64
+ * A date representing when the file was created
65
+ * @type {Date}
66
+ */
67
+ modified;
68
+
69
+
70
+ /**
71
+ * A human readable, formatted version of "modified"
72
+ * @type {String}
73
+ */
74
+ modifiedFormatted;
75
+
76
+
77
+ /**
78
+ * A date representing when the file was last accessed
79
+ * @type {Date}
80
+ */
81
+ accessed;
82
+
83
+
84
+ /**
85
+ * A human readable, formatted version of "accessed"
86
+ * @type {String}
87
+ */
88
+ accessedFormatted;
89
+
90
+
91
+ /**
92
+ * Size, in bytes, of the file
93
+ * @type {Number}
94
+ */
95
+ size;
96
+
97
+
98
+ /**
99
+ * A human readable, formatted version of the file size
100
+ * @type {String}
101
+ */
102
+ sizeFormatted;
103
+
104
+
105
+ /**
106
+ * The associated mime type for the file
107
+ * @type {String}
108
+ */
109
+ mime;
110
+
111
+
112
+ /**
113
+ * ProjectFile constructor
114
+ * Takes the input basic file type from Supabase and adds additional formatted fields
115
+ * @param {SupabaseFile} baseFile The basic Supabase file to extend
116
+ */
117
+ constructor(baseFile) {
118
+ if (!baseFile.tera) throw new Error('Basic file requires a `tera` key to access the Tera instance');
119
+ Object.assign(this, baseFile);
120
+
121
+ // Set all `*Formatted` fields
122
+ this.sizeFormatted = filesize(this.size || 0, {spacer: ''});
123
+ this.createdFormatted = this.created.toLocaleDateString();
124
+ this.modifiedFormatted = this.modified.toLocaleDateString();
125
+ this.accessedFormatted = this.accessed.toLocaleDateString();
126
+ }
127
+
128
+
129
+ /**
130
+ * Fetch the raw file contents as a Blob
131
+ *
132
+ * returns {Blob} The eventual raw file contents as a Blob
133
+ *
134
+ * @see getProjectFile()
135
+ */
136
+ getContents() {
137
+ return this.tera.getProjectFile(this.path);
138
+ }
139
+
140
+
141
+ /**
142
+ * Overwrite the contents of a file with new content
143
+ *
144
+ * @param {File|Blob|FormData|Object|Array} contents The new file contents
145
+ *
146
+ * @returns {Promise} A promise which resolves when the operation has completed
147
+ *
148
+ * @see setProjectFile()
149
+ */
150
+ setContents(contents) {
151
+ return this.tera.setProjectFile(this.path, contents);
152
+ }
153
+
154
+
155
+ /**
156
+ * Fetch the file contents as an array of Reflib refs
157
+ *
158
+ * @returns {Promise<Array<Ref>>} An eventual array of RefLib references
159
+ *
160
+ * @see parseProjectLibrary()
161
+ */
162
+ getRefs() {
163
+ return this.tera.parseProjectLibrary(this.path);
164
+ }
165
+
166
+
167
+ /**
168
+ * Overwrite the contents of a file with a new collection of Reflib refs
169
+ *
170
+ * @param {Array<RefLibRef>} Collection of references for the selected library
171
+ *
172
+ * @returns {Promise} A promise which resolves when the operation has completed
173
+ *
174
+ * @see setProjectLibrary()
175
+ */
176
+ setRefs(refs) {
177
+ return this.tera.setProjectLibrary(this.path, refs);
178
+ }
179
+ }
@@ -2,6 +2,7 @@ import {diff, jsonPatchPathConverter as jsPatchConverter} from 'just-diff';
2
2
  import {cloneDeep} from 'lodash-es';
3
3
  import Mitt from 'mitt';
4
4
  import {nanoid} from 'nanoid';
5
+ import ProjectFile from './projectFile.js';
5
6
 
6
7
  /* globals globalThis */
7
8
 
@@ -83,23 +84,41 @@ export default class TeraFy {
83
84
  'handshake',
84
85
 
85
86
  // Session
86
- 'getUser', 'requireUser',
87
+ 'getUser',
88
+ 'requireUser',
87
89
 
88
90
  // Projects
89
- 'bindProject', 'getProject', 'getProjects', 'setActiveProject', 'requireProject', 'selectProject',
91
+ 'bindProject',
92
+ 'getProject',
93
+ 'getProjects',
94
+ 'setActiveProject',
95
+ 'requireProject',
96
+ 'selectProject',
90
97
 
91
98
  // Project State
92
- 'getProjectState', 'setProjectState', 'setProjectStateDefaults', 'saveProjectState', 'replaceProjectState', 'applyProjectStatePatch',
99
+ 'getProjectState',
100
+ 'setProjectState',
101
+ 'setProjectStateDefaults',
102
+ 'saveProjectState',
103
+ 'replaceProjectState',
104
+ 'applyProjectStatePatch',
93
105
  // For bindProjectState() - See individual plugins
94
106
 
95
107
  // Project files
96
- 'selectProjectFile', 'getProjectFiles',
108
+ // 'selectProjectFile', - Handled below (requires return collection mapped to ProjectFile)
109
+ // 'getProjectFiles', - Handled below (requires return collection mapped to ProjectFile)
110
+ // 'getProjectFile', - Handled below (requires return mapped to ProjectFile)
111
+ 'setProjectFile',
97
112
 
98
113
  // Project Libraries
99
- 'selectProjectLibrary', 'parseProjectLibrary', 'setProjectLibrary',
114
+ 'selectProjectLibrary',
115
+ 'parseProjectLibrary',
116
+ 'setProjectLibrary',
100
117
 
101
118
  // UI
102
- 'uiAlert', 'uiSplat', 'uiWindow',
119
+ 'uiAlert',
120
+ 'uiSplat',
121
+ 'uiWindow',
103
122
  ];
104
123
 
105
124
 
@@ -818,25 +837,6 @@ export default class TeraFy {
818
837
  */
819
838
 
820
839
 
821
- /**
822
- * Data structure for a project file
823
- *
824
- * @name ProjectFile
825
- *
826
- * @property {String} id A UUID string representing the unique ID of the file
827
- * @property {String} name Relative name path (can contain prefix directories) for the human readable file name
828
- * @property {Object} parsedName An object representing meta file parts of a file name
829
- * @property {String} parsedName.basename The filename + extention (i.e. everything without directory name)
830
- * @property {String} parsedName.filename The file portion of the name (basename without the extension)
831
- * @property {String} parsedName.ext The extension portion of the name (always lower case)
832
- * @property {String} parsedName.dirName The directory path portion of the name
833
- * @property {Date} created A date representing when the file was created
834
- * @property {Date} modified A date representing when the file was created
835
- * @property {Date} accessed A date representing when the file was last accessed
836
- * @property {Number} size Size, in bytes, of the file
837
- * @property {String} mime The associated mime type for the file
838
- */
839
-
840
840
  /**
841
841
  * Data structure for a file filter
842
842
  * @name FileFilters
@@ -865,18 +865,64 @@ export default class TeraFy {
865
865
  *
866
866
  * @returns {Promise<ProjectFile>} The eventually selected file
867
867
  */
868
+ selectProjectFile(options) {
869
+ return this.rpc('selectProjectFile', options)
870
+ .then(file => file
871
+ ? new ProjectFile({
872
+ tera: this,
873
+ ...file,
874
+ })
875
+ : file
876
+ )
877
+ }
868
878
 
869
879
 
870
880
  /**
871
881
  * Fetch the files associated with a given project
872
882
  *
873
- * @function getProjectFiles
874
883
  * @param {Object} options Options which mutate behaviour
875
884
  * @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
876
885
  * @param {Boolean} [options.meta=true] Pull meta information for each file entity
877
886
  *
878
887
  * @returns {Promise<Array<ProjectFile>>} A collection of project files for the given project
879
888
  */
889
+ getProjectFiles(options) {
890
+ return this.rpc('getProjectFiles', options)
891
+ .then(files => files.map(file =>
892
+ new ProjectFile({
893
+ tera: this,
894
+ ...file,
895
+ })
896
+ ))
897
+ }
898
+
899
+
900
+ /**
901
+ * Fetch a project file
902
+ *
903
+ * @param {String} path File path to read
904
+ * @returns {Promise<Blob>} The eventual fetched file as a blob
905
+ */
906
+ getProjectFile(path) {
907
+ return this.rpc('getProjectFile', path)
908
+ .then(file => file
909
+ ? new ProjectFile({
910
+ tera: this,
911
+ ...file,
912
+ })
913
+ : file
914
+ )
915
+ }
916
+
917
+
918
+ /**
919
+ * Replace a project files contents
920
+ *
921
+ * @function setProjectFile
922
+ * @param {String} path File path to write
923
+ * @param {File|Blob|FormData|Object|Array} contents The new file contents
924
+ * @returns {Promise} A promise which will resolve when the write operation has completed
925
+ */
880
926
 
881
927
 
882
928
  /**