@inditextech/weave-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.cjs CHANGED
@@ -52,7 +52,7 @@ Error generating stack: `+p.message+`
52
52
 
53
53
  No matching component was found for:
54
54
  `)+t.join(" > ")}return null},r.getPublicRootInstance=function(t){if(t=t.current,!t.child)return null;switch(t.child.tag){case 5:return mt(t.child.stateNode);default:return t.child.stateNode}},r.injectIntoDevTools=function(t){if(t={bundleType:t.bundleType,version:t.version,rendererPackageName:t.rendererPackageName,rendererConfig:t.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:v.ReactCurrentDispatcher,findHostInstanceByFiber:Ja,findFiberByHostInstance:t.findFiberByHostInstance||zo,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.1.0"},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u")t=!1;else{var n=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(n.isDisabled||!n.supportsFiber)t=!0;else{try{to=n.inject(t),Te=n}catch{}t=!!n.checkDCE}}return t},r.isAlreadyRendering=function(){return!1},r.observeVisibleRects=function(t,n,s,a){if(!ii)throw Error(g(363));t=rr(t,n);var d=is(t,s,a).disconnect;return{disconnect:function(){d()}}},r.registerMutableSourceForHydration=function(t,n){var s=n._getVersion;s=s(n._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[n,s]:t.mutableSourceEagerHydrationData.push(n,s)},r.runWithPriority=function(t,n){var s=Me;try{return Me=t,n()}finally{Me=s}},r.shouldError=function(){return null},r.shouldSuspend=function(){return!1},r.updateContainer=function(t,n,s,a){var d=n.current,p=Lt(),P=ki(d);return s=ar(s),n.context===null?n.context=s:n.pendingContext=s,n=Sn(p,P),n.payload={element:t},a=a===void 0?null:a,a!==null&&(n.callback=a),bn(d,n),t=Et(d,P,p),t!==null&&We(t,d,P),P},r};$d.exports=ev;var tv=$d.exports;const nv=_u(tv);class iv{constructor(c,r,l){E(this,"instance");E(this,"reconciler");E(this,"serializer");E(this,"renderer");E(this,"root");this.instance=c,this.reconciler=r,this.serializer=l,this.renderer=null}init(){this.renderer=nv(this.reconciler.getConfig()),this.root=this.renderer.createContainer(this.instance,0,null,!0,null,"",c=>{console.error(c)},null),this.root.onUncaughtError=function(c){console.error(c)}}render(c){var u,h,g,v;const r=JSON.parse(JSON.stringify(this.instance.getStore().getState()));if(!((u=r==null?void 0:r.weave)!=null&&u.key)||!((h=r==null?void 0:r.weave)!=null&&h.type)||!((g=r==null?void 0:r.weave)!=null&&g.props))return;const l=this.serializer.deserialize(r.weave);(v=this.renderer)==null||v.updateContainer(l,this.root,null,c)}}class rv{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("groups-manager"),this.logger.debug("Groups manager created")}allNodesInSameParent(c){var v,S,_;const r=this.instance.getStage();if(c.length===0)return{allInSame:!1,nodeId:void 0,parentId:void 0};let l=!0;const u=r.findOne(`#${c[0].props.id}`),h=(v=u==null?void 0:u.getParent())==null?void 0:v.getAttrs().id,g=(S=u==null?void 0:u.getParent())==null?void 0:S.getAttrs().nodeId;for(const C of c){const R=r.findOne(`#${C.props.id}`);if(((_=R==null?void 0:R.getParent())==null?void 0:_.getAttrs().id)!==h){l=!1;break}}return{allInSame:l,nodeId:g,parentId:h}}group(c){this.logger.debug({nodes:c},"Grouping nodes");const r=this.instance.getStage(),l=this.instance.getStore().getState(),u=this.instance.getMainLayer();if(jt.isEmpty(l.weave)){this.logger.warn({nodes:c},"State is empty, cannot group nodes");return}const{allInSame:h,nodeId:g,parentId:v}=this.allNodesInSameParent(c);if(!h){this.logger.warn({nodes:c},"Not all nodes are in the same container, cannot group them");return}const S=this.instance.getPlugin("nodesSelection");S&&(S.getTransformer().hide(),S.setSelectedNodes([]));let _=v??wu;typeof _>"u"&&(_=wu);const C=r.findOne(`#${_}`),R=et(),D=new ne.Group({id:et(),nodeType:"group",draggable:!0});C==null||C.add(D);const Z=this.instance.getNodeHandler("group").createNode(R,{draggable:!0});this.instance.addNode(Z,g??_);const F=c.map(X=>{const se=u==null?void 0:u.findOne(`#${X.key}`);return{node:X,zIndex:(se==null?void 0:se.zIndex())??-1}}).filter(X=>X.zIndex!==-1),Y=jt.orderBy(F,["zIndex"],["asc"]).map(X=>X.node);for(const[X,se]of Y.entries()){if(se.type==="group"){const ye=se,we=u==null?void 0:u.findOne(`#${ye.key}`);if(we){const xe=we.getAbsolutePosition(),Ie=we.getAbsoluteRotation();we.moveTo(D),we.setAbsolutePosition(xe),we.rotation(Ie),we.zIndex(X),we.setAttr("id",et()),we.setAttr("draggable",!1);const gt=this.instance.getNodeHandler("group").toNode(we);this.instance.addNode(gt,R)}continue}const j=u==null?void 0:u.findOne(`#${se.key}`);if(j){const ye=j.getAbsolutePosition(),we=j.getAbsoluteRotation();j.moveTo(D),j.setAbsolutePosition(ye),j.rotation(we),j.zIndex(X),j.setAttr("id",et()),j.setAttr("draggable",!1);const Ie=this.instance.getNodeHandler(j.getAttrs().nodeType).toNode(j);this.instance.addNode(Ie,R)}}this.instance.removeNodes(Y),D.destroy(),setTimeout(()=>{const X=r.findOne(`#${R}`),se=this.instance.getPlugin("nodesSelection");if(X&&se){const j=se.getTransformer();se.setSelectedNodes([X]),j.show(),j.forceUpdate()}},0)}unGroup(c){var R,D,H;this.logger.warn({group:c},"Un-grouping group");const l=this.instance.getStage().findOne(`#${c.props.id}`);if(!l){this.logger.warn({group:c},"Group instance doesn't exists, cannot un-group");return}let u,h=this.instance.getMainLayer();if(l.getParent()&&l.getParent()instanceof ne.Group&&((R=l.getParent())!=null&&R.getAttrs().nodeId)&&(u=(D=l.getParent())==null?void 0:D.getAttrs().nodeId,h=l.getParent()),l.getParent()&&l.getParent()instanceof ne.Group&&!((H=l.getParent())!=null&&H.getAttrs().nodeId)&&(h=l.getParent()),l.getParent()&&l.getParent()instanceof ne.Layer&&(h=l.getParent()),!h){this.logger.warn({group:c},"Group target container doesn't exists, cannot un-group");return}const g=(h==null?void 0:h.getChildren().length)??0;let v;const S=[...l.getChildren()];for(const Z of S){const F=Z.getAbsolutePosition(),Y=Z.getAbsoluteRotation();Z.moveTo(h),Z.setAbsolutePosition(F),Z.rotation(Y),Z.zIndex(g-1+Z.zIndex()),Z.setAttr("id",et()),Z.setAttr("draggable",!0),v=Z.getAttrs().id;const se=this.instance.getNodeHandler(Z.getAttrs().nodeType).toNode(Z);this.instance.addNode(se,u??h.getAttrs().id),Z.destroy()}const C=this.instance.getNodeHandler("group").toNode(l);this.instance.removeNode(C),setTimeout(()=>{const Z=h.findOne(`#${v}`),F=this.instance.getPlugin("nodesSelection");Z&&F&&F.setSelectedNodes([Z])},0)}}var Eu={exports:{}};function sv(x){try{return JSON.stringify(x)}catch{return'"[Circular]"'}}var ov=lv;function lv(x,c,r){var l=r&&r.stringify||sv,u=1;if(typeof x=="object"&&x!==null){var h=c.length+u;if(h===1)return x;var g=new Array(h);g[0]=l(x);for(var v=1;v<h;v++)g[v]=l(c[v]);return g.join(" ")}if(typeof x!="string")return x;var S=c.length;if(S===0)return x;for(var _="",C=1-u,R=-1,D=x&&x.length||0,H=0;H<D;){if(x.charCodeAt(H)===37&&H+1<D){switch(R=R>-1?R:0,x.charCodeAt(H+1)){case 100:case 102:if(C>=S||c[C]==null)break;R<H&&(_+=x.slice(R,H)),_+=Number(c[C]),R=H+2,H++;break;case 105:if(C>=S||c[C]==null)break;R<H&&(_+=x.slice(R,H)),_+=Math.floor(Number(c[C])),R=H+2,H++;break;case 79:case 111:case 106:if(C>=S||c[C]===void 0)break;R<H&&(_+=x.slice(R,H));var Z=typeof c[C];if(Z==="string"){_+="'"+c[C]+"'",R=H+2,H++;break}if(Z==="function"){_+=c[C].name||"<anonymous>",R=H+2,H++;break}_+=l(c[C]),R=H+2,H++;break;case 115:if(C>=S)break;R<H&&(_+=x.slice(R,H)),_+=String(c[C]),R=H+2,H++;break;case 37:R<H&&(_+=x.slice(R,H)),_+="%",R=H+2,H++,C--;break}++C}++H}return R===-1?x:(R<D&&(_+=x.slice(R)),_)}const Yd=ov;Eu.exports=pr;const $l=Pv().console||{},av={mapHttpRequest:du,mapHttpResponse:du,wrapRequestSerializer:Uc,wrapResponseSerializer:Uc,wrapErrorSerializer:Uc,req:du,res:du,err:Qd,errWithCause:Qd};function Jr(x,c){return x==="silent"?1/0:c.levels.values[x]}const Gc=Symbol("pino.logFuncs"),Fc=Symbol("pino.hierarchy"),uv={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function Kd(x,c){const r={logger:c,parent:x[Fc]};c[Fc]=r}function cv(x,c,r){const l={};c.forEach(u=>{l[u]=r[u]?r[u]:$l[u]||$l[uv[u]||"log"]||Bo}),x[Gc]=l}function dv(x,c){return Array.isArray(x)?x.filter(function(l){return l!=="!stdSerializers.err"}):x===!0?Object.keys(c):!1}function pr(x){x=x||{},x.browser=x.browser||{};const c=x.browser.transmit;if(c&&typeof c.send!="function")throw Error("pino: transmit option must have a send function");const r=x.browser.write||$l;x.browser.write&&(x.browser.asObject=!0);const l=x.serializers||{},u=dv(x.browser.serialize,l);let h=x.browser.serialize;Array.isArray(x.browser.serialize)&&x.browser.serialize.indexOf("!stdSerializers.err")>-1&&(h=!1);const g=Object.keys(x.customLevels||{}),v=["error","fatal","warn","info","debug","trace"].concat(g);typeof r=="function"&&v.forEach(function(F){r[F]=r}),(x.enabled===!1||x.browser.disabled)&&(x.level="silent");const S=x.level||"info",_=Object.create(r);_.log||(_.log=Bo),cv(_,v,r),Kd({},_),Object.defineProperty(_,"levelVal",{get:R}),Object.defineProperty(_,"level",{get:D,set:H});const C={transmit:c,serialize:u,asObject:x.browser.asObject,formatters:x.browser.formatters,levels:v,timestamp:Sv(x),messageKey:x.messageKey||"msg",onChild:x.onChild||Bo};_.levels=fv(x),_.level=S,_.setMaxListeners=_.getMaxListeners=_.emit=_.addListener=_.on=_.prependListener=_.once=_.prependOnceListener=_.removeListener=_.removeAllListeners=_.listeners=_.listenerCount=_.eventNames=_.write=_.flush=Bo,_.serializers=l,_._serialize=u,_._stdErrSerialize=h,_.child=function(...F){return Z.call(this,C,...F)},c&&(_._logEvent=Hc());function R(){return Jr(this.level,this)}function D(){return this._level}function H(F){if(F!=="silent"&&!this.levels.values[F])throw Error("unknown level "+F);this._level=F,Fs(this,C,_,"error"),Fs(this,C,_,"fatal"),Fs(this,C,_,"warn"),Fs(this,C,_,"info"),Fs(this,C,_,"debug"),Fs(this,C,_,"trace"),g.forEach(Y=>{Fs(this,C,_,Y)})}function Z(F,Y,X){if(!Y)throw new Error("missing bindings for child Pino");X=X||{},u&&Y.serializers&&(X.serializers=Y.serializers);const se=X.serializers;if(u&&se){var j=Object.assign({},l,se),ye=x.browser.serialize===!0?Object.keys(j):u;delete Y.serializers,Zc([Y],ye,j,this._stdErrSerialize)}function we(Ie){this._childLevel=(Ie._childLevel|0)+1,this.bindings=Y,j&&(this.serializers=j,this._serialize=ye),c&&(this._logEvent=Hc([].concat(Ie._logEvent.bindings,Y)))}we.prototype=this;const xe=new we(this);return Kd(this,xe),xe.child=function(...Ie){return Z.call(this,F,...Ie)},xe.level=X.level||this.level,F.onChild(xe),xe}return _}function fv(x){const c=x.customLevels||{},r=Object.assign({},pr.levels.values,c),l=Object.assign({},pr.levels.labels,hv(c));return{values:r,labels:l}}function hv(x){const c={};return Object.keys(x).forEach(function(r){c[x[r]]=r}),c}pr.levels={values:{fatal:60,error:50,warn:40,info:30,debug:20,trace:10},labels:{10:"trace",20:"debug",30:"info",40:"warn",50:"error",60:"fatal"}};pr.stdSerializers=av;pr.stdTimeFunctions=Object.assign({},{nullTime:ef,epochTime:tf,unixTime:wv,isoTime:xv});function gv(x){const c=[];x.bindings&&c.push(x.bindings);let r=x[Fc];for(;r.parent;)r=r.parent,r.logger.bindings&&c.push(r.logger.bindings);return c.reverse()}function Fs(x,c,r,l){if(Object.defineProperty(x,l,{value:Jr(x.level,r)>Jr(l,r)?Bo:r[Gc][l],writable:!0,enumerable:!0,configurable:!0}),x[l]===Bo){if(!c.transmit)return;const h=c.transmit.level||x.level,g=Jr(h,r);if(Jr(l,r)<g)return}x[l]=mv(x,c,r,l);const u=gv(x);u.length!==0&&(x[l]=pv(u,x[l]))}function pv(x,c){return function(){return c.apply(this,[...x,...arguments])}}function mv(x,c,r,l){return function(u){return function(){const g=c.timestamp(),v=new Array(arguments.length),S=Object.getPrototypeOf&&Object.getPrototypeOf(this)===$l?$l:this;for(var _=0;_<v.length;_++)v[_]=arguments[_];var C=!1;if(c.serialize&&(Zc(v,this._serialize,this.serializers,this._stdErrSerialize),C=!0),c.asObject||c.formatters?u.call(S,vv(this,l,v,g,c)):u.apply(S,v),c.transmit){const R=c.transmit.level||x._level,D=Jr(R,r),H=Jr(l,r);if(H<D)return;yv(this,{ts:g,methodLevel:l,methodValue:H,transmitValue:r.levels.values[c.transmit.level||x._level],send:c.transmit.send,val:Jr(x._level,r)},v,C)}}}(x[Gc][l])}function vv(x,c,r,l,u){const{level:h,log:g=D=>D}=u.formatters||{},v=r.slice();let S=v[0];const _={};if(l&&(_.time=l),h){const D=h(c,x.levels.values[c]);Object.assign(_,D)}else _.level=x.levels.values[c];let C=(x._childLevel|0)+1;if(C<1&&(C=1),S!==null&&typeof S=="object"){for(;C--&&typeof v[0]=="object";)Object.assign(_,v.shift());S=v.length?Yd(v.shift(),v):void 0}else typeof S=="string"&&(S=Yd(v.shift(),v));return S!==void 0&&(_[u.messageKey]=S),g(_)}function Zc(x,c,r,l){for(const u in x)if(l&&x[u]instanceof Error)x[u]=pr.stdSerializers.err(x[u]);else if(typeof x[u]=="object"&&!Array.isArray(x[u])&&c)for(const h in x[u])c.indexOf(h)>-1&&h in r&&(x[u][h]=r[h](x[u][h]))}function yv(x,c,r,l=!1){const u=c.send,h=c.ts,g=c.methodLevel,v=c.methodValue,S=c.val,_=x._logEvent.bindings;l||Zc(r,x._serialize||Object.keys(x.serializers),x.serializers,x._stdErrSerialize===void 0?!0:x._stdErrSerialize),x._logEvent.ts=h,x._logEvent.messages=r.filter(function(C){return _.indexOf(C)===-1}),x._logEvent.level.label=g,x._logEvent.level.value=v,u(g,x._logEvent,S),x._logEvent=Hc(_)}function Hc(x){return{ts:0,messages:[],bindings:x||[],level:{label:"",value:0}}}function Qd(x){const c={type:x.constructor.name,msg:x.message,stack:x.stack};for(const r in x)c[r]===void 0&&(c[r]=x[r]);return c}function Sv(x){return typeof x.timestamp=="function"?x.timestamp:x.timestamp===!1?ef:tf}function du(){return{}}function Uc(x){return x}function Bo(){}function ef(){return!1}function tf(){return Date.now()}function wv(){return Math.round(Date.now()/1e3)}function xv(){return new Date(Date.now()).toISOString()}function Pv(){function x(c){return typeof c<"u"&&c}try{return typeof globalThis<"u"||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch{return x(self)||x(window)||x(this)||{}}}Eu.exports.default=pr;Eu.exports.pino=pr;var _v=Eu.exports;const Ev=_u(_v);class Iv{constructor(c){E(this,"config");E(this,"disabled");E(this,"logger");this.config=c,this.disabled=this.config.disabled??!1,this.logger=Ev({name:"weave.js",level:this.config.level??"error",browser:{write:{warn:r=>{this.log(console.warn,"WARN",r,{textColor:"white",bgColor:"yellow"})},debug:r=>{this.log(console.debug,"DEBUG",r,{textColor:"white",bgColor:"pink"})},info:r=>{this.log(console.info,"INFO",r,{textColor:"white",bgColor:"blue"})},error:r=>{this.log(console.error,"ERROR",r,{textColor:"white",bgColor:"red"})},trace:r=>{this.log(console.trace,"TRACE",r,{textColor:"white",bgColor:"green"})}},disabled:this.disabled}})}log(c,r,l,{textColor:u,bgColor:h}){const{name:g,msg:v,time:S,..._}=l,C={..._};delete C.level;const R=new Date(S),D=[`%cWEAVE.JS%c %c[${r}]%c %c[${g}]%c %c${R.toISOString()}%c
55
- %s`,"color: black; font-weight: bold; padding: 2px","color: black;",`color: ${u}; background: ${h}; padding: 2px`,"color: black;","color: white; background: black; padding: 2px","color: black;","color: white; background: black; padding: 2px","color: black; margin-top: 2px",v];jt.isEqual(C,{})||D.push(C),c(...D)}getDisabled(){return this.disabled}getLevel(){return this.logger.level}getLogger(){return this.logger}getChildLogger(c){return this.logger.child({name:c})}}class Av{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("targeting-manager"),this.logger.debug("Targeting manager created")}getMousePointer(c){this.logger.debug({point:c},"getMousePointer");const r=this.instance.getStage(),l=this.instance.getMainLayer();let u=c||(r.getPointerPosition()??{x:0,y:0}),h=l,g=l;const v=r.getIntersection(u);if(v){const S=this.instance.getInstanceRecursive(v,["group"]);let _=null;S.getParent()&&(_=this.instance.getInstanceRecursive(S.getParent(),["group"])),S&&S instanceof ne.Group&&S.getAttrs().containerId&&(h=S.findOne(`#${S.getAttrs().containerId}`),g=S),_&&_ instanceof ne.Group&&_.getAttrs().containerId&&(h=_.findOne(`#${_.getAttrs().containerId}`),g=_)}return(g==null?void 0:g.getAttrs().nodeType)!=="layer"&&(u=(h==null?void 0:h.getRelativePointerPosition())??u),(g==null?void 0:g.getAttrs().nodeType)==="layer"&&(u=(h==null?void 0:h.getRelativePointerPosition())??{x:0,y:0}),{mousePoint:u,container:g,measureContainer:h}}getMousePointerRelativeToContainer(c){return{mousePoint:c.getRelativePointerPosition()??{x:0,y:0},container:c}}}class Nv{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("cloning-manager"),this.logger.debug("Cloning manager created")}allInstancesInSameParent(c){var h,g,v,S,_;if(c.length===0)return{allInSame:!1,nodeId:void 0,parentId:void 0};let r=!0;const l=(g=(h=c[0])==null?void 0:h.getParent())==null?void 0:g.getAttrs().id,u=(S=(v=c[0])==null?void 0:v.getParent())==null?void 0:S.getAttrs().nodeId;for(const C of c)if(((_=C==null?void 0:C.getParent())==null?void 0:_.getAttrs().id)!==l){r=!1;break}return{allInSame:r,nodeId:u,parentId:l}}nodesToGroupSerialized(c){if(c.length===0)return;const{allInSame:r}=this.allInstancesInSameParent(c);if(!r)return;const l=et(),u=new ne.Group({id:l}),h=c.map(_=>({node:_,zIndex:_.zIndex()})).filter(_=>_.zIndex!==-1),g=jt.orderBy(h,["zIndex"],["asc"]).map(_=>_.node);for(const[_,C]of g.entries()){if(C.getAttrs().type==="group"){const F=C.clone({id:et(),type:"group"}),Y=F.getAbsolutePosition(),X=F.getAbsoluteRotation();F.moveTo(u),F.zIndex(_),F.setAbsolutePosition(Y),F.rotation(X);continue}const D=C.clone({id:et()}),H=D.getAbsolutePosition(),Z=D.getAbsoluteRotation();D.moveTo(u),D.zIndex(_),D.setAbsolutePosition(H),D.rotation(Z)}const v={x:1/0,y:1/0},S=[];return u.getChildren().forEach(_=>{const C=this.instance.getNodeHandler(_.getAttrs().nodeType);(_.x()<v.x||_.y()<v.y)&&(v.x=_.x(),v.y=_.y());const R=C.toNode(_);S.push(R)}),u.destroy(),{serializedNodes:S,minPoint:v}}cloneNodes(c,r,l){if(c.length===0||!r)return;const{allInSame:u}=this.allInstancesInSameParent(c);if(!u)return;const h=et(),g=new ne.Group({id:h});r.add(g);const v=c.map(R=>({node:R,zIndex:R.zIndex()})).filter(R=>R.zIndex!==-1),S=jt.orderBy(v,["zIndex"],["asc"]).map(R=>R.node);for(const[R,D]of S.entries()){if(D.getAttrs().type==="group"){const X=D.clone({id:et(),type:"group"}),se=X.getAbsolutePosition(),j=X.getAbsoluteRotation();X.moveTo(g),X.zIndex(R),X.setAbsolutePosition(se),X.rotation(j);continue}const Z=D.clone({id:et()}),F=Z.getAbsolutePosition(),Y=Z.getAbsoluteRotation();Z.moveTo(g),Z.zIndex(R),Z.setAbsolutePosition(F),Z.rotation(Y)}const _=g.getClientRect({relativeTo:r});g.x(l.x-_.x),g.y(l.y-_.y);const C=[...g.getChildren()];for(const[R,D]of C.entries()){const H=D.getAbsolutePosition(),Z=D.getAbsoluteRotation();D.moveTo(r),D.zIndex(R),D.setAbsolutePosition(H),D.rotation(Z);const Y=this.instance.getNodeHandler(D.getAttrs().nodeType).toNode(D);this.instance.addNode(Y,r.getAttrs().id),D.destroy()}g.destroy()}}var nf={exports:{}};(function(x){(function(){function c(F,Y){document.addEventListener?F.addEventListener("scroll",Y,!1):F.attachEvent("scroll",Y)}function r(F){document.body?F():document.addEventListener?document.addEventListener("DOMContentLoaded",function Y(){document.removeEventListener("DOMContentLoaded",Y),F()}):document.attachEvent("onreadystatechange",function Y(){(document.readyState=="interactive"||document.readyState=="complete")&&(document.detachEvent("onreadystatechange",Y),F())})}function l(F){this.g=document.createElement("div"),this.g.setAttribute("aria-hidden","true"),this.g.appendChild(document.createTextNode(F)),this.h=document.createElement("span"),this.i=document.createElement("span"),this.m=document.createElement("span"),this.j=document.createElement("span"),this.l=-1,this.h.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.i.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.j.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.m.style.cssText="display:inline-block;width:200%;height:200%;font-size:16px;max-width:none;",this.h.appendChild(this.m),this.i.appendChild(this.j),this.g.appendChild(this.h),this.g.appendChild(this.i)}function u(F,Y){F.g.style.cssText="max-width:none;min-width:20px;min-height:20px;display:inline-block;overflow:hidden;position:absolute;width:auto;margin:0;padding:0;top:-999px;white-space:nowrap;font-synthesis:none;font:"+Y+";"}function h(F){var Y=F.g.offsetWidth,X=Y+100;return F.j.style.width=X+"px",F.i.scrollLeft=X,F.h.scrollLeft=F.h.scrollWidth+100,F.l!==Y?(F.l=Y,!0):!1}function g(F,Y){function X(){var j=se;h(j)&&j.g.parentNode!==null&&Y(j.l)}var se=F;c(F.h,X),c(F.i,X),h(F)}function v(F,Y,X){Y=Y||{},X=X||window,this.family=F,this.style=Y.style||"normal",this.weight=Y.weight||"normal",this.stretch=Y.stretch||"normal",this.context=X}var S=null,_=null,C=null,R=null;function D(F){return _===null&&(H(F)&&/Apple/.test(window.navigator.vendor)?(F=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent),_=!!F&&603>parseInt(F[1],10)):_=!1),_}function H(F){return R===null&&(R=!!F.document.fonts),R}function Z(F,Y){var X=F.style,se=F.weight;if(C===null){var j=document.createElement("div");try{j.style.font="condensed 100px sans-serif"}catch{}C=j.style.font!==""}return[X,se,C?F.stretch:"","100px",Y].join(" ")}v.prototype.load=function(F,Y){var X=this,se=F||"BESbswy",j=0,ye=Y||3e3,we=new Date().getTime();return new Promise(function(xe,Ie){if(H(X.context)&&!D(X.context)){var at=new Promise(function($t,en){function It(){new Date().getTime()-we>=ye?en(Error(""+ye+"ms timeout exceeded")):X.context.document.fonts.load(Z(X,'"'+X.family+'"'),se).then(function(pt){1<=pt.length?$t():setTimeout(It,25)},en)}It()}),gt=new Promise(function($t,en){j=setTimeout(function(){en(Error(""+ye+"ms timeout exceeded"))},ye)});Promise.race([gt,at]).then(function(){clearTimeout(j),xe(X)},Ie)}else r(function(){function $t(){var pe;(pe=At!=-1&&mt!=-1||At!=-1&&ut!=-1||mt!=-1&&ut!=-1)&&((pe=At!=mt&&At!=ut&&mt!=ut)||(S===null&&(pe=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent),S=!!pe&&(536>parseInt(pe[1],10)||parseInt(pe[1],10)===536&&11>=parseInt(pe[2],10))),pe=S&&(At==V&&mt==V&&ut==V||At==le&&mt==le&&ut==le||At==ae&&mt==ae&&ut==ae)),pe=!pe),pe&&(ge.parentNode!==null&&ge.parentNode.removeChild(ge),clearTimeout(j),xe(X))}function en(){if(new Date().getTime()-we>=ye)ge.parentNode!==null&&ge.parentNode.removeChild(ge),Ie(Error(""+ye+"ms timeout exceeded"));else{var pe=X.context.document.hidden;(pe===!0||pe===void 0)&&(At=It.g.offsetWidth,mt=pt.g.offsetWidth,ut=tn.g.offsetWidth,$t()),j=setTimeout(en,50)}}var It=new l(se),pt=new l(se),tn=new l(se),At=-1,mt=-1,ut=-1,V=-1,le=-1,ae=-1,ge=document.createElement("div");ge.dir="ltr",u(It,Z(X,"sans-serif")),u(pt,Z(X,"serif")),u(tn,Z(X,"monospace")),ge.appendChild(It.g),ge.appendChild(pt.g),ge.appendChild(tn.g),X.context.document.body.appendChild(ge),V=It.g.offsetWidth,le=pt.g.offsetWidth,ae=tn.g.offsetWidth,en(),g(It,function(pe){At=pe,$t()}),u(It,Z(X,'"'+X.family+'",sans-serif')),g(pt,function(pe){mt=pe,$t()}),u(pt,Z(X,'"'+X.family+'",serif')),g(tn,function(pe){ut=pe,$t()}),u(tn,Z(X,'"'+X.family+'",monospace'))})})},x.exports=v})()})(nf);var Tv=nf.exports;const Lv=_u(Tv);class Cv{constructor(c){E(this,"instance");E(this,"logger");E(this,"loadedFonts",[]);this.instance=c,this.logger=this.instance.getChildLogger("fonts-manager"),this.logger.debug("Fonts manager created")}async loadFont(c,r){return new Promise(l=>{this.logger.debug(`Loading font with id [${c.id}]`),r.load().then(()=>{this.logger.debug(`Font with id [${c.id}] loaded`),this.loadedFonts.push(c),l()}).catch(()=>{this.logger.debug(`Font with id [${c.id}] failed to load`),l()})})}async loadFonts(){var c;if(this.logger.info("Loading fonts"),this.instance.getConfiguration().fonts){const r=[];for(const l of((c=this.instance.getConfiguration())==null?void 0:c.fonts)??[]){const u=new Lv(l.id);r.push(this.loadFont(l,u))}await Promise.allSettled(r)}this.logger.info("Fonts loaded"),this.instance.emitEvent("weaveFontsLoaded",{})}getFonts(){return this.loadedFonts}}class kv{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("zindex-manager"),this.logger.debug("zIndex manager created")}moveUp(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], up one step of z-index`),c.moveUp();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.moveNode(l,qr.UP)}moveDown(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], down one step of z-index`),c.moveDown();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.moveNode(l,qr.DOWN)}sendToBack(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], to bottom of z-index`),c.moveToBottom();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.moveNode(l,qr.BACK)}bringToFront(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], to top of z-index`),c.moveToTop();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.updateNode(l),this.instance.moveNode(l,qr.FRONT)}}class Rv{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("state-manager"),this.logger.debug("State manager created")}getInstanceRecursive(c,r=[]){var u,h;const l=c.getAttrs();return c.getParent()&&((u=c.getParent())!=null&&u.getAttrs().nodeType)&&!["stage","layer",...r].includes((h=c.getParent())==null?void 0:h.getAttrs().nodeType)?this.getInstanceRecursive(c.getParent()):l.id==="mainLayer"?this.instance.getMainLayer():l.id==="stage"?this.instance.getMainLayer():c}findNodeById(c,r,l=null,u=-1){let h={node:null,parent:l,index:u};return c.key===r?{node:c,parent:l,index:u}:(Array.isArray(c.props.children)&&c.props.children.length>0&&c.props.children.some((g,v)=>(h=this.findNodeById(g,r,c,v),h.node)),h)}findNodesByType(c,r){var u;const l=[];return c.type===r?(l.push(c),l):((u=c.props)!=null&&u.children&&c.props.children.length>0&&c.props.children.some(h=>{l.push(...this.findNodesByType(h,r))}),l)}getNode(c){const r=this.instance.getStore().getState().weave;return jt.isEmpty(r)?{node:null,parent:null,index:-1}:this.findNodeById(r,c)}addNode(c,r="mainLayer",l=void 0,u=!0){const h=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const g=this.instance.getStore().getState();if(jt.isEmpty(g.weave)){this.logger.warn({node:c,parentId:r,doRender:u},"State is empty, cannot add the node");return}const{node:v}=this.findNodeById(g.weave,c.key);if(v){const _=`Node with key [${c.key}] already exists, cannot add it`;this.logger.warn({node:c,parentId:r,doRender:u},_);return}const{node:S}=this.findNodeById(g.weave,r);if(!S){const _=`Parent container with key [${c.key}] doesn't exists, cannot add it`;this.logger.warn({node:c,parentId:r,doRender:u},_);return}if((!S.props.children||typeof S.props.children>"u")&&(S.props.children=[]),l){let _=JSON.parse(JSON.stringify([...S.props.children]));_.splice(l,0,c),_=_.map((C,R)=>({...C,props:{...C.props,zIndex:R}})),S.props.children=_}else{const _=S.props.children.length,C={...c,props:{...c.props,zIndex:_}};S.props.children.push(C)}u&&this.instance.render()},h)}updateNode(c,r=!0){const l=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const u=this.instance.getStore().getState();if(jt.isEmpty(u.weave)){this.logger.warn({node:c,doRender:r},"State is empty, cannot update the node");return}const{node:h}=this.findNodeById(u.weave,c.key);if(!h){const v=`Node with key [${c.key}] doesn't exists, cannot update it`;this.logger.warn({node:c,doRender:r},v);return}const g=JSON.parse(JSON.stringify({...h.props,...c.props}));h.props={...g},r&&this.instance.render()},l)}removeNode(c,r=!0){const l=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const u=this.instance.getStore().getState();if(jt.isEmpty(u.weave)){this.logger.warn({node:c,doRender:r},"State is empty, cannot update the node");return}const{node:h,parent:g}=this.findNodeById(u.weave,c.key);if(!h){const v=`Node with key [${c.key}] doesn't exists, cannot remove it`;this.logger.warn({node:c,doRender:r},v);return}if(g){const S=JSON.parse(JSON.stringify(g.props.children)).filter(_=>_.key!==c.key);g.props.children=S}r&&this.instance.render()},l)}removeNodes(c,r=!0){for(const l of c)this.removeNode(l,!1);r&&this.instance.render()}moveNode(c,r,l=!0){const u=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const h=this.instance.getStore().getState();if(jt.isEmpty(h.weave)){this.logger.warn({node:c,doRender:l},"State is empty, cannot update the node");return}const{node:g,parent:v}=this.findNodeById(h.weave,c.key);if(!g){const S=`Node with key [${c.key}] doesn't exists, cannot update it`;this.logger.warn({node:c,doRender:l},S);return}if(v){let S=JSON.parse(JSON.stringify([...v.props.children??[]]));const _=JSON.parse(JSON.stringify({...c})),C=S.length,R=S.findIndex(D=>D.key===_.key);S.splice(R,1),r===qr.UP&&S.splice(R+1,0,_),r===qr.DOWN&&S.splice(R-1,0,_),r===qr.FRONT&&S.splice(C-1,0,_),r===qr.BACK&&S.splice(0,0,_),S=S.map((D,H)=>({...D,props:{...D.props,zIndex:H}})),v.props.children||(v.props.children=[]),v.props.children=S,l&&this.instance.render()}},u)}}class Mv{constructor(c){E(this,"instance");E(this,"nodesHandlers",{});E(this,"actionsHandlers",{});E(this,"plugins",{});E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("register-manager"),this.logger.debug("Register manager created")}getPlugins(){return this.plugins}getNodesHandlers(){return this.nodesHandlers}getActionsHandlers(){return this.actionsHandlers}getPlugin(c){if(!this.plugins[c]){const r=`Plugin with name [${c}] is not registered`;throw this.logger.error(r),new Error(r)}return this.plugins[c]}getActionHandler(c){if(!this.actionsHandlers[c]){const r=`Action handler with name [${c}] is not registered`;throw this.logger.error(r),new Error(r)}return this.actionsHandlers[c]}getNodeHandler(c){if(!this.nodesHandlers[c]){const r=`Node handler with type [${c}] is not registered`;throw this.logger.error(r),new Error(r)}return this.nodesHandlers[c]}registerPlugins(){const c=this.instance.getConfiguration();if(c.plugins)for(const r of c.plugins)this.registerPlugin(r);this.logger.info("Plugins registered")}registerPlugin(c){const r=c.getName();c.register(this.instance),this.plugins[r]=c}registerNodesHandlers(){const c=this.instance.getConfiguration();if(c.nodes)for(const r of c.nodes)this.registerNodeHandler(r);this.logger.info("Nodes handlers registered")}registerNodeHandler(c){const r=c.getNodeType();if(this.nodesHandlers[r]){const l=`Node handler with type [${r}] already exists`;throw this.logger.error(l),new Error(l)}c.register(this.instance),this.nodesHandlers[r]=c}registerActionsHandlers(){const c=this.instance.getConfiguration();if(c.actions)for(const r of c.actions)this.registerActionHandler(r);this.logger.info("Actions handlers registered")}registerActionHandler(c){const r=c.getName();if(this.actionsHandlers[r]){const l=`Action handler with name [${r}] already exists`;throw this.logger.error(l),new Error(l)}c.register(this.instance),this.actionsHandlers[r]=c}}const zv="0.1.0";class Ov{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("setup-manager"),this.logger.debug("Setup manager created")}welcomeLog(){const c=this.instance.getLogger().getDisabled(),r=this.instance.getLogger().getLevel(),l=[`%cWEAVE.JS%c
55
+ %s`,"color: black; font-weight: bold; padding: 2px","color: black;",`color: ${u}; background: ${h}; padding: 2px`,"color: black;","color: white; background: black; padding: 2px","color: black;","color: white; background: black; padding: 2px","color: black; margin-top: 2px",v];jt.isEqual(C,{})||D.push(C),c(...D)}getDisabled(){return this.disabled}getLevel(){return this.logger.level}getLogger(){return this.logger}getChildLogger(c){return this.logger.child({name:c})}}class Av{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("targeting-manager"),this.logger.debug("Targeting manager created")}getMousePointer(c){this.logger.debug({point:c},"getMousePointer");const r=this.instance.getStage(),l=this.instance.getMainLayer();let u=c||(r.getPointerPosition()??{x:0,y:0}),h=l,g=l;const v=r.getIntersection(u);if(v){const S=this.instance.getInstanceRecursive(v,["group"]);let _=null;S.getParent()&&(_=this.instance.getInstanceRecursive(S.getParent(),["group"])),S&&S instanceof ne.Group&&S.getAttrs().containerId&&(h=S.findOne(`#${S.getAttrs().containerId}`),g=S),_&&_ instanceof ne.Group&&_.getAttrs().containerId&&(h=_.findOne(`#${_.getAttrs().containerId}`),g=_)}return(g==null?void 0:g.getAttrs().nodeType)!=="layer"&&(u=(h==null?void 0:h.getRelativePointerPosition())??u),(g==null?void 0:g.getAttrs().nodeType)==="layer"&&(u=(h==null?void 0:h.getRelativePointerPosition())??{x:0,y:0}),{mousePoint:u,container:g,measureContainer:h}}getMousePointerRelativeToContainer(c){return{mousePoint:c.getRelativePointerPosition()??{x:0,y:0},container:c}}}class Nv{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("cloning-manager"),this.logger.debug("Cloning manager created")}allInstancesInSameParent(c){var h,g,v,S,_;if(c.length===0)return{allInSame:!1,nodeId:void 0,parentId:void 0};let r=!0;const l=(g=(h=c[0])==null?void 0:h.getParent())==null?void 0:g.getAttrs().id,u=(S=(v=c[0])==null?void 0:v.getParent())==null?void 0:S.getAttrs().nodeId;for(const C of c)if(((_=C==null?void 0:C.getParent())==null?void 0:_.getAttrs().id)!==l){r=!1;break}return{allInSame:r,nodeId:u,parentId:l}}nodesToGroupSerialized(c){if(c.length===0)return;const{allInSame:r}=this.allInstancesInSameParent(c);if(!r)return;const l=et(),u=new ne.Group({id:l}),h=c.map(_=>({node:_,zIndex:_.zIndex()})).filter(_=>_.zIndex!==-1),g=jt.orderBy(h,["zIndex"],["asc"]).map(_=>_.node);for(const[_,C]of g.entries()){if(C.getAttrs().type==="group"){const F=C.clone({id:et(),type:"group"}),Y=F.getAbsolutePosition(),X=F.getAbsoluteRotation();F.moveTo(u),F.zIndex(_),F.setAbsolutePosition(Y),F.rotation(X);continue}const D=C.clone({id:et()}),H=D.getAbsolutePosition(),Z=D.getAbsoluteRotation();D.moveTo(u),D.zIndex(_),D.setAbsolutePosition(H),D.rotation(Z)}const v={x:1/0,y:1/0},S=[];return u.getChildren().forEach(_=>{const C=this.instance.getNodeHandler(_.getAttrs().nodeType);(_.x()<v.x||_.y()<v.y)&&(v.x=_.x(),v.y=_.y());const R=C.toNode(_);S.push(R)}),u.destroy(),{serializedNodes:S,minPoint:v}}cloneNodes(c,r,l){if(c.length===0||!r)return;const{allInSame:u}=this.allInstancesInSameParent(c);if(!u)return;const h=et(),g=new ne.Group({id:h});r.add(g);const v=c.map(R=>({node:R,zIndex:R.zIndex()})).filter(R=>R.zIndex!==-1),S=jt.orderBy(v,["zIndex"],["asc"]).map(R=>R.node);for(const[R,D]of S.entries()){if(D.getAttrs().type==="group"){const X=D.clone({id:et(),type:"group"}),se=X.getAbsolutePosition(),j=X.getAbsoluteRotation();X.moveTo(g),X.zIndex(R),X.setAbsolutePosition(se),X.rotation(j);continue}const Z=D.clone({id:et()}),F=Z.getAbsolutePosition(),Y=Z.getAbsoluteRotation();Z.moveTo(g),Z.zIndex(R),Z.setAbsolutePosition(F),Z.rotation(Y)}const _=g.getClientRect({relativeTo:r});g.x(l.x-_.x),g.y(l.y-_.y);const C=[...g.getChildren()];for(const[R,D]of C.entries()){const H=D.getAbsolutePosition(),Z=D.getAbsoluteRotation();D.moveTo(r),D.zIndex(R),D.setAbsolutePosition(H),D.rotation(Z);const Y=this.instance.getNodeHandler(D.getAttrs().nodeType).toNode(D);this.instance.addNode(Y,r.getAttrs().id),D.destroy()}g.destroy()}}var nf={exports:{}};(function(x){(function(){function c(F,Y){document.addEventListener?F.addEventListener("scroll",Y,!1):F.attachEvent("scroll",Y)}function r(F){document.body?F():document.addEventListener?document.addEventListener("DOMContentLoaded",function Y(){document.removeEventListener("DOMContentLoaded",Y),F()}):document.attachEvent("onreadystatechange",function Y(){(document.readyState=="interactive"||document.readyState=="complete")&&(document.detachEvent("onreadystatechange",Y),F())})}function l(F){this.g=document.createElement("div"),this.g.setAttribute("aria-hidden","true"),this.g.appendChild(document.createTextNode(F)),this.h=document.createElement("span"),this.i=document.createElement("span"),this.m=document.createElement("span"),this.j=document.createElement("span"),this.l=-1,this.h.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.i.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.j.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.m.style.cssText="display:inline-block;width:200%;height:200%;font-size:16px;max-width:none;",this.h.appendChild(this.m),this.i.appendChild(this.j),this.g.appendChild(this.h),this.g.appendChild(this.i)}function u(F,Y){F.g.style.cssText="max-width:none;min-width:20px;min-height:20px;display:inline-block;overflow:hidden;position:absolute;width:auto;margin:0;padding:0;top:-999px;white-space:nowrap;font-synthesis:none;font:"+Y+";"}function h(F){var Y=F.g.offsetWidth,X=Y+100;return F.j.style.width=X+"px",F.i.scrollLeft=X,F.h.scrollLeft=F.h.scrollWidth+100,F.l!==Y?(F.l=Y,!0):!1}function g(F,Y){function X(){var j=se;h(j)&&j.g.parentNode!==null&&Y(j.l)}var se=F;c(F.h,X),c(F.i,X),h(F)}function v(F,Y,X){Y=Y||{},X=X||window,this.family=F,this.style=Y.style||"normal",this.weight=Y.weight||"normal",this.stretch=Y.stretch||"normal",this.context=X}var S=null,_=null,C=null,R=null;function D(F){return _===null&&(H(F)&&/Apple/.test(window.navigator.vendor)?(F=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent),_=!!F&&603>parseInt(F[1],10)):_=!1),_}function H(F){return R===null&&(R=!!F.document.fonts),R}function Z(F,Y){var X=F.style,se=F.weight;if(C===null){var j=document.createElement("div");try{j.style.font="condensed 100px sans-serif"}catch{}C=j.style.font!==""}return[X,se,C?F.stretch:"","100px",Y].join(" ")}v.prototype.load=function(F,Y){var X=this,se=F||"BESbswy",j=0,ye=Y||3e3,we=new Date().getTime();return new Promise(function(xe,Ie){if(H(X.context)&&!D(X.context)){var at=new Promise(function($t,en){function It(){new Date().getTime()-we>=ye?en(Error(""+ye+"ms timeout exceeded")):X.context.document.fonts.load(Z(X,'"'+X.family+'"'),se).then(function(pt){1<=pt.length?$t():setTimeout(It,25)},en)}It()}),gt=new Promise(function($t,en){j=setTimeout(function(){en(Error(""+ye+"ms timeout exceeded"))},ye)});Promise.race([gt,at]).then(function(){clearTimeout(j),xe(X)},Ie)}else r(function(){function $t(){var pe;(pe=At!=-1&&mt!=-1||At!=-1&&ut!=-1||mt!=-1&&ut!=-1)&&((pe=At!=mt&&At!=ut&&mt!=ut)||(S===null&&(pe=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent),S=!!pe&&(536>parseInt(pe[1],10)||parseInt(pe[1],10)===536&&11>=parseInt(pe[2],10))),pe=S&&(At==V&&mt==V&&ut==V||At==le&&mt==le&&ut==le||At==ae&&mt==ae&&ut==ae)),pe=!pe),pe&&(ge.parentNode!==null&&ge.parentNode.removeChild(ge),clearTimeout(j),xe(X))}function en(){if(new Date().getTime()-we>=ye)ge.parentNode!==null&&ge.parentNode.removeChild(ge),Ie(Error(""+ye+"ms timeout exceeded"));else{var pe=X.context.document.hidden;(pe===!0||pe===void 0)&&(At=It.g.offsetWidth,mt=pt.g.offsetWidth,ut=tn.g.offsetWidth,$t()),j=setTimeout(en,50)}}var It=new l(se),pt=new l(se),tn=new l(se),At=-1,mt=-1,ut=-1,V=-1,le=-1,ae=-1,ge=document.createElement("div");ge.dir="ltr",u(It,Z(X,"sans-serif")),u(pt,Z(X,"serif")),u(tn,Z(X,"monospace")),ge.appendChild(It.g),ge.appendChild(pt.g),ge.appendChild(tn.g),X.context.document.body.appendChild(ge),V=It.g.offsetWidth,le=pt.g.offsetWidth,ae=tn.g.offsetWidth,en(),g(It,function(pe){At=pe,$t()}),u(It,Z(X,'"'+X.family+'",sans-serif')),g(pt,function(pe){mt=pe,$t()}),u(pt,Z(X,'"'+X.family+'",serif')),g(tn,function(pe){ut=pe,$t()}),u(tn,Z(X,'"'+X.family+'",monospace'))})})},x.exports=v})()})(nf);var Tv=nf.exports;const Lv=_u(Tv);class Cv{constructor(c){E(this,"instance");E(this,"logger");E(this,"loadedFonts",[]);this.instance=c,this.logger=this.instance.getChildLogger("fonts-manager"),this.logger.debug("Fonts manager created")}async loadFont(c,r){return new Promise(l=>{this.logger.debug(`Loading font with id [${c.id}]`),r.load().then(()=>{this.logger.debug(`Font with id [${c.id}] loaded`),this.loadedFonts.push(c),l()}).catch(()=>{this.logger.debug(`Font with id [${c.id}] failed to load`),l()})})}async loadFonts(){var c;if(this.logger.info("Loading fonts"),this.instance.getConfiguration().fonts){const r=[];for(const l of((c=this.instance.getConfiguration())==null?void 0:c.fonts)??[]){const u=new Lv(l.id);r.push(this.loadFont(l,u))}await Promise.allSettled(r)}this.logger.info("Fonts loaded"),this.instance.emitEvent("weaveFontsLoaded",{})}getFonts(){return this.loadedFonts}}class kv{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("zindex-manager"),this.logger.debug("zIndex manager created")}moveUp(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], up one step of z-index`),c.moveUp();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.moveNode(l,qr.UP)}moveDown(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], down one step of z-index`),c.moveDown();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.moveNode(l,qr.DOWN)}sendToBack(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], to bottom of z-index`),c.moveToBottom();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.moveNode(l,qr.BACK)}bringToFront(c){this.logger.debug(`Moving instance with id [${c.getAttrs().id}], to top of z-index`),c.moveToTop();const l=this.instance.getNodeHandler(c.getAttrs().nodeType).toNode(c);this.instance.updateNode(l),this.instance.moveNode(l,qr.FRONT)}}class Rv{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("state-manager"),this.logger.debug("State manager created")}getInstanceRecursive(c,r=[]){var u,h;const l=c.getAttrs();return c.getParent()&&((u=c.getParent())!=null&&u.getAttrs().nodeType)&&!["stage","layer",...r].includes((h=c.getParent())==null?void 0:h.getAttrs().nodeType)?this.getInstanceRecursive(c.getParent()):l.id==="mainLayer"?this.instance.getMainLayer():l.id==="stage"?this.instance.getMainLayer():c}findNodeById(c,r,l=null,u=-1){let h={node:null,parent:l,index:u};return c.key===r?{node:c,parent:l,index:u}:(Array.isArray(c.props.children)&&c.props.children.length>0&&c.props.children.some((g,v)=>(h=this.findNodeById(g,r,c,v),h.node)),h)}findNodesByType(c,r){var u;const l=[];return c.type===r?(l.push(c),l):((u=c.props)!=null&&u.children&&c.props.children.length>0&&c.props.children.some(h=>{l.push(...this.findNodesByType(h,r))}),l)}getNode(c){const r=this.instance.getStore().getState().weave;return jt.isEmpty(r)?{node:null,parent:null,index:-1}:this.findNodeById(r,c)}addNode(c,r="mainLayer",l=void 0,u=!0){const h=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const g=this.instance.getStore().getState();if(jt.isEmpty(g.weave)){this.logger.warn({node:c,parentId:r,doRender:u},"State is empty, cannot add the node");return}const{node:v}=this.findNodeById(g.weave,c.key);if(v){const _=`Node with key [${c.key}] already exists, cannot add it`;this.logger.warn({node:c,parentId:r,doRender:u},_);return}const{node:S}=this.findNodeById(g.weave,r);if(!S){const _=`Parent container with key [${c.key}] doesn't exists, cannot add it`;this.logger.warn({node:c,parentId:r,doRender:u},_);return}if((!S.props.children||typeof S.props.children>"u")&&(S.props.children=[]),l){let _=JSON.parse(JSON.stringify([...S.props.children]));_.splice(l,0,c),_=_.map((C,R)=>({...C,props:{...C.props,zIndex:R}})),S.props.children=_}else{const _=S.props.children.length,C={...c,props:{...c.props,zIndex:_}};S.props.children.push(C)}u&&this.instance.render()},h)}updateNode(c,r=!0){const l=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const u=this.instance.getStore().getState();if(jt.isEmpty(u.weave)){this.logger.warn({node:c,doRender:r},"State is empty, cannot update the node");return}const{node:h}=this.findNodeById(u.weave,c.key);if(!h){const v=`Node with key [${c.key}] doesn't exists, cannot update it`;this.logger.warn({node:c,doRender:r},v);return}const g=JSON.parse(JSON.stringify({...h.props,...c.props}));h.props={...g},r&&this.instance.render()},l)}removeNode(c,r=!0){const l=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const u=this.instance.getStore().getState();if(jt.isEmpty(u.weave)){this.logger.warn({node:c,doRender:r},"State is empty, cannot update the node");return}const{node:h,parent:g}=this.findNodeById(u.weave,c.key);if(!h){const v=`Node with key [${c.key}] doesn't exists, cannot remove it`;this.logger.warn({node:c,doRender:r},v);return}if(g){const S=JSON.parse(JSON.stringify(g.props.children)).filter(_=>_.key!==c.key);g.props.children=S}r&&this.instance.render()},l)}removeNodes(c,r=!0){for(const l of c)this.removeNode(l,!1);r&&this.instance.render()}moveNode(c,r,l=!0){const u=this.instance.getStore().getUser().name;this.instance.getStore().getDocument().transact(()=>{const h=this.instance.getStore().getState();if(jt.isEmpty(h.weave)){this.logger.warn({node:c,doRender:l},"State is empty, cannot update the node");return}const{node:g,parent:v}=this.findNodeById(h.weave,c.key);if(!g){const S=`Node with key [${c.key}] doesn't exists, cannot update it`;this.logger.warn({node:c,doRender:l},S);return}if(v){let S=JSON.parse(JSON.stringify([...v.props.children??[]]));const _=JSON.parse(JSON.stringify({...c})),C=S.length,R=S.findIndex(D=>D.key===_.key);S.splice(R,1),r===qr.UP&&S.splice(R+1,0,_),r===qr.DOWN&&S.splice(R-1,0,_),r===qr.FRONT&&S.splice(C-1,0,_),r===qr.BACK&&S.splice(0,0,_),S=S.map((D,H)=>({...D,props:{...D.props,zIndex:H}})),v.props.children||(v.props.children=[]),v.props.children=S,l&&this.instance.render()}},u)}}class Mv{constructor(c){E(this,"instance");E(this,"nodesHandlers",{});E(this,"actionsHandlers",{});E(this,"plugins",{});E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("register-manager"),this.logger.debug("Register manager created")}getPlugins(){return this.plugins}getNodesHandlers(){return this.nodesHandlers}getActionsHandlers(){return this.actionsHandlers}getPlugin(c){if(!this.plugins[c]){const r=`Plugin with name [${c}] is not registered`;throw this.logger.error(r),new Error(r)}return this.plugins[c]}getActionHandler(c){if(!this.actionsHandlers[c]){const r=`Action handler with name [${c}] is not registered`;throw this.logger.error(r),new Error(r)}return this.actionsHandlers[c]}getNodeHandler(c){if(!this.nodesHandlers[c]){const r=`Node handler with type [${c}] is not registered`;throw this.logger.error(r),new Error(r)}return this.nodesHandlers[c]}registerPlugins(){const c=this.instance.getConfiguration();if(c.plugins)for(const r of c.plugins)this.registerPlugin(r);this.logger.info("Plugins registered")}registerPlugin(c){const r=c.getName();c.register(this.instance),this.plugins[r]=c}registerNodesHandlers(){const c=this.instance.getConfiguration();if(c.nodes)for(const r of c.nodes)this.registerNodeHandler(r);this.logger.info("Nodes handlers registered")}registerNodeHandler(c){const r=c.getNodeType();if(this.nodesHandlers[r]){const l=`Node handler with type [${r}] already exists`;throw this.logger.error(l),new Error(l)}c.register(this.instance),this.nodesHandlers[r]=c}registerActionsHandlers(){const c=this.instance.getConfiguration();if(c.actions)for(const r of c.actions)this.registerActionHandler(r);this.logger.info("Actions handlers registered")}registerActionHandler(c){const r=c.getName();if(this.actionsHandlers[r]){const l=`Action handler with name [${r}] already exists`;throw this.logger.error(l),new Error(l)}c.register(this.instance),this.actionsHandlers[r]=c}}const zv="0.1.1";class Ov{constructor(c){E(this,"instance");E(this,"logger");this.instance=c,this.logger=this.instance.getChildLogger("setup-manager"),this.logger.debug("Setup manager created")}welcomeLog(){const c=this.instance.getLogger().getDisabled(),r=this.instance.getLogger().getLevel(),l=[`%cWEAVE.JS%c
56
56
  version: ${zv}
57
57
  log disabled: ${c}
58
58
  log level: ${r}`,"color: black; font-size: 20px; font-weight: bold; padding: 2px; margin-bottom: 12px;","color: black;"];console.log(...l)}setupLog(){const c=this.instance.getRegisterManager().getNodesHandlers(),r=this.instance.getRegisterManager().getActionsHandlers(),l=this.instance.getRegisterManager().getPlugins(),u=[`%cWEAVE.JS SETUP%c
package/dist/sdk.cjs.gz CHANGED
Binary file
package/dist/sdk.js CHANGED
@@ -9721,7 +9721,7 @@ class Tv {
9721
9721
  c.register(this.instance), this.actionsHandlers[r] = c;
9722
9722
  }
9723
9723
  }
9724
- const Lv = "0.1.0";
9724
+ const Lv = "0.1.1";
9725
9725
  class Cv {
9726
9726
  constructor(c) {
9727
9727
  _(this, "instance");
package/dist/sdk.js.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inditextech/weave-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Jesus Manuel Piñeiro Cid <jesusmpc@inditex.com>",
@@ -43,7 +43,7 @@
43
43
  "version:release": "npm version $RELEASE_VERSION -m \"[npm-scripts] prepare release $RELEASE_VERSION\" --tag-version-prefix \"\""
44
44
  },
45
45
  "devDependencies": {
46
- "@inditextech/weave-types": "0.1.0",
46
+ "@inditextech/weave-types": "0.1.1",
47
47
  "@types/fontfaceobserver": "2.1.3",
48
48
  "@types/lodash": "4.17.15",
49
49
  "@types/react-reconciler": "0.28.9",