manga-renderer 1.0.30 → 1.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -10,4 +10,4 @@ Ctrlを押しているとコピー`],null,v);this.insertIcons.push(w)}this.calcu
10
10
  ,.:;?!-" ')]}
11
11
  `),Or=2,jt=2;function*qA(A,e,t,i,n,s){let a=i;const r=[];let o=0;function l(){if(o<r.length)return r[o];const f=t.next();return f.done||r.push(f.value),f.done?null:f.value}function c(){for(let f=0;f<jt;f++){const u=o-1-f;if(u<0||!n(r[u]))return f}return jt}let d=null;for(;l()!=null;){if(o===0){o=1,d=1;continue}else{const{size:p,wrap:v}=A(r.slice(0,o+1));if(!v){d=p,o++;continue}}e!=null&&(d=e);let u=c();if(u===0)for(let p=0;p<Or;p++){const v=l();if(v===null||!s(v))break;o++}else o-=u,o===0&&(o=1);const g=r.splice(0,o);yield{index:a,buffer:g,size:d,wrap:!0},a+=g.length,o=0}0<r.length&&(yield{index:a,buffer:r,size:d,wrap:!1})}function Jr(A,e,t){let i=[],n=0;function*s(r){let o=0;for(;o<r.length;)if(UA(r,o)){const l=Vr(r,o);o+=l.length,yield l}else yield r.charAt(o),o++}for(let r of t.split(`
12
12
  `))i.push(...qA(A,e,s(r),n,wt.has.bind(wt),Qt.has.bind(Qt))),n+=r.length+1;return i.map(({index:r,buffer:o,size:l,wrap:c})=>({index:r,text:o.join(""),size:l,wrap:c}))}function UA(A,e){const t=String.fromCodePoint(A.codePointAt(e)||0);return new RegExp("\\p{Emoji}","u").test(t)}function Vr(A,e){let t=e+1;return A.codePointAt(e)&&A.codePointAt(e)>65535&&t++,A.slice(e,t)}function Zr(A){const e=/\{([^{}]+)\|([^{}]+)\}/,t=/\[([^\[\]]+)\]\(([^\(\)]+)\)/,i=/\<\<([^<>]+)\>\>/;function n(s,a,r,o){const l=[];let c=s;for(;c;){const d=c.match(e),f=c.match(t),u=c.match(i),g=[{type:"color",match:d},{type:"ruby",match:f},{type:"romanHanging",match:u}].filter(p=>p.match).sort((p,v)=>p.match.index-v.match.index);if(g.length>0){const{type:p,match:v}=g[0],[b,w,D]=v,Q=v.index;switch(Q>0&&l.push({content:c.slice(0,Q),color:a,size:r,ruby:o}),p){case"color":const P=D.split(",").map(x=>x.trim()),E=P[0]||void 0,I=P[1]?parseFloat(P[1]):void 0;l.push(...n(w,E||a,I||r,o));break;case"ruby":l.push(...n(w,a,r,D));break;case"romanHanging":l.push({content:w,color:a,size:r,ruby:o,romanHanging:!0});break}c=c.slice(Q+b.length)}else l.push({content:c,color:a,size:r,ruby:o}),c=""}return l}return n(A)}function MA(A){return/^[\u0020-\u007E\uFF61-\uFF9F]$/.test(A)}function Hr(A,e){const t=new RegExp("(\\p{Emoji}(\\uFE0F|\\u200D\\p{Emoji})*)","u"),i=A.slice(e).match(t);return i&&i.index===0&&!MA(i[0])?i[0]:A.length>e+1&&(A[e+1]==="゙"||A[e+1]==="゚")?A.slice(e,e+2):null}function*Kt(A){let e="",t=!1,i=0;for(;i<A.length;){const n=A[i];if(MA(n))t?e+=n:(e&&(yield e),e=n,t=!0),i++;else{const s=Hr(A,i);s?(e&&(yield e),yield s,e="",t=!1,i+=s.length):(e&&(yield e),yield n,e="",t=!1,i++)}}e&&(yield e)}function*Fr(A){for(const e of A){const t=[...Kt(e.content)];if(e.ruby)yield{chars:t,color:e.color,size:e.size,ruby:[...Kt(e.ruby)],romanHanging:e.romanHanging};else if(e.romanHanging)yield{chars:[e.content],color:e.color,size:e.size,romanHanging:e.romanHanging};else for(const i of t)yield{chars:[i],color:e.color,size:e.size,romanHanging:e.romanHanging}}}function Nr(A,e,t,i,n,s,a,r,o,l){o||(o=St(A,t.height,i,n,s,l));let c=t.x+t.width-n*.5;for(const d of o.verticalLines){let f=0,u=null;for(const g of d){let p,v;const b=g.size??1;if({lineH:f,prev:u,startH:p,endH:v}=_t(A,t,c,f,s,e,g,b,!1,u),g.ruby){const D=(v-p)/g.ruby.length,Q=c+n*r,P={chars:g.ruby,color:g.color};_t(A,t,Q,p,D,e,P,a,!0,null)}}c-=n}}function _t(A,e,t,i,n,s,a,r,o,l){const c=n*(o?1:r);let d=null,f=null;if(a.romanHanging){const p=a.chars.join(""),v=A.measureText(p),b=v.width,w=v.actualBoundingBoxAscent+v.actualBoundingBoxDescent,D=n*.15;return d===null&&(d=i),f=i+b,A.save(),A.translate(t-w*.5,e.y+i+D),A.rotate(90*Math.PI/180),A.scale(r,r),s==="fill"?(a.color&&(A.fillStyle=a.color),A.fillText(p,0,0)):s==="stroke"&&(a.color&&(A.strokeStyle=a.color),A.strokeText(p,0,0)),A.restore(),{lineH:i+b,prev:l,startH:d,endH:f}}function u(p,v,b,w,D,Q){const P=A.measureText(Q),E=P.width;P.actualBoundingBoxAscent+P.actualBoundingBoxDescent,d===null&&(d=i+n-P.actualBoundingBoxAscent),f=i+n+P.actualBoundingBoxDescent;const I=t,x=(1-r)*n*.15,O=e.y+i+c*.5+x;A.save(),A.translate(I,O),A.scale(r,r),A.translate(v*n,b*n),A.rotate(p*Math.PI/180),A.scale(w,D),A.translate(-E*.5,n*.5),s==="fill"?(a.color&&(A.fillStyle=a.color),A.fillText(Q,0,0)):s==="stroke"&&(a.color&&(A.strokeStyle=a.color),A.strokeText(Q,0,0)),A.restore()}function g(p,v,b){u(0,p,v,1,1,b)}for(const p of a.chars){switch(i+=LA(l,p)*n*r,!0){case/[、。]/.test(p):g(.6,-.6,p);break;case/[“]/.test(p):u(0,.5,.5,-1,1,"〝");break;case/[”]/.test(p):u(0,-.4,-.4,-1,1,"〟");break;case/[ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヵヶ]/.test(p):g(.1,-.1,p);break;case/[「『:;]/.test(p):u(90,.2,.3,1,1,p);break;case/[」』]/.test(p):u(90,.1,-.1,1,1,p);break;case/[<(【〔≪{]/.test(p):u(90,.15,.15,1,1,p);break;case/[>)】〕≫}]/.test(p):u(90,.15,.15,1,1,p);break;case/[ー…―〰]/.test(p):u(90,-.1,.1,1,-1,p);break;case/[~〜]/.test(p):u(90,.1,.1,1,1,p);break;case UA(p,0):g(0,0,p);break;default:g(0,0,p);break}i+=c,l=p}return{lineH:i,prev:l,startH:d,endH:f}}function St(A,e,t,i,n,s){s||(e=1/0);function a(l){let c=0,d=null;for(const f of l)if(f.romanHanging){const u=A.measureText(f.chars.join(""));c+=u.width}else for(const u of f.chars){c+=LA(d,u);const g=f.size??1;c+=n*g,d=u}return c}const r=t.split(`
13
- `),o=[];for(const l of r){const c=Zr(l),d=Fr(c),f=qA(u=>{const g=a(u);return{size:g,wrap:e<g}},e,d,0,u=>u&&u.chars&&u.chars.length==1&&wt.has(u.chars[0]),u=>u&&u.chars&&u.chars.length==1&&Qt.has(u.chars[0]));for(const u of f)o.push({size:u.size,text:u.buffer})}return{height:o.reduce((l,c)=>Math.max(l,c.size),0),width:i*o.length,verticalLines:o.map(l=>l.text)}}function LA(A,e){return A?/[、。」』)】〕”]/.test(A)?/[「『(【〔“]/.test(e)||/[、。]/.test(e)?-.5:-.4:/[「『(【〔“]/.test(e)?-.4:0:/[「『(【〔“]/.test(e)?-.3:0}function $t(A,e,t,i,n,s,a,r,o,l,c){A==="v"?Nr(e,t,i,n,s,a,r,o,l,c):Wr(e,t,i,n,s,a,l,c)}function Wr(A,e,t,i,n,s,a,r){a||(a=It(A,t.width,i,n,s,r));for(let[o,l]of a.horizontalLines.entries())e==="fill"?A.fillText(l.text,t.x,t.y+n*o+n*.8):e==="stroke"&&A.strokeText(l.text,t.x,t.y+n*o+n*.8)}function zr(A,e,t,i,n,s,a,r){return A==="v"?St(e,i*.85,n,s,a,r):It(e,t*.85,n,s,a,r)}function It(A,e,t,i,n,s){s||(e=1/0);const a=Jr(r=>{const o=A.measureText(r.join(""));return{size:o.width,wrap:e<o.width}},e,t);return{width:a.reduce((r,o)=>Math.max(r,o.size),0),height:i*a.length,horizontalLines:a}}const Ye=48,M=10;class q{constructor(){h(this,"n_p0");h(this,"n_p1");h(this,"n_offset");h(this,"rotation");h(this,"text");h(this,"shape");h(this,"embedded");h(this,"fontStyle");h(this,"fontWeight");h(this,"n_fontSize");h(this,"charSkip");h(this,"lineSkip");h(this,"fontFamily");h(this,"direction");h(this,"fontColor");h(this,"fillColor");h(this,"strokeColor");h(this,"n_strokeWidth");h(this,"outlineColor");h(this,"n_outlineWidth");h(this,"autoNewline");h(this,"uuid");h(this,"parent");h(this,"creationContext");h(this,"filmStack");h(this,"scaleLock");h(this,"rubySize");h(this,"rubyDistance");h(this,"displayName");h(this,"optionContext");h(this,"pageNumber");h(this,"fontRenderVersion");h(this,"appearanceDelay");h(this,"hidesText");h(this,"prompt","");h(this,"gallery",[]);h(this,"renderInfo");this.reset(),this.n_p0=[0,0],this.n_p1=[.1,.1],this.text="empty",this.uuid=Pe.ulid(),this.parent=null,this.creationContext=this.getStackTrace(),this.filmStack=new $e,this.optionContext={},this.fontRenderVersion=0,this.gallery=[],this.displayName=""}reset(){const e=.0011904761904761906;this.n_offset=[0,0],this.rotation=0,this.shape="soft",this.embedded=!1,this.fontStyle="normal",this.fontWeight="400",this.n_fontSize=32*e,this.charSkip=0,this.lineSkip=0,this.fontFamily="源暎アンチック",this.direction="v",this.fontColor="#000000FF",this.fillColor="#ffffffE6",this.strokeColor="#000000FF",this.n_strokeWidth=3*e,this.n_outlineWidth=0,this.outlineColor="#000000FF",this.autoNewline=!1,this.appearanceDelay=0,this.hidesText=!1,this.rubySize=.4,this.rubyDistance=.45,this.displayName=""}getStackTrace(){return Error().stack}clone(e){const t=new q;return t.n_p0=[...this.n_p0],t.n_p1=[...this.n_p1],t.n_offset=[...this.n_offset],t.rotation=this.rotation,t.text=this.text,t.shape=this.shape,t.embedded=this.embedded,t.fontStyle=this.fontStyle,t.fontWeight=this.fontWeight,t.n_fontSize=this.n_fontSize,t.charSkip=this.charSkip,t.lineSkip=this.lineSkip,t.fontFamily=this.fontFamily,t.direction=this.direction,t.fontColor=this.fontColor,t.fillColor=this.fillColor,t.strokeColor=this.strokeColor,t.n_strokeWidth=this.n_strokeWidth,t.outlineColor=this.outlineColor,t.n_outlineWidth=this.n_outlineWidth,t.autoNewline=this.autoNewline,t.appearanceDelay=this.appearanceDelay,t.rubySize=this.rubySize,t.rubyDistance=this.rubyDistance,t.displayName=this.displayName,e&&(t.uuid=this.uuid,t.parent=this.parent),t.filmStack=new $e,t.filmStack.films=this.filmStack.films.map(i=>i.clone()),t.optionContext={...this.optionContext},t}copyStyleFrom(e){this.shape=e.shape,this.embedded=e.embedded,this.fontStyle=e.fontStyle,this.fontWeight=e.fontWeight,this.n_fontSize=e.n_fontSize,this.charSkip=e.charSkip,this.lineSkip=e.lineSkip,this.fontFamily=e.fontFamily,this.direction=e.direction,this.fontColor=e.fontColor,this.fillColor=e.fillColor,this.strokeColor=e.strokeColor,this.n_strokeWidth=e.n_strokeWidth,this.outlineColor=e.outlineColor,this.n_outlineWidth=e.n_outlineWidth,this.autoNewline=e.autoNewline,this.optionContext={...e.optionContext},this.rubySize=e.rubySize,this.rubyDistance=e.rubyDistance,this.displayName=e.displayName}static getUnit(e){return 1/Math.min(e[0],e[1])}static compile(e,t){const i=.0011904761904761906,n=q.getUnit(e),s=(r,o,l)=>r??(o!=null?o*n:l*i),a=new q;return a.n_p0=t.p0??t.n_p0,a.n_p1=t.p1??t.n_p1,a.n_offset=[0,0],t.n_offset?a.n_offset=t.n_offset:t.offset&&(a.n_offset=this.normalizedPosition(e,t.offset)),a.rotation=t.rotation??0,a.text=t.text??"",a.shape=t.shape??"square",a.shape=="harsh-curve"&&(a.shape="shout"),a.embedded=t.embedded??!1,a.fontStyle=t.fontStyle??"normal",a.fontWeight=t.fontWeight??"400",a.n_fontSize=26*n,t.n_fontSize?a.n_fontSize=t.n_fontSize:t.fontSize&&(a.n_fontSize=t.fontSize),a.charSkip=t.charSkip??0,a.lineSkip=t.lineSkip??0,a.fontFamily=t.fontFamily??"Noto Sans JP",a.direction=t.direction??"v",a.fontColor=t.fontColor??"#000000FF",a.fillColor=t.fillColor??"#ffffffE6",a.strokeColor=t.strokeColor??"#000000FF",a.n_strokeWidth=s(t.n_strokeWidth,t.strokeWidth,1),a.outlineColor=t.outlineColor??"#000000FF",a.n_outlineWidth=s(t.n_outlineWidth,t.outlineWidth,0),a.autoNewline=t.autoNewline??!0,a.uuid=t.uuid??Pe.ulid(),a.parent=t.parent,a.rubySize=t.rubySize??.4,a.rubyDistance=t.rubyDistance??.45,a.displayName=t.displayName??"ふきだし",a.optionContext=q.getInitialOptions(a),Object.assign(a.optionContext,t.optionContext??{}),a.forceEnoughSize(e),a}static decompile(e){const t=.0011904761904761906,i=(n,s)=>Math.abs(n-s)<1e-4;return{n_p0:e.n_p0,n_p1:e.n_p1,n_offset:e.n_offset[0]==0&&e.n_offset[1]==0?void 0:e.n_offset,rotation:e.rotation==0?void 0:e.rotation,text:e.text==""?void 0:e.text,shape:e.shape=="square"?void 0:e.shape,embedded:e.embedded==!1?void 0:e.embedded,fontStyle:e.fontStyle=="normal"?void 0:e.fontStyle,fontWeight:e.fontWeight=="400"?void 0:e.fontWeight,n_fontSize:i(e.n_fontSize,26*t)?void 0:e.n_fontSize,charSkip:e.charSkip==0?void 0:e.charSkip,lineSkip:e.lineSkip==0?void 0:e.lineSkip,fontFamily:e.fontFamily=="Noto Sans JP"?void 0:e.fontFamily,direction:e.direction=="v"?void 0:e.direction,fontColor:e.fontColor=="#000000FF"?void 0:e.fontColor,fillColor:e.fillColor=="#ffffffE6"?void 0:e.fillColor,strokeColor:e.strokeColor=="#000000FF"?void 0:e.strokeColor,n_strokeWidth:i(e.n_strokeWidth,1*t)?void 0:e.n_strokeWidth,outlineColor:e.outlineColor=="#000000FF"?void 0:e.outlineColor,n_outlineWidth:i(e.n_outlineWidth,0*t)?void 0:e.n_outlineWidth,autoNewline:e.autoNewline?void 0:e.autoNewline,uuid:e.uuid,parent:e.parent,rubySize:e.rubySize==.4?void 0:e.rubySize,rubyDistance:e.rubyDistance==.45?void 0:e.rubyDistance,displayName:e.displayName,optionContext:JSON.stringify(e.optionContext)==JSON.stringify(q.getInitialOptions(e))?void 0:e.optionContext}}static getPhysicalPoint(e,t){return[t[0]*e[0],t[1]*e[1]]}getPhysicalRect(e){const[t,i]=q.getPhysicalPoint(e,this.n_p0),[n,s]=q.getPhysicalPoint(e,this.n_p1);return[t,i,n-t,s-i]}getPhysicalBox(e){return[q.getPhysicalPoint(e,this.n_p0),q.getPhysicalPoint(e,this.n_p1)]}getPhysicalCenter(e){const t=this.getPhysicalRect(e);return[t[0]+t[2]/2,t[1]+t[3]/2]}getPhysicalSize(e){const t=this.getPhysicalRect(e);return[t[2],t[3]]}getPhysicalOffset(e){return q.denormalizedPosition(e,this.n_offset)}getPhysicalFontSize(e){return this.n_fontSize/q.getUnit(e)}getPhysicalStrokeWidth(e){return this.n_strokeWidth/q.getUnit(e)}getPhysicalOutlineWidth(e){return this.n_outlineWidth/q.getUnit(e)}getPhysicalRegularizedRect(e){const[t,i]=this.regularized(),[n,s]=q.getPhysicalPoint(e,t),[a,r]=q.getPhysicalPoint(e,i);return[n,s,a-n,r-s]}getPhysicalRegularizedBox(e){const[t,i]=this.regularized();return[q.getPhysicalPoint(e,t),q.getPhysicalPoint(e,i)]}hasEnoughSize(e){const t=this.getPhysicalRect(e);return Ye<=t[2]&&Ye<=t[3]}static enoughSize(e){return[Math.max(e[0],Ye+1),Math.max(e[1],Ye+1)]}setPhysicalCenter(e,t){const[i,n]=t,[s,a]=this.getPhysicalSize(e);this.n_p0=q.normalizedPosition(e,[i-s/2,n-a/2]),this.n_p1=q.normalizedPosition(e,[i+s/2,n+a/2])}setPhysicalSize(e,t){const i=[(this.n_p0[0]+this.n_p1[0])/2,(this.n_p0[1]+this.n_p1[1])/2];this.n_p0=[i[0]-t[0]/e[0]/2,i[1]-t[1]/e[1]/2],this.n_p1=[i[0]+t[0]/e[0]/2,i[1]+t[1]/e[1]/2]}setPhysicalRect(e,t){this.n_p0=[t[0]/e[0],t[1]/e[1]],this.n_p1=[(t[0]+t[2])/e[0],(t[1]+t[3])/e[1]]}setPhysicalFontSize(e,t){this.n_fontSize=t*q.getUnit(e)}setPhysicalStrokeWidth(e,t){this.n_strokeWidth=t*q.getUnit(e)}setPhysicalOutlineWidth(e,t){this.n_outlineWidth=t*q.getUnit(e)}setPhysicalOffset(e,t){this.n_offset=q.normalizedPosition(e,t)}forceEnoughSize(e){const t=this.getPhysicalRect(e),i=q.enoughSize([t[2],t[3]]);this.setPhysicalSize(e,i)}contains(e,t){const[i,n]=t,[s,a]=q.getPhysicalPoint(e,this.n_p0),[r,o]=q.getPhysicalPoint(e,this.n_p1);return s<=i&&i<=r&&a<=n&&n<=o}getHandleAt(e,t){for(let i of Ur){const n=this.getHandleRect(e,i);if(Mi(n,t))return i}return null}getHandleRect(e,t){const[i,n,s,a]=this.getPhysicalRect(e);switch(t){case"topLeft":return[i-M,n-M,M*2,M*2];case"topRight":return[i+s-M,n-M,M*2,M*2];case"bottomLeft":return[i-M,n+a-M,M*2,M*2];case"bottomRight":return[i+s-M,n+a-M,M*2,M*2];case"top":return[i-M,n-M,s+M*2,M*2];case"bottom":return[i-M,n+a-M,s+M*2,M*2];case"left":return[i-M,n-M,M*2,a+M*2];case"right":return[i+s-M,n-M,M*2,a+M*2]}}regularized(){const e=[Math.min(this.n_p0[0],this.n_p1[0]),Math.min(this.n_p0[1],this.n_p1[1])],t=[Math.max(this.n_p0[0],this.n_p1[0]),Math.max(this.n_p0[1],this.n_p1[1])];return[e,t]}regularize(){[this.n_p0,this.n_p1]=this.regularized()}canLink(){return console.log(this.optionSet),!!this.optionSet.link}linkTo(e){this.parent=e.uuid}linkedTo(e){return this.parent===e.uuid||e.parent===this.uuid}static normalizedPosition(e,t){return[t[0]/e[0],t[1]/e[1]]}static denormalizedPosition(e,t){return[t[0]*e[0],t[1]*e[1]]}get optionSet(){return eA[this.shape]}initOptions(){this.optionContext=q.getInitialOptions(this)}static getInitialOptions(e,t=!1){const i=eA[e.shape],n={};for(const s of Object.keys(i))i[s].init&&(n[s]=i[s].init(e),t&&i[s].sampleInit&&(n[s]=i[s].sampleInit(e)));return n}calculateFitSize(e){const t=this.getPhysicalFontSize(e),i=t*1.5*(1+this.lineSkip),n=t*(1+this.charSkip),a=document.createElement("canvas").getContext("2d");let r=[0,0];if(this.direction=="v"){const o=St(a,1/0,this.text,i,n,!1);r=[Math.floor(o.width*1.2),Math.floor(o.height*1.4)]}else{const o=`${this.fontStyle} ${this.fontWeight} ${t}px '${this.fontFamily}'`;a.font=o;const l=It(a,1/0,this.text,i,n,!1);r=[Math.floor(l.width*1.4),Math.floor(l.height*1.2)]}return console.log(r),q.enoughSize(r)}}const eA={rounded:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.7},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},square:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},ellipse:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>.1}},concentration:{lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:A=>200},lineLength:{label:"線の長さ",type:"number",min:1.05,max:1.5,step:.01,init:A=>1.3}},thought:{lineCount:{label:"線の本数",type:"number",min:100,max:600,step:1,init:A=>400},lineLength:{label:"線の長さ",type:"number",min:.05,max:.5,step:.01,init:A=>.3},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.2,step:.01,init:A=>.14},jitter:{label:"ジッター",type:"number",min:0,max:.5,step:.001,init:A=>.08},waveFrequency:{label:"ウェーブ周期",type:"number",min:8,max:64,step:1,init:A=>8},waveAmplitude:{label:"ウェーブ振幅",type:"number",min:0,max:.1,step:.001,init:A=>0}},polygon:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:A=>7},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.4},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},strokes:{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:A=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:A=>1.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0}},"double-strokes":{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:A=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:A=>1.25},interval:{label:"間隔",type:"number",min:.01,max:.2,step:.01,init:A=>.04},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0}},harsh:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:A=>.07},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:A=>15},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},shout:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>6,sampleInit:A=>6},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3,sampleInit:A=>3},bumpSharp:{label:"でっぱりの鋭さ",type:"number",min:.01,max:.5,step:.01,init:A=>.16,sampleInit:A=>.2},bumpCount:{label:"でっぱりの数",type:"number",min:4,max:20,step:1,init:A=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.5,sampleInit:A=>.2},depthJitter:{label:"鋭さジッター",type:"number",min:0,max:1.5,step:.01,init:A=>.5,sampleInit:A=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},soft:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:A=>.14},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:A=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.4},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:A=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},heart:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},diamond:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},arrow:{link:{hint:"結合",icon:"unite"},shaftWidth:{label:"軸の太さ",type:"number",min:0,max:1,step:.01,init:A=>.5},headLength:{label:"矢じりの長さ",type:"number",min:0,max:1,step:.01,init:A=>.5},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},"motion-lines":{focalPoint:{hint:"内円の中心",icon:"circle",init:A=>[0,0]},focalRange:{hint:"内円の範囲",icon:"radius",init:A=>[0,40]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:A=>200},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.1,step:.01,init:A=>.05},angleJitter:{label:"角度ジッター",type:"number",min:0,max:.2,step:.01,init:A=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:1,step:.01,init:A=>.5}},"speed-lines":{tailTip:{hint:"流線の先端",icon:"tail",init:A=>[40,0]},tailMid:{hint:"流線の途中",icon:"curve",init:A=>[.5,0]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},lineCount:{label:"線の本数",type:"number",min:10,max:200,step:1,init:A=>70},lineWidth:{label:"線の太さ",type:"number",min:.01,max:1,step:.01,init:A=>.2},laneJitter:{label:"間隔ジッター",type:"number",min:0,max:.2,step:.01,init:A=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:.5,step:.01,init:A=>.3}},"ellipse-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:A=>1}},"soft-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:A=>.15},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:A=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.4},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:A=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:A=>1}},"rounded-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.7},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:A=>1}},none:{}};class TA extends ot{constructor(t,i,n,s,a,r){super();h(this,"selected",null);h(this,"playIcon");h(this,"dashPhase",0);h(this,"lastNow",null);h(this,"dashSpeed",10);h(this,"showPlayButton");h(this,"showDottedBorder");this.frameTree=t,this.bubbles=i,this.onFocus=n,this.focusKeeper=s,this.playIcon=new $(["viewerLayer/play.webp"],[32,32],[1,1],"再生",()=>!0,()=>this.paper.matrix),s.subscribe(this.changeFocus.bind(this)),this.showPlayButton=a,this.showDottedBorder=r}renderDepths(){return[0,1]}calculateRootLayout(){return mt(this.frameTree,this.getPaperSize(),[0,0])}render(t,i){if(i===0){const n=this.calculateRootLayout();this.interactable&&this.renderLayoutRecursive(t,n),this.renderFramePlayButtons(t,n)}i===1&&this.renderBubblePlayButtons(t)}renderLayoutRecursive(t,i){var n;t.strokeStyle="rgba(0, 200, 200, 0.2)",t.lineWidth=2,t.beginPath(),t.moveTo(...i.corners.topLeft),t.lineTo(...i.corners.topRight),t.lineTo(...i.corners.bottomRight),t.lineTo(...i.corners.bottomLeft),t.closePath(),t.stroke(),(n=i.children)==null||n.forEach(s=>{this.renderLayoutRecursive(t,s)})}renderFramePlayButtons(t,i){var n;this.hasVideo(i==null?void 0:i.element.filmStack)&&(this.showDottedBorder&&pt(t,"rgba(128, 128, 128, 1)",i.corners,2,5,!1,this.dashPhase,[20,20]),this.showPlayButton&&(this.playIcon.position=ge(i.corners.bottomRight,[8,8]),this.playIcon.pivot=[1,1],this.playIcon.shadowColor="rgba(0, 0, 0, 0.5)",this.playIcon.render(t))),(n=i.children)==null||n.forEach(s=>{this.renderFramePlayButtons(t,s)})}renderBubblePlayButtons(t){for(const i of this.bubbles)if(this.hasVideo(i.filmStack)){const n=this.getPaperSize(),[s,a,r,o]=i.getPhysicalRect(n),l=[s+r/2,a];this.showDottedBorder&&pt(t,"rgba(128, 128, 128, 1)",SA([s,a,r,o]),2,5,!1,this.dashPhase,[20,20]),this.showPlayButton&&(this.playIcon.position=l,this.playIcon.pivot=[.5,0],this.playIcon.shadowColor="rgba(0, 0, 0, 0.5)",this.playIcon.render(t))}}handleClick(t){this.selectTarget(t)}acceptDepths(){return[0,1]}accepts(t,i,n){if(Ge.Space)return null;if(n===1){for(const s of this.bubbles){const a=this.getPaperSize();if(s.contains(a,t))return{action:"click",layout:s}}return null}else{const s=this.calculateRootLayout(),a=RA(s,t,0);return a?{action:"click",layout:a}:(this.selectTarget(null),null)}}async*pointer(t,i){i.action==="click"&&this.handleClick(i.layout)}async keyDown(t,i){return i.code==="Escape"?(this.selectTarget(null),!0):!1}changeFocus(t){t!==this&&(this.onFocus(null),this.redraw())}selectTarget(t){t!==this.selected&&(this.stopVideo(this.selected),this.selected=t,this.startVideo(t),this.onFocus(t),this.focusKeeper.setFocus(t?this:null),this.redraw())}stopVideo(t){var i;if(t){const n=this.getFilmStack(t);for(const s of n.films)(i=s.media.player)==null||i.pause()}}startVideo(t){if(!t)return;const i=this.getFilmStack(t);for(const n of i.films)n.media.player&&n.media.player.play()}tick(t){if(this.hasAnyVideo()&&this.showDottedBorder){this.lastNow==null&&(this.lastNow=t);const i=t-this.lastNow;this.lastNow=t,this.dashPhase=(this.dashPhase+this.dashSpeed*i/1e3)%1e4,this.redraw()}if(this.selected){const i=this.getFilmStack(this.selected);for(const n of i.films){const s=n.media.drawSource;if(s instanceof HTMLVideoElement&&!s.paused&&!s.ended){this.redraw();break}}}}getFilmStack(t){return t instanceof q?t.filmStack:t.element.filmStack}hasVideo(t){for(const i of t.films)if(i.media.player)return!0;return!1}hasAnyVideoInLayout(t){if(this.hasVideo(t.element.filmStack))return!0;if(t.children){for(const i of t.children)if(this.hasAnyVideoInLayout(i))return!0}return!1}hasAnyVideo(){const t=this.calculateRootLayout();if(this.hasAnyVideoInLayout(t))return!0;for(const i of this.bubbles)if(this.hasVideo(i.filmStack))return!0;return!1}get interactable(){return this.mode==null}}DA(TA);var qe=[];function GA(A){if(qe=[],A.length==3)return A.push(A[0]),A;var e=Xr(A);return et(e,A),et([e[1],e[0]],A),qe.push(qe[0]),qe}function Xr(A){var e,t,i;for(t=A[0],i=A[0],e=1;e<A.length;e++)A[e][0]<t[0]&&(t=A[e]),A[e][0]>i[0]&&(i=A[e]);return[t,i]}function Yr(A,e){var t=e[1][1]-e[0][1],i=e[0][0]-e[1][0];return i*(A[1]-e[0][1])+t*(A[0]-e[0][0])}function jr(A,e){var t,i=[],n,s,a=0,r=0;for(t=0;t<e.length;t++){if(n=e[t],a=Yr(n,A),a>0)i.push(n);else continue;a>r&&(s=n,r=a)}return{points:i,max:s}}function et(A,e){var t=jr(A,e);if(!t.max)return qe.push(A[0]);et([A[0],t.max],t.points),et([t.max,A[1]],t.points)}function Je(A,e,t){const[i,n]=A,[s,a]=e,[r,o]=t,[l,c]=[r*s+o*a,r*a-o*s];return[l+i,c+n]}function Ie(A,e,t=.5){const i=[];for(let n=0;n<e;n++){const s=(A()-.5)/e*t,a=(n/e+s)*2*Math.PI;i.push(a)}return i}function Re(A,e,t=3){return e.map(i=>Ri(A[0]/2,A[1]/2,t,i))}function Kr(A,e,t,i,n=2){const s=[];for(let a=0;a<e.length;a++)if(a%n===0){const[r,o]=e[a],l=Math.hypot(r,o),c=1+t+(A()-.5)*i,d=l*c,[f,u]=[r*d/l,o*d/l];s.push([f,u])}else s.push(e[a]);return s}function _r(A,e,t){const i=Ci(A,e),n=ge(e,A),s=me(n),a=Oe(s,t);return pe(i,a)}function lt(A,e,t){const i=Math.min(A[0],A[1])*t,n=[];for(let s=0;s<e.length;s++){const a=(s+1)%e.length,r=e[s],o=e[a];n.push(r),n.push(_r(r,o,i))}return n}function j(A){return`rgba(${A[0]}, ${A[1]}, ${A[2]}, ${A[3]})`}function $r(){V.setup([1,1]),V.view.autoUpdate=!1}function Rt(A,e,t,i,n,s){switch(t=s.randomSeed??0,n){case"rounded":mo(A,e,t,i,s);break;case"square":po(A,e,t,i,s);break;case"ellipse":fo(A,e,t,i,s);break;case"concentration":eo(A,e,t,i,s);break;case"thought":to(A,e,t,i,s);break;case"polygon":go(A,e,t,i,s);break;case"strokes":io(A,e,t,i,s);break;case"double-strokes":no(A,e,t,i,s);break;case"harsh":bo(A,e,t,i,s);break;case"shout":wo(A,e,t,i,s);break;case"soft":Qo(A,e,t,i,s);break;case"heart":vo(A,e,t,i,s);break;case"diamond":yo(A,e,t,i,s);break;case"arrow":Po(A,e,t,i,s);break;case"motion-lines":so(A,e,t,i,s);break;case"speed-lines":ao(A,e,t,i,s);break;case"ellipse-mind":ko(A,e,t,i,s);break;case"soft-mind":Bo(A,e,t,i,s);break;case"rounded-mind":Do(A,e,t,i,s);break;case"none":break;default:throw new Error(`Unknown bubble : ${n}`)}}function eo(A,e,t,i,n){const[s,a]=i;if(e==="fill"){A.save(),A.translate(0,0),A.scale(s/2,a/2),A.lineWidth=1/Math.min(s,a);const r=n.lineCount;A.save();const o=A.createRadialGradient(0,0,1,0,0,n.lineLength),l=A.strokeStyle,c=ce(l),d=ce(l);c[3]=0,o.addColorStop(0,j(d)),o.addColorStop(1,j(c)),A.strokeStyle=o,A.beginPath();for(let f=0;f<r;f++){const u=f*2*Math.PI/r,[g,p]=[Math.cos(u),Math.sin(u)],[v,b]=[g*n.lineLength,p*n.lineLength];A.moveTo(g,p),A.lineTo(v,b)}A.closePath(),A.stroke(),A.restore(),A.restore()}else e==="clip"&&(A.beginPath(),A.ellipse(0,0,s*.5,a*.5,0,0,2*Math.PI),A.clip())}function to(A,e,t,i,n){const s=ne(t),[a,r]=i;if(e==="fill"){A.save(),A.translate(0,0),A.scale(a/2,r/2),A.beginPath(),A.ellipse(0,0,1,1,0,0,2*Math.PI),A.fill(),A.lineWidth=1;const o=n.lineCount;A.save(),A.createRadialGradient(0,0,1,0,0,n.lineLength);const l=A.strokeStyle;A.fillStyle=l;const d=n.lineLength*.5,f=1-d,u=1+d;for(let g=0;g<o;g++){const p=g*2*Math.PI/o,[v,b]=[Math.cos(p),Math.sin(p)],[w,D]=ve([v,b],f),[Q,P]=ve([v,b],u),E=s()*n.jitter,I=s()*n.jitter,x=1+Math.sin(p*n.waveFrequency)*n.waveAmplitude,O=ve([w,D],(1-E)*x),F=ve([Q,P],(1+I)*x);Ao(A,O,F,n.lineWidth)}A.restore(),A.restore()}else e==="clip"&&(A.beginPath(),A.ellipse(0,0,a*.5,r*.5,0,0,2*Math.PI),A.clip())}function Ao(A,e,t,i){const[n,s]=[t[0]-e[0],t[1]-e[1]],[a,r]=[n/2,s/2],[o,l]=[-r,a],[c,d]=[a+o*i/2,r+l*i/2],[f,u]=[a-o*i/2,r-l*i/2];A.beginPath(),A.moveTo(e[0],e[1]),A.lineTo(e[0]+c,e[1]+d),A.lineTo(t[0],t[1]),A.lineTo(e[0]+f,e[1]+u),A.closePath(),A.fill()}function io(A,e,t,i,n){OA(A,e,t,i,n,!1)}function no(A,e,t,i,n){OA(A,e,t,i,n,!0)}function OA(A,e,t,i,n,s){const a=ne(t),r=Re(i,Ie(a,n.vertexCount,n.angleJitter),n.superEllipse),o=GA(r);if(e=="fill"||e=="clip"){const l=new V.Path;for(let c=0;c<o.length;c++){const d=o[c];c===0?l.moveTo(d):l.lineTo(d)}l.closed=!0,G(A,e,l,n),l.remove()}else{const l=A.strokeStyle;for(let c=0;c<o.length;c++){A.beginPath();const d=o[c],f=o[(c+1)%o.length],[u,g]=ro(d,f,n.overRun),p=A.createLinearGradient(...u,...g),v=ce(l),b=ce(l);if(v[3]=0,p.addColorStop(0,j(v)),p.addColorStop(.15,j(b)),p.addColorStop(.85,j(b)),p.addColorStop(1,j(v)),A.strokeStyle=p,A.moveTo(u[0],u[1]),A.lineTo(g[0],g[1]),s){const w=Math.min(i[0],i[1])*n.interval,[D,Q]=[f[0]-d[0],f[1]-d[1]],[P,E]=[-Q,D],[I,x]=[P/Math.sqrt(P*P+E*E),E/Math.sqrt(P*P+E*E)],[O,F]=[u[0]+I*w,u[1]+x*w],[Z,H]=[g[0]+I*w,g[1]+x*w];A.moveTo(O,F),A.lineTo(Z,H)}A.stroke()}}}function so(A,e,t,i,n){const[s,a,r,o]=xe(i);if(e==="fill"){const l=ne(t);A.save(),A.beginPath(),A.rect(s,a,r,o),A.clip(),A.lineWidth=1;const c=n.lineCount,d=(n==null?void 0:n.focalPoint)??[0,0],f=(n==null?void 0:n.focalRange)??[0,Math.hypot(r/2,o/2)*.25],u=Math.hypot(f[0],f[1]),[g,p,v]=[0,0,Math.hypot(r/2,o/2)],[b,w,D]=[d[0],d[1],u],Q=A.createRadialGradient(b,w,D,g,p,v),P=ce(A.strokeStyle),E=ce(A.strokeStyle);P[3]=0,Q.addColorStop(0,j(P)),Q.addColorStop(.2,j(E)),Q.addColorStop(1,j(E)),A.fillStyle=Q;for(let I=0;I<c;I++){const x=I*2*Math.PI/c+(l()-.5)*n.angleJitter,[O,F]=[Math.cos(x),Math.sin(x)],Z=D*(1+l()*n.startJitter),H=[b,w],N=[g+O*v,p+F*v],se=[N[0]-H[0],N[1]-H[1]],Gt=Math.hypot(...se),Ot=[H[0]+se[0]*Z/Gt,H[1]+se[1]*Z/Gt],Jt=n.lineWidth*.1,[Vt,Zt]=[me(se,Jt),me(se,-Jt)];A.beginPath(),A.moveTo(Ot[0],Ot[1]),A.lineTo(N[0]+Vt[0],N[1]+Vt[1]),A.lineTo(N[0]+Zt[0],N[1]+Zt[1]),A.closePath(),A.fill()}A.restore()}}function ao(A,e,t,i,n){const[s,a,r,o]=xe(i);if(e==="fill"){const l=ne(t);A.save();try{let c=function([w,D]){const Q=[u*.5,0],[P,E]=xi(Q,g),I=.5-Si([w,D],[P,E])*.5;return Wt(I)};A.beginPath(),A.rect(s,a,r,o),A.clip();const d=(n==null?void 0:n.tailTip)??[0,0],f=Je([0,0],d,(n==null?void 0:n.tailMid)??[0,0]),u=Math.hypot(r,o);if(!Number.isFinite(u)||u<=1e-6)return;const g=Math.atan2(d[1],d[0]);A.rotate(g),A.lineWidth=1;const p=n.lineCount,v=Wt(.5-Bi(d)/u),b=c(f);for(let w=0;w<p;w++){const D=(w+.5)/p*u-u/2+l()*u*n.laneJitter,Q=-u*.5+(l()-.5)*r*n.startJitter,P=o*n.lineWidth*.01*(l()+.5);try{const E=A.createLinearGradient(Q+u,D,Q,D),I=ce(A.strokeStyle),x=ce(A.strokeStyle);I[3]=0,E.addColorStop(v,j(I)),E.addColorStop(b,j(x)),E.addColorStop(1,j(x)),A.fillStyle=E}catch(E){throw console.error("drawSpeedLinesBubble: gradient addColorStop failed",{seed:t,i:w,length:u,angle:g,tailTip:d,tailMid:f,psf0:v,psf1:b,y:D,lx:Q,lw:P,lineCount:p,strokeStyle:A.strokeStyle,opts:n,error:E}),E}A.beginPath(),A.moveTo(Q,D-P),A.lineTo(Q+u,D),A.lineTo(Q,D+P),A.closePath(),A.fill()}}catch(c){throw console.error("drawSpeedLinesBubble: unexpected error",{seed:t,size:i,rect:[s,a,r,o],tailTip:(n==null?void 0:n.tailTip)??[0,0],tailMid:(n==null?void 0:n.tailMid)??[0,0],lineCount:n==null?void 0:n.lineCount,opts:n,error:c}),c}finally{A.restore()}}}function ro(A,e,t){const[i,n]=[e[0]-A[0],e[1]-A[1]],s=[e[0]-i*t,e[1]-n*t],a=[A[0]+i*t,A[1]+n*t];return[s,a]}function oo(A,e,t,i){i=t.randomSeed??0,performance.now();try{switch(A){case"square":return JA(e,t,i);case"ellipse":return xt(e,t,i);case"polygon":return YA(e,t,i);case"rounded":return Ct(e,t,i);case"harsh":return VA(e,t,i);case"shout":return ZA(e,t,i);case"soft":return qt(e,t,i);case"heart":return HA(e,t,i);case"diamond":return FA(e,t,i);case"arrow":return NA(e,t,i);case"ellipse-mind":return WA(e,t,i);case"soft-mind":return zA(e,t,i);case"rounded-mind":return XA(e,t,i);case"concentration":case"thought":case"none":return null}return console.error(`Unknown bubble shape: ${A}`),null}finally{}}function xe(A){return[-A[0]*.5,-A[1]*.5,A[0],A[1]]}function lo(A){return[A[0]*.5,A[1]*.5]}function JA(A,e,t){const i=new V.Path.Rectangle(xe(A));return fe(i,A,e)}function xt(A,e,t){const i=new V.Path.Ellipse({center:[0,0],radius:lo(A)});return fe(i,A,e)}function Ct(A,e,t){const[i,n,s,a]=xe(A),[r,o]=[0,0],[l,c]=[i+s,n+a],[d,f]=[e.xStraight*s*.5,e.yStraight*a*.5],u=new V.Path;return u.moveTo([r+d,n]),u.lineTo([r-d,n]),u.quadraticCurveTo([i,n],[i,o-f]),u.lineTo([i,o+f]),u.quadraticCurveTo([i,c],[r-d,c]),u.lineTo([r+d,c]),u.quadraticCurveTo([l,c],[l,o+f]),u.lineTo([l,o-f]),u.quadraticCurveTo([l,n],[r+d,n]),u.closed=!0,fe(u,A,e)}function VA(A,e,t){const i=ne(t);let n=Ie(i,e.bumpCount,e.angleJitter);const s=Re(A,n,e.superEllipse);let a=lt(A,s,e.bumpDepth);const r=new V.Path;return r.addSegments(a),r.closed=!0,fe(r,A,e)}function ZA(A,e,t){const i=e.bumpSharp,n=ne(t);let s;const a=Ie(n,e.bumpCount,e.angleJitter);s=Re(A,a,e.superEllipse),s=lt(A,s,i),s=Kr(n,s,i,e.depthJitter);const r=new V.Path;r.moveTo(s[0]);for(let o=0;o<s.length;o+=2){s[o];const l=s[o+1],c=s[(o+2)%s.length];r.quadraticCurveTo(l,c)}return r.closed=!0,fe(r,A,e)}function qt(A,e,t){const i=ne(t),n=Re(A,Ie(i,e.bumpCount,e.angleJitter),e.superEllipse),s=lt(A,n,-e.bumpDepth),a=new V.Path;if(e.smoothing)for(let r=0;r<s.length+1;r++){const o=s[r%s.length],l=s[(r+1)%s.length];let c=[(o[0]+l[0])/2,(o[1]+l[1])/2];r==0?a.moveTo(c):a.quadraticCurveTo(o,c)}else{a.moveTo(s[0]);for(let r=0;r<s.length;r+=2){const o=s[r+1],l=s[(r+2)%s.length];a.quadraticCurveTo(o,l)}a.closed=!0}return fe(a,A,e)}function HA(A,e,t){const[i,n]=A,[s,a]=[0,0],r=n*-.58,o=n*-.35,l=n*-.1,c=n*.1,d=n*.35,f=n*.5,u=new V.Path;return u.moveTo([s,a+o]),u.cubicCurveTo([-.1*i,r],[-.5*i,r],[-.5*i,l]),u.cubicCurveTo([-.5*i,c],[-.3*i,d],[0,f]),u.cubicCurveTo([.3*i,d],[.5*i,c],[.5*i,l]),u.cubicCurveTo([.5*i,r],[.1*i,r],[0,o]),u.closed=!0,u}function FA(A,e,t){const[i,n,s,a]=xe(A),r=new V.Path;return r.moveTo([0,n]),r.lineTo([i,0]),r.lineTo([0,n+a]),r.lineTo([i+s,0]),r.closed=!0,r}function NA(A,e,t){const[i,n,s,a]=xe(A),{shaftWidth:r,headLength:o}=e,l=r*s*.5,c=new V.Path,d=n+a*o,f=i+s*.5-l,u=i+s*.5+l;return c.moveTo([0,n]),c.lineTo([i,d]),c.lineTo([f,d]),c.lineTo([f,n+a]),c.lineTo([u,n+a]),c.lineTo([u,d]),c.lineTo([i+s,d]),c.lineTo([0,n]),c.closed=!0,c}function WA(A,e,t){const i={...e};i.tailTip=[0,0],i.tailMid=[.5,0];const n=xt(A,i);return Ut(n,t,A,e,i)}function zA(A,e,t){const i={...e};i.tailTip=[0,0],i.tailMid=[.5,0];const n=qt(A,i,t);return Ut(n,t,A,e,i)}function XA(A,e,t){const i={...e};i.tailTip=[0,0],i.tailMid=[.5,0];const n=Ct(A,i);return Ut(n,t,A,e,i)}function co(A,e,t,i,n,s){const a=ne(t),r=Re(A,Ie(a,i),n),o=lt(A,r,-s),l=new V.Path;l.moveTo(o[0]);for(let c=0;c<o.length;c+=2){o[c];const d=o[c+1],f=o[(c+2)%o.length];l.quadraticCurveTo(d,f)}return l.closed=!0,fe(l,A,e)}function fe(A,e,t){if(t!=null&&t.tailTip){const i=t.tailTip,n=t.tailMid;if(!(i[0]===0&&i[1]===0))if(t!=null&&t.extract){const s=uo(e,n,i,t.extractWidth),a=A.subtract(s);return A.remove(),s.remove(),a}else{const s=ho(e,n,i,t.tailWidth),a=A.unite(s);return A.remove(),s.remove(),a}}return A}function ho(A,e,t,i){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=A[0]*A[1]*i,s=Math.max(5e4,Math.hypot(t[0],t[1])**2),a=Oe(me(t),n*35/s),r=Oe(me(t,-1),n*35/s),o=[t[0]-a[0],t[1]-a[1]],l=[t[0]-r[0],t[1]-r[1]],c=t,d=a,f=r,u=Je(d,o,e),g=Je(f,l,e),p=new V.Path;return p.moveTo(d),p.curveTo(u,c),p.curveTo(g,f),p.closed=!0,p}function uo(A,e,t,i){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=Je([0,0],t,e),s=[t[0]-n[0],t[1]-n[1]],a=Math.hypot(t[0],t[1]),r=Oe(me(s),a*i),o=[t[0]+r[0],t[1]+r[1]],l=[t[0]-r[0],t[1]-r[1]],c=new V.Path;return c.moveTo(n),c.lineTo(o),c.lineTo(l),c.closed=!0,c}function YA(A,e,t){const i=ne(t),n=Ie(i,e.vertexCount,e.angleJitter),s=Re(A,n,e.superEllipse),a=GA(s),r=new V.Path;return r.addSegments(a),r.closed=!0,fe(r,A,e)}function fo(A,e,t,i,n){const s=xt(i,n);G(A,e,s,n)}function po(A,e,t,i,n){const s=JA(i,n);G(A,e,s,n)}function go(A,e,t,i,n){const s=YA(i,n,t);G(A,e,s,n)}function mo(A,e,t,i,n){const s=Ct(i,n);G(A,e,s,n)}function bo(A,e,t,i,n){const s=VA(i,n,t);G(A,e,s,n)}function wo(A,e,t,i,n){const s=ZA(i,n,t);G(A,e,s,n)}function Qo(A,e,t,i,n){const s=qt(i,n,t);G(A,e,s,n)}function vo(A,e,t,i,n){const s=HA(i);G(A,e,s,n)}function yo(A,e,t,i,n){const s=FA(i);G(A,e,s,n)}function Po(A,e,t,i,n){const s=NA(i,n);G(A,e,s,n)}function ko(A,e,t,i,n){const s=WA(i,n,t);G(A,e,s,n)}function Bo(A,e,t,i,n){const s=zA(i,n,t);G(A,e,s,n)}function Do(A,e,t,i,n){const s=XA(i,n,t);G(A,e,s,n)}function G(A,e,t,i){switch(A.beginPath(),e){case"fill":A.fill(new Path2D(t.pathData));break;case"stroke":const n=i.roughness??0;if(0<n){const s=(i.randomSeed??0)+1;pi.canvas(A.canvas,{options:{seed:s,roughness:n,strokeWidth:A.lineWidth,stroke:A.strokeStyle}}).path(t.pathData)}else A.stroke(new Path2D(t.pathData));break;case"clip":A.clip(new Path2D(t.pathData));break}}function Ut(A,e,t,i,n){const s=[[.97,.04],[.8,.05],[.6,.08],[.3,.12]],a=Je([0,0],i.tailTip,i.tailMid),r=i.tailTip,o=[r[0]-a[0],r[1]-a[1]],l=Math.min(t[0],t[1])*.5*i.tailWidth,c=(i==null?void 0:i.flattening)??1;for(let d of s){const f=[a[0]+d[0]*o[0],a[1]+d[0]*o[1]],u=l*d[1]*2,g=co([u,u],n,e,6,2,.15);if(c&&Math.abs(c-1)>1e-6){const p=c>1?1/c:1,v=c<1?c:1;g.scale(p,v,[0,0])}g.translate(f),A=A.unite(g)}return A}function je(A,e,t,i=!0){const n=[],s=r=>((t[0]-e[0])*(r[1]-e[1])-(t[1]-e[1])*(r[0]-e[0]))*(i?1:-1)>=0,a=(r,o)=>{const l=o[0]-r[0],c=o[1]-r[1],d=t[1]-e[1],f=-(t[0]-e[0]),u=((e[0]-r[0])*d+(e[1]-r[1])*f)/(l*d+c*f);return[r[0]+u*l,r[1]+u*c]};for(let r=0;r<A.length;r++){const o=A[r],l=A[(r+A.length-1)%A.length],c=s(o),d=s(l);c?(d||n.push(a(l,o)),n.push(o)):d&&n.push(a(l,o))}return n}function tA(A,e,t,i){const[n,s]=e;let a=[[0,0],[n,0],[n,s],[0,s]];if(t.top){const r=Xe(A.topLeft,A.topRight,-i);a=je(a,...r)}if(t.right){const r=Xe(A.topRight,A.bottomRight,-i);a=je(a,...r)}if(t.bottom){const r=Xe(A.bottomRight,A.bottomLeft,-i);a=je(a,...r)}if(t.left){const r=Xe(A.bottomLeft,A.topLeft,-i);a=je(a,...r)}return a}function jA(A,e,t,i,n){const s=e.films;for(let a of s){if(!a.visible)continue;const r=a.getShiftedScale(t),o=a.getShiftedTranslation(t);A.save(),n&&n(A,a),A.translate(...i),A.translate(o[0],o[1]),A.rotate(-a.rotation*Math.PI/180),A.scale(r*a.reverse[0],r*a.reverse[1]);let l=a.media;for(let c=a.effects.length-1;0<=c;c--)if(a.effects[c].outputMedia){l=a.effects[c].outputMedia;break}A.translate(-l.naturalWidth*.5,-l.naturalHeight*.5),A.drawImage(l.drawSource,0,0,l.naturalWidth,l.naturalHeight),A.restore()}}function AA(A,e,t,i,n){for(let s of t)KA(A,e,s),tt(A,e,s,!1,n);for(let s of t)tt(A,e,s,!0,n)}function KA(A,e,t,i){if(t.parent)return;const n=t.getPhysicalSize(e);t.getPhysicalStrokeWidth(e),A.save(),A.translate(...t.getPhysicalCenter(e)),A.rotate(-t.rotation*Math.PI/180),Eo(A,e,t,n),_A(A,t,n),jA(A,t.filmStack,e,[0,0],null),A.restore()}function Ce(A,e,t,i,n){A.fillStyle=e.hasEnoughSize(t)?i:"rgba(255, 128, 0, 0.9)"}function tt(A,e,t,i,n){if(t.parent){if(!i)return}else if(i)return;const s=t.getPhysicalSize(e),a=t.getPhysicalCenter(e),r=t.getPhysicalStrokeWidth(e);A.save(),A.translate(...a),A.rotate(-t.rotation*Math.PI/180),A.save(),_A(A,t,s),t.text&&!t.hidesText&&Io(A,e,t,n),A.restore(),A.strokeStyle=0<r?t.strokeColor:"rgba(0, 0, 0, 0)",A.lineWidth=r,So(A,e,t,s),A.restore()}function Eo(A,e,t,i,n){const s=t.renderInfo;s.unitedOuterPath?(s.innerPathIsSameWithOuterPath||(Ce(A,t,e,t.optionContext.shapeOutlineColor??"white"),G(A,"fill",s.unitedOuterPath,t.optionContext)),Ce(A,t,e,t.fillColor),G(A,"fill",s.unitedInnerPath,t.optionContext)):t.parent||(s.outerPath?(s.innerPathIsSameWithOuterPath||(Ce(A,t,e,t.optionContext.shapeOutlineColor??"white"),G(A,"fill",s.outerPath,t.optionContext)),Ce(A,t,e,t.fillColor),G(A,"fill",s.innerPath,t.optionContext)):(i[0]=Math.abs(i[0]),i[1]=Math.abs(i[1]),Ce(A,t,e,t.fillColor),A.strokeStyle=t.strokeColor,Rt(A,"fill",t.text,i,t.shape,t.optionContext)))}function _A(A,e,t){const i=e.renderInfo;i.unitedStrokePath?G(A,"clip",i.unitedStrokePath,e.optionContext):e.parent||(i.strokePath?G(A,"clip",i.strokePath,e.optionContext):(t[0]=Math.abs(t[0]),t[1]=Math.abs(t[1]),Rt(A,"clip",e.text,t,e.shape,e.optionContext)))}function So(A,e,t,i){const n=t.getPhysicalStrokeWidth(e);A.strokeStyle=0<n?t.strokeColor:"rgba(0, 0, 0, 0)",A.lineWidth=n;const s=t.renderInfo;s.unitedStrokePath?G(A,"stroke",s.unitedStrokePath,t.optionContext):t.parent||(s.strokePath?G(A,"stroke",s.strokePath,t.optionContext):(i[0]=Math.abs(i[0]),i[1]=Math.abs(i[1]),Rt(A,"stroke",t.text,i,t.shape,t.optionContext)))}function Io(A,e,t,i){const n=A.getTransform(),s=i?window.devicePixelRatio??1:1;let a,r;Math.abs(n.b)<.001&&Math.abs(n.c)<.001?(a=Math.abs(n.a),r=Math.abs(n.d)):(a=Math.sqrt(n.a*n.a+n.b*n.b),r=Math.sqrt(n.c*n.c+n.d*n.d));const o=[a*s,r*s],l=t.getPhysicalSize(e);let c=t.getPhysicalFontSize(e);const d=t.getPhysicalOffset(e),f=t.getPhysicalOutlineWidth(e),[u,g]=Nt(ki(l,o));if(u<1||g<1)return;isNaN(c)&&(c=14),c<1&&(c=14);const p=t.renderInfo,v=`${t.fontStyle} ${t.fontWeight} ${c}px '${t.fontFamily}'`,b={viewScale:Nt(ve(o,1e3)),size:l,offset:d,fontStyle:t.fontStyle,fontWeight:t.fontWeight,fontSize:c,lineSkip:t.lineSkip,charSkip:t.charSkip,fontFamily:t.fontFamily,text:t.text,direction:t.direction,autoNewline:t.autoNewline,fontColor:t.fontColor,outlineWidth:f,outlineColor:t.outlineColor,fontRenderVersion:t.fontRenderVersion,fontCheck:document.fonts.check(v),rubySize:t.rubySize,rubyDistance:t.rubyDistance},w=JSON.stringify(b);if(p.textJson!=w){p.textJson=w,p.textCanvas=document.createElement("canvas"),p.textCtx=p.textCanvas.getContext("2d");const Q=p.textCanvas,P=p.textCtx;Q.width=u,Q.height=g,P.translate(u*.5,g*.5),P.scale(...o),P.translate(...d),P.font=v;let E=t.text;document.fonts.check(`${t.fontStyle} ${t.fontWeight} 20px '${t.fontFamily}'`);const I=c*1.5*(1+t.lineSkip),x=c*(1+t.charSkip),O=t.rubySize,F=t.rubyDistance,Z=zr(t.direction,P,l[0]*.85,l[1]*.85,E,I,x,t.autoNewline),[H,N]=[Z.width,Z.height],se={x:-H*.5,y:-N*.5,width:H,height:N};P.globalCompositeOperation="source-over",P.fillStyle=t.fontColor,$t(t.direction,P,"fill",se,E,I,x,O,F,Z,t.autoNewline),0<f&&(P.globalCompositeOperation="destination-over",P.strokeStyle=t.outlineColor,P.lineWidth=f,P.font=v,P.lineJoin="round",$t(t.direction,P,"stroke",se,E,I,x,O,F,Z,t.autoNewline))}const D=p.textCanvas;try{const Q=Math.round(t.rotation*10)/10;A.save(),(Q===0||Q===90||Q===180||Q===270)&&(A.imageSmoothingEnabled=!1),A.scale(...Ei(o)),A.drawImage(D,0-u*.5,0-g*.5),A.restore()}catch(Q){throw console.log(u,g,D.width,D.height,l),Q}}function iA(A){const e=new Path2D;if(0<A.length){e.moveTo(...A[0]);for(let t=1;t<A.length;t++)e.lineTo(...A[t]);e.closePath()}return e}class $A extends ot{constructor(t){super();h(this,"frameTree",null);h(this,"rawBubbles",null);h(this,"thisFrameRenderData",null);this.supportsDpr=t}renderDepths(){return[0,1]}prerender(){const t=this.getPaperSize(),i=mt(this.frameTree,t,[0,0]);this.thisFrameRenderData=this.setUpRenderData(i)}render(t,i){const{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}=this.thisFrameRenderData;if(i===0){for(let{layout:o}of n)this.renderFrameBackground(t,o,null);s.sort((o,l)=>o.layout.element.z-l.layout.element.z);for(let{layout:o,inheritanceContext:l}of s)this.renderFrame(t,o,l,a)}i===1&&AA(t,this.getPaperSize(),r,!0,this.supportsDpr)}setUpRenderData(t){const i={borderColor:"black",borderWidth:1},{backgrounds:n,foregrounds:s}=this.setUpFrameTree(t,i),{embeddedBubbles:a,floatingBubbles:r}=this.setUpBubbles(t,this.rawBubbles);return{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}}setUpFrameTree(t,i){const n=[],s=[];if(t.element.borderColor!=null&&(i.borderColor=t.element.borderColor),t.element.borderWidth!=null&&(i.borderWidth=t.element.borderWidth),t.children){n.push({layout:t,inheritanceContext:i});for(let a=0;a<t.children.length;a++){const r=this.setUpFrameTree(t.children[a],i);n.push(...r.backgrounds),s.push(...r.foregrounds)}}else n.push({layout:t,inheritanceContext:i}),s.push({layout:t,inheritanceContext:i});return{backgrounds:n,foregrounds:s}}setUpBubbles(t,i){const n=this.getPaperSize();this.resolveLinkages(i);const s=new Map,a=[];for(let r of i)if(r.embedded){const o=RA(t,r.getPhysicalCenter(n),0);o&&0<o.element.visibility&&o.element.isLeaf()?(s.has(o)||s.set(o,[]),s.get(o).push(r)):a.push(r)}else a.push(r);return{embeddedBubbles:s,floatingBubbles:a}}resolveLinkages(t){var s,a,r,o,l,c,d,f,u,g,p,v;const i=this.getPaperSize(),n={};for(let b of t)b.renderInfo??(b.renderInfo={}),(s=b.renderInfo.unitedOuterPath)==null||s.remove(),b.renderInfo.unitedOuterPath=null,(a=b.renderInfo.unitedInnerPath)==null||a.remove(),b.renderInfo.unitedInnerPath=null,(r=b.renderInfo.unitedStrokePath)==null||r.remove(),b.renderInfo.unitedStrokePath=null,b.renderInfo.children=[],n[b.uuid]=b;for(let b of t)b.parent&&(n[b.parent]==null?b.parent=null:n[b.parent].renderInfo.children.push(b));for(let b of t){const w=b.optionContext,D=[b.n_p1[0]-b.n_p0[0],b.n_p1[1]-b.n_p0[1]],Q=b.renderInfo,P={paperSize:i,shape:b.shape,size:D,optionContext:w,rotation:b.rotation},E=JSON.stringify(P);if(Q.pathJson!=E){(o=Q.strokePath)==null||o.remove(),(l=Q.outerPath)==null||l.remove(),(c=Q.innerPath)==null||c.remove(),Q.strokePath=null,Q.outerPath=null,Q.innerPath=null;const I=b.getPhysicalSize(i);if(Q.pathJson=E,Q.strokePath=oo(b.shape,I,w,b.text),(d=Q.strokePath)==null||d.rotate(-b.rotation),Q.innerPathIsSameWithOuterPath=!1,Q.strokePath){const x=Math.min(Q.strokePath.bounds.width,Q.strokePath.bounds.height)*(w.shapeExpand??0);try{x==0?Q.outerPath=Q.strokePath.clone():Q.outerPath=Ht.PaperOffset.offset(Q.strokePath,x)}catch{console.error("PaperOffset failed, using strokePath as outerPath",q.decompile(b)),Q.outerPath=Q.strokePath.clone()}const O=Math.min(Q.outerPath.bounds.width,Q.outerPath.bounds.height)*(w.shapeOutline??0);try{O==0?(Q.innerPath=Q.outerPath.clone(),Q.innerPathIsSameWithOuterPath=!0):Q.innerPath=Ht.PaperOffset.offset(Q.outerPath,-O)}catch{console.error("PaperOffset failed, using outerPath as innerPath",q.decompile(b)),Q.innerPath=Q.outerPath.clone(),Q.innerPathIsSameWithOuterPath=!0}}}}for(let b of t){const w=b.renderInfo;if(b.parent==null&&w.strokePath){const D=b.getPhysicalCenter(i);w.unitedStrokePath=w.strokePath.clone(),w.unitedOuterPath=w.outerPath.clone(),w.unitedInnerPath=w.innerPath.clone(),w.unitedOuterPath.translate(D),w.unitedInnerPath.translate(D),w.unitedStrokePath.translate(D);for(let Q of w.children){const P=Q.getPhysicalCenter(i),E=Q.renderInfo;if(E.strokePath==null)continue;const I=E.strokePath.clone();I==null||I.translate(Q.getPhysicalCenter(i)),(f=w.unitedStrokePath)==null||f.remove(),w.unitedStrokePath=w.unitedStrokePath.unite(I),I.remove();const x=E.outerPath.clone();x.translate(P),(u=w.unitedOuterPath)==null||u.remove(),w.unitedOuterPath=w.unitedOuterPath.unite(x),x.remove();const O=E.innerPath.clone();O.translate(P),(g=w.unitedInnerPath)==null||g.remove(),w.unitedInnerPath=w.unitedInnerPath.unite(O),O.remove()}w.children.length===0&&w.innerPathIsSameWithOuterPath?((p=w.unitedInnerPath)==null||p.remove(),w.unitedInnerPath=w.unitedOuterPath.clone()):((v=w.unitedOuterPath)==null||v.remove(),w.unitedOuterPath=w.unitedOuterPath.subtract(w.unitedInnerPath)),w.unitedOuterPath.rotate(b.rotation,D),w.unitedOuterPath.translate(ht(D)),w.unitedInnerPath.rotate(b.rotation,D),w.unitedInnerPath.translate(ht(D)),w.unitedStrokePath.rotate(b.rotation,D),w.unitedStrokePath.translate(ht(D))}}}makeFramePath(t,i){const n=this.getPaperSize(),s=tA(t.corners,n,{top:!0,right:!0,bottom:!0,left:!0},i);return iA(s)}renderFrame(t,i,n,s){this.renderFrameBackground(t,i,n);const a=i.element;2<=a.visibility&&this.renderFrameBorder(t,i,n),1<=a.visibility&&this.renderFrameContent(t,i,n,s)}renderFrameBackground(t,i,n){if(i.element.visibility===0||!i.element.bgColor)return;const s=(n==null?void 0:n.borderWidth)??0,a=this.makeFramePath(i,-s*.5);t.save(),t.lineJoin="miter",t.fillStyle=i.element.bgColor,t.fill(a),t.restore()}renderFrameContent(t,i,n,s){if(0<i.element.filmStack.films.length||s.has(i)){const r=this.getPaperSize(),o=i.element,[l,c,d,f]=Rr(i.corners),u=-n.borderWidth*.5,g=(b,w)=>{const D=tA(i.corners,r,w.barriers,u);b.clip(iA(D))};jA(t,o.filmStack,r,[l+d*.5,c+f*.5],g);const p=this.makeFramePath(i,-n.borderWidth*.5),v=s.get(i);v&&(t.save(),t.clip(p),AA(t,this.getPaperSize(),v,!0,this.supportsDpr),t.restore())}}renderFrameBorder(t,i,n){const s=n.borderWidth;if(0<s){t.save(),t.strokeStyle=n.borderColor,t.lineWidth=s,t.lineJoin="miter";const a=this.makeFramePath(i,0);t.stroke(a),t.restore()}}setBubbles(t){this.rawBubbles=t}setFrameTree(t){this.frameTree=t}renderApart(){const t=this.getPaperSize();function i(){const d=bi(t[0],t[1]),f=d.getContext("2d");return{canvas:d,ctx:f}}const n=mt(this.frameTree,t,[0,0]),{foregrounds:s,embeddedBubbles:a,floatingBubbles:r}=this.setUpRenderData(n),o=[];s.sort((d,f)=>d.layout.element.z-f.layout.element.z);for(let{layout:d,inheritanceContext:f}of s){if(d.element.visibility<1)continue;const{canvas:u,ctx:g}=i();this.renderFrameBackground(g,d,f),this.renderFrameContent(g,d,f,a);const{canvas:p,ctx:v}=i();this.renderFrameBorder(v,d,f),o.push({border:p,content:u})}const l=[...[...a.values()].flat(),...r],c={};for(let d of l){if(d.renderInfo,d.parent!=null)continue;const{canvas:f,ctx:u}=i(),g=this.getPaperSize();KA(u,g,d),tt(u,g,d,!1,this.supportsDpr),c[d.uuid]=f}for(let d of l){if(d.parent==null)continue;const f=c[d.parent].getContext("2d");tt(f,this.getPaperSize(),d,!0,this.supportsDpr)}return{frames:o,bubbles:Object.values(c)}}resetCache(){var t,i,n,s,a,r;for(let o of this.rawBubbles){const l=o.renderInfo;l&&((t=l.strokePath)==null||t.remove(),(i=l.outerPath)==null||i.remove(),(n=l.innerPath)==null||n.remove(),(s=l.unitedStrokePath)==null||s.remove(),(a=l.unitedOuterPath)==null||a.remove(),(r=l.unitedInnerPath)==null||r.remove()),o.renderInfo=void 0}}}class Ro{constructor(){h(this,"subscribers",[])}subscribe(e){this.subscribers.push(e)}unsubscribe(e){this.subscribers=this.subscribers.filter(t=>t!==e)}setFocus(e){this.subscribers.forEach(t=>t(e))}}const xo=typeof process<"u"&&(process.env.NODE_ENV==="test"||process.env.VITEST);let vt;async function Co(){const A=new Te.Computron;await A.init(),vt=new Te.JFACompute(A),await vt.init()}xo||Co();class ei{constructor(){h(this,"ulid");h(this,"inputMedia");h(this,"outputMedia");this.ulid=Pe.ulid(),this.inputMedia=null,this.outputMedia=null}get tag(){return this.constructor.name}clone(){throw new Error("Not implemented")}cleanInput(){this.inputMedia=null}setOutputDirty(){this.outputMedia=null}async apply(e){throw new Error("Not implemented")}decompile(){throw new Error("Not implemented")}static compile(e){switch(e.tag){case"OutlineEffect":const t=e.properties;return new Mt(t.color,t.width,t.sharp);default:throw new Error("Unknown effect tag: "+e.tag)}}}class Mt extends ei{constructor(t,i,n){super();h(this,"rawDistanceField",null);this.color=t,this.width=i,this.sharp=n}clone(){return new Mt(this.color,this.width,this.sharp)}async apply(t){if(this.inputMedia!=t){const u=t.drawSource,g=Te.FloatField.createFromImageOrCanvas(u),p=Te.JFACompute.createJFASeedMap(g,.5,!1);this.rawDistanceField=await vt.compute(p),this.inputMedia=t}const i=t.drawSource,n=Math.max(t.naturalWidth,t.naturalHeight),s=this.width*n,a=mi(this.color),r={r:a.values[0]/255,g:a.values[1]/255,b:a.values[2]/255},o=1-this.sharp,l=u=>o<=u?1:u*(1/o),c=Te.JFACompute.generateDistanceField(this.rawDistanceField,r,s,l),d=document.createElement("canvas");d.width=i.width,d.height=i.height;const f=d.getContext("2d");return f.drawImage(i,0,0),f.globalCompositeOperation="destination-over",f.drawImage(c.toCanvas(),0,0),this.outputMedia=new Ae(d),this.outputMedia}decompile(){return{color:this.color,width:this.width,sharp:this.sharp}}}async function ti(A,e,t){const i=ae.compileNode(e);if(i.gallery=[],e.image||e.scribble)if(typeof e.image=="string"||typeof e.scribble=="string"){let s=function(a){const r=Math.min(a.width,a.height),o=Math.min(A[0],A[1]),l=r/o,c=(e.scale??[1,1])[0],d=l*c,f=e.translation??[0,0],u=[f[0]*l,f[1]*l],g=new _(new Ae(a));return g.n_scale=d,g.n_translation=u,g.rotation=e.rotation,g.reverse=[...e.reverse??[1,1]],g.prompt=e.prompt,g};if(e.image){const a=await t(e.image,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}if(e.scribble){const a=await t(e.scribble,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}}else{let s=function(a){const r=new _(new Ae(a));return r.n_scale=e.image.n_scale,r.n_translation=e.image.n_translation,r.rotation=e.image.rotation,r.reverse=[...e.image.reverse],r.prompt=e.prompt,r};if(e.image.image){const a=await t(e.image.image,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}if(e.image.scribble){const a=await t(e.image.scribble,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}}else if(e.films){const s=await Ai(e.films,t);i.filmStack.films.push(...s)}const n=e.column??e.row;if(n){i.direction=e.column?"v":"h",i.children=[];for(let s of n)i.children.push(await ti(A,s,t));i.calculateLengthAndBreadth()}for(const s of i.filmStack.films)s.media instanceof Ae&&i.gallery.push(s.media);return i}async function qo(A,e,t){const i=[];for(const n of e){const s=q.compile(A,n),a=n.image;if(a){const r=await t(a.image,"image");if(r instanceof HTMLCanvasElement){const o=Math.min(r.width,r.height),l=Math.min(A[0],A[1]);let c=a.n_scale;if(!c){const g=(a.scale??[1,1])[0];c=o/l*g}let d=a.n_translation;if(!d){const u=a.translation??[0,0],g=o/l;d=[u[0]*g,u[1]*g]}const f=new _(new Ae(r));f.n_scale=c,f.n_translation=d,s.filmStack.films.push(f),s.scaleLock=a.scaleLock}}else if(n.films){const r=await Ai(n.films,t);s.filmStack.films=r}i.push(s)}for(const n of i)for(const s of n.filmStack.films)s.media instanceof Ae&&n.gallery.push(s.media);return i}async function Ai(A,e){const t=[];for(const i of A){const n=await e(i.image,i.mediaType??"image");if(!n)continue;const s=[];if(i.effects)for(const o of i.effects){const l=ei.compile(o);s.push(l)}const a=i.mediaType==="video"?new gt(n):new Ae(n),r=new _(a);i.ulid&&(r.ulid=i.ulid),r.n_scale=i.n_scale,r.n_translation=i.n_translation,r.rotation=i.rotation,r.reverse=i.reverse,r.visible=i.visible,r.prompt=i.prompt,r.effects=s,r.barriers=i.barriers??{top:!0,right:!0,bottom:!0,left:!0},t.push(r)}return t}async function Uo(A,e){const t=[];for(const i of A.characters){const n=i.portrait?await e(i.portrait,"image"):null;t.push({...i,portrait:Lr(n)})}return{...A,characters:t,format:A.format??"standard"}}var L;(function(A){A.assertEqual=n=>{};function e(n){}A.assertIs=e;function t(n){throw new Error}A.assertNever=t,A.arrayToEnum=n=>{const s={};for(const a of n)s[a]=a;return s},A.getValidEnumValues=n=>{const s=A.objectKeys(n).filter(r=>typeof n[n[r]]!="number"),a={};for(const r of s)a[r]=n[r];return A.objectValues(a)},A.objectValues=n=>A.objectKeys(n).map(function(s){return n[s]}),A.objectKeys=typeof Object.keys=="function"?n=>Object.keys(n):n=>{const s=[];for(const a in n)Object.prototype.hasOwnProperty.call(n,a)&&s.push(a);return s},A.find=(n,s)=>{for(const a of n)if(s(a))return a},A.isInteger=typeof Number.isInteger=="function"?n=>Number.isInteger(n):n=>typeof n=="number"&&Number.isFinite(n)&&Math.floor(n)===n;function i(n,s=" | "){return n.map(a=>typeof a=="string"?`'${a}'`:a).join(s)}A.joinValues=i,A.jsonStringifyReplacer=(n,s)=>typeof s=="bigint"?s.toString():s})(L||(L={}));var nA;(function(A){A.mergeShapes=(e,t)=>({...e,...t})})(nA||(nA={}));const k=L.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),re=A=>{switch(typeof A){case"undefined":return k.undefined;case"string":return k.string;case"number":return Number.isNaN(A)?k.nan:k.number;case"boolean":return k.boolean;case"function":return k.function;case"bigint":return k.bigint;case"symbol":return k.symbol;case"object":return Array.isArray(A)?k.array:A===null?k.null:A.then&&typeof A.then=="function"&&A.catch&&typeof A.catch=="function"?k.promise:typeof Map<"u"&&A instanceof Map?k.map:typeof Set<"u"&&A instanceof Set?k.set:typeof Date<"u"&&A instanceof Date?k.date:k.object;default:return k.unknown}},m=L.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ie extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=i=>{this.issues=[...this.issues,i]},this.addIssues=(i=[])=>{this.issues=[...this.issues,...i]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(s){return s.message},i={_errors:[]},n=s=>{for(const a of s.issues)if(a.code==="invalid_union")a.unionErrors.map(n);else if(a.code==="invalid_return_type")n(a.returnTypeError);else if(a.code==="invalid_arguments")n(a.argumentsError);else if(a.path.length===0)i._errors.push(t(a));else{let r=i,o=0;for(;o<a.path.length;){const l=a.path[o];o===a.path.length-1?(r[l]=r[l]||{_errors:[]},r[l]._errors.push(t(a))):r[l]=r[l]||{_errors:[]},r=r[l],o++}}};return n(this),i}static assert(e){if(!(e instanceof ie))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,L.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},i=[];for(const n of this.issues)n.path.length>0?(t[n.path[0]]=t[n.path[0]]||[],t[n.path[0]].push(e(n))):i.push(e(n));return{formErrors:i,fieldErrors:t}}get formErrors(){return this.flatten()}}ie.create=A=>new ie(A);const yt=(A,e)=>{let t;switch(A.code){case m.invalid_type:A.received===k.undefined?t="Required":t=`Expected ${A.expected}, received ${A.received}`;break;case m.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(A.expected,L.jsonStringifyReplacer)}`;break;case m.unrecognized_keys:t=`Unrecognized key(s) in object: ${L.joinValues(A.keys,", ")}`;break;case m.invalid_union:t="Invalid input";break;case m.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${L.joinValues(A.options)}`;break;case m.invalid_enum_value:t=`Invalid enum value. Expected ${L.joinValues(A.options)}, received '${A.received}'`;break;case m.invalid_arguments:t="Invalid function arguments";break;case m.invalid_return_type:t="Invalid function return type";break;case m.invalid_date:t="Invalid date";break;case m.invalid_string:typeof A.validation=="object"?"includes"in A.validation?(t=`Invalid input: must include "${A.validation.includes}"`,typeof A.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${A.validation.position}`)):"startsWith"in A.validation?t=`Invalid input: must start with "${A.validation.startsWith}"`:"endsWith"in A.validation?t=`Invalid input: must end with "${A.validation.endsWith}"`:L.assertNever(A.validation):A.validation!=="regex"?t=`Invalid ${A.validation}`:t="Invalid";break;case m.too_small:A.type==="array"?t=`Array must contain ${A.exact?"exactly":A.inclusive?"at least":"more than"} ${A.minimum} element(s)`:A.type==="string"?t=`String must contain ${A.exact?"exactly":A.inclusive?"at least":"over"} ${A.minimum} character(s)`:A.type==="number"?t=`Number must be ${A.exact?"exactly equal to ":A.inclusive?"greater than or equal to ":"greater than "}${A.minimum}`:A.type==="date"?t=`Date must be ${A.exact?"exactly equal to ":A.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(A.minimum))}`:t="Invalid input";break;case m.too_big:A.type==="array"?t=`Array must contain ${A.exact?"exactly":A.inclusive?"at most":"less than"} ${A.maximum} element(s)`:A.type==="string"?t=`String must contain ${A.exact?"exactly":A.inclusive?"at most":"under"} ${A.maximum} character(s)`:A.type==="number"?t=`Number must be ${A.exact?"exactly":A.inclusive?"less than or equal to":"less than"} ${A.maximum}`:A.type==="bigint"?t=`BigInt must be ${A.exact?"exactly":A.inclusive?"less than or equal to":"less than"} ${A.maximum}`:A.type==="date"?t=`Date must be ${A.exact?"exactly":A.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(A.maximum))}`:t="Invalid input";break;case m.custom:t="Invalid input";break;case m.invalid_intersection_types:t="Intersection results could not be merged";break;case m.not_multiple_of:t=`Number must be a multiple of ${A.multipleOf}`;break;case m.not_finite:t="Number must be finite";break;default:t=e.defaultError,L.assertNever(A)}return{message:t}};let Mo=yt;function Lo(){return Mo}const To=A=>{const{data:e,path:t,errorMaps:i,issueData:n}=A,s=[...t,...n.path||[]],a={...n,path:s};if(n.message!==void 0)return{...n,path:s,message:n.message};let r="";const o=i.filter(l=>!!l).slice().reverse();for(const l of o)r=l(a,{data:e,defaultError:r}).message;return{...n,path:s,message:r}};function y(A,e){const t=Lo(),i=To({issueData:e,data:A.data,path:A.path,errorMaps:[A.common.contextualErrorMap,A.schemaErrorMap,t,t===yt?void 0:yt].filter(n=>!!n)});A.common.issues.push(i)}class W{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const i=[];for(const n of t){if(n.status==="aborted")return R;n.status==="dirty"&&e.dirty(),i.push(n.value)}return{status:e.value,value:i}}static async mergeObjectAsync(e,t){const i=[];for(const n of t){const s=await n.key,a=await n.value;i.push({key:s,value:a})}return W.mergeObjectSync(e,i)}static mergeObjectSync(e,t){const i={};for(const n of t){const{key:s,value:a}=n;if(s.status==="aborted"||a.status==="aborted")return R;s.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof a.value<"u"||n.alwaysSet)&&(i[s.value]=a.value)}return{status:e.value,value:i}}}const R=Object.freeze({status:"aborted"}),Ue=A=>({status:"dirty",value:A}),K=A=>({status:"valid",value:A}),sA=A=>A.status==="aborted",aA=A=>A.status==="dirty",ke=A=>A.status==="valid",At=A=>typeof Promise<"u"&&A instanceof Promise;var B;(function(A){A.errToObj=e=>typeof e=="string"?{message:e}:e||{},A.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(B||(B={}));var it=function(A,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?A!==e||!i:!e.has(A))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(A):i?i.value:e.get(A)},ii=function(A,e,t,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?A!==e||!n:!e.has(A))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(A,t):n?n.value=t:e.set(A,t),t},Me,Le;class de{constructor(e,t,i,n){this._cachedPath=[],this.parent=e,this.data=t,this._path=i,this._key=n}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const rA=(A,e)=>{if(ke(e))return{success:!0,data:e.value};if(!A.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new ie(A.common.issues);return this._error=t,this._error}}};function C(A){if(!A)return{};const{errorMap:e,invalid_type_error:t,required_error:i,description:n}=A;if(e&&(t||i))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:n}:{errorMap:(a,r)=>{const{message:o}=A;return a.code==="invalid_enum_value"?{message:o??r.defaultError}:typeof r.data>"u"?{message:o??i??r.defaultError}:a.code!=="invalid_type"?{message:r.defaultError}:{message:o??t??r.defaultError}},description:n}}class U{get description(){return this._def.description}_getType(e){return re(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:re(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new W,ctx:{common:e.parent.common,data:e.data,parsedType:re(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(At(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const i=this.safeParse(e,t);if(i.success)return i.data;throw i.error}safeParse(e,t){const i={common:{issues:[],async:(t==null?void 0:t.async)??!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)},n=this._parseSync({data:e,path:i.path,parent:i});return rA(i,n)}"~validate"(e){var i,n;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:t});return ke(s)?{value:s.value}:{issues:t.common.issues}}catch(s){(n=(i=s==null?void 0:s.message)==null?void 0:i.toLowerCase())!=null&&n.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(s=>ke(s)?{value:s.value}:{issues:t.common.issues})}async parseAsync(e,t){const i=await this.safeParseAsync(e,t);if(i.success)return i.data;throw i.error}async safeParseAsync(e,t){const i={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)},n=this._parse({data:e,path:i.path,parent:i}),s=await(At(n)?n:Promise.resolve(n));return rA(i,s)}refine(e,t){const i=n=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(n):t;return this._refinement((n,s)=>{const a=e(n),r=()=>s.addIssue({code:m.custom,...i(n)});return typeof Promise<"u"&&a instanceof Promise?a.then(o=>o?!0:(r(),!1)):a?!0:(r(),!1)})}refinement(e,t){return this._refinement((i,n)=>e(i)?!0:(n.addIssue(typeof t=="function"?t(i,n):t),!1))}_refinement(e){return new Ee({schema:this,typeName:S.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return le.create(this,this._def)}nullable(){return Se.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ee.create(this)}promise(){return rt.create(this,this._def)}or(e){return st.create([this,e],this._def)}and(e){return at.create(this,e,this._def)}transform(e){return new Ee({...C(this._def),schema:this,typeName:S.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new kt({...C(this._def),innerType:this,defaultValue:t,typeName:S.ZodDefault})}brand(){return new al({typeName:S.ZodBranded,type:this,...C(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Bt({...C(this._def),innerType:this,catchValue:t,typeName:S.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Lt.create(this,e)}readonly(){return Dt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Go=/^c[^\s-]{8,}$/i,Oo=/^[0-9a-z]+$/,Jo=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Vo=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Zo=/^[a-z0-9_-]{21}$/i,Ho=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Fo=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,No=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Wo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let ut;const zo=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Xo=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Yo=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,jo=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ko=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,_o=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ni="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",$o=new RegExp(`^${ni}$`);function si(A){let e="[0-5]\\d";A.precision?e=`${e}\\.\\d{${A.precision}}`:A.precision==null&&(e=`${e}(\\.\\d+)?`);const t=A.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function el(A){return new RegExp(`^${si(A)}$`)}function tl(A){let e=`${ni}T${si(A)}`;const t=[];return t.push(A.local?"Z?":"Z"),A.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Al(A,e){return!!((e==="v4"||!e)&&zo.test(A)||(e==="v6"||!e)&&Yo.test(A))}function il(A,e){if(!Ho.test(A))return!1;try{const[t]=A.split("."),i=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),n=JSON.parse(atob(i));return!(typeof n!="object"||n===null||"typ"in n&&(n==null?void 0:n.typ)!=="JWT"||!n.alg||e&&n.alg!==e)}catch{return!1}}function nl(A,e){return!!((e==="v4"||!e)&&Xo.test(A)||(e==="v6"||!e)&&jo.test(A))}class oe extends U{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==k.string){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_type,expected:k.string,received:s.parsedType}),R}const i=new W;let n;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),i.dirty());else if(s.kind==="max")e.data.length>s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),i.dirty());else if(s.kind==="length"){const a=e.data.length>s.value,r=e.data.length<s.value;(a||r)&&(n=this._getOrReturnCtx(e,n),a?y(n,{code:m.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&y(n,{code:m.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),i.dirty())}else if(s.kind==="email")No.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"email",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="emoji")ut||(ut=new RegExp(Wo,"u")),ut.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"emoji",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="uuid")Vo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"uuid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="nanoid")Zo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"nanoid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="cuid")Go.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"cuid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="cuid2")Oo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"cuid2",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="ulid")Jo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"ulid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),y(n,{validation:"url",code:m.invalid_string,message:s.message}),i.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"regex",code:m.invalid_string,message:s.message}),i.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),i.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:{startsWith:s.value},message:s.message}),i.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:{endsWith:s.value},message:s.message}),i.dirty()):s.kind==="datetime"?tl(s).test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:"datetime",message:s.message}),i.dirty()):s.kind==="date"?$o.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:"date",message:s.message}),i.dirty()):s.kind==="time"?el(s).test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:"time",message:s.message}),i.dirty()):s.kind==="duration"?Fo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"duration",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="ip"?Al(e.data,s.version)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"ip",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="jwt"?il(e.data,s.alg)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"jwt",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="cidr"?nl(e.data,s.version)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"cidr",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="base64"?Ko.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"base64",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="base64url"?_o.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"base64url",code:m.invalid_string,message:s.message}),i.dirty()):L.assertNever(s);return{status:i.value,value:e.data}}_regex(e,t,i){return this.refinement(n=>e.test(n),{validation:t,code:m.invalid_string,...B.errToObj(i)})}_addCheck(e){return new oe({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...B.errToObj(e)})}url(e){return this._addCheck({kind:"url",...B.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...B.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...B.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...B.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...B.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...B.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...B.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...B.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...B.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...B.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...B.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...B.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...B.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...B.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...B.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...B.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...B.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...B.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...B.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...B.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...B.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...B.errToObj(t)})}nonempty(e){return this.min(1,B.errToObj(e))}trim(){return new oe({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new oe({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new oe({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}oe.create=A=>new oe({checks:[],typeName:S.ZodString,coerce:(A==null?void 0:A.coerce)??!1,...C(A)});function sl(A,e){const t=(A.toString().split(".")[1]||"").length,i=(e.toString().split(".")[1]||"").length,n=t>i?t:i,s=Number.parseInt(A.toFixed(n).replace(".","")),a=Number.parseInt(e.toFixed(n).replace(".",""));return s%a/10**n}class Be extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==k.number){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_type,expected:k.number,received:s.parsedType}),R}let i;const n=new W;for(const s of this._def.checks)s.kind==="int"?L.isInteger(e.data)||(i=this._getOrReturnCtx(e,i),y(i,{code:m.invalid_type,expected:"integer",received:"float",message:s.message}),n.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),n.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),n.dirty()):s.kind==="multipleOf"?sl(e.data,s.value)!==0&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.not_multiple_of,multipleOf:s.value,message:s.message}),n.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(i=this._getOrReturnCtx(e,i),y(i,{code:m.not_finite,message:s.message}),n.dirty()):L.assertNever(s);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,B.toString(t))}gt(e,t){return this.setLimit("min",e,!1,B.toString(t))}lte(e,t){return this.setLimit("max",e,!0,B.toString(t))}lt(e,t){return this.setLimit("max",e,!1,B.toString(t))}setLimit(e,t,i,n){return new Be({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:B.toString(n)}]})}_addCheck(e){return new Be({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:B.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:B.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:B.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:B.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:B.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:B.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:B.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:B.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:B.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&L.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const i of this._def.checks){if(i.kind==="finite"||i.kind==="int"||i.kind==="multipleOf")return!0;i.kind==="min"?(t===null||i.value>t)&&(t=i.value):i.kind==="max"&&(e===null||i.value<e)&&(e=i.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Be.create=A=>new Be({checks:[],typeName:S.ZodNumber,coerce:(A==null?void 0:A.coerce)||!1,...C(A)});class Ve extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==k.bigint)return this._getInvalidInput(e);let i;const n=new W;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),n.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),n.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.not_multiple_of,multipleOf:s.value,message:s.message}),n.dirty()):L.assertNever(s);return{status:n.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return y(t,{code:m.invalid_type,expected:k.bigint,received:t.parsedType}),R}gte(e,t){return this.setLimit("min",e,!0,B.toString(t))}gt(e,t){return this.setLimit("min",e,!1,B.toString(t))}lte(e,t){return this.setLimit("max",e,!0,B.toString(t))}lt(e,t){return this.setLimit("max",e,!1,B.toString(t))}setLimit(e,t,i,n){return new Ve({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:B.toString(n)}]})}_addCheck(e){return new Ve({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:B.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:B.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:B.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:B.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:B.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Ve.create=A=>new Ve({checks:[],typeName:S.ZodBigInt,coerce:(A==null?void 0:A.coerce)??!1,...C(A)});class oA extends U{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==k.boolean){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.boolean,received:i.parsedType}),R}return K(e.data)}}oA.create=A=>new oA({typeName:S.ZodBoolean,coerce:(A==null?void 0:A.coerce)||!1,...C(A)});class nt extends U{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==k.date){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_type,expected:k.date,received:s.parsedType}),R}if(Number.isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_date}),R}const i=new W;let n;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),i.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),i.dirty()):L.assertNever(s);return{status:i.value,value:new Date(e.data.getTime())}}_addCheck(e){return new nt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:B.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:B.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}nt.create=A=>new nt({checks:[],coerce:(A==null?void 0:A.coerce)||!1,typeName:S.ZodDate,...C(A)});class lA extends U{_parse(e){if(this._getType(e)!==k.symbol){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.symbol,received:i.parsedType}),R}return K(e.data)}}lA.create=A=>new lA({typeName:S.ZodSymbol,...C(A)});class cA extends U{_parse(e){if(this._getType(e)!==k.undefined){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.undefined,received:i.parsedType}),R}return K(e.data)}}cA.create=A=>new cA({typeName:S.ZodUndefined,...C(A)});class dA extends U{_parse(e){if(this._getType(e)!==k.null){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.null,received:i.parsedType}),R}return K(e.data)}}dA.create=A=>new dA({typeName:S.ZodNull,...C(A)});class hA extends U{constructor(){super(...arguments),this._any=!0}_parse(e){return K(e.data)}}hA.create=A=>new hA({typeName:S.ZodAny,...C(A)});class uA extends U{constructor(){super(...arguments),this._unknown=!0}_parse(e){return K(e.data)}}uA.create=A=>new uA({typeName:S.ZodUnknown,...C(A)});class he extends U{_parse(e){const t=this._getOrReturnCtx(e);return y(t,{code:m.invalid_type,expected:k.never,received:t.parsedType}),R}}he.create=A=>new he({typeName:S.ZodNever,...C(A)});class fA extends U{_parse(e){if(this._getType(e)!==k.undefined){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.void,received:i.parsedType}),R}return K(e.data)}}fA.create=A=>new fA({typeName:S.ZodVoid,...C(A)});class ee extends U{_parse(e){const{ctx:t,status:i}=this._processInputParams(e),n=this._def;if(t.parsedType!==k.array)return y(t,{code:m.invalid_type,expected:k.array,received:t.parsedType}),R;if(n.exactLength!==null){const a=t.data.length>n.exactLength.value,r=t.data.length<n.exactLength.value;(a||r)&&(y(t,{code:a?m.too_big:m.too_small,minimum:r?n.exactLength.value:void 0,maximum:a?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),i.dirty())}if(n.minLength!==null&&t.data.length<n.minLength.value&&(y(t,{code:m.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),i.dirty()),n.maxLength!==null&&t.data.length>n.maxLength.value&&(y(t,{code:m.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),i.dirty()),t.common.async)return Promise.all([...t.data].map((a,r)=>n.type._parseAsync(new de(t,a,t.path,r)))).then(a=>W.mergeArray(i,a));const s=[...t.data].map((a,r)=>n.type._parseSync(new de(t,a,t.path,r)));return W.mergeArray(i,s)}get element(){return this._def.type}min(e,t){return new ee({...this._def,minLength:{value:e,message:B.toString(t)}})}max(e,t){return new ee({...this._def,maxLength:{value:e,message:B.toString(t)}})}length(e,t){return new ee({...this._def,exactLength:{value:e,message:B.toString(t)}})}nonempty(e){return this.min(1,e)}}ee.create=(A,e)=>new ee({type:A,minLength:null,maxLength:null,exactLength:null,typeName:S.ZodArray,...C(e)});function Qe(A){if(A instanceof T){const e={};for(const t in A.shape){const i=A.shape[t];e[t]=le.create(Qe(i))}return new T({...A._def,shape:()=>e})}else return A instanceof ee?new ee({...A._def,type:Qe(A.element)}):A instanceof le?le.create(Qe(A.unwrap())):A instanceof Se?Se.create(Qe(A.unwrap())):A instanceof be?be.create(A.items.map(e=>Qe(e))):A}class T extends U{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=L.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==k.object){const l=this._getOrReturnCtx(e);return y(l,{code:m.invalid_type,expected:k.object,received:l.parsedType}),R}const{status:i,ctx:n}=this._processInputParams(e),{shape:s,keys:a}=this._getCached(),r=[];if(!(this._def.catchall instanceof he&&this._def.unknownKeys==="strip"))for(const l in n.data)a.includes(l)||r.push(l);const o=[];for(const l of a){const c=s[l],d=n.data[l];o.push({key:{status:"valid",value:l},value:c._parse(new de(n,d,n.path,l)),alwaysSet:l in n.data})}if(this._def.catchall instanceof he){const l=this._def.unknownKeys;if(l==="passthrough")for(const c of r)o.push({key:{status:"valid",value:c},value:{status:"valid",value:n.data[c]}});else if(l==="strict")r.length>0&&(y(n,{code:m.unrecognized_keys,keys:r}),i.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const c of r){const d=n.data[c];o.push({key:{status:"valid",value:c},value:l._parse(new de(n,d,n.path,c)),alwaysSet:c in n.data})}}return n.common.async?Promise.resolve().then(async()=>{const l=[];for(const c of o){const d=await c.key,f=await c.value;l.push({key:d,value:f,alwaysSet:c.alwaysSet})}return l}).then(l=>W.mergeObjectSync(i,l)):W.mergeObjectSync(i,o)}get shape(){return this._def.shape()}strict(e){return B.errToObj,new T({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,i)=>{var s,a;const n=((a=(s=this._def).errorMap)==null?void 0:a.call(s,t,i).message)??i.defaultError;return t.code==="unrecognized_keys"?{message:B.errToObj(e).message??n}:{message:n}}}:{}})}strip(){return new T({...this._def,unknownKeys:"strip"})}passthrough(){return new T({...this._def,unknownKeys:"passthrough"})}extend(e){return new T({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new T({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:S.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new T({...this._def,catchall:e})}pick(e){const t={};for(const i of L.objectKeys(e))e[i]&&this.shape[i]&&(t[i]=this.shape[i]);return new T({...this._def,shape:()=>t})}omit(e){const t={};for(const i of L.objectKeys(this.shape))e[i]||(t[i]=this.shape[i]);return new T({...this._def,shape:()=>t})}deepPartial(){return Qe(this)}partial(e){const t={};for(const i of L.objectKeys(this.shape)){const n=this.shape[i];e&&!e[i]?t[i]=n:t[i]=n.optional()}return new T({...this._def,shape:()=>t})}required(e){const t={};for(const i of L.objectKeys(this.shape))if(e&&!e[i])t[i]=this.shape[i];else{let s=this.shape[i];for(;s instanceof le;)s=s._def.innerType;t[i]=s}return new T({...this._def,shape:()=>t})}keyof(){return ai(L.objectKeys(this.shape))}}T.create=(A,e)=>new T({shape:()=>A,unknownKeys:"strip",catchall:he.create(),typeName:S.ZodObject,...C(e)});T.strictCreate=(A,e)=>new T({shape:()=>A,unknownKeys:"strict",catchall:he.create(),typeName:S.ZodObject,...C(e)});T.lazycreate=(A,e)=>new T({shape:A,unknownKeys:"strip",catchall:he.create(),typeName:S.ZodObject,...C(e)});class st extends U{_parse(e){const{ctx:t}=this._processInputParams(e),i=this._def.options;function n(s){for(const r of s)if(r.result.status==="valid")return r.result;for(const r of s)if(r.result.status==="dirty")return t.common.issues.push(...r.ctx.common.issues),r.result;const a=s.map(r=>new ie(r.ctx.common.issues));return y(t,{code:m.invalid_union,unionErrors:a}),R}if(t.common.async)return Promise.all(i.map(async s=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await s._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}})).then(n);{let s;const a=[];for(const o of i){const l={...t,common:{...t.common,issues:[]},parent:null},c=o._parseSync({data:t.data,path:t.path,parent:l});if(c.status==="valid")return c;c.status==="dirty"&&!s&&(s={result:c,ctx:l}),l.common.issues.length&&a.push(l.common.issues)}if(s)return t.common.issues.push(...s.ctx.common.issues),s.result;const r=a.map(o=>new ie(o));return y(t,{code:m.invalid_union,unionErrors:r}),R}}get options(){return this._def.options}}st.create=(A,e)=>new st({options:A,typeName:S.ZodUnion,...C(e)});function Pt(A,e){const t=re(A),i=re(e);if(A===e)return{valid:!0,data:A};if(t===k.object&&i===k.object){const n=L.objectKeys(e),s=L.objectKeys(A).filter(r=>n.indexOf(r)!==-1),a={...A,...e};for(const r of s){const o=Pt(A[r],e[r]);if(!o.valid)return{valid:!1};a[r]=o.data}return{valid:!0,data:a}}else if(t===k.array&&i===k.array){if(A.length!==e.length)return{valid:!1};const n=[];for(let s=0;s<A.length;s++){const a=A[s],r=e[s],o=Pt(a,r);if(!o.valid)return{valid:!1};n.push(o.data)}return{valid:!0,data:n}}else return t===k.date&&i===k.date&&+A==+e?{valid:!0,data:A}:{valid:!1}}class at extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e),n=(s,a)=>{if(sA(s)||sA(a))return R;const r=Pt(s.value,a.value);return r.valid?((aA(s)||aA(a))&&t.dirty(),{status:t.value,value:r.data}):(y(i,{code:m.invalid_intersection_types}),R)};return i.common.async?Promise.all([this._def.left._parseAsync({data:i.data,path:i.path,parent:i}),this._def.right._parseAsync({data:i.data,path:i.path,parent:i})]).then(([s,a])=>n(s,a)):n(this._def.left._parseSync({data:i.data,path:i.path,parent:i}),this._def.right._parseSync({data:i.data,path:i.path,parent:i}))}}at.create=(A,e,t)=>new at({left:A,right:e,typeName:S.ZodIntersection,...C(t)});class be extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==k.array)return y(i,{code:m.invalid_type,expected:k.array,received:i.parsedType}),R;if(i.data.length<this._def.items.length)return y(i,{code:m.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),R;!this._def.rest&&i.data.length>this._def.items.length&&(y(i,{code:m.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const s=[...i.data].map((a,r)=>{const o=this._def.items[r]||this._def.rest;return o?o._parse(new de(i,a,i.path,r)):null}).filter(a=>!!a);return i.common.async?Promise.all(s).then(a=>W.mergeArray(t,a)):W.mergeArray(t,s)}get items(){return this._def.items}rest(e){return new be({...this._def,rest:e})}}be.create=(A,e)=>{if(!Array.isArray(A))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new be({items:A,typeName:S.ZodTuple,rest:null,...C(e)})};class pA extends U{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==k.map)return y(i,{code:m.invalid_type,expected:k.map,received:i.parsedType}),R;const n=this._def.keyType,s=this._def.valueType,a=[...i.data.entries()].map(([r,o],l)=>({key:n._parse(new de(i,r,i.path,[l,"key"])),value:s._parse(new de(i,o,i.path,[l,"value"]))}));if(i.common.async){const r=new Map;return Promise.resolve().then(async()=>{for(const o of a){const l=await o.key,c=await o.value;if(l.status==="aborted"||c.status==="aborted")return R;(l.status==="dirty"||c.status==="dirty")&&t.dirty(),r.set(l.value,c.value)}return{status:t.value,value:r}})}else{const r=new Map;for(const o of a){const l=o.key,c=o.value;if(l.status==="aborted"||c.status==="aborted")return R;(l.status==="dirty"||c.status==="dirty")&&t.dirty(),r.set(l.value,c.value)}return{status:t.value,value:r}}}}pA.create=(A,e,t)=>new pA({valueType:e,keyType:A,typeName:S.ZodMap,...C(t)});class Ze extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==k.set)return y(i,{code:m.invalid_type,expected:k.set,received:i.parsedType}),R;const n=this._def;n.minSize!==null&&i.data.size<n.minSize.value&&(y(i,{code:m.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),t.dirty()),n.maxSize!==null&&i.data.size>n.maxSize.value&&(y(i,{code:m.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),t.dirty());const s=this._def.valueType;function a(o){const l=new Set;for(const c of o){if(c.status==="aborted")return R;c.status==="dirty"&&t.dirty(),l.add(c.value)}return{status:t.value,value:l}}const r=[...i.data.values()].map((o,l)=>s._parse(new de(i,o,i.path,l)));return i.common.async?Promise.all(r).then(o=>a(o)):a(r)}min(e,t){return new Ze({...this._def,minSize:{value:e,message:B.toString(t)}})}max(e,t){return new Ze({...this._def,maxSize:{value:e,message:B.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Ze.create=(A,e)=>new Ze({valueType:A,minSize:null,maxSize:null,typeName:S.ZodSet,...C(e)});class gA extends U{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}gA.create=(A,e)=>new gA({getter:A,typeName:S.ZodLazy,...C(e)});class mA extends U{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return y(t,{received:t.data,code:m.invalid_literal,expected:this._def.value}),R}return{status:"valid",value:e.data}}get value(){return this._def.value}}mA.create=(A,e)=>new mA({value:A,typeName:S.ZodLiteral,...C(e)});function ai(A,e){return new De({values:A,typeName:S.ZodEnum,...C(e)})}class De extends U{constructor(){super(...arguments),Me.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),i=this._def.values;return y(t,{expected:L.joinValues(i),received:t.parsedType,code:m.invalid_type}),R}if(it(this,Me,"f")||ii(this,Me,new Set(this._def.values),"f"),!it(this,Me,"f").has(e.data)){const t=this._getOrReturnCtx(e),i=this._def.values;return y(t,{received:t.data,code:m.invalid_enum_value,options:i}),R}return K(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return De.create(e,{...this._def,...t})}exclude(e,t=this._def){return De.create(this.options.filter(i=>!e.includes(i)),{...this._def,...t})}}Me=new WeakMap;De.create=ai;class bA extends U{constructor(){super(...arguments),Le.set(this,void 0)}_parse(e){const t=L.getValidEnumValues(this._def.values),i=this._getOrReturnCtx(e);if(i.parsedType!==k.string&&i.parsedType!==k.number){const n=L.objectValues(t);return y(i,{expected:L.joinValues(n),received:i.parsedType,code:m.invalid_type}),R}if(it(this,Le,"f")||ii(this,Le,new Set(L.getValidEnumValues(this._def.values)),"f"),!it(this,Le,"f").has(e.data)){const n=L.objectValues(t);return y(i,{received:i.data,code:m.invalid_enum_value,options:n}),R}return K(e.data)}get enum(){return this._def.values}}Le=new WeakMap;bA.create=(A,e)=>new bA({values:A,typeName:S.ZodNativeEnum,...C(e)});class rt extends U{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==k.promise&&t.common.async===!1)return y(t,{code:m.invalid_type,expected:k.promise,received:t.parsedType}),R;const i=t.parsedType===k.promise?t.data:Promise.resolve(t.data);return K(i.then(n=>this._def.type.parseAsync(n,{path:t.path,errorMap:t.common.contextualErrorMap})))}}rt.create=(A,e)=>new rt({type:A,typeName:S.ZodPromise,...C(e)});class Ee extends U{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===S.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:i}=this._processInputParams(e),n=this._def.effect||null,s={addIssue:a=>{y(i,a),a.fatal?t.abort():t.dirty()},get path(){return i.path}};if(s.addIssue=s.addIssue.bind(s),n.type==="preprocess"){const a=n.transform(i.data,s);if(i.common.async)return Promise.resolve(a).then(async r=>{if(t.value==="aborted")return R;const o=await this._def.schema._parseAsync({data:r,path:i.path,parent:i});return o.status==="aborted"?R:o.status==="dirty"||t.value==="dirty"?Ue(o.value):o});{if(t.value==="aborted")return R;const r=this._def.schema._parseSync({data:a,path:i.path,parent:i});return r.status==="aborted"?R:r.status==="dirty"||t.value==="dirty"?Ue(r.value):r}}if(n.type==="refinement"){const a=r=>{const o=n.refinement(r,s);if(i.common.async)return Promise.resolve(o);if(o instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return r};if(i.common.async===!1){const r=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});return r.status==="aborted"?R:(r.status==="dirty"&&t.dirty(),a(r.value),{status:t.value,value:r.value})}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(r=>r.status==="aborted"?R:(r.status==="dirty"&&t.dirty(),a(r.value).then(()=>({status:t.value,value:r.value}))))}if(n.type==="transform")if(i.common.async===!1){const a=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});if(!ke(a))return a;const r=n.transform(a.value,s);if(r instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:r}}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(a=>ke(a)?Promise.resolve(n.transform(a.value,s)).then(r=>({status:t.value,value:r})):a);L.assertNever(n)}}Ee.create=(A,e,t)=>new Ee({schema:A,typeName:S.ZodEffects,effect:e,...C(t)});Ee.createWithPreprocess=(A,e,t)=>new Ee({schema:e,effect:{type:"preprocess",transform:A},typeName:S.ZodEffects,...C(t)});class le extends U{_parse(e){return this._getType(e)===k.undefined?K(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}le.create=(A,e)=>new le({innerType:A,typeName:S.ZodOptional,...C(e)});class Se extends U{_parse(e){return this._getType(e)===k.null?K(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Se.create=(A,e)=>new Se({innerType:A,typeName:S.ZodNullable,...C(e)});class kt extends U{_parse(e){const{ctx:t}=this._processInputParams(e);let i=t.data;return t.parsedType===k.undefined&&(i=this._def.defaultValue()),this._def.innerType._parse({data:i,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}kt.create=(A,e)=>new kt({innerType:A,typeName:S.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...C(e)});class Bt extends U{_parse(e){const{ctx:t}=this._processInputParams(e),i={...t,common:{...t.common,issues:[]}},n=this._def.innerType._parse({data:i.data,path:i.path,parent:{...i}});return At(n)?n.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ie(i.common.issues)},input:i.data})})):{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new ie(i.common.issues)},input:i.data})}}removeCatch(){return this._def.innerType}}Bt.create=(A,e)=>new Bt({innerType:A,typeName:S.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...C(e)});class wA extends U{_parse(e){if(this._getType(e)!==k.nan){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.nan,received:i.parsedType}),R}return{status:"valid",value:e.data}}}wA.create=A=>new wA({typeName:S.ZodNaN,...C(A)});class al extends U{_parse(e){const{ctx:t}=this._processInputParams(e),i=t.data;return this._def.type._parse({data:i,path:t.path,parent:t})}unwrap(){return this._def.type}}class Lt extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:i.data,path:i.path,parent:i});return s.status==="aborted"?R:s.status==="dirty"?(t.dirty(),Ue(s.value)):this._def.out._parseAsync({data:s.value,path:i.path,parent:i})})();{const n=this._def.in._parseSync({data:i.data,path:i.path,parent:i});return n.status==="aborted"?R:n.status==="dirty"?(t.dirty(),{status:"dirty",value:n.value}):this._def.out._parseSync({data:n.value,path:i.path,parent:i})}}static create(e,t){return new Lt({in:e,out:t,typeName:S.ZodPipeline})}}class Dt extends U{_parse(e){const t=this._def.innerType._parse(e),i=n=>(ke(n)&&(n.value=Object.freeze(n.value)),n);return At(t)?t.then(n=>i(n)):i(t)}unwrap(){return this._def.innerType}}Dt.create=(A,e)=>new Dt({innerType:A,typeName:S.ZodReadonly,...C(e)});T.lazycreate;var S;(function(A){A.ZodString="ZodString",A.ZodNumber="ZodNumber",A.ZodNaN="ZodNaN",A.ZodBigInt="ZodBigInt",A.ZodBoolean="ZodBoolean",A.ZodDate="ZodDate",A.ZodSymbol="ZodSymbol",A.ZodUndefined="ZodUndefined",A.ZodNull="ZodNull",A.ZodAny="ZodAny",A.ZodUnknown="ZodUnknown",A.ZodNever="ZodNever",A.ZodVoid="ZodVoid",A.ZodArray="ZodArray",A.ZodObject="ZodObject",A.ZodUnion="ZodUnion",A.ZodDiscriminatedUnion="ZodDiscriminatedUnion",A.ZodIntersection="ZodIntersection",A.ZodTuple="ZodTuple",A.ZodRecord="ZodRecord",A.ZodMap="ZodMap",A.ZodSet="ZodSet",A.ZodFunction="ZodFunction",A.ZodLazy="ZodLazy",A.ZodLiteral="ZodLiteral",A.ZodEnum="ZodEnum",A.ZodEffects="ZodEffects",A.ZodNativeEnum="ZodNativeEnum",A.ZodOptional="ZodOptional",A.ZodNullable="ZodNullable",A.ZodDefault="ZodDefault",A.ZodCatch="ZodCatch",A.ZodPromise="ZodPromise",A.ZodBranded="ZodBranded",A.ZodPipeline="ZodPipeline",A.ZodReadonly="ZodReadonly"})(S||(S={}));const J=oe.create,ct=Be.create;he.create;const ue=ee.create,te=T.create;T.strictCreate;st.create;at.create;be.create;const Tt=De.create;rt.create;le.create;Se.create;const rl=te({id:J().describe("対応する入力要素のid"),ratio:ct().describe("兄弟間でのratio(weightに比例する)")}).describe("横方向要素、1~2要素 すべてのコマの重要度が低い場合は3要素も許される"),ol=te({columns:ue(rl),ratio:ct().describe("兄弟間でのratio(weightに比例する)")}).describe("縦方向要素(段)、1~3要素"),ll=te({rows:ue(ol)}).describe("ページ"),cl=Tt(["4koma","standard"]).describe("基本フォーマット。作風から適切な方を選べ"),dl=te({name:J().describe("キャラクター名"),appearance:J().describe("キャラクターの容姿。脇役のappearanceは簡潔にすること"),themeColor:J().describe("キャラクターのテーマカラー")}).describe("キャラクター一覧。キャラクタードキュメントにない脇役も列挙しろ"),hl=te({owner:J(),speech:J().describe("セリフは10文字前後までとしろ。また、適切に改行コード(\\n)を入れ、1行5文字程度に収めろ"),color:J().describe("セリフの色。話者のテーマカラー"),shape:Tt(["rounded","square","ellipse","polygon","shout","soft","none"]).describe("セリフの形。基本はsoft。キャラクタの感情にあわせろ。使ってよいのはsoft, polygon, shout, noneのいずれか。")}).describe("キャラクターのセリフ"),ul=te({composition:J().describe("そのコマの視覚情報。画像生成AIに渡されるプロンプト。セリフや音声情報を含めるな。キャラクターはいなくてもよい。キャラクターのリアクションはオーバーにし、コマごとに大きく変化させろ。"),camera:J().describe("そのコマのカメラ。例: from side, from back, Dutch angle shot, dramatic angle, from side, from back, Dutch angle shot, dramatic angle, top-down view, aerial shot, birds-eye-view shot, top angle view, from above, wide angle, eye-level shot, front view, straight-on, from below, etc."),bubbles:ue(hl).describe("そのコマのセリフ。セリフがない場合は空配列にしろ"),weight:ct().describe("そのコマの重要度。0~1の範囲で指定しろ。0が最も不要で、1が最も重要")}),fl=te({panels:ue(ul),layout:ll.describe("コマの配置").nullable().default(null)}),pl=te({format:cl,actors:ue(dl),pages:ue(fl)}),ri=te({name:J(),personality:J(),appearance:J(),themeColor:J().describe("テーマカラー。#ffffffff形式"),ulid:J()});ue(ri);te({theme:J(),characters:ue(ri),plot:J(),scenario:J(),storyboard:pl.nullable(),critique:J(),pageNumber:ct().nullable(),format:Tt(["4koma","standard"])});const gl={paperSize:[840,1188],paperColor:"#FFFFFF",frameColor:"#000000",frameWidth:2,templateName:"standard"};function ml(){return{theme:"",characters:[],plot:"",scenario:"",critique:"",storyboard:null,pageNumber:null,format:"standard"}}async function bl(A,e){const t=new Uint8Array(await A.arrayBuffer()),i=gi.decode(t),n={};if(i.images){e(0);for(const o in i.images){const l=new Blob([i.images[o]],{type:"image/png"}),c=URL.createObjectURL(l),d=new Image;d.src=c,await d.decode(),URL.revokeObjectURL(c);const f=ft(d);f.envelopeFileId=o,n[o]={type:"image",data:f},e(Object.keys(n).length/Object.keys(i.images).length)}}if(i.medias){e(0);for(const o in i.medias){const l=i.medias[o],c=new Blob([l.data],{type:l.type==="image"?`image/${l.format??"png"}`:"video/mp4"}),d=URL.createObjectURL(c);if(l.type==="image"){const f=new Image;f.src=d,await f.decode(),URL.revokeObjectURL(d);const u=ft(f);u.envelopeFileId=o,n[o]={type:"image",data:u}}else{const f=document.createElement("video");f.src=d,await vA(f),n[o]={type:"video",data:f}}e(Object.keys(n).length/Object.keys(i.medias).length)}}const s=i.notebook?await Uo(i.notebook,async o=>n[o].data):ml(),a={revision:{id:"not visited",revision:1,prefix:"envelope-"},pages:[],history:{entries:[],cursor:0},direction:i.direction,wrapMode:i.wrapMode,chatLogs:[],notebook:s,attributes:{publishUrl:null,showVideoPlayButton:!0,showVideoDottedBorder:!0},newPageProperty:i.newPageProperty??{...gl}},r=async o=>n[o].data;for(const o of i.pages){const l=await ti(o.paperSize,o.frameTree,r),c=await qo(o.paperSize,o.bubbles,r),d={id:o.id??Pe.ulid(),frameTree:l,bubbles:c,paperSize:o.paperSize,paperColor:o.paperColor,frameColor:o.frameColor,frameWidth:o.frameWidth,source:null};a.pages.push(d)}return a}class oi{constructor(e,t,i,n){this.arrayLayer=e,this.layeredCanvas=t,this.focusKeeper=i,this.marks=n}cleanup(){this.layeredCanvas.cleanup()}focusToPage(e,t=1){const i=this.layeredCanvas.viewport,[n,s]=i.getCanvasSize(),a=this.arrayLayer.array.papers[e],[r,o]=a.paper.size,l=Math.min(Math.max(1,n)/r,Math.max(1,s)/o)*t,c=a.center;i.scale=l,i.translate=[-c[0]*l,-c[1]*l],i.dirty=!0,this.layeredCanvas.redraw()}getScale(){return this.layeredCanvas.viewport.scale}resetFontCache(){var e,t;for(const i of this.arrayLayer.array.papers)(t=(e=i.paper)==null?void 0:e.findLayer($A))==null||t.resetCache()}}function wl(A,e,t=0,i=-1){console.log("Building renderer...");const n=new Ji(A,()=>{}),s=new Ro,a=new Vi(n,!0),r=new EA(a.viewport,()=>{},()=>{},s);a.rootPaper.addLayer(r);let o=[];const l=i<0?e.pages.length:t+i;for(let v=t;v<l;v++){const b=e.pages[v];for(const w of b.bubbles)w.pageNumber=v;o.push(vl(e,b,s))}const c=Pl(e.direction),{fold:d,gapX:f,gapY:u}=yl(e.wrapMode),g=[],p=new xr(o,g,d,f,u,c,()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{});return a.rootPaper.addLayer(p),a.mode="viewer",new oi(p,a,s,g)}function Ql(A){A.cleanup()}function vl(A,e,t){const i=new BA(e.paperSize,!1),n=new $A(!0);n.setFrameTree(e.frameTree),n.setBubbles(e.bubbles),i.addLayer(n);const s=new TA(e.frameTree,e.bubbles,a=>{console.log(a)},t,A.attributes.showVideoPlayButton??!0,A.attributes.showVideoDottedBorder??!0);return i.addLayer(s),e.frameTree.bgColor=e.paperColor,e.frameTree.borderColor=e.frameColor,e.frameTree.borderWidth=e.frameWidth,i}function yl(A){switch(A){case"none":return{fold:0,gapX:100,gapY:0};case"two-pages":return{fold:2,gapX:100,gapY:200};case"one-page":return{fold:1,gapX:0,gapY:0}}}function Pl(A){switch(A){case"left-to-right":return 1;case"right-to-left":return-1}}function kl(A){const e=new Set;for(let t of A.pages)for(let i of t.bubbles)e.add(JSON.stringify({family:i.fontFamily,weight:i.fontWeight}));return[...e].map(t=>JSON.parse(t))}const li={源暎アンチック:"GenEiAntiqueNv5-M",源暎エムゴ:"GenEiMGothic2-Black",源暎ぽっぷる:"GenEiPOPle-Bk",源暎ラテゴ:"GenEiLateMinN_v2",源暎ラテミン:"GenEiLateMinN_v2",源暎きわみゴ:"GenEiKiwamiGo",ふい字:"HuiFont29",まきばフォント:"MakibaFont13"};function ci(A){return li[A]!==void 0}function Bl(A){return!ci(A)}const QA=new Set;async function di(A,e=["400"]){try{const t=`${A}-${e.join("-")}`;if(QA.has(t))return;const i=A.replace(/\s+/g,"+"),n=e.join(";"),s=`https://fonts.googleapis.com/css2?family=${i}:wght@${n}&display=swap`,r=await(await fetch(s,{headers:{"User-Agent":navigator.userAgent}})).text(),o=Array.from(r.matchAll(/src: url\((.+?)\) format\('woff2'\)/g));if(!o.length)throw new Error("No font URLs found in CSS");const l=o.map(c=>{const d=c[1],u=r.substring(0,c.index).split("}").slice(-1)[0].match(/font-weight: (\d+)/),g=u?u[1]:"400";return new FontFace(A,`url(${d})`,{weight:g,style:"normal"}).load().then(v=>(document.fonts.add(v),v))});await Promise.all(l),await document.fonts.ready,QA.add(t)}catch(t){throw console.error(`Failed to load font "${A}":`,t),t}}async function Dl(A,e=["400"]){try{await di(A,e),await document.fonts.ready;const t=e.map(i=>hi(A,i));await Promise.all(t),console.log(`Font "${A}" is fully loaded and ready for Canvas use`)}catch(t){throw console.error(`Failed to load font "${A}" for Canvas:`,t),t}}async function hi(A,e="400",t=20,i=50){const n="あいうえおABCDE12345",s="24px";function a(){const o=document.createElement("canvas").getContext("2d");o.font=`${e} ${s} "${A}"`;const l=o.measureText(n).width;o.font=`${e} ${s} serif`;const c=o.measureText(n).width;return l!==c}for(let r=0;r<t;r++){if(a())return console.log(`Font "${A}" ${e} is ready for Canvas`),!0;await new Promise(o=>setTimeout(o,i))}throw new Error(`Timeout waiting for font "${A}" ${e} to be ready for Canvas`)}exports.Renderer=oi;exports.buildRenderer=wl;exports.checkCanvasFontAvailable=hi;exports.destroyRenderer=Ql;exports.initPaperJs=$r;exports.isGoogleFont=Bl;exports.isLocalFont=ci;exports.listFonts=kl;exports.loadGoogleFont=di;exports.loadGoogleFontForCanvas=Dl;exports.localFonts=li;exports.readEnvelope=bl;
13
+ `),o=[];for(const l of r){const c=Zr(l),d=Fr(c),f=qA(u=>{const g=a(u);return{size:g,wrap:e<g}},e,d,0,u=>u&&u.chars&&u.chars.length==1&&wt.has(u.chars[0]),u=>u&&u.chars&&u.chars.length==1&&Qt.has(u.chars[0]));for(const u of f)o.push({size:u.size,text:u.buffer})}return{height:o.reduce((l,c)=>Math.max(l,c.size),0),width:i*o.length,verticalLines:o.map(l=>l.text)}}function LA(A,e){return A?/[、。」』)】〕”]/.test(A)?/[「『(【〔“]/.test(e)||/[、。]/.test(e)?-.5:-.4:/[「『(【〔“]/.test(e)?-.4:0:/[「『(【〔“]/.test(e)?-.3:0}function $t(A,e,t,i,n,s,a,r,o,l,c){A==="v"?Nr(e,t,i,n,s,a,r,o,l,c):Wr(e,t,i,n,s,a,l,c)}function Wr(A,e,t,i,n,s,a,r){a||(a=It(A,t.width,i,n,s,r));for(let[o,l]of a.horizontalLines.entries())e==="fill"?A.fillText(l.text,t.x,t.y+n*o+n*.8):e==="stroke"&&A.strokeText(l.text,t.x,t.y+n*o+n*.8)}function zr(A,e,t,i,n,s,a,r){return A==="v"?St(e,i*.85,n,s,a,r):It(e,t*.85,n,s,a,r)}function It(A,e,t,i,n,s){s||(e=1/0);const a=Jr(r=>{const o=A.measureText(r.join(""));return{size:o.width,wrap:e<o.width}},e,t);return{width:a.reduce((r,o)=>Math.max(r,o.size),0),height:i*a.length,horizontalLines:a}}const Ye=48,M=10;class q{constructor(){h(this,"n_p0");h(this,"n_p1");h(this,"n_offset");h(this,"rotation");h(this,"text");h(this,"shape");h(this,"embedded");h(this,"fontStyle");h(this,"fontWeight");h(this,"n_fontSize");h(this,"charSkip");h(this,"lineSkip");h(this,"fontFamily");h(this,"direction");h(this,"fontColor");h(this,"fillColor");h(this,"strokeColor");h(this,"n_strokeWidth");h(this,"outlineColor");h(this,"n_outlineWidth");h(this,"autoNewline");h(this,"uuid");h(this,"parent");h(this,"creationContext");h(this,"filmStack");h(this,"scaleLock");h(this,"rubySize");h(this,"rubyDistance");h(this,"displayName");h(this,"optionContext");h(this,"pageNumber");h(this,"fontRenderVersion");h(this,"appearanceDelay");h(this,"hidesText");h(this,"prompt","");h(this,"gallery",[]);h(this,"renderInfo");this.reset(),this.n_p0=[0,0],this.n_p1=[.1,.1],this.text="empty",this.uuid=Pe.ulid(),this.parent=null,this.creationContext=this.getStackTrace(),this.filmStack=new $e,this.optionContext={},this.fontRenderVersion=0,this.gallery=[],this.displayName=""}reset(){const e=.0011904761904761906;this.n_offset=[0,0],this.rotation=0,this.shape="soft",this.embedded=!1,this.fontStyle="normal",this.fontWeight="400",this.n_fontSize=32*e,this.charSkip=0,this.lineSkip=0,this.fontFamily="源暎アンチック",this.direction="v",this.fontColor="#000000FF",this.fillColor="#ffffffE6",this.strokeColor="#000000FF",this.n_strokeWidth=3*e,this.n_outlineWidth=0,this.outlineColor="#000000FF",this.autoNewline=!1,this.appearanceDelay=0,this.hidesText=!1,this.rubySize=.4,this.rubyDistance=.45,this.displayName=""}getStackTrace(){return Error().stack}clone(e){const t=new q;return t.n_p0=[...this.n_p0],t.n_p1=[...this.n_p1],t.n_offset=[...this.n_offset],t.rotation=this.rotation,t.text=this.text,t.shape=this.shape,t.embedded=this.embedded,t.fontStyle=this.fontStyle,t.fontWeight=this.fontWeight,t.n_fontSize=this.n_fontSize,t.charSkip=this.charSkip,t.lineSkip=this.lineSkip,t.fontFamily=this.fontFamily,t.direction=this.direction,t.fontColor=this.fontColor,t.fillColor=this.fillColor,t.strokeColor=this.strokeColor,t.n_strokeWidth=this.n_strokeWidth,t.outlineColor=this.outlineColor,t.n_outlineWidth=this.n_outlineWidth,t.autoNewline=this.autoNewline,t.appearanceDelay=this.appearanceDelay,t.rubySize=this.rubySize,t.rubyDistance=this.rubyDistance,t.displayName=this.displayName,e&&(t.uuid=this.uuid,t.parent=this.parent),t.filmStack=new $e,t.filmStack.films=this.filmStack.films.map(i=>i.clone()),t.optionContext={...this.optionContext},t}copyStyleFrom(e){this.shape=e.shape,this.embedded=e.embedded,this.fontStyle=e.fontStyle,this.fontWeight=e.fontWeight,this.n_fontSize=e.n_fontSize,this.charSkip=e.charSkip,this.lineSkip=e.lineSkip,this.fontFamily=e.fontFamily,this.direction=e.direction,this.fontColor=e.fontColor,this.fillColor=e.fillColor,this.strokeColor=e.strokeColor,this.n_strokeWidth=e.n_strokeWidth,this.outlineColor=e.outlineColor,this.n_outlineWidth=e.n_outlineWidth,this.autoNewline=e.autoNewline,this.optionContext={...e.optionContext},this.rubySize=e.rubySize,this.rubyDistance=e.rubyDistance,this.displayName=e.displayName}static getUnit(e){return 1/Math.min(e[0],e[1])}static compile(e,t){const i=.0011904761904761906,n=q.getUnit(e),s=(r,o,l)=>r??(o!=null?o*n:l*i),a=new q;return a.n_p0=t.p0??t.n_p0,a.n_p1=t.p1??t.n_p1,a.n_offset=[0,0],t.n_offset?a.n_offset=t.n_offset:t.offset&&(a.n_offset=this.normalizedPosition(e,t.offset)),a.rotation=t.rotation??0,a.text=t.text??"",a.shape=t.shape??"square",a.shape=="harsh-curve"&&(a.shape="shout"),a.embedded=t.embedded??!1,a.fontStyle=t.fontStyle??"normal",a.fontWeight=t.fontWeight??"400",a.n_fontSize=26*n,t.n_fontSize?a.n_fontSize=t.n_fontSize:t.fontSize&&(a.n_fontSize=t.fontSize),a.charSkip=t.charSkip??0,a.lineSkip=t.lineSkip??0,a.fontFamily=t.fontFamily??"Noto Sans JP",a.direction=t.direction??"v",a.fontColor=t.fontColor??"#000000FF",a.fillColor=t.fillColor??"#ffffffE6",a.strokeColor=t.strokeColor??"#000000FF",a.n_strokeWidth=s(t.n_strokeWidth,t.strokeWidth,1),a.outlineColor=t.outlineColor??"#000000FF",a.n_outlineWidth=s(t.n_outlineWidth,t.outlineWidth,0),a.autoNewline=t.autoNewline??!0,a.uuid=t.uuid??Pe.ulid(),a.parent=t.parent,a.rubySize=t.rubySize??.4,a.rubyDistance=t.rubyDistance??.45,a.displayName=t.displayName??"ふきだし",a.optionContext=q.getInitialOptions(a),Object.assign(a.optionContext,t.optionContext??{}),a.forceEnoughSize(e),a}static decompile(e){const t=.0011904761904761906,i=(n,s)=>Math.abs(n-s)<1e-4;return{n_p0:e.n_p0,n_p1:e.n_p1,n_offset:e.n_offset[0]==0&&e.n_offset[1]==0?void 0:e.n_offset,rotation:e.rotation==0?void 0:e.rotation,text:e.text==""?void 0:e.text,shape:e.shape=="square"?void 0:e.shape,embedded:e.embedded==!1?void 0:e.embedded,fontStyle:e.fontStyle=="normal"?void 0:e.fontStyle,fontWeight:e.fontWeight=="400"?void 0:e.fontWeight,n_fontSize:i(e.n_fontSize,26*t)?void 0:e.n_fontSize,charSkip:e.charSkip==0?void 0:e.charSkip,lineSkip:e.lineSkip==0?void 0:e.lineSkip,fontFamily:e.fontFamily=="Noto Sans JP"?void 0:e.fontFamily,direction:e.direction=="v"?void 0:e.direction,fontColor:e.fontColor=="#000000FF"?void 0:e.fontColor,fillColor:e.fillColor=="#ffffffE6"?void 0:e.fillColor,strokeColor:e.strokeColor=="#000000FF"?void 0:e.strokeColor,n_strokeWidth:i(e.n_strokeWidth,1*t)?void 0:e.n_strokeWidth,outlineColor:e.outlineColor=="#000000FF"?void 0:e.outlineColor,n_outlineWidth:i(e.n_outlineWidth,0*t)?void 0:e.n_outlineWidth,autoNewline:e.autoNewline?void 0:e.autoNewline,uuid:e.uuid,parent:e.parent,rubySize:e.rubySize==.4?void 0:e.rubySize,rubyDistance:e.rubyDistance==.45?void 0:e.rubyDistance,displayName:e.displayName,optionContext:JSON.stringify(e.optionContext)==JSON.stringify(q.getInitialOptions(e))?void 0:e.optionContext}}static getPhysicalPoint(e,t){return[t[0]*e[0],t[1]*e[1]]}getPhysicalRect(e){const[t,i]=q.getPhysicalPoint(e,this.n_p0),[n,s]=q.getPhysicalPoint(e,this.n_p1);return[t,i,n-t,s-i]}getPhysicalBox(e){return[q.getPhysicalPoint(e,this.n_p0),q.getPhysicalPoint(e,this.n_p1)]}getPhysicalCenter(e){const t=this.getPhysicalRect(e);return[t[0]+t[2]/2,t[1]+t[3]/2]}getPhysicalSize(e){const t=this.getPhysicalRect(e);return[t[2],t[3]]}getPhysicalOffset(e){return q.denormalizedPosition(e,this.n_offset)}getPhysicalFontSize(e){return this.n_fontSize/q.getUnit(e)}getPhysicalStrokeWidth(e){return this.n_strokeWidth/q.getUnit(e)}getPhysicalOutlineWidth(e){return this.n_outlineWidth/q.getUnit(e)}getPhysicalRegularizedRect(e){const[t,i]=this.regularized(),[n,s]=q.getPhysicalPoint(e,t),[a,r]=q.getPhysicalPoint(e,i);return[n,s,a-n,r-s]}getPhysicalRegularizedBox(e){const[t,i]=this.regularized();return[q.getPhysicalPoint(e,t),q.getPhysicalPoint(e,i)]}hasEnoughSize(e){const t=this.getPhysicalRect(e);return Ye<=t[2]&&Ye<=t[3]}static enoughSize(e){return[Math.max(e[0],Ye+1),Math.max(e[1],Ye+1)]}setPhysicalCenter(e,t){const[i,n]=t,[s,a]=this.getPhysicalSize(e);this.n_p0=q.normalizedPosition(e,[i-s/2,n-a/2]),this.n_p1=q.normalizedPosition(e,[i+s/2,n+a/2])}setPhysicalSize(e,t){const i=[(this.n_p0[0]+this.n_p1[0])/2,(this.n_p0[1]+this.n_p1[1])/2];this.n_p0=[i[0]-t[0]/e[0]/2,i[1]-t[1]/e[1]/2],this.n_p1=[i[0]+t[0]/e[0]/2,i[1]+t[1]/e[1]/2]}setPhysicalRect(e,t){this.n_p0=[t[0]/e[0],t[1]/e[1]],this.n_p1=[(t[0]+t[2])/e[0],(t[1]+t[3])/e[1]]}setPhysicalFontSize(e,t){this.n_fontSize=t*q.getUnit(e)}setPhysicalStrokeWidth(e,t){this.n_strokeWidth=t*q.getUnit(e)}setPhysicalOutlineWidth(e,t){this.n_outlineWidth=t*q.getUnit(e)}setPhysicalOffset(e,t){this.n_offset=q.normalizedPosition(e,t)}forceEnoughSize(e){const t=this.getPhysicalRect(e),i=q.enoughSize([t[2],t[3]]);this.setPhysicalSize(e,i)}contains(e,t){const[i,n]=t,[s,a]=q.getPhysicalPoint(e,this.n_p0),[r,o]=q.getPhysicalPoint(e,this.n_p1);return s<=i&&i<=r&&a<=n&&n<=o}getHandleAt(e,t){for(let i of Ur){const n=this.getHandleRect(e,i);if(Mi(n,t))return i}return null}getHandleRect(e,t){const[i,n,s,a]=this.getPhysicalRect(e);switch(t){case"topLeft":return[i-M,n-M,M*2,M*2];case"topRight":return[i+s-M,n-M,M*2,M*2];case"bottomLeft":return[i-M,n+a-M,M*2,M*2];case"bottomRight":return[i+s-M,n+a-M,M*2,M*2];case"top":return[i-M,n-M,s+M*2,M*2];case"bottom":return[i-M,n+a-M,s+M*2,M*2];case"left":return[i-M,n-M,M*2,a+M*2];case"right":return[i+s-M,n-M,M*2,a+M*2]}}regularized(){const e=[Math.min(this.n_p0[0],this.n_p1[0]),Math.min(this.n_p0[1],this.n_p1[1])],t=[Math.max(this.n_p0[0],this.n_p1[0]),Math.max(this.n_p0[1],this.n_p1[1])];return[e,t]}regularize(){[this.n_p0,this.n_p1]=this.regularized()}canLink(){return console.log(this.optionSet),!!this.optionSet.link}linkTo(e){this.parent=e.uuid}linkedTo(e){return this.parent===e.uuid||e.parent===this.uuid}static normalizedPosition(e,t){return[t[0]/e[0],t[1]/e[1]]}static denormalizedPosition(e,t){return[t[0]*e[0],t[1]*e[1]]}get optionSet(){return eA[this.shape]}initOptions(){this.optionContext=q.getInitialOptions(this)}static getInitialOptions(e,t=!1){const i=eA[e.shape],n={};for(const s of Object.keys(i))i[s].init&&(n[s]=i[s].init(e),t&&i[s].sampleInit&&(n[s]=i[s].sampleInit(e)));return n}calculateFitSize(e){const t=this.getPhysicalFontSize(e),i=t*1.5*(1+this.lineSkip),n=t*(1+this.charSkip),a=document.createElement("canvas").getContext("2d");let r=[0,0];if(this.direction=="v"){const o=St(a,1/0,this.text,i,n,!1);r=[Math.floor(o.width*1.2),Math.floor(o.height*1.4)]}else{const o=`${this.fontStyle} ${this.fontWeight} ${t}px '${this.fontFamily}'`;a.font=o;const l=It(a,1/0,this.text,i,n,!1);r=[Math.floor(l.width*1.4),Math.floor(l.height*1.2)]}return console.log(r),q.enoughSize(r)}}const eA={rounded:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.7},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},square:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},ellipse:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>.1}},concentration:{lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:A=>200},lineLength:{label:"線の長さ",type:"number",min:1.05,max:1.5,step:.01,init:A=>1.3}},thought:{lineCount:{label:"線の本数",type:"number",min:100,max:600,step:1,init:A=>400},lineLength:{label:"線の長さ",type:"number",min:.05,max:.5,step:.01,init:A=>.3},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.2,step:.01,init:A=>.14},jitter:{label:"ジッター",type:"number",min:0,max:.5,step:.001,init:A=>.08},waveFrequency:{label:"ウェーブ周期",type:"number",min:8,max:64,step:1,init:A=>8},waveAmplitude:{label:"ウェーブ振幅",type:"number",min:0,max:.1,step:.001,init:A=>0}},polygon:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:A=>7},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.4},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},strokes:{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:A=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:A=>1.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0}},"double-strokes":{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:A=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:A=>1.25},interval:{label:"間隔",type:"number",min:.01,max:.2,step:.01,init:A=>.04},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0}},harsh:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:A=>.07},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:A=>15},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},shout:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>6,sampleInit:A=>6},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3,sampleInit:A=>3},bumpSharp:{label:"でっぱりの鋭さ",type:"number",min:.01,max:.5,step:.01,init:A=>.16,sampleInit:A=>.2},bumpCount:{label:"でっぱりの数",type:"number",min:4,max:20,step:1,init:A=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.5,sampleInit:A=>.2},depthJitter:{label:"鋭さジッター",type:"number",min:0,max:1.5,step:.01,init:A=>.5,sampleInit:A=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},soft:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:A=>.14},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:A=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.4},extract:{label:"食い込み",type:"boolean",init:A=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:A=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:A=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},heart:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},diamond:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},arrow:{link:{hint:"結合",icon:"unite"},shaftWidth:{label:"軸の太さ",type:"number",min:0,max:1,step:.01,init:A=>.5},headLength:{label:"矢じりの長さ",type:"number",min:0,max:1,step:.01,init:A=>.5},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0}},"motion-lines":{focalPoint:{hint:"内円の中心",icon:"circle",init:A=>[0,0]},focalRange:{hint:"内円の範囲",icon:"radius",init:A=>[0,40]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:A=>200},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.1,step:.01,init:A=>.05},angleJitter:{label:"角度ジッター",type:"number",min:0,max:.2,step:.01,init:A=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:1,step:.01,init:A=>.5}},"speed-lines":{tailTip:{hint:"流線の先端",icon:"tail",init:A=>[40,0]},tailMid:{hint:"流線の途中",icon:"curve",init:A=>[.5,0]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>0},lineCount:{label:"線の本数",type:"number",min:10,max:200,step:1,init:A=>70},lineWidth:{label:"線の太さ",type:"number",min:.01,max:1,step:.01,init:A=>.2},laneJitter:{label:"間隔ジッター",type:"number",min:0,max:.2,step:.01,init:A=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:.5,step:.01,init:A=>.3}},"ellipse-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:A=>1}},"soft-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:A=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:A=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:A=>.15},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:A=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:A=>.4},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:A=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:A=>1}},"rounded-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:A=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:A=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:A=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:A=>.7},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:A=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:A=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:A=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:A=>1}},none:{}};class TA extends ot{constructor(t,i,n,s,a,r){super();h(this,"selected",null);h(this,"playIcon");h(this,"dashPhase",0);h(this,"lastNow",null);h(this,"dashSpeed",10);h(this,"showPlayButton");h(this,"showDottedBorder");this.frameTree=t,this.bubbles=i,this.onFocus=n,this.focusKeeper=s,this.playIcon=new $(["viewerLayer/play.webp"],[32,32],[1,1],"再生",()=>!0,()=>this.paper.matrix),s.subscribe(this.changeFocus.bind(this)),this.showPlayButton=a,this.showDottedBorder=r}renderDepths(){return[0,1]}calculateRootLayout(){return mt(this.frameTree,this.getPaperSize(),[0,0])}render(t,i){if(i===0){const n=this.calculateRootLayout();this.interactable&&this.renderLayoutRecursive(t,n),this.renderFramePlayButtons(t,n)}i===1&&this.renderBubblePlayButtons(t)}renderLayoutRecursive(t,i){var n;t.strokeStyle="rgba(0, 200, 200, 0.2)",t.lineWidth=2,t.beginPath(),t.moveTo(...i.corners.topLeft),t.lineTo(...i.corners.topRight),t.lineTo(...i.corners.bottomRight),t.lineTo(...i.corners.bottomLeft),t.closePath(),t.stroke(),(n=i.children)==null||n.forEach(s=>{this.renderLayoutRecursive(t,s)})}renderFramePlayButtons(t,i){var n;this.hasVideo(i==null?void 0:i.element.filmStack)&&(this.showDottedBorder&&pt(t,"rgba(128, 128, 128, 1)",i.corners,2,5,!1,this.dashPhase,[20,20]),this.showPlayButton&&(this.playIcon.position=ge(i.corners.bottomRight,[8,8]),this.playIcon.pivot=[1,1],this.playIcon.shadowColor="rgba(0, 0, 0, 0.5)",this.playIcon.render(t))),(n=i.children)==null||n.forEach(s=>{this.renderFramePlayButtons(t,s)})}renderBubblePlayButtons(t){for(const i of this.bubbles)if(this.hasVideo(i.filmStack)){const n=this.getPaperSize(),[s,a,r,o]=i.getPhysicalRect(n),l=[s+r/2,a];this.showDottedBorder&&pt(t,"rgba(128, 128, 128, 1)",SA([s,a,r,o]),2,5,!1,this.dashPhase,[20,20]),this.showPlayButton&&(this.playIcon.position=l,this.playIcon.pivot=[.5,0],this.playIcon.shadowColor="rgba(0, 0, 0, 0.5)",this.playIcon.render(t))}}handleClick(t){this.selectTarget(t)}acceptDepths(){return[0,1]}accepts(t,i,n){if(Ge.Space)return null;if(n===1){for(const s of this.bubbles){const a=this.getPaperSize();if(s.contains(a,t))return{action:"click",layout:s}}return null}else{const s=this.calculateRootLayout(),a=RA(s,t,0);return a?{action:"click",layout:a}:(this.selectTarget(null),null)}}async*pointer(t,i){i.action==="click"&&this.handleClick(i.layout)}async keyDown(t,i){return i.code==="Escape"?(this.selectTarget(null),!0):!1}changeFocus(t){t!==this&&(this.onFocus(null),this.redraw())}selectTarget(t){t!==this.selected&&(this.stopVideo(this.selected),this.selected=t,this.startVideo(t),this.onFocus(t),this.focusKeeper.setFocus(t?this:null),this.redraw())}stopVideo(t){var i;if(t){const n=this.getFilmStack(t);for(const s of n.films)(i=s.media.player)==null||i.pause()}}startVideo(t){if(!t)return;const i=this.getFilmStack(t);for(const n of i.films)n.media.player&&n.media.player.play()}tick(t){if(this.hasAnyVideo()&&this.showDottedBorder){this.lastNow==null&&(this.lastNow=t);const i=t-this.lastNow;this.lastNow=t,this.dashPhase=(this.dashPhase+this.dashSpeed*i/1e3)%1e4,this.redraw()}if(this.selected){const i=this.getFilmStack(this.selected);for(const n of i.films){const s=n.media.drawSource;if(s instanceof HTMLVideoElement&&!s.paused&&!s.ended){this.redraw();break}}}}getFilmStack(t){return t instanceof q?t.filmStack:t.element.filmStack}hasVideo(t){for(const i of t.films)if(i.media.player)return!0;return!1}hasAnyVideoInLayout(t){if(this.hasVideo(t.element.filmStack))return!0;if(t.children){for(const i of t.children)if(this.hasAnyVideoInLayout(i))return!0}return!1}hasAnyVideo(){const t=this.calculateRootLayout();if(this.hasAnyVideoInLayout(t))return!0;for(const i of this.bubbles)if(this.hasVideo(i.filmStack))return!0;return!1}get interactable(){return this.mode==null}}DA(TA);var qe=[];function GA(A){if(qe=[],A.length==3)return A.push(A[0]),A;var e=Xr(A);return et(e,A),et([e[1],e[0]],A),qe.push(qe[0]),qe}function Xr(A){var e,t,i;for(t=A[0],i=A[0],e=1;e<A.length;e++)A[e][0]<t[0]&&(t=A[e]),A[e][0]>i[0]&&(i=A[e]);return[t,i]}function Yr(A,e){var t=e[1][1]-e[0][1],i=e[0][0]-e[1][0];return i*(A[1]-e[0][1])+t*(A[0]-e[0][0])}function jr(A,e){var t,i=[],n,s,a=0,r=0;for(t=0;t<e.length;t++){if(n=e[t],a=Yr(n,A),a>0)i.push(n);else continue;a>r&&(s=n,r=a)}return{points:i,max:s}}function et(A,e){var t=jr(A,e);if(!t.max)return qe.push(A[0]);et([A[0],t.max],t.points),et([t.max,A[1]],t.points)}function Je(A,e,t){const[i,n]=A,[s,a]=e,[r,o]=t,[l,c]=[r*s+o*a,r*a-o*s];return[l+i,c+n]}function Ie(A,e,t=.5){const i=[];for(let n=0;n<e;n++){const s=(A()-.5)/e*t,a=(n/e+s)*2*Math.PI;i.push(a)}return i}function Re(A,e,t=3){return e.map(i=>Ri(A[0]/2,A[1]/2,t,i))}function Kr(A,e,t,i,n=2){const s=[];for(let a=0;a<e.length;a++)if(a%n===0){const[r,o]=e[a],l=Math.hypot(r,o),c=1+t+(A()-.5)*i,d=l*c,[f,u]=[r*d/l,o*d/l];s.push([f,u])}else s.push(e[a]);return s}function _r(A,e,t){const i=Ci(A,e),n=ge(e,A),s=me(n),a=Oe(s,t);return pe(i,a)}function lt(A,e,t){const i=Math.min(A[0],A[1])*t,n=[];for(let s=0;s<e.length;s++){const a=(s+1)%e.length,r=e[s],o=e[a];n.push(r),n.push(_r(r,o,i))}return n}function j(A){return`rgba(${A[0]}, ${A[1]}, ${A[2]}, ${A[3]})`}function $r(){V.setup([1,1]),V.view.autoUpdate=!1}function Rt(A,e,t,i,n,s){switch(t=s.randomSeed??0,n){case"rounded":mo(A,e,t,i,s);break;case"square":po(A,e,t,i,s);break;case"ellipse":fo(A,e,t,i,s);break;case"concentration":eo(A,e,t,i,s);break;case"thought":to(A,e,t,i,s);break;case"polygon":go(A,e,t,i,s);break;case"strokes":io(A,e,t,i,s);break;case"double-strokes":no(A,e,t,i,s);break;case"harsh":bo(A,e,t,i,s);break;case"shout":wo(A,e,t,i,s);break;case"soft":Qo(A,e,t,i,s);break;case"heart":vo(A,e,t,i,s);break;case"diamond":yo(A,e,t,i,s);break;case"arrow":Po(A,e,t,i,s);break;case"motion-lines":so(A,e,t,i,s);break;case"speed-lines":ao(A,e,t,i,s);break;case"ellipse-mind":ko(A,e,t,i,s);break;case"soft-mind":Bo(A,e,t,i,s);break;case"rounded-mind":Do(A,e,t,i,s);break;case"none":break;default:throw new Error(`Unknown bubble : ${n}`)}}function eo(A,e,t,i,n){const[s,a]=i;if(e==="fill"){A.save(),A.translate(0,0),A.scale(s/2,a/2),A.lineWidth=1/Math.min(s,a);const r=n.lineCount;A.save();const o=A.createRadialGradient(0,0,1,0,0,n.lineLength),l=A.strokeStyle,c=ce(l),d=ce(l);c[3]=0,o.addColorStop(0,j(d)),o.addColorStop(1,j(c)),A.strokeStyle=o,A.beginPath();for(let f=0;f<r;f++){const u=f*2*Math.PI/r,[g,p]=[Math.cos(u),Math.sin(u)],[v,b]=[g*n.lineLength,p*n.lineLength];A.moveTo(g,p),A.lineTo(v,b)}A.closePath(),A.stroke(),A.restore(),A.restore()}else e==="clip"&&(A.beginPath(),A.ellipse(0,0,s*.5,a*.5,0,0,2*Math.PI),A.clip())}function to(A,e,t,i,n){const s=ne(t),[a,r]=i;if(e==="fill"){A.save(),A.translate(0,0),A.scale(a/2,r/2),A.beginPath(),A.ellipse(0,0,1,1,0,0,2*Math.PI),A.fill(),A.lineWidth=1;const o=n.lineCount;A.save(),A.createRadialGradient(0,0,1,0,0,n.lineLength);const l=A.strokeStyle;A.fillStyle=l;const d=n.lineLength*.5,f=1-d,u=1+d;for(let g=0;g<o;g++){const p=g*2*Math.PI/o,[v,b]=[Math.cos(p),Math.sin(p)],[w,D]=ve([v,b],f),[Q,P]=ve([v,b],u),E=s()*n.jitter,I=s()*n.jitter,x=1+Math.sin(p*n.waveFrequency)*n.waveAmplitude,O=ve([w,D],(1-E)*x),F=ve([Q,P],(1+I)*x);Ao(A,O,F,n.lineWidth)}A.restore(),A.restore()}else e==="clip"&&(A.beginPath(),A.ellipse(0,0,a*.5,r*.5,0,0,2*Math.PI),A.clip())}function Ao(A,e,t,i){const[n,s]=[t[0]-e[0],t[1]-e[1]],[a,r]=[n/2,s/2],[o,l]=[-r,a],[c,d]=[a+o*i/2,r+l*i/2],[f,u]=[a-o*i/2,r-l*i/2];A.beginPath(),A.moveTo(e[0],e[1]),A.lineTo(e[0]+c,e[1]+d),A.lineTo(t[0],t[1]),A.lineTo(e[0]+f,e[1]+u),A.closePath(),A.fill()}function io(A,e,t,i,n){OA(A,e,t,i,n,!1)}function no(A,e,t,i,n){OA(A,e,t,i,n,!0)}function OA(A,e,t,i,n,s){const a=ne(t),r=Re(i,Ie(a,n.vertexCount,n.angleJitter),n.superEllipse),o=GA(r);if(e=="fill"||e=="clip"){const l=new V.Path;for(let c=0;c<o.length;c++){const d=o[c];c===0?l.moveTo(d):l.lineTo(d)}l.closed=!0,G(A,e,l,n),l.remove()}else{const l=A.strokeStyle;for(let c=0;c<o.length;c++){A.beginPath();const d=o[c],f=o[(c+1)%o.length],[u,g]=ro(d,f,n.overRun),p=A.createLinearGradient(...u,...g),v=ce(l),b=ce(l);if(v[3]=0,p.addColorStop(0,j(v)),p.addColorStop(.15,j(b)),p.addColorStop(.85,j(b)),p.addColorStop(1,j(v)),A.strokeStyle=p,A.moveTo(u[0],u[1]),A.lineTo(g[0],g[1]),s){const w=Math.min(i[0],i[1])*n.interval,[D,Q]=[f[0]-d[0],f[1]-d[1]],[P,E]=[-Q,D],[I,x]=[P/Math.sqrt(P*P+E*E),E/Math.sqrt(P*P+E*E)],[O,F]=[u[0]+I*w,u[1]+x*w],[Z,H]=[g[0]+I*w,g[1]+x*w];A.moveTo(O,F),A.lineTo(Z,H)}A.stroke()}}}function so(A,e,t,i,n){const[s,a,r,o]=xe(i);if(e==="fill"){const l=ne(t);A.save(),A.beginPath(),A.rect(s,a,r,o),A.clip(),A.lineWidth=1;const c=n.lineCount,d=(n==null?void 0:n.focalPoint)??[0,0],f=(n==null?void 0:n.focalRange)??[0,Math.hypot(r/2,o/2)*.25],u=Math.hypot(f[0],f[1]),[g,p,v]=[0,0,Math.hypot(r/2,o/2)],[b,w,D]=[d[0],d[1],u],Q=A.createRadialGradient(b,w,D,g,p,v),P=ce(A.strokeStyle),E=ce(A.strokeStyle);P[3]=0,Q.addColorStop(0,j(P)),Q.addColorStop(.2,j(E)),Q.addColorStop(1,j(E)),A.fillStyle=Q;for(let I=0;I<c;I++){const x=I*2*Math.PI/c+(l()-.5)*n.angleJitter,[O,F]=[Math.cos(x),Math.sin(x)],Z=D*(1+l()*n.startJitter),H=[b,w],N=[g+O*v,p+F*v],se=[N[0]-H[0],N[1]-H[1]],Gt=Math.hypot(...se),Ot=[H[0]+se[0]*Z/Gt,H[1]+se[1]*Z/Gt],Jt=n.lineWidth*.1,[Vt,Zt]=[me(se,Jt),me(se,-Jt)];A.beginPath(),A.moveTo(Ot[0],Ot[1]),A.lineTo(N[0]+Vt[0],N[1]+Vt[1]),A.lineTo(N[0]+Zt[0],N[1]+Zt[1]),A.closePath(),A.fill()}A.restore()}}function ao(A,e,t,i,n){const[s,a,r,o]=xe(i);if(e==="fill"){const l=ne(t);A.save();try{let c=function([w,D]){const Q=[u*.5,0],[P,E]=xi(Q,g),I=.5-Si([w,D],[P,E])*.5;return Wt(I)};A.beginPath(),A.rect(s,a,r,o),A.clip();const d=(n==null?void 0:n.tailTip)??[0,0],f=Je([0,0],d,(n==null?void 0:n.tailMid)??[0,0]),u=Math.hypot(r,o);if(!Number.isFinite(u)||u<=1e-6)return;const g=Math.atan2(d[1],d[0]);A.rotate(g),A.lineWidth=1;const p=n.lineCount,v=Wt(.5-Bi(d)/u),b=c(f);for(let w=0;w<p;w++){const D=(w+.5)/p*u-u/2+l()*u*n.laneJitter,Q=-u*.5+(l()-.5)*r*n.startJitter,P=o*n.lineWidth*.01*(l()+.5);try{const E=A.createLinearGradient(Q+u,D,Q,D),I=ce(A.strokeStyle),x=ce(A.strokeStyle);I[3]=0,E.addColorStop(v,j(I)),E.addColorStop(b,j(x)),E.addColorStop(1,j(x)),A.fillStyle=E}catch(E){throw console.error("drawSpeedLinesBubble: gradient addColorStop failed",{seed:t,i:w,length:u,angle:g,tailTip:d,tailMid:f,psf0:v,psf1:b,y:D,lx:Q,lw:P,lineCount:p,strokeStyle:A.strokeStyle,opts:n,error:E}),E}A.beginPath(),A.moveTo(Q,D-P),A.lineTo(Q+u,D),A.lineTo(Q,D+P),A.closePath(),A.fill()}}catch(c){throw console.error("drawSpeedLinesBubble: unexpected error",{seed:t,size:i,rect:[s,a,r,o],tailTip:(n==null?void 0:n.tailTip)??[0,0],tailMid:(n==null?void 0:n.tailMid)??[0,0],lineCount:n==null?void 0:n.lineCount,opts:n,error:c}),c}finally{A.restore()}}}function ro(A,e,t){const[i,n]=[e[0]-A[0],e[1]-A[1]],s=[e[0]-i*t,e[1]-n*t],a=[A[0]+i*t,A[1]+n*t];return[s,a]}function oo(A,e,t,i){i=t.randomSeed??0,performance.now();try{switch(A){case"square":return JA(e,t,i);case"ellipse":return xt(e,t,i);case"polygon":return YA(e,t,i);case"rounded":return Ct(e,t,i);case"harsh":return VA(e,t,i);case"shout":return ZA(e,t,i);case"soft":return qt(e,t,i);case"heart":return HA(e,t,i);case"diamond":return FA(e,t,i);case"arrow":return NA(e,t,i);case"ellipse-mind":return WA(e,t,i);case"soft-mind":return zA(e,t,i);case"rounded-mind":return XA(e,t,i);case"concentration":case"thought":case"none":return null}return console.error(`Unknown bubble shape: ${A}`),null}finally{}}function xe(A){return[-A[0]*.5,-A[1]*.5,A[0],A[1]]}function lo(A){return[A[0]*.5,A[1]*.5]}function JA(A,e,t){const i=new V.Path.Rectangle(xe(A));return fe(i,A,e)}function xt(A,e,t){const i=new V.Path.Ellipse({center:[0,0],radius:lo(A)});return fe(i,A,e)}function Ct(A,e,t){const[i,n,s,a]=xe(A),[r,o]=[0,0],[l,c]=[i+s,n+a],[d,f]=[e.xStraight*s*.5,e.yStraight*a*.5],u=new V.Path;return u.moveTo([r+d,n]),u.lineTo([r-d,n]),u.quadraticCurveTo([i,n],[i,o-f]),u.lineTo([i,o+f]),u.quadraticCurveTo([i,c],[r-d,c]),u.lineTo([r+d,c]),u.quadraticCurveTo([l,c],[l,o+f]),u.lineTo([l,o-f]),u.quadraticCurveTo([l,n],[r+d,n]),u.closed=!0,fe(u,A,e)}function VA(A,e,t){const i=ne(t);let n=Ie(i,e.bumpCount,e.angleJitter);const s=Re(A,n,e.superEllipse);let a=lt(A,s,e.bumpDepth);const r=new V.Path;return r.addSegments(a),r.closed=!0,fe(r,A,e)}function ZA(A,e,t){const i=e.bumpSharp,n=ne(t);let s;const a=Ie(n,e.bumpCount,e.angleJitter);s=Re(A,a,e.superEllipse),s=lt(A,s,i),s=Kr(n,s,i,e.depthJitter);const r=new V.Path;r.moveTo(s[0]);for(let o=0;o<s.length;o+=2){s[o];const l=s[o+1],c=s[(o+2)%s.length];r.quadraticCurveTo(l,c)}return r.closed=!0,fe(r,A,e)}function qt(A,e,t){const i=ne(t),n=Re(A,Ie(i,e.bumpCount,e.angleJitter),e.superEllipse),s=lt(A,n,-e.bumpDepth),a=new V.Path;if(e.smoothing)for(let r=0;r<s.length+1;r++){const o=s[r%s.length],l=s[(r+1)%s.length];let c=[(o[0]+l[0])/2,(o[1]+l[1])/2];r==0?a.moveTo(c):a.quadraticCurveTo(o,c)}else{a.moveTo(s[0]);for(let r=0;r<s.length;r+=2){const o=s[r+1],l=s[(r+2)%s.length];a.quadraticCurveTo(o,l)}a.closed=!0}return fe(a,A,e)}function HA(A,e,t){const[i,n]=A,[s,a]=[0,0],r=n*-.58,o=n*-.35,l=n*-.1,c=n*.1,d=n*.35,f=n*.5,u=new V.Path;return u.moveTo([s,a+o]),u.cubicCurveTo([-.1*i,r],[-.5*i,r],[-.5*i,l]),u.cubicCurveTo([-.5*i,c],[-.3*i,d],[0,f]),u.cubicCurveTo([.3*i,d],[.5*i,c],[.5*i,l]),u.cubicCurveTo([.5*i,r],[.1*i,r],[0,o]),u.closed=!0,u}function FA(A,e,t){const[i,n,s,a]=xe(A),r=new V.Path;return r.moveTo([0,n]),r.lineTo([i,0]),r.lineTo([0,n+a]),r.lineTo([i+s,0]),r.closed=!0,r}function NA(A,e,t){const[i,n,s,a]=xe(A),{shaftWidth:r,headLength:o}=e,l=r*s*.5,c=new V.Path,d=n+a*o,f=i+s*.5-l,u=i+s*.5+l;return c.moveTo([0,n]),c.lineTo([i,d]),c.lineTo([f,d]),c.lineTo([f,n+a]),c.lineTo([u,n+a]),c.lineTo([u,d]),c.lineTo([i+s,d]),c.lineTo([0,n]),c.closed=!0,c}function WA(A,e,t){const i={...e};i.tailTip=[0,0],i.tailMid=[.5,0];const n=xt(A,i);return Ut(n,t,A,e,i)}function zA(A,e,t){const i={...e};i.tailTip=[0,0],i.tailMid=[.5,0];const n=qt(A,i,t);return Ut(n,t,A,e,i)}function XA(A,e,t){const i={...e};i.tailTip=[0,0],i.tailMid=[.5,0];const n=Ct(A,i);return Ut(n,t,A,e,i)}function co(A,e,t,i,n,s){const a=ne(t),r=Re(A,Ie(a,i),n),o=lt(A,r,-s),l=new V.Path;l.moveTo(o[0]);for(let c=0;c<o.length;c+=2){o[c];const d=o[c+1],f=o[(c+2)%o.length];l.quadraticCurveTo(d,f)}return l.closed=!0,fe(l,A,e)}function fe(A,e,t){if(t!=null&&t.tailTip){const i=t.tailTip,n=t.tailMid;if(!(i[0]===0&&i[1]===0))if(t!=null&&t.extract){const s=uo(e,n,i,t.extractWidth),a=A.subtract(s);return A.remove(),s.remove(),a}else{const s=ho(e,n,i,t.tailWidth),a=A.unite(s);return A.remove(),s.remove(),a}}return A}function ho(A,e,t,i){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=A[0]*A[1]*i,s=Math.max(5e4,Math.hypot(t[0],t[1])**2),a=Oe(me(t),n*35/s),r=Oe(me(t,-1),n*35/s),o=[t[0]-a[0],t[1]-a[1]],l=[t[0]-r[0],t[1]-r[1]],c=t,d=a,f=r,u=Je(d,o,e),g=Je(f,l,e),p=new V.Path;return p.moveTo(d),p.curveTo(u,c),p.curveTo(g,f),p.closed=!0,p}function uo(A,e,t,i){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=Je([0,0],t,e),s=[t[0]-n[0],t[1]-n[1]],a=Math.hypot(t[0],t[1]),r=Oe(me(s),a*i),o=[t[0]+r[0],t[1]+r[1]],l=[t[0]-r[0],t[1]-r[1]],c=new V.Path;return c.moveTo(n),c.lineTo(o),c.lineTo(l),c.closed=!0,c}function YA(A,e,t){const i=ne(t),n=Ie(i,e.vertexCount,e.angleJitter),s=Re(A,n,e.superEllipse),a=GA(s),r=new V.Path;return r.addSegments(a),r.closed=!0,fe(r,A,e)}function fo(A,e,t,i,n){const s=xt(i,n);G(A,e,s,n)}function po(A,e,t,i,n){const s=JA(i,n);G(A,e,s,n)}function go(A,e,t,i,n){const s=YA(i,n,t);G(A,e,s,n)}function mo(A,e,t,i,n){const s=Ct(i,n);G(A,e,s,n)}function bo(A,e,t,i,n){const s=VA(i,n,t);G(A,e,s,n)}function wo(A,e,t,i,n){const s=ZA(i,n,t);G(A,e,s,n)}function Qo(A,e,t,i,n){const s=qt(i,n,t);G(A,e,s,n)}function vo(A,e,t,i,n){const s=HA(i);G(A,e,s,n)}function yo(A,e,t,i,n){const s=FA(i);G(A,e,s,n)}function Po(A,e,t,i,n){const s=NA(i,n);G(A,e,s,n)}function ko(A,e,t,i,n){const s=WA(i,n,t);G(A,e,s,n)}function Bo(A,e,t,i,n){const s=zA(i,n,t);G(A,e,s,n)}function Do(A,e,t,i,n){const s=XA(i,n,t);G(A,e,s,n)}function G(A,e,t,i){switch(A.beginPath(),e){case"fill":A.fill(new Path2D(t.pathData));break;case"stroke":const n=i.roughness??0;if(0<n){const s=(i.randomSeed??0)+1;pi.canvas(A.canvas,{options:{seed:s,roughness:n,strokeWidth:A.lineWidth,stroke:A.strokeStyle}}).path(t.pathData)}else A.stroke(new Path2D(t.pathData));break;case"clip":A.clip(new Path2D(t.pathData));break}}function Ut(A,e,t,i,n){const s=[[.97,.04],[.8,.05],[.6,.08],[.3,.12]],a=Je([0,0],i.tailTip,i.tailMid),r=i.tailTip,o=[r[0]-a[0],r[1]-a[1]],l=Math.min(t[0],t[1])*.5*i.tailWidth,c=(i==null?void 0:i.flattening)??1;for(let d of s){const f=[a[0]+d[0]*o[0],a[1]+d[0]*o[1]],u=l*d[1]*2,g=co([u,u],n,e,6,2,.15);if(c&&Math.abs(c-1)>1e-6){const p=c>1?1/c:1,v=c<1?c:1;g.scale(p,v,[0,0])}g.translate(f),A=A.unite(g)}return A}function je(A,e,t,i=!0){const n=[],s=r=>((t[0]-e[0])*(r[1]-e[1])-(t[1]-e[1])*(r[0]-e[0]))*(i?1:-1)>=0,a=(r,o)=>{const l=o[0]-r[0],c=o[1]-r[1],d=t[1]-e[1],f=-(t[0]-e[0]),u=((e[0]-r[0])*d+(e[1]-r[1])*f)/(l*d+c*f);return[r[0]+u*l,r[1]+u*c]};for(let r=0;r<A.length;r++){const o=A[r],l=A[(r+A.length-1)%A.length],c=s(o),d=s(l);c?(d||n.push(a(l,o)),n.push(o)):d&&n.push(a(l,o))}return n}function tA(A,e,t,i){const[n,s]=e;let a=[[0,0],[n,0],[n,s],[0,s]];if(t.top){const r=Xe(A.topLeft,A.topRight,-i);a=je(a,...r)}if(t.right){const r=Xe(A.topRight,A.bottomRight,-i);a=je(a,...r)}if(t.bottom){const r=Xe(A.bottomRight,A.bottomLeft,-i);a=je(a,...r)}if(t.left){const r=Xe(A.bottomLeft,A.topLeft,-i);a=je(a,...r)}return a}function jA(A,e,t,i,n){const s=e.films;for(let a of s){if(!a.visible)continue;const r=a.getShiftedScale(t),o=a.getShiftedTranslation(t);A.save(),n&&n(A,a),A.translate(...i),A.translate(o[0],o[1]),A.rotate(-a.rotation*Math.PI/180),A.scale(r*a.reverse[0],r*a.reverse[1]);let l=a.media;for(let c=a.effects.length-1;0<=c;c--)if(a.effects[c].outputMedia){l=a.effects[c].outputMedia;break}A.translate(-l.naturalWidth*.5,-l.naturalHeight*.5),A.drawImage(l.drawSource,0,0,l.naturalWidth,l.naturalHeight),A.restore()}}function AA(A,e,t,i,n){for(let s of t)KA(A,e,s),tt(A,e,s,!1,n);for(let s of t)tt(A,e,s,!0,n)}function KA(A,e,t,i){if(t.parent)return;const n=t.getPhysicalSize(e);t.getPhysicalStrokeWidth(e),A.save(),A.translate(...t.getPhysicalCenter(e)),A.rotate(-t.rotation*Math.PI/180),Eo(A,e,t,n),_A(A,t,n),jA(A,t.filmStack,e,[0,0],null),A.restore()}function Ce(A,e,t,i,n){A.fillStyle=e.hasEnoughSize(t)?i:"rgba(255, 128, 0, 0.9)"}function tt(A,e,t,i,n){if(t.parent){if(!i)return}else if(i)return;const s=t.getPhysicalSize(e),a=t.getPhysicalCenter(e),r=t.getPhysicalStrokeWidth(e);A.save(),A.translate(...a),A.rotate(-t.rotation*Math.PI/180),A.save(),_A(A,t,s),t.text&&!t.hidesText&&Io(A,e,t,n),A.restore(),A.strokeStyle=0<r?t.strokeColor:"rgba(0, 0, 0, 0)",A.lineWidth=r,So(A,e,t,s),A.restore()}function Eo(A,e,t,i,n){const s=t.renderInfo;s.unitedOuterPath?(s.innerPathIsSameWithOuterPath||(Ce(A,t,e,t.optionContext.shapeOutlineColor??"white"),G(A,"fill",s.unitedOuterPath,t.optionContext)),Ce(A,t,e,t.fillColor),G(A,"fill",s.unitedInnerPath,t.optionContext)):t.parent||(s.outerPath?(s.innerPathIsSameWithOuterPath||(Ce(A,t,e,t.optionContext.shapeOutlineColor??"white"),G(A,"fill",s.outerPath,t.optionContext)),Ce(A,t,e,t.fillColor),G(A,"fill",s.innerPath,t.optionContext)):(i[0]=Math.abs(i[0]),i[1]=Math.abs(i[1]),Ce(A,t,e,t.fillColor),A.strokeStyle=t.strokeColor,Rt(A,"fill",t.text,i,t.shape,t.optionContext)))}function _A(A,e,t){const i=e.renderInfo;i.unitedStrokePath?G(A,"clip",i.unitedStrokePath,e.optionContext):e.parent||(i.strokePath?G(A,"clip",i.strokePath,e.optionContext):(t[0]=Math.abs(t[0]),t[1]=Math.abs(t[1]),Rt(A,"clip",e.text,t,e.shape,e.optionContext)))}function So(A,e,t,i){const n=t.getPhysicalStrokeWidth(e);A.strokeStyle=0<n?t.strokeColor:"rgba(0, 0, 0, 0)",A.lineWidth=n;const s=t.renderInfo;s.unitedStrokePath?G(A,"stroke",s.unitedStrokePath,t.optionContext):t.parent||(s.strokePath?G(A,"stroke",s.strokePath,t.optionContext):(i[0]=Math.abs(i[0]),i[1]=Math.abs(i[1]),Rt(A,"stroke",t.text,i,t.shape,t.optionContext)))}function Io(A,e,t,i){const n=A.getTransform(),s=i?window.devicePixelRatio??1:1;let a,r;Math.abs(n.b)<.001&&Math.abs(n.c)<.001?(a=Math.abs(n.a),r=Math.abs(n.d)):(a=Math.sqrt(n.a*n.a+n.b*n.b),r=Math.sqrt(n.c*n.c+n.d*n.d));const o=[a*s,r*s],l=t.getPhysicalSize(e);let c=t.getPhysicalFontSize(e);const d=t.getPhysicalOffset(e),f=t.getPhysicalOutlineWidth(e),[u,g]=Nt(ki(l,o));if(u<1||g<1)return;isNaN(c)&&(c=14),c<1&&(c=14);const p=t.renderInfo,v=`${t.fontStyle} ${t.fontWeight} ${c}px '${t.fontFamily}'`,b={viewScale:Nt(ve(o,1e3)),size:l,offset:d,fontStyle:t.fontStyle,fontWeight:t.fontWeight,fontSize:c,lineSkip:t.lineSkip,charSkip:t.charSkip,fontFamily:t.fontFamily,text:t.text,direction:t.direction,autoNewline:t.autoNewline,fontColor:t.fontColor,outlineWidth:f,outlineColor:t.outlineColor,fontRenderVersion:t.fontRenderVersion,fontCheck:document.fonts.check(v),rubySize:t.rubySize,rubyDistance:t.rubyDistance},w=JSON.stringify(b);if(p.textJson!=w){p.textJson=w,p.textCanvas=document.createElement("canvas"),p.textCtx=p.textCanvas.getContext("2d");const Q=p.textCanvas,P=p.textCtx;Q.width=u,Q.height=g,P.translate(u*.5,g*.5),P.scale(...o),P.translate(...d),P.font=v;let E=t.text;document.fonts.check(`${t.fontStyle} ${t.fontWeight} 20px '${t.fontFamily}'`);const I=c*1.5*(1+t.lineSkip),x=c*(1+t.charSkip),O=t.rubySize,F=t.rubyDistance,Z=zr(t.direction,P,l[0]*.85,l[1]*.85,E,I,x,t.autoNewline),[H,N]=[Z.width,Z.height],se={x:-H*.5,y:-N*.5,width:H,height:N};P.globalCompositeOperation="source-over",P.fillStyle=t.fontColor,$t(t.direction,P,"fill",se,E,I,x,O,F,Z,t.autoNewline),0<f&&(P.globalCompositeOperation="destination-over",P.strokeStyle=t.outlineColor,P.lineWidth=f,P.font=v,P.lineJoin="round",$t(t.direction,P,"stroke",se,E,I,x,O,F,Z,t.autoNewline))}const D=p.textCanvas;try{const Q=Math.round(t.rotation*10)/10;A.save(),(Q===0||Q===90||Q===180||Q===270)&&(A.imageSmoothingEnabled=!1),A.scale(...Ei(o)),A.drawImage(D,0-u*.5,0-g*.5),A.restore()}catch(Q){throw console.log(u,g,D.width,D.height,l),Q}}function iA(A){const e=new Path2D;if(0<A.length){e.moveTo(...A[0]);for(let t=1;t<A.length;t++)e.lineTo(...A[t]);e.closePath()}return e}class $A extends ot{constructor(t){super();h(this,"frameTree",null);h(this,"rawBubbles",null);h(this,"thisFrameRenderData",null);this.supportsDpr=t}renderDepths(){return[0,1]}prerender(){const t=this.getPaperSize(),i=mt(this.frameTree,t,[0,0]);this.thisFrameRenderData=this.setUpRenderData(i)}render(t,i){const{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}=this.thisFrameRenderData;if(i===0){for(let{layout:o}of n)this.renderFrameBackground(t,o,null);s.sort((o,l)=>o.layout.element.z-l.layout.element.z);for(let{layout:o,inheritanceContext:l}of s)this.renderFrame(t,o,l,a)}i===1&&AA(t,this.getPaperSize(),r,!0,this.supportsDpr)}setUpRenderData(t){const i={borderColor:"black",borderWidth:1},{backgrounds:n,foregrounds:s}=this.setUpFrameTree(t,i),{embeddedBubbles:a,floatingBubbles:r}=this.setUpBubbles(t,this.rawBubbles);return{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}}setUpFrameTree(t,i){const n=[],s=[];if(t.element.borderColor!=null&&(i.borderColor=t.element.borderColor),t.element.borderWidth!=null&&(i.borderWidth=t.element.borderWidth),t.children){n.push({layout:t,inheritanceContext:i});for(let a=0;a<t.children.length;a++){const r=this.setUpFrameTree(t.children[a],i);n.push(...r.backgrounds),s.push(...r.foregrounds)}}else n.push({layout:t,inheritanceContext:i}),s.push({layout:t,inheritanceContext:i});return{backgrounds:n,foregrounds:s}}setUpBubbles(t,i){const n=this.getPaperSize();this.resolveLinkages(i);const s=new Map,a=[];for(let r of i)if(r.embedded){const o=RA(t,r.getPhysicalCenter(n),0);o&&0<o.element.visibility&&o.element.isLeaf()?(s.has(o)||s.set(o,[]),s.get(o).push(r)):a.push(r)}else a.push(r);return{embeddedBubbles:s,floatingBubbles:a}}resolveLinkages(t){var s,a,r,o,l,c,d,f,u,g,p,v;const i=this.getPaperSize(),n={};for(let b of t)b.renderInfo??(b.renderInfo={}),(s=b.renderInfo.unitedOuterPath)==null||s.remove(),b.renderInfo.unitedOuterPath=null,(a=b.renderInfo.unitedInnerPath)==null||a.remove(),b.renderInfo.unitedInnerPath=null,(r=b.renderInfo.unitedStrokePath)==null||r.remove(),b.renderInfo.unitedStrokePath=null,b.renderInfo.children=[],n[b.uuid]=b;for(let b of t)b.parent&&(n[b.parent]==null?b.parent=null:n[b.parent].renderInfo.children.push(b));for(let b of t){const w=b.optionContext,D=[b.n_p1[0]-b.n_p0[0],b.n_p1[1]-b.n_p0[1]],Q=b.renderInfo,P={paperSize:i,shape:b.shape,size:D,optionContext:w,rotation:b.rotation},E=JSON.stringify(P);if(Q.pathJson!=E){(o=Q.strokePath)==null||o.remove(),(l=Q.outerPath)==null||l.remove(),(c=Q.innerPath)==null||c.remove(),Q.strokePath=null,Q.outerPath=null,Q.innerPath=null;const I=b.getPhysicalSize(i);if(Q.pathJson=E,Q.strokePath=oo(b.shape,I,w,b.text),(d=Q.strokePath)==null||d.rotate(-b.rotation),Q.innerPathIsSameWithOuterPath=!1,Q.strokePath){const x=Math.min(Q.strokePath.bounds.width,Q.strokePath.bounds.height)*(w.shapeExpand??0);try{x==0?Q.outerPath=Q.strokePath.clone():Q.outerPath=Ht.PaperOffset.offset(Q.strokePath,x)}catch{console.error("PaperOffset failed, using strokePath as outerPath",q.decompile(b)),Q.outerPath=Q.strokePath.clone()}const O=Math.min(Q.outerPath.bounds.width,Q.outerPath.bounds.height)*(w.shapeOutline??0);try{O==0?(Q.innerPath=Q.outerPath.clone(),Q.innerPathIsSameWithOuterPath=!0):Q.innerPath=Ht.PaperOffset.offset(Q.outerPath,-O)}catch{console.error("PaperOffset failed, using outerPath as innerPath",q.decompile(b)),Q.innerPath=Q.outerPath.clone(),Q.innerPathIsSameWithOuterPath=!0}}}}for(let b of t){const w=b.renderInfo;if(b.parent==null&&w.strokePath){const D=b.getPhysicalCenter(i);w.unitedStrokePath=w.strokePath.clone(),w.unitedOuterPath=w.outerPath.clone(),w.unitedInnerPath=w.innerPath.clone(),w.unitedOuterPath.translate(D),w.unitedInnerPath.translate(D),w.unitedStrokePath.translate(D);for(let Q of w.children){const P=Q.getPhysicalCenter(i),E=Q.renderInfo;if(E.strokePath==null)continue;const I=E.strokePath.clone();I==null||I.translate(Q.getPhysicalCenter(i)),(f=w.unitedStrokePath)==null||f.remove(),w.unitedStrokePath=w.unitedStrokePath.unite(I),I.remove();const x=E.outerPath.clone();x.translate(P),(u=w.unitedOuterPath)==null||u.remove(),w.unitedOuterPath=w.unitedOuterPath.unite(x),x.remove();const O=E.innerPath.clone();O.translate(P),(g=w.unitedInnerPath)==null||g.remove(),w.unitedInnerPath=w.unitedInnerPath.unite(O),O.remove()}w.children.length===0&&w.innerPathIsSameWithOuterPath?((p=w.unitedInnerPath)==null||p.remove(),w.unitedInnerPath=w.unitedOuterPath.clone()):((v=w.unitedOuterPath)==null||v.remove(),w.unitedOuterPath=w.unitedOuterPath.subtract(w.unitedInnerPath)),w.unitedOuterPath.rotate(b.rotation,D),w.unitedOuterPath.translate(ht(D)),w.unitedInnerPath.rotate(b.rotation,D),w.unitedInnerPath.translate(ht(D)),w.unitedStrokePath.rotate(b.rotation,D),w.unitedStrokePath.translate(ht(D))}}}makeFramePath(t,i){const n=this.getPaperSize(),s=tA(t.corners,n,{top:!0,right:!0,bottom:!0,left:!0},i);return iA(s)}renderFrame(t,i,n,s){this.renderFrameBackground(t,i,n);const a=i.element;2<=a.visibility&&this.renderFrameBorder(t,i,n),1<=a.visibility&&this.renderFrameContent(t,i,n,s)}renderFrameBackground(t,i,n){if(i.element.visibility===0||!i.element.bgColor)return;const s=(n==null?void 0:n.borderWidth)??0,a=this.makeFramePath(i,-s*.5);t.save(),t.lineJoin="miter",t.fillStyle=i.element.bgColor,t.fill(a),t.restore()}renderFrameContent(t,i,n,s){if(0<i.element.filmStack.films.length||s.has(i)){const r=this.getPaperSize(),o=i.element,[l,c,d,f]=Rr(i.corners),u=-n.borderWidth*.5,g=(b,w)=>{const D=tA(i.corners,r,w.barriers,u);b.clip(iA(D))};jA(t,o.filmStack,r,[l+d*.5,c+f*.5],g);const p=this.makeFramePath(i,-n.borderWidth*.5),v=s.get(i);v&&(t.save(),t.clip(p),AA(t,this.getPaperSize(),v,!0,this.supportsDpr),t.restore())}}renderFrameBorder(t,i,n){const s=n.borderWidth;if(0<s){t.save(),t.strokeStyle=n.borderColor,t.lineWidth=s,t.lineJoin="miter";const a=this.makeFramePath(i,0);t.stroke(a),t.restore()}}setBubbles(t){this.rawBubbles=t}setFrameTree(t){this.frameTree=t}renderApart(){const t=this.getPaperSize();function i(){const d=bi(t[0],t[1]),f=d.getContext("2d");return{canvas:d,ctx:f}}const n=mt(this.frameTree,t,[0,0]),{foregrounds:s,embeddedBubbles:a,floatingBubbles:r}=this.setUpRenderData(n),o=[];s.sort((d,f)=>d.layout.element.z-f.layout.element.z);for(let{layout:d,inheritanceContext:f}of s){if(d.element.visibility<1)continue;const{canvas:u,ctx:g}=i();this.renderFrameBackground(g,d,f),this.renderFrameContent(g,d,f,a);const{canvas:p,ctx:v}=i();this.renderFrameBorder(v,d,f),o.push({border:p,content:u})}const l=[...[...a.values()].flat(),...r],c={};for(let d of l){if(d.renderInfo,d.parent!=null)continue;const{canvas:f,ctx:u}=i(),g=this.getPaperSize();KA(u,g,d),tt(u,g,d,!1,this.supportsDpr),c[d.uuid]=f}for(let d of l){if(d.parent==null)continue;const f=c[d.parent].getContext("2d");tt(f,this.getPaperSize(),d,!0,this.supportsDpr)}return{frames:o,bubbles:Object.values(c)}}resetCache(){var t,i,n,s,a,r;for(let o of this.rawBubbles){const l=o.renderInfo;l&&((t=l.strokePath)==null||t.remove(),(i=l.outerPath)==null||i.remove(),(n=l.innerPath)==null||n.remove(),(s=l.unitedStrokePath)==null||s.remove(),(a=l.unitedOuterPath)==null||a.remove(),(r=l.unitedInnerPath)==null||r.remove()),o.renderInfo=void 0}}}class Ro{constructor(){h(this,"subscribers",[])}subscribe(e){this.subscribers.push(e)}unsubscribe(e){this.subscribers=this.subscribers.filter(t=>t!==e)}setFocus(e){this.subscribers.forEach(t=>t(e))}}const xo=typeof process<"u"&&(process.env.NODE_ENV==="test"||process.env.VITEST);let vt;async function Co(){const A=new Te.Computron;await A.init(),vt=new Te.JFACompute(A),await vt.init()}xo||Co();class ei{constructor(){h(this,"ulid");h(this,"inputMedia");h(this,"outputMedia");this.ulid=Pe.ulid(),this.inputMedia=null,this.outputMedia=null}get tag(){return this.constructor.name}clone(){throw new Error("Not implemented")}cleanInput(){this.inputMedia=null}setOutputDirty(){this.outputMedia=null}async apply(e){throw new Error("Not implemented")}decompile(){throw new Error("Not implemented")}static compile(e){switch(e.tag){case"OutlineEffect":const t=e.properties;return new Mt(t.color,t.width,t.sharp);default:throw new Error("Unknown effect tag: "+e.tag)}}}class Mt extends ei{constructor(t,i,n){super();h(this,"rawDistanceField",null);this.color=t,this.width=i,this.sharp=n}clone(){return new Mt(this.color,this.width,this.sharp)}async apply(t){if(this.inputMedia!=t){const u=t.drawSource,g=Te.FloatField.createFromImageOrCanvas(u),p=Te.JFACompute.createJFASeedMap(g,.5,!1);this.rawDistanceField=await vt.compute(p),this.inputMedia=t}const i=t.drawSource,n=Math.max(t.naturalWidth,t.naturalHeight),s=this.width*n,a=mi(this.color),r={r:a.values[0]/255,g:a.values[1]/255,b:a.values[2]/255},o=1-this.sharp,l=u=>o<=u?1:u*(1/o),c=Te.JFACompute.generateDistanceField(this.rawDistanceField,r,s,l),d=document.createElement("canvas");d.width=i.width,d.height=i.height;const f=d.getContext("2d");return f.drawImage(i,0,0),f.globalCompositeOperation="destination-over",f.drawImage(c.toCanvas(),0,0),this.outputMedia=new Ae(d),this.outputMedia}decompile(){return{color:this.color,width:this.width,sharp:this.sharp}}}async function ti(A,e,t){const i=ae.compileNode(e);if(i.gallery=[],e.image||e.scribble)if(typeof e.image=="string"||typeof e.scribble=="string"){let s=function(a){const r=Math.min(a.width,a.height),o=Math.min(A[0],A[1]),l=r/o,c=(e.scale??[1,1])[0],d=l*c,f=e.translation??[0,0],u=[f[0]*l,f[1]*l],g=new _(new Ae(a));return g.n_scale=d,g.n_translation=u,g.rotation=e.rotation,g.reverse=[...e.reverse??[1,1]],g.prompt=e.prompt,g};if(e.image){const a=await t(e.image,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}if(e.scribble){const a=await t(e.scribble,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}}else{let s=function(a){const r=new _(new Ae(a));return r.n_scale=e.image.n_scale,r.n_translation=e.image.n_translation,r.rotation=e.image.rotation,r.reverse=[...e.image.reverse],r.prompt=e.prompt,r};if(e.image.image){const a=await t(e.image.image,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}if(e.image.scribble){const a=await t(e.image.scribble,"image");if(a){const r=s(a);i.filmStack.films.push(r)}}}else if(e.films){const s=await Ai(e.films,t);i.filmStack.films.push(...s)}const n=e.column??e.row;if(n){i.direction=e.column?"v":"h",i.children=[];for(let s of n)i.children.push(await ti(A,s,t));i.calculateLengthAndBreadth()}for(const s of i.filmStack.films)s.media instanceof Ae&&i.gallery.push(s.media);return i}async function qo(A,e,t){const i=[];for(const n of e){const s=q.compile(A,n),a=n.image;if(a){const r=await t(a.image,"image");if(r instanceof HTMLCanvasElement){const o=Math.min(r.width,r.height),l=Math.min(A[0],A[1]);let c=a.n_scale;if(!c){const g=(a.scale??[1,1])[0];c=o/l*g}let d=a.n_translation;if(!d){const u=a.translation??[0,0],g=o/l;d=[u[0]*g,u[1]*g]}const f=new _(new Ae(r));f.n_scale=c,f.n_translation=d,s.filmStack.films.push(f),s.scaleLock=a.scaleLock}}else if(n.films){const r=await Ai(n.films,t);s.filmStack.films=r}i.push(s)}for(const n of i)for(const s of n.filmStack.films)s.media instanceof Ae&&n.gallery.push(s.media);return i}async function Ai(A,e){const t=[];for(const i of A){const n=await e(i.image,i.mediaType??"image");if(!n)continue;const s=[];if(i.effects)for(const o of i.effects){const l=ei.compile(o);s.push(l)}const a=i.mediaType==="video"?new gt(n):new Ae(n),r=new _(a);i.ulid&&(r.ulid=i.ulid),r.n_scale=i.n_scale,r.n_translation=i.n_translation,r.rotation=i.rotation,r.reverse=i.reverse,r.visible=i.visible,r.prompt=i.prompt,r.effects=s,r.barriers=i.barriers??{top:!0,right:!0,bottom:!0,left:!0},t.push(r)}return t}async function Uo(A,e){const t=[];for(const i of A.characters){const n=i.portrait?await e(i.portrait,"image"):null;t.push({...i,portrait:Lr(n)})}return{...A,characters:t,format:A.format??"standard"}}var L;(function(A){A.assertEqual=n=>{};function e(n){}A.assertIs=e;function t(n){throw new Error}A.assertNever=t,A.arrayToEnum=n=>{const s={};for(const a of n)s[a]=a;return s},A.getValidEnumValues=n=>{const s=A.objectKeys(n).filter(r=>typeof n[n[r]]!="number"),a={};for(const r of s)a[r]=n[r];return A.objectValues(a)},A.objectValues=n=>A.objectKeys(n).map(function(s){return n[s]}),A.objectKeys=typeof Object.keys=="function"?n=>Object.keys(n):n=>{const s=[];for(const a in n)Object.prototype.hasOwnProperty.call(n,a)&&s.push(a);return s},A.find=(n,s)=>{for(const a of n)if(s(a))return a},A.isInteger=typeof Number.isInteger=="function"?n=>Number.isInteger(n):n=>typeof n=="number"&&Number.isFinite(n)&&Math.floor(n)===n;function i(n,s=" | "){return n.map(a=>typeof a=="string"?`'${a}'`:a).join(s)}A.joinValues=i,A.jsonStringifyReplacer=(n,s)=>typeof s=="bigint"?s.toString():s})(L||(L={}));var nA;(function(A){A.mergeShapes=(e,t)=>({...e,...t})})(nA||(nA={}));const k=L.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),re=A=>{switch(typeof A){case"undefined":return k.undefined;case"string":return k.string;case"number":return Number.isNaN(A)?k.nan:k.number;case"boolean":return k.boolean;case"function":return k.function;case"bigint":return k.bigint;case"symbol":return k.symbol;case"object":return Array.isArray(A)?k.array:A===null?k.null:A.then&&typeof A.then=="function"&&A.catch&&typeof A.catch=="function"?k.promise:typeof Map<"u"&&A instanceof Map?k.map:typeof Set<"u"&&A instanceof Set?k.set:typeof Date<"u"&&A instanceof Date?k.date:k.object;default:return k.unknown}},m=L.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ie extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=i=>{this.issues=[...this.issues,i]},this.addIssues=(i=[])=>{this.issues=[...this.issues,...i]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(s){return s.message},i={_errors:[]},n=s=>{for(const a of s.issues)if(a.code==="invalid_union")a.unionErrors.map(n);else if(a.code==="invalid_return_type")n(a.returnTypeError);else if(a.code==="invalid_arguments")n(a.argumentsError);else if(a.path.length===0)i._errors.push(t(a));else{let r=i,o=0;for(;o<a.path.length;){const l=a.path[o];o===a.path.length-1?(r[l]=r[l]||{_errors:[]},r[l]._errors.push(t(a))):r[l]=r[l]||{_errors:[]},r=r[l],o++}}};return n(this),i}static assert(e){if(!(e instanceof ie))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,L.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},i=[];for(const n of this.issues)n.path.length>0?(t[n.path[0]]=t[n.path[0]]||[],t[n.path[0]].push(e(n))):i.push(e(n));return{formErrors:i,fieldErrors:t}}get formErrors(){return this.flatten()}}ie.create=A=>new ie(A);const yt=(A,e)=>{let t;switch(A.code){case m.invalid_type:A.received===k.undefined?t="Required":t=`Expected ${A.expected}, received ${A.received}`;break;case m.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(A.expected,L.jsonStringifyReplacer)}`;break;case m.unrecognized_keys:t=`Unrecognized key(s) in object: ${L.joinValues(A.keys,", ")}`;break;case m.invalid_union:t="Invalid input";break;case m.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${L.joinValues(A.options)}`;break;case m.invalid_enum_value:t=`Invalid enum value. Expected ${L.joinValues(A.options)}, received '${A.received}'`;break;case m.invalid_arguments:t="Invalid function arguments";break;case m.invalid_return_type:t="Invalid function return type";break;case m.invalid_date:t="Invalid date";break;case m.invalid_string:typeof A.validation=="object"?"includes"in A.validation?(t=`Invalid input: must include "${A.validation.includes}"`,typeof A.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${A.validation.position}`)):"startsWith"in A.validation?t=`Invalid input: must start with "${A.validation.startsWith}"`:"endsWith"in A.validation?t=`Invalid input: must end with "${A.validation.endsWith}"`:L.assertNever(A.validation):A.validation!=="regex"?t=`Invalid ${A.validation}`:t="Invalid";break;case m.too_small:A.type==="array"?t=`Array must contain ${A.exact?"exactly":A.inclusive?"at least":"more than"} ${A.minimum} element(s)`:A.type==="string"?t=`String must contain ${A.exact?"exactly":A.inclusive?"at least":"over"} ${A.minimum} character(s)`:A.type==="number"?t=`Number must be ${A.exact?"exactly equal to ":A.inclusive?"greater than or equal to ":"greater than "}${A.minimum}`:A.type==="date"?t=`Date must be ${A.exact?"exactly equal to ":A.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(A.minimum))}`:t="Invalid input";break;case m.too_big:A.type==="array"?t=`Array must contain ${A.exact?"exactly":A.inclusive?"at most":"less than"} ${A.maximum} element(s)`:A.type==="string"?t=`String must contain ${A.exact?"exactly":A.inclusive?"at most":"under"} ${A.maximum} character(s)`:A.type==="number"?t=`Number must be ${A.exact?"exactly":A.inclusive?"less than or equal to":"less than"} ${A.maximum}`:A.type==="bigint"?t=`BigInt must be ${A.exact?"exactly":A.inclusive?"less than or equal to":"less than"} ${A.maximum}`:A.type==="date"?t=`Date must be ${A.exact?"exactly":A.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(A.maximum))}`:t="Invalid input";break;case m.custom:t="Invalid input";break;case m.invalid_intersection_types:t="Intersection results could not be merged";break;case m.not_multiple_of:t=`Number must be a multiple of ${A.multipleOf}`;break;case m.not_finite:t="Number must be finite";break;default:t=e.defaultError,L.assertNever(A)}return{message:t}};let Mo=yt;function Lo(){return Mo}const To=A=>{const{data:e,path:t,errorMaps:i,issueData:n}=A,s=[...t,...n.path||[]],a={...n,path:s};if(n.message!==void 0)return{...n,path:s,message:n.message};let r="";const o=i.filter(l=>!!l).slice().reverse();for(const l of o)r=l(a,{data:e,defaultError:r}).message;return{...n,path:s,message:r}};function y(A,e){const t=Lo(),i=To({issueData:e,data:A.data,path:A.path,errorMaps:[A.common.contextualErrorMap,A.schemaErrorMap,t,t===yt?void 0:yt].filter(n=>!!n)});A.common.issues.push(i)}class W{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const i=[];for(const n of t){if(n.status==="aborted")return R;n.status==="dirty"&&e.dirty(),i.push(n.value)}return{status:e.value,value:i}}static async mergeObjectAsync(e,t){const i=[];for(const n of t){const s=await n.key,a=await n.value;i.push({key:s,value:a})}return W.mergeObjectSync(e,i)}static mergeObjectSync(e,t){const i={};for(const n of t){const{key:s,value:a}=n;if(s.status==="aborted"||a.status==="aborted")return R;s.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof a.value<"u"||n.alwaysSet)&&(i[s.value]=a.value)}return{status:e.value,value:i}}}const R=Object.freeze({status:"aborted"}),Ue=A=>({status:"dirty",value:A}),K=A=>({status:"valid",value:A}),sA=A=>A.status==="aborted",aA=A=>A.status==="dirty",ke=A=>A.status==="valid",At=A=>typeof Promise<"u"&&A instanceof Promise;var B;(function(A){A.errToObj=e=>typeof e=="string"?{message:e}:e||{},A.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(B||(B={}));var it=function(A,e,t,i){if(t==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?A!==e||!i:!e.has(A))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?i:t==="a"?i.call(A):i?i.value:e.get(A)},ii=function(A,e,t,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?A!==e||!n:!e.has(A))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(A,t):n?n.value=t:e.set(A,t),t},Me,Le;class de{constructor(e,t,i,n){this._cachedPath=[],this.parent=e,this.data=t,this._path=i,this._key=n}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const rA=(A,e)=>{if(ke(e))return{success:!0,data:e.value};if(!A.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new ie(A.common.issues);return this._error=t,this._error}}};function C(A){if(!A)return{};const{errorMap:e,invalid_type_error:t,required_error:i,description:n}=A;if(e&&(t||i))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:n}:{errorMap:(a,r)=>{const{message:o}=A;return a.code==="invalid_enum_value"?{message:o??r.defaultError}:typeof r.data>"u"?{message:o??i??r.defaultError}:a.code!=="invalid_type"?{message:r.defaultError}:{message:o??t??r.defaultError}},description:n}}class U{get description(){return this._def.description}_getType(e){return re(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:re(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new W,ctx:{common:e.parent.common,data:e.data,parsedType:re(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(At(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const i=this.safeParse(e,t);if(i.success)return i.data;throw i.error}safeParse(e,t){const i={common:{issues:[],async:(t==null?void 0:t.async)??!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)},n=this._parseSync({data:e,path:i.path,parent:i});return rA(i,n)}"~validate"(e){var i,n;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:t});return ke(s)?{value:s.value}:{issues:t.common.issues}}catch(s){(n=(i=s==null?void 0:s.message)==null?void 0:i.toLowerCase())!=null&&n.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(s=>ke(s)?{value:s.value}:{issues:t.common.issues})}async parseAsync(e,t){const i=await this.safeParseAsync(e,t);if(i.success)return i.data;throw i.error}async safeParseAsync(e,t){const i={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:re(e)},n=this._parse({data:e,path:i.path,parent:i}),s=await(At(n)?n:Promise.resolve(n));return rA(i,s)}refine(e,t){const i=n=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(n):t;return this._refinement((n,s)=>{const a=e(n),r=()=>s.addIssue({code:m.custom,...i(n)});return typeof Promise<"u"&&a instanceof Promise?a.then(o=>o?!0:(r(),!1)):a?!0:(r(),!1)})}refinement(e,t){return this._refinement((i,n)=>e(i)?!0:(n.addIssue(typeof t=="function"?t(i,n):t),!1))}_refinement(e){return new Ee({schema:this,typeName:S.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return le.create(this,this._def)}nullable(){return Se.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ee.create(this)}promise(){return rt.create(this,this._def)}or(e){return st.create([this,e],this._def)}and(e){return at.create(this,e,this._def)}transform(e){return new Ee({...C(this._def),schema:this,typeName:S.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new kt({...C(this._def),innerType:this,defaultValue:t,typeName:S.ZodDefault})}brand(){return new al({typeName:S.ZodBranded,type:this,...C(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Bt({...C(this._def),innerType:this,catchValue:t,typeName:S.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Lt.create(this,e)}readonly(){return Dt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Go=/^c[^\s-]{8,}$/i,Oo=/^[0-9a-z]+$/,Jo=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Vo=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Zo=/^[a-z0-9_-]{21}$/i,Ho=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Fo=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,No=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Wo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let ut;const zo=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Xo=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Yo=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,jo=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ko=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,_o=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ni="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",$o=new RegExp(`^${ni}$`);function si(A){let e="[0-5]\\d";A.precision?e=`${e}\\.\\d{${A.precision}}`:A.precision==null&&(e=`${e}(\\.\\d+)?`);const t=A.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function el(A){return new RegExp(`^${si(A)}$`)}function tl(A){let e=`${ni}T${si(A)}`;const t=[];return t.push(A.local?"Z?":"Z"),A.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function Al(A,e){return!!((e==="v4"||!e)&&zo.test(A)||(e==="v6"||!e)&&Yo.test(A))}function il(A,e){if(!Ho.test(A))return!1;try{const[t]=A.split("."),i=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),n=JSON.parse(atob(i));return!(typeof n!="object"||n===null||"typ"in n&&(n==null?void 0:n.typ)!=="JWT"||!n.alg||e&&n.alg!==e)}catch{return!1}}function nl(A,e){return!!((e==="v4"||!e)&&Xo.test(A)||(e==="v6"||!e)&&jo.test(A))}class oe extends U{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==k.string){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_type,expected:k.string,received:s.parsedType}),R}const i=new W;let n;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),i.dirty());else if(s.kind==="max")e.data.length>s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),i.dirty());else if(s.kind==="length"){const a=e.data.length>s.value,r=e.data.length<s.value;(a||r)&&(n=this._getOrReturnCtx(e,n),a?y(n,{code:m.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&y(n,{code:m.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),i.dirty())}else if(s.kind==="email")No.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"email",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="emoji")ut||(ut=new RegExp(Wo,"u")),ut.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"emoji",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="uuid")Vo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"uuid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="nanoid")Zo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"nanoid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="cuid")Go.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"cuid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="cuid2")Oo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"cuid2",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="ulid")Jo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"ulid",code:m.invalid_string,message:s.message}),i.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),y(n,{validation:"url",code:m.invalid_string,message:s.message}),i.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"regex",code:m.invalid_string,message:s.message}),i.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),i.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:{startsWith:s.value},message:s.message}),i.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:{endsWith:s.value},message:s.message}),i.dirty()):s.kind==="datetime"?tl(s).test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:"datetime",message:s.message}),i.dirty()):s.kind==="date"?$o.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:"date",message:s.message}),i.dirty()):s.kind==="time"?el(s).test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{code:m.invalid_string,validation:"time",message:s.message}),i.dirty()):s.kind==="duration"?Fo.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"duration",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="ip"?Al(e.data,s.version)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"ip",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="jwt"?il(e.data,s.alg)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"jwt",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="cidr"?nl(e.data,s.version)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"cidr",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="base64"?Ko.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"base64",code:m.invalid_string,message:s.message}),i.dirty()):s.kind==="base64url"?_o.test(e.data)||(n=this._getOrReturnCtx(e,n),y(n,{validation:"base64url",code:m.invalid_string,message:s.message}),i.dirty()):L.assertNever(s);return{status:i.value,value:e.data}}_regex(e,t,i){return this.refinement(n=>e.test(n),{validation:t,code:m.invalid_string,...B.errToObj(i)})}_addCheck(e){return new oe({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...B.errToObj(e)})}url(e){return this._addCheck({kind:"url",...B.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...B.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...B.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...B.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...B.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...B.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...B.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...B.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...B.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...B.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...B.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...B.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(e==null?void 0:e.offset)??!1,local:(e==null?void 0:e.local)??!1,...B.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...B.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...B.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...B.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...B.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...B.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...B.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...B.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...B.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...B.errToObj(t)})}nonempty(e){return this.min(1,B.errToObj(e))}trim(){return new oe({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new oe({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new oe({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}oe.create=A=>new oe({checks:[],typeName:S.ZodString,coerce:(A==null?void 0:A.coerce)??!1,...C(A)});function sl(A,e){const t=(A.toString().split(".")[1]||"").length,i=(e.toString().split(".")[1]||"").length,n=t>i?t:i,s=Number.parseInt(A.toFixed(n).replace(".","")),a=Number.parseInt(e.toFixed(n).replace(".",""));return s%a/10**n}class Be extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==k.number){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_type,expected:k.number,received:s.parsedType}),R}let i;const n=new W;for(const s of this._def.checks)s.kind==="int"?L.isInteger(e.data)||(i=this._getOrReturnCtx(e,i),y(i,{code:m.invalid_type,expected:"integer",received:"float",message:s.message}),n.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),n.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),n.dirty()):s.kind==="multipleOf"?sl(e.data,s.value)!==0&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.not_multiple_of,multipleOf:s.value,message:s.message}),n.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(i=this._getOrReturnCtx(e,i),y(i,{code:m.not_finite,message:s.message}),n.dirty()):L.assertNever(s);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,B.toString(t))}gt(e,t){return this.setLimit("min",e,!1,B.toString(t))}lte(e,t){return this.setLimit("max",e,!0,B.toString(t))}lt(e,t){return this.setLimit("max",e,!1,B.toString(t))}setLimit(e,t,i,n){return new Be({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:B.toString(n)}]})}_addCheck(e){return new Be({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:B.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:B.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:B.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:B.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:B.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:B.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:B.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:B.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:B.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&L.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const i of this._def.checks){if(i.kind==="finite"||i.kind==="int"||i.kind==="multipleOf")return!0;i.kind==="min"?(t===null||i.value>t)&&(t=i.value):i.kind==="max"&&(e===null||i.value<e)&&(e=i.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Be.create=A=>new Be({checks:[],typeName:S.ZodNumber,coerce:(A==null?void 0:A.coerce)||!1,...C(A)});class Ve extends U{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==k.bigint)return this._getInvalidInput(e);let i;const n=new W;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),n.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),n.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(i=this._getOrReturnCtx(e,i),y(i,{code:m.not_multiple_of,multipleOf:s.value,message:s.message}),n.dirty()):L.assertNever(s);return{status:n.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return y(t,{code:m.invalid_type,expected:k.bigint,received:t.parsedType}),R}gte(e,t){return this.setLimit("min",e,!0,B.toString(t))}gt(e,t){return this.setLimit("min",e,!1,B.toString(t))}lte(e,t){return this.setLimit("max",e,!0,B.toString(t))}lt(e,t){return this.setLimit("max",e,!1,B.toString(t))}setLimit(e,t,i,n){return new Ve({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:i,message:B.toString(n)}]})}_addCheck(e){return new Ve({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:B.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:B.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:B.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:B.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:B.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Ve.create=A=>new Ve({checks:[],typeName:S.ZodBigInt,coerce:(A==null?void 0:A.coerce)??!1,...C(A)});class oA extends U{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==k.boolean){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.boolean,received:i.parsedType}),R}return K(e.data)}}oA.create=A=>new oA({typeName:S.ZodBoolean,coerce:(A==null?void 0:A.coerce)||!1,...C(A)});class nt extends U{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==k.date){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_type,expected:k.date,received:s.parsedType}),R}if(Number.isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return y(s,{code:m.invalid_date}),R}const i=new W;let n;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),i.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(n=this._getOrReturnCtx(e,n),y(n,{code:m.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),i.dirty()):L.assertNever(s);return{status:i.value,value:new Date(e.data.getTime())}}_addCheck(e){return new nt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:B.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:B.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}nt.create=A=>new nt({checks:[],coerce:(A==null?void 0:A.coerce)||!1,typeName:S.ZodDate,...C(A)});class lA extends U{_parse(e){if(this._getType(e)!==k.symbol){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.symbol,received:i.parsedType}),R}return K(e.data)}}lA.create=A=>new lA({typeName:S.ZodSymbol,...C(A)});class cA extends U{_parse(e){if(this._getType(e)!==k.undefined){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.undefined,received:i.parsedType}),R}return K(e.data)}}cA.create=A=>new cA({typeName:S.ZodUndefined,...C(A)});class dA extends U{_parse(e){if(this._getType(e)!==k.null){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.null,received:i.parsedType}),R}return K(e.data)}}dA.create=A=>new dA({typeName:S.ZodNull,...C(A)});class hA extends U{constructor(){super(...arguments),this._any=!0}_parse(e){return K(e.data)}}hA.create=A=>new hA({typeName:S.ZodAny,...C(A)});class uA extends U{constructor(){super(...arguments),this._unknown=!0}_parse(e){return K(e.data)}}uA.create=A=>new uA({typeName:S.ZodUnknown,...C(A)});class he extends U{_parse(e){const t=this._getOrReturnCtx(e);return y(t,{code:m.invalid_type,expected:k.never,received:t.parsedType}),R}}he.create=A=>new he({typeName:S.ZodNever,...C(A)});class fA extends U{_parse(e){if(this._getType(e)!==k.undefined){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.void,received:i.parsedType}),R}return K(e.data)}}fA.create=A=>new fA({typeName:S.ZodVoid,...C(A)});class ee extends U{_parse(e){const{ctx:t,status:i}=this._processInputParams(e),n=this._def;if(t.parsedType!==k.array)return y(t,{code:m.invalid_type,expected:k.array,received:t.parsedType}),R;if(n.exactLength!==null){const a=t.data.length>n.exactLength.value,r=t.data.length<n.exactLength.value;(a||r)&&(y(t,{code:a?m.too_big:m.too_small,minimum:r?n.exactLength.value:void 0,maximum:a?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),i.dirty())}if(n.minLength!==null&&t.data.length<n.minLength.value&&(y(t,{code:m.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),i.dirty()),n.maxLength!==null&&t.data.length>n.maxLength.value&&(y(t,{code:m.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),i.dirty()),t.common.async)return Promise.all([...t.data].map((a,r)=>n.type._parseAsync(new de(t,a,t.path,r)))).then(a=>W.mergeArray(i,a));const s=[...t.data].map((a,r)=>n.type._parseSync(new de(t,a,t.path,r)));return W.mergeArray(i,s)}get element(){return this._def.type}min(e,t){return new ee({...this._def,minLength:{value:e,message:B.toString(t)}})}max(e,t){return new ee({...this._def,maxLength:{value:e,message:B.toString(t)}})}length(e,t){return new ee({...this._def,exactLength:{value:e,message:B.toString(t)}})}nonempty(e){return this.min(1,e)}}ee.create=(A,e)=>new ee({type:A,minLength:null,maxLength:null,exactLength:null,typeName:S.ZodArray,...C(e)});function Qe(A){if(A instanceof T){const e={};for(const t in A.shape){const i=A.shape[t];e[t]=le.create(Qe(i))}return new T({...A._def,shape:()=>e})}else return A instanceof ee?new ee({...A._def,type:Qe(A.element)}):A instanceof le?le.create(Qe(A.unwrap())):A instanceof Se?Se.create(Qe(A.unwrap())):A instanceof be?be.create(A.items.map(e=>Qe(e))):A}class T extends U{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=L.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==k.object){const l=this._getOrReturnCtx(e);return y(l,{code:m.invalid_type,expected:k.object,received:l.parsedType}),R}const{status:i,ctx:n}=this._processInputParams(e),{shape:s,keys:a}=this._getCached(),r=[];if(!(this._def.catchall instanceof he&&this._def.unknownKeys==="strip"))for(const l in n.data)a.includes(l)||r.push(l);const o=[];for(const l of a){const c=s[l],d=n.data[l];o.push({key:{status:"valid",value:l},value:c._parse(new de(n,d,n.path,l)),alwaysSet:l in n.data})}if(this._def.catchall instanceof he){const l=this._def.unknownKeys;if(l==="passthrough")for(const c of r)o.push({key:{status:"valid",value:c},value:{status:"valid",value:n.data[c]}});else if(l==="strict")r.length>0&&(y(n,{code:m.unrecognized_keys,keys:r}),i.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const c of r){const d=n.data[c];o.push({key:{status:"valid",value:c},value:l._parse(new de(n,d,n.path,c)),alwaysSet:c in n.data})}}return n.common.async?Promise.resolve().then(async()=>{const l=[];for(const c of o){const d=await c.key,f=await c.value;l.push({key:d,value:f,alwaysSet:c.alwaysSet})}return l}).then(l=>W.mergeObjectSync(i,l)):W.mergeObjectSync(i,o)}get shape(){return this._def.shape()}strict(e){return B.errToObj,new T({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,i)=>{var s,a;const n=((a=(s=this._def).errorMap)==null?void 0:a.call(s,t,i).message)??i.defaultError;return t.code==="unrecognized_keys"?{message:B.errToObj(e).message??n}:{message:n}}}:{}})}strip(){return new T({...this._def,unknownKeys:"strip"})}passthrough(){return new T({...this._def,unknownKeys:"passthrough"})}extend(e){return new T({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new T({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:S.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new T({...this._def,catchall:e})}pick(e){const t={};for(const i of L.objectKeys(e))e[i]&&this.shape[i]&&(t[i]=this.shape[i]);return new T({...this._def,shape:()=>t})}omit(e){const t={};for(const i of L.objectKeys(this.shape))e[i]||(t[i]=this.shape[i]);return new T({...this._def,shape:()=>t})}deepPartial(){return Qe(this)}partial(e){const t={};for(const i of L.objectKeys(this.shape)){const n=this.shape[i];e&&!e[i]?t[i]=n:t[i]=n.optional()}return new T({...this._def,shape:()=>t})}required(e){const t={};for(const i of L.objectKeys(this.shape))if(e&&!e[i])t[i]=this.shape[i];else{let s=this.shape[i];for(;s instanceof le;)s=s._def.innerType;t[i]=s}return new T({...this._def,shape:()=>t})}keyof(){return ai(L.objectKeys(this.shape))}}T.create=(A,e)=>new T({shape:()=>A,unknownKeys:"strip",catchall:he.create(),typeName:S.ZodObject,...C(e)});T.strictCreate=(A,e)=>new T({shape:()=>A,unknownKeys:"strict",catchall:he.create(),typeName:S.ZodObject,...C(e)});T.lazycreate=(A,e)=>new T({shape:A,unknownKeys:"strip",catchall:he.create(),typeName:S.ZodObject,...C(e)});class st extends U{_parse(e){const{ctx:t}=this._processInputParams(e),i=this._def.options;function n(s){for(const r of s)if(r.result.status==="valid")return r.result;for(const r of s)if(r.result.status==="dirty")return t.common.issues.push(...r.ctx.common.issues),r.result;const a=s.map(r=>new ie(r.ctx.common.issues));return y(t,{code:m.invalid_union,unionErrors:a}),R}if(t.common.async)return Promise.all(i.map(async s=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await s._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}})).then(n);{let s;const a=[];for(const o of i){const l={...t,common:{...t.common,issues:[]},parent:null},c=o._parseSync({data:t.data,path:t.path,parent:l});if(c.status==="valid")return c;c.status==="dirty"&&!s&&(s={result:c,ctx:l}),l.common.issues.length&&a.push(l.common.issues)}if(s)return t.common.issues.push(...s.ctx.common.issues),s.result;const r=a.map(o=>new ie(o));return y(t,{code:m.invalid_union,unionErrors:r}),R}}get options(){return this._def.options}}st.create=(A,e)=>new st({options:A,typeName:S.ZodUnion,...C(e)});function Pt(A,e){const t=re(A),i=re(e);if(A===e)return{valid:!0,data:A};if(t===k.object&&i===k.object){const n=L.objectKeys(e),s=L.objectKeys(A).filter(r=>n.indexOf(r)!==-1),a={...A,...e};for(const r of s){const o=Pt(A[r],e[r]);if(!o.valid)return{valid:!1};a[r]=o.data}return{valid:!0,data:a}}else if(t===k.array&&i===k.array){if(A.length!==e.length)return{valid:!1};const n=[];for(let s=0;s<A.length;s++){const a=A[s],r=e[s],o=Pt(a,r);if(!o.valid)return{valid:!1};n.push(o.data)}return{valid:!0,data:n}}else return t===k.date&&i===k.date&&+A==+e?{valid:!0,data:A}:{valid:!1}}class at extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e),n=(s,a)=>{if(sA(s)||sA(a))return R;const r=Pt(s.value,a.value);return r.valid?((aA(s)||aA(a))&&t.dirty(),{status:t.value,value:r.data}):(y(i,{code:m.invalid_intersection_types}),R)};return i.common.async?Promise.all([this._def.left._parseAsync({data:i.data,path:i.path,parent:i}),this._def.right._parseAsync({data:i.data,path:i.path,parent:i})]).then(([s,a])=>n(s,a)):n(this._def.left._parseSync({data:i.data,path:i.path,parent:i}),this._def.right._parseSync({data:i.data,path:i.path,parent:i}))}}at.create=(A,e,t)=>new at({left:A,right:e,typeName:S.ZodIntersection,...C(t)});class be extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==k.array)return y(i,{code:m.invalid_type,expected:k.array,received:i.parsedType}),R;if(i.data.length<this._def.items.length)return y(i,{code:m.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),R;!this._def.rest&&i.data.length>this._def.items.length&&(y(i,{code:m.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const s=[...i.data].map((a,r)=>{const o=this._def.items[r]||this._def.rest;return o?o._parse(new de(i,a,i.path,r)):null}).filter(a=>!!a);return i.common.async?Promise.all(s).then(a=>W.mergeArray(t,a)):W.mergeArray(t,s)}get items(){return this._def.items}rest(e){return new be({...this._def,rest:e})}}be.create=(A,e)=>{if(!Array.isArray(A))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new be({items:A,typeName:S.ZodTuple,rest:null,...C(e)})};class pA extends U{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==k.map)return y(i,{code:m.invalid_type,expected:k.map,received:i.parsedType}),R;const n=this._def.keyType,s=this._def.valueType,a=[...i.data.entries()].map(([r,o],l)=>({key:n._parse(new de(i,r,i.path,[l,"key"])),value:s._parse(new de(i,o,i.path,[l,"value"]))}));if(i.common.async){const r=new Map;return Promise.resolve().then(async()=>{for(const o of a){const l=await o.key,c=await o.value;if(l.status==="aborted"||c.status==="aborted")return R;(l.status==="dirty"||c.status==="dirty")&&t.dirty(),r.set(l.value,c.value)}return{status:t.value,value:r}})}else{const r=new Map;for(const o of a){const l=o.key,c=o.value;if(l.status==="aborted"||c.status==="aborted")return R;(l.status==="dirty"||c.status==="dirty")&&t.dirty(),r.set(l.value,c.value)}return{status:t.value,value:r}}}}pA.create=(A,e,t)=>new pA({valueType:e,keyType:A,typeName:S.ZodMap,...C(t)});class Ze extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.parsedType!==k.set)return y(i,{code:m.invalid_type,expected:k.set,received:i.parsedType}),R;const n=this._def;n.minSize!==null&&i.data.size<n.minSize.value&&(y(i,{code:m.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),t.dirty()),n.maxSize!==null&&i.data.size>n.maxSize.value&&(y(i,{code:m.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),t.dirty());const s=this._def.valueType;function a(o){const l=new Set;for(const c of o){if(c.status==="aborted")return R;c.status==="dirty"&&t.dirty(),l.add(c.value)}return{status:t.value,value:l}}const r=[...i.data.values()].map((o,l)=>s._parse(new de(i,o,i.path,l)));return i.common.async?Promise.all(r).then(o=>a(o)):a(r)}min(e,t){return new Ze({...this._def,minSize:{value:e,message:B.toString(t)}})}max(e,t){return new Ze({...this._def,maxSize:{value:e,message:B.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Ze.create=(A,e)=>new Ze({valueType:A,minSize:null,maxSize:null,typeName:S.ZodSet,...C(e)});class gA extends U{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}gA.create=(A,e)=>new gA({getter:A,typeName:S.ZodLazy,...C(e)});class mA extends U{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return y(t,{received:t.data,code:m.invalid_literal,expected:this._def.value}),R}return{status:"valid",value:e.data}}get value(){return this._def.value}}mA.create=(A,e)=>new mA({value:A,typeName:S.ZodLiteral,...C(e)});function ai(A,e){return new De({values:A,typeName:S.ZodEnum,...C(e)})}class De extends U{constructor(){super(...arguments),Me.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),i=this._def.values;return y(t,{expected:L.joinValues(i),received:t.parsedType,code:m.invalid_type}),R}if(it(this,Me,"f")||ii(this,Me,new Set(this._def.values),"f"),!it(this,Me,"f").has(e.data)){const t=this._getOrReturnCtx(e),i=this._def.values;return y(t,{received:t.data,code:m.invalid_enum_value,options:i}),R}return K(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return De.create(e,{...this._def,...t})}exclude(e,t=this._def){return De.create(this.options.filter(i=>!e.includes(i)),{...this._def,...t})}}Me=new WeakMap;De.create=ai;class bA extends U{constructor(){super(...arguments),Le.set(this,void 0)}_parse(e){const t=L.getValidEnumValues(this._def.values),i=this._getOrReturnCtx(e);if(i.parsedType!==k.string&&i.parsedType!==k.number){const n=L.objectValues(t);return y(i,{expected:L.joinValues(n),received:i.parsedType,code:m.invalid_type}),R}if(it(this,Le,"f")||ii(this,Le,new Set(L.getValidEnumValues(this._def.values)),"f"),!it(this,Le,"f").has(e.data)){const n=L.objectValues(t);return y(i,{received:i.data,code:m.invalid_enum_value,options:n}),R}return K(e.data)}get enum(){return this._def.values}}Le=new WeakMap;bA.create=(A,e)=>new bA({values:A,typeName:S.ZodNativeEnum,...C(e)});class rt extends U{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==k.promise&&t.common.async===!1)return y(t,{code:m.invalid_type,expected:k.promise,received:t.parsedType}),R;const i=t.parsedType===k.promise?t.data:Promise.resolve(t.data);return K(i.then(n=>this._def.type.parseAsync(n,{path:t.path,errorMap:t.common.contextualErrorMap})))}}rt.create=(A,e)=>new rt({type:A,typeName:S.ZodPromise,...C(e)});class Ee extends U{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===S.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:i}=this._processInputParams(e),n=this._def.effect||null,s={addIssue:a=>{y(i,a),a.fatal?t.abort():t.dirty()},get path(){return i.path}};if(s.addIssue=s.addIssue.bind(s),n.type==="preprocess"){const a=n.transform(i.data,s);if(i.common.async)return Promise.resolve(a).then(async r=>{if(t.value==="aborted")return R;const o=await this._def.schema._parseAsync({data:r,path:i.path,parent:i});return o.status==="aborted"?R:o.status==="dirty"||t.value==="dirty"?Ue(o.value):o});{if(t.value==="aborted")return R;const r=this._def.schema._parseSync({data:a,path:i.path,parent:i});return r.status==="aborted"?R:r.status==="dirty"||t.value==="dirty"?Ue(r.value):r}}if(n.type==="refinement"){const a=r=>{const o=n.refinement(r,s);if(i.common.async)return Promise.resolve(o);if(o instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return r};if(i.common.async===!1){const r=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});return r.status==="aborted"?R:(r.status==="dirty"&&t.dirty(),a(r.value),{status:t.value,value:r.value})}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(r=>r.status==="aborted"?R:(r.status==="dirty"&&t.dirty(),a(r.value).then(()=>({status:t.value,value:r.value}))))}if(n.type==="transform")if(i.common.async===!1){const a=this._def.schema._parseSync({data:i.data,path:i.path,parent:i});if(!ke(a))return a;const r=n.transform(a.value,s);if(r instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:r}}else return this._def.schema._parseAsync({data:i.data,path:i.path,parent:i}).then(a=>ke(a)?Promise.resolve(n.transform(a.value,s)).then(r=>({status:t.value,value:r})):a);L.assertNever(n)}}Ee.create=(A,e,t)=>new Ee({schema:A,typeName:S.ZodEffects,effect:e,...C(t)});Ee.createWithPreprocess=(A,e,t)=>new Ee({schema:e,effect:{type:"preprocess",transform:A},typeName:S.ZodEffects,...C(t)});class le extends U{_parse(e){return this._getType(e)===k.undefined?K(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}le.create=(A,e)=>new le({innerType:A,typeName:S.ZodOptional,...C(e)});class Se extends U{_parse(e){return this._getType(e)===k.null?K(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Se.create=(A,e)=>new Se({innerType:A,typeName:S.ZodNullable,...C(e)});class kt extends U{_parse(e){const{ctx:t}=this._processInputParams(e);let i=t.data;return t.parsedType===k.undefined&&(i=this._def.defaultValue()),this._def.innerType._parse({data:i,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}kt.create=(A,e)=>new kt({innerType:A,typeName:S.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...C(e)});class Bt extends U{_parse(e){const{ctx:t}=this._processInputParams(e),i={...t,common:{...t.common,issues:[]}},n=this._def.innerType._parse({data:i.data,path:i.path,parent:{...i}});return At(n)?n.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ie(i.common.issues)},input:i.data})})):{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new ie(i.common.issues)},input:i.data})}}removeCatch(){return this._def.innerType}}Bt.create=(A,e)=>new Bt({innerType:A,typeName:S.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...C(e)});class wA extends U{_parse(e){if(this._getType(e)!==k.nan){const i=this._getOrReturnCtx(e);return y(i,{code:m.invalid_type,expected:k.nan,received:i.parsedType}),R}return{status:"valid",value:e.data}}}wA.create=A=>new wA({typeName:S.ZodNaN,...C(A)});class al extends U{_parse(e){const{ctx:t}=this._processInputParams(e),i=t.data;return this._def.type._parse({data:i,path:t.path,parent:t})}unwrap(){return this._def.type}}class Lt extends U{_parse(e){const{status:t,ctx:i}=this._processInputParams(e);if(i.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:i.data,path:i.path,parent:i});return s.status==="aborted"?R:s.status==="dirty"?(t.dirty(),Ue(s.value)):this._def.out._parseAsync({data:s.value,path:i.path,parent:i})})();{const n=this._def.in._parseSync({data:i.data,path:i.path,parent:i});return n.status==="aborted"?R:n.status==="dirty"?(t.dirty(),{status:"dirty",value:n.value}):this._def.out._parseSync({data:n.value,path:i.path,parent:i})}}static create(e,t){return new Lt({in:e,out:t,typeName:S.ZodPipeline})}}class Dt extends U{_parse(e){const t=this._def.innerType._parse(e),i=n=>(ke(n)&&(n.value=Object.freeze(n.value)),n);return At(t)?t.then(n=>i(n)):i(t)}unwrap(){return this._def.innerType}}Dt.create=(A,e)=>new Dt({innerType:A,typeName:S.ZodReadonly,...C(e)});T.lazycreate;var S;(function(A){A.ZodString="ZodString",A.ZodNumber="ZodNumber",A.ZodNaN="ZodNaN",A.ZodBigInt="ZodBigInt",A.ZodBoolean="ZodBoolean",A.ZodDate="ZodDate",A.ZodSymbol="ZodSymbol",A.ZodUndefined="ZodUndefined",A.ZodNull="ZodNull",A.ZodAny="ZodAny",A.ZodUnknown="ZodUnknown",A.ZodNever="ZodNever",A.ZodVoid="ZodVoid",A.ZodArray="ZodArray",A.ZodObject="ZodObject",A.ZodUnion="ZodUnion",A.ZodDiscriminatedUnion="ZodDiscriminatedUnion",A.ZodIntersection="ZodIntersection",A.ZodTuple="ZodTuple",A.ZodRecord="ZodRecord",A.ZodMap="ZodMap",A.ZodSet="ZodSet",A.ZodFunction="ZodFunction",A.ZodLazy="ZodLazy",A.ZodLiteral="ZodLiteral",A.ZodEnum="ZodEnum",A.ZodEffects="ZodEffects",A.ZodNativeEnum="ZodNativeEnum",A.ZodOptional="ZodOptional",A.ZodNullable="ZodNullable",A.ZodDefault="ZodDefault",A.ZodCatch="ZodCatch",A.ZodPromise="ZodPromise",A.ZodBranded="ZodBranded",A.ZodPipeline="ZodPipeline",A.ZodReadonly="ZodReadonly"})(S||(S={}));const J=oe.create,ct=Be.create;he.create;const ue=ee.create,te=T.create;T.strictCreate;st.create;at.create;be.create;const Tt=De.create;rt.create;le.create;Se.create;const rl=te({id:J().describe("対応する入力要素のid"),ratio:ct().describe("兄弟間でのratio(weightに比例する)")}).describe("横方向要素、1~2要素 すべてのコマの重要度が低い場合は3要素も許される"),ol=te({columns:ue(rl),ratio:ct().describe("兄弟間でのratio(weightに比例する)")}).describe("縦方向要素(段)、1~3要素"),ll=te({rows:ue(ol)}).describe("ページ"),cl=Tt(["4koma","standard"]).describe("基本フォーマット。作風から適切な方を選べ"),dl=te({name:J().describe("キャラクター名"),appearance:J().describe("キャラクターの容姿。脇役のappearanceは簡潔にすること"),themeColor:J().describe("キャラクターのテーマカラー")}).describe("キャラクター一覧。キャラクタードキュメントにない脇役も列挙しろ"),hl=te({owner:J(),speech:J().describe("セリフは10文字前後までとしろ。また、適切に改行コード(\\n)を入れ、1行5文字程度に収めろ"),color:J().describe("セリフの色。話者のテーマカラー"),shape:Tt(["rounded","square","ellipse","polygon","shout","soft","none"]).describe("セリフの形。基本はsoft。キャラクタの感情にあわせろ。使ってよいのはsoft, polygon, shout, noneのいずれか。")}).describe("キャラクターのセリフ"),ul=te({composition:J().describe("そのコマの視覚情報。画像生成AIに渡されるプロンプト。セリフや音声情報を含めるな。キャラクターはいなくてもよい。キャラクターのリアクションはオーバーにし、コマごとに大きく変化させろ。"),camera:J().describe("そのコマのカメラ。例: from side, from back, Dutch angle shot, dramatic angle, from side, from back, Dutch angle shot, dramatic angle, top-down view, aerial shot, birds-eye-view shot, top angle view, from above, wide angle, eye-level shot, front view, straight-on, from below, etc."),bubbles:ue(hl).describe("そのコマのセリフ。セリフがない場合は空配列にしろ"),weight:ct().describe("そのコマの重要度。0~1の範囲で指定しろ。0が最も不要で、1が最も重要")}),fl=te({panels:ue(ul),layout:ll.describe("コマの配置").nullable().default(null)}),pl=te({format:cl,actors:ue(dl),pages:ue(fl)}),ri=te({name:J(),personality:J(),appearance:J(),themeColor:J().describe("テーマカラー。#ffffffff形式"),ulid:J()});ue(ri);te({theme:J(),characters:ue(ri),plot:J(),scenario:J(),storyboard:pl.nullable(),critique:J(),pageNumber:ct().nullable(),format:Tt(["4koma","standard"])});const gl={paperSize:[840,1188],paperColor:"#FFFFFF",frameColor:"#000000",frameWidth:2,templateName:"standard"};function ml(){return{theme:"",characters:[],plot:"",scenario:"",critique:"",storyboard:null,pageNumber:null,format:"standard"}}async function bl(A,e){const t=new Uint8Array(await A.arrayBuffer()),i=gi.decode(t),n={};if("images"in i&&i.images){e(0);for(const l in i.images){const c=new Blob([i.images[l]],{type:"image/png"}),d=URL.createObjectURL(c),f=new Image;f.src=d,await f.decode(),URL.revokeObjectURL(d);const u=ft(f);u.envelopeFileId=l,n[l]={type:"image",data:u},e(Object.keys(n).length/Object.keys(i.images).length)}}if("medias"in i&&i.medias){e(0);for(const l in i.medias){const c=i.medias[l],d=new Blob([c.data],{type:c.type==="image"?`image/${c.format??"png"}`:"video/mp4"}),f=URL.createObjectURL(d);if(c.type==="image"){const u=new Image;u.src=f,await u.decode(),URL.revokeObjectURL(f);const g=ft(u);g.envelopeFileId=l,n[l]={type:"image",data:g}}else{const u=document.createElement("video");u.src=f,await vA(u),n[l]={type:"video",data:u}}e(Object.keys(n).length/Object.keys(i.medias).length)}}const s=i.notebook?await Uo(i.notebook,async l=>n[l].data):ml(),a=i.attributes??null;console.log("readEnvelope",i.attributes,a);const r={revision:{id:"not visited",revision:1,prefix:"envelope-"},pages:[],history:{entries:[],cursor:0},direction:i.direction,wrapMode:i.wrapMode,chatLogs:[],notebook:s,attributes:{publishUrl:null,...a??{}},newPageProperty:i.newPageProperty??{...gl}},o=async l=>n[l].data;for(const l of i.pages){const c=await ti(l.paperSize,l.frameTree,o),d=await qo(l.paperSize,l.bubbles,o),f={id:l.id??Pe.ulid(),frameTree:c,bubbles:d,paperSize:l.paperSize,paperColor:l.paperColor,frameColor:l.frameColor,frameWidth:l.frameWidth,source:null};r.pages.push(f)}return r}class oi{constructor(e,t,i,n){this.arrayLayer=e,this.layeredCanvas=t,this.focusKeeper=i,this.marks=n}cleanup(){this.layeredCanvas.cleanup()}focusToPage(e,t=1){const i=this.layeredCanvas.viewport,[n,s]=i.getCanvasSize(),a=this.arrayLayer.array.papers[e],[r,o]=a.paper.size,l=Math.min(Math.max(1,n)/r,Math.max(1,s)/o)*t,c=a.center;i.scale=l,i.translate=[-c[0]*l,-c[1]*l],i.dirty=!0,this.layeredCanvas.redraw()}getScale(){return this.layeredCanvas.viewport.scale}resetFontCache(){var e,t;for(const i of this.arrayLayer.array.papers)(t=(e=i.paper)==null?void 0:e.findLayer($A))==null||t.resetCache()}}function wl(A,e,t=0,i=-1){console.log("Building renderer...");const n=new Ji(A,()=>{}),s=new Ro,a=new Vi(n,!0),r=new EA(a.viewport,()=>{},()=>{},s);a.rootPaper.addLayer(r);let o=[];const l=i<0?e.pages.length:t+i;for(let v=t;v<l;v++){const b=e.pages[v];for(const w of b.bubbles)w.pageNumber=v;o.push(vl(e,b,s))}const c=Pl(e.direction),{fold:d,gapX:f,gapY:u}=yl(e.wrapMode),g=[],p=new xr(o,g,d,f,u,c,()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{});return a.rootPaper.addLayer(p),a.mode="viewer",new oi(p,a,s,g)}function Ql(A){A.cleanup()}function vl(A,e,t){const i=new BA(e.paperSize,!1),n=new $A(!0);n.setFrameTree(e.frameTree),n.setBubbles(e.bubbles),i.addLayer(n);const s=new TA(e.frameTree,e.bubbles,a=>{console.log(a)},t,A.attributes.showVideoPlayButton??!0,A.attributes.showVideoDottedBorder??!0);return i.addLayer(s),e.frameTree.bgColor=e.paperColor,e.frameTree.borderColor=e.frameColor,e.frameTree.borderWidth=e.frameWidth,i}function yl(A){switch(A){case"none":return{fold:0,gapX:100,gapY:0};case"two-pages":return{fold:2,gapX:100,gapY:200};case"one-page":return{fold:1,gapX:0,gapY:0}}}function Pl(A){switch(A){case"left-to-right":return 1;case"right-to-left":return-1}}function kl(A){const e=new Set;for(let t of A.pages)for(let i of t.bubbles)e.add(JSON.stringify({family:i.fontFamily,weight:i.fontWeight}));return[...e].map(t=>JSON.parse(t))}const li={源暎アンチック:"GenEiAntiqueNv5-M",源暎エムゴ:"GenEiMGothic2-Black",源暎ぽっぷる:"GenEiPOPle-Bk",源暎ラテゴ:"GenEiLateMinN_v2",源暎ラテミン:"GenEiLateMinN_v2",源暎きわみゴ:"GenEiKiwamiGo",ふい字:"HuiFont29",まきばフォント:"MakibaFont13"};function ci(A){return li[A]!==void 0}function Bl(A){return!ci(A)}const QA=new Set;async function di(A,e=["400"]){try{const t=`${A}-${e.join("-")}`;if(QA.has(t))return;const i=A.replace(/\s+/g,"+"),n=e.join(";"),s=`https://fonts.googleapis.com/css2?family=${i}:wght@${n}&display=swap`,r=await(await fetch(s,{headers:{"User-Agent":navigator.userAgent}})).text(),o=Array.from(r.matchAll(/src: url\((.+?)\) format\('woff2'\)/g));if(!o.length)throw new Error("No font URLs found in CSS");const l=o.map(c=>{const d=c[1],u=r.substring(0,c.index).split("}").slice(-1)[0].match(/font-weight: (\d+)/),g=u?u[1]:"400";return new FontFace(A,`url(${d})`,{weight:g,style:"normal"}).load().then(v=>(document.fonts.add(v),v))});await Promise.all(l),await document.fonts.ready,QA.add(t)}catch(t){throw console.error(`Failed to load font "${A}":`,t),t}}async function Dl(A,e=["400"]){try{await di(A,e),await document.fonts.ready;const t=e.map(i=>hi(A,i));await Promise.all(t),console.log(`Font "${A}" is fully loaded and ready for Canvas use`)}catch(t){throw console.error(`Failed to load font "${A}" for Canvas:`,t),t}}async function hi(A,e="400",t=20,i=50){const n="あいうえおABCDE12345",s="24px";function a(){const o=document.createElement("canvas").getContext("2d");o.font=`${e} ${s} "${A}"`;const l=o.measureText(n).width;o.font=`${e} ${s} serif`;const c=o.measureText(n).width;return l!==c}for(let r=0;r<t;r++){if(a())return console.log(`Font "${A}" ${e} is ready for Canvas`),!0;await new Promise(o=>setTimeout(o,i))}throw new Error(`Timeout waiting for font "${A}" ${e} to be ready for Canvas`)}exports.Renderer=oi;exports.buildRenderer=wl;exports.checkCanvasFontAvailable=hi;exports.destroyRenderer=Ql;exports.initPaperJs=$r;exports.isGoogleFont=Bl;exports.isLocalFont=ci;exports.listFonts=kl;exports.loadGoogleFont=di;exports.loadGoogleFontForCanvas=Dl;exports.localFonts=li;exports.readEnvelope=bl;
package/dist/index.es.js CHANGED
@@ -6592,37 +6592,39 @@ function hl() {
6592
6592
  }
6593
6593
  async function Cl(A, e) {
6594
6594
  const t = new Uint8Array(await A.arrayBuffer()), i = ci(t), n = {};
6595
- if (i.images) {
6595
+ if ("images" in i && i.images) {
6596
6596
  e(0);
6597
- for (const o in i.images) {
6598
- const l = new Blob([i.images[o]], { type: "image/png" }), c = URL.createObjectURL(l), d = new Image();
6599
- d.src = c, await d.decode(), URL.revokeObjectURL(c);
6600
- const f = ut(d);
6601
- f.envelopeFileId = o, n[o] = { type: "image", data: f }, e(Object.keys(n).length / Object.keys(i.images).length);
6597
+ for (const l in i.images) {
6598
+ const c = new Blob([i.images[l]], { type: "image/png" }), d = URL.createObjectURL(c), f = new Image();
6599
+ f.src = d, await f.decode(), URL.revokeObjectURL(d);
6600
+ const u = ut(f);
6601
+ u.envelopeFileId = l, n[l] = { type: "image", data: u }, e(Object.keys(n).length / Object.keys(i.images).length);
6602
6602
  }
6603
6603
  }
6604
- if (i.medias) {
6604
+ if ("medias" in i && i.medias) {
6605
6605
  e(0);
6606
- for (const o in i.medias) {
6607
- const l = i.medias[o], c = new Blob(
6608
- [l.data],
6606
+ for (const l in i.medias) {
6607
+ const c = i.medias[l], d = new Blob(
6608
+ [c.data],
6609
6609
  {
6610
- type: l.type === "image" ? `image/${l.format ?? "png"}` : "video/mp4"
6610
+ type: c.type === "image" ? `image/${c.format ?? "png"}` : "video/mp4"
6611
6611
  }
6612
- ), d = URL.createObjectURL(c);
6613
- if (l.type === "image") {
6614
- const f = new Image();
6615
- f.src = d, await f.decode(), URL.revokeObjectURL(d);
6616
- const u = ut(f);
6617
- u.envelopeFileId = o, n[o] = { type: "image", data: u };
6612
+ ), f = URL.createObjectURL(d);
6613
+ if (c.type === "image") {
6614
+ const u = new Image();
6615
+ u.src = f, await u.decode(), URL.revokeObjectURL(f);
6616
+ const g = ut(u);
6617
+ g.envelopeFileId = l, n[l] = { type: "image", data: g };
6618
6618
  } else {
6619
- const f = document.createElement("video");
6620
- f.src = d, await QA(f), n[o] = { type: "video", data: f };
6619
+ const u = document.createElement("video");
6620
+ u.src = f, await QA(u), n[l] = { type: "video", data: u };
6621
6621
  }
6622
6622
  e(Object.keys(n).length / Object.keys(i.medias).length);
6623
6623
  }
6624
6624
  }
6625
- const s = i.notebook ? await Io(i.notebook, async (o) => n[o].data) : hl(), a = {
6625
+ const s = i.notebook ? await Io(i.notebook, async (l) => n[l].data) : hl(), a = i.attributes ?? null;
6626
+ console.log("readEnvelope", i.attributes, a);
6627
+ const r = {
6626
6628
  revision: { id: "not visited", revision: 1, prefix: "envelope-" },
6627
6629
  pages: [],
6628
6630
  history: { entries: [], cursor: 0 },
@@ -6630,23 +6632,23 @@ async function Cl(A, e) {
6630
6632
  wrapMode: i.wrapMode,
6631
6633
  chatLogs: [],
6632
6634
  notebook: s,
6633
- attributes: { publishUrl: null, showVideoPlayButton: !0, showVideoDottedBorder: !0 },
6635
+ attributes: { publishUrl: null, ...a ?? {} },
6634
6636
  newPageProperty: i.newPageProperty ?? { ...dl }
6635
- }, r = async (o) => n[o].data;
6636
- for (const o of i.pages) {
6637
- const l = await ei(o.paperSize, o.frameTree, r), c = await So(o.paperSize, o.bubbles, r), d = {
6638
- id: o.id ?? Pe(),
6639
- frameTree: l,
6640
- bubbles: c,
6641
- paperSize: o.paperSize,
6642
- paperColor: o.paperColor,
6643
- frameColor: o.frameColor,
6644
- frameWidth: o.frameWidth,
6637
+ }, o = async (l) => n[l].data;
6638
+ for (const l of i.pages) {
6639
+ const c = await ei(l.paperSize, l.frameTree, o), d = await So(l.paperSize, l.bubbles, o), f = {
6640
+ id: l.id ?? Pe(),
6641
+ frameTree: c,
6642
+ bubbles: d,
6643
+ paperSize: l.paperSize,
6644
+ paperColor: l.paperColor,
6645
+ frameColor: l.frameColor,
6646
+ frameWidth: l.frameWidth,
6645
6647
  source: null
6646
6648
  };
6647
- a.pages.push(d);
6649
+ r.pages.push(f);
6648
6650
  }
6649
- return a;
6651
+ return r;
6650
6652
  }
6651
6653
  class ul {
6652
6654
  constructor(e, t, i, n) {
@@ -80,6 +80,10 @@ export type SerializedBookAttributes = {
80
80
  showVideoPlayButton?: boolean;
81
81
  showVideoDottedBorder?: boolean;
82
82
  };
83
+ export type EnvelopeBookAttributes = {
84
+ showVideoPlayButton?: boolean;
85
+ showVideoDottedBorder?: boolean;
86
+ };
83
87
  export type SerializedCharacter = {
84
88
  name: string;
85
89
  personality: string;
@@ -1,22 +1,30 @@
1
1
  import { MediaType } from './imagePacking';
2
- import { Book, WrapMode, ReadingDirection, SerializedPage, SerializedNotebook, SerializedNewPageProperty, NotebookLocal } from './book';
3
- export type EnvelopedBook = {
2
+ import { Book, WrapMode, ReadingDirection, SerializedPage, SerializedNotebook, SerializedNewPageProperty, NotebookLocal, EnvelopeBookAttributes } from './book';
3
+ type EnvelopedBookBase = {
4
4
  pages: SerializedPage[];
5
5
  direction: ReadingDirection;
6
6
  wrapMode: WrapMode;
7
- images?: {
7
+ notebook: SerializedNotebook | null;
8
+ newPageProperty: SerializedNewPageProperty | null;
9
+ attributes?: EnvelopeBookAttributes | null;
10
+ };
11
+ export type EnvelopedBookWithImages = EnvelopedBookBase & {
12
+ images: {
8
13
  [fileId: string]: Uint8Array;
9
14
  };
10
- medias?: {
15
+ medias?: undefined;
16
+ };
17
+ export type EnvelopedBookWithMedias = EnvelopedBookBase & {
18
+ medias: {
11
19
  [fileId: string]: {
12
20
  type: MediaType;
13
21
  data: Uint8Array;
14
22
  format?: string;
15
23
  };
16
24
  };
17
- notebook: SerializedNotebook | null;
18
- newPageProperty: SerializedNewPageProperty | null;
25
+ images?: undefined;
19
26
  };
27
+ export type EnvelopedBook = EnvelopedBookWithImages | EnvelopedBookWithMedias;
20
28
  export type CanvasBag = {
21
29
  [fileId: string]: {
22
30
  type: MediaType;
@@ -35,3 +43,4 @@ export type OldEnvelopedBook = {
35
43
  notebook: NotebookLocal | null;
36
44
  };
37
45
  export declare function readOldEnvelope(json: string): Promise<Book>;
46
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "manga-renderer",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "A renderer for package files output from FramePlanner",
5
5
  "files": [
6
6
  "dist"