@iebh/tera-fy 1.7.4 → 1.9.0

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 uo=Object.defineProperty;var co=(t,e,r)=>e in t?uo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var d=(t,e,r)=>(co(t,typeof e!="symbol"?e+"":e,r),r);function Yt(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(i){return i});function o({obj1:i,obj2:f,basePath:m,basePathForRemoves:x,diffs:v}){var P=Object.keys(i),O=P.length,y=Object.keys(f),_=y.length,b,p=i.length-f.length;if(xo(i,f)){for(var u=0;u<O;u++){var l=Array.isArray(i)?Number(P[u]):P[u];l in f||(b=x.concat(l),v.remove.push({op:"remove",path:r(b)}))}for(var u=0;u<_;u++){var l=Array.isArray(f)?Number(y[u]):y[u];s({key:l,obj1:i,obj2:f,path:m.concat(l),pathForRemoves:m.concat(l),diffs:v})}}else{for(var u=0;u<p;u++)b=x.concat(u),v.remove.push({op:"remove",path:r(b)});for(var E=i.slice(p),u=0;u<_;u++)s({key:u,obj1:E,obj2:f,path:m.concat(u),pathForRemoves:m.concat(u+p),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 s({key:i,obj1:f,obj2:m,path:x,pathForRemoves:v,diffs:P}){var O=f[i],y=m[i];if(!(i in f)&&i in m){var _=y;P.add.push({op:"add",path:r(x),value:_})}else O!==y&&(Object(O)!==O||Object(y)!==y||ho(O,y)||!Object.keys(O).length&&!Object.keys(y).length&&String(O)!=String(y)?n(x,P,y):o({obj1:f[i],obj2:m[i],basePath:x,basePathForRemoves:v,diffs:P}))}function n(i,f,m){f.replace.push({op:"replace",path:r(i),value:m})}}function Vt(t){return[""].concat(t).join("/")}function ho(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function xo(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,s=0;s<e.length&&String(t[s])===String(e[s]);s++)o++;for(var n=e.length;n>0&&String(t[n+r])===String(e[n]);n--)a++;return o>=a}return!0}var go=typeof global=="object"&&global&&global.Object===Object&&global,dt=go;var yo=typeof self=="object"&&self&&self.Object===Object&&self,bo=dt||yo||Function("return this")(),g=bo;var vo=g.Symbol,T=vo;var Zt=Object.prototype,wo=Zt.hasOwnProperty,To=Zt.toString,pt=T?T.toStringTag:void 0;function Oo(t){var e=wo.call(t,pt),r=t[pt];try{t[pt]=void 0;var o=!0}catch{}var a=To.call(t);return o&&(e?t[pt]=r:delete t[pt]),a}var Jt=Oo;var jo=Object.prototype,Po=jo.toString;function So(t){return Po.call(t)}var Xt=So;var Ao="[object Null]",Io="[object Undefined]",Qt=T?T.toStringTag:void 0;function _o(t){return t==null?t===void 0?Io:Ao:Qt&&Qt in Object(t)?Jt(t):Xt(t)}var I=_o;function Eo(t){return t!=null&&typeof t=="object"}var A=Eo;var Co="[object Symbol]";function Fo(t){return typeof t=="symbol"||A(t)&&I(t)==Co}var K=Fo;function Mo(t,e){for(var r=-1,o=t==null?0:t.length,a=Array(o);++r<o;)a[r]=e(t[r],r,t);return a}var te=Mo;var No=Array.isArray,w=No;var Ro=1/0,ee=T?T.prototype:void 0,re=ee?ee.toString:void 0;function oe(t){if(typeof t=="string")return t;if(w(t))return te(t,oe)+"";if(K(t))return re?re.call(t):"";var e=t+"";return e=="0"&&1/t==-Ro?"-0":e}var ae=oe;function Bo(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var S=Bo;function Lo(t){return t}var ie=Lo;var Do="[object AsyncFunction]",Uo="[object Function]",ko="[object GeneratorFunction]",zo="[object Proxy]";function Ko(t){if(!S(t))return!1;var e=I(t);return e==Uo||e==ko||e==Do||e==zo}var ct=Ko;var Go=g["__core-js_shared__"],ht=Go;var se=function(){var t=/[^.]+$/.exec(ht&&ht.keys&&ht.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Wo(t){return!!se&&se in t}var ne=Wo;var $o=Function.prototype,Ho=$o.toString;function qo(t){if(t!=null){try{return Ho.call(t)}catch{}try{return t+""}catch{}}return""}var C=qo;var Yo=/[\\^$.*+?()[\]{}|]/g,Vo=/^\[object .+?Constructor\]$/,Zo=Function.prototype,Jo=Object.prototype,Xo=Zo.toString,Qo=Jo.hasOwnProperty,ta=RegExp("^"+Xo.call(Qo).replace(Yo,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ea(t){if(!S(t)||ne(t))return!1;var e=ct(t)?ta:Vo;return e.test(C(t))}var fe=ea;function ra(t,e){return t==null?void 0:t[e]}var pe=ra;function oa(t,e){var r=pe(t,e);return fe(r)?r:void 0}var j=oa;var aa=j(g,"WeakMap"),xt=aa;var le=Object.create,ia=function(){function t(){}return function(e){if(!S(e))return{};if(le)return le(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),me=ia;function sa(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}var ue=sa;function na(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var de=na;var fa=800,pa=16,la=Date.now;function ma(t){var e=0,r=0;return function(){var o=la(),a=pa-(o-r);if(r=o,a>0){if(++e>=fa)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var ce=ma;function ua(t){return function(){return t}}var he=ua;var da=function(){try{var t=j(Object,"defineProperty");return t({},"",{}),t}catch{}}(),G=da;var ca=G?function(t,e){return G(t,"toString",{configurable:!0,enumerable:!1,value:he(e),writable:!0})}:ie,xe=ca;var ha=ce(xe),ge=ha;function xa(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var ye=xa;var ga=9007199254740991,ya=/^(?:0|[1-9]\d*)$/;function ba(t,e){var r=typeof t;return e=e==null?ga:e,!!e&&(r=="number"||r!="symbol"&&ya.test(t))&&t>-1&&t%1==0&&t<e}var W=ba;function va(t,e,r){e=="__proto__"&&G?G(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var gt=va;function wa(t,e){return t===e||t!==t&&e!==e}var yt=wa;var Ta=Object.prototype,Oa=Ta.hasOwnProperty;function ja(t,e,r){var o=t[e];(!(Oa.call(t,e)&&yt(o,r))||r===void 0&&!(e in t))&&gt(t,e,r)}var $=ja;function Pa(t,e,r,o){var a=!r;r||(r={});for(var s=-1,n=e.length;++s<n;){var i=e[s],f=o?o(r[i],t[i],i,r,t):void 0;f===void 0&&(f=t[i]),a?gt(r,i,f):$(r,i,f)}return r}var N=Pa;var be=Math.max;function Sa(t,e,r){return e=be(e===void 0?t.length-1:e,0),function(){for(var o=arguments,a=-1,s=be(o.length-e,0),n=Array(s);++a<s;)n[a]=o[e+a];a=-1;for(var i=Array(e+1);++a<e;)i[a]=o[a];return i[e]=r(n),ue(t,this,i)}}var ve=Sa;var Aa=9007199254740991;function Ia(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Aa}var H=Ia;function _a(t){return t!=null&&H(t.length)&&!ct(t)}var bt=_a;var Ea=Object.prototype;function Ca(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Ea;return t===r}var q=Ca;function Fa(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var we=Fa;var Ma="[object Arguments]";function Na(t){return A(t)&&I(t)==Ma}var Mt=Na;var Te=Object.prototype,Ra=Te.hasOwnProperty,Ba=Te.propertyIsEnumerable,La=Mt(function(){return arguments}())?Mt:function(t){return A(t)&&Ra.call(t,"callee")&&!Ba.call(t,"callee")},Y=La;function Da(){return!1}var Oe=Da;var Se=typeof exports=="object"&&exports&&!exports.nodeType&&exports,je=Se&&typeof module=="object"&&module&&!module.nodeType&&module,Ua=je&&je.exports===Se,Pe=Ua?g.Buffer:void 0,ka=Pe?Pe.isBuffer:void 0,za=ka||Oe,vt=za;var Ka="[object Arguments]",Ga="[object Array]",Wa="[object Boolean]",$a="[object Date]",Ha="[object Error]",qa="[object Function]",Ya="[object Map]",Va="[object Number]",Za="[object Object]",Ja="[object RegExp]",Xa="[object Set]",Qa="[object String]",ti="[object WeakMap]",ei="[object ArrayBuffer]",ri="[object DataView]",oi="[object Float32Array]",ai="[object Float64Array]",ii="[object Int8Array]",si="[object Int16Array]",ni="[object Int32Array]",fi="[object Uint8Array]",pi="[object Uint8ClampedArray]",li="[object Uint16Array]",mi="[object Uint32Array]",h={};h[oi]=h[ai]=h[ii]=h[si]=h[ni]=h[fi]=h[pi]=h[li]=h[mi]=!0;h[Ka]=h[Ga]=h[ei]=h[Wa]=h[ri]=h[$a]=h[Ha]=h[qa]=h[Ya]=h[Va]=h[Za]=h[Ja]=h[Xa]=h[Qa]=h[ti]=!1;function ui(t){return A(t)&&H(t.length)&&!!h[I(t)]}var Ae=ui;function di(t){return function(e){return t(e)}}var V=di;var Ie=typeof exports=="object"&&exports&&!exports.nodeType&&exports,lt=Ie&&typeof module=="object"&&module&&!module.nodeType&&module,ci=lt&&lt.exports===Ie,Nt=ci&&dt.process,hi=function(){try{var t=lt&&lt.require&&lt.require("util").types;return t||Nt&&Nt.binding&&Nt.binding("util")}catch{}}(),F=hi;var _e=F&&F.isTypedArray,xi=_e?V(_e):Ae,Ee=xi;var gi=Object.prototype,yi=gi.hasOwnProperty;function bi(t,e){var r=w(t),o=!r&&Y(t),a=!r&&!o&&vt(t),s=!r&&!o&&!a&&Ee(t),n=r||o||a||s,i=n?we(t.length,String):[],f=i.length;for(var m in t)(e||yi.call(t,m))&&!(n&&(m=="length"||a&&(m=="offset"||m=="parent")||s&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||W(m,f)))&&i.push(m);return i}var wt=bi;function vi(t,e){return function(r){return t(e(r))}}var Tt=vi;var wi=Tt(Object.keys,Object),Ce=wi;var Ti=Object.prototype,Oi=Ti.hasOwnProperty;function ji(t){if(!q(t))return Ce(t);var e=[];for(var r in Object(t))Oi.call(t,r)&&r!="constructor"&&e.push(r);return e}var Fe=ji;function Pi(t){return bt(t)?wt(t):Fe(t)}var Z=Pi;function Si(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var Me=Si;var Ai=Object.prototype,Ii=Ai.hasOwnProperty;function _i(t){if(!S(t))return Me(t);var e=q(t),r=[];for(var o in t)o=="constructor"&&(e||!Ii.call(t,o))||r.push(o);return r}var Ne=_i;function Ei(t){return bt(t)?wt(t,!0):Ne(t)}var J=Ei;var Ci=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Fi=/^\w*$/;function Mi(t,e){if(w(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||K(t)?!0:Fi.test(t)||!Ci.test(t)||e!=null&&t in Object(e)}var Re=Mi;var Ni=j(Object,"create"),M=Ni;function Ri(){this.__data__=M?M(null):{},this.size=0}var Be=Ri;function Bi(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Le=Bi;var Li="__lodash_hash_undefined__",Di=Object.prototype,Ui=Di.hasOwnProperty;function ki(t){var e=this.__data__;if(M){var r=e[t];return r===Li?void 0:r}return Ui.call(e,t)?e[t]:void 0}var De=ki;var zi=Object.prototype,Ki=zi.hasOwnProperty;function Gi(t){var e=this.__data__;return M?e[t]!==void 0:Ki.call(e,t)}var Ue=Gi;var Wi="__lodash_hash_undefined__";function $i(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=M&&e===void 0?Wi:e,this}var ke=$i;function X(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])}}X.prototype.clear=Be;X.prototype.delete=Le;X.prototype.get=De;X.prototype.has=Ue;X.prototype.set=ke;var Rt=X;function Hi(){this.__data__=[],this.size=0}var ze=Hi;function qi(t,e){for(var r=t.length;r--;)if(yt(t[r][0],e))return r;return-1}var R=qi;var Yi=Array.prototype,Vi=Yi.splice;function Zi(t){var e=this.__data__,r=R(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Vi.call(e,r,1),--this.size,!0}var Ke=Zi;function Ji(t){var e=this.__data__,r=R(e,t);return r<0?void 0:e[r][1]}var Ge=Ji;function Xi(t){return R(this.__data__,t)>-1}var We=Xi;function Qi(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 $e=Qi;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=ze;Q.prototype.delete=Ke;Q.prototype.get=Ge;Q.prototype.has=We;Q.prototype.set=$e;var B=Q;var ts=j(g,"Map"),L=ts;function es(){this.size=0,this.__data__={hash:new Rt,map:new(L||B),string:new Rt}}var He=es;function rs(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var qe=rs;function os(t,e){var r=t.__data__;return qe(e)?r[typeof e=="string"?"string":"hash"]:r.map}var D=os;function as(t){var e=D(this,t).delete(t);return this.size-=e?1:0,e}var Ye=as;function is(t){return D(this,t).get(t)}var Ve=is;function ss(t){return D(this,t).has(t)}var Ze=ss;function ns(t,e){var r=D(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var Je=ns;function tt(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])}}tt.prototype.clear=He;tt.prototype.delete=Ye;tt.prototype.get=Ve;tt.prototype.has=Ze;tt.prototype.set=Je;var mt=tt;var fs="Expected a function";function Bt(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError(fs);var r=function(){var o=arguments,a=e?e.apply(this,o):o[0],s=r.cache;if(s.has(a))return s.get(a);var n=t.apply(this,o);return r.cache=s.set(a,n)||s,n};return r.cache=new(Bt.Cache||mt),r}Bt.Cache=mt;var Xe=Bt;var ps=500;function ls(t){var e=Xe(t,function(o){return r.size===ps&&r.clear(),o}),r=e.cache;return e}var Qe=ls;var ms=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,us=/\\(\\)?/g,ds=Qe(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(ms,function(r,o,a,s){e.push(a?s.replace(us,"$1"):o||r)}),e}),tr=ds;function cs(t){return t==null?"":ae(t)}var er=cs;function hs(t,e){return w(t)?t:Re(t,e)?[t]:tr(er(t))}var U=hs;var xs=1/0;function gs(t){if(typeof t=="string"||K(t))return t;var e=t+"";return e=="0"&&1/t==-xs?"-0":e}var et=gs;function ys(t,e){e=U(e,t);for(var r=0,o=e.length;t!=null&&r<o;)t=t[et(e[r++])];return r&&r==o?t:void 0}var rr=ys;function bs(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var rt=bs;var or=T?T.isConcatSpreadable:void 0;function vs(t){return w(t)||Y(t)||!!(or&&t&&t[or])}var ar=vs;function ir(t,e,r,o,a){var s=-1,n=t.length;for(r||(r=ar),a||(a=[]);++s<n;){var i=t[s];e>0&&r(i)?e>1?ir(i,e-1,r,o,a):rt(a,i):o||(a[a.length]=i)}return a}var sr=ir;function ws(t){var e=t==null?0:t.length;return e?sr(t,1):[]}var nr=ws;function Ts(t){return ge(ve(t,void 0,nr),t+"")}var fr=Ts;var Os=Tt(Object.getPrototypeOf,Object),Ot=Os;function js(){this.__data__=new B,this.size=0}var pr=js;function Ps(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var lr=Ps;function Ss(t){return this.__data__.get(t)}var mr=Ss;function As(t){return this.__data__.has(t)}var ur=As;var Is=200;function _s(t,e){var r=this.__data__;if(r instanceof B){var o=r.__data__;if(!L||o.length<Is-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new mt(o)}return r.set(t,e),this.size=r.size,this}var dr=_s;function ot(t){var e=this.__data__=new B(t);this.size=e.size}ot.prototype.clear=pr;ot.prototype.delete=lr;ot.prototype.get=mr;ot.prototype.has=ur;ot.prototype.set=dr;var cr=ot;function Es(t,e){return t&&N(e,Z(e),t)}var hr=Es;function Cs(t,e){return t&&N(e,J(e),t)}var xr=Cs;var vr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,gr=vr&&typeof module=="object"&&module&&!module.nodeType&&module,Fs=gr&&gr.exports===vr,yr=Fs?g.Buffer:void 0,br=yr?yr.allocUnsafe:void 0;function Ms(t,e){if(e)return t.slice();var r=t.length,o=br?br(r):new t.constructor(r);return t.copy(o),o}var wr=Ms;function Ns(t,e){for(var r=-1,o=t==null?0:t.length,a=0,s=[];++r<o;){var n=t[r];e(n,r,t)&&(s[a++]=n)}return s}var Tr=Ns;function Rs(){return[]}var jt=Rs;var Bs=Object.prototype,Ls=Bs.propertyIsEnumerable,Or=Object.getOwnPropertySymbols,Ds=Or?function(t){return t==null?[]:(t=Object(t),Tr(Or(t),function(e){return Ls.call(t,e)}))}:jt,at=Ds;function Us(t,e){return N(t,at(t),e)}var jr=Us;var ks=Object.getOwnPropertySymbols,zs=ks?function(t){for(var e=[];t;)rt(e,at(t)),t=Ot(t);return e}:jt,Pt=zs;function Ks(t,e){return N(t,Pt(t),e)}var Pr=Ks;function Gs(t,e,r){var o=e(t);return w(t)?o:rt(o,r(t))}var St=Gs;function Ws(t){return St(t,Z,at)}var Sr=Ws;function $s(t){return St(t,J,Pt)}var Ar=$s;var Hs=j(g,"DataView"),At=Hs;var qs=j(g,"Promise"),It=qs;var Ys=j(g,"Set"),_t=Ys;var Ir="[object Map]",Vs="[object Object]",_r="[object Promise]",Er="[object Set]",Cr="[object WeakMap]",Fr="[object DataView]",Zs=C(At),Js=C(L),Xs=C(It),Qs=C(_t),tn=C(xt),z=I;(At&&z(new At(new ArrayBuffer(1)))!=Fr||L&&z(new L)!=Ir||It&&z(It.resolve())!=_r||_t&&z(new _t)!=Er||xt&&z(new xt)!=Cr)&&(z=function(t){var e=I(t),r=e==Vs?t.constructor:void 0,o=r?C(r):"";if(o)switch(o){case Zs:return Fr;case Js:return Ir;case Xs:return _r;case Qs:return Er;case tn:return Cr}return e});var it=z;var en=Object.prototype,rn=en.hasOwnProperty;function on(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&rn.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var Mr=on;var an=g.Uint8Array,Lt=an;function sn(t){var e=new t.constructor(t.byteLength);return new Lt(e).set(new Lt(t)),e}var st=sn;function nn(t,e){var r=e?st(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var Nr=nn;var fn=/\w*$/;function pn(t){var e=new t.constructor(t.source,fn.exec(t));return e.lastIndex=t.lastIndex,e}var Rr=pn;var Br=T?T.prototype:void 0,Lr=Br?Br.valueOf:void 0;function ln(t){return Lr?Object(Lr.call(t)):{}}var Dr=ln;function mn(t,e){var r=e?st(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var Ur=mn;var un="[object Boolean]",dn="[object Date]",cn="[object Map]",hn="[object Number]",xn="[object RegExp]",gn="[object Set]",yn="[object String]",bn="[object Symbol]",vn="[object ArrayBuffer]",wn="[object DataView]",Tn="[object Float32Array]",On="[object Float64Array]",jn="[object Int8Array]",Pn="[object Int16Array]",Sn="[object Int32Array]",An="[object Uint8Array]",In="[object Uint8ClampedArray]",_n="[object Uint16Array]",En="[object Uint32Array]";function Cn(t,e,r){var o=t.constructor;switch(e){case vn:return st(t);case un:case dn:return new o(+t);case wn:return Nr(t,r);case Tn:case On:case jn:case Pn:case Sn:case An:case In:case _n:case En:return Ur(t,r);case cn:return new o;case hn:case yn:return new o(t);case xn:return Rr(t);case gn:return new o;case bn:return Dr(t)}}var kr=Cn;function Fn(t){return typeof t.constructor=="function"&&!q(t)?me(Ot(t)):{}}var zr=Fn;var Mn="[object Map]";function Nn(t){return A(t)&&it(t)==Mn}var Kr=Nn;var Gr=F&&F.isMap,Rn=Gr?V(Gr):Kr,Wr=Rn;var Bn="[object Set]";function Ln(t){return A(t)&&it(t)==Bn}var $r=Ln;var Hr=F&&F.isSet,Dn=Hr?V(Hr):$r,qr=Dn;var Un=1,kn=2,zn=4,Yr="[object Arguments]",Kn="[object Array]",Gn="[object Boolean]",Wn="[object Date]",$n="[object Error]",Vr="[object Function]",Hn="[object GeneratorFunction]",qn="[object Map]",Yn="[object Number]",Zr="[object Object]",Vn="[object RegExp]",Zn="[object Set]",Jn="[object String]",Xn="[object Symbol]",Qn="[object WeakMap]",tf="[object ArrayBuffer]",ef="[object DataView]",rf="[object Float32Array]",of="[object Float64Array]",af="[object Int8Array]",sf="[object Int16Array]",nf="[object Int32Array]",ff="[object Uint8Array]",pf="[object Uint8ClampedArray]",lf="[object Uint16Array]",mf="[object Uint32Array]",c={};c[Yr]=c[Kn]=c[tf]=c[ef]=c[Gn]=c[Wn]=c[rf]=c[of]=c[af]=c[sf]=c[nf]=c[qn]=c[Yn]=c[Zr]=c[Vn]=c[Zn]=c[Jn]=c[Xn]=c[ff]=c[pf]=c[lf]=c[mf]=!0;c[$n]=c[Vr]=c[Qn]=!1;function Et(t,e,r,o,a,s){var n,i=e&Un,f=e&kn,m=e&zn;if(r&&(n=a?r(t,o,a,s):r(t)),n!==void 0)return n;if(!S(t))return t;var x=w(t);if(x){if(n=Mr(t),!i)return de(t,n)}else{var v=it(t),P=v==Vr||v==Hn;if(vt(t))return wr(t,i);if(v==Zr||v==Yr||P&&!a){if(n=f||P?{}:zr(t),!i)return f?Pr(t,xr(n,t)):jr(t,hr(n,t))}else{if(!c[v])return a?t:{};n=kr(t,v,i)}}s||(s=new cr);var O=s.get(t);if(O)return O;s.set(t,n),qr(t)?t.forEach(function(b){n.add(Et(b,e,r,b,t,s))}):Wr(t)&&t.forEach(function(b,p){n.set(p,Et(b,e,r,p,t,s))});var y=m?f?Ar:Sr:f?J:Z,_=x?void 0:y(t);return ye(_||t,function(b,p){_&&(p=b,b=t[p]),$(n,p,Et(b,e,r,p,t,s))}),n}var Jr=Et;var uf=1,df=4;function cf(t){return Jr(t,uf|df)}var Dt=cf;function hf(t,e){return t!=null&&e in Object(t)}var Xr=hf;function xf(t,e,r){e=U(e,t);for(var o=-1,a=e.length,s=!1;++o<a;){var n=et(e[o]);if(!(s=t!=null&&r(t,n)))break;t=t[n]}return s||++o!=a?s:(a=t==null?0:t.length,!!a&&H(a)&&W(n,a)&&(w(t)||Y(t)))}var Qr=xf;function gf(t,e){return t!=null&&Qr(t,e,Xr)}var to=gf;function yf(t,e,r,o){if(!S(t))return t;e=U(e,t);for(var a=-1,s=e.length,n=s-1,i=t;i!=null&&++a<s;){var f=et(e[a]),m=r;if(f==="__proto__"||f==="constructor"||f==="prototype")return t;if(a!=n){var x=i[f];m=o?o(x,f,i):void 0,m===void 0&&(m=S(x)?x:W(e[a+1])?[]:{})}$(i,f,m),i=i[f]}return t}var eo=yf;function bf(t,e,r){for(var o=-1,a=e.length,s={};++o<a;){var n=e[o],i=rr(t,n);r(i,n)&&eo(s,U(n,t),i)}return s}var ro=bf;function vf(t,e){return ro(t,e,function(r,o){return to(t,o)})}var oo=vf;var wf=fr(function(t,e){return t==null?{}:oo(t,e)}),Ct=wf;function ao(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 Ut=(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",Of="bit",io="bits",jf="byte",so="bytes",nt="",Pf="exponent",Sf="function",no="iec",Af="Invalid number",If="Invalid rounding method",kt="jedec",_f="object",fo=".",Ef="round",Cf="s",Ff="si",Mf="kbit",Nf="kB",Rf=" ",Bf="string",Lf="0",zt={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 po(t,{bits:e=!1,pad:r=!1,base:o=-1,round:a=2,locale:s=nt,localeOptions:n={},separator:i=nt,spacer:f=Rf,symbols:m={},standard:x=nt,output:v=Bf,fullform:P=!1,fullforms:O=[],exponent:y=-1,roundingMethod:_=Ef,precision:b=0}={}){let p=y,u=Number(t),l=[],E=0,Ft=nt;x===Ff?(o=10,x=kt):x===no||x===kt?o=2:o===2?x=no:(o=10,x=kt);let ut=o===10?1e3:1024,lo=P===!0,Gt=u<0,Wt=Math[_];if(typeof t!="bigint"&&isNaN(t))throw new TypeError(Af);if(typeof Wt!==Sf)throw new TypeError(If);if(Gt&&(u=-u),(p===-1||isNaN(p))&&(p=Math.floor(Math.log(u)/Math.log(ut)),p<0&&(p=0)),p>8&&(b>0&&(b+=8-p),p=8),v===Pf)return p;if(u===0)l[0]=0,Ft=l[1]=zt.symbol[x][e?io:so][p];else{E=u/(o===2?Math.pow(2,p*10):Math.pow(1e3,p)),e&&(E=E*8,E>=ut&&p<8&&(E=E/ut,p++));let ft=Math.pow(10,p>0?a:0);l[0]=Wt(E*ft)/ft,l[0]===ut&&p<8&&y===-1&&(l[0]=1,p++),Ft=l[1]=o===10&&p===1?e?Mf:Nf:zt.symbol[x][e?io:so][p]}if(Gt&&(l[0]=-l[0]),b>0&&(l[0]=l[0].toPrecision(b)),l[1]=m[l[1]]||l[1],s===!0?l[0]=l[0].toLocaleString():s.length>0?l[0]=l[0].toLocaleString(s,n):i.length>0&&(l[0]=l[0].toString().replace(fo,i)),r&&Number.isInteger(l[0])===!1&&a>0){let ft=i||fo,$t=l[0].toString().split(ft),Ht=$t[1]||nt,qt=Ht.length,mo=a-qt;l[0]=`${$t[0]}${ft}${Ht.padEnd(qt+mo,Lf)}`}return lo&&(l[1]=O[p]?O[p]:zt.fullform[x][p]+(e?Of:jf)+(l[0]===1?nt:Cf)),v===Tf?l:v===_f?{value:l[0],symbol:l[1],exponent:p,unit:Ft}:l.join(f)}var k=class t{constructor(e){d(this,"_tera");d(this,"id");d(this,"name");d(this,"icon");d(this,"path");d(this,"url");d(this,"teraUrl");d(this,"parsedName");d(this,"created");d(this,"createdFormatted");d(this,"modified");d(this,"modifiedFormatted");d(this,"accessed");d(this,"accessedFormatted");d(this,"size");d(this,"sizeFormatted");d(this,"mime");d(this,"meta",{});if(!e.tera)throw new Error("Basic file requires a `tera` key to access the Tera instance");Object.assign(this,e);let r=this.tera;Object.defineProperty(this,"_tera",{enumerable:!1,configurable:!1,get(){return r}}),delete this.tera,this.teraUrl=this.url.replace(/^https:\/\/tera-tools.com\/projects\/(?:.+?)\/(.+)$/,"/project/$1"),this.sizeFormatted=po(this.size||0,{spacer:""}),this.createdFormatted=this.created?this.created.toLocaleDateString():"Unknown created date",this.modifiedFormatted=this.modified?this.modified.toLocaleDateString():"Unknown modified date",this.accessedFormatted=this.accessed?this.accessed.toLocaleDateString():"Unknown access date"}getContents(){return this._tera.getProjectFile(this.id)}setContents(e){return this._tera.setProjectFile(this.id,e)}getRefs(){return this._tera.getProjectLibrary(this.id)}setRefs(e){return this._tera.setProjectLibrary(this.id,e)}serialize(){return Ct(this,["id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"])}static deserialize(e){return new t(Ct(e,["tera","id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"]))}};var Kt=class{constructor(e){d(this,"settings",{devMode:!0,verbosity:1,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});d(this,"events",ao());d(this,"dom",{el:null,iframe:null,popup:null,stylesheet:null});d(this,"methods",["handshake","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","setProjectStateFlush","setProjectStateRefresh","saveProjectState","replaceProjectState","applyProjectStatePatch","deleteProjectFile","setProjectFile","selectProjectLibrary","getProjectLibrary","setProjectLibrary","projectLog","setPageUrl","setPageTitle","uiAlert","uiSplat","uiWindow"]);d(this,"plugins",[]);d(this,"acceptPostboxes",{});e&&this.set(e)}send(e){let r=Ut();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||Ut(),...Dt(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",1,"Message compose client->server:",o),this.debug("ERROR",1,"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("INFO",3,"Recieved message",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&&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("INFO",3,`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("INFO",3,"Unexpected incoming TERA-FY CLIENT message",{message:r})}}createProjectStatePatch(e,r){let o=Yt(r,e,Vt);return this.debug("INFO",3,"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.debug("INFO",4,"[0/5] Init using server",this.settings.siteUrl)).then(()=>this.detectMode()).then(o=>{this.debug("INFO",4,"[1/5] Setting client mode to",o),this.settings.mode=o}).then(()=>this.debug("INFO",4,"[2/5] Injecting comms + styles + methods")).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>this.debug("INFO",4,"[3/5] Set server mode")).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(()=>this.debug("INFO",4,"[4/5] Run client plugins")).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings)))).then(()=>this.debug("INFO",4,"[5/5] Init complete")).catch(o=>this.debug("WARN",0,"Init caught error",o))}detectMode(){return this.settings.mode!="detect"?Promise.resolve(this.settings.mode):window.self===window.parent?Promise.resolve(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("INFO",2,"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("INFO",2,"Embeded iframe ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("INFO",2,"Using TERA window parent"),e();break;case"popup":this.debug("INFO",2,"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("INFO",3,"Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("INFO",3,"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()`)}return Promise.resolve()}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){if(!this.settings.devMode||this.settings.verbosity<1)return;let r="log",o=1;typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),typeof e[0]=="number"&&(o=e[0],e.shift()),!(this.settings.verbosity<o)&&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("INFO",2,"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}))}createProjectFile(e){return this.rpc("createProjectFile",e).then(r=>r&&new k({tera:this,...r}))}};export{Kt as default};
1
+ var uo=Object.defineProperty;var co=(t,e,r)=>e in t?uo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var d=(t,e,r)=>(co(t,typeof e!="symbol"?e+"":e,r),r);function Vt(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(i){return i});function o({obj1:i,obj2:f,basePath:m,basePathForRemoves:x,diffs:v}){var j=Object.keys(i),O=j.length,y=Object.keys(f),_=y.length,b,p=i.length-f.length;if(xo(i,f)){for(var u=0;u<O;u++){var l=Array.isArray(i)?Number(j[u]):j[u];l in f||(b=x.concat(l),v.remove.push({op:"remove",path:r(b)}))}for(var u=0;u<_;u++){var l=Array.isArray(f)?Number(y[u]):y[u];s({key:l,obj1:i,obj2:f,path:m.concat(l),pathForRemoves:m.concat(l),diffs:v})}}else{for(var u=0;u<p;u++)b=x.concat(u),v.remove.push({op:"remove",path:r(b)});for(var E=i.slice(p),u=0;u<_;u++)s({key:u,obj1:E,obj2:f,path:m.concat(u),pathForRemoves:m.concat(u+p),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 s({key:i,obj1:f,obj2:m,path:x,pathForRemoves:v,diffs:j}){var O=f[i],y=m[i];if(!(i in f)&&i in m){var _=y;j.add.push({op:"add",path:r(x),value:_})}else O!==y&&(Object(O)!==O||Object(y)!==y||ho(O,y)||!Object.keys(O).length&&!Object.keys(y).length&&String(O)!=String(y)?n(x,j,y):o({obj1:f[i],obj2:m[i],basePath:x,basePathForRemoves:v,diffs:j}))}function n(i,f,m){f.replace.push({op:"replace",path:r(i),value:m})}}function Yt(t){return[""].concat(t).join("/")}function ho(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function xo(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,s=0;s<e.length&&String(t[s])===String(e[s]);s++)o++;for(var n=e.length;n>0&&String(t[n+r])===String(e[n]);n--)a++;return o>=a}return!0}var go=typeof global=="object"&&global&&global.Object===Object&&global,dt=go;var yo=typeof self=="object"&&self&&self.Object===Object&&self,bo=dt||yo||Function("return this")(),g=bo;var vo=g.Symbol,T=vo;var Zt=Object.prototype,wo=Zt.hasOwnProperty,To=Zt.toString,pt=T?T.toStringTag:void 0;function Oo(t){var e=wo.call(t,pt),r=t[pt];try{t[pt]=void 0;var o=!0}catch{}var a=To.call(t);return o&&(e?t[pt]=r:delete t[pt]),a}var Jt=Oo;var So=Object.prototype,jo=So.toString;function Po(t){return jo.call(t)}var Xt=Po;var Ao="[object Null]",Io="[object Undefined]",Qt=T?T.toStringTag:void 0;function _o(t){return t==null?t===void 0?Io:Ao:Qt&&Qt in Object(t)?Jt(t):Xt(t)}var I=_o;function Eo(t){return t!=null&&typeof t=="object"}var A=Eo;var Co="[object Symbol]";function Fo(t){return typeof t=="symbol"||A(t)&&I(t)==Co}var K=Fo;function No(t,e){for(var r=-1,o=t==null?0:t.length,a=Array(o);++r<o;)a[r]=e(t[r],r,t);return a}var te=No;var Mo=Array.isArray,w=Mo;var Ro=1/0,ee=T?T.prototype:void 0,re=ee?ee.toString:void 0;function oe(t){if(typeof t=="string")return t;if(w(t))return te(t,oe)+"";if(K(t))return re?re.call(t):"";var e=t+"";return e=="0"&&1/t==-Ro?"-0":e}var ae=oe;function Bo(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var P=Bo;function Lo(t){return t}var ie=Lo;var Do="[object AsyncFunction]",Uo="[object Function]",ko="[object GeneratorFunction]",zo="[object Proxy]";function Ko(t){if(!P(t))return!1;var e=I(t);return e==Uo||e==ko||e==Do||e==zo}var ct=Ko;var Go=g["__core-js_shared__"],ht=Go;var se=function(){var t=/[^.]+$/.exec(ht&&ht.keys&&ht.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function Wo(t){return!!se&&se in t}var ne=Wo;var $o=Function.prototype,Ho=$o.toString;function qo(t){if(t!=null){try{return Ho.call(t)}catch{}try{return t+""}catch{}}return""}var C=qo;var Vo=/[\\^$.*+?()[\]{}|]/g,Yo=/^\[object .+?Constructor\]$/,Zo=Function.prototype,Jo=Object.prototype,Xo=Zo.toString,Qo=Jo.hasOwnProperty,ta=RegExp("^"+Xo.call(Qo).replace(Vo,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ea(t){if(!P(t)||ne(t))return!1;var e=ct(t)?ta:Yo;return e.test(C(t))}var fe=ea;function ra(t,e){return t==null?void 0:t[e]}var pe=ra;function oa(t,e){var r=pe(t,e);return fe(r)?r:void 0}var S=oa;var aa=S(g,"WeakMap"),xt=aa;var le=Object.create,ia=function(){function t(){}return function(e){if(!P(e))return{};if(le)return le(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),me=ia;function sa(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}var ue=sa;function na(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var de=na;var fa=800,pa=16,la=Date.now;function ma(t){var e=0,r=0;return function(){var o=la(),a=pa-(o-r);if(r=o,a>0){if(++e>=fa)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var ce=ma;function ua(t){return function(){return t}}var he=ua;var da=function(){try{var t=S(Object,"defineProperty");return t({},"",{}),t}catch{}}(),G=da;var ca=G?function(t,e){return G(t,"toString",{configurable:!0,enumerable:!1,value:he(e),writable:!0})}:ie,xe=ca;var ha=ce(xe),ge=ha;function xa(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var ye=xa;var ga=9007199254740991,ya=/^(?:0|[1-9]\d*)$/;function ba(t,e){var r=typeof t;return e=e==null?ga:e,!!e&&(r=="number"||r!="symbol"&&ya.test(t))&&t>-1&&t%1==0&&t<e}var W=ba;function va(t,e,r){e=="__proto__"&&G?G(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var gt=va;function wa(t,e){return t===e||t!==t&&e!==e}var yt=wa;var Ta=Object.prototype,Oa=Ta.hasOwnProperty;function Sa(t,e,r){var o=t[e];(!(Oa.call(t,e)&&yt(o,r))||r===void 0&&!(e in t))&&gt(t,e,r)}var $=Sa;function ja(t,e,r,o){var a=!r;r||(r={});for(var s=-1,n=e.length;++s<n;){var i=e[s],f=o?o(r[i],t[i],i,r,t):void 0;f===void 0&&(f=t[i]),a?gt(r,i,f):$(r,i,f)}return r}var M=ja;var be=Math.max;function Pa(t,e,r){return e=be(e===void 0?t.length-1:e,0),function(){for(var o=arguments,a=-1,s=be(o.length-e,0),n=Array(s);++a<s;)n[a]=o[e+a];a=-1;for(var i=Array(e+1);++a<e;)i[a]=o[a];return i[e]=r(n),ue(t,this,i)}}var ve=Pa;var Aa=9007199254740991;function Ia(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Aa}var H=Ia;function _a(t){return t!=null&&H(t.length)&&!ct(t)}var bt=_a;var Ea=Object.prototype;function Ca(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Ea;return t===r}var q=Ca;function Fa(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var we=Fa;var Na="[object Arguments]";function Ma(t){return A(t)&&I(t)==Na}var Nt=Ma;var Te=Object.prototype,Ra=Te.hasOwnProperty,Ba=Te.propertyIsEnumerable,La=Nt(function(){return arguments}())?Nt:function(t){return A(t)&&Ra.call(t,"callee")&&!Ba.call(t,"callee")},V=La;function Da(){return!1}var Oe=Da;var Pe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Se=Pe&&typeof module=="object"&&module&&!module.nodeType&&module,Ua=Se&&Se.exports===Pe,je=Ua?g.Buffer:void 0,ka=je?je.isBuffer:void 0,za=ka||Oe,vt=za;var Ka="[object Arguments]",Ga="[object Array]",Wa="[object Boolean]",$a="[object Date]",Ha="[object Error]",qa="[object Function]",Va="[object Map]",Ya="[object Number]",Za="[object Object]",Ja="[object RegExp]",Xa="[object Set]",Qa="[object String]",ti="[object WeakMap]",ei="[object ArrayBuffer]",ri="[object DataView]",oi="[object Float32Array]",ai="[object Float64Array]",ii="[object Int8Array]",si="[object Int16Array]",ni="[object Int32Array]",fi="[object Uint8Array]",pi="[object Uint8ClampedArray]",li="[object Uint16Array]",mi="[object Uint32Array]",h={};h[oi]=h[ai]=h[ii]=h[si]=h[ni]=h[fi]=h[pi]=h[li]=h[mi]=!0;h[Ka]=h[Ga]=h[ei]=h[Wa]=h[ri]=h[$a]=h[Ha]=h[qa]=h[Va]=h[Ya]=h[Za]=h[Ja]=h[Xa]=h[Qa]=h[ti]=!1;function ui(t){return A(t)&&H(t.length)&&!!h[I(t)]}var Ae=ui;function di(t){return function(e){return t(e)}}var Y=di;var Ie=typeof exports=="object"&&exports&&!exports.nodeType&&exports,lt=Ie&&typeof module=="object"&&module&&!module.nodeType&&module,ci=lt&&lt.exports===Ie,Mt=ci&&dt.process,hi=function(){try{var t=lt&&lt.require&&lt.require("util").types;return t||Mt&&Mt.binding&&Mt.binding("util")}catch{}}(),F=hi;var _e=F&&F.isTypedArray,xi=_e?Y(_e):Ae,Ee=xi;var gi=Object.prototype,yi=gi.hasOwnProperty;function bi(t,e){var r=w(t),o=!r&&V(t),a=!r&&!o&&vt(t),s=!r&&!o&&!a&&Ee(t),n=r||o||a||s,i=n?we(t.length,String):[],f=i.length;for(var m in t)(e||yi.call(t,m))&&!(n&&(m=="length"||a&&(m=="offset"||m=="parent")||s&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||W(m,f)))&&i.push(m);return i}var wt=bi;function vi(t,e){return function(r){return t(e(r))}}var Tt=vi;var wi=Tt(Object.keys,Object),Ce=wi;var Ti=Object.prototype,Oi=Ti.hasOwnProperty;function Si(t){if(!q(t))return Ce(t);var e=[];for(var r in Object(t))Oi.call(t,r)&&r!="constructor"&&e.push(r);return e}var Fe=Si;function ji(t){return bt(t)?wt(t):Fe(t)}var Z=ji;function Pi(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var Ne=Pi;var Ai=Object.prototype,Ii=Ai.hasOwnProperty;function _i(t){if(!P(t))return Ne(t);var e=q(t),r=[];for(var o in t)o=="constructor"&&(e||!Ii.call(t,o))||r.push(o);return r}var Me=_i;function Ei(t){return bt(t)?wt(t,!0):Me(t)}var J=Ei;var Ci=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Fi=/^\w*$/;function Ni(t,e){if(w(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||K(t)?!0:Fi.test(t)||!Ci.test(t)||e!=null&&t in Object(e)}var Re=Ni;var Mi=S(Object,"create"),N=Mi;function Ri(){this.__data__=N?N(null):{},this.size=0}var Be=Ri;function Bi(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Le=Bi;var Li="__lodash_hash_undefined__",Di=Object.prototype,Ui=Di.hasOwnProperty;function ki(t){var e=this.__data__;if(N){var r=e[t];return r===Li?void 0:r}return Ui.call(e,t)?e[t]:void 0}var De=ki;var zi=Object.prototype,Ki=zi.hasOwnProperty;function Gi(t){var e=this.__data__;return N?e[t]!==void 0:Ki.call(e,t)}var Ue=Gi;var Wi="__lodash_hash_undefined__";function $i(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=N&&e===void 0?Wi:e,this}var ke=$i;function X(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])}}X.prototype.clear=Be;X.prototype.delete=Le;X.prototype.get=De;X.prototype.has=Ue;X.prototype.set=ke;var Rt=X;function Hi(){this.__data__=[],this.size=0}var ze=Hi;function qi(t,e){for(var r=t.length;r--;)if(yt(t[r][0],e))return r;return-1}var R=qi;var Vi=Array.prototype,Yi=Vi.splice;function Zi(t){var e=this.__data__,r=R(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Yi.call(e,r,1),--this.size,!0}var Ke=Zi;function Ji(t){var e=this.__data__,r=R(e,t);return r<0?void 0:e[r][1]}var Ge=Ji;function Xi(t){return R(this.__data__,t)>-1}var We=Xi;function Qi(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 $e=Qi;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=ze;Q.prototype.delete=Ke;Q.prototype.get=Ge;Q.prototype.has=We;Q.prototype.set=$e;var B=Q;var ts=S(g,"Map"),L=ts;function es(){this.size=0,this.__data__={hash:new Rt,map:new(L||B),string:new Rt}}var He=es;function rs(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var qe=rs;function os(t,e){var r=t.__data__;return qe(e)?r[typeof e=="string"?"string":"hash"]:r.map}var D=os;function as(t){var e=D(this,t).delete(t);return this.size-=e?1:0,e}var Ve=as;function is(t){return D(this,t).get(t)}var Ye=is;function ss(t){return D(this,t).has(t)}var Ze=ss;function ns(t,e){var r=D(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var Je=ns;function tt(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])}}tt.prototype.clear=He;tt.prototype.delete=Ve;tt.prototype.get=Ye;tt.prototype.has=Ze;tt.prototype.set=Je;var mt=tt;var fs="Expected a function";function Bt(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError(fs);var r=function(){var o=arguments,a=e?e.apply(this,o):o[0],s=r.cache;if(s.has(a))return s.get(a);var n=t.apply(this,o);return r.cache=s.set(a,n)||s,n};return r.cache=new(Bt.Cache||mt),r}Bt.Cache=mt;var Xe=Bt;var ps=500;function ls(t){var e=Xe(t,function(o){return r.size===ps&&r.clear(),o}),r=e.cache;return e}var Qe=ls;var ms=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,us=/\\(\\)?/g,ds=Qe(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(ms,function(r,o,a,s){e.push(a?s.replace(us,"$1"):o||r)}),e}),tr=ds;function cs(t){return t==null?"":ae(t)}var er=cs;function hs(t,e){return w(t)?t:Re(t,e)?[t]:tr(er(t))}var U=hs;var xs=1/0;function gs(t){if(typeof t=="string"||K(t))return t;var e=t+"";return e=="0"&&1/t==-xs?"-0":e}var et=gs;function ys(t,e){e=U(e,t);for(var r=0,o=e.length;t!=null&&r<o;)t=t[et(e[r++])];return r&&r==o?t:void 0}var rr=ys;function bs(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var rt=bs;var or=T?T.isConcatSpreadable:void 0;function vs(t){return w(t)||V(t)||!!(or&&t&&t[or])}var ar=vs;function ir(t,e,r,o,a){var s=-1,n=t.length;for(r||(r=ar),a||(a=[]);++s<n;){var i=t[s];e>0&&r(i)?e>1?ir(i,e-1,r,o,a):rt(a,i):o||(a[a.length]=i)}return a}var sr=ir;function ws(t){var e=t==null?0:t.length;return e?sr(t,1):[]}var nr=ws;function Ts(t){return ge(ve(t,void 0,nr),t+"")}var fr=Ts;var Os=Tt(Object.getPrototypeOf,Object),Ot=Os;function Ss(){this.__data__=new B,this.size=0}var pr=Ss;function js(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var lr=js;function Ps(t){return this.__data__.get(t)}var mr=Ps;function As(t){return this.__data__.has(t)}var ur=As;var Is=200;function _s(t,e){var r=this.__data__;if(r instanceof B){var o=r.__data__;if(!L||o.length<Is-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new mt(o)}return r.set(t,e),this.size=r.size,this}var dr=_s;function ot(t){var e=this.__data__=new B(t);this.size=e.size}ot.prototype.clear=pr;ot.prototype.delete=lr;ot.prototype.get=mr;ot.prototype.has=ur;ot.prototype.set=dr;var cr=ot;function Es(t,e){return t&&M(e,Z(e),t)}var hr=Es;function Cs(t,e){return t&&M(e,J(e),t)}var xr=Cs;var vr=typeof exports=="object"&&exports&&!exports.nodeType&&exports,gr=vr&&typeof module=="object"&&module&&!module.nodeType&&module,Fs=gr&&gr.exports===vr,yr=Fs?g.Buffer:void 0,br=yr?yr.allocUnsafe:void 0;function Ns(t,e){if(e)return t.slice();var r=t.length,o=br?br(r):new t.constructor(r);return t.copy(o),o}var wr=Ns;function Ms(t,e){for(var r=-1,o=t==null?0:t.length,a=0,s=[];++r<o;){var n=t[r];e(n,r,t)&&(s[a++]=n)}return s}var Tr=Ms;function Rs(){return[]}var St=Rs;var Bs=Object.prototype,Ls=Bs.propertyIsEnumerable,Or=Object.getOwnPropertySymbols,Ds=Or?function(t){return t==null?[]:(t=Object(t),Tr(Or(t),function(e){return Ls.call(t,e)}))}:St,at=Ds;function Us(t,e){return M(t,at(t),e)}var Sr=Us;var ks=Object.getOwnPropertySymbols,zs=ks?function(t){for(var e=[];t;)rt(e,at(t)),t=Ot(t);return e}:St,jt=zs;function Ks(t,e){return M(t,jt(t),e)}var jr=Ks;function Gs(t,e,r){var o=e(t);return w(t)?o:rt(o,r(t))}var Pt=Gs;function Ws(t){return Pt(t,Z,at)}var Pr=Ws;function $s(t){return Pt(t,J,jt)}var Ar=$s;var Hs=S(g,"DataView"),At=Hs;var qs=S(g,"Promise"),It=qs;var Vs=S(g,"Set"),_t=Vs;var Ir="[object Map]",Ys="[object Object]",_r="[object Promise]",Er="[object Set]",Cr="[object WeakMap]",Fr="[object DataView]",Zs=C(At),Js=C(L),Xs=C(It),Qs=C(_t),tn=C(xt),z=I;(At&&z(new At(new ArrayBuffer(1)))!=Fr||L&&z(new L)!=Ir||It&&z(It.resolve())!=_r||_t&&z(new _t)!=Er||xt&&z(new xt)!=Cr)&&(z=function(t){var e=I(t),r=e==Ys?t.constructor:void 0,o=r?C(r):"";if(o)switch(o){case Zs:return Fr;case Js:return Ir;case Xs:return _r;case Qs:return Er;case tn:return Cr}return e});var it=z;var en=Object.prototype,rn=en.hasOwnProperty;function on(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&rn.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var Nr=on;var an=g.Uint8Array,Lt=an;function sn(t){var e=new t.constructor(t.byteLength);return new Lt(e).set(new Lt(t)),e}var st=sn;function nn(t,e){var r=e?st(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var Mr=nn;var fn=/\w*$/;function pn(t){var e=new t.constructor(t.source,fn.exec(t));return e.lastIndex=t.lastIndex,e}var Rr=pn;var Br=T?T.prototype:void 0,Lr=Br?Br.valueOf:void 0;function ln(t){return Lr?Object(Lr.call(t)):{}}var Dr=ln;function mn(t,e){var r=e?st(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var Ur=mn;var un="[object Boolean]",dn="[object Date]",cn="[object Map]",hn="[object Number]",xn="[object RegExp]",gn="[object Set]",yn="[object String]",bn="[object Symbol]",vn="[object ArrayBuffer]",wn="[object DataView]",Tn="[object Float32Array]",On="[object Float64Array]",Sn="[object Int8Array]",jn="[object Int16Array]",Pn="[object Int32Array]",An="[object Uint8Array]",In="[object Uint8ClampedArray]",_n="[object Uint16Array]",En="[object Uint32Array]";function Cn(t,e,r){var o=t.constructor;switch(e){case vn:return st(t);case un:case dn:return new o(+t);case wn:return Mr(t,r);case Tn:case On:case Sn:case jn:case Pn:case An:case In:case _n:case En:return Ur(t,r);case cn:return new o;case hn:case yn:return new o(t);case xn:return Rr(t);case gn:return new o;case bn:return Dr(t)}}var kr=Cn;function Fn(t){return typeof t.constructor=="function"&&!q(t)?me(Ot(t)):{}}var zr=Fn;var Nn="[object Map]";function Mn(t){return A(t)&&it(t)==Nn}var Kr=Mn;var Gr=F&&F.isMap,Rn=Gr?Y(Gr):Kr,Wr=Rn;var Bn="[object Set]";function Ln(t){return A(t)&&it(t)==Bn}var $r=Ln;var Hr=F&&F.isSet,Dn=Hr?Y(Hr):$r,qr=Dn;var Un=1,kn=2,zn=4,Vr="[object Arguments]",Kn="[object Array]",Gn="[object Boolean]",Wn="[object Date]",$n="[object Error]",Yr="[object Function]",Hn="[object GeneratorFunction]",qn="[object Map]",Vn="[object Number]",Zr="[object Object]",Yn="[object RegExp]",Zn="[object Set]",Jn="[object String]",Xn="[object Symbol]",Qn="[object WeakMap]",tf="[object ArrayBuffer]",ef="[object DataView]",rf="[object Float32Array]",of="[object Float64Array]",af="[object Int8Array]",sf="[object Int16Array]",nf="[object Int32Array]",ff="[object Uint8Array]",pf="[object Uint8ClampedArray]",lf="[object Uint16Array]",mf="[object Uint32Array]",c={};c[Vr]=c[Kn]=c[tf]=c[ef]=c[Gn]=c[Wn]=c[rf]=c[of]=c[af]=c[sf]=c[nf]=c[qn]=c[Vn]=c[Zr]=c[Yn]=c[Zn]=c[Jn]=c[Xn]=c[ff]=c[pf]=c[lf]=c[mf]=!0;c[$n]=c[Yr]=c[Qn]=!1;function Et(t,e,r,o,a,s){var n,i=e&Un,f=e&kn,m=e&zn;if(r&&(n=a?r(t,o,a,s):r(t)),n!==void 0)return n;if(!P(t))return t;var x=w(t);if(x){if(n=Nr(t),!i)return de(t,n)}else{var v=it(t),j=v==Yr||v==Hn;if(vt(t))return wr(t,i);if(v==Zr||v==Vr||j&&!a){if(n=f||j?{}:zr(t),!i)return f?jr(t,xr(n,t)):Sr(t,hr(n,t))}else{if(!c[v])return a?t:{};n=kr(t,v,i)}}s||(s=new cr);var O=s.get(t);if(O)return O;s.set(t,n),qr(t)?t.forEach(function(b){n.add(Et(b,e,r,b,t,s))}):Wr(t)&&t.forEach(function(b,p){n.set(p,Et(b,e,r,p,t,s))});var y=m?f?Ar:Pr:f?J:Z,_=x?void 0:y(t);return ye(_||t,function(b,p){_&&(p=b,b=t[p]),$(n,p,Et(b,e,r,p,t,s))}),n}var Jr=Et;var uf=1,df=4;function cf(t){return Jr(t,uf|df)}var Dt=cf;function hf(t,e){return t!=null&&e in Object(t)}var Xr=hf;function xf(t,e,r){e=U(e,t);for(var o=-1,a=e.length,s=!1;++o<a;){var n=et(e[o]);if(!(s=t!=null&&r(t,n)))break;t=t[n]}return s||++o!=a?s:(a=t==null?0:t.length,!!a&&H(a)&&W(n,a)&&(w(t)||V(t)))}var Qr=xf;function gf(t,e){return t!=null&&Qr(t,e,Xr)}var to=gf;function yf(t,e,r,o){if(!P(t))return t;e=U(e,t);for(var a=-1,s=e.length,n=s-1,i=t;i!=null&&++a<s;){var f=et(e[a]),m=r;if(f==="__proto__"||f==="constructor"||f==="prototype")return t;if(a!=n){var x=i[f];m=o?o(x,f,i):void 0,m===void 0&&(m=P(x)?x:W(e[a+1])?[]:{})}$(i,f,m),i=i[f]}return t}var eo=yf;function bf(t,e,r){for(var o=-1,a=e.length,s={};++o<a;){var n=e[o],i=rr(t,n);r(i,n)&&eo(s,U(n,t),i)}return s}var ro=bf;function vf(t,e){return ro(t,e,function(r,o){return to(t,o)})}var oo=vf;var wf=fr(function(t,e){return t==null?{}:oo(t,e)}),Ct=wf;function ao(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 Ut=(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",Of="bit",io="bits",Sf="byte",so="bytes",nt="",jf="exponent",Pf="function",no="iec",Af="Invalid number",If="Invalid rounding method",kt="jedec",_f="object",fo=".",Ef="round",Cf="s",Ff="si",Nf="kbit",Mf="kB",Rf=" ",Bf="string",Lf="0",zt={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 po(t,{bits:e=!1,pad:r=!1,base:o=-1,round:a=2,locale:s=nt,localeOptions:n={},separator:i=nt,spacer:f=Rf,symbols:m={},standard:x=nt,output:v=Bf,fullform:j=!1,fullforms:O=[],exponent:y=-1,roundingMethod:_=Ef,precision:b=0}={}){let p=y,u=Number(t),l=[],E=0,Ft=nt;x===Ff?(o=10,x=kt):x===no||x===kt?o=2:o===2?x=no:(o=10,x=kt);let ut=o===10?1e3:1024,lo=j===!0,Gt=u<0,Wt=Math[_];if(typeof t!="bigint"&&isNaN(t))throw new TypeError(Af);if(typeof Wt!==Pf)throw new TypeError(If);if(Gt&&(u=-u),(p===-1||isNaN(p))&&(p=Math.floor(Math.log(u)/Math.log(ut)),p<0&&(p=0)),p>8&&(b>0&&(b+=8-p),p=8),v===jf)return p;if(u===0)l[0]=0,Ft=l[1]=zt.symbol[x][e?io:so][p];else{E=u/(o===2?Math.pow(2,p*10):Math.pow(1e3,p)),e&&(E=E*8,E>=ut&&p<8&&(E=E/ut,p++));let ft=Math.pow(10,p>0?a:0);l[0]=Wt(E*ft)/ft,l[0]===ut&&p<8&&y===-1&&(l[0]=1,p++),Ft=l[1]=o===10&&p===1?e?Nf:Mf:zt.symbol[x][e?io:so][p]}if(Gt&&(l[0]=-l[0]),b>0&&(l[0]=l[0].toPrecision(b)),l[1]=m[l[1]]||l[1],s===!0?l[0]=l[0].toLocaleString():s.length>0?l[0]=l[0].toLocaleString(s,n):i.length>0&&(l[0]=l[0].toString().replace(fo,i)),r&&Number.isInteger(l[0])===!1&&a>0){let ft=i||fo,$t=l[0].toString().split(ft),Ht=$t[1]||nt,qt=Ht.length,mo=a-qt;l[0]=`${$t[0]}${ft}${Ht.padEnd(qt+mo,Lf)}`}return lo&&(l[1]=O[p]?O[p]:zt.fullform[x][p]+(e?Of:Sf)+(l[0]===1?nt:Cf)),v===Tf?l:v===_f?{value:l[0],symbol:l[1],exponent:p,unit:Ft}:l.join(f)}var k=class t{constructor(e){d(this,"_tera");d(this,"id");d(this,"name");d(this,"icon");d(this,"path");d(this,"url");d(this,"teraUrl");d(this,"parsedName");d(this,"created");d(this,"createdFormatted");d(this,"modified");d(this,"modifiedFormatted");d(this,"accessed");d(this,"accessedFormatted");d(this,"size");d(this,"sizeFormatted");d(this,"mime");d(this,"meta",{});if(!e.tera)throw new Error("Basic file requires a `tera` key to access the Tera instance");Object.assign(this,e);let r=this.tera;Object.defineProperty(this,"_tera",{enumerable:!1,configurable:!1,get(){return r}}),delete this.tera,this.teraUrl=this.url.replace(/^https:\/\/tera-tools.com\/projects\/(?:.+?)\/project\/(.+)$/,"/project/$1"),this.sizeFormatted=po(this.size||0,{spacer:""}),this.createdFormatted=this.created?this.created.toLocaleDateString():"Unknown created date",this.modifiedFormatted=this.modified?this.modified.toLocaleDateString():"Unknown modified date",this.accessedFormatted=this.accessed?this.accessed.toLocaleDateString():"Unknown access date"}getContents(){return this._tera.getProjectFile(this.id)}setContents(e){return this._tera.setProjectFile(this.id,e)}getRefs(){return this._tera.getProjectLibrary(this.id)}setRefs(e){return this._tera.setProjectLibrary(this.id,e)}serialize(){return Ct(this,["id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"])}static deserialize(e){return new t(Ct(e,["tera","id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"]))}};var Kt=class{constructor(e){d(this,"settings",{devMode:!0,verbosity:1,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});d(this,"events",ao());d(this,"dom",{el:null,iframe:null,popup:null,stylesheet:null});d(this,"methods",["handshake","setServerVerbosity","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","setProjectStateFlush","setProjectStateRefresh","saveProjectState","replaceProjectState","applyProjectStatePatch","deleteProjectFile","setProjectFile","selectProjectLibrary","getProjectLibrary","setProjectLibrary","projectLog","setPageUrl","setPageTitle","uiAlert","uiProgress","uiSplat","uiWindow"]);d(this,"plugins",[]);d(this,"acceptPostboxes",{});e&&this.set(e)}send(e){let r=Ut();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||Ut(),...Dt(e)},this.settings.mode=="parent")window.parent.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="child")console.log("SEND DOWN",{target:this.dom.iframe.contentWindow,payload:r,restrictOrigin:this.settings.restrictOrigin}),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",1,"Message compose client->server:",o),this.debug("ERROR",1,"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("INFO",3,"Recieved message",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&&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("INFO",3,`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("INFO",3,"Unexpected incoming TERA-FY CLIENT message",{message:r})}}createProjectStatePatch(e,r){let o=Vt(r,e,Yt);return this.debug("INFO",3,"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.debug("INFO",4,"[0/6] Init using server",this.settings.siteUrl)).then(()=>this.detectMode()).then(o=>{this.debug("INFO",4,"[1/6] Setting client mode to",o),this.settings.mode=o}).then(()=>this.debug("INFO",4,"[2/6] Injecting comms + styles + methods")).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>{if(this.settings.verbosity<=1){this.debug("INFO",4,"[3/6] Skip - Server verbosity is already at 1");return}else return this.debug("INFO",4,`[3/6] Set server verbosity to ${this.settings.verbosity}`),this.rpc("setServerVerbsity",this.settings.verbosity)}).then(()=>this.debug("INFO",4,`[4/6] Set server mode to "${this.settings.mode}"`)).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(()=>this.debug("INFO",4,"[5/6] Run client plugins")).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings)))).then(()=>this.debug("INFO",4,"[6/6] Init complete")).catch(o=>this.debug("WARN",0,"Init process fault",o))}detectMode(){return this.settings.mode!="detect"?Promise.resolve(this.settings.mode):window.self===window.parent?Promise.resolve(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("INFO",2,"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("INFO",2,"Embeded iframe ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("INFO",2,"Using TERA window parent"),e();break;case"popup":this.debug("INFO",2,"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("INFO",3,"Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("INFO",3,"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()`)}return Promise.resolve()}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){if(!this.settings.devMode||this.settings.verbosity<1)return;let r="log",o=1;typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),typeof e[0]=="number"&&(o=e[0],e.shift()),!(this.settings.verbosity<o)&&console[r]("%c[TERA-FY CLIENT]","font-weight: bold; color: #ff5722;",...e)}set(e,r,o){let a={ignoreNullish:!0,...o};return typeof e=="string"?(!a.ignoreNullish||r!=null)&&(this.settings[e]=r):Object.assign(this.settings,e),this.toggleDevMode(this.settings.devMode)}setIfDev(e,r,o){return!this.settings.devMode||r===void 0?this:this.set(e,r,o)}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 e==="toggle"?this.settings.devMode=!this.settings.devMode:e==="proxy"?Object.assign(this.settings,{devMode:!0,siteUrl:"http://localhost:7334/embed",mode:"child"}):this.settings.devMode=!!e,this.dom.el&&this.dom.el.classList.toggle("dev-mode",this.settings.devMode),this}toggleFocus(e="toggle"){this.debug("INFO",2,"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}))}createProjectFile(e){return this.rpc("createProjectFile",e).then(r=>r&&new k({tera:this,...r}))}};export{Kt as default};
3
3
  /*! Bundled license information:
4
4
 
5
5
  lodash-es/lodash.js:
package/dist/terafy.js CHANGED
@@ -1,5 +1,5 @@
1
- function qt(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(i){return i});function o({obj1:i,obj2:f,basePath:m,basePathForRemoves:h,diffs:b}){var j=Object.keys(i),T=j.length,g=Object.keys(f),I=g.length,y,p=i.length-f.length;if(uo(i,f)){for(var u=0;u<T;u++){var l=Array.isArray(i)?Number(j[u]):j[u];l in f||(y=h.concat(l),b.remove.push({op:"remove",path:r(y)}))}for(var u=0;u<I;u++){var l=Array.isArray(f)?Number(g[u]):g[u];s({key:l,obj1:i,obj2:f,path:m.concat(l),pathForRemoves:m.concat(l),diffs:b})}}else{for(var u=0;u<p;u++)y=h.concat(u),b.remove.push({op:"remove",path:r(y)});for(var _=i.slice(p),u=0;u<I;u++)s({key:u,obj1:_,obj2:f,path:m.concat(u),pathForRemoves:m.concat(u+p),diffs:b})}}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 s({key:i,obj1:f,obj2:m,path:h,pathForRemoves:b,diffs:j}){var T=f[i],g=m[i];if(!(i in f)&&i in m){var I=g;j.add.push({op:"add",path:r(h),value:I})}else T!==g&&(Object(T)!==T||Object(g)!==g||mo(T,g)||!Object.keys(T).length&&!Object.keys(g).length&&String(T)!=String(g)?n(h,j,g):o({obj1:f[i],obj2:m[i],basePath:h,basePathForRemoves:b,diffs:j}))}function n(i,f,m){f.replace.push({op:"replace",path:r(i),value:m})}}function Yt(t){return[""].concat(t).join("/")}function mo(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function uo(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,s=0;s<e.length&&String(t[s])===String(e[s]);s++)o++;for(var n=e.length;n>0&&String(t[n+r])===String(e[n]);n--)a++;return o>=a}return!0}var co=typeof global=="object"&&global&&global.Object===Object&&global,ut=co;var ho=typeof self=="object"&&self&&self.Object===Object&&self,xo=ut||ho||Function("return this")(),x=xo;var go=x.Symbol,w=go;var Vt=Object.prototype,yo=Vt.hasOwnProperty,bo=Vt.toString,ft=w?w.toStringTag:void 0;function vo(t){var e=yo.call(t,ft),r=t[ft];try{t[ft]=void 0;var o=!0}catch{}var a=bo.call(t);return o&&(e?t[ft]=r:delete t[ft]),a}var Zt=vo;var wo=Object.prototype,To=wo.toString;function Oo(t){return To.call(t)}var Jt=Oo;var jo="[object Null]",Po="[object Undefined]",Xt=w?w.toStringTag:void 0;function So(t){return t==null?t===void 0?Po:jo:Xt&&Xt in Object(t)?Zt(t):Jt(t)}var A=So;function Ao(t){return t!=null&&typeof t=="object"}var S=Ao;var Io="[object Symbol]";function _o(t){return typeof t=="symbol"||S(t)&&A(t)==Io}var z=_o;function Eo(t,e){for(var r=-1,o=t==null?0:t.length,a=Array(o);++r<o;)a[r]=e(t[r],r,t);return a}var Qt=Eo;var Co=Array.isArray,v=Co;var Fo=1/0,te=w?w.prototype:void 0,ee=te?te.toString:void 0;function re(t){if(typeof t=="string")return t;if(v(t))return Qt(t,re)+"";if(z(t))return ee?ee.call(t):"";var e=t+"";return e=="0"&&1/t==-Fo?"-0":e}var oe=re;function Mo(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var P=Mo;function No(t){return t}var ae=No;var Ro="[object AsyncFunction]",Bo="[object Function]",Lo="[object GeneratorFunction]",Do="[object Proxy]";function Uo(t){if(!P(t))return!1;var e=A(t);return e==Bo||e==Lo||e==Ro||e==Do}var dt=Uo;var ko=x["__core-js_shared__"],ct=ko;var ie=function(){var t=/[^.]+$/.exec(ct&&ct.keys&&ct.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function zo(t){return!!ie&&ie in t}var se=zo;var Ko=Function.prototype,Go=Ko.toString;function Wo(t){if(t!=null){try{return Go.call(t)}catch{}try{return t+""}catch{}}return""}var E=Wo;var $o=/[\\^$.*+?()[\]{}|]/g,Ho=/^\[object .+?Constructor\]$/,qo=Function.prototype,Yo=Object.prototype,Vo=qo.toString,Zo=Yo.hasOwnProperty,Jo=RegExp("^"+Vo.call(Zo).replace($o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Xo(t){if(!P(t)||se(t))return!1;var e=dt(t)?Jo:Ho;return e.test(E(t))}var ne=Xo;function Qo(t,e){return t?.[e]}var fe=Qo;function ta(t,e){var r=fe(t,e);return ne(r)?r:void 0}var O=ta;var ea=O(x,"WeakMap"),ht=ea;var pe=Object.create,ra=function(){function t(){}return function(e){if(!P(e))return{};if(pe)return pe(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),le=ra;function oa(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}var me=oa;function aa(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var ue=aa;var ia=800,sa=16,na=Date.now;function fa(t){var e=0,r=0;return function(){var o=na(),a=sa-(o-r);if(r=o,a>0){if(++e>=ia)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var de=fa;function pa(t){return function(){return t}}var ce=pa;var la=function(){try{var t=O(Object,"defineProperty");return t({},"",{}),t}catch{}}(),K=la;var ma=K?function(t,e){return K(t,"toString",{configurable:!0,enumerable:!1,value:ce(e),writable:!0})}:ae,he=ma;var ua=de(he),xe=ua;function da(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var ge=da;var ca=9007199254740991,ha=/^(?:0|[1-9]\d*)$/;function xa(t,e){var r=typeof t;return e=e??ca,!!e&&(r=="number"||r!="symbol"&&ha.test(t))&&t>-1&&t%1==0&&t<e}var G=xa;function ga(t,e,r){e=="__proto__"&&K?K(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var xt=ga;function ya(t,e){return t===e||t!==t&&e!==e}var gt=ya;var ba=Object.prototype,va=ba.hasOwnProperty;function wa(t,e,r){var o=t[e];(!(va.call(t,e)&&gt(o,r))||r===void 0&&!(e in t))&&xt(t,e,r)}var W=wa;function Ta(t,e,r,o){var a=!r;r||(r={});for(var s=-1,n=e.length;++s<n;){var i=e[s],f=o?o(r[i],t[i],i,r,t):void 0;f===void 0&&(f=t[i]),a?xt(r,i,f):W(r,i,f)}return r}var M=Ta;var ye=Math.max;function Oa(t,e,r){return e=ye(e===void 0?t.length-1:e,0),function(){for(var o=arguments,a=-1,s=ye(o.length-e,0),n=Array(s);++a<s;)n[a]=o[e+a];a=-1;for(var i=Array(e+1);++a<e;)i[a]=o[a];return i[e]=r(n),me(t,this,i)}}var be=Oa;var ja=9007199254740991;function Pa(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=ja}var $=Pa;function Sa(t){return t!=null&&$(t.length)&&!dt(t)}var yt=Sa;var Aa=Object.prototype;function Ia(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Aa;return t===r}var H=Ia;function _a(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var ve=_a;var Ea="[object Arguments]";function Ca(t){return S(t)&&A(t)==Ea}var Ft=Ca;var we=Object.prototype,Fa=we.hasOwnProperty,Ma=we.propertyIsEnumerable,Na=Ft(function(){return arguments}())?Ft:function(t){return S(t)&&Fa.call(t,"callee")&&!Ma.call(t,"callee")},q=Na;function Ra(){return!1}var Te=Ra;var Pe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Oe=Pe&&typeof module=="object"&&module&&!module.nodeType&&module,Ba=Oe&&Oe.exports===Pe,je=Ba?x.Buffer:void 0,La=je?je.isBuffer:void 0,Da=La||Te,bt=Da;var Ua="[object Arguments]",ka="[object Array]",za="[object Boolean]",Ka="[object Date]",Ga="[object Error]",Wa="[object Function]",$a="[object Map]",Ha="[object Number]",qa="[object Object]",Ya="[object RegExp]",Va="[object Set]",Za="[object String]",Ja="[object WeakMap]",Xa="[object ArrayBuffer]",Qa="[object DataView]",ti="[object Float32Array]",ei="[object Float64Array]",ri="[object Int8Array]",oi="[object Int16Array]",ai="[object Int32Array]",ii="[object Uint8Array]",si="[object Uint8ClampedArray]",ni="[object Uint16Array]",fi="[object Uint32Array]",c={};c[ti]=c[ei]=c[ri]=c[oi]=c[ai]=c[ii]=c[si]=c[ni]=c[fi]=!0;c[Ua]=c[ka]=c[Xa]=c[za]=c[Qa]=c[Ka]=c[Ga]=c[Wa]=c[$a]=c[Ha]=c[qa]=c[Ya]=c[Va]=c[Za]=c[Ja]=!1;function pi(t){return S(t)&&$(t.length)&&!!c[A(t)]}var Se=pi;function li(t){return function(e){return t(e)}}var Y=li;var Ae=typeof exports=="object"&&exports&&!exports.nodeType&&exports,pt=Ae&&typeof module=="object"&&module&&!module.nodeType&&module,mi=pt&&pt.exports===Ae,Mt=mi&&ut.process,ui=function(){try{var t=pt&&pt.require&&pt.require("util").types;return t||Mt&&Mt.binding&&Mt.binding("util")}catch{}}(),C=ui;var Ie=C&&C.isTypedArray,di=Ie?Y(Ie):Se,_e=di;var ci=Object.prototype,hi=ci.hasOwnProperty;function xi(t,e){var r=v(t),o=!r&&q(t),a=!r&&!o&&bt(t),s=!r&&!o&&!a&&_e(t),n=r||o||a||s,i=n?ve(t.length,String):[],f=i.length;for(var m in t)(e||hi.call(t,m))&&!(n&&(m=="length"||a&&(m=="offset"||m=="parent")||s&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||G(m,f)))&&i.push(m);return i}var vt=xi;function gi(t,e){return function(r){return t(e(r))}}var wt=gi;var yi=wt(Object.keys,Object),Ee=yi;var bi=Object.prototype,vi=bi.hasOwnProperty;function wi(t){if(!H(t))return Ee(t);var e=[];for(var r in Object(t))vi.call(t,r)&&r!="constructor"&&e.push(r);return e}var Ce=wi;function Ti(t){return yt(t)?vt(t):Ce(t)}var V=Ti;function Oi(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var Fe=Oi;var ji=Object.prototype,Pi=ji.hasOwnProperty;function Si(t){if(!P(t))return Fe(t);var e=H(t),r=[];for(var o in t)o=="constructor"&&(e||!Pi.call(t,o))||r.push(o);return r}var Me=Si;function Ai(t){return yt(t)?vt(t,!0):Me(t)}var Z=Ai;var Ii=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,_i=/^\w*$/;function Ei(t,e){if(v(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||z(t)?!0:_i.test(t)||!Ii.test(t)||e!=null&&t in Object(e)}var Ne=Ei;var Ci=O(Object,"create"),F=Ci;function Fi(){this.__data__=F?F(null):{},this.size=0}var Re=Fi;function Mi(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Be=Mi;var Ni="__lodash_hash_undefined__",Ri=Object.prototype,Bi=Ri.hasOwnProperty;function Li(t){var e=this.__data__;if(F){var r=e[t];return r===Ni?void 0:r}return Bi.call(e,t)?e[t]:void 0}var Le=Li;var Di=Object.prototype,Ui=Di.hasOwnProperty;function ki(t){var e=this.__data__;return F?e[t]!==void 0:Ui.call(e,t)}var De=ki;var zi="__lodash_hash_undefined__";function Ki(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=F&&e===void 0?zi:e,this}var Ue=Ki;function J(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])}}J.prototype.clear=Re;J.prototype.delete=Be;J.prototype.get=Le;J.prototype.has=De;J.prototype.set=Ue;var Nt=J;function Gi(){this.__data__=[],this.size=0}var ke=Gi;function Wi(t,e){for(var r=t.length;r--;)if(gt(t[r][0],e))return r;return-1}var N=Wi;var $i=Array.prototype,Hi=$i.splice;function qi(t){var e=this.__data__,r=N(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Hi.call(e,r,1),--this.size,!0}var ze=qi;function Yi(t){var e=this.__data__,r=N(e,t);return r<0?void 0:e[r][1]}var Ke=Yi;function Vi(t){return N(this.__data__,t)>-1}var Ge=Vi;function Zi(t,e){var r=this.__data__,o=N(r,t);return o<0?(++this.size,r.push([t,e])):r[o][1]=e,this}var We=Zi;function X(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])}}X.prototype.clear=ke;X.prototype.delete=ze;X.prototype.get=Ke;X.prototype.has=Ge;X.prototype.set=We;var R=X;var Ji=O(x,"Map"),B=Ji;function Xi(){this.size=0,this.__data__={hash:new Nt,map:new(B||R),string:new Nt}}var $e=Xi;function Qi(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var He=Qi;function ts(t,e){var r=t.__data__;return He(e)?r[typeof e=="string"?"string":"hash"]:r.map}var L=ts;function es(t){var e=L(this,t).delete(t);return this.size-=e?1:0,e}var qe=es;function rs(t){return L(this,t).get(t)}var Ye=rs;function os(t){return L(this,t).has(t)}var Ve=os;function as(t,e){var r=L(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var Ze=as;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=$e;Q.prototype.delete=qe;Q.prototype.get=Ye;Q.prototype.has=Ve;Q.prototype.set=Ze;var lt=Q;var is="Expected a function";function Rt(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError(is);var r=function(){var o=arguments,a=e?e.apply(this,o):o[0],s=r.cache;if(s.has(a))return s.get(a);var n=t.apply(this,o);return r.cache=s.set(a,n)||s,n};return r.cache=new(Rt.Cache||lt),r}Rt.Cache=lt;var Je=Rt;var ss=500;function ns(t){var e=Je(t,function(o){return r.size===ss&&r.clear(),o}),r=e.cache;return e}var Xe=ns;var fs=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ps=/\\(\\)?/g,ls=Xe(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(fs,function(r,o,a,s){e.push(a?s.replace(ps,"$1"):o||r)}),e}),Qe=ls;function ms(t){return t==null?"":oe(t)}var tr=ms;function us(t,e){return v(t)?t:Ne(t,e)?[t]:Qe(tr(t))}var D=us;var ds=1/0;function cs(t){if(typeof t=="string"||z(t))return t;var e=t+"";return e=="0"&&1/t==-ds?"-0":e}var tt=cs;function hs(t,e){e=D(e,t);for(var r=0,o=e.length;t!=null&&r<o;)t=t[tt(e[r++])];return r&&r==o?t:void 0}var er=hs;function xs(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var et=xs;var rr=w?w.isConcatSpreadable:void 0;function gs(t){return v(t)||q(t)||!!(rr&&t&&t[rr])}var or=gs;function ar(t,e,r,o,a){var s=-1,n=t.length;for(r||(r=or),a||(a=[]);++s<n;){var i=t[s];e>0&&r(i)?e>1?ar(i,e-1,r,o,a):et(a,i):o||(a[a.length]=i)}return a}var ir=ar;function ys(t){var e=t==null?0:t.length;return e?ir(t,1):[]}var sr=ys;function bs(t){return xe(be(t,void 0,sr),t+"")}var nr=bs;var vs=wt(Object.getPrototypeOf,Object),Tt=vs;function ws(){this.__data__=new R,this.size=0}var fr=ws;function Ts(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var pr=Ts;function Os(t){return this.__data__.get(t)}var lr=Os;function js(t){return this.__data__.has(t)}var mr=js;var Ps=200;function Ss(t,e){var r=this.__data__;if(r instanceof R){var o=r.__data__;if(!B||o.length<Ps-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new lt(o)}return r.set(t,e),this.size=r.size,this}var ur=Ss;function rt(t){var e=this.__data__=new R(t);this.size=e.size}rt.prototype.clear=fr;rt.prototype.delete=pr;rt.prototype.get=lr;rt.prototype.has=mr;rt.prototype.set=ur;var dr=rt;function As(t,e){return t&&M(e,V(e),t)}var cr=As;function Is(t,e){return t&&M(e,Z(e),t)}var hr=Is;var br=typeof exports=="object"&&exports&&!exports.nodeType&&exports,xr=br&&typeof module=="object"&&module&&!module.nodeType&&module,_s=xr&&xr.exports===br,gr=_s?x.Buffer:void 0,yr=gr?gr.allocUnsafe:void 0;function Es(t,e){if(e)return t.slice();var r=t.length,o=yr?yr(r):new t.constructor(r);return t.copy(o),o}var vr=Es;function Cs(t,e){for(var r=-1,o=t==null?0:t.length,a=0,s=[];++r<o;){var n=t[r];e(n,r,t)&&(s[a++]=n)}return s}var wr=Cs;function Fs(){return[]}var Ot=Fs;var Ms=Object.prototype,Ns=Ms.propertyIsEnumerable,Tr=Object.getOwnPropertySymbols,Rs=Tr?function(t){return t==null?[]:(t=Object(t),wr(Tr(t),function(e){return Ns.call(t,e)}))}:Ot,ot=Rs;function Bs(t,e){return M(t,ot(t),e)}var Or=Bs;var Ls=Object.getOwnPropertySymbols,Ds=Ls?function(t){for(var e=[];t;)et(e,ot(t)),t=Tt(t);return e}:Ot,jt=Ds;function Us(t,e){return M(t,jt(t),e)}var jr=Us;function ks(t,e,r){var o=e(t);return v(t)?o:et(o,r(t))}var Pt=ks;function zs(t){return Pt(t,V,ot)}var Pr=zs;function Ks(t){return Pt(t,Z,jt)}var Sr=Ks;var Gs=O(x,"DataView"),St=Gs;var Ws=O(x,"Promise"),At=Ws;var $s=O(x,"Set"),It=$s;var Ar="[object Map]",Hs="[object Object]",Ir="[object Promise]",_r="[object Set]",Er="[object WeakMap]",Cr="[object DataView]",qs=E(St),Ys=E(B),Vs=E(At),Zs=E(It),Js=E(ht),k=A;(St&&k(new St(new ArrayBuffer(1)))!=Cr||B&&k(new B)!=Ar||At&&k(At.resolve())!=Ir||It&&k(new It)!=_r||ht&&k(new ht)!=Er)&&(k=function(t){var e=A(t),r=e==Hs?t.constructor:void 0,o=r?E(r):"";if(o)switch(o){case qs:return Cr;case Ys:return Ar;case Vs:return Ir;case Zs:return _r;case Js:return Er}return e});var at=k;var Xs=Object.prototype,Qs=Xs.hasOwnProperty;function tn(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&Qs.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var Fr=tn;var en=x.Uint8Array,Bt=en;function rn(t){var e=new t.constructor(t.byteLength);return new Bt(e).set(new Bt(t)),e}var it=rn;function on(t,e){var r=e?it(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var Mr=on;var an=/\w*$/;function sn(t){var e=new t.constructor(t.source,an.exec(t));return e.lastIndex=t.lastIndex,e}var Nr=sn;var Rr=w?w.prototype:void 0,Br=Rr?Rr.valueOf:void 0;function nn(t){return Br?Object(Br.call(t)):{}}var Lr=nn;function fn(t,e){var r=e?it(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var Dr=fn;var pn="[object Boolean]",ln="[object Date]",mn="[object Map]",un="[object Number]",dn="[object RegExp]",cn="[object Set]",hn="[object String]",xn="[object Symbol]",gn="[object ArrayBuffer]",yn="[object DataView]",bn="[object Float32Array]",vn="[object Float64Array]",wn="[object Int8Array]",Tn="[object Int16Array]",On="[object Int32Array]",jn="[object Uint8Array]",Pn="[object Uint8ClampedArray]",Sn="[object Uint16Array]",An="[object Uint32Array]";function In(t,e,r){var o=t.constructor;switch(e){case gn:return it(t);case pn:case ln:return new o(+t);case yn:return Mr(t,r);case bn:case vn:case wn:case Tn:case On:case jn:case Pn:case Sn:case An:return Dr(t,r);case mn:return new o;case un:case hn:return new o(t);case dn:return Nr(t);case cn:return new o;case xn:return Lr(t)}}var Ur=In;function _n(t){return typeof t.constructor=="function"&&!H(t)?le(Tt(t)):{}}var kr=_n;var En="[object Map]";function Cn(t){return S(t)&&at(t)==En}var zr=Cn;var Kr=C&&C.isMap,Fn=Kr?Y(Kr):zr,Gr=Fn;var Mn="[object Set]";function Nn(t){return S(t)&&at(t)==Mn}var Wr=Nn;var $r=C&&C.isSet,Rn=$r?Y($r):Wr,Hr=Rn;var Bn=1,Ln=2,Dn=4,qr="[object Arguments]",Un="[object Array]",kn="[object Boolean]",zn="[object Date]",Kn="[object Error]",Yr="[object Function]",Gn="[object GeneratorFunction]",Wn="[object Map]",$n="[object Number]",Vr="[object Object]",Hn="[object RegExp]",qn="[object Set]",Yn="[object String]",Vn="[object Symbol]",Zn="[object WeakMap]",Jn="[object ArrayBuffer]",Xn="[object DataView]",Qn="[object Float32Array]",tf="[object Float64Array]",ef="[object Int8Array]",rf="[object Int16Array]",of="[object Int32Array]",af="[object Uint8Array]",sf="[object Uint8ClampedArray]",nf="[object Uint16Array]",ff="[object Uint32Array]",d={};d[qr]=d[Un]=d[Jn]=d[Xn]=d[kn]=d[zn]=d[Qn]=d[tf]=d[ef]=d[rf]=d[of]=d[Wn]=d[$n]=d[Vr]=d[Hn]=d[qn]=d[Yn]=d[Vn]=d[af]=d[sf]=d[nf]=d[ff]=!0;d[Kn]=d[Yr]=d[Zn]=!1;function _t(t,e,r,o,a,s){var n,i=e&Bn,f=e&Ln,m=e&Dn;if(r&&(n=a?r(t,o,a,s):r(t)),n!==void 0)return n;if(!P(t))return t;var h=v(t);if(h){if(n=Fr(t),!i)return ue(t,n)}else{var b=at(t),j=b==Yr||b==Gn;if(bt(t))return vr(t,i);if(b==Vr||b==qr||j&&!a){if(n=f||j?{}:kr(t),!i)return f?jr(t,hr(n,t)):Or(t,cr(n,t))}else{if(!d[b])return a?t:{};n=Ur(t,b,i)}}s||(s=new dr);var T=s.get(t);if(T)return T;s.set(t,n),Hr(t)?t.forEach(function(y){n.add(_t(y,e,r,y,t,s))}):Gr(t)&&t.forEach(function(y,p){n.set(p,_t(y,e,r,p,t,s))});var g=m?f?Sr:Pr:f?Z:V,I=h?void 0:g(t);return ge(I||t,function(y,p){I&&(p=y,y=t[p]),W(n,p,_t(y,e,r,p,t,s))}),n}var Zr=_t;var pf=1,lf=4;function mf(t){return Zr(t,pf|lf)}var Lt=mf;function uf(t,e){return t!=null&&e in Object(t)}var Jr=uf;function df(t,e,r){e=D(e,t);for(var o=-1,a=e.length,s=!1;++o<a;){var n=tt(e[o]);if(!(s=t!=null&&r(t,n)))break;t=t[n]}return s||++o!=a?s:(a=t==null?0:t.length,!!a&&$(a)&&G(n,a)&&(v(t)||q(t)))}var Xr=df;function cf(t,e){return t!=null&&Xr(t,e,Jr)}var Qr=cf;function hf(t,e,r,o){if(!P(t))return t;e=D(e,t);for(var a=-1,s=e.length,n=s-1,i=t;i!=null&&++a<s;){var f=tt(e[a]),m=r;if(f==="__proto__"||f==="constructor"||f==="prototype")return t;if(a!=n){var h=i[f];m=o?o(h,f,i):void 0,m===void 0&&(m=P(h)?h:G(e[a+1])?[]:{})}W(i,f,m),i=i[f]}return t}var to=hf;function xf(t,e,r){for(var o=-1,a=e.length,s={};++o<a;){var n=e[o],i=er(t,n);r(i,n)&&to(s,D(n,t),i)}return s}var eo=xf;function gf(t,e){return eo(t,e,function(r,o){return Qr(t,o)})}var ro=gf;var yf=nr(function(t,e){return t==null?{}:ro(t,e)}),Et=yf;function oo(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 Dt=(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 bf="array",vf="bit",ao="bits",wf="byte",io="bytes",st="",Tf="exponent",Of="function",so="iec",jf="Invalid number",Pf="Invalid rounding method",Ut="jedec",Sf="object",no=".",Af="round",If="s",_f="si",Ef="kbit",Cf="kB",Ff=" ",Mf="string",Nf="0",kt={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 fo(t,{bits:e=!1,pad:r=!1,base:o=-1,round:a=2,locale:s=st,localeOptions:n={},separator:i=st,spacer:f=Ff,symbols:m={},standard:h=st,output:b=Mf,fullform:j=!1,fullforms:T=[],exponent:g=-1,roundingMethod:I=Af,precision:y=0}={}){let p=g,u=Number(t),l=[],_=0,Ct=st;h===_f?(o=10,h=Ut):h===so||h===Ut?o=2:o===2?h=so:(o=10,h=Ut);let mt=o===10?1e3:1024,po=j===!0,Kt=u<0,Gt=Math[I];if(typeof t!="bigint"&&isNaN(t))throw new TypeError(jf);if(typeof Gt!==Of)throw new TypeError(Pf);if(Kt&&(u=-u),(p===-1||isNaN(p))&&(p=Math.floor(Math.log(u)/Math.log(mt)),p<0&&(p=0)),p>8&&(y>0&&(y+=8-p),p=8),b===Tf)return p;if(u===0)l[0]=0,Ct=l[1]=kt.symbol[h][e?ao:io][p];else{_=u/(o===2?Math.pow(2,p*10):Math.pow(1e3,p)),e&&(_=_*8,_>=mt&&p<8&&(_=_/mt,p++));let nt=Math.pow(10,p>0?a:0);l[0]=Gt(_*nt)/nt,l[0]===mt&&p<8&&g===-1&&(l[0]=1,p++),Ct=l[1]=o===10&&p===1?e?Ef:Cf:kt.symbol[h][e?ao:io][p]}if(Kt&&(l[0]=-l[0]),y>0&&(l[0]=l[0].toPrecision(y)),l[1]=m[l[1]]||l[1],s===!0?l[0]=l[0].toLocaleString():s.length>0?l[0]=l[0].toLocaleString(s,n):i.length>0&&(l[0]=l[0].toString().replace(no,i)),r&&Number.isInteger(l[0])===!1&&a>0){let nt=i||no,Wt=l[0].toString().split(nt),$t=Wt[1]||st,Ht=$t.length,lo=a-Ht;l[0]=`${Wt[0]}${nt}${$t.padEnd(Ht+lo,Nf)}`}return po&&(l[1]=T[p]?T[p]:kt.fullform[h][p]+(e?vf:wf)+(l[0]===1?st:If)),b===bf?l:b===Sf?{value:l[0],symbol:l[1],exponent:p,unit:Ct}:l.join(f)}var U=class t{_tera;id;name;icon;path;url;teraUrl;parsedName;created;createdFormatted;modified;modifiedFormatted;accessed;accessedFormatted;size;sizeFormatted;mime;meta={};constructor(e){if(!e.tera)throw new Error("Basic file requires a `tera` key to access the Tera instance");Object.assign(this,e);let r=this.tera;Object.defineProperty(this,"_tera",{enumerable:!1,configurable:!1,get(){return r}}),delete this.tera,this.teraUrl=this.url.replace(/^https:\/\/tera-tools.com\/projects\/(?:.+?)\/(.+)$/,"/project/$1"),this.sizeFormatted=fo(this.size||0,{spacer:""}),this.createdFormatted=this.created?this.created.toLocaleDateString():"Unknown created date",this.modifiedFormatted=this.modified?this.modified.toLocaleDateString():"Unknown modified date",this.accessedFormatted=this.accessed?this.accessed.toLocaleDateString():"Unknown access date"}getContents(){return this._tera.getProjectFile(this.id)}setContents(e){return this._tera.setProjectFile(this.id,e)}getRefs(){return this._tera.getProjectLibrary(this.id)}setRefs(e){return this._tera.setProjectLibrary(this.id,e)}serialize(){return Et(this,["id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"])}static deserialize(e){return new t(Et(e,["tera","id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"]))}};var zt=class{settings={devMode:!0,verbosity:1,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=oo();dom={el:null,iframe:null,popup:null,stylesheet:null};methods=["handshake","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","setProjectStateFlush","setProjectStateRefresh","saveProjectState","replaceProjectState","applyProjectStatePatch","deleteProjectFile","setProjectFile","selectProjectLibrary","getProjectLibrary","setProjectLibrary","projectLog","setPageUrl","setPageTitle","uiAlert","uiSplat","uiWindow"];plugins=[];send(e){let r=Dt();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||Dt(),...Lt(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",1,"Message compose client->server:",o),this.debug("ERROR",1,"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("INFO",3,"Recieved message",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&&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("INFO",3,`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("INFO",3,"Unexpected incoming TERA-FY CLIENT message",{message:r})}}acceptPostboxes={};createProjectStatePatch(e,r){let o=qt(r,e,Yt);return this.debug("INFO",3,"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.debug("INFO",4,"[0/5] Init using server",this.settings.siteUrl)).then(()=>this.detectMode()).then(o=>{this.debug("INFO",4,"[1/5] Setting client mode to",o),this.settings.mode=o}).then(()=>this.debug("INFO",4,"[2/5] Injecting comms + styles + methods")).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>this.debug("INFO",4,"[3/5] Set server mode")).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(()=>this.debug("INFO",4,"[4/5] Run client plugins")).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings)))).then(()=>this.debug("INFO",4,"[5/5] Init complete")).catch(o=>this.debug("WARN",0,"Init caught error",o))}detectMode(){return this.settings.mode!="detect"?Promise.resolve(this.settings.mode):window.self===window.parent?Promise.resolve(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("INFO",2,"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("INFO",2,"Embeded iframe ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("INFO",2,"Using TERA window parent"),e();break;case"popup":this.debug("INFO",2,"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("INFO",3,"Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("INFO",3,"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()`)}return Promise.resolve()}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){if(!this.settings.devMode||this.settings.verbosity<1)return;let r="log",o=1;typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),typeof e[0]=="number"&&(o=e[0],e.shift()),!(this.settings.verbosity<o)&&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("INFO",2,"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 U({tera:this,...r}))}getProjectFiles(e){return this.rpc("getProjectFiles",e).then(r=>r.map(o=>new U({tera:this,...o})))}getProjectFile(e){return this.rpc("getProjectFile",e).then(r=>r&&new U({tera:this,...r}))}createProjectFile(e){return this.rpc("createProjectFile",e).then(r=>r&&new U({tera:this,...r}))}};export{zt as default};
1
+ function qt(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(i){return i});function o({obj1:i,obj2:f,basePath:m,basePathForRemoves:h,diffs:b}){var S=Object.keys(i),T=S.length,g=Object.keys(f),I=g.length,y,p=i.length-f.length;if(uo(i,f)){for(var u=0;u<T;u++){var l=Array.isArray(i)?Number(S[u]):S[u];l in f||(y=h.concat(l),b.remove.push({op:"remove",path:r(y)}))}for(var u=0;u<I;u++){var l=Array.isArray(f)?Number(g[u]):g[u];s({key:l,obj1:i,obj2:f,path:m.concat(l),pathForRemoves:m.concat(l),diffs:b})}}else{for(var u=0;u<p;u++)y=h.concat(u),b.remove.push({op:"remove",path:r(y)});for(var _=i.slice(p),u=0;u<I;u++)s({key:u,obj1:_,obj2:f,path:m.concat(u),pathForRemoves:m.concat(u+p),diffs:b})}}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 s({key:i,obj1:f,obj2:m,path:h,pathForRemoves:b,diffs:S}){var T=f[i],g=m[i];if(!(i in f)&&i in m){var I=g;S.add.push({op:"add",path:r(h),value:I})}else T!==g&&(Object(T)!==T||Object(g)!==g||mo(T,g)||!Object.keys(T).length&&!Object.keys(g).length&&String(T)!=String(g)?n(h,S,g):o({obj1:f[i],obj2:m[i],basePath:h,basePathForRemoves:b,diffs:S}))}function n(i,f,m){f.replace.push({op:"replace",path:r(i),value:m})}}function Vt(t){return[""].concat(t).join("/")}function mo(t,e){return Object.prototype.toString.call(t)!=Object.prototype.toString.call(e)}function uo(t,e){var r=t.length-e.length;if(Array.isArray(t)&&Array.isArray(e)&&r>0){for(var o=0,a=0,s=0;s<e.length&&String(t[s])===String(e[s]);s++)o++;for(var n=e.length;n>0&&String(t[n+r])===String(e[n]);n--)a++;return o>=a}return!0}var co=typeof global=="object"&&global&&global.Object===Object&&global,ut=co;var ho=typeof self=="object"&&self&&self.Object===Object&&self,xo=ut||ho||Function("return this")(),x=xo;var go=x.Symbol,w=go;var Yt=Object.prototype,yo=Yt.hasOwnProperty,bo=Yt.toString,ft=w?w.toStringTag:void 0;function vo(t){var e=yo.call(t,ft),r=t[ft];try{t[ft]=void 0;var o=!0}catch{}var a=bo.call(t);return o&&(e?t[ft]=r:delete t[ft]),a}var Zt=vo;var wo=Object.prototype,To=wo.toString;function Oo(t){return To.call(t)}var Jt=Oo;var So="[object Null]",jo="[object Undefined]",Xt=w?w.toStringTag:void 0;function Po(t){return t==null?t===void 0?jo:So:Xt&&Xt in Object(t)?Zt(t):Jt(t)}var A=Po;function Ao(t){return t!=null&&typeof t=="object"}var P=Ao;var Io="[object Symbol]";function _o(t){return typeof t=="symbol"||P(t)&&A(t)==Io}var z=_o;function Eo(t,e){for(var r=-1,o=t==null?0:t.length,a=Array(o);++r<o;)a[r]=e(t[r],r,t);return a}var Qt=Eo;var Co=Array.isArray,v=Co;var Fo=1/0,te=w?w.prototype:void 0,ee=te?te.toString:void 0;function re(t){if(typeof t=="string")return t;if(v(t))return Qt(t,re)+"";if(z(t))return ee?ee.call(t):"";var e=t+"";return e=="0"&&1/t==-Fo?"-0":e}var oe=re;function No(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}var j=No;function Mo(t){return t}var ae=Mo;var Ro="[object AsyncFunction]",Bo="[object Function]",Lo="[object GeneratorFunction]",Do="[object Proxy]";function Uo(t){if(!j(t))return!1;var e=A(t);return e==Bo||e==Lo||e==Ro||e==Do}var dt=Uo;var ko=x["__core-js_shared__"],ct=ko;var ie=function(){var t=/[^.]+$/.exec(ct&&ct.keys&&ct.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();function zo(t){return!!ie&&ie in t}var se=zo;var Ko=Function.prototype,Go=Ko.toString;function Wo(t){if(t!=null){try{return Go.call(t)}catch{}try{return t+""}catch{}}return""}var E=Wo;var $o=/[\\^$.*+?()[\]{}|]/g,Ho=/^\[object .+?Constructor\]$/,qo=Function.prototype,Vo=Object.prototype,Yo=qo.toString,Zo=Vo.hasOwnProperty,Jo=RegExp("^"+Yo.call(Zo).replace($o,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Xo(t){if(!j(t)||se(t))return!1;var e=dt(t)?Jo:Ho;return e.test(E(t))}var ne=Xo;function Qo(t,e){return t?.[e]}var fe=Qo;function ta(t,e){var r=fe(t,e);return ne(r)?r:void 0}var O=ta;var ea=O(x,"WeakMap"),ht=ea;var pe=Object.create,ra=function(){function t(){}return function(e){if(!j(e))return{};if(pe)return pe(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),le=ra;function oa(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}var me=oa;function aa(t,e){var r=-1,o=t.length;for(e||(e=Array(o));++r<o;)e[r]=t[r];return e}var ue=aa;var ia=800,sa=16,na=Date.now;function fa(t){var e=0,r=0;return function(){var o=na(),a=sa-(o-r);if(r=o,a>0){if(++e>=ia)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var de=fa;function pa(t){return function(){return t}}var ce=pa;var la=function(){try{var t=O(Object,"defineProperty");return t({},"",{}),t}catch{}}(),K=la;var ma=K?function(t,e){return K(t,"toString",{configurable:!0,enumerable:!1,value:ce(e),writable:!0})}:ae,he=ma;var ua=de(he),xe=ua;function da(t,e){for(var r=-1,o=t==null?0:t.length;++r<o&&e(t[r],r,t)!==!1;);return t}var ge=da;var ca=9007199254740991,ha=/^(?:0|[1-9]\d*)$/;function xa(t,e){var r=typeof t;return e=e??ca,!!e&&(r=="number"||r!="symbol"&&ha.test(t))&&t>-1&&t%1==0&&t<e}var G=xa;function ga(t,e,r){e=="__proto__"&&K?K(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var xt=ga;function ya(t,e){return t===e||t!==t&&e!==e}var gt=ya;var ba=Object.prototype,va=ba.hasOwnProperty;function wa(t,e,r){var o=t[e];(!(va.call(t,e)&&gt(o,r))||r===void 0&&!(e in t))&&xt(t,e,r)}var W=wa;function Ta(t,e,r,o){var a=!r;r||(r={});for(var s=-1,n=e.length;++s<n;){var i=e[s],f=o?o(r[i],t[i],i,r,t):void 0;f===void 0&&(f=t[i]),a?xt(r,i,f):W(r,i,f)}return r}var N=Ta;var ye=Math.max;function Oa(t,e,r){return e=ye(e===void 0?t.length-1:e,0),function(){for(var o=arguments,a=-1,s=ye(o.length-e,0),n=Array(s);++a<s;)n[a]=o[e+a];a=-1;for(var i=Array(e+1);++a<e;)i[a]=o[a];return i[e]=r(n),me(t,this,i)}}var be=Oa;var Sa=9007199254740991;function ja(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Sa}var $=ja;function Pa(t){return t!=null&&$(t.length)&&!dt(t)}var yt=Pa;var Aa=Object.prototype;function Ia(t){var e=t&&t.constructor,r=typeof e=="function"&&e.prototype||Aa;return t===r}var H=Ia;function _a(t,e){for(var r=-1,o=Array(t);++r<t;)o[r]=e(r);return o}var ve=_a;var Ea="[object Arguments]";function Ca(t){return P(t)&&A(t)==Ea}var Ft=Ca;var we=Object.prototype,Fa=we.hasOwnProperty,Na=we.propertyIsEnumerable,Ma=Ft(function(){return arguments}())?Ft:function(t){return P(t)&&Fa.call(t,"callee")&&!Na.call(t,"callee")},q=Ma;function Ra(){return!1}var Te=Ra;var je=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Oe=je&&typeof module=="object"&&module&&!module.nodeType&&module,Ba=Oe&&Oe.exports===je,Se=Ba?x.Buffer:void 0,La=Se?Se.isBuffer:void 0,Da=La||Te,bt=Da;var Ua="[object Arguments]",ka="[object Array]",za="[object Boolean]",Ka="[object Date]",Ga="[object Error]",Wa="[object Function]",$a="[object Map]",Ha="[object Number]",qa="[object Object]",Va="[object RegExp]",Ya="[object Set]",Za="[object String]",Ja="[object WeakMap]",Xa="[object ArrayBuffer]",Qa="[object DataView]",ti="[object Float32Array]",ei="[object Float64Array]",ri="[object Int8Array]",oi="[object Int16Array]",ai="[object Int32Array]",ii="[object Uint8Array]",si="[object Uint8ClampedArray]",ni="[object Uint16Array]",fi="[object Uint32Array]",c={};c[ti]=c[ei]=c[ri]=c[oi]=c[ai]=c[ii]=c[si]=c[ni]=c[fi]=!0;c[Ua]=c[ka]=c[Xa]=c[za]=c[Qa]=c[Ka]=c[Ga]=c[Wa]=c[$a]=c[Ha]=c[qa]=c[Va]=c[Ya]=c[Za]=c[Ja]=!1;function pi(t){return P(t)&&$(t.length)&&!!c[A(t)]}var Pe=pi;function li(t){return function(e){return t(e)}}var V=li;var Ae=typeof exports=="object"&&exports&&!exports.nodeType&&exports,pt=Ae&&typeof module=="object"&&module&&!module.nodeType&&module,mi=pt&&pt.exports===Ae,Nt=mi&&ut.process,ui=function(){try{var t=pt&&pt.require&&pt.require("util").types;return t||Nt&&Nt.binding&&Nt.binding("util")}catch{}}(),C=ui;var Ie=C&&C.isTypedArray,di=Ie?V(Ie):Pe,_e=di;var ci=Object.prototype,hi=ci.hasOwnProperty;function xi(t,e){var r=v(t),o=!r&&q(t),a=!r&&!o&&bt(t),s=!r&&!o&&!a&&_e(t),n=r||o||a||s,i=n?ve(t.length,String):[],f=i.length;for(var m in t)(e||hi.call(t,m))&&!(n&&(m=="length"||a&&(m=="offset"||m=="parent")||s&&(m=="buffer"||m=="byteLength"||m=="byteOffset")||G(m,f)))&&i.push(m);return i}var vt=xi;function gi(t,e){return function(r){return t(e(r))}}var wt=gi;var yi=wt(Object.keys,Object),Ee=yi;var bi=Object.prototype,vi=bi.hasOwnProperty;function wi(t){if(!H(t))return Ee(t);var e=[];for(var r in Object(t))vi.call(t,r)&&r!="constructor"&&e.push(r);return e}var Ce=wi;function Ti(t){return yt(t)?vt(t):Ce(t)}var Y=Ti;function Oi(t){var e=[];if(t!=null)for(var r in Object(t))e.push(r);return e}var Fe=Oi;var Si=Object.prototype,ji=Si.hasOwnProperty;function Pi(t){if(!j(t))return Fe(t);var e=H(t),r=[];for(var o in t)o=="constructor"&&(e||!ji.call(t,o))||r.push(o);return r}var Ne=Pi;function Ai(t){return yt(t)?vt(t,!0):Ne(t)}var Z=Ai;var Ii=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,_i=/^\w*$/;function Ei(t,e){if(v(t))return!1;var r=typeof t;return r=="number"||r=="symbol"||r=="boolean"||t==null||z(t)?!0:_i.test(t)||!Ii.test(t)||e!=null&&t in Object(e)}var Me=Ei;var Ci=O(Object,"create"),F=Ci;function Fi(){this.__data__=F?F(null):{},this.size=0}var Re=Fi;function Ni(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}var Be=Ni;var Mi="__lodash_hash_undefined__",Ri=Object.prototype,Bi=Ri.hasOwnProperty;function Li(t){var e=this.__data__;if(F){var r=e[t];return r===Mi?void 0:r}return Bi.call(e,t)?e[t]:void 0}var Le=Li;var Di=Object.prototype,Ui=Di.hasOwnProperty;function ki(t){var e=this.__data__;return F?e[t]!==void 0:Ui.call(e,t)}var De=ki;var zi="__lodash_hash_undefined__";function Ki(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=F&&e===void 0?zi:e,this}var Ue=Ki;function J(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])}}J.prototype.clear=Re;J.prototype.delete=Be;J.prototype.get=Le;J.prototype.has=De;J.prototype.set=Ue;var Mt=J;function Gi(){this.__data__=[],this.size=0}var ke=Gi;function Wi(t,e){for(var r=t.length;r--;)if(gt(t[r][0],e))return r;return-1}var M=Wi;var $i=Array.prototype,Hi=$i.splice;function qi(t){var e=this.__data__,r=M(e,t);if(r<0)return!1;var o=e.length-1;return r==o?e.pop():Hi.call(e,r,1),--this.size,!0}var ze=qi;function Vi(t){var e=this.__data__,r=M(e,t);return r<0?void 0:e[r][1]}var Ke=Vi;function Yi(t){return M(this.__data__,t)>-1}var Ge=Yi;function Zi(t,e){var r=this.__data__,o=M(r,t);return o<0?(++this.size,r.push([t,e])):r[o][1]=e,this}var We=Zi;function X(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])}}X.prototype.clear=ke;X.prototype.delete=ze;X.prototype.get=Ke;X.prototype.has=Ge;X.prototype.set=We;var R=X;var Ji=O(x,"Map"),B=Ji;function Xi(){this.size=0,this.__data__={hash:new Mt,map:new(B||R),string:new Mt}}var $e=Xi;function Qi(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}var He=Qi;function ts(t,e){var r=t.__data__;return He(e)?r[typeof e=="string"?"string":"hash"]:r.map}var L=ts;function es(t){var e=L(this,t).delete(t);return this.size-=e?1:0,e}var qe=es;function rs(t){return L(this,t).get(t)}var Ve=rs;function os(t){return L(this,t).has(t)}var Ye=os;function as(t,e){var r=L(this,t),o=r.size;return r.set(t,e),this.size+=r.size==o?0:1,this}var Ze=as;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=$e;Q.prototype.delete=qe;Q.prototype.get=Ve;Q.prototype.has=Ye;Q.prototype.set=Ze;var lt=Q;var is="Expected a function";function Rt(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new TypeError(is);var r=function(){var o=arguments,a=e?e.apply(this,o):o[0],s=r.cache;if(s.has(a))return s.get(a);var n=t.apply(this,o);return r.cache=s.set(a,n)||s,n};return r.cache=new(Rt.Cache||lt),r}Rt.Cache=lt;var Je=Rt;var ss=500;function ns(t){var e=Je(t,function(o){return r.size===ss&&r.clear(),o}),r=e.cache;return e}var Xe=ns;var fs=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ps=/\\(\\)?/g,ls=Xe(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(fs,function(r,o,a,s){e.push(a?s.replace(ps,"$1"):o||r)}),e}),Qe=ls;function ms(t){return t==null?"":oe(t)}var tr=ms;function us(t,e){return v(t)?t:Me(t,e)?[t]:Qe(tr(t))}var D=us;var ds=1/0;function cs(t){if(typeof t=="string"||z(t))return t;var e=t+"";return e=="0"&&1/t==-ds?"-0":e}var tt=cs;function hs(t,e){e=D(e,t);for(var r=0,o=e.length;t!=null&&r<o;)t=t[tt(e[r++])];return r&&r==o?t:void 0}var er=hs;function xs(t,e){for(var r=-1,o=e.length,a=t.length;++r<o;)t[a+r]=e[r];return t}var et=xs;var rr=w?w.isConcatSpreadable:void 0;function gs(t){return v(t)||q(t)||!!(rr&&t&&t[rr])}var or=gs;function ar(t,e,r,o,a){var s=-1,n=t.length;for(r||(r=or),a||(a=[]);++s<n;){var i=t[s];e>0&&r(i)?e>1?ar(i,e-1,r,o,a):et(a,i):o||(a[a.length]=i)}return a}var ir=ar;function ys(t){var e=t==null?0:t.length;return e?ir(t,1):[]}var sr=ys;function bs(t){return xe(be(t,void 0,sr),t+"")}var nr=bs;var vs=wt(Object.getPrototypeOf,Object),Tt=vs;function ws(){this.__data__=new R,this.size=0}var fr=ws;function Ts(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r}var pr=Ts;function Os(t){return this.__data__.get(t)}var lr=Os;function Ss(t){return this.__data__.has(t)}var mr=Ss;var js=200;function Ps(t,e){var r=this.__data__;if(r instanceof R){var o=r.__data__;if(!B||o.length<js-1)return o.push([t,e]),this.size=++r.size,this;r=this.__data__=new lt(o)}return r.set(t,e),this.size=r.size,this}var ur=Ps;function rt(t){var e=this.__data__=new R(t);this.size=e.size}rt.prototype.clear=fr;rt.prototype.delete=pr;rt.prototype.get=lr;rt.prototype.has=mr;rt.prototype.set=ur;var dr=rt;function As(t,e){return t&&N(e,Y(e),t)}var cr=As;function Is(t,e){return t&&N(e,Z(e),t)}var hr=Is;var br=typeof exports=="object"&&exports&&!exports.nodeType&&exports,xr=br&&typeof module=="object"&&module&&!module.nodeType&&module,_s=xr&&xr.exports===br,gr=_s?x.Buffer:void 0,yr=gr?gr.allocUnsafe:void 0;function Es(t,e){if(e)return t.slice();var r=t.length,o=yr?yr(r):new t.constructor(r);return t.copy(o),o}var vr=Es;function Cs(t,e){for(var r=-1,o=t==null?0:t.length,a=0,s=[];++r<o;){var n=t[r];e(n,r,t)&&(s[a++]=n)}return s}var wr=Cs;function Fs(){return[]}var Ot=Fs;var Ns=Object.prototype,Ms=Ns.propertyIsEnumerable,Tr=Object.getOwnPropertySymbols,Rs=Tr?function(t){return t==null?[]:(t=Object(t),wr(Tr(t),function(e){return Ms.call(t,e)}))}:Ot,ot=Rs;function Bs(t,e){return N(t,ot(t),e)}var Or=Bs;var Ls=Object.getOwnPropertySymbols,Ds=Ls?function(t){for(var e=[];t;)et(e,ot(t)),t=Tt(t);return e}:Ot,St=Ds;function Us(t,e){return N(t,St(t),e)}var Sr=Us;function ks(t,e,r){var o=e(t);return v(t)?o:et(o,r(t))}var jt=ks;function zs(t){return jt(t,Y,ot)}var jr=zs;function Ks(t){return jt(t,Z,St)}var Pr=Ks;var Gs=O(x,"DataView"),Pt=Gs;var Ws=O(x,"Promise"),At=Ws;var $s=O(x,"Set"),It=$s;var Ar="[object Map]",Hs="[object Object]",Ir="[object Promise]",_r="[object Set]",Er="[object WeakMap]",Cr="[object DataView]",qs=E(Pt),Vs=E(B),Ys=E(At),Zs=E(It),Js=E(ht),k=A;(Pt&&k(new Pt(new ArrayBuffer(1)))!=Cr||B&&k(new B)!=Ar||At&&k(At.resolve())!=Ir||It&&k(new It)!=_r||ht&&k(new ht)!=Er)&&(k=function(t){var e=A(t),r=e==Hs?t.constructor:void 0,o=r?E(r):"";if(o)switch(o){case qs:return Cr;case Vs:return Ar;case Ys:return Ir;case Zs:return _r;case Js:return Er}return e});var at=k;var Xs=Object.prototype,Qs=Xs.hasOwnProperty;function tn(t){var e=t.length,r=new t.constructor(e);return e&&typeof t[0]=="string"&&Qs.call(t,"index")&&(r.index=t.index,r.input=t.input),r}var Fr=tn;var en=x.Uint8Array,Bt=en;function rn(t){var e=new t.constructor(t.byteLength);return new Bt(e).set(new Bt(t)),e}var it=rn;function on(t,e){var r=e?it(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}var Nr=on;var an=/\w*$/;function sn(t){var e=new t.constructor(t.source,an.exec(t));return e.lastIndex=t.lastIndex,e}var Mr=sn;var Rr=w?w.prototype:void 0,Br=Rr?Rr.valueOf:void 0;function nn(t){return Br?Object(Br.call(t)):{}}var Lr=nn;function fn(t,e){var r=e?it(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}var Dr=fn;var pn="[object Boolean]",ln="[object Date]",mn="[object Map]",un="[object Number]",dn="[object RegExp]",cn="[object Set]",hn="[object String]",xn="[object Symbol]",gn="[object ArrayBuffer]",yn="[object DataView]",bn="[object Float32Array]",vn="[object Float64Array]",wn="[object Int8Array]",Tn="[object Int16Array]",On="[object Int32Array]",Sn="[object Uint8Array]",jn="[object Uint8ClampedArray]",Pn="[object Uint16Array]",An="[object Uint32Array]";function In(t,e,r){var o=t.constructor;switch(e){case gn:return it(t);case pn:case ln:return new o(+t);case yn:return Nr(t,r);case bn:case vn:case wn:case Tn:case On:case Sn:case jn:case Pn:case An:return Dr(t,r);case mn:return new o;case un:case hn:return new o(t);case dn:return Mr(t);case cn:return new o;case xn:return Lr(t)}}var Ur=In;function _n(t){return typeof t.constructor=="function"&&!H(t)?le(Tt(t)):{}}var kr=_n;var En="[object Map]";function Cn(t){return P(t)&&at(t)==En}var zr=Cn;var Kr=C&&C.isMap,Fn=Kr?V(Kr):zr,Gr=Fn;var Nn="[object Set]";function Mn(t){return P(t)&&at(t)==Nn}var Wr=Mn;var $r=C&&C.isSet,Rn=$r?V($r):Wr,Hr=Rn;var Bn=1,Ln=2,Dn=4,qr="[object Arguments]",Un="[object Array]",kn="[object Boolean]",zn="[object Date]",Kn="[object Error]",Vr="[object Function]",Gn="[object GeneratorFunction]",Wn="[object Map]",$n="[object Number]",Yr="[object Object]",Hn="[object RegExp]",qn="[object Set]",Vn="[object String]",Yn="[object Symbol]",Zn="[object WeakMap]",Jn="[object ArrayBuffer]",Xn="[object DataView]",Qn="[object Float32Array]",tf="[object Float64Array]",ef="[object Int8Array]",rf="[object Int16Array]",of="[object Int32Array]",af="[object Uint8Array]",sf="[object Uint8ClampedArray]",nf="[object Uint16Array]",ff="[object Uint32Array]",d={};d[qr]=d[Un]=d[Jn]=d[Xn]=d[kn]=d[zn]=d[Qn]=d[tf]=d[ef]=d[rf]=d[of]=d[Wn]=d[$n]=d[Yr]=d[Hn]=d[qn]=d[Vn]=d[Yn]=d[af]=d[sf]=d[nf]=d[ff]=!0;d[Kn]=d[Vr]=d[Zn]=!1;function _t(t,e,r,o,a,s){var n,i=e&Bn,f=e&Ln,m=e&Dn;if(r&&(n=a?r(t,o,a,s):r(t)),n!==void 0)return n;if(!j(t))return t;var h=v(t);if(h){if(n=Fr(t),!i)return ue(t,n)}else{var b=at(t),S=b==Vr||b==Gn;if(bt(t))return vr(t,i);if(b==Yr||b==qr||S&&!a){if(n=f||S?{}:kr(t),!i)return f?Sr(t,hr(n,t)):Or(t,cr(n,t))}else{if(!d[b])return a?t:{};n=Ur(t,b,i)}}s||(s=new dr);var T=s.get(t);if(T)return T;s.set(t,n),Hr(t)?t.forEach(function(y){n.add(_t(y,e,r,y,t,s))}):Gr(t)&&t.forEach(function(y,p){n.set(p,_t(y,e,r,p,t,s))});var g=m?f?Pr:jr:f?Z:Y,I=h?void 0:g(t);return ge(I||t,function(y,p){I&&(p=y,y=t[p]),W(n,p,_t(y,e,r,p,t,s))}),n}var Zr=_t;var pf=1,lf=4;function mf(t){return Zr(t,pf|lf)}var Lt=mf;function uf(t,e){return t!=null&&e in Object(t)}var Jr=uf;function df(t,e,r){e=D(e,t);for(var o=-1,a=e.length,s=!1;++o<a;){var n=tt(e[o]);if(!(s=t!=null&&r(t,n)))break;t=t[n]}return s||++o!=a?s:(a=t==null?0:t.length,!!a&&$(a)&&G(n,a)&&(v(t)||q(t)))}var Xr=df;function cf(t,e){return t!=null&&Xr(t,e,Jr)}var Qr=cf;function hf(t,e,r,o){if(!j(t))return t;e=D(e,t);for(var a=-1,s=e.length,n=s-1,i=t;i!=null&&++a<s;){var f=tt(e[a]),m=r;if(f==="__proto__"||f==="constructor"||f==="prototype")return t;if(a!=n){var h=i[f];m=o?o(h,f,i):void 0,m===void 0&&(m=j(h)?h:G(e[a+1])?[]:{})}W(i,f,m),i=i[f]}return t}var to=hf;function xf(t,e,r){for(var o=-1,a=e.length,s={};++o<a;){var n=e[o],i=er(t,n);r(i,n)&&to(s,D(n,t),i)}return s}var eo=xf;function gf(t,e){return eo(t,e,function(r,o){return Qr(t,o)})}var ro=gf;var yf=nr(function(t,e){return t==null?{}:ro(t,e)}),Et=yf;function oo(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 Dt=(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 bf="array",vf="bit",ao="bits",wf="byte",io="bytes",st="",Tf="exponent",Of="function",so="iec",Sf="Invalid number",jf="Invalid rounding method",Ut="jedec",Pf="object",no=".",Af="round",If="s",_f="si",Ef="kbit",Cf="kB",Ff=" ",Nf="string",Mf="0",kt={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 fo(t,{bits:e=!1,pad:r=!1,base:o=-1,round:a=2,locale:s=st,localeOptions:n={},separator:i=st,spacer:f=Ff,symbols:m={},standard:h=st,output:b=Nf,fullform:S=!1,fullforms:T=[],exponent:g=-1,roundingMethod:I=Af,precision:y=0}={}){let p=g,u=Number(t),l=[],_=0,Ct=st;h===_f?(o=10,h=Ut):h===so||h===Ut?o=2:o===2?h=so:(o=10,h=Ut);let mt=o===10?1e3:1024,po=S===!0,Kt=u<0,Gt=Math[I];if(typeof t!="bigint"&&isNaN(t))throw new TypeError(Sf);if(typeof Gt!==Of)throw new TypeError(jf);if(Kt&&(u=-u),(p===-1||isNaN(p))&&(p=Math.floor(Math.log(u)/Math.log(mt)),p<0&&(p=0)),p>8&&(y>0&&(y+=8-p),p=8),b===Tf)return p;if(u===0)l[0]=0,Ct=l[1]=kt.symbol[h][e?ao:io][p];else{_=u/(o===2?Math.pow(2,p*10):Math.pow(1e3,p)),e&&(_=_*8,_>=mt&&p<8&&(_=_/mt,p++));let nt=Math.pow(10,p>0?a:0);l[0]=Gt(_*nt)/nt,l[0]===mt&&p<8&&g===-1&&(l[0]=1,p++),Ct=l[1]=o===10&&p===1?e?Ef:Cf:kt.symbol[h][e?ao:io][p]}if(Kt&&(l[0]=-l[0]),y>0&&(l[0]=l[0].toPrecision(y)),l[1]=m[l[1]]||l[1],s===!0?l[0]=l[0].toLocaleString():s.length>0?l[0]=l[0].toLocaleString(s,n):i.length>0&&(l[0]=l[0].toString().replace(no,i)),r&&Number.isInteger(l[0])===!1&&a>0){let nt=i||no,Wt=l[0].toString().split(nt),$t=Wt[1]||st,Ht=$t.length,lo=a-Ht;l[0]=`${Wt[0]}${nt}${$t.padEnd(Ht+lo,Mf)}`}return po&&(l[1]=T[p]?T[p]:kt.fullform[h][p]+(e?vf:wf)+(l[0]===1?st:If)),b===bf?l:b===Pf?{value:l[0],symbol:l[1],exponent:p,unit:Ct}:l.join(f)}var U=class t{_tera;id;name;icon;path;url;teraUrl;parsedName;created;createdFormatted;modified;modifiedFormatted;accessed;accessedFormatted;size;sizeFormatted;mime;meta={};constructor(e){if(!e.tera)throw new Error("Basic file requires a `tera` key to access the Tera instance");Object.assign(this,e);let r=this.tera;Object.defineProperty(this,"_tera",{enumerable:!1,configurable:!1,get(){return r}}),delete this.tera,this.teraUrl=this.url.replace(/^https:\/\/tera-tools.com\/projects\/(?:.+?)\/project\/(.+)$/,"/project/$1"),this.sizeFormatted=fo(this.size||0,{spacer:""}),this.createdFormatted=this.created?this.created.toLocaleDateString():"Unknown created date",this.modifiedFormatted=this.modified?this.modified.toLocaleDateString():"Unknown modified date",this.accessedFormatted=this.accessed?this.accessed.toLocaleDateString():"Unknown access date"}getContents(){return this._tera.getProjectFile(this.id)}setContents(e){return this._tera.setProjectFile(this.id,e)}getRefs(){return this._tera.getProjectLibrary(this.id)}setRefs(e){return this._tera.setProjectLibrary(this.id,e)}serialize(){return Et(this,["id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"])}static deserialize(e){return new t(Et(e,["tera","id","name","icon","path","url","parsedName","created","modified","accessed","size","mime","meta"]))}};var zt=class{settings={devMode:!0,verbosity:1,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=oo();dom={el:null,iframe:null,popup:null,stylesheet:null};methods=["handshake","setServerVerbosity","getUser","requireUser","bindProject","getProject","getProjects","setActiveProject","requireProject","selectProject","getProjectState","setProjectState","setProjectStateDefaults","setProjectStateFlush","setProjectStateRefresh","saveProjectState","replaceProjectState","applyProjectStatePatch","deleteProjectFile","setProjectFile","selectProjectLibrary","getProjectLibrary","setProjectLibrary","projectLog","setPageUrl","setPageTitle","uiAlert","uiProgress","uiSplat","uiWindow"];plugins=[];send(e){let r=Dt();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||Dt(),...Lt(e)},this.settings.mode=="parent")window.parent.postMessage(r,this.settings.restrictOrigin);else if(this.settings.mode=="child")console.log("SEND DOWN",{target:this.dom.iframe.contentWindow,payload:r,restrictOrigin:this.settings.restrictOrigin}),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",1,"Message compose client->server:",o),this.debug("ERROR",1,"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("INFO",3,"Recieved message",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&&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("INFO",3,`Ignoring message ID ${r.id} - was meant for someone else?`):this.debug("INFO",3,"Unexpected incoming TERA-FY CLIENT message",{message:r})}}acceptPostboxes={};createProjectStatePatch(e,r){let o=qt(r,e,Vt);return this.debug("INFO",3,"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.debug("INFO",4,"[0/6] Init using server",this.settings.siteUrl)).then(()=>this.detectMode()).then(o=>{this.debug("INFO",4,"[1/6] Setting client mode to",o),this.settings.mode=o}).then(()=>this.debug("INFO",4,"[2/6] Injecting comms + styles + methods")).then(()=>Promise.all([this.injectComms(),this.injectStylesheet(),this.injectMethods()])).then(()=>{if(this.settings.verbosity<=1){this.debug("INFO",4,"[3/6] Skip - Server verbosity is already at 1");return}else return this.debug("INFO",4,`[3/6] Set server verbosity to ${this.settings.verbosity}`),this.rpc("setServerVerbsity",this.settings.verbosity)}).then(()=>this.debug("INFO",4,`[4/6] Set server mode to "${this.settings.mode}"`)).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(()=>this.debug("INFO",4,"[5/6] Run client plugins")).then(()=>Promise.all(this.plugins.map(o=>o.init.call(r,this.settings)))).then(()=>this.debug("INFO",4,"[6/6] Init complete")).catch(o=>this.debug("WARN",0,"Init process fault",o))}detectMode(){return this.settings.mode!="detect"?Promise.resolve(this.settings.mode):window.self===window.parent?Promise.resolve(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("INFO",2,"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("INFO",2,"Embeded iframe ready"),e()}),this.dom.iframe.src=this.settings.siteUrl,this.dom.el.append(this.dom.iframe);break;case"parent":this.debug("INFO",2,"Using TERA window parent"),e();break;case"popup":this.debug("INFO",2,"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("INFO",3,"Trying handshake",++r),clearTimeout(o),o=setTimeout(a,this.settings.handshakeInterval),this.rpc("handshake").then(()=>{clearTimeout(o),this.debug("INFO",3,"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()`)}return Promise.resolve()}injectMethods(){this.methods.forEach(e=>this[e]=this.rpc.bind(this,e))}debug(...e){if(!this.settings.devMode||this.settings.verbosity<1)return;let r="log",o=1;typeof e[0]=="string"&&["INFO","LOG","WARN","ERROR"].includes(e[0])&&(r=e.shift().toLowerCase()),typeof e[0]=="number"&&(o=e[0],e.shift()),!(this.settings.verbosity<o)&&console[r]("%c[TERA-FY CLIENT]","font-weight: bold; color: #ff5722;",...e)}set(e,r,o){let a={ignoreNullish:!0,...o};return typeof e=="string"?(!a.ignoreNullish||r!=null)&&(this.settings[e]=r):Object.assign(this.settings,e),this.toggleDevMode(this.settings.devMode)}setIfDev(e,r,o){return!this.settings.devMode||r===void 0?this:this.set(e,r,o)}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 e==="toggle"?this.settings.devMode=!this.settings.devMode:e==="proxy"?Object.assign(this.settings,{devMode:!0,siteUrl:"http://localhost:7334/embed",mode:"child"}):this.settings.devMode=!!e,this.dom.el&&this.dom.el.classList.toggle("dev-mode",this.settings.devMode),this}toggleFocus(e="toggle"){this.debug("INFO",2,"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 U({tera:this,...r}))}getProjectFiles(e){return this.rpc("getProjectFiles",e).then(r=>r.map(o=>new U({tera:this,...o})))}getProjectFile(e){return this.rpc("getProjectFile",e).then(r=>r&&new U({tera:this,...r}))}createProjectFile(e){return this.rpc("createProjectFile",e).then(r=>r&&new U({tera:this,...r}))}};export{zt as default};
3
3
  /*! Bundled license information:
4
4
 
5
5
  lodash-es/lodash.js:
@@ -164,7 +164,7 @@ export default class ProjectFile {
164
164
  delete this.tera; // Remove original ref we merged above
165
165
 
166
166
  // Calculate `teraUrl` from URL
167
- this.teraUrl = this.url.replace(/^https:\/\/tera-tools.com\/projects\/(?:.+?)\/(.+)$/, '/project/$1');
167
+ this.teraUrl = this.url.replace(/^https:\/\/tera-tools.com\/projects\/(?:.+?)\/project\/(.+)$/, '/project/$1');
168
168
 
169
169
  // Set all `*Formatted` fields
170
170
  this.sizeFormatted = filesize(this.size || 0, {spacer: ''});
@@ -84,6 +84,7 @@ export default class TeraFy {
84
84
  methods = [
85
85
  // Messages
86
86
  'handshake',
87
+ 'setServerVerbosity',
87
88
 
88
89
  // Session
89
90
  'getUser',
@@ -130,6 +131,7 @@ export default class TeraFy {
130
131
 
131
132
  // UI
132
133
  'uiAlert',
134
+ 'uiProgress',
133
135
  'uiSplat',
134
136
  'uiWindow',
135
137
  ];
@@ -186,6 +188,11 @@ export default class TeraFy {
186
188
  if (this.settings.mode == 'parent') {
187
189
  window.parent.postMessage(payload, this.settings.restrictOrigin);
188
190
  } else if (this.settings.mode == 'child') {
191
+ console.log('SEND DOWN', {
192
+ target: this.dom.iframe.contentWindow,
193
+ payload,
194
+ restrictOrigin: this.settings.restrictOrigin,
195
+ });
189
196
  this.dom.iframe.contentWindow.postMessage(payload, this.settings.restrictOrigin);
190
197
  } else if (this.settings.mode == 'popup') {
191
198
  this.dom.popup.postMessage(payload, this.settings.restrictOrigin);
@@ -335,34 +342,43 @@ export default class TeraFy {
335
342
 
336
343
  const context = this;
337
344
  return this.init.promise = Promise.resolve()
338
- .then(()=> this.debug('INFO', 4, '[0/5] Init using server', this.settings.siteUrl))
345
+ .then(()=> this.debug('INFO', 4, '[0/6] Init using server', this.settings.siteUrl))
339
346
  .then(()=> this.detectMode())
340
347
  .then(mode => {
341
- this.debug('INFO', 4, '[1/5] Setting client mode to', mode);
348
+ this.debug('INFO', 4, '[1/6] Setting client mode to', mode);
342
349
  this.settings.mode = mode;
343
350
  })
344
- .then(()=> this.debug('INFO', 4, '[2/5] Injecting comms + styles + methods'))
351
+ .then(()=> this.debug('INFO', 4, '[2/6] Injecting comms + styles + methods'))
345
352
  .then(()=> Promise.all([
346
353
  // Init core functions async
347
354
  this.injectComms(),
348
355
  this.injectStylesheet(),
349
356
  this.injectMethods(),
350
357
  ]))
351
- .then(()=> this.debug('INFO', 4, '[3/5] Set server mode'))
358
+ .then(()=> {
359
+ if (this.settings.verbosity <=1) {
360
+ this.debug('INFO', 4, '[3/6] Skip - Server verbosity is already at 1');
361
+ return;
362
+ } else {
363
+ this.debug('INFO', 4, `[3/6] Set server verbosity to ${this.settings.verbosity}`);
364
+ return this.rpc('setServerVerbsity', this.settings.verbosity);
365
+ }
366
+ })
367
+ .then(()=> this.debug('INFO', 4, `[4/6] Set server mode to "${this.settings.mode}"`))
352
368
  .then(()=> this.rpc('setServerMode', // Tell server what mode its in
353
369
  this.settings.mode == 'child' ? 'embedded'
354
370
  : this.settings.mode == 'parent' ? 'frame'
355
371
  : this.settings.mode == 'popup' ? 'popup'
356
372
  : (()=> { throw(`Unknown server mode "${this.settings.mode}"`) })()
357
373
  ))
358
- .then(()=> this.debug('INFO', 4, '[4/5] Run client plugins'))
374
+ .then(()=> this.debug('INFO', 4, '[5/6] Run client plugins'))
359
375
  .then(()=> Promise.all( // Init all plugins (with this outer module as the context)
360
376
  this.plugins.map(plugin =>
361
377
  plugin.init.call(context, this.settings)
362
378
  )
363
379
  ))
364
- .then(()=> this.debug('INFO', 4, '[5/5] Init complete'))
365
- .catch(e => this.debug('WARN', 0, 'Init caught error', e))
380
+ .then(()=> this.debug('INFO', 4, '[6/6] Init complete'))
381
+ .catch(e => this.debug('WARN', 0, 'Init process fault', e))
366
382
  }
367
383
 
368
384
 
@@ -573,11 +589,20 @@ export default class TeraFy {
573
589
  * @param {String|Object} key Either a single setting key to set or an object to merge
574
590
  * @param {*} value The value to set if `key` is a string
575
591
  *
592
+ * @param {Object} [options] Additional options to mutate behaviour
593
+ * @param {Boolean} [options.ignoreNullish=true] If falsy, this forces the setting of undefined or null values rather than ignoring them when specifying values by string
594
+ *
576
595
  * @returns {TeraFy} This chainable terafy instance
577
596
  */
578
- set(key, value) {
597
+ set(key, value, options) {
598
+ let settings = {
599
+ ignoreNullish: true,
600
+ ...options,
601
+ };
602
+
579
603
  if (typeof key == 'string') {
580
- this.settings[key] = value;
604
+ if (!settings.ignoreNullish || (value !== null && value !== undefined))
605
+ this.settings[key] = value;
581
606
  } else {
582
607
  Object.assign(this.settings, key);
583
608
  }
@@ -592,12 +617,13 @@ export default class TeraFy {
592
617
  * @see set()
593
618
  * @param {String|Object} key Either a single setting key to set or an object to merge
594
619
  * @param {*} value The value to set if `key` is a string
620
+ * @param {Object} [options] Additional options to mutate behaviour
595
621
  *
596
622
  * @returns {TeraFy} This chainable terafy instance
597
623
  */
598
- setIfDev(key, value) {
624
+ setIfDev(key, value, options) {
599
625
  if (!this.settings.devMode || value === undefined) return this;
600
- return this.set(key, value);
626
+ return this.set(key, value, options);
601
627
  }
602
628
 
603
629
 
@@ -645,15 +671,27 @@ export default class TeraFy {
645
671
 
646
672
  /**
647
673
  * Set or toggle devMode
674
+ * This function also accepts meta values:
675
+ *
676
+ * 'toggle' - Set dev mode to whatever the opposing value of the current mode
677
+ * 'proxy' - Optimize for using a loopback proxy
648
678
  *
649
- * @param {String|Boolean} [devModeEnabled='toggle'] Optional boolean to force dev mode
679
+ * @param {'toggle'|'proxy'|Boolean} [devModeEnabled='toggle'] Optional boolean to force dev mode or specify other behaviour
650
680
  *
651
681
  * @returns {TeraFy} This chainable terafy instance
652
682
  */
653
683
  toggleDevMode(devModeEnabled = 'toggle') {
654
- this.settings.devMode = devModeEnabled === 'toggle'
655
- ? !this.settings.devMode
656
- : devModeEnabled;
684
+ if (devModeEnabled === 'toggle') {
685
+ this.settings.devMode = !this.settings.devMode;
686
+ } else if (devModeEnabled === 'proxy') {
687
+ Object.assign(this.settings, {
688
+ devMode: true,
689
+ siteUrl: 'http://localhost:7334/embed',
690
+ mode: 'child',
691
+ });
692
+ } else {
693
+ this.settings.devMode = !! devModeEnabled;
694
+ }
657
695
 
658
696
  if (this.dom.el) // Have we actually set up yet?
659
697
  this.dom.el.classList.toggle('dev-mode', this.settings.devMode);
@@ -684,6 +722,14 @@ export default class TeraFy {
684
722
  */
685
723
 
686
724
 
725
+ /**
726
+ * RPC callback to set the server verbostiy level
727
+ *
728
+ * @function setServerVerbosity
729
+ * @param {Number} verbosity The desired server verbosity level
730
+ */
731
+
732
+
687
733
  /**
688
734
  * User / active session within TERA
689
735
  *
@@ -931,6 +977,7 @@ export default class TeraFy {
931
977
  *
932
978
  * @param {Object} options Options which mutate behaviour
933
979
  * @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
980
+ * @param {Boolean} [options.lazy=true] If true, use the fastest method to retrieve the file list such as the cache. If false, force a refresh each time
934
981
  * @param {Boolean} [options.meta=true] Pull meta information for each file entity
935
982
  *
936
983
  * @returns {Promise<Array<ProjectFile>>} A collection of project files for the given project
@@ -1109,14 +1156,20 @@ export default class TeraFy {
1109
1156
 
1110
1157
 
1111
1158
  /**
1112
- * Display HTML content full-screen within TERA
1113
- * This function is ideally called within a requestFocus() wrapper
1114
- *
1115
- * @function uiSplat
1116
- * @param {DOMElement|String|false} content Either a prepared DOM element or string to compile, set to falsy to remove existing content
1117
- *
1118
- * @param {Object} [options] Additional options to mutate behaviour
1119
- * @param {Boolean|String} [options.logo=false] Add a logo to the output, if boolean true the Tera-tools logo is used otherwise specify a path or URL
1159
+ * Display, update or dispose of windows for long running tasks
1160
+ * All options are cumulative - i.e. they are merged with other options previously provided
1161
+ *
1162
+ * @function uiProgress
1163
+ * @param {Object|Boolean} [options] Additional options to mutate behaviour, if boolean false `{close: true}` is assumed
1164
+ * @param {String} [options.title='TERA'] Window title, can only be set on the initial call
1165
+ * @param {String} [options.body=''] Window body text, can only be set on the initial call
1166
+ * @param {Boolean} [options.bodyHtml=false] Treat body text as HTML
1167
+ * @param {Boolean} [options.close=false] Close the existing dialog, if true the dialog is disposed and options reset
1168
+ * @param {String} [options.text] The text of the task being conducted
1169
+ * @param {Number} [options.progress] The current progress of the task being conducted, this is assumed to be a value less than `maxProgress`
1170
+ * @param {Number} [options.maxProgress] The maximum value that the progress can be
1171
+ *
1172
+ * @returns {Promise} A promise which resolves when the dialog has been updated
1120
1173
  */
1121
1174
 
1122
1175
 
@@ -1135,5 +1188,17 @@ export default class TeraFy {
1135
1188
  * @returns {WindowProxy} The opened window object (if `noopener` is not set in permissions)
1136
1189
  */
1137
1190
 
1191
+
1192
+ /**
1193
+ * Display HTML content full-screen within TERA
1194
+ * This function is ideally called within a requestFocus() wrapper
1195
+ *
1196
+ * @function uiSplat
1197
+ * @param {DOMElement|String|false} content Either a prepared DOM element or string to compile, set to falsy to remove existing content
1198
+ *
1199
+ * @param {Object} [options] Additional options to mutate behaviour
1200
+ * @param {Boolean|String} [options.logo=false] Add a logo to the output, if boolean true the Tera-tools logo is used otherwise specify a path or URL
1201
+ */
1202
+
1138
1203
  // }}}
1139
1204
  }