@pippit-dev/cli 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/checksums.txt +6 -6
- package/cmd/canvas/canvas.go +8 -2
- package/cmd/canvas/canvas_test.go +56 -0
- package/cmd/get_credit_balance.go +37 -0
- package/cmd/get_credit_balance_test.go +73 -0
- package/cmd/root.go +2 -1
- package/cmd/root_test.go +9 -0
- package/cmd/short_drama_test.go +1 -0
- package/dist/checksums.txt +6 -0
- package/dist/xyq-canvas-command-runtime.cjs +16 -0
- package/dist/xyq-canvas-command-runtime.cjs.LEGAL.txt +599 -0
- package/dist/xyq-canvas-command-runtime.cjs.sha256 +2 -0
- package/internal/canvas/apply.go +104 -28
- package/internal/canvas/canvas_test.go +113 -0
- package/internal/common/get_credit_balance.go +61 -0
- package/internal/common/get_credit_balance_test.go +75 -0
- package/internal/config/config.go +11 -8
- package/internal/config/config_test.go +3 -0
- package/package.json +9 -2
- package/scripts/canvas-command.js +881 -0
- package/scripts/run.js +21 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";var QG=Object.create;var Za=Object.defineProperty;var JG=Object.getOwnPropertyDescriptor;var ZG=Object.getOwnPropertyNames;var e1=Object.getPrototypeOf,t1=Object.prototype.hasOwnProperty;var A=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),n1=(e,t)=>{for(var n in t)Za(e,n,{get:t[n],enumerable:!0})},Ty=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ZG(t))!t1.call(e,o)&&o!==n&&Za(e,o,{get:()=>t[o],enumerable:!(r=JG(t,o))||r.enumerable});return e};var ed=(e,t,n)=>(n=e!=null?QG(e1(e)):{},Ty(t||!e||!e.__esModule?Za(n,"default",{value:e,enumerable:!0}):n,e)),r1=e=>Ty(Za({},"__esModule",{value:!0}),e);var PI=A((hCe,Ec)=>{var eI,tI,nI,rI,oI,sI,iI,aI,dI,cI,uI,pI,lI,_c,Ef,fI,mI,hI,jo,gI,yI,AI,vI,SI,bI,II,_I,RI,Rc,EI,CI;(function(e){var t=typeof global=="object"?global:typeof self=="object"?self:typeof this=="object"?this:{};typeof define=="function"&&define.amd?define("tslib",["exports"],function(r){e(n(t,n(r)))}):typeof Ec=="object"&&typeof Ec.exports=="object"?e(n(t,n(Ec.exports))):e(n(t));function n(r,o){return r!==t&&(typeof Object.create=="function"?Object.defineProperty(r,"__esModule",{value:!0}):r.__esModule=!0),function(s,i){return r[s]=o?o(s,i):i}}})(function(e){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(o,s){o.__proto__=s}||function(o,s){for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(o[i]=s[i])};eI=function(o,s){if(typeof s!="function"&&s!==null)throw new TypeError("Class extends value "+String(s)+" is not a constructor or null");t(o,s);function i(){this.constructor=o}o.prototype=s===null?Object.create(s):(i.prototype=s.prototype,new i)},tI=Object.assign||function(o){for(var s,i=1,a=arguments.length;i<a;i++){s=arguments[i];for(var d in s)Object.prototype.hasOwnProperty.call(s,d)&&(o[d]=s[d])}return o},nI=function(o,s){var i={};for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&s.indexOf(a)<0&&(i[a]=o[a]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function")for(var d=0,a=Object.getOwnPropertySymbols(o);d<a.length;d++)s.indexOf(a[d])<0&&Object.prototype.propertyIsEnumerable.call(o,a[d])&&(i[a[d]]=o[a[d]]);return i},rI=function(o,s,i,a){var d=arguments.length,c=d<3?s:a===null?a=Object.getOwnPropertyDescriptor(s,i):a,u;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")c=Reflect.decorate(o,s,i,a);else for(var p=o.length-1;p>=0;p--)(u=o[p])&&(c=(d<3?u(c):d>3?u(s,i,c):u(s,i))||c);return d>3&&c&&Object.defineProperty(s,i,c),c},oI=function(o,s){return function(i,a){s(i,a,o)}},sI=function(o,s,i,a,d,c){function u(I){if(I!==void 0&&typeof I!="function")throw new TypeError("Function expected");return I}for(var p=a.kind,l=p==="getter"?"get":p==="setter"?"set":"value",f=!s&&o?a.static?o:o.prototype:null,h=s||(f?Object.getOwnPropertyDescriptor(f,a.name):{}),m,g=!1,y=i.length-1;y>=0;y--){var v={};for(var S in a)v[S]=S==="access"?{}:a[S];for(var S in a.access)v.access[S]=a.access[S];v.addInitializer=function(I){if(g)throw new TypeError("Cannot add initializers after decoration has completed");c.push(u(I||null))};var b=(0,i[y])(p==="accessor"?{get:h.get,set:h.set}:h[l],v);if(p==="accessor"){if(b===void 0)continue;if(b===null||typeof b!="object")throw new TypeError("Object expected");(m=u(b.get))&&(h.get=m),(m=u(b.set))&&(h.set=m),(m=u(b.init))&&d.unshift(m)}else(m=u(b))&&(p==="field"?d.unshift(m):h[l]=m)}f&&Object.defineProperty(f,a.name,h),g=!0},iI=function(o,s,i){for(var a=arguments.length>2,d=0;d<s.length;d++)i=a?s[d].call(o,i):s[d].call(o);return a?i:void 0},aI=function(o){return typeof o=="symbol"?o:"".concat(o)},dI=function(o,s,i){return typeof s=="symbol"&&(s=s.description?"[".concat(s.description,"]"):""),Object.defineProperty(o,"name",{configurable:!0,value:i?"".concat(i," ",s):s})},cI=function(o,s){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(o,s)},uI=function(o,s,i,a){function d(c){return c instanceof i?c:new i(function(u){u(c)})}return new(i||(i=Promise))(function(c,u){function p(h){try{f(a.next(h))}catch(m){u(m)}}function l(h){try{f(a.throw(h))}catch(m){u(m)}}function f(h){h.done?c(h.value):d(h.value).then(p,l)}f((a=a.apply(o,s||[])).next())})},pI=function(o,s){var i={label:0,sent:function(){if(c[0]&1)throw c[1];return c[1]},trys:[],ops:[]},a,d,c,u;return u={next:p(0),throw:p(1),return:p(2)},typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function p(f){return function(h){return l([f,h])}}function l(f){if(a)throw new TypeError("Generator is already executing.");for(;u&&(u=0,f[0]&&(i=0)),i;)try{if(a=1,d&&(c=f[0]&2?d.return:f[0]?d.throw||((c=d.return)&&c.call(d),0):d.next)&&!(c=c.call(d,f[1])).done)return c;switch(d=0,c&&(f=[f[0]&2,c.value]),f[0]){case 0:case 1:c=f;break;case 4:return i.label++,{value:f[1],done:!1};case 5:i.label++,d=f[1],f=[0];continue;case 7:f=i.ops.pop(),i.trys.pop();continue;default:if(c=i.trys,!(c=c.length>0&&c[c.length-1])&&(f[0]===6||f[0]===2)){i=0;continue}if(f[0]===3&&(!c||f[1]>c[0]&&f[1]<c[3])){i.label=f[1];break}if(f[0]===6&&i.label<c[1]){i.label=c[1],c=f;break}if(c&&i.label<c[2]){i.label=c[2],i.ops.push(f);break}c[2]&&i.ops.pop(),i.trys.pop();continue}f=s.call(o,i)}catch(h){f=[6,h],d=0}finally{a=c=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}},lI=function(o,s){for(var i in o)i!=="default"&&!Object.prototype.hasOwnProperty.call(s,i)&&Rc(s,o,i)},Rc=Object.create?function(o,s,i,a){a===void 0&&(a=i);var d=Object.getOwnPropertyDescriptor(s,i);(!d||("get"in d?!s.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return s[i]}}),Object.defineProperty(o,a,d)}:function(o,s,i,a){a===void 0&&(a=i),o[a]=s[i]},_c=function(o){var s=typeof Symbol=="function"&&Symbol.iterator,i=s&&o[s],a=0;if(i)return i.call(o);if(o&&typeof o.length=="number")return{next:function(){return o&&a>=o.length&&(o=void 0),{value:o&&o[a++],done:!o}}};throw new TypeError(s?"Object is not iterable.":"Symbol.iterator is not defined.")},Ef=function(o,s){var i=typeof Symbol=="function"&&o[Symbol.iterator];if(!i)return o;var a=i.call(o),d,c=[],u;try{for(;(s===void 0||s-- >0)&&!(d=a.next()).done;)c.push(d.value)}catch(p){u={error:p}}finally{try{d&&!d.done&&(i=a.return)&&i.call(a)}finally{if(u)throw u.error}}return c},fI=function(){for(var o=[],s=0;s<arguments.length;s++)o=o.concat(Ef(arguments[s]));return o},mI=function(){for(var o=0,s=0,i=arguments.length;s<i;s++)o+=arguments[s].length;for(var a=Array(o),d=0,s=0;s<i;s++)for(var c=arguments[s],u=0,p=c.length;u<p;u++,d++)a[d]=c[u];return a},hI=function(o,s,i){if(i||arguments.length===2)for(var a=0,d=s.length,c;a<d;a++)(c||!(a in s))&&(c||(c=Array.prototype.slice.call(s,0,a)),c[a]=s[a]);return o.concat(c||Array.prototype.slice.call(s))},jo=function(o){return this instanceof jo?(this.v=o,this):new jo(o)},gI=function(o,s,i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var a=i.apply(o,s||[]),d,c=[];return d={},u("next"),u("throw"),u("return"),d[Symbol.asyncIterator]=function(){return this},d;function u(g){a[g]&&(d[g]=function(y){return new Promise(function(v,S){c.push([g,y,v,S])>1||p(g,y)})})}function p(g,y){try{l(a[g](y))}catch(v){m(c[0][3],v)}}function l(g){g.value instanceof jo?Promise.resolve(g.value.v).then(f,h):m(c[0][2],g)}function f(g){p("next",g)}function h(g){p("throw",g)}function m(g,y){g(y),c.shift(),c.length&&p(c[0][0],c[0][1])}},yI=function(o){var s,i;return s={},a("next"),a("throw",function(d){throw d}),a("return"),s[Symbol.iterator]=function(){return this},s;function a(d,c){s[d]=o[d]?function(u){return(i=!i)?{value:jo(o[d](u)),done:!1}:c?c(u):u}:c}},AI=function(o){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=o[Symbol.asyncIterator],i;return s?s.call(o):(o=typeof _c=="function"?_c(o):o[Symbol.iterator](),i={},a("next"),a("throw"),a("return"),i[Symbol.asyncIterator]=function(){return this},i);function a(c){i[c]=o[c]&&function(u){return new Promise(function(p,l){u=o[c](u),d(p,l,u.done,u.value)})}}function d(c,u,p,l){Promise.resolve(l).then(function(f){c({value:f,done:p})},u)}},vI=function(o,s){return Object.defineProperty?Object.defineProperty(o,"raw",{value:s}):o.raw=s,o};var n=Object.create?function(o,s){Object.defineProperty(o,"default",{enumerable:!0,value:s})}:function(o,s){o.default=s};SI=function(o){if(o&&o.__esModule)return o;var s={};if(o!=null)for(var i in o)i!=="default"&&Object.prototype.hasOwnProperty.call(o,i)&&Rc(s,o,i);return n(s,o),s},bI=function(o){return o&&o.__esModule?o:{default:o}},II=function(o,s,i,a){if(i==="a"&&!a)throw new TypeError("Private accessor was defined without a getter");if(typeof s=="function"?o!==s||!a:!s.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return i==="m"?a:i==="a"?a.call(o):a?a.value:s.get(o)},_I=function(o,s,i,a,d){if(a==="m")throw new TypeError("Private method is not writable");if(a==="a"&&!d)throw new TypeError("Private accessor was defined without a setter");if(typeof s=="function"?o!==s||!d:!s.has(o))throw new TypeError("Cannot write private member to an object whose class did not declare it");return a==="a"?d.call(o,i):d?d.value=i:s.set(o,i),i},RI=function(o,s){if(s===null||typeof s!="object"&&typeof s!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof o=="function"?s===o:o.has(s)},EI=function(o,s,i){if(s!=null){if(typeof s!="object"&&typeof s!="function")throw new TypeError("Object expected.");var a;if(i){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");a=s[Symbol.asyncDispose]}if(a===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");a=s[Symbol.dispose]}if(typeof a!="function")throw new TypeError("Object not disposable.");o.stack.push({value:s,dispose:a,async:i})}else i&&o.stack.push({async:!0});return s};var r=typeof SuppressedError=="function"?SuppressedError:function(o,s,i){var a=new Error(i);return a.name="SuppressedError",a.error=o,a.suppressed=s,a};CI=function(o){function s(a){o.error=o.hasError?new r(a,o.error,"An error was suppressed during disposal."):a,o.hasError=!0}function i(){for(;o.stack.length;){var a=o.stack.pop();try{var d=a.dispose&&a.dispose.call(a.value);if(a.async)return Promise.resolve(d).then(i,function(c){return s(c),i()})}catch(c){s(c)}}if(o.hasError)throw o.error}return i()},e("__extends",eI),e("__assign",tI),e("__rest",nI),e("__decorate",rI),e("__param",oI),e("__esDecorate",sI),e("__runInitializers",iI),e("__propKey",aI),e("__setFunctionName",dI),e("__metadata",cI),e("__awaiter",uI),e("__generator",pI),e("__exportStar",lI),e("__createBinding",Rc),e("__values",_c),e("__read",Ef),e("__spread",fI),e("__spreadArrays",mI),e("__spreadArray",hI),e("__await",jo),e("__asyncGenerator",gI),e("__asyncDelegator",yI),e("__asyncValues",AI),e("__makeTemplateObject",vI),e("__importStar",SI),e("__importDefault",bI),e("__classPrivateFieldGet",II),e("__classPrivateFieldSet",_I),e("__classPrivateFieldIn",RI),e("__addDisposableResource",EI),e("__disposeResources",CI)})});var QE=A((PLe,WE)=>{function $3(){this.__data__=[],this.size=0}WE.exports=$3});var eo=A((xLe,JE)=>{function W3(e,t){return e===t||e!==e&&t!==t}JE.exports=W3});var ha=A((TLe,ZE)=>{var Q3=eo();function J3(e,t){for(var n=e.length;n--;)if(Q3(e[n][0],t))return n;return-1}ZE.exports=J3});var tC=A((NLe,eC)=>{var Z3=ha(),e$=Array.prototype,t$=e$.splice;function n$(e){var t=this.__data__,n=Z3(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():t$.call(t,n,1),--this.size,!0}eC.exports=n$});var rC=A((wLe,nC)=>{var r$=ha();function o$(e){var t=this.__data__,n=r$(t,e);return n<0?void 0:t[n][1]}nC.exports=o$});var sC=A((OLe,oC)=>{var s$=ha();function i$(e){return s$(this.__data__,e)>-1}oC.exports=i$});var aC=A((DLe,iC)=>{var a$=ha();function d$(e,t){var n=this.__data__,r=a$(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}iC.exports=d$});var ga=A((kLe,dC)=>{var c$=QE(),u$=tC(),p$=rC(),l$=sC(),f$=aC();function fs(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}fs.prototype.clear=c$;fs.prototype.delete=u$;fs.prototype.get=p$;fs.prototype.has=l$;fs.prototype.set=f$;dC.exports=fs});var uC=A((MLe,cC)=>{var m$=ga();function h$(){this.__data__=new m$,this.size=0}cC.exports=h$});var lC=A((LLe,pC)=>{function g$(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}pC.exports=g$});var mC=A((BLe,fC)=>{function y$(e){return this.__data__.get(e)}fC.exports=y$});var gC=A((GLe,hC)=>{function A$(e){return this.__data__.has(e)}hC.exports=A$});var bh=A((ULe,yC)=>{var v$=typeof global=="object"&&global&&global.Object===Object&&global;yC.exports=v$});var yt=A((zLe,AC)=>{var S$=bh(),b$=typeof self=="object"&&self&&self.Object===Object&&self,I$=S$||b$||Function("return this")();AC.exports=I$});var to=A((qLe,vC)=>{var _$=yt(),R$=_$.Symbol;vC.exports=R$});var _C=A((FLe,IC)=>{var SC=to(),bC=Object.prototype,E$=bC.hasOwnProperty,C$=bC.toString,ya=SC?SC.toStringTag:void 0;function P$(e){var t=E$.call(e,ya),n=e[ya];try{e[ya]=void 0;var r=!0}catch{}var o=C$.call(e);return r&&(t?e[ya]=n:delete e[ya]),o}IC.exports=P$});var EC=A((jLe,RC)=>{var x$=Object.prototype,T$=x$.toString;function N$(e){return T$.call(e)}RC.exports=N$});var rr=A((VLe,xC)=>{var CC=to(),w$=_C(),O$=EC(),D$="[object Null]",k$="[object Undefined]",PC=CC?CC.toStringTag:void 0;function M$(e){return e==null?e===void 0?k$:D$:PC&&PC in Object(e)?w$(e):O$(e)}xC.exports=M$});var it=A((HLe,TC)=>{function L$(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}TC.exports=L$});var ms=A((YLe,NC)=>{var B$=rr(),G$=it(),U$="[object AsyncFunction]",z$="[object Function]",q$="[object GeneratorFunction]",F$="[object Proxy]";function j$(e){if(!G$(e))return!1;var t=B$(e);return t==z$||t==q$||t==U$||t==F$}NC.exports=j$});var OC=A((KLe,wC)=>{var V$=yt(),H$=V$["__core-js_shared__"];wC.exports=H$});var MC=A((XLe,kC)=>{var Ih=OC(),DC=function(){var e=/[^.]+$/.exec(Ih&&Ih.keys&&Ih.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Y$(e){return!!DC&&DC in e}kC.exports=Y$});var _h=A(($Le,LC)=>{var K$=Function.prototype,X$=K$.toString;function $$(e){if(e!=null){try{return X$.call(e)}catch{}try{return e+""}catch{}}return""}LC.exports=$$});var GC=A((WLe,BC)=>{var W$=ms(),Q$=MC(),J$=it(),Z$=_h(),e8=/[\\^$.*+?()[\]{}|]/g,t8=/^\[object .+?Constructor\]$/,n8=Function.prototype,r8=Object.prototype,o8=n8.toString,s8=r8.hasOwnProperty,i8=RegExp("^"+o8.call(s8).replace(e8,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function a8(e){if(!J$(e)||Q$(e))return!1;var t=W$(e)?i8:t8;return t.test(Z$(e))}BC.exports=a8});var zC=A((QLe,UC)=>{function d8(e,t){return e==null?void 0:e[t]}UC.exports=d8});var or=A((JLe,qC)=>{var c8=GC(),u8=zC();function p8(e,t){var n=u8(e,t);return c8(n)?n:void 0}qC.exports=p8});var Eu=A((ZLe,FC)=>{var l8=or(),f8=yt(),m8=l8(f8,"Map");FC.exports=m8});var Aa=A((eBe,jC)=>{var h8=or(),g8=h8(Object,"create");jC.exports=g8});var YC=A((tBe,HC)=>{var VC=Aa();function y8(){this.__data__=VC?VC(null):{},this.size=0}HC.exports=y8});var XC=A((nBe,KC)=>{function A8(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}KC.exports=A8});var WC=A((rBe,$C)=>{var v8=Aa(),S8="__lodash_hash_undefined__",b8=Object.prototype,I8=b8.hasOwnProperty;function _8(e){var t=this.__data__;if(v8){var n=t[e];return n===S8?void 0:n}return I8.call(t,e)?t[e]:void 0}$C.exports=_8});var JC=A((oBe,QC)=>{var R8=Aa(),E8=Object.prototype,C8=E8.hasOwnProperty;function P8(e){var t=this.__data__;return R8?t[e]!==void 0:C8.call(t,e)}QC.exports=P8});var eP=A((sBe,ZC)=>{var x8=Aa(),T8="__lodash_hash_undefined__";function N8(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=x8&&t===void 0?T8:t,this}ZC.exports=N8});var nP=A((iBe,tP)=>{var w8=YC(),O8=XC(),D8=WC(),k8=JC(),M8=eP();function hs(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}hs.prototype.clear=w8;hs.prototype.delete=O8;hs.prototype.get=D8;hs.prototype.has=k8;hs.prototype.set=M8;tP.exports=hs});var sP=A((aBe,oP)=>{var rP=nP(),L8=ga(),B8=Eu();function G8(){this.size=0,this.__data__={hash:new rP,map:new(B8||L8),string:new rP}}oP.exports=G8});var aP=A((dBe,iP)=>{function U8(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}iP.exports=U8});var va=A((cBe,dP)=>{var z8=aP();function q8(e,t){var n=e.__data__;return z8(t)?n[typeof t=="string"?"string":"hash"]:n.map}dP.exports=q8});var uP=A((uBe,cP)=>{var F8=va();function j8(e){var t=F8(this,e).delete(e);return this.size-=t?1:0,t}cP.exports=j8});var lP=A((pBe,pP)=>{var V8=va();function H8(e){return V8(this,e).get(e)}pP.exports=H8});var mP=A((lBe,fP)=>{var Y8=va();function K8(e){return Y8(this,e).has(e)}fP.exports=K8});var gP=A((fBe,hP)=>{var X8=va();function $8(e,t){var n=X8(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}hP.exports=$8});var Cu=A((mBe,yP)=>{var W8=sP(),Q8=uP(),J8=lP(),Z8=mP(),eW=gP();function gs(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}gs.prototype.clear=W8;gs.prototype.delete=Q8;gs.prototype.get=J8;gs.prototype.has=Z8;gs.prototype.set=eW;yP.exports=gs});var vP=A((hBe,AP)=>{var tW=ga(),nW=Eu(),rW=Cu(),oW=200;function sW(e,t){var n=this.__data__;if(n instanceof tW){var r=n.__data__;if(!nW||r.length<oW-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new rW(r)}return n.set(e,t),this.size=n.size,this}AP.exports=sW});var Sa=A((gBe,SP)=>{var iW=ga(),aW=uC(),dW=lC(),cW=mC(),uW=gC(),pW=vP();function ys(e){var t=this.__data__=new iW(e);this.size=t.size}ys.prototype.clear=aW;ys.prototype.delete=dW;ys.prototype.get=cW;ys.prototype.has=uW;ys.prototype.set=pW;SP.exports=ys});var Pu=A((yBe,bP)=>{function lW(e,t){for(var n=-1,r=e==null?0:e.length;++n<r&&t(e[n],n,e)!==!1;);return e}bP.exports=lW});var Rh=A((ABe,IP)=>{var fW=or(),mW=function(){try{var e=fW(Object,"defineProperty");return e({},"",{}),e}catch{}}();IP.exports=mW});var ba=A((vBe,RP)=>{var _P=Rh();function hW(e,t,n){t=="__proto__"&&_P?_P(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}RP.exports=hW});var Ia=A((SBe,EP)=>{var gW=ba(),yW=eo(),AW=Object.prototype,vW=AW.hasOwnProperty;function SW(e,t,n){var r=e[t];(!(vW.call(e,t)&&yW(r,n))||n===void 0&&!(t in e))&&gW(e,t,n)}EP.exports=SW});var As=A((bBe,CP)=>{var bW=Ia(),IW=ba();function _W(e,t,n,r){var o=!n;n||(n={});for(var s=-1,i=t.length;++s<i;){var a=t[s],d=r?r(n[a],e[a],a,n,e):void 0;d===void 0&&(d=e[a]),o?IW(n,a,d):bW(n,a,d)}return n}CP.exports=_W});var xP=A((IBe,PP)=>{function RW(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}PP.exports=RW});var Ot=A((_Be,TP)=>{function EW(e){return e!=null&&typeof e=="object"}TP.exports=EW});var wP=A((RBe,NP)=>{var CW=rr(),PW=Ot(),xW="[object Arguments]";function TW(e){return PW(e)&&CW(e)==xW}NP.exports=TW});var vs=A((EBe,kP)=>{var OP=wP(),NW=Ot(),DP=Object.prototype,wW=DP.hasOwnProperty,OW=DP.propertyIsEnumerable,DW=OP(function(){return arguments}())?OP:function(e){return NW(e)&&wW.call(e,"callee")&&!OW.call(e,"callee")};kP.exports=DW});var ve=A((CBe,MP)=>{var kW=Array.isArray;MP.exports=kW});var BP=A((PBe,LP)=>{function MW(){return!1}LP.exports=MW});var no=A((_a,Ss)=>{var LW=yt(),BW=BP(),zP=typeof _a=="object"&&_a&&!_a.nodeType&&_a,GP=zP&&typeof Ss=="object"&&Ss&&!Ss.nodeType&&Ss,GW=GP&&GP.exports===zP,UP=GW?LW.Buffer:void 0,UW=UP?UP.isBuffer:void 0,zW=UW||BW;Ss.exports=zW});var Ra=A((xBe,qP)=>{var qW=9007199254740991,FW=/^(?:0|[1-9]\d*)$/;function jW(e,t){var n=typeof e;return t=t??qW,!!t&&(n=="number"||n!="symbol"&&FW.test(e))&&e>-1&&e%1==0&&e<t}qP.exports=jW});var xu=A((TBe,FP)=>{var VW=9007199254740991;function HW(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=VW}FP.exports=HW});var VP=A((NBe,jP)=>{var YW=rr(),KW=xu(),XW=Ot(),$W="[object Arguments]",WW="[object Array]",QW="[object Boolean]",JW="[object Date]",ZW="[object Error]",e4="[object Function]",t4="[object Map]",n4="[object Number]",r4="[object Object]",o4="[object RegExp]",s4="[object Set]",i4="[object String]",a4="[object WeakMap]",d4="[object ArrayBuffer]",c4="[object DataView]",u4="[object Float32Array]",p4="[object Float64Array]",l4="[object Int8Array]",f4="[object Int16Array]",m4="[object Int32Array]",h4="[object Uint8Array]",g4="[object Uint8ClampedArray]",y4="[object Uint16Array]",A4="[object Uint32Array]",pe={};pe[u4]=pe[p4]=pe[l4]=pe[f4]=pe[m4]=pe[h4]=pe[g4]=pe[y4]=pe[A4]=!0;pe[$W]=pe[WW]=pe[d4]=pe[QW]=pe[c4]=pe[JW]=pe[ZW]=pe[e4]=pe[t4]=pe[n4]=pe[r4]=pe[o4]=pe[s4]=pe[i4]=pe[a4]=!1;function v4(e){return XW(e)&&KW(e.length)&&!!pe[YW(e)]}jP.exports=v4});var Ea=A((wBe,HP)=>{function S4(e){return function(t){return e(t)}}HP.exports=S4});var Tu=A((Ca,bs)=>{var b4=bh(),YP=typeof Ca=="object"&&Ca&&!Ca.nodeType&&Ca,Pa=YP&&typeof bs=="object"&&bs&&!bs.nodeType&&bs,I4=Pa&&Pa.exports===YP,Eh=I4&&b4.process,_4=function(){try{var e=Pa&&Pa.require&&Pa.require("util").types;return e||Eh&&Eh.binding&&Eh.binding("util")}catch{}}();bs.exports=_4});var Is=A((OBe,$P)=>{var R4=VP(),E4=Ea(),KP=Tu(),XP=KP&&KP.isTypedArray,C4=XP?E4(XP):R4;$P.exports=C4});var Ch=A((DBe,WP)=>{var P4=xP(),x4=vs(),T4=ve(),N4=no(),w4=Ra(),O4=Is(),D4=Object.prototype,k4=D4.hasOwnProperty;function M4(e,t){var n=T4(e),r=!n&&x4(e),o=!n&&!r&&N4(e),s=!n&&!r&&!o&&O4(e),i=n||r||o||s,a=i?P4(e.length,String):[],d=a.length;for(var c in e)(t||k4.call(e,c))&&!(i&&(c=="length"||o&&(c=="offset"||c=="parent")||s&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||w4(c,d)))&&a.push(c);return a}WP.exports=M4});var xa=A((kBe,QP)=>{var L4=Object.prototype;function B4(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||L4;return e===n}QP.exports=B4});var Ph=A((MBe,JP)=>{function G4(e,t){return function(n){return e(t(n))}}JP.exports=G4});var ex=A((LBe,ZP)=>{var U4=Ph(),z4=U4(Object.keys,Object);ZP.exports=z4});var Nu=A((BBe,tx)=>{var q4=xa(),F4=ex(),j4=Object.prototype,V4=j4.hasOwnProperty;function H4(e){if(!q4(e))return F4(e);var t=[];for(var n in Object(e))V4.call(e,n)&&n!="constructor"&&t.push(n);return t}tx.exports=H4});var tn=A((GBe,nx)=>{var Y4=ms(),K4=xu();function X4(e){return e!=null&&K4(e.length)&&!Y4(e)}nx.exports=X4});var Tn=A((UBe,rx)=>{var $4=Ch(),W4=Nu(),Q4=tn();function J4(e){return Q4(e)?$4(e):W4(e)}rx.exports=J4});var sx=A((zBe,ox)=>{var Z4=As(),e9=Tn();function t9(e,t){return e&&Z4(t,e9(t),e)}ox.exports=t9});var ax=A((qBe,ix)=>{function n9(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}ix.exports=n9});var cx=A((FBe,dx)=>{var r9=it(),o9=xa(),s9=ax(),i9=Object.prototype,a9=i9.hasOwnProperty;function d9(e){if(!r9(e))return s9(e);var t=o9(e),n=[];for(var r in e)r=="constructor"&&(t||!a9.call(e,r))||n.push(r);return n}dx.exports=d9});var sr=A((jBe,ux)=>{var c9=Ch(),u9=cx(),p9=tn();function l9(e){return p9(e)?c9(e,!0):u9(e)}ux.exports=l9});var lx=A((VBe,px)=>{var f9=As(),m9=sr();function h9(e,t){return e&&f9(t,m9(t),e)}px.exports=h9});var xh=A((Ta,_s)=>{var g9=yt(),gx=typeof Ta=="object"&&Ta&&!Ta.nodeType&&Ta,fx=gx&&typeof _s=="object"&&_s&&!_s.nodeType&&_s,y9=fx&&fx.exports===gx,mx=y9?g9.Buffer:void 0,hx=mx?mx.allocUnsafe:void 0;function A9(e,t){if(t)return e.slice();var n=e.length,r=hx?hx(n):new e.constructor(n);return e.copy(r),r}_s.exports=A9});var Th=A((HBe,yx)=>{function v9(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}yx.exports=v9});var Nh=A((YBe,Ax)=>{function S9(e,t){for(var n=-1,r=e==null?0:e.length,o=0,s=[];++n<r;){var i=e[n];t(i,n,e)&&(s[o++]=i)}return s}Ax.exports=S9});var wh=A((KBe,vx)=>{function b9(){return[]}vx.exports=b9});var wu=A((XBe,bx)=>{var I9=Nh(),_9=wh(),R9=Object.prototype,E9=R9.propertyIsEnumerable,Sx=Object.getOwnPropertySymbols,C9=Sx?function(e){return e==null?[]:(e=Object(e),I9(Sx(e),function(t){return E9.call(e,t)}))}:_9;bx.exports=C9});var _x=A(($Be,Ix)=>{var P9=As(),x9=wu();function T9(e,t){return P9(e,x9(e),t)}Ix.exports=T9});var Ou=A((WBe,Rx)=>{function N9(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}Rx.exports=N9});var Na=A((QBe,Ex)=>{var w9=Ph(),O9=w9(Object.getPrototypeOf,Object);Ex.exports=O9});var Oh=A((JBe,Cx)=>{var D9=Ou(),k9=Na(),M9=wu(),L9=wh(),B9=Object.getOwnPropertySymbols,G9=B9?function(e){for(var t=[];e;)D9(t,M9(e)),e=k9(e);return t}:L9;Cx.exports=G9});var xx=A((ZBe,Px)=>{var U9=As(),z9=Oh();function q9(e,t){return U9(e,z9(e),t)}Px.exports=q9});var Dh=A((eGe,Tx)=>{var F9=Ou(),j9=ve();function V9(e,t,n){var r=t(e);return j9(e)?r:F9(r,n(e))}Tx.exports=V9});var kh=A((tGe,Nx)=>{var H9=Dh(),Y9=wu(),K9=Tn();function X9(e){return H9(e,K9,Y9)}Nx.exports=X9});var Ox=A((nGe,wx)=>{var $9=Dh(),W9=Oh(),Q9=sr();function J9(e){return $9(e,Q9,W9)}wx.exports=J9});var kx=A((rGe,Dx)=>{var Z9=or(),e6=yt(),t6=Z9(e6,"DataView");Dx.exports=t6});var Lx=A((oGe,Mx)=>{var n6=or(),r6=yt(),o6=n6(r6,"Promise");Mx.exports=o6});var Mh=A((sGe,Bx)=>{var s6=or(),i6=yt(),a6=s6(i6,"Set");Bx.exports=a6});var Ux=A((iGe,Gx)=>{var d6=or(),c6=yt(),u6=d6(c6,"WeakMap");Gx.exports=u6});var oo=A((aGe,Yx)=>{var Lh=kx(),Bh=Eu(),Gh=Lx(),Uh=Mh(),zh=Ux(),Hx=rr(),Rs=_h(),zx="[object Map]",p6="[object Object]",qx="[object Promise]",Fx="[object Set]",jx="[object WeakMap]",Vx="[object DataView]",l6=Rs(Lh),f6=Rs(Bh),m6=Rs(Gh),h6=Rs(Uh),g6=Rs(zh),ro=Hx;(Lh&&ro(new Lh(new ArrayBuffer(1)))!=Vx||Bh&&ro(new Bh)!=zx||Gh&&ro(Gh.resolve())!=qx||Uh&&ro(new Uh)!=Fx||zh&&ro(new zh)!=jx)&&(ro=function(e){var t=Hx(e),n=t==p6?e.constructor:void 0,r=n?Rs(n):"";if(r)switch(r){case l6:return Vx;case f6:return zx;case m6:return qx;case h6:return Fx;case g6:return jx}return t});Yx.exports=ro});var Xx=A((dGe,Kx)=>{var y6=Object.prototype,A6=y6.hasOwnProperty;function v6(e){var t=e.length,n=new e.constructor(t);return t&&typeof e[0]=="string"&&A6.call(e,"index")&&(n.index=e.index,n.input=e.input),n}Kx.exports=v6});var qh=A((cGe,$x)=>{var S6=yt(),b6=S6.Uint8Array;$x.exports=b6});var Du=A((uGe,Qx)=>{var Wx=qh();function I6(e){var t=new e.constructor(e.byteLength);return new Wx(t).set(new Wx(e)),t}Qx.exports=I6});var Zx=A((pGe,Jx)=>{var _6=Du();function R6(e,t){var n=t?_6(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}Jx.exports=R6});var tT=A((lGe,eT)=>{var E6=/\w*$/;function C6(e){var t=new e.constructor(e.source,E6.exec(e));return t.lastIndex=e.lastIndex,t}eT.exports=C6});var iT=A((fGe,sT)=>{var nT=to(),rT=nT?nT.prototype:void 0,oT=rT?rT.valueOf:void 0;function P6(e){return oT?Object(oT.call(e)):{}}sT.exports=P6});var Fh=A((mGe,aT)=>{var x6=Du();function T6(e,t){var n=t?x6(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}aT.exports=T6});var cT=A((hGe,dT)=>{var N6=Du(),w6=Zx(),O6=tT(),D6=iT(),k6=Fh(),M6="[object Boolean]",L6="[object Date]",B6="[object Map]",G6="[object Number]",U6="[object RegExp]",z6="[object Set]",q6="[object String]",F6="[object Symbol]",j6="[object ArrayBuffer]",V6="[object DataView]",H6="[object Float32Array]",Y6="[object Float64Array]",K6="[object Int8Array]",X6="[object Int16Array]",$6="[object Int32Array]",W6="[object Uint8Array]",Q6="[object Uint8ClampedArray]",J6="[object Uint16Array]",Z6="[object Uint32Array]";function e5(e,t,n){var r=e.constructor;switch(t){case j6:return N6(e);case M6:case L6:return new r(+e);case V6:return w6(e,n);case H6:case Y6:case K6:case X6:case $6:case W6:case Q6:case J6:case Z6:return k6(e,n);case B6:return new r;case G6:case q6:return new r(e);case U6:return O6(e);case z6:return new r;case F6:return D6(e)}}dT.exports=e5});var jh=A((gGe,pT)=>{var t5=it(),uT=Object.create,n5=function(){function e(){}return function(t){if(!t5(t))return{};if(uT)return uT(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();pT.exports=n5});var Vh=A((yGe,lT)=>{var r5=jh(),o5=Na(),s5=xa();function i5(e){return typeof e.constructor=="function"&&!s5(e)?r5(o5(e)):{}}lT.exports=i5});var mT=A((AGe,fT)=>{var a5=oo(),d5=Ot(),c5="[object Map]";function u5(e){return d5(e)&&a5(e)==c5}fT.exports=u5});var AT=A((vGe,yT)=>{var p5=mT(),l5=Ea(),hT=Tu(),gT=hT&&hT.isMap,f5=gT?l5(gT):p5;yT.exports=f5});var ST=A((SGe,vT)=>{var m5=oo(),h5=Ot(),g5="[object Set]";function y5(e){return h5(e)&&m5(e)==g5}vT.exports=y5});var RT=A((bGe,_T)=>{var A5=ST(),v5=Ea(),bT=Tu(),IT=bT&&bT.isSet,S5=IT?v5(IT):A5;_T.exports=S5});var Hh=A((IGe,xT)=>{var b5=Sa(),I5=Pu(),_5=Ia(),R5=sx(),E5=lx(),C5=xh(),P5=Th(),x5=_x(),T5=xx(),N5=kh(),w5=Ox(),O5=oo(),D5=Xx(),k5=cT(),M5=Vh(),L5=ve(),B5=no(),G5=AT(),U5=it(),z5=RT(),q5=Tn(),F5=sr(),j5=1,V5=2,H5=4,ET="[object Arguments]",Y5="[object Array]",K5="[object Boolean]",X5="[object Date]",$5="[object Error]",CT="[object Function]",W5="[object GeneratorFunction]",Q5="[object Map]",J5="[object Number]",PT="[object Object]",Z5="[object RegExp]",e7="[object Set]",t7="[object String]",n7="[object Symbol]",r7="[object WeakMap]",o7="[object ArrayBuffer]",s7="[object DataView]",i7="[object Float32Array]",a7="[object Float64Array]",d7="[object Int8Array]",c7="[object Int16Array]",u7="[object Int32Array]",p7="[object Uint8Array]",l7="[object Uint8ClampedArray]",f7="[object Uint16Array]",m7="[object Uint32Array]",ae={};ae[ET]=ae[Y5]=ae[o7]=ae[s7]=ae[K5]=ae[X5]=ae[i7]=ae[a7]=ae[d7]=ae[c7]=ae[u7]=ae[Q5]=ae[J5]=ae[PT]=ae[Z5]=ae[e7]=ae[t7]=ae[n7]=ae[p7]=ae[l7]=ae[f7]=ae[m7]=!0;ae[$5]=ae[CT]=ae[r7]=!1;function ku(e,t,n,r,o,s){var i,a=t&j5,d=t&V5,c=t&H5;if(n&&(i=o?n(e,r,o,s):n(e)),i!==void 0)return i;if(!U5(e))return e;var u=L5(e);if(u){if(i=D5(e),!a)return P5(e,i)}else{var p=O5(e),l=p==CT||p==W5;if(B5(e))return C5(e,a);if(p==PT||p==ET||l&&!o){if(i=d||l?{}:M5(e),!a)return d?T5(e,E5(i,e)):x5(e,R5(i,e))}else{if(!ae[p])return o?e:{};i=k5(e,p,a)}}s||(s=new b5);var f=s.get(e);if(f)return f;s.set(e,i),z5(e)?e.forEach(function(g){i.add(ku(g,t,n,g,e,s))}):G5(e)&&e.forEach(function(g,y){i.set(y,ku(g,t,n,y,e,s))});var h=c?d?w5:N5:d?F5:q5,m=u?void 0:h(e);return I5(m||e,function(g,y){m&&(y=g,g=e[y]),_5(i,y,ku(g,t,n,y,e,s))}),i}xT.exports=ku});var NT=A((_Ge,TT)=>{var h7=Hh(),g7=4;function y7(e){return h7(e,g7)}TT.exports=y7});var Mu=A((RGe,wT)=>{function A7(e){return function(){return e}}wT.exports=A7});var DT=A((EGe,OT)=>{function v7(e){return function(t,n,r){for(var o=-1,s=Object(t),i=r(t),a=i.length;a--;){var d=i[e?a:++o];if(n(s[d],d,s)===!1)break}return t}}OT.exports=v7});var Lu=A((CGe,kT)=>{var S7=DT(),b7=S7();kT.exports=b7});var Bu=A((PGe,MT)=>{var I7=Lu(),_7=Tn();function R7(e,t){return e&&I7(e,t,_7)}MT.exports=R7});var BT=A((xGe,LT)=>{var E7=tn();function C7(e,t){return function(n,r){if(n==null)return n;if(!E7(n))return e(n,r);for(var o=n.length,s=t?o:-1,i=Object(n);(t?s--:++s<o)&&r(i[s],s,i)!==!1;);return n}}LT.exports=C7});var wa=A((TGe,GT)=>{var P7=Bu(),x7=BT(),T7=x7(P7);GT.exports=T7});var ir=A((NGe,UT)=>{function N7(e){return e}UT.exports=N7});var Yh=A((wGe,zT)=>{var w7=ir();function O7(e){return typeof e=="function"?e:w7}zT.exports=O7});var Kh=A((OGe,qT)=>{var D7=Pu(),k7=wa(),M7=Yh(),L7=ve();function B7(e,t){var n=L7(e)?D7:k7;return n(e,M7(t))}qT.exports=B7});var Xh=A((DGe,FT)=>{FT.exports=Kh()});var VT=A((kGe,jT)=>{var G7=wa();function U7(e,t){var n=[];return G7(e,function(r,o,s){t(r,o,s)&&n.push(r)}),n}jT.exports=U7});var YT=A((MGe,HT)=>{var z7="__lodash_hash_undefined__";function q7(e){return this.__data__.set(e,z7),this}HT.exports=q7});var XT=A((LGe,KT)=>{function F7(e){return this.__data__.has(e)}KT.exports=F7});var $h=A((BGe,$T)=>{var j7=Cu(),V7=YT(),H7=XT();function Gu(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new j7;++t<n;)this.add(e[t])}Gu.prototype.add=Gu.prototype.push=V7;Gu.prototype.has=H7;$T.exports=Gu});var QT=A((GGe,WT)=>{function Y7(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}WT.exports=Y7});var Wh=A((UGe,JT)=>{function K7(e,t){return e.has(t)}JT.exports=K7});var Qh=A((zGe,ZT)=>{var X7=$h(),$7=QT(),W7=Wh(),Q7=1,J7=2;function Z7(e,t,n,r,o,s){var i=n&Q7,a=e.length,d=t.length;if(a!=d&&!(i&&d>a))return!1;var c=s.get(e),u=s.get(t);if(c&&u)return c==t&&u==e;var p=-1,l=!0,f=n&J7?new X7:void 0;for(s.set(e,t),s.set(t,e);++p<a;){var h=e[p],m=t[p];if(r)var g=i?r(m,h,p,t,e,s):r(h,m,p,e,t,s);if(g!==void 0){if(g)continue;l=!1;break}if(f){if(!$7(t,function(y,v){if(!W7(f,v)&&(h===y||o(h,y,n,r,s)))return f.push(v)})){l=!1;break}}else if(!(h===m||o(h,m,n,r,s))){l=!1;break}}return s.delete(e),s.delete(t),l}ZT.exports=Z7});var tN=A((qGe,eN)=>{function eQ(e){var t=-1,n=Array(e.size);return e.forEach(function(r,o){n[++t]=[o,r]}),n}eN.exports=eQ});var Uu=A((FGe,nN)=>{function tQ(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}nN.exports=tQ});var aN=A((jGe,iN)=>{var rN=to(),oN=qh(),nQ=eo(),rQ=Qh(),oQ=tN(),sQ=Uu(),iQ=1,aQ=2,dQ="[object Boolean]",cQ="[object Date]",uQ="[object Error]",pQ="[object Map]",lQ="[object Number]",fQ="[object RegExp]",mQ="[object Set]",hQ="[object String]",gQ="[object Symbol]",yQ="[object ArrayBuffer]",AQ="[object DataView]",sN=rN?rN.prototype:void 0,Jh=sN?sN.valueOf:void 0;function vQ(e,t,n,r,o,s,i){switch(n){case AQ:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case yQ:return!(e.byteLength!=t.byteLength||!s(new oN(e),new oN(t)));case dQ:case cQ:case lQ:return nQ(+e,+t);case uQ:return e.name==t.name&&e.message==t.message;case fQ:case hQ:return e==t+"";case pQ:var a=oQ;case mQ:var d=r&iQ;if(a||(a=sQ),e.size!=t.size&&!d)return!1;var c=i.get(e);if(c)return c==t;r|=aQ,i.set(e,t);var u=rQ(a(e),a(t),r,o,s,i);return i.delete(e),u;case gQ:if(Jh)return Jh.call(e)==Jh.call(t)}return!1}iN.exports=vQ});var uN=A((VGe,cN)=>{var dN=kh(),SQ=1,bQ=Object.prototype,IQ=bQ.hasOwnProperty;function _Q(e,t,n,r,o,s){var i=n&SQ,a=dN(e),d=a.length,c=dN(t),u=c.length;if(d!=u&&!i)return!1;for(var p=d;p--;){var l=a[p];if(!(i?l in t:IQ.call(t,l)))return!1}var f=s.get(e),h=s.get(t);if(f&&h)return f==t&&h==e;var m=!0;s.set(e,t),s.set(t,e);for(var g=i;++p<d;){l=a[p];var y=e[l],v=t[l];if(r)var S=i?r(v,y,l,t,e,s):r(y,v,l,e,t,s);if(!(S===void 0?y===v||o(y,v,n,r,s):S)){m=!1;break}g||(g=l=="constructor")}if(m&&!g){var b=e.constructor,I=t.constructor;b!=I&&"constructor"in e&&"constructor"in t&&!(typeof b=="function"&&b instanceof b&&typeof I=="function"&&I instanceof I)&&(m=!1)}return s.delete(e),s.delete(t),m}cN.exports=_Q});var AN=A((HGe,yN)=>{var Zh=Sa(),RQ=Qh(),EQ=aN(),CQ=uN(),pN=oo(),lN=ve(),fN=no(),PQ=Is(),xQ=1,mN="[object Arguments]",hN="[object Array]",zu="[object Object]",TQ=Object.prototype,gN=TQ.hasOwnProperty;function NQ(e,t,n,r,o,s){var i=lN(e),a=lN(t),d=i?hN:pN(e),c=a?hN:pN(t);d=d==mN?zu:d,c=c==mN?zu:c;var u=d==zu,p=c==zu,l=d==c;if(l&&fN(e)){if(!fN(t))return!1;i=!0,u=!1}if(l&&!u)return s||(s=new Zh),i||PQ(e)?RQ(e,t,n,r,o,s):EQ(e,t,d,n,r,o,s);if(!(n&xQ)){var f=u&&gN.call(e,"__wrapped__"),h=p&&gN.call(t,"__wrapped__");if(f||h){var m=f?e.value():e,g=h?t.value():t;return s||(s=new Zh),o(m,g,n,r,s)}}return l?(s||(s=new Zh),CQ(e,t,n,r,o,s)):!1}yN.exports=NQ});var eg=A((YGe,bN)=>{var wQ=AN(),vN=Ot();function SN(e,t,n,r,o){return e===t?!0:e==null||t==null||!vN(e)&&!vN(t)?e!==e&&t!==t:wQ(e,t,n,r,SN,o)}bN.exports=SN});var _N=A((KGe,IN)=>{var OQ=Sa(),DQ=eg(),kQ=1,MQ=2;function LQ(e,t,n,r){var o=n.length,s=o,i=!r;if(e==null)return!s;for(e=Object(e);o--;){var a=n[o];if(i&&a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++o<s;){a=n[o];var d=a[0],c=e[d],u=a[1];if(i&&a[2]){if(c===void 0&&!(d in e))return!1}else{var p=new OQ;if(r)var l=r(c,u,d,e,t,p);if(!(l===void 0?DQ(u,c,kQ|MQ,r,p):l))return!1}}return!0}IN.exports=LQ});var tg=A((XGe,RN)=>{var BQ=it();function GQ(e){return e===e&&!BQ(e)}RN.exports=GQ});var CN=A(($Ge,EN)=>{var UQ=tg(),zQ=Tn();function qQ(e){for(var t=zQ(e),n=t.length;n--;){var r=t[n],o=e[r];t[n]=[r,o,UQ(o)]}return t}EN.exports=qQ});var ng=A((WGe,PN)=>{function FQ(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}PN.exports=FQ});var TN=A((QGe,xN)=>{var jQ=_N(),VQ=CN(),HQ=ng();function YQ(e){var t=VQ(e);return t.length==1&&t[0][2]?HQ(t[0][0],t[0][1]):function(n){return n===e||jQ(n,e,t)}}xN.exports=YQ});var so=A((JGe,NN)=>{var KQ=rr(),XQ=Ot(),$Q="[object Symbol]";function WQ(e){return typeof e=="symbol"||XQ(e)&&KQ(e)==$Q}NN.exports=WQ});var qu=A((ZGe,wN)=>{var QQ=ve(),JQ=so(),ZQ=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,eJ=/^\w*$/;function tJ(e,t){if(QQ(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||JQ(e)?!0:eJ.test(e)||!ZQ.test(e)||t!=null&&e in Object(t)}wN.exports=tJ});var kN=A((e1e,DN)=>{var ON=Cu(),nJ="Expected a function";function rg(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(nJ);var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],s=n.cache;if(s.has(o))return s.get(o);var i=e.apply(this,r);return n.cache=s.set(o,i)||s,i};return n.cache=new(rg.Cache||ON),n}rg.Cache=ON;DN.exports=rg});var LN=A((t1e,MN)=>{var rJ=kN(),oJ=500;function sJ(e){var t=rJ(e,function(r){return n.size===oJ&&n.clear(),r}),n=t.cache;return t}MN.exports=sJ});var GN=A((n1e,BN)=>{var iJ=LN(),aJ=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,dJ=/\\(\\)?/g,cJ=iJ(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(aJ,function(n,r,o,s){t.push(o?s.replace(dJ,"$1"):r||n)}),t});BN.exports=cJ});var Oa=A((r1e,UN)=>{function uJ(e,t){for(var n=-1,r=e==null?0:e.length,o=Array(r);++n<r;)o[n]=t(e[n],n,e);return o}UN.exports=uJ});var HN=A((o1e,VN)=>{var zN=to(),pJ=Oa(),lJ=ve(),fJ=so(),mJ=1/0,qN=zN?zN.prototype:void 0,FN=qN?qN.toString:void 0;function jN(e){if(typeof e=="string")return e;if(lJ(e))return pJ(e,jN)+"";if(fJ(e))return FN?FN.call(e):"";var t=e+"";return t=="0"&&1/e==-mJ?"-0":t}VN.exports=jN});var og=A((s1e,YN)=>{var hJ=HN();function gJ(e){return e==null?"":hJ(e)}YN.exports=gJ});var Da=A((i1e,KN)=>{var yJ=ve(),AJ=qu(),vJ=GN(),SJ=og();function bJ(e,t){return yJ(e)?e:AJ(e,t)?[e]:vJ(SJ(e))}KN.exports=bJ});var Es=A((a1e,XN)=>{var IJ=so(),_J=1/0;function RJ(e){if(typeof e=="string"||IJ(e))return e;var t=e+"";return t=="0"&&1/e==-_J?"-0":t}XN.exports=RJ});var ka=A((d1e,$N)=>{var EJ=Da(),CJ=Es();function PJ(e,t){t=EJ(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[CJ(t[n++])];return n&&n==r?e:void 0}$N.exports=PJ});var QN=A((c1e,WN)=>{var xJ=ka();function TJ(e,t,n){var r=e==null?void 0:xJ(e,t);return r===void 0?n:r}WN.exports=TJ});var ZN=A((u1e,JN)=>{function NJ(e,t){return e!=null&&t in Object(e)}JN.exports=NJ});var sg=A((p1e,ew)=>{var wJ=Da(),OJ=vs(),DJ=ve(),kJ=Ra(),MJ=xu(),LJ=Es();function BJ(e,t,n){t=wJ(t,e);for(var r=-1,o=t.length,s=!1;++r<o;){var i=LJ(t[r]);if(!(s=e!=null&&n(e,i)))break;e=e[i]}return s||++r!=o?s:(o=e==null?0:e.length,!!o&&MJ(o)&&kJ(i,o)&&(DJ(e)||OJ(e)))}ew.exports=BJ});var ig=A((l1e,tw)=>{var GJ=ZN(),UJ=sg();function zJ(e,t){return e!=null&&UJ(e,t,GJ)}tw.exports=zJ});var rw=A((f1e,nw)=>{var qJ=eg(),FJ=QN(),jJ=ig(),VJ=qu(),HJ=tg(),YJ=ng(),KJ=Es(),XJ=1,$J=2;function WJ(e,t){return VJ(e)&&HJ(t)?YJ(KJ(e),t):function(n){var r=FJ(n,e);return r===void 0&&r===t?jJ(n,e):qJ(t,r,XJ|$J)}}nw.exports=WJ});var ag=A((m1e,ow)=>{function QJ(e){return function(t){return t==null?void 0:t[e]}}ow.exports=QJ});var iw=A((h1e,sw)=>{var JJ=ka();function ZJ(e){return function(t){return JJ(t,e)}}sw.exports=ZJ});var dw=A((g1e,aw)=>{var eZ=ag(),tZ=iw(),nZ=qu(),rZ=Es();function oZ(e){return nZ(e)?eZ(rZ(e)):tZ(e)}aw.exports=oZ});var nn=A((y1e,cw)=>{var sZ=TN(),iZ=rw(),aZ=ir(),dZ=ve(),cZ=dw();function uZ(e){return typeof e=="function"?e:e==null?aZ:typeof e=="object"?dZ(e)?iZ(e[0],e[1]):sZ(e):cZ(e)}cw.exports=uZ});var dg=A((A1e,uw)=>{var pZ=Nh(),lZ=VT(),fZ=nn(),mZ=ve();function hZ(e,t){var n=mZ(e)?pZ:lZ;return n(e,fZ(t,3))}uw.exports=hZ});var lw=A((v1e,pw)=>{var gZ=Object.prototype,yZ=gZ.hasOwnProperty;function AZ(e,t){return e!=null&&yZ.call(e,t)}pw.exports=AZ});var cg=A((S1e,fw)=>{var vZ=lw(),SZ=sg();function bZ(e,t){return e!=null&&SZ(e,t,vZ)}fw.exports=bZ});var hw=A((b1e,mw)=>{var IZ=Nu(),_Z=oo(),RZ=vs(),EZ=ve(),CZ=tn(),PZ=no(),xZ=xa(),TZ=Is(),NZ="[object Map]",wZ="[object Set]",OZ=Object.prototype,DZ=OZ.hasOwnProperty;function kZ(e){if(e==null)return!0;if(CZ(e)&&(EZ(e)||typeof e=="string"||typeof e.splice=="function"||PZ(e)||TZ(e)||RZ(e)))return!e.length;var t=_Z(e);if(t==NZ||t==wZ)return!e.size;if(xZ(e))return!IZ(e).length;for(var n in e)if(DZ.call(e,n))return!1;return!0}mw.exports=kZ});var ug=A((I1e,gw)=>{function MZ(e){return e===void 0}gw.exports=MZ});var pg=A((_1e,yw)=>{var LZ=wa(),BZ=tn();function GZ(e,t){var n=-1,r=BZ(e)?Array(e.length):[];return LZ(e,function(o,s,i){r[++n]=t(o,s,i)}),r}yw.exports=GZ});var lg=A((R1e,Aw)=>{var UZ=Oa(),zZ=nn(),qZ=pg(),FZ=ve();function jZ(e,t){var n=FZ(e)?UZ:qZ;return n(e,zZ(t,3))}Aw.exports=jZ});var Sw=A((E1e,vw)=>{function VZ(e,t,n,r){var o=-1,s=e==null?0:e.length;for(r&&s&&(n=e[++o]);++o<s;)n=t(n,e[o],o,e);return n}vw.exports=VZ});var Iw=A((C1e,bw)=>{function HZ(e,t,n,r,o){return o(e,function(s,i,a){n=r?(r=!1,s):t(n,s,i,a)}),n}bw.exports=HZ});var fg=A((P1e,_w)=>{var YZ=Sw(),KZ=wa(),XZ=nn(),$Z=Iw(),WZ=ve();function QZ(e,t,n){var r=WZ(e)?YZ:$Z,o=arguments.length<3;return r(e,XZ(t,4),n,o,KZ)}_w.exports=QZ});var Ew=A((x1e,Rw)=>{var JZ=rr(),ZZ=ve(),eee=Ot(),tee="[object String]";function nee(e){return typeof e=="string"||!ZZ(e)&&eee(e)&&JZ(e)==tee}Rw.exports=nee});var Pw=A((T1e,Cw)=>{var ree=ag(),oee=ree("length");Cw.exports=oee});var Tw=A((N1e,xw)=>{var see="\\ud800-\\udfff",iee="\\u0300-\\u036f",aee="\\ufe20-\\ufe2f",dee="\\u20d0-\\u20ff",cee=iee+aee+dee,uee="\\ufe0e\\ufe0f",pee="\\u200d",lee=RegExp("["+pee+see+cee+uee+"]");function fee(e){return lee.test(e)}xw.exports=fee});var Gw=A((w1e,Bw)=>{var ww="\\ud800-\\udfff",mee="\\u0300-\\u036f",hee="\\ufe20-\\ufe2f",gee="\\u20d0-\\u20ff",yee=mee+hee+gee,Aee="\\ufe0e\\ufe0f",vee="["+ww+"]",mg="["+yee+"]",hg="\\ud83c[\\udffb-\\udfff]",See="(?:"+mg+"|"+hg+")",Ow="[^"+ww+"]",Dw="(?:\\ud83c[\\udde6-\\uddff]){2}",kw="[\\ud800-\\udbff][\\udc00-\\udfff]",bee="\\u200d",Mw=See+"?",Lw="["+Aee+"]?",Iee="(?:"+bee+"(?:"+[Ow,Dw,kw].join("|")+")"+Lw+Mw+")*",_ee=Lw+Mw+Iee,Ree="(?:"+[Ow+mg+"?",mg,Dw,kw,vee].join("|")+")",Nw=RegExp(hg+"(?="+hg+")|"+Ree+_ee,"g");function Eee(e){for(var t=Nw.lastIndex=0;Nw.test(e);)++t;return t}Bw.exports=Eee});var zw=A((O1e,Uw)=>{var Cee=Pw(),Pee=Tw(),xee=Gw();function Tee(e){return Pee(e)?xee(e):Cee(e)}Uw.exports=Tee});var Fw=A((D1e,qw)=>{var Nee=Nu(),wee=oo(),Oee=tn(),Dee=Ew(),kee=zw(),Mee="[object Map]",Lee="[object Set]";function Bee(e){if(e==null)return 0;if(Oee(e))return Dee(e)?kee(e):e.length;var t=wee(e);return t==Mee||t==Lee?e.size:Nee(e).length}qw.exports=Bee});var Vw=A((k1e,jw)=>{var Gee=Pu(),Uee=jh(),zee=Bu(),qee=nn(),Fee=Na(),jee=ve(),Vee=no(),Hee=ms(),Yee=it(),Kee=Is();function Xee(e,t,n){var r=jee(e),o=r||Vee(e)||Kee(e);if(t=qee(t,4),n==null){var s=e&&e.constructor;o?n=r?new s:[]:Yee(e)?n=Hee(s)?Uee(Fee(e)):{}:n={}}return(o?Gee:zee)(e,function(i,a,d){return t(n,i,a,d)}),n}jw.exports=Xee});var Xw=A((M1e,Kw)=>{var Hw=to(),$ee=vs(),Wee=ve(),Yw=Hw?Hw.isConcatSpreadable:void 0;function Qee(e){return Wee(e)||$ee(e)||!!(Yw&&e&&e[Yw])}Kw.exports=Qee});var Fu=A((L1e,Ww)=>{var Jee=Ou(),Zee=Xw();function $w(e,t,n,r,o){var s=-1,i=e.length;for(n||(n=Zee),o||(o=[]);++s<i;){var a=e[s];t>0&&n(a)?t>1?$w(a,t-1,n,r,o):Jee(o,a):r||(o[o.length]=a)}return o}Ww.exports=$w});var Jw=A((B1e,Qw)=>{function ete(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}Qw.exports=ete});var gg=A((G1e,eO)=>{var tte=Jw(),Zw=Math.max;function nte(e,t,n){return t=Zw(t===void 0?e.length-1:t,0),function(){for(var r=arguments,o=-1,s=Zw(r.length-t,0),i=Array(s);++o<s;)i[o]=r[t+o];o=-1;for(var a=Array(t+1);++o<t;)a[o]=r[o];return a[t]=n(i),tte(e,this,a)}}eO.exports=nte});var rO=A((U1e,nO)=>{var rte=Mu(),tO=Rh(),ote=ir(),ste=tO?function(e,t){return tO(e,"toString",{configurable:!0,enumerable:!1,value:rte(t),writable:!0})}:ote;nO.exports=ste});var sO=A((z1e,oO)=>{var ite=800,ate=16,dte=Date.now;function cte(e){var t=0,n=0;return function(){var r=dte(),o=ate-(r-n);if(n=r,o>0){if(++t>=ite)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}oO.exports=cte});var yg=A((q1e,iO)=>{var ute=rO(),pte=sO(),lte=pte(ute);iO.exports=lte});var Ma=A((F1e,aO)=>{var fte=ir(),mte=gg(),hte=yg();function gte(e,t){return hte(mte(e,t,fte),e+"")}aO.exports=gte});var Ag=A((j1e,dO)=>{function yte(e,t,n,r){for(var o=e.length,s=n+(r?1:-1);r?s--:++s<o;)if(t(e[s],s,e))return s;return-1}dO.exports=yte});var uO=A((V1e,cO)=>{function Ate(e){return e!==e}cO.exports=Ate});var lO=A((H1e,pO)=>{function vte(e,t,n){for(var r=n-1,o=e.length;++r<o;)if(e[r]===t)return r;return-1}pO.exports=vte});var mO=A((Y1e,fO)=>{var Ste=Ag(),bte=uO(),Ite=lO();function _te(e,t,n){return t===t?Ite(e,t,n):Ste(e,bte,n)}fO.exports=_te});var gO=A((K1e,hO)=>{var Rte=mO();function Ete(e,t){var n=e==null?0:e.length;return!!n&&Rte(e,t,0)>-1}hO.exports=Ete});var AO=A((X1e,yO)=>{function Cte(e,t,n){for(var r=-1,o=e==null?0:e.length;++r<o;)if(n(t,e[r]))return!0;return!1}yO.exports=Cte});var SO=A(($1e,vO)=>{function Pte(){}vO.exports=Pte});var IO=A((W1e,bO)=>{var vg=Mh(),xte=SO(),Tte=Uu(),Nte=1/0,wte=vg&&1/Tte(new vg([,-0]))[1]==Nte?function(e){return new vg(e)}:xte;bO.exports=wte});var RO=A((Q1e,_O)=>{var Ote=$h(),Dte=gO(),kte=AO(),Mte=Wh(),Lte=IO(),Bte=Uu(),Gte=200;function Ute(e,t,n){var r=-1,o=Dte,s=e.length,i=!0,a=[],d=a;if(n)i=!1,o=kte;else if(s>=Gte){var c=t?null:Lte(e);if(c)return Bte(c);i=!1,o=Mte,d=new Ote}else d=t?[]:a;e:for(;++r<s;){var u=e[r],p=t?t(u):u;if(u=n||u!==0?u:0,i&&p===p){for(var l=d.length;l--;)if(d[l]===p)continue e;t&&d.push(p),a.push(u)}else o(d,p,n)||(d!==a&&d.push(p),a.push(u))}return a}_O.exports=Ute});var Sg=A((J1e,EO)=>{var zte=tn(),qte=Ot();function Fte(e){return qte(e)&&zte(e)}EO.exports=Fte});var PO=A((Z1e,CO)=>{var jte=Fu(),Vte=Ma(),Hte=RO(),Yte=Sg(),Kte=Vte(function(e){return Hte(jte(e,1,Yte,!0))});CO.exports=Kte});var TO=A((eUe,xO)=>{var Xte=Oa();function $te(e,t){return Xte(t,function(n){return e[n]})}xO.exports=$te});var bg=A((tUe,NO)=>{var Wte=TO(),Qte=Tn();function Jte(e){return e==null?[]:Wte(e,Qte(e))}NO.exports=Jte});var at=A((nUe,wO)=>{var ju;if(typeof require=="function")try{ju={clone:NT(),constant:Mu(),each:Xh(),filter:dg(),has:cg(),isArray:ve(),isEmpty:hw(),isFunction:ms(),isUndefined:ug(),keys:Tn(),map:lg(),reduce:fg(),size:Fw(),transform:Vw(),union:PO(),values:bg()}}catch{}ju||(ju=window._);wO.exports=ju});var Vu=A((rUe,MO)=>{"use strict";var D=at();MO.exports=G;var Zte="\0",io="\0",OO="";function G(e){this._isDirected=D.has(e,"directed")?e.directed:!0,this._isMultigraph=D.has(e,"multigraph")?e.multigraph:!1,this._isCompound=D.has(e,"compound")?e.compound:!1,this._label=void 0,this._defaultNodeLabelFn=D.constant(void 0),this._defaultEdgeLabelFn=D.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[io]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}G.prototype._nodeCount=0;G.prototype._edgeCount=0;G.prototype.isDirected=function(){return this._isDirected};G.prototype.isMultigraph=function(){return this._isMultigraph};G.prototype.isCompound=function(){return this._isCompound};G.prototype.setGraph=function(e){return this._label=e,this};G.prototype.graph=function(){return this._label};G.prototype.setDefaultNodeLabel=function(e){return D.isFunction(e)||(e=D.constant(e)),this._defaultNodeLabelFn=e,this};G.prototype.nodeCount=function(){return this._nodeCount};G.prototype.nodes=function(){return D.keys(this._nodes)};G.prototype.sources=function(){var e=this;return D.filter(this.nodes(),function(t){return D.isEmpty(e._in[t])})};G.prototype.sinks=function(){var e=this;return D.filter(this.nodes(),function(t){return D.isEmpty(e._out[t])})};G.prototype.setNodes=function(e,t){var n=arguments,r=this;return D.each(e,function(o){n.length>1?r.setNode(o,t):r.setNode(o)}),this};G.prototype.setNode=function(e,t){return D.has(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=io,this._children[e]={},this._children[io][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)};G.prototype.node=function(e){return this._nodes[e]};G.prototype.hasNode=function(e){return D.has(this._nodes,e)};G.prototype.removeNode=function(e){var t=this;if(D.has(this._nodes,e)){var n=function(r){t.removeEdge(t._edgeObjs[r])};delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],D.each(this.children(e),function(r){t.setParent(r)}),delete this._children[e]),D.each(D.keys(this._in[e]),n),delete this._in[e],delete this._preds[e],D.each(D.keys(this._out[e]),n),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this};G.prototype.setParent=function(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(D.isUndefined(t))t=io;else{t+="";for(var n=t;!D.isUndefined(n);n=this.parent(n))if(n===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this};G.prototype._removeFromParentsChildList=function(e){delete this._children[this._parent[e]][e]};G.prototype.parent=function(e){if(this._isCompound){var t=this._parent[e];if(t!==io)return t}};G.prototype.children=function(e){if(D.isUndefined(e)&&(e=io),this._isCompound){var t=this._children[e];if(t)return D.keys(t)}else{if(e===io)return this.nodes();if(this.hasNode(e))return[]}};G.prototype.predecessors=function(e){var t=this._preds[e];if(t)return D.keys(t)};G.prototype.successors=function(e){var t=this._sucs[e];if(t)return D.keys(t)};G.prototype.neighbors=function(e){var t=this.predecessors(e);if(t)return D.union(t,this.successors(e))};G.prototype.isLeaf=function(e){var t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),t.length===0};G.prototype.filterNodes=function(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var n=this;D.each(this._nodes,function(s,i){e(i)&&t.setNode(i,s)}),D.each(this._edgeObjs,function(s){t.hasNode(s.v)&&t.hasNode(s.w)&&t.setEdge(s,n.edge(s))});var r={};function o(s){var i=n.parent(s);return i===void 0||t.hasNode(i)?(r[s]=i,i):i in r?r[i]:o(i)}return this._isCompound&&D.each(t.nodes(),function(s){t.setParent(s,o(s))}),t};G.prototype.setDefaultEdgeLabel=function(e){return D.isFunction(e)||(e=D.constant(e)),this._defaultEdgeLabelFn=e,this};G.prototype.edgeCount=function(){return this._edgeCount};G.prototype.edges=function(){return D.values(this._edgeObjs)};G.prototype.setPath=function(e,t){var n=this,r=arguments;return D.reduce(e,function(o,s){return r.length>1?n.setEdge(o,s,t):n.setEdge(o,s),s}),this};G.prototype.setEdge=function(){var e,t,n,r,o=!1,s=arguments[0];typeof s=="object"&&s!==null&&"v"in s?(e=s.v,t=s.w,n=s.name,arguments.length===2&&(r=arguments[1],o=!0)):(e=s,t=arguments[1],n=arguments[3],arguments.length>2&&(r=arguments[2],o=!0)),e=""+e,t=""+t,D.isUndefined(n)||(n=""+n);var i=La(this._isDirected,e,t,n);if(D.has(this._edgeLabels,i))return o&&(this._edgeLabels[i]=r),this;if(!D.isUndefined(n)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[i]=o?r:this._defaultEdgeLabelFn(e,t,n);var a=ene(this._isDirected,e,t,n);return e=a.v,t=a.w,Object.freeze(a),this._edgeObjs[i]=a,DO(this._preds[t],e),DO(this._sucs[e],t),this._in[t][i]=a,this._out[e][i]=a,this._edgeCount++,this};G.prototype.edge=function(e,t,n){var r=arguments.length===1?Ig(this._isDirected,arguments[0]):La(this._isDirected,e,t,n);return this._edgeLabels[r]};G.prototype.hasEdge=function(e,t,n){var r=arguments.length===1?Ig(this._isDirected,arguments[0]):La(this._isDirected,e,t,n);return D.has(this._edgeLabels,r)};G.prototype.removeEdge=function(e,t,n){var r=arguments.length===1?Ig(this._isDirected,arguments[0]):La(this._isDirected,e,t,n),o=this._edgeObjs[r];return o&&(e=o.v,t=o.w,delete this._edgeLabels[r],delete this._edgeObjs[r],kO(this._preds[t],e),kO(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--),this};G.prototype.inEdges=function(e,t){var n=this._in[e];if(n){var r=D.values(n);return t?D.filter(r,function(o){return o.v===t}):r}};G.prototype.outEdges=function(e,t){var n=this._out[e];if(n){var r=D.values(n);return t?D.filter(r,function(o){return o.w===t}):r}};G.prototype.nodeEdges=function(e,t){var n=this.inEdges(e,t);if(n)return n.concat(this.outEdges(e,t))};function DO(e,t){e[t]?e[t]++:e[t]=1}function kO(e,t){--e[t]||delete e[t]}function La(e,t,n,r){var o=""+t,s=""+n;if(!e&&o>s){var i=o;o=s,s=i}return o+OO+s+OO+(D.isUndefined(r)?Zte:r)}function ene(e,t,n,r){var o=""+t,s=""+n;if(!e&&o>s){var i=o;o=s,s=i}var a={v:o,w:s};return r&&(a.name=r),a}function Ig(e,t){return La(e,t.v,t.w,t.name)}});var BO=A((oUe,LO)=>{LO.exports="2.1.8"});var UO=A((sUe,GO)=>{GO.exports={Graph:Vu(),version:BO()}});var qO=A((iUe,zO)=>{var rn=at(),tne=Vu();zO.exports={write:nne,read:sne};function nne(e){var t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:rne(e),edges:one(e)};return rn.isUndefined(e.graph())||(t.value=rn.clone(e.graph())),t}function rne(e){return rn.map(e.nodes(),function(t){var n=e.node(t),r=e.parent(t),o={v:t};return rn.isUndefined(n)||(o.value=n),rn.isUndefined(r)||(o.parent=r),o})}function one(e){return rn.map(e.edges(),function(t){var n=e.edge(t),r={v:t.v,w:t.w};return rn.isUndefined(t.name)||(r.name=t.name),rn.isUndefined(n)||(r.value=n),r})}function sne(e){var t=new tne(e.options).setGraph(e.value);return rn.each(e.nodes,function(n){t.setNode(n.v,n.value),n.parent&&t.setParent(n.v,n.parent)}),rn.each(e.edges,function(n){t.setEdge({v:n.v,w:n.w,name:n.name},n.value)}),t}});var jO=A((aUe,FO)=>{var Hu=at();FO.exports=ine;function ine(e){var t={},n=[],r;function o(s){Hu.has(t,s)||(t[s]=!0,r.push(s),Hu.each(e.successors(s),o),Hu.each(e.predecessors(s),o))}return Hu.each(e.nodes(),function(s){r=[],o(s),r.length&&n.push(r)}),n}});var _g=A((dUe,HO)=>{var VO=at();HO.exports=At;function At(){this._arr=[],this._keyIndices={}}At.prototype.size=function(){return this._arr.length};At.prototype.keys=function(){return this._arr.map(function(e){return e.key})};At.prototype.has=function(e){return VO.has(this._keyIndices,e)};At.prototype.priority=function(e){var t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority};At.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key};At.prototype.add=function(e,t){var n=this._keyIndices;if(e=String(e),!VO.has(n,e)){var r=this._arr,o=r.length;return n[e]=o,r.push({key:e,priority:t}),this._decrease(o),!0}return!1};At.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key};At.prototype.decrease=function(e,t){var n=this._keyIndices[e];if(t>this._arr[n].priority)throw new Error("New priority is greater than current priority. Key: "+e+" Old: "+this._arr[n].priority+" New: "+t);this._arr[n].priority=t,this._decrease(n)};At.prototype._heapify=function(e){var t=this._arr,n=2*e,r=n+1,o=e;n<t.length&&(o=t[n].priority<t[o].priority?n:o,r<t.length&&(o=t[r].priority<t[o].priority?r:o),o!==e&&(this._swap(e,o),this._heapify(o)))};At.prototype._decrease=function(e){for(var t=this._arr,n=t[e].priority,r;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r};At.prototype._swap=function(e,t){var n=this._arr,r=this._keyIndices,o=n[e],s=n[t];n[e]=s,n[t]=o,r[s.key]=e,r[o.key]=t}});var Rg=A((cUe,YO)=>{var ane=at(),dne=_g();YO.exports=une;var cne=ane.constant(1);function une(e,t,n,r){return pne(e,String(t),n||cne,r||function(o){return e.outEdges(o)})}function pne(e,t,n,r){var o={},s=new dne,i,a,d=function(c){var u=c.v!==i?c.v:c.w,p=o[u],l=n(c),f=a.distance+l;if(l<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+c+" Weight: "+l);f<p.distance&&(p.distance=f,p.predecessor=i,s.decrease(u,f))};for(e.nodes().forEach(function(c){var u=c===t?0:Number.POSITIVE_INFINITY;o[c]={distance:u},s.add(c,u)});s.size()>0&&(i=s.removeMin(),a=o[i],a.distance!==Number.POSITIVE_INFINITY);)r(i).forEach(d);return o}});var XO=A((uUe,KO)=>{var lne=Rg(),fne=at();KO.exports=mne;function mne(e,t,n){return fne.transform(e.nodes(),function(r,o){r[o]=lne(e,o,t,n)},{})}});var Eg=A((pUe,WO)=>{var $O=at();WO.exports=hne;function hne(e){var t=0,n=[],r={},o=[];function s(i){var a=r[i]={onStack:!0,lowlink:t,index:t++};if(n.push(i),e.successors(i).forEach(function(u){$O.has(r,u)?r[u].onStack&&(a.lowlink=Math.min(a.lowlink,r[u].index)):(s(u),a.lowlink=Math.min(a.lowlink,r[u].lowlink))}),a.lowlink===a.index){var d=[],c;do c=n.pop(),r[c].onStack=!1,d.push(c);while(i!==c);o.push(d)}}return e.nodes().forEach(function(i){$O.has(r,i)||s(i)}),o}});var JO=A((lUe,QO)=>{var gne=at(),yne=Eg();QO.exports=Ane;function Ane(e){return gne.filter(yne(e),function(t){return t.length>1||t.length===1&&e.hasEdge(t[0],t[0])})}});var eD=A((fUe,ZO)=>{var vne=at();ZO.exports=bne;var Sne=vne.constant(1);function bne(e,t,n){return Ine(e,t||Sne,n||function(r){return e.outEdges(r)})}function Ine(e,t,n){var r={},o=e.nodes();return o.forEach(function(s){r[s]={},r[s][s]={distance:0},o.forEach(function(i){s!==i&&(r[s][i]={distance:Number.POSITIVE_INFINITY})}),n(s).forEach(function(i){var a=i.v===s?i.w:i.v,d=t(i);r[s][a]={distance:d,predecessor:s}})}),o.forEach(function(s){var i=r[s];o.forEach(function(a){var d=r[a];o.forEach(function(c){var u=d[s],p=i[c],l=d[c],f=u.distance+p.distance;f<l.distance&&(l.distance=f,l.predecessor=p.predecessor)})})}),r}});var Cg=A((mUe,nD)=>{var Ba=at();nD.exports=tD;tD.CycleException=Yu;function tD(e){var t={},n={},r=[];function o(s){if(Ba.has(n,s))throw new Yu;Ba.has(t,s)||(n[s]=!0,t[s]=!0,Ba.each(e.predecessors(s),o),delete n[s],r.push(s))}if(Ba.each(e.sinks(),o),Ba.size(t)!==e.nodeCount())throw new Yu;return r}function Yu(){}Yu.prototype=new Error});var sD=A((hUe,oD)=>{var rD=Cg();oD.exports=_ne;function _ne(e){try{rD(e)}catch(t){if(t instanceof rD.CycleException)return!1;throw t}return!0}});var Pg=A((gUe,aD)=>{var Ku=at();aD.exports=Rne;function Rne(e,t,n){Ku.isArray(t)||(t=[t]);var r=(e.isDirected()?e.successors:e.neighbors).bind(e),o=[],s={};return Ku.each(t,function(i){if(!e.hasNode(i))throw new Error("Graph does not have node: "+i);iD(e,i,n==="post",s,r,o)}),o}function iD(e,t,n,r,o,s){Ku.has(r,t)||(r[t]=!0,n||s.push(t),Ku.each(o(t),function(i){iD(e,i,n,r,o,s)}),n&&s.push(t))}});var cD=A((yUe,dD)=>{var Ene=Pg();dD.exports=Cne;function Cne(e,t){return Ene(e,t,"post")}});var pD=A((AUe,uD)=>{var Pne=Pg();uD.exports=xne;function xne(e,t){return Pne(e,t,"pre")}});var mD=A((vUe,fD)=>{var lD=at(),Tne=Vu(),Nne=_g();fD.exports=wne;function wne(e,t){var n=new Tne,r={},o=new Nne,s;function i(d){var c=d.v===s?d.w:d.v,u=o.priority(c);if(u!==void 0){var p=t(d);p<u&&(r[c]=s,o.decrease(c,p))}}if(e.nodeCount()===0)return n;lD.each(e.nodes(),function(d){o.add(d,Number.POSITIVE_INFINITY),n.setNode(d)}),o.decrease(e.nodes()[0],0);for(var a=!1;o.size()>0;){if(s=o.removeMin(),lD.has(r,s))n.setEdge(s,r[s]);else{if(a)throw new Error("Input graph is not connected: "+e);a=!0}e.nodeEdges(s).forEach(i)}return n}});var gD=A((SUe,hD)=>{hD.exports={components:jO(),dijkstra:Rg(),dijkstraAll:XO(),findCycles:JO(),floydWarshall:eD(),isAcyclic:sD(),postorder:cD(),preorder:pD(),prim:mD(),tarjan:Eg(),topsort:Cg()}});var vD=A((bUe,AD)=>{var yD=UO();AD.exports={Graph:yD.Graph,json:qO(),alg:gD(),version:yD.version}});var vt=A((IUe,SD)=>{var Xu;if(typeof require=="function")try{Xu=vD()}catch{}Xu||(Xu=window.graphlib);SD.exports=Xu});var ID=A((_Ue,bD)=>{var One=Hh(),Dne=1,kne=4;function Mne(e){return One(e,Dne|kne)}bD.exports=Mne});var Ga=A((RUe,_D)=>{var Lne=eo(),Bne=tn(),Gne=Ra(),Une=it();function zne(e,t,n){if(!Une(n))return!1;var r=typeof t;return(r=="number"?Bne(n)&&Gne(t,n.length):r=="string"&&t in n)?Lne(n[t],e):!1}_D.exports=zne});var CD=A((EUe,ED)=>{var qne=Ma(),Fne=eo(),jne=Ga(),Vne=sr(),RD=Object.prototype,Hne=RD.hasOwnProperty,Yne=qne(function(e,t){e=Object(e);var n=-1,r=t.length,o=r>2?t[2]:void 0;for(o&&jne(t[0],t[1],o)&&(r=1);++n<r;)for(var s=t[n],i=Vne(s),a=-1,d=i.length;++a<d;){var c=i[a],u=e[c];(u===void 0||Fne(u,RD[c])&&!Hne.call(e,c))&&(e[c]=s[c])}return e});ED.exports=Yne});var xD=A((CUe,PD)=>{var Kne=nn(),Xne=tn(),$ne=Tn();function Wne(e){return function(t,n,r){var o=Object(t);if(!Xne(t)){var s=Kne(n,3);t=$ne(t),n=function(a){return s(o[a],a,o)}}var i=e(t,n,r);return i>-1?o[s?t[i]:i]:void 0}}PD.exports=Wne});var ND=A((PUe,TD)=>{var Qne=/\s/;function Jne(e){for(var t=e.length;t--&&Qne.test(e.charAt(t)););return t}TD.exports=Jne});var OD=A((xUe,wD)=>{var Zne=ND(),ere=/^\s+/;function tre(e){return e&&e.slice(0,Zne(e)+1).replace(ere,"")}wD.exports=tre});var LD=A((TUe,MD)=>{var nre=OD(),DD=it(),rre=so(),kD=0/0,ore=/^[-+]0x[0-9a-f]+$/i,sre=/^0b[01]+$/i,ire=/^0o[0-7]+$/i,are=parseInt;function dre(e){if(typeof e=="number")return e;if(rre(e))return kD;if(DD(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=DD(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=nre(e);var n=sre.test(e);return n||ire.test(e)?are(e.slice(2),n?2:8):ore.test(e)?kD:+e}MD.exports=dre});var xg=A((NUe,GD)=>{var cre=LD(),BD=1/0,ure=17976931348623157e292;function pre(e){if(!e)return e===0?e:0;if(e=cre(e),e===BD||e===-BD){var t=e<0?-1:1;return t*ure}return e===e?e:0}GD.exports=pre});var zD=A((wUe,UD)=>{var lre=xg();function fre(e){var t=lre(e),n=t%1;return t===t?n?t-n:t:0}UD.exports=fre});var FD=A((OUe,qD)=>{var mre=Ag(),hre=nn(),gre=zD(),yre=Math.max;function Are(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var o=n==null?0:gre(n);return o<0&&(o=yre(r+o,0)),mre(e,hre(t,3),o)}qD.exports=Are});var VD=A((DUe,jD)=>{var vre=xD(),Sre=FD(),bre=vre(Sre);jD.exports=bre});var Tg=A((kUe,HD)=>{var Ire=Fu();function _re(e){var t=e==null?0:e.length;return t?Ire(e,1):[]}HD.exports=_re});var KD=A((MUe,YD)=>{var Rre=Lu(),Ere=Yh(),Cre=sr();function Pre(e,t){return e==null?e:Rre(e,Ere(t),Cre)}YD.exports=Pre});var $D=A((LUe,XD)=>{function xre(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}XD.exports=xre});var QD=A((BUe,WD)=>{var Tre=ba(),Nre=Bu(),wre=nn();function Ore(e,t){var n={};return t=wre(t,3),Nre(e,function(r,o,s){Tre(n,o,t(r,o,s))}),n}WD.exports=Ore});var $u=A((GUe,JD)=>{var Dre=so();function kre(e,t,n){for(var r=-1,o=e.length;++r<o;){var s=e[r],i=t(s);if(i!=null&&(a===void 0?i===i&&!Dre(i):n(i,a)))var a=i,d=s}return d}JD.exports=kre});var ek=A((UUe,ZD)=>{function Mre(e,t){return e>t}ZD.exports=Mre});var nk=A((zUe,tk)=>{var Lre=$u(),Bre=ek(),Gre=ir();function Ure(e){return e&&e.length?Lre(e,Gre,Bre):void 0}tk.exports=Ure});var Ng=A((qUe,rk)=>{var zre=ba(),qre=eo();function Fre(e,t,n){(n!==void 0&&!qre(e[t],n)||n===void 0&&!(t in e))&&zre(e,t,n)}rk.exports=Fre});var ik=A((FUe,sk)=>{var jre=rr(),Vre=Na(),Hre=Ot(),Yre="[object Object]",Kre=Function.prototype,Xre=Object.prototype,ok=Kre.toString,$re=Xre.hasOwnProperty,Wre=ok.call(Object);function Qre(e){if(!Hre(e)||jre(e)!=Yre)return!1;var t=Vre(e);if(t===null)return!0;var n=$re.call(t,"constructor")&&t.constructor;return typeof n=="function"&&n instanceof n&&ok.call(n)==Wre}sk.exports=Qre});var wg=A((jUe,ak)=>{function Jre(e,t){if(!(t==="constructor"&&typeof e[t]=="function")&&t!="__proto__")return e[t]}ak.exports=Jre});var ck=A((VUe,dk)=>{var Zre=As(),eoe=sr();function toe(e){return Zre(e,eoe(e))}dk.exports=toe});var hk=A((HUe,mk)=>{var uk=Ng(),noe=xh(),roe=Fh(),ooe=Th(),soe=Vh(),pk=vs(),lk=ve(),ioe=Sg(),aoe=no(),doe=ms(),coe=it(),uoe=ik(),poe=Is(),fk=wg(),loe=ck();function foe(e,t,n,r,o,s,i){var a=fk(e,n),d=fk(t,n),c=i.get(d);if(c){uk(e,n,c);return}var u=s?s(a,d,n+"",e,t,i):void 0,p=u===void 0;if(p){var l=lk(d),f=!l&&aoe(d),h=!l&&!f&&poe(d);u=d,l||f||h?lk(a)?u=a:ioe(a)?u=ooe(a):f?(p=!1,u=noe(d,!0)):h?(p=!1,u=roe(d,!0)):u=[]:uoe(d)||pk(d)?(u=a,pk(a)?u=loe(a):(!coe(a)||doe(a))&&(u=soe(d))):p=!1}p&&(i.set(d,u),o(u,d,r,s,i),i.delete(d)),uk(e,n,u)}mk.exports=foe});var Ak=A((YUe,yk)=>{var moe=Sa(),hoe=Ng(),goe=Lu(),yoe=hk(),Aoe=it(),voe=sr(),Soe=wg();function gk(e,t,n,r,o){e!==t&&goe(t,function(s,i){if(o||(o=new moe),Aoe(s))yoe(e,t,i,n,gk,r,o);else{var a=r?r(Soe(e,i),s,i+"",e,t,o):void 0;a===void 0&&(a=s),hoe(e,i,a)}},voe)}yk.exports=gk});var Sk=A((KUe,vk)=>{var boe=Ma(),Ioe=Ga();function _oe(e){return boe(function(t,n){var r=-1,o=n.length,s=o>1?n[o-1]:void 0,i=o>2?n[2]:void 0;for(s=e.length>3&&typeof s=="function"?(o--,s):void 0,i&&Ioe(n[0],n[1],i)&&(s=o<3?void 0:s,o=1),t=Object(t);++r<o;){var a=n[r];a&&e(t,a,r,s)}return t})}vk.exports=_oe});var Ik=A((XUe,bk)=>{var Roe=Ak(),Eoe=Sk(),Coe=Eoe(function(e,t,n){Roe(e,t,n)});bk.exports=Coe});var Og=A(($Ue,_k)=>{function Poe(e,t){return e<t}_k.exports=Poe});var Ek=A((WUe,Rk)=>{var xoe=$u(),Toe=Og(),Noe=ir();function woe(e){return e&&e.length?xoe(e,Noe,Toe):void 0}Rk.exports=woe});var Pk=A((QUe,Ck)=>{var Ooe=$u(),Doe=nn(),koe=Og();function Moe(e,t){return e&&e.length?Ooe(e,Doe(t,2),koe):void 0}Ck.exports=Moe});var Tk=A((JUe,xk)=>{var Loe=yt(),Boe=function(){return Loe.Date.now()};xk.exports=Boe});var Ok=A((ZUe,wk)=>{var Goe=Ia(),Uoe=Da(),zoe=Ra(),Nk=it(),qoe=Es();function Foe(e,t,n,r){if(!Nk(e))return e;t=Uoe(t,e);for(var o=-1,s=t.length,i=s-1,a=e;a!=null&&++o<s;){var d=qoe(t[o]),c=n;if(d==="__proto__"||d==="constructor"||d==="prototype")return e;if(o!=i){var u=a[d];c=r?r(u,d,a):void 0,c===void 0&&(c=Nk(u)?u:zoe(t[o+1])?[]:{})}Goe(a,d,c),a=a[d]}return e}wk.exports=Foe});var kk=A((eze,Dk)=>{var joe=ka(),Voe=Ok(),Hoe=Da();function Yoe(e,t,n){for(var r=-1,o=t.length,s={};++r<o;){var i=t[r],a=joe(e,i);n(a,i)&&Voe(s,Hoe(i,e),a)}return s}Dk.exports=Yoe});var Lk=A((tze,Mk)=>{var Koe=kk(),Xoe=ig();function $oe(e,t){return Koe(e,t,function(n,r){return Xoe(e,r)})}Mk.exports=$oe});var Gk=A((nze,Bk)=>{var Woe=Tg(),Qoe=gg(),Joe=yg();function Zoe(e){return Joe(Qoe(e,void 0,Woe),e+"")}Bk.exports=Zoe});var zk=A((rze,Uk)=>{var ese=Lk(),tse=Gk(),nse=tse(function(e,t){return e==null?{}:ese(e,t)});Uk.exports=nse});var Fk=A((oze,qk)=>{var rse=Math.ceil,ose=Math.max;function sse(e,t,n,r){for(var o=-1,s=ose(rse((t-e)/(n||1)),0),i=Array(s);s--;)i[r?s:++o]=e,e+=n;return i}qk.exports=sse});var Vk=A((sze,jk)=>{var ise=Fk(),ase=Ga(),Dg=xg();function dse(e){return function(t,n,r){return r&&typeof r!="number"&&ase(t,n,r)&&(n=r=void 0),t=Dg(t),n===void 0?(n=t,t=0):n=Dg(n),r=r===void 0?t<n?1:-1:Dg(r),ise(t,n,r,e)}}jk.exports=dse});var Yk=A((ize,Hk)=>{var cse=Vk(),use=cse();Hk.exports=use});var Xk=A((aze,Kk)=>{function pse(e,t){var n=e.length;for(e.sort(t);n--;)e[n]=e[n].value;return e}Kk.exports=pse});var Qk=A((dze,Wk)=>{var $k=so();function lse(e,t){if(e!==t){var n=e!==void 0,r=e===null,o=e===e,s=$k(e),i=t!==void 0,a=t===null,d=t===t,c=$k(t);if(!a&&!c&&!s&&e>t||s&&i&&d&&!a&&!c||r&&i&&d||!n&&d||!o)return 1;if(!r&&!s&&!c&&e<t||c&&n&&o&&!r&&!s||a&&n&&o||!i&&o||!d)return-1}return 0}Wk.exports=lse});var Zk=A((cze,Jk)=>{var fse=Qk();function mse(e,t,n){for(var r=-1,o=e.criteria,s=t.criteria,i=o.length,a=n.length;++r<i;){var d=fse(o[r],s[r]);if(d){if(r>=a)return d;var c=n[r];return d*(c=="desc"?-1:1)}}return e.index-t.index}Jk.exports=mse});var t0=A((uze,e0)=>{var kg=Oa(),hse=ka(),gse=nn(),yse=pg(),Ase=Xk(),vse=Ea(),Sse=Zk(),bse=ir(),Ise=ve();function _se(e,t,n){t.length?t=kg(t,function(s){return Ise(s)?function(i){return hse(i,s.length===1?s[0]:s)}:s}):t=[bse];var r=-1;t=kg(t,vse(gse));var o=yse(e,function(s,i,a){var d=kg(t,function(c){return c(s)});return{criteria:d,index:++r,value:s}});return Ase(o,function(s,i){return Sse(s,i,n)})}e0.exports=_se});var o0=A((pze,r0)=>{var Rse=Fu(),Ese=t0(),Cse=Ma(),n0=Ga(),Pse=Cse(function(e,t){if(e==null)return[];var n=t.length;return n>1&&n0(e,t[0],t[1])?t=[]:n>2&&n0(t[0],t[1],t[2])&&(t=[t[0]]),Ese(e,Rse(t,1),[])});r0.exports=Pse});var i0=A((lze,s0)=>{var xse=og(),Tse=0;function Nse(e){var t=++Tse;return xse(e)+t}s0.exports=Nse});var d0=A((fze,a0)=>{function wse(e,t,n){for(var r=-1,o=e.length,s=t.length,i={};++r<o;){var a=r<s?t[r]:void 0;n(i,e[r],a)}return i}a0.exports=wse});var u0=A((mze,c0)=>{var Ose=Ia(),Dse=d0();function kse(e,t){return Dse(e||[],t||[],Ose)}c0.exports=kse});var le=A((hze,p0)=>{var Wu;if(typeof require=="function")try{Wu={cloneDeep:ID(),constant:Mu(),defaults:CD(),each:Xh(),filter:dg(),find:VD(),flatten:Tg(),forEach:Kh(),forIn:KD(),has:cg(),isUndefined:ug(),last:$D(),map:lg(),mapValues:QD(),max:nk(),merge:Ik(),min:Ek(),minBy:Pk(),now:Tk(),pick:zk(),range:Yk(),reduce:fg(),sortBy:o0(),uniqueId:i0(),values:bg(),zipObject:u0()}}catch{}Wu||(Wu=window._);p0.exports=Wu});var m0=A((gze,f0)=>{f0.exports=Qu;function Qu(){var e={};e._next=e._prev=e,this._sentinel=e}Qu.prototype.dequeue=function(){var e=this._sentinel,t=e._prev;if(t!==e)return l0(t),t};Qu.prototype.enqueue=function(e){var t=this._sentinel;e._prev&&e._next&&l0(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t};Qu.prototype.toString=function(){for(var e=[],t=this._sentinel,n=t._prev;n!==t;)e.push(JSON.stringify(n,Mse)),n=n._prev;return"["+e.join(", ")+"]"};function l0(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Mse(e,t){if(e!=="_next"&&e!=="_prev")return t}});var g0=A((yze,h0)=>{var Nn=le(),Lse=vt().Graph,Bse=m0();h0.exports=Use;var Gse=Nn.constant(1);function Use(e,t){if(e.nodeCount()<=1)return[];var n=qse(e,t||Gse),r=zse(n.graph,n.buckets,n.zeroIdx);return Nn.flatten(Nn.map(r,function(o){return e.outEdges(o.v,o.w)}),!0)}function zse(e,t,n){for(var r=[],o=t[t.length-1],s=t[0],i;e.nodeCount();){for(;i=s.dequeue();)Mg(e,t,n,i);for(;i=o.dequeue();)Mg(e,t,n,i);if(e.nodeCount()){for(var a=t.length-2;a>0;--a)if(i=t[a].dequeue(),i){r=r.concat(Mg(e,t,n,i,!0));break}}}return r}function Mg(e,t,n,r,o){var s=o?[]:void 0;return Nn.forEach(e.inEdges(r.v),function(i){var a=e.edge(i),d=e.node(i.v);o&&s.push({v:i.v,w:i.w}),d.out-=a,Lg(t,n,d)}),Nn.forEach(e.outEdges(r.v),function(i){var a=e.edge(i),d=i.w,c=e.node(d);c.in-=a,Lg(t,n,c)}),e.removeNode(r.v),s}function qse(e,t){var n=new Lse,r=0,o=0;Nn.forEach(e.nodes(),function(a){n.setNode(a,{v:a,in:0,out:0})}),Nn.forEach(e.edges(),function(a){var d=n.edge(a.v,a.w)||0,c=t(a),u=d+c;n.setEdge(a.v,a.w,u),o=Math.max(o,n.node(a.v).out+=c),r=Math.max(r,n.node(a.w).in+=c)});var s=Nn.range(o+r+3).map(function(){return new Bse}),i=r+1;return Nn.forEach(n.nodes(),function(a){Lg(s,i,n.node(a))}),{graph:n,buckets:s,zeroIdx:i}}function Lg(e,t,n){n.out?n.in?e[n.out-n.in+t].enqueue(n):e[e.length-1].enqueue(n):e[0].enqueue(n)}});var A0=A((Aze,y0)=>{"use strict";var ao=le(),Fse=g0();y0.exports={run:jse,undo:Hse};function jse(e){var t=e.graph().acyclicer==="greedy"?Fse(e,n(e)):Vse(e);ao.forEach(t,function(r){var o=e.edge(r);e.removeEdge(r),o.forwardName=r.name,o.reversed=!0,e.setEdge(r.w,r.v,o,ao.uniqueId("rev"))});function n(r){return function(o){return r.edge(o).weight}}}function Vse(e){var t=[],n={},r={};function o(s){ao.has(r,s)||(r[s]=!0,n[s]=!0,ao.forEach(e.outEdges(s),function(i){ao.has(n,i.w)?t.push(i):o(i.w)}),delete n[s])}return ao.forEach(e.nodes(),o),t}function Hse(e){ao.forEach(e.edges(),function(t){var n=e.edge(t);if(n.reversed){e.removeEdge(t);var r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}});var Ve=A((vze,I0)=>{"use strict";var Z=le(),v0=vt().Graph;I0.exports={addDummyNode:S0,simplify:Yse,asNonCompoundGraph:Kse,successorWeights:Xse,predecessorWeights:$se,intersectRect:Wse,buildLayerMatrix:Qse,normalizeRanks:Jse,removeEmptyRanks:Zse,addBorderNode:eie,maxRank:b0,partition:tie,time:nie,notime:rie};function S0(e,t,n,r){var o;do o=Z.uniqueId(r);while(e.hasNode(o));return n.dummy=t,e.setNode(o,n),o}function Yse(e){var t=new v0().setGraph(e.graph());return Z.forEach(e.nodes(),function(n){t.setNode(n,e.node(n))}),Z.forEach(e.edges(),function(n){var r=t.edge(n.v,n.w)||{weight:0,minlen:1},o=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+o.weight,minlen:Math.max(r.minlen,o.minlen)})}),t}function Kse(e){var t=new v0({multigraph:e.isMultigraph()}).setGraph(e.graph());return Z.forEach(e.nodes(),function(n){e.children(n).length||t.setNode(n,e.node(n))}),Z.forEach(e.edges(),function(n){t.setEdge(n,e.edge(n))}),t}function Xse(e){var t=Z.map(e.nodes(),function(n){var r={};return Z.forEach(e.outEdges(n),function(o){r[o.w]=(r[o.w]||0)+e.edge(o).weight}),r});return Z.zipObject(e.nodes(),t)}function $se(e){var t=Z.map(e.nodes(),function(n){var r={};return Z.forEach(e.inEdges(n),function(o){r[o.v]=(r[o.v]||0)+e.edge(o).weight}),r});return Z.zipObject(e.nodes(),t)}function Wse(e,t){var n=e.x,r=e.y,o=t.x-n,s=t.y-r,i=e.width/2,a=e.height/2;if(!o&&!s)throw new Error("Not possible to find intersection inside of the rectangle");var d,c;return Math.abs(s)*i>Math.abs(o)*a?(s<0&&(a=-a),d=a*o/s,c=a):(o<0&&(i=-i),d=i,c=i*s/o),{x:n+d,y:r+c}}function Qse(e){var t=Z.map(Z.range(b0(e)+1),function(){return[]});return Z.forEach(e.nodes(),function(n){var r=e.node(n),o=r.rank;Z.isUndefined(o)||(t[o][r.order]=n)}),t}function Jse(e){var t=Z.min(Z.map(e.nodes(),function(n){return e.node(n).rank}));Z.forEach(e.nodes(),function(n){var r=e.node(n);Z.has(r,"rank")&&(r.rank-=t)})}function Zse(e){var t=Z.min(Z.map(e.nodes(),function(s){return e.node(s).rank})),n=[];Z.forEach(e.nodes(),function(s){var i=e.node(s).rank-t;n[i]||(n[i]=[]),n[i].push(s)});var r=0,o=e.graph().nodeRankFactor;Z.forEach(n,function(s,i){Z.isUndefined(s)&&i%o!==0?--r:r&&Z.forEach(s,function(a){e.node(a).rank+=r})})}function eie(e,t,n,r){var o={width:0,height:0};return arguments.length>=4&&(o.rank=n,o.order=r),S0(e,"border",o,t)}function b0(e){return Z.max(Z.map(e.nodes(),function(t){var n=e.node(t).rank;if(!Z.isUndefined(n))return n}))}function tie(e,t){var n={lhs:[],rhs:[]};return Z.forEach(e,function(r){t(r)?n.lhs.push(r):n.rhs.push(r)}),n}function nie(e,t){var n=Z.now();try{return t()}finally{console.log(e+" time: "+(Z.now()-n)+"ms")}}function rie(e,t){return t()}});var E0=A((Sze,R0)=>{"use strict";var _0=le(),oie=Ve();R0.exports={run:sie,undo:aie};function sie(e){e.graph().dummyChains=[],_0.forEach(e.edges(),function(t){iie(e,t)})}function iie(e,t){var n=t.v,r=e.node(n).rank,o=t.w,s=e.node(o).rank,i=t.name,a=e.edge(t),d=a.labelRank;if(s!==r+1){e.removeEdge(t);var c,u,p;for(p=0,++r;r<s;++p,++r)a.points=[],u={width:0,height:0,edgeLabel:a,edgeObj:t,rank:r},c=oie.addDummyNode(e,"edge",u,"_d"),r===d&&(u.width=a.width,u.height=a.height,u.dummy="edge-label",u.labelpos=a.labelpos),e.setEdge(n,c,{weight:a.weight},i),p===0&&e.graph().dummyChains.push(c),n=c;e.setEdge(n,o,{weight:a.weight},i)}}function aie(e){_0.forEach(e.graph().dummyChains,function(t){var n=e.node(t),r=n.edgeLabel,o;for(e.setEdge(n.edgeObj,r);n.dummy;)o=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy==="edge-label"&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=o,n=e.node(t)})}});var Ua=A((bze,C0)=>{"use strict";var Ju=le();C0.exports={longestPath:die,slack:cie};function die(e){var t={};function n(r){var o=e.node(r);if(Ju.has(t,r))return o.rank;t[r]=!0;var s=Ju.min(Ju.map(e.outEdges(r),function(i){return n(i.w)-e.edge(i).minlen}));return(s===Number.POSITIVE_INFINITY||s===void 0||s===null)&&(s=0),o.rank=s}Ju.forEach(e.sources(),n)}function cie(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}});var Bg=A((Ize,P0)=>{"use strict";var Zu=le(),uie=vt().Graph,ep=Ua().slack;P0.exports=pie;function pie(e){var t=new uie({directed:!1}),n=e.nodes()[0],r=e.nodeCount();t.setNode(n,{});for(var o,s;lie(t,e)<r;)o=fie(t,e),s=t.hasNode(o.v)?ep(e,o):-ep(e,o),mie(t,e,s);return t}function lie(e,t){function n(r){Zu.forEach(t.nodeEdges(r),function(o){var s=o.v,i=r===s?o.w:s;!e.hasNode(i)&&!ep(t,o)&&(e.setNode(i,{}),e.setEdge(r,i,{}),n(i))})}return Zu.forEach(e.nodes(),n),e.nodeCount()}function fie(e,t){return Zu.minBy(t.edges(),function(n){if(e.hasNode(n.v)!==e.hasNode(n.w))return ep(t,n)})}function mie(e,t,n){Zu.forEach(e.nodes(),function(r){t.node(r).rank+=n})}});var M0=A((_ze,k0)=>{"use strict";var wn=le(),hie=Bg(),gie=Ua().slack,yie=Ua().longestPath,Aie=vt().alg.preorder,vie=vt().alg.postorder,Sie=Ve().simplify;k0.exports=co;co.initLowLimValues=Ug;co.initCutValues=Gg;co.calcCutValue=T0;co.leaveEdge=w0;co.enterEdge=O0;co.exchangeEdges=D0;function co(e){e=Sie(e),yie(e);var t=hie(e);Ug(t),Gg(t,e);for(var n,r;n=w0(t);)r=O0(t,e,n),D0(t,e,n,r)}function Gg(e,t){var n=vie(e,e.nodes());n=n.slice(0,n.length-1),wn.forEach(n,function(r){bie(e,t,r)})}function bie(e,t,n){var r=e.node(n),o=r.parent;e.edge(n,o).cutvalue=T0(e,t,n)}function T0(e,t,n){var r=e.node(n),o=r.parent,s=!0,i=t.edge(n,o),a=0;return i||(s=!1,i=t.edge(o,n)),a=i.weight,wn.forEach(t.nodeEdges(n),function(d){var c=d.v===n,u=c?d.w:d.v;if(u!==o){var p=c===s,l=t.edge(d).weight;if(a+=p?l:-l,_ie(e,n,u)){var f=e.edge(n,u).cutvalue;a+=p?-f:f}}}),a}function Ug(e,t){arguments.length<2&&(t=e.nodes()[0]),N0(e,{},1,t)}function N0(e,t,n,r,o){var s=n,i=e.node(r);return t[r]=!0,wn.forEach(e.neighbors(r),function(a){wn.has(t,a)||(n=N0(e,t,n,a,r))}),i.low=s,i.lim=n++,o?i.parent=o:delete i.parent,n}function w0(e){return wn.find(e.edges(),function(t){return e.edge(t).cutvalue<0})}function O0(e,t,n){var r=n.v,o=n.w;t.hasEdge(r,o)||(r=n.w,o=n.v);var s=e.node(r),i=e.node(o),a=s,d=!1;s.lim>i.lim&&(a=i,d=!0);var c=wn.filter(t.edges(),function(u){return d===x0(e,e.node(u.v),a)&&d!==x0(e,e.node(u.w),a)});return wn.minBy(c,function(u){return gie(t,u)})}function D0(e,t,n,r){var o=n.v,s=n.w;e.removeEdge(o,s),e.setEdge(r.v,r.w,{}),Ug(e),Gg(e,t),Iie(e,t)}function Iie(e,t){var n=wn.find(e.nodes(),function(o){return!t.node(o).parent}),r=Aie(e,n);r=r.slice(1),wn.forEach(r,function(o){var s=e.node(o).parent,i=t.edge(o,s),a=!1;i||(i=t.edge(s,o),a=!0),t.node(o).rank=t.node(s).rank+(a?i.minlen:-i.minlen)})}function _ie(e,t,n){return e.hasEdge(t,n)}function x0(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}});var U0=A((Rze,G0)=>{"use strict";var Rie=Ua(),B0=Rie.longestPath,Eie=Bg(),Cie=M0();G0.exports=Pie;function Pie(e){switch(e.graph().ranker){case"network-simplex":L0(e);break;case"tight-tree":Tie(e);break;case"longest-path":xie(e);break;default:L0(e)}}var xie=B0;function Tie(e){B0(e),Eie(e)}function L0(e){Cie(e)}});var q0=A((Eze,z0)=>{var zg=le();z0.exports=Nie;function Nie(e){var t=Oie(e);zg.forEach(e.graph().dummyChains,function(n){for(var r=e.node(n),o=r.edgeObj,s=wie(e,t,o.v,o.w),i=s.path,a=s.lca,d=0,c=i[d],u=!0;n!==o.w;){if(r=e.node(n),u){for(;(c=i[d])!==a&&e.node(c).maxRank<r.rank;)d++;c===a&&(u=!1)}if(!u){for(;d<i.length-1&&e.node(c=i[d+1]).minRank<=r.rank;)d++;c=i[d]}e.setParent(n,c),n=e.successors(n)[0]}})}function wie(e,t,n,r){var o=[],s=[],i=Math.min(t[n].low,t[r].low),a=Math.max(t[n].lim,t[r].lim),d,c;d=n;do d=e.parent(d),o.push(d);while(d&&(t[d].low>i||a>t[d].lim));for(c=d,d=r;(d=e.parent(d))!==c;)s.push(d);return{path:o.concat(s.reverse()),lca:c}}function Oie(e){var t={},n=0;function r(o){var s=n;zg.forEach(e.children(o),r),t[o]={low:s,lim:n++}}return zg.forEach(e.children(),r),t}});var V0=A((Cze,j0)=>{var On=le(),qg=Ve();j0.exports={run:Die,cleanup:Lie};function Die(e){var t=qg.addDummyNode(e,"root",{},"_root"),n=kie(e),r=On.max(On.values(n))-1,o=2*r+1;e.graph().nestingRoot=t,On.forEach(e.edges(),function(i){e.edge(i).minlen*=o});var s=Mie(e)+1;On.forEach(e.children(),function(i){F0(e,t,o,s,r,n,i)}),e.graph().nodeRankFactor=o}function F0(e,t,n,r,o,s,i){var a=e.children(i);if(!a.length){i!==t&&e.setEdge(t,i,{weight:0,minlen:n});return}var d=qg.addBorderNode(e,"_bt"),c=qg.addBorderNode(e,"_bb"),u=e.node(i);e.setParent(d,i),u.borderTop=d,e.setParent(c,i),u.borderBottom=c,On.forEach(a,function(p){F0(e,t,n,r,o,s,p);var l=e.node(p),f=l.borderTop?l.borderTop:p,h=l.borderBottom?l.borderBottom:p,m=l.borderTop?r:2*r,g=f!==h?1:o-s[i]+1;e.setEdge(d,f,{weight:m,minlen:g,nestingEdge:!0}),e.setEdge(h,c,{weight:m,minlen:g,nestingEdge:!0})}),e.parent(i)||e.setEdge(t,d,{weight:0,minlen:o+s[i]})}function kie(e){var t={};function n(r,o){var s=e.children(r);s&&s.length&&On.forEach(s,function(i){n(i,o+1)}),t[r]=o}return On.forEach(e.children(),function(r){n(r,1)}),t}function Mie(e){return On.reduce(e.edges(),function(t,n){return t+e.edge(n).weight},0)}function Lie(e){var t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,On.forEach(e.edges(),function(n){var r=e.edge(n);r.nestingEdge&&e.removeEdge(n)})}});var K0=A((Pze,Y0)=>{var Fg=le(),Bie=Ve();Y0.exports=Gie;function Gie(e){function t(n){var r=e.children(n),o=e.node(n);if(r.length&&Fg.forEach(r,t),Fg.has(o,"minRank")){o.borderLeft=[],o.borderRight=[];for(var s=o.minRank,i=o.maxRank+1;s<i;++s)H0(e,"borderLeft","_bl",n,o,s),H0(e,"borderRight","_br",n,o,s)}}Fg.forEach(e.children(),t)}function H0(e,t,n,r,o,s){var i={width:0,height:0,rank:s,borderType:t},a=o[t][s-1],d=Bie.addDummyNode(e,"border",i,n);o[t][s]=d,e.setParent(d,r),a&&e.setEdge(a,d,{weight:1})}});var Q0=A((xze,W0)=>{"use strict";var on=le();W0.exports={adjust:Uie,undo:zie};function Uie(e){var t=e.graph().rankdir.toLowerCase();(t==="lr"||t==="rl")&&$0(e)}function zie(e){var t=e.graph().rankdir.toLowerCase();(t==="bt"||t==="rl")&&qie(e),(t==="lr"||t==="rl")&&(Fie(e),$0(e))}function $0(e){on.forEach(e.nodes(),function(t){X0(e.node(t))}),on.forEach(e.edges(),function(t){X0(e.edge(t))})}function X0(e){var t=e.width;e.width=e.height,e.height=t}function qie(e){on.forEach(e.nodes(),function(t){jg(e.node(t))}),on.forEach(e.edges(),function(t){var n=e.edge(t);on.forEach(n.points,jg),on.has(n,"y")&&jg(n)})}function jg(e){e.y=-e.y}function Fie(e){on.forEach(e.nodes(),function(t){Vg(e.node(t))}),on.forEach(e.edges(),function(t){var n=e.edge(t);on.forEach(n.points,Vg),on.has(n,"x")&&Vg(n)})}function Vg(e){var t=e.x;e.x=e.y,e.y=t}});var Z0=A((Tze,J0)=>{"use strict";var Dn=le();J0.exports=jie;function jie(e){var t={},n=Dn.filter(e.nodes(),function(a){return!e.children(a).length}),r=Dn.max(Dn.map(n,function(a){return e.node(a).rank})),o=Dn.map(Dn.range(r+1),function(){return[]});function s(a){if(!Dn.has(t,a)){t[a]=!0;var d=e.node(a);o[d.rank].push(a),Dn.forEach(e.successors(a),s)}}var i=Dn.sortBy(n,function(a){return e.node(a).rank});return Dn.forEach(i,s),o}});var tM=A((Nze,eM)=>{"use strict";var ar=le();eM.exports=Vie;function Vie(e,t){for(var n=0,r=1;r<t.length;++r)n+=Hie(e,t[r-1],t[r]);return n}function Hie(e,t,n){for(var r=ar.zipObject(n,ar.map(n,function(c,u){return u})),o=ar.flatten(ar.map(t,function(c){return ar.sortBy(ar.map(e.outEdges(c),function(u){return{pos:r[u.w],weight:e.edge(u).weight}}),"pos")}),!0),s=1;s<n.length;)s<<=1;var i=2*s-1;s-=1;var a=ar.map(new Array(i),function(){return 0}),d=0;return ar.forEach(o.forEach(function(c){var u=c.pos+s;a[u]+=c.weight;for(var p=0;u>0;)u%2&&(p+=a[u+1]),u=u-1>>1,a[u]+=c.weight;d+=c.weight*p})),d}});var oM=A((wze,rM)=>{var nM=le();rM.exports=Yie;function Yie(e,t){return nM.map(t,function(n){var r=e.inEdges(n);if(r.length){var o=nM.reduce(r,function(s,i){var a=e.edge(i),d=e.node(i.v);return{sum:s.sum+a.weight*d.order,weight:s.weight+a.weight}},{sum:0,weight:0});return{v:n,barycenter:o.sum/o.weight,weight:o.weight}}else return{v:n}})}});var iM=A((Oze,sM)=>{"use strict";var dt=le();sM.exports=Kie;function Kie(e,t){var n={};dt.forEach(e,function(o,s){var i=n[o.v]={indegree:0,in:[],out:[],vs:[o.v],i:s};dt.isUndefined(o.barycenter)||(i.barycenter=o.barycenter,i.weight=o.weight)}),dt.forEach(t.edges(),function(o){var s=n[o.v],i=n[o.w];!dt.isUndefined(s)&&!dt.isUndefined(i)&&(i.indegree++,s.out.push(n[o.w]))});var r=dt.filter(n,function(o){return!o.indegree});return Xie(r)}function Xie(e){var t=[];function n(s){return function(i){i.merged||(dt.isUndefined(i.barycenter)||dt.isUndefined(s.barycenter)||i.barycenter>=s.barycenter)&&$ie(s,i)}}function r(s){return function(i){i.in.push(s),--i.indegree===0&&e.push(i)}}for(;e.length;){var o=e.pop();t.push(o),dt.forEach(o.in.reverse(),n(o)),dt.forEach(o.out,r(o))}return dt.map(dt.filter(t,function(s){return!s.merged}),function(s){return dt.pick(s,["vs","i","barycenter","weight"])})}function $ie(e,t){var n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}});var cM=A((Dze,dM)=>{var za=le(),Wie=Ve();dM.exports=Qie;function Qie(e,t){var n=Wie.partition(e,function(u){return za.has(u,"barycenter")}),r=n.lhs,o=za.sortBy(n.rhs,function(u){return-u.i}),s=[],i=0,a=0,d=0;r.sort(Jie(!!t)),d=aM(s,o,d),za.forEach(r,function(u){d+=u.vs.length,s.push(u.vs),i+=u.barycenter*u.weight,a+=u.weight,d=aM(s,o,d)});var c={vs:za.flatten(s,!0)};return a&&(c.barycenter=i/a,c.weight=a),c}function aM(e,t,n){for(var r;t.length&&(r=za.last(t)).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Jie(e){return function(t,n){return t.barycenter<n.barycenter?-1:t.barycenter>n.barycenter?1:e?n.i-t.i:t.i-n.i}}});var lM=A((kze,pM)=>{var dr=le(),Zie=oM(),eae=iM(),tae=cM();pM.exports=uM;function uM(e,t,n,r){var o=e.children(t),s=e.node(t),i=s?s.borderLeft:void 0,a=s?s.borderRight:void 0,d={};i&&(o=dr.filter(o,function(h){return h!==i&&h!==a}));var c=Zie(e,o);dr.forEach(c,function(h){if(e.children(h.v).length){var m=uM(e,h.v,n,r);d[h.v]=m,dr.has(m,"barycenter")&&rae(h,m)}});var u=eae(c,n);nae(u,d);var p=tae(u,r);if(i&&(p.vs=dr.flatten([i,p.vs,a],!0),e.predecessors(i).length)){var l=e.node(e.predecessors(i)[0]),f=e.node(e.predecessors(a)[0]);dr.has(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+l.order+f.order)/(p.weight+2),p.weight+=2}return p}function nae(e,t){dr.forEach(e,function(n){n.vs=dr.flatten(n.vs.map(function(r){return t[r]?t[r].vs:r}),!0)})}function rae(e,t){dr.isUndefined(e.barycenter)?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}});var mM=A((Mze,fM)=>{var qa=le(),oae=vt().Graph;fM.exports=sae;function sae(e,t,n){var r=iae(e),o=new oae({compound:!0}).setGraph({root:r}).setDefaultNodeLabel(function(s){return e.node(s)});return qa.forEach(e.nodes(),function(s){var i=e.node(s),a=e.parent(s);(i.rank===t||i.minRank<=t&&t<=i.maxRank)&&(o.setNode(s),o.setParent(s,a||r),qa.forEach(e[n](s),function(d){var c=d.v===s?d.w:d.v,u=o.edge(c,s),p=qa.isUndefined(u)?0:u.weight;o.setEdge(c,s,{weight:e.edge(d).weight+p})}),qa.has(i,"minRank")&&o.setNode(s,{borderLeft:i.borderLeft[t],borderRight:i.borderRight[t]}))}),o}function iae(e){for(var t;e.hasNode(t=qa.uniqueId("_root")););return t}});var gM=A((Lze,hM)=>{var aae=le();hM.exports=dae;function dae(e,t,n){var r={},o;aae.forEach(n,function(s){for(var i=e.parent(s),a,d;i;){if(a=e.parent(i),a?(d=r[a],r[a]=i):(d=o,o=i),d&&d!==i){t.setEdge(d,i);return}i=a}})}});var bM=A((Bze,SM)=>{"use strict";var cr=le(),cae=Z0(),uae=tM(),pae=lM(),lae=mM(),fae=gM(),mae=vt().Graph,yM=Ve();SM.exports=hae;function hae(e){var t=yM.maxRank(e),n=AM(e,cr.range(1,t+1),"inEdges"),r=AM(e,cr.range(t-1,-1,-1),"outEdges"),o=cae(e);vM(e,o);for(var s=Number.POSITIVE_INFINITY,i,a=0,d=0;d<4;++a,++d){gae(a%2?n:r,a%4>=2),o=yM.buildLayerMatrix(e);var c=uae(e,o);c<s&&(d=0,i=cr.cloneDeep(o),s=c)}vM(e,i)}function AM(e,t,n){return cr.map(t,function(r){return lae(e,r,n)})}function gae(e,t){var n=new mae;cr.forEach(e,function(r){var o=r.graph().root,s=pae(r,o,n,t);cr.forEach(s.vs,function(i,a){r.node(i).order=a}),fae(r,n,s.vs)})}function vM(e,t){cr.forEach(t,function(n){cr.forEach(n,function(r,o){e.node(r).order=o})})}});var wM=A((Gze,NM)=>{"use strict";var k=le(),yae=vt().Graph,Aae=Ve();NM.exports={positionX:bae,findType1Conflicts:IM,findType2Conflicts:_M,addConflict:Hg,hasConflict:RM,verticalAlignment:EM,horizontalCompaction:CM,alignCoordinates:xM,findSmallestWidthAlignment:PM,balance:TM};function IM(e,t){var n={};function r(o,s){var i=0,a=0,d=o.length,c=k.last(s);return k.forEach(s,function(u,p){var l=vae(e,u),f=l?e.node(l).order:d;(l||u===c)&&(k.forEach(s.slice(a,p+1),function(h){k.forEach(e.predecessors(h),function(m){var g=e.node(m),y=g.order;(y<i||f<y)&&!(g.dummy&&e.node(h).dummy)&&Hg(n,m,h)})}),a=p+1,i=f)}),s}return k.reduce(t,r),n}function _M(e,t){var n={};function r(s,i,a,d,c){var u;k.forEach(k.range(i,a),function(p){u=s[p],e.node(u).dummy&&k.forEach(e.predecessors(u),function(l){var f=e.node(l);f.dummy&&(f.order<d||f.order>c)&&Hg(n,l,u)})})}function o(s,i){var a=-1,d,c=0;return k.forEach(i,function(u,p){if(e.node(u).dummy==="border"){var l=e.predecessors(u);l.length&&(d=e.node(l[0]).order,r(i,c,p,a,d),c=p,a=d)}r(i,c,i.length,d,s.length)}),i}return k.reduce(t,o),n}function vae(e,t){if(e.node(t).dummy)return k.find(e.predecessors(t),function(n){return e.node(n).dummy})}function Hg(e,t,n){if(t>n){var r=t;t=n,n=r}var o=e[t];o||(e[t]=o={}),o[n]=!0}function RM(e,t,n){if(t>n){var r=t;t=n,n=r}return k.has(e[t],n)}function EM(e,t,n,r){var o={},s={},i={};return k.forEach(t,function(a){k.forEach(a,function(d,c){o[d]=d,s[d]=d,i[d]=c})}),k.forEach(t,function(a){var d=-1;k.forEach(a,function(c){var u=r(c);if(u.length){u=k.sortBy(u,function(m){return i[m]});for(var p=(u.length-1)/2,l=Math.floor(p),f=Math.ceil(p);l<=f;++l){var h=u[l];s[c]===c&&d<i[h]&&!RM(n,c,h)&&(s[h]=c,s[c]=o[c]=o[h],d=i[h])}}})}),{root:o,align:s}}function CM(e,t,n,r,o){var s={},i=Sae(e,t,n,o),a=o?"borderLeft":"borderRight";function d(p,l){for(var f=i.nodes(),h=f.pop(),m={};h;)m[h]?p(h):(m[h]=!0,f.push(h),f=f.concat(l(h))),h=f.pop()}function c(p){s[p]=i.inEdges(p).reduce(function(l,f){return Math.max(l,s[f.v]+i.edge(f))},0)}function u(p){var l=i.outEdges(p).reduce(function(h,m){return Math.min(h,s[m.w]-i.edge(m))},Number.POSITIVE_INFINITY),f=e.node(p);l!==Number.POSITIVE_INFINITY&&f.borderType!==a&&(s[p]=Math.max(s[p],l))}return d(c,i.predecessors.bind(i)),d(u,i.successors.bind(i)),k.forEach(r,function(p){s[p]=s[n[p]]}),s}function Sae(e,t,n,r){var o=new yae,s=e.graph(),i=Iae(s.nodesep,s.edgesep,r);return k.forEach(t,function(a){var d;k.forEach(a,function(c){var u=n[c];if(o.setNode(u),d){var p=n[d],l=o.edge(p,u);o.setEdge(p,u,Math.max(i(e,c,d),l||0))}d=c})}),o}function PM(e,t){return k.minBy(k.values(t),function(n){var r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;return k.forIn(n,function(s,i){var a=_ae(e,i)/2;r=Math.max(s+a,r),o=Math.min(s-a,o)}),r-o})}function xM(e,t){var n=k.values(t),r=k.min(n),o=k.max(n);k.forEach(["u","d"],function(s){k.forEach(["l","r"],function(i){var a=s+i,d=e[a],c;if(d!==t){var u=k.values(d);c=i==="l"?r-k.min(u):o-k.max(u),c&&(e[a]=k.mapValues(d,function(p){return p+c}))}})})}function TM(e,t){return k.mapValues(e.ul,function(n,r){if(t)return e[t.toLowerCase()][r];var o=k.sortBy(k.map(e,r));return(o[1]+o[2])/2})}function bae(e){var t=Aae.buildLayerMatrix(e),n=k.merge(IM(e,t),_M(e,t)),r={},o;k.forEach(["u","d"],function(i){o=i==="u"?t:k.values(t).reverse(),k.forEach(["l","r"],function(a){a==="r"&&(o=k.map(o,function(p){return k.values(p).reverse()}));var d=(i==="u"?e.predecessors:e.successors).bind(e),c=EM(e,o,n,d),u=CM(e,o,c.root,c.align,a==="r");a==="r"&&(u=k.mapValues(u,function(p){return-p})),r[i+a]=u})});var s=PM(e,r);return xM(r,s),TM(r,e.graph().align)}function Iae(e,t,n){return function(r,o,s){var i=r.node(o),a=r.node(s),d=0,c;if(d+=i.width/2,k.has(i,"labelpos"))switch(i.labelpos.toLowerCase()){case"l":c=-i.width/2;break;case"r":c=i.width/2;break}if(c&&(d+=n?c:-c),c=0,d+=(i.dummy?t:e)/2,d+=(a.dummy?t:e)/2,d+=a.width/2,k.has(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":c=a.width/2;break;case"r":c=-a.width/2;break}return c&&(d+=n?c:-c),c=0,d}}function _ae(e,t){return e.node(t).width}});var kM=A((Uze,DM)=>{"use strict";var Fa=le(),OM=Ve(),Rae=wM().positionX;DM.exports=Eae;function Eae(e){e=OM.asNonCompoundGraph(e),Cae(e),Fa.forEach(Rae(e),function(t,n){e.node(n).x=t})}function Cae(e){var t=OM.buildLayerMatrix(e),n=e.graph().ranksep,r=0;Fa.forEach(t,function(o){var s=Fa.max(Fa.map(o,function(i){return e.node(i).height}));Fa.forEach(o,function(i){e.node(i).y=r+s/2}),r+=s+n})}});var zM=A((zze,UM)=>{"use strict";var B=le(),MM=A0(),LM=E0(),Pae=U0(),xae=Ve().normalizeRanks,Tae=q0(),Nae=Ve().removeEmptyRanks,BM=V0(),wae=K0(),GM=Q0(),Oae=bM(),Dae=kM(),ur=Ve(),kae=vt().Graph;UM.exports=Mae;function Mae(e,t){var n=t&&t.debugTiming?ur.time:ur.notime;n("layout",function(){var r=n(" buildLayoutGraph",function(){return Yae(e)});n(" runLayout",function(){Lae(r,n)}),n(" updateInputGraph",function(){Bae(e,r)})})}function Lae(e,t){t(" makeSpaceForEdgeLabels",function(){Kae(e)}),t(" removeSelfEdges",function(){nde(e)}),t(" acyclic",function(){MM.run(e)}),t(" nestingGraph.run",function(){BM.run(e)}),t(" rank",function(){Pae(ur.asNonCompoundGraph(e))}),t(" injectEdgeLabelProxies",function(){Xae(e)}),t(" removeEmptyRanks",function(){Nae(e)}),t(" nestingGraph.cleanup",function(){BM.cleanup(e)}),t(" normalizeRanks",function(){xae(e)}),t(" assignRankMinMax",function(){$ae(e)}),t(" removeEdgeLabelProxies",function(){Wae(e)}),t(" normalize.run",function(){LM.run(e)}),t(" parentDummyChains",function(){Tae(e)}),t(" addBorderSegments",function(){wae(e)}),t(" order",function(){Oae(e)}),t(" insertSelfEdges",function(){rde(e)}),t(" adjustCoordinateSystem",function(){GM.adjust(e)}),t(" position",function(){Dae(e)}),t(" positionSelfEdges",function(){ode(e)}),t(" removeBorderNodes",function(){tde(e)}),t(" normalize.undo",function(){LM.undo(e)}),t(" fixupEdgeLabelCoords",function(){Zae(e)}),t(" undoCoordinateSystem",function(){GM.undo(e)}),t(" translateGraph",function(){Qae(e)}),t(" assignNodeIntersects",function(){Jae(e)}),t(" reversePoints",function(){ede(e)}),t(" acyclic.undo",function(){MM.undo(e)})}function Bae(e,t){B.forEach(e.nodes(),function(n){var r=e.node(n),o=t.node(n);r&&(r.x=o.x,r.y=o.y,t.children(n).length&&(r.width=o.width,r.height=o.height))}),B.forEach(e.edges(),function(n){var r=e.edge(n),o=t.edge(n);r.points=o.points,B.has(o,"x")&&(r.x=o.x,r.y=o.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var Gae=["nodesep","edgesep","ranksep","marginx","marginy"],Uae={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},zae=["acyclicer","ranker","rankdir","align"],qae=["width","height"],Fae={width:0,height:0},jae=["minlen","weight","width","height","labeloffset"],Vae={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},Hae=["labelpos"];function Yae(e){var t=new kae({multigraph:!0,compound:!0}),n=Kg(e.graph());return t.setGraph(B.merge({},Uae,Yg(n,Gae),B.pick(n,zae))),B.forEach(e.nodes(),function(r){var o=Kg(e.node(r));t.setNode(r,B.defaults(Yg(o,qae),Fae)),t.setParent(r,e.parent(r))}),B.forEach(e.edges(),function(r){var o=Kg(e.edge(r));t.setEdge(r,B.merge({},Vae,Yg(o,jae),B.pick(o,Hae)))}),t}function Kae(e){var t=e.graph();t.ranksep/=2,B.forEach(e.edges(),function(n){var r=e.edge(n);r.minlen*=2,r.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Xae(e){B.forEach(e.edges(),function(t){var n=e.edge(t);if(n.width&&n.height){var r=e.node(t.v),o=e.node(t.w),s={rank:(o.rank-r.rank)/2+r.rank,e:t};ur.addDummyNode(e,"edge-proxy",s,"_ep")}})}function $ae(e){var t=0;B.forEach(e.nodes(),function(n){var r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=B.max(t,r.maxRank))}),e.graph().maxRank=t}function Wae(e){B.forEach(e.nodes(),function(t){var n=e.node(t);n.dummy==="edge-proxy"&&(e.edge(n.e).labelRank=n.rank,e.removeNode(t))})}function Qae(e){var t=Number.POSITIVE_INFINITY,n=0,r=Number.POSITIVE_INFINITY,o=0,s=e.graph(),i=s.marginx||0,a=s.marginy||0;function d(c){var u=c.x,p=c.y,l=c.width,f=c.height;t=Math.min(t,u-l/2),n=Math.max(n,u+l/2),r=Math.min(r,p-f/2),o=Math.max(o,p+f/2)}B.forEach(e.nodes(),function(c){d(e.node(c))}),B.forEach(e.edges(),function(c){var u=e.edge(c);B.has(u,"x")&&d(u)}),t-=i,r-=a,B.forEach(e.nodes(),function(c){var u=e.node(c);u.x-=t,u.y-=r}),B.forEach(e.edges(),function(c){var u=e.edge(c);B.forEach(u.points,function(p){p.x-=t,p.y-=r}),B.has(u,"x")&&(u.x-=t),B.has(u,"y")&&(u.y-=r)}),s.width=n-t+i,s.height=o-r+a}function Jae(e){B.forEach(e.edges(),function(t){var n=e.edge(t),r=e.node(t.v),o=e.node(t.w),s,i;n.points?(s=n.points[0],i=n.points[n.points.length-1]):(n.points=[],s=o,i=r),n.points.unshift(ur.intersectRect(r,s)),n.points.push(ur.intersectRect(o,i))})}function Zae(e){B.forEach(e.edges(),function(t){var n=e.edge(t);if(B.has(n,"x"))switch((n.labelpos==="l"||n.labelpos==="r")&&(n.width-=n.labeloffset),n.labelpos){case"l":n.x-=n.width/2+n.labeloffset;break;case"r":n.x+=n.width/2+n.labeloffset;break}})}function ede(e){B.forEach(e.edges(),function(t){var n=e.edge(t);n.reversed&&n.points.reverse()})}function tde(e){B.forEach(e.nodes(),function(t){if(e.children(t).length){var n=e.node(t),r=e.node(n.borderTop),o=e.node(n.borderBottom),s=e.node(B.last(n.borderLeft)),i=e.node(B.last(n.borderRight));n.width=Math.abs(i.x-s.x),n.height=Math.abs(o.y-r.y),n.x=s.x+n.width/2,n.y=r.y+n.height/2}}),B.forEach(e.nodes(),function(t){e.node(t).dummy==="border"&&e.removeNode(t)})}function nde(e){B.forEach(e.edges(),function(t){if(t.v===t.w){var n=e.node(t.v);n.selfEdges||(n.selfEdges=[]),n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function rde(e){var t=ur.buildLayerMatrix(e);B.forEach(t,function(n){var r=0;B.forEach(n,function(o,s){var i=e.node(o);i.order=s+r,B.forEach(i.selfEdges,function(a){ur.addDummyNode(e,"selfedge",{width:a.label.width,height:a.label.height,rank:i.rank,order:s+ ++r,e:a.e,label:a.label},"_se")}),delete i.selfEdges})})}function ode(e){B.forEach(e.nodes(),function(t){var n=e.node(t);if(n.dummy==="selfedge"){var r=e.node(n.e.v),o=r.x+r.width/2,s=r.y,i=n.x-o,a=r.height/2;e.setEdge(n.e,n.label),e.removeNode(t),n.label.points=[{x:o+2*i/3,y:s-a},{x:o+5*i/6,y:s-a},{x:o+i,y:s},{x:o+5*i/6,y:s+a},{x:o+2*i/3,y:s+a}],n.label.x=n.x,n.label.y=n.y}})}function Yg(e,t){return B.mapValues(B.pick(e,t),Number)}function Kg(e){var t={};return B.forEach(e,function(n,r){t[r.toLowerCase()]=n}),t}});var FM=A((qze,qM)=>{var tp=le(),sde=Ve(),ide=vt().Graph;qM.exports={debugOrdering:ade};function ade(e){var t=sde.buildLayerMatrix(e),n=new ide({compound:!0,multigraph:!0}).setGraph({});return tp.forEach(e.nodes(),function(r){n.setNode(r,{label:r}),n.setParent(r,"layer"+e.node(r).rank)}),tp.forEach(e.edges(),function(r){n.setEdge(r.v,r.w,{},r.name)}),tp.forEach(t,function(r,o){var s="layer"+o;n.setNode(s,{rank:"same"}),tp.reduce(r,function(i,a){return n.setEdge(i,a,{style:"invis"}),a})}),n}});var VM=A((Fze,jM)=>{jM.exports="0.8.5"});var np=A((jze,HM)=>{HM.exports={graphlib:vt(),layout:zM(),debug:FM(),util:{time:Ve().time,notime:Ve().notime},version:VM()}});var Tme={};n1(Tme,{XYQ_CANVAS_OPENCODE_MUTATION_DEFINITIONS:()=>Cy,XYQ_CANVAS_REGISTERED_COMMAND_DEFINITIONS:()=>Py,createPippitAssetRuntime:()=>il,createPippitAssetSdkCanvasLoader:()=>UG,createPippitAssetServiceTransport:()=>yl,createXyqCanvasCommandRuntime:()=>kE,createXyqCanvasOpencodeToolDefinitions:()=>WG});module.exports=r1(Tme);var Dp={error:(...e)=>{var t,n;return(n=(t=globalThis.console)==null?void 0:t.error)==null?void 0:n.call(t,...e)},info:(...e)=>{var t,n;return(n=(t=globalThis.console)==null?void 0:t.info)==null?void 0:n.call(t,...e)},warn:(...e)=>{var t,n;return(n=(t=globalThis.console)==null?void 0:t.warn)==null?void 0:n.call(t,...e)}};function mo(e){return{error:(e==null?void 0:e.error)??Dp.error,info:(e==null?void 0:e.info)??Dp.info,warn:(e==null?void 0:e.warn)??Dp.warn}}function Ny(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=e,n=t.pippitAssetId,r=t.assetId;return typeof n=="string"&&n.trim().length>0||typeof r=="string"&&r.trim().length>0}function wy(e){if(!Ny(e))throw new Error("Pippit asset SDK requires a structured asset ref: { pippitAssetId } or { assetId }.")}function K(e){var r,o;wy(e);let t=(r=e.pippitAssetId)==null?void 0:r.trim(),n=(o=e.assetId)==null?void 0:o.trim();return{...t?{pippitAssetId:t}:{},...n?{assetId:n}:{},...e.mediaType?{mediaType:e.mediaType}:{}}}function xe(e){return{asset_id:e.assetId,media_type:e.mediaType,pippit_asset_id:e.pippitAssetId}}function pt(e){let t=K(e);return[t.pippitAssetId?`pippit:${t.pippitAssetId}`:"",t.assetId?`asset:${t.assetId}`:"",t.mediaType?`type:${t.mediaType}`:""].filter(Boolean).join("|")}function kp(e){return{...e,context:o1(e.context)}}function Je(e){e&&typeof e.catch=="function"&&e.catch(()=>{})}function o1(e){if(!e)return;let t={};for(let[n,r]of Object.entries(e))t[n]=s1(r);return t}function s1(e){return e instanceof Error?`${e.name}: ${e.message}`:typeof e=="string"?Dy(e)?`[url:${td(e)}]`:e:e===null||typeof e=="number"||typeof e=="boolean"||typeof e>"u"?e:Array.isArray(e)?`[array:${e.length}]`:typeof e=="object"?"[object]":String(e)}function Oy(e){if(e)return Dy(e)?`[url:${td(e)}]`:e}function Dy(e){return/https?:\/\//i.test(e)||/[?&](x|token|sign|signature|expires?)=/i.test(e)}function td(e){if(!e)return;let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function Mp(e){var t;return{assetId:e.assetId,image:(t=e.image)!=null&&t.previews?{previewResolutions:Object.keys(e.image.previews),previewVariants:Object.keys(e.image.previewVariants??{})}:void 0,mediaType:e.mediaType,pippitAssetId:e.pippitAssetId,storageKey:a1(e),updatedAt:Date.now(),video:e.video?{durationMs:e.video.durationMs,height:e.video.height,width:e.video.width}:void 0}}function Lp(e,t){var o,s,i;let n=t.mediaType==="image"?t.imageVariant??"default":void 0,r=i1(e,t.source);return{assetId:r.assetId,expiresAt:(o=t.source)==null?void 0:o.expiresAt,imageVariant:n,mediaType:t.mediaType,pippitAssetId:r.pippitAssetId,purpose:t.purpose,resolution:t.resolution,sourceVersion:Oy((s=t.source)==null?void 0:s.version),storageKey:[pt(r),t.mediaType,t.purpose,t.resolution??"",n??""].join("|"),updatedAt:Date.now(),urlVersion:td(((i=t.source)==null?void 0:i.url)??t.url)}}function i1(e,t){let n=t==null?void 0:t.identity;return n!=null&&n.assetId?{assetId:n.assetId,...n.pippitAssetId?{pippitAssetId:n.pippitAssetId}:{}}:n!=null&&n.pippitAssetId?{pippitAssetId:n.pippitAssetId}:e}function a1(e){return[e.pippitAssetId?`pippit:${e.pippitAssetId}`:"",e.assetId?`asset:${e.assetId}`:""].filter(Boolean).join("|")}var js=class{constructor(t=500,n){this._limit=t;this._storage=n;this._records=[];this._listeners=new Set}add(t){var r;let n=kp(t);for(this._records.push(n);this._limit>=0&&this._records.length>this._limit;)this._records.shift();for(let o of this._listeners)o(n);Je((r=this._storage)==null?void 0:r.putOperationRecord(n))}clearRecords(){this._records.length=0}getRecords(t={}){return this._records.filter(n=>!(t.action&&n.action!==t.action||t.operationId&&n.operationId!==t.operationId||t.status&&n.status!==t.status||t.traceId&&n.traceId!==t.traceId))}subscribe(t){return this._listeners.add(t),()=>{this._listeners.delete(t)}}};var ky;function c1(){let e=globalThis.console;if(!e||typeof e!="object")return;let t=e.warn;return typeof t=="function"?t.bind(e):void 0}function Bp(e){var t;if(ky)try{ky({...e,context:u1(e.context),metrics:p1(e.metrics)})}catch(n){(t=c1())==null||t("[pippit-asset-sdk] telemetry reporter failed",n)}}function u1(e){if(!e)return;let t={},n=40;for(let[r,o]of Object.entries(e)){if(n<=0)break;t[r]=l1(o),n-=1}return t}function p1(e){if(!e)return;let t={};for(let[n,r]of Object.entries(e))Number.isFinite(r)&&(t[n]=r);return Object.keys(t).length?t:void 0}function l1(e){var t;return e instanceof Error?`${e.name}: ${e.message}`:typeof e=="string"?e.length>500?`${e.slice(0,500)}...`:e:e===null||typeof e=="number"||typeof e=="boolean"||typeof e>"u"?e:Array.isArray(e)?`[array:${e.length}]`:typeof e=="object"?`[object:${((t=e.constructor)==null?void 0:t.name)||"Object"}]`:String(e)}var nd=class{constructor(t){this.storage=t.storage,this.ledger=t.ledger??new js(500,t.storage),this._logger=t.logger,this._context=t.context??{}}async run(t,n,r){let o=Date.now(),s=My(t),i=n.traceId??s,a={action:t,category:n.category??"pippit_asset",context:{...this._context,...n.context},operationId:s,parentOperationId:n.parentOperationId,startedAt:o,traceId:i};this._record({...a,metrics:n.metrics,status:"start"});try{let d=await r({operationId:s,traceId:i});return this._record({...a,durationMs:Date.now()-o,endedAt:Date.now(),metrics:{count:1,...n.metrics??{}},status:"success"}),d}catch(d){let c=f1(d);throw this._record({...a,context:{...this._context,...n.context,error:d},durationMs:Date.now()-o,endedAt:Date.now(),metrics:{count:1,...n.metrics??{}},status:c?"cancelled":"failure"}),c||this._logger.error("[pippit-asset-sdk] operation failed",t,d,n.context),d}}log(t,n={}){let r=Date.now(),o=My(t),s=n.traceId??o;this._record({action:t,category:n.category??"pippit_asset",context:{...this._context,...n.context},metrics:n.metrics,operationId:o,parentOperationId:n.parentOperationId,startedAt:r,status:n.status??"log",traceId:s})}_record(t){this.ledger.add(t),Bp({action:t.action,category:t.category,context:t.context,metrics:t.metrics,operationId:t.operationId,packageName:"pippit-asset-sdk",status:t.status,traceId:t.traceId})}};function My(e){var n;let t=typeof((n=globalThis.crypto)==null?void 0:n.randomUUID)=="function"?globalThis.crypto.randomUUID():`${Date.now()}_${Math.random().toString(36).slice(2)}`;return`${e}_${t}`}function f1(e){return!!(e&&typeof e=="object"&&"name"in e&&e.name==="AbortError")}var rd=["200p","360p","480p","720p","1080p","2048p","origin"],od=["720p","1080p","2048p","480p","360p","200p","origin"],ho=["2048p","1080p","720p","480p","360p","200p","origin"];var m1={"200p":["200p","360p",...rd.filter(e=>e!=="200p")],"360p":["360p","480p","720p","200p","1080p","2048p","origin"],"480p":["480p","720p","1080p","2048p","360p","200p","origin"],"720p":od,"1080p":["1080p","2048p","720p","480p","360p","200p","origin"],"2048p":ho,origin:["origin","2048p","1080p","720p","480p","360p","200p"]};function Vs(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function h1(e){let t=Vs(e.width)??0,n=Vs(e.height)??0,r=Vs(e.zoom)??1,o=Vs(e.devicePixelRatio)??Vs(globalThis.devicePixelRatio)??1;return Math.max(t,n)*r*o}function Gp(e){if(!e)return"medium";let t=h1(e);return t>1440?"high":t>720?"medium":"low"}function Ly(e){if(e.resolution)return m1[e.resolution];let t=Gp(e.sourceOptions);return t==="high"?ho:t==="medium"?od:rd}function Lt(){return new DOMException("Pippit asset source polling aborted.","AbortError")}var sd=class{constructor(t,n){this._resolver=t;this._onDetach=n;this._abortController=new AbortController;this._detached=!1;this._retainWhenOrphaned=!1;this._result={status:"pending"};this._started=!1;this._waiters=new Map}waitForResult(t,n=!1){if(t!=null&&t.aborted)return Promise.reject(Lt());if(this._result.status==="fulfilled")return Promise.resolve(this._result.value);if(this._result.status==="rejected")return Promise.reject(this._result.error);if(this._result.status==="orphaned")return Promise.reject(Lt());this._retainWhenOrphaned||=n;let r=Symbol("source-resolve-waiter"),o=new Promise((s,i)=>{let a={reject:i,resolve:s,signal:t};t&&(a.onAbort=()=>this._abortWaiter(r)),this._waiters.set(r,a),t&&a.onAbort&&t.addEventListener("abort",a.onAbort,{once:!0})});return this._start(),o}cancel(){if(this._result.status!=="pending")return;this._result={status:"orphaned"};let t=Array.from(this._waiters.values());this._waiters.clear(),this._detach(),this._abortController.abort();for(let n of t)this._cleanupWaiter(n),n.reject(Lt())}_start(){if(this._started)return;this._started=!0;let t;try{t=this._resolver(this._abortController.signal)}catch(n){this._settle({status:"rejected",error:n});return}Promise.resolve(t).then(n=>this._settle({status:"fulfilled",value:n}),n=>this._settle({status:"rejected",error:n}))}_abortWaiter(t){let n=this._waiters.get(t);n&&(this._waiters.delete(t),this._cleanupWaiter(n),n.reject(Lt()),this._waiters.size===0&&this._result.status==="pending"&&!this._retainWhenOrphaned&&this.cancel())}_settle(t){if(this._result.status!=="pending")return;this._result=t;let n=Array.from(this._waiters.values());this._waiters.clear(),this._detach();for(let r of n)this._cleanupWaiter(r),t.status==="fulfilled"?r.resolve(t.value):r.reject(t.error)}_cleanupWaiter(t){t.signal&&t.onAbort&&t.signal.removeEventListener("abort",t.onAbort)}_detach(){this._detached||(this._detached=!0,this._onDetach(this))}};var g1=["expires","expire","expiration","x-expires","x-everphoto-expires","x_expire","sign_expire","sign_expires"],y1=["x-amz-date","x-tos-date"],A1=["x-amz-expires","x-tos-expires"],v1=/\/[0-9a-f]{32}\/([0-9a-f]{8})\/video(?:\/|$)/i,S1=Date.UTC(2020,0,1)/1e3,b1=Date.UTC(2100,0,1)/1e3;function Sr(e,t=Date.now()){let n=By(e.expiresAt,e.url,t);return n===e.expiresAt?e:{...e,expiresAt:n}}function br(e,t=Date.now()){return By(e.expiresAt,e.url,t)-t>1e4}function By(e,t,n){return typeof e=="number"&&Number.isFinite(e)?e:I1(t)??n+12e5}function I1(e){let t=_1(e);if(!t)return;let n=R1(t.searchParams);if(n)return n;let r=E1(t.searchParams),o=C1(t.searchParams);return r&&o?r+o:x1(t.pathname)}function _1(e){try{return new URL(e,"https://pippit-asset-sdk.local")}catch{return}}function R1(e){for(let t of g1){let n=P1(Up(e,t));if(n)return n}}function E1(e){for(let t of y1){let n=Up(e,t);if(!n)continue;let r=T1(n)??Date.parse(n);if(Number.isFinite(r))return r}}function C1(e){for(let t of A1){let n=Up(e,t),r=n?Number(n):NaN;if(Number.isFinite(r)&&r>0)return r*1e3}}function P1(e){if(!e)return;let t=Number(e);if(Number.isFinite(t)&&t>0)return t>1e10?t:t*1e3;let n=Date.parse(e);return Number.isFinite(n)?n:void 0}function x1(e){let t=v1.exec(e);if(!t)return;let n=Number.parseInt(t[1],16);if(!(!Number.isFinite(n)||n<S1||n>b1))return n*1e3}function T1(e){let t=/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/.exec(e);if(!t)return;let[,n,r,o,s,i,a]=t;return Date.UTC(Number(n),Number(r)-1,Number(o),Number(s),Number(i),Number(a))}function Up(e,t){let n=t.toLowerCase();for(let[r,o]of e.entries())if(r.toLowerCase()===n&&o.trim())return o.trim()}var zp=3e4,Gy=2,go=class{constructor(){this._entries=new Map;this._inFlightResolves=new Map;this._refreshBudgets=new Map;this._refreshSuppressions=new Map;this._aliasInvalidationRevisions=new Map;this._keyRevisions=new Map;this._clearRevision=0}getRevision(t,n){let r=Array.from(Bt(n)).sort().map(o=>`${o}:${this._aliasInvalidationRevisions.get(o)??0}`).join(",");return[this._clearRevision,this._keyRevisions.get(t)??0,r].join("|")}getCurrent(t,n,r){var o;return(o=this._findEntry(t,n,r))==null?void 0:o.entry.source}getUsable(t,n,r){let o=this._findEntry(t,n,r);if(o){if(br(o.entry.source))return o.entry.source;this._entries.delete(o.key),this._bumpKeyRevision(o.key)}}set(t,n,r,o,s){return s!==void 0&&s!==this.getRevision(t,r)?!1:(this._entries.set(t,N1(r,o,n)),this._bumpKeyRevision(t),!0)}setInitial(t,n,r,o){this.getUsable(t,r,o)||br(n)&&this.set(t,n,r,o)}resolveInFlight(t,n,r,o,s){var c;if((c=o.signal)!=null&&c.aborted)return Promise.reject(Lt());let i=this.getRevision(t,n),a=this._findInFlightResolve(t,n,r);if((a==null?void 0:a.entry.revision)===i)return a.entry.task.waitForResult(o.signal,o.inFlightLifetime==="client");let d=new sd(u=>s(i,u),u=>{this._deleteInFlightResolveByTask(u)});return this._inFlightResolves.set(t,{aliases:Bt(n),revision:i,scopeKey:ln(r),task:d}),d.waitForResult(o.signal,o.inFlightLifetime==="client")}hasInFlightResolve(t,n,r){let o=this._findInFlightResolve(t,n,r);return!!(o&&o.entry.revision===this.getRevision(t,n))}markRefreshRequested(t,n,r,o){var i;if(!o)return;let s=((i=this._findRefreshSuppression(t,n,r))==null?void 0:i.entry)??w1(n,r);s.versions.add(o),this._refreshSuppressions.set(t,s)}shouldSuppressRefresh(t,n,r,o){var s;return o?!!((s=this._findRefreshSuppression(t,n,r))!=null&&s.entry.versions.has(o)):!1}markRefreshAttempt(t,n,r,o){var d;let s=((d=this._findRefreshBudget(t,n,r))==null?void 0:d.entry)??O1(n,r),i=s.records.get(o),a=Date.now();!i||a-i.windowStartedAt>=zp?s.records.set(o,{attempts:1,windowStartedAt:a}):i.attempts+=1,this._refreshBudgets.set(t,s)}shouldSuppressRefreshByBudget(t,n,r,o){var i;let s=(i=this._findRefreshBudget(t,n,r))==null?void 0:i.entry.records.get(o);return!s||Date.now()-s.windowStartedAt>=zp?!1:s.attempts>=Gy}getRefreshBudgetPolicy(){return{maxAttempts:Gy,windowMs:zp}}dispose(){this._cancelInFlightResolves(this._inFlightResolves.values()),this.invalidate()}invalidate(t){if(!t){this._entries.clear(),this._inFlightResolves.clear(),this._refreshBudgets.clear(),this._refreshSuppressions.clear(),this._clearRevision+=1;return}let n=Bt(t);for(let[r,o]of Array.from(this._entries.entries()))zn(o.aliases,n)&&(this._entries.delete(r),this._bumpKeyRevision(r));for(let[r,o]of Array.from(this._inFlightResolves.entries()))zn(o.aliases,n)&&this._inFlightResolves.delete(r);for(let[r,o]of Array.from(this._refreshSuppressions.entries()))zn(o.aliases,n)&&this._refreshSuppressions.delete(r);for(let[r,o]of Array.from(this._refreshBudgets.entries()))zn(o.aliases,n)&&this._refreshBudgets.delete(r);for(let r of n)this._aliasInvalidationRevisions.set(r,(this._aliasInvalidationRevisions.get(r)??0)+1)}_findEntry(t,n,r){let o=this._entries.get(t);if(o)return{entry:o,key:t};if(!n||!r)return;let s=Bt(n),i=ln(r);for(let[a,d]of this._entries.entries())if(d.scopeKey===i&&zn(d.aliases,s))return{entry:d,key:a}}_findRefreshSuppression(t,n,r){let o=this._refreshSuppressions.get(t);if(o)return{entry:o,key:t};let s=Bt(n),i=ln(r);for(let[a,d]of this._refreshSuppressions.entries())if(d.scopeKey===i&&zn(d.aliases,s))return{entry:d,key:a}}_findRefreshBudget(t,n,r){let o=this._refreshBudgets.get(t);if(o)return{entry:o,key:t};let s=Bt(n),i=ln(r);for(let[a,d]of this._refreshBudgets.entries())if(d.scopeKey===i&&zn(d.aliases,s))return{entry:d,key:a}}_findInFlightResolve(t,n,r){let o=this._inFlightResolves.get(t);if(o)return{entry:o,key:t};let s=Bt(n),i=ln(r);for(let[a,d]of this._inFlightResolves.entries())if(d.scopeKey===i&&zn(d.aliases,s))return{entry:d,key:a}}_deleteInFlightResolveByTask(t){for(let[n,r]of this._inFlightResolves.entries())if(r.task===t){this._inFlightResolves.delete(n);return}}_cancelInFlightResolves(t){new Set(Array.from(t,n=>n.task)).forEach(n=>n.cancel())}_bumpKeyRevision(t){this._keyRevisions.set(t,(this._keyRevisions.get(t)??0)+1)}};function qy(e,t){return[D1(e),ln(t)].join("|")}function N1(e,t,n){return{aliases:Bt(e,n),scopeKey:ln(t),source:n}}function w1(e,t){return{aliases:Bt(e),scopeKey:ln(t),versions:new Set}}function O1(e,t){return{aliases:Bt(e),records:new Map,scopeKey:ln(t)}}function D1(e){return[e.pippitAssetId?`pippit:${e.pippitAssetId}`:"",e.assetId?`asset:${e.assetId}`:""].filter(Boolean).join("|")}function ln(e){let t=e.mediaType==="image"?e.resolution??Gp(e.sourceOptions):"",n=e.mediaType==="image"&&e.allowProvisionalImage===!1?"final-only":"";return[e.mediaType,e.purpose,e.imageVariant??"",t,n].join("|")}function Bt(e,t){let n=t==null?void 0:t.identity;return n!=null&&n.assetId||n!=null&&n.pippitAssetId?new Set([Uy(n.pippitAssetId),zy(n.assetId)].filter(r=>!!r)):new Set([Uy(e.pippitAssetId),zy(e.assetId)].filter(r=>!!r))}function Uy(e){return e?pt({pippitAssetId:e}):void 0}function zy(e){return e?pt({assetId:e}):void 0}function zn(e,t){for(let n of t)if(e.has(n))return!0;return!1}function Fy(e){return e instanceof File?e:new File([e],"pippit-upload.bin",{type:e.type||"application/octet-stream"})}function jy(){var t;return`upload_${typeof((t=globalThis.crypto)==null?void 0:t.randomUUID)=="function"?globalThis.crypto.randomUUID():`${Date.now()}_${Math.random().toString(36).slice(2)}`}`}function Vy(e){var t;Je((t=e.runtime.storage)==null?void 0:t.putUploadTask({assetId:e.result.assetId,pippitAssetId:e.result.pippitAssetId,status:e.status,taskId:e.taskId,updatedAt:Date.now()}))}function Hy(e){e.runtime.log("upload_task_success",{context:{asset_id:e.result.assetId,pippit_asset_id:e.result.pippitAssetId,task_id:e.taskId}})}function Yy(e){e.runtime.log("upload_task_failure",{context:{error:e.error,task_id:e.taskId},status:"failure"})}function Ky({runtime:e,transport:t}){return{createUploadTask(n,r={}){return new id(n,r,t,e)},async uploadFile(n,r={}){return new id(n,r,t,e).start()}}}var id=class{constructor(t,n,r,o){this._options=n;this._transport=r;this._runtime=o;this._status="pending";this._taskId=jy();this._file=Fy(t),this._runtime.log("upload_task_create",{context:{file_type:this._file.type,task_id:this._taskId},metrics:{file_size:this._file.size}})}cancel(){var t;this._status="cancelled",(t=this._abortController)==null||t.abort(),this._runtime.log("upload_task_cancel",{context:{task_id:this._taskId}})}getSnapshot(){return{error:this._error,progress:this._progress,result:this._result,status:this._status,taskId:this._taskId}}async retry(){return this._runtime.log("upload_task_retry",{context:{resume_mode:"restart",task_id:this._taskId}}),this.start()}async start(){if(this._status==="cancelled")throw new Error("Upload task has been cancelled.");return this._status="uploading",this._runtime.run("upload_task_start",{context:{file_type:this._file.type,task_id:this._taskId},metrics:{file_size:this._file.size}},async()=>{let t=this._createAbortController();this._abortController=t;try{let n=await this._transport.upload(this._file,{onProgress:r=>this._handleProgress(r),signal:t.signal});return this._handleUploadSuccess(n),n}catch(n){throw this._handleUploadFailure(n),n}finally{this._abortController===t&&(this._abortController=void 0)}})}_createAbortController(){var r,o;let t=new AbortController,n=()=>t.abort();return(r=this._options.signal)!=null&&r.aborted?(n(),t):((o=this._options.signal)==null||o.addEventListener("abort",n,{once:!0}),t)}_handleProgress(t){var n,r;this._progress=t,this._runtime.log("upload_task_progress",{context:{task_id:this._taskId},metrics:{loaded:t.loaded,percentage:t.percentage,total:t.total}}),(r=(n=this._options).onProgress)==null||r.call(n,t)}_handleUploadSuccess(t){this._result=t,this._status="success",Vy({result:t,runtime:this._runtime,status:this._status,taskId:this._taskId}),Hy({result:t,runtime:this._runtime,taskId:this._taskId})}_handleUploadFailure(t){this._error=t instanceof Error?t:new Error(String(t)),this._status!=="cancelled"&&(this._status="failed"),Yy({error:this._error,runtime:this._runtime,taskId:this._taskId})}};var k1=new Set(["audio","image","video"]),M1=new Set(["file","text"]);function Xy(e){return!!(e.mediaType&&k1.has(e.mediaType))}function qp(e,t){return e.some(n=>n.mediaType&&M1.has(n.mediaType))?{...t,cachePolicy:"refresh"}:t}function Jy(e){let{invalidateSources:t,runtime:n,transport:r}=e,o=(a,d)=>{let c=K(a);return n.run("asset_refresh",{context:xe(c)},async()=>{let u=await ad(r,c,{cachePolicy:"refresh",signal:d});return qn(n,u),u})},s=(a,d,c={})=>{let u=a.map(K),p=Hs(u),l,f=u;return n.run("asset_subscribe_open",p,()=>{var h;r.subscribeAssetEvents&&(l=r.subscribeAssetEvents(u,m=>{var y,v,S,b,I;let g=K(m.ref);(y=r.invalidateAssets)==null||y.call(r,[g]),t==null||t(g),Je((S=(v=n.storage)==null?void 0:v.deleteAssetMetadata)==null?void 0:S.call(v,g)),Je((I=(b=n.storage)==null?void 0:b.deleteUrlLeases)==null?void 0:I.call(b,g)),d({...m,ref:g})},c),(h=l.syncAssetRefs)==null||h.call(l,f))}).catch(()=>{}),{close:()=>{n.run("asset_subscribe_close",p,()=>{l==null||l.close(),l=void 0}).catch(()=>{})},syncAssetRefs:h=>{var g;let m=h.map(K);f=m,n.log("asset_subscribe_sync",{...Hs(m),metrics:{request_count:m.length}}),(g=l==null?void 0:l.syncAssetRefs)==null||g.call(l,m)}}};return{createAsset:async a=>n.run("asset_create",j1(a),async()=>{if(!r.createAsset)throw new Error("Pippit asset create transport is not configured.");let d=Wy(await r.createAsset(U1(a)));return $y(n,d),Qy(n,r,d,a.refresh!==!1,a.signal)}),getAsset:async(a,d={})=>{let c=K(a);return n.run("asset_query",{context:xe(c)},async()=>{let u=await ad(r,c,d);return qn(n,u),u})},getAssets:async(a,d={})=>{let c=a.map(K);return n.run("asset_batch_query",Hs(c),async()=>{let u=await Fp(r,c,d);return u.forEach(p=>qn(n,p)),u})},queryAssets:async(a,d={})=>{let c=a.map(K);return n.run("asset_batch_query",Hs(c),async()=>{let u=await L1(r,c,d);return u.forEach(({asset:p})=>{p&&qn(n,p)}),u})},invalidate:(a,d={})=>{var p,l,f,h,m;let c=K(a);(p=r.invalidateAssets)==null||p.call(r,[c]);let u=d.scope??"all";(u==="all"||u==="metadata")&&Je((f=(l=n.storage)==null?void 0:l.deleteAssetMetadata)==null?void 0:f.call(l,c)),(u==="all"||u==="source")&&(t==null||t(c),Je((m=(h=n.storage)==null?void 0:h.deleteUrlLeases)==null?void 0:m.call(h,c))),n.log("asset_invalidate",{context:{...xe(c),invalidate_scope:u}})},patchAssets:async a=>n.run("asset_batch_patch",V1(a),async()=>{var p;if(!r.patchAssets)throw new Error("Pippit asset patch transport is not configured.");let d=z1(a),c=await r.patchAssets(d),u=await q1(n,r,d,c,a.refresh!==!1);return dd(d.patches.map(l=>l.ref)).forEach(l=>t==null?void 0:t(l)),(p=r.invalidateAssets)==null||p.call(r,dd(d.patches.map(l=>l.ref))),u}),refresh:o,subscribeAssetEvents:s,updateAsset:async(a,d)=>{let c=K(a);return n.run("asset_update",{context:xe(c)},async()=>{if(!r.updateAsset)throw new Error("Pippit asset update transport is not configured.");let u=Wy(await r.updateAsset(c,d));$y(n,u);let p=await Qy(n,r,u,d.refresh!==!1,d.signal);return t==null||t(u.ref),p})},watchAsset:(a,d,c={})=>{let u=K(a);if(n.log("asset_subscribe_start",{context:xe(u)}),r.subscribeAssetEvents){let p=s([u],l=>{F1({event:l,invalidateSources:t,listener:d,ref:u,runtime:n,shouldRefresh:c.refreshOnChange!==!1,signal:c.signal,transport:r}).catch(f=>{n.log("asset_update_refresh_failure",{context:{...xe(u),error:f},status:"failure"})})},c);return()=>{n.log("asset_subscribe_stop",{context:xe(u)}),p.close()}}return n.log("asset_subscribe_unavailable",{context:xe(u)}),()=>{n.log("asset_subscribe_stop",{context:xe(u)})}}}}async function ad(e,t,n){let o=(await Fp(e,[t],n))[0];if(!o)throw new Error("Pippit asset query returned no asset.");return o}async function Fp(e,t,n){if(!e.queryAssets)throw new Error("Pippit asset query transport is not configured.");let r=await e.queryAssets(t,qp(t,{batchingStrategy:n.batchingStrategy,cachePolicy:n.cachePolicy,dispatchMode:n.dispatchMode,signal:n.signal}));return B1(t,r)}async function L1(e,t,n){if(!e.queryAssets)throw new Error("Pippit asset query transport is not configured.");let r=await e.queryAssets(t,qp(t,{batchingStrategy:n.batchingStrategy,cachePolicy:n.cachePolicy,dispatchMode:n.dispatchMode,signal:n.signal}));return G1(t,r)}function B1(e,t){let n=[...t];return e.map(r=>{let o=n.findIndex(i=>Zy(i,r));if(o<0)throw new Error(`Pippit asset query missing result for ref: ${pt(r)}`);let[s]=n.splice(o,1);if(!s)throw new Error(`Pippit asset query missing result for ref: ${pt(r)}`);return s})}function G1(e,t){let n=[...t];return e.map(r=>{let o=n.findIndex(i=>Zy(i,r));if(o<0)return{asset:null,ref:r};let[s]=n.splice(o,1);return{asset:s??null,ref:r}})}function Zy(e,t){return t.pippitAssetId&&e.pippitAssetId!==t.pippitAssetId||t.assetId&&e.assetId!==t.assetId?!1:!!(t.pippitAssetId||t.assetId)}function qn(e,t){var n;Xy(t)&&Je((n=e.storage)==null?void 0:n.putAssetMetadata(Mp(t)))}function $y(e,t){t.asset&&qn(e,t.asset)}function U1(e){return{...e,ref:e.ref?K(e.ref):void 0}}function z1(e){return{...e,patches:e.patches.map(t=>({...t,ref:K(t.ref)})),rootRef:e.rootRef?K(e.rootRef):void 0}}function Wy(e){return{...e,ref:K(e.ref)}}async function Qy(e,t,n,r,o){if(!r||!t.queryAssets)return n;let s=await ad(t,n.ref,{cachePolicy:"refresh",signal:o});return qn(e,s),{...n,asset:s}}async function q1(e,t,n,r,o){if(!o||!t.queryAssets)return r;let s=dd(n.patches.map(a=>a.ref)),i=await Fp(t,s,{cachePolicy:"refresh",signal:n.signal});return i.forEach(a=>qn(e,a)),{...r,assets:i}}async function F1(e){var r,o,s;let t=K({...e.ref,...e.event.ref});e.runtime.log("asset_update_received",{context:{...xe(t),event_type:e.event.eventType,version:e.event.version}}),(o=(r=e.transport).invalidateAssets)==null||o.call(r,[t]);let n=e.event.asset??(e.shouldRefresh&&e.transport.queryAssets?await ad(e.transport,t,{cachePolicy:"refresh",signal:e.signal}):void 0);if(!n){e.runtime.log("asset_update_refresh_skipped",{context:xe(t)});return}qn(e.runtime,n),(s=e.invalidateSources)==null||s.call(e,t),e.listener(n),e.runtime.log("asset_update_applied",{context:{...xe(t),event_type:e.event.eventType,version:e.event.version}})}function j1(e){return{context:{...e.ref?xe(K(e.ref)):{},media_type:e.mediaType}}}function V1(e){let t=dd(e.patches.map(n=>K(n.ref)));return{...Hs(t),metrics:{patch_count:e.patches.length,request_count:t.length}}}function dd(e){let t=new Set,n=[];for(let r of e){let o=pt(r);t.has(o)||(t.add(o),n.push(r))}return n}function Hs(e){return{context:{asset_id:e.map(t=>t.assetId).filter(Boolean).join(",")||void 0,pippit_asset_id:e.map(t=>t.pippitAssetId).filter(Boolean).join(",")||void 0,request_count:e.length},metrics:{request_count:e.length}}}var eA=(e,t)=>Number.isFinite(e)?Math.max(1,Math.floor(e)):t,jp=class{constructor(t,n){this.allocate=t;this.options=n;this.buffer=[];this.cursor=0;this.refillFailureCount=0;this.refillRetryAt=0;this.disposed=!1;this.seen=new Set;this.init=()=>this.refill();this.take=()=>{if(this.disposed)return;let t=this.buffer[this.cursor];if(t===void 0){this.refillIfNeeded();return}return this.cursor+=1,this.compactIfNeeded(),this.refillIfNeeded(),t};this.mustTake=()=>{let t=this.take();if(!t)throw new Error("[PippitAssetIdPool] id pool is empty");return t};this.takeMany=t=>{let n=[];for(let r=0;r<Math.max(0,Math.floor(t));r+=1){let o=this.take();if(!o)break;n.push(o)}return n};this.available=()=>this.buffer.length-this.cursor;this.isRefilling=()=>!!this.refillPromise;this.waitForIdle=()=>this.refillPromise??Promise.resolve();this.refill=(t=!1)=>{if(this.disposed)return Promise.resolve();if(this.refillPromise)return this.refillPromise;if(!t&&Date.now()<this.refillRetryAt)return Promise.resolve();let n=this.maxBufferSize-this.available();if(n<=0||!t&&this.available()>this.lowWaterMark)return Promise.resolve();let r=Math.min(this.batchSize,n);return this.refillPromise=this.allocate(r).then(o=>{for(let s of o){let i=s.trim();!i||this.seen.has(i)||this.available()>=this.maxBufferSize||(this.seen.add(i),this.buffer.push(i))}this.resetRefillFailures()}).catch(o=>{throw this.recordRefillFailure(),o}).finally(()=>{this.refillPromise=void 0}),this.refillPromise};this.clear=()=>{this.buffer=[],this.cursor=0,this.seen.clear(),this.resetRefillFailures()};this.dispose=()=>{this.disposed=!0,this.clear()};this.batchSize=eA(n.batchSize,1e3),this.lowWaterMark=Math.max(0,Math.floor(n.lowWaterMark??200)),this.maxBufferSize=eA(n.maxBufferSize,1e3)}refillIfNeeded(){this.available()>this.lowWaterMark||this.refill().catch(t=>{var n,r;return(r=(n=this.options).onRefillError)==null?void 0:r.call(n,t)})}recordRefillFailure(){if(this.refillFailureCount+=1,this.refillFailureCount===1)return;let t=Math.min(5e3*2**(this.refillFailureCount-2),6e4);this.refillRetryAt=Date.now()+t}resetRefillFailures(){this.refillFailureCount=0,this.refillRetryAt=0}compactIfNeeded(){this.cursor<=100||this.cursor<=this.buffer.length/2||(this.buffer=this.buffer.slice(this.cursor),this.cursor=0)}};function tA(e){let t=new Set,n=!1,r=async o=>{if(n)throw new Error("Pippit asset client is disposed.");let s=Math.max(0,Math.floor(o));if(s===0)return[];if(!e.allocateAssetIds)throw new Error("Pippit asset ID transport is not configured.");let a=(await e.allocateAssetIds(s)).map(d=>d.trim()).filter(Boolean);if(a.length<s)throw new Error(`Pippit asset ID allocation returned ${a.length}/${s} IDs.`);if(new Set(a).size!==a.length)throw new Error("Pippit asset ID allocation returned duplicate IDs.");return a};return{module:{allocate:r,createPool:(o={})=>{if(n)throw new Error("Pippit asset client is disposed.");let s=new jp(r,o);return t.add(s),s}},dispose:()=>{n=!0,t.forEach(o=>o.dispose()),t.clear()}}}var nA=new WeakMap,ze=class extends Error{constructor(n="Pippit asset source is not ready."){super(n);this.code="PIPPIT_ASSET_SOURCE_NOT_READY";this.name="PippitAssetSourceNotReadyError"}};function Gt(e){return e instanceof ze}function Vp(e,t){return nA.set(e,{...t}),e}function cd(e){let t=Gt(e)?nA.get(e):void 0;return t?{...t}:void 0}var H1=new Set(["200p","360p","480p","720p","1080p","2048p","origin"]);function rA(e){var r;let t=Sr(e.source),n=e.sourceOptions.resolution??Y1(t);Je((r=e.runtime.storage)==null?void 0:r.putUrlLease(Lp(e.ref,{imageVariant:e.sourceOptions.imageVariant,mediaType:e.sourceOptions.mediaType,purpose:e.sourceOptions.purpose,resolution:n,source:t})))}function Y1(e){var n;let t=(n=e.metadata)==null?void 0:n.resolution;return typeof t=="string"&&H1.has(t)?t:void 0}var K1=1500,X1=40,$1=new Set(["audio","image","video"]),W1="AssetQuery did not return an asset_id for source resolution.";function Yp(e){return Q1(e.sourceOptions.mediaType),new Hp(e)}var Hp=class{constructor(t){this._options=t;this._disposed=!1;this._actionPrefix=`${t.sourceOptions.mediaType}_source`,this._sourceKey=qy(t.ref,t.sourceOptions),this._store=t.store??new go,t.sourceOptions.initialSource&&!t.sourceOptions.shouldUseInitialSource&&(this._initialSourceAllowed=!0,this._store.setInitial(this._sourceKey,Sr(t.sourceOptions.initialSource),t.ref,t.sourceOptions))}dispose(){this._disposed=!0}getCurrentSource(){if(this._disposed||this._options.sourceOptions.shouldUseInitialSource&&this._initialSourceAllowed!==!0)return;let t=this._store.getCurrent(this._sourceKey,this._options.ref,this._options.sourceOptions);return t&&br(t)?t:void 0}async getSource(t){return this._assertActive(),this._options.runtime.run(`${this._actionPrefix}_resolve`,{context:this._buildContext()},()=>this._requiresInitialSourceDecision()?this._prepareInitialSource().then(()=>this._getSourceAfterInitialSourceDecision(t)):this._getSourceAfterInitialSourceDecision(t))}async refresh(t){if(this._assertActive(),this._shouldReturnSuppressedRefresh(t))return this._store.getCurrent(this._sourceKey,this._options.ref,this._options.sourceOptions);if(!this._store.hasInFlightResolve(this._sourceKey,this._options.ref,this._options.sourceOptions)){let n=this._getBudgetSuppressedRefreshSource(t);if(n)return n}return this._runRefresh(t).then(n=>(this._store.markRefreshRequested(this._sourceKey,this._options.ref,this._options.sourceOptions,t.sourceVersion),n))}_assertActive(){if(this._disposed)throw new Error("Pippit asset source controller is disposed.")}_requiresInitialSourceDecision(){let{initialSource:t,shouldUseInitialSource:n}=this._options.sourceOptions;return!!(t&&n&&this._initialSourceAllowed===void 0)}_getSourceAfterInitialSourceDecision(t){let n=this._store.getCurrent(this._sourceKey,this._options.ref,this._options.sourceOptions),r=this._store.getUsable(this._sourceKey,this._options.ref,this._options.sourceOptions);return r&&br(r)?(this._options.runtime.log(`${this._actionPrefix}_cache_hit`,{context:this._buildContext(),status:"log"}),r):this._resolveSource({inFlightLifetime:t==null?void 0:t.inFlightLifetime,refresh:!!n,signal:t==null?void 0:t.signal})}async _prepareInitialSource(){let{initialSource:t,shouldUseInitialSource:n}=this._options.sourceOptions;if(!t||!n||this._initialSourceAllowed!==void 0)return;this._initialSourceDecisionPromise??=Promise.resolve(n());let r=await this._initialSourceDecisionPromise;if(this._assertActive(),this._initialSourceAllowed=r,!r){this._store.invalidate(this._options.ref);return}this._store.setInitial(this._sourceKey,Sr(t),this._options.ref,this._options.sourceOptions)}_shouldReturnSuppressedRefresh(t){return this._store.shouldSuppressRefresh(this._sourceKey,this._options.ref,this._options.sourceOptions,t.sourceVersion)?(this._options.runtime.log(`${this._actionPrefix}_refresh`,{context:this._buildRefreshContext(t,{refresh_suppressed:!0}),status:"log"}),!!this._store.getCurrent(this._sourceKey,this._options.ref,this._options.sourceOptions)):!1}_getBudgetSuppressedRefreshSource(t){let n=this._store.getCurrent(this._sourceKey,this._options.ref,this._options.sourceOptions);if(!n||!this._store.shouldSuppressRefreshByBudget(this._sourceKey,this._options.ref,this._options.sourceOptions,t.reason))return;let r=this._store.getRefreshBudgetPolicy();return this._options.runtime.log(`${this._actionPrefix}_refresh`,{context:this._buildRefreshContext(t,{refresh_budget_max_attempts:r.maxAttempts,refresh_budget_window_ms:r.windowMs,refresh_suppressed:!0,refresh_suppression_reason:"refresh_budget_exhausted"}),status:"log"}),n}_runRefresh(t){return this._options.runtime.run(`${this._actionPrefix}_refresh`,{context:this._buildRefreshContext(t)},()=>this._resolveSource({onSharedResolveStart:()=>{this._store.markRefreshAttempt(this._sourceKey,this._options.ref,this._options.sourceOptions,t.reason)},refresh:!0,signal:t.signal}))}async _resolveSource(t){return this._throwIfAborted(t.signal),this._store.resolveInFlight(this._sourceKey,this._options.ref,this._options.sourceOptions,{inFlightLifetime:t.inFlightLifetime,signal:t.signal},(n,r)=>{var o;return(o=t.onSharedResolveStart)==null||o.call(t),this._resolveSourceWithRevision({refresh:t.refresh,signal:r},n,{commitAfterDispose:!0})})}async _resolveSourceWithRevision(t,n,r={}){let o={effectiveRef:this._options.ref},s=await this._resolveSourceWithPolling(t,o);this._throwIfAborted(t.signal);let i=Sr(this._applyResolvedRefIdentity(s,o.resolvedRef));if((r.commitAfterDispose||!this._disposed)&&this._store.set(this._sourceKey,i,this._options.ref,this._options.sourceOptions,n))return rA({ref:this._options.ref,runtime:this._options.runtime,source:i,sourceOptions:this._options.sourceOptions}),i;let d=this._store.getUsable(this._sourceKey,this._options.ref,this._options.sourceOptions);if(d)return d;throw new Error("Pippit asset source resolve was superseded.")}async _resolveSourceWithPolling(t,n){let r=this._resolvePollingOptions(),o;for(let s=1;s<=r.maxAttempts;s+=1){this._throwIfAborted(t.signal);try{return await this._resolveSourceOnce(t,n.effectiveRef)}catch(i){this._advanceResolvedVideoPreviewRef(i,n);let a=this._normalizeAssetBindingError(i);if(!Gt(a)||s>=r.maxAttempts){o=a;break}o=a,this._logPollAttempt(s,r.maxAttempts),await oA(t.signal,r.intervalMs)}}if(!this._shouldEnterSlowPolling(r,o))throw o instanceof Error?o:new Error("Pippit asset source polling exhausted.");return this._resolveSourceWithSlowPolling(t,r,n)}async _resolveSourceWithSlowPolling(t,n,r){this._logSlowPollingStart(n);let o=0;for(;n.slowMaxAttempts===void 0||o<n.slowMaxAttempts;){o+=1,await oA(t.signal,n.slowIntervalMs??0),this._throwIfAborted(t.signal);try{return await this._resolveSourceOnce(t,r.effectiveRef)}catch(s){this._advanceResolvedVideoPreviewRef(s,r);let i=this._normalizeAssetBindingError(s);if(!Gt(i))throw i;this._logSlowPollAttempt(o,n.slowMaxAttempts)}}throw new Error("Pippit asset source slow polling exhausted.")}async _resolveSourceOnce(t,n){let{sourceOptions:r,transport:o}=this._options;if(!o.resolveSource)throw new Error("Pippit asset source transport is not configured.");let{initialSource:s,shouldUseInitialSource:i,telemetry:a,waitForAssetBinding:d,...c}=r,u=Sr(await o.resolveSource(n,{...c,refresh:t.refresh,signal:t.signal}));if(br(u))return u;if(!t.refresh)return this._resolveSourceOnce({...t,refresh:!0},n);throw new Error("Pippit asset source transport returned an expired URL lease.")}_advanceResolvedVideoPreviewRef(t,n){var i;let{ref:r,sourceOptions:o}=this._options,s=cd(t);if(!(!Gt(t)||!s||o.mediaType!=="video"||o.purpose!=="preview"||!r.pippitAssetId||r.assetId)){if(!s.assetId||s.pippitAssetId!==r.pippitAssetId)throw new Error("Resolved video asset ref does not match the requested pippitAssetId.");if(s.mediaType&&s.mediaType!=="video")throw new Error("Resolved video asset ref has an incompatible mediaType.");if((i=n.resolvedRef)!=null&&i.assetId&&n.resolvedRef.assetId!==s.assetId)throw new Error("Resolved video asset ref changed during source polling.");n.resolvedRef={assetId:s.assetId,mediaType:"video",pippitAssetId:r.pippitAssetId},n.effectiveRef={assetId:s.assetId,mediaType:"video"}}}_applyResolvedRefIdentity(t,n){var r,o;if(!(n!=null&&n.assetId)||!n.pippitAssetId)return t;if((r=t.identity)!=null&&r.assetId&&t.identity.assetId!==n.assetId)throw new Error("Resolved video source assetId does not match the polled assetId.");if((o=t.identity)!=null&&o.pippitAssetId&&t.identity.pippitAssetId!==n.pippitAssetId)throw new Error("Resolved video source pippitAssetId does not match the requested asset.");return{...t,identity:{...t.identity,assetId:n.assetId,pippitAssetId:n.pippitAssetId},metadata:{...t.metadata,assetId:n.assetId,pippitAssetId:n.pippitAssetId}}}_normalizeAssetBindingError(t){return this._options.sourceOptions.waitForAssetBinding&&t instanceof Error&&t.message===W1?new ze(t.message):t}_resolvePollingOptions(){let t=this._options.sourceOptions.polling;if(t===!1)return{intervalMs:0,maxAttempts:1};let n=this._options.sourceOptions.mediaType==="video"&&this._options.sourceOptions.purpose==="preview";return{intervalMs:(t==null?void 0:t.intervalMs)??(n?K1:0),maxAttempts:(t==null?void 0:t.maxAttempts)??(n?X1:1),slowIntervalMs:t==null?void 0:t.slowIntervalMs,slowMaxAttempts:t==null?void 0:t.slowMaxAttempts}}_shouldEnterSlowPolling(t,n){return!!(t.slowIntervalMs&&Gt(n))}_logPollAttempt(t,n){this._options.runtime.log(`${this._actionPrefix}_wait`,{context:{...this._buildContext(),poll_attempt:t,poll_max_attempts:n,wait_reason:"source_not_ready"},metrics:{poll_attempt:t},status:"log"})}_logSlowPollingStart(t){this._options.runtime.log(`${this._actionPrefix}_slow_wait_start`,{context:{...this._buildContext(),poll_max_attempts:t.maxAttempts,slow_interval_ms:t.slowIntervalMs,slow_max_attempts:t.slowMaxAttempts,wait_reason:"source_not_ready"},metrics:{poll_max_attempts:t.maxAttempts},status:"log"})}_logSlowPollAttempt(t,n){this._options.runtime.log(`${this._actionPrefix}_slow_wait`,{context:{...this._buildContext(),slow_poll_attempt:t,slow_poll_max_attempts:n,wait_reason:"source_not_ready"},metrics:{slow_poll_attempt:t},status:"log"})}_throwIfAborted(t){if(t!=null&&t.aborted)throw Lt()}_buildContext(){let t=this._options.sourceOptions.sourceOptions;return{...xe(this._options.ref),image_variant:this._options.sourceOptions.imageVariant,media_type:this._options.sourceOptions.mediaType,purpose:this._options.sourceOptions.purpose,resolution:this._options.sourceOptions.resolution,source_device_pixel_ratio:t==null?void 0:t.devicePixelRatio,source_height:t==null?void 0:t.height,source_width:t==null?void 0:t.width,source_zoom:t==null?void 0:t.zoom,...this._options.sourceOptions.telemetry}}_buildRefreshContext(t,n={}){return{...this._buildContext(),refresh_reason:t.reason,source_version:t.sourceVersion,...n}}};function oA(e,t){return e!=null&&e.aborted?Promise.reject(Lt()):t<=0?Promise.resolve():new Promise((n,r)=>{let o=globalThis.setTimeout(()=>{e==null||e.removeEventListener("abort",s),n()},t),s=()=>{globalThis.clearTimeout(o),r(Lt())};e==null||e.addEventListener("abort",s,{once:!0})})}function Q1(e){if(!$1.has(e))throw new Error("Pippit asset source controller only supports image, video, and audio assets.")}function sA(e){let{runtime:t,sourceLeaseStore:n,transport:r}=e,o=(i,a)=>Yp({ref:K(i),runtime:t,sourceOptions:a,store:n,transport:r});return{createController:o,resolve:async(i,a,d={})=>{var u;let c=o(i,a);try{return d.cachePolicy==="refresh"?await c.refresh({reason:d.reason??"source_resolve_refresh",signal:d.signal,sourceVersion:(u=c.getCurrentSource())==null?void 0:u.version}):await c.getSource({inFlightLifetime:d.inFlightLifetime,signal:d.signal})}finally{c.dispose()}}}}function iA(e){return e.upload?e.upload:{async upload(){throw new Error("Pippit asset upload transport is not configured.")},resumeMode:"restart"}}function ud(e){let t=mo(e.logger),n=e.storage===!1?void 0:e.storage,r=new nd({context:{uid:e.uid,workspace:e.workspace,...e.telemetry??{}},logger:t,storage:n}),{transport:o}=e,s=iA(o),i=new go,a=sA({runtime:r,sourceLeaseStore:i,transport:o}),d=Jy({invalidateSources:p=>i.invalidate(p),runtime:r,transport:o}),c=tA(o),u=Ky({runtime:r,transport:s});return{assets:d,sources:a,diagnostics:{records:r.ledger},dispose:()=>{var p;i.dispose(),c.dispose(),(p=o.dispose)==null||p.call(o)},ids:c.module,upload:{createUploadTask:u.createUploadTask,uploadFile:(p,l)=>u.uploadFile(p,l)}}}var ld="AssetSnapshot",fd="AssetJsonUpdate",Z1=["audio","file","image","text","video"];function eU(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function tU(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function nU(e){return Z1.includes(e)?e:void 0}function pd(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Ir(e,...t){for(let n of t)if(n in e)return e[n]}function Kp(e,...t){let n=Ir(e,...t);return typeof n=="string"&&n.trim()?n.trim():void 0}function aA(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim()){let t=Number(e);return Number.isFinite(t)?t:void 0}}function rU(e){let t=Kp(e,"pippitAssetId","pippit_asset_id"),n=Kp(e,"assetId","asset_id"),r=nU(Kp(e,"mediaType","media_type"));if(!(!t&&!n))return K({...n?{assetId:n}:{},...r?{mediaType:r}:{},...t?{pippitAssetId:t}:{}})}function oU(e){return e===ld?"snapshot":e===fd||e==="message"?"update":e==="delete"||e==="AssetDelete"?"delete":"unknown"}function Xp(e,t){let n=eU(t),r=pd(n);if(!r)return;let o=pd(Ir(r,"data","Data")),s=pd(Ir(r,"assetEvent","asset_event"))??(o?pd(Ir(o,"assetEvent","asset_event")):void 0)??o??r,i=rU(s);if(i)return{content:tU(Ir(s,"content")),eventType:oU(e),raw:r,ref:i,startVersion:aA(Ir(s,"startVersion","start_version")),version:aA(Ir(s,"version","Version"))}}async function cA(e,t){let n=e.getReader(),r;for(;!(r=await n.read()).done;)t(r.value)}function uA(e){let t,n,r,o=!1;return function(i){t===void 0?(t=i,n=0,r=-1):t=sU(t,i);let a=t.length,d=0;for(;n<a;){o&&(t[n]===10&&(d=++n),o=!1);let c=-1;for(;n<a&&c===-1;++n)switch(t[n]){case 58:r===-1&&(r=n-d);break;case 13:o=!0;case 10:c=n;break}if(c===-1)break;e(t.subarray(d,c),r),d=n,r=-1}d===a?t=void 0:d!==0&&(t=t.subarray(d),n-=d)}}function pA(e,t,n){let r=dA(),o=new TextDecoder;return function(i,a){if(i.length===0)n==null||n(r),r=dA();else if(a>0){let d=o.decode(i.subarray(0,a)),c=a+(i[a+1]===32?2:1),u=o.decode(i.subarray(c));switch(d){case"data":r.data=r.data?r.data+`
|
|
2
|
+
`+u:u;break;case"event":r.event=u;break;case"id":e(r.id=u);break;case"retry":let p=parseInt(u,10);isNaN(p)||t(r.retry=p);break}}}}function sU(e,t){let n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n}function dA(){return{data:"",event:"",id:"",retry:void 0}}var iU=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n},md="text/event-stream",aU=1e3,lA="last-event-id";function $p(e,t){var{signal:n,headers:r,onopen:o,onmessage:s,onclose:i,onerror:a,openWhenHidden:d,fetch:c}=t,u=iU(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((p,l)=>{let f=Object.assign({},r);f.accept||(f.accept=md);let h;function m(){h.abort(),document.hidden||I()}d||document.addEventListener("visibilitychange",m);let g=aU,y=0;function v(){document.removeEventListener("visibilitychange",m),window.clearTimeout(y),h.abort()}n==null||n.addEventListener("abort",()=>{v(),p()});let S=c??window.fetch,b=o??dU;async function I(){var N;h=new AbortController;try{let w=await S(e,Object.assign(Object.assign({},u),{headers:f,signal:h.signal}));await b(w),await cA(w.body,uA(pA(ne=>{ne?f[lA]=ne:delete f[lA]},ne=>{g=ne},s))),i==null||i(),v(),p()}catch(w){if(!h.signal.aborted)try{let ne=(N=a==null?void 0:a(w))!==null&&N!==void 0?N:g;window.clearTimeout(y),y=window.setTimeout(I,ne)}catch(ne){v(),l(ne)}}}I()})}function dU(e){let t=e.headers.get("content-type");if(!(t!=null&&t.startsWith(md)))throw new Error(`Expected content-type to be ${md}, Actual: ${t}`)}var cU="/api/biz/v1/asset/sse_asset",uU=["message",ld,fd],Wp={ADD:1,DEL:2};async function Qp(e){let t=await e,n=t&&typeof t=="object"?t:{},r=Number(n.ret??0);if(Number.isNaN(r)||r!==0)throw new Error(typeof n.errmsg=="string"?n.errmsg:"Pippit asset subscription failed.")}var Jp=class{constructor(t){this._options=t;this._closed=!1;this._desiredPippitAssetIds=new Set;this._isFlushing=!1;this._isOpen=!1;this._needsFlush=!1;this._subscribedPippitAssetIds=new Set}sync(t){this._desiredPippitAssetIds.clear();for(let n of t)n.pippitAssetId&&this._desiredPippitAssetIds.add(n.pippitAssetId);this._scheduleFlush()}open(){this._isOpen=!0,this._scheduleFlush()}suspend(){this._isOpen=!1,this._subscribedPippitAssetIds.clear()}async close(){if(this._closed)return;this._closed=!0,this._isOpen=!1,this._desiredPippitAssetIds.clear(),await this._flushTask;let t=[...this._subscribedPippitAssetIds];this._subscribedPippitAssetIds.clear(),t.length&&this._options.subscribeAsset&&await Qp(this._options.subscribeAsset({action_type:Wp.DEL,pippit_asset_ids:t,session_id:this._options.sessionId})).catch(this._options.onError)}_scheduleFlush(){if(this._closed||!this._isOpen||!this._options.subscribeAsset||(this._needsFlush=!0,this._isFlushing))return;let t=this._flush().catch(n=>{var r,o;return(o=(r=this._options).onError)==null?void 0:o.call(r,n)});this._flushTask=t,t.finally(()=>{this._flushTask===t&&(this._flushTask=void 0)})}async _flush(){this._isFlushing=!0;try{for(;this._needsFlush&&!this._closed&&this._isOpen&&this._options.subscribeAsset;){this._needsFlush=!1;let t=new Set(this._desiredPippitAssetIds);await this._syncAddedSubscriptions(t),await this._syncRemovedSubscriptions(t)}}finally{this._isFlushing=!1,this._needsFlush&&!this._closed&&this._isOpen&&this._scheduleFlush()}}async _syncAddedSubscriptions(t){let n=[...t].filter(r=>!this._subscribedPippitAssetIds.has(r));!n.length||!this._options.subscribeAsset||(await Qp(this._options.subscribeAsset({action_type:Wp.ADD,pippit_asset_ids:n,session_id:this._options.sessionId})),n.forEach(r=>this._subscribedPippitAssetIds.add(r)))}async _syncRemovedSubscriptions(t){let n=[...this._subscribedPippitAssetIds].filter(r=>!t.has(r));!n.length||!this._options.subscribeAsset||(await Qp(this._options.subscribeAsset({action_type:Wp.DEL,pippit_asset_ids:n,session_id:this._options.sessionId})),n.forEach(r=>this._subscribedPippitAssetIds.delete(r)))}};function pU(e,t){return(typeof e=="function"?e(t):e)??cU}function fA(e,t){return typeof e=="function"?e(t):e??{}}function lU(e,t){return typeof e=="string"?e:JSON.stringify({session_id:t,...e??{}})}function fU(e,t){let n=fA(e,t),r=lU(n.body,t.sessionId);return{body:r,credentials:n.withCredentials?"include":void 0,headers:{...r&&typeof r=="string"?{"content-type":"application/json"}:{},...n.headers??{}},method:n.method??"POST"}}function mU(e){let t=e.headers.get("content-type");if(!e.ok)throw new Error(`Failed to open Pippit asset event source: ${e.status} ${e.statusText}`);if(t&&!t.startsWith("text/event-stream"))throw new Error(`Unexpected Pippit asset event source content-type: ${t}`)}function hU(e,t){return e==="PING"||e==="ping"?!1:(t??uU).includes(e||"message")}function gU(){var t;return`pippit_asset_session_${typeof((t=globalThis.crypto)==null?void 0:t.randomUUID)=="function"?globalThis.crypto.randomUUID():`${Date.now()}_${Math.random().toString(36).slice(2)}`}`}function hd(e){var a,d;let t=((a=e.createSessionId)==null?void 0:a.call(e))??gU(),n={sessionId:t},r=new AbortController,o=new Jp({onError:e.onError,sessionId:t,subscribeAsset:e.subscribeAsset}),s=!1,i=0;return(d=e.onConnectionChange)==null||d.call(e,"connecting"),e.signal&&(e.signal.aborted?r.abort():e.signal.addEventListener("abort",()=>r.abort(),{once:!0})),o.sync(e.refs),$p(pU(e.url,n),{...fU(e.init,n),openWhenHidden:fA(e.init,n).openWhenHidden??!0,signal:r.signal,onopen:c=>{var u;return mU(c),i=0,o.open(),(u=e.onConnectionChange)==null||u.call(e,"open"),Promise.resolve()},onmessage:c=>{if(!hU(c.event,e.eventTypes))return;let u=Xp(c.event||"message",c.data);u&&e.onEvent(u)},onclose:()=>{var c;if(o.suspend(),!s)throw(c=e.onConnectionChange)==null||c.call(e,"reconnecting"),new Error("Pippit asset event source closed.")},onerror:c=>{var p,l,f;o.suspend(),(p=e.onError)==null||p.call(e,c),i+=1;let u=e.maxReconnectAttempts??10;if(i>u)throw(l=e.onConnectionChange)==null||l.call(e,"closed"),c;return(f=e.onConnectionChange)==null||f.call(e,"reconnecting"),Math.min(1e3*2**Math.max(i-1,0),1e4)}}).catch(c=>{var u,p;!s&&!r.signal.aborted&&((u=e.onConnectionChange)==null||u.call(e,"closed"),(p=e.onError)==null||p.call(e,c))}),{close:()=>{var c;s=!0,(c=e.onConnectionChange)==null||c.call(e,"closed"),o.close().finally(()=>r.abort())},syncAssetRefs:c=>{o.sync(c)}}}function mA(e){return new Set(e.map(t=>{var n;return(n=t.pippitAssetId)==null?void 0:n.trim()}).filter(t=>!!t))}function Zp(e){let t=new Map,n=0,r,o=!1,s=()=>{let u=new Set;for(let p of t.values())p.refs.forEach(l=>u.add(l));return[...u].map(p=>({pippitAssetId:p}))},i=u=>{var p,l;for(let f of t.values())(l=(p=f.options).onConnectionChange)==null||l.call(p,u)},a=u=>{var p,l;for(let f of t.values())(l=(p=f.options).onError)==null||l.call(p,u)},d=()=>{var p;let u=s();if(!t.size){r==null||r.close(),r=void 0;return}if(!r){r=hd({...e,onConnectionChange:i,onError:a,onEvent:l=>{var h;let f=(h=l.ref.pippitAssetId)==null?void 0:h.trim();if(f)for(let m of t.values())m.refs.has(f)&&m.listener(l)},refs:u});return}(p=r.syncAssetRefs)==null||p.call(r,u)};return{dispose:()=>{o||(o=!0,t.clear(),r==null||r.close(),r=void 0)},subscribe:(u,p,l={})=>{var y,v;if(o)throw new Error("Pippit asset subscription hub is disposed.");if((y=l.signal)!=null&&y.aborted)return{close:()=>{},syncAssetRefs:()=>{}};let f=++n,h={listener:p,options:l,refs:mA(u)},m=!1,g=()=>{m||(m=!0,t.delete(f),d())};return t.set(f,h),(v=l.signal)==null||v.addEventListener("abort",g,{once:!0}),d(),{close:g,syncAssetRefs:S=>{m||o||(h.refs=mA(S),d())}}}}}var yo=e=>{let t=new Map;return e.map(K).forEach(n=>t.set(pt(n),n)),[...t.values()]};function gd(e){let t=new Map,n=yo(e.pinnedRefs??[]),r,o=!1,s=()=>yo([...n,...Array.from(t.values()).flat()]),i=()=>{var c,u;if(o)return;let d=s();if(!r){if(!d.length)return;try{r=e.onError?e.assets.subscribeAssetEvents(d,e.onEvent,{onError:e.onError}):e.assets.subscribeAssetEvents(d,e.onEvent)}catch(p){(c=e.onError)==null||c.call(e,p)}return}(u=r.syncAssetRefs)==null||u.call(r,d)},a=d=>{t.delete(d)&&i()};return{dispose:()=>{var d;o||(o=!0,t.clear(),n=[],(d=r==null?void 0:r.syncAssetRefs)==null||d.call(r,[]),r==null||r.close(),r=void 0)},getTrackedRefs:s,pin:d=>{n=yo(d),i()},release:a,set:(d,c)=>{o||(t.set(d,yo(c)),i())},track:(d,c=[])=>{t.set(d,yo(c)),i();let u=!1;return{dispose:()=>{u||(u=!0,a(d))},setRefs:p=>{!u&&!o&&(t.set(d,yo(p)),i())}}}}}var _r=e=>e&&typeof e=="object"&&!Array.isArray(e)?e:void 0,yd=(e,...t)=>{if(e)for(let n of t){let r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}},yU=e=>{let t=_r(e.raw),n=_r(t==null?void 0:t.data)??_r(t==null?void 0:t.Data);return{assetEvent:_r(t==null?void 0:t.assetEvent)??_r(t==null?void 0:t.asset_event)??_r(n==null?void 0:n.assetEvent)??_r(n==null?void 0:n.asset_event)??n??t,root:t}};function AU(e,t){let n=e.ref.pippitAssetId;if(!n||e.version===void 0)return;let{assetEvent:r,root:o}=yU(e);t({assetId:n,version:e.version,fromClientId:yd(r,"clientId","client_id")??yd(o,"clientId","client_id"),messageId:yd(o,"msgId","msg_id","messageId","message_id")??yd(r,"msgId","msg_id","messageId","message_id")})}function el(e){return{subscribe(t){let n=e.subscribeAssetEvents(t.assetIds.map(r=>({pippitAssetId:r})),r=>AU(r,t.onEvent),{onConnectionChange:t.onConnectionChange,onError:t.onError});return{close:n.close,syncAssetIds:r=>{var o;(o=n.syncAssetRefs)==null||o.call(n,r.map(s=>({pippitAssetId:s})))}}}}}var fn=class{constructor(){this._versions=new Map;this._listeners=new Map;this.getVersion=t=>this.get(t);this.getVersions=()=>this.snapshot();this.subscribe=(t,n)=>{let r=this._listeners.get(t)??new Set;return r.add(n),this._listeners.set(t,r),()=>{r.delete(n),r.size===0&&this._listeners.delete(t)}}}get(t){return this._versions.get(t)}remember(t,n){if(n===void 0||!Number.isFinite(n))return;let r=this._versions.get(t);if(r===void 0||n>r){this._versions.set(t,n);for(let o of Array.from(this._listeners.get(t)??[]))o(n)}}rememberAll(t){if(t)for(let[n,r]of Object.entries(t))this.remember(n,r)}hasNewerVersion(t,n){let r=this._versions.get(t);return r===void 0||n>r}snapshot(){return Object.fromEntries(this._versions)}clearListeners(){this._listeners.clear()}};var Ao=class extends Error{constructor(n){super(`Pippit asset version is unavailable for asset ${n}`);this.name="PippitAssetVersionUnavailableError",this.assetId=n}},Ys=class extends fn{getBaseVersion(t,n){if(n.patches.some(s=>s.assetId===t.assetId&&s.op==="add"&&s.path===""))return 0;let o=this.getVersion(t.assetId);if(o===void 0)throw new Ao(t.assetId);return o}};var yA=e=>!!(e&&typeof e=="object"&&!Array.isArray(e)),vd=e=>yA(e)?e:void 0,Ad=(e,...t)=>{for(let n of t)if(n in e)return e[n]},tl=(e,...t)=>{let n=Ad(e,...t);return typeof n=="string"&&n.trim()?n.trim():void 0},vU=e=>{if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"&&e.trim()){let t=Number(e);return Number.isFinite(t)?t:void 0}},hA=e=>{if(!yA(e))return;let t={};for(let[n,r]of Object.entries(e)){let o=vU(r);o!==void 0&&(t[n]=o)}return Object.keys(t).length?t:void 0},gA=(e,t)=>{let n={};for(let r of e)Object.assign(n,r[t]);return Object.keys(n).length?n:void 0},SU=(e,t,n)=>{var o;let r={...e};for(let s of t.envelopes)if(((o=n.get(s.txId))==null?void 0:o.status)==="ack")for(let i of s.patches)i.op==="add"&&i.path===""&&r[i.assetId]===void 0&&(r[i.assetId]=1);return Object.keys(r).length?r:void 0},bU=e=>e==="ack"||e==="skipped"||e==="reject"?e:"reject",IU=e=>{let t=vd(e)??{};return{transactionId:tl(t,"transaction_id","transactionId")??"",status:bU(Ad(t,"status")),assetVersions:hA(Ad(t,"asset_versions","assetVersions")),currentAssetVersions:hA(Ad(t,"current_asset_versions","currentAssetVersions")),blockedBy:tl(t,"blocked_by","blockedBy"),message:tl(t,"error","message")}},_U=e=>"envelopes"in e&&Array.isArray(e.envelopes)?e:{...e,txIds:[e.txId],patches:[...e.patches],status:"in-flight",envelopes:[{...e,patches:[...e.patches]}]};function nl(e,t){var r;let n=_U(e);return{batch:n,request:{batch_id:((r=t.createBatchId)==null?void 0:r.call(t,n))??`batch_${n.txId}`,client_id:t.clientId,root_pippit_asset_id:t.scopeAssetId,transactions:n.envelopes.map(o=>({transaction_id:o.txId,intent:o.intent,merge_key:o.mergeKey,attempt:o.attempt,enqueued_at:o.enqueuedAt,patches:o.patches.map(s=>({asset_id:s.assetId,base_asset_version:t.versionRegistry.getBaseVersion(s,o),op:s.op,path:s.path,...s.op==="remove"?{}:{value:s.value}}))}))}}}function RU(e){let t=vd(e)??{},n=Number(t.ret??0);if(Number.isNaN(n)||n!==0)throw new Error(typeof t.errmsg=="string"?t.errmsg:"Pippit asset patch failed")}function EU(e){return{status:"transport-error",error:new Error(`Pippit asset patch returned no result for transaction ${e}`)}}function rl(e,t){RU(e);let n=vd(e)??{},r=vd(n.data)??n,s=(Array.isArray(r.results)?r.results:[]).map(IU),i=new Map(s.map(l=>[l.transactionId,l])),a=t.txIds.map(l=>i.get(l)),d=t.txIds.find((l,f)=>!a[f]),c=SU(gA(s,"assetVersions"),t,i),u=gA(s,"currentAssetVersions");if(d)return{response:EU(d),assetVersions:c,currentAssetVersions:u};let p=a.findIndex(l=>(l==null?void 0:l.status)!=="ack");if(p>=0){let l=a[p],f=t.txIds.slice(0,p);return{response:{status:"reject",explicit:l.status==="reject",...f.length?{ackedTxIds:f}:{},...l.status==="reject"?{error:new Error(l.message??`Pippit asset patch rejected transaction ${l.transactionId}`)}:{}},assetVersions:c,currentAssetVersions:u}}return{response:{status:"ack",...t.txIds.length>1?{ackedTxIds:t.txIds}:{}},assetVersions:c,currentAssetVersions:u}}function AA(e){return new Set(e.map(t=>t.trim()).filter(Boolean))}function ol(e){let t=AA(e.assetIds??[]),n=!1,r=0,o=!1,s=new Map,i=new Set,a=c=>{!n&&e.versions.hasNewerVersion(c.assetId,c.version)&&e.onNewerEvent(c)},d=()=>{if(!(n||!o||r>0)){for(let c of s.values())a(c);s.clear()}};return{close:()=>{n||(n=!0,t.clear(),s.clear(),i.clear())},handleEvent:c=>{if(!(n||!t.has(c.assetId))){if(c.messageId){if(i.has(c.messageId))return;if(i.add(c.messageId),i.size>1e3){let u=i.values().next().value;u&&i.delete(u)}}if(!o||r>0){let u=s.get(c.assetId);(!u||c.version>=u.version)&&s.set(c.assetId,c);return}a(c)}},runVersionedLoad:async c=>{r+=1;try{return await c(u=>e.versions.rememberAll(u))}finally{r-=1,r===0&&(o=!0,d())}},syncAssetIds:c=>{t=AA(c);for(let u of s.keys())t.has(u)||s.delete(u)}}}var CU=e=>{let t=[],n=new Set,r=o=>{let s=o.trim();!s||n.has(s)||(n.add(s),t.push(s))};return e.forEach(r),t},sl=class{constructor(t){this.options=t;this.invalidateListeners=new Set;this.connectionListeners=new Set;this.abortController=new AbortController;this.subscription=null;this.closed=!1;this.commit=async t=>{if(("envelopes"in t?t.envelopes.reduce((r,o)=>r+o.patches.length,0):t.patches.length)===0){let r="txIds"in t?t.txIds:[t.txId];return{status:"ack",...r.length>1?{ackedTxIds:r}:{}}}try{let{batch:r,request:o}=nl(t,{scopeAssetId:this.options.scopeAssetId,clientId:this.clientId,versionRegistry:this.versions,createBatchId:this.options.createBatchId}),s=await this.options.batchPatchAsset(o),i=rl(s,r);return this.versions.rememberAll(i.assetVersions),i.response}catch(r){if(r instanceof Ao)return this.logger.warn("[pippit-asset-sdk:sync:pippit] missing base asset version",{assetId:r.assetId}),{status:"transport-error",error:r,retryable:!0,requiresResync:!0};let o=r instanceof Error?r:new Error(String(r));return this.logger.error("[pippit-asset-sdk:sync:pippit] commit failed",o,{scopeAssetId:this.options.scopeAssetId,txId:t.txId}),{status:"transport-error",error:o}}};this.fetchSnapshot=t=>this.eventReconciler.runVersionedLoad(async n=>{let r=t==null?void 0:t.onProgress,o=await this.options.loader.fetchSnapshot({scopeAssetId:this.options.scopeAssetId,signal:this.abortController.signal,...r?{onProgress:s=>{try{r(s)}catch(i){this.logger.warn("[pippit-asset-sdk:sync:pippit] snapshot progress observer failed",{error:i instanceof Error?i.message:String(i),scopeAssetId:this.options.scopeAssetId})}}}:{}});return n(o.assetVersions),{state:o.state}});this.fetchAssets=t=>this.eventReconciler.runVersionedLoad(async()=>{let n=await this.options.loader.fetchAssets({scopeAssetId:this.options.scopeAssetId,requests:t,signal:this.abortController.signal});return{assets:n.assets.map(r=>({...r,assetVersion:r.assetVersion??n.assetVersions[r.assetId]}))}});this.onInvalidate=t=>(this.invalidateListeners.add(t),this.openSubscription(),()=>{this.invalidateListeners.delete(t)});this.onConnectionChange=t=>(this.connectionListeners.add(t),()=>{this.connectionListeners.delete(t)});this.getConnectionState=()=>this.connectionState;this.syncAssetSubscriptions=t=>{var n;this.assetIds=CU(t),this.eventReconciler.syncAssetIds(this.assetIds),(n=this.subscription)==null||n.syncAssetIds(this.assetIds)};this.getDebugAssetVersions=()=>this.versions.snapshot();this.close=()=>{var t;this.closed||(this.closed=!0,this.invalidateListeners.clear(),this.eventReconciler.close(),(t=this.subscription)==null||t.close(),this.subscription=null,this.abortController.abort(),this.versions.clearListeners(),this.setConnectionState("closed"))};this.clientId=t.clientId,this.versions=new Ys,this.assetIds=[],this.connectionState=t.assetEventSource?"closed":"open",this.logger=mo(t.logger),this.eventReconciler=ol({assetIds:this.assetIds,versions:this.versions,onNewerEvent:n=>{this.emitInvalidate({scopedAssetId:n.assetId,assetVersion:n.version,fromClientId:n.fromClientId})}})}get assetVersions(){return this.versions}openSubscription(){this.closed||this.subscription||!this.options.assetEventSource||(this.subscription=this.options.assetEventSource.subscribe({assetIds:this.assetIds,clientId:this.clientId,onConnectionChange:t=>{this.setConnectionState(t==="open"?"open":"closed")},onError:t=>{this.logger.error("[pippit-asset-sdk:sync:pippit] asset event source error",t,{scopeAssetId:this.options.scopeAssetId})},onEvent:t=>{this.eventReconciler.handleEvent(t)}}))}emitInvalidate(t){for(let n of Array.from(this.invalidateListeners))n(t)}setConnectionState(t){if(this.connectionState!==t){this.connectionState=t;for(let n of Array.from(this.connectionListeners))n(t)}}};function Sd(e){return new sl(e)}function il(e){let t=ud(e),n=new Set,r=!1,o=()=>{if(r)throw new Error("Pippit asset runtime is disposed.")};return{client:t,createSubscriptionTracker:s=>{o();let i=gd({...s,assets:t.assets});return n.add(i),i},createSyncTransport:s=>{var i;if(o(),!((i=e.sync)!=null&&i.batchPatchAsset))throw new Error("Pippit asset runtime sync transport is not configured.");return Sd({...s,assetEventSource:e.transport.subscribeAssetEvents?el(t.assets):void 0,batchPatchAsset:e.sync.batchPatchAsset})},dispose:()=>{r||(r=!0,n.forEach(s=>s.dispose()),n.clear(),t.dispose())}}}function R(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function ye(e){return Array.isArray(e)?e:void 0}function Ks(e){return typeof e=="string"&&e.trim().length>0}function E(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function oe(e){let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:void 0}function mn(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function bt(e){let t={};return e.assetId&&(t.assetId=e.assetId),e.pippitAssetId&&(t.pippitAssetId=e.pippitAssetId),t.assetId||t.pippitAssetId?t:void 0}function al(e,t){let n=e==null?void 0:e.audio;if(!n)return;let r=n.downloadUrl||n.previewUrl;if(!r)return;let o=e.assetId??e.pippitAssetId??"audio";return{identity:bt({assetId:e.assetId,pippitAssetId:e.pippitAssetId}),metadata:{assetId:e.assetId,downloadUrl:n.downloadUrl,durationMs:n.durationMs,mimeType:n.mimeType,name:n.name,pippitAssetId:e.pippitAssetId,size:n.size},preview:{metadata:{durationMs:n.durationMs,format:n.mimeType,name:n.name,size:n.size},raw:e.raw,type:"audio",urls:{download:n.downloadUrl??r,high:r,low:r,medium:r,url:r}},url:r,version:`${o}:${t.purpose}:${mn(r)}`}}var vA={WEB_DOMAIN:{online:"https://xyq.jianying.com",internal:""},CDN_DOMAIN:{cdnDomain:"https://lf-xiaoyunque.jianying.com",scmStorage:"https://lf-xiaoyunque.jianying.com/obj/pippit-app-buz/xiaoyunque_web"},TOS:{HOST:["https://lf-xiaoyunque.jianying.com"],cmsStaticAssetBaseUrl:"https://p11-xiaoyunque.byteimg.com/tos-cn-i-men7yzdrs1",resultUrlSuffix:{image:"~tplv-men7yzdrs1-webp.webp",video:"~tplv-men7yzdrs1-image.image"}},CMS:{baseUrl:""},SLARDAR:{appxpcode:"",bid:"xiaoyunque_web",pluginPathPrefix:"https://lf3-short.ibytedapm.com/slardar/fe/sdk-web/plugins",domain:"mon.zijieapi.com",sdkUrl:"https://lf3-short.ibytedapm.com/slardar/fe/sdk-web/browser.cn.js",region:"cn",reportUrl:"https://mon.zijieapi.com/monitor_browser/collect/batch/security/"},AGENT_CONNECT:{commandLine:"npx @pippit-dev/cli@latest install"},FIREBASE:{apiKey:"AIzaSyAh-sSmkqiMoEBYLy7yxkaKSCniBUpB6ts"},ASSETS:{entries:{"pippit-role":{path:"https://lf-xiaoyunque.jianying.com/obj/pippit-app-buz/xiaoyunque_web/novel_3d_director/pippit-role.glb"}}},SDK:{canvas:{capcutDownloadUrl:"https://www.capcut.cn/"},novel:{legacyImageOriginHostname:"everphoto-media.jianying.com"},pippitAsset:{imagePreviewBlockedUrlPatterns:["(?:^|/)everphoto-capcut-enc(?:-[^/?#]+)?(?:/|$)","^https://everphoto-media\\.jianying\\.com/download/bucket(?:/|$)"]}}};var dl="https://sf16-web-login-neutral.capcutstatic.com",bd=`${dl}/obj/capcut-web-login-static/ies/pippit/scm_storage`,PU={WEB_DOMAIN:{online:"https://www.pippit.ai"},CDN_DOMAIN:{cdnDomain:dl,scmStorage:bd},TOS:{HOST:[dl],cmsStaticAssetBaseUrl:"https://p16-capcut-sg.capcut.com/tos-alisg-i-hk1xnajzr6-sg",resultUrlSuffix:{image:"~tplv-hk1xnajzr6-webp.webp",video:"~tplv-hk1xnajzr6-image.image"}},CMS:{baseUrl:""},ARGUS_SDK:`${bd}/sdk/secsdk/sg/runtime_bundler_476.js`,SLARDAR:{appxpcode:"lvoverseas_web",bid:"capcut_business",pluginPathPrefix:`${bd}/sdk/slardar-sdk-web/plugins`,sdkUrl:`${bd}/sdk/browser.1.14.1.sg.js`,region:"i18n",domain:"mon-sg.capcutapi.com",reportUrl:"https://mon-sg.capcutapi.com/monitor_browser/collect/batch/security/"},BASE_DOMAIN:{feedAPIDomain:"https://feed-api.capcut.com"},AGENT_CONNECT:{commandLine:"npx skills add https://github.com/Pippit-dev/pippit-skills.git --skill pippit-skill -y -g"},ASSETS:{entries:{"pippit-role":{path:["https://lf-xiaoyunque.","jianying.com/obj/pippit-app-buz/xiaoyunque_web/novel_3d_director/pippit-role.glb"].join("")}}},SDK:{canvas:{capcutDownloadUrl:"https://www.capcut.com/tools/desktop-video-editor"},pippitAsset:{imagePreviewBlockedUrlPatterns:["(?:^|/)everphoto-capcut-enc(?:-[^/?#]+)?(?:/|$)"]}}},SA=PU;var cl="https://sf16-web-tos-buz.capcutcdn-us.com",bA=`${cl}/obj/capcut-web-buz-tx/ies/pippit/scm_storage`,xU={WEB_DOMAIN:{online:"https://www.pippit.ai"},CDN_DOMAIN:{cdnDomain:cl,scmStorage:bA},TOS:{HOST:[cl],cmsStaticAssetBaseUrl:"https://p16-capcut-sg-useast5.capcutcdn-us.com/tos-useast5-i-hk1xnajzr6-tx",resultUrlSuffix:{image:"~tplv-hk1xnajzr6-webp.webp",video:"~tplv-hk1xnajzr6-image.image"}},CMS:{baseUrl:""},SLARDAR:{appxpcode:"lvoverus_web",bid:"capcut_business",sdkUrl:"https://lf16-cdn-tos.tiktokcdn-us.com/obj/static-tx/slardar/fe/sdk-web/browser.1.14.1.oci.js",pluginPathPrefix:`${bA}/sdk/slardar-sdk-web/plugins`,region:"ttp",domain:"mon16-normal-us-ttp.capcutapi.us",reportUrl:"https://mon16-normal-us-ttp.capcutapi.us/monitor_browser/collect/batch/security/"},BASE_DOMAIN:{feedAPIDomain:"https://feed.us.capcut.com"},AGENT_CONNECT:{commandLine:""},ASSETS:{entries:{"pippit-role":{path:["https://lf-xiaoyunque.","jianying.com/obj/pippit-app-buz/xiaoyunque_web/novel_3d_director/pippit-role.glb"].join("")}}},SDK:{canvas:{capcutDownloadUrl:"https://www.capcut.com/tools/desktop-video-editor"},pippitAsset:{imagePreviewBlockedUrlPatterns:["(?:^|/)everphoto-capcut-enc(?:-[^/?#]+)?(?:/|$)"]}}},IA=xU;var vo=process.env.IS_US==="true"?IA:process.env.IS_OVERSEA==="true"?SA:vA;async function _A(e,t,n,r={}){if(!t)return;let o=E(t.asset_id??t.assetId),s=e;if(r.strictAssetId&&o&&o!==s)throw new Error(`Resolved assetId ${o} does not match requested assetId ${s}.`);let i=await kU(t,n.purpose,n.videoVariant,r);if(!i)return;let a=DU(t),d=await pl(r,t,"cover_url","cover_key"),c=await TU(t,r),u={durationMs:oe(t.duration_ms),format:E(t.format),height:oe(t.height),name:E(t.name)??o??s,size:oe(t.size),spriteFrames:c,width:oe(t.width)};return{encryptKey:MU(t),identity:bt({assetId:s}),metadata:{assetId:s,downloadUrl:a,...u,poster:d},preview:{metadata:u,raw:t,type:"video",urls:{download:a??i,high:i,low:i,medium:i,poster:d,url:i}},url:i,version:`${s}:${mn(i)}`}}async function TU(e,t){let n=NU(e),r=wU(n);if(!(r!=null&&r.length))return;let o=(await Promise.all(r.map(i=>OU(i,t)))).filter(i=>!!i);if(!o.length)return;let s=R((n==null?void 0:n.common_info)??(n==null?void 0:n.commonInfo));return{frameCount:oe((s==null?void 0:s.total_set_num)??(s==null?void 0:s.totalSetNum)),frameHeight:oe((s==null?void 0:s.single_frame_height)??(s==null?void 0:s.singleFrameHeight)),frameWidth:oe((s==null?void 0:s.single_frame_width)??(s==null?void 0:s.singleFrameWidth)),images:o}}function NU(e){let t=R(e.video_meta_info??e.videoMetaInfo);return R(e.sprite_frame??e.spriteFrame)??R((t==null?void 0:t.sprite_frame)??(t==null?void 0:t.spriteFrame))}function wU(e){return[e==null?void 0:e.image_list,e==null?void 0:e.imageList,e==null?void 0:e.detail_infos,e==null?void 0:e.detailInfos].find(n=>Array.isArray(n))}async function OU(e,t){let n=R(e),r=await pl(t,n,"url","encrypted_key");if(r)return{encryptKey:E((n==null?void 0:n.encrypted_key)??(n==null?void 0:n.encryptKey)),frameCount:oe((n==null?void 0:n.frame_count)??(n==null?void 0:n.frameCount)),height:oe(n==null?void 0:n.height),url:r,width:oe(n==null?void 0:n.width)}}function ul(e,t){var i,a;let n=e==null?void 0:e.video;if(!n)return;let r=t.purpose==="download"?t.videoVariant?(i=n.downloadVariants)==null?void 0:i[t.videoVariant]:n.downloadUrl:t.videoVariant?(a=n.previewVariants)==null?void 0:a[t.videoVariant]:n.previewUrl;if(!r)return;let o=e.assetId??e.pippitAssetId??"video",s={durationMs:n.durationMs,fps:n.fps,height:n.height,spriteFrames:n.spriteFrames,width:n.width};return{identity:bt({assetId:e.assetId,pippitAssetId:e.pippitAssetId}),metadata:{assetId:e.assetId,downloadUrl:n.downloadUrl,...s,pippitAssetId:e.pippitAssetId,poster:n.coverUrl},preview:{metadata:s,raw:e.raw,type:"video",urls:{download:n.downloadUrl??r,high:r,low:r,medium:r,poster:n.coverUrl,url:r}},refreshOnSourceError:!0,url:r,version:`${o}:${t.purpose}:${mn(r)}`}}function RA(e){let t=R(e.no_watermark_video_url??e.noWatermarkVideoUrl);return Fn([t==null?void 0:t.origin_cover_url,t==null?void 0:t.originCoverUrl,e.origin_cover_url,e.originCoverUrl])}function DU(e){let t=R(e.no_watermark_video_url);return Fn([e.download_url,t==null?void 0:t.download_url,e.origin_url])}function ke(e,t){let n=R(e[`preview_video_${t}`]??e[`previewVideo${t}`]);return(n==null?void 0:n.preview_url)??(n==null?void 0:n.previewUrl)??(n==null?void 0:n.download_url)??(n==null?void 0:n.downloadUrl)}async function kU(e,t,n,r){let o=R(e.no_watermark_video_url);if(t==="download")return Fn(n==="watermark"?[e.download_url]:n==="notWatermark"?[o==null?void 0:o.download_url,e.origin_url,o==null?void 0:o.preview_url,e.download_url]:[e.download_url,o==null?void 0:o.download_url,e.preview_url,e.preview_url_720p,ke(e,"720p"),e.preview_url_1080p,ke(e,"1080p"),e.preview_url_480p,ke(e,"480p"),e.preview_url_360p,ke(e,"360p")]);if(n==="watermark")return Fn([e.preview_url_720p,ke(e,"720p"),e.preview_url_1080p,ke(e,"1080p"),e.preview_url_480p,ke(e,"480p"),e.preview_url_360p,ke(e,"360p"),e.preview_url]);if(n==="notWatermark")return Fn([o==null?void 0:o.preview_url,o==null?void 0:o.download_url,e.origin_url,e.preview_url_720p,ke(e,"720p"),e.preview_url_1080p,ke(e,"1080p"),e.preview_url_480p,ke(e,"480p"),e.preview_url_360p,ke(e,"360p"),e.preview_url]);let s=Fn([e.preview_url_720p,ke(e,"720p"),e.preview_url_1080p,ke(e,"1080p"),e.preview_url_480p,ke(e,"480p"),e.preview_url_360p,ke(e,"360p"),e.preview_url,o==null?void 0:o.preview_url]);return s||await pl(r,e.encrypt_preview_url,"url","key")}function Fn(e){for(let t of e){let n=E(t);if(n)return n}}function MU(e){let t=n=>{let r=R(e[`preview_video_${n}`]??e[`previewVideo${n}`]);return(r==null?void 0:r.preview_key)??(r==null?void 0:r.previewKey)};return E(e.preview_key_720p)??E(t("720p"))??E(e.preview_key_1080p)??E(t("1080p"))??E(e.preview_key_480p)??E(t("480p"))??E(e.preview_key_360p)??E(t("360p"))??E(e.preview_key)}async function pl(e,t,n,r){let o=R(t),s=E(o==null?void 0:o[n]);if(!s)return;let i=E(o==null?void 0:o[r]);return!i||!e.resolveEncryptedUrl?s:await e.resolveEncryptedUrl({key:i,url:s})??s}var LU=["360p","480p","720p","1080p","2048p","origin"];function LA(e,t){return GA(e,GU(t))}function BA(e,t){return GA(e,BU(t))}function BU(e){if(e!=null&&e.assetId)return{assetId:e.assetId,...e.mediaType?{mediaType:e.mediaType}:{},preferRequestedAssetId:!0}}function GU(e){if(e!=null&&e.mediaType)return{mediaType:e.mediaType,pippitAssetId:e.pippitAssetId}}function GA(e,t){let n=UU(e),r=zU(e,n,t==null?void 0:t.mediaType),o=VU(e,n,r),s=E(e.pippit_asset_id??e.pippitAssetId??e.PippitAssetID)??(t==null?void 0:t.pippitAssetId);return{assetId:HU(e,n,r,t),audio:n.audio?xA({...e,...n.audio}):r==="audio"?xA(o):void 0,extra:fl(e.extra??e.Extra),file:n.file?NA(n.file):r==="file"?NA(o):void 0,image:n.image?EA(n.image):r==="image"?EA(o):void 0,mediaType:r,metadata:fl(e.metadata??e.Metadata),pippitAssetId:s,playerInfoVersion:oe(e.player_info_version??e.playerInfoVersion??e.PlayerInfoVersion),raw:e,text:n.text?TA(n.text):r==="text"?TA(o):void 0,video:n.video?PA(n.video):r==="video"?PA(o):void 0,version:oe(e.version??e.Version??e.asset_version??e.assetVersion)}}function fl(e){let t=R(e);if(t)return t;if(!(typeof e!="string"||!e.trim()))try{return R(JSON.parse(e))}catch{return}}function UU(e){return{audio:R(e.Audio)??R(e.audio),file:R(e.File)??R(e.FileInfo)??R(e.file)??R(e.fileInfo),image:R(e.Image)??R(e.image),text:R(e.Text)??R(e.TextInfo)??R(e.text)??R(e.textInfo),video:R(e.Video)??R(e.video)}}function zU(e,t,n){if(n)return n;let r=qU(e.media_type??e.mediaType??e.asset_type??e.type);if(r)return r;let o=FU(e.AssetType??e.assetType??(jU(e)?e.asset_type:void 0));if(o)return o;if(t.audio&&DA(t.audio))return"audio";if(t.video&&OA(t.video))return"video";if(t.image&&wA(t.image))return"image";if(t.text&&kA(t.text))return"text";if(t.file&&MA(t.file))return"file";if(DA(e))return"audio";if(OA(e))return"video";if(wA(e))return"image";if(kA(e))return"text";if(MA(e))return"file"}function qU(e){var n;let t=(n=E(e))==null?void 0:n.toLowerCase();if(t){if(t.includes("audio")||t.includes("music"))return"audio";if(t.includes("video"))return"video";if(t.includes("image")||t.includes("photo")||t.includes("picture"))return"image";if(t.includes("text"))return"text";if(t.includes("file")||t.includes("document"))return"file"}}function FU(e){let t=typeof e=="number"?e:Number(E(e));if(Number.isFinite(t)){if(t===1)return"image";if(t===2)return"video";if(t===3)return"audio";if(t===4)return"text";if(t===5)return"file"}}function jU(e){return!!(e.PippitAssetID||e.pippit_asset_id||e.pippitAssetId||e.AssetSourceType||e.asset_source_type)}function VU(e,t,n){return n==="audio"?t.audio?{...e,...t.audio}:e:n==="video"?t.video??e:n==="image"?t.image??e:n==="text"?t.text??e:n==="file"?t.file??e:e}function So(e){return E((e==null?void 0:e.asset_id)??(e==null?void 0:e.assetId)??(e==null?void 0:e.AssetID))}function HU(e,t,n,r){if(r!=null&&r.preferRequestedAssetId&&r.assetId)return r.assetId;let o=E(e.asset_id??e.assetId),s=n?So(t[n]):void 0,i=E(e.SourceID??e.source_id??e.sourceId);return o??s??So(t.image)??So(t.video)??So(t.audio)??So(t.text)??So(t.file)??((r==null?void 0:r.mediaType)==="audio"?i:void 0)??(r==null?void 0:r.assetId)}function EA(e){let t=ll(e,"default"),n={default:YU(e),notWatermark:KU(e),watermark:XU(e)},r=E(e.url),o=UA(e);return{download:Id(n.default,e,o),downloadVariants:{default:Id(n.default,e,o),notWatermark:Id(n.notWatermark,e,o),watermark:Id(n.watermark,e,o)},provisionalPreview:r?{url:r}:void 0,previews:t,previewVariants:{default:t,notWatermark:ll(e,"notWatermark"),watermark:ll(e,"watermark")}}}function Id(e,t,n){return e?{format:zA(void 0,void 0,n),height:qA(void 0,void 0,n,t),size:jA(void 0,void 0,n,t),url:e,width:FA(void 0,void 0,n,t)}:void 0}function ll(e,t){let n={},r=UA(e);for(let o of LU){let s=WU(e,o,t),i=CA(It(s))??CA(QU(e,o));if(i){let a=$U(s);n[o]={format:zA(s,a,r),height:qA(s,a,r,e),size:jA(s,a,r,e),url:i,width:FA(s,a,r,e)}}}return n}function CA(e){return e?vo.SDK.pippitAsset.imagePreviewBlockedUrlPatterns.some(n=>new RegExp(n,"i").test(e))?void 0:e:void 0}function YU(e){var t;return E(e.download_url)??E(e.url)??E(e.dowmload_url)??E(e.DownloadURL)??It($s(R(e.not_watermark_preview)))??It(Xs(R(e.not_watermark_preview)))??E((t=R(e.not_watermark_preview))==null?void 0:t.url)??It($s(R(e.download_preview)))??It(Xs(R(e.download_preview)))??E(e.downsample_url)}function KU(e){let t=R(e.not_watermark_preview),n=R(e.download_preview);return E(e.url)??E(e.dowmload_url)??E(e.DownloadURL)??It($s(t))??It(Xs(t))??E(t==null?void 0:t.url)??It($s(n))??It(Xs(n))??E(e.downsample_url)??E(e.download_url)}function XU(e){let t=R(e.watermark_preview);return E(e.download_url)??It($s(t))??It(Xs(t))??E(t==null?void 0:t.url)}function UA(e){return R(e.metadata)??R(e.Metadata)}function $U(e){return R(e==null?void 0:e.metadata)??R(e==null?void 0:e.Metadata)}function It(e){return E((e==null?void 0:e.preview_url)??(e==null?void 0:e.previewUrl)??(e==null?void 0:e.PreviewURL)??(e==null?void 0:e.url)??(e==null?void 0:e.URL))}function zA(e,t,n){return E((t==null?void 0:t.format)??(t==null?void 0:t.Format)??(t==null?void 0:t.fileFormat)??(t==null?void 0:t.FileFormat)??(e==null?void 0:e.format)??(e==null?void 0:e.Format)??(n==null?void 0:n.format)??(n==null?void 0:n.Format)??(n==null?void 0:n.fileFormat)??(n==null?void 0:n.FileFormat))}function qA(e,t,n,r){return oe((t==null?void 0:t.height)??(t==null?void 0:t.Height)??(e==null?void 0:e.height)??(e==null?void 0:e.Height)??(n==null?void 0:n.height)??(n==null?void 0:n.Height)??(r==null?void 0:r.height)??(r==null?void 0:r.Height))}function FA(e,t,n,r){return oe((t==null?void 0:t.width)??(t==null?void 0:t.Width)??(e==null?void 0:e.width)??(e==null?void 0:e.Width)??(n==null?void 0:n.width)??(n==null?void 0:n.Width)??(r==null?void 0:r.width)??(r==null?void 0:r.Width))}function jA(e,t,n,r){return oe((t==null?void 0:t.size)??(t==null?void 0:t.Size)??(e==null?void 0:e.size)??(e==null?void 0:e.Size)??(n==null?void 0:n.size)??(n==null?void 0:n.Size)??(r==null?void 0:r.size)??(r==null?void 0:r.Size))}function WU(e,t,n){let r=R(e.not_watermark_preview),o=R(e.watermark_preview),s=[R(e.download_preview),R(e.compliance_preview),R(e.brand_preview),R(e.dynamic_preview),R(e.fusion_preview),R(e.share_preview)];if(t==="origin"){let d=R(e.previewinfo)??R(e.preview_info)??R(e.PreviewInfo),c=s.map(u=>R(u==null?void 0:u.previewinfo)).find(Boolean);return n==="watermark"?R(o==null?void 0:o.previewinfo)??d??R(r==null?void 0:r.previewinfo)??c:R(r==null?void 0:r.previewinfo)??d??R(o==null?void 0:o.previewinfo)??c}let i=R(e[`previewinfo_${t}`])??R(e[`preview_info_${t}`])??R(e[`preview_${t}`])??R(e[`preview_video_${t}`])??R(e[VA(t)]),a=s.map(d=>hn(d,t)).find(Boolean);return n==="watermark"?hn(o,t)??i??hn(r,t)??a:hn(r,t)??i??hn(o,t)??a}function hn(e,t){return R(e==null?void 0:e[`previewinfo_${t}`])??R(e==null?void 0:e[`preview_info_${t}`])??R(e==null?void 0:e[`preview_${t}`])??R(e==null?void 0:e[VA(t)])}function Xs(e){return hn(e,"2048p")??hn(e,"1080p")??hn(e,"720p")??hn(e,"480p")??R(e==null?void 0:e.previewinfo)??R(e==null?void 0:e.preview_info)??R(e==null?void 0:e.PreviewInfo)}function $s(e){return R(e==null?void 0:e.previewinfo)??R(e==null?void 0:e.preview_info)??R(e==null?void 0:e.PreviewInfo)}function VA(e){return`PreviewInfo_${e.toUpperCase()}`}function QU(e,t){return t==="origin"?E(e.preview_url??e.previewUrl??e.PreviewURL??e.downsample_url):E(e[`preview_url_${t}`]??e[`previewUrl_${t}`]??e[`PreviewURL_${t.toUpperCase()}`]??e[`url_${t}`]??e[`URL_${t.toUpperCase()}`])}function PA(e){let t=R(e.no_watermark_video_url??e.noWatermarkVideoUrl),n=R(e.metadata),r=fl(e.extra??e.Extra),o=E(e.downloadUrl)??E(e.download_url),s=E(e.originUrl)??E(e.origin_url)??E(t==null?void 0:t.downloadUrl)??E(t==null?void 0:t.download_url),i=E(e.previewUrl)??E(e.preview_url),a=E(t==null?void 0:t.previewUrl)??E(t==null?void 0:t.preview_url)??E(e.originPreviewUrl)??E(e.origin_preview_url),d=a??E(e.previewUrl_720p)??E(e.preview_url_720p)??E(e.previewUrl_1080p)??E(e.preview_url_1080p)??E(e.previewUrl_480p)??E(e.preview_url_480p)??i??s??o;return{coverUrl:RA(e)??E(e.coverUrl)??E(e.cover_url),draftKey:E(e.draftKey??e.draft_key??e.DraftKey??(r==null?void 0:r.draftKey)??(r==null?void 0:r.draft_key)),downloadUrl:s??o,downloadVariants:{notWatermark:s,watermark:o},durationMs:oe(e.durationMs??e.duration_ms??(n==null?void 0:n.durationMs)??(n==null?void 0:n.duration_ms)),extra:r,fps:oe(e.fps??(n==null?void 0:n.fps)),height:oe(e.height??(n==null?void 0:n.height)),packageId:E(e.packageID??e.packageId??e.package_id??e.PackageID??(r==null?void 0:r.packageID)??(r==null?void 0:r.packageId)??(r==null?void 0:r.package_id)),previewUrl:d,previewVariants:{notWatermark:a,watermark:i},spriteFrames:JU(e),renderTaskId:E(e.renderTaskID??e.renderTaskId??e.render_task_id??e.RenderTaskID??(r==null?void 0:r.renderTaskID)??(r==null?void 0:r.renderTaskId)??(r==null?void 0:r.render_task_id)),width:oe(e.width??(n==null?void 0:n.width))}}function JU(e){let t=ye(e.sprite_info??e.spriteInfo??e.SpriteInfo);if(!(t!=null&&t.length))return;let n=t.map(ZU);if(n.some(i=>!i))return;let r=n,[{frameHeight:o,frameWidth:s}]=r;if(!r.some(i=>i.frameHeight!==o||i.frameWidth!==s))return{frameCount:r.reduce((i,a)=>i+a.image.frameCount,0),frameHeight:o,frameWidth:s,images:r.map(i=>i.image)}}function ZU(e){let t=R(e),n=Rr((t==null?void 0:t.sprite_num)??(t==null?void 0:t.spriteNum)),r=Rr((t==null?void 0:t.image_height)??(t==null?void 0:t.imageHeight)),o=Rr((t==null?void 0:t.image_width)??(t==null?void 0:t.imageWidth)),s=Rr((t==null?void 0:t.canvas_height)??(t==null?void 0:t.canvasHeight)),i=Rr((t==null?void 0:t.canvas_width)??(t==null?void 0:t.canvasWidth)),a=Rr((t==null?void 0:t.image_x_num)??(t==null?void 0:t.imageXNum)),d=Rr((t==null?void 0:t.image_y_num)??(t==null?void 0:t.imageYNum)),c=E((t==null?void 0:t.url)??(t==null?void 0:t.URL));if(!(!n||!r||!o||!s||!i||!a||!d||!c)&&!(n>a*d||i!==o*a||s!==r*d))return{frameHeight:r,frameWidth:o,image:{frameCount:n,height:s,url:c,width:i}}}function Rr(e){let t=oe(e);return t!==void 0&&Number.isInteger(t)&&t>0?t:void 0}function xA(e){return{downloadUrl:E(e.download_url??e.origin_url),durationMs:oe(e.duration_ms),mimeType:E(e.mime_type??e.mimeType??e.format),name:E(e.name??e.Name),previewUrl:E(e.preview_url??e.download_url??e.origin_url),size:oe(e.size)}}function TA(e){return{content:E(e.content??e.text),downloadUrl:E(e.download_url),mimeType:E(e.mime_type??e.mimeType),name:E(e.name),previewUrl:E(e.preview_url??e.origin_url),size:oe(e.size)}}function NA(e){return{downloadUrl:E(e.download_url??e.origin_url??e.internal_url),extension:E(e.extension??e.ext),format:E(e.format),mimeType:E(e.mime_type??e.mimeType),name:E(e.name),previewUrl:E(e.preview_url),size:oe(e.size)}}function wA(e){return!!(e.url||e.preview_url||e.download_url||e.dowmload_url||e.DownloadURL||e.downsample_url||e.PreviewURL||e.URL||e.previewinfo||e.PreviewInfo||e.previewinfo_720p||e.PreviewInfo_720P||e.previewinfo_1080p||e.PreviewInfo_1080P||e.previewinfo_480p||e.PreviewInfo_480P||e.previewinfo_2048p||e.PreviewInfo_2048P||e.not_watermark_preview||e.watermark_preview||e.download_preview||e.compliance_preview||e.brand_preview||e.dynamic_preview||e.fusion_preview||e.share_preview)}function OA(e){return!!(e.preview_url||e.download_url||e.origin_url||e.internal_url||e.preview_url_720p||e.preview_url_1080p||e.preview_url_480p||e.no_watermark_video_url||e.preview_key_720p||e.vid||e.render_task_id)}function DA(e){var r,o;let t=(r=E(e.mime_type??e.mimeType))==null?void 0:r.toLowerCase(),n=(o=E(e.format))==null?void 0:o.toLowerCase();return!!(t!=null&&t.startsWith("audio/")||["mp3","wav","aac","m4a","ogg"].includes(n??"")||e.audio_url||e.preview_url||e.download_url||e.origin_url||e.internal_url)}function kA(e){var n;let t=(n=E(e.mime_type??e.mimeType))==null?void 0:n.toLowerCase();return!!(t!=null&&t.startsWith("text/")||e.text||e.content||e.download_url)}function MA(e){return!!(e.download_url||e.origin_url||e.name)}function _d(e){let t=R(e),n=R(t==null?void 0:t.data),r=ye(t==null?void 0:t.assets)??ye(n==null?void 0:n.assets)??ye(t==null?void 0:t.Assets)??ye(n==null?void 0:n.Assets)??ye(t==null?void 0:t.AgentAsset)??ye(n==null?void 0:n.AgentAsset)??ye(t==null?void 0:t.agentAsset)??ye(n==null?void 0:n.agentAsset)??ye(t==null?void 0:t.asset_list);return HA(r)}function Ws(e){let t=R(e),n=R(t==null?void 0:t.data),r=ye(t==null?void 0:t.asset_infos)??ye(n==null?void 0:n.asset_infos)??ye(t==null?void 0:t.assets)??ye(n==null?void 0:n.assets)??ye(t==null?void 0:t.data);return HA(r)}function HA(e){return(e??[]).map(R).filter(Boolean)}var ez=200,tz=20;function YA(e){if((e==null?void 0:e.reason)!==void 0)return e.reason;let t=new Error("Pippit asset info caller aborted");return t.name="AbortError",t}function KA(){let e=new Error("Pippit asset info coordinator disposed");return e.name="AbortError",e}function XA(e,t){return Number.isFinite(e)&&Number(e)>0?Math.max(1,Math.floor(Number(e))):t}function $A(e){return[...new Set(e.map(t=>t.trim()).filter(Boolean))]}function nz(e){return[(e==null?void 0:e.cachePolicy)??"default",e!=null&&e.refresh?"refresh":"default",(e==null?void 0:e.mediaType)??"",(e==null?void 0:e.purpose)??""].join(":")}function ml(e){e.timer&&(clearTimeout(e.timer),e.timer=void 0)}function Rd(e,t){var n;e.settled||(e.settled=!0,(n=e.cleanupAbort)==null||n.call(e),t.status==="rejected"?e.reject(t.error):e.resolve(t.response))}function rz(e,t){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function oz(e){return E(e.asset_id??e.assetId)}function sz(e,t){let n=new Map,r=new Set,o=0;return e.forEach(s=>{let i=oz(s);!i||!t.includes(i)||r.has(i)||(o+=1,r.add(i),n.set(i,s))}),o===0&&e.length===t.length&&e.forEach((s,i)=>{let a=t[i];a&&n.set(a,s)}),n}function WA(e,t={}){let n=XA(t.batchDelayMs,ez),r=XA(t.maxBatchSize,tz),o=new Map,s=new Set,i=!1,a=async c=>{var h;let u=o.get(c);if(!u)return;o.delete(c),ml(u),s.add(u);let p=u.callers.filter(m=>!m.settled),l=$A(p.flatMap(m=>m.ids));if(!l.length){s.delete(u);return}let f={...(h=p[0])==null?void 0:h.options,signal:u.abortController.signal};try{let m=await Promise.all(rz(l,r).map(async y=>{let v=await e({asset_ids:y},f);return sz(Ws(v),y)})),g=new Map;m.forEach(y=>y.forEach((v,S)=>g.set(S,v))),p.forEach(y=>Rd(y,{response:{asset_infos:y.ids.map(v=>g.get(v)).filter(v=>!!v)},status:"resolved"}))}catch(m){p.forEach(g=>Rd(g,{error:m,status:"rejected"}))}finally{s.delete(u)}},d=(c,u)=>new Promise((p,l)=>{let f=nz(u),h=o.get(f),m=h??{abortController:new AbortController,callers:[]},g={ids:c,options:u,reject:l,resolve:p,settled:!1};m.callers.push(g);let y=u==null?void 0:u.signal;if(y){let S=()=>{Rd(g,{error:YA(y),status:"rejected"}),m.callers.every(b=>b.settled)&&(o.get(f)===m&&(o.delete(f),ml(m)),m.abortController.abort())};g.cleanupAbort=()=>y.removeEventListener("abort",S),y.addEventListener("abort",S,{once:!0}),y.aborted&&S()}if(g.settled)return;h||o.set(f,m),(u==null?void 0:u.dispatchMode)==="immediate"?a(f):h||(m.timer=setTimeout(()=>void a(f),n))});return{dispose:()=>{if(i)return;i=!0;let c=KA(),u=new Set([...o.values(),...s]);o.clear(),u.forEach(p=>{ml(p),p.abortController.abort(),p.callers.forEach(l=>Rd(l,{error:c,status:"rejected"}))}),s.clear()},query:(c,u)=>{var l;if(i)return Promise.reject(KA());if((l=u==null?void 0:u.signal)!=null&&l.aborted)return Promise.reject(YA(u.signal));let p=$A(c.asset_ids);return p.length?d(p,u):Promise.resolve({asset_infos:[]})}}}var iz=["origin",...ho.filter(e=>e!=="origin")];function JA(e,t){var n,r,o;return((r=(n=e==null?void 0:e.image)==null?void 0:n.previewVariants)==null?void 0:r[t])??((o=e==null?void 0:e.image)==null?void 0:o.previews)}function ZA(e,t){var n,r,o;return((r=(n=e==null?void 0:e.image)==null?void 0:n.downloadVariants)==null?void 0:r[t])??((o=e==null?void 0:e.image)==null?void 0:o.download)}function Qs(e,t,n){let r=JA(e,n);if(r)for(let o of t){let s=r[o];if(s!=null&&s.url)return s}}function az(e,t,n){var a,d;let r=Qs(e,rd,t),o=Qs(e,od,t),s=Qs(e,ho,t),i=Qs(e,[n],t)??o??s??r;if(i)return{metadata:{format:i.format??(s==null?void 0:s.format)??(o==null?void 0:o.format)??(r==null?void 0:r.format),height:i.height??(s==null?void 0:s.height)??(o==null?void 0:o.height)??(r==null?void 0:r.height),imageVariant:t,size:i.size??(s==null?void 0:s.size)??(o==null?void 0:o.size)??(r==null?void 0:r.size),width:i.width??(s==null?void 0:s.width)??(o==null?void 0:o.width)??(r==null?void 0:r.width)},raw:e==null?void 0:e.raw,type:"image",urls:{download:((a=ZA(e,t))==null?void 0:a.url)??((d=Qs(e,["origin",...ho],t))==null?void 0:d.url)??(s==null?void 0:s.url)??i.url,high:(s==null?void 0:s.url)??(o==null?void 0:o.url)??(r==null?void 0:r.url)??i.url,low:(r==null?void 0:r.url)??(o==null?void 0:o.url)??(s==null?void 0:s.url)??i.url,medium:(o==null?void 0:o.url)??(s==null?void 0:s.url)??(r==null?void 0:r.url)??i.url,url:i.url}}}function dz(e,t,n){let r=(e==null?void 0:e.assetId)??(e==null?void 0:e.pippitAssetId)??"image",{url:o}=n;return{identity:bt({assetId:e==null?void 0:e.assetId,pippitAssetId:e==null?void 0:e.pippitAssetId}),isProvisional:!0,metadata:{assetId:e==null?void 0:e.assetId,format:n.format,height:n.height,imageVariant:t,pippitAssetId:e==null?void 0:e.pippitAssetId,resolution:"origin",size:n.size,width:n.width},preview:{metadata:{format:n.format,height:n.height,imageVariant:t,size:n.size,width:n.width},raw:e==null?void 0:e.raw,type:"image",urls:{url:o}},url:o,version:`${r}:origin:${t}:provisional:${mn(o)}`}}function cz(e){var o,s,i;let t=(o=e==null?void 0:e.video)==null?void 0:o.coverUrl;if(!t)return;let n=(e==null?void 0:e.assetId)??(e==null?void 0:e.pippitAssetId)??"video-cover",r={height:(s=e==null?void 0:e.video)==null?void 0:s.height,width:(i=e==null?void 0:e.video)==null?void 0:i.width};return{identity:bt({assetId:e==null?void 0:e.assetId,pippitAssetId:e==null?void 0:e.pippitAssetId}),metadata:{assetId:e==null?void 0:e.assetId,...r,pippitAssetId:e==null?void 0:e.pippitAssetId,resolution:"origin"},preview:{metadata:r,raw:e==null?void 0:e.raw,type:"image",urls:{download:t,high:t,low:t,medium:t,poster:t,url:t}},url:t,version:`${n}:video-cover:${mn(t)}`}}function QA(e,t,n,r,o){let s=(e==null?void 0:e.assetId)??(e==null?void 0:e.pippitAssetId)??"image";return{identity:bt({assetId:e==null?void 0:e.assetId,pippitAssetId:e==null?void 0:e.pippitAssetId}),metadata:{assetId:e==null?void 0:e.assetId,format:r==null?void 0:r.format,height:r==null?void 0:r.height,imageVariant:t,pippitAssetId:e==null?void 0:e.pippitAssetId,resolution:n,size:r==null?void 0:r.size,width:r==null?void 0:r.width},preview:az(e,t,n),url:o,version:`${s}:${n}:${t}:${mn(o)}`}}function ev(e,t){var a,d;let n=t.imageVariant??"default",r=JA(e,n),o=ZA(e,n);if(t.purpose==="download"&&(o!=null&&o.url))return QA(e,n,"origin",o,o.url);let s=t.purpose==="download"?iz:Ly(t);for(let c of s){let u=(a=r==null?void 0:r[c])==null?void 0:a.url;if(u)return QA(e,n,c,r==null?void 0:r[c],u)}let i=(d=e==null?void 0:e.image)==null?void 0:d.provisionalPreview;return t.purpose==="preview"&&n==="default"&&(i!=null&&i.url)?dz(e,n,i):cz(e)}function nv(e){return e?{createAsset:async t=>{if(e.createAsset)return e.createAsset(t);let n=await uz(e,t),r=await hl(e,{intent:"asset.create",patches:[{baseVersion:0,op:"add",path:"",ref:n,value:hz(t)}],signal:t.signal});return{raw:r.raw,ref:n,version:tv(r,n)}},patchAssets:async t=>e.patchAssets?e.patchAssets(t):hl(e,t),updateAsset:async(t,n)=>{let r=K(t);if(e.updateAsset)return e.updateAsset(r,n);let o=await hl(e,{intent:n.intent??"asset.update",patches:pz(r,n),signal:n.signal,transactionId:n.transactionId});return{raw:o.raw,ref:r,version:tv(o,r)}}}:{}}async function uz(e,t){if(t.ref)return K(t.ref);if(!e.batchGeneratePippitAssetIds)throw new Error("Pippit asset create requires request.ref or batchGeneratePippitAssetIds.");let n=await e.batchGeneratePippitAssetIds({count:1}),r=gz(n);if(!r)throw new Error("Pippit asset ID generation returned no usable pippitAssetId.");return K({mediaType:t.mediaType,pippitAssetId:r})}function pz(e,t){var n;return(n=t.patches)!=null&&n.length?t.patches.map(r=>({...r,ref:K(r.ref)})):[{op:"replace",path:"",ref:e,value:t.content??{metadata:t.metadata}}]}async function hl(e,t){var s,i;if(!e.batchPatchAsset)throw new Error("Pippit asset batchPatchAsset transport is not configured.");let n=lz(t),r=n.transactionId||`asset_patch_${Date.now()}`,o=await e.batchPatchAsset({batch_id:n.batchId||`batch_${r}`,client_id:n.clientId||`client_${r}`,root_pippit_asset_id:((s=n.rootRef)==null?void 0:s.pippitAssetId)??((i=n.patches[0])==null?void 0:i.ref.pippitAssetId),transactions:[{attempt:1,enqueued_at:Date.now(),intent:n.intent,patches:n.patches.map(fz),transaction_id:r}]});return rv(o,"Pippit asset patch failed."),{raw:o,versions:yz(o,r)}}function lz(e){return{...e,patches:e.patches.map(t=>({...t,ref:K(t.ref)})),rootRef:e.rootRef?K(e.rootRef):void 0}}function fz(e){return{asset_id:mz(e.ref),base_asset_version:e.baseVersion,op:e.op,path:e.path,...e.op==="remove"?{}:{value:e.value}}}function mz(e){return e.pippitAssetId??e.assetId}function hz(e){return e.content!==void 0?e.content:{mediaType:e.mediaType,metadata:e.metadata}}function tv(e,t){var r;let n=t.pippitAssetId??t.assetId;return n?(r=e.versions)==null?void 0:r[n]:void 0}function gz(e){rv(e,"Pippit asset ID generation failed.");let t=R(e),n=R(t==null?void 0:t.data),r=ye(n==null?void 0:n.ids)??ye(t==null?void 0:t.ids),o=r==null?void 0:r.find(Ks);return o==null?void 0:o.trim()}function rv(e,t){let n=R(e),r=Number((n==null?void 0:n.ret)??0);if(Number.isNaN(r)||r!==0)throw new Error(typeof(n==null?void 0:n.errmsg)=="string"?n.errmsg:t)}function yz(e,t){let n=R(e),r=R(n==null?void 0:n.data),o=ye(r==null?void 0:r.results)??ye(n==null?void 0:n.results),s=o==null?void 0:o.find(c=>{let u=R(c);return(u==null?void 0:u.transaction_id)===t||(u==null?void 0:u.transactionId)===t}),i=R(s)??R(o==null?void 0:o[0]),a=R(i==null?void 0:i.asset_versions)??R(i==null?void 0:i.assetVersions);if(!a)return;let d={};for(let[c,u]of Object.entries(a)){let p=oe(u);p!==void 0&&(d[c]=p)}return Object.keys(d).length?d:void 0}function ov(e){return Number.isFinite(e)&&e>0?Math.max(1,Math.floor(e)):1}function gn(e,t,n){if(e.length===0)return[];let r=ov(t),o=ov(n),s=Math.ceil(e.length/r),i=Math.min(e.length,Math.max(s,o)),a=Math.floor(e.length/i),d=e.length%i,c=[],u=0;for(let p=0;p<i;p+=1){let l=a+(p<d?1:0);c.push(e.slice(u,u+l)),u+=l}return c}var Az=200,vz=150,Sz=20,bz=2,Iz=500,Ed=()=>{let e=new Error("Pippit asset query coordinator disposed");return e.name="AbortError",e},gl=e=>{e.timer&&(clearTimeout(e.timer),e.timer=void 0)},Cd=e=>{if((e==null?void 0:e.reason)!==void 0)return e.reason;let t=new Error("Pippit asset query caller aborted");return t.name="AbortError",t},Js=(e,t)=>{var n;e.settled||(e.settled=!0,(n=e.cleanupAbort)==null||n.call(e),t.status==="rejected"?e.reject(t.error):e.resolve(t.records))},sv=(e,t,n,r,o,s)=>new Promise((i,a)=>{let{cacheKey:d,queueKey:c}=t,u={ids:n,options:r,reject:a,resolve:i,settled:!1},p=e.get(c),l=p??{abortController:new AbortController,cacheKey:d,callers:[]};l.callers.push(u);let f=r==null?void 0:r.signal;if(f){let h=()=>{Js(u,{error:Cd(f),status:"rejected"}),l.callers.every(m=>m.settled)&&(e.get(c)===l&&(gl(l),e.delete(c)),l.abortController.abort())};u.cleanupAbort=()=>f.removeEventListener("abort",h),f.addEventListener("abort",h,{once:!0}),f.aborted&&h()}if(!u.settled){if(p){(r==null?void 0:r.dispatchMode)==="immediate"&&(gl(p),s.flush(e,c,o));return}if(e.set(c,l),(r==null?void 0:r.dispatchMode)==="immediate")return void s.flush(e,c,o);l.timer=setTimeout(()=>void s.flush(e,c,o),s.batchDelayMs)}}),Pd=e=>e===null||typeof e!="object"?JSON.stringify(e):Array.isArray(e)?`[${e.map(Pd).join(",")}]`:`{${Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>`${JSON.stringify(t)}:${Pd(n)}`).join(",")}}`,iv=e=>E(e.pippit_asset_id??e.pippitAssetId??e.PippitAssetID),av=(e,t)=>(e==null?void 0:e.batchingStrategy)??t.batchingStrategy??"max-size",_z=(e,t)=>Pd({batchingStrategy:t,cacheKey:e}),Rz=(e,t)=>{let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},Ez=(e,t,n,r)=>t==="balanced"?gn(e,n,r):Rz(e,Math.max(1,n)),Cz=e=>{let t=n=>{let r={pippit_asset_ids:n};return(typeof e.bodyExtra=="function"?e.bodyExtra(r):e.bodyExtra)??{}};return{bodyExtraFor:t,cacheKeyFor:n=>Pd({bodyExtra:t(n),scopeKey:e.scopeKey})}};function xd(e,t={}){let n=new Map,r=new Map,o=new Map,s=new Map,i=new Set,a=t.batchDelayMs??Az,d=t.cacheTtlMs??Iz,c=t.maxBatchSize??vz,u=t.maxAttempts??bz,p=t.maxConcurrentChunks??Sz,l=Cz(t),f=0,h=0,m=!1,g=[],y=async Y=>{var T;if(m||(f>=p&&await new Promise(F=>g.push(F)),m))throw Ed();f+=1;try{return await Y()}finally{f-=1,(T=g.shift())==null||T()}},v=(Y,T)=>Ez(Y,av(T,t),c,p),S=(Y,T)=>{let F=Date.now(),j=[];for(let J of Y){let ie=`${T}:${J}`,Se=o.get(ie);if(!Se||Se.expiresAt<=F)return o.delete(ie),{complete:!1,records:[]};Se.record&&j.push(Se.record)}return{complete:!0,records:j}},b=async(Y,T)=>{var J,ie;let F={...l.bodyExtraFor(Y),pippit_asset_ids:Y},j;for(let Se=1;Se<=Math.max(1,u);Se+=1){if((J=T==null?void 0:T.signal)!=null&&J.aborted)throw Cd(T.signal);try{return _d(await e(F,T))}catch(He){if((ie=T==null?void 0:T.signal)!=null&&ie.aborted)throw Cd(T.signal);j=He}}throw j},I=async(Y,T,F)=>{let j=h,J=Date.now(),ie=new Map,Se=[],He=[];Y.forEach(re=>{let St=`${T}:${re}`,We=o.get(St);if(We&&We.expiresAt>J){We.record&&ie.set(re,We.record);return}o.delete(St);let pn=s.get(St);if(pn){Se.push(pn.then(Ue=>{Ue&&ie.set(re,Ue)}));return}He.push(re)});let ge=v(He,F).map(async re=>{let We=y(()=>b(re,F)).then(Ue=>{let Qe=new Map;return Ue.forEach(Mt=>{let ut=iv(Mt);ut&&Qe.set(ut,Mt)}),Qe});re.forEach(Ue=>{let Qe=`${T}:${Ue}`,Mt=We.then(Fs=>Fs.get(Ue)??null);s.set(Qe,Mt);let ut=()=>{s.get(Qe)===Mt&&s.delete(Qe)};Mt.then(ut,ut)});let pn=await We;re.forEach(Ue=>{let Qe=pn.get(Ue)??null;!m&&h===j&&o.set(`${T}:${Ue}`,{expiresAt:Date.now()+d,record:Qe}),Qe&&ie.set(Ue,Qe)})});return await Promise.all([...ge,...Se]),ie},N=async(Y,T,F)=>{let j=h,J=new Map;return await Promise.all(v(Y,F).map(async ie=>{let Se=await y(()=>b(ie,F)),He=new Map;Se.forEach(ge=>{let re=iv(ge);re&&He.set(re,ge)}),ie.forEach(ge=>{let re=He.get(ge)??null;!m&&h===j&&o.set(`${T}:${ge}`,{expiresAt:Date.now()+d,record:re}),re&&J.set(ge,re)})})),J},w=async(Y,T,F)=>{var He;let j=Y.get(T);if(!j)return;Y.delete(T),i.add(j);let J=j.callers.filter(ge=>!ge.settled),ie=[...new Set(J.flatMap(ge=>ge.ids))],Se={...(He=J[0])==null?void 0:He.options,signal:j.abortController.signal};try{let ge=await F(ie,j.cacheKey,Se);J.forEach(re=>Js(re,{records:re.ids.map(St=>ge.get(St)).filter(St=>!!St),status:"resolved"}))}catch(ge){J.forEach(re=>Js(re,{error:ge,status:"rejected"}))}finally{i.delete(j)}},ne=()=>{h+=1,o.clear(),s.clear()};return{clear:ne,dispose:()=>{if(m)return;m=!0,h+=1;let Y=Ed();[n,r].forEach(T=>{T.forEach(F=>{gl(F),F.abortController.abort(),F.callers.forEach(j=>Js(j,{error:Y,status:"rejected"}))}),T.clear()}),i.forEach(T=>{T.abortController.abort(),T.callers.forEach(F=>Js(F,{error:Y,status:"rejected"}))}),o.clear(),s.clear(),g.splice(0).forEach(T=>T())},invalidate:ne,query:(Y,T)=>{var Se;if(m)return Promise.reject(Ed());if((Se=T==null?void 0:T.signal)!=null&&Se.aborted)return Promise.reject(Cd(T.signal));let F=[...new Set(Y.map(He=>He.trim()).filter(Boolean))];if(!F.length)return Promise.resolve([]);let j=l.cacheKeyFor(F),J=_z(j,av(T,t));if((T==null?void 0:T.cachePolicy)==="refresh")return sv(r,{cacheKey:j,queueKey:J},F,T,N,{batchDelayMs:a,flush:w});let ie=S(F,j);return ie.complete?Promise.resolve(ie.records):sv(n,{cacheKey:j,queueKey:J},F,T,I,{batchDelayMs:a,flush:w})}}}function yl({assetInfo:e,assetQuery:t,mgetAssetInfo:n,mutation:r,query:o,resolveEncryptedUrl:s,shouldUseAssetQuerySource:i,subscription:a,upload:d}){let c=nv(r),u=t&&o?xd(t,o):void 0,p=u?(m,g)=>u.query(m.pippit_asset_ids,g).then(y=>({data:{Assets:y},ret:0})):t,l=n&&e!==!1?WA(n,e):void 0,f=l?(m,g)=>l.query(m,g):n,h=a?Zp(a):void 0;return{...c,allocateAssetIds:r!=null&&r.batchGeneratePippitAssetIds?async m=>{var g;return xz(await((g=r.batchGeneratePippitAssetIds)==null?void 0:g.call(r,{count:m})),m)}:void 0,dispose:()=>{l==null||l.dispose(),u==null||u.dispose(),h==null||h.dispose()},invalidateAssets:()=>u==null?void 0:u.invalidate(),async queryAssets(m,g){let y=await Td(m,{assetQuery:p},g),v=m.filter(I=>Tz(I,y)),S=await uv(v,{mgetAssetInfo:f},g),b=m.map(I=>{if(I.pippitAssetId){let N=y.get(I.pippitAssetId);return N?(Nd(I,N),N):dv(I,S)}return dv(I,S)}).filter(I=>!!I);return Promise.all(b.map(I=>Pz(I,g)))},async resolveSource(m,g){if(g.mediaType==="image"){let v=await cv(m,{assetQuery:p,mgetAssetInfo:f},g),S=ev(v,g);if(S!=null&&S.isProvisional&&g.allowProvisionalImage===!1)throw new ze("Public image preview is not ready yet.");if(!S)throw new ze("No image source URL found yet.");return S}if(g.mediaType==="audio"){let v=await cv(m,{assetQuery:p,mgetAssetInfo:f},g),S=al(v,g);if(!S)throw new ze("No audio source URL found yet.");return S}if(g.mediaType!=="video")throw new Error(`Source resolution for ${g.mediaType} assets is not supported.`);let y=await Dz(m,g,{assetQuery:p,mgetAssetInfo:f,resolveEncryptedUrl:s,shouldUseAssetQuerySource:i});if(!y)throw new ze("No video source URL found yet.");return y},subscribeAssetEvents:h?(m,g,y)=>h.subscribe(m,g,y):void 0,upload:d}}async function Pz(e,t){var r,o;if(e.mediaType!=="text"||(r=e.text)!=null&&r.content||!((o=e.text)!=null&&o.downloadUrl))return e;let n=await fetch(e.text.downloadUrl,{signal:t.signal});if(!n.ok)throw new Error(`Failed to download Pippit text asset: ${n.status} ${n.statusText}`);return{...e,text:{...e.text,content:await n.text()}}}function xz(e,t){let n=e&&typeof e=="object"?e:void 0,r=Number((n==null?void 0:n.ret)??0);if(Number.isNaN(r)||r!==0)throw new Error(typeof(n==null?void 0:n.errmsg)=="string"?n.errmsg:"Pippit asset ID generation failed.");let o=n!=null&&n.data&&typeof n.data=="object"&&!Array.isArray(n.data)?n.data:void 0,i=(Array.isArray(o==null?void 0:o.ids)?o.ids:Array.isArray(n==null?void 0:n.ids)?n.ids:[]).filter(a=>typeof a=="string"&&!!a.trim());if(i.length<t)throw new Error(`Pippit asset ID generation returned ${i.length}/${t} IDs.`);return i}function Tz(e,t){return e.assetId?e.pippitAssetId?!t.has(e.pippitAssetId):!0:!1}function dv(e,t){return e.assetId?t.get(e.assetId):void 0}async function Td(e,t,n){let r=pv(e.map(s=>s.pippitAssetId).filter(Ks));if(!r.length)return new Map;if(!t.assetQuery){if(e.filter(s=>s.pippitAssetId).every(s=>s.assetId))return new Map;throw new Error("assetQuery is not configured.")}let o=await t.assetQuery({pippit_asset_ids:r},n);return new Map(_d(o).map(s=>{let i=Nz(s),a=e.find(d=>d.pippitAssetId===i);return LA(s,a)}).filter(s=>s.pippitAssetId).map(s=>[s.pippitAssetId,s]))}function Nz(e){return E(e.pippit_asset_id??e.pippitAssetId??e.PippitAssetID)}async function uv(e,t,n){let r=e.filter(d=>Ks(d.assetId)),o=pv(r.map(d=>d.assetId));if(!o.length)return new Map;if(!t.mgetAssetInfo){if(r.every(d=>d.pippitAssetId))return new Map;throw new Error("mgetAssetInfo is not configured.")}let s=await t.mgetAssetInfo({asset_ids:o},n),i=Ws(s),a=Oz(i,r);return new Map(i.map((d,c)=>{let u=a[c],p=BA(d,u),l=(u==null?void 0:u.assetId)??p.assetId;return l?[l,p]:void 0}).filter(d=>!!d))}function wz(e){return typeof e.asset_id=="string"&&e.asset_id.trim()?e.asset_id.trim():typeof e.assetId=="string"&&e.assetId.trim()?e.assetId.trim():void 0}function Oz(e,t){let n=e.map(()=>{}),r=new Set,o=0;return e.forEach((i,a)=>{let d=wz(i);if(!d)return;let c=t.findIndex((u,p)=>!r.has(p)&&u.assetId===d);c>=0&&(r.add(c),n[a]=t[c],o+=1)}),o===0&&e.length===t.length&&e.forEach((i,a)=>{n[a]=t[a]}),n}function pv(e){return Array.from(new Set(e))}async function Dz(e,t,n){return kz(e)&&Mz(t,n)&&await Lz(e,t,n)?Bz(e,t,n):zz(e,t,n)}function kz(e){return!!e.pippitAssetId}function Mz(e,t){return!e.refresh&&!!(t.assetQuery&&t.shouldUseAssetQuerySource)}async function Lz(e,t,n){var r,o;try{return!!await((r=n.shouldUseAssetQuerySource)==null?void 0:r.call(n,{options:t,ref:e}))}catch(s){if((o=t.signal)!=null&&o.aborted)throw s;return!1}}async function Bz(e,t,n){let r=await Uz(e,t,n),o=lv(r)?void 0:ul(r,t);if(jz(o,t))return Zs(o,r);let s=Gz(e,r);return s?fv(e,s,t,n,r??hv(e)):o?Zs(o,r):void 0}function lv(e){return(e==null?void 0:e.playerInfoVersion)!==1}function Gz(e,t){return lv(t)?e.assetId??(t==null?void 0:t.assetId):(t==null?void 0:t.assetId)??e.assetId}async function Uz(e,t,n){var r;try{let s=(await Td([e],n,t)).get(e.pippitAssetId);return s&&Nd(e,s),s}catch(o){if((r=t.signal)!=null&&r.aborted)throw o;return}}async function zz(e,t,n){if(e.assetId){let s=await mv(e.assetId,t,n);return Vz(s,hv(e))}let r=await Fz(e,t,n);if(r!=null&&r.assetId)return fv(e,r.assetId,t,n,r,{strictAssetId:!0});let o=t.purpose==="download"?ul(r,t):void 0;if(o)return Zs(o,r);throw!e.pippitAssetId||!n.assetQuery?new Error("resolveSource requires assetId or assetQuery with pippitAssetId."):t.purpose==="preview"?new ze("AssetQuery did not return an asset_id for source resolution."):new Error("AssetQuery did not return an asset_id for source resolution.")}async function fv(e,t,n,r,o,s={}){let i=qz(e,t,n);try{let a=await mv(t,n,r,s);if(!a&&i)throw Vp(new ze("No video source URL found yet."),i);return a&&Zs(a,o)}catch(a){throw!i||!Gt(a)||cd(a)?a:Vp(a,i)}}function qz(e,t,n){if(!(e.assetId||!e.pippitAssetId||n.mediaType!=="video"||n.purpose!=="preview"))return{assetId:t,mediaType:"video",pippitAssetId:e.pippitAssetId}}async function Fz(e,t,n){if(!e.pippitAssetId||!n.assetQuery)return;let o=(await Td([e],n,t)).get(e.pippitAssetId);return o&&Nd(e,o),o}function jz(e,t){var n,r;return e?t.purpose==="download"||!!((r=(n=e.preview)==null?void 0:n.urls)!=null&&r.poster):!1}async function mv(e,t,n,r={}){if(!n.mgetAssetInfo)throw new Error("mgetAssetInfo is not configured.");let o=await n.mgetAssetInfo({asset_ids:[e]},t),s=Ws(o)[0];if(!s)throw t.purpose==="preview"?new ze("No video asset info found yet."):new Error("Pippit asset info was not found.");return _A(e,s,t,{resolveEncryptedUrl:n.resolveEncryptedUrl,strictAssetId:r.strictAssetId})}async function cv(e,t,n){if(e.pippitAssetId&&t.assetQuery){let s=(await Td([e],t,n)).get(e.pippitAssetId);if(s)return Nd(e,s),s}return e.assetId?(await uv([e],t,n)).get(e.assetId):void 0}function Nd(e,t){if(e.pippitAssetId&&t.pippitAssetId&&e.pippitAssetId!==t.pippitAssetId)throw new Error(`Resolved pippitAssetId ${t.pippitAssetId} does not match requested pippitAssetId ${e.pippitAssetId}.`);if(!e.pippitAssetId&&e.assetId&&t.assetId&&e.assetId!==t.assetId)throw new Error(`Resolved assetId ${t.assetId} does not match requested assetId ${e.assetId}.`)}function hv(e){return{assetId:e.assetId,mediaType:e.mediaType,pippitAssetId:e.pippitAssetId}}function Vz(e,t){return e?Zs(e,t):void 0}function Zs(e,t){var s,i,a,d,c;let n=bt({assetId:((s=e.identity)==null?void 0:s.assetId)??(t==null?void 0:t.assetId),pippitAssetId:((i=e.identity)==null?void 0:i.pippitAssetId)??(t==null?void 0:t.pippitAssetId)}),r=((d=(a=e.preview)==null?void 0:a.urls)==null?void 0:d.poster)??((c=t==null?void 0:t.video)==null?void 0:c.coverUrl),o={...n!=null&&n.assetId?{assetId:n.assetId}:{},...n!=null&&n.pippitAssetId?{pippitAssetId:n.pippitAssetId}:{}};return{...e,identity:n,metadata:{...e.metadata,...o,...r?{poster:r}:{}},preview:e.preview?{...e.preview,raw:e.preview.raw??(t==null?void 0:t.raw),urls:{...e.preview.urls,...r?{poster:r}:{}}}:void 0}}var lt="canvas";function Ut(e){return e.type===lt}function wd(e){let t=e.assets[e.rootCanvasId];if(!t)throw new Error(`Root canvas asset ${e.rootCanvasId} is missing`);if(!Ut(t))throw new Error(`Root asset ${e.rootCanvasId} is not a canvas`);return t}function x(e){return wd(e).content}var Hz={snap:{enabled:!0,threshold:8,targets:["grid","node"]},grid:{size:28,visible:!0}};function bo(e){let t={pippitAssetId:e,type:lt,content:{metadata:{title:"Canvas",globalBounds:{minX:-4e3,minY:-3e3,maxX:4e3,maxY:3e3}},settings:Hz,nodes:{},edges:{}},extra:{}};return{rootCanvasId:e,assets:{[e]:t}}}var gv;function yv(e){let t=globalThis.console;if(!t||typeof t!="object")return;let n=t[e];return typeof n=="function"?n.bind(t):void 0}function Al(e,t){var n;(n=yv(e))==null||n(...t),e==="error"&&Yz(t)}function Yz(e){var t;if(gv)try{gv({packageName:"canvas-sdk",message:Kz(e),error:Xz(e),context:$z(e)})}catch(n){(t=yv("warn"))==null||t("[canvas-sdk] error reporter failed",n)}}function Kz(e){return e.filter(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean").map(n=>String(n)).join(" ")||"[canvas-sdk] error"}function Xz(e){for(let t of e){if(t instanceof Error)return t;if(Av(t)&&t.error instanceof Error)return t.error}}function $z(e){let t={},n=20;for(let r of e){if(n<=0)break;if(!(r instanceof Error)&&Av(r))for(let[o,s]of Object.entries(r)){if(n<=0)break;t[o]=Wz(s),n-=1}}return t}function Wz(e){var t;return e instanceof Error?`${e.name}: ${e.message}`:typeof e=="string"?e.length>500?`${e.slice(0,500)}...`:e:e===null||typeof e=="number"||typeof e=="boolean"||typeof e>"u"?e:Array.isArray(e)?`[array:${e.length}]`:typeof e=="object"?`[object:${((t=e.constructor)==null?void 0:t.name)||"Object"}]`:String(e)}function Av(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}var Re={error:(...e)=>Al("error",e),info:(...e)=>Al("info",e),warn:(...e)=>Al("warn",e)};var xl=Symbol.for("immer-nothing"),ei=Symbol.for("immer-draftable"),Ze=Symbol.for("immer-state");function Me(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var Io=Object.getPrototypeOf;function Cr(e){return!!e&&!!e[Ze]}function jn(e){var t;return e?Rv(e)||Array.isArray(e)||!!e[ei]||!!((t=e.constructor)!=null&&t[ei])||_o(e)||ii(e):!1}var Qz=Object.prototype.constructor.toString(),vv=new WeakMap;function Rv(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);if(t===null||t===Object.prototype)return!0;let n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let r=vv.get(n);return r===void 0&&(r=Function.toString.call(n),vv.set(n,r)),r===Qz}function ti(e,t,n=!0){Pr(e)===0?(n?Reflect.ownKeys(e):Object.keys(e)).forEach(o=>{t(o,e[o],e)}):e.forEach((r,o)=>t(o,r,e))}function Pr(e){let t=e[Ze];return t?t.type_:Array.isArray(e)?1:_o(e)?2:ii(e)?3:0}function ni(e,t){return Pr(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function vl(e,t){return Pr(e)===2?e.get(t):e[t]}function Ev(e,t,n){let r=Pr(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function Jz(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function _o(e){return e instanceof Map}function ii(e){return e instanceof Set}function Er(e){return e.copy_||e.base_}function Il(e,t){if(_o(e))return new Map(e);if(ii(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);let n=Rv(e);if(t===!0||t==="class_only"&&!n){let r=Object.getOwnPropertyDescriptors(e);delete r[Ze];let o=Reflect.ownKeys(r);for(let s=0;s<o.length;s++){let i=o[s],a=r[i];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(r[i]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[i]})}return Object.create(Io(e),r)}else{let r=Io(e);if(r!==null&&n)return{...e};let o=Object.create(r);return Object.assign(o,e)}}function Tl(e,t=!1){return Md(e)||Cr(e)||!jn(e)||(Pr(e)>1&&Object.defineProperties(e,{set:Od,add:Od,clear:Od,delete:Od}),Object.freeze(e),t&&Object.values(e).forEach(n=>Tl(n,!0))),e}function Zz(){Me(2)}var Od={value:Zz};function Md(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var _l={};function xr(e){let t=_l[e];return t||Me(0,e),t}function eq(e,t){_l[e]||(_l[e]=t)}var ri;function Cv(){return ri}function tq(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Sv(e,t){t&&(xr("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function Rl(e){El(e),e.drafts_.forEach(nq),e.drafts_=null}function El(e){e===ri&&(ri=e.parent_)}function bv(e){return ri=tq(ri,e)}function nq(e){let t=e[Ze];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function Iv(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];return e!==void 0&&e!==n?(n[Ze].modified_&&(Rl(t),Me(4)),jn(e)&&(e=Dd(t,e),t.parent_||kd(t,e)),t.patches_&&xr("Patches").generateReplacementPatches_(n[Ze].base_,e,t.patches_,t.inversePatches_)):e=Dd(t,n,[]),Rl(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==xl?e:void 0}function Dd(e,t,n){if(Md(t))return t;let r=e.immer_.shouldUseStrictIteration(),o=t[Ze];if(!o)return ti(t,(s,i)=>_v(e,o,t,s,i,n),r),t;if(o.scope_!==e)return t;if(!o.modified_)return kd(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;let s=o.copy_,i=s,a=!1;o.type_===3&&(i=new Set(s),s.clear(),a=!0),ti(i,(d,c)=>_v(e,o,s,d,c,n,a),r),kd(e,s,!1),n&&e.patches_&&xr("Patches").generatePatches_(o,n,e.patches_,e.inversePatches_)}return o.copy_}function _v(e,t,n,r,o,s,i){if(o==null||typeof o!="object"&&!i)return;let a=Md(o);if(!(a&&!i)){if(Cr(o)){let d=s&&t&&t.type_!==3&&!ni(t.assigned_,r)?s.concat(r):void 0,c=Dd(e,o,d);if(Ev(n,r,c),Cr(c))e.canAutoFreeze_=!1;else return}else i&&n.add(o);if(jn(o)&&!a){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[r]===o&&a)return;Dd(e,o),(!t||!t.scope_.parent_)&&typeof r!="symbol"&&(_o(n)?n.has(r):Object.prototype.propertyIsEnumerable.call(n,r))&&kd(e,o)}}}function kd(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Tl(t,n)}function rq(e,t){let n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:Cv(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=r,s=Nl;n&&(o=[r],s=oi);let{revoke:i,proxy:a}=Proxy.revocable(o,s);return r.draft_=a,r.revoke_=i,a}var Nl={get(e,t){if(t===Ze)return e;let n=Er(e);if(!ni(n,t))return oq(e,n,t);let r=n[t];return e.finalized_||!jn(r)?r:r===Sl(e.base_,t)?(bl(e),e.copy_[t]=Pl(r,e)):r},has(e,t){return t in Er(e)},ownKeys(e){return Reflect.ownKeys(Er(e))},set(e,t,n){let r=Pv(Er(e),t);if(r!=null&&r.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let o=Sl(Er(e),t),s=o==null?void 0:o[Ze];if(s&&s.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(Jz(n,o)&&(n!==void 0||ni(e.base_,t)))return!0;bl(e),Cl(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return Sl(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,bl(e),Cl(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=Er(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty(){Me(11)},getPrototypeOf(e){return Io(e.base_)},setPrototypeOf(){Me(12)}},oi={};ti(Nl,(e,t)=>{oi[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});oi.deleteProperty=function(e,t){return oi.set.call(this,e,t,void 0)};oi.set=function(e,t,n){return Nl.set.call(this,e[0],t,n,e[0])};function Sl(e,t){let n=e[Ze];return(n?Er(n):e)[t]}function oq(e,t,n){var o;let r=Pv(t,n);return r?"value"in r?r.value:(o=r.get)==null?void 0:o.call(e.draft_):void 0}function Pv(e,t){if(!(t in e))return;let n=Io(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=Io(n)}}function Cl(e){e.modified_||(e.modified_=!0,e.parent_&&Cl(e.parent_))}function bl(e){e.copy_||(e.copy_=Il(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var sq=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,n,r)=>{if(typeof t=="function"&&typeof n!="function"){let s=n;n=t;let i=this;return function(d=s,...c){return i.produce(d,u=>n.call(this,u,...c))}}typeof n!="function"&&Me(6),r!==void 0&&typeof r!="function"&&Me(7);let o;if(jn(t)){let s=bv(this),i=Pl(t,void 0),a=!0;try{o=n(i),a=!1}finally{a?Rl(s):El(s)}return Sv(s,r),Iv(o,s)}else if(!t||typeof t!="object"){if(o=n(t),o===void 0&&(o=t),o===xl&&(o=void 0),this.autoFreeze_&&Tl(o,!0),r){let s=[],i=[];xr("Patches").generateReplacementPatches_(t,o,s,i),r(s,i)}return o}else Me(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(i,...a)=>this.produceWithPatches(i,d=>t(d,...a));let r,o;return[this.produce(t,n,(i,a)=>{r=i,o=a}),r,o]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof(e==null?void 0:e.useStrictIteration)=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){jn(e)||Me(8),Cr(e)&&(e=iq(e));let t=bv(this),n=Pl(e,void 0);return n[Ze].isManual_=!0,El(t),n}finishDraft(e,t){let n=e&&e[Ze];(!n||!n.isManual_)&&Me(9);let{scope_:r}=n;return Sv(r,t),Iv(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let o=t[n];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}n>-1&&(t=t.slice(n+1));let r=xr("Patches").applyPatches_;return Cr(e)?r(e,t):this.produce(e,o=>r(o,t))}};function Pl(e,t){let n=_o(e)?xr("MapSet").proxyMap_(e,t):ii(e)?xr("MapSet").proxySet_(e,t):rq(e,t);return(t?t.scope_:Cv()).drafts_.push(n),n}function iq(e){return Cr(e)||Me(10,e),xv(e)}function xv(e){if(!jn(e)||Md(e))return e;let t=e[Ze],n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=Il(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=Il(e,!0);return ti(n,(o,s)=>{Ev(n,o,xv(s))},r),t&&(t.finalized_=!1),n}function zt(){let t="replace",n="add",r="remove";function o(l,f,h,m){switch(l.type_){case 0:case 2:return i(l,f,h,m);case 1:return s(l,f,h,m);case 3:return a(l,f,h,m)}}function s(l,f,h,m){let{base_:g,assigned_:y}=l,v=l.copy_;v.length<g.length&&([g,v]=[v,g],[h,m]=[m,h]);for(let S=0;S<g.length;S++)if(y[S]&&v[S]!==g[S]){let b=f.concat([S]);h.push({op:t,path:b,value:p(v[S])}),m.push({op:t,path:b,value:p(g[S])})}for(let S=g.length;S<v.length;S++){let b=f.concat([S]);h.push({op:n,path:b,value:p(v[S])})}for(let S=v.length-1;g.length<=S;--S){let b=f.concat([S]);m.push({op:r,path:b})}}function i(l,f,h,m){let{base_:g,copy_:y}=l;ti(l.assigned_,(v,S)=>{let b=vl(g,v),I=vl(y,v),N=S?ni(g,v)?t:n:r;if(b===I&&N===t)return;let w=f.concat(v);h.push(N===r?{op:N,path:w}:{op:N,path:w,value:I}),m.push(N===n?{op:r,path:w}:N===r?{op:n,path:w,value:p(b)}:{op:t,path:w,value:p(b)})})}function a(l,f,h,m){let{base_:g,copy_:y}=l,v=0;g.forEach(S=>{if(!y.has(S)){let b=f.concat([v]);h.push({op:r,path:b,value:S}),m.unshift({op:n,path:b,value:S})}v++}),v=0,y.forEach(S=>{if(!g.has(S)){let b=f.concat([v]);h.push({op:n,path:b,value:S}),m.unshift({op:r,path:b,value:S})}v++})}function d(l,f,h,m){h.push({op:t,path:[],value:f===xl?void 0:f}),m.push({op:t,path:[],value:l})}function c(l,f){return f.forEach(h=>{let{path:m,op:g}=h,y=l;for(let I=0;I<m.length-1;I++){let N=Pr(y),w=m[I];typeof w!="string"&&typeof w!="number"&&(w=""+w),(N===0||N===1)&&(w==="__proto__"||w==="constructor")&&Me(16+3),typeof y=="function"&&w==="prototype"&&Me(16+3),y=vl(y,w),typeof y!="object"&&Me(16+2,m.join("/"))}let v=Pr(y),S=u(h.value),b=m[m.length-1];switch(g){case t:switch(v){case 2:return y.set(b,S);case 3:Me(16);default:return y[b]=S}case n:switch(v){case 1:return b==="-"?y.push(S):y.splice(b,0,S);case 2:return y.set(b,S);case 3:return y.add(S);default:return y[b]=S}case r:switch(v){case 1:return y.splice(b,1);case 2:return y.delete(b);case 3:return y.delete(h.value);default:return delete y[b]}default:Me(16+1,g)}}),l}function u(l){if(!jn(l))return l;if(Array.isArray(l))return l.map(u);if(_o(l))return new Map(Array.from(l.entries()).map(([h,m])=>[h,u(m)]));if(ii(l))return new Set(Array.from(l).map(u));let f=Object.create(Io(l));for(let h in l)f[h]=u(l[h]);return ni(l,ei)&&(f[ei]=l[ei]),f}function p(l){return Cr(l)?u(l):l}eq("Patches",{applyPatches_:c,generatePatches_:o,generateReplacementPatches_:d})}var si=new sq,Ld=si.produce,qt=si.produceWithPatches.bind(si);var yn=si.applyPatches.bind(si);var Te=class extends Error{constructor(n,r,o){super(n);this.code=r;this.cause=o;this.name="TransactionError"}};zt();function Ye(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function aq(e,t){return JSON.stringify(e)===JSON.stringify(t)}function et(e,t){for(let n of Object.keys(e))n in t||delete e[n];for(let[n,r]of Object.entries(t)){let o=e[n];if(!aq(o,r)){if(Ye(o)&&Ye(r)){et(o,r);continue}e[n]=r}}}function dq(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function")}function wl(e,t){let n=t(e);if(dq(n))throw Promise.resolve(n).catch(()=>{}),new Te("transact recipe must be synchronous","ASYNC_RECIPE")}function Bd(e){if(e===void 0)return;if(Array.isArray(e)){let r=!1,o=e.map(s=>{let i=Bd(s);return i===void 0?(r=!0,null):(i!==s&&(r=!0),i)});return r?o:e}if(!Ye(e))return e;let t=!1,n={};for(let[r,o]of Object.entries(e)){let s=Bd(o);if(s===void 0){t=!0;continue}s!==o&&(t=!0),n[r]=s}return t?n:e}function ai(e){return Bd(e)}function di(e){let t=Bd(e);return Ye(t)?t:{}}var be="group",Ft="builtin/group";function An(e){return e?e!==be&&e!==Ft:!1}function Ol(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function cq(e){return di(e)}function Gd(e){return{pippitAssetId:e.id,type:e.type,content:cq(e.data),extra:{}}}function _t(e){return!!(e&&e.type!==lt&&e.content&&typeof e.content=="object"&&!Array.isArray(e.content))}function uq(e){if(_t(e))return Ol(e.content)?e.content:void 0}function ci(e,t){if(!(!t||!e||!Ol(e.assets)))return uq(e.assets[t])}function ui(e,t){if(!t||!An(t.type))return t;let n=ci(e,t.id);if(!n)return t;let r=Ol(t.data)?t.data:{};return{...t,data:{...r,...n}}}var Tv="unknown",Nv="unknown_node";function hq(e){if(e!==be&&!/^(builtin|biz|plugin)\//.test(e))throw new Error(`Node type must be namespaced with builtin/, biz/ or plugin/: ${e}`)}function kl(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Dl(e){return typeof e=="string"&&e.length>0?e:void 0}function Ud(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function gq(e){if(kl(e))return e}function zd(e,t){if(!kl(e))return{id:t??Nv,type:Tv,x:0,y:0,w:1,h:1,parentId:null,data:e,status:"unknown"};let n=Dl(e.type)??Tv;return{...e,id:Dl(e.id)??t??Nv,type:n,x:Ud(e.x,0),y:Ud(e.y,0),w:Ud(e.w,1),h:Ud(e.h,1),parentId:Dl(e.parentId)??null,order:typeof e.order=="number"?e.order:void 0,data:"data"in e?e.data:e,style:gq(e.style),status:"unknown"}}function yq(e,t,n,r){let o=zd(e,r);return{id:o.id,x:o.x,y:o.y,w:o.w,h:o.h,parentId:o.parentId,order:o.order,style:o.style,type:t.type,data:n}}function qd(){let e=new Map;return{register(t){if(hq(t.type),e.has(t.type))throw new Error(`Node definition already registered: ${t.type}`);return e.set(t.type,t),()=>{e.delete(t.type)}},get(t){return e.get(t)},has(t){return e.has(t)},hydrate(t,n){if(!kl(t))return zd(t,n);let r=typeof t.type=="string"?t.type:"",o=e.get(r);if(!o)return zd(t,n);let{data:s}=t;return o.validate(s)?yq(t,o,s,n):zd(t,n)}}}function Ml(){let e=new Map;return{register(t){if(e.has(t.type))throw new Error(`Directive handler already registered: ${t.type}`);return e.set(t.type,t),()=>{e.get(t.type)===t&&e.delete(t.type)}},resolve(t){return e.get(t)},has(t){return e.has(t)}}}var Ll="directive.apply";function pi(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Aq(e){if(!(!pi(e)||!pi(e.directives)))return e.directives}function vq(e){let t=x(e.getState()),n=[],r=t.directives;if(pi(r))for(let[o,s]of Object.entries(r))n.push({carrier:{kind:"canvas"},directiveId:o,directive:s});for(let[o,s]of Object.entries(t.nodes)){let i=Aq(s==null?void 0:s.data);if(i)for(let[a,d]of Object.entries(i))n.push({carrier:{kind:"node",nodeId:o},directiveId:a,directive:d})}return n}function Sq(e,t,n){var s;let r=x(e);if(t.kind==="canvas"){r.directives&&(delete r.directives[n],Object.keys(r.directives).length===0&&delete r.directives);return}let o=(s=r.nodes[t.nodeId])==null?void 0:s.data;pi(o)&&pi(o.directives)&&(delete o.directives[n],Object.keys(o.directives).length===0&&delete o.directives)}function Bl(e,t){let{registry:n,onError:r}=t,o=()=>{let s=vq(e);s.length!==0&&e.transact(i=>{for(let{carrier:a,directiveId:d,directive:c}of s){Sq(i,a,d);let u=n.resolve(c.type);if(!u){Re.info("[canvas-sdk:directive] no handler, directive removed",{type:c.type,directiveId:d,carrier:a});continue}try{u.run({directiveId:d,carrier:a,directive:c,commands:e.commands,store:e})}catch(p){Re.error("[canvas-sdk:directive] handler threw",p,{type:c.type,directiveId:d,carrier:a}),r==null||r(p,c,a)}}},{intent:Ll,source:"local",undoable:!1})};return o(),e.subscribe(({transaction:s})=>{s.intent!==Ll&&o()})}var Gl=(e,t)=>{t()};var Fd=["horizontal-directed-cluster","vertical-directed-cluster","dag-layered","component-packing","incremental-stress"],bq=["directed-cluster"];function Tr(e){return typeof e=="string"&&[...Fd,...bq].includes(e)}function wv(e,t){let n=new Map;return{batch(r,o,s){return e.transact(()=>{o(t())},{...s,intent:r})},register(r,o){return n.set(r,o),()=>{n.delete(r)}},invoke(r,...o){let s=n.get(r);return s?s(e,...o):{status:"aborted",reason:`Unknown command: ${r}`}}}}function Rt(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function ee(e){return!!(e&&Array.isArray(e.children))}function W(e){return x(e)}function Nr(e,t,n){let r=e.nodes[t];ee(r)&&(r.children=r.children.filter(o=>o!==n))}function Ov(e,t){let n=new Set,r=o=>{if(n.has(o))return;n.add(o);let s=e.nodes[o];if(ee(s))for(let i of s.children)r(i)};for(let o of t)r(o);return n}function Ee(e,t){let n=e[t];if(!n)return{x:0,y:0};if(!n.parentId)return{x:n.x,y:n.y};let r=Ee(e,n.parentId);return{x:r.x+n.x,y:r.y+n.y}}function vn(e,t){let n=e[t];if(!n)return;let r=Ee(e,t);return{minX:r.x,minY:r.y,maxX:r.x+n.w,maxY:r.y+n.h}}function Ne(e){if(e.length!==0)return e.reduce((t,n)=>({minX:Math.min(t.minX,n.minX),minY:Math.min(t.minY,n.minY),maxX:Math.max(t.maxX,n.maxX),maxY:Math.max(t.maxY,n.maxY)}),e[0])}function ft(e,t){let n=new Set(t);return t.filter(r=>{var s,i;let o=(s=e[r])==null?void 0:s.parentId;for(;o;){if(n.has(o))return!1;o=(i=e[o])==null?void 0:i.parentId}return!!e[r]})}function Dv(e,t){var r;if(t.length===0)return null;let n=((r=e[t[0]])==null?void 0:r.parentId)??null;return t.every(o=>{var s;return(((s=e[o])==null?void 0:s.parentId)??null)===n})?n:null}function kv(e,t,n="_"){let r=1,o=`${t}${n}${Date.now().toString(36)}`;for(;e[o];)r+=1,o=`${t}${n}${Date.now().toString(36)}${n}${r}`;return o}function Mv(e,t,n,r){let o=e.nodes[t];if(!ee(o))return;let s=new Set(n),i=o.children.findIndex(a=>s.has(a));o.children=o.children.filter(a=>!s.has(a)),o.children.splice(Math.max(i,0),0,r)}function Lv(e,t){let n=Object.values(e).filter(r=>r.parentId===t);return n.length===0?0:Math.max(...n.map(r=>r.order??0))+1}function Bv(e){return{createEdge(t){return e.transact(n=>{W(n).edges[t.id]=t},{intent:"edge.create"})},deleteEdges(t){return e.transact(n=>{let{edges:r}=W(n);for(let o of t)delete r[o]},{intent:"edge.delete"})},reconnectEdge(t,n){return e.transact(r=>{let o=W(r).edges[t];o&&(o.source=n.source,o.target=n.target,n.sourceHandle?o.sourceHandle=n.sourceHandle:delete o.sourceHandle,n.targetHandle?o.targetHandle=n.targetHandle:delete o.targetHandle)},{intent:"edge.reconnect"})},updateEdgeData(t,n){return e.transact(r=>{let o=W(r).edges[t];o&&(o.data={...Rt(o.data)?o.data:{},...n})},{intent:"edge.updateData"})}}}function Gv(e,t={}){let n=t.centerThreshold??1048576,r=t.targetCenter??{x:0,y:0};if(!Number.isFinite(n)||n<0||!Number.isFinite(r.x)||!Number.isFinite(r.y))return;let o=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY,d=!1;for(let l of e){if(![l.x,l.y,l.w,l.h].every(Number.isFinite))return;let f=l.x+l.w,h=l.y+l.h;if(!Number.isFinite(f)||!Number.isFinite(h))return;o=Math.min(o,l.x,f),s=Math.min(s,l.y,h),i=Math.max(i,l.x,f),a=Math.max(a,l.y,h),d=!0}if(!d)return;let c=o/2+i/2,u=s/2+a/2;if(Math.abs(c-r.x)<=n&&Math.abs(u-r.y)<=n)return;let p={dx:r.x-c,dy:r.y-u};return Number.isFinite(p.dx)&&Number.isFinite(p.dy)?p:void 0}function Uv(e){let t=new Set;return e.filter(n=>t.has(n)?!1:(t.add(n),!0))}function Ul(e,t){return!e||!t?e?-1:t?1:0:(e.order??0)-(t.order??0)||e.y-t.y||e.x-t.x||e.id.localeCompare(t.id)}function tt(e,t){return Ul(e.node,t.node)||e.rect.minY-t.rect.minY||e.rect.minX-t.rect.minX}function Vn(e,t){e.sort((n,r)=>{let o=t.get(n),s=t.get(r);return!o||!s?n.localeCompare(r):tt(o,s)})}function wr(e,t){return t.flatMap(n=>{let r=e[n],o=vn(e,n);return r&&o?[{node:r,rect:o}]:[]})}function zv(e,t,n){switch(n){case"left":return{dx:t.minX-e.minX,dy:0};case"center":return{dx:(t.minX+t.maxX)/2-(e.minX+e.maxX)/2,dy:0};case"right":return{dx:t.maxX-e.maxX,dy:0};case"top":return{dx:0,dy:t.minY-e.minY};case"middle":return{dx:0,dy:(t.minY+t.maxY)/2-(e.minY+e.maxY)/2};case"bottom":return{dx:0,dy:t.maxY-e.maxY}}}function jd(e,t){t.dx!==0&&(e.x+=t.dx),t.dy!==0&&(e.y+=t.dy)}var Iq=40,_q=40;function Rq(e,t){return e.x-t.x||e.y-t.y||e.id.localeCompare(t.id)}function Eq(e,t){return e.y-t.y||e.x-t.x||e.id.localeCompare(t.id)}function Vd(e,t){var s;let n=Uv(t);if(n.length===1){let i=e[n[0]];if(!ee(i))return;let a=i.children.filter(d=>{var c;return((c=e[d])==null?void 0:c.parentId)===i.id});return a.length>=2?{ids:a,parentId:i.id}:void 0}let r=ft(e,n);if(r.length<2)return;let o=((s=e[r[0]])==null?void 0:s.parentId)??null;if(r.every(i=>{var a;return(((a=e[i])==null?void 0:a.parentId)??null)===o}))return{ids:r,parentId:o}}function Hd(e,t,n,r){let o=t.map(m=>e[m]).filter(m=>!!m);if(o.length<2)return;let s=Math.min(...o.map(m=>m.x)),i=Math.min(...o.map(m=>m.y)),a=Math.max(...o.map(m=>m.w)),d=Math.max(...o.map(m=>m.h)),c=(r==null?void 0:r.horizontalGap)??Iq,u=(r==null?void 0:r.verticalGap)??_q,p=[...o].sort(n==="horizontal"?Rq:Eq);if(n==="horizontal"){let m=s;for(let g of p)g.x=m,g.y=i,m+=g.w+c;return}if(n==="vertical"){let m=i;for(let g of p)g.x=s,g.y=m,m+=g.h+u;return}let l=Math.max(1,(r==null?void 0:r.gridColumns)??Math.ceil(Math.sqrt(o.length))),f=a+c,h=d+u;p.forEach((m,g)=>{m.x=s+g%l*f,m.y=i+Math.floor(g/l)*h})}function Cq(e){return e.maxX-e.minX}function Pq(e){return e.maxY-e.minY}function jt(e){return{x:e.minX+Cq(e)/2,y:e.minY+Pq(e)/2}}function Yd(e,t){return{id:e,minX:t.minX,minY:t.minY,maxX:t.maxX,maxY:t.maxY}}function Kd(e){return{...e}}function Co(e,t,n){e.minX+=t,e.maxX+=t,e.minY+=n,e.maxY+=n}function Po(e){return(e.minX+e.maxX)/2}function xo(e){return(e.minY+e.maxY)/2}function To(e){return e.maxX-e.minX}function No(e){return e.maxY-e.minY}function zl(e,t){return Ne([...e.entries()].flatMap(([n,r])=>{let o=t.get(n);return o?[{minX:r.x,minY:r.y,maxX:r.x+o.node.w,maxY:r.y+o.node.h}]:[]}))}function xq(e,t){return t.flatMap(n=>{let r=e.get(n.node.id);return r?[{id:n.node.id,minX:r.x,minY:r.y,maxX:r.x+n.node.w,maxY:r.y+n.node.h}]:[]})}function Fv(e,t,n){let r=(To(e)+To(t))/2+n-Math.abs(Po(t)-Po(e)),o=(No(e)+No(t))/2+n-Math.abs(xo(t)-xo(e));return r>0&&o>0}function Tq(e,t,n){let r=Math.max(0,(To(e)+To(t))/2+n-Math.abs(Po(t)-Po(e))),o=Math.max(0,(No(e)+No(t))/2+n-Math.abs(xo(t)-xo(e)));return r*o}function ql(e,t,n){return t.reduce((r,o)=>r+Tq(e,o,n),0)}function qv(e,t,n){return e!==0?Math.sign(e):t.localeCompare(n)<=0?1:-1}function Nq(e,t,n){let r=Po(t)-Po(e),o=xo(t)-xo(e),s=(To(e)+To(t))/2+n-Math.abs(r),i=(No(e)+No(t))/2+n-Math.abs(o);if(s<=0||i<=0)return!1;if(s<=i){let c=qv(r,e.id,t.id),u=s/2;return Co(e,-c*u,0),Co(t,c*u,0),!0}let a=qv(o,e.id,t.id),d=i/2;return Co(e,0,-a*d),Co(t,0,a*d),!0}function Fl(e,t,n=Math.max(24,e.length*16)){if(!(e.length<2))for(let r=0;r<n;r+=1){let o=!1;for(let s=0;s<e.length;s+=1)for(let i=s+1;i<e.length;i+=1)o=Nq(e[s],e[i],t)||o;if(!o)return}}function jl(e,t,n){let r=new Map;for(let[o,s]of e)r.set(o,{x:s.x+t,y:s.y+n});return r}function li(e,t,n){let r=xq(e,t.items);Fl(r,n);let o=new Map;for(let d of r)o.set(d.id,{x:d.minX,y:d.minY});let s=new Map(t.items.map(d=>[d.node.id,d])),i=zl(o,s);if(!i)return o;let a=jt(i);return jl(o,t.center.x-a.x,t.center.y-a.y)}function Vl(e){return new Map(e.map(t=>[t.node.id,{x:t.rect.minX,y:t.rect.minY}]))}function Vv(e,t,n){var o;let r=t;for(;r;){if(n.has(r))return r;r=((o=e[r])==null?void 0:o.parentId)??null}}function Dq(e,t,n){let r=new Set(n),o=new Set,s=[];for(let i of Object.values(t)){let a=Vv(e,i.source,r),d=Vv(e,i.target,r);if(!a||!d||a===d)continue;let c=`${a}->${d}`;o.has(c)||(o.add(c),s.push({source:a,target:d}))}return s}function kq(e,t,n){var u,p;let r=wr(e,t).sort((l,f)=>tt(l,f)),o=new Map(r.map(l=>[l.node.id,l])),s=r.map(l=>l.node.id),i=Dq(e,n,s),a=new Map;for(let l of s)a.set(l,new Set);for(let l of i)(u=a.get(l.source))==null||u.add(l.target),(p=a.get(l.target))==null||p.add(l.source);let d=[],c=new Set;for(let l of s){if(c.has(l))continue;let f=[],h=[l];for(c.add(l);h.length>0;){let S=h.pop();f.push(S);let b=[...a.get(S)??[]].filter(I=>!c.has(I));Vn(b,o);for(let I of b.reverse())c.add(I),h.push(I)}f.sort((S,b)=>tt(o.get(S),o.get(b)));let m=f.flatMap(S=>{let b=o.get(S);return b?[b]:[]}),g=Ne(m.map(S=>S.rect));if(!g)continue;let y=new Set(f),v=i.filter(S=>y.has(S.source)&&y.has(S.target));d.push({ids:f,items:m,edges:v,bounds:g,center:jt(g),isolated:v.length===0&&f.length===1})}return d}function Mq(e,t,n){let r=n(e,t),o=new Map(e.items.map(i=>[i.node.id,i])),s=zl(r,o)??e.bounds;return{component:e,positions:r,bounds:s}}function Hl(e,t){return jl(e.positions,t.minX-e.bounds.minX,t.minY-e.bounds.minY)}function Lq(e,t,n){let r=jt(t),o=e.map((s,i)=>{let a={x:r.x+(s.component.center.x-r.x)*.78,y:r.y+(s.component.center.y-r.y)*.78},d=jt(s.bounds),c=a.x-d.x,u=a.y-d.y;return Yd(String(i),{minX:s.bounds.minX+c,minY:s.bounds.minY+u,maxX:s.bounds.maxX+c,maxY:s.bounds.maxY+u})});return Fl(o,n),o}function Hv(e,t,n){return t.some(r=>Fv(e,r,n))}function Bq(e,t){let n=[{x:0,y:0}],r=Math.max(0,Math.ceil(t/e));for(let o=1;o<=r;o+=1){for(let s=-o;s<=o;s+=1)n.push({x:s*e,y:-o*e}),n.push({x:s*e,y:o*e});for(let s=-o+1;s<=o-1;s+=1)n.push({x:-o*e,y:s*e}),n.push({x:o*e,y:s*e})}return n.filter(o=>Math.hypot(o.x,o.y)<=t).sort((o,s)=>Math.hypot(o.x,o.y)-Math.hypot(s.x,s.y)||o.y-s.y||o.x-s.x)}function Yl(e){var t;return((t=e.component.items[0])==null?void 0:t.node.id)??e.component.ids[0]??""}function fi(e){return{w:e.bounds.maxX-e.bounds.minX,h:e.bounds.maxY-e.bounds.minY}}function Gq(e,t,n,r){let o=[...e].sort((h,m)=>tt(h.component.items[0],m.component.items[0])),s=Math.max(0,t.maxY-t.minY),i=Math.max(0,...o.map(h=>fi(h).h)),a=o.reduce((h,m)=>h+fi(m).h+r,0),d=s>0?Math.max(s,i):a,c=[],u=[],p=0;for(let h of o){let{h:m}=fi(h);u.length>0&&p+m+r>d&&(c.push(u),u=[],p=0),u.push(h),p+=m+r}u.length>0&&c.push(u);let l=new Map,f=t.minX-n;for(let h of c){let m=Math.max(0,...h.map(v=>fi(v).w)),g=f-m,y=t.minY;for(let v of h){let{w:S,h:b}=fi(v);l.set(Yl(v),Yd(Yl(v),{minX:g,minY:y,maxX:g+S,maxY:y+b})),y+=b+r}f=g-n}return l}function Uq(e,t,n,r,o){if(!Hv(e,t,n))return Kd(e);let s=Kd(e),i=ql(s,t,n);for(let a of Bq(o,r)){let d=Kd(e);if(Co(d,a.x,a.y),!Hv(d,t,n))return d;let c=ql(d,t,n);c<i&&(i=c,s=d)}return s}function Or({nodes:e,edges:t,ids:n,options:r,resolveComponentPositions:o}){let s=kq(e,n,t),i=Ne(s.map(y=>y.bounds));if(!i)return new Map;let a=(r==null?void 0:r.componentGap)??180,d=(r==null?void 0:r.nodeGap)??40,c=(r==null?void 0:r.isolatedNodeMoveLimit)??360,u=s.map(y=>Mq(y,r,o)),p=u.filter(y=>!y.component.isolated),l=u.filter(y=>y.component.isolated),f=new Map,h=[],m=Lq(p,i,a);if(p.forEach((y,v)=>{let S=m[v];for(let[b,I]of Hl(y,S))f.set(b,I);h.push(S)}),(r==null?void 0:r.isolatedPlacement)==="left"&&l.length>0){let y=Ne(h)??i,v=Gq(l,y,a,d);for(let S of l){let b=v.get(Yl(S));if(b){for(let[I,N]of Hl(S,b))f.set(I,N);h.push(b)}}return f}let g=Math.max(40,d+20);return l.forEach((y,v)=>{let S=Yd(`isolated-${v}`,y.bounds),b=Uq(S,h,a,c,g);for(let[I,N]of Hl(y,b))f.set(I,N);h.push(b)}),f}var Yv=.86;function Kl(e,t){if(e.items.length<2)return Vl(e.items);let n=new Map;for(let o of e.items){let s=jt(o.rect),i={x:e.center.x+(s.x-e.center.x)*Yv,y:e.center.y+(s.y-e.center.y)*Yv};n.set(o.node.id,{x:i.x-o.node.w/2,y:i.y-o.node.h/2})}let r=(t==null?void 0:t.nodeGap)??40;return li(n,e,r)}function Kv({nodes:e,edges:t,ids:n,options:r}){return Or({nodes:e,edges:t,ids:n,options:r,resolveComponentPositions:Kl})}var zq=240,qq=40,Fq=240,jq=2.2;function Vq(e,t,n,r,o){let s=e.filter(a=>(n.get(a.node.id)??0)===0).map(a=>a.node.id);Vn(s,o);let i=[];for(;s.length>0;){let a=s.shift();i.push(a);let d=t.get(a)??[];Vn(d,o);for(let c of d){r.set(c,Math.max(r.get(c)??0,(r.get(a)??0)+1));let u=(n.get(c)??0)-1;n.set(c,u),u===0&&(s.push(c),Vn(s,o))}}return i}function Hq(e,t,n){let r=new Map;for(let o of e){let s=t.get(o);if(!s)continue;let i=n.get(o)??0,a=r.get(i)??[];a.push(s),r.set(i,a)}return r}function Yq(e,t,n){let r=[],o=e;for(let s=0;s<t.length;s+=1)r[s]=o,o+=t[s]+n;return r}function Kq({itemById:e,items:t,outgoing:n,indegree:r,layer:o,options:s}){let i=Vq(t,n,r,o,e);if(i.length!==t.length)return;let a=Ne(t.map(m=>m.rect));if(!a)return;let d=(s==null?void 0:s.horizontalGap)??zq,c=(s==null?void 0:s.verticalGap)??qq,u=Hq(i,e,o),p=Math.max(...u.keys()),l=Array.from({length:p+1},(m,g)=>Math.max(...(u.get(g)??[]).map(y=>y.node.w),0)),f=Yq(a.minX,l,d),h=new Map;for(let m=0;m<=p;m+=1){let g=u.get(m)??[],y=a.minY;for(let v of g)h.set(v.node.id,{x:f[m],y}),y+=v.node.h+c}return h}function Xq(e,t,n){var d;if(t.length===0)return;let r=new Map(e.map(c=>[c.node.id,c])),o=new Map,s=new Map,i=new Map;for(let c of e)o.set(c.node.id,[]),s.set(c.node.id,0),i.set(c.node.id,0);let a=new Set;for(let c of t){let u=`${c.source}->${c.target}`;a.has(u)||(a.add(u),(d=o.get(c.source))==null||d.push(c.target),s.set(c.target,(s.get(c.target)??0)+1))}return Kq({itemById:r,items:e,outgoing:o,indegree:s,layer:i,options:n})}function $q(e,t){let n=new Set,r=[];for(let o of t){if(o.source===o.target||!e.has(o.source)||!e.has(o.target))continue;let s=`${o.source}->${o.target}`;n.has(s)||(n.add(s),r.push(o))}return r}function Wq(e,t){var a,d;let n=new Map(e.map(c=>[c.node.id,c])),r=e.map(c=>c.node.id),o=new Map;for(let c of r)o.set(c,new Set);for(let c of t)(a=o.get(c.source))==null||a.add(c.target),(d=o.get(c.target))==null||d.add(c.source);let s=[],i=new Set;for(let c of r){if(i.has(c))continue;let u=[],p=[c];for(i.add(c);p.length>0;){let m=p.pop();u.push(m);let g=[...o.get(m)??[]].filter(y=>!i.has(y));Vn(g,n);for(let y of g.reverse())i.add(y),p.push(y)}Vn(u,n);let l=new Set(u),f=u.flatMap(m=>{let g=n.get(m);return g?[g]:[]}),h=t.filter(m=>l.has(m.source)&&l.has(m.target));s.push({edges:h,ids:u,items:f})}return s}function Qq(e,t){let n;for(let[r,o]of e){let s=t.get(r);if(!s)continue;let i={minX:o.x,minY:o.y,maxX:o.x+s.node.w,maxY:o.y+s.node.h};n=n?{minX:Math.min(n.minX,i.minX),minY:Math.min(n.minY,i.minY),maxX:Math.max(n.maxX,i.maxX),maxY:Math.max(n.maxY,i.maxY)}:i}return n}function Xv(e,t){let n=[...e].sort((h,m)=>tt(h,m)),r=Ne(n.map(h=>h.rect)),o=(r==null?void 0:r.minX)??0,s=(r==null?void 0:r.minY)??0,i=(t==null?void 0:t.horizontalGap)??120,a=(t==null?void 0:t.verticalGap)??80,d=Math.max(1,(t==null?void 0:t.gridColumns)??Math.ceil(Math.sqrt(n.length))),c=Math.max(...n.map(h=>h.node.w),0),u=Math.max(...n.map(h=>h.node.h),0),p=c+i,l=u+a,f=new Map;return n.forEach((h,m)=>{f.set(h.node.id,{x:o+m%d*p,y:s+Math.floor(m/d)*l})}),f}function Jq(e,t){let n=e.edges.length>0?Xq(e.items,e.edges,t):Xv(e.items,t);if(!n)return;let r=Qq(n,new Map(e.items.map(o=>[o.node.id,o])));if(r)return{bounds:r,positions:n}}function Zq(e,t,n){let r=(n==null?void 0:n.componentGap)??Fq,o=e.reduce((p,l)=>p+(l.bounds.maxX-l.bounds.minX)*(l.bounds.maxY-l.bounds.minY),0),s=Math.max(...e.map(p=>p.bounds.maxX-p.bounds.minX),0),i=Math.max(s,Math.sqrt(o)*jq),a=new Map,d=t.minX,c=t.minY,u=0;for(let p of e){let l=p.bounds.maxX-p.bounds.minX,f=p.bounds.maxY-p.bounds.minY;d>t.minX&&d+l>t.minX+i&&(d=t.minX,c+=u+r,u=0);let h=d-p.bounds.minX,m=c-p.bounds.minY;for(let[g,y]of p.positions)a.set(g,{x:y.x+h,y:y.y+m});d+=l+r,u=Math.max(u,f)}return a}function eF(e,t,n){let r=new Set(e.map(a=>a.node.id)),o=$q(r,t);if(o.length===0)return;let s=[];for(let a of Wq(e,o)){let d=Jq(a,n);if(!d)return;s.push(d)}if(s.length===0)return;if(s.length===1)return s[0].positions;let i=Ne(e.map(a=>a.rect));return i?Zq(s,i,n):void 0}function $v({nodes:e,edges:t,ids:n,options:r}){let o=wr(e,n);return eF(o,Object.values(t),r)??Xv(o,r)}function mi(e,t){let n=(e==null?void 0:e.horizontalGap)??(t==="horizontal"?240:48),r=(e==null?void 0:e.verticalGap)??(t==="horizontal"?96:480);return{horizontalGap:n,verticalGap:r,mainGap:t==="horizontal"?n:r,crossGap:t==="horizontal"?r:n}}function Wv(e,t){let{horizontalGap:n,verticalGap:r}=mi(e,t);return{...e,horizontalGap:n,verticalGap:r,nodeGap:(e==null?void 0:e.nodeGap)??80,componentGap:(e==null?void 0:e.componentGap)??240,isolatedPlacement:(e==null?void 0:e.isolatedPlacement)??"left"}}function Qv(e,t){var n;return((n=e.get(t))==null?void 0:n.node.h)??0}function Jv(e,t){var n;return((n=e.get(t))==null?void 0:n.node.w)??0}function Dr(e,t,n){return n==="horizontal"?Qv(e,t):Jv(e,t)}function Zv(e,t,n){return n==="horizontal"?Jv(e,t):Qv(e,t)}var aF=4;function eS(e){if(e.length===0)return-1;let t=[...e].sort((r,o)=>r-o),n=Math.floor(t.length/2);return t.length%2===1?t[n]:(t[n-1]+t[n])/2}function nS(e,t,n){var u;let r=new Map;for(let p of e)r.set(p,[]);let o=new Set;for(let p of t){if(p.source===p.target||!r.has(p.source)||!r.has(p.target))continue;let l=`${p.source}->${p.target}`;o.has(l)||(o.add(l),(u=r.get(p.source))==null||u.push(p.target))}for(let p of r.values())p.sort((l,f)=>tt(n.get(l),n.get(f)));let s=new Map,i=new Map;for(let p of e)s.set(p,[]),i.set(p,[]);let a=new Map;for(let p of e)a.set(p,0);let d=[...e].sort((p,l)=>tt(n.get(p),n.get(l))),c=p=>{var f,h;let l=[{id:p,index:0}];for(a.set(p,1);l.length>0;){let m=l[l.length-1],g=r.get(m.id)??[];if(m.index<g.length){let y=g[m.index];m.index+=1;let v=a.get(y);if(v===1)continue;(f=s.get(m.id))==null||f.push(y),(h=i.get(y))==null||h.push(m.id),v===0&&(a.set(y,1),l.push({id:y,index:0}))}else a.set(m.id,2),l.pop()}};for(let p of d)a.get(p)===0&&c(p);return{out:s,inn:i}}function dF(e,t,n){var a;let r=new Map;for(let d of e)r.set(d,((a=t.inn.get(d))==null?void 0:a.length)??0);let o=new Map;for(let d of e)o.set(d,0);let s=e.filter(d=>(r.get(d)??0)===0).sort((d,c)=>tt(n.get(d),n.get(c))),i=0;for(;i<s.length;){let d=s[i];i+=1;for(let c of t.out.get(d)??[]){o.set(c,Math.max(o.get(c)??0,(o.get(d)??0)+1));let u=(r.get(c)??0)-1;r.set(c,u),u===0&&s.push(c)}}return o}function cF(e,t,n){let r=Math.max(0,...e.map(s=>t.get(s)??0)),o=Array.from({length:r+1},()=>[]);for(let s of e)o[t.get(s)??0].push(s);for(let s of o)s.sort((i,a)=>tt(n.get(i),n.get(a)));return o}function tS(e,t,n){let r=new Map(e.map((s,i)=>[s,i])),o=new Map;for(let s of e){let i=t(s);o.set(s,i<0?r.get(s)??0:i)}e.sort((s,i)=>(o.get(s)??0)-(o.get(i)??0)||tt(n.get(s),n.get(i)))}function uF(e,t,n){let r=new Map,o=s=>{s.forEach((i,a)=>r.set(i,a))};e.forEach(o);for(let s=0;s<aF;s+=1)if(s%2===0)for(let a=1;a<e.length;a+=1)tS(e[a],d=>eS((t.inn.get(d)??[]).map(c=>r.get(c)).filter(c=>c!==void 0)),n),o(e[a]);else for(let a=e.length-2;a>=0;a-=1)tS(e[a],d=>eS((t.out.get(d)??[]).map(c=>r.get(c)).filter(c=>c!==void 0)),n),o(e[a])}function rS(e,t,n){let r=dF(e,t,n),o=cF(e,r,n);return uF(o,t,n),o}var pF=6;function Xl(e){return e.length===0?0:e.reduce((t,n)=>t+n,0)/e.length}function lF(e,t,n,r,o,s,i){if(e.length===0)return;let a=e.map(p=>(t.get(p)??r.get(p)??0)-Dr(o,p,i)/2);for(let p=1;p<e.length;p+=1){let l=a[p-1]+Dr(o,e[p-1],i)+s;a[p]<l&&(a[p]=l)}let d=e.map((p,l)=>a[l]+Dr(o,p,i)/2),c=e.map(p=>t.get(p)??r.get(p)??0),u=Xl(c)-Xl(d);e.forEach((p,l)=>{let f=a[l]+u;n.set(p,f),r.set(p,f+Dr(o,p,i)/2)})}function fF(e,t,n,r,o){let s=new Map,i=new Map;for(let a of e){let d=0;for(let c of a)s.set(c,d),i.set(c,d+Dr(n,c,o)/2),d+=Dr(n,c,o)+r}for(let a=0;a<pF;a+=1){let d=a%2===0,c=d?e.map((u,p)=>p):e.map((u,p)=>p).reverse();for(let u of c){let p=e[u],l=new Map;for(let f of p){let h=d?t.inn.get(f)??[]:t.out.get(f)??[],m=[...t.inn.get(f)??[],...t.out.get(f)??[]],y=(h.length>0?h:m).map(v=>i.get(v)).filter(v=>v!==void 0);l.set(f,y.length>0?Xl(y):i.get(f)??0)}lF(p,l,s,i,n,r,o)}}return s}function mF(e,t,n){let r=new Map,o=0;for(let s of e)r.set(s.node.id,n==="horizontal"?{x:0,y:o}:{x:o,y:0}),o+=(n==="horizontal"?s.node.h:s.node.w)+t;return r}function oS(e,t,n="horizontal"){let r=new Map(e.items.map(f=>[f.node.id,f])),o=e.items.map(f=>f.node.id),{mainGap:s,crossGap:i}=mi(t,n);if(e.items.length<2||e.edges.length===0)return mF(e.items,i,n);let a=nS(o,e.edges,r),d=rS(o,a,r),c=fF(d,a,r,i,n),u=[],p=0;for(let f=0;f<d.length;f+=1){u[f]=p;let h=Math.max(0,...d[f].map(m=>Zv(r,m,n)));p+=h+s}let l=new Map;for(let f=0;f<d.length;f+=1)for(let h of d[f]){let m=c.get(h)??0;l.set(h,n==="horizontal"?{x:u[f],y:m}:{x:m,y:u[f]})}return l}function sS({nodes:e,edges:t,ids:n,options:r,axis:o}){let s=Wv(r,o);return Or({nodes:e,edges:t,ids:n,options:s,resolveComponentPositions:(i,a)=>oS(i,a,o)})}function iS({nodes:e,edges:t,ids:n,options:r}){return sS({nodes:e,edges:t,ids:n,options:r,axis:"horizontal"})}function aS({nodes:e,edges:t,ids:n,options:r}){return sS({nodes:e,edges:t,ids:n,options:r,axis:"vertical"})}var dS=.9;function hF(e,t){return(e==null?void 0:e.stressIterations)!==void 0?Math.max(0,e.stressIterations):Math.max(24,Math.min(80,Math.floor(2400/Math.max(1,t))))}function gF(e,t){let n=e.items.reduce((i,a)=>i+a.node.w,0)/e.items.length,r=e.items.reduce((i,a)=>i+a.node.h,0)/e.items.length,o=(t==null?void 0:t.horizontalGap)??120,s=(t==null?void 0:t.verticalGap)??80;return Math.max(120,Math.min(520,Math.max(n+o,r+s)))}function yF(e,t){if(e.items.length<2||e.edges.length===0)return Kl(e,t);let n=(t==null?void 0:t.nodeGap)??40,r=gF(e,t),o=hF(t,e.items.length),s=new Map,i=new Map,a=new Map,d=0,c=0;for(let p of e.items){let l=jt(p.rect),f={x:e.center.x+(l.x-e.center.x)*dS,y:e.center.y+(l.y-e.center.y)*dS};s.set(p.node.id,{...l}),i.set(p.node.id,f),a.set(p.node.id,{w:p.node.w,h:p.node.h}),d+=f.x,c+=f.y}d/=e.items.length,c/=e.items.length;for(let p=0;p<o;p+=1){for(let g of e.edges){let y=s.get(g.source),v=s.get(g.target);if(!y||!v)continue;let S=v.x-y.x,b=v.y-y.y,I=Math.max(1,Math.hypot(S,b)),N=Math.max(-r*.18,Math.min(r*.18,(I-r)*.08)),w=S/I*N*.5,ne=b/I*N*.5;y.x+=w,y.y+=ne,v.x-=w,v.y-=ne}for(let g=0;g<e.items.length;g+=1)for(let y=g+1;y<e.items.length;y+=1){let v=e.items[g],S=e.items[y],b=s.get(v.node.id),I=s.get(S.node.id),N=a.get(v.node.id),w=a.get(S.node.id);if(!b||!I||!N||!w)continue;let ne=I.x-b.x,Ge=I.y-b.y,Y=(N.w+w.w)/2+n-Math.abs(ne),T=(N.h+w.h)/2+n-Math.abs(Ge);if(Y>0&&T>0){if(Y<=T){let j=ne===0?v.node.id.localeCompare(S.node.id)<=0?1:-1:Math.sign(ne),J=Y/2;b.x-=j*J,I.x+=j*J}else{let j=Ge===0?v.node.id.localeCompare(S.node.id)<=0?1:-1:Math.sign(Ge),J=T/2;b.y-=j*J,I.y+=j*J}continue}let F=Math.max(1,Math.hypot(ne,Ge));if(F<r*.55){let j=ne===0?v.node.id.localeCompare(S.node.id)<=0?1:-1:ne/F,J=Ge===0?0:Ge/F,ie=(r*.55-F)*.015;b.x-=j*ie,b.y-=J*ie,I.x+=j*ie,I.y+=J*ie}}let l=0,f=0;for(let g of e.items){let y=s.get(g.node.id),v=i.get(g.node.id);!y||!v||(y.x+=(v.x-y.x)*.035,y.y+=(v.y-y.y)*.035,l+=y.x,f+=y.y)}l/=e.items.length,f/=e.items.length;let h=(d-l)*.15,m=(c-f)*.15;for(let g of s.values())g.x+=h,g.y+=m}let u=new Map;for(let p of e.items){let l=s.get(p.node.id);l&&u.set(p.node.id,{x:l.x-p.node.w/2,y:l.y-p.node.h/2})}return li(u,e,n)}function cS({nodes:e,edges:t,ids:n,options:r}){return Or({nodes:e,edges:t,ids:n,options:r,resolveComponentPositions:yF})}var AF="horizontal-directed-cluster";function uS(e,t){let n=t!=null&&t.length?ft(e,t):Object.values(e).filter(o=>o.parentId===null).map(o=>o.id),r=new Set;return n.filter(o=>{let s=e[o];return!s||s.parentId!==null||r.has(o)?!1:(r.add(o),!0)}).sort((o,s)=>Ul(e[o],e[s]))}function Oo(e,t,n,r){let o=(r==null?void 0:r.strategy)??AF;return o==="component-packing"?Kv({nodes:e,edges:t,ids:n,options:r}):o==="incremental-stress"?cS({nodes:e,edges:t,ids:n,options:r}):o==="dag-layered"?$v({nodes:e,edges:t,ids:n,options:r}):o==="vertical-directed-cluster"?aS({nodes:e,edges:t,ids:n,options:r}):iS({nodes:e,edges:t,ids:n,options:r})}function Qd(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Do(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function $l(e){if(!(!Qd(e)||!Do(e.w)||!Do(e.h)))return{w:e.w,h:e.h}}function Wd(e){return{w:Do(e.w)?e.w:320,h:Do(e.h)?e.h:180}}function Jd(e){return!!(e&&(e.type===be||e.type===Ft)&&Array.isArray(e.children))}function kr(e){return Jd(e)&&Qd(e.data)&&e.data.collapsed===!0}function Wl(e){return Jd(e)&&Qd(e.data)?$l(e.data.expandedSize):void 0}function hi(e){return kr(e)?Wl(e)??Wd(e):Wd(e)}function gi(e,t){if(kr(e)){e.data.expandedSize={...t};return}e.w=t.w,e.h=t.h}function Zd(e){if(!Jd(e))return!1;Qd(e.data)||(e.data={});let{data:t}=e,n=$l(t.expandedSize);if(t.collapsed===!0){let r=!1;return n?(!Do(e.w)||!Do(e.h))&&(e.w=320,e.h=180,r=!0):(t.expandedSize=Wd(e),e.w=320,e.h=180,r=!0),r}return n?(e.w=n.w,e.h=n.h,delete t.expandedSize,!0):!1}function pS(e,t){if(!Jd(e))return!1;let n=Zd(e),{data:r}=e;if(r.collapsed===!0===t)return n;if(t)return r.expandedSize=Wd(e),r.collapsed=!0,e.w=320,e.h=180,!0;let o=$l(r.expandedSize);return r.collapsed=!1,o&&(e.w=o.w,e.h=o.h),delete r.expandedSize,!0}function lS(e,t){return e.minX>=t.minX-.001&&e.minY>=t.minY-.001&&e.maxX<=t.maxX+.001&&e.maxY<=t.maxY+.001}function fS(e,t){e.x+=t.minX,e.y+=t.minY,gi(e,{w:Math.max(1,t.maxX-t.minX),h:Math.max(1,t.maxY-t.minY)})}function vF(e,t){return Ne(t.map(n=>{let r=typeof n=="string"?e[n]:void 0;return r?{minX:r.x,minY:r.y,maxX:r.x+r.w,maxY:r.y+r.h}:void 0}).filter(n=>!!n))}function SF(e,t){return Ne(t.children.map(n=>e[n]).filter(n=>!!(n&&n.parentId===t.id)).map(n=>({minX:n.x,minY:n.y,maxX:n.x+n.w,maxY:n.y+n.h})))}function bF(e,t,n,r){for(let o of t){let s=typeof o=="string"?e[o]:void 0;s&&(s.x-=n,s.y-=r)}}function IF(e,t,n,r){for(let o of t.children){let s=e[o];(s==null?void 0:s.parentId)===t.id&&(s.x-=n,s.y-=r)}}function mS(e,t,n,r){let o=e[t];if(o){if(o.x*=n,o.y*=r,kr(o)){let s=hi(o);gi(o,{w:s.w*n,h:s.h*r})}else o.w*=n,o.h*=r;if(ee(o))for(let s of o.children)mS(e,s,n,r)}}function hS(e,t,n){if(n.has(t))return;n.add(t);let r=e[t];if(ee(r))for(let o of r.children)hS(e,o,n)}function _F(e,t,n){let r=vn(e,t);if(!r)return null;let o=null,s=Number.POSITIVE_INFINITY;for(let i of Object.values(e)){if(!ee(i)||n.has(i.id))continue;let a=vn(e,i.id);if(!a||!lS(r,a))continue;let d=i.w*i.h;d<s&&(o=i.id,s=d)}return o}function RF(e,t){let{nodes:n}=e;for(let r of t){let o=n[r],s=o==null?void 0:o.parentId;if(!o||!s)continue;let i=vn(n,r),a=vn(n,s);if(i&&a&&lS(i,a))continue;let d=Ee(n,r);Nr(e,s,r),o.parentId=null,o.x=d.x,o.y=d.y}}function EF(e,t,n){let{nodes:r}=e;for(let o of t){let s=r[o];if(!s||s.parentId)continue;let i=_F(r,o,n),a=i?r[i]:void 0;if(!i||!ee(a))continue;let d=Ee(r,o),c=Ee(r,i);s.parentId=i,s.x=d.x-c.x,s.y=d.y-c.y,a.children=[...a.children.filter(u=>u!==o),o]}}function CF(e,t){var o,s;let n=[],r=new Set;for(let i of t){let a=((o=e[i])==null?void 0:o.parentId)??null;for(;a;)r.has(a)||(r.add(a),n.push(a)),a=((s=e[a])==null?void 0:s.parentId)??null}return n}function PF(e,t){let n=e[t];if(!Array.isArray(n==null?void 0:n.children)||n.children.length===0)return;let r=vF(e,n.children);if(!r)return;let o=hi(n),s={minX:Math.min(0,r.minX-40),minY:Math.min(0,r.minY-40),maxX:Math.max(o.w,r.maxX+40),maxY:Math.max(o.h,r.maxY+40)};fS(n,s),bF(e,n.children,s.minX,s.minY)}function gS(e,t,n){if(!ee(t)||kr(t)||t.w===n.w&&t.h===n.h)return;let r=t.w===0?1:n.w/t.w,o=t.h===0?1:n.h/t.h;for(let s of t.children)mS(e,s,r,o)}function yS(e,t){let{nodes:n}=e,r=ft(n,t),o=new Set;for(let s of r)hS(n,s,o);RF(e,r),EF(e,r,o)}function ec(e,t){let n=CF(e,t);for(let r of n)PF(e,r)}function ko(e,t,n=new Set){if(!t||n.has(t))return;let r=e[t];if(!ee(r))return;n.add(t);let o=SF(e,r);if(!o)return;let s={minX:o.minX-40,minY:o.minY-40,maxX:o.maxX+40,maxY:o.maxY+40};fS(r,s),IF(e,r,s.minX,s.minY),ko(e,r.parentId??null,n)}function xF(e,t){let n=[],r=new Set,o=s=>{let i=e[s];if(!(!ee(i)||r.has(s))){r.add(s);for(let a of i.children)o(a);n.push(s)}};for(let s of t)o(s);return n}function TF(e,t){let n=e[t];return ee(n)?n.children.filter(r=>{var o;return((o=e[r])==null?void 0:o.parentId)===t}):[]}function vS(e){return e==="horizontal-directed-cluster"||e==="vertical-directed-cluster"}function AS(e,t,n){var o;let r=t;for(;r;){if(n.has(r))return r;r=((o=e[r])==null?void 0:o.parentId)??null}}function NF(e,t,n){let r=new Set(n);return Object.values(t).some(o=>{let s=AS(e,o.source,r),i=AS(e,o.target,r);return!!(s&&i&&s!==i)})}function wF(e,t){let n=new Set(t);return Object.fromEntries(Object.entries(e).map(([r,o])=>[r,n.has(r)?{...o,parentId:null}:{...o}]))}function OF(e,t){let n;for(let[r,o]of t)e[r]&&(n=n?{minX:Math.min(n.minX,o.x),minY:Math.min(n.minY,o.y)}:{minX:o.x,minY:o.y});return n}function DF(e,t,n){let r=Object.fromEntries(Object.entries(e).map(([a,d])=>[a,{...d}])),o=n==="horizontal-directed-cluster"?"horizontal":"vertical",{horizontalGap:s,verticalGap:i}=mi(void 0,o);return Hd(r,t,o==="horizontal"?"vertical":"horizontal",{horizontalGap:s,verticalGap:i}),new Map(t.flatMap(a=>{let d=r[a];return d?[[a,{x:d.x,y:d.y}]]:[]}))}function kF(e,t,n){let{nodes:r}=e,o=wF(r,t),s=NF(r,e.edges,t)?Oo(o,e.edges,t,{strategy:n}):DF(o,t,n),i=OF(o,s);return i?new Map([...s.entries()].map(([a,d])=>[a,{x:d.x-i.minX+40,y:d.y-i.minY+40}])):s}function SS(e,t,n){let{nodes:r}=e,o=Vd(r,t);if(!o)return;let s=o.parentId?kF(e,o.ids,n):Oo(r,e.edges,o.ids,{strategy:n});if(s.size!==0){for(let[i,a]of s){let d=r[i];d&&(d.x=a.x,d.y=a.y)}ko(r,o.parentId)}}function bS(e,t,n,r){let o=r.strategy??"horizontal-directed-cluster";if(!["directed-cluster","horizontal-directed-cluster","vertical-directed-cluster"].includes(o)||!r.sortGroupChildren)return!1;let i=!1;for(let a of xF(e,n)){let d=TF(e,a);if(d.length<2)continue;let c=Oo(e,t,d,r);if(c.size===0)continue;let u=Ee(e,a);for(let[p,l]of c){let f=e[p];!f||f.parentId!==a||(f.x=l.x-u.x,f.y=l.y-u.y,i=!0)}ko(e,a)}return i}function MF(e,t,n){let r=ft(e,t);if(r.length<3)return;let o=wr(e,r).sort((p,l)=>n==="horizontal"?p.rect.minX-l.rect.minX:p.rect.minY-l.rect.minY);if(o.length<3)return;let s=o[0],i=o[o.length-1],a=o.reduce((p,l)=>{let f=n==="horizontal"?l.rect.maxX-l.rect.minX:l.rect.maxY-l.rect.minY;return p+f},0),c=((n==="horizontal"?i.rect.maxX-s.rect.minX:i.rect.maxY-s.rect.minY)-a)/(o.length-1),u=n==="horizontal"?s.rect.maxX+c:s.rect.maxY+c;for(let p=1;p<o.length-1;p+=1){let l=o[p];n==="horizontal"?(jd(l.node,{dx:u-l.rect.minX,dy:0}),u+=l.rect.maxX-l.rect.minX+c):(jd(l.node,{dx:0,dy:u-l.rect.minY}),u+=l.rect.maxY-l.rect.minY+c)}}function IS(e,t){let n=t.flatMap(o=>{let s=e[o];return s?[s]:[]}),r=Gv(n);if(r)for(let o of t){let s=e[o];s&&(s.x+=r.dx,s.y+=r.dy)}}function _S(e){return{moveNodes(t,n,r){return e.transact(o=>{let s=W(o),{nodes:i}=s,a=ft(i,t);for(let d of a){let c=i[d];c&&(c.x+=n.dx,c.y+=n.dy)}r!=null&&r.reparentToContainingGroup?yS(s,a):ec(i,a)},{intent:"geometry.moveNodes",mergeKey:r==null?void 0:r.mergeKey})},resizeNode(t,n,r){return e.transact(o=>{let{nodes:s}=W(o),i=s[t];i&&(gS(s,i,n),i.w=n.w,i.h=n.h),ec(s,[t])},{intent:"geometry.resizeNode",mergeKey:r==null?void 0:r.mergeKey})},setNodePosition(t,n,r){return e.transact(o=>{let{nodes:s}=W(o),i=s[t];i&&(i.x=n.x,i.y=n.y),ec(s,[t])},{intent:"geometry.setNodePosition",mergeKey:r==null?void 0:r.mergeKey})},alignNodes(t,n){return e.transact(r=>{let{nodes:o}=W(r),s=ft(o,t);if(s.length<2)return;let i=wr(o,s),a=Ne(i.map(d=>d.rect));if(a)for(let d of i)jd(d.node,zv(d.rect,a,n))},{intent:`geometry.alignNodes.${n}`})},distributeNodes(t,n){return e.transact(r=>{MF(W(r).nodes,t,n)},{intent:`geometry.distributeNodes.${n}`})},arrangeNodes(t,n,r){return e.transact(o=>{let s=W(o);if(vS(n)){SS(s,t,n);return}let{nodes:i}=s,a=Vd(i,t);a&&(Hd(i,a.ids,n,r),ko(i,a.parentId))},{intent:`geometry.arrangeNodes.${n}`})},autoLayoutNodes(t){return e.transact(n=>{var c,u,p;let r=W(n),o=uS(r.nodes,t==null?void 0:t.ids),s=(c=r.settings.autoLayout)==null?void 0:c.strategy,i=(t==null?void 0:t.strategy)??(Tr(s)?s:void 0),a=i?{...t,strategy:i}:t;if(a&&bS(r.nodes,r.edges,o,a),o.length<2){(u=t==null?void 0:t.ids)!=null&&u.length||IS(r.nodes,o);return}let d=Oo(r.nodes,r.edges,o,a);for(let[l,f]of d){let h=r.nodes[l];h&&(h.x=f.x,h.y=f.y)}(p=t==null?void 0:t.ids)!=null&&p.length||IS(r.nodes,o)},{intent:"geometry.autoLayoutNodes"})}}}function RS(e,t){let n=[],r=new Set,o=s=>{let i=e[s];if(!(!i||r.has(s))){if(ee(i)){r.add(s);for(let a of i.children)o(a);return}r.add(s),n.push(s)}};for(let s of t)o(s);return n}function ES(e,t,n){var s;let r=new Set,o=i=>{let a=e[i];if(!(!ee(a)||r.has(i))){r.add(i);for(let d of a.children)o(d)}};for(let i of t)o(i);for(let i of n){let a=((s=e[i])==null?void 0:s.parentId)??null;for(;a;){let d=e[a];ee(d)&&r.add(a),a=(d==null?void 0:d.parentId)??null}}return[...r]}function CS(e,t,n){let{nodes:r}=e,o=r[n];if(!ee(o))return;let s=[...o.children],i=Ee(r,n),{parentId:a}=o,d=a?Ee(r,a):{x:0,y:0};for(let c of s){let u=r[c];u&&(u.parentId=a,u.x=i.x+u.x-d.x,u.y=i.y+u.y-d.y)}if(a){let c=r[a];if(ee(c)){let u=c.children.indexOf(n);c.children=c.children.filter(p=>p!==n),c.children.splice(Math.max(u,0),0,...s)}}delete r[n],delete t[n];for(let c of Object.values(e.edges))(c.source===n||c.target===n)&&delete e.edges[c.id]}function LF(e,t){let n=e;if(!_t(n)||!Rt(n.content))return;let r=Rt(n.content.data)?n.content.data:n.content;r.collapsed=Rt(t.data)&&t.data.collapsed===!0;let o=Wl(t);o?r.expandedSize={...o}:delete r.expandedSize}function PS(e){return{group(t){return e.transact(n=>{let r=W(n),{nodes:o}=r,s=ft(o,t);if(s.length===0)return;let i=RS(o,s);if(i.length<2)return;let a=Ne(i.map(h=>vn(o,h)).filter(h=>!!h));if(!a)return;let d=ES(o,s,i),c=kv(o,"group","$");for(let h of d)CS(r,n.assets,h);let u=Dv(o,i),p=u?Ee(o,u):{x:0,y:0},l={x:a.minX-40,y:a.minY-40},f={id:c,type:be,x:l.x-p.x,y:l.y-p.y,w:Math.max(1,a.maxX-a.minX+40*2),h:Math.max(1,a.maxY-a.minY+40*2),parentId:u,order:Lv(o,u),data:{},children:[...i]};u&&Mv(r,u,i,c);for(let h of i){let m=o[h],g=Ee(o,h);m&&(m.parentId&&m.parentId!==u&&Nr(r,m.parentId,h),m.parentId=c,m.x=g.x-l.x,m.y=g.y-l.y)}o[c]=f},{intent:"group.create"})},ungroup(t){return e.transact(n=>{let r=W(n),{nodes:o}=r,s=o[t];if(!ee(s))return;let i=Ee(o,t),a=s.parentId?Ee(o,s.parentId):{x:0,y:0},{parentId:d}=s;for(let c of s.children){let u=o[c];u&&(u.parentId=d,u.x=i.x+u.x-a.x,u.y=i.y+u.y-a.y)}if(d){let c=o[d];if(ee(c)){let u=c.children.indexOf(t);c.children=c.children.filter(p=>p!==t),c.children.splice(Math.max(u,0),0,...s.children)}}delete o[t],delete n.assets[t];for(let c of Object.values(r.edges))(c.source===t||c.target===t)&&delete r.edges[c.id]},{intent:"group.ungroup"})},reparent(t,n,r){return e.transact(o=>{let s=W(o),{nodes:i}=s,a=i[t];if(!a||t===n)return;let d=n?i[n]:void 0;if(n&&!ee(d))return;let c=Ee(i,t);a.parentId&&Nr(s,a.parentId,t),a.parentId=n;let u=n?Ee(i,n):{x:0,y:0};if(a.x=c.x-u.x,a.y=c.y-u.y,d&&ee(d)){let p=d.children.filter(f=>f!==t),l=r===void 0?p.length:Math.max(0,Math.min(r,p.length));p.splice(l,0,t),d.children=p}},{intent:"group.reparent"})},reorderChildren(t,n){return e.transact(r=>{let o=W(r).nodes[t];ee(o)&&(o.children=[...n])},{intent:"group.reorderChildren"})},setGroupCollapsed(t,n){return e.transact(r=>{let o=W(r).nodes[t];ee(o)&&(pS(o,n),LF(r.assets[t],o))},{intent:"group.setCollapsed"})}}}function BF(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function GF(e){let t=BF(e.pippitAssetId);if(t)return{pippitAssetId:t}}function xS(e){return{setTitle(t){return e.transact(n=>{W(n).metadata.title=t},{intent:"metadata.setTitle"})},setCover(t){return e.transact(n=>{var s;let r=GF(t);if(!r)return;let{metadata:o}=W(n);((s=o.cover)==null?void 0:s.pippitAssetId)!==r.pippitAssetId&&(o.cover=r)},{intent:"metadata.setCover",undoable:!1})},setGlobalBounds(t){return e.transact(n=>{W(n).metadata.globalBounds=t},{intent:"metadata.setGlobalBounds"})}}}function UF(e){return typeof structuredClone=="function"?ai(structuredClone(e)):ai(JSON.parse(JSON.stringify(e)))}function TS(e){return{createNode(t,n={}){return e.transact(r=>{let o=W(r),s=e.registry.hydrate(t),i=n.autoCreateNodeAsset??!0,a=An(s.type);for(let d of n.assets??[]){if(r.assets[d.pippitAssetId])throw new Error(`Asset already exists: ${d.pippitAssetId}`);a&&d.pippitAssetId===s.id&&d.type!==lt&&!_t(d)&&Re.error("[canvas-sdk] biz node companion asset must be NodeAsset shape (flat content: object)",{nodeId:s.id,nodeType:s.type,assetType:d.type}),r.assets[d.pippitAssetId]=UF(d)}if(i&&a){if(r.assets[s.id])throw new Error(`Node asset already exists: ${s.id}`);r.assets[s.id]=Gd(s)}if(o.nodes[s.id]=s,s.parentId){let d=o.nodes[s.parentId];ee(d)&&!d.children.includes(s.id)&&d.children.push(s.id)}},{intent:"node.create"})},deleteNodes(t){return e.transact(n=>{let r=W(n),o=Ov(r,t);for(let s of o){let i=r.nodes[s];i!=null&&i.parentId&&Nr(r,i.parentId,s)}for(let s of o)delete r.nodes[s];for(let s of Object.values(r.edges))(o.has(s.source)||o.has(s.target))&&delete r.edges[s.id]},{intent:"node.delete"})},updateNodeData(t,n){return e.transact(r=>{let o=W(r).nodes[t];if(!o)return;if(!An(o.type)){if(Rt(o.data)||(o.data={}),typeof n=="function"){wl(o.data,n);return}let a=Rt(n)?di(n):{};if(Object.keys(a).length===0)return;Object.assign(o.data,a);return}let s=r.assets[t];if(!_t(s))throw new Te(`biz node "${t}" missing NodeAsset; cannot apply updateNodeData`,"INVARIANT_VIOLATION");if(Rt(s.content)||(s.content={}),typeof n=="function"){wl(s.content,n);return}let i=Rt(n)?di(n):{};Object.keys(i).length!==0&&Object.assign(s.content,i)},{intent:"node.updateData"})},setNodeStyle(t,n){return e.transact(r=>{let o=W(r).nodes[t];o&&(o.style={...o.style??{},...n})},{intent:"node.setStyle"})}}}function NS(e){return{updateSnapSettings(t){return e.transact(n=>{let{settings:r}=W(n);r.snap={...r.snap,...t}},{intent:"settings.updateSnap"})},setSnapEnabled(t){return e.transact(n=>{W(n).settings.snap.enabled=t},{intent:"settings.setSnapEnabled"})},setAutoLayoutStrategy(t){return e.transact(n=>{let{settings:r}=W(n);if(!t){delete r.autoLayout;return}r.autoLayout={...r.autoLayout,strategy:t}},{intent:"settings.setAutoLayoutStrategy"})}}}function Ql(e){let t={...TS(e),..._S(e),...PS(e),...Bv(e),...xS(e),...NS(e),...wv(e,()=>t)};return t}var zF=[[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[1,-1],[-1,-1]];function qF(e,t){return e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y}function FF(e,t){return{x:e.x-t,y:e.y-t,w:e.w+t*2,h:e.h+t*2}}function jF(e){return{x:e.x,y:e.y,w:e.w,h:e.h}}function VF({base:e,gap:t,searchRings:n,size:r}){let o=[e],s=r.w+t,i=r.h+t;for(let a=1;a<=n;a+=1)for(let[d,c]of zF)o.push({x:e.x+d*s*a,y:e.y+c*i*a});return o}function HF(e,t,n){return t.some(r=>qF(e,FF(r,n)))}function wS({center:e,existingNodes:t={},gap:n=24,searchRings:r=8,size:o}){let s={x:e.x-o.w/2,y:e.y-o.h/2},i=Object.values(t).filter(d=>!d.parentId).map(jF);if(i.length===0)return s;let a=VF({base:s,gap:n,searchRings:r,size:o});return a.find(d=>!HF({...d,...o},i,n))??a[0]}var OS;function YF(){let e=globalThis.console;if(!e||typeof e!="object")return;let t=e.warn;return typeof t=="function"?t.bind(e):void 0}function yi(e){var t;if(OS)try{OS({...e,context:KF(e.context),metrics:XF(e.metrics)})}catch(n){(t=YF())==null||t("[canvas-sdk] telemetry reporter failed",n)}}function KF(e){if(!e)return;let t={},n=40;for(let[r,o]of Object.entries(e)){if(n<=0)break;t[r]=$F(o),n-=1}return t}function XF(e){if(!e)return;let t={};for(let[n,r]of Object.entries(e))Number.isFinite(r)&&(t[n]=r);return Object.keys(t).length?t:void 0}function $F(e){var t;return e instanceof Error?`${e.name}: ${e.message}`:typeof e=="string"?e.length>500?`${e.slice(0,500)}...`:e:e===null||typeof e=="number"||typeof e=="boolean"||typeof e>"u"?e:Array.isArray(e)?`[array:${e.length}]`:typeof e=="object"?`[object:${((t=e.constructor)==null?void 0:t.name)||"Object"}]`:String(e)}var WF=e=>String(e).replace(/~/g,"~0").replace(/\//g,"~1"),QF=e=>e.replace(/~1/g,"/").replace(/~0/g,"~"),JF=e=>/^\d+$/.test(e)?Number(e):e,ZF=e=>e.length===0?"":`/${e.map(WF).join("/")}`,Jl=e=>{if(e==="")return[];if(!e.startsWith("/"))throw new Error(`Invalid JSON pointer: ${e}`);return e.slice(1).split("/").map(QF).map(JF)},e2=e=>{if(e.path[0]==="revision"||e.path[0]!=="assets"||e.path[1]===void 0)return null;let t=String(e.path[1]),n=e.path.slice(2),r={assetId:t,op:e.op,path:ZF(n)};return e.op!=="remove"&&(r.value=e.value),r},Hn=e=>{let t=[];for(let n of e){let r=e2(n);r&&t.push(r)}return t},t2=e=>{let t={op:e.op,path:["assets",e.assetId,...Jl(e.path)]};return e.op!=="remove"&&(t.value=e.value),t},tc=e=>e.map(t2);function Mo(e,t,n){e.assets[t]=n}function Zl(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function n2(e){let t=e;if(!(!_t(t)||!Zl(t.content)))return Zl(t.content.data)?t.content.data:t.content}function Ai(e,t){let n=Ld(e,r=>{for(let o of Object.values(r.assets))if(Ut(o)){for(let s of Object.keys(o.content.nodes)){let i=t.hydrate(o.content.nodes[s],s),a=r.assets[s];if(!An(i.type)){let c=n2(a),u=Zl(i.data)?i.data:{};o.content.nodes[s]=t.hydrate({...i,data:c?{...c,...u}:i.data},s);continue}if(_t(a)){o.content.nodes[s]=t.hydrate({...i,type:a.type},s);continue}if(!a){o.content.nodes[s]=i;continue}Re.error("[canvas-sdk:hydrate] biz node companion asset has invalid shape",{nodeId:s,nodeType:i.type,assetType:a.type}),o.content.nodes[s]=i}for(let s of Object.values(o.content.nodes))Zd(s)}});return ai(n)}function DS(e){return Object.keys(e).sort()}function ef(e,t){return JSON.stringify(e)===JSON.stringify(t)}function kS(e,t){et(e,t)}function r2(e,t){let n=DS(e),r=DS(t);return n.length===r.length&&n.every((o,s)=>o===r[s]&&ef(e[o],t[o]))}function MS(e,t){let[n,r,o]=qt(e,s=>{s.rootCanvasId=t.rootCanvasId;for(let i of Object.keys(s.assets))i in t.assets||delete s.assets[i];for(let[i,a]of Object.entries(t.assets)){let d=s.assets[i];if(!d){Mo(s,i,a);continue}ef(d,a)||kS(d,a)}});return{forwardPatches:Hn(r),reversePatches:Hn(o),nextState:n}}function LS(e,t){return e.rootCanvasId===t.rootCanvasId&&r2(e.assets,t.assets)}function tf(e,t,n={}){let r=e.getState();return r.rootCanvasId!==t.rootCanvasId?{status:"aborted",reason:"root-canvas-id-mismatch"}:t.assets[t.rootCanvasId]?LS(r,t)?{status:"noop",reason:"no-changes"}:e.transact(o=>{for(let s of Object.keys(o.assets))s in t.assets||delete o.assets[s];for(let[s,i]of Object.entries(t.assets)){let a=o.assets[s];if(!a){Mo(o,s,i);continue}ef(a,i)||kS(a,i)}for(let s of Object.values(o.assets))if(Ut(s))for(let i of Object.values(s.content.nodes))Zd(i)},n):{status:"aborted",reason:"missing-root-canvas-asset"}}function BS(e={}){return{undoStack:[],redoStack:[],limit:e.limit??200,mergeWindow:e.mergeWindow??500}}function o2(e,t){if(!t.historyGroupKey||t.historyGroupMode!=="append")return-1;for(let n=e.length-1;n>=0;n-=1)if(e[n].historyGroupKey===t.historyGroupKey)return n;return-1}function s2(e,t){return{...e,forwardPatches:[...e.forwardPatches,...t.forwardPatches],reversePatches:[...t.reversePatches,...e.reversePatches],timestamp:t.timestamp}}function nf(e,t,n){if(!n||t.source!=="local")return;let r=o2(e.undoStack,t);if(r>=0){e.undoStack[r]=s2(e.undoStack[r],t),e.redoStack=[];return}let o=e.undoStack[e.undoStack.length-1];o&&t.mergeKey&&o.mergeKey===t.mergeKey&&t.timestamp-o.timestamp<=e.mergeWindow?e.undoStack[e.undoStack.length-1]={...o,forwardPatches:[...o.forwardPatches,...t.forwardPatches],reversePatches:[...t.reversePatches,...o.reversePatches],timestamp:t.timestamp}:(e.undoStack.push(t),e.undoStack.length>e.limit&&e.undoStack.shift()),e.redoStack=[]}function rf(e){e.undoStack=[],e.redoStack=[]}function of(e,t,n,r){let o=-1,s=a=>{throw new Te(a,"MIDDLEWARE_REJECTED")},i=a=>{if(a<=o)throw new Te("Middleware called next() multiple times","MIDDLEWARE_REJECTED");o=a;let d=e[a];d&&d({txId:t.id,forwardPatches:t.forwardPatches,reversePatches:t.reversePatches,intent:t.intent,source:t.source,nextState:r,prevState:n,reject:s},()=>i(a+1))};i(0)}function GS(e){let t={id:e.txId,intent:e.intent,forwardPatches:e.forwardPatches,reversePatches:e.reversePatches,timestamp:Date.now(),source:"remote"};return t.undoable=!1,t}function US(e){return{applyRemoteSnapshot(t,n){let r=e.getState(),{forwardPatches:o,reversePatches:s,nextState:i}=MS(r,t);if(o.length===0)return{status:"noop",reason:"no-changes"};let a=GS({forwardPatches:o,intent:"remote.snapshot",reversePatches:s,txId:e.nextTransactionId()}),d=Ai(i,e.registry);return e.setState(d),e.onStateCommitted(),e.notify(a,o,r,d),e.reportCommit(a,d),n==null||n.conflicts,{status:"committed",transaction:a}},applyRemotePatches(t,n){if(t.length===0)return{status:"noop",reason:"no-changes"};let r=e.getState();try{let[o,,s]=qt(r,d=>yn(d,tc(t))),i=Ai(o,e.registry),a=GS({forwardPatches:[...t],intent:"remote.patches",reversePatches:Hn(s),txId:e.nextTransactionId()});return e.setState(i),e.onStateCommitted(),e.notify(a,a.forwardPatches,r,i),e.reportCommit(a,i),n==null||n.conflicts,{status:"committed",transaction:a}}catch(o){return e.logAbort({error:o,intent:"remote.patches",source:"remote"}),{status:"aborted",reason:o instanceof Error?o.message:String(o),error:o instanceof Error?o:void 0}}}}}function zS(){let e=new Set,t=new Set;return{notify(n,r,o,s){let i={transaction:n,prevState:o,nextState:s};for(let d of Array.from(e))d(i);if(r.length===0)return;let a={transaction:n,patches:r,prevState:o,nextState:s};for(let d of Array.from(t))d(a)},subscribe(n){return e.add(n),()=>{e.delete(n)}},subscribePatches(n,r){let o=r?s=>{let i=s.patches.filter(a=>a.assetId===r.assetId);i.length!==0&&n({...s,patches:i})}:n;return t.add(o),()=>{t.delete(o)}}}}var i2=/\b(node|edge|asset|canvas|group|tx|run|request|workflow)[_-][A-Za-z0-9_-]+\b/gi,a2=/\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/gi;function d2(e){return e instanceof Error?e.message:String(e)}function c2(e){return e instanceof Error?e.name:typeof e}function qS(e){if(e instanceof Te)return e.code}function u2(e){return e.replace(i2,"$1_<id>").replace(a2,"<uuid>").replace(/\b\d{6,}\b/g,"<number>").replace(/\s+/g," ").trim()||"unknown"}function p2(e,t){let n=qS(e);return n&&n!=="MIDDLEWARE_REJECTED"?n:u2(t)}function FS(e){let t=d2(e),n=qS(e);return{canvas_sdk_error_reason:p2(e,t),error_name:c2(e),reason:t,...n?{transaction_error_code:n}:{}}}zt();function sf(e){let t=e.registry??qd(),n=zS(),r=[Gl,...e.middlewares??[]],o=BS({limit:e.historyLimit,mergeWindow:e.mergeWindow}),s=Ai(e.initialDocument,t),i=null,a=0,d=0,c,u=(m,g)=>{l2(m,g,e.getTelemetryContext)},p=()=>{a+=1;let m=typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;return`tx_${a}_${m}`},l=(m,g,y)=>{if(m.length===0)return{status:"noop",reason:"no-changes"};let v=s,b=Ld(v,N=>yn(N,tc(m))),I={id:p(),intent:y.intent,forwardPatches:[...m],reversePatches:[...g],timestamp:Date.now(),mergeKey:y.mergeKey,historyGroupKey:y.historyGroupKey,historyGroupMode:y.historyGroupMode,source:y.source};return I.undoable=y.undoable,y.skipMiddleware||of(r,I,v,b),s=b,d+=1,nf(o,I,y.undoable),n.notify(I,I.forwardPatches,v,s),u(I,s),{status:"committed",transaction:I}},f=US({clearHistory:()=>rf(o),getState:()=>s,logAbort:VS,nextTransactionId:p,notify:n.notify,registry:t,reportCommit:u,setState:m=>{s=m},onStateCommitted:()=>{d+=1}}),h={transact(m,g={}){if(i){let b=m(i);if(jS(b))throw new Te("transact recipe must be synchronous","ASYNC_RECIPE");return{status:"noop",reason:"merged-into-outer"}}let y=s,v=g.source??"local",S=g.undoable??!0;try{let[b,I,N]=qt(y,T=>{i=T;try{let F=m(T);if(jS(F))throw new Te("transact recipe must be synchronous","ASYNC_RECIPE")}finally{i=null}}),w=Hn(I),ne=Hn(N);if(w.length===0)return{status:"noop",reason:"no-changes"};let Ge=b,Y={id:p(),intent:g.intent,forwardPatches:w,reversePatches:ne,timestamp:Date.now(),mergeKey:g.mergeKey,historyGroupKey:g.historyGroupKey,historyGroupMode:g.historyGroupMode,source:v};return Y.undoable=S,g.skipMiddleware||of(r,Y,y,Ge),s=Ge,d+=1,nf(o,Y,S),n.notify(Y,w,y,s),u(Y,s),{status:"committed",transaction:Y}}catch(b){return i=null,m2(b)&&VS({error:b,intent:g.intent,source:v}),{status:"aborted",reason:b instanceof Error?b.message:String(b),error:b instanceof Error?b:void 0}}},getState(){return s},getRevision(){return d},getRootCanvas(){return wd(s)},getRootCanvasContent(){return x(s)},subscribe:n.subscribe,subscribePatches:n.subscribePatches,subscribeSelector(m,g,y){let v=(y==null?void 0:y.equalityFn)??Object.is,S=m(s);return h.subscribe(({nextState:b})=>{let I=m(b);if(!v(I,S)){let N=S;S=I,g(I,N)}})},undo(){let m=o.undoStack.pop();if(!m)return{status:"noop",reason:"no-changes"};let g=l(m.reversePatches,m.forwardPatches,{intent:m.intent?`undo:${m.intent}`:"undo",source:"local",undoable:!1});return g.status==="committed"?o.redoStack.push(m):o.undoStack.push(m),g},redo(){let m=o.redoStack.pop();if(!m)return{status:"noop",reason:"no-changes"};let g=l(m.forwardPatches,m.reversePatches,{intent:m.intent?`redo:${m.intent}`:"redo",source:"local",undoable:!1});return g.status==="committed"?o.undoStack.push(m):o.redoStack.push(m),g},canUndo(){return o.undoStack.length>0},canRedo(){return o.redoStack.length>0},clearHistory(){rf(o)},use(m){return r.push(m),()=>{let g=r.indexOf(m);g>=0&&r.splice(g,1)}},applyRemoteSnapshot:f.applyRemoteSnapshot,applyRemotePatches:f.applyRemotePatches,get commands(){return c},registry:t};return c=Ql(h),h}function l2(e,t,n){let r=new Set(e.forwardPatches.map(s=>s.assetId)),o=x(t);yi({action:"canvas_transaction_commit",category:"canvas",packageName:"canvas-sdk",status:"success",context:{...f2(n),root_canvas_id:t.rootCanvasId,transaction_id:e.id,transaction_history_group_key:e.historyGroupKey,transaction_history_group_mode:e.historyGroupMode,transaction_intent:e.intent,transaction_merge_key:e.mergeKey,transaction_source:e.source,undoable:e.undoable??!0},metrics:{asset_count:r.size,count:1,node_count:Object.keys(o.nodes).length,patch_count:e.forwardPatches.length}})}function f2(e){try{return e==null?void 0:e()}catch{return}}function jS(e){return!!(e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function")}function VS({error:e,intent:t,source:n}){Re.error("[canvas-sdk] transaction aborted",{error:e,...FS(e),intent:t,source:n})}function m2(e){return!(e instanceof Te&&e.code==="READ_ONLY")}function A2(e){return typeof structuredClone=="function"?structuredClone(e):JSON.parse(JSON.stringify(e))}function HS(){let e,t=0;return{getCanvasClipboard(){return e},setCanvasClipboard(n){e=A2(n),t=0},clearCanvasClipboard(){e=void 0,t=0},getCanvasClipboardPasteCount(){return t},markCanvasClipboardPasted(){t+=1}}}function mt(e,t,n){let r=e.get(t)??new Set;r.add(n),e.set(t,r)}function ht(e,t,n){let r=e.get(t);r&&(r.delete(n),r.size===0&&e.delete(t))}function qe(e,t,n){for(let r of Array.from(e.get(t)??[]))r(n)}function Ae(e,t){return()=>{e.delete(t)}}function YS(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,{...n}]))}function KS(e,t){return(e==null?void 0:e.x)===(t==null?void 0:t.x)&&(e==null?void 0:e.y)===(t==null?void 0:t.y)}function XS(){let e={},t=new Set,n=new Map,r=o=>{let s=e;e=YS(o);for(let a of Array.from(t))a(e);let i=new Set([...Object.keys(s),...Object.keys(e)]);for(let a of i){let d=s[a],c=e[a];KS(d,c)||qe(n,a,c)}};return{getDragPreview(){return e},getPreviewOf(o){return e[o]},setDragPreview:r,update(o,s){r({...e,[o]:{...s}})},updateMany(o){let s={...e};for(let{id:i,position:a}of o)s[i]={...a};r(s)},clear(o){if(o){let s={...e};delete s[o],r(s);return}r({})},clearDragPreview(){r({})},subscribeDragPreview(o){return t.add(o),Ae(t,o)},subscribePreviewOf(o,s){return mt(n,o,s),()=>ht(n,o,s)}}}function $S(){let e,t=new Set,n=new Map,r=o=>{if(e===o)return;let s=e;e=o;for(let i of Array.from(t))i(e);s&&qe(n,s,!1),e&&qe(n,e,!0)};return{getHoveredEdgeId(){return e},isEdgeHovered(o){return e===o},setHoveredEdge:r,clearEdgeHover(){r(void 0)},subscribeEdgeHover(o){return t.add(o),Ae(t,o)},subscribeEdgeHoverOf(o,s){return mt(n,o,s),()=>ht(n,o,s)}}}function WS(){let e,t=new Set,n=new Map,r=s=>{if(s!==e){for(let i of Array.from(t))i(e);s&&qe(n,s,!1),e&&qe(n,e,!0)}},o=s=>{let i=e;e=s,r(i)};return{getSelectedEdgeId(){return e},isEdgeSelected(s){return e===s},setSelectedEdge(s){o(s)},clearEdgeSelection(){o(void 0)},subscribeEdgeSelection(s){return t.add(s),Ae(t,s)},subscribeEdgeSelectionOf(s,i){return mt(n,s,i),()=>ht(n,s,i)}}}function QS(){let e=null,t=new Set,n=new Map,r=o=>{if(e===o)return;let s=e;e=o;for(let i of Array.from(t))i(e);s&&qe(n,s,!1),e&&qe(n,e,!0)};return{getHovered(){return e},isHovered(o){return e===o},setHovered:r,clear(){r(null)},subscribeHover(o){return t.add(o),Ae(t,o)},subscribeHoverOf(o,s){return mt(n,o,s),()=>ht(n,o,s)}}}function JS(e=!1){let t=e,n=new Set,r=o=>{if(t!==o){t=o;for(let s of Array.from(n))s(t)}};return{isMiniMapVisible(){return t},setMiniMapVisible:r,toggleMiniMapVisible(){r(!t)},subscribeMiniMapVisible(o){return n.add(o),Ae(n,o)}}}function v2(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function ZS(){let e=new Set,t=new Set,n=new Map,r=o=>{let s=e,i=new Set(o);if(v2(s,i))return;e=i;for(let d of Array.from(t))d(e);let a=new Set([...s,...i]);for(let d of a)s.has(d)!==i.has(d)&&qe(n,d,i.has(d))};return{getHighlightedNodeIds(){return e},isNodeHighlighted(o){return e.has(o)},setHighlightedNodes:r,clearHighlightedNodes(){r([])},subscribeNodeHighlight(o){return t.add(o),Ae(t,o)},subscribeNodeHighlightOf(o,s){return mt(n,o,s),()=>ht(n,o,s)}}}function S2(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function eb(){let e=new Set,t=new Set,n=r=>{let o=new Set([...r].map(s=>s.trim()).filter(s=>!!s));if(!S2(e,o)){e=o;for(let s of Array.from(t))s(e)}};return{getHighlightedNodeTypes(){return e},isNodeTypeHighlighted(r){return e.has(r)},setHighlightedNodeTypes:n,clearHighlightedNodeTypes(){n([])},subscribeNodeTypeHighlight(r){return t.add(r),Ae(t,r)}}}function Vt(e){switch(e.type){case"single_node":return new Set([e.activeId]);case"multi_node_discrete":case"multi_node_region":return new Set(e.selectedIds);case"none":default:return new Set}}function nc(e){let t=new Set(e);return t.size===0?{type:"none"}:t.size===1?{type:"single_node",activeId:[...t][0]}:{type:"multi_node_discrete",selectedIds:t}}function af(e){if(e.type==="multi_node_discrete"){let t=new Set(e.selectedIds);return{...nc(t),...t.size>1&&e.activeId&&t.has(e.activeId)?{activeId:e.activeId}:{}}}if(e.type==="multi_node_region"){let t=new Set(e.selectedIds);return t.size===0?{type:"none"}:{...e,selectedIds:t}}return e}function tb(e,t,n){let r=new Set(t),o=new Set(n==="replace"?[]:Vt(e));if(n==="replace")return r;for(let s of r)n==="add"?o.add(s):n==="subtract"||o.has(s)?o.delete(s):o.add(s);return o}function df(e,t){let n=Vt(e),r=Vt(t);if(n.size!==r.size)return!1;for(let o of n)if(!r.has(o))return!1;return e.type===t.type}function nb(e={type:"none"}){let t=af(e),n=Vt(t),r=new Set,o=new Map,s=a=>{if(df(a,t))return;for(let p of Array.from(r))p(t);let d=Vt(a),c=n,u=new Set([...d,...c]);for(let p of u)d.has(p)!==c.has(p)&&qe(o,p,c.has(p))},i=a=>{let d=t;t=af(a),df(d,t)||(n=Vt(t)),s(d)};return{getSelection(){return t},has(a){return n.has(a)},getSelectedIds(){return n},setSelection:i,clear(){i({type:"none"})},apply(a,d){i(nc(tb(t,a,d)))},subscribeSelection(a){return r.add(a),Ae(r,a)},subscribeSelectionOf(a,d){return mt(o,a,d),()=>ht(o,a,d)}}}function vi(e){let t=new Set(e.targets);return{enabled:e.enabled,tolerance:e.threshold,snapToGrid:t.has("grid"),snapToNodes:t.has("node"),snapToGuidelines:t.has("guide")}}function cf(e,t){return e.enabled===t.enabled&&e.threshold===t.threshold&&e.targets.length===t.targets.length&&e.targets.every((n,r)=>n===t.targets[r])}function uf(e,t){let n=new Set(t),r={vertical:[],horizontal:[]};for(let[o,s]of e.entries())n.has(o)||(r.vertical.push({value:s.x,nodeId:o,type:"min"},{value:s.x+s.w/2,nodeId:o,type:"mid"},{value:s.x+s.w,nodeId:o,type:"max"}),r.horizontal.push({value:s.y,nodeId:o,type:"min"},{value:s.y+s.h/2,nodeId:o,type:"mid"},{value:s.y+s.h,nodeId:o,type:"max"}));return r}function b2(e,t){let n=t.candidate.value-t.moved,r=Math.abs(n);return r>t.tolerance||e&&r>=e.distance?e:{offset:n,distance:r,line:{id:`${t.axis}:${t.draggingId}:${t.candidate.nodeId}:${t.candidate.value}`,type:t.axis==="x"?"v":"h",value:t.candidate.value,sourceNodeId:t.candidate.nodeId,targetNodeIds:[t.draggingId]}}}function rc(e,t,n,r,o,s){if(!s.snapToNodes||e.length===0)return;let i;for(let a of t){let d=n.get(a);if(!d)continue;let c=o==="x"?[d.x,d.x+d.w/2,d.x+d.w]:[d.y,d.y+d.h/2,d.y+d.h];for(let u of c){let p=u+r;for(let l of e)i=b2(i,{axis:o,candidate:l,draggingId:a,moved:p,tolerance:s.tolerance})}}return i}var I2={enabled:!0,tolerance:6,snapToGrid:!1,snapToNodes:!0,snapToGuidelines:!0,edgeSnapping:!0,centerSnapping:!0,spacingSnapping:!1};function rb(e){let t={...I2,...e??{}},n={activeLines:[],snapOffset:{x:0,y:0}},r={vertical:[],horizontal:[]},o=new Set,s=i=>{n={activeLines:[...i.activeLines],snapOffset:{...i.snapOffset}};for(let a of Array.from(o))a(n)};return{getSnapConfig(){return t},setSnapConfig(i){t={...t,...i}},getSnappingState(){return n},setSnappingState:s,clearSnapping(){s({activeLines:[],snapOffset:{x:0,y:0}})},buildCandidatePool(i,a){let d=new Set(i);r=a?uf(a,i):{vertical:r.vertical.filter(c=>!d.has(c.nodeId)),horizontal:r.horizontal.filter(c=>!d.has(c.nodeId))}},clearCandidatePool(){r={vertical:[],horizontal:[]}},computeSnapResult(i,a,d){if(!t.enabled){let m={adjustedDelta:a,snapOffset:{x:0,y:0},activeLines:[]};return s({activeLines:m.activeLines,snapOffset:m.snapOffset}),m}let c=new Set(i),u=rc(r.vertical.filter(m=>!c.has(m.nodeId)),i,d,a.x,"x",t),p=rc(r.horizontal.filter(m=>!c.has(m.nodeId)),i,d,a.y,"y",t),l={x:(u==null?void 0:u.offset)??0,y:(p==null?void 0:p.offset)??0},f=[...u?[u.line]:[],...p?[p.line]:[]],h={adjustedDelta:{x:a.x+l.x,y:a.y+l.y},snapOffset:l,activeLines:f};return s({activeLines:f,snapOffset:l}),h},subscribeSnapping(i){return o.add(i),Ae(o,i)}}}function ob(e=!1){let t=e,n=new Set,r=o=>{if(t!==o){t=o;for(let s of Array.from(n))s(t)}};return{isViewportPanModeEnabled(){return t},setViewportPanModeEnabled:r,toggleViewportPanModeEnabled(){r(!t)},subscribeViewportPanModeEnabled(o){return n.add(o),Ae(n,o)}}}function sb(){let e=new Set;return{emitGeometryChange(t){if(t.nodeIds.size!==0)for(let n of Array.from(e))n(t)},subscribeGeometryChange(t){return e.add(t),Ae(e,t)}}}function pf(e){let t=nb(e==null?void 0:e.initialSelection),n=WS(),r=$S(),o=QS(),s=ZS(),i=eb(),a=JS(),d=ob(),c=rb(e==null?void 0:e.initialSnapConfig),u=XS(),p=HS(),l=sb();return{...t,...n,...r,...o,...s,...i,...a,...d,...c,...u,...p,...l,setSelection:m=>{t.setSelection(m),Vt(t.getSelection()).size>0&&n.clearEdgeSelection()},apply:(m,g)=>{t.apply(m,g),t.getSelectedIds().size>0&&n.clearEdgeSelection()},setSelectedEdge(m){t.clear(),n.setSelectedEdge(m)},clearEdgeSelection:n.clearEdgeSelection,clear(m){if(m){u.clear(m);return}t.clear(),n.clearEdgeSelection(),r.clearEdgeHover(),o.clear(),s.clearHighlightedNodes()}}}var _2=e=>String(e).replace(/~/g,"~0").replace(/\//g,"~1"),R2=e=>e.replace(/~1/g,"/").replace(/~0/g,"~"),E2=e=>/^\d+$/.test(e)?Number(e):e,ib=e=>e.length===0?"":`/${e.map(_2).join("/")}`,lf=e=>{if(e==="")return[];if(!e.startsWith("/"))throw new Error(`Invalid JSON pointer: ${e}`);return e.slice(1).split("/").map(R2).map(E2)},ab=e=>{if(e.path[0]==="revision"||e.path[0]!=="assets"||e.path[1]===void 0)return null;let t={assetId:String(e.path[1]),op:e.op,path:ib(e.path.slice(2))};return e.op!=="remove"&&(t.value=e.value),t},oc=e=>{let t=[];for(let n of e){let r=ab(n);r&&t.push(r)}return t},db=e=>{let t={op:e.op,path:["assets",e.assetId,...lf(e.path)]};return e.op!=="remove"&&(t.value=e.value),t},Lo=e=>e.map(db),cb=e=>`${e.assetId}\0${e.path}`,ub=e=>lf(e).some(t=>typeof t=="number"),C2=(e,t)=>e===t||e===""||t===""?!0:e.startsWith(`${t}/`)||t.startsWith(`${e}/`);function P2(e,t){if(e.op==="add"&&t.op==="remove")return null;if((e.op==="add"||e.op==="replace")&&t.op==="replace")return{...t,op:e.op};if((e.op==="add"||e.op==="replace")&&t.op==="add")return{...t,op:e.op};if(e.op==="replace"&&t.op==="remove")return t;if(e.op==="remove"&&t.op==="add")return{...t,op:"replace"};if(e.op==="remove"&&t.op==="remove")return t}function x2(e){let t=new Map;for(let n=0;n<e.length;n+=1){let r=e[n];ub(r.path)||t.set(cb(r),n)}return t}var Mr=e=>{let t=[],n=new Map;for(let r of e){let o=!ub(r.path),s=cb(r),i=o?n.get(s):void 0,a=i===void 0?void 0:t[i],d=a?P2(a,r):void 0;if(i!==void 0&&a&&d!==void 0){t.splice(i,1),d!==null&&t.push(d),n=x2(t);continue}for(let[c,u]of Array.from(n.entries())){let p=t[u];p.assetId===r.assetId&&C2(p.path,r.path)&&n.delete(c)}t.push(r),o&&n.set(s,t.length-1)}return t};function pb(e,t){return!Number.isFinite(e)||e===void 0?t:Math.max(1,Math.floor(e))}function Si(e){let t=pb(e==null?void 0:e.maxBatchSize,10),n=pb(e==null?void 0:e.maxBatchPatchCount,50),r=[],o=[],s=(a,d)=>{for(let c of a.patches)c.op==="add"&&c.path===""&&d.add(c.assetId)};return{enqueue(a){let d={txId:a.id,patches:Mr(a.forwardPatches),intent:a.intent,mergeKey:a.mergeKey,attempt:0,enqueuedAt:Date.now(),status:"pending"};return r.push(d),d},takeNextBatch(){if(r.length===0||r[0].status==="in-flight")return null;let a=[r[0]],d=new Set;s(r[0],d);let c=a[0].patches.length;for(let p=1;p<r.length;p+=1){let l=r[p],f=l.patches.length,h=l.patches.some(m=>d.has(m.assetId));if(l.status!=="pending"||a.length>=t||c+f>n||h)break;a.push(l),s(l,d),c+=f}for(let p of a)p.status="in-flight",p.attempt+=1;return o=a.map(p=>p.txId),{...a[0],txIds:[...o],patches:a.flatMap(p=>p.patches),attempt:Math.max(...a.map(p=>p.attempt)),status:"in-flight",envelopes:a.map(p=>({...p,patches:[...p.patches]}))}},ack(a){let d=Array.isArray(a)?a:[a],c=new Set(d),u=r.filter(p=>c.has(p.txId)).map(p=>p.txId);return r=r.filter(p=>!c.has(p.txId)),o=o.filter(p=>!c.has(p)),Promise.resolve(u)},markRebasing(a){let d=Array.isArray(a)?a:[a],c=new Set(d);for(let u of r)c.has(u.txId)&&(u.status="rebasing");o=o.filter(u=>!c.has(u))},replaceAll(a){let d=new Set(o);return r=a.map(c=>({...c,patches:[...c.patches],status:d.has(c.txId)?"in-flight":c.status==="in-flight"?"pending":c.status})),o=r.filter(c=>c.status==="in-flight").map(c=>c.txId),Promise.resolve()},size:()=>r.length,snapshot:()=>r.map(a=>({...a,patches:[...a.patches]})),releaseInflight(){let a=new Set(o);for(let d of r)a.has(d.txId)&&(d.status="pending");o=[]}}}var sc=class{constructor(t){this.onFailure=t;this.pending=new Set;this.failure=null;this.tail=Promise.resolve()}track(t){this.run(t).catch(()=>{})}run(t){let n=this.tail.then(async()=>{this.throwIfFailed();try{await t()}catch(r){throw this.recordFailure(r)}}).finally(()=>{this.pending.delete(n)});return this.pending.add(n),this.tail=n.catch(()=>{}),n}async waitForCaptured(){for(;;){this.throwIfFailed();let t=[...this.pending];if(t.length===0)return;await Promise.all(t)}}hasFailed(){return this.failure!==null}recordFailure(t){let n=t instanceof Error?t:new Error(String(t));return this.failure||(this.failure=n,this.onFailure(n)),this.failure}throwIfFailed(){if(this.failure)throw this.failure}};var ic=class{constructor(t){this.options=t;this.ready=!1;this.retryAttempt=0;this.retryTimer=null}isReady(){return this.ready}reset(){this.dispose(),this.ready=!1,this.retryAttempt=0}markReady(){this.ready=!0,this.retryAttempt=0,this.dispose()}schedule(){if(this.options.isClosed()||this.ready||this.retryTimer||!this.options.hasAttachedStore())return;let t=Math.min(this.options.retryMaxMs,this.options.retryBaseMs*2**this.retryAttempt);this.retryAttempt+=1,this.retryTimer=setTimeout(()=>{this.retryTimer=null,this.options.sync().then(n=>{n||this.schedule()},()=>{this.schedule()})},t)}dispose(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}};zt();var lb=e=>`${e.assetId}\0${e.path}`;function T2(e,t){let n=new Set(e.filter(r=>r.op==="add"&&r.path==="").map(lb));return n.size===0?t:t.map(r=>r.op==="replace"&&r.path===""&&n.has(lb(r))?{...r,op:"add"}:r)}function N2(e,t,n){var o;if(!e.observeRebasedEnvelope)return;let r={state:t,envelope:n};try{e.observeRebasedEnvelope(r)}catch(s){try{(o=e.onObserverError)==null||o.call(e,s,r)}catch{}}}function ac(e){let t=e.baseState,n=[],r=[];for(let o of e.envelopes)try{let[s,i]=qt(t,c=>yn(c,Lo(o.patches))),a=T2(o.patches,Mr(oc(i)));if(a.length===0){t=s;continue}let d={...o,patches:a,status:"pending"};N2(e,t,d),t=s,n.push(d)}catch(s){r.push({txId:o.txId,intent:o.intent,reason:s instanceof Error?s.message:String(s),cause:s instanceof Error?s:void 0})}return{rebased:n,conflicts:r,resultState:t}}zt();var w2=500;function Sn(e){return e instanceof Error?e:new Error(String(e))}async function ff(e,t){if(e.runPersistenceMutation){await e.runPersistenceMutation(t);return}await t()}function Ht(e,t,n){var r;return!e.closed&&e.attachedStore===t&&(n===void 0||((r=e.getAttachmentEpoch)==null?void 0:r.call(e))===n)}async function O2(e,t,n){await ff(e,async()=>{if(e.persistence.replaceOutboundPartition){await e.persistence.replaceOutboundPartition(t,n);return}let r=new Set(n),o=new Set(t.map(a=>a.txId)),i=(await e.persistence.loadOutbound()).filter(a=>!r.has(a.txId)&&!o.has(a.txId));await e.persistence.replaceOutbound([...t,...i])})}var dc=new WeakMap;function D2(e,t){return e===void 0?t:t===void 0?e:Math.max(e,t)}function k2(e,t,n){let r=new Set(n.rebased.map(a=>a.txId)),o=new Set(n.conflicts.map(a=>a.txId)),s=[],i=[];for(let a of t)r.has(a.txId)||(o.has(a.txId)?i.push(a.txId):s.push(a.txId));s.length>0&&e.emit({kind:"discarded",txId:s[0],txIds:s,reason:"rebase-noop"}),i.length>0&&e.emit({kind:"discarded",txId:i[0],txIds:i,reason:"rebase-conflict"})}function fb(e){let t=dc.get(e);if(t)return t;let n={pending:new Map,timer:null,applyQueue:Promise.resolve(),disposed:!1};return dc.set(e,n),n}function mf(e,t){for(let n of t){let r=e.pending.get(n.assetId);e.pending.set(n.assetId,{assetId:n.assetId,minimumAssetVersion:D2(r==null?void 0:r.minimumAssetVersion,n.minimumAssetVersion)})}}function mb(e){return e.assetVersion}function hb(e,t){let n=e,r=[];for(let o of t)try{n=yn(n,Lo(o.patches))}catch(s){r.push({txId:o.txId,intent:o.intent,reason:s instanceof Error?s.message:String(s),cause:s instanceof Error?s:void 0})}return{conflicts:r,resultState:n}}function gb(e,t,n){return n.filter(r=>{var a;let o=(a=t.assets.find(d=>d.assetId===r.assetId))==null?void 0:a.minimumAssetVersion,s=mb(r),i=e.assetVersions.getVersion(r.assetId)??0;return s===void 0||o!==void 0&&s<o?(e.logger.warn(`${e.logPrefix} skip scoped asset: fetched version is below event version`,{assetId:r.assetId,remoteAssetVersion:s,minimumAssetVersion:o,localAssetVersion:i}),!1):s<=i?(e.logger.info(`${e.logPrefix} skip scoped asset: remote asset version is not newer`,{assetId:r.assetId,remoteAssetVersion:s,localAssetVersion:i}),!1):!0})}function M2(e,t,n){return{assets:n,requests:n.map(r=>e.stateAdapter.createRemoteAssetRequest(t,r.assetId))}}function L2(e,t,n,r){let o=e.attachedStore;if(!o||e.closed||t.disposed)return null;let s=gb(e,n,r);if(s.length===0)return e.setState(e.transport.getConnectionState()==="open"?{phase:"idle"}:{phase:"offline"}),e.scheduleFlush(),null;let i=e.stateAdapter.mergeRemoteAssets(o.getState(),s);e.setState({phase:"rebasing"});let a=hb(i,e.outbound.snapshot());a.conflicts.length>0&&e.logger.warn(`${e.logPrefix} scoped asset overlay conflicts`,{assetIds:s.map(c=>c.assetId),conflicts:a.conflicts});let d=()=>{o.applyRemoteSnapshot(a.resultState,{conflicts:a.conflicts})};e.withApplyingRemoteAssets?e.withApplyingRemoteAssets(s.map(c=>c.assetId),d):d();for(let c of s)e.assetVersions.remember(c.assetId,mb(c));return{acceptedAssets:s,remoteState:i,conflicts:a.conflicts}}async function B2(e,t,n,r){var s,i;await((s=e.waitForCapturedPersistenceWrites)==null?void 0:s.call(e));let o=L2(e,t,n,r);if(!(!o||!e.attachedStore||e.closed||t.disposed)&&(e.readOnly||(await ff(e,()=>e.persistence.saveSnapshot({state:o.remoteState})),await((i=e.waitForCapturedPersistenceWrites)==null?void 0:i.call(e))),!(!e.attachedStore||e.closed||t.disposed))){if(e.emit({kind:"snapshot-applied"}),e.conflictPolicy==="conflict-event")for(let a of o.conflicts)e.emit({kind:"conflict",conflict:a});e.setState(e.transport.getConnectionState()==="open"?{phase:"idle"}:{phase:"offline"}),e.scheduleFlush()}}function G2(e,t,n,r){t.applyQueue=t.applyQueue.catch(()=>{}).then(()=>B2(e,t,n,r)).catch(o=>{var s;(s=e.hasPersistenceWriteFailure)!=null&&s.call(e)||e.closed||t.disposed||(e.logger.error(`${e.logPrefix} failed to apply scoped asset`,o),e.setState({phase:"error",error:Sn(o),reason:"remote-sync-failed"}))})}async function U2(e,t){var s,i,a;let n=e.attachedStore;if(!n||e.closed||t.disposed||(s=e.hasPersistenceWriteFailure)!=null&&s.call(e)||!e.transport.fetchAssets)return;let r=Array.from(t.pending.values());if(t.pending.clear(),r.length===0)return;let o=M2(e,n.getState(),r);e.setState({phase:"syncing",reason:"invalidate"});try{let d=await e.transport.fetchAssets(o.requests);if(t.disposed||e.closed||(i=e.hasPersistenceWriteFailure)!=null&&i.call(e))return;let c=gb(e,o,d.assets);if(c.length===0){e.setState(e.transport.getConnectionState()==="open"?{phase:"idle"}:{phase:"offline"}),e.scheduleFlush();return}G2(e,t,o,c)}catch(d){if((a=e.hasPersistenceWriteFailure)!=null&&a.call(e)||e.closed||t.disposed)return;!t.disposed&&!e.closed&&mf(t,r),e.logger.error(`${e.logPrefix} failed to sync scoped assets`,d),e.setState({phase:"error",error:Sn(d),reason:"remote-sync-failed"})}}function yb(e,t){t.timer||t.disposed||(t.timer=setTimeout(()=>{t.timer=null,U2(e,t)},w2))}function Ab(e){let t=dc.get(e);t&&(t.timer&&clearTimeout(t.timer),t.disposed=!0,t.pending.clear(),dc.delete(e))}async function bi(e){var f,h,m,g,y,v,S;let t=e.attachedStore;if(!t||e.closed)return;let n=(f=e.getAttachmentEpoch)==null?void 0:f.call(e);if(await((h=e.waitForCapturedPersistenceWrites)==null?void 0:h.call(e)),!Ht(e,t,n))return;e.setState({phase:"syncing",reason:"bootstrap"});let r=await e.transport.fetchSnapshot();if(!Ht(e,t,n)||(await((m=e.waitForCapturedPersistenceWrites)==null?void 0:m.call(e)),!Ht(e,t,n)))return;e.setState({phase:"rebasing"});let o=e.outbound.snapshot(),s=ac({baseState:r.state,envelopes:o,observeRebasedEnvelope:e.observeOutboundEnvelope?({state:b,envelope:I})=>{var N;return(N=e.observeOutboundEnvelope)==null?void 0:N.call(e,b,I,"rebase")}:void 0,onObserverError:(b,{envelope:I})=>{e.logger.warn(`${e.logPrefix} outbound observer failed`,{error:b instanceof Error?b.message:String(b),phase:"rebase",txId:I.txId})}});s.conflicts.length>0&&e.logger.warn(`${e.logPrefix} rebase conflicts`,{conflicts:s.conflicts});let i=o.map(b=>b.txId),a=new Set(i);if(await((g=e.waitForCapturedPersistenceWrites)==null?void 0:g.call(e)),!Ht(e,t,n))return;let d=e.outbound.snapshot().filter(b=>!a.has(b.txId)),c=hb(s.resultState,d),u=[...s.conflicts,...c.conflicts];if(t.applyRemoteSnapshot(c.resultState,{conflicts:u}),!Ht(e,t,n))return;let p=e.readOnly?void 0:O2(e,s.rebased,i),l=e.outbound.snapshot().filter(b=>!a.has(b.txId));if(await e.outbound.replaceAll(e.readOnly?[]:[...s.rebased,...l]),!!Ht(e,t,n)){if(e.emitOutboundChange(),!e.readOnly){if(await p,!Ht(e,t,n)||(await((y=e.waitForCapturedPersistenceWrites)==null?void 0:y.call(e)),!Ht(e,t,n))||(await ff(e,()=>e.persistence.saveSnapshot({state:r.state})),!Ht(e,t,n)))return;await((v=e.waitForCapturedPersistenceWrites)==null?void 0:v.call(e))}if(Ht(e,t,n)){if((S=e.markRemoteBaselineReady)==null||S.call(e),k2(e,o,s),e.emit({kind:"snapshot-applied"}),e.conflictPolicy==="conflict-event")for(let b of u)e.emit({kind:"conflict",conflict:b});e.setState(e.transport.getConnectionState()==="open"?{phase:"idle"}:{phase:"offline"}),e.scheduleFlush()}}}function vb(e,t){if(!e.attachedStore||e.closed||!t.scopedAssetId||!e.transport.fetchAssets)return Promise.resolve(!1);let r=fb(e);return mf(r,[{assetId:t.scopedAssetId,minimumAssetVersion:t.assetVersion}]),yb(e,r),Promise.resolve(!0)}function Sb(e,t){if(!e.attachedStore||e.closed||!e.transport.fetchAssets)return Promise.resolve(!1);let n=fb(e);return mf(n,[{assetId:t}]),yb(e,n),Promise.resolve(!0)}function Et(e,t,n){return!e.closed&&e.attachedStore===t&&e.getAttachmentEpoch()===n}function z2(e,t){return e.closed&&t!==null&&typeof t=="object"&&"name"in t&&t.name==="AbortError"}function bb(e,t){if(e.hasPersistenceWriteFailure())return;let n=e.attachedStore,r=e.getAttachmentEpoch();(async()=>{try{if(!t.scopedAssetId){e.logger.info(`${e.logPrefix} skip invalidate: only scoped asset refresh is supported`);return}await vb(e,t)}catch(o){if(e.hasPersistenceWriteFailure()||e.attachedStore!==n||e.getAttachmentEpoch()!==r)return;e.logger.error(`${e.logPrefix} failed to handle invalidate`,o),e.setState({phase:"error",error:Sn(o),reason:"remote-sync-failed"})}})()}function Ib(e,t){if(!e.hasPersistenceWriteFailure()){if(t==="closed"){e.setState({phase:"offline"});return}e.setState({phase:"idle"}),e.scheduleFlush()}}async function q2(e,t,n){if(e.isOutboundHydrated())return Et(e,t,n);if(e.readOnly)await e.outbound.replaceAll([]);else{if(await e.waitForCapturedPersistenceWrites(),!Et(e,t,n))return!1;let r=await e.persistence.loadOutbound();if(!Et(e,t,n))return!1;let o=new Set(r.map(i=>i.txId)),s=e.outbound.snapshot().filter(i=>!o.has(i.txId));await e.outbound.replaceAll([...r,...s])}return Et(e,t,n)?(e.markOutboundHydrated(),e.emitOutboundChange(),!0):!1}async function hf(e,t,n){if(!e.isClientIdentityHydrated()){let r=await e.persistence.loadClientId();if(!Et(e,t,n)||!r&&(await e.runPersistenceMutation(()=>e.persistence.saveClientId(e.transport.clientId)),!Et(e,t,n)))return!1;e.markClientIdentityHydrated()}if(!e.isLocalSnapshotHydrated()){let r=await e.persistence.loadSnapshot();if(!Et(e,t,n)||r&&(t.applyRemoteSnapshot(r.state),!Et(e,t,n)))return!1;e.markLocalSnapshotHydrated()}return q2(e,t,n)}async function _b(e,t,n){var o;let r=e.getAttachmentEpoch();try{if(!await hf(e,t,r)||!Et(e,t,r))return;await bi(e)}catch(s){Et(e,t,r)&&!z2(e,s)&&!e.hasPersistenceWriteFailure()&&(e.logger.error(`${e.logPrefix} bootstrap failed`,s),e.setState({phase:"error",error:Sn(s),reason:"bootstrap-failed"}),e.scheduleRemoteBaselineRetry())}finally{e.getAttachmentEpoch()===r&&e.markBootstrapSettled(),Et(e,t,r)&&((o=n.onBootstrapSettled)==null||o.call(n))}}var cc=class{constructor(t){this.options=t;this.listeners=new Set;this.ackSinceSnapshot=0;this.storeUnsubscribe=null;this.invalidateUnsubscribe=null;this.connectionUnsubscribe=null;this.flushTimer=null;this.resyncTimer=null;this.applyingRemoteAssetIds=new Set;this.attachmentEpoch=0;this.bootstrapSettled=!1;this.clientIdentityHydrated=!1;this.localSnapshotHydrated=!1;this.outboundHydrated=!1;this.attachedStore=null;this.closed=!1;this.attach=t=>{this.detachListeners(),this.attachmentEpoch+=1,this.attachedStore=t,this.bootstrapSettled=!1,this.clientIdentityHydrated=!1,this.localSnapshotHydrated=!1,this.outboundHydrated=!1,this.remoteBaselineGate.reset();let{attachmentEpoch:n}=this;return this.storeUnsubscribe=t.subscribe(({prevState:r,nextState:o,transaction:s})=>{if(this.syncTransportAssetSubscriptions(o),this.syncDiscoveredRemoteAssets(r,o,s.source),this.readOnly||s.source!=="local"||s.forwardPatches.length===0)return;let i=this.outbound.enqueue(s);this.emitOutboundChange(),this.observeOutboundEnvelope(r,i,"local"),this.persistenceWriteBarrier.track(()=>this.persistence.appendOutbound(i)),this.scheduleFlush()}),this.syncTransportAssetSubscriptions(t.getState()),this.invalidateUnsubscribe=this.transport.onInvalidate(r=>bb(this,r)),this.connectionUnsubscribe=this.transport.onConnectionChange(r=>Ib(this,r)),this.bootstrap(t),()=>{this.attachedStore!==t||this.attachmentEpoch!==n||(this.detachListeners(),this.attachmentEpoch+=1,this.attachedStore=null,this.clientIdentityHydrated=!1,this.localSnapshotHydrated=!1,this.outboundHydrated=!1,this.remoteBaselineGate.reset())}};this.getState=()=>this.state;this.subscribe=t=>(this.listeners.add(t),()=>{this.listeners.delete(t)});this.getPendingOutboundCount=()=>this.outbound.size();this.getPendingTransactionIds=()=>this.outbound.snapshot().map(t=>t.txId);this.isBootstrapSettled=()=>this.bootstrapSettled;this.getAttachmentEpoch=()=>this.attachmentEpoch;this.isClientIdentityHydrated=()=>this.clientIdentityHydrated;this.isLocalSnapshotHydrated=()=>this.localSnapshotHydrated;this.isOutboundHydrated=()=>this.outboundHydrated;this.markBootstrapSettled=()=>{this.bootstrapSettled=!0};this.markClientIdentityHydrated=()=>{this.clientIdentityHydrated=!0};this.markLocalSnapshotHydrated=()=>{this.localSnapshotHydrated=!0};this.markOutboundHydrated=()=>{this.outboundHydrated=!0};this.markRemoteBaselineReady=()=>{this.persistenceWriteBarrier.hasFailed()||this.remoteBaselineGate.markReady()};this.scheduleRemoteBaselineRetry=()=>{this.persistenceWriteBarrier.hasFailed()||this.remoteBaselineGate.schedule()};this.hasPersistenceWriteFailure=()=>this.persistenceWriteBarrier.hasFailed();this.waitForCapturedPersistenceWrites=()=>this.persistenceWriteBarrier.waitForCaptured();this.runPersistenceMutation=t=>this.persistenceWriteBarrier.run(t);this.flush=()=>{this.readOnly||this.scheduleFlush(0)};this.close=()=>{this.closed=!0,this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.resyncTimer&&(clearTimeout(this.resyncTimer),this.resyncTimer=null),this.detachListeners(),this.transport.close(),this.setState({phase:"offline"})};var n,r,o,s,i,a,d;this.transport=t.transport,this.persistence=t.persistence,this.stateAdapter=t.stateAdapter,this.assetVersions=t.transport.assetVersions??new fn,this.readOnly=!!t.readOnly,this.outbound=Si({maxBatchSize:(n=t.flush)==null?void 0:n.maxBatchSize,maxBatchPatchCount:(r=t.flush)==null?void 0:r.maxBatchPatchCount}),this.conflictPolicy=t.conflictPolicy??"remote-wins",this.logger=mo(t.logger),this.logPrefix=t.logPrefix??"[pippit-asset-sdk:sync]",this.debounceMs=((o=t.flush)==null?void 0:o.debounceMs)??0,this.retryBaseMs=((s=t.flush)==null?void 0:s.retryBaseMs)??500,this.retryMaxMs=((i=t.flush)==null?void 0:i.retryMaxMs)??3e4,this.maxAttempts=((a=t.flush)==null?void 0:a.maxAttempts)??1/0,this.saveEveryNAcks=((d=t.snapshot)==null?void 0:d.saveEveryNAcks)??50,this.remoteBaselineGate=new ic({hasAttachedStore:()=>!!this.attachedStore,isClosed:()=>this.closed,retryBaseMs:this.retryBaseMs,retryMaxMs:this.retryMaxMs,sync:()=>this.syncRemoteBaseline()}),this.persistenceWriteBarrier=new sc(c=>this.handlePersistenceWriteFailure(c)),this.state=t.transport.getConnectionState()==="open"?{phase:"idle"}:{phase:"offline"}}emit(t){for(let n of Array.from(this.listeners))n(t)}emitOutboundChange(){this.emit({kind:"outbound-change",pendingOutboundCount:this.outbound.size()})}observeOutboundEnvelope(t,n,r){var o,s;try{(s=(o=this.options).observeOutboundEnvelope)==null||s.call(o,{state:t,envelope:n,phase:r})}catch(i){this.logger.warn(`${this.logPrefix} outbound observer failed`,{error:i instanceof Error?i.message:String(i),phase:r,txId:n.txId})}}withApplyingRemoteAssets(t,n){for(let r of t)this.applyingRemoteAssetIds.add(r);try{n()}finally{for(let r of t)this.applyingRemoteAssetIds.delete(r)}}setState(t){this.persistenceWriteBarrier.hasFailed()&&!(t.phase==="error"&&t.reason==="persistence-failed")&&!(this.closed&&t.phase==="offline")||(this.state=t,this.emit({kind:"state-change",state:t}))}scheduleFlush(t=this.debounceMs){this.closed||this.readOnly||this.persistenceWriteBarrier.hasFailed()||(this.flushTimer&&clearTimeout(this.flushTimer),this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flushNow().catch(n=>{if(this.persistenceWriteBarrier.hasFailed())return;let r=Sn(n);this.logger.error(`${this.logPrefix} flush failed`,r),this.setState({phase:"error",error:r,reason:"commit-failed"})})},t))}releaseInflight(){var t,n;(n=(t=this.outbound).releaseInflight)==null||n.call(t)}handlePersistenceWriteFailure(t){this.remoteBaselineGate.reset(),this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null),this.resyncTimer&&(clearTimeout(this.resyncTimer),this.resyncTimer=null),!this.closed&&(this.logger.error(`${this.logPrefix} persistence write failed`,t),this.setState({phase:"error",error:t,reason:"persistence-failed"}))}syncTransportAssetSubscriptions(t){!t||!this.transport.syncAssetSubscriptions||this.transport.syncAssetSubscriptions(this.stateAdapter.collectAssetIds(t))}syncDiscoveredRemoteAssets(t,n,r){if(r!=="remote"||!this.bootstrapSettled||!this.transport.fetchAssets)return;let o=new Set(this.stateAdapter.collectAssetIds(t)),s=this.stateAdapter.collectAssetIds(n).filter(i=>!o.has(i)&&!this.applyingRemoteAssetIds.has(i));for(let i of s)Sb(this,i)}async flushNow(){if(!this.attachedStore||this.closed||this.readOnly||this.persistenceWriteBarrier.hasFailed())return;if(this.transport.getConnectionState()!=="open"){this.setState({phase:"offline"});return}if(!this.remoteBaselineGate.isReady()){this.bootstrapSettled&&this.scheduleRemoteBaselineRetry();return}try{await this.waitForCapturedPersistenceWrites()}catch{return}if(!this.attachedStore||this.closed||this.transport.getConnectionState()!=="open"||!this.remoteBaselineGate.isReady()||this.state.phase==="flushing"||this.state.phase==="syncing"||this.state.phase==="rebasing")return;let t=this.outbound.takeNextBatch();if(!t){this.setState({phase:"idle"});return}if(this.observeOutboundBatch(t,"commit"),t.patches.length===0){let o;try{o=await this.removeAckedOutbound(t.txIds)}catch{return}this.emit({kind:"committed",txId:t.txId,ackedTxIds:o}),this.setState({phase:"idle"}),this.scheduleFlush();return}this.setState({phase:"flushing",inflight:t.txId,inflightTxIds:t.txIds});let n=await this.transport.commit(t);if(this.closed||this.persistenceWriteBarrier.hasFailed())return;if(n.status==="ack"){try{await this.handleAck(t,n.ackedTxIds)}catch{return}return}if(n.status==="reject"){try{await this.handleCommitReject(t,n.ackedTxIds,n.error)}catch{return}return}if(n.retryable===!1){try{await this.removeAckedOutbound(t.txIds)}catch{return}this.logger.error(`${this.logPrefix} non-retryable commit failed`,n.error,{txIds:t.txIds,attempt:t.attempt}),this.setState({phase:"error",error:n.error,reason:"commit-failed"});return}if(this.releaseInflight(),t.attempt>=this.maxAttempts){this.logger.error(`${this.logPrefix} commit retry attempts exhausted`,n.error,{txIds:t.txIds,attempt:t.attempt,maxAttempts:this.maxAttempts}),this.setState({phase:"error",error:n.error,reason:"commit-failed"});return}let r=Math.min(this.retryMaxMs,this.retryBaseMs*2**Math.max(0,t.attempt-1));if(n.requiresResync){this.logger.warn(`${this.logPrefix} commit blocked on missing base versions, scheduling resync`,{txIds:t.txIds,attempt:t.attempt,delay:r}),this.setState({phase:"idle"}),this.scheduleResync(r);return}this.setState({phase:"idle"}),this.scheduleFlush(r)}scheduleResync(t){this.closed||this.readOnly||this.persistenceWriteBarrier.hasFailed()||this.resyncTimer||(this.resyncTimer=setTimeout(()=>{this.resyncTimer=null,this.resyncNow()},t))}async resyncNow(){let{attachedStore:t,attachmentEpoch:n}=this;if(!(!t||this.closed||this.readOnly||this.persistenceWriteBarrier.hasFailed())){if(this.state.phase==="flushing"||this.state.phase==="syncing"||this.state.phase==="rebasing"){this.scheduleResync(this.retryBaseMs);return}try{await bi(this)}catch(r){if(this.persistenceWriteBarrier.hasFailed()||this.attachedStore!==t||this.attachmentEpoch!==n)return;this.logger.error(`${this.logPrefix} resync after blocked commit failed`,r),this.setState({phase:"error",error:Sn(r),reason:"remote-sync-failed"}),this.scheduleResync(this.retryMaxMs)}}}async syncRemoteBaseline(){let{attachedStore:t,attachmentEpoch:n}=this;if(!t||this.closed)return!1;if(this.persistenceWriteBarrier.hasFailed())return!0;if(this.state.phase==="flushing"||this.state.phase==="syncing"||this.state.phase==="rebasing")return!1;try{return!await hf(this,t,n)||this.attachedStore!==t||this.attachmentEpoch!==n||(await bi(this),this.attachedStore!==t||this.attachmentEpoch!==n)?!0:this.remoteBaselineGate.isReady()}catch(r){return this.closed?!1:this.persistenceWriteBarrier.hasFailed()||this.attachedStore!==t||this.attachmentEpoch!==n?!0:(this.logger.error(`${this.logPrefix} remote baseline retry failed`,r),this.setState({phase:"error",error:Sn(r),reason:"remote-sync-failed"}),!1)}}async handleCommitReject(t,n,r){let o=n!=null&&n.length?await this.removeAckedOutbound(n):[];o.length>0&&(this.ackSinceSnapshot+=o.length,this.emit({kind:"committed",txId:o[0],ackedTxIds:o}));let s=new Set(o),i=t.txIds.filter(d=>!s.has(d));i.length>0&&await this.removeAckedOutbound(i);let a=r??new Error(`Asset sync commit rejected for transaction ${t.txId}`);this.logger.error(`${this.logPrefix} commit rejected`,a,{txIds:t.txIds,ackedTxIds:o,rejectedTxIds:i}),this.setState({phase:"error",error:a,reason:"commit-rejected"})}async handleAck(t,n){let r=await this.removeAckedOutbound(n!=null&&n.length?n:t.txIds);if(this.ackSinceSnapshot+=Math.max(1,r.length),this.emit({kind:"committed",txId:t.txId,ackedTxIds:r}),this.ackSinceSnapshot>=this.saveEveryNAcks&&this.attachedStore){this.ackSinceSnapshot=0;let o=this.attachedStore.getState();await this.runPersistenceMutation(()=>this.persistence.saveSnapshot({state:o}))}this.setState({phase:"idle"}),this.scheduleFlush()}async removeAckedOutbound(t){let n=new Set(Array.isArray(t)?t:[t]),r=this.outbound.snapshot().filter(s=>n.has(s.txId)).map(s=>s.txId);for(let s of r)await this.runPersistenceMutation(()=>this.persistence.removeOutbound(s));let o=await this.outbound.ack(r);return this.emitOutboundChange(),o}observeOutboundBatch(t,n){var o;let r=(o=this.attachedStore)==null?void 0:o.getState();if(!(!r||!this.options.observeOutboundEnvelope))for(let s of t.envelopes)this.observeOutboundEnvelope(r,s,n)}async bootstrap(t){await _b(this,t,this.options)}detachListeners(){var t,n,r;Ab(this),this.remoteBaselineGate.dispose(),(t=this.storeUnsubscribe)==null||t.call(this),(n=this.invalidateUnsubscribe)==null||n.call(this),(r=this.connectionUnsubscribe)==null||r.call(this),this.storeUnsubscribe=null,this.invalidateUnsubscribe=null,this.connectionUnsubscribe=null}};function Ii(e){return new cc(e)}zt();function gf(e,t){if(typeof t!="string")return;let n=t.trim();n&&e.add(n)}function Rb(e){let t=new Set;gf(t,e.rootCanvasId);for(let[n,r]of Object.entries(e.assets))gf(t,n),gf(t,r==null?void 0:r.pippitAssetId);return[...t]}function K2(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function X2(e){let t=K2(e.data)?e.data:void 0,n=(t==null?void 0:t.pippitAssetId)??e.pippitAssetId;return typeof n=="string"&&n.trim()?n:typeof e.id=="string"&&e.id.trim()?e.id:void 0}function $2(e,t){for(let n of Object.values(e.assets))if(Ut(n)){for(let r of Object.values(n.content.nodes))if(X2(r)===t)return r.type}}function Eb(e,t){let n=e.assets[t],r=$2(e,t);return{assetId:t,assetKind:n&&Ut(n)?"canvas":"node",...r?{nodeType:r}:{}}}function Cb(e,t){let n={...e.assets};for(let r of t)r.asset&&(n[r.assetId]=r.asset);return{...e,assets:n}}var W2={collectAssetIds:Rb,createRemoteAssetRequest:Eb,mergeRemoteAssets:Cb};function Q2(e,t){return{...e,assetVersions:e.assetVersions,fetchSnapshot:async()=>({state:(await e.fetchSnapshot({onProgress:r=>{try{t(r.kind==="root-ready"?{kind:"bootstrap-root-ready",document:r.document}:{kind:"bootstrap-assets-ready",document:r.document,readyAssetIds:r.readyAssetIds})}catch(o){Re.warn("[canvas-sdk:sync] bootstrap progress observer failed",{error:o instanceof Error?o.message:String(o),kind:r.kind})}}})).document})}}function J2(e){return{...e,replaceOutboundPartition:e.replaceOutboundPartition,loadSnapshot:async()=>{let t=await e.loadSnapshot();return t?{state:t.document}:null},saveSnapshot:({state:t})=>e.saveSnapshot({document:t})}}function yf(e){let t=new Set,n=s=>{for(let i of Array.from(t))i(s)},r=Ii({...e,transport:Q2(e.transport,n),persistence:J2(e.persistence),stateAdapter:W2,observeOutboundEnvelope:e.observeOutboundEnvelope?({state:s,envelope:i,phase:a})=>{var d;return(d=e.observeOutboundEnvelope)==null?void 0:d.call(e,{document:s,envelope:i,phase:a})}:void 0,logger:Re,logPrefix:"[canvas-sdk:sync]"}),o=r.subscribe(s=>n(s));return{attach:s=>r.attach(s),getState:r.getState,subscribe:s=>(t.add(s),()=>t.delete(s)),getPendingOutboundCount:()=>{var s;return((s=r.getPendingOutboundCount)==null?void 0:s.call(r))??0},flush:r.flush,close:()=>{r.close(),o(),t.clear()}}}var Pb=new WeakMap;function Z2(e){return{txId:e.id,patches:Mr(e.forwardPatches),intent:e.intent,mergeKey:e.mergeKey,attempt:0,enqueuedAt:Date.now(),status:"pending"}}function xb(e,t,n){e.pendingEnvelopes.get(t)===n&&e.pendingEnvelopes.delete(t),e.pendingEnvelopes.size===0&&(e.captureFailure=void 0,e.failedPersistence=void 0)}function Tb(e,t,n,r){e.captureFailure=r,e.failedPersistence=t,Re.error("[canvas-sdk:sync] failed to persist a transaction between sync engines",r,{txId:n})}function ej(e,t){let n,r=e.captureTail.then(async()=>{n=e.persistence,await n.appendOutbound(t),xb(e,t.txId,t)});e.captureTail=r.then(()=>{},o=>Tb(e,n,t.txId,o))}function tj(e){if(e.pendingEnvelopes.size===0||e.failedPersistence===e.persistence)return;let t,n,r=e.captureTail.then(async()=>{t=e.persistence;for(let[o,s]of Array.from(e.pendingEnvelopes.entries()))n=o,await t.appendOutbound(s),xb(e,o,s)});e.captureTail=r.then(()=>{},o=>Tb(e,t,n??"unknown",o))}function nj(e,t){if(!e.captureEnabled||e.liveEngineTokens.size>0||t.source!=="local"||t.forwardPatches.length===0)return;let n=Z2(t);e.pendingEnvelopes.set(n.txId,n),ej(e,n)}function rj(e,t,n){let r={captureEnabled:n,captureTail:Promise.resolve(),liveEngineTokens:new Set,pendingEnvelopes:new Map,persistence:t};return e.subscribe(({transaction:o})=>nj(r,o)),r}function Nb(e,t,n){let r=Pb.get(e)??rj(e,t,n);Pb.set(e,r),r.persistence=t,r.captureEnabled=n;let o={};return{activateEngine:()=>r.liveEngineTokens.add(o),deactivateEngine:()=>r.liveEngineTokens.delete(o),waitForCaptures:async()=>{for(;;){let s=r.captureTail;if(await s,s===r.captureTail&&(tj(r),s===r.captureTail))break}if(r.pendingEnvelopes.size>0)throw r.captureFailure??new Error("Canvas outbound journal is not durable")}}}var uc=new WeakMap;function wb(){return`client_${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}`}async function oj(e,t,n){var c,u;let r=await e.persistence.loadClientId(),o=r??((c=e.createClientId)==null?void 0:c.call(e))??wb();if(r||await e.persistence.saveClientId(o),n.isDisposed()||(await t.waitForCaptures(),n.isDisposed()))return;let s=e.transportFactory({canvasId:e.canvasId,clientId:o});try{await t.waitForCaptures()}catch(p){throw s.close(),p}if(n.isDisposed()){s.close();return}let i=yf({...e.sync??{},transport:s,persistence:e.persistence}),a=e.onSyncEvent?i.subscribe(e.onSyncEvent):void 0,d;try{d=i.attach(e.store)}catch(p){throw a==null||a(),i.close(),p}if(n.isDisposed()){a==null||a(),d(),i.close();return}t.activateEngine();try{(u=e.onAttached)==null||u.call(e,i)}catch(p){throw t.deactivateEngine(),a==null||a(),d(),i.close(),p}n.onAttached(i,()=>{t.deactivateEngine(),a==null||a(),d()})}function sj(e){return e instanceof Error?e:new Error(String(e))}function Af(e){var d;let t=Nb(e.store,e.persistence,((d=e.sync)==null?void 0:d.readOnly)!==!0),n={},r=!1,o,s,i=()=>{let c=uc.get(e.store);(c==null?void 0:c.token)===n&&uc.delete(e.store),r=!0,o==null||o(),s==null||s.close(),o=void 0,s=void 0},a=uc.get(e.store);return uc.set(e.store,{dispose:i,token:n}),a==null||a.dispose(),r||oj(e,t,{isDisposed:()=>r,onAttached:(c,u)=>{s=c,o=u,r&&i()}}).catch(c=>{var u;r||(Re.error("[canvas-sdk:sync] failed to attach sync engine",c),(u=e.onError)==null||u.call(e,sj(c)))}),i}var ij="__xyq_idb_success_debug__";function Ob(){return globalThis}function aj(){var t;let e=Ob();try{return((t=e.localStorage)==null?void 0:t.getItem(ij))==="1"}catch{return!1}}function Lr(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}function gt(e){var t;if(e==null)return{type:String(e)};if(typeof e=="string")return{type:"string",length:e.length};if(typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer)return{type:"ArrayBuffer",byteLength:e.byteLength};if(typeof Blob<"u"&&e instanceof Blob)return{type:"Blob",size:e.size};if(Array.isArray(e)){let n=0,r={};for(let o of e){if(!o||typeof o!="object")continue;let s=o;Array.isArray(s.patches)&&(n+=s.patches.length),s.status&&(r[s.status]=(r[s.status]??0)+1)}return{type:"Array",length:e.length,patchCount:n,statusCounts:r}}if(typeof e=="object"){let n=e;return{type:((t=e.constructor)==null?void 0:t.name)??"Object",keyCount:Object.keys(n).length,txId:n.txId,status:n.status,patchCount:Array.isArray(n.patches)?n.patches.length:void 0}}return{type:typeof e}}function Yn(e,t,n){if(!aj())return;let r=n===void 0?void 0:Math.round((Lr()-n)*10)/10;Ob().console.info("[xyq-idb-success]",e,{...t,...r===void 0?{}:{elapsedMs:r}})}var kb="canvas-sync",Mb="outbound",dj="clientId",pc=new Map,_i=new Map,Ri=new Map;function Bo(e,t,n=!1){let o=(_i.get(e)??Promise.resolve()).then(t,t).catch(i=>{throw n&&!Ri.has(e)&&Ri.set(e,i),i}),s=o.then(()=>{},()=>{});return _i.set(e,s),s.then(()=>{_i.get(e)===s&&_i.delete(e)}),o}async function Db(e,t=!1){if(await _i.get(e),t&&Ri.has(e))throw Ri.get(e)}function cj(e){if(typeof indexedDB>"u")return Promise.resolve(null);let t=e.dbName??kb,n=e.storeName??Mb;return new Promise(r=>{let o=Lr(),s=indexedDB.open(t,1);s.onupgradeneeded=()=>{let i=s.result;i.objectStoreNames.contains(n)||i.createObjectStore(n)},s.onsuccess=()=>{Yn("canvas.open",{dbName:t,storeName:n},o),r(s.result)},s.onerror=()=>r(null),s.onblocked=()=>r(null)})}function uj(e,t,n){return new Promise((r,o)=>{let s=Lr(),i=e.transaction(t,"readonly").objectStore(t).get(n);i.onsuccess=()=>{Yn("canvas.get",{dbName:e.name,storeName:t,key:n,result:gt(i.result)},s),r(i.result)},i.onerror=()=>o(i.error)})}function pj(e,t,n,r){return new Promise((o,s)=>{let i=Lr(),a=e.transaction(t,"readwrite"),d=a.objectStore(t),c=d.get(n),u,p;c.onsuccess=()=>{let l=c.result;try{let f=r(l);p={after:f,before:l},f===void 0?d.delete(n):d.put(f,n)}catch(f){u=f,a.abort()}},a.oncomplete=()=>{Yn("canvas.mutate",{dbName:e.name,storeName:t,key:n,before:gt(p==null?void 0:p.before),after:gt(p==null?void 0:p.after)},i),o(p??{after:void 0,before:void 0})},a.onerror=()=>s(u??a.error??new Error("IndexedDB mutation failed")),a.onabort=()=>s(u??a.error??new Error("IndexedDB mutation aborted"))})}function Lb(e){return{...e,patches:e.patches.map(t=>({...t})),status:e.status==="in-flight"?"pending":e.status}}function Go(e){return e.map(Lb)}function vf(e,t={}){let n=t.dbName??kb,r=t.storeName??Mb,o=cj(t),s=`outbound:${e}`,i=t.clientIdKey??dj,a=f=>`${n}\0${r}\0${f}`,d=a(s),c=a(i),u=async f=>{let h=await o;return h?uj(h,r,f):pc.get(a(f))},p=async(f,h)=>{let m=await o;if(!m){let g=a(f),y=pc.get(g),v=h(y);return v===void 0?pc.delete(g):pc.set(g,v),{after:v,before:y}}return pj(m,r,f,h)};return{async loadClientId(){return await Db(c),await u(i)??null},async saveClientId(f){await Bo(c,()=>p(i,()=>f).then(()=>{}))},loadSnapshot(){return Promise.resolve(null)},async saveSnapshot(){},loadOutbound:async()=>(await Db(d,!0),Go(await u(s)??[])),async appendOutbound(f){await Bo(d,async()=>{let h=Lr(),m=await p(s,g=>[...Go(g??[]).filter(v=>v.txId!==f.txId),Lb(f)]);Yn("canvas.appendOutbound.plan",{key:s,txId:f.txId,env:gt(f),before:gt(m.before),after:gt(m.after)},h)},!0)},async removeOutbound(f){await Bo(d,async()=>{let h=Lr(),m=await p(s,g=>Go(g??[]).filter(y=>y.txId!==f));Yn("canvas.removeOutbound.plan",{key:s,txId:f,before:gt(m.before),after:gt(m.after)},h)},!0)},async replaceOutboundPartition(f,h){await Bo(d,async()=>{let m=Go(f),g=new Set(h),y=new Set(m.map(S=>S.txId)),v=await p(s,S=>{let b=Go(S??[]).filter(I=>!g.has(I.txId)&&!y.has(I.txId));return[...m,...b]});Yn("canvas.replaceOutboundPartition.plan",{key:s,capturedTxIds:[...h],before:gt(v.before),after:gt(v.after)})},!0)},async replaceOutbound(f){await Bo(d,async()=>{let h=Go(f);Yn("canvas.replaceOutbound.plan",{key:s,value:gt(h)}),await p(s,()=>h)},!0)},async clear(){await Bo(d,()=>p(s,()=>{}).then(()=>{}),!0),Ri.delete(d)}}}function lc(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function lj(e){if(!lc(e))throw new Error("Mutation must be an object");return e}function fj(e){throw new Error(`Unsupported canvas mutation kind: ${String(e)}`)}function mj(e,t,n){if(typeof t!="number"||!Number.isSafeInteger(t)||t<0)throw new Error(`Invalid array index for op ${n.op} at ${n.path}: ${String(t)}`);if(!(n.op==="add"?t<=e.length:t<e.length))throw new Error(`Array index out of bounds for op ${n.op} at ${n.path}: ${t}`);return t}function hj(e,t,n){if(!e||typeof e!="object")throw new Error(`Cannot apply patch at ${n.path}`);if(Array.isArray(e)){let o=mj(e,t,n);if(n.op==="remove"){e.splice(o,1);return}if(!("value"in n)||n.value===void 0)throw new Error(`Patch value is required for op ${n.op} at ${n.path}`);if(n.op==="add"){e.splice(o,0,n.value);return}e[o]=n.value;return}let r=e;if(n.op==="remove"){delete r[String(t)];return}if(!("value"in n)||n.value===void 0)throw new Error(`Patch value is required for op ${n.op} at ${n.path}`);r[String(t)]=n.value}function gj(e,t){let n=e,r=t;for(let o of Object.keys(n))o in r||delete n[o];for(let[o,s]of Object.entries(r))n[o]=s}function yj(e,t){if(t.op!=="remove"&&(!("value"in t)||t.value===void 0))throw new Error(`Patch value is required for op ${t.op} at ${t.path}`);if(t.path===""){if(t.op==="remove"){if(t.assetId===e.rootCanvasId)throw new Error(`Cannot remove root canvas asset: ${t.assetId}`);if(!Object.prototype.hasOwnProperty.call(e.assets,t.assetId))throw new Error(`Unknown patch target asset: ${t.assetId}`);delete e.assets[t.assetId];return}let i=t.value;if(!lc(i)||i.pippitAssetId!==t.assetId)throw new Error(`Invalid asset payload for ${t.assetId}`);let a=e.assets[t.assetId];if(!a){Mo(e,t.assetId,i);return}gj(a,i);return}let n=e.assets[t.assetId];if(!n)throw new Error(`Unknown patch target asset: ${t.assetId}`);let r=Jl(t.path),o=n;for(let i=0;i<r.length-1;i+=1){let a=r[i];if(!o||typeof o!="object")throw new Error(`Cannot apply patch at ${t.path}`);o=o[String(a)]}let s=r[r.length-1];if(s===void 0)throw new Error(`Invalid patch path: ${t.path}`);hj(o,s,t)}function Aj(e,t,n){return e.store.transact(r=>{let o=r.assets[t.assetId];if(!o)throw new Error(`Unknown asset: ${t.assetId}`);t.contentPatch&&lc(o.content)?Object.assign(o.content,t.contentPatch):t.contentPatch&&(o.content=t.contentPatch),t.extraPatch&&lc(o.extra)?Object.assign(o.extra,t.extraPatch):t.extraPatch&&(o.extra=t.extraPatch)},{intent:n})}function vj(e,t,n){return e.store.transact(r=>{for(let o of t.patches)yj(r,o)},{intent:n})}function Sj(e,t,n,r){var s,i;let o;switch(t.kind){case"set_title":o=e.store.commands.setTitle(t.title);break;case"set_cover":o=e.store.commands.setCover(t.cover);break;case"set_global_bounds":o=e.store.commands.setGlobalBounds(t.bounds);break;case"create_node":o=e.store.commands.createNode(t.node,{assets:t.assets,autoCreateNodeAsset:t.autoCreateNodeAsset});break;case"delete_nodes":o=e.store.commands.deleteNodes(t.ids);break;case"update_node_data":o=e.store.commands.updateNodeData(t.id,t.patch);break;case"set_node_style":o=e.store.commands.setNodeStyle(t.id,t.style);break;case"update_asset":o=Aj(e,t,n);break;case"move_nodes":o=e.store.commands.moveNodes(t.ids,t.delta);break;case"resize_node":o=e.store.commands.resizeNode(t.id,t.size);break;case"set_node_position":o=e.store.commands.setNodePosition(t.id,t.position);break;case"align_nodes":o=e.store.commands.alignNodes(t.ids,t.direction);break;case"distribute_nodes":o=e.store.commands.distributeNodes(t.ids,t.axis);break;case"arrange_nodes":o=e.store.commands.arrangeNodes(t.ids,t.layout,t.options);break;case"auto_layout_nodes":o=e.store.commands.autoLayoutNodes(t.options);break;case"group_nodes":o=e.store.commands.group(t.ids);break;case"ungroup":o=e.store.commands.ungroup(t.groupId);break;case"reparent":o=e.store.commands.reparent(t.nodeId,t.newParentId,t.index);break;case"reorder_children":o=e.store.commands.reorderChildren(t.groupId,t.orderedChildren);break;case"set_group_collapsed":o=e.store.commands.setGroupCollapsed(t.groupId,t.collapsed);break;case"create_edge":o=e.store.commands.createEdge(t.edge);break;case"delete_edges":o=e.store.commands.deleteEdges(t.ids);break;case"reconnect_edge":o=e.store.commands.reconnectEdge(t.id,t.patch);break;case"update_edge_data":o=e.store.commands.updateEdgeData(t.id,t.patch);break;case"update_snap_settings":o=e.store.commands.updateSnapSettings(t.patch);break;case"set_snap_enabled":o=e.store.commands.setSnapEnabled(t.enabled);break;case"set_auto_layout_strategy":o=e.store.commands.setAutoLayoutStrategy(t.strategy);break;case"invoke_command":o=e.store.commands.invoke(t.name,...t.args??[]);break;case"delete":(s=t.edgeIds)!=null&&s.length&&r(e.store.commands.deleteEdges(t.edgeIds)),(i=t.nodeIds)!=null&&i.length&&r(e.store.commands.deleteNodes(t.nodeIds));return;case"apply_patches":o=vj(e,t,n);break;default:fj(t)}r(o)}function Ei({atomic:e,dryRun:t,expectedRevision:n,intent:r,mutations:o,runtime:s}){if(typeof n=="number"&&s.store.getRevision()!==n)throw new Error(`Expected revision ${n}, current revision ${s.store.getRevision()}`);if(t)return{dryRun:!0,results:[]};let i=[],a=u=>{if(i.push(u),e&&u.status==="aborted")throw u.error??new Error(u.reason)},d=()=>{for(let u of o)Sj(s,lj(u),r,a)};if(!e)return d(),{results:i};let c=s.store.commands.batch(r,d);if(c.status==="aborted")throw c.error??new Error(c.reason);return{results:[c]}}function fc(e){return JSON.parse(JSON.stringify(e))}function bj(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Sf(e){return Array.isArray(e)?`[${e.map(Sf).join(",")}]`:bj(e)?`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${Sf(e[t])}`).join(",")}}`:JSON.stringify(e)}function Ij(e){let t=5381;for(let n=0;n<e.length;n+=1)t=t*33^e.charCodeAt(n);return`hash_${(t>>>0).toString(36)}`}function _j(e){return Ij(Sf(e))}function Rj(){let e=new Map;return{create(t){e.set(t.checkpointId,fc(t))},get(t){let n=e.get(t);return n?fc(n):void 0},list(t){return Array.from(e.values()).filter(n=>n.canvasId===t).map(n=>fc(n))}}}var Bb=new WeakMap;function Uo(e){if(e.checkpoints)return e.checkpoints;let t=Bb.get(e);return t||(t=Rj(),Bb.set(e,t)),t}async function Ej(e,t){let n=typeof e.permissions=="function"?await e.permissions(t):e.permissions;return new Set(n)}function Ct(e,t,n){return{code:t,message:n,ok:!1,revision:e.store.getRevision()}}function se(e){return JSON.stringify(e,null,2)}function bn(e,t){return{data:t,ok:!0,revision:e.store.getRevision()}}function zo(e){return e.store.getState().rootCanvasId}function mc(e){var t;return!!((t=e.store.getRootCanvasContent().settings)!=null&&t.readOnly)}async function hc(e,t,n){let r=await Ej(e,t),o=n.filter(s=>!r.has(s));return o.length>0?Ct(e,"PERMISSION_DENIED",`Missing canvas tool permission(s): ${o.join(", ")}`):null}function bf(e,t){var o,s;let n=fc(e.store.getState()),r=((o=e.now)==null?void 0:o.call(e))??Date.now();return{canvasId:n.rootCanvasId,checkpointId:((s=e.createCheckpointId)==null?void 0:s.call(e))??`canvas_checkpoint_${r}`,createdAt:r,document:n,documentHash:_j(n),reason:t,revision:e.store.getRevision()}}function Gb(e,t){return tf(e.store,t.document,{intent:"opencode.checkpoint.restore"})}var Cj="__debug_i18n__",Pj="1",xj="0",Ub=new WeakMap;function If(e){try{return e()}catch{return}}function zb(e,t){try{e(t)}catch{}}function Tj(e,t){if(e)try{return new URL(e,"http://pippit-business-shared.local").searchParams.get(t)??void 0}catch{return}}function Nj(e){try{return decodeURIComponent(e)}catch{return}}function wj(e,t){if(e===void 0)return;let n=`${encodeURIComponent(t)}=`,r=e.split(";").map(o=>o.trim()).find(o=>o.startsWith(n));return r?Nj(r.slice(n.length)):void 0}function qb(e,t,n,r){let o=r===void 0?"":`; Max-Age=${r}`;return`${encodeURIComponent(e)}=${encodeURIComponent(t)}; path=${n}${o}`}function Oj(){return{readHref:()=>typeof window>"u"?void 0:window.location.href,readCookie:()=>typeof document>"u"?void 0:document.cookie,writeCookie:e=>{typeof document<"u"&&(document.cookie=e)}}}function Dj(e={}){let t=e.cookieKey??Cj,n=e.enabledValue??Pj,r=e.disabledValue??xj,o=e.cookiePath??"/",s=e.environment??Oj(),i=e.refreshOnHrefChange??!1,a,d,c=p=>{d=p;let l=Tj(p,t);if(l===n)return zb(h=>s.writeCookie(h),qb(t,n,o)),a=!0,a;if(l===r)return zb(h=>s.writeCookie(h),qb(t,"",o,0)),a=!1,a;let f=If(()=>s.readCookie());return p===void 0&&f===void 0?(a=void 0,!1):(a=wj(f,t)===n,a)},u=()=>c(If(()=>s.readHref()));return{isEnabled:()=>{if(a===void 0)return u();if(i){let p=If(()=>s.readHref());if(p!==d)return c(p)}return a},refresh:u,invalidate:()=>{a=void 0,d=void 0}}}function kj(e){return Array.isArray(e)?`${e[0]??""}`:`${e??""}`}var Mj=Dj({refreshOnHrefChange:!0});function gc(){return{memoize:!0,memoizeFallback:!0,bindI18n:"languageChanged",bindI18nStore:"added removed"}}function yc(e,t={}){let n=t.runtime??Mj,r=t.resolveKeyText??kj,o=Ub.get(e)??e.t.bind(e);return Ub.set(e,o),e.t=(...s)=>n.isEnabled()?r(s[0]):o(...s),e}function Fe(e){"@babel/helpers - typeof";return Fe=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Fe(e)}function Fb(e,t){if(Fe(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(Fe(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function Ac(e){var t=Fb(e,"string");return Fe(t)=="symbol"?t:t+""}function jb(e,t,n){return(t=Ac(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function we(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?Object(arguments[t]):{},r=Object.keys(n);typeof Object.getOwnPropertySymbols=="function"&&r.push.apply(r,Object.getOwnPropertySymbols(n).filter(function(o){return Object.getOwnPropertyDescriptor(n,o).enumerable})),r.forEach(function(o){jb(e,o,n[o])})}return e}function Yt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Vb(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,Ac(r.key),r)}}function Kt(e,t,n){return t&&Vb(e.prototype,t),n&&Vb(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function In(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function qo(e,t){if(t&&(Fe(t)=="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return In(e)}function Br(e){return Br=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Br(e)}function vc(e,t){return vc=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},vc(e,t)}function Ci(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&vc(e,t)}var Lj={type:"logger",log:function(t){this.output("log",t)},warn:function(t){this.output("warn",t)},error:function(t){this.output("error",t)},output:function(t,n){console&&console[t]&&console[t].apply(console,n)}},Bj=function(){function e(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Yt(this,e),this.init(t,n)}return Kt(e,[{key:"init",value:function(n){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};this.prefix=r.prefix||"i18next:",this.logger=n||Lj,this.options=r,this.debug=r.debug}},{key:"setDebug",value:function(n){this.debug=n}},{key:"log",value:function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return this.forward(r,"log","",!0)}},{key:"warn",value:function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return this.forward(r,"warn","",!0)}},{key:"error",value:function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return this.forward(r,"error","")}},{key:"deprecate",value:function(){for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return this.forward(r,"warn","WARNING DEPRECATED: ",!0)}},{key:"forward",value:function(n,r,o,s){return s&&!this.debug?null:(typeof n[0]=="string"&&(n[0]="".concat(o).concat(this.prefix," ").concat(n[0])),this.logger[r](n))}},{key:"create",value:function(n){return new e(this.logger,we({},{prefix:"".concat(this.prefix,":").concat(n,":")},this.options))}}]),e}(),_n=new Bj,Kn=function(){function e(){Yt(this,e),this.observers={}}return Kt(e,[{key:"on",value:function(n,r){var o=this;return n.split(" ").forEach(function(s){o.observers[s]=o.observers[s]||[],o.observers[s].push(r)}),this}},{key:"off",value:function(n,r){if(this.observers[n]){if(!r){delete this.observers[n];return}this.observers[n]=this.observers[n].filter(function(o){return o!==r})}}},{key:"emit",value:function(n){for(var r=arguments.length,o=new Array(r>1?r-1:0),s=1;s<r;s++)o[s-1]=arguments[s];if(this.observers[n]){var i=[].concat(this.observers[n]);i.forEach(function(d){d.apply(void 0,o)})}if(this.observers["*"]){var a=[].concat(this.observers["*"]);a.forEach(function(d){d.apply(d,[n].concat(o))})}}}]),e}();function Pi(){var e,t,n=new Promise(function(r,o){e=r,t=o});return n.resolve=e,n.reject=t,n}function Hb(e){return e==null?"":""+e}function Gj(e,t,n){e.forEach(function(r){t[r]&&(n[r]=t[r])})}function Rf(e,t,n){function r(a){return a&&a.indexOf("###")>-1?a.replace(/###/g,"."):a}function o(){return!e||typeof e=="string"}for(var s=typeof t!="string"?[].concat(t):t.split(".");s.length>1;){if(o())return{};var i=r(s.shift());!e[i]&&n&&(e[i]=new n),Object.prototype.hasOwnProperty.call(e,i)?e=e[i]:e={}}return o()?{}:{obj:e,k:r(s.shift())}}function Yb(e,t,n){var r=Rf(e,t,Object),o=r.obj,s=r.k;o[s]=n}function Uj(e,t,n,r){var o=Rf(e,t,Object),s=o.obj,i=o.k;s[i]=s[i]||[],r&&(s[i]=s[i].concat(n)),r||s[i].push(n)}function bc(e,t){var n=Rf(e,t),r=n.obj,o=n.k;if(r)return r[o]}function Kb(e,t,n){var r=bc(e,n);return r!==void 0?r:bc(t,n)}function Qb(e,t,n){for(var r in t)r!=="__proto__"&&r!=="constructor"&&(r in e?typeof e[r]=="string"||e[r]instanceof String||typeof t[r]=="string"||t[r]instanceof String?n&&(e[r]=t[r]):Qb(e[r],t[r],n):e[r]=t[r]);return e}function Fo(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}var zj={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};function qj(e){return typeof e=="string"?e.replace(/[&<>"'\/]/g,function(t){return zj[t]}):e}var Ic=typeof window<"u"&&window.navigator&&window.navigator.userAgent&&window.navigator.userAgent.indexOf("MSIE")>-1,Fj=function(e){Ci(t,e);function t(n){var r,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{ns:["translation"],defaultNS:"translation"};return Yt(this,t),r=qo(this,Br(t).call(this)),Ic&&Kn.call(In(r)),r.data=n||{},r.options=o,r.options.keySeparator===void 0&&(r.options.keySeparator="."),r}return Kt(t,[{key:"addNamespaces",value:function(r){this.options.ns.indexOf(r)<0&&this.options.ns.push(r)}},{key:"removeNamespaces",value:function(r){var o=this.options.ns.indexOf(r);o>-1&&this.options.ns.splice(o,1)}},{key:"getResource",value:function(r,o,s){var i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{},a=i.keySeparator!==void 0?i.keySeparator:this.options.keySeparator,d=[r,o];return s&&typeof s!="string"&&(d=d.concat(s)),s&&typeof s=="string"&&(d=d.concat(a?s.split(a):s)),r.indexOf(".")>-1&&(d=r.split(".")),bc(this.data,d)}},{key:"addResource",value:function(r,o,s,i){var a=arguments.length>4&&arguments[4]!==void 0?arguments[4]:{silent:!1},d=this.options.keySeparator;d===void 0&&(d=".");var c=[r,o];s&&(c=c.concat(d?s.split(d):s)),r.indexOf(".")>-1&&(c=r.split("."),i=o,o=c[1]),this.addNamespaces(o),Yb(this.data,c,i),a.silent||this.emit("added",r,o,s,i)}},{key:"addResources",value:function(r,o,s){var i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{silent:!1};for(var a in s)(typeof s[a]=="string"||Object.prototype.toString.apply(s[a])==="[object Array]")&&this.addResource(r,o,a,s[a],{silent:!0});i.silent||this.emit("added",r,o,s)}},{key:"addResourceBundle",value:function(r,o,s,i,a){var d=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{silent:!1},c=[r,o];r.indexOf(".")>-1&&(c=r.split("."),i=s,s=o,o=c[1]),this.addNamespaces(o);var u=bc(this.data,c)||{};i?Qb(u,s,a):u=we({},u,s),Yb(this.data,c,u),d.silent||this.emit("added",r,o,s)}},{key:"removeResourceBundle",value:function(r,o){this.hasResourceBundle(r,o)&&delete this.data[r][o],this.removeNamespaces(o),this.emit("removed",r,o)}},{key:"hasResourceBundle",value:function(r,o){return this.getResource(r,o)!==void 0}},{key:"getResourceBundle",value:function(r,o){return o||(o=this.options.defaultNS),this.options.compatibilityAPI==="v1"?we({},{},this.getResource(r,o)):this.getResource(r,o)}},{key:"getDataByLanguage",value:function(r){return this.data[r]}},{key:"toJSON",value:function(){return this.data}}]),t}(Kn),Jb={processors:{},addPostProcessor:function(t){this.processors[t.name]=t},handle:function(t,n,r,o,s){var i=this;return t.forEach(function(a){i.processors[a]&&(n=i.processors[a].process(n,r,o,s))}),n}},Xb={},$b=function(e){Ci(t,e);function t(n){var r,o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return Yt(this,t),r=qo(this,Br(t).call(this)),Ic&&Kn.call(In(r)),Gj(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],n,In(r)),r.options=o,r.options.keySeparator===void 0&&(r.options.keySeparator="."),r.logger=_n.create("translator"),r}return Kt(t,[{key:"changeLanguage",value:function(r){r&&(this.language=r)}},{key:"exists",value:function(r){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{interpolation:{}},s=this.resolve(r,o);return s&&s.res!==void 0}},{key:"extractFromKey",value:function(r,o){var s=o.nsSeparator!==void 0?o.nsSeparator:this.options.nsSeparator;s===void 0&&(s=":");var i=o.keySeparator!==void 0?o.keySeparator:this.options.keySeparator,a=o.ns||this.options.defaultNS;if(s&&r.indexOf(s)>-1){var d=r.match(this.interpolator.nestingRegexp);if(d&&d.length>0)return{key:r,namespaces:a};var c=r.split(s);(s!==i||s===i&&this.options.ns.indexOf(c[0])>-1)&&(a=c.shift()),r=c.join(i)}return typeof a=="string"&&(a=[a]),{key:r,namespaces:a}}},{key:"translate",value:function(r,o,s){var i=this;if(Fe(o)!=="object"&&this.options.overloadTranslationOptionHandler&&(o=this.options.overloadTranslationOptionHandler(arguments)),o||(o={}),r==null)return"";Array.isArray(r)||(r=[String(r)]);var a=o.keySeparator!==void 0?o.keySeparator:this.options.keySeparator,d=this.extractFromKey(r[r.length-1],o),c=d.key,u=d.namespaces,p=u[u.length-1],l=o.lng||this.language,f=o.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if(l&&l.toLowerCase()==="cimode"){if(f){var h=o.nsSeparator||this.options.nsSeparator;return p+h+c}return c}var m=this.resolve(r,o),g=m&&m.res,y=m&&m.usedKey||c,v=m&&m.exactUsedKey||c,S=Object.prototype.toString.apply(g),b=["[object Number]","[object Function]","[object RegExp]"],I=o.joinArrays!==void 0?o.joinArrays:this.options.joinArrays,N=!this.i18nFormat||this.i18nFormat.handleAsObject,w=typeof g!="string"&&typeof g!="boolean"&&typeof g!="number";if(N&&g&&w&&b.indexOf(S)<0&&!(typeof I=="string"&&S==="[object Array]")){if(!o.returnObjects&&!this.options.returnObjects)return this.logger.warn("accessing an object - but returnObjects options is not enabled!"),this.options.returnedObjectHandler?this.options.returnedObjectHandler(y,g,o):"key '".concat(c," (").concat(this.language,")' returned an object instead of string.");if(a){var ne=S==="[object Array]",Ge=ne?[]:{},Y=ne?v:y;for(var T in g)if(Object.prototype.hasOwnProperty.call(g,T)){var F="".concat(Y).concat(a).concat(T);Ge[T]=this.translate(F,we({},o,{joinArrays:!1,ns:u})),Ge[T]===F&&(Ge[T]=g[T])}g=Ge}}else if(N&&typeof I=="string"&&S==="[object Array]")g=g.join(I),g&&(g=this.extendTranslation(g,r,o,s));else{var j=!1,J=!1,ie=o.count!==void 0&&typeof o.count!="string",Se=t.hasDefaultValue(o),He=ie?this.pluralResolver.getSuffix(l,o.count):"",ge=o["defaultValue".concat(He)]||o.defaultValue;!this.isValidLookup(g)&&Se&&(j=!0,g=ge),this.isValidLookup(g)||(J=!0,g=c);var re=Se&&ge!==g&&this.options.updateMissing;if(J||j||re){if(this.logger.log(re?"updateKey":"missingKey",l,p,c,re?ge:g),a){var St=this.resolve(c,we({},o,{keySeparator:!1}));St&&St.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}var We=[],pn=this.languageUtils.getFallbackCodes(this.options.fallbackLng,o.lng||this.language);if(this.options.saveMissingTo==="fallback"&&pn&&pn[0])for(var Ue=0;Ue<pn.length;Ue++)We.push(pn[Ue]);else this.options.saveMissingTo==="all"?We=this.languageUtils.toResolveHierarchy(o.lng||this.language):We.push(o.lng||this.language);var Qe=function(ut,Fs,xy){i.options.missingKeyHandler?i.options.missingKeyHandler(ut,p,Fs,re?xy:g,re,o):i.backendConnector&&i.backendConnector.saveMissing&&i.backendConnector.saveMissing(ut,p,Fs,re?xy:g,re,o),i.emit("missingKey",ut,p,Fs,g)};this.options.saveMissing&&(this.options.saveMissingPlurals&&ie?We.forEach(function(Mt){i.pluralResolver.getSuffixes(Mt).forEach(function(ut){Qe([Mt],c+ut,o["defaultValue".concat(ut)]||ge)})}):Qe(We,c,ge))}g=this.extendTranslation(g,r,o,m,s),J&&g===c&&this.options.appendNamespaceToMissingKey&&(g="".concat(p,":").concat(c)),J&&this.options.parseMissingKeyHandler&&(g=this.options.parseMissingKeyHandler(g))}return g}},{key:"extendTranslation",value:function(r,o,s,i,a){var d=this;if(this.i18nFormat&&this.i18nFormat.parse)r=this.i18nFormat.parse(r,s,i.usedLng,i.usedNS,i.usedKey,{resolved:i});else if(!s.skipInterpolation){s.interpolation&&this.interpolator.init(we({},s,{interpolation:we({},this.options.interpolation,s.interpolation)}));var c=s.interpolation&&s.interpolation.skipOnVariables||this.options.interpolation.skipOnVariables,u;if(c){var p=r.match(this.interpolator.nestingRegexp);u=p&&p.length}var l=s.replace&&typeof s.replace!="string"?s.replace:s;if(this.options.interpolation.defaultVariables&&(l=we({},this.options.interpolation.defaultVariables,l)),r=this.interpolator.interpolate(r,l,s.lng||this.language,s),c){var f=r.match(this.interpolator.nestingRegexp),h=f&&f.length;u<h&&(s.nest=!1)}s.nest!==!1&&(r=this.interpolator.nest(r,function(){for(var y=arguments.length,v=new Array(y),S=0;S<y;S++)v[S]=arguments[S];return a&&a[0]===v[0]&&!s.context?(d.logger.warn("It seems you are nesting recursively key: ".concat(v[0]," in key: ").concat(o[0])),null):d.translate.apply(d,v.concat([o]))},s)),s.interpolation&&this.interpolator.reset()}var m=s.postProcess||this.options.postProcess,g=typeof m=="string"?[m]:m;return r!=null&&g&&g.length&&s.applyPostProcessor!==!1&&(r=Jb.handle(g,r,o,this.options&&this.options.postProcessPassResolved?we({i18nResolved:i},s):s,this)),r}},{key:"resolve",value:function(r){var o=this,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i,a,d,c,u;return typeof r=="string"&&(r=[r]),r.forEach(function(p){if(!o.isValidLookup(i)){var l=o.extractFromKey(p,s),f=l.key;a=f;var h=l.namespaces;o.options.fallbackNS&&(h=h.concat(o.options.fallbackNS));var m=s.count!==void 0&&typeof s.count!="string",g=s.context!==void 0&&typeof s.context=="string"&&s.context!=="",y=s.lngs?s.lngs:o.languageUtils.toResolveHierarchy(s.lng||o.language,s.fallbackLng);h.forEach(function(v){o.isValidLookup(i)||(u=v,!Xb["".concat(y[0],"-").concat(v)]&&o.utils&&o.utils.hasLoadedNamespace&&!o.utils.hasLoadedNamespace(u)&&(Xb["".concat(y[0],"-").concat(v)]=!0,o.logger.warn('key "'.concat(a,'" for languages "').concat(y.join(", "),`" won't get resolved as namespace "`).concat(u,'" was not yet loaded'),"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),y.forEach(function(S){if(!o.isValidLookup(i)){c=S;var b=f,I=[b];if(o.i18nFormat&&o.i18nFormat.addLookupKeys)o.i18nFormat.addLookupKeys(I,f,S,v,s);else{var N;m&&(N=o.pluralResolver.getSuffix(S,s.count)),m&&g&&I.push(b+N),g&&I.push(b+="".concat(o.options.contextSeparator).concat(s.context)),m&&I.push(b+=N)}for(var w;w=I.pop();)o.isValidLookup(i)||(d=w,i=o.getResource(S,v,w,s))}}))})}}),{res:i,usedKey:a,exactUsedKey:d,usedLng:c,usedNS:u}}},{key:"isValidLookup",value:function(r){return r!==void 0&&!(!this.options.returnNull&&r===null)&&!(!this.options.returnEmptyString&&r==="")}},{key:"getResource",value:function(r,o,s){var i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return this.i18nFormat&&this.i18nFormat.getResource?this.i18nFormat.getResource(r,o,s,i):this.resourceStore.getResource(r,o,s,i)}}],[{key:"hasDefaultValue",value:function(r){var o="defaultValue";for(var s in r)if(Object.prototype.hasOwnProperty.call(r,s)&&o===s.substring(0,o.length)&&r[s]!==void 0)return!0;return!1}}]),t}(Kn);function _f(e){return e.charAt(0).toUpperCase()+e.slice(1)}var jj=function(){function e(t){Yt(this,e),this.options=t,this.whitelist=this.options.supportedLngs||!1,this.supportedLngs=this.options.supportedLngs||!1,this.logger=_n.create("languageUtils")}return Kt(e,[{key:"getScriptPartFromCode",value:function(n){if(!n||n.indexOf("-")<0)return null;var r=n.split("-");return r.length===2||(r.pop(),r[r.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(r.join("-"))}},{key:"getLanguagePartFromCode",value:function(n){if(!n||n.indexOf("-")<0)return n;var r=n.split("-");return this.formatLanguageCode(r[0])}},{key:"formatLanguageCode",value:function(n){if(typeof n=="string"&&n.indexOf("-")>-1){var r=["hans","hant","latn","cyrl","cans","mong","arab"],o=n.split("-");return this.options.lowerCaseLng?o=o.map(function(s){return s.toLowerCase()}):o.length===2?(o[0]=o[0].toLowerCase(),o[1]=o[1].toUpperCase(),r.indexOf(o[1].toLowerCase())>-1&&(o[1]=_f(o[1].toLowerCase()))):o.length===3&&(o[0]=o[0].toLowerCase(),o[1].length===2&&(o[1]=o[1].toUpperCase()),o[0]!=="sgn"&&o[2].length===2&&(o[2]=o[2].toUpperCase()),r.indexOf(o[1].toLowerCase())>-1&&(o[1]=_f(o[1].toLowerCase())),r.indexOf(o[2].toLowerCase())>-1&&(o[2]=_f(o[2].toLowerCase()))),o.join("-")}return this.options.cleanCode||this.options.lowerCaseLng?n.toLowerCase():n}},{key:"isWhitelisted",value:function(n){return this.logger.deprecate("languageUtils.isWhitelisted",`function "isWhitelisted" will be renamed to "isSupportedCode" in the next major - please make sure to rename it's usage asap.`),this.isSupportedCode(n)}},{key:"isSupportedCode",value:function(n){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(n=this.getLanguagePartFromCode(n)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(n)>-1}},{key:"getBestMatchFromCodes",value:function(n){var r=this;if(!n)return null;var o;return n.forEach(function(s){if(!o){var i=r.formatLanguageCode(s);(!r.options.supportedLngs||r.isSupportedCode(i))&&(o=i)}}),!o&&this.options.supportedLngs&&n.forEach(function(s){if(!o){var i=r.getLanguagePartFromCode(s);if(r.isSupportedCode(i))return o=i;o=r.options.supportedLngs.find(function(a){if(a.indexOf(i)===0)return a})}}),o||(o=this.getFallbackCodes(this.options.fallbackLng)[0]),o}},{key:"getFallbackCodes",value:function(n,r){if(!n)return[];if(typeof n=="function"&&(n=n(r)),typeof n=="string"&&(n=[n]),Object.prototype.toString.apply(n)==="[object Array]")return n;if(!r)return n.default||[];var o=n[r];return o||(o=n[this.getScriptPartFromCode(r)]),o||(o=n[this.formatLanguageCode(r)]),o||(o=n[this.getLanguagePartFromCode(r)]),o||(o=n.default),o||[]}},{key:"toResolveHierarchy",value:function(n,r){var o=this,s=this.getFallbackCodes(r||this.options.fallbackLng||[],n),i=[],a=function(c){c&&(o.isSupportedCode(c)?i.push(c):o.logger.warn("rejecting language code not found in supportedLngs: ".concat(c)))};return typeof n=="string"&&n.indexOf("-")>-1?(this.options.load!=="languageOnly"&&a(this.formatLanguageCode(n)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&a(this.getScriptPartFromCode(n)),this.options.load!=="currentOnly"&&a(this.getLanguagePartFromCode(n))):typeof n=="string"&&a(this.formatLanguageCode(n)),s.forEach(function(d){i.indexOf(d)<0&&a(o.formatLanguageCode(d))}),i}}]),e}(),Vj=[{lngs:["ach","ak","am","arn","br","fil","gun","ln","mfe","mg","mi","oc","pt","pt-BR","tg","tl","ti","tr","uz","wa"],nr:[1,2],fc:1},{lngs:["af","an","ast","az","bg","bn","ca","da","de","dev","el","en","eo","es","et","eu","fi","fo","fur","fy","gl","gu","ha","hi","hu","hy","ia","it","kn","ku","lb","mai","ml","mn","mr","nah","nap","nb","ne","nl","nn","no","nso","pa","pap","pms","ps","pt-PT","rm","sco","se","si","so","son","sq","sv","sw","ta","te","tk","ur","yo"],nr:[1,2],fc:2},{lngs:["ay","bo","cgg","fa","ht","id","ja","jbo","ka","kk","km","ko","ky","lo","ms","sah","su","th","tt","ug","vi","wo","zh"],nr:[1],fc:3},{lngs:["be","bs","cnr","dz","hr","ru","sr","uk"],nr:[1,2,5],fc:4},{lngs:["ar"],nr:[0,1,2,3,11,100],fc:5},{lngs:["cs","sk"],nr:[1,2,5],fc:6},{lngs:["csb","pl"],nr:[1,2,5],fc:7},{lngs:["cy"],nr:[1,2,3,8],fc:8},{lngs:["fr"],nr:[1,2],fc:9},{lngs:["ga"],nr:[1,2,3,7,11],fc:10},{lngs:["gd"],nr:[1,2,3,20],fc:11},{lngs:["is"],nr:[1,2],fc:12},{lngs:["jv"],nr:[0,1],fc:13},{lngs:["kw"],nr:[1,2,3,4],fc:14},{lngs:["lt"],nr:[1,2,10],fc:15},{lngs:["lv"],nr:[1,2,0],fc:16},{lngs:["mk"],nr:[1,2],fc:17},{lngs:["mnk"],nr:[0,1,2],fc:18},{lngs:["mt"],nr:[1,2,11,20],fc:19},{lngs:["or"],nr:[2,1],fc:2},{lngs:["ro"],nr:[1,2,20],fc:20},{lngs:["sl"],nr:[5,1,2,3],fc:21},{lngs:["he","iw"],nr:[1,2,20,21],fc:22}],Hj={1:function(t){return+(t>1)},2:function(t){return+(t!=1)},3:function(t){return 0},4:function(t){return t%10==1&&t%100!=11?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2},5:function(t){return t==0?0:t==1?1:t==2?2:t%100>=3&&t%100<=10?3:t%100>=11?4:5},6:function(t){return t==1?0:t>=2&&t<=4?1:2},7:function(t){return t==1?0:t%10>=2&&t%10<=4&&(t%100<10||t%100>=20)?1:2},8:function(t){return t==1?0:t==2?1:t!=8&&t!=11?2:3},9:function(t){return+(t>=2)},10:function(t){return t==1?0:t==2?1:t<7?2:t<11?3:4},11:function(t){return t==1||t==11?0:t==2||t==12?1:t>2&&t<20?2:3},12:function(t){return+(t%10!=1||t%100==11)},13:function(t){return+(t!==0)},14:function(t){return t==1?0:t==2?1:t==3?2:3},15:function(t){return t%10==1&&t%100!=11?0:t%10>=2&&(t%100<10||t%100>=20)?1:2},16:function(t){return t%10==1&&t%100!=11?0:t!==0?1:2},17:function(t){return t==1||t%10==1&&t%100!=11?0:1},18:function(t){return t==0?0:t==1?1:2},19:function(t){return t==1?0:t==0||t%100>1&&t%100<11?1:t%100>10&&t%100<20?2:3},20:function(t){return t==1?0:t==0||t%100>0&&t%100<20?1:2},21:function(t){return t%100==1?1:t%100==2?2:t%100==3||t%100==4?3:0},22:function(t){return t==1?0:t==2?1:(t<0||t>10)&&t%10==0?2:3}};function Yj(){var e={};return Vj.forEach(function(t){t.lngs.forEach(function(n){e[n]={numbers:t.nr,plurals:Hj[t.fc]}})}),e}var Kj=function(){function e(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Yt(this,e),this.languageUtils=t,this.options=n,this.logger=_n.create("pluralResolver"),this.rules=Yj()}return Kt(e,[{key:"addRule",value:function(n,r){this.rules[n]=r}},{key:"getRule",value:function(n){return this.rules[n]||this.rules[this.languageUtils.getLanguagePartFromCode(n)]}},{key:"needsPlural",value:function(n){var r=this.getRule(n);return r&&r.numbers.length>1}},{key:"getPluralFormsOfKey",value:function(n,r){return this.getSuffixes(n).map(function(o){return r+o})}},{key:"getSuffixes",value:function(n){var r=this,o=this.getRule(n);return o?o.numbers.map(function(s){return r.getSuffix(n,s)}):[]}},{key:"getSuffix",value:function(n,r){var o=this,s=this.getRule(n);if(s){var i=s.noAbs?s.plurals(r):s.plurals(Math.abs(r)),a=s.numbers[i];this.options.simplifyPluralSuffix&&s.numbers.length===2&&s.numbers[0]===1&&(a===2?a="plural":a===1&&(a=""));var d=function(){return o.options.prepend&&a.toString()?o.options.prepend+a.toString():a.toString()};return this.options.compatibilityJSON==="v1"?a===1?"":typeof a=="number"?"_plural_".concat(a.toString()):d():this.options.compatibilityJSON==="v2"||this.options.simplifyPluralSuffix&&s.numbers.length===2&&s.numbers[0]===1?d():this.options.prepend&&i.toString()?this.options.prepend+i.toString():i.toString()}return this.logger.warn("no plural rule found for: ".concat(n)),""}}]),e}(),Xj=function(){function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Yt(this,e),this.logger=_n.create("interpolator"),this.options=t,this.format=t.interpolation&&t.interpolation.format||function(n){return n},this.init(t)}return Kt(e,[{key:"init",value:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};n.interpolation||(n.interpolation={escapeValue:!0});var r=n.interpolation;this.escape=r.escape!==void 0?r.escape:qj,this.escapeValue=r.escapeValue!==void 0?r.escapeValue:!0,this.useRawValueToEscape=r.useRawValueToEscape!==void 0?r.useRawValueToEscape:!1,this.prefix=r.prefix?Fo(r.prefix):r.prefixEscaped||"{{",this.suffix=r.suffix?Fo(r.suffix):r.suffixEscaped||"}}",this.formatSeparator=r.formatSeparator?r.formatSeparator:r.formatSeparator||",",this.unescapePrefix=r.unescapeSuffix?"":r.unescapePrefix||"-",this.unescapeSuffix=this.unescapePrefix?"":r.unescapeSuffix||"",this.nestingPrefix=r.nestingPrefix?Fo(r.nestingPrefix):r.nestingPrefixEscaped||Fo("$t("),this.nestingSuffix=r.nestingSuffix?Fo(r.nestingSuffix):r.nestingSuffixEscaped||Fo(")"),this.nestingOptionsSeparator=r.nestingOptionsSeparator?r.nestingOptionsSeparator:r.nestingOptionsSeparator||",",this.maxReplaces=r.maxReplaces?r.maxReplaces:1e3,this.alwaysFormat=r.alwaysFormat!==void 0?r.alwaysFormat:!1,this.resetRegExp()}},{key:"reset",value:function(){this.options&&this.init(this.options)}},{key:"resetRegExp",value:function(){var n="".concat(this.prefix,"(.+?)").concat(this.suffix);this.regexp=new RegExp(n,"g");var r="".concat(this.prefix).concat(this.unescapePrefix,"(.+?)").concat(this.unescapeSuffix).concat(this.suffix);this.regexpUnescape=new RegExp(r,"g");var o="".concat(this.nestingPrefix,"(.+?)").concat(this.nestingSuffix);this.nestingRegexp=new RegExp(o,"g")}},{key:"interpolate",value:function(n,r,o,s){var i=this,a,d,c,u=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{};function p(g){return g.replace(/\$/g,"$$$$")}var l=function(y){if(y.indexOf(i.formatSeparator)<0){var v=Kb(r,u,y);return i.alwaysFormat?i.format(v,void 0,o):v}var S=y.split(i.formatSeparator),b=S.shift().trim(),I=S.join(i.formatSeparator).trim();return i.format(Kb(r,u,b),I,o,s)};this.resetRegExp();var f=s&&s.missingInterpolationHandler||this.options.missingInterpolationHandler,h=s&&s.interpolation&&s.interpolation.skipOnVariables||this.options.interpolation.skipOnVariables,m=[{regex:this.regexpUnescape,safeValue:function(y){return p(y)}},{regex:this.regexp,safeValue:function(y){return i.escapeValue?p(i.escape(y)):p(y)}}];return m.forEach(function(g){for(c=0;a=g.regex.exec(n);){if(d=l(a[1].trim()),d===void 0)if(typeof f=="function"){var y=f(n,a,s);d=typeof y=="string"?y:""}else if(h){d=a[0];continue}else i.logger.warn("missed to pass in variable ".concat(a[1]," for interpolating ").concat(n)),d="";else typeof d!="string"&&!i.useRawValueToEscape&&(d=Hb(d));if(n=n.replace(a[0],g.safeValue(d)),g.regex.lastIndex=0,c++,c>=i.maxReplaces)break}}),n}},{key:"nest",value:function(n,r){var o=this,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},i,a,d=we({},s);d.applyPostProcessor=!1,delete d.defaultValue;function c(f,h){var m=this.nestingOptionsSeparator;if(f.indexOf(m)<0)return f;var g=f.split(new RegExp("".concat(m,"[ ]*{"))),y="{".concat(g[1]);f=g[0],y=this.interpolate(y,d),y=y.replace(/'/g,'"');try{d=JSON.parse(y),h&&(d=we({},h,d))}catch(v){return this.logger.warn("failed parsing options string in nesting for key ".concat(f),v),"".concat(f).concat(m).concat(y)}return delete d.defaultValue,f}for(;i=this.nestingRegexp.exec(n);){var u=[],p=!1;if(i[0].includes(this.formatSeparator)&&!/{.*}/.test(i[1])){var l=i[1].split(this.formatSeparator).map(function(f){return f.trim()});i[1]=l.shift(),u=l,p=!0}if(a=r(c.call(this,i[1].trim(),d),d),a&&i[0]===n&&typeof a!="string")return a;typeof a!="string"&&(a=Hb(a)),a||(this.logger.warn("missed to resolve ".concat(i[1]," for nesting ").concat(n)),a=""),p&&(a=u.reduce(function(f,h){return o.format(f,h,s.lng,s)},a.trim())),n=n.replace(i[0],a),this.regexp.lastIndex=0}return n}}]),e}();function $j(e,t){for(var n=e.indexOf(t);n!==-1;)e.splice(n,1),n=e.indexOf(t)}var Wj=function(e){Ci(t,e);function t(n,r,o){var s,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:{};return Yt(this,t),s=qo(this,Br(t).call(this)),Ic&&Kn.call(In(s)),s.backend=n,s.store=r,s.services=o,s.languageUtils=o.languageUtils,s.options=i,s.logger=_n.create("backendConnector"),s.state={},s.queue=[],s.backend&&s.backend.init&&s.backend.init(o,i.backend,i),s}return Kt(t,[{key:"queueLoad",value:function(r,o,s,i){var a=this,d=[],c=[],u=[],p=[];return r.forEach(function(l){var f=!0;o.forEach(function(h){var m="".concat(l,"|").concat(h);!s.reload&&a.store.hasResourceBundle(l,h)?a.state[m]=2:a.state[m]<0||(a.state[m]===1?c.indexOf(m)<0&&c.push(m):(a.state[m]=1,f=!1,c.indexOf(m)<0&&c.push(m),d.indexOf(m)<0&&d.push(m),p.indexOf(h)<0&&p.push(h)))}),f||u.push(l)}),(d.length||c.length)&&this.queue.push({pending:c,loaded:{},errors:[],callback:i}),{toLoad:d,pending:c,toLoadLanguages:u,toLoadNamespaces:p}}},{key:"loaded",value:function(r,o,s){var i=r.split("|"),a=i[0],d=i[1];o&&this.emit("failedLoading",a,d,o),s&&this.store.addResourceBundle(a,d,s),this.state[r]=o?-1:2;var c={};this.queue.forEach(function(u){Uj(u.loaded,[a],d),$j(u.pending,r),o&&u.errors.push(o),u.pending.length===0&&!u.done&&(Object.keys(u.loaded).forEach(function(p){c[p]||(c[p]=[]),u.loaded[p].length&&u.loaded[p].forEach(function(l){c[p].indexOf(l)<0&&c[p].push(l)})}),u.done=!0,u.errors.length?u.callback(u.errors):u.callback())}),this.emit("loaded",c),this.queue=this.queue.filter(function(u){return!u.done})}},{key:"read",value:function(r,o,s){var i=this,a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,d=arguments.length>4&&arguments[4]!==void 0?arguments[4]:350,c=arguments.length>5?arguments[5]:void 0;return r.length?this.backend[s](r,o,function(u,p){if(u&&p&&a<5){setTimeout(function(){i.read.call(i,r,o,s,a+1,d*2,c)},d);return}c(u,p)}):c(null,{})}},{key:"prepareLoading",value:function(r,o){var s=this,i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},a=arguments.length>3?arguments[3]:void 0;if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),a&&a();typeof r=="string"&&(r=this.languageUtils.toResolveHierarchy(r)),typeof o=="string"&&(o=[o]);var d=this.queueLoad(r,o,i,a);if(!d.toLoad.length)return d.pending.length||a(),null;d.toLoad.forEach(function(c){s.loadOne(c)})}},{key:"load",value:function(r,o,s){this.prepareLoading(r,o,{},s)}},{key:"reload",value:function(r,o,s){this.prepareLoading(r,o,{reload:!0},s)}},{key:"loadOne",value:function(r){var o=this,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"",i=r.split("|"),a=i[0],d=i[1];this.read(a,d,"read",void 0,void 0,function(c,u){c&&o.logger.warn("".concat(s,"loading namespace ").concat(d," for language ").concat(a," failed"),c),!c&&u&&o.logger.log("".concat(s,"loaded namespace ").concat(d," for language ").concat(a),u),o.loaded(r,c,u)})}},{key:"saveMissing",value:function(r,o,s,i,a){var d=arguments.length>5&&arguments[5]!==void 0?arguments[5]:{};if(this.services.utils&&this.services.utils.hasLoadedNamespace&&!this.services.utils.hasLoadedNamespace(o)){this.logger.warn('did not save key "'.concat(s,'" as the namespace "').concat(o,'" was not yet loaded'),"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}s==null||s===""||(this.backend&&this.backend.create&&this.backend.create(r,o,s,i,null,we({},d,{isUpdate:a})),!(!r||!r[0])&&this.store.addResource(r[0],o,s,i))}}]),t}(Kn);function Qj(){return{debug:!1,initImmediate:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,whitelist:!1,nonExplicitWhitelist:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!0,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:function(t){var n={};if(Fe(t[1])==="object"&&(n=t[1]),typeof t[1]=="string"&&(n.defaultValue=t[1]),typeof t[2]=="string"&&(n.tDescription=t[2]),Fe(t[2])==="object"||Fe(t[3])==="object"){var r=t[3]||t[2];Object.keys(r).forEach(function(o){n[o]=r[o]})}return n},interpolation:{escapeValue:!0,format:function(t,n,r,o){return t},prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!1}}}function Wb(e){return typeof e.ns=="string"&&(e.ns=[e.ns]),typeof e.fallbackLng=="string"&&(e.fallbackLng=[e.fallbackLng]),typeof e.fallbackNS=="string"&&(e.fallbackNS=[e.fallbackNS]),e.whitelist&&(e.whitelist&&e.whitelist.indexOf("cimode")<0&&(e.whitelist=e.whitelist.concat(["cimode"])),e.supportedLngs=e.whitelist),e.nonExplicitWhitelist&&(e.nonExplicitSupportedLngs=e.nonExplicitWhitelist),e.supportedLngs&&e.supportedLngs.indexOf("cimode")<0&&(e.supportedLngs=e.supportedLngs.concat(["cimode"])),e}function Sc(){}var Jj=function(e){Ci(t,e);function t(){var n,r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},o=arguments.length>1?arguments[1]:void 0;if(Yt(this,t),n=qo(this,Br(t).call(this)),Ic&&Kn.call(In(n)),n.options=Wb(r),n.services={},n.logger=_n,n.modules={external:[]},o&&!n.isInitialized&&!r.isClone){if(!n.options.initImmediate)return n.init(r,o),qo(n,In(n));setTimeout(function(){n.init(r,o)},0)}return n}return Kt(t,[{key:"init",value:function(){var r=this,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=arguments.length>1?arguments[1]:void 0;typeof o=="function"&&(s=o,o={}),o.whitelist&&!o.supportedLngs&&this.logger.deprecate("whitelist",'option "whitelist" will be renamed to "supportedLngs" in the next major - please make sure to rename this option asap.'),o.nonExplicitWhitelist&&!o.nonExplicitSupportedLngs&&this.logger.deprecate("whitelist",'options "nonExplicitWhitelist" will be renamed to "nonExplicitSupportedLngs" in the next major - please make sure to rename this option asap.'),this.options=we({},Qj(),this.options,Wb(o)),this.format=this.options.interpolation.format,s||(s=Sc);function i(h){return h?typeof h=="function"?new h:h:null}if(!this.options.isClone){this.modules.logger?_n.init(i(this.modules.logger),this.options):_n.init(null,this.options);var a=new jj(this.options);this.store=new Fj(this.options.resources,this.options);var d=this.services;d.logger=_n,d.resourceStore=this.store,d.languageUtils=a,d.pluralResolver=new Kj(a,{prepend:this.options.pluralSeparator,compatibilityJSON:this.options.compatibilityJSON,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),d.interpolator=new Xj(this.options),d.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},d.backendConnector=new Wj(i(this.modules.backend),d.resourceStore,d,this.options),d.backendConnector.on("*",function(h){for(var m=arguments.length,g=new Array(m>1?m-1:0),y=1;y<m;y++)g[y-1]=arguments[y];r.emit.apply(r,[h].concat(g))}),this.modules.languageDetector&&(d.languageDetector=i(this.modules.languageDetector),d.languageDetector.init(d,this.options.detection,this.options)),this.modules.i18nFormat&&(d.i18nFormat=i(this.modules.i18nFormat),d.i18nFormat.init&&d.i18nFormat.init(this)),this.translator=new $b(this.services,this.options),this.translator.on("*",function(h){for(var m=arguments.length,g=new Array(m>1?m-1:0),y=1;y<m;y++)g[y-1]=arguments[y];r.emit.apply(r,[h].concat(g))}),this.modules.external.forEach(function(h){h.init&&h.init(r)})}if(this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){var c=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);c.length>0&&c[0]!=="dev"&&(this.options.lng=c[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined");var u=["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"];u.forEach(function(h){r[h]=function(){var m;return(m=r.store)[h].apply(m,arguments)}});var p=["addResource","addResources","addResourceBundle","removeResourceBundle"];p.forEach(function(h){r[h]=function(){var m;return(m=r.store)[h].apply(m,arguments),r}});var l=Pi(),f=function(){var m=function(y,v){r.isInitialized&&r.logger.warn("init: i18next is already initialized. You should call init just once!"),r.isInitialized=!0,r.options.isClone||r.logger.log("initialized",r.options),r.emit("initialized",r.options),l.resolve(v),s(y,v)};if(r.languages&&r.options.compatibilityAPI!=="v1"&&!r.isInitialized)return m(null,r.t.bind(r));r.changeLanguage(r.options.lng,m)};return this.options.resources||!this.options.initImmediate?f():setTimeout(f,0),l}},{key:"loadResources",value:function(r){var o=this,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Sc,i=s,a=typeof r=="string"?r:this.language;if(typeof r=="function"&&(i=r),!this.options.resources||this.options.partialBundledLanguages){if(a&&a.toLowerCase()==="cimode")return i();var d=[],c=function(l){if(l){var f=o.services.languageUtils.toResolveHierarchy(l);f.forEach(function(h){d.indexOf(h)<0&&d.push(h)})}};if(a)c(a);else{var u=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);u.forEach(function(p){return c(p)})}this.options.preload&&this.options.preload.forEach(function(p){return c(p)}),this.services.backendConnector.load(d,this.options.ns,i)}else i(null)}},{key:"reloadResources",value:function(r,o,s){var i=Pi();return r||(r=this.languages),o||(o=this.options.ns),s||(s=Sc),this.services.backendConnector.reload(r,o,function(a){i.resolve(),s(a)}),i}},{key:"use",value:function(r){if(!r)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!r.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return r.type==="backend"&&(this.modules.backend=r),(r.type==="logger"||r.log&&r.warn&&r.error)&&(this.modules.logger=r),r.type==="languageDetector"&&(this.modules.languageDetector=r),r.type==="i18nFormat"&&(this.modules.i18nFormat=r),r.type==="postProcessor"&&Jb.addPostProcessor(r),r.type==="3rdParty"&&this.modules.external.push(r),this}},{key:"changeLanguage",value:function(r,o){var s=this;this.isLanguageChangingTo=r;var i=Pi();this.emit("languageChanging",r);var a=function(u,p){p?(s.language=p,s.languages=s.services.languageUtils.toResolveHierarchy(p),s.translator.changeLanguage(p),s.isLanguageChangingTo=void 0,s.emit("languageChanged",p),s.logger.log("languageChanged",p)):s.isLanguageChangingTo=void 0,i.resolve(function(){return s.t.apply(s,arguments)}),o&&o(u,function(){return s.t.apply(s,arguments)})},d=function(u){var p=typeof u=="string"?u:s.services.languageUtils.getBestMatchFromCodes(u);p&&(s.language||(s.language=p,s.languages=s.services.languageUtils.toResolveHierarchy(p)),s.translator.language||s.translator.changeLanguage(p),s.services.languageDetector&&s.services.languageDetector.cacheUserLanguage(p)),s.loadResources(p,function(l){a(l,p)})};return!r&&this.services.languageDetector&&!this.services.languageDetector.async?d(this.services.languageDetector.detect()):!r&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect(d):d(r),i}},{key:"getFixedT",value:function(r,o){var s=this,i=function a(d,c){var u;if(Fe(c)!=="object"){for(var p=arguments.length,l=new Array(p>2?p-2:0),f=2;f<p;f++)l[f-2]=arguments[f];u=s.options.overloadTranslationOptionHandler([d,c].concat(l))}else u=we({},c);return u.lng=u.lng||a.lng,u.lngs=u.lngs||a.lngs,u.ns=u.ns||a.ns,s.t(d,u)};return typeof r=="string"?i.lng=r:i.lngs=r,i.ns=o,i}},{key:"t",value:function(){var r;return this.translator&&(r=this.translator).translate.apply(r,arguments)}},{key:"exists",value:function(){var r;return this.translator&&(r=this.translator).exists.apply(r,arguments)}},{key:"setDefaultNamespace",value:function(r){this.options.defaultNS=r}},{key:"hasLoadedNamespace",value:function(r){var o=this,s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;var i=this.languages[0],a=this.options?this.options.fallbackLng:!1,d=this.languages[this.languages.length-1];if(i.toLowerCase()==="cimode")return!0;var c=function(l,f){var h=o.services.backendConnector.state["".concat(l,"|").concat(f)];return h===-1||h===2};if(s.precheck){var u=s.precheck(this,c);if(u!==void 0)return u}return!!(this.hasResourceBundle(i,r)||!this.services.backendConnector.backend||c(i,r)&&(!a||c(d,r)))}},{key:"loadNamespaces",value:function(r,o){var s=this,i=Pi();return this.options.ns?(typeof r=="string"&&(r=[r]),r.forEach(function(a){s.options.ns.indexOf(a)<0&&s.options.ns.push(a)}),this.loadResources(function(a){i.resolve(),o&&o(a)}),i):(o&&o(),Promise.resolve())}},{key:"loadLanguages",value:function(r,o){var s=Pi();typeof r=="string"&&(r=[r]);var i=this.options.preload||[],a=r.filter(function(d){return i.indexOf(d)<0});return a.length?(this.options.preload=i.concat(a),this.loadResources(function(d){s.resolve(),o&&o(d)}),s):(o&&o(),Promise.resolve())}},{key:"dir",value:function(r){if(r||(r=this.languages&&this.languages.length>0?this.languages[0]:this.language),!r)return"rtl";var o=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam"];return o.indexOf(this.services.languageUtils.getLanguagePartFromCode(r))>=0?"rtl":"ltr"}},{key:"createInstance",value:function(){var r=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},o=arguments.length>1?arguments[1]:void 0;return new t(r,o)}},{key:"cloneInstance",value:function(){var r=this,o=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Sc,i=we({},this.options,o,{isClone:!0}),a=new t(i),d=["store","services","language"];return d.forEach(function(c){a[c]=r[c]}),a.services=we({},this.services),a.services.utils={hasLoadedNamespace:a.hasLoadedNamespace.bind(a)},a.translator=new $b(a.services,a.options),a.translator.on("*",function(c){for(var u=arguments.length,p=new Array(u>1?u-1:0),l=1;l<u;l++)p[l-1]=arguments[l];a.emit.apply(a,[c].concat(p))}),a.init(i,s),a.translator.options=a.options,a.translator.backendConnector.services.utils={hasLoadedNamespace:a.hasLoadedNamespace.bind(a)},a}}]),t}(Kn),Zj=new Jj,Zb=Zj;var xI=ed(PI(),1),{__extends:xi,__assign:V,__rest:TI,__decorate:gCe,__param:yCe,__esDecorate:ACe,__runInitializers:vCe,__propKey:SCe,__setFunctionName:bCe,__metadata:ICe,__awaiter:_Ce,__generator:RCe,__exportStar:ECe,__createBinding:CCe,__values:PCe,__read:xCe,__spread:TCe,__spreadArrays:NCe,__spreadArray:Cc,__await:wCe,__asyncGenerator:OCe,__asyncDelegator:DCe,__asyncValues:kCe,__makeTemplateObject:MCe,__importStar:LCe,__importDefault:BCe,__classPrivateFieldGet:GCe,__classPrivateFieldSet:UCe,__classPrivateFieldIn:zCe,__addDisposableResource:qCe,__disposeResources:FCe}=xI.default;var U;(function(e){e[e.EXPECT_ARGUMENT_CLOSING_BRACE=1]="EXPECT_ARGUMENT_CLOSING_BRACE",e[e.EMPTY_ARGUMENT=2]="EMPTY_ARGUMENT",e[e.MALFORMED_ARGUMENT=3]="MALFORMED_ARGUMENT",e[e.EXPECT_ARGUMENT_TYPE=4]="EXPECT_ARGUMENT_TYPE",e[e.INVALID_ARGUMENT_TYPE=5]="INVALID_ARGUMENT_TYPE",e[e.EXPECT_ARGUMENT_STYLE=6]="EXPECT_ARGUMENT_STYLE",e[e.INVALID_NUMBER_SKELETON=7]="INVALID_NUMBER_SKELETON",e[e.INVALID_DATE_TIME_SKELETON=8]="INVALID_DATE_TIME_SKELETON",e[e.EXPECT_NUMBER_SKELETON=9]="EXPECT_NUMBER_SKELETON",e[e.EXPECT_DATE_TIME_SKELETON=10]="EXPECT_DATE_TIME_SKELETON",e[e.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE=11]="UNCLOSED_QUOTE_IN_ARGUMENT_STYLE",e[e.EXPECT_SELECT_ARGUMENT_OPTIONS=12]="EXPECT_SELECT_ARGUMENT_OPTIONS",e[e.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE=13]="EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE",e[e.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE=14]="INVALID_PLURAL_ARGUMENT_OFFSET_VALUE",e[e.EXPECT_SELECT_ARGUMENT_SELECTOR=15]="EXPECT_SELECT_ARGUMENT_SELECTOR",e[e.EXPECT_PLURAL_ARGUMENT_SELECTOR=16]="EXPECT_PLURAL_ARGUMENT_SELECTOR",e[e.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT=17]="EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT",e[e.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT=18]="EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT",e[e.INVALID_PLURAL_ARGUMENT_SELECTOR=19]="INVALID_PLURAL_ARGUMENT_SELECTOR",e[e.DUPLICATE_PLURAL_ARGUMENT_SELECTOR=20]="DUPLICATE_PLURAL_ARGUMENT_SELECTOR",e[e.DUPLICATE_SELECT_ARGUMENT_SELECTOR=21]="DUPLICATE_SELECT_ARGUMENT_SELECTOR",e[e.MISSING_OTHER_CLAUSE=22]="MISSING_OTHER_CLAUSE",e[e.INVALID_TAG=23]="INVALID_TAG",e[e.INVALID_TAG_NAME=25]="INVALID_TAG_NAME",e[e.UNMATCHED_CLOSING_TAG=26]="UNMATCHED_CLOSING_TAG",e[e.UNCLOSED_TAG=27]="UNCLOSED_TAG"})(U||(U={}));var ce;(function(e){e[e.literal=0]="literal",e[e.argument=1]="argument",e[e.number=2]="number",e[e.date=3]="date",e[e.time=4]="time",e[e.select=5]="select",e[e.plural=6]="plural",e[e.pound=7]="pound",e[e.tag=8]="tag"})(ce||(ce={}));var Gr;(function(e){e[e.number=0]="number",e[e.dateTime=1]="dateTime"})(Gr||(Gr={}));function Cf(e){return e.type===ce.literal}function NI(e){return e.type===ce.argument}function Pc(e){return e.type===ce.number}function xc(e){return e.type===ce.date}function Tc(e){return e.type===ce.time}function Nc(e){return e.type===ce.select}function wc(e){return e.type===ce.plural}function wI(e){return e.type===ce.pound}function Oc(e){return e.type===ce.tag}function Dc(e){return!!(e&&typeof e=="object"&&e.type===Gr.number)}function Ti(e){return!!(e&&typeof e=="object"&&e.type===Gr.dateTime)}var Pf=/[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;var eV=/(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;function OI(e){var t={};return e.replace(eV,function(n){var r=n.length;switch(n[0]){case"G":t.era=r===4?"long":r===5?"narrow":"short";break;case"y":t.year=r===2?"2-digit":"numeric";break;case"Y":case"u":case"U":case"r":throw new RangeError("`Y/u/U/r` (year) patterns are not supported, use `y` instead");case"q":case"Q":throw new RangeError("`q/Q` (quarter) patterns are not supported");case"M":case"L":t.month=["numeric","2-digit","short","long","narrow"][r-1];break;case"w":case"W":throw new RangeError("`w/W` (week) patterns are not supported");case"d":t.day=["numeric","2-digit"][r-1];break;case"D":case"F":case"g":throw new RangeError("`D/F/g` (day) patterns are not supported, use `d` instead");case"E":t.weekday=r===4?"short":r===5?"narrow":"short";break;case"e":if(r<4)throw new RangeError("`e..eee` (weekday) patterns are not supported");t.weekday=["short","long","narrow","short"][r-4];break;case"c":if(r<4)throw new RangeError("`c..ccc` (weekday) patterns are not supported");t.weekday=["short","long","narrow","short"][r-4];break;case"a":t.hour12=!0;break;case"b":case"B":throw new RangeError("`b/B` (period) patterns are not supported, use `a` instead");case"h":t.hourCycle="h12",t.hour=["numeric","2-digit"][r-1];break;case"H":t.hourCycle="h23",t.hour=["numeric","2-digit"][r-1];break;case"K":t.hourCycle="h11",t.hour=["numeric","2-digit"][r-1];break;case"k":t.hourCycle="h24",t.hour=["numeric","2-digit"][r-1];break;case"j":case"J":case"C":throw new RangeError("`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead");case"m":t.minute=["numeric","2-digit"][r-1];break;case"s":t.second=["numeric","2-digit"][r-1];break;case"S":case"A":throw new RangeError("`S/A` (second) patterns are not supported, use `s` instead");case"z":t.timeZoneName=r<4?"short":"long";break;case"Z":case"O":case"v":case"V":case"X":case"x":throw new RangeError("`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead")}return""}),t}var DI=/[\t-\r \x85\u200E\u200F\u2028\u2029]/i;function BI(e){if(e.length===0)throw new Error("Number skeleton cannot be empty");for(var t=e.split(DI).filter(function(l){return l.length>0}),n=[],r=0,o=t;r<o.length;r++){var s=o[r],i=s.split("/");if(i.length===0)throw new Error("Invalid number skeleton");for(var a=i[0],d=i.slice(1),c=0,u=d;c<u.length;c++){var p=u[c];if(p.length===0)throw new Error("Invalid number skeleton")}n.push({stem:a,options:d})}return n}function tV(e){return e.replace(/^(.*?)-/,"")}var kI=/^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g,GI=/^(@+)?(\+|#+)?[rs]?$/g,nV=/(\*)(0+)|(#+)(0+)|(0+)/g,UI=/^(0+)$/;function MI(e){var t={};return e[e.length-1]==="r"?t.roundingPriority="morePrecision":e[e.length-1]==="s"&&(t.roundingPriority="lessPrecision"),e.replace(GI,function(n,r,o){return typeof o!="string"?(t.minimumSignificantDigits=r.length,t.maximumSignificantDigits=r.length):o==="+"?t.minimumSignificantDigits=r.length:r[0]==="#"?t.maximumSignificantDigits=r.length:(t.minimumSignificantDigits=r.length,t.maximumSignificantDigits=r.length+(typeof o=="string"?o.length:0)),""}),t}function zI(e){switch(e){case"sign-auto":return{signDisplay:"auto"};case"sign-accounting":case"()":return{currencySign:"accounting"};case"sign-always":case"+!":return{signDisplay:"always"};case"sign-accounting-always":case"()!":return{signDisplay:"always",currencySign:"accounting"};case"sign-except-zero":case"+?":return{signDisplay:"exceptZero"};case"sign-accounting-except-zero":case"()?":return{signDisplay:"exceptZero",currencySign:"accounting"};case"sign-never":case"+_":return{signDisplay:"never"}}}function rV(e){var t;if(e[0]==="E"&&e[1]==="E"?(t={notation:"engineering"},e=e.slice(2)):e[0]==="E"&&(t={notation:"scientific"},e=e.slice(1)),t){var n=e.slice(0,2);if(n==="+!"?(t.signDisplay="always",e=e.slice(2)):n==="+?"&&(t.signDisplay="exceptZero",e=e.slice(2)),!UI.test(e))throw new Error("Malformed concise eng/scientific notation");t.minimumIntegerDigits=e.length}return t}function LI(e){var t={},n=zI(e);return n||t}function qI(e){for(var t={},n=0,r=e;n<r.length;n++){var o=r[n];switch(o.stem){case"percent":case"%":t.style="percent";continue;case"%x100":t.style="percent",t.scale=100;continue;case"currency":t.style="currency",t.currency=o.options[0];continue;case"group-off":case",_":t.useGrouping=!1;continue;case"precision-integer":case".":t.maximumFractionDigits=0;continue;case"measure-unit":case"unit":t.style="unit",t.unit=tV(o.options[0]);continue;case"compact-short":case"K":t.notation="compact",t.compactDisplay="short";continue;case"compact-long":case"KK":t.notation="compact",t.compactDisplay="long";continue;case"scientific":t=V(V(V({},t),{notation:"scientific"}),o.options.reduce(function(d,c){return V(V({},d),LI(c))},{}));continue;case"engineering":t=V(V(V({},t),{notation:"engineering"}),o.options.reduce(function(d,c){return V(V({},d),LI(c))},{}));continue;case"notation-simple":t.notation="standard";continue;case"unit-width-narrow":t.currencyDisplay="narrowSymbol",t.unitDisplay="narrow";continue;case"unit-width-short":t.currencyDisplay="code",t.unitDisplay="short";continue;case"unit-width-full-name":t.currencyDisplay="name",t.unitDisplay="long";continue;case"unit-width-iso-code":t.currencyDisplay="symbol";continue;case"scale":t.scale=parseFloat(o.options[0]);continue;case"integer-width":if(o.options.length>1)throw new RangeError("integer-width stems only accept a single optional option");o.options[0].replace(nV,function(d,c,u,p,l,f){if(c)t.minimumIntegerDigits=u.length;else{if(p&&l)throw new Error("We currently do not support maximum integer digits");if(f)throw new Error("We currently do not support exact integer digits")}return""});continue}if(UI.test(o.stem)){t.minimumIntegerDigits=o.stem.length;continue}if(kI.test(o.stem)){if(o.options.length>1)throw new RangeError("Fraction-precision stems only accept a single optional option");o.stem.replace(kI,function(d,c,u,p,l,f){return u==="*"?t.minimumFractionDigits=c.length:p&&p[0]==="#"?t.maximumFractionDigits=p.length:l&&f?(t.minimumFractionDigits=l.length,t.maximumFractionDigits=l.length+f.length):(t.minimumFractionDigits=c.length,t.maximumFractionDigits=c.length),""});var s=o.options[0];s==="w"?t=V(V({},t),{trailingZeroDisplay:"stripIfInteger"}):s&&(t=V(V({},t),MI(s)));continue}if(GI.test(o.stem)){t=V(V({},t),MI(o.stem));continue}var i=zI(o.stem);i&&(t=V(V({},t),i));var a=rV(o.stem);a&&(t=V(V({},t),a))}return t}var Ni={"001":["H","h"],AC:["H","h","hb","hB"],AD:["H","hB"],AE:["h","hB","hb","H"],AF:["H","hb","hB","h"],AG:["h","hb","H","hB"],AI:["H","h","hb","hB"],AL:["h","H","hB"],AM:["H","hB"],AO:["H","hB"],AR:["H","h","hB","hb"],AS:["h","H"],AT:["H","hB"],AU:["h","hb","H","hB"],AW:["H","hB"],AX:["H"],AZ:["H","hB","h"],BA:["H","hB","h"],BB:["h","hb","H","hB"],BD:["h","hB","H"],BE:["H","hB"],BF:["H","hB"],BG:["H","hB","h"],BH:["h","hB","hb","H"],BJ:["H","hB"],BL:["H","hB"],BM:["h","hb","H","hB"],BN:["hb","hB","h","H"],BO:["H","hB","h","hb"],BQ:["H"],BR:["H","hB"],BS:["h","hb","H","hB"],BT:["h","H"],BW:["H","h","hb","hB"],BZ:["H","h","hb","hB"],CA:["h","hb","H","hB"],CC:["H","h","hb","hB"],CD:["hB","H"],CF:["H","h","hB"],CG:["H","hB"],CH:["H","hB","h"],CI:["H","hB"],CK:["H","h","hb","hB"],CL:["H","h","hB","hb"],CM:["H","h","hB"],CN:["H","hB","hb","h"],CO:["h","H","hB","hb"],CP:["H"],CR:["H","h","hB","hb"],CU:["H","h","hB","hb"],CV:["H","hB"],CX:["H","h","hb","hB"],CY:["h","H","hb","hB"],CZ:["H"],DE:["H","hB"],DG:["H","h","hb","hB"],DJ:["h","H"],DK:["H"],DM:["h","hb","H","hB"],DO:["h","H","hB","hb"],DZ:["h","hB","hb","H"],EA:["H","h","hB","hb"],EC:["H","hB","h","hb"],EE:["H","hB"],EG:["h","hB","hb","H"],EH:["h","hB","hb","H"],ER:["h","H"],ES:["H","hB","h","hb"],ET:["hB","hb","h","H"],FI:["H"],FJ:["h","hb","H","hB"],FK:["H","h","hb","hB"],FM:["h","hb","H","hB"],FR:["H","hB"],GA:["H","hB"],GB:["H","h","hb","hB"],GD:["h","hb","H","hB"],GE:["H","hB","h"],GF:["H","hB"],GG:["H","h","hb","hB"],GH:["h","H"],GI:["H","h","hb","hB"],GM:["h","hb","H","hB"],GN:["H","hB"],GP:["H","hB"],GQ:["H","hB","h","hb"],GR:["h","H","hb","hB"],GT:["H","h","hB","hb"],GU:["h","hb","H","hB"],GW:["H","hB"],GY:["h","hb","H","hB"],HK:["h","hB","hb","H"],HN:["H","h","hB","hb"],HR:["H","hB"],IC:["H","h","hB","hb"],ID:["H"],IE:["H","h","hb","hB"],IL:["H","hB"],IM:["H","h","hb","hB"],IN:["h","H"],IO:["H","h","hb","hB"],IQ:["h","hB","hb","H"],IR:["hB","H"],IS:["H"],IT:["H","hB"],JE:["H","h","hb","hB"],JM:["h","hb","H","hB"],JO:["h","hB","hb","H"],JP:["H","h","K"],KE:["hB","hb","H","h"],KG:["H","h","hB","hb"],KH:["hB","h","H","hb"],KI:["h","hb","H","hB"],KM:["H","h","hB","hb"],KN:["h","hb","H","hB"],KP:["h","H","hB","hb"],KR:["h","H","hB","hb"],KW:["h","hB","hb","H"],KY:["h","hb","H","hB"],KZ:["H","hB"],LA:["H","hb","hB","h"],LB:["h","hB","hb","H"],LC:["h","hb","H","hB"],LI:["H","hB","h"],LK:["H","h","hB","hb"],LR:["h","hb","H","hB"],LS:["h","H"],LT:["H","h","hb","hB"],LU:["H","h","hB"],LV:["H","hB","hb","h"],LY:["h","hB","hb","H"],MA:["H","h","hB","hb"],MC:["H","hB"],MD:["H","hB"],ME:["H","hB","h"],MF:["H","hB"],MH:["h","hb","H","hB"],MK:["H","h","hb","hB"],ML:["H"],MM:["hB","hb","H","h"],MN:["H","h","hb","hB"],MO:["h","hB","hb","H"],MP:["h","hb","H","hB"],MQ:["H","hB"],MR:["h","hB","hb","H"],MS:["H","h","hb","hB"],MW:["h","hb","H","hB"],MX:["H","h","hB","hb"],MY:["hb","hB","h","H"],MZ:["H","hB"],NA:["h","H","hB","hb"],NC:["H","hB"],NE:["H"],NF:["H","h","hb","hB"],NG:["H","h","hb","hB"],NI:["H","h","hB","hb"],NL:["H","hB"],NP:["H","h","hB"],NR:["H","h","hb","hB"],NU:["H","h","hb","hB"],NZ:["h","hb","H","hB"],OM:["h","hB","hb","H"],PA:["h","H","hB","hb"],PE:["H","hB","h","hb"],PF:["H","h","hB"],PG:["h","H"],PH:["h","hB","hb","H"],PK:["h","hB","H"],PM:["H","hB"],PN:["H","h","hb","hB"],PR:["h","H","hB","hb"],PS:["h","hB","hb","H"],PT:["H","hB"],PW:["h","H"],PY:["H","h","hB","hb"],QA:["h","hB","hb","H"],RE:["H","hB"],RO:["H","hB"],RS:["H","hB","h"],RU:["H"],SA:["h","hB","hb","H"],SB:["h","hb","H","hB"],SC:["H","h","hB"],SD:["h","hB","hb","H"],SE:["H"],SG:["h","hb","H","hB"],SH:["H","h","hb","hB"],SI:["H","hB"],SJ:["H"],SK:["H"],SL:["h","hb","H","hB"],SM:["H","h","hB"],SN:["H","h","hB"],SO:["h","H"],SR:["H","hB"],SS:["h","hb","H","hB"],ST:["H","hB"],SV:["H","h","hB","hb"],SX:["H","h","hb","hB"],SY:["h","hB","hb","H"],SZ:["h","hb","H","hB"],TA:["H","h","hb","hB"],TC:["h","hb","H","hB"],TD:["h","H","hB"],TF:["H","h","hB"],TG:["H","hB"],TL:["H","hB","hb","h"],TN:["h","hB","hb","H"],TO:["h","H"],TR:["H","hB"],TT:["h","hb","H","hB"],TW:["hB","hb","h","H"],TZ:["hB","hb","H","h"],UA:["H","hB","h"],UG:["hB","hb","H","h"],UM:["h","hb","H","hB"],US:["h","hb","H","hB"],UY:["H","h","hB","hb"],UZ:["H","hB","h"],VA:["H","h","hB"],VC:["h","hb","H","hB"],VE:["h","H","hB","hb"],VG:["h","hb","H","hB"],VI:["h","hb","H","hB"],VU:["h","H"],WF:["H","hB"],WS:["h","H"],XK:["H","hB","h"],YE:["h","hB","hb","H"],YT:["H","hB"],ZA:["H","h","hb","hB"],ZM:["h","hb","H","hB"],"af-ZA":["H","h","hB","hb"],"ar-001":["h","hB","hb","H"],"ca-ES":["H","h","hB"],"en-001":["h","hb","H","hB"],"es-BO":["H","h","hB","hb"],"es-BR":["H","h","hB","hb"],"es-EC":["H","h","hB","hb"],"es-ES":["H","h","hB","hb"],"es-GQ":["H","h","hB","hb"],"es-PE":["H","h","hB","hb"],"fr-CA":["H","h","hB"],"gl-ES":["H","h","hB"],"gu-IN":["hB","hb","h","H"],"hi-IN":["hB","h","H"],"it-CH":["H","h","hB"],"it-IT":["H","h","hB"],"kn-IN":["hB","h","H"],"ml-IN":["hB","h","H"],"mr-IN":["hB","hb","h","H"],"pa-IN":["hB","hb","h","H"],"ta-IN":["hB","h","hb","H"],"te-IN":["hB","h","H"],"zu-ZA":["H","hB","hb","h"]};function FI(e,t){for(var n="",r=0;r<e.length;r++){var o=e.charAt(r);if(o==="j"){for(var s=0;r+1<e.length&&e.charAt(r+1)===o;)s++,r++;var i=1+(s&1),a=s<2?1:3+(s>>1),d="a",c=oV(t);for((c=="H"||c=="k")&&(a=0);a-- >0;)n+=d;for(;i-- >0;)n=c+n}else o==="J"?n+="H":n+=o}return n}function oV(e){var t=e.hourCycle;if(t===void 0&&e.hourCycles&&e.hourCycles.length&&(t=e.hourCycles[0]),t)switch(t){case"h24":return"k";case"h23":return"H";case"h12":return"h";case"h11":return"K";default:throw new Error("Invalid hourCycle")}var n=e.language,r;n!=="root"&&(r=e.maximize().region);var o=Ni[r||""]||Ni[n||""]||Ni["".concat(n,"-001")]||Ni["001"];return o[0]}var xf,sV=new RegExp("^".concat(Pf.source,"*")),iV=new RegExp("".concat(Pf.source,"*$"));function H(e,t){return{start:e,end:t}}var aV=!!String.prototype.startsWith&&"_a".startsWith("a",1),dV=!!String.fromCodePoint,cV=!!Object.fromEntries,uV=!!String.prototype.codePointAt,pV=!!String.prototype.trimStart,lV=!!String.prototype.trimEnd,fV=!!Number.isSafeInteger,mV=fV?Number.isSafeInteger:function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e&&Math.abs(e)<=9007199254740991},Nf=!0;try{jI=KI("([^\\p{White_Space}\\p{Pattern_Syntax}]*)","yu"),Nf=((xf=jI.exec("a"))===null||xf===void 0?void 0:xf[0])==="a"}catch{Nf=!1}var jI,VI=aV?function(t,n,r){return t.startsWith(n,r)}:function(t,n,r){return t.slice(r,r+n.length)===n},wf=dV?String.fromCodePoint:function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];for(var r="",o=t.length,s=0,i;o>s;){if(i=t[s++],i>1114111)throw RangeError(i+" is not a valid code point");r+=i<65536?String.fromCharCode(i):String.fromCharCode(((i-=65536)>>10)+55296,i%1024+56320)}return r},HI=cV?Object.fromEntries:function(t){for(var n={},r=0,o=t;r<o.length;r++){var s=o[r],i=s[0],a=s[1];n[i]=a}return n},YI=uV?function(t,n){return t.codePointAt(n)}:function(t,n){var r=t.length;if(!(n<0||n>=r)){var o=t.charCodeAt(n),s;return o<55296||o>56319||n+1===r||(s=t.charCodeAt(n+1))<56320||s>57343?o:(o-55296<<10)+(s-56320)+65536}},hV=pV?function(t){return t.trimStart()}:function(t){return t.replace(sV,"")},gV=lV?function(t){return t.trimEnd()}:function(t){return t.replace(iV,"")};function KI(e,t){return new RegExp(e,t)}var Of;Nf?(Tf=KI("([^\\p{White_Space}\\p{Pattern_Syntax}]*)","yu"),Of=function(t,n){var r;Tf.lastIndex=n;var o=Tf.exec(t);return(r=o[1])!==null&&r!==void 0?r:""}):Of=function(t,n){for(var r=[];;){var o=YI(t,n);if(o===void 0||$I(o)||vV(o))break;r.push(o),n+=o>=65536?2:1}return wf.apply(void 0,r)};var Tf,XI=function(){function e(t,n){n===void 0&&(n={}),this.message=t,this.position={offset:0,line:1,column:1},this.ignoreTag=!!n.ignoreTag,this.locale=n.locale,this.requiresOtherClause=!!n.requiresOtherClause,this.shouldParseSkeletons=!!n.shouldParseSkeletons}return e.prototype.parse=function(){if(this.offset()!==0)throw Error("parser can only be used once");return this.parseMessage(0,"",!1)},e.prototype.parseMessage=function(t,n,r){for(var o=[];!this.isEOF();){var s=this.char();if(s===123){var i=this.parseArgument(t,r);if(i.err)return i;o.push(i.val)}else{if(s===125&&t>0)break;if(s===35&&(n==="plural"||n==="selectordinal")){var a=this.clonePosition();this.bump(),o.push({type:ce.pound,location:H(a,this.clonePosition())})}else if(s===60&&!this.ignoreTag&&this.peek()===47){if(r)break;return this.error(U.UNMATCHED_CLOSING_TAG,H(this.clonePosition(),this.clonePosition()))}else if(s===60&&!this.ignoreTag&&Df(this.peek()||0)){var i=this.parseTag(t,n);if(i.err)return i;o.push(i.val)}else{var i=this.parseLiteral(t,n);if(i.err)return i;o.push(i.val)}}}return{val:o,err:null}},e.prototype.parseTag=function(t,n){var r=this.clonePosition();this.bump();var o=this.parseTagName();if(this.bumpSpace(),this.bumpIf("/>"))return{val:{type:ce.literal,value:"<".concat(o,"/>"),location:H(r,this.clonePosition())},err:null};if(this.bumpIf(">")){var s=this.parseMessage(t+1,n,!0);if(s.err)return s;var i=s.val,a=this.clonePosition();if(this.bumpIf("</")){if(this.isEOF()||!Df(this.char()))return this.error(U.INVALID_TAG,H(a,this.clonePosition()));var d=this.clonePosition(),c=this.parseTagName();return o!==c?this.error(U.UNMATCHED_CLOSING_TAG,H(d,this.clonePosition())):(this.bumpSpace(),this.bumpIf(">")?{val:{type:ce.tag,value:o,children:i,location:H(r,this.clonePosition())},err:null}:this.error(U.INVALID_TAG,H(a,this.clonePosition())))}else return this.error(U.UNCLOSED_TAG,H(r,this.clonePosition()))}else return this.error(U.INVALID_TAG,H(r,this.clonePosition()))},e.prototype.parseTagName=function(){var t=this.offset();for(this.bump();!this.isEOF()&&AV(this.char());)this.bump();return this.message.slice(t,this.offset())},e.prototype.parseLiteral=function(t,n){for(var r=this.clonePosition(),o="";;){var s=this.tryParseQuote(n);if(s){o+=s;continue}var i=this.tryParseUnquoted(t,n);if(i){o+=i;continue}var a=this.tryParseLeftAngleBracket();if(a){o+=a;continue}break}var d=H(r,this.clonePosition());return{val:{type:ce.literal,value:o,location:d},err:null}},e.prototype.tryParseLeftAngleBracket=function(){return!this.isEOF()&&this.char()===60&&(this.ignoreTag||!yV(this.peek()||0))?(this.bump(),"<"):null},e.prototype.tryParseQuote=function(t){if(this.isEOF()||this.char()!==39)return null;switch(this.peek()){case 39:return this.bump(),this.bump(),"'";case 123:case 60:case 62:case 125:break;case 35:if(t==="plural"||t==="selectordinal")break;return null;default:return null}this.bump();var n=[this.char()];for(this.bump();!this.isEOF();){var r=this.char();if(r===39)if(this.peek()===39)n.push(39),this.bump();else{this.bump();break}else n.push(r);this.bump()}return wf.apply(void 0,n)},e.prototype.tryParseUnquoted=function(t,n){if(this.isEOF())return null;var r=this.char();return r===60||r===123||r===35&&(n==="plural"||n==="selectordinal")||r===125&&t>0?null:(this.bump(),wf(r))},e.prototype.parseArgument=function(t,n){var r=this.clonePosition();if(this.bump(),this.bumpSpace(),this.isEOF())return this.error(U.EXPECT_ARGUMENT_CLOSING_BRACE,H(r,this.clonePosition()));if(this.char()===125)return this.bump(),this.error(U.EMPTY_ARGUMENT,H(r,this.clonePosition()));var o=this.parseIdentifierIfPossible().value;if(!o)return this.error(U.MALFORMED_ARGUMENT,H(r,this.clonePosition()));if(this.bumpSpace(),this.isEOF())return this.error(U.EXPECT_ARGUMENT_CLOSING_BRACE,H(r,this.clonePosition()));switch(this.char()){case 125:return this.bump(),{val:{type:ce.argument,value:o,location:H(r,this.clonePosition())},err:null};case 44:return this.bump(),this.bumpSpace(),this.isEOF()?this.error(U.EXPECT_ARGUMENT_CLOSING_BRACE,H(r,this.clonePosition())):this.parseArgumentOptions(t,n,o,r);default:return this.error(U.MALFORMED_ARGUMENT,H(r,this.clonePosition()))}},e.prototype.parseIdentifierIfPossible=function(){var t=this.clonePosition(),n=this.offset(),r=Of(this.message,n),o=n+r.length;this.bumpTo(o);var s=this.clonePosition(),i=H(t,s);return{value:r,location:i}},e.prototype.parseArgumentOptions=function(t,n,r,o){var s,i=this.clonePosition(),a=this.parseIdentifierIfPossible().value,d=this.clonePosition();switch(a){case"":return this.error(U.EXPECT_ARGUMENT_TYPE,H(i,d));case"number":case"date":case"time":{this.bumpSpace();var c=null;if(this.bumpIf(",")){this.bumpSpace();var u=this.clonePosition(),p=this.parseSimpleArgStyleIfPossible();if(p.err)return p;var l=gV(p.val);if(l.length===0)return this.error(U.EXPECT_ARGUMENT_STYLE,H(this.clonePosition(),this.clonePosition()));var f=H(u,this.clonePosition());c={style:l,styleLocation:f}}var h=this.tryParseArgumentClose(o);if(h.err)return h;var m=H(o,this.clonePosition());if(c&&VI(c==null?void 0:c.style,"::",0)){var g=hV(c.style.slice(2));if(a==="number"){var p=this.parseNumberSkeletonFromString(g,c.styleLocation);return p.err?p:{val:{type:ce.number,value:r,location:m,style:p.val},err:null}}else{if(g.length===0)return this.error(U.EXPECT_DATE_TIME_SKELETON,m);var y=g;this.locale&&(y=FI(g,this.locale));var l={type:Gr.dateTime,pattern:y,location:c.styleLocation,parsedOptions:this.shouldParseSkeletons?OI(y):{}},v=a==="date"?ce.date:ce.time;return{val:{type:v,value:r,location:m,style:l},err:null}}}return{val:{type:a==="number"?ce.number:a==="date"?ce.date:ce.time,value:r,location:m,style:(s=c==null?void 0:c.style)!==null&&s!==void 0?s:null},err:null}}case"plural":case"selectordinal":case"select":{var S=this.clonePosition();if(this.bumpSpace(),!this.bumpIf(","))return this.error(U.EXPECT_SELECT_ARGUMENT_OPTIONS,H(S,V({},S)));this.bumpSpace();var b=this.parseIdentifierIfPossible(),I=0;if(a!=="select"&&b.value==="offset"){if(!this.bumpIf(":"))return this.error(U.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE,H(this.clonePosition(),this.clonePosition()));this.bumpSpace();var p=this.tryParseDecimalInteger(U.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE,U.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE);if(p.err)return p;this.bumpSpace(),b=this.parseIdentifierIfPossible(),I=p.val}var N=this.tryParsePluralOrSelectOptions(t,a,n,b);if(N.err)return N;var h=this.tryParseArgumentClose(o);if(h.err)return h;var w=H(o,this.clonePosition());return a==="select"?{val:{type:ce.select,value:r,options:HI(N.val),location:w},err:null}:{val:{type:ce.plural,value:r,options:HI(N.val),offset:I,pluralType:a==="plural"?"cardinal":"ordinal",location:w},err:null}}default:return this.error(U.INVALID_ARGUMENT_TYPE,H(i,d))}},e.prototype.tryParseArgumentClose=function(t){return this.isEOF()||this.char()!==125?this.error(U.EXPECT_ARGUMENT_CLOSING_BRACE,H(t,this.clonePosition())):(this.bump(),{val:!0,err:null})},e.prototype.parseSimpleArgStyleIfPossible=function(){for(var t=0,n=this.clonePosition();!this.isEOF();){var r=this.char();switch(r){case 39:{this.bump();var o=this.clonePosition();if(!this.bumpUntil("'"))return this.error(U.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE,H(o,this.clonePosition()));this.bump();break}case 123:{t+=1,this.bump();break}case 125:{if(t>0)t-=1;else return{val:this.message.slice(n.offset,this.offset()),err:null};break}default:this.bump();break}}return{val:this.message.slice(n.offset,this.offset()),err:null}},e.prototype.parseNumberSkeletonFromString=function(t,n){var r=[];try{r=BI(t)}catch{return this.error(U.INVALID_NUMBER_SKELETON,n)}return{val:{type:Gr.number,tokens:r,location:n,parsedOptions:this.shouldParseSkeletons?qI(r):{}},err:null}},e.prototype.tryParsePluralOrSelectOptions=function(t,n,r,o){for(var s,i=!1,a=[],d=new Set,c=o.value,u=o.location;;){if(c.length===0){var p=this.clonePosition();if(n!=="select"&&this.bumpIf("=")){var l=this.tryParseDecimalInteger(U.EXPECT_PLURAL_ARGUMENT_SELECTOR,U.INVALID_PLURAL_ARGUMENT_SELECTOR);if(l.err)return l;u=H(p,this.clonePosition()),c=this.message.slice(p.offset,this.offset())}else break}if(d.has(c))return this.error(n==="select"?U.DUPLICATE_SELECT_ARGUMENT_SELECTOR:U.DUPLICATE_PLURAL_ARGUMENT_SELECTOR,u);c==="other"&&(i=!0),this.bumpSpace();var f=this.clonePosition();if(!this.bumpIf("{"))return this.error(n==="select"?U.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT:U.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT,H(this.clonePosition(),this.clonePosition()));var h=this.parseMessage(t+1,n,r);if(h.err)return h;var m=this.tryParseArgumentClose(f);if(m.err)return m;a.push([c,{value:h.val,location:H(f,this.clonePosition())}]),d.add(c),this.bumpSpace(),s=this.parseIdentifierIfPossible(),c=s.value,u=s.location}return a.length===0?this.error(n==="select"?U.EXPECT_SELECT_ARGUMENT_SELECTOR:U.EXPECT_PLURAL_ARGUMENT_SELECTOR,H(this.clonePosition(),this.clonePosition())):this.requiresOtherClause&&!i?this.error(U.MISSING_OTHER_CLAUSE,H(this.clonePosition(),this.clonePosition())):{val:a,err:null}},e.prototype.tryParseDecimalInteger=function(t,n){var r=1,o=this.clonePosition();this.bumpIf("+")||this.bumpIf("-")&&(r=-1);for(var s=!1,i=0;!this.isEOF();){var a=this.char();if(a>=48&&a<=57)s=!0,i=i*10+(a-48),this.bump();else break}var d=H(o,this.clonePosition());return s?(i*=r,mV(i)?{val:i,err:null}:this.error(n,d)):this.error(t,d)},e.prototype.offset=function(){return this.position.offset},e.prototype.isEOF=function(){return this.offset()===this.message.length},e.prototype.clonePosition=function(){return{offset:this.position.offset,line:this.position.line,column:this.position.column}},e.prototype.char=function(){var t=this.position.offset;if(t>=this.message.length)throw Error("out of bound");var n=YI(this.message,t);if(n===void 0)throw Error("Offset ".concat(t," is at invalid UTF-16 code unit boundary"));return n},e.prototype.error=function(t,n){return{val:null,err:{kind:t,message:this.message,location:n}}},e.prototype.bump=function(){if(!this.isEOF()){var t=this.char();t===10?(this.position.line+=1,this.position.column=1,this.position.offset+=1):(this.position.column+=1,this.position.offset+=t<65536?1:2)}},e.prototype.bumpIf=function(t){if(VI(this.message,t,this.offset())){for(var n=0;n<t.length;n++)this.bump();return!0}return!1},e.prototype.bumpUntil=function(t){var n=this.offset(),r=this.message.indexOf(t,n);return r>=0?(this.bumpTo(r),!0):(this.bumpTo(this.message.length),!1)},e.prototype.bumpTo=function(t){if(this.offset()>t)throw Error("targetOffset ".concat(t," must be greater than or equal to the current offset ").concat(this.offset()));for(t=Math.min(t,this.message.length);;){var n=this.offset();if(n===t)break;if(n>t)throw Error("targetOffset ".concat(t," is at invalid UTF-16 code unit boundary"));if(this.bump(),this.isEOF())break}},e.prototype.bumpSpace=function(){for(;!this.isEOF()&&$I(this.char());)this.bump()},e.prototype.peek=function(){if(this.isEOF())return null;var t=this.char(),n=this.offset(),r=this.message.charCodeAt(n+(t>=65536?2:1));return r??null},e}();function Df(e){return e>=97&&e<=122||e>=65&&e<=90}function yV(e){return Df(e)||e===47}function AV(e){return e===45||e===46||e>=48&&e<=57||e===95||e>=97&&e<=122||e>=65&&e<=90||e==183||e>=192&&e<=214||e>=216&&e<=246||e>=248&&e<=893||e>=895&&e<=8191||e>=8204&&e<=8205||e>=8255&&e<=8256||e>=8304&&e<=8591||e>=11264&&e<=12271||e>=12289&&e<=55295||e>=63744&&e<=64975||e>=65008&&e<=65533||e>=65536&&e<=983039}function $I(e){return e>=9&&e<=13||e===32||e===133||e>=8206&&e<=8207||e===8232||e===8233}function vV(e){return e>=33&&e<=35||e===36||e>=37&&e<=39||e===40||e===41||e===42||e===43||e===44||e===45||e>=46&&e<=47||e>=58&&e<=59||e>=60&&e<=62||e>=63&&e<=64||e===91||e===92||e===93||e===94||e===96||e===123||e===124||e===125||e===126||e===161||e>=162&&e<=165||e===166||e===167||e===169||e===171||e===172||e===174||e===176||e===177||e===182||e===187||e===191||e===215||e===247||e>=8208&&e<=8213||e>=8214&&e<=8215||e===8216||e===8217||e===8218||e>=8219&&e<=8220||e===8221||e===8222||e===8223||e>=8224&&e<=8231||e>=8240&&e<=8248||e===8249||e===8250||e>=8251&&e<=8254||e>=8257&&e<=8259||e===8260||e===8261||e===8262||e>=8263&&e<=8273||e===8274||e===8275||e>=8277&&e<=8286||e>=8592&&e<=8596||e>=8597&&e<=8601||e>=8602&&e<=8603||e>=8604&&e<=8607||e===8608||e>=8609&&e<=8610||e===8611||e>=8612&&e<=8613||e===8614||e>=8615&&e<=8621||e===8622||e>=8623&&e<=8653||e>=8654&&e<=8655||e>=8656&&e<=8657||e===8658||e===8659||e===8660||e>=8661&&e<=8691||e>=8692&&e<=8959||e>=8960&&e<=8967||e===8968||e===8969||e===8970||e===8971||e>=8972&&e<=8991||e>=8992&&e<=8993||e>=8994&&e<=9e3||e===9001||e===9002||e>=9003&&e<=9083||e===9084||e>=9085&&e<=9114||e>=9115&&e<=9139||e>=9140&&e<=9179||e>=9180&&e<=9185||e>=9186&&e<=9254||e>=9255&&e<=9279||e>=9280&&e<=9290||e>=9291&&e<=9311||e>=9472&&e<=9654||e===9655||e>=9656&&e<=9664||e===9665||e>=9666&&e<=9719||e>=9720&&e<=9727||e>=9728&&e<=9838||e===9839||e>=9840&&e<=10087||e===10088||e===10089||e===10090||e===10091||e===10092||e===10093||e===10094||e===10095||e===10096||e===10097||e===10098||e===10099||e===10100||e===10101||e>=10132&&e<=10175||e>=10176&&e<=10180||e===10181||e===10182||e>=10183&&e<=10213||e===10214||e===10215||e===10216||e===10217||e===10218||e===10219||e===10220||e===10221||e===10222||e===10223||e>=10224&&e<=10239||e>=10240&&e<=10495||e>=10496&&e<=10626||e===10627||e===10628||e===10629||e===10630||e===10631||e===10632||e===10633||e===10634||e===10635||e===10636||e===10637||e===10638||e===10639||e===10640||e===10641||e===10642||e===10643||e===10644||e===10645||e===10646||e===10647||e===10648||e>=10649&&e<=10711||e===10712||e===10713||e===10714||e===10715||e>=10716&&e<=10747||e===10748||e===10749||e>=10750&&e<=11007||e>=11008&&e<=11055||e>=11056&&e<=11076||e>=11077&&e<=11078||e>=11079&&e<=11084||e>=11085&&e<=11123||e>=11124&&e<=11125||e>=11126&&e<=11157||e===11158||e>=11159&&e<=11263||e>=11776&&e<=11777||e===11778||e===11779||e===11780||e===11781||e>=11782&&e<=11784||e===11785||e===11786||e===11787||e===11788||e===11789||e>=11790&&e<=11798||e===11799||e>=11800&&e<=11801||e===11802||e===11803||e===11804||e===11805||e>=11806&&e<=11807||e===11808||e===11809||e===11810||e===11811||e===11812||e===11813||e===11814||e===11815||e===11816||e===11817||e>=11818&&e<=11822||e===11823||e>=11824&&e<=11833||e>=11834&&e<=11835||e>=11836&&e<=11839||e===11840||e===11841||e===11842||e>=11843&&e<=11855||e>=11856&&e<=11857||e===11858||e>=11859&&e<=11903||e>=12289&&e<=12291||e===12296||e===12297||e===12298||e===12299||e===12300||e===12301||e===12302||e===12303||e===12304||e===12305||e>=12306&&e<=12307||e===12308||e===12309||e===12310||e===12311||e===12312||e===12313||e===12314||e===12315||e===12316||e===12317||e>=12318&&e<=12319||e===12320||e===12336||e===64830||e===64831||e>=65093&&e<=65094}function kf(e){e.forEach(function(t){if(delete t.location,Nc(t)||wc(t))for(var n in t.options)delete t.options[n].location,kf(t.options[n].value);else Pc(t)&&Dc(t.style)||(xc(t)||Tc(t))&&Ti(t.style)?delete t.style.location:Oc(t)&&kf(t.children)})}function WI(e,t){t===void 0&&(t={}),t=V({shouldParseSkeletons:!0,requiresOtherClause:!0},t);var n=new XI(e,t).parse();if(n.err){var r=SyntaxError(U[n.err.kind]);throw r.location=n.err.location,r.originalMessage=n.err.message,r}return t!=null&&t.captureLocation||kf(n.val),n.val}function kc(e,t){var n=t&&t.cache?t.cache:EV,r=t&&t.serializer?t.serializer:RV,o=t&&t.strategy?t.strategy:bV;return o(e,{cache:n,serializer:r})}function SV(e){return e==null||typeof e=="number"||typeof e=="boolean"}function QI(e,t,n,r){var o=SV(r)?r:n(r),s=t.get(o);return typeof s>"u"&&(s=e.call(this,r),t.set(o,s)),s}function JI(e,t,n){var r=Array.prototype.slice.call(arguments,3),o=n(r),s=t.get(o);return typeof s>"u"&&(s=e.apply(this,r),t.set(o,s)),s}function Mf(e,t,n,r,o){return n.bind(t,e,r,o)}function bV(e,t){var n=e.length===1?QI:JI;return Mf(e,this,n,t.cache.create(),t.serializer)}function IV(e,t){return Mf(e,this,JI,t.cache.create(),t.serializer)}function _V(e,t){return Mf(e,this,QI,t.cache.create(),t.serializer)}var RV=function(){return JSON.stringify(arguments)};function Lf(){this.cache=Object.create(null)}Lf.prototype.get=function(e){return this.cache[e]};Lf.prototype.set=function(e,t){this.cache[e]=t};var EV={create:function(){return new Lf}},Mc={variadic:IV,monadic:_V};var Ur;(function(e){e.MISSING_VALUE="MISSING_VALUE",e.INVALID_VALUE="INVALID_VALUE",e.MISSING_INTL_API="MISSING_INTL_API"})(Ur||(Ur={}));var wi=function(e){xi(t,e);function t(n,r,o){var s=e.call(this,n)||this;return s.code=r,s.originalMessage=o,s}return t.prototype.toString=function(){return"[formatjs Error: ".concat(this.code,"] ").concat(this.message)},t}(Error);var Bf=function(e){xi(t,e);function t(n,r,o,s){return e.call(this,'Invalid values for "'.concat(n,'": "').concat(r,'". Options are "').concat(Object.keys(o).join('", "'),'"'),Ur.INVALID_VALUE,s)||this}return t}(wi);var ZI=function(e){xi(t,e);function t(n,r,o){return e.call(this,'Value for "'.concat(n,'" must be of type ').concat(r),Ur.INVALID_VALUE,o)||this}return t}(wi);var e_=function(e){xi(t,e);function t(n,r){return e.call(this,'The intl string context variable "'.concat(n,'" was not provided to the string "').concat(r,'"'),Ur.MISSING_VALUE,r)||this}return t}(wi);var Le;(function(e){e[e.literal=0]="literal",e[e.object=1]="object"})(Le||(Le={}));function CV(e){return e.length<2?e:e.reduce(function(t,n){var r=t[t.length-1];return!r||r.type!==Le.literal||n.type!==Le.literal?t.push(n):r.value+=n.value,t},[])}function PV(e){return typeof e=="function"}function Oi(e,t,n,r,o,s,i){if(e.length===1&&Cf(e[0]))return[{type:Le.literal,value:e[0].value}];for(var a=[],d=0,c=e;d<c.length;d++){var u=c[d];if(Cf(u)){a.push({type:Le.literal,value:u.value});continue}if(wI(u)){typeof s=="number"&&a.push({type:Le.literal,value:n.getNumberFormat(t).format(s)});continue}var p=u.value;if(!(o&&p in o))throw new e_(p,i);var l=o[p];if(NI(u)){(!l||typeof l=="string"||typeof l=="number")&&(l=typeof l=="string"||typeof l=="number"?String(l):""),a.push({type:typeof l=="string"?Le.literal:Le.object,value:l});continue}if(xc(u)){var f=typeof u.style=="string"?r.date[u.style]:Ti(u.style)?u.style.parsedOptions:void 0;a.push({type:Le.literal,value:n.getDateTimeFormat(t,f).format(l)});continue}if(Tc(u)){var f=typeof u.style=="string"?r.time[u.style]:Ti(u.style)?u.style.parsedOptions:r.time.medium;a.push({type:Le.literal,value:n.getDateTimeFormat(t,f).format(l)});continue}if(Pc(u)){var f=typeof u.style=="string"?r.number[u.style]:Dc(u.style)?u.style.parsedOptions:void 0;f&&f.scale&&(l=l*(f.scale||1)),a.push({type:Le.literal,value:n.getNumberFormat(t,f).format(l)});continue}if(Oc(u)){var h=u.children,m=u.value,g=o[m];if(!PV(g))throw new ZI(m,"function",i);var y=Oi(h,t,n,r,o,s),v=g(y.map(function(I){return I.value}));Array.isArray(v)||(v=[v]),a.push.apply(a,v.map(function(I){return{type:typeof I=="string"?Le.literal:Le.object,value:I}}))}if(Nc(u)){var S=u.options[l]||u.options.other;if(!S)throw new Bf(u.value,l,Object.keys(u.options),i);a.push.apply(a,Oi(S.value,t,n,r,o));continue}if(wc(u)){var S=u.options["=".concat(l)];if(!S){if(!Intl.PluralRules)throw new wi(`Intl.PluralRules is not available in this environment.
|
|
3
|
+
Try polyfilling it using "@formatjs/intl-pluralrules"
|
|
4
|
+
`,Ur.MISSING_INTL_API,i);var b=n.getPluralRules(t,{type:u.pluralType}).select(l-(u.offset||0));S=u.options[b]||u.options.other}if(!S)throw new Bf(u.value,l,Object.keys(u.options),i);a.push.apply(a,Oi(S.value,t,n,r,o,l-(u.offset||0)));continue}}return CV(a)}function xV(e,t){return t?V(V(V({},e||{}),t||{}),Object.keys(e).reduce(function(n,r){return n[r]=V(V({},e[r]),t[r]||{}),n},{})):e}function TV(e,t){return t?Object.keys(e).reduce(function(n,r){return n[r]=xV(e[r],t[r]),n},V({},e)):e}function Gf(e){return{create:function(){return{get:function(t){return e[t]},set:function(t,n){e[t]=n}}}}}function NV(e){return e===void 0&&(e={number:{},dateTime:{},pluralRules:{}}),{getNumberFormat:kc(function(){for(var t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return new((t=Intl.NumberFormat).bind.apply(t,Cc([void 0],n,!1)))},{cache:Gf(e.number),strategy:Mc.variadic}),getDateTimeFormat:kc(function(){for(var t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return new((t=Intl.DateTimeFormat).bind.apply(t,Cc([void 0],n,!1)))},{cache:Gf(e.dateTime),strategy:Mc.variadic}),getPluralRules:kc(function(){for(var t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return new((t=Intl.PluralRules).bind.apply(t,Cc([void 0],n,!1)))},{cache:Gf(e.pluralRules),strategy:Mc.variadic})}}var t_=function(){function e(t,n,r,o){n===void 0&&(n=e.defaultLocale);var s=this;if(this.formatterCache={number:{},dateTime:{},pluralRules:{}},this.format=function(c){var u=s.formatToParts(c);if(u.length===1)return u[0].value;var p=u.reduce(function(l,f){return!l.length||f.type!==Le.literal||typeof l[l.length-1]!="string"?l.push(f.value):l[l.length-1]+=f.value,l},[]);return p.length<=1?p[0]||"":p},this.formatToParts=function(c){return Oi(s.ast,s.locales,s.formatters,s.formats,c,void 0,s.message)},this.resolvedOptions=function(){var c;return{locale:((c=s.resolvedLocale)===null||c===void 0?void 0:c.toString())||Intl.NumberFormat.supportedLocalesOf(s.locales)[0]}},this.getAst=function(){return s.ast},this.locales=n,this.resolvedLocale=e.resolveLocale(n),typeof t=="string"){if(this.message=t,!e.__parse)throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");var i=o||{},a=i.formatters,d=TI(i,["formatters"]);this.ast=e.__parse(t,V(V({},d),{locale:this.resolvedLocale}))}else this.ast=t;if(!Array.isArray(this.ast))throw new TypeError("A message must be provided as a String or AST.");this.formats=TV(e.formats,r),this.formatters=o&&o.formatters||NV(this.formatterCache)}return Object.defineProperty(e,"defaultLocale",{get:function(){return e.memoizedDefaultLocale||(e.memoizedDefaultLocale=new Intl.NumberFormat().resolvedOptions().locale),e.memoizedDefaultLocale},enumerable:!1,configurable:!0}),e.memoizedDefaultLocale=null,e.resolveLocale=function(t){if(!(typeof Intl.Locale>"u")){var n=Intl.NumberFormat.supportedLocalesOf(t);return n.length>0?new Intl.Locale(n[0]):new Intl.Locale(typeof t=="string"?t:t[0])}},e.__parse=WI,e.formats={number:{integer:{maximumFractionDigits:0},currency:{style:"currency"},percent:{style:"percent"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},e}();var Di=t_;var Lc=function(){return Lc=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Lc.apply(this,arguments)};function n_(e,t,n){n===void 0&&(n=null);function r(a){return a&&a.indexOf("###")>-1?a.replace(/###/g,"."):a}function o(){return!e||typeof e=="string"}for(var s=typeof t!="string"?[].concat(t):t.split(".");s.length>1;){if(o())return{};var i=r(s.shift());!e[i]&&n&&(e[i]=new n),e=e[i]}return o()?{}:{obj:e,k:r(s.shift())}}function wV(e,t,n){var r=n_(e,t,Object),o=r.obj,s=r.k;o[s]=n}function OV(e,t){var n=n_(e,t),r=n.obj,o=n.k;if(r)return r[o]}var Vo;(function(e){e.keepRaw="keepRaw",e.replaceAnyway="replaceAnyway"})(Vo||(Vo={}));var kPe=Vo.replaceAnyway,DV={memoize:!1,memoizeFallback:!1,bindI18n:!1,bindI18nStore:!1,onParseError:Vo.replaceAnyway},Uf=function(){function e(){this.mem={}}return e.staticInit=function(t){e._i18nextInstance=t},e.prototype.init=function(t,n){var r=this;t===void 0&&(t=e._i18nextInstance);var o={};if(t!=null&&t.options&&(t.options.i18nFormat&&(o=t.options.i18nFormat),o.onParseError=t.options.onParseError,o.missingInterpolationHandler=t.options.missingInterpolationHandler,o.icuConfig=t.options.icuConfig,o.ignoreWarning=!!t.options.ignoreWarning),this.options=Object.assign(DV,n,o),this.formats=this.options.formats,t){var s=this.options,i=s.bindI18n,a=s.bindI18nStore,d=s.memoize;t.IntlMessageFormat=Di,this.IntlMessageFormat=Di,t.ICU=this,d&&(i&&t.on(i,function(){return r.clearCache()}),a&&t.store.on(a,function(){return r.clearCache()}))}this.options.localeData&&(Object.prototype.toString.apply(this.options.localeData)==="[object Array]"?this.options.localeData.forEach(function(c){return r.addLocaleData(c)}):this.addLocaleData(this.options.localeData))},e.prototype.addLocaleData=function(t){var n=Object.prototype.toString.apply(t)==="[object Array]"?t:[t];n.forEach(function(r){r&&r.locale&&Di.__addLocaleData(r)})},e.prototype.addUserDefinedFormats=function(t){this.formats=this.formats?Lc(Lc({},this.formats),t):t},e.prototype.checkMissingInterpolation=function(t,n,r,o,s){if((this.options.icuConfig||{}).strict===!1)return r;for(var i={},a=0,d=t;a<d.length;a++){var c=d[a];if(c.type===1){var u=c.value;if(!(r[u]!==null&&r[u]!==void 0)){if(typeof this.options.missingInterpolationHandler=="function"){var p=this.options.missingInterpolationHandler({key:s,text:n,locale:o,interpolation:{key:u,val:r[u]}});if(typeof p=="string"){i[u]=p;continue}}switch(this.options.onParseError){case Vo.keepRaw:throw new Error;case Vo.replaceAnyway:i[u]="{"+u+"}";continue}if(typeof this.options.onParseError=="function"){console.warn("[DEPRECATED] onParseError is deprecated, please use 'missingInterpolationHandler' instead of");var l=this.options.onParseError(n,u,o,this.IntlMessageFormat);if(l===!0)throw new Error;i[u]=typeof l=="string"?l:"{"+u+"}"}else this.options.ignoreWarning||console.warn('[Starling ICU Warning] The interpolation parameter "{'+u+'}" is missing in the translation text "'+n+'" for the key "'+s+`"
|
|
5
|
+
Suggestions: check whether the value is null or undefined. Try using empty string '' as fallback! e.g I18n.t('key', { apple: count || '' })`),i[u]="{"+u+"}"}}}return Object.assign({},r,i)},e.prototype.parse=function(t,n,r,o,s,i){var a=i&&i.resolved&&i.resolved.res,d=this.options.memoize&&r+"."+o+"."+s.replace(/\./g,"###");!a&&n.thirdParamFallback&&n.fallbackText&&(t=n.fallbackText);var c;this.options.memoize&&(c=OV(this.mem,d));try{return c||(c=new this.IntlMessageFormat(t,r,this.formats,(this.options.icuConfig||{}).formatOptions),this.options.memoize&&(this.options.memoizeFallback||!i||a)&&wV(this.mem,d,c)),c.format(this.checkMissingInterpolation(c.getAst(),t,n||{},r,s))}catch{return t}},e.prototype.addLookupKeys=function(t,n,r,o,s){return t},e.prototype.clearCache=function(){this.mem={}},e.type="i18nFormat",e._i18nextInstance=null,e}(),MPe=Uf.name;var zf=function(){return zf=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},zf.apply(this,arguments)},kV="INCONTEXT-KEY-MATCH",Bc=/^\s*\[\[__starling_(\d+)_(.*)__\]\]\s*$/,MV=function(){return document.getElementById(kV)};typeof window<"u"&&(window.__STARLING_INCONTEXT_GLOBAL__HOOK__=zf({},window.__STARLING_INCONTEXT_GLOBAL__HOOK__||{payload:{}}));var r_={name:"inContext",type:"postProcessor",process:function(e,t,n,r){if(window&&MV()&&!n.__STARLING_INCONTEXT_FLAG__){window.__STARLING_INCONTEXT_GLOBAL_I18N__||(window.__STARLING_INCONTEXT_GLOBAL_I18N__=r),delete n.keySeparator,delete n.lngs;var o=0;if(t=t.toString(),Bc.test(t)){var s=t.match(Bc);s[0];var i=s[1],a=s[2];o=i,t=a}if(Bc.test(e)){var s=e.match(Bc);s[0];var i=s[1],a=s[2];e=a}return window.__STARLING_INCONTEXT_GLOBAL__HOOK__.payload[t]?o=window.__STARLING_INCONTEXT_GLOBAL__HOOK__.payload[t].push({options:n,default:e})-1:(window.__STARLING_INCONTEXT_GLOBAL__HOOK__.payload[t]=[{options:n,default:e}],o=0),"[[__starling_"+o+"_"+t+"__]]"}else return e}};function Yf(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function LV(e){if(Array.isArray(e))return Yf(e)}function d_(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o_(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,qV(r.key),r)}}function c_(e,t,n){return t&&o_(e.prototype,t),n&&o_(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function BV(e,t){var n=typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=u_(e))||t&&e&&typeof e.length=="number"){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(d){throw d},f:o}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
6
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var s,i=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var d=n.next();return i=d.done,d},e:function(d){a=!0,s=d},f:function(){try{i||n.return==null||n.return()}finally{if(a)throw s}}}}function GV(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function UV(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
7
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function s_(e){return LV(e)||GV(e)||u_(e)||UV()}function zV(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function qV(e){var t=zV(e,"string");return typeof t=="symbol"?t:t+""}function u_(e,t){if(e){if(typeof e=="string")return Yf(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Yf(e,t):void 0}}var qf=["AFN","EUR","ALL","DZD","USD","AOA","XCD","ARS","AMD","AWG","AUD","AZN","BSD","BHD","BDT","BBD","BYN","BZD","XOF","BMD","INR","BTN","BOB","BOV","BAM","BWP","NOK","BRL","BND","BGN","BIF","CVE","KHR","XAF","CAD","KYD","CLP","CLF","CNY","COP","COU","KMF","CDF","NZD","CRC","HRK","CUP","CUC","ANG","CZK","DKK","DJF","DOP","EGP","SVC","ERN","ETB","FKP","FJD","XPF","GMD","GEL","GHS","GIP","GTQ","GBP","GNF","GYD","HTG","HNL","HKD","HUF","ISK","IDR","XDR","IRR","IQD","ILS","JMD","JPY","JOD","KZT","KES","KPW","KRW","KWD","KGS","LAK","LBP","LSL","ZAR","LRD","LYD","CHF","MOP","MKD","MGA","MWK","MYR","MVR","MRO","MUR","XUA","MXN","MXV","MDL","MNT","MAD","MZN","MMK","NAD","NPR","NIO","NGN","OMR","PKR","PAB","PGK","PYG","PEN","PHP","PLN","QAR","RON","RUB","RWF","SHP","WST","STD","SAR","RSD","SCR","SLL","SGD","XSU","SBD","SOS","SSP","LKR","SDG","SRD","SZL","SEK","CHE","CHW","SYP","TWD","TJS","TZS","THB","TOP","TTD","TND","TRY","TMT","UGX","UAH","AED","USN","UYU","UYI","UZS","VUV","VEF","VND","YER","ZMW","ZWL","XBA","XBB","XBC","XBD","XTS","XXX","XAU","XPD","XPT","XAG"],p_={};for(ki=0;ki<qf.length;ki++)p_[qf[ki]]={style:"currency",currency:qf[ki]};var ki,FV={number:p_},Kf={LOGGER:"logger",LAMGUAGE_DETECTOR:"languageDetector",LAMGUAGE_TRANSFORMER:"languageTransformer",BACKEND:"backend"};function Xf(e){return function(t){return t.type===e}}function $f(e,t){var n=e;return(t||[]).map(function(r){n=r.process(e)||n}),n}var jV="zh-CN",VV={lng:jV,fallbackLng:["en-US"],inContext:!0},Ff=[Uf,r_],HV=function(){function e(t,n){if(d_(this,e),this._waitingToAddResourceBundle=[],t!=null&&t.copiedI18nextInstance){this.instance=t.copiedI18nextInstance;return}this._handlePlugins(n),this._handleConfigs(t),this.instance=Zb.createInstance(),this.instance.isInitialized=!1}return c_(e,[{key:"_handlePlugins",value:function(n){var r,o;((r=this.config)===null||r===void 0||(o=r.icuConfig)===null||o===void 0?void 0:o.open)===!1&&Ff.shift(),this.plugins=Array.isArray(n)?n.concat(Ff):Ff}},{key:"_handleConfigs",value:function(n){this.userLng=(n==null?void 0:n.lng)||null,this.config=Object.assign({},VV,n||{})}},{key:"language",get:function(){return(this.instance||{}).language}},{key:"createInstance",value:function(){var n=this;return new Promise(function(r,o){typeof window<"u"&&!window.CocosEngine&&n.config.inContext&&(n.config.postProcess=[].concat(["inContext"],n.config.postProcess||[]),window.__STARLING_DEVTOOLS_I18N=n.instance),n.plugins.map(function(a){a.name==="IES_INTL_ICU_PLUGIN"&&a.staticInit(n.instance),n.instance.use(a)});var s=n.config;n.config.formats=Object.assign({},n.config.formats,FV);var i=$f(s.lng,n.plugins.filter(Xf(Kf.LAMGUAGE_TRANSFORMER)));n.instance.init(Object.assign({},s,{lng:i,i18nFormat:Object.assign({},s.i18nFormat||{},{formats:n.config.formats})}),function(a,d){try{var c=BV(n._waitingToAddResourceBundle),u;try{for(c.s();!(u=c.n()).done;){var p,l=u.value;(p=n.instance).addResourceBundle.apply(p,s_(l))}}catch(f){c.e(f)}finally{c.f()}n._waitingToAddResourceBundle=[]}catch{}a||(n._updateLanguages(),r({t:d,err:a})),n.init=!0,o({t:d,err:a})})})}},{key:"_updateLanguages",value:function(){this.languages=this.instance?Array.from(new Set([this.instance.language].concat(s_(this.instance.languages)))):null}},{key:"getLanguages",value:function(){return this.languages}},{key:"changeLanguage",value:function(n,r){var o=this;this.config.lng=n,this.instance.changeLanguage(n,function(s,i){s||o._updateLanguages(),r&&r(s,i)})}},{key:"changeLanguageWithPromise",value:function(n){var r=this;return new Promise(function(o,s){r.config.lng=n,r.instance.changeLanguage(n,function(i,a){i&&s({err:i,t:a}),r._updateLanguages(),o({err:i,t:a})})})}},{key:"getDir",value:function(n){return this.instance.dir(n)}},{key:"t",value:function(n,r,o){var s=Array.isArray(n)?Array.from(n).map(function(){return" "}).join(""):Array(n.length).fill(" "),i=Object.assign({keySeparator:s,nsSeparator:s},r);return"thirdParamFallback"in this.config&&this.config.thirdParamFallback&&(i.thirdParamFallback=!0),this.instance.t(n,o,i)}},{key:"addResourceBundle",value:function(n,r,o,s,i){return this.instance.isInitialized?this.instance.addResourceBundle(n,r,o,s,i):(this._waitingToAddResourceBundle.push([n,r,o,!!s,!!i]),this.instance)}},{key:"cloneInstance",value:function(n,r){var o=this.instance.cloneInstance(n,r),s=new e({copiedI18nextInstance:o});return s.t=this.t.bind(s),s.config=this.config,s.plugins=this.plugins,s.languages=this.languages,s.init=o.isInitialized||!!this.init,s.userLng=this.userLng,o.on("initialized",function(){s.init=!0}),s}}])}(),i_="Starling_intl:",jf={warn:function(){for(var t,n="".concat(i_," [WARNING]"),r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];(t=console).warn.apply(t,[n].concat(o))},error:function(){for(var t,n="".concat(i_," [ERROR]"),r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];(t=console).error.apply(t,[n].concat(o))}};function YV(e){return new Promise(function(t,n){if(Array.isArray(e)||(e=Array.from(e)),e.length<=0)return t([]);var r=[];e=e.map(function(o,s){return function(){var i=typeof o=="function"?new Promise(o):Promise.resolve(o);i.then(function(a){r[s]=a,s===e.length-1?t(r):e[s+1]()},n)}}),e[0]()})}function Vf(e,t,n){return n?t?t(e):e:((!e||!e.then)&&(e=Promise.resolve(e)),t?e.then(t):e)}function KV(e,t){try{var n=e()}catch(r){return t(r)}return n&&n.then?n.then(void 0,t):n}function XV(){}function $V(e,t){if(!t)return e&&e.then?e.then(XV):Promise.resolve()}function a_(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(e.apply(this,t))}catch(r){return Promise.reject(r)}}}var Wf;(function(e){e.intl3rdParty="intl3rdParty",e.backend="backend",e.logger="logger",e.languageDetector="languageDetector",e.postProcessor="postProcessor",e.i18nFormat="i18nFormat",e["3rdParty"]="3rdParty"})(Wf||(Wf={}));var Qf=null,Mi=function(){function e(t){var n;d_(this,e),this.plugins=[],this.i18nInstance=(n=t==null?void 0:t.i18nInstance)!==null&&n!==void 0?n:new HV}return c_(e,[{key:"use",value:function(n){return this.plugins.includes(n)?(jf.warn("Plugin: ".concat(n.name," has beeninit installed.")),this):(this.plugins.push(n),this)}},{key:"init",value:function(n,r){try{var o=this;return o.ignoreWarning=n.ignoreWarning,o.i18nInstance._handleConfigs(n),o.i18nInstance._handlePlugins(o.plugins),Vf(KV(function(){return Vf(o.i18nInstance.createInstance(),function(s){var i=s.err,a=s.t,d=o.plugins.filter(function(c){return c.type===Wf.intl3rdParty});return Vf(YV(d.map(a_(function(c){if(!(!c||typeof c.init!="function")){var u=c.init instanceof Promise?c.init:a_(function(p){return Promise.resolve(c.init(p))});return $V(u(o))}}))),function(){return typeof r=="function"&&r(i,a),{err:i,t:a}})})},function(s){return jf.error("The instance init error: ".concat(s)),{err:s,t:function(a){return a}}}))}catch(s){return Promise.reject(s)}}},{key:"language",get:function(){return(this.i18nInstance||{}).language}},{key:"setLang",value:function(n,r){var o=$f(n,this.plugins.filter(Xf(Kf.LAMGUAGE_TRANSFORMER)));this.i18nInstance.changeLanguage(o,r)}},{key:"getLanguages",value:function(){return this.i18nInstance.getLanguages()}},{key:"setLangWithPromise",value:function(n){var r=$f(n,this.plugins.filter(Xf(Kf.LAMGUAGE_TRANSFORMER)));return this.i18nInstance.changeLanguageWithPromise(r)}},{key:"dir",value:function(n){return this.i18nInstance.getDir(n)}},{key:"t",value:function(n,r,o){var s=null;return typeof this>"u"?s=Qf:s=this,!s.ignoreWarning&&(!s.i18nInstance||!s.i18nInstance.init)?(jf.error("The instance has not been initialized: i18n.t('".concat(n,"'").concat(r?","+JSON.stringify(r):"",");")),o??(Array.isArray(n)?n[0]:n)):!n||typeof n=="string"&&!n.trim()?"":s.i18nInstance.t(n,r,o)}},{key:"addResourceBundle",value:function(n,r,o,s,i){return this.i18nInstance.addResourceBundle(n,r,o,s,i)}},{key:"cloneInstance",value:function(n){var r=this.i18nInstance.cloneInstance(n),o=new e({i18nInstance:r});return o.t=this.t.bind(o),o.plugins=this.plugins,o.ignoreWarning=this.ignoreWarning,o}}])}();Qf=new Mi;var Hf=Qf;Hf.t=Hf.t.bind(Hf);var Gc=class{static create(){let t=new Mi;return t.init({lng:"en",fallbackLng:"en",resources:{},i18nFormat:gc()}),yc(t)}constructor(){}},Q=Gc.create();function te(e,t,n){return{get description(){return n()},input:t,kind:e}}var Uc=[te("set_title","{title}",()=>Q.t("Pippit_canvas_command_desc_setcanvastitle",{},"设置画布标题")),te("set_cover","{cover}",()=>Q.t("Pippit_canvas_command_desc_setcanvascover",{},"设置画布封面")),te("set_global_bounds","{bounds}",()=>Q.t("Pippit_canvas_command_desc_setcanvasglobalbounds",{},"设置画布全局边界")),te("create_node","{node, assets?, autoCreateNodeAsset?}",()=>Q.t("Pippit_canvas_command_desc_creategenericnode",{},"创建通用节点及配套资产")),te("delete_nodes","{ids}",()=>Q.t("Pippit_canvas_command_desc_deletenodes",{},"删除节点并维护关联关系")),te("update_node_data","{id, patch}",()=>Q.t("Pippit_canvas_command_desc_updatenodedata",{},"更新节点业务数据")),te("set_node_style","{id, style}",()=>Q.t("Pippit_canvas_command_desc_setnodestyle",{},"更新节点样式")),te("update_asset","{assetId, contentPatch?, extraPatch?}",()=>Q.t("Pippit_canvas_command_desc_updatecanvasasset",{},"更新画布资产内容或扩展信息")),te("move_nodes","{ids, delta}",()=>Q.t("Pippit_canvas_command_desc_movenodes",{},"移动节点")),te("resize_node","{id, size}",()=>Q.t("Pippit_canvas_command_desc_resizenode",{},"缩放节点")),te("set_node_position","{id, position}",()=>Q.t("Pippit_canvas_command_desc_setnodeposition",{},"设置节点位置")),te("align_nodes","{ids, direction}",()=>Q.t("Pippit_canvas_command_desc_alignnodes",{},"对齐节点")),te("distribute_nodes","{ids, axis}",()=>Q.t("Pippit_canvas_command_desc_distributenodes",{},"等距分布节点")),te("arrange_nodes","{ids, layout, options?}",()=>Q.t("Pippit_canvas_command_desc_arrangenodes",{},"按指定布局排列节点")),te("auto_layout_nodes","{options?}",()=>Q.t("Pippit_canvas_command_desc_autolayoutnodes",{},"执行自动布局")),te("group_nodes","{ids}",()=>Q.t("Pippit_canvas_command_desc_groupnodes",{},"创建分组")),te("ungroup","{groupId}",()=>Q.t("Pippit_canvas_command_desc_ungroupnodes",{},"解散分组")),te("reparent","{nodeId, newParentId, index?}",()=>Q.t("Pippit_canvas_command_desc_reparentnode",{},"重新设置节点归属")),te("reorder_children","{groupId, orderedChildren}",()=>Q.t("Pippit_canvas_command_desc_reordergroupchildren",{},"调整分组内节点顺序")),te("set_group_collapsed","{groupId, collapsed}",()=>Q.t("Pippit_canvas_command_desc_setgroupcollapsed",{},"设置分组折叠状态")),te("create_edge","{edge}",()=>Q.t("Pippit_canvas_command_desc_createedge",{},"创建连线")),te("delete_edges","{ids}",()=>Q.t("Pippit_canvas_command_desc_deleteedges",{},"删除连线")),te("reconnect_edge","{id, patch}",()=>Q.t("Pippit_canvas_command_desc_reconnectedge",{},"重连连线")),te("update_edge_data","{id, patch}",()=>Q.t("Pippit_canvas_command_desc_updateedgedata",{},"更新连线数据")),te("update_snap_settings","{patch}",()=>Q.t("Pippit_canvas_command_desc_updatesnapsettings",{},"更新吸附设置")),te("set_snap_enabled","{enabled}",()=>Q.t("Pippit_canvas_command_desc_setsnapenabled",{},"启用或关闭吸附")),te("set_auto_layout_strategy","{strategy?}",()=>Q.t("Pippit_canvas_command_desc_setautolayoutstrategy",{},"设置默认自动布局策略")),te("invoke_command","{name, args?}",()=>Q.t("Pippit_canvas_command_desc_invokeregisteredcommand",{},"调用 SDK 已注册的业务命令")),te("delete","{nodeIds?, edgeIds?}",()=>Q.t("Pippit_canvas_command_desc_deletenodesoredges",{},"兼容方式删除节点或连线")),te("apply_patches","{patches}",()=>Q.t("Pippit_canvas_command_desc_applypatches",{},"特权级底层 patch 操作"))];function nt(e,t){var n;return((n=e.describe)==null?void 0:n.call(e,t))??e}function zr(e){var t;return((t=e.optional)==null?void 0:t.call(e))??e}function WV(e,t,n){if(!(t!=null&&t.length))return e;let r=new Set(t);return n&&r.add(e.rootCanvasId),{...e,assets:Object.fromEntries(Object.entries(e.assets).filter(([s])=>r.has(s)))}}function QV(e){return e.map(t=>t&&typeof t=="object"&&"kind"in t?String(t.kind):"<invalid>")}function JV(e){let t=new Set(["canvas.write"]);return e.includes("apply_patches")&&t.add("canvas.patch"),(e.includes("create_node")||e.includes("create_biz_node")||e.includes("invoke_command")||e.includes("update_asset"))&&t.add("canvas.asset.write"),[...t]}async function qr(e,t,n=["canvas.read"]){return hc(e,{canvasId:zo(e),operation:t},n)}function l_(e){let{runtime:t,schema:n}=e,r=e.mutationHandler??Ei;return{get_snapshot:{args:{assetIds:zr((()=>nt(n.array(nt(n.string(),"Canvas asset id")),"Canvas asset ids"))()),includeRootCanvas:zr(nt(n.boolean(),"Whether to include the root canvas asset in the returned snapshot"))},description:"Read the current canvas snapshot as CanvasDocument JSON, optionally filtered by asset ids.",async execute(s={}){let i=await qr(t,"get_snapshot");if(i)return se(i);let a=t.store.getState();return se(bn(t,{document:WV(a,s.assetIds,s.includeRootCanvas!==!1)}))}},get_asset:{args:{assetId:nt(n.string(),"Canvas asset id to read")},description:"Read one canvas asset from the current CanvasDocument.",async execute(s){let i=await qr(t,"get_asset",["canvas.read","canvas.asset.read"]);if(i)return se(i);let a=t.store.getState().assets[s.assetId];return a?se(bn(t,{asset:a})):se(Ct(t,"INVALID_ARGUMENT",`Unknown asset: ${s.assetId}`))}},apply_mutations:{args:{atomic:zr(nt(n.boolean(),"Merge all mutations into one SDK transaction")),checkpointBefore:zr(nt(n.boolean(),"Create a checkpoint before applying mutations")),dryRun:zr(nt(n.boolean(),"Validate tool routing without writing")),expectedRevision:zr(nt(n.number(),"Reject if the current document revision differs from this value")),intent:nt(n.string(),"Short semantic intent for the canvas transaction"),mutations:nt(n.array(n.unknown()),`Canvas mutations: ${Uc.map(({kind:s})=>s).join(", ")}. Use apply_patches only for privileged patch-level changes.`)},description:"Apply semantic CanvasDocument mutations. The tool enforces canvas permissions, read-only state, revision checks, and checkpoint creation.",async execute(s){if(!Array.isArray(s.mutations))return se(Ct(t,"INVALID_ARGUMENT","mutations must be an array"));let i=QV(s.mutations),a=await hc(t,{canvasId:zo(t),mutationKinds:i,operation:"apply_mutations"},JV(i));if(a)return se(a);if(mc(t))return se(Ct(t,"READ_ONLY","Canvas is read-only"));if(typeof s.expectedRevision=="number"&&t.store.getRevision()!==s.expectedRevision)return se(Ct(t,"REVISION_CONFLICT",`Expected revision ${s.expectedRevision}, current revision ${t.store.getRevision()}`));let d;if(s.checkpointBefore){let c=await hc(t,{canvasId:zo(t),operation:"create_checkpoint"},["canvas.checkpoint.create"]);if(c)return se(c);let u=bf(t,`before:${s.intent}`);await Uo(t).create(u),d=u.checkpointId}try{let c=await r({atomic:s.atomic,dryRun:s.dryRun,expectedRevision:s.expectedRevision,intent:s.intent,mutations:s.mutations,runtime:t});return se(bn(t,{...c,checkpointId:c.checkpointId??d}))}catch(c){return se(Ct(t,"INVARIANT_FAILED",c instanceof Error?c.message:String(c)))}}},create_checkpoint:{args:{reason:zr(nt(n.string(),"Why this checkpoint is being created"))},description:"Create an opencode checkpoint from the current CanvasDocument.",async execute(s={}){let i=await qr(t,"create_checkpoint",["canvas.read","canvas.checkpoint.create"]);if(i)return se(i);let a=bf(t,s.reason);return await Uo(t).create(a),se(bn(t,{checkpointId:a.checkpointId,documentHash:a.documentHash,revision:a.revision}))}},list_checkpoints:{args:{},description:"List opencode checkpoints for the current canvas.",async execute(){let s=await qr(t,"list_checkpoints",["canvas.read"]);if(s)return se(s);let i=await Uo(t).list(zo(t));return se(bn(t,{checkpoints:i.map(({document:a,...d})=>d)}))}},restore_checkpoint:{args:{checkpointId:nt(n.string(),"Checkpoint id returned by create_checkpoint")},description:"Restore a previously created opencode checkpoint into the canvas store.",async execute(s){let i=await qr(t,"restore_checkpoint",["canvas.write","canvas.checkpoint.restore"]);if(i)return se(i);if(mc(t))return se(Ct(t,"READ_ONLY","Canvas is read-only"));let a=await Uo(t).get(s.checkpointId);if(!a)return se(Ct(t,"CHECKPOINT_NOT_FOUND",`Unknown checkpoint: ${s.checkpointId}`));let d=Gb(t,a);return d.status==="aborted"?se(Ct(t,"INVARIANT_FAILED",d.reason)):se(bn(t,{result:d}))}},compare_checkpoint:{args:{checkpointId:nt(n.string(),"Checkpoint id to compare with current canvas state")},description:"Compare a checkpoint with the current CanvasDocument at asset granularity.",async execute(s){let i=await qr(t,"compare_checkpoint");if(i)return se(i);let a=await Uo(t).get(s.checkpointId);if(!a)return se(Ct(t,"CHECKPOINT_NOT_FOUND",`Unknown checkpoint: ${s.checkpointId}`));let d=t.store.getState(),u=[...new Set([...Object.keys(d.assets),...Object.keys(a.document.assets)])].filter(p=>JSON.stringify(d.assets[p])!==JSON.stringify(a.document.assets[p]));return se(bn(t,{changedAssetIds:u,checkpointRevision:a.revision,currentRevision:t.store.getRevision()}))}},get_permissions:{args:{},description:"Read effective opencode canvas permissions for the current canvas.",async execute(){let s=await qr(t,"get_permissions",["canvas.permission.read"]);return s?se(s):se(bn(t,{canvasId:zo(t),readOnly:mc(t)}))}}}}var Jf={error(...e){typeof console.error=="function"&&console.error(...e)},info(...e){typeof console.info=="function"&&console.info(...e)},log(...e){typeof console.log=="function"&&console.log(...e)},time(e){typeof console.time=="function"&&console.time(e)},timeEnd(e){typeof console.timeEnd=="function"&&console.timeEnd(e)},timeLog(e,...t){typeof console.timeLog=="function"&&console.timeLog(e,...t)},timeStamp(e){typeof console.timeStamp=="function"&&console.timeStamp(e)},trace(...e){typeof console.trace=="function"&&console.trace(...e)},warn(...e){typeof console.warn=="function"&&console.warn(...e)},profile(e){typeof console.profile=="function"&&console.profile(e)},profileEnd(e){typeof console.profileEnd=="function"&&console.profileEnd(e)}};var Zf=null;function zc(e,t){Zf==null||Zf.branch(e,t)}var Rn=null;function Li(e){return Rn==null||Rn.trackDisposable(e),e}function Bi(e){Rn==null||Rn.markAsDisposed(e)}function qc(e,t){Rn==null||Rn.setParent(e,t)}var Gi=class e{get isDisposed(){return this._isDisposed}dispose(){if(this._isDisposed){Jf.warn(new Error("DisposableStore has disposed.").stack);return}Bi(this),this._isDisposed=!0,this.clear()}clear(){if(this._toDispose.size===0)return;for(let n of this._toDispose)zc(this.constructor.name,n.constructor.name);let t=[];for(let n of this._toDispose)try{n.dispose()}catch(r){t.push(r)}if(this._toDispose.clear(),t.length>0)throw new AggregateError(t,"find error when dispose store.")}add(t){if(!t)return t;if(t===this)throw new Error("Cannot register a disposable on itself.");return qc(t,this),this._isDisposed?e.DISABLE_DISPOSED_WARNING||Jf.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(t),t}constructor(){this._toDispose=new Set,this._isDisposed=!1,Li(this)}};Gi.DISABLE_DISPOSED_WARNING=!1;var Ui=class{dispose(){Bi(this),zc(this.constructor.name,this._store.constructor.name),this._store.dispose()}_register(t){if(t===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(t)}constructor(){this._store=new Gi,Li(this),qc(this._store,this)}};var Fc=class{get value(){return this._value}isEmpty(){return this._value===void 0}dispose(){this._value&&(this._value.dispose(),this._value=void 0,Bi(this))}constructor(t){this._value=t,Li(this)}};function zi(e){return new Fc({dispose:e})}var Sxe=Symbol.for("canvas-sdk.glassbox.host");var qi=class{constructor(t){this._items=[];this._capacity=Math.max(1,Math.floor(t))}get size(){return this._items.length}get capacity(){return this._capacity}push(t){this._items.push(t);let n=this._items.length-this._capacity;n>0&&this._items.splice(0,n)}take(t){return t===void 0||t>=this._items.length?this._items.slice():t<=0?[]:this._items.slice(this._items.length-t)}clear(){this._items=[]}};var jc={debug:10,info:20,warn:30,error:40,silent:100};function em(e){return e<10?`0${e}`:`${e}`}function sH(e){return e<10?`00${e}`:e<100?`0${e}`:`${e}`}function iH(e){let t=new Date(e);return`${em(t.getHours())}:${em(t.getMinutes())}:${em(t.getSeconds())}.${sH(t.getMilliseconds())}`}var aH={debug:"DEBUG",info:"INFO ",warn:"WARN ",error:"ERROR"},dH={debug:"debug",info:"info",warn:"warn",error:"error"};function cH(e){let t=globalThis.console;if(!t||typeof t!="object")return;let n=t[dH[e]];return typeof n=="function"?n.bind(t):void 0}var tm={write(e){var r;let t=`${iH(e.time)} ${aH[e.level]} ${e.scope}: ${e.message}`,n=[];e.fields&&Object.keys(e.fields).length>0&&n.push(e.fields),e.error!==void 0&&n.push(e.error),(r=cH(e.level))==null||r(t,...n)}};var rm="__LOG_LEVEL__",f_="LOG_LEVEL",uH="info",pH=200;function nm(e){if(typeof e!="string")return;let t=e.trim().toLowerCase();if(t==="debug"||t==="info"||t==="warn"||t==="error"||t==="silent")return t;if(t==="warning")return"warn";if(t==="off"||t==="none")return"silent"}function lH(){let e=globalThis,t=nm(e[rm]);if(t!==void 0)return t;try{let n=e.localStorage;if(n){let r=nm(n.getItem(rm));if(r!==void 0)return r}}catch{}try{if(typeof process<"u"&&process.env){let n=nm(process.env[f_]);if(n!==void 0)return n}}catch{}}var om=class e{constructor(t,n){this._hub=t,this._scope=n}debug(t,n){this._log("debug",t,void 0,n)}info(t,n){this._log("info",t,void 0,n)}warn(t,n){this._log("warn",t,void 0,n)}error(t,n,r){this._log("error",t,n,r)}scope(t){return new e(this._hub,`${this._scope}.${t}`)}isEnabled(t){return this._hub.isEnabled(t)}_log(t,n,r,o){if(!this._hub.isEnabled(t))return;let s={time:Date.now(),level:t,scope:this._scope,message:n};o&&Object.keys(o).length>0&&(s.fields=o),r!==void 0&&(s.error=r),this._hub.emit(s)}},Fi=class extends Ui{constructor(n){super();this._counters={debug:0,info:0,warn:0,error:0};this._explicitLevel=n==null?void 0:n.level,this._useRuntimeLevel=(n==null?void 0:n.useRuntimeLevel)??!0,this._rootScope=(n==null?void 0:n.rootScope)??"app",this._sinks=new Set((n==null?void 0:n.sinks)??[tm]),this._buffer=new qi((n==null?void 0:n.bufferSize)??pH)}logger(n){return new om(this,n??this._rootScope)}setLevel(n){this._explicitLevel=n}getLevel(){return this._effectiveLevel()}isEnabled(n){return jc[n]>=jc[this._effectiveLevel()]}emit(n){if(this.isEnabled(n.level)){this._counters[n.level]++,this._buffer.push(n);for(let r of this._sinks)try{r.write(n)}catch{}}}addSink(n){return this._sinks.add(n),zi(()=>this._sinks.delete(n))}removeSink(n){this._sinks.delete(n)}clearSinks(){this._sinks.clear()}recent(n){return this._buffer.take(n)}stats(){return{level:this._effectiveLevel(),counters:{...this._counters},sinks:this._sinks.size,buffered:this._buffer.size}}dispose(){this._sinks.clear(),this._buffer.clear(),super.dispose()}_effectiveLevel(){if(this._explicitLevel!==void 0)return this._explicitLevel;if(this._useRuntimeLevel){let n=lH();if(n!==void 0)return n}return uH}};var sm;function im(){return sm||(sm=new Fi),sm}function m_(e){return im().logger(e)}var fH=m_();var mH=["brightness","cameraMotion","color","count","direction","durationMs","effect","goutu","jiaoduan","jingbie","leftright","novelStyle","promptTemplate","ratio","resolution","seed","updown"],hH=["brightness","color","direction","effect","goutu","jiaoduan","jingbie","leftright","updown"],gH=["cameraMotion","count","durationMs","novelStyle","promptTemplate","ratio","resolution","seed"],yH=new Set(mH),AH=new Set(hH),NTe=new Set(gH);function vH(e){return yH.has(e)}function SH(e){return AH.has(e)}function h_(e){return e==null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e)}function g_(e){return e===void 0?!0:!e||typeof e!="object"||Array.isArray(e)?!1:Object.entries(e).every(([t,n])=>vH(t)&&h_(n))}function y_(e){return e===void 0?!0:!e||typeof e!="object"||Array.isArray(e)?!1:Object.entries(e).every(([t,n])=>SH(t)&&h_(n))}var bH=new Set(["empty","generated","tool","uploaded"]);function IH(e){return typeof e=="string"&&bH.has(e)}function Vc(e){return e===void 0||IH(e)}function P(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function De(e){return typeof e=="string"}function _(e){return e===void 0||De(e)}function Oe(e){return typeof e=="number"&&Number.isFinite(e)}function Ce(e){return e===void 0||Oe(e)}function rt(e){return e===void 0||typeof e=="boolean"}function Xt(e){return Array.isArray(e)&&e.every(De)}function Xn(e){return e===void 0||P(e)}function Ho(e,t,n,r=480){let o=Oe(e)&&e>0?e:void 0,s=Oe(t)&&t>0?t:void 0,i=n&&n.w>0?n.w:void 0,a=n&&n.h>0?n.h:void 0,d=o??i,c=s??a;if(!(!d||!c||r<=0))return{w:r,h:Math.max(1,Math.round(r*c/d))}}var _H=new Set(["audioUrl","audio_url","coverPreviewUrl","cover_preview_url","coverUrl","coverURL","cover_url","downloadUrl","download_url","playUrl","play_url","playerInfo","player_info","posterUrl","poster_url","previewUrl","preview_url","sourceUrl","source_url","src","thumbnailUrl","thumbnail_url","uri","url","urlList","url_list","waveformUrl","waveform_url"]);function ji(e){return Array.isArray(e)?e.map(ji):P(e)?Object.fromEntries(Object.entries(e).filter(([t])=>!_H.has(t)).map(([t,n])=>[t,ji(n)])):e}function RH(e){if(!P(e))return;let t=e.uploadPath==="legacy"||e.uploadPath==="optimized"?e.uploadPath:void 0;return{...typeof e.id=="string"?{id:e.id}:{},...typeof e.type=="string"?{type:e.type}:{},...typeof e.assetId=="string"?{assetId:e.assetId}:{},...Xt(e.dataReferenceSelection)?{dataReferenceSelection:e.dataReferenceSelection}:{},...typeof e.edgeId=="string"?{edgeId:e.edgeId}:{},...P(e.nodeAssetExtra)?{nodeAssetExtra:ji(e.nodeAssetExtra)}:{},...typeof e.nodeAssetId=="string"?{nodeAssetId:e.nodeAssetId}:{},...typeof e.nodeAssetType=="string"?{nodeAssetType:e.nodeAssetType}:{},...typeof e.pippitAssetId=="string"?{pippitAssetId:e.pippitAssetId}:{},...typeof e.referenceSource=="string"?{referenceSource:e.referenceSource}:{},...typeof e.sourceNodeId=="string"?{sourceNodeId:e.sourceNodeId}:{},...typeof e.sourceNodeType=="string"?{sourceNodeType:e.sourceNodeType}:{},...t?{uploadPath:t}:{},...typeof e.label=="string"?{label:e.label}:{},...P(e.metadata)?{metadata:ji(e.metadata)}:{}}}function EH(e){Array.isArray(e.references)&&(e.references=e.references.map(RH).filter(t=>!!t))}var Yo={Generated:"generated",Tool:"tool",Uploaded:"uploaded"},A_={CanvasMentionText:"canvas-mention-text"};function Hc(e,t){if(t===void 0){delete e.generation;return}let n=ji(t);if(EH(n),Ye(e.generation)&&Ye(t)){et(e.generation,n);return}e.generation=n}function v_(e){let t=e==null?void 0:e.source;if(t==="generated"||t==="tool"||t==="uploaded")return t}function CH(e){return P(e)?_(e.id)&&_(e.type)&&_(e.assetId)&&(e.dataReferenceSelection===void 0||Xt(e.dataReferenceSelection))&&_(e.edgeId)&&Xn(e.nodeAssetExtra)&&_(e.nodeAssetId)&&_(e.nodeAssetType)&&_(e.pippitAssetId)&&_(e.referenceSource)&&_(e.sourceNodeId)&&_(e.sourceNodeType)&&_(e.label)&&Xn(e.metadata):!1}function PH(e){return e===void 0||Array.isArray(e)&&e.every(CH)}var xH={submitting:!0,running:!0,succeeded:!0,failed:!0};function TH(e){return e===void 0||De(e)&&xH[e]}function NH(e){return e===void 0?!0:P(e)?_(e.threadId)&&_(e.runId)&&_(e.target)&&TH(e.status)&&_(e.submittedAt)&&_(e.updatedAt)&&_(e.errorMessage)&&Xn(e.failureContext):!1}function wH(e){return e==null?!0:P(e)?_(e.styleId)&&_(e.stylePeBefore)&&_(e.stylePeAfter)&&_(e.stylePosition)&&_(e.modelKey)&&_(e.stylePe)&&_(e.style_id)&&_(e.title)&&_(e.style_pe_before)&&_(e.style_pe_after)&&_(e.style_position)&&_(e.version)&&_(e.model_key)&&_(e.style_pe)&&_(e.category):!1}function S_(e){return P(e)?_(e.agentName)&&Xn(e.submitRunClientExtra)&&_(e.generateId)&&_(e.taskId)&&_(e.artifactId)&&_(e.threadId)&&_(e.runId)&&_(e.source)&&_(e.runSource)&&_(e.outputName)&&_(e.outputAudioType)&&_(e.prompt)&&_(e.modelKey)&&Xn(e.audioConfig)&&y_(e.args)&&_(e.cameraMotion)&&Ce(e.count)&&Ce(e.durationMs)&&_(e.novelStyle)&&_(e.promptTemplate)&&_(e.ratio)&&Ce(e.videoRatioUpdatedAt)&&Ce(e.successfulGenerationCount)&&_(e.lastSuccessfulGenerationRunId)&&_(e.resolution)&&wH(e.styleSnapshot)&&Ce(e.seed)&&g_(e.params)&&PH(e.references)&&NH(e.state)&&Xn(e.snapshot)&&Xn(e.sceneSegmentation)&&_(e.createdAt):!1}function $n(e){return P(e)?_(e.name)&&_(e.variant):!1}var am=class{static create(){let t=new Mi;return t.init({lng:"en",fallbackLng:"en",resources:{},i18nFormat:gc()}),yc(t)}constructor(){}},O=am.create();function I_(){return O.t("Pippit_xyqcanvas_legacy_label_basic_image",{},"基础形象")}function um(){return O.t("Pippit_xyqcanvas_legacy_label_unnamed_scene",{},"未命名场景")}var OH=new Set([0,1,2,3,4]),DH=new Set(["user_created","ai_generated","novel_template_clone"]),kH=new Set([1,2]),MH=new Set(["audio","image","video"]),LH=["image","Generation","Config"].join("");function BH(e){return e===void 0||Oe(e)&&OH.has(e)}function GH(e){return e===void 0||typeof e=="string"&&DH.has(e)}function __(e){return e===void 0||Oe(e)&&kH.has(e)}function R_(e){return e===void 0||typeof e=="string"&&MH.has(e)}function st(e,t){let n=e[t];return typeof n=="string"?n:void 0}function dm(e,t){let n=e[t];return Oe(n)?n:void 0}function ot(e,t,n){n!==void 0&&(e[t]=n)}function Yc(e){if(!P(e))return;let t={};ot(t,"ttsProvider",dm(e,"ttsProvider")),ot(t,"age",st(e,"age")),ot(t,"gender",st(e,"gender")),ot(t,"speaker",st(e,"speaker")),ot(t,"description",st(e,"description")),ot(t,"audioAssetId",st(e,"audioAssetId")),ot(t,"audioPippitAssetId",st(e,"audioPippitAssetId")),ot(t,"audioName",st(e,"audioName")),ot(t,"audioNodeId",st(e,"audioNodeId"));let n=st(e,"audioSource");(n===Yo.Generated||n===Yo.Uploaded)&&ot(t,"audioSource",n),ot(t,"audioDurationMs",dm(e,"audioDurationMs")),ot(t,"voiceId",st(e,"voiceId"));let r=e.voice_type??e.voiceType;return __(r)&&ot(t,"voice_type",r),Object.keys(t).length>0?t:void 0}function Pt(e){return Yc(e==null?void 0:e.voiceInfo)}function UH(e){return typeof e=="string"&&e.trim().length>0}function b_(e){return(e==null?void 0:e.trim())||void 0}function E_(e){let t=P(e)?e:void 0,n=Yc(t==null?void 0:t.voiceInfo);return(n==null?void 0:n.voice_type)!==2?!1:[n.voiceId,n.audioAssetId,n.audioPippitAssetId].some(UH)}function C_(e){var r;let t=P(e)?e:void 0,n=Yc(t==null?void 0:t.voiceInfo);if((n==null?void 0:n.voice_type)===2)return((r=n.audioAssetId)==null?void 0:r.trim())||void 0}function P_(e){let t=P(e)?e:void 0,n=Yc(t==null?void 0:t.voiceInfo);if((n==null?void 0:n.voice_type)===2)return n.audioDurationMs}function zH(e){return e===void 0?!0:P(e)?Ce(e.ttsProvider)&&_(e.age)&&_(e.gender)&&_(e.speaker)&&_(e.voiceId)&&_(e.description)&&__(e.voice_type)&&_(e.audioAssetId)&&_(e.audioPippitAssetId)&&_(e.audioName)&&_(e.audioNodeId)&&_(e.audioSource)&&Ce(e.audioDurationMs):!1}function qH(e){return e===void 0?!0:P(e)?_(e.name)&&_(e.appearanceName)&&_(e.stageTag)&&_(e.label)&&rt(e.isMainImage)&&_(e.description)&&_(e.biography)&&(e.alias===void 0||Xt(e.alias))&&_(e.referName)&&rt(e.unpromptable)&&rt(e.isMainCharacter):!1}function x_(e){if(!P(e))return{};let{[LH]:t,...n}=e;return n}function T_(e,t){let n=x_(e);delete n.assetId,delete n.pippitAssetId,delete n.uploadPath;let r=b_(t.assetId),o=b_(t.pippitAssetId);return t.imageSource!==void 0&&(n.imageSource=t.imageSource),r&&(n.assetId=r),o&&(n.pippitAssetId=o),t.uploadPath==="optimized"&&(n.uploadPath="optimized"),n}function Ko(e){let{url:t,...n}=x_(e);return n}function Kc(e){return e===void 0?!0:P(e)?BH(e.imageSource)&&_(e.assetId)&&_(e.pippitAssetId)&&(e.uploadPath===void 0||e.uploadPath==="legacy"||e.uploadPath==="optimized")&&_(e.description)&&_(e.modify):!1}function FH(e){return e===void 0||Array.isArray(e)&&e.every(t=>Kc(t))}function N_(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Fr(e,t,n){n!==void 0&&(e[t]=n)}var jH=new Set(["audioUrl","coverPreviewUrl","coverUrl","coverURL","downloadUrl","playerInfo","posterUrl","previewUrl","sceneUrls","sourceUrl","src","thumbnailUrl","uri","url","urlList","waveformUrl"]);function cm(e){return Array.isArray(e)?e.map(cm):P(e)?Object.fromEntries(Object.entries(e).filter(([t])=>!jH.has(t)).map(([t,n])=>[t,cm(n)])):e}function VH(e){let t=st({metadata:e},"metadata");if(t)try{let n=JSON.parse(t);if(!P(n))return t;let r=cm(n);return Object.keys(r).length?JSON.stringify(r):void 0}catch{return t}}function HH(e,t){if(!P(t))return;let n=N_(e);if(!n)return;let r={pippitAssetId:n};Fr(r,"assetId",st(t,"assetId")),Fr(r,"name",st(t,"name")),Fr(r,"order",dm(t,"order"));let o=t.type??void 0;if(R_(o))return Fr(r,"type",o),t.uploadPath==="optimized"&&(r.uploadPath="optimized"),Fr(r,"isMain",typeof t.isMain=="boolean"?t.isMain:void 0),Fr(r,"isDefault",typeof t.isDefault=="boolean"?t.isDefault:void 0),Fr(r,"metadata",VH(t.metadata)),r}function Xo(e){if(!P(e))return;let t=Object.entries(e).map(([n,r])=>{let o=HH(n,r);return o!=null&&o.pippitAssetId?[o.pippitAssetId,o]:void 0}).filter(n=>!!n);return t.length?Object.fromEntries(t):void 0}function YH(e){return e===void 0?!0:P(e)?Object.entries(e).every(([t,n])=>!N_(t)||!P(n)?!1:_(n.pippitAssetId)&&_(n.assetId)&&_(n.name)&&Ce(n.order)&&R_(n.type)&&(n.uploadPath===void 0||n.uploadPath==="legacy"||n.uploadPath==="optimized")&&rt(n.isMain)&&rt(n.isDefault)&&_(n.metadata)):!1}function Xc(e){return P(e)?_(e.nodeName)&&Ce(e.order)&&qH(e.basicInfo)&&_(e.useContext)&&(e.episodes===void 0||Xt(e.episodes))&&GH(e.createType)&&Kc(e.appearanceInfo)&&FH(e.referenceAppearances)&&zH(e.voiceInfo)&&(e.generation===void 0||S_(e.generation))&&YH(e.sourceInfos):!1}var z="biz/role",pm=z,O_="role";function XH(e){return P(e)&&!("pippitAssetId"in e)&&_(e.name)&&_(e.extra)&&rt(e.isCover)}function w_(e){return Xc(e)}function $t(e){if(!P(e))return;let{content:t}=e;return P(t)&&w_(t.data)?t.data:w_(t)?t:void 0}function jr(e){if(!P(e))return;let t=$t(e);if(t)return e.type=pm,e.content=t,e}var Vr={type:z,validate:XH,getDefaultSize:e=>({w:362,h:468})};var Vi="data-reference-selection",lm="roleVoiceReference";function xt(e){return typeof e=="string"?e.trim():""}function WH(e){return e==="audio"||e==="image"||e==="video"?e:void 0}function QH(e){let t=WH(e==null?void 0:e.type);return!t||t==="image"}function $o(e){var r,o,s;let t=Xo(e==null?void 0:e.sourceInfos),n=t?Object.entries(t):[];if(!n.length){let i=xt((r=e==null?void 0:e.appearanceInfo)==null?void 0:r.pippitAssetId);i&&n.push([i,{assetId:xt((o=e==null?void 0:e.appearanceInfo)==null?void 0:o.assetId)||void 0,isMain:!0,name:xt((s=e==null?void 0:e.basicInfo)==null?void 0:s.appearanceName)||void 0,order:0,pippitAssetId:i,type:"image"}])}return n.map(([i,a])=>[i,{...a,isMain:QH(a)?a.isMain:!1,pippitAssetId:i}]).sort((i,a)=>{let d=Number.isFinite(i[1].order)?Number(i[1].order):0,c=Number.isFinite(a[1].order)?Number(a[1].order):0;return d!==c?d-c:i[0].localeCompare(a[0])})}function D_(e,t){var a,d,c;let n=xt(t.pippitAssetId),r=$o(e);if(!n)return Object.fromEntries(r);let o=((a=r.find(([,u])=>u.isMain===!0))==null?void 0:a[0])||xt((d=e==null?void 0:e.appearanceInfo)==null?void 0:d.pippitAssetId),s=(c=r.find(([u])=>u===n))==null?void 0:c[1],i=r.filter(([u])=>u!==o&&u!==n);return Object.fromEntries([[n,{...s??{},...t,isMain:!0,order:0,pippitAssetId:n,type:"image"}],...i.map(([u,p],l)=>[u,{...p,isMain:!1,order:l+1,pippitAssetId:u}])])}function k_(e,t){let n=xt(t.assetId)||void 0,r=xt(t.pippitAssetId)||void 0,o={appearanceInfo:T_(e==null?void 0:e.appearanceInfo,{assetId:n,imageSource:t.imageSource,pippitAssetId:r})};if(r){let s={pippitAssetId:r,type:"image"},i=xt(t.name);n&&(s.assetId=n),i&&(s.name=i),typeof t.metadata=="string"&&(s.metadata=t.metadata),typeof t.isMain=="boolean"&&(s.isMain=t.isMain),Number.isFinite(t.order)&&(s.order=t.order),t.uploadPath&&(s.uploadPath=t.uploadPath),o.sourceInfos=D_(e,s)}return o}function M_(e){return e.map(xt).filter(Boolean).join(",")}function fm(e){let t=xt(e);return t?t.split(",").map(xt).filter(Boolean):null}function $c(e){return e.nodeAssetType===z||e.sourceNodeType===z}var Hr=/<(pippit-asset-id|node-asset)\b(?:[^>]*?\slabel="([^"]*)")?[^>]*>([^<]*)<\/\1>/g;var Wo=/<(pippit-asset-id|node-asset)\b(?:[^>]*?\slabel="([^"]*)")?[^>]*>([^<]*)<\/\1>|<bbox\s+pippit-asset-id="([^"]*)">\s*(\[[^\]]*\])\s*<\/bbox>/g,JH=/^<(pippit-asset-id|node-asset)\b([^>]*)>/i,mm=/([A-Za-z_:][A-Za-z0-9_:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;function ZH(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function L_(e){return e.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}function B_(e){return/^[A-Za-z_:][A-Za-z0-9_:.-]*$/.test(e)}function Wc(e){return!e||typeof e!="object"||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e).map(([t,n])=>[t.trim(),String(n??"").trim()]).filter(([t,n])=>B_(t)&&n))}function eY(e){let t={};mm.lastIndex=0;for(let n of e.matchAll(mm)){let r=String(n[1]??"").trim(),o=String(n[2]??n[3]??"");B_(r)&&(t[r]=L_(o))}return mm.lastIndex=0,t}function Qc(e){let t=JH.exec(e[0]??"");return eY((t==null?void 0:t[2])??"")}function tY(e,t={}){let n={...Wc(e),...Wc(t)};return Object.entries(n).map(([r,o])=>` ${r}="${ZH(o)}"`).join("")}function G_(e){return String(e??"").trim()}function U_({attributes:e,tagId:t,tagName:n}){let r=G_(t);return r?`<${n}${tY(e)}>${r}</${n}>`:""}function z_(e,t){return U_({attributes:t,tagId:e,tagName:"pippit-asset-id"})}function Jc(e,t){return U_({attributes:t,tagId:e,tagName:"node-asset"})}function hm(e){return String(e??"").replace(Hr,(t,n,r,o)=>G_(o)?t:"")}function Qo(e){return P(e)&&(e.episodes===void 0||Xt(e.episodes))}function q_(e){let t=new Set,n=[];for(let r of e??[]){let o=String(r).trim();!o||t.has(o)||(t.add(o),n.push(o))}return n}function nY(e){return P(e)&&_(e.tag)}function F_(e){return e===void 0||Array.isArray(e)&&e.every(nY)}var ue="biz/audio";function Tt(e){let t=typeof e=="string"?Number(e):e;return typeof t=="number"&&Number.isFinite(t)&&t>0?t:void 0}function j_(e){let t=e==null?void 0:e.metadata;return P(t)?t:void 0}function Hi(e){let t=Tt(e);return t===void 0?void 0:t*1e3}function V_(e){let t=j_(e);return Tt(e==null?void 0:e.durationMs)??Tt(t==null?void 0:t.durationMs)??Tt(t==null?void 0:t.durationMS)??Tt(t==null?void 0:t.duration_ms)??Hi(t==null?void 0:t.durationSec)??Hi(t==null?void 0:t.duration_sec)??Hi(t==null?void 0:t.duration)??Hi(t==null?void 0:t.originalDuration)??Hi(t==null?void 0:t.original_duration)}function H_(e){let t=e,n=j_(e);return Tt(t==null?void 0:t.sizeBytes)??Tt(t==null?void 0:t.size_bytes)??Tt(t==null?void 0:t.size)??Tt(n==null?void 0:n.sizeBytes)??Tt(n==null?void 0:n.size_bytes)??Tt(n==null?void 0:n.size)}function rY(e){return e===void 0?!0:P(e)?Ce(e.startMs)&&Ce(e.endMs)&&Ce(e.currentTimeMs)&&Ce(e.playbackRate)&&rt(e.muted)&&rt(e.loop)&&Ce(e.volume):!1}function gm(e){return!P(e)||!_(e.assetId)||!_(e.pippitAssetId)||e.securityCheckScene!==void 0&&!Xt(e.securityCheckScene)||!F_(e.tagInfos)||!$n(e)||!Qo(e)||!Ce(e.durationMs)||!rY(e.playback)||!_(e.waveformKey)||!Vc(e.source)?!1:Object.keys(e).length===0||!!(e.assetId||e.pippitAssetId||e.generation||e.episodes)}var Wn={type:ue,validate:gm,getDefaultSize:()=>({w:362,h:218})};var L="biz/image";function Yi(e){return!(!P(e)||!$n(e)||!Qo(e))}function oY(e){var r,o;let t=e.naturalWidth??((r=e.metadata)==null?void 0:r.width),n=e.naturalHeight??((o=e.metadata)==null?void 0:o.height);return Ho(t,n,{w:420,h:326})??{w:480,h:373}}var En={type:L,validate:Yi,getDefaultSize:oY};var me="biz/image-panorama",sY="equirectangular",Y_=1,ANe=Object.freeze({fov:90,pitch:0,version:Y_,yaw:0});function iY(e){return e===void 0||e===sY}function aY(e){return!P(e)||e.version!==Y_?!1:typeof e.yaw=="number"&&Number.isFinite(e.yaw)&&e.yaw>=-180&&e.yaw<180&&typeof e.pitch=="number"&&Number.isFinite(e.pitch)&&e.pitch>=-85&&e.pitch<=85&&typeof e.fov=="number"&&Number.isFinite(e.fov)&&e.fov>=45&&e.fov<=110}function ym(e){return P(e)&&Yi(e)&&iY(e.projection)&&(e.viewState===void 0||aY(e.viewState))}function dY(e){var r,o;let t=e.naturalWidth??((r=e.metadata)==null?void 0:r.width),n=e.naturalHeight??((o=e.metadata)==null?void 0:o.height);return Ho(t,n,{w:320,h:180})??{w:480,h:270}}var Zc={type:me,validate:ym,getDefaultSize:dY};function K_(e){return e===L||e===me}var cY=new Set(["manual","image-operation","panorama-capture","panorama-grid","scene3d-capture-send"]);function Nt(e,t){return!(!P(e)||!De(e.id)||!e.id.trim()||e.type!=="image"&&e.type!=="video"||t&&e.type!==t||e.status!=="capturing"&&e.status!=="uploading"&&e.status!=="failed"||!_(e.cacheId)||e.cacheId!==void 0&&!e.cacheId.trim()||!_(e.fileName)||!_(e.mimeType)||!_(e.errorMessage)||!_(e.sourceKind)||e.sourceKind!==void 0&&!cY.has(e.sourceKind)||e.uploadPath!==void 0&&e.uploadPath!=="legacy"&&e.uploadPath!=="optimized"||e.size!==void 0&&(!Oe(e.size)||e.size<0)||e.cachedAt!==void 0&&!Oe(e.cachedAt))}function eu(e,t){return Nt(e,t)?e.status==="capturing"||e.status==="uploading":!1}var he="biz/scene",Am=he;var Yr={w:420,h:372};function uY(e){return P(e)&&!("pippitAssetId"in e)&&_(e.name)&&_(e.extra)&&rt(e.isCover)}function X_(e){return Xc(e)}function tu(e){if(!P(e))return;let{content:t}=e;return P(t)&&X_(t.data)?t.data:X_(t)?t:void 0}function $_(e){if(!P(e))return;let t=tu(e);if(t)return e.type=Am,e.content=t,e}var Ki={type:he,validate:uY,getDefaultSize:()=>({...Yr})};var M="biz/video";function vm(e){return!(!P(e)||!$n(e)||!Qo(e))}function pY(e){var r,o;let t=(r=e.metadata)==null?void 0:r.width,n=(o=e.metadata)==null?void 0:o.height;return Ho(t,n,{w:420,h:236})??{w:480,h:270}}var Cn={type:M,validate:vm,getDefaultSize:pY};var lY=new Set([z,he]);function fY(){return new Set([O.t("Pippit_xyqcanvas_legacy_label_role",{},"角色"),O.t("Pippit_xyqcanvas_legacy_label_scene",{},"场景"),O.t("Pippit_xyqcanvas_legacy_label_basic_image",{},"基础形象"),O.t("Pippit_xyqcanvas_legacy_label_default_image",{},"默认形象"),O.t("Pippit_xyqcanvas_legacy_label_master_image",{},"主设定形象"),O.t("Pippit_xyqcanvas_legacy_label_no_character_name_yet",{},"暂无角色名"),O.t("Pippit_xyqcanvas_legacy_label_no_image_name_yet",{},"暂无形象名称"),O.t("Pippit_xyqcanvas_legacy_label_unnamed_role",{},"未命名角色"),O.t("Pippit_xyqcanvas_legacy_label_unnamed_image_name",{},"未命名形象名"),O.t("Pippit_xyqcanvas_legacy_label_unnamed_scene",{},"未命名场景")])}function mY(){return new Set([O.t("Pippit_xyqcanvas_legacy_label_no_image_name_yet",{},"暂无形象名称"),O.t("Pippit_xyqcanvas_legacy_label_unnamed_image_name",{},"未命名形象名"),O.t("Pippit_xyqcanvas_legacy_label_unnamed_scene",{},"未命名场景")])}function ru(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Xi(e){if(e){if(typeof e=="string")try{return Xi(JSON.parse(e))}catch{return}return ru(e)?e:void 0}}function Pn(e){let t=e==null?void 0:e.trim();return t||void 0}function $i(e){if(ru(e))return Pn(typeof e.name=="string"?e.name:void 0)}function Sm(e){let t=e==null?void 0:e.replace(/_\d+$/,"");return!!(t&&fY().has(t))}function nu(e){let t=e==null?void 0:e.replace(/_\d+$/,"");return!!(t&&mY().has(t))}function W_(e,t){let n=e==null?void 0:e[t];return typeof n=="string"?n:void 0}function Q_(e){let t=Xi(e);if(!t)return!0;let n=Xi(t.basicInfo),r=Pn(W_(n,"appearanceName"));if(r)return nu(r);let o=Pn(W_(t,"nodeName"));return!o||nu(o)}function Wi(e){if(!ru(e))return;let t=Xi(e.data);if(e.type===be)return Pn(typeof(t==null?void 0:t.title)=="string"?t.title:void 0);let n=$i(t);return typeof e.type=="string"&&lY.has(e.type)&&Sm(n)?void 0:n}function hY(e){switch(e){case L:return O.t("Pippit_xyqcanvas_legacy_label_picture",{},"图片");case me:return O.t("Pippit_xyqcanvas_legacy_label_panorama",{},"全景图");case M:return O.t("Pippit_xyqcanvas_legacy_title_video",{},"视频");default:return}}function gY(e,t){let n=Xi(t);if(n&&e===M)return Pn(typeof n.title=="string"?n.title:void 0)}function J_(e){if(ru(e))return Wi(e)??gY(e.type,e.data)??hY(e.type)}var Ie="biz/text",Z_={overflow:"wrap",padding:28,verticalAlign:"top"};var yY=new Set(["top","middle","bottom"]),AY=new Set(["clip","wrap","auto-height"]);function vY(e){if(e===void 0)return!0;if(!P(e))return!1;let{verticalAlign:t,overflow:n,padding:r}=e;return!(t!==void 0&&(!De(t)||!yY.has(t))||n!==void 0&&(!De(n)||!AY.has(n))||r!==void 0&&(!Oe(r)||r<0))}function bm(e){return!(!P(e)||"pippitAssetId"in e||!$n(e)||e.plainText!==void 0&&!De(e.plainText)||e.markdownText!==void 0&&!De(e.markdownText)||!_(e.placeholder)||!vY(e.block)||e.plainText===void 0&&e.content!==void 0||e.content!==void 0&&!P(e.content))}var Qn={type:Ie,validate:bm,getDefaultSize:e=>{var t;return{w:420,h:((t=e.block)==null?void 0:t.overflow)==="auto-height"?64:180}}};function Kr(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!=null))}function Ke(e,t){let n=e==null?void 0:e[t];return typeof n=="string"?n:void 0}function ou(e){return typeof e=="object"&&e!==null}function su(e){return ou(e==null?void 0:e.data)?e.data:{}}function Jo(e,t){var a;let n=su(t),r=t!=null&&t.id?(a=e.assets)==null?void 0:a[t.id]:void 0,o=ou(r)?r.content:void 0,s=ou(o)?o:void 0,i=ou(s==null?void 0:s.data)?s.data:s;return i||n}var SY=new Set(["audiourl","coverpreviewurl","coverurl","downloadurl","imageurl","playerinfo","posterurl","previewinfo","previewurl","sceneurls","sourceimageurl","sourceurl","src","thumbnailurl","uri","url","urls","urllist","videourl","waveformurl"]);function Em(e){return Array.isArray(e)?e.map(t=>Em(t)):!e||typeof e!="object"?e:Object.fromEntries(Object.entries(e).flatMap(([t,n])=>SY.has(t.replaceAll("_","").toLowerCase())?[]:[[t,Em(n)]]))}function Jn(e){let t=e.pippitAssetId?Em(e):e;return Kr(t)}function Zo(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Im(e){let t=(Array.isArray(e)?e:e?[e]:[]).map(n=>typeof n=="string"?n.trim():"").filter(Boolean);return t.length?t:void 0}function _m(e){if(!Zo(e.localUploadTask))return;let t=Ke(e.localUploadTask,"uploadPath");if(e.uploadPath!=="optimized"&&t!=="optimized")return;let n=Ke(e.localUploadTask,"status");return n==="capturing"||n==="uploading"?"uploading":void 0}function bY(e,t){if(Nt(e,"image"))return t==="optimized"||e.uploadPath==="optimized"?"uploading":void 0}function Qi(e){if(!Zo(e))return"";if(typeof e.text=="string")return e.text;if(e.type==="hardBreak")return`
|
|
8
|
+
`;if(e.type==="table")return Array.isArray(e.content)?e.content.map(Qi).filter(Boolean).join(`
|
|
9
|
+
`):"";if(e.type==="tableRow")return Array.isArray(e.content)?e.content.map(Qi).join(" "):"";if(e.type==="tableCell"||e.type==="tableHeader")return Array.isArray(e.content)?e.content.map(Qi).filter(Boolean).join(`
|
|
10
|
+
`):"";let t=Array.isArray(e.content)?e.content.map(Qi).filter(Boolean):[];return t.length===0?"":e.type==="doc"||e.type==="bulletList"||e.type==="orderedList"?t.join(`
|
|
11
|
+
`):t.join("")}function nR(e){return(typeof e.plainText=="string"?e.plainText.trim():"")||Qi(e.content).trim()}function IY(e,t,n){return Wi(n??e)??$i(t)??Pn(Ke(t,"title"))??O.t("Pippit_xyqcanvas_legacy_title_text",{},"文本")}function eR(e,t){return Wi(t)??J_(e)??e.id}function _Y(e){var r;let t=$i(e);if(t)return t;let n=(r=e.assetId)==null?void 0:r.trim();return n||O.t("Pippit_xyqcanvas_legacy_label_audio",{},"音频")}function Rm(e){let t=Pn(e);return t&&!Sm(t)?t:void 0}function tR(e){let t=Pn(e);return t&&!nu(t)?t:void 0}function RY(e,t){if(!e)return t;if(!t||t===e)return e;let n=`${e}-`,r=t.startsWith(n)?t.slice(n.length):t;return r?`${e}-${r}`:e}function EY(e,t,n,r){let o=Rm(Wi(r??e))??Rm(Ke(n,"name"))??Rm(t.nodeName),s=tR(Ke(n,"appearanceName"))??(e.type===he?tR(t.nodeName):void 0);return{label:RY(o,s)??e.id,subjectName:o,variantName:s}}function CY(e,t,n,r,o,s){let i=Zo(t.appearanceInfo)?t.appearanceInfo:void 0,a=Zo(t.basicInfo)?t.basicInfo:void 0,d=Ke(i,"assetId"),c=Ke(i,"pippitAssetId"),u=Ke(i,"uploadPath"),p=u==="legacy"||u==="optimized"?u:void 0,{label:l,subjectName:f,variantName:h}=EY(e,t,a,r),m=e.type===z?C_(t):void 0,g=e.type===z?P_(t):void 0;return Jn({id:e.id,type:"image",assetId:d,...n,nodeAssetId:e.id,nodeAssetType:e.type,sourceNodeType:e.type,content:o,pippitAssetId:c,uploadPath:p,uploadStatus:bY(s,p),label:l,metadata:Kr({audioVoiceAssetId:m,audioVoiceDurationMs:g,hasAudioVoice:e.type===z?E_(t):void 0,name:l===e.id?void 0:l,subjectName:f,variantName:h})})}function iu(e,t,n={}){var i,a,d,c,u;if(!e)return;let r=su(e),o=Zo(r.metadata)?r.metadata:{},s=t?{edgeId:t.id,referenceSource:"canvas-edge",sourceNodeId:t.source}:void 0;if(K_(e.type))return Jn({id:e.id,type:"image",assetId:r.assetId,...s,nodeAssetId:e.id,nodeAssetType:e.type,sourceNodeType:e.type,content:n.content,mediaSource:Ke(r,"source"),pippitAssetId:r.pippitAssetId,securityCheckScene:Im(r.securityCheckScene),uploadPath:r.uploadPath,uploadStatus:_m(r),label:eR(e,n.displayNode),metadata:Kr({height:r.naturalHeight??((i=r.metadata)==null?void 0:i.height),name:$i(r)??((a=r.metadata)==null?void 0:a.name)??r.caption,sizeBytes:r.sizeBytes??o.sizeBytes??o.size,width:r.naturalWidth??((d=r.metadata)==null?void 0:d.width)})});switch(e.type){case z:case he:return CY(e,r,s,n.displayNode,n.content,n.localUploadTask);case M:return Jn({id:e.id,type:"video",assetId:r.assetId,...s,nodeAssetId:e.id,nodeAssetType:e.type,sourceNodeType:e.type,content:n.content,coverPreviewKey:r.coverPreviewKey,mediaSource:Ke(r,"source"),pippitAssetId:r.pippitAssetId,securityCheckScene:Im(r.securityCheckScene),uploadPath:r.uploadPath,uploadStatus:_m(r),label:eR(e,n.displayNode),metadata:Kr({width:o.width,height:o.height,durationMs:o.durationMs??o.durationMS,durationSec:o.durationSec??o.duration,fps:o.fps,sizeBytes:o.sizeBytes??o.size})});case ue:return Jn({id:e.id,type:"audio",assetId:r.assetId,...s,nodeAssetId:e.id,nodeAssetType:e.type,sourceNodeType:e.type,content:n.content,pippitAssetId:r.pippitAssetId,securityCheckScene:Im(r.securityCheckScene),uploadPath:r.uploadPath,uploadStatus:_m(r),label:_Y(r),metadata:Kr({durationMs:r.durationMs??((c=r.metadata)==null?void 0:c.durationMs)??((u=r.metadata)==null?void 0:u.durationMS),durationSec:r.durationSec??o.durationSec??o.duration,sizeBytes:r.sizeBytes??o.sizeBytes??o.size})});case Ie:return Jn({id:e.id,type:"text",...s,sourceNodeType:e.type,displayLabel:IY(e,r,n.displayNode),label:nR(r)});default:return}}function au(e,t){var s;if(!t)return;let n=Jo(e,t),r=(s=e.assets)==null?void 0:s[t.id],o=Zo(r)?Ke(r,"pippitAssetId"):void 0;return{...t,data:o&&!Ke(n,"pippitAssetId")?{...n,pippitAssetId:o}:n}}var rR="roleReferenceNodeId";function NY(e){return typeof e=="string"?e.trim():""}function Ji(e){return Array.from(new Set([e.nodeAssetId,e.sourceNodeId,e.pippitAssetId,e.id].map(NY).filter(Boolean)))}function oR(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function sR(e){return String(e??"").trim()}function du(e,t){let n=sR(t);return n?`${e}:${n}`:""}function cu(e){return du("node",e)}function uu(e){var t;return cu(e.sourceNodeId)||cu((t=e.metadata)==null?void 0:t[rR])||du("pippit_asset",e.pippitAssetId)||du("asset",e.assetId)||du("reference",e.id)}function wY(e){return typeof e=="string"?cu(e):oR(e)?e.kind==="node"?cu(e.nodeId):e.kind==="reference"?sR(e.referenceKey):"":""}function Zi(e){if(!(!oR(e)||!Array.isArray(e.inputOrder)))return e.inputOrder}function pu(e){if(!Array.isArray(e))return[];let t=[],n=new Set;return e.forEach(r=>{let o=wY(r);!o||n.has(o)||(n.add(o),t.push(o))}),t}function Cm(e){return e.startsWith("node:")}function OY(e){return{kind:"reference",referenceKey:e}}function iR(e,t){let n=pu(e);if(!n.length)return{changed:!1};let r=[],o=new Set;t.forEach(d=>{let c=uu(d);!c||!Cm(c)||o.has(c)||(o.add(c),r.push(c))});let s=n.some(Cm),i=n.filter(d=>!Cm(d)||o.has(d));return s&&r.forEach(d=>{i.includes(d)||i.push(d)}),{changed:i.length!==n.length||i.some((d,c)=>d!==n[c]),inputOrder:i.length?i.map(OY):void 0}}function aR(e,t){let n=pu(t);if(!n.length)return[...e];let r=new Map(n.map((i,a)=>[i,a])),o=[],s=[];return e.forEach((i,a)=>{let d=uu(i),c=d?r.get(d):void 0;if(c===void 0){s.push(i);return}o.push({index:a,rank:c,reference:i})}),o.sort((i,a)=>i.rank-a.rank||i.index-a.index),[...o.map(({reference:i})=>i),...s]}var DY="xyqLocalImageUploadTask";function dR(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function ea(e){var n,r;let t=(r=dR((n=dR(e))==null?void 0:n.extra))==null?void 0:r[DY];return Nt(t,"image")?t:void 0}function Xr(e){return typeof e=="string"?e.trim():""}function lu(e,t){if(!$c(t))return t;let n=Pt(t.content),r=Xr(n==null?void 0:n.audioNodeId);if(!r)return t;let o=x(e).nodes[r];if(!o||o.type!==ue)return t;let s=Jo(e,o),i=Xr(s==null?void 0:s.pippitAssetId);if(!i)return t;let a=v_(s==null?void 0:s.generation)??(n==null?void 0:n.audioSource),d=Xr(s==null?void 0:s.src),c=H_(s);return{...t,metadata:{...t.metadata??{},...c!==void 0?{audioVoiceSizeBytes:c}:{},[lm]:{assetId:Xr(s==null?void 0:s.assetId)||void 0,audioNodeId:r,...a?{audioSource:a}:{},durationMs:V_(s),name:Xr(s==null?void 0:s.name)||Xr(n==null?void 0:n.audioName)||Xr(s==null?void 0:s.assetId)||void 0,pippitAssetId:i,...c!==void 0?{sizeBytes:c}:{},...d?{url:d}:{}}}}}var Pm=[L,me,z,he],Vwe=new Set(Pm),Hwe=new Set([...Pm,ue]),Ywe=new Set([...Pm,M,ue]);function kY(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function MY(e,t){var r;let n=t!=null&&t.id?(r=e.assets)==null?void 0:r[t.id]:void 0;if(!(!kY(n)||!("content"in n)))return n.content??void 0}function LY(e,t){let n=pu(t);if(!n.length)return;let r=[],o=new Set;if(e.forEach(s=>{let i=uu(s);!i||o.has(i)||(o.add(i),r.push(i))}),r.length===n.length)return n.every(s=>o.has(s))?t:void 0}function fu(e,t){let n=x(e),r=n.nodes[t],o=Zi(r==null?void 0:r.data)??Zi(Jo(e,r)),s=Object.values(n.edges).filter(i=>i.target===t).map(i=>{let a=n.nodes[i.source],d=iu(au(e,a),i,{content:MY(e,a),displayNode:a,localUploadTask:ea(a!=null&&a.id?e.assets[a.id]:void 0)});return d?lu(e,d):void 0}).filter(i=>!!i);return aR(s,LY(s,o))}var mu="generation.normalizeInputOrder";function es(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function BY(e){return e===L||e===M}function cR(e,t){var o;if(!es(e)||!Zi(e))return{changed:!1,data:e};let n=iR(e.inputOrder,t);if(!n.changed)return{changed:!1,data:e};let r={...e};return(o=n.inputOrder)!=null&&o.length?r.inputOrder=n.inputOrder:delete r.inputOrder,{changed:!0,data:r}}function GY(e){let t=x(e),n=!1;return Object.values(t.nodes).forEach(r=>{if(!BY(r.type))return;let o=fu(e,r.id),s=cR(r.data,o);s.changed&&es(r.data)&&es(s.data)&&(et(r.data,s.data),n=!0);let i=e.assets[r.id];if(!es(i)||!es(i.content))return;let a=cR(i.content,o);a.changed&&es(a.data)&&(et(i.content,a.data),n=!0)}),n}function UY(e){e.transact(t=>{GY(t)},{intent:mu,undoable:!1,source:"local"})}function uR(e){return e.subscribe(({transaction:t})=>{t.intent!==mu&&UY(e)})}function xm(e){return String(e??"").trim()}function pR(e){let t=xm(e.type),n=xm(e.sourceNodeType),r=xm(e.nodeAssetType);return t==="audio"||n===ue||r===ue?"audio":t==="video"||n===M||r===M?"video":"image"}function Be(e){return String(e??"").trim()}var zY=new RegExp("^(\\u56fe\\u7247|\\u89c6\\u9891|\\u97f3\\u9891|\\u6587\\u4ef6)\\s+(\\d+)$");function $r(e){return Be(e).replace(zY,"$1$2")}var qY="camera-motion:";function FY(e){return Be(e).startsWith(qY)}function lR(e,t,n){let r=Be(e);if(!r)return"";let o=$r(t),s=Wc(n);return o&&FY(r)&&(s.label=o),z_(r,s)}function fR(e,t){let n=Be(e);return Jc(n,t)}var jY=String.fromCharCode(35270,39057),mR=/【\s*@?\s*(图片|图|视频)\s*(\d+)\s*】|@\s*(图片|图|视频)\s*(\d+)|(图片|图|视频)\s*(\d+)/g;function VY(e){return Be(e.sourceNodeId)||Be(e.nodeAssetId)||Be(e.pippitAssetId)||Be(e.id)||Be(e.name)}function HY({mentionItems:e,mentionSourceItems:t}){let n=[],r=new Set,o=s=>{s==null||s.forEach(i=>{let a=VY(i);!a||r.has(a)||(r.add(a),n.push(i))})};return o(e),Object.values(t??{}).forEach(o),n}function YY(e){return e===jY?"video":"image"}function KY(e,t){return t==="video"?e.type==="video":e.type==="image"||e.type==="character"}function XY(e,t,n){if(!Number.isInteger(n)||n<=0)return;let r=e.filter(o=>KY(o,t))[n-1];return r?{...r,label:r.name}:void 0}function $Y(e,t){let n=$r(t.replace(/[【】@]/g,"").trim());if(!n)return;let r=e.find(o=>[$r(o.name),$r(o.originalName),$r(o.displayName)].some(s=>s==null?void 0:s.includes(n)));return r?{...r,label:r.name}:void 0}function WY(e){if(!e)return"";let t=Be(e.nodeAssetId)||Be(e.sourceNodeId);if(t)return fR(t);let n=Be(e.pippitAssetId)||Be(e.id);return n?lR(n,$r(e.label)):""}function hR(e,t){return mR.lastIndex=0,e.replace(mR,(n,...r)=>{let[o,s,i,a,d,c]=r,u=Be(o||i||d),p=Be(s||a||c),l=Number.parseInt(p,10),f=XY(t,YY(u),l),h=$Y(t,n);return WY(f??h)||n})}function gR(e,t={}){let n=String(e??""),r=HY(t);if(!n||!r.length)return{changed:!1,value:n};let o=!1,s=0,i=[];Hr.lastIndex=0;for(let c of n.matchAll(Hr)){let u=c.index??0,p=c[0]||"",l=n.slice(s,u),f=hR(l,r);o||=f!==l,i.push(f,p),s=u+p.length}Hr.lastIndex=0;let a=n.slice(s),d=hR(a,r);return o||=d!==a,i.push(d),{changed:o,value:o?i.join(""):n}}var hu="generation.normalizePromptMentionContent";function Wr(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function wt(e){return String(e??"").trim()}function QY(e){return wt(e)===A_.CanvasMentionText}function JY(e){let t=wt(e);return t==="video"||t==="audio"||t==="text"?t:"image"}function ZY(e,t){let n=wt(e.label)||wt(e.sourceNodeId)||wt(e.nodeAssetId)||wt(e.pippitAssetId)||wt(e.id)||`material-${t+1}`;return{id:wt(e.id)||wt(e.sourceNodeId)||wt(e.nodeAssetId)||wt(e.pippitAssetId)||n,name:n,originalName:n,type:pR(e),nodeAssetId:e.nodeAssetId||e.sourceNodeId,nodeAssetType:e.nodeAssetType,pippitAssetId:e.pippitAssetId,sourceNodeId:e.sourceNodeId,sourceNodeType:e.sourceNodeType}}function eK(e){return(e??[]).map((t,n)=>ZY({...t,type:JY(t.type)},n))}function tK(e,t={}){if(!Wr(e)||!Wr(e.generation))return{changed:!1,data:e};let n=e.generation;if(!QY(n.promptContentFormat))return{changed:!1,data:e};let r={...n};delete r.promptContentFormat;let o=typeof n.prompt=="string"?n.prompt:void 0;if(o===void 0)return{changed:!0,data:{...e,generation:r}};let s=eK(t.mentionReferences),i=gR(o,{mentionItems:s});return r.prompt=i.value,{changed:!0,data:{...e,generation:r}}}function yR(e){return e===L||e===M}function AR(e,t,n){return tK(n,{mentionReferences:fu(e,t)})}function nK(e){let t=x(e),n=!1;return Object.values(t.nodes).forEach(r=>{if(!yR(r.type)||!Wr(r.data))return;let o=AR(e,r.id,r.data);o.changed&&Wr(o.data)&&(et(r.data,o.data),n=!0)}),Object.entries(e.assets).forEach(([r,o])=>{if(!Wr(o)||!Wr(o.content))return;let s=t.nodes[r],i=typeof o.type=="string"?o.type:s==null?void 0:s.type;if(!yR(i))return;let a=AR(e,r,o.content);a.changed&&Wr(a.data)&&(et(o.content,a.data),n=!0)}),n}function rK(e){e.transact(t=>{nK(t)},{intent:hu,undoable:!1,source:"local"})}function vR(e){return e.subscribe(({transaction:t})=>{t.intent!==hu&&rK(e)})}var ta="link",oK=new Set(["http:","https:","mailto:","tel:"]),sK=/^[a-z][a-z\d+.-]*:/i;function iK(e){return sK.test(e)}function aK(e){return e.startsWith("/")||e.startsWith("#")||e.startsWith("?")}function gu(e){if(typeof e!="string")return null;let t=e.trim();if(!t||aK(t))return null;let n=iK(t)?t:`https://${t}`;try{let r=new URL(n);return!oK.has(r.protocol)||(r.protocol==="http:"||r.protocol==="https:")&&!r.hostname?null:n}catch{return null}}function SR(e){return e.replace(/[()\s]/g,t=>encodeURIComponent(t))}function bR(e,t){let n=gu(t);return n?`[${e}](${SR(n)})`:e}function dK(e){return e.type==="paragraph"||e.type==="heading"||e.type==="listItem"||e.type==="bulletList"||e.type==="orderedList"||e.type==="blockquote"||e.type==="table"||e.type==="tableRow"}function ts(e){var t,n,r;if(!e)return"";if(typeof e.text=="string"){let o=(r=(n=(t=e.marks)==null?void 0:t.find(s=>s.type===ta))==null?void 0:n.attrs)==null?void 0:r.href;return bR(e.text,o)}return e.type==="table"?(e.content??[]).map(ts).filter(Boolean).join(`
|
|
12
|
+
`):e.type==="tableRow"?(e.content??[]).map(ts).join(" "):e.type==="tableCell"||e.type==="tableHeader"?(e.content??[]).map(ts).filter(Boolean).join(`
|
|
13
|
+
`):(e.content??[]).flatMap((o,s)=>{let i=ts(o);return s>0&&dK(o)?[`
|
|
14
|
+
`,i]:[i]}).join("")}var cK="markdown",uK=/\\([\\`*_[\]{}()#+\-.!>~|])/g;function pK(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function lK(e){return typeof e=="string"&&e.trim().toLowerCase()===cK}function fK(e){if(typeof e.markdownText=="string")return e.markdownText;if(typeof e.plainText=="string")return e.plainText}function IR(e){return{type:"paragraph",...e?{content:[{type:"text",text:e}]}:{}}}function CR(e,t){let n=0;for(let r=t-1;r>=0&&e[r]==="\\";r-=1)n+=1;return n%2===1}function mK(e){let t=e.trim(),n=0,r=t.length;return t[n]==="|"&&(n+=1),r>n&&t[r-1]==="|"&&!CR(t,r-1)&&(r-=1),t.slice(n,r)}function Nm(e){let t=mK(e),n=[],r="";for(let o=0;o<t.length;o+=1){let s=t[o];if(s==="|"&&!CR(t,o)){n.push(r.trim()),r="";continue}r+=s}return n.push(r.trim()),n}function wm(e){let t=Nm(e);if(t.length<2)return null;let n=[];for(let r of t){let o=r.trim();if(!/^:?-{3,}:?$/.test(o))return null;let s=o.startsWith(":"),i=o.endsWith(":");n.push(s&&i?"center":i?"right":s?"left":null)}return n}function PR(e,t){let n=e[t]??"",r=e[t+1]??"";return n.includes("|")&&wm(r)!==null}function xR(e){return/^\s{0,3}([-*_])(\s*\1){2,}\s*$/.test(e)}function hK(e){return!!(/^\s*(```|~~~)/.test(e)||/^( {4}|\t)\S/.test(e)||/^\s{0,3}#{5,6}\s+/.test(e)||/^\s{0,3}>\s*>/.test(e)||/^\s{2,}([-+*]|\d+[.)])\s+/.test(e)||/^\s{0,3}[-+*]\s+\[[ xX]\]\s+/.test(e)||/^\s{0,3}<[A-Za-z][^>]*>/.test(e))}function gK(e){return/!\[[^\]]*]\([^)]+\)/.test(e)||/`/.test(e)}function ra(e){return hK(e)||gK(e)}function _R(e,t){return e.some(n=>n.type===t.type)?e:[...e,t]}function Tm(e,t){let n=e.replace(uK,"$1");return n?[{type:"text",text:n,...t.length?{marks:t}:{}}]:[]}function Om(e,t,n){let r=e.indexOf(t,n);for(;r>0&&e[r-1]==="\\";)r=e.indexOf(t,r+t.length);return r}function yK(e){let t=[{delimiter:"**",mark:{type:"bold"}},{delimiter:"__",mark:{type:"bold"}},{delimiter:"~~",mark:{type:"strike"}},{delimiter:"*",mark:{type:"italic"}},{delimiter:"_",mark:{type:"italic"}}],n=null;for(let r=0;r<e.length;r+=1){if(e[r]==="\\"){r+=1;continue}for(let o of t){if(!e.startsWith(o.delimiter,r))continue;let s=Om(e,o.delimiter,r+o.delimiter.length);s<=r+o.delimiter.length||(!n||r<n.open||o.delimiter.length>n.delimiter.length)&&(n={...o,close:s,open:r})}if((n==null?void 0:n.open)===r)return n}return n}function AK(e){for(let t=0;t<e.length;t+=1){if(e[t]==="\\"){t+=1;continue}if(e[t]!=="["||e[t-1]==="!")continue;let n=Om(e,"]",t+1);if(n<=t+1||e[n+1]!=="(")continue;let r=Om(e,")",n+2);if(r<=n+2)continue;let o=gu(e.slice(n+2,r).trim());if(o)return{close:r,href:o,label:e.slice(t+1,n),open:t}}return null}function na(e,t=[]){let n=AK(e),r=yK(e);if(n&&(!r||n.open<=r.open)){let d={type:ta,attrs:{href:n.href}};return[...Tm(e.slice(0,n.open),t),...na(n.label,_R(t,d)),...na(e.slice(n.close+1),t)]}if(!r)return Tm(e,t);let{close:o,delimiter:s,mark:i,open:a}=r;return[...Tm(e.slice(0,a),t),...na(e.slice(a+s.length,o),_R(t,i)),...na(e.slice(o+s.length),t)]}function yu(e,t,n){let r=na(t);return{type:e,...n?{attrs:n}:{},...r.length?{content:r}:{}}}function Dm(e){return!e.trim()}function TR(e){return e.match(/^\s{0,3}(#{1,4})\s+(.+?)\s*#*\s*$/)}function km(e){return e.match(/^\s{0,3}[-+*]\s+(.+)$/)}function Mm(e){return e.match(/^\s{0,3}\d+[.)]\s+(.+)$/)}function Lm(e){return e.match(/^\s{0,3}>\s?(.*)$/)}function vK(e){return{type:"listItem",content:[yu("paragraph",e)]}}function SK(e,t,n){return{type:e,attrs:{colspan:1,rowspan:1,colwidth:null,...n?{align:n}:{}},content:[yu("paragraph",t)]}}function RR(e,t,n,r){return{type:"tableRow",content:Array.from({length:r},(o,s)=>SK(e,t[s]??"",n[s]??null))}}function bK(e,t){let n=wm(e[t+1]??"");if(!n||!(e[t]??"").includes("|"))return null;let r=Nm(e[t]??""),o=[],s=t+2;for(;s<e.length;){let d=e[s];if(Dm(d)||ra(d)||!d.includes("|")||wm(d))break;o.push(Nm(d)),s+=1}let i=Math.max(r.length,n.length,...o.map(d=>d.length)),a=[RR("tableHeader",r,n,i),...o.map(d=>RR("tableCell",d,n,i))];return{nextIndex:s,node:{type:"table",content:a}}}function ER(e,t,n){let r=[],o=t;for(;o<e.length&&!ra(e[o]);){let s=n?Mm(e[o]):km(e[o]);if(!s)break;r.push(vK(s[1]??"")),o+=1}return{nextIndex:o,node:{type:n?"orderedList":"bulletList",content:r}}}function IK(e,t,n){let r=[],o=t;for(;o<e.length&&!ra(e[o]);){let s=Lm(e[o]);if(!s)break;r.push(s[1]??""),o+=1}return{nextIndex:o,node:{type:"blockquote",content:n(r)}}}function _K(e){return!!(xR(e)||TR(e)||Lm(e)||km(e)||Mm(e))}function RK(e,t){let n=[],r=t;for(;r<e.length&&!Dm(e[r])&&!ra(e[r])&&!_K(e[r])&&!PR(e,r);)n.push(e[r].trim()),r+=1;return{nextIndex:r,node:yu("paragraph",n.join(" "))}}function NR(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(Dm(r)){n+=1;continue}if(ra(r)){t.push(IR(r)),n+=1;continue}if(xR(r)){t.push({type:"horizontalRule"}),n+=1;continue}let o=PR(e,n)?bK(e,n):null;if(o){t.push(o.node),n=o.nextIndex;continue}let s=TR(r);if(s){t.push(yu("heading",s[2]??"",{level:s[1].length})),n+=1;continue}if(Lm(r)){let u=IK(e,n,NR);t.push(u.node),n=u.nextIndex;continue}if(km(r)){let u=ER(e,n,!1);t.push(u.node),n=u.nextIndex;continue}if(Mm(r)){let u=ER(e,n,!0);t.push(u.node),n=u.nextIndex;continue}let c=RK(e,n);t.push(c.node),n=c.nextIndex}return t.length?t:[IR("")]}function EK(e){return{type:"doc",content:NR(e.replace(/\r\n/g,`
|
|
15
|
+
`).split(`
|
|
16
|
+
`))}}function Zn(e){if(!pK(e)||!lK(e.contentFormat))return{changed:!1,data:e};let t=fK(e),n={...e};if(delete n.contentFormat,t===void 0)return{changed:!0,data:n};let r=EK(t),o=ts(r);return{changed:!0,data:{...n,content:r,markdownText:typeof n.markdownText=="string"?n.markdownText:t,plainText:o}}}var Au="text.normalizeMarkdownContent";function Bm(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function CK(e){let t=x(e),n=!1;return Object.entries(t.nodes).forEach(([r,o])=>{if(o.type!==Ie||!Bm(o.data))return;let s=Zn(o.data);s.changed&&(o.data=s.data,n=!0)}),Object.entries(e.assets).forEach(([r,o])=>{var a;if(!Bm(o)||!Bm(o.content)||(typeof o.type=="string"?o.type:(a=t.nodes[r])==null?void 0:a.type)!==Ie)return;let i=Zn(o.content);i.changed&&(o.content=i.data,n=!0)}),n}function PK(e){e.transact(t=>{CK(t)},{intent:Au,undoable:!1,source:"local"})}function wR(e){return e.subscribe(({transaction:t})=>{t.intent!==Au&&PK(e)})}function xK(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function OR(e,t,n="media.localUploadTask.clear",r={}){return e.transact(o=>{let s=o.assets[t],i=xK(s==null?void 0:s.content)?s.content:void 0;!i||!Object.prototype.hasOwnProperty.call(i,"localUploadTask")||delete i.localUploadTask},{intent:n,mergeKey:`local-upload-task:${t}`,...r.system?{source:"system",undoable:!1}:{}})}var DR="role-scene",bDe=[DR,...Fd];function TK(e){return e===DR||Tr(e)}function kR(e){var n;let t=(n=x(e).settings.autoLayout)==null?void 0:n.strategy;return typeof t=="string"&&t.trim()||void 0}function MR({configuredStrategies:e,storedStrategy:t}){if(e!=null&&e.length)return TK(t)&&e.includes(t)?t:e[0]}var NK="canvas is read-only";function LR(e){return(t,n)=>{if(t.source==="remote"||t.intent===Au||t.intent===mu||t.intent===hu){n();return}throw t.source==="local"&&(e==null||e()),new Te(NK,"READ_ONLY")}}function BR(e,t){let n=kR(e.getState()),r=MR({configuredStrategies:t,storedStrategy:n});!r||n===r||e.transact(o=>{let{settings:s}=x(o);s.autoLayout={...s.autoLayout,strategy:r}},{intent:"settings.normalizeAutoLayoutStrategy",undoable:!1})}function GR(e,t=!1){return Object.values(x(e).nodes).some(n=>{var s,i;if(!t){if(n.type!==L)return!1;let a=(s=ui(e,n))==null?void 0:s.data;return eu(a==null?void 0:a.localUploadTask,"image")}if(n.type===z||n.type===he)return eu(ea(e.assets[n.id]),"image");let r;if(n.type===L?r="image":n.type===M&&(r="video"),!r)return!1;let o=(i=ui(e,n))==null?void 0:i.data;return eu(o==null?void 0:o.localUploadTask,r)})}function UR(e,t){var n,r;for(let o of Object.values(x(e).nodes)){if(o.type!==L)continue;let s=(r=(n=ui(e,o))==null?void 0:n.data)==null?void 0:r.localUploadTask;Nt(s,"image")&&s.status==="capturing"&&!s.cacheId&&OR(t,o.id,"image.upload.clearRestoredCapturingTask")}}var qR="biz/auto-layout";function zR(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function wK(e){let t={};if(!e)return t;Tr(e.strategy)&&(t.strategy=e.strategy);let n=zR(e.horizontalGap);n!==void 0&&(t.horizontalGap=n);let r=zR(e.verticalGap);return r!==void 0&&(t.verticalGap=r),t}var Gm={type:qR,run:e=>{e.commands.autoLayoutNodes(wK(e.directive.params))}};var FR="biz/layout-group",OK="horizontal-directed-cluster",DK=["horizontal","vertical","grid","horizontal-directed-cluster","vertical-directed-cluster"];function kK(e){return DK.includes(e)?e:void 0}function MK(e){return e==="vertical-directed-cluster"||e==="horizontal-directed-cluster"?e:OK}var Um={type:FR,run:e=>{var r,o;if(e.carrier.kind!=="node")return;let t=e.store.getRootCanvasContent().nodes[e.carrier.nodeId];if((t==null?void 0:t.type)!==be)return;let n=kK((r=e.directive.params)==null?void 0:r.strategy)??MK((o=e.store.getRootCanvasContent().settings.autoLayout)==null?void 0:o.strategy);e.commands.arrangeNodes([e.carrier.nodeId],n)}};var VR="biz/resize-node";function jR(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}var zm={type:VR,run:e=>{if(e.carrier.kind!=="node")return;let t=e.directive.params??{},n=jR(t.w),r=jR(t.h);n===void 0||r===void 0||e.commands.resizeNode(e.carrier.nodeId,{w:n,h:r})}};var HR=Ml(),LK=[Gm,zm,Um];for(let e of LK)HR.register(e);function qm(){return HR}function ns(e){return String(e??"").trim()}function Fm(e){return Array.from(new Set(e.map(ns).filter(Boolean)))}function YR(e,t){let n=hm(e),r=new Set(t.map(ns).filter(Boolean));return r.size===0?n:n.replace(Hr,(o,s,i,a)=>s==="node-asset"&&r.has(ns(a))?"":o)}function KR({nextSelectableSelection:e,previousDefaultSelection:t,prompt:n,reference:r,selectionReplacements:o}){let s=new Set(Ji(r));if(!s.size)return{explicitSelection:[],hasRoleMention:!1,prompt:n};let i=Object.fromEntries(Object.entries(o??{}).map(([p,l])=>[ns(p),ns(l)]).filter(([p,l])=>p&&p!==l)),a=[],d=!1,c=0,u=[];Wo.lastIndex=0;for(let p of String(n??"").matchAll(Wo)){let l=p.index??0;u.push(n.slice(c,l)),c=l+p[0].length;let f=ns(p[3]);if(p[1]!=="node-asset"||!s.has(f)){u.push(p[0]);continue}d=!0;let h=Qc(p);if(!(Vi in h)){u.push(p[0]);continue}let m=Fm(fm(h[Vi])??[]),g=Fm(m.map(y=>i[y]??y));a.push(...g),g.length&&u.push(Jc(f,{...h,[Vi]:M_(g)}))}return Wo.lastIndex=0,u.push(n.slice(c)),{explicitSelection:Fm(a),hasRoleMention:d,prompt:u.join("")}}function BK(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function GK(e){return e===L||e===M||e===ue}function UK(e,t){let{nodes:n}=x(e),r=new Set,o=s=>{if(r.has(s))return;let i=n[s];if(!i)return;r.add(s);let{children:a}=i;Array.isArray(a)&&a.forEach(o)};return t.forEach(o),r}function zK(e,t){let n=x(e),r=UK(e,t);return r.size===0?[]:Object.values(n.nodes).flatMap(o=>{if(r.has(o.id)||!GK(o.type))return[];let s=ci(e,o.id),i=BK(s==null?void 0:s.generation)?s.generation:void 0,a=typeof(i==null?void 0:i.prompt)=="string"?i.prompt:void 0;if(a===void 0)return[];let d=YR(a,[...r]);return d===a?[]:[{generation:{...i,prompt:d},nodeId:o.id}]})}function XR(e){let{deleteNodes:t}=e.commands,n=r=>{let o=zK(e.getState(),r);return o.length===0?t(r):e.commands.batch("node.delete",s=>{t(r),o.forEach(({generation:i,nodeId:a})=>{s.updateNodeData(a,{generation:i})})})};return e.commands.deleteNodes=n,()=>{e.commands.deleteNodes===n&&(e.commands.deleteNodes=t)}}function qK(...e){let[t="",...n]=e,r=n.map(o=>o.replace(/^\/+|\/+$/g,"")).filter(Boolean).join("/");return r?`${t.replace(/\/+$/g,"")}/${r}`:t}function jm(e=""){return qK(vo.TOS.cmsStaticAssetBaseUrl,e)}function X(e){return{coverImageUrl:jm(`${e}.webp`),previewVideoUrl:jm(`${e}.mp4`)}}var FK={static_shot:X("01_%E5%9B%BA%E5%AE%9A%E9%95%9C%E5%A4%B4"),tilt_up:X("02_%E9%95%9C%E5%A4%B4%E4%B8%8A%E6%91%87"),tilt_down:X("03_%E9%95%9C%E5%A4%B4%E4%B8%8B%E6%91%87"),pan_left:X("04_%E9%95%9C%E5%A4%B4%E5%B7%A6%E6%91%87"),pan_right:X("05_%E9%95%9C%E5%A4%B4%E5%8F%B3%E6%91%87"),crane_up:X("06_%E9%95%9C%E5%A4%B4%E4%B8%8A%E5%8D%87"),crane_down:X("07_%E9%95%9C%E5%A4%B4%E4%B8%8B%E9%99%8D"),truck_left:X("08_%E9%95%9C%E5%A4%B4%E5%B7%A6%E7%A7%BB"),truck_right:X("09_%E9%95%9C%E5%A4%B4%E5%8F%B3%E7%A7%BB"),dolly_in:X("10_%E9%95%9C%E5%A4%B4%E5%89%8D%E6%8E%A8"),dolly_out:X("11_%E9%95%9C%E5%A4%B4%E5%90%8E%E7%A7%BB"),zoom_in:X("12_%E5%8F%98%E7%84%A6%E6%8E%A8%E8%BF%9B"),zoom_out:X("13_%E5%8F%98%E7%84%A6%E6%8B%89%E8%BF%9C"),follow_tracking:X("14_%E8%B7%9F%E9%9A%8F%E6%8B%8D%E6%91%84"),leading_tracking:X("15_%E8%BF%8E%E9%9D%A2%E8%B7%9F%E6%8B%8D"),profile_tracking:X("16_%E4%BE%A7%E9%9D%A2%E8%B7%9F%E6%8B%8D"),handheld_shot:X("17_%E6%89%8B%E6%8C%81%E6%8B%8D%E6%91%84"),pov_shot:X("18_%E7%AC%AC%E4%B8%80%E8%A7%86%E8%A7%92"),steadicam_walkthrough:X("19_%E7%A8%B3%E5%AE%9A%E5%99%A8%E8%A1%8C%E8%BF%9B"),slider_reveal:X("20_%E6%A8%AA%E6%BB%91%E6%8F%AD%E7%A4%BA"),foreground_wipe:X("21_%E5%89%8D%E6%99%AF%E6%93%A6%E8%BF%87"),push_through:X("22_%E7%A9%BF%E8%B6%8A%E9%95%9C%E5%A4%B4"),whip_pan:X("23_%E7%94%A9%E6%91%87"),rack_focus:X("24_%E7%84%A6%E7%82%B9%E8%BD%AC%E7%A7%BB"),crash_zoom:X("25_%E6%80%A5%E9%80%9F%E5%8F%98%E7%84%A6"),dolly_zoom:X("26_%E6%9F%AF%E5%85%8B%E5%8F%98%E7%84%A6"),orbit_180:X("27_%E7%8E%AF%E7%BB%95%E6%8B%8D%E6%91%84"),ascending_orbit:X("28_%E7%9B%98%E6%97%8B%E6%8A%AC%E5%8D%87"),descending_orbit:X("29_%E7%9B%98%E6%97%8B%E4%B8%8B%E9%99%8D"),aerial_establishing:X("30_%E9%AB%98%E7%A9%BA%E8%88%AA%E6%8B%8D"),fpv_flythrough:X("31_%E7%A9%BF%E8%B6%8A%E6%9C%BA%E8%BF%90%E9%95%9C"),drone_dive:X("32_%E4%BF%AF%E5%86%B2%E4%B8%8B%E9%99%8D"),pull_away:X("33_%E6%8B%89%E5%8D%87%E7%A6%BB%E5%9C%BA")};function $R(e){let t=FK[e.id];return t?{...e,url:t.coverImageUrl,previewVideoUrl:t.previewVideoUrl}:e}var eE=["AnyDream_2.0","anycook_1_standard","anycook_1_creative","seedream_5.0_pro","NanoPro","Nano2"],tE=[{value:"auto"},{value:"21:9"},{value:"16:9"},{value:"9:16"},{value:"3:4"},{value:"4:3"},{value:"3:2"},{value:"2:3"},{value:"1:1"}],nE=[{value:"1K"},{value:"2K"},{value:"3K"},{value:"4K"}],VK=[{value:"3K"},{value:"4K"}],HK=[{value:"1K"},{value:"2K"},{value:"4K"}],YK=[{value:"1K"},{value:"2K"},{value:"4K"}],Hm={aspectRatio:tE,resolution:nE},WR={...Hm,resolution:VK},QR={...Hm,resolution:HK},KK={...Hm,resolution:YK},vu={aspectRatio:"9:16",resolution:"3K"},JR={...vu,resolution:"2K"},XK={...vu,resolution:"1K"},$K={maxImageReferences:10},oa=["text_to_image","image_to_image"],WK=["image_to_image"],rE=[{modelId:"AnyDream_2.0",modelKind:"image",modes:oa,defaultMode:"text_to_image",settingOptions:WR,defaultSettings:vu},{modelId:"anycook_1_standard",modelKind:"image",modes:oa,defaultMode:"text_to_image",settingOptions:WR,defaultSettings:vu},{modelId:"anycook_1_creative",modelKind:"image",modes:WK,defaultMode:"image_to_image",referenceLimits:{minImageReferences:1}},{modelId:"seedream_5.0_pro",modelKind:"image",modes:oa,defaultMode:"text_to_image",referenceLimits:$K,settingOptions:KK,defaultSettings:XK},{modelId:"NanoPro",modelKind:"image",modes:oa,defaultMode:"text_to_image",settingOptions:QR,defaultSettings:JR},{modelId:"Nano2",modelKind:"image",modes:oa,defaultMode:"text_to_image",settingOptions:QR,defaultSettings:JR}];var ZK=[{value:"480p"},{value:"720p"},{value:"1080p"}],eX=[{value:"auto"},{value:"16:9"},{value:"4:3"},{value:"1:1"},{value:"3:4"},{value:"9:16"}];function tX(e,t){return{...e,aspectRatio:eX,resolution:ZK,durationSec:t}}function nX(e){return{...e,aspectRatio:"auto",resolution:"720p",durationSec:10}}function oE({durationOptions:e,modes:t,standardVideoDefaultSettings:n,standardVideoSettings:r}){return{modelId:"wan3.0",modelKind:"video",modes:t,defaultMode:"text_to_video",referenceLimits:{maxImageReferences:10},settingOptions:tX(r,e),defaultSettings:nX(n)}}var iX={auto:void 0,"16:9":2,"21:9":8,"9:16":3,"3:4":5,"4:3":4,"3:2":void 0,"2:3":void 0,"1:1":6},aX={2:"16:9",8:"21:9",3:"9:16",4:"4:3",5:"3:4",6:"1:1"},dX=["seedance_1.0","seedance1.5_direct","Seedance_2.0_mini_lite","Seedance_2.0_lite","seedance2.0_direct","seedance2.0_fast_direct","seedance2.0_vision","seedance2.0_fast_vision","Seedance_2.5","MiniMax-H3","wan3.0","happyhorse-1.1"],cX=[{value:"auto"},{value:"16:9"},{value:"21:9"},{value:"9:16"},{value:"4:3"},{value:"3:4"},{value:"1:1"}],uX=[{value:"480p"},{value:"720p_lite"},{value:"720p"}],pX=[{value:"720p"},{value:"1080p"},{value:"4k"}],lX=[{value:"480p"},{value:"720p"},{value:"1080p"},{value:"4k"}],fX=[{value:"768p"},{value:"2k"}],mX=[{value:"720p"},{value:"1080p"}],Km=[{value:4},{value:5},{value:6},{value:7},{value:8},{value:9},{value:10},{value:11},{value:12},{value:13},{value:14},{value:15}],hX=[{value:3},...Km],iE=[...Km,{value:16},{value:17},{value:18},{value:19},{value:20},{value:21},{value:22},{value:23},{value:24},{value:25},{value:26},{value:27},{value:28},{value:29},{value:30}],gX=[{value:!1},{value:!0}];var yX=[{id:"static_shot",label:"固定镜头",promptValue:"固定镜头",tag:"基础控制",desc:"建立冷静秩序",submitPromptText:"运镜:固定机位,镜头位置和拍摄方向都保持不变,画面构图稳定,由主体动作或画面内部变化形成运动感。"},{id:"tilt_up",label:"镜头上摇",promptValue:"镜头上摇",tag:"基础控制",desc:"展示高度威压",submitPromptText:"运镜:固定机位上摇,镜头位置不移动,只沿垂直方向缓慢向上转动,画面重心从下方逐步移向上方。"},{id:"tilt_down",label:"镜头下摇",promptValue:"镜头下摇",tag:"基础控制",desc:"从环境落到人",submitPromptText:"运镜:固定机位下摇,镜头位置不移动,只沿垂直方向缓慢向下转动,画面重心从上方逐步移向下方。"},{id:"pan_left",label:"镜头左摇",promptValue:"镜头左摇",tag:"基础控制",desc:"横向展示空间",submitPromptText:"运镜:固定机位左摇,镜头位置不移动,只沿水平方向缓慢向左转动,让画面内容从右向左连续变化。"},{id:"pan_right",label:"镜头右摇",promptValue:"镜头右摇",tag:"基础控制",desc:"引出画外信息",submitPromptText:"运镜:固定机位右摇,镜头位置不移动,只沿水平方向缓慢向右转动,让画面内容从左向右连续变化。"},{id:"crane_up",label:"镜头上升",promptValue:"镜头上升",tag:"基础控制",desc:"展开场景规模",submitPromptText:"运镜:镜头垂直上升,拍摄方向基本保持稳定,机位高度从低到高变化,画面视角随高度产生变化。"},{id:"crane_down",label:"镜头下降",promptValue:"镜头下降",tag:"基础控制",desc:"从全局聚焦",submitPromptText:"运镜:镜头垂直下降,拍摄方向基本保持稳定,机位高度从高到低变化,画面视角随高度产生变化。"},{id:"truck_left",label:"镜头左移",promptValue:"镜头左移",tag:"基础控制",desc:"制造空间视差",submitPromptText:"运镜:镜头左移,机位整体向左横向平移,拍摄方向基本不变,前景与背景形成自然视差。"},{id:"truck_right",label:"镜头右移",promptValue:"镜头右移",tag:"基础控制",desc:"制造空间视差",submitPromptText:"运镜:镜头右移,机位整体向右横向平移,拍摄方向基本不变,前景与背景形成自然视差。"},{id:"dolly_in",label:"镜头前推",promptValue:"镜头前推",tag:"基础控制",desc:"强调情绪靠近",submitPromptText:"运镜:镜头缓慢前推,机位沿镜头朝向向前移动,主体在画面中逐渐变大,空间层次产生自然视差。"},{id:"dolly_out",label:"镜头后移",promptValue:"镜头后移",tag:"基础控制",desc:"展示人物孤独",submitPromptText:"运镜:镜头缓慢后拉,机位沿镜头朝向向后移动,主体在画面中逐渐变小,画面范围逐步变宽。"},{id:"zoom_in",label:"变焦推进",promptValue:"变焦推进",tag:"基础控制",desc:"突出表情反应",submitPromptText:"运镜:缓慢变焦推进,机位保持不动,只通过焦距变化让画面范围逐渐收紧。"},{id:"zoom_out",label:"变焦拉远",promptValue:"变焦拉远",tag:"基础控制",desc:"从局部到全貌",submitPromptText:"运镜:缓慢变焦拉远,机位保持不动,只通过焦距变化让画面范围逐渐放宽。"},{id:"follow_tracking",label:"跟随拍摄",promptValue:"跟随拍摄",tag:"人物跟拍",desc:"跟住人物行动",submitPromptText:"运镜:跟随拍摄,镜头跟随主体运动方向移动,与主体保持相对稳定的距离和构图。"},{id:"leading_tracking",label:"迎面跟拍",promptValue:"迎面跟拍",tag:"人物跟拍",desc:"保留人物表情",submitPromptText:"运镜:迎面跟拍,镜头位于主体前方并随主体运动同步后退,保持主体正面信息稳定可见。"},{id:"profile_tracking",label:"侧面跟拍",promptValue:"侧面跟拍",tag:"人物跟拍",desc:"强化行进节奏",submitPromptText:"运镜:侧面跟拍,镜头在主体侧方与其平行移动,保持侧向构图稳定,并形成横向空间视差。"},{id:"handheld_shot",label:"手持拍摄",promptValue:"手持拍摄",tag:"人物跟拍",desc:"增加真实紧张",submitPromptText:"运镜:手持拍摄,镜头带轻微自然晃动和近距离临场感,可随主体动作产生小幅调整。"},{id:"pov_shot",label:"第一视角",promptValue:"第一视角",tag:"人物跟拍",desc:"进入角色视角",submitPromptText:"运镜:第一视角,镜头模拟角色视线和身体移动,带轻微头部晃动和主观视角的运动反馈。"},{id:"fpv_flythrough",label:"穿越机运镜",promptValue:"穿越机运镜",tag:"空间航拍",desc:"高速掠过空间",submitPromptText:"运镜:穿越机运镜,fpv 镜头以第一视角高速穿行空间,贴近场景边界和主体灵活飞行,带明显速度感与滚转俯仰变化。"},{id:"steadicam_walkthrough",label:"稳定器行进",promptValue:"稳定器行进",tag:"人物跟拍",desc:"平稳进入现场",submitPromptText:"运镜:稳定器行进,镜头以稳定、连续的方式向前或跟随移动,运动平滑,晃动幅度低。"},{id:"slider_reveal",label:"横滑揭示",promptValue:"横滑揭示",tag:"揭示转场",desc:"从遮挡露主体",submitPromptText:"运镜:横滑揭示,镜头从遮挡关系中横向滑出,逐步露出被遮挡的主体或关键信息。"},{id:"foreground_wipe",label:"前景擦过",promptValue:"前景擦过",tag:"揭示转场",desc:"用遮挡完成切换",submitPromptText:"运镜:前景擦过,近处遮挡物从镜头前掠过并短暂覆盖画面,随后露出新的画面内容。"},{id:"push_through",label:"穿越镜头",promptValue:"穿越镜头",tag:"揭示转场",desc:"穿过边界入场",submitPromptText:"运镜:穿越镜头,镜头持续快速向前推进,并产生短暂运动模糊,穿过明确的前景边界或空间层次,进入后方画面,最后落到新的构图或目标上。"},{id:"whip_pan",label:"甩摇",promptValue:"甩摇",tag:"揭示转场",desc:"快速切换信息",submitPromptText:"运镜:甩摇,镜头快速水平转动并产生短暂运动模糊,最后落到新的构图或目标上。"},{id:"rack_focus",label:"焦点转移",promptValue:"焦点转移",tag:"揭示转场",desc:"注意力换目标",submitPromptText:"运镜:焦点转移,镜头位置可以不变,焦点从一个画面层次平滑切换到另一个画面层次。"},{id:"crash_zoom",label:"急速变焦",promptValue:"急速变焦",tag:"情绪强化",desc:"放大狗血反应",submitPromptText:"运镜:急速变焦推进,机位保持不动,画面范围快速收紧到目标区域,形成突然强调。"},{id:"dolly_zoom",label:"希区柯克",promptValue:"希区柯克",tag:"情绪强化",desc:"现实崩塌瞬间",submitPromptText:"运镜:希区柯克式变焦,机位移动与反向变焦同时发生,主体大小基本保持稳定,背景透视发生明显变化。"},{id:"orbit_180",label:"环绕拍摄",promptValue:"环绕拍摄",tag:"情绪强化",desc:"强化人物气场",submitPromptText:"运镜:环绕拍摄,镜头围绕主体平稳旋转约180度,主体保持在画面核心位置,背景产生连续旋转视差。"},{id:"ascending_orbit",label:"盘旋抬升",promptValue:"盘旋抬升",tag:"情绪强化",desc:"高光登场时刻",submitPromptText:"运镜:盘旋抬升,镜头围绕主体旋转的同时逐渐升高,主体保持锁定,机位高度持续变化。"},{id:"descending_orbit",label:"盘旋下降",promptValue:"盘旋下降",tag:"情绪强化",desc:"巨物压迫登场",submitPromptText:"运镜:盘旋下降,镜头围绕主体旋转的同时逐渐降低,主体保持锁定,机位高度持续变化。"},{id:"aerial_establishing",label:"高空航拍",promptValue:"高空航拍",tag:"空间航拍",desc:"建立宏大世界",submitPromptText:"运镜:高空航拍,镜头以高角度俯视画面,并保持稳定滑行,用于呈现空间关系和整体布局。"},{id:"drone_dive",label:"俯冲下降",promptValue:"俯冲下降",tag:"空间航拍",desc:"从高空压向目标",submitPromptText:"运镜:俯冲下降,镜头从高处向目标方向快速下降并靠近,形成明显速度感和压迫感。"},{id:"pull_away",label:"拉升离场",promptValue:"拉升离场",tag:"空间航拍",desc:"人变小世界变大",submitPromptText:"运镜:拉升离场,镜头从主体附近向后并向上移动,主体在画面中逐渐变小,画面范围逐步扩大。"}],AX=yX.map($R),vX=new Map(AX.map(e=>[e.id,e])),Wt={aspectRatio:cX,resolution:uX,durationSec:Km,soundEffectEnabled:gX},aE={...Wt,resolution:pX},SX={...aE,resolution:lX,durationSec:iE},bX={...Wt,resolution:fX},IX={...Wt,resolution:mX,durationSec:hX},_X={...Wt,resolution:[{value:"480p"},{value:"720p"}]},Qt={aspectRatio:"9:16",resolution:"720p_lite",durationSec:10,soundEffectEnabled:!1},RX=["text_to_video","omni_reference","image_to_video","image_reference"],bke={modelId:"seedance_1.0",modelKind:"video",modes:RX,defaultMode:"text_to_video",referenceLimits:{maxImageReferences:9},settingOptions:Wt,defaultSettings:Qt},sE={...Qt,resolution:"720p"},EX={...Qt,resolution:"720p"},CX={...Qt,aspectRatio:"16:9",resolution:"768p"},PX={...Qt,aspectRatio:"16:9",resolution:"720p",durationSec:5},xX=["text_to_video","omni_reference","image_to_video","image_reference"],TX=["text_to_video","image_to_video","first_last_frame"],er=["text_to_video","omni_reference","image_to_video","first_last_frame","image_reference"],NX=[...er,"video_edit","video_extend"],Ike=[{modelId:"seedance1.5_direct",modelKind:"video",modes:TX,defaultMode:"text_to_video",settingOptions:Wt,defaultSettings:Qt},...["Seedance_2.0_mini_lite","Seedance_2.0_lite"].map(e=>({modelId:e,modelKind:"video",modes:er,defaultMode:"text_to_video",settingOptions:_X,defaultSettings:EX})),{modelId:"seedance2.0_direct",modelKind:"video",modes:er,defaultMode:"text_to_video",settingOptions:Wt,defaultSettings:Qt},{modelId:"seedance2.0_fast_direct",modelKind:"video",modes:er,defaultMode:"text_to_video",settingOptions:Wt,defaultSettings:Qt},{modelId:"seedance2.0_vision",modelKind:"video",modes:er,defaultMode:"text_to_video",settingOptions:aE,defaultSettings:sE},{modelId:"seedance2.0_fast_vision",modelKind:"video",modes:er,defaultMode:"text_to_video",settingOptions:Wt,defaultSettings:Qt},{modelId:"Seedance_2.5",modelKind:"video",modes:NX,defaultMode:"text_to_video",settingOptions:SX,defaultSettings:sE},{modelId:"MiniMax-H3",modelKind:"video",modes:er,defaultMode:"text_to_video",referenceLimits:{maxImageReferences:5},settingOptions:bX,defaultSettings:CX},oE({durationOptions:iE,modes:er,standardVideoDefaultSettings:Qt,standardVideoSettings:Wt}),{modelId:"happyhorse-1.1",modelKind:"video",modes:xX,defaultMode:"text_to_video",referenceLimits:{maxImageReferences:9},settingOptions:IX,defaultSettings:PX},...rE];var Gke={"seedance1.0":"seedance_1.0",seedance_1_5:"seedance1.5_direct","seedance_1.5":"seedance1.5_direct","seedance1.5":"seedance1.5_direct",seedance_2_0_lite:"Seedance_2.0_lite","seedance_2.0_lite":"Seedance_2.0_lite","seedance2.0_lite":"Seedance_2.0_lite","seedance2.0lite":"Seedance_2.0_lite",seedance_2_0_mini:"Seedance_2.0_lite","seedance_2.0_mini":"Seedance_2.0_lite","seedance2.0_mini":"Seedance_2.0_lite","seedance2.0mini":"Seedance_2.0_lite",seedance_2_0_mini_lite:"Seedance_2.0_mini_lite","seedance_2.0_mini_lite":"Seedance_2.0_mini_lite","seedance2.0_mini_lite":"Seedance_2.0_mini_lite","seedance2.0minilite":"Seedance_2.0_mini_lite",seedance_2_0:"seedance2.0_direct","seedance_2.0":"seedance2.0_direct","seedance2.0":"seedance2.0_direct",seedance_2_0_fast:"seedance2.0_fast_direct","seedance_2.0_fast":"seedance2.0_fast_direct","seedance2.0_fast":"seedance2.0_fast_direct",seedance_2_0_vision:"seedance2.0_vision","seedance_2.0_vision":"seedance2.0_vision",seedance_2_0_fast_vision:"seedance2.0_fast_vision","seedance_2.0_fast_vision":"seedance2.0_fast_vision",seedance_2_5:"Seedance_2.5","seedance_2.5":"Seedance_2.5","seedance2.5":"Seedance_2.5",seedance_25:"Seedance_2.5",seedance25:"Seedance_2.5",seedance_2_5_vision:"Seedance_2.5","seedance2.5_direct":"Seedance_2.5","seedance_2.5_direct":"Seedance_2.5","seedance2.5direct":"Seedance_2.5","seedance_2.5_fast":"Seedance_2.5","seedance2.5_fast":"Seedance_2.5","seedance_2.5_fast_direct":"Seedance_2.5","seedance2.5fast":"Seedance_2.5","seedance2.5fastdirect":"Seedance_2.5","seedance_2.5_vision":"Seedance_2.5","seedance2.5_vision":"Seedance_2.5","seedance2.5vision":"Seedance_2.5","seedance_2.5_fast_vision":"Seedance_2.5","seedance2.5_fast_vision":"Seedance_2.5","seedance2.5_fastvision":"Seedance_2.5","seedance2.5fastvision":"Seedance_2.5","seedance_2.5_lite":"Seedance_2.5","seedance2.5_lite":"Seedance_2.5","seedance2.5lite":"Seedance_2.5",seedance_2_5_lite:"Seedance_2.5","seedance_2.5_pro":"Seedance_2.5","seedance2.5_pro":"Seedance_2.5","seedance2.5pro":"Seedance_2.5","minimax-h3":"MiniMax-H3",minimax_h3:"MiniMax-H3",minimaxh3:"MiniMax-H3","happyhorse-1.1":"happyhorse-1.1","happyhorse_1.1":"happyhorse-1.1",happyhorse_1_1:"happyhorse-1.1",happyhorse11:"happyhorse-1.1"},Uke={nano:"AnyDream_2.0",gpt_image_2:"Nano2",nano2:"Nano2",nanopro:"NanoPro","seedream_5.0_pro":"seedream_5.0_pro",anydream_2:"AnyDream_2.0",anydream2:"AnyDream_2.0","anydream2.0":"AnyDream_2.0",anydream_2_0:"AnyDream_2.0","anydream_2.0":"AnyDream_2.0",anycook_1_standard:"anycook_1_standard",anycook_1_creative:"anycook_1_creative",seedream_4:"AnyDream_2.0","seedream_4.1":"AnyDream_2.0","seedream_4.3":"AnyDream_2.0","seedream_4.5":"AnyDream_2.0","seedream_5.0":"AnyDream_2.0"};var zke={around:"orbit_180",push_in:"dolly_in",pull_back:"dolly_out",left_tracking:"truck_left",right_tracking:"truck_right"};function cE(e){if(e===L)return"image";if(e===M)return"video"}function Xm(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function sa(e){return typeof e=="string"?e.trim():""}function wX(e){return Array.from(new Set(e.map(sa).filter(Boolean)))}function OX(e){return Array.isArray(e==null?void 0:e.references)?e.references:[]}function uE(e,t){return Ji(e).includes(t)}function DX(e,t){return wX(e.map(n=>t[n]??n))}function kX(e,t,n){let r=e.assets[t];r&&Xm(r.content)&&Object.assign(r.content,{generation:n});let o=x(e).nodes[t];o&&Xm(o.data)&&Object.assign(o.data,{generation:n})}function ia({document:e,nextRoleContent:t,previousRoleContent:n,roleNodeId:r,selectionReplacements:o}){let s=Object.fromEntries(Object.entries(o??{}).map(([a,d])=>[sa(a),sa(d)]).filter(([a,d])=>a&&a!==d));if(!Object.keys(s).length)return;let i=x(e);Object.values(i.nodes).forEach(a=>{if(!cE(a.type))return;let d=e.assets[a.id];if(!d||!Xm(d.content))return;let{generation:c}=d.content;if(!c)return;let u=OX(c),l=u.find(y=>uE(y,r))??{nodeAssetId:r,type:"image"},f=typeof c.prompt=="string"?c.prompt:"",h=KR({nextSelectableSelection:[],previousDefaultSelection:[],prompt:f,reference:l,selectionReplacements:s}),m=u.map(y=>!uE(y,r)||!Array.isArray(y.dataReferenceSelection)?y:{...y,dataReferenceSelection:DX(y.dataReferenceSelection,s)});!m.some((y,v)=>y!==u[v])&&h.prompt===f||kX(e,a.id,{...c,prompt:h.prompt,references:m})})}function pE({document:e,nextPippitAssetId:t,previousPippitAssetId:n,roleContent:r,roleNodeId:o}){let s=sa(n),i=sa(t);!s||s===i||ia({document:e,nextRoleContent:r,previousRoleContent:r,roleNodeId:o,selectionReplacements:{[s]:i}})}var MX=["assetId","caption","generation","metadata","naturalHeight","naturalWidth","pippitAssetId","source","sourceType"];function tr(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function lE(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function $m(e){return tr(e)&&tr(e.appearanceInfo)?e.appearanceInfo:void 0}function fE(e){var t;if(tr(e))return lE(e.pippitAssetId)??lE((t=$m(e))==null?void 0:t.pippitAssetId)}function LX(e){var n;if(!tr(e))return;let t=e.uploadPath??((n=$m(e))==null?void 0:n.uploadPath);return t==="legacy"||t==="optimized"?t:void 0}function BX(e){if(!tr(e)||!fE(e))return;let n=$m(e);if(n){let o=tr(e.generation)?{...e.generation}:void 0;return{appearanceInfo:Ko(n),...o?{generation:o}:{}}}let r={};return MX.forEach(o=>{e[o]!==void 0&&(r[o]=e[o])}),LX(e)==="optimized"&&(r.uploadPath="optimized",e.localUploadCache!==void 0&&(r.localUploadCache=e.localUploadCache),e.securityCheckScene!==void 0&&(r.securityCheckScene=e.securityCheckScene)),Object.keys(r).length?r:void 0}function os(e,t,n){var a;let r=(a=e.assets)==null?void 0:a[t];if(!r||!tr(r))return;let o=BX(n??r.content),s=fE(o);if(!o||!s)return;let i=tr(r.history)?r.history:void 0;r.history={...i??{},[s]:o}}var aa="xyq.role.updateAppearance";function Pe(e){return(e==null?void 0:e.trim())||void 0}function Wm(e){let t=new Set;return e.flatMap(n=>{let r=n.trim();return!r||t.has(r)?[]:(t.add(r),[r])})}function mE(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function nr(e,t){return Pe(e)===Pe(t)}function GX(e,t){var n,r;return t?nr((n=e.appearanceInfo)==null?void 0:n.assetId,t.assetId)&&nr((r=e.appearanceInfo)==null?void 0:r.pippitAssetId,t.pippitAssetId):!0}function UX(e){var t,n;return{runId:Pe((t=e==null?void 0:e.state)==null?void 0:t.runId)??Pe(e==null?void 0:e.runId),threadId:Pe((n=e==null?void 0:e.state)==null?void 0:n.threadId)??Pe(e==null?void 0:e.threadId)}}function zX(e,t){if(!t)return!0;let n=UX(e);return nr(n.runId??void 0,t.runId)&&nr(n.threadId??void 0,t.threadId)}function qX(e,t){return nr(e==null?void 0:e.prompt,t)}function FX(e,t){if(t===null){e.content.generation&&delete e.content.generation.prompt;return}e.content.generation??={},e.content.generation.prompt=t}function jX(e,t){let n=t.state.runId.trim(),r=t.state.threadId.trim();if(!n||!r)return;let{generation:o}=e.content;o||(o={},e.content.generation=o),o.runId=n,o.threadId=r,o.state={...structuredClone(t.state),runId:n,threadId:r}}function xn(e,t,n){if(!t||!Object.prototype.hasOwnProperty.call(t,n))return!0;let r=t[n];if(n==="voiceType")return e.voice_type===r;if(n==="description")return(e.description??"")===(r??"");if(n==="audioDurationMs")return(e.audioDurationMs??null)===(r??null);let o={audioAssetId:e.audioAssetId,audioName:e.audioName,audioNodeId:e.audioNodeId,audioPippitAssetId:e.audioPippitAssetId,audioSource:e.audioSource,voiceId:e.voiceId}[n];return nr(typeof o=="string"?o:void 0,typeof r=="string"?r:void 0)}function VX(e,t){let n=e.getState(),r=x(n).nodes[t.nodeId];if((r==null?void 0:r.type)!==z||r.id!==t.assetId)return;let o=n.assets[t.assetId];return o&&$t(o)?o:void 0}function HX(e,t,n){let r={...e.content.voiceInfo??{}};t.description!==void 0&&xn(r,n,"description")&&(r.description=t.description),t.voiceType!==void 0&&xn(r,n,"voiceType")&&(r.voice_type=t.voiceType),t.audioAssetId!==void 0&&xn(r,n,"audioAssetId")&&(r.audioAssetId=Pe(t.audioAssetId)),t.audioName!==void 0&&xn(r,n,"audioName")&&(r.audioName=Pe(t.audioName)),t.audioNodeId!==void 0&&xn(r,n,"audioNodeId")&&(r.audioNodeId=Pe(t.audioNodeId)),t.audioPippitAssetId!==void 0&&xn(r,n,"audioPippitAssetId")&&(r.audioPippitAssetId=Pe(t.audioPippitAssetId)),t.audioSource!==void 0&&xn(r,n,"audioSource")&&(r.audioSource=t.audioSource??void 0),t.voiceId!==void 0&&xn(r,n,"voiceId")&&(r.voiceId=Pe(t.voiceId)),t.audioDurationMs!==void 0&&xn(r,n,"audioDurationMs")&&(t.audioDurationMs===null||!Number.isFinite(t.audioDurationMs)||t.audioDurationMs<=0?delete r.audioDurationMs:r.audioDurationMs=t.audioDurationMs),e.content.voiceInfo=r,delete e.content.voice_info}function YX(e,t,n){var a,d;let r=Pe((a=e.content.appearanceInfo)==null?void 0:a.pippitAssetId),o=Pe(t.pippitAssetId),i=!!(o&&(o!==r||Pe(t.assetId)!==Pe((d=e.content.appearanceInfo)==null?void 0:d.assetId)))?k_(e.content,{assetId:Pe(t.assetId),imageSource:t.imageSource,isMain:!0,name:n,pippitAssetId:o,type:"image",uploadPath:t.uploadPath}):void 0;e.content.appearanceInfo={...(i==null?void 0:i.appearanceInfo)??e.content.appearanceInfo??{},...t.assetId!==void 0?{assetId:Pe(t.assetId)}:{},...t.pippitAssetId!==void 0?{pippitAssetId:Pe(t.pippitAssetId)}:{},...t.imageSource!==void 0?{imageSource:t.imageSource}:{},...t.uploadPath!==void 0?{uploadPath:t.uploadPath}:{}},i!=null&&i.sourceInfos&&(e.content.sourceInfos=i.sourceInfos)}function Qm(e,t){let n=VX(e,t);if(!n)return{status:"aborted",reason:"role asset not found"};let r=structuredClone(n.content);return e.transact(o=>{var h,m,g,y,v,S;let s=x(o).nodes[t.nodeId];if((s==null?void 0:s.type)!==z||s.id!==t.assetId)return;let i=jr(o.assets[t.assetId]);if(!(i!=null&&i.content))return;let{expected:a,patch:d}=t;d.characterName!==void 0&&(!a||!Object.prototype.hasOwnProperty.call(a,"characterName")||nr(s.data.name,a.characterName))&&(s.data.name=d.characterName,i.content.basicInfo={...i.content.basicInfo??{},name:d.characterName}),d.appearanceName!==void 0&&(!a||!Object.prototype.hasOwnProperty.call(a,"appearanceName")||nr((h=r.basicInfo)==null?void 0:h.appearanceName,a.appearanceName))&&(i.content.basicInfo={...i.content.basicInfo??{},appearanceName:d.appearanceName}),d.episodes!==void 0&&(!a||!Object.prototype.hasOwnProperty.call(a,"episodes")||mE(Wm(r.episodes??[]),Wm(a.episodes??[])))&&(i.content.episodes=Wm(d.episodes)),d.appearanceDescription!==void 0&&(i.content.appearanceInfo={...i.content.appearanceInfo??{},description:d.appearanceDescription});let c=!d.mainImage||GX(r,a==null?void 0:a.mainImage),u=d.generation===void 0||!a||!Object.prototype.hasOwnProperty.call(a,"generation")||mE(r.generation,a.generation),p=!!(d.mainImage&&d.generation!==void 0),l=c&&u;d.mainImage&&(p?l:c)&&YX(i,d.mainImage,d.appearanceName??((m=i.content.basicInfo)==null?void 0:m.appearanceName)),d.voice&&HX(i,d.voice,a==null?void 0:a.voice),d.generation!==void 0&&(p?l:u)&&(d.generation===null?delete i.content.generation:i.content.generation=structuredClone(d.generation)),d.generationPrompt!==void 0&&(!a||!Object.prototype.hasOwnProperty.call(a,"generationPrompt")||qX(r.generation,a.generationPrompt))&&FX(i,d.generationPrompt),d.generationRun&&(!a||!Object.prototype.hasOwnProperty.call(a,"generationRun")||zX(r.generation,a.generationRun))&&jX(i,d.generationRun),(((g=r.appearanceInfo)==null?void 0:g.pippitAssetId)!==((y=i.content.appearanceInfo)==null?void 0:y.pippitAssetId)||((v=r.appearanceInfo)==null?void 0:v.assetId)!==((S=i.content.appearanceInfo)==null?void 0:S.assetId))&&(os(o,t.assetId,r),os(o,t.assetId,i.content)),ia({document:o,nextRoleContent:i.content,previousRoleContent:r,roleNodeId:t.nodeId})},{intent:"role.updateAppearance",mergeKey:`role-appearance:${t.nodeId}`})}var da="xyq.role.updateSourceInfos";function ss(e){return typeof e=="string"?e.trim():""}function Jt(e){return e!==void 0&&(!e.type||e.type==="image")}function Jm(e){return[...e].sort((t,n)=>{let r=typeof t[1].order=="number"&&Number.isFinite(t[1].order)?t[1].order:0,o=typeof n[1].order=="number"&&Number.isFinite(n[1].order)?n[1].order:0;return r!==o?r-o:t[0].localeCompare(n[0])})}function KX(e){return Object.fromEntries($o(e.content))}function hE(e){let t=Object.fromEntries(Jm(Object.entries(e)).map(([n,r],o)=>[n,{...r,pippitAssetId:n,order:o}]));return Xo(t)??{}}function XX(e,t){!t||!Jt(t)||(e.content.appearanceInfo={...e.content.appearanceInfo??{},assetId:t.assetId,pippitAssetId:t.pippitAssetId,imageSource:2},t.uploadPath==="optimized"?e.content.appearanceInfo.uploadPath="optimized":delete e.content.appearanceInfo.uploadPath,Hc(e.content,{source:Yo.Uploaded}))}function $X(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,{...r,isMain:n===t,pippitAssetId:n}]))}function WX(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,{...n,isMain:!1,pippitAssetId:t}]))}function gE(e){var t;return(t=Jm(Object.entries(e)).find(([,n])=>Jt(n)))==null?void 0:t[0]}function QX(e){var t;return(t=Object.entries(e).find(([,n])=>n.isMain===!0&&Jt(n)))==null?void 0:t[0]}function yE(e,t){let n=e[t];if(!n)return e;let r=Math.min(0,...Object.values(e).map(o=>typeof o.order=="number"&&Number.isFinite(o.order)?o.order:0));return{...e,[t]:{...n,order:r-1,pippitAssetId:t}}}function JX(e,t,n){let r=!1;return Object.values(x(e).nodes).forEach(o=>{if(o.type!==z)return;let s=jr(e.assets[o.id]);if(!(s!=null&&s.content))return;let i=Object.fromEntries($o(s.content)),a=i[t];!a||a.name===n||(s.content.sourceInfos={...i,[t]:{...a,name:n,pippitAssetId:t}},r=!0)}),r}function ZX(e,t,n,r){if(r.type==="setDefault")return!1;if(r.type==="setName"){let l=ss(r.pippitAssetId),f=r.name.trim();return!l||!f?!1:JX(e,l,f)}let o=KX(n),s={...n.content,appearanceInfo:{...n.content.appearanceInfo??{}},sourceInfos:hE(o)},i={...o},a,d=!1,c=QX(o);if(r.type==="upsert"){let l=ss(r.sourceInfo.pippitAssetId);if(!l)return!1;let f=Object.keys(i).length>0,h=Object.values(i).some(Jt),m=Math.max(-1,...Object.values(i).map(v=>typeof v.order=="number"&&Number.isFinite(v.order)?v.order:-1)),g=i[l],y={...g??{},...r.sourceInfo,isMain:r.sourceInfo.isMain??(g==null?void 0:g.isMain)??!f,order:r.sourceInfo.order??(g==null?void 0:g.order)??m+1,pippitAssetId:l,type:r.sourceInfo.type??(g==null?void 0:g.type)??"image"};i[l]={...y,isMain:Jt(y)&&(!h||y.isMain===!0)},i[l].isMain&&(i=yE(i,l),a=l)}if(r.type==="setMain"){let l=ss(r.pippitAssetId);if(!Jt(i[l]))return!1;i=yE(i,l),a=l}if(r.type==="delete"){let l=ss(r.pippitAssetId),f=i[l];if(!f||Object.keys(i).length<=1&&Jt(f))return!1;let h=f.isMain===!0?gE(Object.fromEntries(Object.entries(i).filter(([m])=>m!==l))):void 0;if(f.isMain===!0&&!h)return!1;delete i[l],h&&(a=h)}if(r.type==="reorder"){let l=ss(r.activePippitAssetId),f=ss(r.overPippitAssetId),h=i[l],m=i[f];if(!h||!m||l===f)return!1;i[l]={...h,order:m.order,pippitAssetId:l},i[f]={...m,order:h.order,pippitAssetId:f};let g=Jm(Object.entries(i))[0];if(!g)return!1;if(Jt(g[1]))a=g[0];else if(Object.values(i).some(Jt))return!1}i=hE(i);let u=Jt(i[c??""])?c:void 0,p=a??u??gE(i);return p?(i=$X(i,p),c!==p&&(a=p,d=!0)):i=WX(i),n.content.sourceInfos=i,a&&XX(n,i[a]),d&&(os(e,t,s),os(e,t,n.content)),ia({document:e,nextRoleContent:n.content,previousRoleContent:s,roleNodeId:t}),!0}function e3(e,t){let n=e.getState(),r=x(n).nodes[t.nodeId];if((r==null?void 0:r.type)!==z||r.id!==t.assetId)return;let o=n.assets[t.assetId];return o&&$t(o)?o:void 0}function Zm(e,t){return e3(e,t)?e.transact(n=>{let r=x(n).nodes[t.nodeId];if((r==null?void 0:r.type)!==z||r.id!==t.assetId)return;let o=jr(n.assets[t.assetId]);o!=null&&o.content&&ZX(n,t.assetId,o,t.operation)},{intent:"role.updateSourceInfos",mergeKey:`role-source-infos:${t.nodeId}:${t.operation.type}`,undoable:t.operation.type!=="setName"}):{status:"aborted",reason:"role asset not found"}}var t3=2e3,n3=5e3;function r3(e){return e!==void 0&&e>t3&&e<=n3}function eh(e){return e!==void 0&&!r3(e)}var nh="xyq.role.updateDescription";function AE(e){var a,d,c,u,p;let t=((a=e==null?void 0:e.audioAssetId)==null?void 0:a.trim())||((d=e==null?void 0:e.voiceId)==null?void 0:d.trim()),n=(c=e==null?void 0:e.audioPippitAssetId)==null?void 0:c.trim(),r=(u=e==null?void 0:e.audioName)==null?void 0:u.trim(),o=e==null?void 0:e.audioDurationMs,s=e==null?void 0:e.audioSource,i=(p=e==null?void 0:e.audioNodeId)==null?void 0:p.trim();if(!(!t&&!i&&!n&&!r&&(typeof o!="number"||!Number.isFinite(o)||o<=0)))return{assetId:t,audioNodeId:i,durationMs:o,name:r,pippitAssetId:n,audioSource:s}}function o3(e,t){var o;let n=t?(o=e.assets[t])==null?void 0:o.content:void 0;if(!n||typeof n!="object"||Array.isArray(n))return;let{pippitAssetId:r}=n;return typeof r=="string"&&r.trim()||void 0}function vE(e){let t=typeof e=="string"?e.split(/[、,,\s]+/):e??[],n=new Set,r=[];for(let o of t){let s=String(o).trim();!s||n.has(s)||(n.add(s),r.push(s))}return r}function s3(e,t){var r,o,s,i,a,d;let n=$t(e);return n?t==="voice"?((r=Pt(n))==null?void 0:r.description)??"":t==="characterName"?((o=n.basicInfo)==null?void 0:o.name)??"":t==="appearanceName"?((s=n.basicInfo)==null?void 0:s.appearanceName)??"":t==="episodes"?vE(n.episodes).join("、"):t==="voiceAudio"?AE(Pt(n)):t==="voiceType"?(i=Pt(n))==null?void 0:i.voice_type:((a=n.appearanceInfo)==null?void 0:a.description)??((d=n.basicInfo)==null?void 0:d.description)??"":""}function bu(e){var d,c,u,p,l;if(!e||typeof e!="object")return;let t=(d=e.assetId)==null?void 0:d.trim(),n=(c=e.name)==null?void 0:c.trim(),r=typeof e.durationMs=="number"&&Number.isFinite(e.durationMs)&&e.durationMs>0?e.durationMs:void 0,{audioSource:o}=e,s=(u=e.audioNodeId)==null?void 0:u.trim(),i=(p=e.pippitAssetId)==null?void 0:p.trim(),a=(l=e.previousPippitAssetId)==null?void 0:l.trim();if(!(!t&&!s&&!i&&!n&&r===void 0))return{...t?{assetId:t}:{},...s?{audioNodeId:s}:{},...r!==void 0?{durationMs:r}:{},...n?{name:n}:{},...o?{audioSource:o}:{},...i?{pippitAssetId:i}:{},...a?{previousPippitAssetId:a}:{}}}function i3(e){if(e===2)return 2;if(e===1)return 1;let t=bu(e);return(t!=null&&t.assetId||t!=null&&t.audioNodeId)&&!eh(t.durationMs)?2:1}function a3(e,t){let n=bu(e),r=bu(t);return((n==null?void 0:n.assetId)??"")===((r==null?void 0:r.assetId)??"")&&((n==null?void 0:n.audioNodeId)??"")===((r==null?void 0:r.audioNodeId)??"")&&((n==null?void 0:n.durationMs)??0)===((r==null?void 0:r.durationMs)??0)&&((n==null?void 0:n.name)??"")===((r==null?void 0:r.name)??"")&&((n==null?void 0:n.pippitAssetId)??"")===((r==null?void 0:r.pippitAssetId)??"")&&((n==null?void 0:n.audioSource)??"")===((r==null?void 0:r.audioSource)??"")}function th(e,t){e.content.voiceInfo={...Pt(e.content)??{},...t},delete e.content.voice_info}function d3(e,t){let n=e.getState(),r=x(n).nodes[t.nodeId];if((r==null?void 0:r.type)!==z||r.id!==t.assetId)return;let o=n.assets[t.assetId];if(!(!o||!$t(o)))return{asset:o,node:r}}function c3(e,t,n){var r,o,s;if(t.field==="characterName"){let i=typeof t.value=="string"?t.value:"";return n===t.value&&e.node.data.name===i}return t.field==="voiceAudio"?a3(n,t.value)&&!(typeof t.value=="object"&&((o=(r=t.value)==null?void 0:r.pippitAssetId)!=null&&o.trim())&&((s=t.value.previousPippitAssetId)!=null&&s.trim())&&t.value.pippitAssetId.trim()!==t.value.previousPippitAssetId.trim()):n===t.value}function u3(e,t){let n=d3(e,t);if(!n)return{status:"aborted",reason:"role asset not found"};let r=s3(n.asset,t.field);return c3(n,t,r)?{status:"noop",reason:"no-changes"}:e.transact(o=>{let s=x(o).nodes[t.nodeId];if((s==null?void 0:s.type)!==z||s.id!==t.assetId)return;let i=jr(o.assets[t.assetId]);if(!(i!=null&&i.content))return;if(t.field==="characterName"){let d=typeof t.value=="string"?t.value:"";s.data.name=d,i.content.basicInfo={...i.content.basicInfo??{},name:d};return}if(t.field==="appearanceName"){let d=typeof t.value=="string"?t.value:"";i.content.basicInfo={...i.content.basicInfo??{},appearanceName:d};return}if(t.field==="voice"){let d=typeof t.value=="string"?t.value:"";th(i,{description:d});return}if(t.field==="voiceAudio"){let d=AE(Pt(i.content)),c=bu(t.value);if(eh(c==null?void 0:c.durationMs))return;th(i,{audioAssetId:c==null?void 0:c.assetId,audioDurationMs:c==null?void 0:c.durationMs,audioName:c==null?void 0:c.name,audioNodeId:c==null?void 0:c.audioNodeId,audioPippitAssetId:c==null?void 0:c.pippitAssetId,audioSource:c==null?void 0:c.audioSource,voiceId:c==null?void 0:c.assetId});let u=(c==null?void 0:c.previousPippitAssetId)??(d==null?void 0:d.pippitAssetId)??o3(o,d==null?void 0:d.audioNodeId);u&&u!==(c==null?void 0:c.pippitAssetId)&&pE({document:o,nextPippitAssetId:c==null?void 0:c.pippitAssetId,previousPippitAssetId:u,roleContent:i.content,roleNodeId:t.nodeId});return}if(t.field==="voiceType"){let d=i3(t.value);th(i,{voice_type:d});return}if(t.field==="episodes"){i.content.episodes=vE(typeof t.value=="string"?t.value:void 0);return}let a=typeof t.value=="string"?t.value:"";i.content.appearanceInfo={...Ko(i.content.appearanceInfo),description:a}},{intent:"role.updateDescription",mergeKey:`role-description:${t.nodeId}:${t.field}`})}function SE(e){let t=e.commands.register(aa,Qm),n=e.commands.register(nh,u3),r=e.commands.register(da,Zm);return()=>{t(),n(),r()}}var rh="pippit-role",bE="base-model",IE="base",_E=vo.ASSETS.entries[rh].path;function p3(e){return P(e)?De(e.captureId)&&!!e.captureId.trim()&&Oe(e.createdAt)&&Nt(e):!1}function RE(e){return e===void 0?!0:P(e)?Object.entries(e).every(([t,n])=>p3(n)&&n.captureId===t):!1}var Qr="biz/scene3d-director",l3=Qr,f3="biz/scene3d-director-document";function oh(){return O.t("Pippit_xyqcanvas_legacy_title_3d_director_s_desk",{},"3D 导演台")}var CMe=oh();function m3(){return O.t("Pippit_xyqcanvas_scene3ddirector_defaultname_democharacter",{},"角色1")}var h3={baseAction:"idle",additiveWeights:{},boneRotations:{},controlValues:{bodyBend:0,bodyTilt:0,bodyTurn:0,headNod:0,headTilt:0,headTurn:0,lArmRaise:0,lArmStraddle:0,lArmTurn:0,lElbowBend:0,lKneeBend:0,lLegRaise:0,lLegStraddle:0,lLegTurn:0,rArmRaise:0,rArmStraddle:0,rArmTurn:0,rElbowBend:0,rKneeBend:0,rLegRaise:0,rLegStraddle:0,rLegTurn:0,torsoBend:0,torsoTilt:0,torsoTurn:0},posePresetId:"tpose",rootPositionOffset:{x:0,y:0,z:0},speed:1};function sh(){return{version:1,nodes:[{id:"character_1",type:"character",name:m3(),visible:!0,locked:!1,transform:{position:{x:0,y:0,z:0},rotation:{x:0,y:0,z:0},scale:{x:1,y:1,z:1}},metadata:{assetCategory:bE,assetId:rh,assetSource:IE,defaultCharacterIndex:1,modelUrl:_E},character:{gender:"female",placeholder:!0,appearance:{color:"#d7b5ee"},label:{scale:1,yOffset:1.1},animation:h3}}],aspectRatio:"21:9",settings:{gridVisible:!0,helpersVisible:!0,compositionGuide:"none",transformMode:"translate",viewMode:"director"},environment:{transform:{position:{x:0,y:0,z:0},rotation:{x:0,y:0,z:0},scale:{x:1,y:1,z:1}},background:{skyColor:"#060608"},sphere:{orientationVersion:1,rotationX:0,rotationY:90,radius:180},display:{characterLabelsVisible:!0,gridSnapEnabled:!1,groundVisible:!1,groundOpacity:1}}}}var g3=["assetId","pippitAssetId","previewUrl","url","naturalWidth","naturalHeight","latestCaptureAt","directorDocument","metadata"];function y3(e){return g3.some(t=>t in e)}function A3(e){return P(e)?!y3(e)&&_(e.title)&&_(e.name)&&_(e.caption)&&_(e.subType)&&Vc(e.source)&&RE(e.captureUploadTasks):!1}function v3(e){return e===void 0?!0:P(e)?Oe(e.width)&&Oe(e.height):!1}function S3(e){return P(e)?e.kind==="pippit-asset"&&De(e.pippitAssetId)&&e.schemaVersion===1:!1}function b3(e){return{kind:"pippit-asset",pippitAssetId:e,schemaVersion:1}}function I3(e){return{version:2,documentRef:e}}function _3(e){return`${e}_document`}function R3({document:e,documentAssetId:t,nodeId:n}){return{pippitAssetId:t,type:f3,content:e,extra:{sourceNodeId:n}}}function EE({document:e=sh(),documentAssetId:t,nodeId:n}){let r=t??_3(n),o=b3(r);return[{pippitAssetId:n,type:l3,content:I3(o),extra:{}},R3({document:e,documentAssetId:r,nodeId:n})]}function ih(e){if(!P(e))return!1;let t=e.cover===void 0||P(e.cover)&&De(e.cover.pippitAssetId)&&!!e.cover.pippitAssetId.trim();return e.version===2&&S3(e.documentRef)&&t}function is(e){return P(e)?e.version===1&&Array.isArray(e.nodes)&&(_(e.activeCameraId)||_(e.activeShotCameraNodeId))&&De(e.aspectRatio)&&v3(e.customAspectRatio)&&P(e.settings)&&P(e.environment)&&(e.captures===void 0||Array.isArray(e.captures)):!1}function CE(e){var t;if(!(!P(e)||!ih(e.content)))return((t=e.content.cover)==null?void 0:t.pippitAssetId.trim())||void 0}var ca={type:Qr,validate:A3,getDefaultSize:()=>({w:420,h:236})};var E3=["/content/generation","/content/data/generation"],C3=["","/content","/content/data"],P3="generation requires field-level updates",x3=2e3,ua=new Set;function PE(e){if(!Ye(e))return!1;let t=Ye(e.content)?e.content:e,n=Ye(t==null?void 0:t.data)?t.data:void 0;return(t==null?void 0:t.generation)!==void 0||(n==null?void 0:n.generation)!==void 0}function T3(e,t){return t.op!=="replace"||!Ye(t.value)?!1:E3.some(n=>t.path===n||t.path.startsWith(`${n}/`))?!0:C3.includes(t.path)&&(PE(e.assets[t.assetId])||PE(t.value))}function xE(e,t,n,r){if(t.txId){let o=[e,t.txId,n.assetId,n.path,n.op].join("\0");if(ua.has(o))return;if(ua.add(o),ua.size>x3){let s=ua.values().next().value;s!==void 0&&ua.delete(s)}}yi({action:e,category:"canvas_sync",context:{txId:t.txId,intent:t.intent,assetId:n.assetId,path:n.path,op:n.op,reason:r},packageName:"xyq-canvas-sdk",status:e==="canvas_generation_replace_report_only"?"failure":"log"})}function N3(e){for(let t of e.patches){if(T3(e.document,t)){xE("canvas_generation_replace_report_only",e,t,P3);continue}t.op==="replace"&&Ye(t.value)&&e.phase==="local"&&e.txId!==void 0&&xE("canvas_object_replace_report_only",e,t,"broad object replace")}}function w3(e){try{N3(e)}catch{}}var TE=(e,t)=>{if(e.source==="remote"){t();return}w3({document:e.prevState,patches:e.forwardPatches,txId:e.txId,intent:e.intent,phase:"local"}),t()};function O3(e){let t=[XR(e),wR(e),uR(e),vR(e),Bl(e,{registry:qm()})];return()=>{for(let n of t.splice(0))n()}}function D3(e="canvas_1",t){let n=qd();n.register(Qn),n.register(En),n.register(Zc),n.register(Wn),n.register(Cn),n.register(Vr),n.register(Ki),n.register(ca);let r=sf({getTelemetryContext:t,initialDocument:bo(e),middlewares:[TE],registry:n});return SE(r),{dispose:O3(r),store:r}}function NE({canvasId:e,telemetryContext:t}){let n=t,{dispose:r,store:o}=D3(e,()=>n),s=pf({initialSnapConfig:vi(o.getRootCanvasContent().settings.snap)});return{store:o,runtime:s,dispose:r,setTelemetryContext:i=>{n=i}}}function wE({hasPendingLocalChanges:e,hasPendingLocalMediaUploads:t,isReady:n,syncState:r}){return r.phase==="error"?"error":r.phase==="offline"?"offline":n?e||t||r.phase==="flushing"?"saving":r.phase==="connecting"||r.phase==="syncing"||r.phase==="rebasing"?"syncing":"saved":"loading"}var k3="xyq-canvas-sync",M3=3e4,ah=new Set,dh=class{constructor(t,n){this._listeners=new Set;this._disposers=[];this._disposed=!1;this._uploadCleanupAttached=!1;this._pendingFlush=!1;this._started=!1;this.updateRuntimeConfig=t=>{this._disposed||(this._runtimeConfig=t,this._options.session.setTelemetryContext(t.telemetryContext),this._runReadyEffectsIfSyncAttached())};this.start=()=>{var t,n,r;if(this._disposed)throw new Error(((t=this._effects.disposedErrorMessages)==null?void 0:t.cannotStart)??"Cannot start a disposed canvas runtime");return this._started?this:(this._started=!0,this._options.session.setTelemetryContext(this._runtimeConfig.telemetryContext),this._attachStoreLifecycle(),this._attachSyncLifecycle(),this._attachUploadCleanup(),(r=(n=this._effects).configureGenerationRuntime)==null||r.call(n,this._options),this._runReadyEffectsIfSyncAttached(),this._syncGenerationRunsIfNeeded(),this)};this.getSnapshot=()=>this._snapshot;this.subscribe=t=>(this._listeners.add(t),()=>this._listeners.delete(t));this.flush=()=>{if(this._syncEngine){this._syncEngine.flush();return}this._pendingFlush=!0};this.whenReady=(t={})=>{var n;return this._disposed?Promise.reject(new Error(((n=this._effects.disposedErrorMessages)==null?void 0:n.wait)??"Canvas runtime was disposed")):(this.start(),this._waitFor(r=>r.isReady,t.timeoutMs))};this.waitUntilSaved=(t={})=>{var r;if(this._disposed)return Promise.reject(new Error(((r=this._effects.disposedErrorMessages)==null?void 0:r.wait)??"Canvas runtime was disposed"));this.start();let n=t.includeMediaUploads??!0;return this._waitFor(o=>o.isReady&&o.syncState.phase==="idle"&&!o.hasPendingLocalChanges&&(!n||!o.hasPendingLocalMediaUploads),t.timeoutMs)};this.dispose=()=>{if(!this._disposed){this._disposed=!0;for(let t of this._disposers.splice(0).reverse())t();this._syncEngine=void 0;for(let t of Array.from(this._listeners))t(this._snapshot);this._listeners.clear(),this._options.ownsSession&&this._options.session.dispose()}};this._handleSyncEvent=t=>{var n,r,o,s,i,a;if(!this._disposed){if(t.kind==="bootstrap-root-ready"){this._isRootReady=!0,this._lifecycle={phase:"root-ready",settled:!1},this._rootPreviewDocument=t.document,this._rootPreviewReadyNodeAssetIds=new Set,this._publish(),(r=(n=this._options).onSyncEvent)==null||r.call(n,t);return}if(t.kind==="bootstrap-assets-ready"){this._lifecycle={phase:"hydrating",settled:!1},this._rootPreviewDocument=t.document;let d=this._rootPreviewReadyNodeAssetIds??new Set;t.readyAssetIds.forEach(c=>d.add(c)),this._rootPreviewReadyNodeAssetIds=d,this._publish(),(s=(o=this._options).onSyncEvent)==null||s.call(o,t);return}if((a=(i=this._options).onSyncEvent)==null||a.call(i,t),t.kind==="state-change"){t.state.phase==="error"&&t.state.reason==="bootstrap-failed"&&(this._lifecycle={error:t.state.error,phase:"error",settled:!0},this._snapshot=this._createSnapshot(!1,t.state)),this._publish(t.state);return}if(t.kind==="outbound-change"||t.kind==="committed"||t.kind==="discarded"){this._publish();return}t.kind==="snapshot-applied"&&(this._isRootReady=!0,this._lifecycle={phase:"ready",settled:!0},ah.add(this._sessionKey),this._snapshot=this._createSnapshot(!0,this._snapshot.syncState),this._runReadyEffectsIfSyncAttached(),this._publish())}};this._options=t,this._effects=n,this._runtimeConfig={autoLayoutStrategies:t.autoLayoutStrategies,telemetryContext:t.telemetryContext},this.store=t.session.store,this.runtime=t.session.runtime;let r=!t.ownsSession&&ah.has(this._sessionKey);this._isRootReady=r,this._lifecycle={phase:r?"ready":"bootstrap-loading",settled:r},this._snapshot=this._createSnapshot(r,r?{phase:"idle"}:{phase:"connecting"})}get _readOnly(){return this._options.editable===!1}get _sessionKey(){return this._options.sessionKey??this._options.canvasId}_attachStoreLifecycle(){let t=n=>{this.runtime.setSnapConfig(vi(n)),n.enabled||this.runtime.clearSnapping()};t(this.store.getRootCanvasContent().settings.snap),this._disposers.push(this.store.subscribeSelector(n=>x(n).settings.snap,t,{equalityFn:cf})),this._readOnly?this._disposers.push(this.store.use(LR(this._options.onReadOnlyEditAttempt))):this._disposers.push(this.store.subscribe(()=>{this._publish(),this._syncGenerationRunsIfNeeded()}));for(let n of this._options.middlewares??[])this._disposers.push(this.store.use(n));this._readOnly&&this._disposers.push(this.store.subscribe(()=>{this._publish(),this._syncGenerationRunsIfNeeded()}))}_attachSyncLifecycle(){var n;let t=Af({canvasId:this._options.canvasId,createClientId:this._options.createClientId,persistence:this._options.persistence??vf(this._options.canvasId,{dbName:k3}),store:this.store,transportFactory:this._options.transportFactory,onAttached:r=>{this._disposed||(this._syncEngine=r,this._runReadyEffectsIfSyncAttached(),this._pendingFlush&&(this._pendingFlush=!1,r.flush()))},onError:r=>{this._disposed||(this._lifecycle={error:r,phase:"error",settled:!0},this._snapshot=this._createSnapshot(!1,{phase:"error",error:r,reason:"bootstrap-failed"}),this._publish({phase:"error",error:r,reason:"bootstrap-failed"}))},onSyncEvent:this._handleSyncEvent,sync:{...this._options.sync,flush:{debounceMs:1e3,maxBatchPatchCount:50,...(n=this._options.sync)==null?void 0:n.flush},readOnly:this._readOnly,onBootstrapSettled:()=>{if(!this._disposed){if(this._snapshot.syncState.phase==="error"){this._lifecycle={error:this._snapshot.syncState.error,phase:"error",settled:!0},this._publish();return}this._snapshot.isReady&&(ah.add(this._sessionKey),this._lifecycle={phase:"ready",settled:!0},this._runReadyEffectsIfSyncAttached(),this._publish())}}}});this._disposers.push(()=>{t(),this._syncEngine=void 0})}_attachUploadCleanup(){var n,r;if(this._readOnly||this._options.optimizedUploadEnabled||this._uploadCleanupAttached)return;let t=(r=(n=this._effects).attachDeletedLocalUploadCleanup)==null?void 0:r.call(n,this._options,this.store);t&&(this._uploadCleanupAttached=!0,this._disposers.push(t))}_runReadyEffectsIfSyncAttached(){var n,r,o,s;if(!this._syncEngine||!this._snapshot.isReady)return;let{autoLayoutStrategies:t}=this._runtimeConfig;if(!this._readOnly&&(t!=null&&t.length)&&BR(this.store,t),this._readOnly||(r=(n=this._effects).clearNonRecoverableLocalUploadTasks)==null||r.call(n,this._options,this.store),!this._readOnly&&this._options.optimizedUploadEnabled&&!this._uploadCleanupAttached){let i=(s=(o=this._effects).attachDeletedLocalUploadCleanup)==null?void 0:s.call(o,this._options,this.store);i&&(this._uploadCleanupAttached=!0,this._disposers.push(i))}}_syncGenerationRunsIfNeeded(){var t,n;this._readOnly||(this._generationSyncSignature=(n=(t=this._effects).syncGenerationRunsIfNeeded)==null?void 0:n.call(t,{options:this._options,previousSignature:this._generationSyncSignature,store:this.store}))}_createSnapshot(t,n){var i;let r=this.store.getState(),o=GR(r,this._options.optimizedUploadEnabled),s=!this._readOnly&&(((i=this._syncEngine)==null?void 0:i.getPendingOutboundCount())??0)>0;return{document:r,hasPendingLocalChanges:s,hasPendingLocalMediaUploads:o,isReady:t,isRootReady:this._isRootReady,lifecycle:this._lifecycle,nodeCount:Object.keys(x(r).nodes).length,...this._rootPreviewDocument?{rootPreviewDocument:this._rootPreviewDocument}:{},...this._rootPreviewReadyNodeAssetIds?{rootPreviewReadyNodeAssetIds:[...this._rootPreviewReadyNodeAssetIds].sort()}:{},saveState:wE({hasPendingLocalChanges:s,hasPendingLocalMediaUploads:o,isReady:t,syncState:n}),syncState:n}}_publish(t=this._snapshot.syncState){this._snapshot=this._createSnapshot(this._snapshot.isReady,t);for(let n of Array.from(this._listeners))n(this._snapshot)}_waitFor(t,n=M3){return new Promise((r,o)=>{let s={unsubscribe:()=>{}},i=d=>{s.unsubscribe(),s.timeout&&clearTimeout(s.timeout),d()},a=d=>{let{syncState:c}=d;this._disposed?i(()=>{var u;return o(new Error(((u=this._effects.disposedErrorMessages)==null?void 0:u.wait)??"Canvas runtime was disposed"))}):c.phase==="error"?i(()=>o(c.error)):t(d)&&i(()=>r(d))};s.unsubscribe=this.subscribe(a),s.timeout=setTimeout(()=>i(()=>o(new Error(`Timed out after ${n}ms waiting for canvas state`))),n),a(this._snapshot)})}};function OE(e,t={}){let n=NE({canvasId:e.canvasId,telemetryContext:e.telemetryContext});return new dh({...e,ownsSession:!0,session:n},t)}var ch="xyq.scene.updateDescription";function L3(e,t){var r,o,s,i;let n=tu(e);return n?t==="sceneName"?((r=n.basicInfo)==null?void 0:r.name)??"":t==="sceneViewName"?((o=n.basicInfo)==null?void 0:o.appearanceName)??"":t==="episodes"?n.episodes??[]:((s=n.appearanceInfo)==null?void 0:s.description)??((i=n.basicInfo)==null?void 0:i.description)??"":""}function B3(e,t){return Array.isArray(e)||Array.isArray(t)?!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((n,r)=>n===t[r]):e===t}function G3(e,t){let n=e.getState(),r=x(n).nodes[t.nodeId];if((r==null?void 0:r.type)!==he||r.id!==t.assetId)return;let o=n.assets[t.assetId];if(!(!o||!tu(o)))return{asset:o,node:r}}function U3(e,t){let n=t.value;return B3(L3(e.asset,t.field),n)?t.field!=="sceneName"||e.node.data.name===String(n):!1}function z3(e,t){let n=G3(e,t);return n?U3(n,t)?{status:"noop",reason:"no-changes"}:e.transact(r=>{let o=x(r).nodes[t.nodeId];if((o==null?void 0:o.type)!==he||o.id!==t.assetId)return;let s=$_(r.assets[t.assetId]);if(!(s!=null&&s.content))return;if(t.field==="sceneName"){let a=String(t.value),d=Q_(s.content);o.data.name=a,s.content.basicInfo={...s.content.basicInfo??{},name:a,...d?{appearanceName:a}:{}},d&&(s.content.nodeName=a);return}if(t.field==="sceneViewName"){let a=String(t.value);s.content.nodeName=a,s.content.basicInfo={...s.content.basicInfo??{},appearanceName:a};return}if(t.field==="episodes"){s.content.episodes=Array.isArray(t.value)?[...t.value]:[];return}let i=String(t.value);s.content.basicInfo={...s.content.basicInfo??{},description:i},s.content.appearanceInfo={...Ko(s.content.appearanceInfo),description:i}},{intent:"scene.updateDescription",mergeKey:`scene-description:${t.nodeId}:${t.field}`}):{status:"aborted",reason:"scene asset not found"}}function DE(e){return e.commands.register(ch,z3)}var q3={clearNonRecoverableLocalUploadTasks:(e,t)=>{UR(t.getState(),t)}};function kE(e){let t=OE({...e,generationAgUi:null,legacyGlobalContextBridge:!1},q3),n=DE(t.store),r=t.dispose,o=!1;return t.dispose=()=>{if(!o){o=!0;try{n()}finally{r()}}},{canvas:t,commands:t.store.commands,runtime:t.runtime,store:t.store}}var ME;function LE(e){let t=globalThis.console;if(!t||typeof t!="object")return;let n=t[e];return typeof n=="function"?n.bind(t):void 0}function uh(e,t){var n;(n=LE(e))==null||n(...t),e==="error"&&F3(t)}function F3(e){var t;if(ME)try{ME({packageName:"xyq-canvas-sdk",message:j3(e),error:V3(e),context:H3(e)})}catch(n){(t=LE("warn"))==null||t("[xyq-canvas-sdk] error reporter failed",n)}}function j3(e){return e.filter(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean").map(n=>String(n)).join(" ")||"[xyq-canvas-sdk] error"}function V3(e){for(let t of e){if(t instanceof Error)return t;if(BE(t)&&t.error instanceof Error)return t.error}}function H3(e){let t={},n=20;for(let r of e){if(n<=0)break;if(!(r instanceof Error)&&BE(r))for(let[o,s]of Object.entries(r)){if(n<=0)break;t[o]=Y3(s),n-=1}}return t}function Y3(e){var t;return e instanceof Error?`${e.name}: ${e.message}`:typeof e=="string"?e.length>500?`${e.slice(0,500)}...`:e:e===null||typeof e=="number"||typeof e=="boolean"||typeof e>"u"?e:Array.isArray(e)?`[array:${e.length}]`:typeof e=="object"?`[object:${((t=e.constructor)==null?void 0:t.name)||"Object"}]`:String(e)}function BE(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}var Xe={error:(...e)=>uh("error",e),info:(...e)=>uh("info",e),warn:(...e)=>uh("warn",e)};var Iu=class{constructor(t,n=null,r=null){this.value=t,this.next=n,this.prev=r}},_u=class{get size(){return this._count}get firstNode(){return this._head}isEmpty(){return this._head===null}clear(){let t=this._head;for(;t!==null;){let n=t.next;t.prev=null,t.next=null,t=n}this._head=null,this._tail=null,this._count=0}unshift(t){let n=new Iu(t);if(this.isEmpty())this._head=n,this._tail=n;else{let r=this._head;this._head=n,n.next=r,r.prev=n}return this._count++,this}push(t){let n=new Iu(t);if(this.isEmpty())this._head=n,this._tail=n;else{let r=this._tail;this._tail=n,n.prev=r,r.next=n}return this._count++,this}shift(){if(this.isEmpty())return null;let t=this._head,n=t.value;return this._remove(t),n}pop(){if(this.isEmpty())return null;let t=this._tail,n=t.value;return this._remove(t),n}toArray(){let t=[];for(let n of this)t.push(n);return t}*[Symbol.iterator](){let t=this._head;for(;t!==null;)yield t.value,t=t.next}_remove(t){t.prev===null&&t.next===null&&t!==this._head&&t!==this._tail||(t===this._head&&(this._head=t.next,this._head&&(this._head.prev=null)),t===this._tail&&(this._tail=t.prev,this._tail&&(this._tail.next=null)),t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),t.prev=null,t.next=null,this._count--)}constructor(){this._head=null,this._tail=null,this._count=0}};var as=class extends _u{unshiftAndGetDisposableNode(t){this.unshift(t);let n=this._head,r=!1;return()=>{r||(r=!0,super._remove(n))}}pushAndGetDisposableNode(t){this.push(t);let n=this._tail,r=!1;return()=>{r||(r=!0,super._remove(n))}}};function ph(e){setTimeout(()=>{throw e},0)}var lh=class{invoke(...t){this._callback.call(this._callbackThis,...t)}constructor(t,n){this._callback=t,this._callbackThis=n}},fh=class{constructor(t,n,r){this.emitter=t,this.listener=n,this.event=r}},mh=class{get size(){return this._queue.size}push(t,n,r){this._queue.push(new fh(t,n,r))}clear(t){let n=new as;for(let r of this._queue)r.emitter!==t&&n.push(r);this._queue=n}deliver(){for(;this._queue.size>0;){let t=this._queue.shift();try{t.listener.invoke(...t.event)}catch(n){this._onListenerError(n)}}}constructor(t=ph){this._onListenerError=t,this._queue=new as}},pa=class{get event(){return this._event?this._event:(this._event=(t,n)=>{var r;let o=new lh(t,n);this._listeners||(this._listeners=new as);let s=this._listeners.pushAndGetDisposableNode(o);return!((r=this._options)===null||r===void 0)&&r.onAddListener&&this._options.onAddListener(this,t,n),zi(()=>{if(!this._disposed){var a;s(),!((a=this._options)===null||a===void 0)&&a.onRemoveListener&&this._options.onRemoveListener(this,t,n)}})},this._event)}dispose(){var t,n;this._disposed||(this._disposed=!0,(t=this._listeners)===null||t===void 0||t.clear(),(n=this._deliveryQueue)===null||n===void 0||n.clear(this))}fire(...t){var n;if(!(!this._listeners||this._listeners.size===0)){if(this._listeners.size===1){let s=this._listeners.firstNode;try{s.value.invoke(...t)}catch(i){var r;!((r=this._options)===null||r===void 0)&&r.onListenerError?this._options.onListenerError(i):ph(i)}return}var o;(o=this._deliveryQueue)!==null&&o!==void 0||(this._deliveryQueue=new mh((n=this._options)===null||n===void 0?void 0:n.onListenerError));for(let s of this._listeners)this._deliveryQueue.push(this,s,t);this._deliveryQueue.deliver()}}constructor(t){this._disposed=!1,this._options=t}};var K3=.2,je=Math.ceil((16+4)/K3);function C(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function q(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function la(e,t=300){let n=e.replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}...`:n}function GE(e,...t){if(e)for(let n of t){let r=e[n];if(C(r))return r}}var fa=Vr.getDefaultSize({}),zE=96,gh=48,yh=72,Ah=120,qE=2,ds=48,FE=400,jE=3,vh=3,VE=Number.MAX_SAFE_INTEGER;function UE(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function X3(e){return q(e.id)}function Sh(e,t){let n=X3(t);if(!n)return;let r=e.assets[n];if(!(!C(r)||!C(r.content)))return r.content}function hh(e,t){var r;if(typeof t.order=="number"&&Number.isFinite(t.order))return t.order;let n=(r=Sh(e,t))==null?void 0:r.order;return typeof n=="number"&&Number.isFinite(n)?n:VE}function HE(e,t){var r;if(typeof t.order=="number"&&Number.isFinite(t.order))return;let n=(r=Sh(e,t))==null?void 0:r.order;return typeof n=="number"&&Number.isFinite(n)?n:void 0}function Jr(e,t){return[...t].sort((n,r)=>{let o=hh(e,n),s=hh(e,r);return o!==s?o-s:String(n.id).localeCompare(String(r.id))})}function YE(e,t){let n=Sh(e,t),r=C(n==null?void 0:n.basicInfo)?n.basicInfo:void 0,o=C(t.data)?t.data:void 0;return q(r==null?void 0:r.name)||q(o==null?void 0:o.name)||q(n==null?void 0:n.name)||q(n==null?void 0:n.nodeName)||q(r==null?void 0:r.appearanceName)||q(r==null?void 0:r.stageTag)||q(r==null?void 0:r.label)||String(t.id)}function cs(e,t){return{w:UE(e.w)?e.w:t.w,h:UE(e.h)?e.h:t.h}}function KE(e,t){let n=cs(e,t);return{...n,h:n.h+je}}function us(e,t){return Math.min(...t.map(n=>hh(e,n)))}function ps(e,t){return e.order-t.order}function Ru(e){return e.stackHeight??e.height}function Zt(e){return(e==null?void 0:e.type)===z}function en(e){return(e==null?void 0:e.type)===he}function Zr(e){return(e==null?void 0:e.type)===be&&Array.isArray(e.children)}function XE(e,t){let n=new Set;return e.children.map(r=>t[r]).filter(r=>!r||r.parentId!==e.id||n.has(r.id)?!1:(n.add(r.id),!0))}function $E(e){if(e.length!==0){if(e.filter(Zt).length===e.length)return"role";if(e.filter(en).length===e.length)return"scene"}}function ls(e,t,n){let r=cs(t,n);return{order:us(e,[t]),width:r.w,height:r.h,stackHeight:r.h+je,apply:(o,s)=>{s.set(t.id,{x:o.x,y:o.y,width:r.w,height:r.h})}}}function ma(e,t,n){var u;let r=[...e].sort(ps),o=Math.max(1,Math.min(n,Math.ceil(Math.sqrt(r.length)))),s=Math.ceil(r.length/o),i=new Map,a=0,d=0,c=0;return Array.from({length:s}).forEach((p,l)=>{let f=r.slice(l*o,(l+1)*o),h=0,m=Math.max(...f.map(y=>y.height),0),g=Math.max(...f.map(Ru),0);f.forEach(y=>{i.set(y,{x:h,y:c+(m-y.height)/2}),h+=y.width+t}),a=Math.max(a,Math.max(0,h-t)),d=Math.max(d,c+m),c+=g+(l<s-1?t:0)}),{order:((u=r[0])==null?void 0:u.order)??VE,width:a,height:d,stackHeight:c,apply:(p,l)=>{r.forEach(f=>{let h=i.get(f)??{x:0,y:0};f.apply({x:p.x+h.x,y:p.y+h.y},l)})}}}var Xg=ed(np());function rp(e,t){let n=new Set;return e.children.map(r=>t[r]).filter(r=>!r||r.parentId!==e.id||n.has(r.id)?!1:(n.add(r.id),!0))}function YM(e){return Object.fromEntries(Object.entries(e).map(([t,n])=>{let r={...n};return Array.isArray(n.children)&&(r.children=[...n.children??[]]),[t,r]}))}function op(e,t,n,r){let o=r[e.rootCanvasId],s=x(e);return{...e,assets:{...r,[e.rootCanvasId]:{...o,content:{...s,edges:n,nodes:t}}}}}function Cs(e){return{maxX:e.x+e.w,maxY:e.y+e.h+je,minX:e.x,minY:e.y}}function Dt(e){let t=e.filter(n=>!!n);if(t.length!==0)return t.reduce((n,r)=>({maxX:Math.max(n.maxX,r.maxX),maxY:Math.max(n.maxY,r.maxY),minX:Math.min(n.minX,r.minX),minY:Math.min(n.minY,r.minY)}),{...t[0]})}function sn(e,t){return!e||!t?e?-1:t?1:0:(e.order??0)-(t.order??0)||e.y-t.y||e.x-t.x||e.id.localeCompare(t.id)}function dde(e){let t=[...e].sort(sn),n=Math.max(1,Math.min(3,Math.ceil(Math.sqrt(t.length)))),r=Math.max(...t.map(i=>i.w),0),o=Math.max(...t.map(i=>i.h),0),s=new Map;return t.forEach((i,a)=>{s.set(i.id,{x:a%n*(r+80),y:Math.floor(a/n)*(o+je+64)})}),s}function XM(e,t,n,r=new Set){if(t===n)return!0;if(r.has(t))return!1;r.add(t);let o=e.get(t);if(!o)return!1;for(let s of o)if(XM(e,s,n,r))return!0;return!1}function cde(e,t){let n=new Set(e.map(i=>i.id)),r=new Map,o=[],s=new Set;return[...t].sort((i,a)=>String(i.id).localeCompare(String(a.id))).forEach(i=>{if(!n.has(i.source)||!n.has(i.target)||i.source===i.target)return;let a=`${i.source}->${i.target}`;if(s.has(a)||XM(r,i.target,i.source))return;s.add(a);let d=r.get(i.source)??new Set;d.add(i.target),r.set(i.source,d),o.push(i)}),o}function KM(e,t,n,r){if(r.has(e))return r.get(e);let o=[],s=e,i;for(;s;){if(t.has(s)){i=s;break}if(o.includes(s))break;o.push(s);let a=n.get(s);s=typeof(a==null?void 0:a.parentId)=="string"?a.parentId:null}return r.set(e,i),o.forEach(a=>r.set(a,i)),i}function ude(e,t,n){let r=new Set(e.map(a=>a.id)),o=new Map,s=new Set,i=[];return[...t].sort((a,d)=>String(a.id).localeCompare(String(d.id))).forEach(a=>{let d=KM(a.source,r,n,o),c=KM(a.target,r,n,o);if(!d||!c||d===c)return;let u=`${d}->${c}`;s.has(u)||(s.add(u),i.push({...a,id:`${String(a.id)}:layout:${u}`,source:d,target:c}))}),i}function pde(e,t){if(t.length===0)return;let n=cde(e,t);if(n.length===0)return;let r=new Xg.default.graphlib.Graph;r.setDefaultEdgeLabel(()=>({})),r.setGraph({marginx:0,marginy:0,nodesep:64,rankdir:"LR",ranker:"tight-tree",ranksep:80});let o=[...e].sort(sn),s=new Map;o.forEach(c=>{let u=c.h+je;s.set(c.id,u),r.setNode(c.id,{width:c.w,height:u})}),n.forEach(c=>r.setEdge(c.source,c.target)),Xg.default.layout(r);let i=new Map,a=[];return o.forEach(c=>{let u=s.get(c.id)??c.h+je,p=r.node(c.id),l=(p==null?void 0:p.x)??c.w/2;a.push(l.toFixed(3)),i.set(c.id,{x:l-c.w/2,y:((p==null?void 0:p.y)??u/2)-u/2})}),new Set(a).size===i.size&&i.forEach((c,u)=>{i.set(u,{x:c.x,y:0})}),i}function lde(e,t){let n=new Set(e.map(i=>i.id)),r=t.filter(i=>n.has(i.source)&&n.has(i.target)),o=pde(e,r)??dde(e),s=Dt(e.map(i=>{let a=o.get(i.id)??{x:0,y:0};return{maxX:a.x+i.w,maxY:a.y+i.h+je,minX:a.x,minY:a.y}}))??{minX:0,minY:0,maxX:1,maxY:1};return(s.minX!==0||s.minY!==0)&&o.forEach((i,a)=>{o.set(a,{x:i.x-s.minX,y:i.y-s.minY})}),{edges:r,height:Math.max(1,s.maxY-s.minY),nodes:e,relativePositions:o,width:Math.max(1,s.maxX-s.minX)}}function $M(e,t,n=e){let r=new Map(e.map(c=>[c.id,c])),o=new Map(n.map(c=>[c.id,c])),s=ude(e,t,o),i=new Map;r.forEach((c,u)=>i.set(u,new Set)),s.forEach(c=>{var u,p;(u=i.get(c.source))==null||u.add(c.target),(p=i.get(c.target))==null||p.add(c.source)});let a=new Set,d=[];return e.sort(sn).forEach(c=>{var f;if(a.has(c.id))return;let u=[],p=[c.id];for(a.add(c.id);p.length>0;){let h=p.shift();u.push(h),(f=i.get(h))==null||f.forEach(m=>{a.has(m)||(a.add(m),p.push(m))})}let l=u.map(h=>r.get(h)).filter(h=>!!h);d.push(lde(l,s))}),d.sort((c,u)=>sn(c.nodes[0],u.nodes[0]))}function fde(e){return Math.max(1,Math.min(3,Math.ceil(Math.sqrt(e.length))))}function $g(e,t,n=fde(e)){let r=[...e].sort((a,d)=>sn(a.nodes[0],d.nodes[0])),o=Math.max(1,Math.min(n,r.length)),s=[],{y:i}=t;for(let a=0;a<r.length;a+=o){let d=r.slice(a,a+o),{x:c}=t,u=Math.max(...d.map(p=>p.height),0);for(let p of d)s.push({component:p,x:c,y:i+(u-p.height)/2}),c+=p.width+72;i+=u+72}return s}function JM(e,t,n){let r=Dt([n,...e.map(({component:a,x:d,y:c})=>({maxX:d+a.width,maxY:c+a.height,minX:d,minY:c}))]);if(!r)return{aspectError:Number.POSITIVE_INFINITY,area:Number.POSITIVE_INFINITY};let o=r.maxX-r.minX,s=r.maxY-r.minY,i=o/Math.max(1,s);return{area:o*s,aspectError:Math.abs(Math.log(i/t))}}function ZM(e,t,n,r){if(!n||e.length<=1)return $g(e,t);let o=e.length,s=$g(e,t,1),i=JM(s,n,r);for(let a=2;a<=o;a+=1){let d=$g(e,t,a),c=JM(d,n,r);(c.aspectError<i.aspectError||c.aspectError===i.aspectError&&c.area<i.area)&&(s=d,i=c)}return s}function mde(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0}function hde(e){return Dt([e.roleBounds,e.sceneBounds,...e.mixedBounds])}function gde(e,t){let{roleBounds:n,sceneBounds:r}=e;return n&&r?{x:r.maxX+96,y:t.minY}:{x:t.maxX+96,y:t.minY}}function eL(e,t,n,r){let o=n?{x:n.minX,y:n.minY}:{x:0,y:0},s=mde(r),i=hde(t);return i?ZM(e,gde(t,i),s,i):ZM(e,o,s)}function yde(e,t){if(Zt(e))return"role";if(en(e))return"scene";if(!Zr(e))return;let n=rp(e,t);if(n.length===0)return;if(n.filter(Zt).length===n.length)return"role";if(n.filter(en).length===n.length)return"scene"}function oL(e,t){if(Zt(e)||en(e))return!0;if(!Zr(e))return!1;let n=rp(e,t);return n.length>0&&n.every(r=>Zt(r)||en(r))}function Wg(e,t){return oL(e,t)?!1:e.type===Ie||e.type===L||e.type===me||e.type===ue||e.type===M||Zr(e)}function pr(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function an(e){return typeof e=="number"&&Number.isFinite(e)}function kn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Qg(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Ade(e){return(e==null?void 0:e.type)===Ie||(e==null?void 0:e.type)===L||(e==null?void 0:e.type)===me||(e==null?void 0:e.type)===ue||(e==null?void 0:e.type)===M}function tL(e){if(!(!kn(e)||!kn(e.content)))return e.content}function vde(e,t){if(!t)return;let n=tL(e[t]);if(n)return n;for(let r of Object.values(e)){if(!kn(r)||Qg(r.pippitAssetId)!==t)continue;let o=tL(r);if(o)return o}}function sL(e){let{data:t}=e;return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function Sde(e,t){let n=kn(e)?e:void 0,r=Qg(n==null?void 0:n.pippitAssetId)||Qg(e.id);return vde(t,r)}function nL(e,t){let n=sL(e),r=Sde(e,t);if(!r)return n;let o=kn(r.data)?r.data:r,s={...n,...o};return(kn(n.metadata)||kn(o.metadata))&&(s.metadata={...kn(n.metadata)?n.metadata:{},...kn(o.metadata)?o.metadata:{}}),s}function rL({defaultSize:e,mediaSize:t}){let n=t.w>0&&t.h>0?t.w/t.h:void 0;if(!n)return e;let r=Math.max(1,e.w*e.h);return{w:Math.round(Math.sqrt(r*n)),h:Math.round(Math.sqrt(r/n))}}function bde(e,t){var r,o,s,i,a,d,c,u,p,l,f,h,m,g;let n=sL(e);switch(e.type){case Ie:return((o=(r=Qn).getDefaultSize)==null?void 0:o.call(r,n))??{w:420,h:180};case L:{let y=nL(e,t),v=((i=(s=En).getDefaultSize)==null?void 0:i.call(s,{}))??{w:480,h:373},S=((d=(a=En).getDefaultSize)==null?void 0:d.call(a,y))??v;return rL({defaultSize:v,mediaSize:S})}case me:return((u=(c=Zc).getDefaultSize)==null?void 0:u.call(c,n))??{w:320,h:180};case ue:return((l=(p=Wn).getDefaultSize)==null?void 0:l.call(p,n))??{w:362,h:218};case M:{let y=nL(e,t),v=((h=(f=Cn).getDefaultSize)==null?void 0:h.call(f,{}))??{w:480,h:270},S=((g=(m=Cn).getDefaultSize)==null?void 0:g.call(m,y))??v;return rL({defaultSize:v,mediaSize:S})}default:return}}function lr(e){return an(e.x)&&an(e.y)&&pr(e.w)&&pr(e.h)}function Jg(e,t){let n=!1;if(an(e.x)||(e.x=0,n=!0),an(e.y)||(e.y=0,n=!0),pr(e.w)&&pr(e.h))return n;let r=bde(e,t);return r&&(pr(e.w)||(e.w=r.w,n=!0),pr(e.h)||(e.h=r.h,n=!0)),n}function Zg(e){return!an(e.x)||!an(e.y)||e.x===0&&e.y===0}function iL(e,t){let n=Dt(t.filter(lr).map(Cs));if(!n)return!1;let r=!1,o=n.maxX+80,s=n.minY;return[...e].sort(sn).forEach(i=>{lr(i)&&(i.x!==o&&(i.x=o,r=!0),i.y!==s&&(i.y=s,r=!0),o+=i.w+80)}),r}function aL(e,t,n){let r=kr(e)?hi(e):{w:e.w,h:e.h},o=pr(r.w)?Math.max(r.w,t):t,s=pr(r.h)?Math.max(r.h,n):n;return o===r.w&&s===r.h?!1:(gi(e,{w:o,h:s}),!0)}function Ide(e,t){let n=Dt(t.filter(lr).map(i=>({maxX:i.x+i.w,maxY:i.y+i.h+je,minX:i.x,minY:i.y})));if(!n)return!1;let r=!1;an(e.x)||(e.x=0,r=!0),an(e.y)||(e.y=0,r=!0);let o=Math.max(40*2,n.maxX+40),s=Math.max(40*2,n.maxY+40);return aL(e,o,s)||r}function _de(e,t,n,r){let o=rp(e,t).filter(Ade),s=o.filter(m=>!lr(m));if(o.length===0||s.length===0)return!1;let i=new Set(s.filter(Zg).map(m=>m.id)),a=!1;if(s.forEach(m=>{a=Jg(m,n)||a}),r&&s.length<o.length){let m=o.filter(y=>i.has(y.id)),g=o.filter(y=>!i.has(y.id)&&lr(y));return a=iL(m,g)||a,Ide(e,o)||a}let d=[...o].sort(sn),c=Math.max(1,Math.min(3,Math.ceil(Math.sqrt(d.length)))),u=Math.ceil(d.length/c),p=Math.max(...d.map(m=>m.w),1),l=Math.max(...d.map(m=>m.h+je),1);d.forEach((m,g)=>{let y=40+g%c*(p+80),v=40+Math.floor(g/c)*(l+64);m.x!==y&&(m.x=y,a=!0),m.y!==v&&(m.y=v,a=!0)});let f=40*2+c*p+Math.max(0,c-1)*80,h=40*2+u*l+Math.max(0,u-1)*64;return an(e.x)||(e.x=0,a=!0),an(e.y)||(e.y=0,a=!0),aL(e,f,h)||a}function Rde(e,t,n,r){let o=!1;return e.forEach(s=>{!Zr(s)||!Wg(s,t)||(o=_de(s,t,n,r)||o)}),o}function Ede(e,t){let n=[],r=[],o=[];return e.forEach(s=>{let i=yde(s,t);if(i==="role"){n.push(Cs(s));return}if(i==="scene"){r.push(Cs(s));return}oL(s,t)&&o.push(Cs(s))}),{mixedBounds:o,roleBounds:Dt(n),sceneBounds:Dt(r)}}function dL(e,t){let n=x(e),r=YM(n.nodes),o=Object.values(r).filter(g=>(g.parentId??null)===null),s=t.repairInvalidOnly===!0,i=s?new Set(o.filter(g=>Wg(g,r)).filter(g=>!lr(g)&&Zg(g)).map(g=>g.id)):new Set,a=Rde(o,r,e.assets,s),d=Ede(o,r),c=o.filter(g=>Wg(g,r));if(c.length===0)return a?op(e,r,n.edges,e.assets):e;let u=c.filter(g=>!lr(g)),p=new Set([...i,...u.filter(Zg).map(g=>g.id)]),l=!1;if(u.forEach(g=>{l=Jg(g,e.assets)||l}),s&&u.length<c.length){let g=c.filter(v=>p.has(v.id)),y=c.filter(v=>!p.has(v.id)&&lr(v));if(g.length===0||y.length>0)return l=iL(g,y)||l,a||l?op(e,r,n.edges,e.assets):e}s||c.forEach(g=>{l=Jg(g,e.assets)||l});let f=$M(c,Object.values(n.edges),Object.values(r));if(f.length===0)return e;let h=Dt(c.map(g=>Cs(g)));return eL(f,d,h,t.aspectRatio).forEach(({component:g,x:y,y:v})=>{g.relativePositions.forEach((S,b)=>{let I=r[b];I&&(I.x=y+S.x,I.y=v+S.y)})}),op(e,r,n.edges,e.assets)}var Ha=class extends Error{constructor(n){super(n);this.restoreFailureReason="empty-text-asset";this.name="CanvasAssetNotFoundError"}};function ey(e,t){return!!(t!=null&&t.aborted||e instanceof Error&&e.name==="AbortError"||typeof DOMException<"u"&&e instanceof DOMException&&e.name==="AbortError")}function ty(e){return e instanceof Ha?e.restoreFailureReason:void 0}function cL(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown canvas restore failure")}var sy=ed(np());var ny=ed(np());function Cde(e,t){let n=[],r=new Map;return Jr(e,t).forEach(o=>{let s=YE(e,o),i=r.get(s);i||(i=[],r.set(s,i),n.push(i)),i.push(o)}),n}function Pde(e,t,n){let r=t;for(;r;){if(r===n)return!0;r=e.get(r)}return!1}function xde(e,t){let n=new Set(e.map(s=>s.id)),r=new Map,o=[];return[...t].sort((s,i)=>String(s.id).localeCompare(String(i.id))).forEach(s=>{!n.has(s.source)||!n.has(s.target)||s.source===s.target||r.has(s.target)||Pde(r,s.source,s.target)||(r.set(s.target,s.source),o.push(s))}),o}function Tde(e,t,n){if(t.length===1)return ls(e,t[0],fa);let r=new ny.default.graphlib.Graph;r.setDefaultEdgeLabel(()=>({})),r.setGraph({rankdir:"LR",nodesep:gh,ranksep:zE,ranker:"tight-tree",marginx:0,marginy:0});let o=Jr(e,t),s=new Map,i=new Map;o.forEach(l=>{let f=cs(l,fa),h=KE(l,fa);s.set(l.id,f),i.set(l.id,h),r.setNode(l.id,{width:h.w,height:h.h})}),xde(o,n).forEach(l=>r.setEdge(l.source,l.target)),ny.default.layout(r);let a=new Map,d=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY,p=Number.NEGATIVE_INFINITY;return o.forEach(l=>{let f=s.get(l.id)??fa,h=i.get(l.id)??f,m=r.node(l.id),g=((m==null?void 0:m.x)??h.w/2)-h.w/2,y=((m==null?void 0:m.y)??h.h/2)-h.h/2;a.set(l.id,{x:g,y,width:f.w,height:f.h}),d=Math.min(d,g),c=Math.min(c,y),u=Math.max(u,g+h.w),p=Math.max(p,y+h.h)}),{order:us(e,o),width:Math.max(1,u-d),height:Math.max(1,p-c),apply:(l,f)=>{a.forEach((h,m)=>{f.set(m,{x:l.x+h.x-d,y:l.y+h.y-c,width:h.width,height:h.height})})}}}function Nde(e,t){return ps(e.block,t.block)}function ry(e,t,n){return Cde(e,t).map(r=>({kind:r.length===1?"single":"group",block:Tde(e,r,n)}))}function oy(e){let t=[],n=[],r=()=>{n.length!==0&&(t.push(ma(n,gh,jE)),n=[])};return[...e].sort(Nde).forEach(o=>{if(o.kind==="single"){n.push(o.block);return}r(),t.push(o.block)}),r(),t}function uL(e,t,n){return oy(ry(e,t,n))}function pL(e,t,n,r=new Set){if(t===n)return!0;if(r.has(t))return!1;r.add(t);let o=e.get(t);if(!o)return!1;for(let s of o)if(pL(e,s,n,r))return!0;return!1}function wde(e,t){let n=new Set(e.map(s=>s.id)),r=new Map,o=[];return[...t].sort((s,i)=>String(s.id).localeCompare(String(i.id))).forEach(s=>{if(!n.has(s.source)||!n.has(s.target)||s.source===s.target||pL(r,s.target,s.source))return;let i=r.get(s.source)??new Set;i.add(s.target),r.set(s.source,i),o.push(s)}),o}function Ode(e,t,n,r,o,s){if(t.length===0)return;if(t.length===1)return ls(e,t[0],r);let i=wde(t,n);if(i.length===0)return;let a=new sy.default.graphlib.Graph;a.setDefaultEdgeLabel(()=>({})),a.setGraph({rankdir:"LR",nodesep:o,ranksep:s,ranker:"tight-tree",marginx:0,marginy:0});let d=Jr(e,t),c=new Map;d.forEach(m=>{let g=cs(m,r);c.set(m.id,g),a.setNode(m.id,{width:g.w,height:g.h})}),i.forEach(m=>a.setEdge(m.source,m.target)),sy.default.layout(a);let u=new Map,p=Number.POSITIVE_INFINITY,l=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY;return d.forEach(m=>{let g=c.get(m.id)??r,y=a.node(m.id),v=((y==null?void 0:y.x)??g.w/2)-g.w/2,S=((y==null?void 0:y.y)??g.h/2)-g.h/2;u.set(m.id,{x:v,y:S,width:g.w,height:g.h}),p=Math.min(p,v),l=Math.min(l,S),f=Math.max(f,v+g.w),h=Math.max(h,S+g.h)}),{order:us(e,d),width:Math.max(1,f-p),height:Math.max(1,h-l),apply:(m,g)=>{u.forEach((y,v)=>{g.set(v,{x:m.x+y.x-p,y:m.y+y.y-l,width:y.width,height:y.height})})}}}function lL(e,t,n,r){let{y:o}=t,s=0,i=0;return[...e].sort(ps).forEach((a,d)=>{d>0&&(o+=n),a.apply({x:t.x,y:o},r),o+=Ru(a),s=Math.max(s,a.width),i=o-t.y}),{width:s,height:i}}function Dde(e,t,n){let r=[...e].sort(ps);if(r.length===0)return{width:0,height:0};let o=Math.max(1,Math.min(qE,Math.ceil(Math.sqrt(r.length)))),s=Array.from({length:o},()=>({items:[],width:0,height:0}));r.forEach(a=>{let d=s.reduce((u,p)=>p.height<u.height||p.height===u.height&&p.items.length<u.items.length?p:u),c=d.height>0?d.height+yh:0;d.items.push({block:a,y:c}),d.width=Math.max(d.width,a.width),d.height=c+Ru(a)});let i=s.map((a,d)=>s.slice(0,d).reduce((c,u)=>c+u.width+Ah,0));return s.forEach((a,d)=>{a.items.forEach(({block:c,y:u})=>{c.apply({x:t.x+i[d],y:t.y+u},n)})}),{width:s.reduce((a,d)=>a+d.width,0)+Ah*(s.length-1),height:Math.max(...s.map(a=>a.height))}}function kde(e,t,n=[]){let r=Ode(e,t,n,Yr,ds,ds);if(r)return r;let o=Jr(e,t).map(s=>ls(e,s,Yr));return o.length>0?ma(o,ds,vh):void 0}function Mde(e){let t;for(let n of e){let r={minX:n.x,minY:n.y,maxX:n.x+n.width,maxY:n.y+n.height};t=t?{minX:Math.min(t.minX,r.minX),minY:Math.min(t.minY,r.minY),maxX:Math.max(t.maxX,r.maxX),maxY:Math.max(t.maxY,r.maxY)}:r}return t}function Lde(e,t,n,r,o){let s=o==="role"?uL(e,n.filter(Zt),r):[kde(e,n.filter(en),r)].filter(u=>!!u);if(s.length===0)return;let i=new Map;lL(s,{x:0,y:0},yh,i);let a=Mde(i.values())??{minX:0,minY:0,maxX:1,maxY:1},d=Math.max(1,a.maxX-a.minX+40*2),c=Math.max(1,a.maxY-a.minY+40*2);return{order:us(e,n),width:d,height:c,stackHeight:c+je,apply:(u,p)=>{p.set(t.id,{x:u.x,y:u.y,width:d,height:c}),i.forEach((l,f)=>{p.set(f,{...l,x:l.x-a.minX+40,y:l.y-a.minY+40})})}}}function fL(e,t,n){let r=new Map,s=Jr(e,Object.values(t)).filter(f=>!f.parentId),i=ry(e,s.filter(Zt),n),d=s.filter(en).map(f=>ls(e,f,Yr));s.filter(Zr).forEach(f=>{let h=XE(f,t),m=$E(h);if(!m)return;let g=Lde(e,f,h,n,m);if(g){if(m==="role"){i.push({kind:"group",block:g});return}m==="scene"&&d.push(g)}});let c=oy(i),u=d.length>0?ma(d,ds,vh):void 0,p=Dde(c,{x:0,y:0},r),l=c.length>0?p.width+FE:0;return lL(u?[u]:[],{x:l,y:0},ds,r),r}var sp={name:"role-tree-scene-columns",layout(e){let t=x(e),n=fL(e,t.nodes,Object.values(t.edges)),r={},o=!1;if(Object.values(t.nodes).forEach(i=>{let a=n.get(i.id),d=HE(e,i),c=a||d!==void 0?{...i,...d!==void 0?{order:d}:{},...a?{x:a.x,y:a.y,w:a.width,h:a.height}:{}}:i;r[i.id]=c,c!==i&&(c.x!==i.x||c.y!==i.y||c.w!==i.w||c.h!==i.h||c.order!==i.order)&&(o=!0)}),!o)return e;let s=e.assets[e.rootCanvasId];return{...e,assets:{...e.assets,[e.rootCanvasId]:{...s,content:{...t,nodes:r}}}}}};var iy="[novel-detail-canvas]";function Bde(){var t,n;let e=globalThis.process;return((t=e==null?void 0:e.env)==null?void 0:t.JEST_WORKER_ID)==null&&((n=e==null?void 0:e.env)==null?void 0:n.VITEST)==null}function Gde(e){let{error:t,...n}=e.payload??{},r=C(t)?t:void 0,o=typeof(r==null?void 0:r.name)=="string"?r.name:void 0,s=typeof(r==null?void 0:r.message)=="string"?r.message:void 0;return{canvasAssetId:e.canvasAssetId,...n,...o?{canvas_restore_error_name:la(o,128)}:{},...s?{canvas_restore_error_message:la(s,256)}:{}}}function mL(e,t={},n){var s;if((s=t.logger)==null||s.call(t,e),!Bde()||t.debugLog===!1&&e.level==="info")return;let r=Gde(e),o=n===void 0?void 0:cL(n);if(e.level==="error"){Xe.error(iy,e.type,...o?[o,r]:[r]);return}if(e.level==="warn"){Xe.warn(iy,e.type,...o?[o,r]:[r]);return}Xe.info(iy,e.type,...o?[o,r]:[r])}function Ya(e){let t=C(e.assets)?e.assets:{},n=t[e.rootCanvasId],r=C(n)&&C(n.content)?n.content:null,o=r&&C(r.nodes)?r.nodes:null,s=r&&C(r.edges)?r.edges:null;return{rootCanvasId:e.rootCanvasId,assetKeys:Object.keys(t).slice(0,20),rootAssetKeys:C(n)?Object.keys(n).slice(0,30):[],nodeCount:o?Object.keys(o).length:void 0,edgeCount:s?Object.keys(s).length:void 0}}function ip(e){if(e==null)return{type:String(e)};if(typeof e=="string")return{type:"string",length:e.length,preview:la(e)};if(Array.isArray(e))return{type:"array",length:e.length,first:ip(e[0])};if(typeof e=="object"){let t=e;return{type:"object",keys:Object.keys(t).slice(0,50),rootCanvasId:t.rootCanvasId,root_canvas_id:t.root_canvas_id,typeField:t.type,hasAssets:C(t.assets),hasContent:t.content!=null,hasData:t.data!=null,hasDocument:t.document!=null,hasCanvasDocument:t.canvasDocument!=null,hasSnapshot:t.snapshot!=null}}return{type:typeof e,value:e}}function Ps(e){return{pippitAssetId:e.pippitAssetId,value:ip(e.value),extra:ip(e.extra)}}function dn(e){return e instanceof Error?{name:e.name,message:e.message,stack:la(e.stack??"",500)}:ip(e)}function xs(e){let t=C(e)?e:void 0;return q(t==null?void 0:t.pippitAssetId)||q(t==null?void 0:t.id)}var Ude=new Set([L,me,M]),zde=new Set([z,he]);function gL(e,t){let n=xs(t);return n?e.assets[n]:void 0}function qde(e,t){let n=C(t.data)?t.data:{},r=gL(e,t),o=C(r)&&C(r.content)?r.content:{};return{...n,...o}}function hL(e){let t=C(e.appearanceInfo)?e.appearanceInfo:void 0;return q(t==null?void 0:t.pippitAssetId)||q(t==null?void 0:t.PippitAssetID)}function Fde(e,t){if(t.type===Qr)return CE(gL(e,t));let n=qde(e,t);if(zde.has(t.type))return hL(n);if(Ude.has(t.type))return q(n.pippitAssetId)||hL(n)}function ay(e,t){let n=new Set;return Object.values(x(e).nodes).forEach(r=>{let o=xs(r);if(t&&(!o||!t.has(o)))return;let s=Fde(e,r);s&&n.add(s)}),[...n].sort()}var yL=150,jde=10;function Vde(e,t){return!!(t!=null&&t.aborted||e instanceof Error&&e.name==="AbortError"||typeof DOMException<"u"&&e instanceof DOMException&&e.name==="AbortError")}function AL(e){let t=[],n=new Set,r=new Set,o=0,s=()=>{o||t.length||(r.forEach(a=>a()),r.clear())},i=()=>{var u;if((u=e.signal)!=null&&u.aborted){t.splice(0),s();return}let a=jde-o;if(a<=0||t.length===0){s();return}let d=t.splice(0,a*yL);gn(d,yL,a).forEach(p=>{o+=1,e.emit({type:"cover-assets-query:start",level:"info",canvasAssetId:e.canvasAssetId,payload:{assetIds:p}}),e.prefetchCoverAssets({pippitAssetIds:p,signal:e.signal}).then(()=>{e.emit({type:"cover-assets-query:success",level:"info",canvasAssetId:e.canvasAssetId,payload:{assetIds:p}})}).catch(l=>{Vde(l,e.signal)||(e.emit({type:"cover-assets-query:error",level:"warn",canvasAssetId:e.canvasAssetId,payload:{assetIds:p,error:dn(l)}}),Xe.warn("[xyq-canvas] Failed to prefetch canvas cover assets",{canvasAssetId:e.canvasAssetId,assetIds:p,error:dn(l)}))}).finally(()=>{o-=1,i()})})};return{enqueue(a){a.forEach(d=>{let c=q(d);!c||n.has(c)||(n.add(c),t.push(c))}),i()},waitForIdle(){return!o&&t.length===0?Promise.resolve():new Promise(a=>r.add(a))}}}var bL=150,fr=10;function Hde(e,t){let n={pippitAssetIds:e,isCamelCase:!0};return t&&(n.signal=t),n}function IL(e){let t=0,n=[],r=()=>t<e?(t+=1,Promise.resolve()):new Promise(s=>{n.push(()=>{t+=1,s()})}),o=()=>{var s;t-=1,(s=n.shift())==null||s()};return{async run(s){await r();try{return await s()}finally{o()}}}}function vL(e){if(e.reason instanceof Error)return e.reason;let t=new Error("Canvas node asset query aborted");return t.name="AbortError",t}function _L(e,t){return!!(t!=null&&t.aborted||e instanceof Error&&e.name==="AbortError"||typeof DOMException<"u"&&e instanceof DOMException&&e.name==="AbortError")}function RL(e,t){let n=async()=>{var s,i;if((s=t.signal)!=null&&s.aborted)throw vL(t.signal);let r=Hde(e,t.signal),o=await(t.queryTextAssetContent.queryImmediately?t.queryTextAssetContent.queryImmediately(r):t.queryTextAssetContent(r));if((i=t.signal)!=null&&i.aborted)throw vL(t.signal);return o};return t.queryLimiter?t.queryLimiter.run(n):n()}async function dy(e,t,n){let r=new Array(e.length),o=0,s=async()=>{for(;o<e.length;){let a=o;o+=1;let d=e[a];if(d===void 0)return;r[a]=await n(d)}},i=Math.min(t,e.length);return await Promise.all(Array.from({length:i},()=>s())),r}async function Yde(e,t){return(await dy(e,fr,async r=>{try{let o=await RL([r],t);return Array.isArray(o)?o:[]}catch(o){if(_L(o,t.signal))throw o;return[]}})).flat()}function SL(e,t,n,r,o){let s=n.filter(i=>i.value!==null&&i.value!==void 0).map(i=>i.pippitAssetId);r.emit({type:"node-assets-query:success",level:o?"warn":"info",canvasAssetId:e,payload:{requestedAssetIds:t,returnedAssetIds:s,missingAssetIds:t.filter(i=>!s.includes(i)),assets:n.map(Ps),...o?{fallback:"individual",batchError:dn(o)}:{}}})}async function EL(e,t,n){n.emit({type:"node-assets-query:start",level:"info",canvasAssetId:t,payload:{assetIds:e}});try{let r=await RL(e,n);return SL(t,e,r,n),{assetIds:e,assets:r}}catch(r){if(_L(r,n.signal))throw r;let o=await Yde(e,n);if(o.length)return SL(t,e,o,n,r),{assetIds:e,assets:o};let s=dn(r);return n.emit({type:"node-assets-query:error",level:"error",canvasAssetId:t,payload:{assetIds:e,error:s}}),Xe.error("[xyq-canvas] Failed to query canvas node assets during restore",{canvasAssetId:t,nodeAssetIds:e,error:s}),{assetIds:e,assets:[]}}}function Kde(e,t){let n=new Set;return t().filter(r=>!e.has(r)||n.has(r)?!1:(n.add(r),!0))}function Xde(e){return gn(e,bL,fr).slice(0,fr)}async function $de(e,t,n,r){let o=new Set(e),s={...n,queryLimiter:IL(fr)};for(;o.size>0;){let i=Kde(o,n.getPriorityNodeAssetIds),a=i.length?i:[...o],d=Xde(a);d.flat().forEach(c=>o.delete(c)),await dy(d,fr,async c=>{let u=await EL(c,t,s);r(u)})}}async function CL(e,t,n,r){if(n.getPriorityNodeAssetIds){await $de(e,t,n,r);return}let o=gn(e,bL,fr),s={...n,queryLimiter:IL(fr)};await dy(o,fr,async i=>{let a=await EL(i,t,s);r(a)})}var PL=["assetId","pippitAssetId","tagInfos","subType","source","sourceType","src","url","metadata","naturalWidth","naturalHeight","caption","display","generation","variant","episodes","localUploadCache","localUploadTask"],Wde={[L]:PL,[me]:[...PL,"projection"],[M]:["assetId","pippitAssetId","tagInfos","subType","source","src","url","downloadUrl","previewUrl","coverUrl","coverURL","metadata","frameWidth","frameHeight","durationMs","caption","title","playback","generation","variant","episodes"],[Ie]:["plainText","content","contentFormat","markdownText","placeholder","block","generation","variant"],[ue]:["assetId","tagInfos","source","src","durationMs","waveformUrl","waveformKey","playback","generation","variant","episodes"]};function ct(e){if(typeof e=="string"){let t=e.trim();if(!t)return null;try{return ct(JSON.parse(t))}catch{return null}}return C(e)?e:null}function Ka(e){let t=ct(e),n=ct(t==null?void 0:t.content);return n&&((t==null?void 0:t.protocolVersion)!==void 0||(t==null?void 0:t.protocol_version)!==void 0)?n:e}function Qde(e){return C(e)?e.nodeName!==void 0||e.order!==void 0||e.basicInfo!==void 0||e.useContext!==void 0||e.episodes!==void 0||e.createType!==void 0||e.appearanceInfo!==void 0||e.referenceAppearances!==void 0||e.voiceInfo!==void 0||e.generation!==void 0||e.sourceInfos!==void 0:!1}function Jde(e){let t=Pt(e);return{...e.nodeName!==void 0?{nodeName:e.nodeName}:{},...e.order!==void 0?{order:e.order}:{},...e.basicInfo!==void 0?{basicInfo:e.basicInfo}:{},...e.useContext!==void 0?{useContext:e.useContext}:{},...e.episodes!==void 0?{episodes:e.episodes}:{},...e.createType!==void 0?{createType:e.createType}:{},...e.appearanceInfo!==void 0?{appearanceInfo:e.appearanceInfo}:{},...e.referenceAppearances!==void 0?{referenceAppearances:e.referenceAppearances}:{},...t!==void 0?{voiceInfo:t}:{},...e.generation!==void 0?{generation:e.generation}:{},...e.sourceInfos!==void 0?{sourceInfos:e.sourceInfos}:{}}}function Zde(e){if(e!==void 0)return Array.isArray(e)?e.reduce((t,n)=>{let r=ct(n);return Kc(r)&&t.push(r),t},[]):[]}function ece(e){let t=Xo(e.sourceInfos),n=Zde(e.referenceAppearances),{referenceAppearances:r,sourceInfos:o,...s}=e,i={...s,...n!==void 0?{referenceAppearances:n}:{},...t?{sourceInfos:t}:{}},a=ct(e.appearanceInfo);return a?{...i,appearanceInfo:a}:i}function tce(e){let t=ct(Ka(e));return Qde(t)?ece(Jde(t)):null}function xL(e,t){let n=q(e),r=q(t);if(n===L||r===L)return L;if(n===me||r===me)return me;if(n===M||r===M)return M;if(n===Ie||r===Ie)return Ie;if(n===ue||r===ue)return ue}function nce(e,t){let n=q(e),r=q(t);return n===Qr||r===Qr}function rce(e,t){if(!nce(e.type,t))return null;let n=ct(Ka(e.content));if(ih(n)||is(n))return n;let r=ct(n==null?void 0:n.directorDocument);if(is(r))return r;let o=ct(n==null?void 0:n.data);if(is(o))return o;let s=ct(Ka(e.data));if(is(s))return s;let i=ct(s==null?void 0:s.directorDocument);return is(i)?i:null}function oce(e,t){return C(e)?Object.keys(e).length===0||Wde[t].some(r=>r in e):!1}function sce(e,t){if(!C(e))return e;if(t===Ie)return Zn(e).data;if(t!==L&&t!==M)return e;let n={...e},r=!1;(e.localUploadCache===""||e.localUploadCache===null)&&(delete n.localUploadCache,r=!0);let o=C(e.localUploadTask)?e.localUploadTask:void 0;if((t===L||t===M&&(e.uploadPath==="optimized"||(o==null?void 0:o.uploadPath)==="optimized"))&&e.localUploadTask!==void 0){let i=t===L?"image":"video";(e.localUploadTask===""||e.localUploadTask===null||!Nt(e.localUploadTask,i)||e.localUploadTask.status==="capturing"&&!e.localUploadTask.cacheId)&&(delete n.localUploadTask,r=!0)}return r?n:e}function cy(e,t){if(!oce(e,t))return null;let n=sce(e,t);return t===L&&Yi(n)?{...n}:t===me&&ym(n)?{...n}:t===M&&vm(n)?{...n}:t===Ie&&bm(n)?{...n}:t===ue&&gm(n)?{...n}:null}function ice(e,t){let n=xL(e.type,t);if(!n)return null;let r=cy(Ka(e.content),n),o=cy(Ka(e.data),n);return r||o||"content"in e||"data"in e?r??o:cy(e,n)}function ace(e){let t=C(e.extra)?{...e.extra}:{},n=e.create_type??e.createType??e.CreateType;return n!==void 0&&t.create_type===void 0&&(t.create_type=n),t}function dce(e){let t=ct(e.history??e.History);return t?{...t}:void 0}function cce(e,t){let n=ct(e);if(!n)return null;let r=n,o=!!xL(r.type,t.nodeType),s=rce(r,t.nodeType)??(o?ice(r,t.nodeType):tce(r.content));if(!s)return null;let i=q(r.protocolVersion),a=q(r.dataVersion),d=dce(r);return{pippitAssetId:q(r.pippitAssetId)||t.nodeAssetId,type:q(r.type)||"unknown",...i?{protocolVersion:i}:{},...a?{dataVersion:a}:{},content:s,...d?{history:d}:{},extra:ace(r)}}function ap(e,t){return cce(e,t)}function uce(e){let t=C(e)?e:void 0;return q(t==null?void 0:t.type)}function wL(e){let t=q(e);return t===be||t===Ft}function pce(e){let t=x(e),n=new Map;return Object.values(t.nodes).forEach(r=>{let o=uce(r);if(wL(o))return;let s=xs(r);s&&s!==e.rootCanvasId&&n.set(s,{assetId:s,nodeType:o})}),[...n.values()].sort((r,o)=>r.assetId.localeCompare(o.assetId))}function TL(e){return e.includes("::")}function lce(e,t){let n=e.assets[t];return C(n)&&C(n.content)}function fce(e){let t=q(e);return t===z||t===O_}function mce(e,t){var r,o;if(!fce(t.type))return!1;let n=e.assets[xs(t)??""];return((o=(r=$t(n))==null?void 0:r.basicInfo)==null?void 0:o.unpromptable)===!0}function uy(e){let t=x(e),n=new Set(Object.values(t.nodes).filter(i=>mce(e,i)).map(i=>i.id));if(!n.size)return e;let r=Object.fromEntries(Object.entries(t.nodes).filter(([i])=>!n.has(i)).map(([i,a])=>{let{children:d}=a;return!wL(a.type)||!Array.isArray(d)?[i,a]:[i,{...a,children:d.filter(c=>!n.has(c))}]})),o=Object.fromEntries(Object.entries(t.edges).filter(([,i])=>!n.has(i.source)&&!n.has(i.target))),s=e.assets[e.rootCanvasId];return{...e,assets:{...e.assets,[e.rootCanvasId]:{...s,content:{...t,nodes:r,edges:o}}}}}function dp(e){if(e==null)return null;if(typeof e=="string"){let t=e.trim();if(!t)return e;try{return dp(JSON.parse(t))}catch{return e}}return Array.isArray(e)?e.map(dp):C(e)?Object.fromEntries(Object.entries(e).map(([t,n])=>[t,dp(n)])):e}function hce(e,t){let n=new Map(e.assets.map(i=>[i.pippitAssetId,i])),r={},o=[],s=[];return e.assetIds.forEach(i=>{let a=n.get(i);if((a==null?void 0:a.value)==null)return;let d=ap(a.value,{nodeAssetId:i,nodeType:t.get(i)});if(!d){s.push(i);return}r[i]={...d,assetExtra:dp(a.extra)},o.push(i)}),{assets:r,loadedAssetIds:o,unparsedAssetIds:s}}function NL(e,t,n){if(n)try{n({document:uy(e),readyNodeAssetIds:[...t].sort()})}catch(r){Xe.warn("[xyq-canvas] Node asset ready observer failed during restore",r)}}async function OL(e,t,n){let r=pce(e),o=r.map(y=>y.assetId),s=new Map(r.map(y=>[y.assetId,y.nodeType])),i=n.prefetchCoverAssets?AL({canvasAssetId:t,emit:n.emit,prefetchCoverAssets:n.prefetchCoverAssets,signal:n.signal}):void 0;i==null||i.enqueue(ay(e));let a=o.filter(y=>!lce(e,y)),d=o.filter(y=>!a.includes(y)),c=a.filter(y=>!TL(y)),u=a.filter(TL);n.emit({type:"node-assets:collect",level:"info",canvasAssetId:t,payload:{nodeAssetIds:o,missingNodeAssetIds:a,existingNodeAssetIds:d,skippedSyntheticNodeAssetIds:u}}),u.length&&Xe.error("[xyq-canvas] Skip synthetic node asset ids during canvas restore",{canvasAssetId:t,skippedSyntheticNodeAssetIds:u});let p=new Set(d);if(d.length&&NL(e,p,n.onNodeAssetsReady),!a.length)return{document:uy(e),canvasAssetId:t,nodeAssetIds:o,loadedNodeAssetIds:[],missingNodeAssetIds:[]};let l=[],f=[],h=e;c.length&&await CL(c,t,{...n,getPriorityNodeAssetIds:n.resolvePriorityNodeAssetIds?()=>{var y;return((y=n.resolvePriorityNodeAssetIds)==null?void 0:y.call(n,h))??[]}:void 0},y=>{let v=hce(y,s);f.push(...v.unparsedAssetIds),v.loadedAssetIds.length&&(l.push(...v.loadedAssetIds),v.loadedAssetIds.forEach(S=>p.add(S)),h={...h,assets:{...h.assets,...v.assets}},i==null||i.enqueue(ay(h,new Set(v.loadedAssetIds))),NL(h,p,n.onNodeAssetsReady))}),l.sort(),f.sort();let m=uy(h),g=a.filter(y=>!l.includes(y));return n.emit({type:"node-assets:merge",level:g.length?"warn":"info",canvasAssetId:t,payload:{loadedNodeAssetIds:l,missingNodeAssetIds:g,unparsedNodeAssetIds:f,document:Ya(m)}}),{document:m,canvasAssetId:t,nodeAssetIds:o,loadedNodeAssetIds:l,missingNodeAssetIds:g}}function ML(e){return e===be||e===Ft}function DL(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function LL(e){if(!e.startsWith("group"))return e;let t=e.slice(5);if(!t)return e;let n=t.replace(/^[-_$]+/,"");if(!n)return e;let r=n.replace(/[-_]/g,"$").replace(/([a-z0-9])([A-Z])/g,"$1$$$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1$$$2").replace(/\$+/g,"$").replace(/^\$|\$$/g,"").toLowerCase();return r?`group$${r}`:e}function gce(e,t){let n=e,r=2;for(;t.has(n);)n=`${e}$${r}`,r+=1;return n}function yce(e){let t=new Set(Object.keys(e)),n=new Map;return Object.values(e).forEach(r=>{if(!ML(r.type))return;let o=LL(r.id);if(o===r.id)return;t.delete(r.id);let s=gce(o,t);t.add(s),n.set(r.id,s)}),n}function kL(e,t,n){let r=t.get(e);if(r)return r;let o=LL(e);return o!==e&&n.has(o)?o:e}function BL(e,t,n,r){t.has(n)||(e[n]={...e[n]},t.add(n)),r(e[n])}function GL(e){let t=yce(e),n=new Set(Object.keys(e).map(s=>t.get(s)??s)),r={},o=t.size>0;return Object.entries(e).forEach(([s,i])=>{let a=t.get(s)??s,d=i;if(i.id!==a&&(d={...d,id:a},o=!0),typeof d.parentId=="string"){let u=kL(d.parentId,t,n);u!==d.parentId&&(d={...d,parentId:u},o=!0)}let c=d.children;if(Array.isArray(c)){let u=c.map(p=>typeof p=="string"?kL(p,t,n):p);u.some((p,l)=>p!==c[l])&&(d={...d,children:u},o=!0)}a!==s&&(o=!0),r[a]=d}),{nodes:o?r:e,changed:o,nodeIdAliases:t}}function UL(e,t,n,r){let o={...e};return t.forEach((s,i)=>{if(i===n||!DL(o,i))return;let a=o[i];DL(o,s)||(o[s]=C(a)?{...a,pippitAssetId:s}:a),delete o[i]}),o[n]=r,o}function py(e){let t={...e},n=new Set,r=new Map,o=!1,s=(i,a)=>{BL(t,n,i,a),o=!0};return Object.values(e).forEach(i=>{if(!ML(i.type)){"children"in i&&s(i.id,u=>{delete u.children});return}let a=i.children;if(a==null)return;if(!Array.isArray(a)){s(i.id,u=>{u.children=[]});return}let d=new Set,c=a.filter(u=>{if(typeof u!="string"||d.has(u))return!1;d.add(u);let p=e[u];return!p||p.parentId!==i.id||r.has(u)?!1:(r.set(u,i.id),!0)});(c.length!==a.length||c.some((u,p)=>u!==a[p]))&&s(i.id,u=>{u.children=c})}),Object.values(t).forEach(i=>{if(!i.parentId)return;let a=t[i.parentId];if(a&&"children"in a&&a.children===null)return;let d=Array.isArray(a==null?void 0:a.children)?a.children:[];(!a||!d.includes(i.id))&&s(i.id,c=>{delete c.parentId})}),{nodes:o?t:e,changed:o}}function zL(e){let t=new Set;if(Object.values(e).forEach(o=>{let s=[],i=new Map,a=o;for(;a!=null&&a.parentId;){let d=i.get(a.id);if(d!==void 0){s.slice(d).forEach(c=>t.add(c));break}i.set(a.id,s.length),s.push(a.id),a=e[a.parentId]}}),!t.size)return{nodes:e,changed:!1};let n={...e},r=new Set;return t.forEach(o=>{BL(n,r,o,s=>{delete s.parentId})}),{nodes:n,changed:!0}}function mr(e){return typeof e=="string"?e.trim()||void 0:typeof e=="number"&&Number.isFinite(e)?String(e):void 0}function Ts(e,t){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e!="string"||!e.trim())return t;let n=Number(e);return Number.isFinite(n)?n:t}function qL(e,t){let n=Ts(e,t);return n>0?n:t}function FL(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function jL(e){if(typeof e!="string")return;let t=e.trim();if(!(!t||t==="null"||t==="undefined"))return t}function Ace(e){return{...e,snap:{...e.snap,targets:[...e.snap.targets]},grid:{...e.grid},...e.autoLayout?{autoLayout:{...e.autoLayout}}:{}}}function VL(e,t){if(!C(e))return{settings:Ace(t),changed:!0};let n=C(e.snap)?e.snap:void 0,r=C(e.grid)?e.grid:void 0,o=C(e.autoLayout)?e.autoLayout:void 0,s=o==null?void 0:o.strategy,i=Object.prototype.hasOwnProperty.call(e,"autoLayout"),a=typeof s=="string"?s.trim():void 0,d=!!a,c=Array.isArray(n==null?void 0:n.targets)?n.targets.filter(p=>typeof p=="string"):void 0,u={...e,snap:{enabled:typeof(n==null?void 0:n.enabled)=="boolean"?n.enabled:t.snap.enabled,threshold:qL(n==null?void 0:n.threshold,t.snap.threshold),targets:c&&c.length>0?c:[...t.snap.targets]},grid:{size:Ts(r==null?void 0:r.size,t.grid.size),visible:typeof(r==null?void 0:r.visible)=="boolean"?r.visible:t.grid.visible}};return d?u.autoLayout={...o,strategy:a}:delete u.autoLayout,{settings:u,changed:!n||!r||typeof n.enabled!="boolean"||typeof r.visible!="boolean"||!Number.isFinite(n.threshold)||qL(n.threshold,t.snap.threshold)!==n.threshold||!Number.isFinite(r.size)||!Array.isArray(n.targets)||((c==null?void 0:c.length)??0)!==n.targets.length||i&&(!d||a!==s)}}function HL(e){if(!C(e))return{nodes:{},changed:e!==void 0};let t={},n=!1;return Object.entries(e).forEach(([r,o])=>{if(!C(o)){n=!0;return}let s={...o},i=mr(s.id)||r;s.id!==i&&(s.id=i,n=!0),i!==r&&(n=!0);let a=mr(s.parentId)||mr(s.parent_id);a&&s.parentId!==a?(s.parentId=a,n=!0):!a&&s.parentId!=null&&typeof s.parentId!="string"&&(delete s.parentId,n=!0);let d=Ts(s.x,0),c=Ts(s.y,0),u=Ts(s.w,0),p=Ts(s.h,0);(s.x!==d||s.y!==c||s.w!==u||s.h!==p)&&(Object.assign(s,{x:d,y:c,w:u,h:p}),n=!0),t[i]=s}),{nodes:t,changed:n}}function YL(e,t,n=new Map){if(!C(e))return{edges:{},changed:e!==void 0};let r={},o=!1;return Object.entries(e).forEach(([s,i])=>{if(!C(i)){o=!0;return}let a=mr(i.id)||s,d=mr(i.source),c=mr(i.target),u=d?n.get(d)??d:void 0,p=c?n.get(c)??c:void 0;if(!u||!p||!t[u]||!t[p]){o=!0;return}r[a]&&(o=!0);let l=jL(i.sourceHandle),f=jL(i.targetHandle),h={...i,id:a,source:u,target:p},m=a!==s||i.id!==a||i.source!==u||i.target!==p||d!==u||c!==p;l?(h.sourceHandle=l,m||=i.sourceHandle!==l):FL(i,"sourceHandle")&&(delete h.sourceHandle,m=!0),f?(h.targetHandle=f,m||=i.targetHandle!==f):FL(i,"targetHandle")&&(delete h.targetHandle,m=!0),r[a]=m?h:i,o||=m}),{edges:r,changed:o}}function Xa(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function KL(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function vce(e,t){return JSON.stringify(e)===JSON.stringify(t)}function po(e,t,n,r,o,s){let i=Xa(n,r);i&&vce(n[r],s)||e.push({assetId:t,op:i?"replace":"add",path:o,value:s})}function XL(e,t,n,r,o){Object.keys(n).forEach(s=>{Xa(r,s)||e.push({assetId:t,op:"remove",path:`${o}/${KL(s)}`})}),Object.entries(r).forEach(([s,i])=>{po(e,t,n,s,`${o}/${KL(s)}`,i)})}function Sce(e,t,n,r){if(!C(t.content))return[{assetId:e,op:Xa(t,"content")?"replace":"add",path:"/content",value:r}];let o=[];return po(o,e,n,"metadata","/content/metadata",r.metadata),C(n.settings)?(po(o,e,n.settings,"snap","/content/settings/snap",r.settings.snap),po(o,e,n.settings,"grid","/content/settings/grid",r.settings.grid)):po(o,e,n,"settings","/content/settings",r.settings),C(n.nodes)?XL(o,e,n.nodes,r.nodes,"/content/nodes"):po(o,e,n,"nodes","/content/nodes",r.nodes),C(n.edges)?XL(o,e,n.edges,r.edges,"/content/edges"):po(o,e,n,"edges","/content/edges",r.edges),o}function bce(e){let t={...e},n=!1;return Object.entries(e).forEach(([r,o])=>{if(o.type!==Ie||!C(o.data))return;let s=Zn(o.data);s.changed&&(t[r]={...o,data:s.data},n=!0)}),{nodes:n?t:e,changed:n}}function Ice(e,t,n){let r={...e},o=[],s=!1;return Object.entries(e).forEach(([i,a])=>{var u;if(i===n||!C(a)||!C(a.content)||(typeof a.type=="string"?a.type:(u=t[i])==null?void 0:u.type)!==Ie)return;let c=Zn(a.content);c.changed&&(r[i]={...a,content:c.data},o.push({assetId:i,op:"replace",path:"/content",value:c.data}),s=!0)}),{assets:s?r:e,changed:s,repairPatches:o}}function ly(e){let t=e.assets[e.rootCanvasId];if(!t||!C(t))return{document:e,repairPatches:[]};let n=bo(e.rootCanvasId).assets[e.rootCanvasId].content,r=C(t.content)?t.content:{},o=HL(r.nodes),s=bce(o.nodes),i=GL(s.nodes),a=py(i.nodes),d=zL(a.nodes),c=d.changed?py(d.nodes):d,u=Ice(e.assets,c.nodes,e.rootCanvasId),p=YL(r.edges,c.nodes,i.nodeIdAliases),l=VL(r.settings,n.settings),f=C(r.metadata)?r.metadata:n.metadata,m=mr(t.pippitAssetId)!==e.rootCanvasId,g=t.type!==lt,y=!C(t.content)||!C(r.metadata)||!C(r.nodes)||!C(r.edges)||o.changed||s.changed||i.changed||a.changed||d.changed||c.changed||p.changed||l.changed;if(!(g||m||y||u.changed))return{document:e,repairPatches:[]};let S={...n,...r,metadata:f,settings:l.settings,nodes:c.nodes,edges:p.edges},b={...t,pippitAssetId:e.rootCanvasId,type:lt,content:S},I=[];return m&&I.push({assetId:e.rootCanvasId,op:Xa(t,"pippitAssetId")?"replace":"add",path:"/pippitAssetId",value:e.rootCanvasId}),g&&I.push({assetId:e.rootCanvasId,op:Xa(t,"type")?"replace":"add",path:"/type",value:lt}),y&&I.push(...Sce(e.rootCanvasId,t,r,S)),I.push(...u.repairPatches),{document:{...e,assets:UL(u.assets,i.nodeIdAliases,e.rootCanvasId,b)},repairPatches:I}}function $L(e){return C(e.nodes)?Object.keys(e.nodes).length:0}function _ce(e,t){let n=$L(e),r=$L(t);if(r<=0)return!1;let o=C(e.edges),s=C(t.edges);return!o&&s&&r>n?!0:n===0&&r>0}function Rce(e){let t=C(e.content)?e.content:null,n=C(e.data)?e.data:null;return t?n&&_ce(t,n)?n:t:n}function Ece(e){let t={...e};return delete t.data,t}function Cce(e,t){let n=q(e.rootCanvasId)||q(e.root_canvas_id)||t,r=C(e.assets)?e.assets:null;return!n||!r||!C(r[n])?null:{rootCanvasId:n,assets:r}}function Pce(e,t){let n=q(e.pippitAssetId)||q(e.pippit_asset_id)||t,r=Rce(e);return!n||e.type!=="canvas"||!r?null:{rootCanvasId:n,assets:{[n]:{...Ece(e),pippitAssetId:n,content:r,extra:C(e.extra)?e.extra:C(e.Extra)?e.Extra:{}}}}}function hy(e,t,n){if(e==null)return null;if(typeof e=="string"){let s=e.trim();if(!s)return null;try{return hy(JSON.parse(s),t,n)}catch{return null}}if(!C(e)||n.has(e))return null;n.add(e);let r=Cce(e,t);if(r){let s=ly(r);return{document:s.document,repairPatches:s.repairPatches}}let o=Pce(e,t);if(o){let s=ly(o);return{document:s.document,repairPatches:s.repairPatches}}for(let s of["document","canvasDocument","canvas_document","snapshot","data","content","value"]){let i=hy(e[s],t,n);if(i)return i}return null}function fy(e,t){return hy(e,t,new Set)}function my(e,t){var n;return e?(e.repairPatches.length>0&&((n=t.onRepairPatches)==null||n.call(t,e.repairPatches)),e.document):null}function cp(e,t={}){let n=fy(e,t.canvasAssetId);if(n)return Promise.resolve(my(n,t));let r=C(e)?e:void 0,o=GE(r,"TextInfo","textInfo"),s=fy(o==null?void 0:o.content,t.canvasAssetId);if(s)return Promise.resolve(my(s,t));let i=fy((r==null?void 0:r.Extra)??(r==null?void 0:r.extra),t.canvasAssetId);return i?Promise.resolve(my(i,t)):Promise.resolve(null)}var xce=new Set([z,he]),Tce=new Set([L,M]);function Nce(e){return typeof e.x=="number"&&Number.isFinite(e.x)&&typeof e.y=="number"&&Number.isFinite(e.y)&&typeof e.w=="number"&&Number.isFinite(e.w)&&e.w>0&&typeof e.h=="number"&&Number.isFinite(e.h)&&e.h>0}function wce(e){return{name:e?`${sp.name}-media`:"media-node-geometry-repair",layout(t){let n=e?sp.layout(t):t;return dL(n,{repairInvalidOnly:!0})}}}function Oce(e){let t=!1,n=!1;if(Object.values(x(e).nodes).forEach(r=>{if(!Nce(r)){if(Tce.has(r.type)){n=!0;return}xce.has(r.type)&&(t=!0)}}),n)return wce(t);if(t)return sp}var Dce=["x","y","w","h","order"];function kce(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Mce(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Lce(e,t){let n=x(e).nodes,r=x(t).nodes,o=[];return Object.values(r).forEach(s=>{let i=n[s.id];i&&Dce.forEach(a=>{let d=s[a];i[a]!==d&&o.push({assetId:t.rootCanvasId,op:Mce(i,a)?"replace":"add",path:`/content/nodes/${kce(s.id)}/${a}`,value:d})})}),o}function Bce(e,t){let n={pippitAssetIds:e,isCamelCase:!0};return t&&(n.signal=t),n}var gy=class{constructor(t){this._options=t;this._eventEmitter=new pa;this.onEvent=this._eventEmitter.event}async loadDocument(t){return(await this.restore(t)).document}async restore(t){var o,s;let n=t.trim();if(!n)throw new Error("missing canvasAssetId");let r="canvas-asset-query";try{this._emit({type:"restore:start",level:"info",canvasAssetId:n});let{selectedAsset:i}=await this._queryCanvasAsset(n),a=[];r="canvas-document-normalize",this._emit({type:"canvas-document-normalize:start",level:"info",canvasAssetId:n,payload:{textAsset:Ps(i)}});let d=await cp(i.value,{canvasAssetId:n,signal:this._options.signal,onRepairPatches:h=>a.push(...h)});if(!d){let h=new Error(O.t("Pippit_xyqcanvas_restore_error_invalidcanvasasset",{},"画布资产内容为空或格式不正确"));throw this._emit({type:"canvas-document-normalize:error",level:"warn",canvasAssetId:n,payload:{error:dn(h),textAsset:Ps(i)}},h),h}this._emit({type:"canvas-document-normalize:success",level:"info",canvasAssetId:n,payload:{document:Ya(d)}}),r="root-document-ready",(s=(o=this._options).onRootDocumentReady)==null||s.call(o,d),r="node-assets-hydrate";let c=await OL(d,n,{signal:this._options.signal,queryTextAssetContent:this._options.queryTextAssetContent,prefetchCoverAssets:this._options.prefetchCoverAssets,emit:h=>this._emit(h),onNodeAssetsReady:this._options.onNodeAssetsReady,resolvePriorityNodeAssetIds:this._options.resolvePriorityNodeAssetIds});r="canvas-layout";let u=this._options.layoutStrategy===void 0?Oce(c.document):this._options.layoutStrategy,p=u?u.layout(c.document):c.document,l=u?Lce(c.document,p):[],f=p===c.document?c:{...c,document:p};return u&&(f.layoutApplied=!0,f.layoutPatches=l,f.layoutStrategy=u.name),a.length>0&&(f.repairApplied=!0,f.repairPatches=a),r="restore-finalize",this._emit({type:"restore:success",level:"info",canvasAssetId:n,payload:{document:Ya(f.document),nodeAssetIds:f.nodeAssetIds,loadedNodeAssetIds:f.loadedNodeAssetIds,missingNodeAssetIds:f.missingNodeAssetIds,repairApplied:a.length>0,repairPatchCount:a.length,layoutApplied:!!u,layoutPatchCount:l.length,layoutStrategy:u?u.name:void 0}}),f}catch(i){let a=ey(i,this._options.signal),d=a?"aborted":ty(i);throw this._emit({type:a?"restore:cancel":"restore:error",level:a?"info":"error",canvasAssetId:n,payload:{error:dn(i),failure_stage:r,...d?{reason:d}:{}}},i),i}}dispose(){this._eventEmitter.dispose()}async _queryCanvasAsset(t){this._emit({type:"canvas-asset-query:start",level:"info",canvasAssetId:t,payload:{assetIds:[t]}});try{let n=await this._options.queryTextAssetContent(Bce([t],this._options.signal)),r=n.find(o=>o.pippitAssetId===t)??n[0];if((r==null?void 0:r.value)===null||(r==null?void 0:r.value)===void 0)throw new Ha(O.t("Pippit_xyqcanvas_restore_error_canvasassetnotfound",{},"画布资产不存在"));return this._emit({type:"canvas-asset-query:success",level:"info",canvasAssetId:t,payload:{assetCount:n.length,resolvedAssetIds:n.filter(o=>o.value!==null&&o.value!==void 0).map(o=>o.pippitAssetId),assets:n.map(Ps)}}),{selectedAsset:r,assets:n}}catch(n){let r=ey(n,this._options.signal),o=r?"aborted":ty(n);throw this._emit({type:r?"canvas-asset-query:cancel":"canvas-asset-query:error",level:r?"info":"warn",canvasAssetId:t,payload:{error:dn(n),...o?{reason:o}:{}}},n),n}}_emit(t,n){this._eventEmitter.fire(t),mL(t,this._options,n)}};async function WL(e,t){let n=new gy(t),r=t.onEvent?n.onEvent(t.onEvent):void 0;try{return await n.restore(e)}finally{r==null||r.dispose(),n.dispose()}}function Gce(){this.__data__=[],this.size=0}var QL=Gce;function Uce(e,t){return e===t||e!==e&&t!==t}var up=Uce;function zce(e,t){for(var n=e.length;n--;)if(up(e[n][0],t))return n;return-1}var hr=zce;var qce=Array.prototype,Fce=qce.splice;function jce(e){var t=this.__data__,n=hr(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():Fce.call(t,n,1),--this.size,!0}var JL=jce;function Vce(e){var t=this.__data__,n=hr(t,e);return n<0?void 0:t[n][1]}var ZL=Vce;function Hce(e){return hr(this.__data__,e)>-1}var eB=Hce;function Yce(e,t){var n=this.__data__,r=hr(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var tB=Yce;function Ns(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Ns.prototype.clear=QL;Ns.prototype.delete=JL;Ns.prototype.get=ZL;Ns.prototype.has=eB;Ns.prototype.set=tB;var gr=Ns;function Kce(){this.__data__=new gr,this.size=0}var nB=Kce;function Xce(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var rB=Xce;function $ce(e){return this.__data__.get(e)}var oB=$ce;function Wce(e){return this.__data__.has(e)}var sB=Wce;var Qce=typeof global=="object"&&global&&global.Object===Object&&global,pp=Qce;var Jce=typeof self=="object"&&self&&self.Object===Object&&self,Zce=pp||Jce||Function("return this")(),_e=Zce;var eue=_e.Symbol,Mn=eue;var iB=Object.prototype,tue=iB.hasOwnProperty,nue=iB.toString,$a=Mn?Mn.toStringTag:void 0;function rue(e){var t=tue.call(e,$a),n=e[$a];try{e[$a]=void 0;var r=!0}catch{}var o=nue.call(e);return r&&(t?e[$a]=n:delete e[$a]),o}var aB=rue;var oue=Object.prototype,sue=oue.toString;function iue(e){return sue.call(e)}var dB=iue;var aue="[object Null]",due="[object Undefined]",cB=Mn?Mn.toStringTag:void 0;function cue(e){return e==null?e===void 0?due:aue:cB&&cB in Object(e)?aB(e):dB(e)}var Ln=cue;function uue(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var cn=uue;var pue="[object AsyncFunction]",lue="[object Function]",fue="[object GeneratorFunction]",mue="[object Proxy]";function hue(e){if(!cn(e))return!1;var t=Ln(e);return t==lue||t==fue||t==pue||t==mue}var lp=hue;var gue=_e["__core-js_shared__"],fp=gue;var uB=function(){var e=/[^.]+$/.exec(fp&&fp.keys&&fp.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function yue(e){return!!uB&&uB in e}var pB=yue;var Aue=Function.prototype,vue=Aue.toString;function Sue(e){if(e!=null){try{return vue.call(e)}catch{}try{return e+""}catch{}}return""}var Bn=Sue;var bue=/[\\^$.*+?()[\]{}|]/g,Iue=/^\[object .+?Constructor\]$/,_ue=Function.prototype,Rue=Object.prototype,Eue=_ue.toString,Cue=Rue.hasOwnProperty,Pue=RegExp("^"+Eue.call(Cue).replace(bue,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function xue(e){if(!cn(e)||pB(e))return!1;var t=lp(e)?Pue:Iue;return t.test(Bn(e))}var lB=xue;function Tue(e,t){return e==null?void 0:e[t]}var fB=Tue;function Nue(e,t){var n=fB(e,t);return lB(n)?n:void 0}var $e=Nue;var wue=$e(_e,"Map"),yr=wue;var Oue=$e(Object,"create"),Gn=Oue;function Due(){this.__data__=Gn?Gn(null):{},this.size=0}var mB=Due;function kue(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var hB=kue;var Mue="__lodash_hash_undefined__",Lue=Object.prototype,Bue=Lue.hasOwnProperty;function Gue(e){var t=this.__data__;if(Gn){var n=t[e];return n===Mue?void 0:n}return Bue.call(t,e)?t[e]:void 0}var gB=Gue;var Uue=Object.prototype,zue=Uue.hasOwnProperty;function que(e){var t=this.__data__;return Gn?t[e]!==void 0:zue.call(t,e)}var yB=que;var Fue="__lodash_hash_undefined__";function jue(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Gn&&t===void 0?Fue:t,this}var AB=jue;function ws(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}ws.prototype.clear=mB;ws.prototype.delete=hB;ws.prototype.get=gB;ws.prototype.has=yB;ws.prototype.set=AB;var yy=ws;function Vue(){this.size=0,this.__data__={hash:new yy,map:new(yr||gr),string:new yy}}var vB=Vue;function Hue(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}var SB=Hue;function Yue(e,t){var n=e.__data__;return SB(t)?n[typeof t=="string"?"string":"hash"]:n.map}var Ar=Yue;function Kue(e){var t=Ar(this,e).delete(e);return this.size-=t?1:0,t}var bB=Kue;function Xue(e){return Ar(this,e).get(e)}var IB=Xue;function $ue(e){return Ar(this,e).has(e)}var _B=$ue;function Wue(e,t){var n=Ar(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var RB=Wue;function Os(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Os.prototype.clear=vB;Os.prototype.delete=bB;Os.prototype.get=IB;Os.prototype.has=_B;Os.prototype.set=RB;var EB=Os;var Que=200;function Jue(e,t){var n=this.__data__;if(n instanceof gr){var r=n.__data__;if(!yr||r.length<Que-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new EB(r)}return n.set(e,t),this.size=n.size,this}var CB=Jue;function Ds(e){var t=this.__data__=new gr(e);this.size=t.size}Ds.prototype.clear=nB;Ds.prototype.delete=rB;Ds.prototype.get=oB;Ds.prototype.has=sB;Ds.prototype.set=CB;var PB=Ds;var Zue=_e.Uint8Array,Ay=Zue;function epe(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}var mp=epe;var tpe=Array.isArray,ks=tpe;function npe(e,t,n){var r=t(e);return ks(e)?r:mp(r,n(e))}var hp=npe;function rpe(e,t){for(var n=-1,r=e==null?0:e.length,o=0,s=[];++n<r;){var i=e[n];t(i,n,e)&&(s[o++]=i)}return s}var xB=rpe;function ope(){return[]}var gp=ope;var spe=Object.prototype,ipe=spe.propertyIsEnumerable,TB=Object.getOwnPropertySymbols,ape=TB?function(e){return e==null?[]:(e=Object(e),xB(TB(e),function(t){return ipe.call(e,t)}))}:gp,Ms=ape;function dpe(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var NB=dpe;function cpe(e){return e!=null&&typeof e=="object"}var un=cpe;var upe="[object Arguments]";function ppe(e){return un(e)&&Ln(e)==upe}var vy=ppe;var wB=Object.prototype,lpe=wB.hasOwnProperty,fpe=wB.propertyIsEnumerable,mpe=vy(function(){return arguments}())?vy:function(e){return un(e)&&lpe.call(e,"callee")&&!fpe.call(e,"callee")},OB=mpe;function hpe(){return!1}var DB=hpe;var LB=typeof exports=="object"&&exports&&!exports.nodeType&&exports,kB=LB&&typeof module=="object"&&module&&!module.nodeType&&module,gpe=kB&&kB.exports===LB,MB=gpe?_e.Buffer:void 0,ype=MB?MB.isBuffer:void 0,Ape=ype||DB,yp=Ape;var vpe=9007199254740991,Spe=/^(?:0|[1-9]\d*)$/;function bpe(e,t){var n=typeof e;return t=t??vpe,!!t&&(n=="number"||n!="symbol"&&Spe.test(e))&&e>-1&&e%1==0&&e<t}var BB=bpe;var Ipe=9007199254740991;function _pe(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Ipe}var Ap=_pe;var Rpe="[object Arguments]",Epe="[object Array]",Cpe="[object Boolean]",Ppe="[object Date]",xpe="[object Error]",Tpe="[object Function]",Npe="[object Map]",wpe="[object Number]",Ope="[object Object]",Dpe="[object RegExp]",kpe="[object Set]",Mpe="[object String]",Lpe="[object WeakMap]",Bpe="[object ArrayBuffer]",Gpe="[object DataView]",Upe="[object Float32Array]",zpe="[object Float64Array]",qpe="[object Int8Array]",Fpe="[object Int16Array]",jpe="[object Int32Array]",Vpe="[object Uint8Array]",Hpe="[object Uint8ClampedArray]",Ype="[object Uint16Array]",Kpe="[object Uint32Array]",fe={};fe[Upe]=fe[zpe]=fe[qpe]=fe[Fpe]=fe[jpe]=fe[Vpe]=fe[Hpe]=fe[Ype]=fe[Kpe]=!0;fe[Rpe]=fe[Epe]=fe[Bpe]=fe[Cpe]=fe[Gpe]=fe[Ppe]=fe[xpe]=fe[Tpe]=fe[Npe]=fe[wpe]=fe[Ope]=fe[Dpe]=fe[kpe]=fe[Mpe]=fe[Lpe]=!1;function Xpe(e){return un(e)&&Ap(e.length)&&!!fe[Ln(e)]}var GB=Xpe;function $pe(e){return function(t){return e(t)}}var Ls=$pe;var UB=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Wa=UB&&typeof module=="object"&&module&&!module.nodeType&&module,Wpe=Wa&&Wa.exports===UB,Sy=Wpe&&pp.process,Qpe=function(){try{var e=Wa&&Wa.require&&Wa.require("util").types;return e||Sy&&Sy.binding&&Sy.binding("util")}catch{}}(),Un=Qpe;var zB=Un&&Un.isTypedArray,Jpe=zB?Ls(zB):GB,qB=Jpe;var Zpe=Object.prototype,ele=Zpe.hasOwnProperty;function tle(e,t){var n=ks(e),r=!n&&OB(e),o=!n&&!r&&yp(e),s=!n&&!r&&!o&&qB(e),i=n||r||o||s,a=i?NB(e.length,String):[],d=a.length;for(var c in e)(t||ele.call(e,c))&&!(i&&(c=="length"||o&&(c=="offset"||c=="parent")||s&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||BB(c,d)))&&a.push(c);return a}var vp=tle;var nle=Object.prototype;function rle(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||nle;return e===n}var Bs=rle;function ole(e,t){return function(n){return e(t(n))}}var Sp=ole;var sle=Sp(Object.keys,Object),FB=sle;var ile=Object.prototype,ale=ile.hasOwnProperty;function dle(e){if(!Bs(e))return FB(e);var t=[];for(var n in Object(e))ale.call(e,n)&&n!="constructor"&&t.push(n);return t}var jB=dle;function cle(e){return e!=null&&Ap(e.length)&&!lp(e)}var bp=cle;function ule(e){return bp(e)?vp(e):jB(e)}var Gs=ule;function ple(e){return hp(e,Gs,Ms)}var VB=ple;var lle=$e(_e,"DataView"),Ip=lle;var fle=$e(_e,"Promise"),_p=fle;var mle=$e(_e,"Set"),Rp=mle;var hle=$e(_e,"WeakMap"),Ep=hle;var HB="[object Map]",gle="[object Object]",YB="[object Promise]",KB="[object Set]",XB="[object WeakMap]",$B="[object DataView]",yle=Bn(Ip),Ale=Bn(yr),vle=Bn(_p),Sle=Bn(Rp),ble=Bn(Ep),lo=Ln;(Ip&&lo(new Ip(new ArrayBuffer(1)))!=$B||yr&&lo(new yr)!=HB||_p&&lo(_p.resolve())!=YB||Rp&&lo(new Rp)!=KB||Ep&&lo(new Ep)!=XB)&&(lo=function(e){var t=Ln(e),n=t==gle?e.constructor:void 0,r=n?Bn(n):"";if(r)switch(r){case yle:return $B;case Ale:return HB;case vle:return YB;case Sle:return KB;case ble:return XB}return t});var Us=lo;function Ile(e,t){for(var n=-1,r=e==null?0:e.length;++n<r&&t(e[n],n,e)!==!1;);return e}var WB=Ile;var _le=function(){try{var e=$e(Object,"defineProperty");return e({},"",{}),e}catch{}}(),by=_le;function Rle(e,t,n){t=="__proto__"&&by?by(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var Cp=Rle;var Ele=Object.prototype,Cle=Ele.hasOwnProperty;function Ple(e,t,n){var r=e[t];(!(Cle.call(e,t)&&up(r,n))||n===void 0&&!(t in e))&&Cp(e,t,n)}var Pp=Ple;function xle(e,t,n,r){var o=!n;n||(n={});for(var s=-1,i=t.length;++s<i;){var a=t[s],d=r?r(n[a],e[a],a,n,e):void 0;d===void 0&&(d=e[a]),o?Cp(n,a,d):Pp(n,a,d)}return n}var vr=xle;function Tle(e,t){return e&&vr(t,Gs(t),e)}var QB=Tle;function Nle(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var JB=Nle;var wle=Object.prototype,Ole=wle.hasOwnProperty;function Dle(e){if(!cn(e))return JB(e);var t=Bs(e),n=[];for(var r in e)r=="constructor"&&(t||!Ole.call(e,r))||n.push(r);return n}var ZB=Dle;function kle(e){return bp(e)?vp(e,!0):ZB(e)}var zs=kle;function Mle(e,t){return e&&vr(t,zs(t),e)}var eG=Mle;var oG=typeof exports=="object"&&exports&&!exports.nodeType&&exports,tG=oG&&typeof module=="object"&&module&&!module.nodeType&&module,Lle=tG&&tG.exports===oG,nG=Lle?_e.Buffer:void 0,rG=nG?nG.allocUnsafe:void 0;function Ble(e,t){if(t)return e.slice();var n=e.length,r=rG?rG(n):new e.constructor(n);return e.copy(r),r}var sG=Ble;function Gle(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}var iG=Gle;function Ule(e,t){return vr(e,Ms(e),t)}var aG=Ule;var zle=Sp(Object.getPrototypeOf,Object),xp=zle;var qle=Object.getOwnPropertySymbols,Fle=qle?function(e){for(var t=[];e;)mp(t,Ms(e)),e=xp(e);return t}:gp,Tp=Fle;function jle(e,t){return vr(e,Tp(e),t)}var dG=jle;function Vle(e){return hp(e,zs,Tp)}var cG=Vle;var Hle=Object.prototype,Yle=Hle.hasOwnProperty;function Kle(e){var t=e.length,n=new e.constructor(t);return t&&typeof e[0]=="string"&&Yle.call(e,"index")&&(n.index=e.index,n.input=e.input),n}var uG=Kle;function Xle(e){var t=new e.constructor(e.byteLength);return new Ay(t).set(new Ay(e)),t}var qs=Xle;function $le(e,t){var n=t?qs(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}var pG=$le;var Wle=/\w*$/;function Qle(e){var t=new e.constructor(e.source,Wle.exec(e));return t.lastIndex=e.lastIndex,t}var lG=Qle;var fG=Mn?Mn.prototype:void 0,mG=fG?fG.valueOf:void 0;function Jle(e){return mG?Object(mG.call(e)):{}}var hG=Jle;function Zle(e,t){var n=t?qs(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}var gG=Zle;var efe="[object Boolean]",tfe="[object Date]",nfe="[object Map]",rfe="[object Number]",ofe="[object RegExp]",sfe="[object Set]",ife="[object String]",afe="[object Symbol]",dfe="[object ArrayBuffer]",cfe="[object DataView]",ufe="[object Float32Array]",pfe="[object Float64Array]",lfe="[object Int8Array]",ffe="[object Int16Array]",mfe="[object Int32Array]",hfe="[object Uint8Array]",gfe="[object Uint8ClampedArray]",yfe="[object Uint16Array]",Afe="[object Uint32Array]";function vfe(e,t,n){var r=e.constructor;switch(t){case dfe:return qs(e);case efe:case tfe:return new r(+e);case cfe:return pG(e,n);case ufe:case pfe:case lfe:case ffe:case mfe:case hfe:case gfe:case yfe:case Afe:return gG(e,n);case nfe:return new r;case rfe:case ife:return new r(e);case ofe:return lG(e);case sfe:return new r;case afe:return hG(e)}}var yG=vfe;var AG=Object.create,Sfe=function(){function e(){}return function(t){if(!cn(t))return{};if(AG)return AG(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}(),vG=Sfe;function bfe(e){return typeof e.constructor=="function"&&!Bs(e)?vG(xp(e)):{}}var SG=bfe;var Ife="[object Map]";function _fe(e){return un(e)&&Us(e)==Ife}var bG=_fe;var IG=Un&&Un.isMap,Rfe=IG?Ls(IG):bG,_G=Rfe;var Efe="[object Set]";function Cfe(e){return un(e)&&Us(e)==Efe}var RG=Cfe;var EG=Un&&Un.isSet,Pfe=EG?Ls(EG):RG,CG=Pfe;var xfe=1,Tfe=2,Nfe=4,PG="[object Arguments]",wfe="[object Array]",Ofe="[object Boolean]",Dfe="[object Date]",kfe="[object Error]",xG="[object Function]",Mfe="[object GeneratorFunction]",Lfe="[object Map]",Bfe="[object Number]",TG="[object Object]",Gfe="[object RegExp]",Ufe="[object Set]",zfe="[object String]",qfe="[object Symbol]",Ffe="[object WeakMap]",jfe="[object ArrayBuffer]",Vfe="[object DataView]",Hfe="[object Float32Array]",Yfe="[object Float64Array]",Kfe="[object Int8Array]",Xfe="[object Int16Array]",$fe="[object Int32Array]",Wfe="[object Uint8Array]",Qfe="[object Uint8ClampedArray]",Jfe="[object Uint16Array]",Zfe="[object Uint32Array]",de={};de[PG]=de[wfe]=de[jfe]=de[Vfe]=de[Ofe]=de[Dfe]=de[Hfe]=de[Yfe]=de[Kfe]=de[Xfe]=de[$fe]=de[Lfe]=de[Bfe]=de[TG]=de[Gfe]=de[Ufe]=de[zfe]=de[qfe]=de[Wfe]=de[Qfe]=de[Jfe]=de[Zfe]=!0;de[kfe]=de[xG]=de[Ffe]=!1;function Np(e,t,n,r,o,s){var i,a=t&xfe,d=t&Tfe,c=t&Nfe;if(n&&(i=o?n(e,r,o,s):n(e)),i!==void 0)return i;if(!cn(e))return e;var u=ks(e);if(u){if(i=uG(e),!a)return iG(e,i)}else{var p=Us(e),l=p==xG||p==Mfe;if(yp(e))return sG(e,a);if(p==TG||p==PG||l&&!o){if(i=d||l?{}:SG(e),!a)return d?dG(e,eG(i,e)):aG(e,QB(i,e))}else{if(!de[p])return o?e:{};i=yG(e,p,a)}}s||(s=new PB);var f=s.get(e);if(f)return f;s.set(e,i),CG(e)?e.forEach(function(g){i.add(Np(g,t,n,g,e,s))}):_G(e)&&e.forEach(function(g,y){i.set(y,Np(g,t,n,y,e,s))});var h=c?d?cG:VB:d?zs:Gs,m=u?void 0:h(e);return WB(m||e,function(g,y){m&&(y=g,g=e[y]),Pp(i,y,Np(g,t,n,y,e,s))}),i}var NG=Np;var eme=1,tme=4;function nme(e){return NG(e,eme|tme)}var wG=nme;function OG(e,t,n=!1){if(e&&typeof e=="object")for(let r of Object.keys(e)){let o=t(r),s=e[r];o!==r&&(e[o]=s,delete e[r]),s===null&&n&&(e[o]=void 0),OG(e[o],t,n)}return e}var DG=(e,t,n=!0)=>OG(n?wG(e):e,t??rme,!0);function rme(e){return e.replace(/_([a-z])/g,(t,n)=>n.toUpperCase())}function kt(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function fo(e){return typeof e=="string"&&e.trim()?e:void 0}function ome(e){var r;let t=e.replace(/_([a-zA-Z0-9])/g,(o,s)=>s.toUpperCase()),n=t&&`${(r=t[0])==null?void 0:r.toLowerCase()}${t.slice(1)}`;return Array.from(new Set([e,t,n]))}function MG(e,t){for(let n of ome(t))if(n in e)return e[n]}function sme(e){if(kt(e))return fo(e.id)??fo(e.pippitAssetId)??fo(e.pippit_asset_id)??fo(e.PippitAssetID)}function ime(e,t){return(fo(e.type)??fo(t.type)??fo(t.Type))==="canvas"&&(t.content!==void 0||t.Content!==void 0)}function kG(e,t,n,r){let o=kt(e[n])?e[n]:kt(e[r])?e[r]:null,s=kt(t[r])?t[r]:kt(t[n])?t[n]:null;if(!o||!s)return;let i={};for(let a of Object.keys(s))i[a]=MG(o,a)??s[a];e[n]=i}function Iy(e,t,n,r){let o=kt(e[n])?e[n]:null,s=kt(t[n])?t[n]:null;if(!o||!s)return;let i=new Map;for(let d of Object.values(o)){let c=sme(d);c&&i.set(c,d)}let a={};for(let d of Object.keys(s)){let c=MG(o,d)??i.get(d)??s[d];r(c,s[d]),a[d]=c}e[n]=a}function ame(e,t,n){for(let r of["document","canvasDocument","canvas_document","snapshot","data","content","payload","value"]){let o=e[r],s=t[r];kt(o)&&kt(s)&&n(o,s)}}function Qa(e,t){if(!(!kt(e)||!kt(t))){if(ime(e,t)){let n=t.content??t.Content;n!==void 0&&(e.content=n);return}Iy(e,t,"assets",Qa),Iy(e,t,"nodes",Qa),Iy(e,t,"edges",Qa),kG(e,t,"assetVersions","asset_versions"),kG(e,t,"currentAssetVersions","current_asset_versions"),ame(e,t,Qa)}}function LG(e){let t=DG(e);return Qa(t,e),t}function BG(e){return LG(e)}var GG=(e,t=!0)=>{if(!e)return null;try{let n=JSON.parse(e);return t?BG(n):n}catch{return e}},Ja=e=>({mediaType:"text",pippitAssetId:e}),Ry=e=>e==null?void 0:e.version,dme=e=>Object.fromEntries(e),cme=e=>[...e.repairPatches??[],...e.layoutPatches??[]],_y=(e,t)=>e.op==="add"&&e.path===""?0:t.get(e.assetId),ume=async(e,t,n,r)=>{let o=[...new Set(t.filter(i=>_y(i,n)===void 0).map(i=>i.assetId))];if(!o.length)return;let s=new Set(o);try{(await e.assets.queryAssets(o.map(Ja),{cachePolicy:"refresh",dispatchMode:"immediate",signal:r})).forEach(({asset:a,ref:d})=>{let c=Ry(a),u=d.pippitAssetId;u&&s.has(u)&&c!==void 0&&n.set(u,c)})}catch(i){Xe.error("[xyq-canvas-sdk:restore] failed to refresh restore patch asset versions",i,{assetIds:o})}},pme=async(e,t,n,r)=>{var d;let o=cme(t);if(!o.length)return;await ume(e,o,n,r);let s=o.filter(c=>_y(c,n)===void 0);s.length&&Xe.error("[xyq-canvas-sdk:restore] skipped restore patches without base asset versions",{assetIds:[...new Set(s.map(c=>c.assetId))],canvasAssetId:t.canvasAssetId,patchCount:s.length});let i=o.flatMap(c=>{let u=_y(c,n);return u===void 0?[]:[{baseVersion:u,op:c.op,path:c.path,ref:Ja(c.assetId),...c.op==="remove"?{}:{value:c.value}}]});if(!i.length)return;let a=await e.assets.patchAssets({intent:(d=t.repairPatches)!=null&&d.length?"restore.repairDocument":"restore.repairLayout",patches:i,refresh:!1,rootRef:Ja(t.canvasAssetId),transactionId:`restore_${t.canvasAssetId}_${Date.now()}`});Object.entries(a.versions??{}).forEach(([c,u])=>n.set(c,u))},lme=({client:e,onAssetVersion:t,preloadedAssets:n})=>{let r=async({pippitAssetIds:s,isCamelCase:i=!0,signal:a},d)=>{let c=s.filter(f=>!(n!=null&&n.has(f))),[u,p]=await Promise.all([c.length>0?e.assets.queryAssets(c.map(Ja),d?{dispatchMode:d,signal:a}:{signal:a}):Promise.resolve([]),Promise.all(s.filter(f=>n==null?void 0:n.has(f)).map(async f=>[f,await(n==null?void 0:n.get(f))]))]),l=new Map;return u.forEach(({asset:f,ref:h})=>{l.set(h.pippitAssetId,f)}),p.forEach(([f,h])=>{l.set(f,h??null)}),s.map(f=>{var g;let h=l.get(f)??null,m=Ry(h);return m!==void 0&&(t==null||t(f,m)),{extra:(h==null?void 0:h.extra)??null,pippitAssetId:f,value:GG((g=h==null?void 0:h.text)==null?void 0:g.content,i)}})},o=s=>r(s);return o.queryImmediately=s=>r(s,"immediate"),o},fme=async(e,t)=>{var i;let n=Ry(t),r=GG((i=t==null?void 0:t.text)==null?void 0:i.content);if(r===null)return{asset:null,assetId:e.assetId,...n===void 0?{}:{assetVersion:n}};if(e.assetKind==="canvas"){let a=await cp(r,{canvasAssetId:e.assetId});return{asset:(a==null?void 0:a.assets[e.assetId])??null,assetId:e.assetId,...n===void 0?{}:{assetVersion:n}}}let o=ap(r,{nodeAssetId:e.assetId,nodeType:e.nodeType});return{asset:o?{...o,assetExtra:(t==null?void 0:t.extra)??null}:null,assetId:e.assetId,...n===void 0?{}:{assetVersion:n}}};function UG({client:e,enableCoverAssetPrefetch:t=!1,initialRootAsset:n,onRestoreEvent:r,onRestoreResult:o,resolvePriorityNodeAssetIds:s}){let i=n,a=t?async({pippitAssetIds:d,signal:c})=>{await e.assets.queryAssets(d.map(u=>({pippitAssetId:u})),{batchingStrategy:"max-size",dispatchMode:"immediate",signal:c})}:void 0;return{async fetchSnapshot({scopeAssetId:d,signal:c,onProgress:u}){let p=i;i=void 0;let l=new Map,f=await WL(d,{debugLog:!1,onEvent:r,prefetchCoverAssets:a,onRootDocumentReady:h=>{u==null||u({kind:"root-ready",document:h})},onNodeAssetsReady:({document:h,readyNodeAssetIds:m})=>{u==null||u({kind:"assets-ready",document:h,readyAssetIds:m})},queryTextAssetContent:lme({client:e,onAssetVersion:(h,m)=>l.set(h,m),preloadedAssets:p?new Map([[d,p]]):void 0}),resolvePriorityNodeAssetIds:s,signal:c});return await pme(e,f,l,c),o==null||o(f),{assetVersions:dme(l),state:f.document}},async fetchAssets({requests:d,signal:c}){let u=await e.assets.queryAssets(d.map(({assetId:f})=>Ja(f)),{signal:c}),p=await Promise.all(d.map((f,h)=>{var m;return fme(f,((m=u[h])==null?void 0:m.asset)??null)})),l={};return u.forEach(({asset:f},h)=>{(f==null?void 0:f.version)!==void 0&&(l[d[h].assetId]=f.version)}),{assets:p,assetVersions:l}}}}var mme=["9:16","16:9","21:9","3:4","4:3","1:1"],hme={"9:16":{w:236,h:420},"16:9":{w:420,h:236},"21:9":{w:420,h:180},"3:4":{w:315,h:420},"4:3":{w:420,h:315},"1:1":{w:360,h:360}},gme={"9:16":"9:16","16:9":"16:9","21:9":"21:9","3:4":"3:4","4:3":"4:3","1:1":"1:1"},yme={"9:16":{width:9,height:16},"16:9":{width:16,height:9},"21:9":{width:21,height:9},"3:4":{width:3,height:4},"4:3":{width:4,height:3},"1:1":{width:1,height:1}};function qG(e){return mme.includes(e)}function Ame(e){return gme[e]}function FG(e){return hme[e]}function jG(e){return(e==null?void 0:e.type)===he||(e==null?void 0:e.type)===L||(e==null?void 0:e.type)===me||(e==null?void 0:e.type)===M}function VG(e){return(e==null?void 0:e.type)===L||(e==null?void 0:e.type)===me||(e==null?void 0:e.type)===M}function zG(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function vme(e){return"metadata"in e||"naturalWidth"in e||"caption"in e}function Sme(e){return"playback"in e||"frameWidth"in e||"durationMs"in e||"title"in e}function HG(e,t){let n=e,r=Ame(t),o=yme[t],s={...n,generation:{...zG(n.generation)?n.generation:{},ratio:r}},i=Sme(n);return!i&&vme(n)&&(s.metadata={...zG(n.metadata)?n.metadata:{},ratio:r}),i&&(s.ratio=o),s}function YG(){return O.t("Pippit_xyqcanvas_legacy_label_unnamed_role",{},"未命名角色")}function Op(e,t){let n=q_(t);return n.length>0?{...e,episodes:n}:e}function KG(e,t,n={}){return Op({nodeName:e,order:t,basicInfo:{name:e,...n.defaultAppearanceName?{appearanceName:n.defaultAppearanceName}:{}}},n.defaultEpisodeIds)}var bme={text:{type:Qn.type,createNodeData:()=>({}),createAsset:e=>wp(e,Qn.type,{plainText:"",placeholder:O.t("Pippit_xyqcanvas_legacy_label_text",{},"文本"),block:{verticalAlign:"top",overflow:"wrap",padding:Z_.padding}}),getDefaultSize:e=>{var t,n;return((n=(t=Qn).getDefaultSize)==null?void 0:n.call(t,e))??{w:420,h:180}}},image:{type:En.type,createNodeData:()=>({}),createAsset:(e,t,n)=>wp(e,En.type,Op(Ey({caption:O.t("Pippit_xyqcanvas_legacy_label_picture",{},"图片")},n==null?void 0:n.defaultVideoRatio),n==null?void 0:n.defaultEpisodeIds)),getDefaultSize:e=>{var t,n;return((n=(t=En).getDefaultSize)==null?void 0:n.call(t,e))??{w:480,h:373}}},video:{type:Cn.type,createNodeData:()=>({}),createAsset:(e,t,n)=>wp(e,Cn.type,Op(Ey({title:O.t("Pippit_xyqcanvas_legacy_title_video",{},"视频"),caption:O.t("Pippit_xyqcanvas_legacy_title_video",{},"视频"),playback:{muted:!0}},n==null?void 0:n.defaultVideoRatio),n==null?void 0:n.defaultEpisodeIds)),getDefaultSize:e=>{var t,n;return((n=(t=Cn).getDefaultSize)==null?void 0:n.call(t,e))??{w:480,h:270}}},audio:{type:Wn.type,createNodeData:()=>({}),createAsset:(e,t,n)=>wp(e,Wn.type,Op({},n==null?void 0:n.defaultEpisodeIds)),getDefaultSize:e=>{var t,n;return((n=(t=Wn).getDefaultSize)==null?void 0:n.call(t,e))??{w:362,h:218}}},role:{type:Vr.type,createNodeData:()=>({name:YG()}),createAsset:(e,t,n)=>({pippitAssetId:e,type:pm,content:KG(YG(),t,{defaultAppearanceName:I_(),defaultEpisodeIds:n==null?void 0:n.defaultEpisodeIds}),extra:{}}),getDefaultSize:e=>Vr.getDefaultSize(e)},scene:{type:Ki.type,createNodeData:()=>({name:um()}),createAsset:(e,t,n)=>({pippitAssetId:e,type:Am,content:Ey(KG(um(),t,{defaultEpisodeIds:n==null?void 0:n.defaultEpisodeIds}),n==null?void 0:n.defaultVideoRatio),extra:{}}),getDefaultSize:e=>{var t,n;return((n=(t=Ki).getDefaultSize)==null?void 0:n.call(t,e))??{...Yr}}},scene3d:{type:ca.type,createNodeData:()=>({title:oh()}),createAsset:(e,t,n)=>{let r=sh(),o=n==null?void 0:n.initialData;return EE({document:o&&Object.keys(o).length>0?{...r,...o}:r,documentAssetId:n==null?void 0:n.scene3DDocumentAssetId,nodeId:e})},getDefaultSize:e=>{var t,n;return((n=(t=ca).getDefaultSize)==null?void 0:n.call(t,e))??{w:420,h:236}}}};function wp(e,t,n){return{pippitAssetId:e,type:t,content:n,extra:{}}}function Ey(e,t){return t?HG(e,t):e}function XG(e,t){if(!t||Object.keys(t).length===0)return e;let n=e.content&&typeof e.content=="object"&&!Array.isArray(e.content)?e.content:{};return{...e,content:{...n,...t}}}function Ime(e){return Array.isArray(e)?e:[e]}function _me({defaultSize:e,initialSize:t}){let n=t.w>0&&t.h>0?t.w/t.h:void 0;if(!n)return e;let r=Math.max(1,e.w*e.h);return{w:Math.round(Math.sqrt(r*n)),h:Math.round(Math.sqrt(r/n))}}function $G({kind:e,id:t,center:n,topLeft:r,initialData:o,initialAssetContent:s,initialNodeData:i,order:a=0,existingNodes:d,defaultEpisodeIds:c,defaultEpisodes:u,defaultVideoRatio:p,scene3DDocumentAssetId:l}){let f=bme[e],h=f.createNodeData(t),m=i?{...h,...i}:h,g=!!(o&&Object.keys(o).length>0),y=g?{...m,...o}:m,v=p&&!g&&VG({type:f.type}),S=p&&jG({type:f.type}),b=v?FG(p):g&&(e==="image"||e==="video")?_me({defaultSize:f.getDefaultSize(m),initialSize:f.getDefaultSize(y)}):f.getDefaultSize(y),I=r??wS({center:n??{x:0,y:0},size:b,existingNodes:d}),N=Ime(f.createAsset(t,a,{defaultEpisodeIds:c??u,defaultVideoRatio:S?p:void 0,initialData:o,scene3DDocumentAssetId:l})),w=N[0],ne=e==="scene3d"||!w?N:[XG(XG(w,o),s),...N.slice(1)];return{node:{id:t,type:f.type,x:I.x,y:I.y,w:b.w,h:b.h,parentId:null,order:a,data:m},assets:ne}}var Cy=[...Uc.filter(({kind:e})=>e!=="invoke_command"),{get description(){return O.t("Pippit_xyqcanvas_command_desc_createbusinessnode",{},"使用小云雀现有业务工厂创建文字、图片、视频、音频、角色、场景或 3D 导演台节点")},input:"{nodeKind, id?, topLeft?, center?, order?, initialData?, defaultEpisodeIds?, defaultVideoRatio?}",kind:"create_biz_node"}],Py=[{get description(){return O.t("Pippit_xyqcanvas_command_desc_updaterolefields",{},"更新角色名称、描述、集数、音色或配音字段")},input:"{nodeId, assetId, field, value}",name:nh},{get description(){return O.t("Pippit_xyqcanvas_command_desc_updateroleappearance",{},"更新角色外观主图、描述和音色信息")},input:"{nodeId, assetId, patch}",name:aa},{get description(){return O.t("Pippit_xyqcanvas_command_desc_updaterolereferenceimages",{},"更新角色参考图来源列表")},input:"{nodeId, assetId, operation}",name:da},{get description(){return O.t("Pippit_xyqcanvas_command_desc_updatescenefields",{},"更新场景名称、场景视图、描述或集数字段")},input:"{nodeId, assetId, field, value}",name:ch}],Rme=new Set(Py.map(({name:e})=>e));function Eme(e){return!!(e&&typeof e=="object"&&"kind"in e&&e.kind==="invoke_command")}function Cme(e){let t=e.filter(Eme);if(t.length===0)return;if(e.length!==1||t.length!==1)throw new Error("Registered business commands must run as a single mutation");let[{name:n}]=t;if(!Rme.has(n))throw new Error(`Unsupported registered business command: ${n}`)}function Pme(e){return e.kind==="create_biz_node"}async function xme(e,t){let n=[];for(let r of e.mutations){if(!Pme(r)){n.push(r);continue}let o=r.id??(t?await t(r):void 0);if(!o)throw new Error("create_biz_node requires id when allocateNodeId is not configured");let s=r.defaultVideoRatio===void 0?void 0:qG(r.defaultVideoRatio)?r.defaultVideoRatio:void 0;if(r.defaultVideoRatio!==void 0&&s===void 0)throw new Error(`Invalid defaultVideoRatio: ${String(r.defaultVideoRatio)}`);let{assets:i,node:a}=$G({defaultEpisodeIds:r.defaultEpisodeIds??r.defaultEpisodes,defaultVideoRatio:s,existingNodes:e.runtime.store.getRootCanvasContent().nodes,id:o,initialData:r.initialData,kind:r.nodeKind,order:r.order,topLeft:r.topLeft,center:r.center});n.push({assets:i,autoCreateNodeAsset:!1,kind:"create_node",node:a})}return n}function WG(e){var s;let t=l_({...e,mutationHandler:async i=>(Cme(i.mutations),Ei({...i,mutations:await xme(i,e.allocateNodeId)}))}),n=Cy.map(({kind:i})=>i).join(", "),r=`Canvas mutations: ${n}. Use apply_patches only for privileged patch-level changes.`,o=t.apply_mutations.args.mutations;return{...t,apply_mutations:{...t.apply_mutations,args:{...t.apply_mutations.args,mutations:((s=o.describe)==null?void 0:s.call(o,r))??o},description:`${t.apply_mutations.description} Supported mutation kinds: ${n}.`}}}0&&(module.exports={XYQ_CANVAS_OPENCODE_MUTATION_DEFINITIONS,XYQ_CANVAS_REGISTERED_COMMAND_DEFINITIONS,createPippitAssetRuntime,createPippitAssetSdkCanvasLoader,createPippitAssetServiceTransport,createXyqCanvasCommandRuntime,createXyqCanvasOpencodeToolDefinitions});
|