manga-renderer 1.0.35 → 1.0.37
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 +1 -1
- package/dist/index.es.js +152 -152
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -10,4 +10,4 @@ Ctrlを押しているとコピー`],null,v);this.insertIcons.push(b)}this.calcu
|
|
|
10
10
|
,.:;?!-" ')]}
|
|
11
11
|
`),$r=2,aA=2;function*zA(i,e,t,A,n,s){let a=A;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<aA;f++){const h=o-1-f;if(h<0||!n(r[h]))return f}return aA}let d=null;for(;l()!=null;){if(o===0){o=1,d=1;continue}else{const{size:g,wrap:v}=i(r.slice(0,o+1));if(!v){d=g,o++;continue}}e!=null&&(d=e);let h=c();if(h===0)for(let g=0;g<$r;g++){const v=l();if(v===null||!s(v))break;o++}else o-=h,o===0&&(o=1);const p=r.splice(0,o);yield{index:a,buffer:p,size:d,wrap:!0},a+=p.length,o=0}0<r.length&&(yield{index:a,buffer:r,size:d,wrap:!1})}function eo(i,e,t){let A=[],n=0;function*s(r){let o=0;for(;o<r.length;)if(XA(r,o)){const l=to(r,o);o+=l.length,yield l}else yield r.charAt(o),o++}for(let r of t.split(`
|
|
12
12
|
`))A.push(...zA(i,e,s(r),n,Rt.has.bind(Rt),Ct.has.bind(Ct))),n+=r.length+1;return A.map(({index:r,buffer:o,size:l,wrap:c})=>({index:r,text:o.join(""),size:l,wrap:c}))}function XA(i,e){const t=String.fromCodePoint(i.codePointAt(e)||0);return new RegExp("\\p{Emoji}","u").test(t)}function to(i,e){let t=e+1;return i.codePointAt(e)&&i.codePointAt(e)>65535&&t++,i.slice(e,t)}function Ao(i){const e=/\{([^{}]+)\|([^{}]+)\}/,t=/\[([^\[\]]+)\]\(([^\(\)]+)\)/,A=/\<\<([^<>]+)\>\>/;function n(s,a,r,o){const l=[];let c=s;for(;c;){const d=c.match(e),f=c.match(t),h=c.match(A),p=[{type:"color",match:d},{type:"ruby",match:f},{type:"romanHanging",match:h}].filter(g=>g.match).sort((g,v)=>g.match.index-v.match.index);if(p.length>0){const{type:g,match:v}=p[0],[m,b,D]=v,w=v.index;switch(w>0&&l.push({content:c.slice(0,w),color:a,size:r,ruby:o}),g){case"color":const y=D.split(",").map(R=>R.trim()),k=y[0]||void 0,S=y[1]?parseFloat(y[1]):void 0;l.push(...n(b,k||a,S||r,o));break;case"ruby":l.push(...n(b,a,r,D));break;case"romanHanging":l.push({content:b,color:a,size:r,ruby:o,romanHanging:!0});break}c=c.slice(w+m.length)}else l.push({content:c,color:a,size:r,ruby:o}),c=""}return l}return n(i)}function YA(i){return/^[\u0020-\u007E\uFF61-\uFF9F]$/.test(i)}function io(i,e){const t=new RegExp("(\\p{Emoji}(\\uFE0F|\\u200D\\p{Emoji})*)","u"),A=i.slice(e).match(t);return A&&A.index===0&&!YA(A[0])?A[0]:i.length>e+1&&(i[e+1]==="゙"||i[e+1]==="゚")?i.slice(e,e+2):null}function*rA(i){let e="",t=!1,A=0;for(;A<i.length;){const n=i[A];if(YA(n))t?e+=n:(e&&(yield e),e=n,t=!0),A++;else{const s=io(i,A);s?(e&&(yield e),yield s,e="",t=!1,A+=s.length):(e&&(yield e),yield n,e="",t=!1,A++)}}e&&(yield e)}function*no(i){for(const e of i){const t=[...rA(e.content)];if(e.ruby)yield{chars:t,color:e.color,size:e.size,ruby:[...rA(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 A of t)yield{chars:[A],color:e.color,size:e.size,romanHanging:e.romanHanging}}}function so(i,e,t,A,n,s,a,r,o,l){o||(o=Gt(i,t.height,A,n,s,l));let c=t.x+t.width-n*.5;for(const d of o.verticalLines){let f=0,h=null;for(const p of d){let g,v;const m=p.size??1;if({lineH:f,prev:h,startH:g,endH:v}=oA(i,t,c,f,s,e,p,m,!1,h),p.ruby){const D=(v-g)/p.ruby.length,w=c+n*r,y={chars:p.ruby,color:p.color};oA(i,t,w,g,D,e,y,a,!0,null)}}c-=n}}function oA(i,e,t,A,n,s,a,r,o,l){const c=n*(o?1:r);let d=null,f=null;if(a.romanHanging){const g=a.chars.join(""),v=i.measureText(g),m=v.width,b=v.actualBoundingBoxAscent+v.actualBoundingBoxDescent,D=n*.15;return d===null&&(d=A),f=A+m,i.save(),i.translate(t-b*.5,e.y+A+D),i.rotate(90*Math.PI/180),i.scale(r,r),s==="fill"?(a.color&&(i.fillStyle=a.color),i.fillText(g,0,0)):s==="stroke"&&(a.color&&(i.strokeStyle=a.color),i.strokeText(g,0,0)),i.restore(),{lineH:A+m,prev:l,startH:d,endH:f}}function h(g,v,m,b,D,w){const y=i.measureText(w),k=y.width;y.actualBoundingBoxAscent+y.actualBoundingBoxDescent,d===null&&(d=A+n-y.actualBoundingBoxAscent),f=A+n+y.actualBoundingBoxDescent;const S=t,R=(1-r)*n*.15,T=e.y+A+c*.5+R;i.save(),i.translate(S,T),i.scale(r,r),i.translate(v*n,m*n),i.rotate(g*Math.PI/180),i.scale(b,D),i.translate(-k*.5,n*.5),s==="fill"?(a.color&&(i.fillStyle=a.color),i.fillText(w,0,0)):s==="stroke"&&(a.color&&(i.strokeStyle=a.color),i.strokeText(w,0,0)),i.restore()}function p(g,v,m){h(0,g,v,1,1,m)}for(const g of a.chars){switch(A+=jA(l,g)*n*r,!0){case/[、。]/.test(g):p(.6,-.6,g);break;case/[“]/.test(g):h(0,.5,.5,-1,1,"〝");break;case/[”]/.test(g):h(0,-.4,-.4,-1,1,"〟");break;case/[ぁぃぅぇぉっゃゅょゎァィゥェォッャュョヵヶ]/.test(g):p(.1,-.1,g);break;case/[「『:;]/.test(g):h(90,.2,.3,1,1,g);break;case/[」』]/.test(g):h(90,.1,-.1,1,1,g);break;case/[<(【〔≪{]/.test(g):h(90,.15,.15,1,1,g);break;case/[>)】〕≫}]/.test(g):h(90,.15,.15,1,1,g);break;case/[ー…―〰]/.test(g):h(90,-.1,.1,1,-1,g);break;case/[~〜]/.test(g):h(90,.1,.1,1,1,g);break;case XA(g,0):p(0,0,g);break;default:p(0,0,g);break}A+=c,l=g}return{lineH:A,prev:l,startH:d,endH:f}}function Gt(i,e,t,A,n,s){s||(e=1/0);function a(l){let c=0,d=null;for(const f of l)if(f.romanHanging){const h=i.measureText(f.chars.join(""));c+=h.width}else for(const h of f.chars){c+=jA(d,h);const p=f.size??1;c+=n*p,d=h}return c}const r=t.split(`
|
|
13
|
-
`),o=[];for(const l of r){const c=Ao(l),d=no(c),f=zA(h=>{const p=a(h);return{size:p,wrap:e<p}},e,d,0,h=>h&&h.chars&&h.chars.length==1&&Rt.has(h.chars[0]),h=>h&&h.chars&&h.chars.length==1&&Ct.has(h.chars[0]));for(const h of f)o.push({size:h.size,text:h.buffer})}return{height:o.reduce((l,c)=>Math.max(l,c.size),0),width:A*o.length,verticalLines:o.map(l=>l.text)}}function jA(i,e){return i?/[、。」』)】〕”]/.test(i)?/[「『(【〔“]/.test(e)||/[、。]/.test(e)?-.5:-.4:/[「『(【〔“]/.test(e)?-.4:0:/[「『(【〔“]/.test(e)?-.3:0}function lA(i,e,t,A,n,s,a,r,o,l,c){i==="v"?so(e,t,A,n,s,a,r,o,l,c):ao(e,t,A,n,s,a,l,c)}function ao(i,e,t,A,n,s,a,r){a||(a=Jt(i,t.width,A,n,s,r));for(let[o,l]of a.horizontalLines.entries())e==="fill"?i.fillText(l.text,t.x,t.y+n*o+n*.8):e==="stroke"&&i.strokeText(l.text,t.x,t.y+n*o+n*.8)}function ro(i,e,t,A,n,s,a,r){return i==="v"?Gt(e,A*.85,n,s,a,r):Jt(e,t*.85,n,s,a,r)}function Jt(i,e,t,A,n,s){s||(e=1/0);const a=eo(r=>{const o=i.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:A*a.length,horizontalLines:a}}const nt=48,U=10;class q{constructor(){u(this,"n_p0");u(this,"n_p1");u(this,"n_offset");u(this,"rotation");u(this,"text");u(this,"shape");u(this,"embedded");u(this,"fontStyle");u(this,"fontWeight");u(this,"n_fontSize");u(this,"charSkip");u(this,"lineSkip");u(this,"fontFamily");u(this,"direction");u(this,"fontColor");u(this,"fillColor");u(this,"strokeColor");u(this,"n_strokeWidth");u(this,"outlineColor");u(this,"n_outlineWidth");u(this,"autoNewline");u(this,"uuid");u(this,"parent");u(this,"creationContext");u(this,"filmStack");u(this,"scaleLock");u(this,"rubySize");u(this,"rubyDistance");u(this,"displayName");u(this,"optionContext");u(this,"pageNumber");u(this,"fontRenderVersion");u(this,"appearanceDelay");u(this,"hidesText");u(this,"prompt","");u(this,"gallery",[]);u(this,"renderInfo");this.reset(),this.n_p0=[0,0],this.n_p1=[.1,.1],this.text="empty",this.uuid=Se.ulid(),this.parent=null,this.creationContext=this.getStackTrace(),this.filmStack=new lt,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 lt,t.filmStack.films=this.filmStack.films.map(A=>A.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 A=.0011904761904761906,n=q.getUnit(e),s=(r,o,l)=>r??(o!=null?o*n:l*A),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??Se.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,A=(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:A(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:A(e.n_strokeWidth,1*t)?void 0:e.n_strokeWidth,outlineColor:e.outlineColor=="#000000FF"?void 0:e.outlineColor,n_outlineWidth:A(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,A]=q.getPhysicalPoint(e,this.n_p0),[n,s]=q.getPhysicalPoint(e,this.n_p1);return[t,A,n-t,s-A]}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,A]=this.regularized(),[n,s]=q.getPhysicalPoint(e,t),[a,r]=q.getPhysicalPoint(e,A);return[n,s,a-n,r-s]}getPhysicalRegularizedBox(e){const[t,A]=this.regularized();return[q.getPhysicalPoint(e,t),q.getPhysicalPoint(e,A)]}hasEnoughSize(e){const t=this.getPhysicalRect(e);return nt<=t[2]&&nt<=t[3]}static enoughSize(e){return[Math.max(e[0],nt+1),Math.max(e[1],nt+1)]}setPhysicalCenter(e,t){const[A,n]=t,[s,a]=this.getPhysicalSize(e);this.n_p0=q.normalizedPosition(e,[A-s/2,n-a/2]),this.n_p1=q.normalizedPosition(e,[A+s/2,n+a/2])}setPhysicalSize(e,t){const A=[(this.n_p0[0]+this.n_p1[0])/2,(this.n_p0[1]+this.n_p1[1])/2];this.n_p0=[A[0]-t[0]/e[0]/2,A[1]-t[1]/e[1]/2],this.n_p1=[A[0]+t[0]/e[0]/2,A[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),A=q.enoughSize([t[2],t[3]]);this.setPhysicalSize(e,A)}contains(e,t){const[A,n]=t,[s,a]=q.getPhysicalPoint(e,this.n_p0),[r,o]=q.getPhysicalPoint(e,this.n_p1);return s<=A&&A<=r&&a<=n&&n<=o}getHandleAt(e,t){for(let A of Hr){const n=this.getHandleRect(e,A);if(Ni(n,t))return A}return null}getHandleRect(e,t){const[A,n,s,a]=this.getPhysicalRect(e);switch(t){case"topLeft":return[A-U,n-U,U*2,U*2];case"topRight":return[A+s-U,n-U,U*2,U*2];case"bottomLeft":return[A-U,n+a-U,U*2,U*2];case"bottomRight":return[A+s-U,n+a-U,U*2,U*2];case"top":return[A-U,n-U,s+U*2,U*2];case"bottom":return[A-U,n+a-U,s+U*2,U*2];case"left":return[A-U,n-U,U*2,a+U*2];case"right":return[A+s-U,n-U,U*2,a+U*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 cA[this.shape]}initOptions(){this.optionContext=q.getInitialOptions(this)}static getInitialOptions(e,t=!1){const A=cA[e.shape],n={};for(const s of Object.keys(A))A[s].init&&(n[s]=A[s].init(e),t&&A[s].sampleInit&&(n[s]=A[s].sampleInit(e)));return n}calculateFitSize(e){const t=this.getPhysicalFontSize(e),A=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=Gt(a,1/0,this.text,A,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=Jt(a,1/0,this.text,A,n,!1);r=[Math.floor(l.width*1.4),Math.floor(l.height*1.2)]}return console.log(r),q.enoughSize(r)}}const cA={rounded:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.7},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},square:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},ellipse:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>.1}},concentration:{lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:i=>200},lineLength:{label:"線の長さ",type:"number",min:1.05,max:1.5,step:.01,init:i=>1.3}},thought:{lineCount:{label:"線の本数",type:"number",min:100,max:600,step:1,init:i=>400},lineLength:{label:"線の長さ",type:"number",min:.05,max:.5,step:.01,init:i=>.3},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.2,step:.01,init:i=>.14},jitter:{label:"ジッター",type:"number",min:0,max:.5,step:.001,init:i=>.08},waveFrequency:{label:"ウェーブ周期",type:"number",min:8,max:64,step:1,init:i=>8},waveAmplitude:{label:"ウェーブ振幅",type:"number",min:0,max:.1,step:.001,init:i=>0}},polygon:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:i=>7},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.4},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},strokes:{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:i=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:i=>1.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0}},"double-strokes":{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:i=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:i=>1.25},interval:{label:"間隔",type:"number",min:.01,max:.2,step:.01,init:i=>.04},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0}},harsh:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:i=>.07},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:i=>15},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},shout:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>6,sampleInit:i=>6},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3,sampleInit:i=>3},bumpSharp:{label:"でっぱりの鋭さ",type:"number",min:.01,max:.5,step:.01,init:i=>.16,sampleInit:i=>.2},bumpCount:{label:"でっぱりの数",type:"number",min:4,max:20,step:1,init:i=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.5,sampleInit:i=>.2},depthJitter:{label:"鋭さジッター",type:"number",min:0,max:1.5,step:.01,init:i=>.5,sampleInit:i=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},soft:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:i=>.14},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:i=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.4},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:i=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},heart:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},diamond:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},arrow:{link:{hint:"結合",icon:"unite"},shaftWidth:{label:"軸の太さ",type:"number",min:0,max:1,step:.01,init:i=>.5},headLength:{label:"矢じりの長さ",type:"number",min:0,max:1,step:.01,init:i=>.5},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},"motion-lines":{focalPoint:{hint:"内円の中心",icon:"circle",init:i=>[0,0]},focalRange:{hint:"内円の範囲",icon:"radius",init:i=>[0,40]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:i=>200},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.1,step:.01,init:i=>.05},angleJitter:{label:"角度ジッター",type:"number",min:0,max:.2,step:.01,init:i=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:1,step:.01,init:i=>.5}},"speed-lines":{tailTip:{hint:"流線の先端",icon:"tail",init:i=>[40,0]},tailMid:{hint:"流線の途中",icon:"curve",init:i=>[.5,0]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},lineCount:{label:"線の本数",type:"number",min:10,max:200,step:1,init:i=>70},lineWidth:{label:"線の太さ",type:"number",min:.01,max:1,step:.01,init:i=>.2},laneJitter:{label:"間隔ジッター",type:"number",min:0,max:.2,step:.01,init:i=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:.5,step:.01,init:i=>.3}},"ellipse-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:i=>1}},"soft-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:i=>.15},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:i=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.4},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:i=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:i=>1}},"rounded-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.7},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:i=>1}},none:{}};class KA extends wt{constructor(t,A,n,s,a,r){super();u(this,"selected",null);u(this,"playIcon");u(this,"dashPhase",0);u(this,"lastNow",null);u(this,"dashSpeed",10);u(this,"showPlayButton");u(this,"showDottedBorder");u(this,"onVisibilityChangeBound",null);this.frameTree=t,this.bubbles=A,this.onFocus=n,this.focusKeeper=s,this.playIcon=new ne(["viewerLayer/play.webp"],[32,32],[1,1],"再生",()=>!0,()=>this.paper.matrix),s.subscribe(this.changeFocus.bind(this)),this.showPlayButton=a,this.showDottedBorder=r,this.onVisibilityChangeBound=this.onVisibilityChange.bind(this),document.addEventListener("visibilitychange",this.onVisibilityChangeBound)}renderDepths(){return[0,1]}calculateRootLayout(){return St(this.frameTree,this.getPaperSize(),[0,0])}render(t,A){if(A===0){const n=this.calculateRootLayout();this.interactable&&this.renderLayoutRecursive(t,n),this.renderFramePlayButtons(t,n)}A===1&&this.renderBubblePlayButtons(t)}renderLayoutRecursive(t,A){var n;t.strokeStyle="rgba(0, 200, 200, 0.2)",t.lineWidth=2,t.beginPath(),t.moveTo(...A.corners.topLeft),t.lineTo(...A.corners.topRight),t.lineTo(...A.corners.bottomRight),t.lineTo(...A.corners.bottomLeft),t.closePath(),t.stroke(),(n=A.children)==null||n.forEach(s=>{this.renderLayoutRecursive(t,s)})}renderFramePlayButtons(t,A){var n;this.hasVideo(A==null?void 0:A.element.filmStack)&&(this.showDottedBorder&&Dt(t,"rgba(128, 128, 128, 1)",A.corners,2,5,!1,this.dashPhase,[20,20]),this.showPlayButton&&(this.playIcon.position=Pe(A.corners.bottomRight,[8,8]),this.playIcon.pivot=[1,1],this.playIcon.shadowColor="rgba(0, 0, 0, 0.5)",this.playIcon.render(t))),(n=A.children)==null||n.forEach(s=>{this.renderFramePlayButtons(t,s)})}renderBubblePlayButtons(t){for(const A of this.bubbles)if(this.hasVideo(A.filmStack)){const n=this.getPaperSize(),[s,a,r,o]=A.getPhysicalRect(n),l=[s+r/2,a];this.showDottedBorder&&Dt(t,"rgba(128, 128, 128, 1)",VA([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,A,n){if(ze.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=HA(s,t,0);return a?{action:"click",layout:a}:(this.selectTarget(null),null)}}async*pointer(t,A){A.action==="click"&&this.handleClick(A.layout)}async keyDown(t,A){return A.code==="Escape"?(this.selectTarget(null),!0):!1}changeFocus(t){t!==this&&(this.onFocus(null),this.redraw())}isSameTarget(t,A){if(t===A)return!0;if(!t||!A)return!1;const n=s=>s.element!==void 0;return n(t)&&n(A)?t.element===A.element:!n(t)&&!n(A)?t===A:!1}selectTarget(t){this.isSameTarget(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 A;if(t){const n=this.getFilmStack(t);for(const s of n.films)s.content.kind==="media"&&((A=s.content.media.player)==null||A.pause())}}startVideo(t){if(!t)return;const A=this.getFilmStack(t);for(const n of A.films)n.content.kind==="media"&&n.content.media.player&&n.content.media.player.play()}onVisibilityChange(){if(!document.hidden&&this.selected){const t=this.getFilmStack(this.selected);for(const A of t.films){if(A.content.kind!=="media")continue;const n=A.content.media.drawSource;n instanceof HTMLVideoElement&&n.paused&&A.content.media.player&&A.content.media.player.play()}}}tick(t){if(this.hasAnyVideo()&&this.showDottedBorder){this.lastNow==null&&(this.lastNow=t);const A=t-this.lastNow;this.lastNow=t,this.dashPhase=(this.dashPhase+this.dashSpeed*A/1e3)%1e4,this.redraw()}if(this.selected){const A=this.getFilmStack(this.selected);for(const n of A.films){if(n.content.kind!=="media")continue;const s=n.content.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 A of t.films)if(A.content.kind==="media"&&A.content.media.player)return!0;return!1}hasAnyVideoInFrames(t){if(this.hasVideo(t.filmStack))return!0;if(t.children){for(const A of t.children)if(this.hasAnyVideoInFrames(A))return!0}return!1}hasAnyVideo(){if(this.hasAnyVideoInFrames(this.frameTree))return!0;for(const t of this.bubbles)if(this.hasVideo(t.filmStack))return!0;return!1}get interactable(){return this.mode==null}tearDown(){this.onVisibilityChangeBound&&(document.removeEventListener("visibilitychange",this.onVisibilityChangeBound),this.onVisibilityChangeBound=null),this.selected&&this.stopVideo(this.selected),super.tearDown()}}GA(KA);var Ze=[];function _A(i){if(Ze=[],i.length==3)return i.push(i[0]),i;var e=oo(i);return ct(e,i),ct([e[1],e[0]],i),Ze.push(Ze[0]),Ze}function oo(i){var e,t,A;for(t=i[0],A=i[0],e=1;e<i.length;e++)i[e][0]<t[0]&&(t=i[e]),i[e][0]>A[0]&&(A=i[e]);return[t,A]}function lo(i,e){var t=e[1][1]-e[0][1],A=e[0][0]-e[1][0];return A*(i[1]-e[0][1])+t*(i[0]-e[0][0])}function co(i,e){var t,A=[],n,s,a=0,r=0;for(t=0;t<e.length;t++){if(n=e[t],a=lo(n,i),a>0)A.push(n);else continue;a>r&&(s=n,r=a)}return{points:A,max:s}}function ct(i,e){var t=co(i,e);if(!t.max)return Ze.push(i[0]);ct([i[0],t.max],t.points),ct([t.max,i[1]],t.points)}function Ie(i,e,t){const[A,n]=i,[s,a]=e,[r,o]=t,[l,c]=[r*s+o*a,r*a-o*s];return[l+A,c+n]}function Ue(i,e,t=.5){const A=[];for(let n=0;n<e;n++){const s=(i()-.5)/e*t,a=(n/e+s)*2*Math.PI;A.push(a)}return A}function Le(i,e,t=3){return e.map(A=>Zi(i[0]/2,i[1]/2,t,A))}function ho(i,e,t,A,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+(i()-.5)*A,d=l*c,[f,h]=[r*d/l,o*d/l];s.push([f,h])}else s.push(e[a]);return s}function uo(i,e,t){const A=Fi(i,e),n=Pe(e,i),s=ce(n),a=Xe(s,t);return ye(A,a)}function Qt(i,e,t){const A=Math.min(i[0],i[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(uo(r,o,A))}return n}function Z(i){return`rgba(${i[0]}, ${i[1]}, ${i[2]}, ${i[3]})`}function fo(){z.setup([1,1]),z.view.autoUpdate=!1}function Vt(i,e,t,A,n,s){switch(t=s.randomSeed??0,n){case"rounded":Co(i,e,t,A,s);break;case"square":Io(i,e,t,A,s);break;case"ellipse":So(i,e,t,A,s);break;case"concentration":po(i,e,t,A,s);break;case"thought":go(i,e,t,A,s);break;case"polygon":Ro(i,e,t,A,s);break;case"strokes":bo(i,e,t,A,s);break;case"double-strokes":wo(i,e,t,A,s);break;case"harsh":xo(i,e,t,A,s);break;case"shout":qo(i,e,t,A,s);break;case"soft":Mo(i,e,t,A,s);break;case"heart":Uo(i,e,t,A,s);break;case"diamond":Lo(i,e,t,A,s);break;case"arrow":To(i,e,t,A,s);break;case"motion-lines":Qo(i,e,t,A,s);break;case"speed-lines":vo(i,e,t,A,s);break;case"ellipse-mind":Oo(i,e,t,A,s);break;case"soft-mind":Go(i,e,t,A,s);break;case"rounded-mind":Jo(i,e,t,A,s);break;case"none":break;default:throw new Error(`Unknown bubble : ${n}`)}}function po(i,e,t,A,n){const[s,a]=A;if(e==="fill"){i.save(),i.translate(0,0),i.scale(s/2,a/2),i.lineWidth=1/Math.min(s,a);const r=n.lineCount;i.save();const o=i.createRadialGradient(0,0,1,0,0,n.lineLength),l=i.strokeStyle,c=ee(l),d=ee(l);c[3]=0,o.addColorStop(0,Z(d)),o.addColorStop(1,Z(c)),i.strokeStyle=o,i.beginPath();for(let f=0;f<r;f++){const h=f*2*Math.PI/r,[p,g]=[Math.cos(h),Math.sin(h)],[v,m]=[p*n.lineLength,g*n.lineLength];i.moveTo(p,g),i.lineTo(v,m)}i.closePath(),i.stroke(),i.restore(),i.restore()}else e==="clip"&&(i.beginPath(),i.ellipse(0,0,s*.5,a*.5,0,0,2*Math.PI),i.clip())}function go(i,e,t,A,n){const s=Ae(t),[a,r]=A;if(e==="fill"){i.save(),i.translate(0,0),i.scale(a/2,r/2),i.beginPath(),i.ellipse(0,0,1,1,0,0,2*Math.PI),i.fill(),i.lineWidth=1;const o=n.lineCount;i.save(),i.createRadialGradient(0,0,1,0,0,n.lineLength);const l=i.strokeStyle;i.fillStyle=l;const d=n.lineLength*.5,f=1-d,h=1+d;for(let p=0;p<o;p++){const g=p*2*Math.PI/o,[v,m]=[Math.cos(g),Math.sin(g)],[b,D]=Ee([v,m],f),[w,y]=Ee([v,m],h),k=s()*n.jitter,S=s()*n.jitter,R=1+Math.sin(g*n.waveFrequency)*n.waveAmplitude,T=Ee([b,D],(1-k)*R),F=Ee([w,y],(1+S)*R);mo(i,T,F,n.lineWidth)}i.restore(),i.restore()}else e==="clip"&&(i.beginPath(),i.ellipse(0,0,a*.5,r*.5,0,0,2*Math.PI),i.clip())}function mo(i,e,t,A){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*A/2,r+l*A/2],[f,h]=[a-o*A/2,r-l*A/2];i.beginPath(),i.moveTo(e[0],e[1]),i.lineTo(e[0]+c,e[1]+d),i.lineTo(t[0],t[1]),i.lineTo(e[0]+f,e[1]+h),i.closePath(),i.fill()}function bo(i,e,t,A,n){$A(i,e,t,A,n,!1)}function wo(i,e,t,A,n){$A(i,e,t,A,n,!0)}function $A(i,e,t,A,n,s){const a=Ae(t),r=Le(A,Ue(a,n.vertexCount,n.angleJitter),n.superEllipse),o=_A(r);if(e=="fill"||e=="clip"){const l=new z.Path;for(let c=0;c<o.length;c++){const d=o[c];c===0?l.moveTo(d):l.lineTo(d)}l.closed=!0,J(i,e,l,n),l.remove()}else{const l=i.strokeStyle;for(let c=0;c<o.length;c++){i.beginPath();const d=o[c],f=o[(c+1)%o.length],[h,p]=yo(d,f,n.overRun),g=i.createLinearGradient(...h,...p),v=ee(l),m=ee(l);if(v[3]=0,g.addColorStop(0,Z(v)),g.addColorStop(.15,Z(m)),g.addColorStop(.85,Z(m)),g.addColorStop(1,Z(v)),i.strokeStyle=g,i.moveTo(h[0],h[1]),i.lineTo(p[0],p[1]),s){const b=Math.min(A[0],A[1])*n.interval,[D,w]=[f[0]-d[0],f[1]-d[1]],[y,k]=[-w,D],[S,R]=[y/Math.sqrt(y*y+k*k),k/Math.sqrt(y*y+k*k)],[T,F]=[h[0]+S*b,h[1]+R*b],[H,N]=[p[0]+S*b,p[1]+R*b];i.moveTo(T,F),i.lineTo(H,N)}i.stroke()}}}function Qo(i,e,t,A,n){const[s,a,r,o]=Te(A);if(e==="fill"){const l=Ae(t);i.save(),i.beginPath(),i.rect(s,a,r,o),i.clip(),i.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],h=Math.hypot(f[0],f[1]),[p,g,v]=[0,0,Math.hypot(r/2,o/2)],[m,b,D]=[d[0],d[1],h],w=i.createRadialGradient(m,b,D,p,g,v),y=ee(i.strokeStyle),k=ee(i.strokeStyle);y[3]=0,w.addColorStop(0,Z(y)),w.addColorStop(.2,Z(k)),w.addColorStop(1,Z(k)),i.fillStyle=w;for(let S=0;S<c;S++){const R=S*2*Math.PI/c+(l()-.5)*n.angleJitter,[T,F]=[Math.cos(R),Math.sin(R)],H=D*(1+l()*n.startJitter),N=[m,b],W=[p+T*v,g+F*v],Y=[W[0]-N[0],W[1]-N[1]],oe=Math.hypot(...Y),he=[N[0]+Y[0]*H/oe,N[1]+Y[1]*H/oe],Oe=n.lineWidth*.1,[Ge,Je]=[ce(Y,Oe),ce(Y,-Oe)];i.beginPath(),i.moveTo(he[0],he[1]),i.lineTo(W[0]+Ge[0],W[1]+Ge[1]),i.lineTo(W[0]+Je[0],W[1]+Je[1]),i.closePath(),i.fill()}i.restore()}}function vo(i,e,t,A,n){const[s,a,r,o]=Te(A);if(e==="fill"){const l=Ae(t);i.save();try{let c=function([b,D]){const w=[h*.5,0],[y,k]=TA(w,p),S=.5-LA([b,D],[y,k])*.5;return rt(S)};i.beginPath(),i.rect(s,a,r,o),i.clip();const d=(n==null?void 0:n.tailTip)??[0,0],f=Ie([0,0],d,(n==null?void 0:n.tailMid)??[0,0]),h=Math.hypot(r,o);if(!Number.isFinite(h)||h<=1e-6)return;const p=Math.atan2(d[1],d[0]);i.rotate(p),i.lineWidth=1;const g=n.lineCount,v=rt(.5-MA(d)/h),m=c(f);for(let b=0;b<g;b++){const D=(b+.5)/g*h-h/2+l()*h*n.laneJitter,w=-h*.5+(l()-.5)*r*n.startJitter,y=o*n.lineWidth*.01*(l()+.5);try{const k=i.createLinearGradient(w+h,D,w,D),S=ee(i.strokeStyle),R=ee(i.strokeStyle);S[3]=0,k.addColorStop(v,Z(S)),k.addColorStop(m,Z(R)),k.addColorStop(1,Z(R)),i.fillStyle=k}catch(k){throw console.error("drawSpeedLinesBubble: gradient addColorStop failed",{seed:t,i:b,length:h,angle:p,tailTip:d,tailMid:f,psf0:v,psf1:m,y:D,lx:w,lw:y,lineCount:g,strokeStyle:i.strokeStyle,opts:n,error:k}),k}i.beginPath(),i.moveTo(w,D-y),i.lineTo(w+h,D),i.lineTo(w,D+y),i.closePath(),i.fill()}}catch(c){throw console.error("drawSpeedLinesBubble: unexpected error",{seed:t,size:A,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{i.restore()}}}function yo(i,e,t){const[A,n]=[e[0]-i[0],e[1]-i[1]],s=[e[0]-A*t,e[1]-n*t],a=[i[0]+A*t,i[1]+n*t];return[s,a]}function Po(i,e,t,A){A=t.randomSeed??0,performance.now();try{switch(i){case"square":return ei(e,t,A);case"ellipse":return Zt(e,t,A);case"polygon":return li(e,t,A);case"rounded":return Ft(e,t,A);case"harsh":return ti(e,t,A);case"shout":return Ai(e,t,A);case"soft":return Ht(e,t,A);case"heart":return ii(e,t,A);case"diamond":return ni(e,t,A);case"arrow":return si(e,t,A);case"ellipse-mind":return ai(e,t,A);case"soft-mind":return ri(e,t,A);case"rounded-mind":return oi(e,t,A);case"concentration":case"thought":case"none":return null}return console.error(`Unknown bubble shape: ${i}`),null}finally{}}function Te(i){return[-i[0]*.5,-i[1]*.5,i[0],i[1]]}function ko(i){return[i[0]*.5,i[1]*.5]}function ei(i,e,t){const A=new z.Path.Rectangle(Te(i));return ve(A,i,e)}function Zt(i,e,t){const A=new z.Path.Ellipse({center:[0,0],radius:ko(i)});return ve(A,i,e)}function Ft(i,e,t){const[A,n,s,a]=Te(i),[r,o]=[0,0],[l,c]=[A+s,n+a],[d,f]=[e.xStraight*s*.5,e.yStraight*a*.5],h=new z.Path;return h.moveTo([r+d,n]),h.lineTo([r-d,n]),h.quadraticCurveTo([A,n],[A,o-f]),h.lineTo([A,o+f]),h.quadraticCurveTo([A,c],[r-d,c]),h.lineTo([r+d,c]),h.quadraticCurveTo([l,c],[l,o+f]),h.lineTo([l,o-f]),h.quadraticCurveTo([l,n],[r+d,n]),h.closed=!0,ve(h,i,e)}function ti(i,e,t){const A=Ae(t);let n=Ue(A,e.bumpCount,e.angleJitter);const s=Le(i,n,e.superEllipse);let a=Qt(i,s,e.bumpDepth);const r=new z.Path;return r.addSegments(a),r.closed=!0,ve(r,i,e)}function Ai(i,e,t){const A=e.bumpSharp,n=Ae(t);let s;const a=Ue(n,e.bumpCount,e.angleJitter);s=Le(i,a,e.superEllipse),s=Qt(i,s,A),s=ho(n,s,A,e.depthJitter);const r=new z.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,ve(r,i,e)}function Ht(i,e,t){const A=Ae(t),n=Le(i,Ue(A,e.bumpCount,e.angleJitter),e.superEllipse),s=Qt(i,n,-e.bumpDepth),a=new z.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 ve(a,i,e)}function ii(i,e,t){const[A,n]=i,[s,a]=[0,0],r=n*-.58,o=n*-.35,l=n*-.1,c=n*.1,d=n*.35,f=n*.5,h=new z.Path;return h.moveTo([s,a+o]),h.cubicCurveTo([-.1*A,r],[-.5*A,r],[-.5*A,l]),h.cubicCurveTo([-.5*A,c],[-.3*A,d],[0,f]),h.cubicCurveTo([.3*A,d],[.5*A,c],[.5*A,l]),h.cubicCurveTo([.5*A,r],[.1*A,r],[0,o]),h.closed=!0,h}function ni(i,e,t){const[A,n,s,a]=Te(i),r=new z.Path;return r.moveTo([0,n]),r.lineTo([A,0]),r.lineTo([0,n+a]),r.lineTo([A+s,0]),r.closed=!0,r}function si(i,e,t){const[A,n,s,a]=Te(i),{shaftWidth:r,headLength:o}=e,l=r*s*.5,c=new z.Path,d=n+a*o,f=A+s*.5-l,h=A+s*.5+l;return c.moveTo([0,n]),c.lineTo([A,d]),c.lineTo([f,d]),c.lineTo([f,n+a]),c.lineTo([h,n+a]),c.lineTo([h,d]),c.lineTo([A+s,d]),c.lineTo([0,n]),c.closed=!0,c}function ai(i,e,t){const A={...e};A.tailTip=[0,0],A.tailMid=[.5,0];const n=Zt(i,A);return Nt(n,t,i,e,A)}function ri(i,e,t){const A={...e};A.tailTip=[0,0],A.tailMid=[.5,0];const n=Ht(i,A,t);return Nt(n,t,i,e,A)}function oi(i,e,t){const A={...e};A.tailTip=[0,0],A.tailMid=[.5,0];const n=Ft(i,A);return Nt(n,t,i,e,A)}function Bo(i,e,t,A,n,s){const a=Ae(t),r=Le(i,Ue(a,A),n),o=Qt(i,r,-s),l=new z.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,ve(l,i,e)}function ve(i,e,t){if(t!=null&&t.tailTip){const A=t.tailTip,n=t.tailMid;if(!(A[0]===0&&A[1]===0))if(t!=null&&t.extract){const s=Eo(e,n,A,t.extractWidth),a=i.subtract(s);return i.remove(),s.remove(),a}else{const s=Do(e,n,A,t.tailWidth),a=i.unite(s);return i.remove(),s.remove(),a}}return i}function Do(i,e,t,A){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=i[0]*i[1]*A,s=Math.max(5e4,Math.hypot(t[0],t[1])**2),a=Xe(ce(t),n*35/s),r=Xe(ce(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,h=Ie(d,o,e),p=Ie(f,l,e),g=new z.Path;return g.moveTo(d),g.curveTo(h,c),g.curveTo(p,f),g.closed=!0,g}function Eo(i,e,t,A){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=Ie([0,0],t,e),s=[t[0]-n[0],t[1]-n[1]],a=Math.hypot(t[0],t[1]),r=Xe(ce(s),a*A),o=[t[0]+r[0],t[1]+r[1]],l=[t[0]-r[0],t[1]-r[1]],c=new z.Path;return c.moveTo(n),c.lineTo(o),c.lineTo(l),c.closed=!0,c}function li(i,e,t){const A=Ae(t),n=Ue(A,e.vertexCount,e.angleJitter),s=Le(i,n,e.superEllipse),a=_A(s),r=new z.Path;return r.addSegments(a),r.closed=!0,ve(r,i,e)}function So(i,e,t,A,n){const s=Zt(A,n);J(i,e,s,n)}function Io(i,e,t,A,n){const s=ei(A,n);J(i,e,s,n)}function Ro(i,e,t,A,n){const s=li(A,n,t);J(i,e,s,n)}function Co(i,e,t,A,n){const s=Ft(A,n);J(i,e,s,n)}function xo(i,e,t,A,n){const s=ti(A,n,t);J(i,e,s,n)}function qo(i,e,t,A,n){const s=Ai(A,n,t);J(i,e,s,n)}function Mo(i,e,t,A,n){const s=Ht(A,n,t);J(i,e,s,n)}function Uo(i,e,t,A,n){const s=ii(A);J(i,e,s,n)}function Lo(i,e,t,A,n){const s=ni(A);J(i,e,s,n)}function To(i,e,t,A,n){const s=si(A,n);J(i,e,s,n)}function Oo(i,e,t,A,n){const s=ai(A,n,t);J(i,e,s,n)}function Go(i,e,t,A,n){const s=ri(A,n,t);J(i,e,s,n)}function Jo(i,e,t,A,n){const s=oi(A,n,t);J(i,e,s,n)}function J(i,e,t,A){switch(i.beginPath(),e){case"fill":i.fill(new Path2D(t.pathData));break;case"stroke":const n=A.roughness??0;if(0<n){const s=(A.randomSeed??0)+1;Ii.canvas(i.canvas,{options:{seed:s,roughness:n,strokeWidth:i.lineWidth,stroke:i.strokeStyle}}).path(t.pathData)}else i.stroke(new Path2D(t.pathData));break;case"clip":i.clip(new Path2D(t.pathData));break}}function Nt(i,e,t,A,n){const s=[[.97,.04],[.8,.05],[.6,.08],[.3,.12]],a=Ie([0,0],A.tailTip,A.tailMid),r=A.tailTip,o=[r[0]-a[0],r[1]-a[1]],l=Math.min(t[0],t[1])*.5*A.tailWidth,c=(A==null?void 0:A.flattening)??1;for(let d of s){const f=[a[0]+d[0]*o[0],a[1]+d[0]*o[1]],h=l*d[1]*2,p=Bo([h,h],n,e,6,2,.15);if(c&&Math.abs(c-1)>1e-6){const g=c>1?1/c:1,v=c<1?c:1;p.scale(g,v,[0,0])}p.translate(f),i=i.unite(p)}return i}function st(i,e,t,A=!0){const n=[],s=r=>((t[0]-e[0])*(r[1]-e[1])-(t[1]-e[1])*(r[0]-e[0]))*(A?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]),h=((e[0]-r[0])*d+(e[1]-r[1])*f)/(l*d+c*f);return[r[0]+h*l,r[1]+h*c]};for(let r=0;r<i.length;r++){const o=i[r],l=i[(r+i.length-1)%i.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 dA(i,e,t,A){const[n,s]=e;let a=[[0,0],[n,0],[n,s],[0,s]];if(t.top){const r=At(i.topLeft,i.topRight,-A);a=st(a,...r)}if(t.right){const r=At(i.topRight,i.bottomRight,-A);a=st(a,...r)}if(t.bottom){const r=At(i.bottomRight,i.bottomLeft,-A);a=st(a,...r)}if(t.left){const r=At(i.bottomLeft,i.topLeft,-A);a=st(a,...r)}return a}function pe(i,e,t,A){return Number.isFinite(i)?Math.min(t,Math.max(e,i)):A}function se(i,e,t){const A=i.params[e];if(typeof A=="number")return A;if(typeof A=="string"){const n=Number(A);if(Number.isFinite(n))return n}return t}function dt(i,e,t){const A=i.params[e];if(Array.isArray(A)&&A.length>=2){const n=Number(A[0]),s=Number(A[1]);if(Number.isFinite(n)&&Number.isFinite(s))return[n,s]}return[...t]}const Vo={draw(i,e,t){const A=t,n=t;e.save();try{e.translate(t/2,t/2);const s=Ae(String(se(i,"randomSeed",0))),a=dt(i,"focalPoint",[0,0]),r=dt(i,"focalRange",[0,40]),o=pe(se(i,"lineCount",200),100,300,200),l=pe(se(i,"lineWidth",.05),.01,.1,.05),c=pe(se(i,"angleJitter",.05),0,.2,.05),d=pe(se(i,"startJitter",.5),0,1,.5),f=String(i.params.color||"#000000");e.lineWidth=1;const h=a,p=r,g=Math.hypot(p[0],p[1]),[v,m,b]=[0,0,Math.hypot(A/2,n/2)],[D,w,y]=[h[0],h[1],g],k=e.createRadialGradient(D,w,y,v,m,b),S=ee(f),R=ee(f);S[3]=0,k.addColorStop(0,Z(S)),k.addColorStop(.2,Z(R)),k.addColorStop(1,Z(R)),e.fillStyle=k;for(let T=0;T<o;T++){const F=T*2*Math.PI/o+(s()-.5)*c,[H,N]=[Math.cos(F),Math.sin(F)],W=y*(1+s()*d),Y=[D,w],oe=[v+H*b,m+N*b],he=[oe[0]-Y[0],oe[1]-Y[1]],Oe=Math.hypot(...he),Ge=[Y[0]+he[0]*W/Oe,Y[1]+he[1]*W/Oe],Je=l*.1,[Yt,jt]=[ce(he,Je),ce(he,-Je)];e.beginPath(),e.moveTo(Ge[0],Ge[1]),e.lineTo(oe[0]+Yt[0],oe[1]+Yt[1]),e.lineTo(oe[0]+jt[0],oe[1]+jt[1]),e.closePath(),e.fill()}}finally{e.restore()}}},Zo={draw(i,e,t){const A=t,n=t;e.save();try{let s=function([b,D]){const w=[p*.5,0],[y,k]=TA(w,g),S=.5-LA([b,D],[y,k])*.5;return rt(S)};e.translate(t/2,t/2);const a=Ae(String(se(i,"randomSeed",0))),r=dt(i,"tailTip",[40,0]),o=Ie([0,0],r,dt(i,"tailMid",[.5,0])),l=pe(se(i,"lineCount",70),10,200,70),c=pe(se(i,"lineWidth",.2),.01,1,.2),d=pe(se(i,"laneJitter",.05),0,.2,.05),f=pe(se(i,"startJitter",.3),0,.5,.3),h=String(i.params.color||"#000000"),p=Math.hypot(A,n);if(!Number.isFinite(p)||p<=1e-6)return;const g=Math.atan2(r[1],r[0]);e.rotate(g),e.lineWidth=1;const v=rt(.5-MA(r)/p),m=s(o);for(let b=0;b<l;b++){const D=(b+.5)/l*p-p/2+a()*p*d,w=-p*.5+(a()-.5)*A*f,y=n*c*.01*(a()+.5),k=e.createLinearGradient(w+p,D,w,D),S=ee(h),R=ee(h);S[3]=0,k.addColorStop(v,Z(S)),k.addColorStop(m,Z(R)),k.addColorStop(1,Z(S)),e.fillStyle=k,e.beginPath(),e.moveTo(w,D-y),e.lineTo(w+p,D),e.lineTo(w,D+y),e.closePath(),e.fill()}}finally{e.restore()}}},Fo={draw(i,e,t){e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(0,0,t,t),e.fillStyle="rgba(0,0,0,0.25)",e.font=`${Math.max(12,Math.round(t*.05))}px sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(i.type,t/2,t/2)}},Ho={"motion-lines":Vo,"speed-lines":Zo};function No(i,e,t){const A=Ho[i.type]??Fo;e.save(),A.draw(i,e,t),e.restore()}function ci(i,e,t,A,n){const s=e.films;for(let a of s){if(!a.visible)continue;const r=a.getShiftedScale(t),o=a.getShiftedTranslation(t);if(i.save(),n&&n(i,a),i.translate(...A),i.translate(o[0],o[1]),i.rotate(-a.rotation*Math.PI/180),i.scale(r*a.reverse[0],r*a.reverse[1]),a.content.kind==="media"){let l=a.content.media;for(let c=a.effects.length-1;0<=c;c--)if(a.effects[c].outputMedia){l=a.effects[c].outputMedia;break}i.translate(-l.naturalWidth*.5,-l.naturalHeight*.5),i.drawImage(l.drawSource,0,0,l.naturalWidth,l.naturalHeight)}else{const[l,c]=a.getContentSize(t),d=Math.max(l,c);i.translate(-d*.5,-d*.5),No(a.content.effect,i,d)}i.restore()}}function hA(i,e,t,A,n){for(let s of t)di(i,e,s),ht(i,e,s,!1,n);for(let s of t)ht(i,e,s,!0,n)}function di(i,e,t,A){if(t.parent)return;const n=t.getPhysicalSize(e);t.getPhysicalStrokeWidth(e),i.save(),i.translate(...t.getPhysicalCenter(e)),i.rotate(-t.rotation*Math.PI/180),Wo(i,e,t,n),hi(i,t,n),ci(i,t.filmStack,e,[0,0],null),i.restore()}function Ve(i,e,t,A,n){i.fillStyle=e.hasEnoughSize(t)?A:"rgba(255, 128, 0, 0.9)"}function ht(i,e,t,A,n){if(t.parent){if(!A)return}else if(A)return;const s=t.getPhysicalSize(e),a=t.getPhysicalCenter(e),r=t.getPhysicalStrokeWidth(e);i.save(),i.translate(...a),i.rotate(-t.rotation*Math.PI/180),i.save(),hi(i,t,s),t.text&&!t.hidesText&&Xo(i,e,t,n),i.restore(),i.strokeStyle=0<r?t.strokeColor:"rgba(0, 0, 0, 0)",i.lineWidth=r,zo(i,e,t,s),i.restore()}function Wo(i,e,t,A,n){const s=t.renderInfo;s.unitedOuterPath?(s.innerPathIsSameWithOuterPath||(Ve(i,t,e,t.optionContext.shapeOutlineColor??"white"),J(i,"fill",s.unitedOuterPath,t.optionContext)),Ve(i,t,e,t.fillColor),J(i,"fill",s.unitedInnerPath,t.optionContext)):t.parent||(s.outerPath?(s.innerPathIsSameWithOuterPath||(Ve(i,t,e,t.optionContext.shapeOutlineColor??"white"),J(i,"fill",s.outerPath,t.optionContext)),Ve(i,t,e,t.fillColor),J(i,"fill",s.innerPath,t.optionContext)):(A[0]=Math.abs(A[0]),A[1]=Math.abs(A[1]),Ve(i,t,e,t.fillColor),i.strokeStyle=t.strokeColor,Vt(i,"fill",t.text,A,t.shape,t.optionContext)))}function hi(i,e,t){const A=e.renderInfo;A.unitedStrokePath?J(i,"clip",A.unitedStrokePath,e.optionContext):e.parent||(A.strokePath?J(i,"clip",A.strokePath,e.optionContext):(t[0]=Math.abs(t[0]),t[1]=Math.abs(t[1]),Vt(i,"clip",e.text,t,e.shape,e.optionContext)))}function zo(i,e,t,A){const n=t.getPhysicalStrokeWidth(e);i.strokeStyle=0<n?t.strokeColor:"rgba(0, 0, 0, 0)",i.lineWidth=n;const s=t.renderInfo;s.unitedStrokePath?J(i,"stroke",s.unitedStrokePath,t.optionContext):t.parent||(s.strokePath?J(i,"stroke",s.strokePath,t.optionContext):(A[0]=Math.abs(A[0]),A[1]=Math.abs(A[1]),Vt(i,"stroke",t.text,A,t.shape,t.optionContext)))}function Xo(i,e,t,A){const n=i.getTransform(),s=A?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),[h,p]=$t(Oi(l,o));if(h<1||p<1)return;isNaN(c)&&(c=14),c<1&&(c=14);const g=t.renderInfo,v=`${t.fontStyle} ${t.fontWeight} ${c}px '${t.fontFamily}'`,m={viewScale:$t(Ee(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},b=JSON.stringify(m);if(g.textJson!=b){g.textJson=b,g.textCanvas=document.createElement("canvas"),g.textCtx=g.textCanvas.getContext("2d");const w=g.textCanvas,y=g.textCtx;w.width=h,w.height=p,y.translate(h*.5,p*.5),y.scale(...o),y.translate(...d),y.font=v;let k=t.text;document.fonts.check(`${t.fontStyle} ${t.fontWeight} 20px '${t.fontFamily}'`);const S=c*1.5*(1+t.lineSkip),R=c*(1+t.charSkip),T=t.rubySize,F=t.rubyDistance,H=ro(t.direction,y,l[0]*.85,l[1]*.85,k,S,R,t.autoNewline),[N,W]=[H.width,H.height],Y={x:-N*.5,y:-W*.5,width:N,height:W};y.globalCompositeOperation="source-over",y.fillStyle=t.fontColor,lA(t.direction,y,"fill",Y,k,S,R,T,F,H,t.autoNewline),0<f&&(y.globalCompositeOperation="destination-over",y.strokeStyle=t.outlineColor,y.lineWidth=f,y.font=v,y.lineJoin="round",lA(t.direction,y,"stroke",Y,k,S,R,T,F,H,t.autoNewline))}const D=g.textCanvas;try{const w=Math.round(t.rotation*10)/10;i.save(),(w===0||w===90||w===180||w===270)&&(i.imageSmoothingEnabled=!1),i.scale(...Ji(o)),i.drawImage(D,0-h*.5,0-p*.5),i.restore()}catch(w){throw console.log(h,p,D.width,D.height,l),w}}function uA(i){const e=new Path2D;if(0<i.length){e.moveTo(...i[0]);for(let t=1;t<i.length;t++)e.lineTo(...i[t]);e.closePath()}return e}class ui extends wt{constructor(t){super();u(this,"frameTree",null);u(this,"rawBubbles",null);u(this,"thisFrameRenderData",null);this.supportsDpr=t}renderDepths(){return[0,1]}tick(t){if(!this.frameTree)return;const A=s=>{var a,r;if((r=(a=s.filmStack)==null?void 0:a.films)!=null&&r.some(o=>!o.media.isLoaded))return!0;if(s.children){for(const o of s.children)if(A(o))return!0}return!1},n=()=>{var s,a;if(!this.rawBubbles)return!1;for(const r of this.rawBubbles)if((a=(s=r.filmStack)==null?void 0:s.films)!=null&&a.some(o=>!o.media.isLoaded))return!0;return!1};(A(this.frameTree)||n())&&this.redraw()}prerender(t){this.thisFrameRenderData=null}render(t,A){if(!this.thisFrameRenderData){if(!this.frameTree)return;const o=this.getPaperSize(),l=St(this.frameTree,o,[0,0]);this.thisFrameRenderData=this.setUpRenderData(l)}const{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}=this.thisFrameRenderData;if(A===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)}A===1&&hA(t,this.getPaperSize(),r,!0,this.supportsDpr)}setUpRenderData(t){const A={borderColor:"black",borderWidth:1},{backgrounds:n,foregrounds:s}=this.setUpFrameTree(t,A),{embeddedBubbles:a,floatingBubbles:r}=this.setUpBubbles(t,this.rawBubbles);return{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}}setUpFrameTree(t,A){const n=[],s=[];if(t.element.borderColor!=null&&(A.borderColor=t.element.borderColor),t.element.borderWidth!=null&&(A.borderWidth=t.element.borderWidth),t.children){n.push({layout:t,inheritanceContext:A});for(let a=0;a<t.children.length;a++){const r=this.setUpFrameTree(t.children[a],A);n.push(...r.backgrounds),s.push(...r.foregrounds)}}else n.push({layout:t,inheritanceContext:A}),s.push({layout:t,inheritanceContext:A});return{backgrounds:n,foregrounds:s}}setUpBubbles(t,A){const n=this.getPaperSize();this.resolveLinkages(A);const s=new Map,a=[];for(let r of A)if(r.embedded){const o=HA(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,h,p,g,v;const A=this.getPaperSize(),n={};for(let m of t)m.renderInfo??(m.renderInfo={}),(s=m.renderInfo.unitedOuterPath)==null||s.remove(),m.renderInfo.unitedOuterPath=null,(a=m.renderInfo.unitedInnerPath)==null||a.remove(),m.renderInfo.unitedInnerPath=null,(r=m.renderInfo.unitedStrokePath)==null||r.remove(),m.renderInfo.unitedStrokePath=null,m.renderInfo.children=[],n[m.uuid]=m;for(let m of t)m.parent&&(n[m.parent]==null?m.parent=null:n[m.parent].renderInfo.children.push(m));for(let m of t){const b=m.optionContext,D=[m.n_p1[0]-m.n_p0[0],m.n_p1[1]-m.n_p0[1]],w=m.renderInfo,y={paperSize:A,shape:m.shape,size:D,optionContext:b,rotation:m.rotation},k=JSON.stringify(y);if(w.pathJson!=k){(o=w.strokePath)==null||o.remove(),(l=w.outerPath)==null||l.remove(),(c=w.innerPath)==null||c.remove(),w.strokePath=null,w.outerPath=null,w.innerPath=null;const S=m.getPhysicalSize(A);if(w.pathJson=k,w.strokePath=Po(m.shape,S,b,m.text),(d=w.strokePath)==null||d.rotate(-m.rotation),w.innerPathIsSameWithOuterPath=!1,w.strokePath){const R=Math.min(w.strokePath.bounds.width,w.strokePath.bounds.height)*(b.shapeExpand??0);try{R==0?w.outerPath=w.strokePath.clone():w.outerPath=Kt.PaperOffset.offset(w.strokePath,R)}catch{console.error("PaperOffset failed, using strokePath as outerPath",q.decompile(m)),w.outerPath=w.strokePath.clone()}const T=Math.min(w.outerPath.bounds.width,w.outerPath.bounds.height)*(b.shapeOutline??0);try{T==0?(w.innerPath=w.outerPath.clone(),w.innerPathIsSameWithOuterPath=!0):w.innerPath=Kt.PaperOffset.offset(w.outerPath,-T)}catch{console.error("PaperOffset failed, using outerPath as innerPath",q.decompile(m)),w.innerPath=w.outerPath.clone(),w.innerPathIsSameWithOuterPath=!0}}}}for(let m of t){const b=m.renderInfo;if(m.parent==null&&b.strokePath){const D=m.getPhysicalCenter(A);b.unitedStrokePath=b.strokePath.clone(),b.unitedOuterPath=b.outerPath.clone(),b.unitedInnerPath=b.innerPath.clone(),b.unitedOuterPath.translate(D),b.unitedInnerPath.translate(D),b.unitedStrokePath.translate(D);for(let w of b.children){const y=w.getPhysicalCenter(A),k=w.renderInfo;if(k.strokePath==null)continue;const S=k.strokePath.clone();S==null||S.translate(w.getPhysicalCenter(A)),(f=b.unitedStrokePath)==null||f.remove(),b.unitedStrokePath=b.unitedStrokePath.unite(S),S.remove();const R=k.outerPath.clone();R.translate(y),(h=b.unitedOuterPath)==null||h.remove(),b.unitedOuterPath=b.unitedOuterPath.unite(R),R.remove();const T=k.innerPath.clone();T.translate(y),(p=b.unitedInnerPath)==null||p.remove(),b.unitedInnerPath=b.unitedInnerPath.unite(T),T.remove()}b.children.length===0&&b.innerPathIsSameWithOuterPath?((g=b.unitedInnerPath)==null||g.remove(),b.unitedInnerPath=b.unitedOuterPath.clone()):((v=b.unitedOuterPath)==null||v.remove(),b.unitedOuterPath=b.unitedOuterPath.subtract(b.unitedInnerPath)),b.unitedOuterPath.rotate(m.rotation,D),b.unitedOuterPath.translate(Pt(D)),b.unitedInnerPath.rotate(m.rotation,D),b.unitedInnerPath.translate(Pt(D)),b.unitedStrokePath.rotate(m.rotation,D),b.unitedStrokePath.translate(Pt(D))}}}makeFramePath(t,A){const n=this.getPaperSize(),s=dA(t.corners,n,{top:!0,right:!0,bottom:!0,left:!0},A);return uA(s)}renderFrame(t,A,n,s){this.renderFrameBackground(t,A,n);const a=A.element;2<=a.visibility&&this.renderFrameBorder(t,A,n),1<=a.visibility&&this.renderFrameContent(t,A,n,s)}renderFrameBackground(t,A,n){if(A.element.visibility===0||!A.element.bgColor)return;const s=(n==null?void 0:n.borderWidth)??0,a=this.makeFramePath(A,-s*.5);t.save(),t.lineJoin="miter",t.fillStyle=A.element.bgColor,t.fill(a),t.restore()}renderFrameContent(t,A,n,s){if(0<A.element.filmStack.films.length||s.has(A)){const r=this.getPaperSize(),o=A.element,[l,c,d,f]=Jr(A.corners),h=-n.borderWidth*.5,p=(m,b)=>{const D=dA(A.corners,r,b.barriers,h);m.clip(uA(D))};ci(t,o.filmStack,r,[l+d*.5,c+f*.5],p);const g=this.makeFramePath(A,-n.borderWidth*.5),v=s.get(A);v&&(t.save(),t.clip(g),hA(t,this.getPaperSize(),v,!0,this.supportsDpr),t.restore())}}renderFrameBorder(t,A,n){const s=n.borderWidth;if(0<s){t.save(),t.strokeStyle=n.borderColor,t.lineWidth=s,t.lineJoin="miter";const a=this.makeFramePath(A,0);t.stroke(a),t.restore()}}setBubbles(t){this.rawBubbles=t}setFrameTree(t){this.frameTree=t}renderApart(){const t=this.getPaperSize();function A(){const d=xi(t[0],t[1]),f=d.getContext("2d");return{canvas:d,ctx:f}}const n=St(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:h,ctx:p}=A();this.renderFrameBackground(p,d,f),this.renderFrameContent(p,d,f,a);const{canvas:g,ctx:v}=A();this.renderFrameBorder(v,d,f),o.push({border:g,content:h})}const l=[...[...a.values()].flat(),...r],c={};for(let d of l){if(d.renderInfo,d.parent!=null)continue;const{canvas:f,ctx:h}=A(),p=this.getPaperSize();di(h,p,d),ht(h,p,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");ht(f,this.getPaperSize(),d,!0,this.supportsDpr)}return{frames:o,bubbles:Object.values(c)}}resetCache(){var t,A,n,s,a,r;for(let o of this.rawBubbles){const l=o.renderInfo;l&&((t=l.strokePath)==null||t.remove(),(A=l.outerPath)==null||A.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 Yo{constructor(){u(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 jo=typeof process<"u"&&(process.env.NODE_ENV==="test"||process.env.VITEST);let xt;async function Ko(){const i=new We.Computron;await i.init(),xt=new We.JFACompute(i),await xt.init()}jo||Ko();class fi{constructor(){u(this,"ulid");u(this,"inputMedia");u(this,"outputMedia");this.ulid=Se.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 Wt(t.color,t.width,t.sharp);default:throw new Error("Unknown effect tag: "+e.tag)}}}class Wt extends fi{constructor(t,A,n){super();u(this,"rawDistanceField",null);this.color=t,this.width=A,this.sharp=n}clone(){return new Wt(this.color,this.width,this.sharp)}async apply(t){if(this.inputMedia!=t){const h=t.drawSource,p=We.FloatField.createFromImageOrCanvas(h),g=We.JFACompute.createJFASeedMap(p,.5,!1);this.rawDistanceField=await xt.compute(g),this.inputMedia=t}const A=t.drawSource,n=Math.max(t.naturalWidth,t.naturalHeight),s=this.width*n,a=Ci(this.color),r={r:a.values[0]/255,g:a.values[1]/255,b:a.values[2]/255},o=1-this.sharp,l=h=>o<=h?1:h*(1/o),c=We.JFACompute.generateDistanceField(this.rawDistanceField,r,s,l),d=document.createElement("canvas");d.width=A.width,d.height=A.height;const f=d.getContext("2d");return f.drawImage(A,0,0),f.globalCompositeOperation="destination-over",f.drawImage(c.toCanvas(),0,0),this.outputMedia=new le(d),this.outputMedia}decompile(){return{color:this.color,width:this.width,sharp:this.sharp}}}async function pi(i,e,t){const A=ue.compileNode(e);if(A.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(i[0],i[1]),l=r/o,c=(e.scale??[1,1])[0],d=l*c,f=e.translation??[0,0],h=[f[0]*l,f[1]*l],p=X.fromMedia(new le(a));return p.n_scale=d,p.n_translation=h,p.rotation=e.rotation,p.reverse=[...e.reverse??[1,1]],p.prompt=e.prompt,p};if(e.image){const a=await t(e.image,"image");if(a){const r=s(a);A.filmStack.films.push(r)}}if(e.scribble){const a=await t(e.scribble,"image");if(a){const r=s(a);A.filmStack.films.push(r)}}}else{let s=function(a){const r=X.fromMedia(new le(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);A.filmStack.films.push(r)}}if(e.image.scribble){const a=await t(e.image.scribble,"image");if(a){const r=s(a);A.filmStack.films.push(r)}}}else if(e.films){const s=await gi(e.films,t);A.filmStack.films.push(...s)}const n=e.column??e.row;if(n){A.direction=e.column?"v":"h",A.children=[];for(let s of n)A.children.push(await pi(i,s,t));A.calculateLengthAndBreadth()}for(const s of A.filmStack.films)s.content.kind==="media"&&s.content.media instanceof le&&A.gallery.push(s.content.media);return A}async function _o(i,e,t){const A=[];for(const n of e){const s=q.compile(i,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(i[0],i[1]);let c=a.n_scale;if(!c){const p=(a.scale??[1,1])[0];c=o/l*p}let d=a.n_translation;if(!d){const h=a.translation??[0,0],p=o/l;d=[h[0]*p,h[1]*p]}const f=X.fromMedia(new le(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 gi(n.films,t);s.filmStack.films=r}A.push(s)}for(const n of A)for(const s of n.filmStack.films)s.content.kind==="media"&&s.content.media instanceof le&&n.gallery.push(s.content.media);return A}async function gi(i,e){const t=[];for(const A of i){const n=[];if(A.effects)for(const a of A.effects){const r=fi.compile(a);n.push(r)}let s=null;if(A.proceduralEffect)s=X.fromProcedural({type:A.proceduralEffect.type,params:A.proceduralEffect.params??{}});else{const a=await e(A.image,A.mediaType??"image");if(!a)continue;const r=A.mediaType==="video"?new Et(a):new le(a);s=X.fromMedia(r)}s&&(A.ulid&&(s.ulid=A.ulid),s.n_scale=A.n_scale,s.n_translation=A.n_translation,s.rotation=A.rotation,s.reverse=A.reverse,s.visible=A.visible,s.prompt=A.prompt,s.effects=n,s.barriers=A.barriers??{top:!0,right:!0,bottom:!0,left:!0},t.push(s))}return t}async function $o(i,e){const t=[];for(const A of i.characters){const n=A.portrait?await e(A.portrait,"image"):null;t.push({...A,portrait:Wr(n)})}return{...i,characters:t,format:i.format??"standard"}}var L;(function(i){i.assertEqual=n=>{};function e(n){}i.assertIs=e;function t(n){throw new Error}i.assertNever=t,i.arrayToEnum=n=>{const s={};for(const a of n)s[a]=a;return s},i.getValidEnumValues=n=>{const s=i.objectKeys(n).filter(r=>typeof n[n[r]]!="number"),a={};for(const r of s)a[r]=n[r];return i.objectValues(a)},i.objectValues=n=>i.objectKeys(n).map(function(s){return n[s]}),i.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},i.find=(n,s)=>{for(const a of n)if(s(a))return a},i.isInteger=typeof Number.isInteger=="function"?n=>Number.isInteger(n):n=>typeof n=="number"&&Number.isFinite(n)&&Math.floor(n)===n;function A(n,s=" | "){return n.map(a=>typeof a=="string"?`'${a}'`:a).join(s)}i.joinValues=A,i.jsonStringifyReplacer=(n,s)=>typeof s=="bigint"?s.toString():s})(L||(L={}));var fA;(function(i){i.mergeShapes=(e,t)=>({...e,...t})})(fA||(fA={}));const B=L.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),fe=i=>{switch(typeof i){case"undefined":return B.undefined;case"string":return B.string;case"number":return Number.isNaN(i)?B.nan:B.number;case"boolean":return B.boolean;case"function":return B.function;case"bigint":return B.bigint;case"symbol":return B.symbol;case"object":return Array.isArray(i)?B.array:i===null?B.null:i.then&&typeof i.then=="function"&&i.catch&&typeof i.catch=="function"?B.promise:typeof Map<"u"&&i instanceof Map?B.map:typeof Set<"u"&&i instanceof Set?B.set:typeof Date<"u"&&i instanceof Date?B.date:B.object;default:return B.unknown}},Q=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 de extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=A=>{this.issues=[...this.issues,A]},this.addIssues=(A=[])=>{this.issues=[...this.issues,...A]};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},A={_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)A._errors.push(t(a));else{let r=A,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),A}static assert(e){if(!(e instanceof de))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={},A=[];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))):A.push(e(n));return{formErrors:A,fieldErrors:t}}get formErrors(){return this.flatten()}}de.create=i=>new de(i);const qt=(i,e)=>{let t;switch(i.code){case Q.invalid_type:i.received===B.undefined?t="Required":t=`Expected ${i.expected}, received ${i.received}`;break;case Q.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(i.expected,L.jsonStringifyReplacer)}`;break;case Q.unrecognized_keys:t=`Unrecognized key(s) in object: ${L.joinValues(i.keys,", ")}`;break;case Q.invalid_union:t="Invalid input";break;case Q.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${L.joinValues(i.options)}`;break;case Q.invalid_enum_value:t=`Invalid enum value. Expected ${L.joinValues(i.options)}, received '${i.received}'`;break;case Q.invalid_arguments:t="Invalid function arguments";break;case Q.invalid_return_type:t="Invalid function return type";break;case Q.invalid_date:t="Invalid date";break;case Q.invalid_string:typeof i.validation=="object"?"includes"in i.validation?(t=`Invalid input: must include "${i.validation.includes}"`,typeof i.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${i.validation.position}`)):"startsWith"in i.validation?t=`Invalid input: must start with "${i.validation.startsWith}"`:"endsWith"in i.validation?t=`Invalid input: must end with "${i.validation.endsWith}"`:L.assertNever(i.validation):i.validation!=="regex"?t=`Invalid ${i.validation}`:t="Invalid";break;case Q.too_small:i.type==="array"?t=`Array must contain ${i.exact?"exactly":i.inclusive?"at least":"more than"} ${i.minimum} element(s)`:i.type==="string"?t=`String must contain ${i.exact?"exactly":i.inclusive?"at least":"over"} ${i.minimum} character(s)`:i.type==="number"?t=`Number must be ${i.exact?"exactly equal to ":i.inclusive?"greater than or equal to ":"greater than "}${i.minimum}`:i.type==="date"?t=`Date must be ${i.exact?"exactly equal to ":i.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(i.minimum))}`:t="Invalid input";break;case Q.too_big:i.type==="array"?t=`Array must contain ${i.exact?"exactly":i.inclusive?"at most":"less than"} ${i.maximum} element(s)`:i.type==="string"?t=`String must contain ${i.exact?"exactly":i.inclusive?"at most":"under"} ${i.maximum} character(s)`:i.type==="number"?t=`Number must be ${i.exact?"exactly":i.inclusive?"less than or equal to":"less than"} ${i.maximum}`:i.type==="bigint"?t=`BigInt must be ${i.exact?"exactly":i.inclusive?"less than or equal to":"less than"} ${i.maximum}`:i.type==="date"?t=`Date must be ${i.exact?"exactly":i.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(i.maximum))}`:t="Invalid input";break;case Q.custom:t="Invalid input";break;case Q.invalid_intersection_types:t="Intersection results could not be merged";break;case Q.not_multiple_of:t=`Number must be a multiple of ${i.multipleOf}`;break;case Q.not_finite:t="Number must be finite";break;default:t=e.defaultError,L.assertNever(i)}return{message:t}};let el=qt;function tl(){return el}const Al=i=>{const{data:e,path:t,errorMaps:A,issueData:n}=i,s=[...t,...n.path||[]],a={...n,path:s};if(n.message!==void 0)return{...n,path:s,message:n.message};let r="";const o=A.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 P(i,e){const t=tl(),A=Al({issueData:e,data:i.data,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,t,t===qt?void 0:qt].filter(n=>!!n)});i.common.issues.push(A)}class j{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const A=[];for(const n of t){if(n.status==="aborted")return C;n.status==="dirty"&&e.dirty(),A.push(n.value)}return{status:e.value,value:A}}static async mergeObjectAsync(e,t){const A=[];for(const n of t){const s=await n.key,a=await n.value;A.push({key:s,value:a})}return j.mergeObjectSync(e,A)}static mergeObjectSync(e,t){const A={};for(const n of t){const{key:s,value:a}=n;if(s.status==="aborted"||a.status==="aborted")return C;s.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof a.value<"u"||n.alwaysSet)&&(A[s.value]=a.value)}return{status:e.value,value:A}}}const C=Object.freeze({status:"aborted"}),Fe=i=>({status:"dirty",value:i}),te=i=>({status:"valid",value:i}),pA=i=>i.status==="aborted",gA=i=>i.status==="dirty",Re=i=>i.status==="valid",ut=i=>typeof Promise<"u"&&i instanceof Promise;var E;(function(i){i.errToObj=e=>typeof e=="string"?{message:e}:e||{},i.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(E||(E={}));var ft=function(i,e,t,A){if(t==="a"&&!A)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!A:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?A:t==="a"?A.call(i):A?A.value:e.get(i)},mi=function(i,e,t,A,n){if(A==="m")throw new TypeError("Private method is not writable");if(A==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return A==="a"?n.call(i,t):n?n.value=t:e.set(i,t),t},He,Ne;class be{constructor(e,t,A,n){this._cachedPath=[],this.parent=e,this.data=t,this._path=A,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 mA=(i,e)=>{if(Re(e))return{success:!0,data:e.value};if(!i.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 de(i.common.issues);return this._error=t,this._error}}};function x(i){if(!i)return{};const{errorMap:e,invalid_type_error:t,required_error:A,description:n}=i;if(e&&(t||A))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}=i;return a.code==="invalid_enum_value"?{message:o??r.defaultError}:typeof r.data>"u"?{message:o??A??r.defaultError}:a.code!=="invalid_type"?{message:r.defaultError}:{message:o??t??r.defaultError}},description:n}}class M{get description(){return this._def.description}_getType(e){return fe(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:fe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new j,ctx:{common:e.parent.common,data:e.data,parsedType:fe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(ut(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 A=this.safeParse(e,t);if(A.success)return A.data;throw A.error}safeParse(e,t){const A={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:fe(e)},n=this._parseSync({data:e,path:A.path,parent:A});return mA(A,n)}"~validate"(e){var A,n;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:fe(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:t});return Re(s)?{value:s.value}:{issues:t.common.issues}}catch(s){(n=(A=s==null?void 0:s.message)==null?void 0:A.toLowerCase())!=null&&n.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(s=>Re(s)?{value:s.value}:{issues:t.common.issues})}async parseAsync(e,t){const A=await this.safeParseAsync(e,t);if(A.success)return A.data;throw A.error}async safeParseAsync(e,t){const A={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:fe(e)},n=this._parse({data:e,path:A.path,parent:A}),s=await(ut(n)?n:Promise.resolve(n));return mA(A,s)}refine(e,t){const A=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:Q.custom,...A(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((A,n)=>e(A)?!0:(n.addIssue(typeof t=="function"?t(A,n):t),!1))}_refinement(e){return new qe({schema:this,typeName:I.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 me.create(this,this._def)}nullable(){return Me.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ae.create(this)}promise(){return bt.create(this,this._def)}or(e){return gt.create([this,e],this._def)}and(e){return mt.create(this,e,this._def)}transform(e){return new qe({...x(this._def),schema:this,typeName:I.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new Ut({...x(this._def),innerType:this,defaultValue:t,typeName:I.ZodDefault})}brand(){return new Bl({typeName:I.ZodBranded,type:this,...x(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Lt({...x(this._def),innerType:this,catchValue:t,typeName:I.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return zt.create(this,e)}readonly(){return Tt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const il=/^c[^\s-]{8,}$/i,nl=/^[0-9a-z]+$/,sl=/^[0-9A-HJKMNP-TV-Z]{26}$/i,al=/^[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,rl=/^[a-z0-9_-]{21}$/i,ol=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ll=/^[-+]?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)?)??$/,cl=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,dl="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let kt;const hl=/^(?:(?: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])$/,ul=/^(?:(?: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])$/,fl=/^(([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]))$/,pl=/^(([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])$/,gl=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ml=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,bi="((\\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])))",bl=new RegExp(`^${bi}$`);function wi(i){let e="[0-5]\\d";i.precision?e=`${e}\\.\\d{${i.precision}}`:i.precision==null&&(e=`${e}(\\.\\d+)?`);const t=i.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function wl(i){return new RegExp(`^${wi(i)}$`)}function Ql(i){let e=`${bi}T${wi(i)}`;const t=[];return t.push(i.local?"Z?":"Z"),i.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function vl(i,e){return!!((e==="v4"||!e)&&hl.test(i)||(e==="v6"||!e)&&fl.test(i))}function yl(i,e){if(!ol.test(i))return!1;try{const[t]=i.split("."),A=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),n=JSON.parse(atob(A));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 Pl(i,e){return!!((e==="v4"||!e)&&ul.test(i)||(e==="v6"||!e)&&pl.test(i))}class ge extends M{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==B.string){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_type,expected:B.string,received:s.parsedType}),C}const A=new j;let n;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),A.dirty());else if(s.kind==="max")e.data.length>s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),A.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?P(n,{code:Q.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&P(n,{code:Q.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),A.dirty())}else if(s.kind==="email")cl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"email",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="emoji")kt||(kt=new RegExp(dl,"u")),kt.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"emoji",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="uuid")al.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"uuid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="nanoid")rl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"nanoid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="cuid")il.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"cuid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="cuid2")nl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"cuid2",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="ulid")sl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"ulid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),P(n,{validation:"url",code:Q.invalid_string,message:s.message}),A.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"regex",code:Q.invalid_string,message:s.message}),A.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),A.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),P(n,{code:Q.invalid_string,validation:{startsWith:s.value},message:s.message}),A.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:{endsWith:s.value},message:s.message}),A.dirty()):s.kind==="datetime"?Ql(s).test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:"datetime",message:s.message}),A.dirty()):s.kind==="date"?bl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:"date",message:s.message}),A.dirty()):s.kind==="time"?wl(s).test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:"time",message:s.message}),A.dirty()):s.kind==="duration"?ll.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"duration",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="ip"?vl(e.data,s.version)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"ip",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="jwt"?yl(e.data,s.alg)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"jwt",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="cidr"?Pl(e.data,s.version)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"cidr",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="base64"?gl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"base64",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="base64url"?ml.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"base64url",code:Q.invalid_string,message:s.message}),A.dirty()):L.assertNever(s);return{status:A.value,value:e.data}}_regex(e,t,A){return this.refinement(n=>e.test(n),{validation:t,code:Q.invalid_string,...E.errToObj(A)})}_addCheck(e){return new ge({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...E.errToObj(e)})}url(e){return this._addCheck({kind:"url",...E.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...E.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...E.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...E.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...E.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...E.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...E.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...E.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...E.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...E.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...E.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...E.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,...E.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,...E.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...E.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...E.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...E.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...E.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...E.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...E.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...E.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...E.errToObj(t)})}nonempty(e){return this.min(1,E.errToObj(e))}trim(){return new ge({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ge({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ge({...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}}ge.create=i=>new ge({checks:[],typeName:I.ZodString,coerce:(i==null?void 0:i.coerce)??!1,...x(i)});function kl(i,e){const t=(i.toString().split(".")[1]||"").length,A=(e.toString().split(".")[1]||"").length,n=t>A?t:A,s=Number.parseInt(i.toFixed(n).replace(".","")),a=Number.parseInt(e.toFixed(n).replace(".",""));return s%a/10**n}class Ce extends M{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)!==B.number){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_type,expected:B.number,received:s.parsedType}),C}let A;const n=new j;for(const s of this._def.checks)s.kind==="int"?L.isInteger(e.data)||(A=this._getOrReturnCtx(e,A),P(A,{code:Q.invalid_type,expected:"integer",received:"float",message:s.message}),n.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),n.dirty()):s.kind==="multipleOf"?kl(e.data,s.value)!==0&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.not_multiple_of,multipleOf:s.value,message:s.message}),n.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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,E.toString(t))}gt(e,t){return this.setLimit("min",e,!1,E.toString(t))}lte(e,t){return this.setLimit("max",e,!0,E.toString(t))}lt(e,t){return this.setLimit("max",e,!1,E.toString(t))}setLimit(e,t,A,n){return new Ce({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:A,message:E.toString(n)}]})}_addCheck(e){return new Ce({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:E.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:E.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:E.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:E.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:E.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:E.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:E.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:E.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:E.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 A of this._def.checks){if(A.kind==="finite"||A.kind==="int"||A.kind==="multipleOf")return!0;A.kind==="min"?(t===null||A.value>t)&&(t=A.value):A.kind==="max"&&(e===null||A.value<e)&&(e=A.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Ce.create=i=>new Ce({checks:[],typeName:I.ZodNumber,coerce:(i==null?void 0:i.coerce)||!1,...x(i)});class Ye extends M{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)!==B.bigint)return this._getInvalidInput(e);let A;const n=new j;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),n.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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 P(t,{code:Q.invalid_type,expected:B.bigint,received:t.parsedType}),C}gte(e,t){return this.setLimit("min",e,!0,E.toString(t))}gt(e,t){return this.setLimit("min",e,!1,E.toString(t))}lte(e,t){return this.setLimit("max",e,!0,E.toString(t))}lt(e,t){return this.setLimit("max",e,!1,E.toString(t))}setLimit(e,t,A,n){return new Ye({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:A,message:E.toString(n)}]})}_addCheck(e){return new Ye({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:E.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:E.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:E.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:E.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:E.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}}Ye.create=i=>new Ye({checks:[],typeName:I.ZodBigInt,coerce:(i==null?void 0:i.coerce)??!1,...x(i)});class bA extends M{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==B.boolean){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.boolean,received:A.parsedType}),C}return te(e.data)}}bA.create=i=>new bA({typeName:I.ZodBoolean,coerce:(i==null?void 0:i.coerce)||!1,...x(i)});class pt extends M{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==B.date){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_type,expected:B.date,received:s.parsedType}),C}if(Number.isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_date}),C}const A=new j;let n;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),A.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),A.dirty()):L.assertNever(s);return{status:A.value,value:new Date(e.data.getTime())}}_addCheck(e){return new pt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:E.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:E.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}}pt.create=i=>new pt({checks:[],coerce:(i==null?void 0:i.coerce)||!1,typeName:I.ZodDate,...x(i)});class wA extends M{_parse(e){if(this._getType(e)!==B.symbol){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.symbol,received:A.parsedType}),C}return te(e.data)}}wA.create=i=>new wA({typeName:I.ZodSymbol,...x(i)});class QA extends M{_parse(e){if(this._getType(e)!==B.undefined){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.undefined,received:A.parsedType}),C}return te(e.data)}}QA.create=i=>new QA({typeName:I.ZodUndefined,...x(i)});class vA extends M{_parse(e){if(this._getType(e)!==B.null){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.null,received:A.parsedType}),C}return te(e.data)}}vA.create=i=>new vA({typeName:I.ZodNull,...x(i)});class yA extends M{constructor(){super(...arguments),this._any=!0}_parse(e){return te(e.data)}}yA.create=i=>new yA({typeName:I.ZodAny,...x(i)});class PA extends M{constructor(){super(...arguments),this._unknown=!0}_parse(e){return te(e.data)}}PA.create=i=>new PA({typeName:I.ZodUnknown,...x(i)});class we extends M{_parse(e){const t=this._getOrReturnCtx(e);return P(t,{code:Q.invalid_type,expected:B.never,received:t.parsedType}),C}}we.create=i=>new we({typeName:I.ZodNever,...x(i)});class kA extends M{_parse(e){if(this._getType(e)!==B.undefined){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.void,received:A.parsedType}),C}return te(e.data)}}kA.create=i=>new kA({typeName:I.ZodVoid,...x(i)});class ae extends M{_parse(e){const{ctx:t,status:A}=this._processInputParams(e),n=this._def;if(t.parsedType!==B.array)return P(t,{code:Q.invalid_type,expected:B.array,received:t.parsedType}),C;if(n.exactLength!==null){const a=t.data.length>n.exactLength.value,r=t.data.length<n.exactLength.value;(a||r)&&(P(t,{code:a?Q.too_big:Q.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}),A.dirty())}if(n.minLength!==null&&t.data.length<n.minLength.value&&(P(t,{code:Q.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),A.dirty()),n.maxLength!==null&&t.data.length>n.maxLength.value&&(P(t,{code:Q.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),A.dirty()),t.common.async)return Promise.all([...t.data].map((a,r)=>n.type._parseAsync(new be(t,a,t.path,r)))).then(a=>j.mergeArray(A,a));const s=[...t.data].map((a,r)=>n.type._parseSync(new be(t,a,t.path,r)));return j.mergeArray(A,s)}get element(){return this._def.type}min(e,t){return new ae({...this._def,minLength:{value:e,message:E.toString(t)}})}max(e,t){return new ae({...this._def,maxLength:{value:e,message:E.toString(t)}})}length(e,t){return new ae({...this._def,exactLength:{value:e,message:E.toString(t)}})}nonempty(e){return this.min(1,e)}}ae.create=(i,e)=>new ae({type:i,minLength:null,maxLength:null,exactLength:null,typeName:I.ZodArray,...x(e)});function De(i){if(i instanceof G){const e={};for(const t in i.shape){const A=i.shape[t];e[t]=me.create(De(A))}return new G({...i._def,shape:()=>e})}else return i instanceof ae?new ae({...i._def,type:De(i.element)}):i instanceof me?me.create(De(i.unwrap())):i instanceof Me?Me.create(De(i.unwrap())):i instanceof ke?ke.create(i.items.map(e=>De(e))):i}class G extends M{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)!==B.object){const l=this._getOrReturnCtx(e);return P(l,{code:Q.invalid_type,expected:B.object,received:l.parsedType}),C}const{status:A,ctx:n}=this._processInputParams(e),{shape:s,keys:a}=this._getCached(),r=[];if(!(this._def.catchall instanceof we&&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 be(n,d,n.path,l)),alwaysSet:l in n.data})}if(this._def.catchall instanceof we){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&&(P(n,{code:Q.unrecognized_keys,keys:r}),A.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 be(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=>j.mergeObjectSync(A,l)):j.mergeObjectSync(A,o)}get shape(){return this._def.shape()}strict(e){return E.errToObj,new G({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,A)=>{var s,a;const n=((a=(s=this._def).errorMap)==null?void 0:a.call(s,t,A).message)??A.defaultError;return t.code==="unrecognized_keys"?{message:E.errToObj(e).message??n}:{message:n}}}:{}})}strip(){return new G({...this._def,unknownKeys:"strip"})}passthrough(){return new G({...this._def,unknownKeys:"passthrough"})}extend(e){return new G({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new G({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:I.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new G({...this._def,catchall:e})}pick(e){const t={};for(const A of L.objectKeys(e))e[A]&&this.shape[A]&&(t[A]=this.shape[A]);return new G({...this._def,shape:()=>t})}omit(e){const t={};for(const A of L.objectKeys(this.shape))e[A]||(t[A]=this.shape[A]);return new G({...this._def,shape:()=>t})}deepPartial(){return De(this)}partial(e){const t={};for(const A of L.objectKeys(this.shape)){const n=this.shape[A];e&&!e[A]?t[A]=n:t[A]=n.optional()}return new G({...this._def,shape:()=>t})}required(e){const t={};for(const A of L.objectKeys(this.shape))if(e&&!e[A])t[A]=this.shape[A];else{let s=this.shape[A];for(;s instanceof me;)s=s._def.innerType;t[A]=s}return new G({...this._def,shape:()=>t})}keyof(){return Qi(L.objectKeys(this.shape))}}G.create=(i,e)=>new G({shape:()=>i,unknownKeys:"strip",catchall:we.create(),typeName:I.ZodObject,...x(e)});G.strictCreate=(i,e)=>new G({shape:()=>i,unknownKeys:"strict",catchall:we.create(),typeName:I.ZodObject,...x(e)});G.lazycreate=(i,e)=>new G({shape:i,unknownKeys:"strip",catchall:we.create(),typeName:I.ZodObject,...x(e)});class gt extends M{_parse(e){const{ctx:t}=this._processInputParams(e),A=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 de(r.ctx.common.issues));return P(t,{code:Q.invalid_union,unionErrors:a}),C}if(t.common.async)return Promise.all(A.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 A){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 de(o));return P(t,{code:Q.invalid_union,unionErrors:r}),C}}get options(){return this._def.options}}gt.create=(i,e)=>new gt({options:i,typeName:I.ZodUnion,...x(e)});function Mt(i,e){const t=fe(i),A=fe(e);if(i===e)return{valid:!0,data:i};if(t===B.object&&A===B.object){const n=L.objectKeys(e),s=L.objectKeys(i).filter(r=>n.indexOf(r)!==-1),a={...i,...e};for(const r of s){const o=Mt(i[r],e[r]);if(!o.valid)return{valid:!1};a[r]=o.data}return{valid:!0,data:a}}else if(t===B.array&&A===B.array){if(i.length!==e.length)return{valid:!1};const n=[];for(let s=0;s<i.length;s++){const a=i[s],r=e[s],o=Mt(a,r);if(!o.valid)return{valid:!1};n.push(o.data)}return{valid:!0,data:n}}else return t===B.date&&A===B.date&&+i==+e?{valid:!0,data:i}:{valid:!1}}class mt extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e),n=(s,a)=>{if(pA(s)||pA(a))return C;const r=Mt(s.value,a.value);return r.valid?((gA(s)||gA(a))&&t.dirty(),{status:t.value,value:r.data}):(P(A,{code:Q.invalid_intersection_types}),C)};return A.common.async?Promise.all([this._def.left._parseAsync({data:A.data,path:A.path,parent:A}),this._def.right._parseAsync({data:A.data,path:A.path,parent:A})]).then(([s,a])=>n(s,a)):n(this._def.left._parseSync({data:A.data,path:A.path,parent:A}),this._def.right._parseSync({data:A.data,path:A.path,parent:A}))}}mt.create=(i,e,t)=>new mt({left:i,right:e,typeName:I.ZodIntersection,...x(t)});class ke extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.parsedType!==B.array)return P(A,{code:Q.invalid_type,expected:B.array,received:A.parsedType}),C;if(A.data.length<this._def.items.length)return P(A,{code:Q.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),C;!this._def.rest&&A.data.length>this._def.items.length&&(P(A,{code:Q.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const s=[...A.data].map((a,r)=>{const o=this._def.items[r]||this._def.rest;return o?o._parse(new be(A,a,A.path,r)):null}).filter(a=>!!a);return A.common.async?Promise.all(s).then(a=>j.mergeArray(t,a)):j.mergeArray(t,s)}get items(){return this._def.items}rest(e){return new ke({...this._def,rest:e})}}ke.create=(i,e)=>{if(!Array.isArray(i))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ke({items:i,typeName:I.ZodTuple,rest:null,...x(e)})};class BA extends M{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.parsedType!==B.map)return P(A,{code:Q.invalid_type,expected:B.map,received:A.parsedType}),C;const n=this._def.keyType,s=this._def.valueType,a=[...A.data.entries()].map(([r,o],l)=>({key:n._parse(new be(A,r,A.path,[l,"key"])),value:s._parse(new be(A,o,A.path,[l,"value"]))}));if(A.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 C;(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 C;(l.status==="dirty"||c.status==="dirty")&&t.dirty(),r.set(l.value,c.value)}return{status:t.value,value:r}}}}BA.create=(i,e,t)=>new BA({valueType:e,keyType:i,typeName:I.ZodMap,...x(t)});class je extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.parsedType!==B.set)return P(A,{code:Q.invalid_type,expected:B.set,received:A.parsedType}),C;const n=this._def;n.minSize!==null&&A.data.size<n.minSize.value&&(P(A,{code:Q.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),t.dirty()),n.maxSize!==null&&A.data.size>n.maxSize.value&&(P(A,{code:Q.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 C;c.status==="dirty"&&t.dirty(),l.add(c.value)}return{status:t.value,value:l}}const r=[...A.data.values()].map((o,l)=>s._parse(new be(A,o,A.path,l)));return A.common.async?Promise.all(r).then(o=>a(o)):a(r)}min(e,t){return new je({...this._def,minSize:{value:e,message:E.toString(t)}})}max(e,t){return new je({...this._def,maxSize:{value:e,message:E.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}je.create=(i,e)=>new je({valueType:i,minSize:null,maxSize:null,typeName:I.ZodSet,...x(e)});class DA extends M{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})}}DA.create=(i,e)=>new DA({getter:i,typeName:I.ZodLazy,...x(e)});class EA extends M{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return P(t,{received:t.data,code:Q.invalid_literal,expected:this._def.value}),C}return{status:"valid",value:e.data}}get value(){return this._def.value}}EA.create=(i,e)=>new EA({value:i,typeName:I.ZodLiteral,...x(e)});function Qi(i,e){return new xe({values:i,typeName:I.ZodEnum,...x(e)})}class xe extends M{constructor(){super(...arguments),He.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),A=this._def.values;return P(t,{expected:L.joinValues(A),received:t.parsedType,code:Q.invalid_type}),C}if(ft(this,He,"f")||mi(this,He,new Set(this._def.values),"f"),!ft(this,He,"f").has(e.data)){const t=this._getOrReturnCtx(e),A=this._def.values;return P(t,{received:t.data,code:Q.invalid_enum_value,options:A}),C}return te(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 xe.create(e,{...this._def,...t})}exclude(e,t=this._def){return xe.create(this.options.filter(A=>!e.includes(A)),{...this._def,...t})}}He=new WeakMap;xe.create=Qi;class SA extends M{constructor(){super(...arguments),Ne.set(this,void 0)}_parse(e){const t=L.getValidEnumValues(this._def.values),A=this._getOrReturnCtx(e);if(A.parsedType!==B.string&&A.parsedType!==B.number){const n=L.objectValues(t);return P(A,{expected:L.joinValues(n),received:A.parsedType,code:Q.invalid_type}),C}if(ft(this,Ne,"f")||mi(this,Ne,new Set(L.getValidEnumValues(this._def.values)),"f"),!ft(this,Ne,"f").has(e.data)){const n=L.objectValues(t);return P(A,{received:A.data,code:Q.invalid_enum_value,options:n}),C}return te(e.data)}get enum(){return this._def.values}}Ne=new WeakMap;SA.create=(i,e)=>new SA({values:i,typeName:I.ZodNativeEnum,...x(e)});class bt extends M{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==B.promise&&t.common.async===!1)return P(t,{code:Q.invalid_type,expected:B.promise,received:t.parsedType}),C;const A=t.parsedType===B.promise?t.data:Promise.resolve(t.data);return te(A.then(n=>this._def.type.parseAsync(n,{path:t.path,errorMap:t.common.contextualErrorMap})))}}bt.create=(i,e)=>new bt({type:i,typeName:I.ZodPromise,...x(e)});class qe extends M{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===I.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:A}=this._processInputParams(e),n=this._def.effect||null,s={addIssue:a=>{P(A,a),a.fatal?t.abort():t.dirty()},get path(){return A.path}};if(s.addIssue=s.addIssue.bind(s),n.type==="preprocess"){const a=n.transform(A.data,s);if(A.common.async)return Promise.resolve(a).then(async r=>{if(t.value==="aborted")return C;const o=await this._def.schema._parseAsync({data:r,path:A.path,parent:A});return o.status==="aborted"?C:o.status==="dirty"||t.value==="dirty"?Fe(o.value):o});{if(t.value==="aborted")return C;const r=this._def.schema._parseSync({data:a,path:A.path,parent:A});return r.status==="aborted"?C:r.status==="dirty"||t.value==="dirty"?Fe(r.value):r}}if(n.type==="refinement"){const a=r=>{const o=n.refinement(r,s);if(A.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(A.common.async===!1){const r=this._def.schema._parseSync({data:A.data,path:A.path,parent:A});return r.status==="aborted"?C:(r.status==="dirty"&&t.dirty(),a(r.value),{status:t.value,value:r.value})}else return this._def.schema._parseAsync({data:A.data,path:A.path,parent:A}).then(r=>r.status==="aborted"?C:(r.status==="dirty"&&t.dirty(),a(r.value).then(()=>({status:t.value,value:r.value}))))}if(n.type==="transform")if(A.common.async===!1){const a=this._def.schema._parseSync({data:A.data,path:A.path,parent:A});if(!Re(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:A.data,path:A.path,parent:A}).then(a=>Re(a)?Promise.resolve(n.transform(a.value,s)).then(r=>({status:t.value,value:r})):a);L.assertNever(n)}}qe.create=(i,e,t)=>new qe({schema:i,typeName:I.ZodEffects,effect:e,...x(t)});qe.createWithPreprocess=(i,e,t)=>new qe({schema:e,effect:{type:"preprocess",transform:i},typeName:I.ZodEffects,...x(t)});class me extends M{_parse(e){return this._getType(e)===B.undefined?te(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}me.create=(i,e)=>new me({innerType:i,typeName:I.ZodOptional,...x(e)});class Me extends M{_parse(e){return this._getType(e)===B.null?te(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Me.create=(i,e)=>new Me({innerType:i,typeName:I.ZodNullable,...x(e)});class Ut extends M{_parse(e){const{ctx:t}=this._processInputParams(e);let A=t.data;return t.parsedType===B.undefined&&(A=this._def.defaultValue()),this._def.innerType._parse({data:A,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ut.create=(i,e)=>new Ut({innerType:i,typeName:I.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...x(e)});class Lt extends M{_parse(e){const{ctx:t}=this._processInputParams(e),A={...t,common:{...t.common,issues:[]}},n=this._def.innerType._parse({data:A.data,path:A.path,parent:{...A}});return ut(n)?n.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new de(A.common.issues)},input:A.data})})):{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new de(A.common.issues)},input:A.data})}}removeCatch(){return this._def.innerType}}Lt.create=(i,e)=>new Lt({innerType:i,typeName:I.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...x(e)});class IA extends M{_parse(e){if(this._getType(e)!==B.nan){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.nan,received:A.parsedType}),C}return{status:"valid",value:e.data}}}IA.create=i=>new IA({typeName:I.ZodNaN,...x(i)});class Bl extends M{_parse(e){const{ctx:t}=this._processInputParams(e),A=t.data;return this._def.type._parse({data:A,path:t.path,parent:t})}unwrap(){return this._def.type}}class zt extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:A.data,path:A.path,parent:A});return s.status==="aborted"?C:s.status==="dirty"?(t.dirty(),Fe(s.value)):this._def.out._parseAsync({data:s.value,path:A.path,parent:A})})();{const n=this._def.in._parseSync({data:A.data,path:A.path,parent:A});return n.status==="aborted"?C:n.status==="dirty"?(t.dirty(),{status:"dirty",value:n.value}):this._def.out._parseSync({data:n.value,path:A.path,parent:A})}}static create(e,t){return new zt({in:e,out:t,typeName:I.ZodPipeline})}}class Tt extends M{_parse(e){const t=this._def.innerType._parse(e),A=n=>(Re(n)&&(n.value=Object.freeze(n.value)),n);return ut(t)?t.then(n=>A(n)):A(t)}unwrap(){return this._def.innerType}}Tt.create=(i,e)=>new Tt({innerType:i,typeName:I.ZodReadonly,...x(e)});G.lazycreate;var I;(function(i){i.ZodString="ZodString",i.ZodNumber="ZodNumber",i.ZodNaN="ZodNaN",i.ZodBigInt="ZodBigInt",i.ZodBoolean="ZodBoolean",i.ZodDate="ZodDate",i.ZodSymbol="ZodSymbol",i.ZodUndefined="ZodUndefined",i.ZodNull="ZodNull",i.ZodAny="ZodAny",i.ZodUnknown="ZodUnknown",i.ZodNever="ZodNever",i.ZodVoid="ZodVoid",i.ZodArray="ZodArray",i.ZodObject="ZodObject",i.ZodUnion="ZodUnion",i.ZodDiscriminatedUnion="ZodDiscriminatedUnion",i.ZodIntersection="ZodIntersection",i.ZodTuple="ZodTuple",i.ZodRecord="ZodRecord",i.ZodMap="ZodMap",i.ZodSet="ZodSet",i.ZodFunction="ZodFunction",i.ZodLazy="ZodLazy",i.ZodLiteral="ZodLiteral",i.ZodEnum="ZodEnum",i.ZodEffects="ZodEffects",i.ZodNativeEnum="ZodNativeEnum",i.ZodOptional="ZodOptional",i.ZodNullable="ZodNullable",i.ZodDefault="ZodDefault",i.ZodCatch="ZodCatch",i.ZodPromise="ZodPromise",i.ZodBranded="ZodBranded",i.ZodPipeline="ZodPipeline",i.ZodReadonly="ZodReadonly"})(I||(I={}));const V=ge.create,vt=Ce.create;we.create;const Qe=ae.create,re=G.create;G.strictCreate;gt.create;mt.create;ke.create;const Xt=xe.create;bt.create;me.create;Me.create;const Dl=re({id:V().describe("対応する入力要素のid"),ratio:vt().describe("兄弟間でのratio(weightに比例する)")}).describe("横方向要素、1~2要素 すべてのコマの重要度が低い場合は3要素も許される"),El=re({columns:Qe(Dl),ratio:vt().describe("兄弟間でのratio(weightに比例する)")}).describe("縦方向要素(段)、1~3要素"),Sl=re({rows:Qe(El)}).describe("ページ"),Il=Xt(["4koma","standard"]).describe("基本フォーマット。作風から適切な方を選べ"),Rl=re({name:V().describe("キャラクター名"),appearance:V().describe("キャラクターの容姿。脇役のappearanceは簡潔にすること"),themeColor:V().describe("キャラクターのテーマカラー")}).describe("キャラクター一覧。キャラクタードキュメントにない脇役も列挙しろ"),Cl=re({owner:V(),speech:V().describe("セリフは10文字前後までとしろ。また、適切に改行コード(\\n)を入れ、1行5文字程度に収めろ"),color:V().describe("セリフの色。話者のテーマカラー"),shape:Xt(["rounded","square","ellipse","polygon","shout","soft","none"]).describe("セリフの形。基本はsoft。キャラクタの感情にあわせろ。使ってよいのはsoft, polygon, shout, noneのいずれか。")}).describe("キャラクターのセリフ"),xl=re({composition:V().describe("そのコマの視覚情報。画像生成AIに渡されるプロンプト。セリフや音声情報を含めるな。キャラクターはいなくてもよい。キャラクターのリアクションはオーバーにし、コマごとに大きく変化させろ。"),camera:V().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:Qe(Cl).describe("そのコマのセリフ。セリフがない場合は空配列にしろ"),weight:vt().describe("そのコマの重要度。0~1の範囲で指定しろ。0が最も不要で、1が最も重要")}),ql=re({panels:Qe(xl),layout:Sl.describe("コマの配置").nullable().default(null)}),Ml=re({format:Il,actors:Qe(Rl),pages:Qe(ql)}),vi=re({name:V(),personality:V(),appearance:V(),themeColor:V().describe("テーマカラー。#ffffffff形式"),ulid:V()});Qe(vi);re({theme:V(),characters:Qe(vi),plot:V(),scenario:V(),storyboard:Ml.nullable(),critique:V(),pageNumber:vt().nullable(),format:Xt(["4koma","standard"])});const Ul={paperSize:[840,1188],paperColor:"#FFFFFF",frameColor:"#000000",frameWidth:2,templateName:"standard"};function Ll(){return{theme:"",characters:[],plot:"",scenario:"",critique:"",storyboard:null,pageNumber:null,format:"standard"}}async function Tl(i,e){const t=new Uint8Array(await i.arrayBuffer()),A=Ri.decode(t),n={};if("images"in A&&A.images){e(0);for(const l in A.images){const c=new Blob([A.images[l]],{type:"image/png"}),d=URL.createObjectURL(c),f=new Image;f.src=d,await f.decode(),URL.revokeObjectURL(d);const h=Bt(f);h.envelopeFileId=l,n[l]={type:"image",data:h},e(Object.keys(n).length/Object.keys(A.images).length)}}if("medias"in A&&A.medias){e(0);for(const l in A.medias){const c=A.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 h=new Image;h.src=f,await h.decode(),URL.revokeObjectURL(f);const p=Bt(h);p.envelopeFileId=l,n[l]={type:"image",data:p}}else{const h=document.createElement("video");h.src=f,await CA(h),n[l]={type:"video",data:h}}e(Object.keys(n).length/Object.keys(A.medias).length)}}const s=A.notebook?await $o(A.notebook,async l=>n[l].data):Ll(),a=A.attributes??null;console.log("readEnvelope",A.attributes,a);const r={revision:{id:"not visited",revision:1,prefix:"envelope-"},pages:[],history:{entries:[],cursor:0},direction:A.direction,wrapMode:A.wrapMode,chatLogs:[],notebook:s,attributes:{publishUrl:null,...a??{}},newPageProperty:A.newPageProperty??{...Ul}},o=async l=>n[l].data;for(const l of A.pages){const c=await pi(l.paperSize,l.frameTree,o),d=await _o(l.paperSize,l.bubbles,o),f={id:l.id??Se.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 yi{constructor(e,t,A,n){this.arrayLayer=e,this.layeredCanvas=t,this.focusKeeper=A,this.marks=n}cleanup(){this.layeredCanvas.cleanup()}focusToPage(e,t=1){const A=this.layeredCanvas.viewport,[n,s]=A.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;A.scale=l,A.translate=[-c[0]*l,-c[1]*l],A.dirty=!0,this.layeredCanvas.redraw()}getScale(){return this.layeredCanvas.viewport.scale}resetFontCache(){var e,t;for(const A of this.arrayLayer.array.papers)(t=(e=A.paper)==null?void 0:e.findLayer(ui))==null||t.resetCache()}}function Ol(i,e,t=0,A=-1){console.log("Building renderer...");const n=new ji(i,()=>{}),s=new Yo,a=new Ki(n,!0),r=new JA(a.viewport,()=>{},()=>{},s);a.rootPaper.addLayer(r);let o=[];const l=A<0?e.pages.length:t+A;for(let v=t;v<l;v++){const m=e.pages[v];for(const b of m.bubbles)b.pageNumber=v;o.push(Jl(e,m,s))}const c=Zl(e.direction),{fold:d,gapX:f,gapY:h}=Vl(e.wrapMode),p=[],g=new Vr(o,p,d,f,h,c,()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{});return a.rootPaper.addLayer(g),a.mode="viewer",new yi(g,a,s,p)}function Gl(i){i.cleanup()}function Jl(i,e,t){const A=new OA(e.paperSize,!1),n=new ui(!0);n.setFrameTree(e.frameTree),n.setBubbles(e.bubbles),A.addLayer(n);const s=new KA(e.frameTree,e.bubbles,a=>{console.log(a)},t,i.attributes.showVideoPlayButton??!0,i.attributes.showVideoDottedBorder??!0);return A.addLayer(s),e.frameTree.bgColor=e.paperColor,e.frameTree.borderColor=e.frameColor,e.frameTree.borderWidth=e.frameWidth,A}function Vl(i){switch(i){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 Zl(i){switch(i){case"left-to-right":return 1;case"right-to-left":return-1}}function Fl(i){const e=new Set;for(let t of i.pages)for(let A of t.bubbles)e.add(JSON.stringify({family:A.fontFamily,weight:A.fontWeight}));return[...e].map(t=>JSON.parse(t))}const Pi={源暎アンチック:"GenEiAntiqueNv5-M",源暎エムゴ:"GenEiMGothic2-Black",源暎ぽっぷる:"GenEiPOPle-Bk",源暎ラテゴ:"GenEiLateMinN_v2",源暎ラテミン:"GenEiLateMinN_v2",源暎きわみゴ:"GenEiKiwamiGo",ふい字:"HuiFont29",まきばフォント:"MakibaFont13"};function ki(i){return Pi[i]!==void 0}function Hl(i){return!ki(i)}const RA=new Set;async function Bi(i,e=["400"]){try{const t=`${i}-${e.join("-")}`;if(RA.has(t))return;const A=i.replace(/\s+/g,"+"),n=e.join(";"),s=`https://fonts.googleapis.com/css2?family=${A}: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],h=r.substring(0,c.index).split("}").slice(-1)[0].match(/font-weight: (\d+)/),p=h?h[1]:"400";return new FontFace(i,`url(${d})`,{weight:p,style:"normal"}).load().then(v=>(document.fonts.add(v),v))});await Promise.all(l),await document.fonts.ready,RA.add(t)}catch(t){throw console.error(`Failed to load font "${i}":`,t),t}}async function Nl(i,e=["400"]){try{await Bi(i,e),await document.fonts.ready;const t=e.map(A=>Di(i,A));await Promise.all(t),console.log(`Font "${i}" is fully loaded and ready for Canvas use`)}catch(t){throw console.error(`Failed to load font "${i}" for Canvas:`,t),t}}async function Di(i,e="400",t=20,A=50){const n="あいうえおABCDE12345",s="24px";function a(){const o=document.createElement("canvas").getContext("2d");o.font=`${e} ${s} "${i}"`;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 "${i}" ${e} is ready for Canvas`),!0;await new Promise(o=>setTimeout(o,A))}throw new Error(`Timeout waiting for font "${i}" ${e} to be ready for Canvas`)}exports.Renderer=yi;exports.buildRenderer=Ol;exports.checkCanvasFontAvailable=Di;exports.destroyRenderer=Gl;exports.initPaperJs=fo;exports.isGoogleFont=Hl;exports.isLocalFont=ki;exports.listFonts=Fl;exports.loadGoogleFont=Bi;exports.loadGoogleFontForCanvas=Nl;exports.localFonts=Pi;exports.readEnvelope=Tl;
|
|
13
|
+
`),o=[];for(const l of r){const c=Ao(l),d=no(c),f=zA(h=>{const p=a(h);return{size:p,wrap:e<p}},e,d,0,h=>h&&h.chars&&h.chars.length==1&&Rt.has(h.chars[0]),h=>h&&h.chars&&h.chars.length==1&&Ct.has(h.chars[0]));for(const h of f)o.push({size:h.size,text:h.buffer})}return{height:o.reduce((l,c)=>Math.max(l,c.size),0),width:A*o.length,verticalLines:o.map(l=>l.text)}}function jA(i,e){return i?/[、。」』)】〕”]/.test(i)?/[「『(【〔“]/.test(e)||/[、。]/.test(e)?-.5:-.4:/[「『(【〔“]/.test(e)?-.4:0:/[「『(【〔“]/.test(e)?-.3:0}function lA(i,e,t,A,n,s,a,r,o,l,c){i==="v"?so(e,t,A,n,s,a,r,o,l,c):ao(e,t,A,n,s,a,l,c)}function ao(i,e,t,A,n,s,a,r){a||(a=Jt(i,t.width,A,n,s,r));for(let[o,l]of a.horizontalLines.entries())e==="fill"?i.fillText(l.text,t.x,t.y+n*o+n*.8):e==="stroke"&&i.strokeText(l.text,t.x,t.y+n*o+n*.8)}function ro(i,e,t,A,n,s,a,r){return i==="v"?Gt(e,A*.85,n,s,a,r):Jt(e,t*.85,n,s,a,r)}function Jt(i,e,t,A,n,s){s||(e=1/0);const a=eo(r=>{const o=i.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:A*a.length,horizontalLines:a}}const nt=48,U=10;class q{constructor(){u(this,"n_p0");u(this,"n_p1");u(this,"n_offset");u(this,"rotation");u(this,"text");u(this,"shape");u(this,"embedded");u(this,"fontStyle");u(this,"fontWeight");u(this,"n_fontSize");u(this,"charSkip");u(this,"lineSkip");u(this,"fontFamily");u(this,"direction");u(this,"fontColor");u(this,"fillColor");u(this,"strokeColor");u(this,"n_strokeWidth");u(this,"outlineColor");u(this,"n_outlineWidth");u(this,"autoNewline");u(this,"uuid");u(this,"parent");u(this,"creationContext");u(this,"filmStack");u(this,"scaleLock");u(this,"rubySize");u(this,"rubyDistance");u(this,"displayName");u(this,"optionContext");u(this,"pageNumber");u(this,"fontRenderVersion");u(this,"appearanceDelay");u(this,"hidesText");u(this,"prompt","");u(this,"gallery",[]);u(this,"renderInfo");this.reset(),this.n_p0=[0,0],this.n_p1=[.1,.1],this.text="empty",this.uuid=Se.ulid(),this.parent=null,this.creationContext=this.getStackTrace(),this.filmStack=new lt,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 lt,t.filmStack.films=this.filmStack.films.map(A=>A.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 A=.0011904761904761906,n=q.getUnit(e),s=(r,o,l)=>r??(o!=null?o*n:l*A),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??Se.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,A=(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:A(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:A(e.n_strokeWidth,1*t)?void 0:e.n_strokeWidth,outlineColor:e.outlineColor=="#000000FF"?void 0:e.outlineColor,n_outlineWidth:A(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,A]=q.getPhysicalPoint(e,this.n_p0),[n,s]=q.getPhysicalPoint(e,this.n_p1);return[t,A,n-t,s-A]}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,A]=this.regularized(),[n,s]=q.getPhysicalPoint(e,t),[a,r]=q.getPhysicalPoint(e,A);return[n,s,a-n,r-s]}getPhysicalRegularizedBox(e){const[t,A]=this.regularized();return[q.getPhysicalPoint(e,t),q.getPhysicalPoint(e,A)]}hasEnoughSize(e){const t=this.getPhysicalRect(e);return nt<=t[2]&&nt<=t[3]}static enoughSize(e){return[Math.max(e[0],nt+1),Math.max(e[1],nt+1)]}setPhysicalCenter(e,t){const[A,n]=t,[s,a]=this.getPhysicalSize(e);this.n_p0=q.normalizedPosition(e,[A-s/2,n-a/2]),this.n_p1=q.normalizedPosition(e,[A+s/2,n+a/2])}setPhysicalSize(e,t){const A=[(this.n_p0[0]+this.n_p1[0])/2,(this.n_p0[1]+this.n_p1[1])/2];this.n_p0=[A[0]-t[0]/e[0]/2,A[1]-t[1]/e[1]/2],this.n_p1=[A[0]+t[0]/e[0]/2,A[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),A=q.enoughSize([t[2],t[3]]);this.setPhysicalSize(e,A)}contains(e,t){const[A,n]=t,[s,a]=q.getPhysicalPoint(e,this.n_p0),[r,o]=q.getPhysicalPoint(e,this.n_p1);return s<=A&&A<=r&&a<=n&&n<=o}getHandleAt(e,t){for(let A of Hr){const n=this.getHandleRect(e,A);if(Ni(n,t))return A}return null}getHandleRect(e,t){const[A,n,s,a]=this.getPhysicalRect(e);switch(t){case"topLeft":return[A-U,n-U,U*2,U*2];case"topRight":return[A+s-U,n-U,U*2,U*2];case"bottomLeft":return[A-U,n+a-U,U*2,U*2];case"bottomRight":return[A+s-U,n+a-U,U*2,U*2];case"top":return[A-U,n-U,s+U*2,U*2];case"bottom":return[A-U,n+a-U,s+U*2,U*2];case"left":return[A-U,n-U,U*2,a+U*2];case"right":return[A+s-U,n-U,U*2,a+U*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 cA[this.shape]}initOptions(){this.optionContext=q.getInitialOptions(this)}static getInitialOptions(e,t=!1){const A=cA[e.shape],n={};for(const s of Object.keys(A))A[s].init&&(n[s]=A[s].init(e),t&&A[s].sampleInit&&(n[s]=A[s].sampleInit(e)));return n}calculateFitSize(e){const t=this.getPhysicalFontSize(e),A=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=Gt(a,1/0,this.text,A,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=Jt(a,1/0,this.text,A,n,!1);r=[Math.floor(l.width*1.4),Math.floor(l.height*1.2)]}return console.log(r),q.enoughSize(r)}}const cA={rounded:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.7},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},square:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},ellipse:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>.1}},concentration:{lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:i=>200},lineLength:{label:"線の長さ",type:"number",min:1.05,max:1.5,step:.01,init:i=>1.3}},thought:{lineCount:{label:"線の本数",type:"number",min:100,max:600,step:1,init:i=>400},lineLength:{label:"線の長さ",type:"number",min:.05,max:.5,step:.01,init:i=>.3},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.2,step:.01,init:i=>.14},jitter:{label:"ジッター",type:"number",min:0,max:.5,step:.001,init:i=>.08},waveFrequency:{label:"ウェーブ周期",type:"number",min:8,max:64,step:1,init:i=>8},waveAmplitude:{label:"ウェーブ振幅",type:"number",min:0,max:.1,step:.001,init:i=>0}},polygon:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:i=>7},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.4},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},strokes:{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:i=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:i=>1.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0}},"double-strokes":{randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},vertexCount:{label:"頂点の数",type:"number",min:4,max:20,step:1,init:i=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.5},overRun:{label:"オーバーラン",type:"number",min:1.01,max:1.4,step:.01,init:i=>1.25},interval:{label:"間隔",type:"number",min:.01,max:.2,step:.01,init:i=>.04},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0}},harsh:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:i=>.07},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:i=>15},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},shout:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>6,sampleInit:i=>6},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3,sampleInit:i=>3},bumpSharp:{label:"でっぱりの鋭さ",type:"number",min:.01,max:.5,step:.01,init:i=>.16,sampleInit:i=>.2},bumpCount:{label:"でっぱりの数",type:"number",min:4,max:20,step:1,init:i=>10},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.5,sampleInit:i=>.2},depthJitter:{label:"鋭さジッター",type:"number",min:0,max:1.5,step:.01,init:i=>.5,sampleInit:i=>.1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},soft:{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:i=>.14},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:i=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.4},extract:{label:"食い込み",type:"boolean",init:i=>!1},extractWidth:{label:"食い込み広さ",type:"number",min:0,max:1,step:.01,init:i=>.2},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:i=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},heart:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},diamond:{link:{hint:"結合",icon:"unite"},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},arrow:{link:{hint:"結合",icon:"unite"},shaftWidth:{label:"軸の太さ",type:"number",min:0,max:1,step:.01,init:i=>.5},headLength:{label:"矢じりの長さ",type:"number",min:0,max:1,step:.01,init:i=>.5},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0}},"motion-lines":{focalPoint:{hint:"内円の中心",icon:"circle",init:i=>[0,0]},focalRange:{hint:"内円の範囲",icon:"radius",init:i=>[0,40]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},lineCount:{label:"線の本数",type:"number",min:100,max:300,step:1,init:i=>200},lineWidth:{label:"線の太さ",type:"number",min:.01,max:.1,step:.01,init:i=>.05},angleJitter:{label:"角度ジッター",type:"number",min:0,max:.2,step:.01,init:i=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:1,step:.01,init:i=>.5}},"speed-lines":{tailTip:{hint:"流線の先端",icon:"tail",init:i=>[40,0]},tailMid:{hint:"流線の途中",icon:"curve",init:i=>[.5,0]},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>0},lineCount:{label:"線の本数",type:"number",min:10,max:200,step:1,init:i=>70},lineWidth:{label:"線の太さ",type:"number",min:.01,max:1,step:.01,init:i=>.2},laneJitter:{label:"間隔ジッター",type:"number",min:0,max:.2,step:.01,init:i=>.05},startJitter:{label:"起点ジッター",type:"number",min:0,max:.5,step:.01,init:i=>.3}},"ellipse-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:i=>1}},"soft-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},randomSeed:{label:"乱数調整",type:"number",min:0,max:100,step:1,init:i=>36},superEllipse:{label:"矩形っぽさ",type:"number",min:1,max:8,step:.1,init:i=>3},bumpDepth:{label:"でこぼこの深さ",type:"number",min:.01,max:.2,step:.01,init:i=>.15},bumpCount:{label:"でこぼこの数",type:"number",min:4,max:20,step:1,init:i=>5},angleJitter:{label:"角度ジッター",type:"number",min:0,max:1,step:.1,init:i=>.4},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},smoothing:{label:"スムース",type:"boolean",init:i=>!0},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:i=>1}},"rounded-mind":{link:{hint:"結合",icon:"unite"},tailTip:{hint:"しっぽの先端",icon:"tail",init:i=>[0,0]},tailMid:{hint:"しっぽの途中",icon:"curve",init:i=>[.5,0]},tailWidth:{label:"しっぽの幅",type:"number",min:.2,max:2,step:.01,init:i=>1},xStraight:{label:"横線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.6},yStraight:{label:"縦線の長さ",type:"number",min:0,max:.9,step:.01,init:i=>.7},shapeExpand:{label:"はみだし",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutline:{label:"フチ",type:"number",min:0,max:.2,step:.01,init:i=>0},shapeOutlineColor:{label:"フチの色",type:"color",init:i=>"#ffffffff"},roughness:{label:"ラフさ",type:"number",min:0,max:5,step:.1,init:i=>0},flattening:{label:"扁平度",type:"number",min:.5,max:2,step:.1,init:i=>1}},none:{}};class KA extends wt{constructor(t,A,n,s,a,r){super();u(this,"selected",null);u(this,"playIcon");u(this,"dashPhase",0);u(this,"lastNow",null);u(this,"dashSpeed",10);u(this,"showPlayButton");u(this,"showDottedBorder");u(this,"onVisibilityChangeBound",null);this.frameTree=t,this.bubbles=A,this.onFocus=n,this.focusKeeper=s,this.playIcon=new ne(["viewerLayer/play.webp"],[32,32],[1,1],"再生",()=>!0,()=>this.paper.matrix),s.subscribe(this.changeFocus.bind(this)),this.showPlayButton=a,this.showDottedBorder=r,this.onVisibilityChangeBound=this.onVisibilityChange.bind(this),document.addEventListener("visibilitychange",this.onVisibilityChangeBound)}renderDepths(){return[0,1]}calculateRootLayout(){return St(this.frameTree,this.getPaperSize(),[0,0])}render(t,A){if(A===0){const n=this.calculateRootLayout();this.interactable&&this.renderLayoutRecursive(t,n),this.renderFramePlayButtons(t,n)}A===1&&this.renderBubblePlayButtons(t)}renderLayoutRecursive(t,A){var n;t.strokeStyle="rgba(0, 200, 200, 0.2)",t.lineWidth=2,t.beginPath(),t.moveTo(...A.corners.topLeft),t.lineTo(...A.corners.topRight),t.lineTo(...A.corners.bottomRight),t.lineTo(...A.corners.bottomLeft),t.closePath(),t.stroke(),(n=A.children)==null||n.forEach(s=>{this.renderLayoutRecursive(t,s)})}renderFramePlayButtons(t,A){var n;this.hasVideo(A==null?void 0:A.element.filmStack)&&(this.showDottedBorder&&Dt(t,"rgba(128, 128, 128, 1)",A.corners,2,5,!1,this.dashPhase,[20,20]),this.showPlayButton&&(this.playIcon.position=Pe(A.corners.bottomRight,[8,8]),this.playIcon.pivot=[1,1],this.playIcon.shadowColor="rgba(0, 0, 0, 0.5)",this.playIcon.render(t))),(n=A.children)==null||n.forEach(s=>{this.renderFramePlayButtons(t,s)})}renderBubblePlayButtons(t){for(const A of this.bubbles)if(this.hasVideo(A.filmStack)){const n=this.getPaperSize(),[s,a,r,o]=A.getPhysicalRect(n),l=[s+r/2,a];this.showDottedBorder&&Dt(t,"rgba(128, 128, 128, 1)",VA([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,A,n){if(ze.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=HA(s,t,0);return a?{action:"click",layout:a}:(this.selectTarget(null),null)}}async*pointer(t,A){A.action==="click"&&this.handleClick(A.layout)}async keyDown(t,A){return A.code==="Escape"?(this.selectTarget(null),!0):!1}changeFocus(t){t!==this&&(this.onFocus(null),this.redraw())}isSameTarget(t,A){if(t===A)return!0;if(!t||!A)return!1;const n=s=>s.element!==void 0;return n(t)&&n(A)?t.element===A.element:!n(t)&&!n(A)?t===A:!1}selectTarget(t){this.isSameTarget(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 A;if(t){const n=this.getFilmStack(t);for(const s of n.films)s.content.kind==="media"&&((A=s.content.media.player)==null||A.pause())}}startVideo(t){if(!t)return;const A=this.getFilmStack(t);for(const n of A.films)n.content.kind==="media"&&n.content.media.player&&n.content.media.player.play()}onVisibilityChange(){if(!document.hidden&&this.selected){const t=this.getFilmStack(this.selected);for(const A of t.films){if(A.content.kind!=="media")continue;const n=A.content.media.drawSource;n instanceof HTMLVideoElement&&n.paused&&A.content.media.player&&A.content.media.player.play()}}}tick(t){if(this.hasAnyVideo()&&this.showDottedBorder){this.lastNow==null&&(this.lastNow=t);const A=t-this.lastNow;this.lastNow=t,this.dashPhase=(this.dashPhase+this.dashSpeed*A/1e3)%1e4,this.redraw()}if(this.selected){const A=this.getFilmStack(this.selected);for(const n of A.films){if(n.content.kind!=="media")continue;const s=n.content.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 A of t.films)if(A.content.kind==="media"&&A.content.media.player)return!0;return!1}hasAnyVideoInFrames(t){if(this.hasVideo(t.filmStack))return!0;if(t.children){for(const A of t.children)if(this.hasAnyVideoInFrames(A))return!0}return!1}hasAnyVideo(){if(this.hasAnyVideoInFrames(this.frameTree))return!0;for(const t of this.bubbles)if(this.hasVideo(t.filmStack))return!0;return!1}get interactable(){return this.mode==null}tearDown(){this.onVisibilityChangeBound&&(document.removeEventListener("visibilitychange",this.onVisibilityChangeBound),this.onVisibilityChangeBound=null),this.selected&&this.stopVideo(this.selected),super.tearDown()}}GA(KA);var Ze=[];function _A(i){if(Ze=[],i.length==3)return i.push(i[0]),i;var e=oo(i);return ct(e,i),ct([e[1],e[0]],i),Ze.push(Ze[0]),Ze}function oo(i){var e,t,A;for(t=i[0],A=i[0],e=1;e<i.length;e++)i[e][0]<t[0]&&(t=i[e]),i[e][0]>A[0]&&(A=i[e]);return[t,A]}function lo(i,e){var t=e[1][1]-e[0][1],A=e[0][0]-e[1][0];return A*(i[1]-e[0][1])+t*(i[0]-e[0][0])}function co(i,e){var t,A=[],n,s,a=0,r=0;for(t=0;t<e.length;t++){if(n=e[t],a=lo(n,i),a>0)A.push(n);else continue;a>r&&(s=n,r=a)}return{points:A,max:s}}function ct(i,e){var t=co(i,e);if(!t.max)return Ze.push(i[0]);ct([i[0],t.max],t.points),ct([t.max,i[1]],t.points)}function Ie(i,e,t){const[A,n]=i,[s,a]=e,[r,o]=t,[l,c]=[r*s+o*a,r*a-o*s];return[l+A,c+n]}function Ue(i,e,t=.5){const A=[];for(let n=0;n<e;n++){const s=(i()-.5)/e*t,a=(n/e+s)*2*Math.PI;A.push(a)}return A}function Le(i,e,t=3){return e.map(A=>Zi(i[0]/2,i[1]/2,t,A))}function ho(i,e,t,A,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+(i()-.5)*A,d=l*c,[f,h]=[r*d/l,o*d/l];s.push([f,h])}else s.push(e[a]);return s}function uo(i,e,t){const A=Fi(i,e),n=Pe(e,i),s=ce(n),a=Xe(s,t);return ye(A,a)}function Qt(i,e,t){const A=Math.min(i[0],i[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(uo(r,o,A))}return n}function Z(i){return`rgba(${i[0]}, ${i[1]}, ${i[2]}, ${i[3]})`}function fo(){z.setup([1,1]),z.view.autoUpdate=!1}function Vt(i,e,t,A,n,s){switch(t=s.randomSeed??0,n){case"rounded":Co(i,e,t,A,s);break;case"square":Io(i,e,t,A,s);break;case"ellipse":So(i,e,t,A,s);break;case"concentration":po(i,e,t,A,s);break;case"thought":go(i,e,t,A,s);break;case"polygon":Ro(i,e,t,A,s);break;case"strokes":bo(i,e,t,A,s);break;case"double-strokes":wo(i,e,t,A,s);break;case"harsh":xo(i,e,t,A,s);break;case"shout":qo(i,e,t,A,s);break;case"soft":Mo(i,e,t,A,s);break;case"heart":Uo(i,e,t,A,s);break;case"diamond":Lo(i,e,t,A,s);break;case"arrow":To(i,e,t,A,s);break;case"motion-lines":Qo(i,e,t,A,s);break;case"speed-lines":vo(i,e,t,A,s);break;case"ellipse-mind":Oo(i,e,t,A,s);break;case"soft-mind":Go(i,e,t,A,s);break;case"rounded-mind":Jo(i,e,t,A,s);break;case"none":break;default:throw new Error(`Unknown bubble : ${n}`)}}function po(i,e,t,A,n){const[s,a]=A;if(e==="fill"){i.save(),i.translate(0,0),i.scale(s/2,a/2),i.lineWidth=1/Math.min(s,a);const r=n.lineCount;i.save();const o=i.createRadialGradient(0,0,1,0,0,n.lineLength),l=i.strokeStyle,c=ee(l),d=ee(l);c[3]=0,o.addColorStop(0,Z(d)),o.addColorStop(1,Z(c)),i.strokeStyle=o,i.beginPath();for(let f=0;f<r;f++){const h=f*2*Math.PI/r,[p,g]=[Math.cos(h),Math.sin(h)],[v,m]=[p*n.lineLength,g*n.lineLength];i.moveTo(p,g),i.lineTo(v,m)}i.closePath(),i.stroke(),i.restore(),i.restore()}else e==="clip"&&(i.beginPath(),i.ellipse(0,0,s*.5,a*.5,0,0,2*Math.PI),i.clip())}function go(i,e,t,A,n){const s=Ae(t),[a,r]=A;if(e==="fill"){i.save(),i.translate(0,0),i.scale(a/2,r/2),i.beginPath(),i.ellipse(0,0,1,1,0,0,2*Math.PI),i.fill(),i.lineWidth=1;const o=n.lineCount;i.save(),i.createRadialGradient(0,0,1,0,0,n.lineLength);const l=i.strokeStyle;i.fillStyle=l;const d=n.lineLength*.5,f=1-d,h=1+d;for(let p=0;p<o;p++){const g=p*2*Math.PI/o,[v,m]=[Math.cos(g),Math.sin(g)],[b,D]=Ee([v,m],f),[w,y]=Ee([v,m],h),k=s()*n.jitter,S=s()*n.jitter,R=1+Math.sin(g*n.waveFrequency)*n.waveAmplitude,T=Ee([b,D],(1-k)*R),F=Ee([w,y],(1+S)*R);mo(i,T,F,n.lineWidth)}i.restore(),i.restore()}else e==="clip"&&(i.beginPath(),i.ellipse(0,0,a*.5,r*.5,0,0,2*Math.PI),i.clip())}function mo(i,e,t,A){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*A/2,r+l*A/2],[f,h]=[a-o*A/2,r-l*A/2];i.beginPath(),i.moveTo(e[0],e[1]),i.lineTo(e[0]+c,e[1]+d),i.lineTo(t[0],t[1]),i.lineTo(e[0]+f,e[1]+h),i.closePath(),i.fill()}function bo(i,e,t,A,n){$A(i,e,t,A,n,!1)}function wo(i,e,t,A,n){$A(i,e,t,A,n,!0)}function $A(i,e,t,A,n,s){const a=Ae(t),r=Le(A,Ue(a,n.vertexCount,n.angleJitter),n.superEllipse),o=_A(r);if(e=="fill"||e=="clip"){const l=new z.Path;for(let c=0;c<o.length;c++){const d=o[c];c===0?l.moveTo(d):l.lineTo(d)}l.closed=!0,J(i,e,l,n),l.remove()}else{const l=i.strokeStyle;for(let c=0;c<o.length;c++){i.beginPath();const d=o[c],f=o[(c+1)%o.length],[h,p]=yo(d,f,n.overRun),g=i.createLinearGradient(...h,...p),v=ee(l),m=ee(l);if(v[3]=0,g.addColorStop(0,Z(v)),g.addColorStop(.15,Z(m)),g.addColorStop(.85,Z(m)),g.addColorStop(1,Z(v)),i.strokeStyle=g,i.moveTo(h[0],h[1]),i.lineTo(p[0],p[1]),s){const b=Math.min(A[0],A[1])*n.interval,[D,w]=[f[0]-d[0],f[1]-d[1]],[y,k]=[-w,D],[S,R]=[y/Math.sqrt(y*y+k*k),k/Math.sqrt(y*y+k*k)],[T,F]=[h[0]+S*b,h[1]+R*b],[H,N]=[p[0]+S*b,p[1]+R*b];i.moveTo(T,F),i.lineTo(H,N)}i.stroke()}}}function Qo(i,e,t,A,n){const[s,a,r,o]=Te(A);if(e==="fill"){const l=Ae(t);i.save(),i.beginPath(),i.rect(s,a,r,o),i.clip(),i.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],h=Math.hypot(f[0],f[1]),[p,g,v]=[0,0,Math.hypot(r/2,o/2)],[m,b,D]=[d[0],d[1],h],w=i.createRadialGradient(m,b,D,p,g,v),y=ee(i.strokeStyle),k=ee(i.strokeStyle);y[3]=0,w.addColorStop(0,Z(y)),w.addColorStop(.2,Z(k)),w.addColorStop(1,Z(k)),i.fillStyle=w;for(let S=0;S<c;S++){const R=S*2*Math.PI/c+(l()-.5)*n.angleJitter,[T,F]=[Math.cos(R),Math.sin(R)],H=D*(1+l()*n.startJitter),N=[m,b],W=[p+T*v,g+F*v],Y=[W[0]-N[0],W[1]-N[1]],oe=Math.hypot(...Y),he=[N[0]+Y[0]*H/oe,N[1]+Y[1]*H/oe],Oe=n.lineWidth*.1,[Ge,Je]=[ce(Y,Oe),ce(Y,-Oe)];i.beginPath(),i.moveTo(he[0],he[1]),i.lineTo(W[0]+Ge[0],W[1]+Ge[1]),i.lineTo(W[0]+Je[0],W[1]+Je[1]),i.closePath(),i.fill()}i.restore()}}function vo(i,e,t,A,n){const[s,a,r,o]=Te(A);if(e==="fill"){const l=Ae(t);i.save();try{let c=function([b,D]){const w=[h*.5,0],[y,k]=TA(w,p),S=.5-LA([b,D],[y,k])*.5;return rt(S)};i.beginPath(),i.rect(s,a,r,o),i.clip();const d=(n==null?void 0:n.tailTip)??[0,0],f=Ie([0,0],d,(n==null?void 0:n.tailMid)??[0,0]),h=Math.hypot(r,o);if(!Number.isFinite(h)||h<=1e-6)return;const p=Math.atan2(d[1],d[0]);i.rotate(p),i.lineWidth=1;const g=n.lineCount,v=rt(.5-MA(d)/h),m=c(f);for(let b=0;b<g;b++){const D=(b+.5)/g*h-h/2+l()*h*n.laneJitter,w=-h*.5+(l()-.5)*r*n.startJitter,y=o*n.lineWidth*.01*(l()+.5);try{const k=i.createLinearGradient(w+h,D,w,D),S=ee(i.strokeStyle),R=ee(i.strokeStyle);S[3]=0,k.addColorStop(v,Z(S)),k.addColorStop(m,Z(R)),k.addColorStop(1,Z(R)),i.fillStyle=k}catch(k){throw console.error("drawSpeedLinesBubble: gradient addColorStop failed",{seed:t,i:b,length:h,angle:p,tailTip:d,tailMid:f,psf0:v,psf1:m,y:D,lx:w,lw:y,lineCount:g,strokeStyle:i.strokeStyle,opts:n,error:k}),k}i.beginPath(),i.moveTo(w,D-y),i.lineTo(w+h,D),i.lineTo(w,D+y),i.closePath(),i.fill()}}catch(c){throw console.error("drawSpeedLinesBubble: unexpected error",{seed:t,size:A,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{i.restore()}}}function yo(i,e,t){const[A,n]=[e[0]-i[0],e[1]-i[1]],s=[e[0]-A*t,e[1]-n*t],a=[i[0]+A*t,i[1]+n*t];return[s,a]}function Po(i,e,t,A){A=t.randomSeed??0,performance.now();try{switch(i){case"square":return ei(e,t,A);case"ellipse":return Zt(e,t,A);case"polygon":return li(e,t,A);case"rounded":return Ft(e,t,A);case"harsh":return ti(e,t,A);case"shout":return Ai(e,t,A);case"soft":return Ht(e,t,A);case"heart":return ii(e,t,A);case"diamond":return ni(e,t,A);case"arrow":return si(e,t,A);case"ellipse-mind":return ai(e,t,A);case"soft-mind":return ri(e,t,A);case"rounded-mind":return oi(e,t,A);case"concentration":case"thought":case"none":return null}return console.error(`Unknown bubble shape: ${i}`),null}finally{}}function Te(i){return[-i[0]*.5,-i[1]*.5,i[0],i[1]]}function ko(i){return[i[0]*.5,i[1]*.5]}function ei(i,e,t){const A=new z.Path.Rectangle(Te(i));return ve(A,i,e)}function Zt(i,e,t){const A=new z.Path.Ellipse({center:[0,0],radius:ko(i)});return ve(A,i,e)}function Ft(i,e,t){const[A,n,s,a]=Te(i),[r,o]=[0,0],[l,c]=[A+s,n+a],[d,f]=[e.xStraight*s*.5,e.yStraight*a*.5],h=new z.Path;return h.moveTo([r+d,n]),h.lineTo([r-d,n]),h.quadraticCurveTo([A,n],[A,o-f]),h.lineTo([A,o+f]),h.quadraticCurveTo([A,c],[r-d,c]),h.lineTo([r+d,c]),h.quadraticCurveTo([l,c],[l,o+f]),h.lineTo([l,o-f]),h.quadraticCurveTo([l,n],[r+d,n]),h.closed=!0,ve(h,i,e)}function ti(i,e,t){const A=Ae(t);let n=Ue(A,e.bumpCount,e.angleJitter);const s=Le(i,n,e.superEllipse);let a=Qt(i,s,e.bumpDepth);const r=new z.Path;return r.addSegments(a),r.closed=!0,ve(r,i,e)}function Ai(i,e,t){const A=e.bumpSharp,n=Ae(t);let s;const a=Ue(n,e.bumpCount,e.angleJitter);s=Le(i,a,e.superEllipse),s=Qt(i,s,A),s=ho(n,s,A,e.depthJitter);const r=new z.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,ve(r,i,e)}function Ht(i,e,t){const A=Ae(t),n=Le(i,Ue(A,e.bumpCount,e.angleJitter),e.superEllipse),s=Qt(i,n,-e.bumpDepth),a=new z.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 ve(a,i,e)}function ii(i,e,t){const[A,n]=i,[s,a]=[0,0],r=n*-.58,o=n*-.35,l=n*-.1,c=n*.1,d=n*.35,f=n*.5,h=new z.Path;return h.moveTo([s,a+o]),h.cubicCurveTo([-.1*A,r],[-.5*A,r],[-.5*A,l]),h.cubicCurveTo([-.5*A,c],[-.3*A,d],[0,f]),h.cubicCurveTo([.3*A,d],[.5*A,c],[.5*A,l]),h.cubicCurveTo([.5*A,r],[.1*A,r],[0,o]),h.closed=!0,h}function ni(i,e,t){const[A,n,s,a]=Te(i),r=new z.Path;return r.moveTo([0,n]),r.lineTo([A,0]),r.lineTo([0,n+a]),r.lineTo([A+s,0]),r.closed=!0,r}function si(i,e,t){const[A,n,s,a]=Te(i),{shaftWidth:r,headLength:o}=e,l=r*s*.5,c=new z.Path,d=n+a*o,f=A+s*.5-l,h=A+s*.5+l;return c.moveTo([0,n]),c.lineTo([A,d]),c.lineTo([f,d]),c.lineTo([f,n+a]),c.lineTo([h,n+a]),c.lineTo([h,d]),c.lineTo([A+s,d]),c.lineTo([0,n]),c.closed=!0,c}function ai(i,e,t){const A={...e};A.tailTip=[0,0],A.tailMid=[.5,0];const n=Zt(i,A);return Nt(n,t,i,e,A)}function ri(i,e,t){const A={...e};A.tailTip=[0,0],A.tailMid=[.5,0];const n=Ht(i,A,t);return Nt(n,t,i,e,A)}function oi(i,e,t){const A={...e};A.tailTip=[0,0],A.tailMid=[.5,0];const n=Ft(i,A);return Nt(n,t,i,e,A)}function Bo(i,e,t,A,n,s){const a=Ae(t),r=Le(i,Ue(a,A),n),o=Qt(i,r,-s),l=new z.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,ve(l,i,e)}function ve(i,e,t){if(t!=null&&t.tailTip){const A=t.tailTip,n=t.tailMid;if(!(A[0]===0&&A[1]===0))if(t!=null&&t.extract){const s=Eo(e,n,A,t.extractWidth),a=i.subtract(s);return i.remove(),s.remove(),a}else{const s=Do(e,n,A,t.tailWidth),a=i.unite(s);return i.remove(),s.remove(),a}}return i}function Do(i,e,t,A){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=i[0]*i[1]*A,s=Math.max(5e4,Math.hypot(t[0],t[1])**2),a=Xe(ce(t),n*35/s),r=Xe(ce(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,h=Ie(d,o,e),p=Ie(f,l,e),g=new z.Path;return g.moveTo(d),g.curveTo(h,c),g.curveTo(p,f),g.closed=!0,g}function Eo(i,e,t,A){(e==null||e[0]==0&&e[1]==0)&&(e=[.5,0]);const n=Ie([0,0],t,e),s=[t[0]-n[0],t[1]-n[1]],a=Math.hypot(t[0],t[1]),r=Xe(ce(s),a*A),o=[t[0]+r[0],t[1]+r[1]],l=[t[0]-r[0],t[1]-r[1]],c=new z.Path;return c.moveTo(n),c.lineTo(o),c.lineTo(l),c.closed=!0,c}function li(i,e,t){const A=Ae(t),n=Ue(A,e.vertexCount,e.angleJitter),s=Le(i,n,e.superEllipse),a=_A(s),r=new z.Path;return r.addSegments(a),r.closed=!0,ve(r,i,e)}function So(i,e,t,A,n){const s=Zt(A,n);J(i,e,s,n)}function Io(i,e,t,A,n){const s=ei(A,n);J(i,e,s,n)}function Ro(i,e,t,A,n){const s=li(A,n,t);J(i,e,s,n)}function Co(i,e,t,A,n){const s=Ft(A,n);J(i,e,s,n)}function xo(i,e,t,A,n){const s=ti(A,n,t);J(i,e,s,n)}function qo(i,e,t,A,n){const s=Ai(A,n,t);J(i,e,s,n)}function Mo(i,e,t,A,n){const s=Ht(A,n,t);J(i,e,s,n)}function Uo(i,e,t,A,n){const s=ii(A);J(i,e,s,n)}function Lo(i,e,t,A,n){const s=ni(A);J(i,e,s,n)}function To(i,e,t,A,n){const s=si(A,n);J(i,e,s,n)}function Oo(i,e,t,A,n){const s=ai(A,n,t);J(i,e,s,n)}function Go(i,e,t,A,n){const s=ri(A,n,t);J(i,e,s,n)}function Jo(i,e,t,A,n){const s=oi(A,n,t);J(i,e,s,n)}function J(i,e,t,A){switch(i.beginPath(),e){case"fill":i.fill(new Path2D(t.pathData));break;case"stroke":const n=A.roughness??0;if(0<n){const s=(A.randomSeed??0)+1;Ii.canvas(i.canvas,{options:{seed:s,roughness:n,strokeWidth:i.lineWidth,stroke:i.strokeStyle}}).path(t.pathData)}else i.stroke(new Path2D(t.pathData));break;case"clip":i.clip(new Path2D(t.pathData));break}}function Nt(i,e,t,A,n){const s=[[.97,.04],[.8,.05],[.6,.08],[.3,.12]],a=Ie([0,0],A.tailTip,A.tailMid),r=A.tailTip,o=[r[0]-a[0],r[1]-a[1]],l=Math.min(t[0],t[1])*.5*A.tailWidth,c=(A==null?void 0:A.flattening)??1;for(let d of s){const f=[a[0]+d[0]*o[0],a[1]+d[0]*o[1]],h=l*d[1]*2,p=Bo([h,h],n,e,6,2,.15);if(c&&Math.abs(c-1)>1e-6){const g=c>1?1/c:1,v=c<1?c:1;p.scale(g,v,[0,0])}p.translate(f),i=i.unite(p)}return i}function st(i,e,t,A=!0){const n=[],s=r=>((t[0]-e[0])*(r[1]-e[1])-(t[1]-e[1])*(r[0]-e[0]))*(A?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]),h=((e[0]-r[0])*d+(e[1]-r[1])*f)/(l*d+c*f);return[r[0]+h*l,r[1]+h*c]};for(let r=0;r<i.length;r++){const o=i[r],l=i[(r+i.length-1)%i.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 dA(i,e,t,A){const[n,s]=e;let a=[[0,0],[n,0],[n,s],[0,s]];if(t.top){const r=At(i.topLeft,i.topRight,-A);a=st(a,...r)}if(t.right){const r=At(i.topRight,i.bottomRight,-A);a=st(a,...r)}if(t.bottom){const r=At(i.bottomRight,i.bottomLeft,-A);a=st(a,...r)}if(t.left){const r=At(i.bottomLeft,i.topLeft,-A);a=st(a,...r)}return a}function pe(i,e,t,A){return Number.isFinite(i)?Math.min(t,Math.max(e,i)):A}function se(i,e,t){const A=i.params[e];if(typeof A=="number")return A;if(typeof A=="string"){const n=Number(A);if(Number.isFinite(n))return n}return t}function dt(i,e,t){const A=i.params[e];if(Array.isArray(A)&&A.length>=2){const n=Number(A[0]),s=Number(A[1]);if(Number.isFinite(n)&&Number.isFinite(s))return[n,s]}return[...t]}const Vo={draw(i,e,t){const A=t,n=t;e.save();try{e.translate(t/2,t/2);const s=Ae(String(se(i,"randomSeed",0))),a=dt(i,"focalPoint",[0,0]),r=dt(i,"focalRange",[0,40]),o=pe(se(i,"lineCount",200),100,300,200),l=pe(se(i,"lineWidth",.05),.01,.1,.05),c=pe(se(i,"angleJitter",.05),0,.2,.05),d=pe(se(i,"startJitter",.5),0,1,.5),f=String(i.params.color||"#000000");e.lineWidth=1;const h=a,p=r,g=Math.hypot(p[0],p[1]),[v,m,b]=[0,0,Math.hypot(A/2,n/2)],[D,w,y]=[h[0],h[1],g],k=e.createRadialGradient(D,w,y,v,m,b),S=ee(f),R=ee(f);S[3]=0,k.addColorStop(0,Z(S)),k.addColorStop(.2,Z(R)),k.addColorStop(1,Z(R)),e.fillStyle=k;for(let T=0;T<o;T++){const F=T*2*Math.PI/o+(s()-.5)*c,[H,N]=[Math.cos(F),Math.sin(F)],W=y*(1+s()*d),Y=[D,w],oe=[v+H*b,m+N*b],he=[oe[0]-Y[0],oe[1]-Y[1]],Oe=Math.hypot(...he),Ge=[Y[0]+he[0]*W/Oe,Y[1]+he[1]*W/Oe],Je=l*.1,[Yt,jt]=[ce(he,Je),ce(he,-Je)];e.beginPath(),e.moveTo(Ge[0],Ge[1]),e.lineTo(oe[0]+Yt[0],oe[1]+Yt[1]),e.lineTo(oe[0]+jt[0],oe[1]+jt[1]),e.closePath(),e.fill()}}finally{e.restore()}}},Zo={draw(i,e,t){const A=t,n=t;e.save();try{let s=function([b,D]){const w=[p*.5,0],[y,k]=TA(w,g),S=.5-LA([b,D],[y,k])*.5;return rt(S)};e.translate(t/2,t/2);const a=Ae(String(se(i,"randomSeed",0))),r=dt(i,"tailTip",[40,0]),o=Ie([0,0],r,dt(i,"tailMid",[.5,0])),l=pe(se(i,"lineCount",70),10,200,70),c=pe(se(i,"lineWidth",.2),.01,1,.2),d=pe(se(i,"laneJitter",.05),0,.2,.05),f=pe(se(i,"startJitter",.3),0,.5,.3),h=String(i.params.color||"#000000"),p=Math.hypot(A,n);if(!Number.isFinite(p)||p<=1e-6)return;const g=Math.atan2(r[1],r[0]);e.rotate(g),e.lineWidth=1;const v=rt(.5-MA(r)/p),m=s(o);for(let b=0;b<l;b++){const D=(b+.5)/l*p-p/2+a()*p*d,w=-p*.5+(a()-.5)*A*f,y=n*c*.01*(a()+.5),k=e.createLinearGradient(w+p,D,w,D),S=ee(h),R=ee(h);S[3]=0,k.addColorStop(v,Z(S)),k.addColorStop(m,Z(R)),k.addColorStop(1,Z(S)),e.fillStyle=k,e.beginPath(),e.moveTo(w,D-y),e.lineTo(w+p,D),e.lineTo(w,D+y),e.closePath(),e.fill()}}finally{e.restore()}}},Fo={draw(i,e,t){e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(0,0,t,t),e.fillStyle="rgba(0,0,0,0.25)",e.font=`${Math.max(12,Math.round(t*.05))}px sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillText(i.type,t/2,t/2)}},Ho={"motion-lines":Vo,"speed-lines":Zo};function No(i,e,t){const A=Ho[i.type]??Fo;e.save(),A.draw(i,e,t),e.restore()}function ci(i,e,t,A,n){const s=e.films;for(let a of s){if(!a.visible)continue;const r=a.getShiftedScale(t),o=a.getShiftedTranslation(t);if(i.save(),n&&n(i,a),i.translate(...A),i.translate(o[0],o[1]),i.rotate(-a.rotation*Math.PI/180),i.scale(r*a.reverse[0],r*a.reverse[1]),a.content.kind==="media"){let l=a.content.media;for(let c=a.effects.length-1;0<=c;c--)if(a.effects[c].outputMedia){l=a.effects[c].outputMedia;break}i.translate(-l.naturalWidth*.5,-l.naturalHeight*.5),i.drawImage(l.drawSource,0,0,l.naturalWidth,l.naturalHeight)}else{const[l,c]=a.getContentSize(t),d=Math.max(l,c);i.translate(-d*.5,-d*.5),No(a.content.effect,i,d)}i.restore()}}function hA(i,e,t,A,n){for(let s of t)di(i,e,s),ht(i,e,s,!1,n);for(let s of t)ht(i,e,s,!0,n)}function di(i,e,t,A){if(t.parent)return;const n=t.getPhysicalSize(e);t.getPhysicalStrokeWidth(e),i.save(),i.translate(...t.getPhysicalCenter(e)),i.rotate(-t.rotation*Math.PI/180),Wo(i,e,t,n),hi(i,t,n),ci(i,t.filmStack,e,[0,0],null),i.restore()}function Ve(i,e,t,A,n){i.fillStyle=e.hasEnoughSize(t)?A:"rgba(255, 128, 0, 0.9)"}function ht(i,e,t,A,n){if(t.parent){if(!A)return}else if(A)return;const s=t.getPhysicalSize(e),a=t.getPhysicalCenter(e),r=t.getPhysicalStrokeWidth(e);i.save(),i.translate(...a),i.rotate(-t.rotation*Math.PI/180),i.save(),hi(i,t,s),t.text&&!t.hidesText&&Xo(i,e,t,n),i.restore(),i.strokeStyle=0<r?t.strokeColor:"rgba(0, 0, 0, 0)",i.lineWidth=r,zo(i,e,t,s),i.restore()}function Wo(i,e,t,A,n){const s=t.renderInfo;s.unitedOuterPath?(s.innerPathIsSameWithOuterPath||(Ve(i,t,e,t.optionContext.shapeOutlineColor??"white"),J(i,"fill",s.unitedOuterPath,t.optionContext)),Ve(i,t,e,t.fillColor),J(i,"fill",s.unitedInnerPath,t.optionContext)):t.parent||(s.outerPath?(s.innerPathIsSameWithOuterPath||(Ve(i,t,e,t.optionContext.shapeOutlineColor??"white"),J(i,"fill",s.outerPath,t.optionContext)),Ve(i,t,e,t.fillColor),J(i,"fill",s.innerPath,t.optionContext)):(A[0]=Math.abs(A[0]),A[1]=Math.abs(A[1]),Ve(i,t,e,t.fillColor),i.strokeStyle=t.strokeColor,Vt(i,"fill",t.text,A,t.shape,t.optionContext)))}function hi(i,e,t){const A=e.renderInfo;A.unitedStrokePath?J(i,"clip",A.unitedStrokePath,e.optionContext):e.parent||(A.strokePath?J(i,"clip",A.strokePath,e.optionContext):(t[0]=Math.abs(t[0]),t[1]=Math.abs(t[1]),Vt(i,"clip",e.text,t,e.shape,e.optionContext)))}function zo(i,e,t,A){const n=t.getPhysicalStrokeWidth(e);i.strokeStyle=0<n?t.strokeColor:"rgba(0, 0, 0, 0)",i.lineWidth=n;const s=t.renderInfo;s.unitedStrokePath?J(i,"stroke",s.unitedStrokePath,t.optionContext):t.parent||(s.strokePath?J(i,"stroke",s.strokePath,t.optionContext):(A[0]=Math.abs(A[0]),A[1]=Math.abs(A[1]),Vt(i,"stroke",t.text,A,t.shape,t.optionContext)))}function Xo(i,e,t,A){const n=i.getTransform(),s=A?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),[h,p]=$t(Oi(l,o));if(h<1||p<1)return;isNaN(c)&&(c=14),c<1&&(c=14);const g=t.renderInfo,v=`${t.fontStyle} ${t.fontWeight} ${c}px '${t.fontFamily}'`,m={viewScale:$t(Ee(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},b=JSON.stringify(m);if(g.textJson!=b){g.textJson=b,g.textCanvas=document.createElement("canvas"),g.textCtx=g.textCanvas.getContext("2d");const w=g.textCanvas,y=g.textCtx;w.width=h,w.height=p,y.translate(h*.5,p*.5),y.scale(...o),y.translate(...d),y.font=v;let k=t.text;document.fonts.check(`${t.fontStyle} ${t.fontWeight} 20px '${t.fontFamily}'`);const S=c*1.5*(1+t.lineSkip),R=c*(1+t.charSkip),T=t.rubySize,F=t.rubyDistance,H=ro(t.direction,y,l[0]*.85,l[1]*.85,k,S,R,t.autoNewline),[N,W]=[H.width,H.height],Y={x:-N*.5,y:-W*.5,width:N,height:W};y.globalCompositeOperation="source-over",y.fillStyle=t.fontColor,lA(t.direction,y,"fill",Y,k,S,R,T,F,H,t.autoNewline),0<f&&(y.globalCompositeOperation="destination-over",y.strokeStyle=t.outlineColor,y.lineWidth=f,y.font=v,y.lineJoin="round",lA(t.direction,y,"stroke",Y,k,S,R,T,F,H,t.autoNewline))}const D=g.textCanvas;try{const w=Math.round(t.rotation*10)/10;i.save(),(w===0||w===90||w===180||w===270)&&(i.imageSmoothingEnabled=!1),i.scale(...Ji(o)),i.drawImage(D,0-h*.5,0-p*.5),i.restore()}catch(w){throw console.log(h,p,D.width,D.height,l),w}}function uA(i){const e=new Path2D;if(0<i.length){e.moveTo(...i[0]);for(let t=1;t<i.length;t++)e.lineTo(...i[t]);e.closePath()}return e}class ui extends wt{constructor(t){super();u(this,"frameTree",null);u(this,"rawBubbles",null);u(this,"thisFrameRenderData",null);this.supportsDpr=t}renderDepths(){return[0,1]}tick(t){if(!this.frameTree)return;const A=s=>{var a,r;if((r=(a=s.filmStack)==null?void 0:a.films)!=null&&r.some(o=>o.content.kind==="media"&&!o.media.isLoaded))return!0;if(s.children){for(const o of s.children)if(A(o))return!0}return!1},n=()=>{var s,a;if(!this.rawBubbles)return!1;for(const r of this.rawBubbles)if((a=(s=r.filmStack)==null?void 0:s.films)!=null&&a.some(o=>o.content.kind==="media"&&!o.media.isLoaded))return!0;return!1};(A(this.frameTree)||n())&&this.redraw()}prerender(t){this.thisFrameRenderData=null}render(t,A){if(!this.thisFrameRenderData){if(!this.frameTree)return;const o=this.getPaperSize(),l=St(this.frameTree,o,[0,0]);this.thisFrameRenderData=this.setUpRenderData(l)}const{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}=this.thisFrameRenderData;if(A===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)}A===1&&hA(t,this.getPaperSize(),r,!0,this.supportsDpr)}setUpRenderData(t){const A={borderColor:"black",borderWidth:1},{backgrounds:n,foregrounds:s}=this.setUpFrameTree(t,A),{embeddedBubbles:a,floatingBubbles:r}=this.setUpBubbles(t,this.rawBubbles);return{backgrounds:n,foregrounds:s,embeddedBubbles:a,floatingBubbles:r}}setUpFrameTree(t,A){const n=[],s=[];if(t.element.borderColor!=null&&(A.borderColor=t.element.borderColor),t.element.borderWidth!=null&&(A.borderWidth=t.element.borderWidth),t.children){n.push({layout:t,inheritanceContext:A});for(let a=0;a<t.children.length;a++){const r=this.setUpFrameTree(t.children[a],A);n.push(...r.backgrounds),s.push(...r.foregrounds)}}else n.push({layout:t,inheritanceContext:A}),s.push({layout:t,inheritanceContext:A});return{backgrounds:n,foregrounds:s}}setUpBubbles(t,A){const n=this.getPaperSize();this.resolveLinkages(A);const s=new Map,a=[];for(let r of A)if(r.embedded){const o=HA(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,h,p,g,v;const A=this.getPaperSize(),n={};for(let m of t)m.renderInfo??(m.renderInfo={}),(s=m.renderInfo.unitedOuterPath)==null||s.remove(),m.renderInfo.unitedOuterPath=null,(a=m.renderInfo.unitedInnerPath)==null||a.remove(),m.renderInfo.unitedInnerPath=null,(r=m.renderInfo.unitedStrokePath)==null||r.remove(),m.renderInfo.unitedStrokePath=null,m.renderInfo.children=[],n[m.uuid]=m;for(let m of t)m.parent&&(n[m.parent]==null?m.parent=null:n[m.parent].renderInfo.children.push(m));for(let m of t){const b=m.optionContext,D=[m.n_p1[0]-m.n_p0[0],m.n_p1[1]-m.n_p0[1]],w=m.renderInfo,y={paperSize:A,shape:m.shape,size:D,optionContext:b,rotation:m.rotation},k=JSON.stringify(y);if(w.pathJson!=k){(o=w.strokePath)==null||o.remove(),(l=w.outerPath)==null||l.remove(),(c=w.innerPath)==null||c.remove(),w.strokePath=null,w.outerPath=null,w.innerPath=null;const S=m.getPhysicalSize(A);if(w.pathJson=k,w.strokePath=Po(m.shape,S,b,m.text),(d=w.strokePath)==null||d.rotate(-m.rotation),w.innerPathIsSameWithOuterPath=!1,w.strokePath){const R=Math.min(w.strokePath.bounds.width,w.strokePath.bounds.height)*(b.shapeExpand??0);try{R==0?w.outerPath=w.strokePath.clone():w.outerPath=Kt.PaperOffset.offset(w.strokePath,R)}catch{console.error("PaperOffset failed, using strokePath as outerPath",q.decompile(m)),w.outerPath=w.strokePath.clone()}const T=Math.min(w.outerPath.bounds.width,w.outerPath.bounds.height)*(b.shapeOutline??0);try{T==0?(w.innerPath=w.outerPath.clone(),w.innerPathIsSameWithOuterPath=!0):w.innerPath=Kt.PaperOffset.offset(w.outerPath,-T)}catch{console.error("PaperOffset failed, using outerPath as innerPath",q.decompile(m)),w.innerPath=w.outerPath.clone(),w.innerPathIsSameWithOuterPath=!0}}}}for(let m of t){const b=m.renderInfo;if(m.parent==null&&b.strokePath){const D=m.getPhysicalCenter(A);b.unitedStrokePath=b.strokePath.clone(),b.unitedOuterPath=b.outerPath.clone(),b.unitedInnerPath=b.innerPath.clone(),b.unitedOuterPath.translate(D),b.unitedInnerPath.translate(D),b.unitedStrokePath.translate(D);for(let w of b.children){const y=w.getPhysicalCenter(A),k=w.renderInfo;if(k.strokePath==null)continue;const S=k.strokePath.clone();S==null||S.translate(w.getPhysicalCenter(A)),(f=b.unitedStrokePath)==null||f.remove(),b.unitedStrokePath=b.unitedStrokePath.unite(S),S.remove();const R=k.outerPath.clone();R.translate(y),(h=b.unitedOuterPath)==null||h.remove(),b.unitedOuterPath=b.unitedOuterPath.unite(R),R.remove();const T=k.innerPath.clone();T.translate(y),(p=b.unitedInnerPath)==null||p.remove(),b.unitedInnerPath=b.unitedInnerPath.unite(T),T.remove()}b.children.length===0&&b.innerPathIsSameWithOuterPath?((g=b.unitedInnerPath)==null||g.remove(),b.unitedInnerPath=b.unitedOuterPath.clone()):((v=b.unitedOuterPath)==null||v.remove(),b.unitedOuterPath=b.unitedOuterPath.subtract(b.unitedInnerPath)),b.unitedOuterPath.rotate(m.rotation,D),b.unitedOuterPath.translate(Pt(D)),b.unitedInnerPath.rotate(m.rotation,D),b.unitedInnerPath.translate(Pt(D)),b.unitedStrokePath.rotate(m.rotation,D),b.unitedStrokePath.translate(Pt(D))}}}makeFramePath(t,A){const n=this.getPaperSize(),s=dA(t.corners,n,{top:!0,right:!0,bottom:!0,left:!0},A);return uA(s)}renderFrame(t,A,n,s){this.renderFrameBackground(t,A,n);const a=A.element;2<=a.visibility&&this.renderFrameBorder(t,A,n),1<=a.visibility&&this.renderFrameContent(t,A,n,s)}renderFrameBackground(t,A,n){if(A.element.visibility===0||!A.element.bgColor)return;const s=(n==null?void 0:n.borderWidth)??0,a=this.makeFramePath(A,-s*.5);t.save(),t.lineJoin="miter",t.fillStyle=A.element.bgColor,t.fill(a),t.restore()}renderFrameContent(t,A,n,s){if(0<A.element.filmStack.films.length||s.has(A)){const r=this.getPaperSize(),o=A.element,[l,c,d,f]=Jr(A.corners),h=-n.borderWidth*.5,p=(m,b)=>{const D=dA(A.corners,r,b.barriers,h);m.clip(uA(D))};ci(t,o.filmStack,r,[l+d*.5,c+f*.5],p);const g=this.makeFramePath(A,-n.borderWidth*.5),v=s.get(A);v&&(t.save(),t.clip(g),hA(t,this.getPaperSize(),v,!0,this.supportsDpr),t.restore())}}renderFrameBorder(t,A,n){const s=n.borderWidth;if(0<s){t.save(),t.strokeStyle=n.borderColor,t.lineWidth=s,t.lineJoin="miter";const a=this.makeFramePath(A,0);t.stroke(a),t.restore()}}setBubbles(t){this.rawBubbles=t}setFrameTree(t){this.frameTree=t}renderApart(){const t=this.getPaperSize();function A(){const d=xi(t[0],t[1]),f=d.getContext("2d");return{canvas:d,ctx:f}}const n=St(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:h,ctx:p}=A();this.renderFrameBackground(p,d,f),this.renderFrameContent(p,d,f,a);const{canvas:g,ctx:v}=A();this.renderFrameBorder(v,d,f),o.push({border:g,content:h})}const l=[...[...a.values()].flat(),...r],c={};for(let d of l){if(d.renderInfo,d.parent!=null)continue;const{canvas:f,ctx:h}=A(),p=this.getPaperSize();di(h,p,d),ht(h,p,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");ht(f,this.getPaperSize(),d,!0,this.supportsDpr)}return{frames:o,bubbles:Object.values(c)}}resetCache(){var t,A,n,s,a,r;for(let o of this.rawBubbles){const l=o.renderInfo;l&&((t=l.strokePath)==null||t.remove(),(A=l.outerPath)==null||A.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 Yo{constructor(){u(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 jo=typeof process<"u"&&(process.env.NODE_ENV==="test"||process.env.VITEST);let xt;async function Ko(){const i=new We.Computron;await i.init(),xt=new We.JFACompute(i),await xt.init()}jo||Ko();class fi{constructor(){u(this,"ulid");u(this,"inputMedia");u(this,"outputMedia");this.ulid=Se.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 Wt(t.color,t.width,t.sharp);default:throw new Error("Unknown effect tag: "+e.tag)}}}class Wt extends fi{constructor(t,A,n){super();u(this,"rawDistanceField",null);this.color=t,this.width=A,this.sharp=n}clone(){return new Wt(this.color,this.width,this.sharp)}async apply(t){if(this.inputMedia!=t){const h=t.drawSource,p=We.FloatField.createFromImageOrCanvas(h),g=We.JFACompute.createJFASeedMap(p,.5,!1);this.rawDistanceField=await xt.compute(g),this.inputMedia=t}const A=t.drawSource,n=Math.max(t.naturalWidth,t.naturalHeight),s=this.width*n,a=Ci(this.color),r={r:a.values[0]/255,g:a.values[1]/255,b:a.values[2]/255},o=1-this.sharp,l=h=>o<=h?1:h*(1/o),c=We.JFACompute.generateDistanceField(this.rawDistanceField,r,s,l),d=document.createElement("canvas");d.width=A.width,d.height=A.height;const f=d.getContext("2d");return f.drawImage(A,0,0),f.globalCompositeOperation="destination-over",f.drawImage(c.toCanvas(),0,0),this.outputMedia=new le(d),this.outputMedia}decompile(){return{color:this.color,width:this.width,sharp:this.sharp}}}async function pi(i,e,t){const A=ue.compileNode(e);if(A.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(i[0],i[1]),l=r/o,c=(e.scale??[1,1])[0],d=l*c,f=e.translation??[0,0],h=[f[0]*l,f[1]*l],p=X.fromMedia(new le(a));return p.n_scale=d,p.n_translation=h,p.rotation=e.rotation,p.reverse=[...e.reverse??[1,1]],p.prompt=e.prompt,p};if(e.image){const a=await t(e.image,"image");if(a){const r=s(a);A.filmStack.films.push(r)}}if(e.scribble){const a=await t(e.scribble,"image");if(a){const r=s(a);A.filmStack.films.push(r)}}}else{let s=function(a){const r=X.fromMedia(new le(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);A.filmStack.films.push(r)}}if(e.image.scribble){const a=await t(e.image.scribble,"image");if(a){const r=s(a);A.filmStack.films.push(r)}}}else if(e.films){const s=await gi(e.films,t);A.filmStack.films.push(...s)}const n=e.column??e.row;if(n){A.direction=e.column?"v":"h",A.children=[];for(let s of n)A.children.push(await pi(i,s,t));A.calculateLengthAndBreadth()}for(const s of A.filmStack.films)s.content.kind==="media"&&s.content.media instanceof le&&A.gallery.push(s.content.media);return A}async function _o(i,e,t){const A=[];for(const n of e){const s=q.compile(i,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(i[0],i[1]);let c=a.n_scale;if(!c){const p=(a.scale??[1,1])[0];c=o/l*p}let d=a.n_translation;if(!d){const h=a.translation??[0,0],p=o/l;d=[h[0]*p,h[1]*p]}const f=X.fromMedia(new le(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 gi(n.films,t);s.filmStack.films=r}A.push(s)}for(const n of A)for(const s of n.filmStack.films)s.content.kind==="media"&&s.content.media instanceof le&&n.gallery.push(s.content.media);return A}async function gi(i,e){const t=[];for(const A of i){const n=[];if(A.effects)for(const a of A.effects){const r=fi.compile(a);n.push(r)}let s=null;if(A.proceduralEffect)s=X.fromProcedural({type:A.proceduralEffect.type,params:A.proceduralEffect.params??{}});else{const a=await e(A.image,A.mediaType??"image");if(!a)continue;const r=A.mediaType==="video"?new Et(a):new le(a);s=X.fromMedia(r)}s&&(A.ulid&&(s.ulid=A.ulid),s.n_scale=A.n_scale,s.n_translation=A.n_translation,s.rotation=A.rotation,s.reverse=A.reverse,s.visible=A.visible,s.prompt=A.prompt,s.effects=n,s.barriers=A.barriers??{top:!0,right:!0,bottom:!0,left:!0},t.push(s))}return t}async function $o(i,e){const t=[];for(const A of i.characters){const n=A.portrait?await e(A.portrait,"image"):null;t.push({...A,portrait:Wr(n)})}return{...i,characters:t,format:i.format??"standard"}}var L;(function(i){i.assertEqual=n=>{};function e(n){}i.assertIs=e;function t(n){throw new Error}i.assertNever=t,i.arrayToEnum=n=>{const s={};for(const a of n)s[a]=a;return s},i.getValidEnumValues=n=>{const s=i.objectKeys(n).filter(r=>typeof n[n[r]]!="number"),a={};for(const r of s)a[r]=n[r];return i.objectValues(a)},i.objectValues=n=>i.objectKeys(n).map(function(s){return n[s]}),i.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},i.find=(n,s)=>{for(const a of n)if(s(a))return a},i.isInteger=typeof Number.isInteger=="function"?n=>Number.isInteger(n):n=>typeof n=="number"&&Number.isFinite(n)&&Math.floor(n)===n;function A(n,s=" | "){return n.map(a=>typeof a=="string"?`'${a}'`:a).join(s)}i.joinValues=A,i.jsonStringifyReplacer=(n,s)=>typeof s=="bigint"?s.toString():s})(L||(L={}));var fA;(function(i){i.mergeShapes=(e,t)=>({...e,...t})})(fA||(fA={}));const B=L.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),fe=i=>{switch(typeof i){case"undefined":return B.undefined;case"string":return B.string;case"number":return Number.isNaN(i)?B.nan:B.number;case"boolean":return B.boolean;case"function":return B.function;case"bigint":return B.bigint;case"symbol":return B.symbol;case"object":return Array.isArray(i)?B.array:i===null?B.null:i.then&&typeof i.then=="function"&&i.catch&&typeof i.catch=="function"?B.promise:typeof Map<"u"&&i instanceof Map?B.map:typeof Set<"u"&&i instanceof Set?B.set:typeof Date<"u"&&i instanceof Date?B.date:B.object;default:return B.unknown}},Q=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 de extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=A=>{this.issues=[...this.issues,A]},this.addIssues=(A=[])=>{this.issues=[...this.issues,...A]};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},A={_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)A._errors.push(t(a));else{let r=A,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),A}static assert(e){if(!(e instanceof de))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={},A=[];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))):A.push(e(n));return{formErrors:A,fieldErrors:t}}get formErrors(){return this.flatten()}}de.create=i=>new de(i);const qt=(i,e)=>{let t;switch(i.code){case Q.invalid_type:i.received===B.undefined?t="Required":t=`Expected ${i.expected}, received ${i.received}`;break;case Q.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(i.expected,L.jsonStringifyReplacer)}`;break;case Q.unrecognized_keys:t=`Unrecognized key(s) in object: ${L.joinValues(i.keys,", ")}`;break;case Q.invalid_union:t="Invalid input";break;case Q.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${L.joinValues(i.options)}`;break;case Q.invalid_enum_value:t=`Invalid enum value. Expected ${L.joinValues(i.options)}, received '${i.received}'`;break;case Q.invalid_arguments:t="Invalid function arguments";break;case Q.invalid_return_type:t="Invalid function return type";break;case Q.invalid_date:t="Invalid date";break;case Q.invalid_string:typeof i.validation=="object"?"includes"in i.validation?(t=`Invalid input: must include "${i.validation.includes}"`,typeof i.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${i.validation.position}`)):"startsWith"in i.validation?t=`Invalid input: must start with "${i.validation.startsWith}"`:"endsWith"in i.validation?t=`Invalid input: must end with "${i.validation.endsWith}"`:L.assertNever(i.validation):i.validation!=="regex"?t=`Invalid ${i.validation}`:t="Invalid";break;case Q.too_small:i.type==="array"?t=`Array must contain ${i.exact?"exactly":i.inclusive?"at least":"more than"} ${i.minimum} element(s)`:i.type==="string"?t=`String must contain ${i.exact?"exactly":i.inclusive?"at least":"over"} ${i.minimum} character(s)`:i.type==="number"?t=`Number must be ${i.exact?"exactly equal to ":i.inclusive?"greater than or equal to ":"greater than "}${i.minimum}`:i.type==="date"?t=`Date must be ${i.exact?"exactly equal to ":i.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(i.minimum))}`:t="Invalid input";break;case Q.too_big:i.type==="array"?t=`Array must contain ${i.exact?"exactly":i.inclusive?"at most":"less than"} ${i.maximum} element(s)`:i.type==="string"?t=`String must contain ${i.exact?"exactly":i.inclusive?"at most":"under"} ${i.maximum} character(s)`:i.type==="number"?t=`Number must be ${i.exact?"exactly":i.inclusive?"less than or equal to":"less than"} ${i.maximum}`:i.type==="bigint"?t=`BigInt must be ${i.exact?"exactly":i.inclusive?"less than or equal to":"less than"} ${i.maximum}`:i.type==="date"?t=`Date must be ${i.exact?"exactly":i.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(i.maximum))}`:t="Invalid input";break;case Q.custom:t="Invalid input";break;case Q.invalid_intersection_types:t="Intersection results could not be merged";break;case Q.not_multiple_of:t=`Number must be a multiple of ${i.multipleOf}`;break;case Q.not_finite:t="Number must be finite";break;default:t=e.defaultError,L.assertNever(i)}return{message:t}};let el=qt;function tl(){return el}const Al=i=>{const{data:e,path:t,errorMaps:A,issueData:n}=i,s=[...t,...n.path||[]],a={...n,path:s};if(n.message!==void 0)return{...n,path:s,message:n.message};let r="";const o=A.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 P(i,e){const t=tl(),A=Al({issueData:e,data:i.data,path:i.path,errorMaps:[i.common.contextualErrorMap,i.schemaErrorMap,t,t===qt?void 0:qt].filter(n=>!!n)});i.common.issues.push(A)}class j{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const A=[];for(const n of t){if(n.status==="aborted")return C;n.status==="dirty"&&e.dirty(),A.push(n.value)}return{status:e.value,value:A}}static async mergeObjectAsync(e,t){const A=[];for(const n of t){const s=await n.key,a=await n.value;A.push({key:s,value:a})}return j.mergeObjectSync(e,A)}static mergeObjectSync(e,t){const A={};for(const n of t){const{key:s,value:a}=n;if(s.status==="aborted"||a.status==="aborted")return C;s.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof a.value<"u"||n.alwaysSet)&&(A[s.value]=a.value)}return{status:e.value,value:A}}}const C=Object.freeze({status:"aborted"}),Fe=i=>({status:"dirty",value:i}),te=i=>({status:"valid",value:i}),pA=i=>i.status==="aborted",gA=i=>i.status==="dirty",Re=i=>i.status==="valid",ut=i=>typeof Promise<"u"&&i instanceof Promise;var E;(function(i){i.errToObj=e=>typeof e=="string"?{message:e}:e||{},i.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(E||(E={}));var ft=function(i,e,t,A){if(t==="a"&&!A)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?i!==e||!A:!e.has(i))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?A:t==="a"?A.call(i):A?A.value:e.get(i)},mi=function(i,e,t,A,n){if(A==="m")throw new TypeError("Private method is not writable");if(A==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?i!==e||!n:!e.has(i))throw new TypeError("Cannot write private member to an object whose class did not declare it");return A==="a"?n.call(i,t):n?n.value=t:e.set(i,t),t},He,Ne;class be{constructor(e,t,A,n){this._cachedPath=[],this.parent=e,this.data=t,this._path=A,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 mA=(i,e)=>{if(Re(e))return{success:!0,data:e.value};if(!i.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 de(i.common.issues);return this._error=t,this._error}}};function x(i){if(!i)return{};const{errorMap:e,invalid_type_error:t,required_error:A,description:n}=i;if(e&&(t||A))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}=i;return a.code==="invalid_enum_value"?{message:o??r.defaultError}:typeof r.data>"u"?{message:o??A??r.defaultError}:a.code!=="invalid_type"?{message:r.defaultError}:{message:o??t??r.defaultError}},description:n}}class M{get description(){return this._def.description}_getType(e){return fe(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:fe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new j,ctx:{common:e.parent.common,data:e.data,parsedType:fe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(ut(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 A=this.safeParse(e,t);if(A.success)return A.data;throw A.error}safeParse(e,t){const A={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:fe(e)},n=this._parseSync({data:e,path:A.path,parent:A});return mA(A,n)}"~validate"(e){var A,n;const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:fe(e)};if(!this["~standard"].async)try{const s=this._parseSync({data:e,path:[],parent:t});return Re(s)?{value:s.value}:{issues:t.common.issues}}catch(s){(n=(A=s==null?void 0:s.message)==null?void 0:A.toLowerCase())!=null&&n.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(s=>Re(s)?{value:s.value}:{issues:t.common.issues})}async parseAsync(e,t){const A=await this.safeParseAsync(e,t);if(A.success)return A.data;throw A.error}async safeParseAsync(e,t){const A={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:fe(e)},n=this._parse({data:e,path:A.path,parent:A}),s=await(ut(n)?n:Promise.resolve(n));return mA(A,s)}refine(e,t){const A=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:Q.custom,...A(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((A,n)=>e(A)?!0:(n.addIssue(typeof t=="function"?t(A,n):t),!1))}_refinement(e){return new qe({schema:this,typeName:I.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 me.create(this,this._def)}nullable(){return Me.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ae.create(this)}promise(){return bt.create(this,this._def)}or(e){return gt.create([this,e],this._def)}and(e){return mt.create(this,e,this._def)}transform(e){return new qe({...x(this._def),schema:this,typeName:I.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new Ut({...x(this._def),innerType:this,defaultValue:t,typeName:I.ZodDefault})}brand(){return new Bl({typeName:I.ZodBranded,type:this,...x(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Lt({...x(this._def),innerType:this,catchValue:t,typeName:I.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return zt.create(this,e)}readonly(){return Tt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const il=/^c[^\s-]{8,}$/i,nl=/^[0-9a-z]+$/,sl=/^[0-9A-HJKMNP-TV-Z]{26}$/i,al=/^[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,rl=/^[a-z0-9_-]{21}$/i,ol=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ll=/^[-+]?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)?)??$/,cl=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,dl="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let kt;const hl=/^(?:(?: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])$/,ul=/^(?:(?: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])$/,fl=/^(([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]))$/,pl=/^(([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])$/,gl=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ml=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,bi="((\\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])))",bl=new RegExp(`^${bi}$`);function wi(i){let e="[0-5]\\d";i.precision?e=`${e}\\.\\d{${i.precision}}`:i.precision==null&&(e=`${e}(\\.\\d+)?`);const t=i.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function wl(i){return new RegExp(`^${wi(i)}$`)}function Ql(i){let e=`${bi}T${wi(i)}`;const t=[];return t.push(i.local?"Z?":"Z"),i.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function vl(i,e){return!!((e==="v4"||!e)&&hl.test(i)||(e==="v6"||!e)&&fl.test(i))}function yl(i,e){if(!ol.test(i))return!1;try{const[t]=i.split("."),A=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),n=JSON.parse(atob(A));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 Pl(i,e){return!!((e==="v4"||!e)&&ul.test(i)||(e==="v6"||!e)&&pl.test(i))}class ge extends M{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==B.string){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_type,expected:B.string,received:s.parsedType}),C}const A=new j;let n;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),A.dirty());else if(s.kind==="max")e.data.length>s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),A.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?P(n,{code:Q.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):r&&P(n,{code:Q.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),A.dirty())}else if(s.kind==="email")cl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"email",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="emoji")kt||(kt=new RegExp(dl,"u")),kt.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"emoji",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="uuid")al.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"uuid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="nanoid")rl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"nanoid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="cuid")il.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"cuid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="cuid2")nl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"cuid2",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="ulid")sl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"ulid",code:Q.invalid_string,message:s.message}),A.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),P(n,{validation:"url",code:Q.invalid_string,message:s.message}),A.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"regex",code:Q.invalid_string,message:s.message}),A.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),A.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),P(n,{code:Q.invalid_string,validation:{startsWith:s.value},message:s.message}),A.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:{endsWith:s.value},message:s.message}),A.dirty()):s.kind==="datetime"?Ql(s).test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:"datetime",message:s.message}),A.dirty()):s.kind==="date"?bl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:"date",message:s.message}),A.dirty()):s.kind==="time"?wl(s).test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{code:Q.invalid_string,validation:"time",message:s.message}),A.dirty()):s.kind==="duration"?ll.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"duration",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="ip"?vl(e.data,s.version)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"ip",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="jwt"?yl(e.data,s.alg)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"jwt",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="cidr"?Pl(e.data,s.version)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"cidr",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="base64"?gl.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"base64",code:Q.invalid_string,message:s.message}),A.dirty()):s.kind==="base64url"?ml.test(e.data)||(n=this._getOrReturnCtx(e,n),P(n,{validation:"base64url",code:Q.invalid_string,message:s.message}),A.dirty()):L.assertNever(s);return{status:A.value,value:e.data}}_regex(e,t,A){return this.refinement(n=>e.test(n),{validation:t,code:Q.invalid_string,...E.errToObj(A)})}_addCheck(e){return new ge({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...E.errToObj(e)})}url(e){return this._addCheck({kind:"url",...E.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...E.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...E.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...E.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...E.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...E.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...E.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...E.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...E.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...E.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...E.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...E.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,...E.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,...E.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...E.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...E.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...E.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...E.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...E.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...E.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...E.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...E.errToObj(t)})}nonempty(e){return this.min(1,E.errToObj(e))}trim(){return new ge({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new ge({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new ge({...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}}ge.create=i=>new ge({checks:[],typeName:I.ZodString,coerce:(i==null?void 0:i.coerce)??!1,...x(i)});function kl(i,e){const t=(i.toString().split(".")[1]||"").length,A=(e.toString().split(".")[1]||"").length,n=t>A?t:A,s=Number.parseInt(i.toFixed(n).replace(".","")),a=Number.parseInt(e.toFixed(n).replace(".",""));return s%a/10**n}class Ce extends M{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)!==B.number){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_type,expected:B.number,received:s.parsedType}),C}let A;const n=new j;for(const s of this._def.checks)s.kind==="int"?L.isInteger(e.data)||(A=this._getOrReturnCtx(e,A),P(A,{code:Q.invalid_type,expected:"integer",received:"float",message:s.message}),n.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),n.dirty()):s.kind==="multipleOf"?kl(e.data,s.value)!==0&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.not_multiple_of,multipleOf:s.value,message:s.message}),n.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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,E.toString(t))}gt(e,t){return this.setLimit("min",e,!1,E.toString(t))}lte(e,t){return this.setLimit("max",e,!0,E.toString(t))}lt(e,t){return this.setLimit("max",e,!1,E.toString(t))}setLimit(e,t,A,n){return new Ce({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:A,message:E.toString(n)}]})}_addCheck(e){return new Ce({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:E.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:E.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:E.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:E.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:E.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:E.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:E.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:E.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:E.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 A of this._def.checks){if(A.kind==="finite"||A.kind==="int"||A.kind==="multipleOf")return!0;A.kind==="min"?(t===null||A.value>t)&&(t=A.value):A.kind==="max"&&(e===null||A.value<e)&&(e=A.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Ce.create=i=>new Ce({checks:[],typeName:I.ZodNumber,coerce:(i==null?void 0:i.coerce)||!1,...x(i)});class Ye extends M{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)!==B.bigint)return this._getInvalidInput(e);let A;const n=new j;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),n.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(A=this._getOrReturnCtx(e,A),P(A,{code:Q.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 P(t,{code:Q.invalid_type,expected:B.bigint,received:t.parsedType}),C}gte(e,t){return this.setLimit("min",e,!0,E.toString(t))}gt(e,t){return this.setLimit("min",e,!1,E.toString(t))}lte(e,t){return this.setLimit("max",e,!0,E.toString(t))}lt(e,t){return this.setLimit("max",e,!1,E.toString(t))}setLimit(e,t,A,n){return new Ye({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:A,message:E.toString(n)}]})}_addCheck(e){return new Ye({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:E.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:E.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:E.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:E.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:E.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}}Ye.create=i=>new Ye({checks:[],typeName:I.ZodBigInt,coerce:(i==null?void 0:i.coerce)??!1,...x(i)});class bA extends M{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==B.boolean){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.boolean,received:A.parsedType}),C}return te(e.data)}}bA.create=i=>new bA({typeName:I.ZodBoolean,coerce:(i==null?void 0:i.coerce)||!1,...x(i)});class pt extends M{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==B.date){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_type,expected:B.date,received:s.parsedType}),C}if(Number.isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return P(s,{code:Q.invalid_date}),C}const A=new j;let n;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),A.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(n=this._getOrReturnCtx(e,n),P(n,{code:Q.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),A.dirty()):L.assertNever(s);return{status:A.value,value:new Date(e.data.getTime())}}_addCheck(e){return new pt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:E.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:E.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}}pt.create=i=>new pt({checks:[],coerce:(i==null?void 0:i.coerce)||!1,typeName:I.ZodDate,...x(i)});class wA extends M{_parse(e){if(this._getType(e)!==B.symbol){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.symbol,received:A.parsedType}),C}return te(e.data)}}wA.create=i=>new wA({typeName:I.ZodSymbol,...x(i)});class QA extends M{_parse(e){if(this._getType(e)!==B.undefined){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.undefined,received:A.parsedType}),C}return te(e.data)}}QA.create=i=>new QA({typeName:I.ZodUndefined,...x(i)});class vA extends M{_parse(e){if(this._getType(e)!==B.null){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.null,received:A.parsedType}),C}return te(e.data)}}vA.create=i=>new vA({typeName:I.ZodNull,...x(i)});class yA extends M{constructor(){super(...arguments),this._any=!0}_parse(e){return te(e.data)}}yA.create=i=>new yA({typeName:I.ZodAny,...x(i)});class PA extends M{constructor(){super(...arguments),this._unknown=!0}_parse(e){return te(e.data)}}PA.create=i=>new PA({typeName:I.ZodUnknown,...x(i)});class we extends M{_parse(e){const t=this._getOrReturnCtx(e);return P(t,{code:Q.invalid_type,expected:B.never,received:t.parsedType}),C}}we.create=i=>new we({typeName:I.ZodNever,...x(i)});class kA extends M{_parse(e){if(this._getType(e)!==B.undefined){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.void,received:A.parsedType}),C}return te(e.data)}}kA.create=i=>new kA({typeName:I.ZodVoid,...x(i)});class ae extends M{_parse(e){const{ctx:t,status:A}=this._processInputParams(e),n=this._def;if(t.parsedType!==B.array)return P(t,{code:Q.invalid_type,expected:B.array,received:t.parsedType}),C;if(n.exactLength!==null){const a=t.data.length>n.exactLength.value,r=t.data.length<n.exactLength.value;(a||r)&&(P(t,{code:a?Q.too_big:Q.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}),A.dirty())}if(n.minLength!==null&&t.data.length<n.minLength.value&&(P(t,{code:Q.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),A.dirty()),n.maxLength!==null&&t.data.length>n.maxLength.value&&(P(t,{code:Q.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),A.dirty()),t.common.async)return Promise.all([...t.data].map((a,r)=>n.type._parseAsync(new be(t,a,t.path,r)))).then(a=>j.mergeArray(A,a));const s=[...t.data].map((a,r)=>n.type._parseSync(new be(t,a,t.path,r)));return j.mergeArray(A,s)}get element(){return this._def.type}min(e,t){return new ae({...this._def,minLength:{value:e,message:E.toString(t)}})}max(e,t){return new ae({...this._def,maxLength:{value:e,message:E.toString(t)}})}length(e,t){return new ae({...this._def,exactLength:{value:e,message:E.toString(t)}})}nonempty(e){return this.min(1,e)}}ae.create=(i,e)=>new ae({type:i,minLength:null,maxLength:null,exactLength:null,typeName:I.ZodArray,...x(e)});function De(i){if(i instanceof G){const e={};for(const t in i.shape){const A=i.shape[t];e[t]=me.create(De(A))}return new G({...i._def,shape:()=>e})}else return i instanceof ae?new ae({...i._def,type:De(i.element)}):i instanceof me?me.create(De(i.unwrap())):i instanceof Me?Me.create(De(i.unwrap())):i instanceof ke?ke.create(i.items.map(e=>De(e))):i}class G extends M{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)!==B.object){const l=this._getOrReturnCtx(e);return P(l,{code:Q.invalid_type,expected:B.object,received:l.parsedType}),C}const{status:A,ctx:n}=this._processInputParams(e),{shape:s,keys:a}=this._getCached(),r=[];if(!(this._def.catchall instanceof we&&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 be(n,d,n.path,l)),alwaysSet:l in n.data})}if(this._def.catchall instanceof we){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&&(P(n,{code:Q.unrecognized_keys,keys:r}),A.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 be(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=>j.mergeObjectSync(A,l)):j.mergeObjectSync(A,o)}get shape(){return this._def.shape()}strict(e){return E.errToObj,new G({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,A)=>{var s,a;const n=((a=(s=this._def).errorMap)==null?void 0:a.call(s,t,A).message)??A.defaultError;return t.code==="unrecognized_keys"?{message:E.errToObj(e).message??n}:{message:n}}}:{}})}strip(){return new G({...this._def,unknownKeys:"strip"})}passthrough(){return new G({...this._def,unknownKeys:"passthrough"})}extend(e){return new G({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new G({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:I.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new G({...this._def,catchall:e})}pick(e){const t={};for(const A of L.objectKeys(e))e[A]&&this.shape[A]&&(t[A]=this.shape[A]);return new G({...this._def,shape:()=>t})}omit(e){const t={};for(const A of L.objectKeys(this.shape))e[A]||(t[A]=this.shape[A]);return new G({...this._def,shape:()=>t})}deepPartial(){return De(this)}partial(e){const t={};for(const A of L.objectKeys(this.shape)){const n=this.shape[A];e&&!e[A]?t[A]=n:t[A]=n.optional()}return new G({...this._def,shape:()=>t})}required(e){const t={};for(const A of L.objectKeys(this.shape))if(e&&!e[A])t[A]=this.shape[A];else{let s=this.shape[A];for(;s instanceof me;)s=s._def.innerType;t[A]=s}return new G({...this._def,shape:()=>t})}keyof(){return Qi(L.objectKeys(this.shape))}}G.create=(i,e)=>new G({shape:()=>i,unknownKeys:"strip",catchall:we.create(),typeName:I.ZodObject,...x(e)});G.strictCreate=(i,e)=>new G({shape:()=>i,unknownKeys:"strict",catchall:we.create(),typeName:I.ZodObject,...x(e)});G.lazycreate=(i,e)=>new G({shape:i,unknownKeys:"strip",catchall:we.create(),typeName:I.ZodObject,...x(e)});class gt extends M{_parse(e){const{ctx:t}=this._processInputParams(e),A=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 de(r.ctx.common.issues));return P(t,{code:Q.invalid_union,unionErrors:a}),C}if(t.common.async)return Promise.all(A.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 A){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 de(o));return P(t,{code:Q.invalid_union,unionErrors:r}),C}}get options(){return this._def.options}}gt.create=(i,e)=>new gt({options:i,typeName:I.ZodUnion,...x(e)});function Mt(i,e){const t=fe(i),A=fe(e);if(i===e)return{valid:!0,data:i};if(t===B.object&&A===B.object){const n=L.objectKeys(e),s=L.objectKeys(i).filter(r=>n.indexOf(r)!==-1),a={...i,...e};for(const r of s){const o=Mt(i[r],e[r]);if(!o.valid)return{valid:!1};a[r]=o.data}return{valid:!0,data:a}}else if(t===B.array&&A===B.array){if(i.length!==e.length)return{valid:!1};const n=[];for(let s=0;s<i.length;s++){const a=i[s],r=e[s],o=Mt(a,r);if(!o.valid)return{valid:!1};n.push(o.data)}return{valid:!0,data:n}}else return t===B.date&&A===B.date&&+i==+e?{valid:!0,data:i}:{valid:!1}}class mt extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e),n=(s,a)=>{if(pA(s)||pA(a))return C;const r=Mt(s.value,a.value);return r.valid?((gA(s)||gA(a))&&t.dirty(),{status:t.value,value:r.data}):(P(A,{code:Q.invalid_intersection_types}),C)};return A.common.async?Promise.all([this._def.left._parseAsync({data:A.data,path:A.path,parent:A}),this._def.right._parseAsync({data:A.data,path:A.path,parent:A})]).then(([s,a])=>n(s,a)):n(this._def.left._parseSync({data:A.data,path:A.path,parent:A}),this._def.right._parseSync({data:A.data,path:A.path,parent:A}))}}mt.create=(i,e,t)=>new mt({left:i,right:e,typeName:I.ZodIntersection,...x(t)});class ke extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.parsedType!==B.array)return P(A,{code:Q.invalid_type,expected:B.array,received:A.parsedType}),C;if(A.data.length<this._def.items.length)return P(A,{code:Q.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),C;!this._def.rest&&A.data.length>this._def.items.length&&(P(A,{code:Q.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const s=[...A.data].map((a,r)=>{const o=this._def.items[r]||this._def.rest;return o?o._parse(new be(A,a,A.path,r)):null}).filter(a=>!!a);return A.common.async?Promise.all(s).then(a=>j.mergeArray(t,a)):j.mergeArray(t,s)}get items(){return this._def.items}rest(e){return new ke({...this._def,rest:e})}}ke.create=(i,e)=>{if(!Array.isArray(i))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ke({items:i,typeName:I.ZodTuple,rest:null,...x(e)})};class BA extends M{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.parsedType!==B.map)return P(A,{code:Q.invalid_type,expected:B.map,received:A.parsedType}),C;const n=this._def.keyType,s=this._def.valueType,a=[...A.data.entries()].map(([r,o],l)=>({key:n._parse(new be(A,r,A.path,[l,"key"])),value:s._parse(new be(A,o,A.path,[l,"value"]))}));if(A.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 C;(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 C;(l.status==="dirty"||c.status==="dirty")&&t.dirty(),r.set(l.value,c.value)}return{status:t.value,value:r}}}}BA.create=(i,e,t)=>new BA({valueType:e,keyType:i,typeName:I.ZodMap,...x(t)});class je extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.parsedType!==B.set)return P(A,{code:Q.invalid_type,expected:B.set,received:A.parsedType}),C;const n=this._def;n.minSize!==null&&A.data.size<n.minSize.value&&(P(A,{code:Q.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),t.dirty()),n.maxSize!==null&&A.data.size>n.maxSize.value&&(P(A,{code:Q.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 C;c.status==="dirty"&&t.dirty(),l.add(c.value)}return{status:t.value,value:l}}const r=[...A.data.values()].map((o,l)=>s._parse(new be(A,o,A.path,l)));return A.common.async?Promise.all(r).then(o=>a(o)):a(r)}min(e,t){return new je({...this._def,minSize:{value:e,message:E.toString(t)}})}max(e,t){return new je({...this._def,maxSize:{value:e,message:E.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}je.create=(i,e)=>new je({valueType:i,minSize:null,maxSize:null,typeName:I.ZodSet,...x(e)});class DA extends M{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})}}DA.create=(i,e)=>new DA({getter:i,typeName:I.ZodLazy,...x(e)});class EA extends M{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return P(t,{received:t.data,code:Q.invalid_literal,expected:this._def.value}),C}return{status:"valid",value:e.data}}get value(){return this._def.value}}EA.create=(i,e)=>new EA({value:i,typeName:I.ZodLiteral,...x(e)});function Qi(i,e){return new xe({values:i,typeName:I.ZodEnum,...x(e)})}class xe extends M{constructor(){super(...arguments),He.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),A=this._def.values;return P(t,{expected:L.joinValues(A),received:t.parsedType,code:Q.invalid_type}),C}if(ft(this,He,"f")||mi(this,He,new Set(this._def.values),"f"),!ft(this,He,"f").has(e.data)){const t=this._getOrReturnCtx(e),A=this._def.values;return P(t,{received:t.data,code:Q.invalid_enum_value,options:A}),C}return te(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 xe.create(e,{...this._def,...t})}exclude(e,t=this._def){return xe.create(this.options.filter(A=>!e.includes(A)),{...this._def,...t})}}He=new WeakMap;xe.create=Qi;class SA extends M{constructor(){super(...arguments),Ne.set(this,void 0)}_parse(e){const t=L.getValidEnumValues(this._def.values),A=this._getOrReturnCtx(e);if(A.parsedType!==B.string&&A.parsedType!==B.number){const n=L.objectValues(t);return P(A,{expected:L.joinValues(n),received:A.parsedType,code:Q.invalid_type}),C}if(ft(this,Ne,"f")||mi(this,Ne,new Set(L.getValidEnumValues(this._def.values)),"f"),!ft(this,Ne,"f").has(e.data)){const n=L.objectValues(t);return P(A,{received:A.data,code:Q.invalid_enum_value,options:n}),C}return te(e.data)}get enum(){return this._def.values}}Ne=new WeakMap;SA.create=(i,e)=>new SA({values:i,typeName:I.ZodNativeEnum,...x(e)});class bt extends M{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==B.promise&&t.common.async===!1)return P(t,{code:Q.invalid_type,expected:B.promise,received:t.parsedType}),C;const A=t.parsedType===B.promise?t.data:Promise.resolve(t.data);return te(A.then(n=>this._def.type.parseAsync(n,{path:t.path,errorMap:t.common.contextualErrorMap})))}}bt.create=(i,e)=>new bt({type:i,typeName:I.ZodPromise,...x(e)});class qe extends M{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===I.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:A}=this._processInputParams(e),n=this._def.effect||null,s={addIssue:a=>{P(A,a),a.fatal?t.abort():t.dirty()},get path(){return A.path}};if(s.addIssue=s.addIssue.bind(s),n.type==="preprocess"){const a=n.transform(A.data,s);if(A.common.async)return Promise.resolve(a).then(async r=>{if(t.value==="aborted")return C;const o=await this._def.schema._parseAsync({data:r,path:A.path,parent:A});return o.status==="aborted"?C:o.status==="dirty"||t.value==="dirty"?Fe(o.value):o});{if(t.value==="aborted")return C;const r=this._def.schema._parseSync({data:a,path:A.path,parent:A});return r.status==="aborted"?C:r.status==="dirty"||t.value==="dirty"?Fe(r.value):r}}if(n.type==="refinement"){const a=r=>{const o=n.refinement(r,s);if(A.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(A.common.async===!1){const r=this._def.schema._parseSync({data:A.data,path:A.path,parent:A});return r.status==="aborted"?C:(r.status==="dirty"&&t.dirty(),a(r.value),{status:t.value,value:r.value})}else return this._def.schema._parseAsync({data:A.data,path:A.path,parent:A}).then(r=>r.status==="aborted"?C:(r.status==="dirty"&&t.dirty(),a(r.value).then(()=>({status:t.value,value:r.value}))))}if(n.type==="transform")if(A.common.async===!1){const a=this._def.schema._parseSync({data:A.data,path:A.path,parent:A});if(!Re(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:A.data,path:A.path,parent:A}).then(a=>Re(a)?Promise.resolve(n.transform(a.value,s)).then(r=>({status:t.value,value:r})):a);L.assertNever(n)}}qe.create=(i,e,t)=>new qe({schema:i,typeName:I.ZodEffects,effect:e,...x(t)});qe.createWithPreprocess=(i,e,t)=>new qe({schema:e,effect:{type:"preprocess",transform:i},typeName:I.ZodEffects,...x(t)});class me extends M{_parse(e){return this._getType(e)===B.undefined?te(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}me.create=(i,e)=>new me({innerType:i,typeName:I.ZodOptional,...x(e)});class Me extends M{_parse(e){return this._getType(e)===B.null?te(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Me.create=(i,e)=>new Me({innerType:i,typeName:I.ZodNullable,...x(e)});class Ut extends M{_parse(e){const{ctx:t}=this._processInputParams(e);let A=t.data;return t.parsedType===B.undefined&&(A=this._def.defaultValue()),this._def.innerType._parse({data:A,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ut.create=(i,e)=>new Ut({innerType:i,typeName:I.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...x(e)});class Lt extends M{_parse(e){const{ctx:t}=this._processInputParams(e),A={...t,common:{...t.common,issues:[]}},n=this._def.innerType._parse({data:A.data,path:A.path,parent:{...A}});return ut(n)?n.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new de(A.common.issues)},input:A.data})})):{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new de(A.common.issues)},input:A.data})}}removeCatch(){return this._def.innerType}}Lt.create=(i,e)=>new Lt({innerType:i,typeName:I.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...x(e)});class IA extends M{_parse(e){if(this._getType(e)!==B.nan){const A=this._getOrReturnCtx(e);return P(A,{code:Q.invalid_type,expected:B.nan,received:A.parsedType}),C}return{status:"valid",value:e.data}}}IA.create=i=>new IA({typeName:I.ZodNaN,...x(i)});class Bl extends M{_parse(e){const{ctx:t}=this._processInputParams(e),A=t.data;return this._def.type._parse({data:A,path:t.path,parent:t})}unwrap(){return this._def.type}}class zt extends M{_parse(e){const{status:t,ctx:A}=this._processInputParams(e);if(A.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:A.data,path:A.path,parent:A});return s.status==="aborted"?C:s.status==="dirty"?(t.dirty(),Fe(s.value)):this._def.out._parseAsync({data:s.value,path:A.path,parent:A})})();{const n=this._def.in._parseSync({data:A.data,path:A.path,parent:A});return n.status==="aborted"?C:n.status==="dirty"?(t.dirty(),{status:"dirty",value:n.value}):this._def.out._parseSync({data:n.value,path:A.path,parent:A})}}static create(e,t){return new zt({in:e,out:t,typeName:I.ZodPipeline})}}class Tt extends M{_parse(e){const t=this._def.innerType._parse(e),A=n=>(Re(n)&&(n.value=Object.freeze(n.value)),n);return ut(t)?t.then(n=>A(n)):A(t)}unwrap(){return this._def.innerType}}Tt.create=(i,e)=>new Tt({innerType:i,typeName:I.ZodReadonly,...x(e)});G.lazycreate;var I;(function(i){i.ZodString="ZodString",i.ZodNumber="ZodNumber",i.ZodNaN="ZodNaN",i.ZodBigInt="ZodBigInt",i.ZodBoolean="ZodBoolean",i.ZodDate="ZodDate",i.ZodSymbol="ZodSymbol",i.ZodUndefined="ZodUndefined",i.ZodNull="ZodNull",i.ZodAny="ZodAny",i.ZodUnknown="ZodUnknown",i.ZodNever="ZodNever",i.ZodVoid="ZodVoid",i.ZodArray="ZodArray",i.ZodObject="ZodObject",i.ZodUnion="ZodUnion",i.ZodDiscriminatedUnion="ZodDiscriminatedUnion",i.ZodIntersection="ZodIntersection",i.ZodTuple="ZodTuple",i.ZodRecord="ZodRecord",i.ZodMap="ZodMap",i.ZodSet="ZodSet",i.ZodFunction="ZodFunction",i.ZodLazy="ZodLazy",i.ZodLiteral="ZodLiteral",i.ZodEnum="ZodEnum",i.ZodEffects="ZodEffects",i.ZodNativeEnum="ZodNativeEnum",i.ZodOptional="ZodOptional",i.ZodNullable="ZodNullable",i.ZodDefault="ZodDefault",i.ZodCatch="ZodCatch",i.ZodPromise="ZodPromise",i.ZodBranded="ZodBranded",i.ZodPipeline="ZodPipeline",i.ZodReadonly="ZodReadonly"})(I||(I={}));const V=ge.create,vt=Ce.create;we.create;const Qe=ae.create,re=G.create;G.strictCreate;gt.create;mt.create;ke.create;const Xt=xe.create;bt.create;me.create;Me.create;const Dl=re({id:V().describe("対応する入力要素のid"),ratio:vt().describe("兄弟間でのratio(weightに比例する)")}).describe("横方向要素、1~2要素 すべてのコマの重要度が低い場合は3要素も許される"),El=re({columns:Qe(Dl),ratio:vt().describe("兄弟間でのratio(weightに比例する)")}).describe("縦方向要素(段)、1~3要素"),Sl=re({rows:Qe(El)}).describe("ページ"),Il=Xt(["4koma","standard"]).describe("基本フォーマット。作風から適切な方を選べ"),Rl=re({name:V().describe("キャラクター名"),appearance:V().describe("キャラクターの容姿。脇役のappearanceは簡潔にすること"),themeColor:V().describe("キャラクターのテーマカラー")}).describe("キャラクター一覧。キャラクタードキュメントにない脇役も列挙しろ"),Cl=re({owner:V(),speech:V().describe("セリフは10文字前後までとしろ。また、適切に改行コード(\\n)を入れ、1行5文字程度に収めろ"),color:V().describe("セリフの色。話者のテーマカラー"),shape:Xt(["rounded","square","ellipse","polygon","shout","soft","none"]).describe("セリフの形。基本はsoft。キャラクタの感情にあわせろ。使ってよいのはsoft, polygon, shout, noneのいずれか。")}).describe("キャラクターのセリフ"),xl=re({composition:V().describe("そのコマの視覚情報。画像生成AIに渡されるプロンプト。セリフや音声情報を含めるな。キャラクターはいなくてもよい。キャラクターのリアクションはオーバーにし、コマごとに大きく変化させろ。"),camera:V().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:Qe(Cl).describe("そのコマのセリフ。セリフがない場合は空配列にしろ"),weight:vt().describe("そのコマの重要度。0~1の範囲で指定しろ。0が最も不要で、1が最も重要")}),ql=re({panels:Qe(xl),layout:Sl.describe("コマの配置").nullable().default(null)}),Ml=re({format:Il,actors:Qe(Rl),pages:Qe(ql)}),vi=re({name:V(),personality:V(),appearance:V(),themeColor:V().describe("テーマカラー。#ffffffff形式"),ulid:V()});Qe(vi);re({theme:V(),characters:Qe(vi),plot:V(),scenario:V(),storyboard:Ml.nullable(),critique:V(),pageNumber:vt().nullable(),format:Xt(["4koma","standard"])});const Ul={paperSize:[840,1188],paperColor:"#FFFFFF",frameColor:"#000000",frameWidth:2,templateName:"standard"};function Ll(){return{theme:"",characters:[],plot:"",scenario:"",critique:"",storyboard:null,pageNumber:null,format:"standard"}}async function Tl(i,e){const t=new Uint8Array(await i.arrayBuffer()),A=Ri.decode(t),n={};if("images"in A&&A.images){e(0);for(const l in A.images){const c=new Blob([new Uint8Array(A.images[l])],{type:"image/png"}),d=URL.createObjectURL(c),f=new Image;f.src=d,await f.decode(),URL.revokeObjectURL(d);const h=Bt(f);h.envelopeFileId=l,n[l]={type:"image",data:h},e(Object.keys(n).length/Object.keys(A.images).length)}}if("medias"in A&&A.medias){e(0);for(const l in A.medias){const c=A.medias[l],d=new Blob([new Uint8Array(c.data)],{type:c.type==="image"?`image/${c.format??"png"}`:"video/mp4"}),f=URL.createObjectURL(d);if(c.type==="image"){const h=new Image;h.src=f,await h.decode(),URL.revokeObjectURL(f);const p=Bt(h);p.envelopeFileId=l,n[l]={type:"image",data:p}}else{const h=document.createElement("video");h.src=f,await CA(h),n[l]={type:"video",data:h}}e(Object.keys(n).length/Object.keys(A.medias).length)}}const s=A.notebook?await $o(A.notebook,async l=>n[l].data):Ll(),a=A.attributes??null;console.log("readEnvelope",A.attributes,a);const r={revision:{id:"not visited",revision:1,prefix:"envelope-"},pages:[],history:{entries:[],cursor:0},direction:A.direction,wrapMode:A.wrapMode,chatLogs:[],notebook:s,attributes:{publishUrl:null,...a??{}},newPageProperty:A.newPageProperty??{...Ul}},o=async l=>n[l].data;for(const l of A.pages){const c=await pi(l.paperSize,l.frameTree,o),d=await _o(l.paperSize,l.bubbles,o),f={id:l.id??Se.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 yi{constructor(e,t,A,n){this.arrayLayer=e,this.layeredCanvas=t,this.focusKeeper=A,this.marks=n}cleanup(){this.layeredCanvas.cleanup()}focusToPage(e,t=1){const A=this.layeredCanvas.viewport,[n,s]=A.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;A.scale=l,A.translate=[-c[0]*l,-c[1]*l],A.dirty=!0,this.layeredCanvas.redraw()}getScale(){return this.layeredCanvas.viewport.scale}resetFontCache(){var e,t;for(const A of this.arrayLayer.array.papers)(t=(e=A.paper)==null?void 0:e.findLayer(ui))==null||t.resetCache()}}function Ol(i,e,t=0,A=-1){console.log("Building renderer...");const n=new ji(i,()=>{}),s=new Yo,a=new Ki(n,!0),r=new JA(a.viewport,()=>{},()=>{},s);a.rootPaper.addLayer(r);let o=[];const l=A<0?e.pages.length:t+A;for(let v=t;v<l;v++){const m=e.pages[v];for(const b of m.bubbles)b.pageNumber=v;o.push(Jl(e,m,s))}const c=Zl(e.direction),{fold:d,gapX:f,gapY:h}=Vl(e.wrapMode),p=[],g=new Vr(o,p,d,f,h,c,()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{},()=>{});return a.rootPaper.addLayer(g),a.mode="viewer",new yi(g,a,s,p)}function Gl(i){i.cleanup()}function Jl(i,e,t){const A=new OA(e.paperSize,!1),n=new ui(!0);n.setFrameTree(e.frameTree),n.setBubbles(e.bubbles),A.addLayer(n);const s=new KA(e.frameTree,e.bubbles,a=>{console.log(a)},t,i.attributes.showVideoPlayButton??!0,i.attributes.showVideoDottedBorder??!0);return A.addLayer(s),e.frameTree.bgColor=e.paperColor,e.frameTree.borderColor=e.frameColor,e.frameTree.borderWidth=e.frameWidth,A}function Vl(i){switch(i){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 Zl(i){switch(i){case"left-to-right":return 1;case"right-to-left":return-1}}function Fl(i){const e=new Set;for(let t of i.pages)for(let A of t.bubbles)e.add(JSON.stringify({family:A.fontFamily,weight:A.fontWeight}));return[...e].map(t=>JSON.parse(t))}const Pi={源暎アンチック:"GenEiAntiqueNv5-M",源暎エムゴ:"GenEiMGothic2-Black",源暎ぽっぷる:"GenEiPOPle-Bk",源暎ラテゴ:"GenEiLateMinN_v2",源暎ラテミン:"GenEiLateMinN_v2",源暎きわみゴ:"GenEiKiwamiGo",ふい字:"HuiFont29",まきばフォント:"MakibaFont13"};function ki(i){return Pi[i]!==void 0}function Hl(i){return!ki(i)}const RA=new Set;async function Bi(i,e=["400"]){try{const t=`${i}-${e.join("-")}`;if(RA.has(t))return;const A=i.replace(/\s+/g,"+"),n=e.join(";"),s=`https://fonts.googleapis.com/css2?family=${A}: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],h=r.substring(0,c.index).split("}").slice(-1)[0].match(/font-weight: (\d+)/),p=h?h[1]:"400";return new FontFace(i,`url(${d})`,{weight:p,style:"normal"}).load().then(v=>(document.fonts.add(v),v))});await Promise.all(l),await document.fonts.ready,RA.add(t)}catch(t){throw console.error(`Failed to load font "${i}":`,t),t}}async function Nl(i,e=["400"]){try{await Bi(i,e),await document.fonts.ready;const t=e.map(A=>Di(i,A));await Promise.all(t),console.log(`Font "${i}" is fully loaded and ready for Canvas use`)}catch(t){throw console.error(`Failed to load font "${i}" for Canvas:`,t),t}}async function Di(i,e="400",t=20,A=50){const n="あいうえおABCDE12345",s="24px";function a(){const o=document.createElement("canvas").getContext("2d");o.font=`${e} ${s} "${i}"`;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 "${i}" ${e} is ready for Canvas`),!0;await new Promise(o=>setTimeout(o,A))}throw new Error(`Timeout waiting for font "${i}" ${e} to be ready for Canvas`)}exports.Renderer=yi;exports.buildRenderer=Ol;exports.checkCanvasFontAvailable=Di;exports.destroyRenderer=Gl;exports.initPaperJs=fo;exports.isGoogleFont=Hl;exports.isLocalFont=ki;exports.listFonts=Fl;exports.loadGoogleFont=Bi;exports.loadGoogleFontForCanvas=Nl;exports.localFonts=Pi;exports.readEnvelope=Tl;
|