@konoui/mjimage 0.0.35 → 0.0.36
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 +1 -1
- package/dist/index.js +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`?n+=a:(this.attr("dy",r?a+n:0),n=0))}),this.fire("rebuild")}return this}setData(t){return this.dom=t,this.dom.leading=new k(t.leading||1.3),this}writeDataToDom(){return ti(this,this.dom,{leading:1.3}),this}text(t){if(t===void 0){const e=this.node.childNodes;let n=0;t="";for(let i=0,r=e.length;i<r;++i){if(e[i].nodeName==="textPath"||An(e[i])){i===0&&(n=i+1);continue}i!==n&&e[i].nodeType!==3&&st(e[i]).dom.newLined===!0&&(t+=`
|
|
4
4
|
`),t+=e[i].textContent}return t}if(this.clear().build(!0),typeof t=="function")t.call(this,this);else{t=(t+"").split(`
|
|
5
5
|
`);for(let e=0,n=t.length;e<n;e++)this.newLine(t[e])}return this.build(!1).rebuild()}}I(F,Ai);T({Container:{text:R(function(s=""){return this.put(new F).text(s)}),plain:R(function(s=""){return this.put(new F).plain(s)})}});N(F,"Text");class rn extends et{constructor(t,e=t){super(H("tspan",t),e),this._build=!1}dx(t){return this.attr("dx",t)}dy(t){return this.attr("dy",t)}newLine(){this.dom.newLined=!0;const t=this.parent();if(!(t instanceof F))return this;const e=t.index(this),n=E.window.getComputedStyle(this.node).getPropertyValue("font-size"),i=t.dom.leading*new k(n);return this.dy(e?i:0).attr("x",t.x())}text(t){return t==null?this.node.textContent+(this.dom.newLined?`
|
|
6
|
-
`:""):(typeof t=="function"?(this.clear().build(!0),t.call(this,this),this.build(!1)):this.plain(t),this)}}I(rn,Ai);T({Tspan:{tspan:R(function(s=""){const t=new rn;return this._build||this.clear(),this.put(t).text(s)})},Text:{newLine:function(s=""){return this.tspan(s).newLine()}}});N(rn,"Tspan");class ls extends et{constructor(t,e=t){super(H("circle",t),e)}radius(t){return this.attr("r",t)}rx(t){return this.attr("r",t)}ry(t){return this.rx(t)}size(t){return this.radius(new k(t).divide(2))}}I(ls,{x:hi,y:li,cx:ui,cy:fi,width:di,height:pi});T({Container:{circle:R(function(s=0){return this.put(new ls).size(s).move(0,0)})}});N(ls,"Circle");class Nn extends J{constructor(t,e=t){super(H("clipPath",t),e)}remove(){return this.targets().forEach(function(t){t.unclip()}),super.remove()}targets(){return ce("svg [clip-path*="+this.id()+"]")}}T({Container:{clip:R(function(){return this.defs().put(new Nn)})},Element:{clipper(){return this.reference("clip-path")},clipWith(s){const t=s instanceof Nn?s:this.parent().clip().add(s);return this.attr("clip-path","url(#"+t.id()+")")},unclip(){return this.attr("clip-path",null)}}});N(Nn,"ClipPath");class xi extends dt{constructor(t,e=t){super(H("foreignObject",t),e)}}T({Container:{foreignObject:R(function(s,t){return this.put(new xi).size(s,t)})}});N(xi,"ForeignObject");function Sa(s,t){return this.children().forEach(e=>{let n;try{n=e.node instanceof xr().SVGSVGElement?new L(e.attr(["x","y","width","height"])):e.bbox()}catch{return}const i=new A(e),r=i.translate(s,t).transform(i.inverse()),o=new B(n.x,n.y).transform(r);e.move(o.x,o.y)}),this}function va(s){return this.dmove(s,0)}function Aa(s){return this.dmove(0,s)}function xa(s,t=this.bbox()){return s==null?t.height:this.size(t.width,s,t)}function ka(s=0,t=0,e=this.bbox()){const n=s-e.x,i=t-e.y;return this.dmove(n,i)}function Ta(s,t,e=this.bbox()){const n=ae(this,s,t,e),i=n.width/e.width,r=n.height/e.height;return this.children().forEach(o=>{const a=new B(e).transform(new A(o).inverse());o.scale(i,r,a.x,a.y)}),this}function Oa(s,t=this.bbox()){return s==null?t.width:this.size(s,t.height,t)}function Ia(s,t=this.bbox()){return s==null?t.x:this.move(s,t.y,t)}function Ea(s,t=this.bbox()){return s==null?t.y:this.move(t.x,s,t)}const ki=Object.freeze(Object.defineProperty({__proto__:null,dmove:Sa,dx:va,dy:Aa,height:xa,move:ka,size:Ta,width:Oa,x:Ia,y:Ea},Symbol.toStringTag,{value:"Module"}));class z extends J{constructor(t,e=t){super(H("g",t),e)}}I(z,ki);T({Container:{group:R(function(){return this.put(new z)})}});N(z,"G");class Ge extends J{constructor(t,e=t){super(H("a",t),e)}target(t){return this.attr("target",t)}to(t){return this.attr("href",t,Oe)}}I(Ge,ki);T({Container:{link:R(function(s){return this.put(new Ge).to(s)})},Element:{unlink(){const s=this.linker();if(!s)return this;const t=s.parent();if(!t)return this.remove();const e=t.index(s);return t.add(this,e),s.remove(),this},linkTo(s){let t=this.linker();return t||(t=new Ge,this.wrap(t)),typeof s=="function"?s.call(t,t):t.to(s),this},linker(){const s=this.parent();return s&&s.node.nodeName.toLowerCase()==="a"?s:null}}});N(Ge,"A");class Mn extends J{constructor(t,e=t){super(H("mask",t),e)}remove(){return this.targets().forEach(function(t){t.unmask()}),super.remove()}targets(){return ce("svg [mask*="+this.id()+"]")}}T({Container:{mask:R(function(){return this.defs().put(new Mn)})},Element:{masker(){return this.reference("mask")},maskWith(s){const t=s instanceof Mn?s:this.parent().mask().add(s);return this.attr("mask","url(#"+t.id()+")")},unmask(){return this.attr("mask",null)}}});N(Mn,"Mask");class Ti extends dt{constructor(t,e=t){super(H("stop",t),e)}update(t){return(typeof t=="number"||t instanceof k)&&(t={offset:arguments[0],color:arguments[1],opacity:arguments[2]}),t.opacity!=null&&this.attr("stop-opacity",t.opacity),t.color!=null&&this.attr("stop-color",t.color),t.offset!=null&&this.attr("offset",new k(t.offset)),this}}T({Gradient:{stop:function(s,t,e){return this.put(new Ti).update(s,t,e)}}});N(Ti,"Stop");function Na(s,t){if(!s)return"";if(!t)return s;let e=s+"{";for(const n in t)e+=Sr(n)+":"+t[n]+";";return e+="}",e}class Dn extends dt{constructor(t,e=t){super(H("style",t),e)}addText(t=""){return this.node.textContent+=t,this}font(t,e,n={}){return this.rule("@font-face",{fontFamily:t,src:e,...n})}rule(t,e){return this.addText(Na(t,e))}}T("Dom",{style(s,t){return this.put(new Dn).rule(s,t)},fontface(s,t,e){return this.put(new Dn).font(s,t,e)}});N(Dn,"Style");class us extends F{constructor(t,e=t){super(H("textPath",t),e)}array(){const t=this.track();return t?t.array():null}plot(t){const e=this.track();let n=null;return e&&(n=e.plot(t)),t==null?n:this}track(){return this.reference("href")}}T({Container:{textPath:R(function(s,t){return s instanceof F||(s=this.text(s)),s.path(t)})},Text:{path:R(function(s,t=!0){const e=new us;s instanceof he||(s=this.defs().path(s)),e.attr("href","#"+s,Oe);let n;if(t)for(;n=this.node.firstChild;)e.node.appendChild(n);return this.put(e)}),textPath(){return this.findOne("textPath")}},Path:{text:R(function(s){return s instanceof F||(s=new F().addTo(this.parent()).text(s)),s.path(this)}),targets(){return ce("svg textPath").filter(s=>(s.attr("href")||"").includes(this.id()))}}});us.prototype.MorphArray=Wt;N(us,"TextPath");class on extends et{constructor(t,e=t){super(H("use",t),e)}use(t,e){return this.attr("href",(e||"")+"#"+t,Oe)}}T({Container:{use:R(function(s,t){return this.put(new on).use(s,t)})}});N(on,"Use");I([hs,sn,Ne,be,Fe],X("viewbox"));I([Se,Ce,De,he],X("marker"));I(F,X("Text"));I(he,X("Path"));I(ss,X("Defs"));I([F,rn],X("Tspan"));I([Re,nn,Ee,tt],X("radius"));I(Ie,X("EventTarget"));I(xt,X("Dom"));I(dt,X("Element"));I(et,X("Shape"));I([J,mi],X("Container"));I(Ee,X("Gradient"));I(tt,X("Runner"));$t.extend(_r());Jo([k,D,L,A,Qt,kt,Wt,B]);Vo();class te{constructor(t={}){b(this,"tileWidth");b(this,"tileHeight");b(this,"imageHostPath");b(this,"imageHostUrl");b(this,"imageExt");b(this,"scale");b(this,"svgSprite");this.scale=t.scale??1,this.imageHostPath=t.imageHostPath??"",this.imageHostUrl=t.imageHostUrl??"",this.imageExt=t.imageExt??"svg",this.tileWidth=vt.WIDTH*this.scale,this.tileHeight=vt.HEIGHT*this.scale,this.svgSprite=t.svgSprite??!1}getDiffTileHeightWidth(t){const e=t.imageSize(this.scale);return(e.baseHeight-e.baseWidth)/2}image(t){let e=new Ne().load(this.buildURL(t));return this.svgSprite&&(e=new on().use(te.buildID(t))),t instanceof g&&t.has(v.COLOR_GRAYSCALE)&&e.css({filter:"contrast(65%)"}),e}createImage(t,e,n){const i=t.imageSize(this.scale);return this.image(t).dx(e).dy(n).size(i.baseWidth,i.baseHeight)}createTextImage(t,e,n,i){const r=this.createImage(t,e,n),o=t.imageSize(this.scale),a=o.baseHeight*.2,c=o.baseWidth,h=o.baseHeight,l=new F().text(i);l.size(o.baseWidth,o.baseHeight).font({family:qn,size:a}).dx(c).dy(h);const u=new z;return u.add(r).add(l).translate(e,n),u}createRotate90Image(t,e,n,i=!1){const r=this.createImage(t,0,0),o=t.imageSize(this.scale),a=o.baseWidth/2,c=o.baseHeight/2,h=e+this.getDiffTileHeightWidth(t),l=i?n-this.getDiffTileHeightWidth(t):n,u=new z;return u.add(r).translate(h,l).rotate(90,a,c),u}createStick(t){return this.image(t)}static buildID(t){if(t==100||t==1e3)return t==100?"stick100":"stick1000";const e=t.t==d.BACK?0:t.n;return`${t.t}${e}`}buildURL(t){const e=`${te.buildID(t)}.${this.imageExt}`;return this.imageHostUrl!=""?`${this.imageHostUrl}${e}`:`${this.imageHostPath}${e}`}}class fs extends te{constructor(){super(...arguments);b(this,"blockMargin",vt.WIDTH*vt.BLOCK_MARGIN_SCALE*this.scale)}createBlockHandDiscard(e){const n=new z;let i=0;for(let r of e.tiles){const o=r.imageSize(this.scale),a=r.has(v.HORIZONTAL)?this.createRotate90Image.bind(this):this.createImage.bind(this),c=r.has(v.HORIZONTAL)?this.getDiffTileHeightWidth(r):0,h=a(r,i,c);n.add(h),i+=o.width}return n}createBlockPonChiKan(e){const n=e.tiles.findIndex(o=>o.has(v.HORIZONTAL));let i=0;const r=new z;if(e.type==_.SHO_KAN){let o=n;for(let a=0;a<e.tiles.length;a++)e.tiles[a].has(v.HORIZONTAL)&&(o=a);for(let a=0;a<e.tiles.length;a++){const c=e.tiles[a].imageSize(this.scale);if(a==o)continue;if(a==n){const u=e.tiles[n],f=e.tiles[o],m=u.imageSize(this.scale),p=this.createRotate90Image(u,0,0,!0),y=this.createRotate90Image(f,0,m.height,!0);r.add(new z().translate(i,0).add(p).add(y)),i+=m.width;continue}const h=c.width*2-c.height,l=this.createImage(e.tiles[a],i,h);i+=c.width,r.add(l)}return r}if(e.type==_.CHI){const o=this.createRotate90Image(e.tiles[n],i,this.getDiffTileHeightWidth(e.tiles[n]));i+=e.tiles[n].imageSize(this.scale).width,r.add(o);for(let a=0;a<e.tiles.length;a++){if(a==n)continue;const c=e.tiles[a].imageSize(this.scale),h=this.createImage(e.tiles[a],i,0);i+=c.width,r.add(h)}return r}for(let o=0;o<e.tiles.length;o++){const a=o==n?this.createRotate90Image.bind(this):this.createImage.bind(this),c=o==n?this.getDiffTileHeightWidth(e.tiles[o]):0,h=e.tiles[o].imageSize(this.scale),l=a(e.tiles[o],i,c);i+=h.width,r.add(l)}return r}}const Ma=s=>{const t=s.scale;return{[_.CHI]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.PON]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.DAI_KAN]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.SHO_KAN]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.AN_KAN]:function(n){assert(n instanceof U,`block type is not ankan: ${n.type}`);const i=n.imageSize(t),r=n.tilesWithBack.filter(a=>a.t!==d.BACK);assert(r!=null&&r.length==2,`back tile must be two but ${n}`);const o=s.createBlockHandDiscard(new U([r[0],r[1],r[0],r[1]]));return{...i,e:o}},[_.IMAGE_DORA]:function(n){const i=n.imageSize(t),r=new z,o=s.createTextImage(n.tiles[0],0,0,"(ドラ)");return r.add(o),{...i,e:r}},[_.TSUMO]:function(n){const i=n.imageSize(t),r=new z,o=s.createTextImage(n.tiles[0],0,0,"(ツモ)");return r.add(o),{...i,e:r}},[_.HAND]:function(n){const i=n.imageSize(t),r=s.createBlockHandDiscard(n);return{...i,e:r}},[_.IMAGE_DISCARD]:function(n){const i=n.imageSize(t),r=s.createBlockHandDiscard(n);return{...i,e:r}},[_.THREE]:function(n){throw new Error("found unknown block")},[_.RUN]:function(n){throw new Error("found unknown block")},[_.UNKNOWN]:function(n){throw new Error("found unknown block")},[_.PAIR]:function(n){throw new Error("unsupported")},[_.ISOLATED]:function(n){throw new Error("unsupported")}}},Xt=(s,t)=>{const{maxHeight:e,sumWidth:n}=t.reduce((l,u)=>{const f=u.imageSize(s.scale);return{maxHeight:f.height>l.maxHeight?f.height:l.maxHeight,sumWidth:l.sumWidth+f.width}},{maxHeight:0,sumWidth:0}),i=e,r=n+(t.length-1)*s.blockMargin,o=Ma(s),a=[];for(let l of t){const u=o[l.type],f=u(l);a.push(f)}const c=new z;let h=0;for(let l of a){const u=i-l.height,f=new z().translate(h,u);f.add(l.e),c.add(f),h+=l.width+s.blockMargin}return{e:c,width:r,height:i}},Da=(s,t,e={},n={responsive:!1})=>{const i=new fs(e),r=Xt(i,t);n.responsive||s.size(r.width,r.height),s.viewbox(0,0,r.width,r.height),s.add(r.e)},Oi=()=>{const s=[0,1,2,3,4,5,6,7,8,9],t=[];for(let e of Object.values(d)){if(e==d.BACK){t.push(te.buildID(new g(e,0)));continue}t.push(...s.map(n=>te.buildID(new g(e,n))).flat())}return t},Ca=s=>{const t=Oi(),e=[];return s.each((n,i)=>{const r=i[n];if(r instanceof on){const a=r.attr("href").substring(1);t.includes(a)&&e.push(a)}}),e},Ra=s=>{const t=Oi(),e=Ca(s);s.each((n,i)=>{const r=i[n];r instanceof sn&&(t.includes(r.id())&&e.includes(r.id())||r.remove())},!0)},Ha=s=>{const e=[];for(let n=0;n<s.length;n+=6){const i=s.slice(n,n+6);e.push(i)}return e},ht=(s,t,e,n,i=0,r=0)=>{const o=new z().add(s);if(n==90){const a=i,c=r-e;return o.rotate(n,0,e).translate(a,c),o}if(n==180){const a=i+t,c=r-e;return o.rotate(n,0,e).translate(a,c),o}if(n==270){const a=i+e,c=r+(t-e);return o.rotate(n,0,e).translate(a,c),o}return o},ze=(s,t)=>{const e=new z,n=Ha(s);for(let i=0;i<n.length;i++){let r=n[i],o=i*t.tileHeight;const a=t.createBlockHandDiscard(new Xn(r,_.IMAGE_DISCARD)).translate(0,o);e.add(a)}return{e,width:t.tileWidth*5+t.tileHeight*1,height:t.tileHeight*n.length}},$a=(s,t,e)=>{const n=t.font,i=t.textWidth,r=t.textHeight,o=new z,a=e.sticks.dead,c=e.sticks.reach,h=125*s.scale,l=27.5*s.scale;let u=i*3,f=r;const m=(h+s.tileWidth+i-u)/2,p=new F().plain(e.round).font(n).move(m,0);o.add(p),f+=25*s.scale;const y=s.tileHeight,w=new z().size(h,y).translate(0,f),x={family:n.family,size:n.size*.7},O=s.createStick(1e3).size(h,l).move(0,0),$=new F().plain(c.toString()).font(x).attr({x:h,y:l});w.add(O),w.add($);const nt=s.createStick(100).size(h,l).move(0,l+l),K=new F().plain(a.toString()).font(x).attr({x:h,y:l*3});w.add(nt),w.add(K);const rt=s.createImage(e.doras[0],0,0).move(h+i,0);return w.add(rt),o.add(p),o.add(w),{e:o,width:h+s.tileWidth+i,height:f+s.tileHeight}},Wa=(s,t,e=0)=>{const n=Xt(s,t.front),i=Xt(s,t.right),r=Xt(s,t.opposite),o=Xt(s,t.left),a=[n.width,i.width,r.width,o.width].reduce((y,w)=>Math.max(y,w)),c=Math.max(e+s.tileHeight*2+s.blockMargin*2,a+s.tileWidth*2+s.blockMargin),h=c,l=new z().size(c,h),u=ht(n.e,n.width,n.height,0).translate((c-n.width)/2,h-n.height),f=ht(i.e,i.width,i.height,270).translate(c-i.height,(c-i.width)/2),m=ht(r.e,r.width,r.height,180).translate((c-r.width)/2,0),p=ht(o.e,o.width,o.height,90).translate(0,(c-o.width)/2);return l.add(u),l.add(f),l.add(m),l.add(p),{e:l,width:c,height:h}},Ba=s=>{const t=Object.values(tn),e=t.indexOf(s);return[...t.slice(e),...t.slice(0,e)]},za=(s,t,e)=>{const n=s.tileWidth*5+s.tileHeight*1,i=new z,r=new Re().size(n,n).move(0,0).fill("none").stroke("#000000");i.add(r);const o=t.font,a=t.textWidth,c=t.textHeight,h=t.numWidth,l=$a(s,t,e);l.e.translate(n/2-l.width/2,n/2-l.height/2);const u=(cn,Ts,ar)=>{const cr=`${cn} ${Ts}`,hr=new F().plain(cr).font(o).attr(ar);return{e:new z().add(hr),width:a+h*Ts.toString().length,height:c}},[f,m,p,y]=Ba(e.frontPlace),w=e.scores,O=u(f,w.front,{x:n/2,y:n,"dominant-baseline":"text-after-edge","text-anchor":"middle"}).e;let $=u(m,w.right,{"dominant-baseline":"text-after-edge","text-anchor":"middle"});const nt=ht($.e,$.width,$.height,270).translate(n,n/2-$.width);let K=u(p,w.opposite,{"text-anchor":"middle","dominant-baseline":"text-after-edge"});const rt=ht(K.e,K.width,K.height,180).translate(n/2-K.width,-K.height);let pt=u(y,w.left,{"dominant-baseline":"ideographic","text-anchor":"middle"});const Kt=ht(pt.e,pt.width,pt.height,90).translate(-pt.height,n/2);return i.add(l.e),i.add(O),i.add(nt),i.add(rt),i.add(Kt),{e:i,width:n,height:n}},Pa=(s,t)=>{const e=ze(t.front,s),n=ze(t.right,s),i=ze(t.opposite,s),r=ze(t.left,s),o=[e.height,n.height,i.height,r.height].reduce((O,$)=>Math.max(O,$)),a=s.tileWidth*5+s.tileHeight*1,c=o,h=a+o*2+s.blockMargin,l=h,u=new z().size(h,l),f=h/2-a/2,m=l/2-a/2,p=ht(e.e,a,c,0).translate(f,l-c),y=ht(n.e,a,c,270).translate(h-c,m),w=ht(i.e,a,c,180).translate(f,0),x=ht(r.e,a,c,90).translate(0,m);return u.add(p),u.add(y),u.add(w),u.add(x),{e:u,width:h,height:l}},Ii=(s,t,e,n,i)=>{const r=new z,o=Pa(s,n),a=Wa(s,e,o.height),c=za(s,t,i);return o.e.translate((a.width-o.width)/2,(a.height-o.height)/2),c.e.translate((a.width-c.width)/2,(a.height-c.height)/2),r.add(a.e),r.add(o.e),r.add(c.e),{e:r,width:a.width,height:a.height}},ja=(s,t,e={},n,i={responsive:!1})=>{const r=new fs(e),o=n,{discards:a,hands:c,scoreBoard:h}=Ei(t),l=Ii(r,o,c,a,h);i.responsive||s.size(l.width,l.height),s.viewbox(0,0,l.width,l.height),s.add(l.e)};var mt;function La(s){return{lang:(s==null?void 0:s.lang)??(mt==null?void 0:mt.lang),message:s==null?void 0:s.message,abortEarly:(s==null?void 0:s.abortEarly)??(mt==null?void 0:mt.abortEarly),abortPipeEarly:(s==null?void 0:s.abortPipeEarly)??(mt==null?void 0:mt.abortPipeEarly)}}var mn;function Ka(s){return mn==null?void 0:mn.get(s)}var gn;function Ua(s){return gn==null?void 0:gn.get(s)}var yn;function Fa(s,t){var e;return(e=yn==null?void 0:yn.get(s))==null?void 0:e.get(t)}function ee(s){var e,n;const t=typeof s;return t==="string"?`"${s}"`:t==="number"||t==="bigint"||t==="boolean"?`${s}`:t==="object"||t==="function"?(s&&((n=(e=Object.getPrototypeOf(s))==null?void 0:e.constructor)==null?void 0:n.name))??"null":t}function Bt(s,t,e,n,i){const r=i&&"input"in i?i.input:e.value,o=(i==null?void 0:i.expected)??s.expects??null,a=(i==null?void 0:i.received)??ee(r),c={kind:s.kind,type:s.type,input:r,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:s.requirement,path:i==null?void 0:i.path,issues:i==null?void 0:i.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},h=s.kind==="schema",l=(i==null?void 0:i.message)??s.message??Fa(s.reference,c.lang)??(h?Ua(c.lang):null)??n.message??Ka(c.lang);l&&(c.message=typeof l=="function"?l(c):l),h&&(e.typed=!1),e.issues?e.issues.push(c):e.issues=[c]}function qa(s,t){const e=[...new Set(s)];return e.length>1?`(${e.join(` ${t} `)})`:e[0]??"never"}function Cn(s,t){return{kind:"validation",type:"max_value",reference:Cn,async:!1,expects:`<=${s instanceof Date?s.toJSON():ee(s)}`,requirement:s,message:t,_run(e,n){return e.typed&&e.value>this.requirement&&Bt(this,"value",e,n,{received:e.value instanceof Date?e.value.toJSON():ee(e.value)}),e}}}function Rn(s,t){return{kind:"validation",type:"min_value",reference:Rn,async:!1,expects:`>=${s instanceof Date?s.toJSON():ee(s)}`,requirement:s,message:t,_run(e,n){return e.typed&&e.value<this.requirement&&Bt(this,"value",e,n,{received:e.value instanceof Date?e.value.toJSON():ee(e.value)}),e}}}function Za(s,t,e){return typeof s.default=="function"?s.default(t,e):s.default}function Ye(s){return{kind:"schema",type:"number",reference:Ye,expects:"number",async:!1,message:s,_run(t,e){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:Bt(this,"type",t,e),t}}}function it(s,...t){const e={kind:"schema",type:"optional",reference:it,expects:`(${s.expects} | undefined)`,async:!1,wrapped:s,_run(n,i){return n.value===void 0&&("default"in this&&(n.value=Za(this,n,i)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in t&&(e.default=t[0]),e}function Hn(s,t){return{kind:"schema",type:"picklist",reference:Hn,expects:qa(s.map(ee),"|"),async:!1,options:s,message:t,_run(e,n){return this.options.includes(e.value)?e.typed=!0:Bt(this,"type",e,n),e}}}function ne(s,t){return{kind:"schema",type:"strict_object",reference:ne,expects:"Object",async:!1,entries:s,message:t,_run(e,n){var r;const i=e.value;if(i&&typeof i=="object"){e.typed=!0,e.value={};for(const o in this.entries){const a=i[o],c=this.entries[o]._run({typed:!1,value:a},n);if(c.issues){const h={type:"object",origin:"value",input:i,key:o,value:a};for(const l of c.issues)l.path?l.path.unshift(h):l.path=[h],(r=e.issues)==null||r.push(l);if(e.issues||(e.issues=c.issues),n.abortEarly){e.typed=!1;break}}c.typed||(e.typed=!1),(c.value!==void 0||o in i)&&(e.value[o]=c.value)}if(!e.issues||!n.abortEarly){for(const o in i)if(!(o in this.entries)){const a=i[o];Bt(this,"type",e,n,{input:a,expected:"never",path:[{type:"object",origin:"value",input:i,key:o,value:a}]});break}}}else Bt(this,"type",e,n);return e}}}function Xe(s){return{kind:"schema",type:"string",reference:Xe,expects:"string",async:!1,message:s,_run(t,e){return typeof t.value=="string"?t.typed=!0:Bt(this,"type",t,e),t}}}function Hs(...s){return{...s[0],pipe:s,_run(t,e){for(const n of s)if(n.kind!=="metadata"){if(t.issues&&(n.kind==="schema"||n.kind==="transformation")){t.typed=!1;break}(!t.issues||!e.abortEarly&&!e.abortPipeEarly)&&(t=n._run(t,e))}return t}}}function Ga(s,t,e){const n=s._run({typed:!1,value:t},La(e));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}const Pe=it(ne({discard:it(Xe(),""),hand:it(Xe(),""),score:it(Ye(),25e3)}),{discard:"",hand:"",score:25e3}),Ya=ne({[S.E]:Pe,[S.S]:Pe,[S.W]:Pe,[S.N]:Pe}),Ot={round:P.E1,sticks:{reach:0,dead:0},doras:S.S,front:S.E},Xa=it(ne({round:it(Hn(Object.keys(Zn)),Ot.round),sticks:it(ne({reach:it(Hs(Ye(),Rn(0,""),Cn(9,"")),Ot.sticks.reach),dead:it(Hs(Ye(),Rn(0,""),Cn(9,"")),Ot.sticks.dead)}),Ot.sticks),doras:it(Xe(),Ot.doras),front:it(Hn(Object.keys(tn)),Ot.front)}),Ot),Ja=ne({...Ya.entries,board:Xa}),Ei=s=>{const t=Ni(s);return Mi(t)},Ni=s=>{const t=Va(s),e=Ga(Ja,t);if(!e.success)throw e.issues;return e.output},Va=s=>{const t="table",e="board",n=s.split(`
|
|
6
|
+
`:""):(typeof t=="function"?(this.clear().build(!0),t.call(this,this),this.build(!1)):this.plain(t),this)}}I(rn,Ai);T({Tspan:{tspan:R(function(s=""){const t=new rn;return this._build||this.clear(),this.put(t).text(s)})},Text:{newLine:function(s=""){return this.tspan(s).newLine()}}});N(rn,"Tspan");class ls extends et{constructor(t,e=t){super(H("circle",t),e)}radius(t){return this.attr("r",t)}rx(t){return this.attr("r",t)}ry(t){return this.rx(t)}size(t){return this.radius(new k(t).divide(2))}}I(ls,{x:hi,y:li,cx:ui,cy:fi,width:di,height:pi});T({Container:{circle:R(function(s=0){return this.put(new ls).size(s).move(0,0)})}});N(ls,"Circle");class Nn extends J{constructor(t,e=t){super(H("clipPath",t),e)}remove(){return this.targets().forEach(function(t){t.unclip()}),super.remove()}targets(){return ce("svg [clip-path*="+this.id()+"]")}}T({Container:{clip:R(function(){return this.defs().put(new Nn)})},Element:{clipper(){return this.reference("clip-path")},clipWith(s){const t=s instanceof Nn?s:this.parent().clip().add(s);return this.attr("clip-path","url(#"+t.id()+")")},unclip(){return this.attr("clip-path",null)}}});N(Nn,"ClipPath");class xi extends dt{constructor(t,e=t){super(H("foreignObject",t),e)}}T({Container:{foreignObject:R(function(s,t){return this.put(new xi).size(s,t)})}});N(xi,"ForeignObject");function Sa(s,t){return this.children().forEach(e=>{let n;try{n=e.node instanceof xr().SVGSVGElement?new L(e.attr(["x","y","width","height"])):e.bbox()}catch{return}const i=new A(e),r=i.translate(s,t).transform(i.inverse()),o=new B(n.x,n.y).transform(r);e.move(o.x,o.y)}),this}function va(s){return this.dmove(s,0)}function Aa(s){return this.dmove(0,s)}function xa(s,t=this.bbox()){return s==null?t.height:this.size(t.width,s,t)}function ka(s=0,t=0,e=this.bbox()){const n=s-e.x,i=t-e.y;return this.dmove(n,i)}function Ta(s,t,e=this.bbox()){const n=ae(this,s,t,e),i=n.width/e.width,r=n.height/e.height;return this.children().forEach(o=>{const a=new B(e).transform(new A(o).inverse());o.scale(i,r,a.x,a.y)}),this}function Oa(s,t=this.bbox()){return s==null?t.width:this.size(s,t.height,t)}function Ia(s,t=this.bbox()){return s==null?t.x:this.move(s,t.y,t)}function Ea(s,t=this.bbox()){return s==null?t.y:this.move(t.x,s,t)}const ki=Object.freeze(Object.defineProperty({__proto__:null,dmove:Sa,dx:va,dy:Aa,height:xa,move:ka,size:Ta,width:Oa,x:Ia,y:Ea},Symbol.toStringTag,{value:"Module"}));class z extends J{constructor(t,e=t){super(H("g",t),e)}}I(z,ki);T({Container:{group:R(function(){return this.put(new z)})}});N(z,"G");class Ge extends J{constructor(t,e=t){super(H("a",t),e)}target(t){return this.attr("target",t)}to(t){return this.attr("href",t,Oe)}}I(Ge,ki);T({Container:{link:R(function(s){return this.put(new Ge).to(s)})},Element:{unlink(){const s=this.linker();if(!s)return this;const t=s.parent();if(!t)return this.remove();const e=t.index(s);return t.add(this,e),s.remove(),this},linkTo(s){let t=this.linker();return t||(t=new Ge,this.wrap(t)),typeof s=="function"?s.call(t,t):t.to(s),this},linker(){const s=this.parent();return s&&s.node.nodeName.toLowerCase()==="a"?s:null}}});N(Ge,"A");class Mn extends J{constructor(t,e=t){super(H("mask",t),e)}remove(){return this.targets().forEach(function(t){t.unmask()}),super.remove()}targets(){return ce("svg [mask*="+this.id()+"]")}}T({Container:{mask:R(function(){return this.defs().put(new Mn)})},Element:{masker(){return this.reference("mask")},maskWith(s){const t=s instanceof Mn?s:this.parent().mask().add(s);return this.attr("mask","url(#"+t.id()+")")},unmask(){return this.attr("mask",null)}}});N(Mn,"Mask");class Ti extends dt{constructor(t,e=t){super(H("stop",t),e)}update(t){return(typeof t=="number"||t instanceof k)&&(t={offset:arguments[0],color:arguments[1],opacity:arguments[2]}),t.opacity!=null&&this.attr("stop-opacity",t.opacity),t.color!=null&&this.attr("stop-color",t.color),t.offset!=null&&this.attr("offset",new k(t.offset)),this}}T({Gradient:{stop:function(s,t,e){return this.put(new Ti).update(s,t,e)}}});N(Ti,"Stop");function Na(s,t){if(!s)return"";if(!t)return s;let e=s+"{";for(const n in t)e+=Sr(n)+":"+t[n]+";";return e+="}",e}class Dn extends dt{constructor(t,e=t){super(H("style",t),e)}addText(t=""){return this.node.textContent+=t,this}font(t,e,n={}){return this.rule("@font-face",{fontFamily:t,src:e,...n})}rule(t,e){return this.addText(Na(t,e))}}T("Dom",{style(s,t){return this.put(new Dn).rule(s,t)},fontface(s,t,e){return this.put(new Dn).font(s,t,e)}});N(Dn,"Style");class us extends F{constructor(t,e=t){super(H("textPath",t),e)}array(){const t=this.track();return t?t.array():null}plot(t){const e=this.track();let n=null;return e&&(n=e.plot(t)),t==null?n:this}track(){return this.reference("href")}}T({Container:{textPath:R(function(s,t){return s instanceof F||(s=this.text(s)),s.path(t)})},Text:{path:R(function(s,t=!0){const e=new us;s instanceof he||(s=this.defs().path(s)),e.attr("href","#"+s,Oe);let n;if(t)for(;n=this.node.firstChild;)e.node.appendChild(n);return this.put(e)}),textPath(){return this.findOne("textPath")}},Path:{text:R(function(s){return s instanceof F||(s=new F().addTo(this.parent()).text(s)),s.path(this)}),targets(){return ce("svg textPath").filter(s=>(s.attr("href")||"").includes(this.id()))}}});us.prototype.MorphArray=Wt;N(us,"TextPath");class on extends et{constructor(t,e=t){super(H("use",t),e)}use(t,e){return this.attr("href",(e||"")+"#"+t,Oe)}}T({Container:{use:R(function(s,t){return this.put(new on).use(s,t)})}});N(on,"Use");I([hs,sn,Ne,be,Fe],X("viewbox"));I([Se,Ce,De,he],X("marker"));I(F,X("Text"));I(he,X("Path"));I(ss,X("Defs"));I([F,rn],X("Tspan"));I([Re,nn,Ee,tt],X("radius"));I(Ie,X("EventTarget"));I(xt,X("Dom"));I(dt,X("Element"));I(et,X("Shape"));I([J,mi],X("Container"));I(Ee,X("Gradient"));I(tt,X("Runner"));$t.extend(_r());Jo([k,D,L,A,Qt,kt,Wt,B]);Vo();class te{constructor(t={}){b(this,"tileWidth");b(this,"tileHeight");b(this,"imageHostPath");b(this,"imageHostUrl");b(this,"imageExt");b(this,"scale");b(this,"svgSprite");this.scale=t.scale??1,this.imageHostPath=t.imageHostPath??"",this.imageHostUrl=t.imageHostUrl??"",this.imageExt=t.imageExt??"svg",this.tileWidth=vt.WIDTH*this.scale,this.tileHeight=vt.HEIGHT*this.scale,this.svgSprite=t.svgSprite??!1}getDiffTileHeightWidth(t){const e=t.imageSize(this.scale);return(e.baseHeight-e.baseWidth)/2}image(t){let e=new Ne().load(this.buildURL(t));return this.svgSprite&&(e=new on().use(te.buildID(t))),t instanceof g&&t.has(v.COLOR_GRAYSCALE)&&e.css({filter:"contrast(65%)"}),e}createImage(t,e,n){const i=t.imageSize(this.scale);return this.image(t).dx(e).dy(n).size(i.baseWidth,i.baseHeight)}createTextImage(t,e,n,i){const r=this.createImage(t,e,n),o=t.imageSize(this.scale),a=o.baseHeight*.2,c=o.baseWidth,h=o.baseHeight,l=new F().text(i);l.size(o.baseWidth,o.baseHeight).font({family:qn,size:a}).dx(c).dy(h);const u=new z;return u.add(r).add(l).translate(e,n),u}createRotate90Image(t,e,n,i=!1){const r=this.createImage(t,0,0),o=t.imageSize(this.scale),a=o.baseWidth/2,c=o.baseHeight/2,h=e+this.getDiffTileHeightWidth(t),l=i?n-this.getDiffTileHeightWidth(t):n,u=new z;return u.add(r).translate(h,l).rotate(90,a,c),u}createStick(t){return this.image(t)}static buildID(t){if(t==100||t==1e3)return t==100?"stick100":"stick1000";const e=t.t==d.BACK?0:t.n;return`${t.t}${e}`}buildURL(t){const e=`${te.buildID(t)}.${this.imageExt}`;return this.imageHostUrl!=""?`${this.imageHostUrl}${e}`:`${this.imageHostPath}${e}`}}class fs extends te{constructor(){super(...arguments);b(this,"blockMargin",vt.WIDTH*vt.BLOCK_MARGIN_SCALE*this.scale)}createBlockHandDiscard(e){const n=new z;let i=0;for(let r of e.tiles){const o=r.imageSize(this.scale),a=r.has(v.HORIZONTAL)?this.createRotate90Image.bind(this):this.createImage.bind(this),c=r.has(v.HORIZONTAL)?this.getDiffTileHeightWidth(r):0,h=a(r,i,c);n.add(h),i+=o.width}return n}createBlockPonChiKan(e){const n=e.tiles.findIndex(o=>o.has(v.HORIZONTAL));let i=0;const r=new z;if(e.type==_.SHO_KAN){let o=n;for(let a=0;a<e.tiles.length;a++)e.tiles[a].has(v.HORIZONTAL)&&(o=a);for(let a=0;a<e.tiles.length;a++){const c=e.tiles[a].imageSize(this.scale);if(a==o)continue;if(a==n){const u=e.tiles[n],f=e.tiles[o],m=u.imageSize(this.scale),p=this.createRotate90Image(u,0,0,!0),y=this.createRotate90Image(f,0,m.height,!0);r.add(new z().translate(i,0).add(p).add(y)),i+=m.width;continue}const h=c.width*2-c.height,l=this.createImage(e.tiles[a],i,h);i+=c.width,r.add(l)}return r}if(e.type==_.CHI){const o=this.createRotate90Image(e.tiles[n],i,this.getDiffTileHeightWidth(e.tiles[n]));i+=e.tiles[n].imageSize(this.scale).width,r.add(o);for(let a=0;a<e.tiles.length;a++){if(a==n)continue;const c=e.tiles[a].imageSize(this.scale),h=this.createImage(e.tiles[a],i,0);i+=c.width,r.add(h)}return r}for(let o=0;o<e.tiles.length;o++){const a=o==n?this.createRotate90Image.bind(this):this.createImage.bind(this),c=o==n?this.getDiffTileHeightWidth(e.tiles[o]):0,h=e.tiles[o].imageSize(this.scale),l=a(e.tiles[o],i,c);i+=h.width,r.add(l)}return r}}const Ma=s=>{const t=s.scale;return{[_.CHI]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.PON]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.DAI_KAN]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.SHO_KAN]:function(n){const i=n.imageSize(t),r=s.createBlockPonChiKan(n);return{...i,e:r}},[_.AN_KAN]:function(n){assert(n instanceof U,`block type is not ankan: ${n.type}`);const i=n.imageSize(t),r=n.tilesWithBack.filter(a=>a.t!==d.BACK);assert(r!=null&&r.length==2,`back tile must be two but ${n}`);const o=s.createBlockHandDiscard(new U([r[0],r[1],r[0],r[1]]));return{...i,e:o}},[_.IMAGE_DORA]:function(n){const i=n.imageSize(t),r=new z,o=s.createTextImage(n.tiles[0],0,0,"(ドラ)");return r.add(o),{...i,e:r}},[_.TSUMO]:function(n){const i=n.imageSize(t),r=new z,o=s.createTextImage(n.tiles[0],0,0,"(ツモ)");return r.add(o),{...i,e:r}},[_.HAND]:function(n){const i=n.imageSize(t),r=s.createBlockHandDiscard(n);return{...i,e:r}},[_.IMAGE_DISCARD]:function(n){const i=n.imageSize(t),r=s.createBlockHandDiscard(n);return{...i,e:r}},[_.THREE]:function(n){throw new Error("three is unsupported")},[_.RUN]:function(n){throw new Error("run is unsupported")},[_.UNKNOWN]:function(n){throw new Error("found unknown block")},[_.PAIR]:function(n){throw new Error("pair is unsupported")},[_.ISOLATED]:function(n){throw new Error("isolated is unsupported")}}},Xt=(s,t)=>{const{maxHeight:e,sumWidth:n}=t.reduce((l,u)=>{const f=u.imageSize(s.scale);return{maxHeight:f.height>l.maxHeight?f.height:l.maxHeight,sumWidth:l.sumWidth+f.width}},{maxHeight:0,sumWidth:0}),i=e,r=n+(t.length-1)*s.blockMargin,o=Ma(s),a=[];for(let l of t){const u=o[l.type],f=u(l);a.push(f)}const c=new z;let h=0;for(let l of a){const u=i-l.height,f=new z().translate(h,u);f.add(l.e),c.add(f),h+=l.width+s.blockMargin}return{e:c,width:r,height:i}},Da=(s,t,e={},n={responsive:!1})=>{const i=new fs(e),r=Xt(i,t);n.responsive||s.size(r.width,r.height),s.viewbox(0,0,r.width,r.height),s.add(r.e)},Oi=()=>{const s=[0,1,2,3,4,5,6,7,8,9],t=[];for(let e of Object.values(d)){if(e==d.BACK){t.push(te.buildID(new g(e,0)));continue}t.push(...s.map(n=>te.buildID(new g(e,n))).flat())}return t},Ca=s=>{const t=Oi(),e=[];return s.each((n,i)=>{const r=i[n];if(r instanceof on){const a=r.attr("href").substring(1);t.includes(a)&&e.push(a)}}),e},Ra=s=>{const t=Oi(),e=Ca(s);s.each((n,i)=>{const r=i[n];r instanceof sn&&(t.includes(r.id())&&e.includes(r.id())||r.remove())},!0)},Ha=s=>{const e=[];for(let n=0;n<s.length;n+=6){const i=s.slice(n,n+6);e.push(i)}return e},ht=(s,t,e,n,i=0,r=0)=>{const o=new z().add(s);if(n==90){const a=i,c=r-e;return o.rotate(n,0,e).translate(a,c),o}if(n==180){const a=i+t,c=r-e;return o.rotate(n,0,e).translate(a,c),o}if(n==270){const a=i+e,c=r+(t-e);return o.rotate(n,0,e).translate(a,c),o}return o},ze=(s,t)=>{const e=new z,n=Ha(s);for(let i=0;i<n.length;i++){let r=n[i],o=i*t.tileHeight;const a=t.createBlockHandDiscard(new Xn(r,_.IMAGE_DISCARD)).translate(0,o);e.add(a)}return{e,width:t.tileWidth*5+t.tileHeight*1,height:t.tileHeight*n.length}},$a=(s,t,e)=>{const n=t.font,i=t.textWidth,r=t.textHeight,o=new z,a=e.sticks.dead,c=e.sticks.reach,h=125*s.scale,l=27.5*s.scale;let u=i*3,f=r;const m=(h+s.tileWidth+i-u)/2,p=new F().plain(e.round).font(n).move(m,0);o.add(p),f+=25*s.scale;const y=s.tileHeight,w=new z().size(h,y).translate(0,f),x={family:n.family,size:n.size*.7},O=s.createStick(1e3).size(h,l).move(0,0),$=new F().plain(c.toString()).font(x).attr({x:h,y:l});w.add(O),w.add($);const nt=s.createStick(100).size(h,l).move(0,l+l),K=new F().plain(a.toString()).font(x).attr({x:h,y:l*3});w.add(nt),w.add(K);const rt=s.createImage(e.doras[0],0,0).move(h+i,0);return w.add(rt),o.add(p),o.add(w),{e:o,width:h+s.tileWidth+i,height:f+s.tileHeight}},Wa=(s,t,e=0)=>{const n=Xt(s,t.front),i=Xt(s,t.right),r=Xt(s,t.opposite),o=Xt(s,t.left),a=[n.width,i.width,r.width,o.width].reduce((y,w)=>Math.max(y,w)),c=Math.max(e+s.tileHeight*2+s.blockMargin*2,a+s.tileWidth*2+s.blockMargin),h=c,l=new z().size(c,h),u=ht(n.e,n.width,n.height,0).translate((c-n.width)/2,h-n.height),f=ht(i.e,i.width,i.height,270).translate(c-i.height,(c-i.width)/2),m=ht(r.e,r.width,r.height,180).translate((c-r.width)/2,0),p=ht(o.e,o.width,o.height,90).translate(0,(c-o.width)/2);return l.add(u),l.add(f),l.add(m),l.add(p),{e:l,width:c,height:h}},Ba=s=>{const t=Object.values(tn),e=t.indexOf(s);return[...t.slice(e),...t.slice(0,e)]},za=(s,t,e)=>{const n=s.tileWidth*5+s.tileHeight*1,i=new z,r=new Re().size(n,n).move(0,0).fill("none").stroke("#000000");i.add(r);const o=t.font,a=t.textWidth,c=t.textHeight,h=t.numWidth,l=$a(s,t,e);l.e.translate(n/2-l.width/2,n/2-l.height/2);const u=(cn,Ts,ar)=>{const cr=`${cn} ${Ts}`,hr=new F().plain(cr).font(o).attr(ar);return{e:new z().add(hr),width:a+h*Ts.toString().length,height:c}},[f,m,p,y]=Ba(e.frontPlace),w=e.scores,O=u(f,w.front,{x:n/2,y:n,"dominant-baseline":"text-after-edge","text-anchor":"middle"}).e;let $=u(m,w.right,{"dominant-baseline":"text-after-edge","text-anchor":"middle"});const nt=ht($.e,$.width,$.height,270).translate(n,n/2-$.width);let K=u(p,w.opposite,{"text-anchor":"middle","dominant-baseline":"text-after-edge"});const rt=ht(K.e,K.width,K.height,180).translate(n/2-K.width,-K.height);let pt=u(y,w.left,{"dominant-baseline":"ideographic","text-anchor":"middle"});const Kt=ht(pt.e,pt.width,pt.height,90).translate(-pt.height,n/2);return i.add(l.e),i.add(O),i.add(nt),i.add(rt),i.add(Kt),{e:i,width:n,height:n}},Pa=(s,t)=>{const e=ze(t.front,s),n=ze(t.right,s),i=ze(t.opposite,s),r=ze(t.left,s),o=[e.height,n.height,i.height,r.height].reduce((O,$)=>Math.max(O,$)),a=s.tileWidth*5+s.tileHeight*1,c=o,h=a+o*2+s.blockMargin,l=h,u=new z().size(h,l),f=h/2-a/2,m=l/2-a/2,p=ht(e.e,a,c,0).translate(f,l-c),y=ht(n.e,a,c,270).translate(h-c,m),w=ht(i.e,a,c,180).translate(f,0),x=ht(r.e,a,c,90).translate(0,m);return u.add(p),u.add(y),u.add(w),u.add(x),{e:u,width:h,height:l}},Ii=(s,t,e,n,i)=>{const r=new z,o=Pa(s,n),a=Wa(s,e,o.height),c=za(s,t,i);return o.e.translate((a.width-o.width)/2,(a.height-o.height)/2),c.e.translate((a.width-c.width)/2,(a.height-c.height)/2),r.add(a.e),r.add(o.e),r.add(c.e),{e:r,width:a.width,height:a.height}},ja=(s,t,e={},n,i={responsive:!1})=>{const r=new fs(e),o=n,{discards:a,hands:c,scoreBoard:h}=Ei(t),l=Ii(r,o,c,a,h);i.responsive||s.size(l.width,l.height),s.viewbox(0,0,l.width,l.height),s.add(l.e)};var mt;function La(s){return{lang:(s==null?void 0:s.lang)??(mt==null?void 0:mt.lang),message:s==null?void 0:s.message,abortEarly:(s==null?void 0:s.abortEarly)??(mt==null?void 0:mt.abortEarly),abortPipeEarly:(s==null?void 0:s.abortPipeEarly)??(mt==null?void 0:mt.abortPipeEarly)}}var mn;function Ka(s){return mn==null?void 0:mn.get(s)}var gn;function Ua(s){return gn==null?void 0:gn.get(s)}var yn;function Fa(s,t){var e;return(e=yn==null?void 0:yn.get(s))==null?void 0:e.get(t)}function ee(s){var e,n;const t=typeof s;return t==="string"?`"${s}"`:t==="number"||t==="bigint"||t==="boolean"?`${s}`:t==="object"||t==="function"?(s&&((n=(e=Object.getPrototypeOf(s))==null?void 0:e.constructor)==null?void 0:n.name))??"null":t}function Bt(s,t,e,n,i){const r=i&&"input"in i?i.input:e.value,o=(i==null?void 0:i.expected)??s.expects??null,a=(i==null?void 0:i.received)??ee(r),c={kind:s.kind,type:s.type,input:r,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:s.requirement,path:i==null?void 0:i.path,issues:i==null?void 0:i.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},h=s.kind==="schema",l=(i==null?void 0:i.message)??s.message??Fa(s.reference,c.lang)??(h?Ua(c.lang):null)??n.message??Ka(c.lang);l&&(c.message=typeof l=="function"?l(c):l),h&&(e.typed=!1),e.issues?e.issues.push(c):e.issues=[c]}function qa(s,t){const e=[...new Set(s)];return e.length>1?`(${e.join(` ${t} `)})`:e[0]??"never"}function Cn(s,t){return{kind:"validation",type:"max_value",reference:Cn,async:!1,expects:`<=${s instanceof Date?s.toJSON():ee(s)}`,requirement:s,message:t,_run(e,n){return e.typed&&e.value>this.requirement&&Bt(this,"value",e,n,{received:e.value instanceof Date?e.value.toJSON():ee(e.value)}),e}}}function Rn(s,t){return{kind:"validation",type:"min_value",reference:Rn,async:!1,expects:`>=${s instanceof Date?s.toJSON():ee(s)}`,requirement:s,message:t,_run(e,n){return e.typed&&e.value<this.requirement&&Bt(this,"value",e,n,{received:e.value instanceof Date?e.value.toJSON():ee(e.value)}),e}}}function Za(s,t,e){return typeof s.default=="function"?s.default(t,e):s.default}function Ye(s){return{kind:"schema",type:"number",reference:Ye,expects:"number",async:!1,message:s,_run(t,e){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:Bt(this,"type",t,e),t}}}function it(s,...t){const e={kind:"schema",type:"optional",reference:it,expects:`(${s.expects} | undefined)`,async:!1,wrapped:s,_run(n,i){return n.value===void 0&&("default"in this&&(n.value=Za(this,n,i)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,i)}};return 0 in t&&(e.default=t[0]),e}function Hn(s,t){return{kind:"schema",type:"picklist",reference:Hn,expects:qa(s.map(ee),"|"),async:!1,options:s,message:t,_run(e,n){return this.options.includes(e.value)?e.typed=!0:Bt(this,"type",e,n),e}}}function ne(s,t){return{kind:"schema",type:"strict_object",reference:ne,expects:"Object",async:!1,entries:s,message:t,_run(e,n){var r;const i=e.value;if(i&&typeof i=="object"){e.typed=!0,e.value={};for(const o in this.entries){const a=i[o],c=this.entries[o]._run({typed:!1,value:a},n);if(c.issues){const h={type:"object",origin:"value",input:i,key:o,value:a};for(const l of c.issues)l.path?l.path.unshift(h):l.path=[h],(r=e.issues)==null||r.push(l);if(e.issues||(e.issues=c.issues),n.abortEarly){e.typed=!1;break}}c.typed||(e.typed=!1),(c.value!==void 0||o in i)&&(e.value[o]=c.value)}if(!e.issues||!n.abortEarly){for(const o in i)if(!(o in this.entries)){const a=i[o];Bt(this,"type",e,n,{input:a,expected:"never",path:[{type:"object",origin:"value",input:i,key:o,value:a}]});break}}}else Bt(this,"type",e,n);return e}}}function Xe(s){return{kind:"schema",type:"string",reference:Xe,expects:"string",async:!1,message:s,_run(t,e){return typeof t.value=="string"?t.typed=!0:Bt(this,"type",t,e),t}}}function Hs(...s){return{...s[0],pipe:s,_run(t,e){for(const n of s)if(n.kind!=="metadata"){if(t.issues&&(n.kind==="schema"||n.kind==="transformation")){t.typed=!1;break}(!t.issues||!e.abortEarly&&!e.abortPipeEarly)&&(t=n._run(t,e))}return t}}}function Ga(s,t,e){const n=s._run({typed:!1,value:t},La(e));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}const Pe=it(ne({discard:it(Xe(),""),hand:it(Xe(),""),score:it(Ye(),25e3)}),{discard:"",hand:"",score:25e3}),Ya=ne({[S.E]:Pe,[S.S]:Pe,[S.W]:Pe,[S.N]:Pe}),Ot={round:P.E1,sticks:{reach:0,dead:0},doras:S.S,front:S.E},Xa=it(ne({round:it(Hn(Object.keys(Zn)),Ot.round),sticks:it(ne({reach:it(Hs(Ye(),Rn(0,""),Cn(9,"")),Ot.sticks.reach),dead:it(Hs(Ye(),Rn(0,""),Cn(9,"")),Ot.sticks.dead)}),Ot.sticks),doras:it(Xe(),Ot.doras),front:it(Hn(Object.keys(tn)),Ot.front)}),Ot),Ja=ne({...Ya.entries,board:Xa}),Ei=s=>{const t=Ni(s);return Mi(t)},Ni=s=>{const t=Va(s),e=Ga(Ja,t);if(!e.success)throw e.issues;return e.output},Va=s=>{const t="table",e="board",n=s.split(`
|
|
7
7
|
`).map(a=>a.trim()).filter(a=>a!="");if(n.length==0)throw new Error("empty input");const i=n.shift();if(!i.startsWith(t))throw new Error(`input does not start with table: ${i}`);const r={};let o=[S.E,S.S,S.W,S.N,e];for(;;){const a=n.shift();if(a==null)break;const c=o.find(h=>a.startsWith(h));if(c==null)throw new Error(`encountered unexpected line ${a}`);if(o=o.filter(h=>!a.startsWith(h)),c==e){const[h,l]=tc([...n]);r.board=h;for(let u=0;u<l;u++)n.shift()}else{const[h,l]=Qa([...n]);r[c]=h;for(let u=0;u<l;u++)n.shift()}}return r},lt=(s,t)=>s.replace(t,"").replace(":","").trim(),Qa=s=>{const t="hand",e="discard",n="score";let i={},r=0;for(;r<s.length;r++){const o=s[r];if(o.startsWith(t))i.hand=lt(o,t);else if(o.startsWith(e))i.discard=lt(o,e);else if(o.startsWith(n))i.score=Number(lt(o,n));else break}return[i,r]},tc=s=>{const t="doras",e="round",n="front",i="sticks",r="reach",o="dead";let a={},c=0;for(;c<s.length;c++){const h=s[c];if(h.startsWith(t))a.doras=lt(h,t);else if(h.startsWith(e))a.round=lt(h,e);else if(h.startsWith(n))a.front=lt(h,n);else if(h.startsWith(i)){a.sticks={};const l=s[c+1]??"",u=s[c+2]??"";l.startsWith(r)&&(a.sticks.reach=Number(lt(l,r))),l.startsWith(o)&&(a.sticks.dead=Number(lt(l,o))),u.startsWith(r)&&(a.sticks.reach=Number(lt(u,r))),u.startsWith(o)&&(a.sticks.dead=Number(lt(u,o))),a.sticks.dead!=null&&c++,a.sticks.reach!=null&&c++}else break}return[a,c]},Mi=s=>{const t=s.board.front,e=ec(t),n=a=>s[a].discard.replace(/\r?\n/g,""),i={front:new Q(n(e.front)).tiles(),right:new Q(n(e.right)).tiles(),opposite:new Q(n(e.opposite)).tiles(),left:new Q(n(e.left)).tiles()},r={front:new Q(s[e.front].hand).parse(),right:new Q(s[e.right].hand).parse(),opposite:new Q(s[e.opposite].hand).parse(),left:new Q(s[e.left].hand).parse()},o={round:Zn[s.board.round],frontPlace:tn[t],sticks:s.board.sticks,doras:new Q(s.board.doras).tiles(),scores:{front:s[e.front].score,right:s[e.right].score,opposite:s[e.opposite].score,left:s[e.left].score}};return{discards:i,hands:r,scoreBoard:o}},ec=s=>({front:s,right:At(s),opposite:At(At(s)),left:Xs(s)});class He{constructor(t,e=!1){b(this,"data");this.data={[d.M]:[0,0,0,0,0,0,0,0,0,0],[d.P]:[0,0,0,0,0,0,0,0,0,0],[d.S]:[0,0,0,0,0,0,0,0,0,0],[d.Z]:[0,0,0,0,0,0,0,0],[d.BACK]:["untouchable",0],called:[],reached:!1,tsumo:null},this.init(t,e)}init(t,e){const n=new Q(t).parse();for(let i of n){if(i.isCalled()){this.data.called=[...this.called,i];continue}else if(i.is(_.TSUMO)){const r=i.tiles[0];this.inc([r]),this.data.tsumo=r;continue}else if(i.is(_.HAND)){this.inc(i.tiles);continue}else if(t.split("").every(r=>r===d.BACK)){this.inc(i.tiles);continue}else if(e){this.inc(i.tiles);continue}throw new Error(`unexpected block ${i.type} ${i.toString()}`)}}get hands(){const t=[];for(let e of Object.values(d))for(let n=1;n<this.getArrayLen(e);n++){let i=this.get(e,n);e!=d.Z&&n==5&&this.get(e,0)>0&&(i-=this.get(e,0),t.push(new g(e,0)));for(let r=0;r<i;r++)t.push(new g(e,n))}if(this.drawn!=null){const e=this.drawn,n=t.findIndex(i=>i.equals(e));C(n>=0,`hand has drawn: ${this.drawn} but no tile in hands: ${t.join("")}`),t[n]=t[n].clone({add:v.TSUMO})}return C(t.length>0,`no tiles in hand ${t.length}, called: ${this.called}, data: ${JSON.stringify(this.data,null,2)}`),t}toString(){let t="";for(let r of this.called)t=`${t},${r.toString()}`;let e="";this.drawn&&(e=`,${this.drawn.toString()}`);const n=this.hands.filter(r=>!r.has(v.TSUMO));return`${new en(n).toString()}${e}${t}`}get called(){return this.data.called}get reached(){return this.data.reached}get drawn(){return this.data.tsumo}get menzen(){return!this.called.some(t=>!(t instanceof U))}getArrayLen(t){return this.data[t].length}sum(t){let e=0;for(let n=1;n<this.getArrayLen(t);n++)e+=this.get(t,n);return e}get(t,e){return t==d.BACK?this.data[t][1]:this.data[t][e]}inc(t){const e=[];for(let n of t){if(n.t!=d.BACK&&this.get(n.t,n.n)>=4)throw this.dec(e),new Error(`unable to increase ${n} in ${this.toString()}`);if(e.push(n),j(n)&&(this.data[n.t][5]+=1),n.t==d.BACK?this.data[n.t][1]+=1:this.data[n.t][n.n]+=1,V(n)&&this.get(n.t,5)==4&&this.get(n.t,0)==0){this.data[n.t][0]=1;const i=e.pop().clone({n:0});e.push(i)}}return e}dec(t){const e=[];for(let n of t){if(this.get(n.t,n.n)<1)throw this.inc(e),new Error(`unable to decrease ${n.toString()} in ${this.toString()}`);if(e.push(n),j(n)&&(this.data[n.t][5]-=1),n.t==d.BACK?this.data[n.t][1]-=1:this.data[n.t][n.n]-=1,V(n)&&this.get(n.t,5)==0&&this.get(n.t,0)>0){this.data[n.t][0]=0;const i=e.pop().clone({n:0});e.push(i)}}return e}draw(t){const e=t.clone({add:v.TSUMO});this.inc([e]),this.data.tsumo=e}discard(t){this.dec([t]),this.data.tsumo=null}reach(){if(!this.menzen)throw new Error("cannot reach");if(this.data.reached)throw new Error("already reached");this.data.reached=!0}call(t){if(!(t instanceof ft||t instanceof ct||t instanceof ut))throw new Error(`unexpected input ${t} ${t.type}`);const e=t.tiles.filter(n=>!n.has(v.HORIZONTAL));if(e.length!=t.tiles.length-1)throw new Error(`removal: ${e} block: ${t}`);this.dec(e),this.data.called=[...this.called,t],this.data.tsumo=null}kan(t){if(t instanceof U){let e=t.tiles[0];j(e)&&(e=new g(e.t,5)),this.dec([e,e,e,e]),this.data.called=[...this.called,t],this.data.tsumo=null;return}if(t instanceof at){const e=this.data.called.findIndex(i=>i.is(_.PON)&&i.tiles[0].equals(t.tiles[0],!0));if(e==-1)throw new Error(`unable to find ${t.tiles[0]}`);let n=t.tiles[0];j(n)&&(n=new g(n.t,5)),this.dec([n]),this.data.called=[...this.called.slice(0,e),...this.called.slice(e+1),t],this.data.tsumo=null;return}throw new Error(`unexpected input ${t}`)}clone(){const t=new He(this.toString());return t.data.reached=this.data.reached,t}}class $e{constructor(t){b(this,"hand");this.hand=t}calc(){return Math.min(this.sevenPairs(),this.thirteenOrphans(),this.fourSetsOnePair())}sevenPairs(){if(this.hand.called.length>0)return 1/0;let t=0,e=0;for(let n of Object.values(d))if(n!=d.BACK)for(let i=1;i<this.hand.getArrayLen(n);i++)this.hand.get(n,i)==2&&t++,this.hand.get(n,i)==1&&e++;return t>7&&(t=7),t+e>=7&&(e=7-t),13-2*t-e}thirteenOrphans(){if(this.hand.called.length>0)return 1/0;let t=0,e=0;for(let n of Object.values(d)){if(n==d.BACK)continue;const i=n==d.Z?Ae:yt;for(let r of i)this.hand.get(n,r)>=1&&t++,this.hand.get(n,r)>=2&&e++}return e>=1?12-t:13-t}fourSetsOnePair(){const t=n=>{const i=[0,0,0],r=d.Z;for(let m=1;m<this.hand.getArrayLen(r);m++)this.hand.get(r,m)>=3?i[0]++:this.hand.get(r,m)==2?i[1]++:this.hand.get(r,m)==1&&i[2]++;const o=[0,0,0],a=this.hand.get(d.BACK,0),c=a%3;o[0]=Math.floor(a/3),c==2&&(o[1]=1),c==1&&(o[2]=1);let h=13;const l=this.commonByType(d.M),u=this.commonByType(d.P),f=this.commonByType(d.S);for(let m of[l.patternA,l.patternB])for(let p of[u.patternA,u.patternB])for(let y of[f.patternA,f.patternB]){const w=[this.hand.called.length,0,0];for(let O=0;O<3;O++)w[O]+=m[O]+p[O]+y[O]+i[O]+o[O];let x=this.calcCommon(w[0],w[1],w[2],n);x<h&&(h=x)}return h};let e=t(!1);for(let n of Object.values(d))for(let i=1;i<this.hand.getArrayLen(n);i++)if(this.hand.get(n,i)>=2){const r=this.hand.dec([new g(n,i),new g(n,i)]),o=t(!0);this.hand.inc(r),o<e&&(e=o)}return e}commonByType(t,e=1){if(t==d.BACK||t==d.Z)throw new Error(`expect number type but ${t}`);if(e>9)return this.groupRemainingTiles(t);let n=this.commonByType(t,e+1);if(e<=7&&this.hand.get(t,e)>0&&this.hand.get(t,e+1)>0&&this.hand.get(t,e+2)>0){const i=this.hand.dec([new g(t,e),new g(t,e+1),new g(t,e+2)]),r=this.commonByType(t,e);this.hand.inc(i),r.patternA[0]++,r.patternB[0]++,(r.patternA[2]<n.patternA[2]||r.patternA[2]==n.patternA[2]&&r.patternA[1]<n.patternA[1])&&(n.patternA=r.patternA),(r.patternB[0]>n.patternB[0]||r.patternB[0]==n.patternB[0]&&r.patternB[1]>n.patternB[1])&&(n.patternB=r.patternB)}if(this.hand.get(t,e)>=3){const i=this.hand.dec([new g(t,e),new g(t,e),new g(t,e)]),r=this.commonByType(t,e);this.hand.inc(i),r.patternA[0]++,r.patternB[0]++,(r.patternA[2]<n.patternA[2]||r.patternA[2]==n.patternA[2]&&r.patternA[1]<n.patternA[1])&&(n.patternA=r.patternA),(r.patternB[0]>n.patternB[0]||r.patternB[0]==n.patternB[0]&&r.patternB[1]>n.patternB[1])&&(n.patternB=r.patternB)}return n}groupRemainingTiles(t){let e=0,n=0,i=0;for(let r=1;r<this.hand.getArrayLen(t);r++)i+=this.hand.get(t,r),r<=7&&this.hand.get(t,r+1)==0&&this.hand.get(t,r+2)==0&&(e+=i>>1,n+=i%2,i=0);return e+=i>>1,n+=i%2,{patternA:[0,e,n],patternB:[0,e,n]}}calcCommon(t,e,n,i){let r=i?4:5;return t>4&&(e+=t-4,t=4),t+e>4&&(n+=t+e-4,e=4-t),t+e+n>r&&(n=r-t-e),i&&e++,13-t*3-e*2-n}}class Di{constructor(t){b(this,"hand");this.hand=t}calc(t){return this.hand.drawn!=null&&(t=this.hand.drawn),this.markDrawn([...this.sevenPairs(),...this.thirteenOrphans(),...this.nineGates(),...this.fourSetsOnePair()],t)}markDrawn(t,e){if(t.length==0)return[];const n=this.hand.drawn!=null||e.has(v.TSUMO)?v.TSUMO:v.RON,i=[];for(let o=0;o<t.length;o++){const a=t[o],c={};for(let h=0;h<a.length;h++){const l=a[h];if(l.isCalled())continue;const u=l.tiles.findIndex(m=>m.equals(e,!0));if(u<0)continue;const f=Ci(l);c[f]||(c[f]=!0,i.push([o,h,u]))}}if(i.length==0)throw new Error(`found no tile ${e.toString()} in hands ${t[0].toString()}`);const r=[];for(let[o,a,c]of i){const l=t[o].map(m=>m.clone()),u=l[a],f=u.tiles[c].clone({add:n});l[a]=u.clone({replace:{idx:c,tile:f}}),r.push(l)}return r}sevenPairs(){if(this.hand.called.length>0)return[];const t=[];for(let e of Object.values(d))if(e!=d.BACK)for(let n=1;n<this.hand.getArrayLen(e);n++){const i=this.hand.get(e,n);if(i==2)t.push(new G(new g(e,n),new g(e,n)));else{if(i==0)continue;return[]}}return[t]}thirteenOrphans(){const t=[];let e="";for(let n of Object.values(d)){if(n==d.BACK)continue;const i=n==d.Z?Ae:yt;for(let r of i)if(this.hand.get(n,r)==1)t.push(new Yn(new g(n,r)));else if(this.hand.get(n,r)==2&&e=="")t.unshift(new G(new g(n,r),new g(n,r)));else return[]}return[t]}nineGates(){const t=(e,n,i)=>i.includes(this.hand.get(e,n));for(let e of Object.values(d)){if(e==d.BACK||e==d.Z)continue;const n=t(e,1,[3,4])&&t(e,9,[3,4])&&t(e,2,[1,2])&&t(e,3,[1,2])&&t(e,4,[1,2])&&t(e,5,[1,2])&&t(e,6,[1,2])&&t(e,7,[1,2])&&t(e,8,[1,2]),i=this.hand.sum(e)==14;if(n&&i)return[[new en(this.hand.hands)]]}return[]}fourSetsOnePair(){let t=[];for(let e of Object.values(d))for(let n=1;n<this.hand.getArrayLen(e);n++)if(this.hand.get(e,n)>=2){const i=this.hand.dec([new g(e,n),new g(e,n)]),r=this.commonAll().filter(o=>o.length==4).map(o=>(o.unshift(new G(i[0],i[1])),o));t=[...t,...r],this.hand.inc(i)}return t}commonAll(){const t=()=>{const r=[],o=d.Z;for(let a=1;a<this.hand.getArrayLen(o);a++)if(this.hand.get(o,a)!=0){if(this.hand.get(o,a)!=3)return[];r.push(new ot([new g(o,a),new g(o,a),new g(o,a)]))}return r.length==0?[]:[r]},e=()=>{const r=[],o=d.BACK,a=this.hand.get(o,0);return a<3?[]:(Array(Math.floor(a/3)).fill(void 0).map(c=>{r.push(new ot([new g(o,0),new g(o,0),new g(o,0)]))}),r.length==0?[]:[r])},n=[this.commonByType(d.M),this.commonByType(d.P),this.commonByType(d.S),t(),e(),[this.hand.called.concat()]].sort((r,o)=>o.length-r.length),i=n[0].concat();for(let r=0;r<i.length;r++)for(let o=1;o<n.length;o++)for(let a of n[o])i[r]=[...i[r],...a];return i}commonByType(t,e=1){if(e>9)return[];if(this.hand.get(t,e)==0)return this.commonByType(t,e+1);const n=[];if(e<=7&&this.hand.get(t,e)>0&&this.hand.get(t,e+1)>0&&this.hand.get(t,e+2)>0){const i=this.hand.dec([new g(t,e),new g(t,e+1),new g(t,e+2)]),r=this.commonByType(t,e);this.hand.inc(i),r.length==0&&r.push([]);for(let o of r)o.unshift(new bt([i[0],i[1],i[2]])),n.push(o)}if(this.hand.get(t,e)==3){const i=this.hand.dec([new g(t,e),new g(t,e),new g(t,e)]),r=this.commonByType(t,e);this.hand.inc(i),r.length==0&&r.push([]);for(let o of r)o.unshift(new ot([i[0],i[1],i[2]])),n.push(o)}return n}}const Ae=[1,2,3,4,5,6,7],yt=[1,9],Le=s=>{var e;const t=s.boardContext;return{...s,hand:s.hand.map(W.deserialize),boardContext:{...t,doraMarkers:t.doraMarkers.map(g.from),blindDoraMarkers:(e=t.blindDoraMarkers)==null?void 0:e.map(g.from)}}};class $n{constructor(t,e){b(this,"hand");b(this,"cfg");this.hand=t,this.cfg={doras:e.doraMarkers.map(n=>Ws(n)),blindDoras:e.blindDoraMarkers==null?[]:e.blindDoraMarkers.map(n=>Ws(n)),roundWind:g.from(e.round.substring(0,2)),myWind:g.from(e.myWind),reached:e.reached??0,sticks:e.sticks??{dead:0,reach:0},replacementWin:e.replacementWin??!1,quadWin:e.quadWin??!1,finalWallWin:e.finalWallWin??!1,finalDiscardWin:e.finalDiscardWin??!1,oneShotWin:e.oneShotWin??!1,orig:e}}calc(t){const e=this.calcPatterns(t);if(e.length==0)return!1;let n=[0,0],i=0;for(let p=0;p<e.length;p++){const y=e[p],w=y.points.reduce((x,O)=>x+O.double,0);(w>n[0]||w==n[0]&&y.fu>n[1])&&(i=p,n[0]=w,n[1]=y.fu)}const r=(p,y=100)=>Math.ceil(p/y)*y,o=n[1]!=25?r(n[1],10):25,a=n[0];let c=o*2**(a+2);switch(a){case 26:c=16e3;break;case 13:c=8e3;break;case 12:case 11:c=6e3;break;case 10:case 9:case 8:c=6e3;break;case 7:case 6:c=4e3;break;case 5:c=2e3;break}a>13&&a<26&&(c=8e3);const h=e[i].hand.some(p=>p.tiles.some(y=>y.has(v.TSUMO))),l=this.cfg.orig.myWind,u=l==S.E,f=Z(0);if(h){const p=this.cfg.sticks.dead*100;if(u){const y=r(c*2);f[S.E]+=y*3+p*3,f[S.S]-=y+p,f[S.W]-=y+p,f[S.N]-=y+p}else for(let y of Object.values(S)){if(y==l)continue;const w=y==S.E?2:1,x=r(c*w)+p;f[y]-=x,f[l]+=x}}else{const p=this.cfg.sticks.dead*300;if(this.cfg.orig.ronWind==null)throw new Error("ron wind is not specified in the parameters");const w=r(c*(u?6:4))+p;f[l]+=w,f[this.cfg.orig.ronWind]-=w}return f[l]+=1e3*this.cfg.sticks.reach,{deltas:f,sum:a,fu:o,points:e[i].points,point:f[l],hand:e[i].hand,boardContext:this.cfg.orig}}calcPatterns(t){const e=[];if(t.length==0)return e;for(let n of t){const i=[...this.dA13(n),...this.dB13(n),...this.dC13(n),...this.dD13(n),...this.dE13(n),...this.dF13(n),...this.dG13(n),...this.dH13(n),...this.dI13(n),...this.dJ13(n),...this.dK13(n)];i.length!=0&&e.push({points:i,fu:30,hand:n})}if(e.length>0)return e;for(let n of t){const i=this.calcFu(n),r=[...this.dA1(n),...this.dB1(n),...this.dC1(n),...this.dD1(n),...this.dE1(n),...this.dF1(n),...this.dG1(n),...this.dH1(n),...this.dI1(n),...this.dJ1(n),...this.dK1(n),...this.dA2(n),...this.dB2(n),...this.dC2(n),...this.dD2(n),...this.dE2(n),...this.dF2(n),...this.dG2(n),...this.dH2(n),...this.dI2(n),...this.dJ2(n),...this.dA3(n),...this.dB3(n),...this.dC3(n),...this.dA6(n)];r.length>0&&r.push(...this.dX1(n)),e.push({points:r,fu:i,hand:n})}return e}minus(){return this.hand.menzen?0:1}dA1(t){return this.cfg.reached==1?[{name:"立直",double:1}]:this.cfg.reached==2?[{name:"ダブルリーチ",double:2}]:[]}dB1(t){return this.minus()!=0?[]:(this.hand.drawn==null,t.some(n=>n.tiles.some(i=>i.has(v.TSUMO)))?[{name:"門前清自摸和",double:1}]:[])}dC1(t){if(this.minus()!=0)return[];const e="平和",n=this.calcFu(t);return n==20?[{name:e,double:1}]:!t.some(i=>i.tiles.some(r=>r.has(v.TSUMO)))&&n==30?[{name:e,double:1}]:[]}dD1(t){return t.some(n=>n.tiles.some(i=>i.t==d.Z||yt.includes(i.n)))?[]:[{name:"断么九",double:1}]}dE1(t){return this.minus()!=0?[]:$s(t)==1?[{name:"一盃口",double:1}]:[]}dF1(t){const e=[];return t.forEach(n=>{if(n instanceof G)return;const i=n.tiles[0];i.t==d.Z&&(i.equals(this.cfg.myWind)?e.push({name:"自風",double:1}):i.equals(this.cfg.roundWind)?e.push({name:"場風",double:1}):i.n==5?e.push({name:"白",double:1}):i.n==6?e.push({name:"發",double:1}):i.n==7&&e.push({name:"中",double:1}))}),e}dG1(t){return this.cfg.oneShotWin?[{name:"一発",double:1}]:[]}dH1(t){return this.cfg.replacementWin?[{name:"嶺上開花",double:1}]:[]}dI1(t){return this.cfg.quadWin?[{name:"搶槓",double:1}]:[]}dJ1(t){return this.cfg.finalWallWin?[{name:"海底摸月",double:1}]:[]}dK1(t){return this.cfg.finalDiscardWin?[{name:"河底撈魚",double:1}]:[]}dX1(t){let e=0,n=0,i=0;for(let o of t)for(let a of o.tiles){for(let c of this.cfg.doras)a.equals(c,!0)&&e++;for(let c of this.cfg.blindDoras)a.equals(c,!0)&&i++;j(a)&&n++}const r=[];return e>0&&r.push({name:"ドラ",double:e}),n>0&&r.push({name:"赤ドラ",double:n}),this.hand.reached&&i>0&&r.push({name:"裏ドラ",double:i}),r}dA2(t){return t.length==7?[{name:"七対子",double:2}]:[]}dB2(t){const e=n=>n instanceof bt||n instanceof ct;for(let n of t){if(!e(n))continue;const i=It(n);if(i.t==d.Z)continue;const r=[d.M,d.P,d.S].filter(c=>c!=i.t),o=t.some(c=>{const h=new g(r[0],i.n);return e(c)&&h.equals(It(c),!0)}),a=t.some(c=>{const h=new g(r[1],i.n);return e(c)&&h.equals(It(c),!0)});if(o&&a)return[{name:"三色同順",double:2-this.minus()}]}return[]}dC2(t){return t.length==7?[]:t.every(n=>n instanceof U||n instanceof at||n instanceof ut||n instanceof ot||n instanceof ft||n instanceof G)?[{name:"対々和",double:2}]:[]}dD2(t){return this.minus()!=0?[]:t.filter(n=>(n instanceof U||n instanceof ot)&&!n.tiles.some(i=>i.has(v.RON))).length>=3?[{name:"三暗刻",double:2}]:[]}dE2(t){return t.filter(n=>n instanceof U||n instanceof at||n instanceof ut).length>=3?[{name:"三槓子",double:2}]:[]}dF2(t){const e=n=>n instanceof U||n instanceof at||n instanceof ut||n instanceof ot||n instanceof ft;for(let n of t){if(!e(n))continue;const i=It(n);if(i.t==d.Z)continue;const r=[d.M,d.P,d.S].filter(c=>c!=i.t),o=t.some(c=>{const h=new g(r[0],i.n);return e(c)&&h.equals(It(c),!0)}),a=t.some(c=>{const h=new g(r[1],i.n);return e(c)&&h.equals(It(c),!0)});if(o&&a)return[{name:"三色同刻",double:2}]}return[]}dG2(t){return t.filter(n=>{const i=n.tiles[0];return i.t==d.Z&&[5,6,7].includes(i.n)}).length==3?[{name:"小三元",double:2}]:[]}dH2(t){return t.every(n=>{const i=n.tiles[0].t==d.Z?Ae:yt;return n.tiles.every(r=>i.includes(r.n))})?[{name:"混老頭",double:2}]:[]}dI2(t){return t.length==7?[]:t.some(n=>n instanceof bt||n instanceof ct)?t.some(n=>n.tiles[0].t==d.Z)?t.every(n=>{const i=n.tiles[0].t==d.Z?Ae:yt;return n.tiles.some(r=>i.includes(r.n))})?[{name:"混全帯么九",double:2-this.minus()}]:[]:[]:[]}dJ2(t){if(this.minus()!=0)return[];let e={[d.M]:[0,0,0],[d.S]:[0,0,0],[d.P]:[0,0,0]};for(let n of t){const i=It(n);i.t!=d.BACK&&i.t!=d.Z&&(n instanceof bt||n instanceof ct)&&(i.n==1&&e[i.t][0]++,i.n==4&&e[i.t][1]++,i.n==7&&e[i.t][2]++)}for(let n of Object.values(e))if(n.filter(i=>i>0).length==n.length)return[{name:"一気通貫",double:2-this.minus()}];return[]}dA3(t){if(!t.some(n=>n.tiles[0].t==d.Z))return[];for(let n of Object.values(d))if(t.every(r=>r.tiles[0].t==d.Z||r.tiles[0].t==n))return[{name:"混一色",double:3-this.minus()}];return[]}dB3(t){return t.length==7?[]:t.some(n=>n instanceof bt||n instanceof ct)?t.some(n=>n.tiles[0].t==d.Z)?[]:t.every(n=>n.tiles.some(i=>yt.includes(i.n)))?[{name:"純全帯么九色",double:3-this.minus()}]:[]:[]}dC3(t){return this.minus()!=0?[]:$s(t)==2?[{name:"ニ盃口",double:3}]:[]}dA6(t){if(t.some(e=>e.tiles[0].t==d.Z))return[];for(let e of Object.values(d)){if(e==d.Z)continue;if(t.every(i=>i.tiles[0].t==e))return[{name:"清一色",double:6-this.minus()}]}return[]}dA13(t){return t.length!=13?[]:t.some(n=>n instanceof G&&n.tiles.some(i=>i.has(v.TSUMO)||i.has(v.RON)))?[{name:"国士無双13面待ち",double:26}]:[{name:"国士無双",double:13}]}dB13(t){return t.length==1?[{name:"九蓮宝燈",double:13}]:[]}dC13(t){return t.length==7?[]:t.every(i=>i instanceof U||i instanceof ot&&!i.tiles.some(r=>r.has(v.RON))||i instanceof G)?t.some(i=>i instanceof G&&i.tiles.every(r=>r.has(v.TSUMO)||r.has(v.RON)))?[{name:"四暗刻単騎待ち",double:26}]:[{name:"四暗刻",double:13}]:[]}dD13(t){if(t.length==13)return[];const e=[5,6,7];return t.filter(i=>!(i instanceof G)&&i.tiles.some(r=>r.t==d.Z&&e.includes(r.n))).length==3?[{name:"大三元",double:13}]:[]}dE13(t){return t.every(n=>n.tiles[0].t==d.Z)?[{name:"字一色",double:13}]:[]}dF13(t){return t.every(n=>n.tiles.every(i=>i.t!=d.Z&&yt.includes(i.n)))?[{name:"清老頭",double:13}]:[]}dG13(t){return t.filter(n=>n instanceof U||n instanceof at||n instanceof ut).length==4?[{name:"四槓子",double:13}]:[]}dH13(t){if(t.length==13)return[];if(t.length==7)return[];const e=[1,2,3,4];return t.filter(r=>r.tiles.some(o=>o.t==d.Z&&e.includes(o.n))).length==4?t.find(r=>r instanceof G).tiles.some(r=>r.t==d.Z&&e.includes(r.n))?[{name:"小四喜",double:13}]:[{name:"大四喜",double:13}]:[]}dI13(t){const e=n=>!!(n.equals(new g(d.Z,6))||n.t==d.S&&[2,3,4,6,8].includes(n.n));return t.every(n=>n.tiles.every(i=>e(i)))?[{name:"緑一色",double:13}]:[]}dJ13(t){return[]}dK13(t){return[]}calcFu(t){let n=20;const i=this.cfg.myWind.n,r=this.cfg.roundWind.n;if(t.length==7)return 25;const o=t.find(p=>p.tiles.some(y=>y.has(v.TSUMO)||y.has(v.RON))),a=this.minus()==1,c=o.tiles.some(p=>p.has(v.TSUMO)),h=(p,y)=>{const w=p.tiles[0];return w.t==d.Z&&[5,6,7].includes(w.n)||w.t==d.Z&&[i,r].includes(w.n)||yt.includes(w.n)?y*2:y};for(let p of t)switch(!0){case p instanceof ot:let y=p.tiles.some(w=>w.has(v.RON))?2:4;n+=h(p,y);break;case p instanceof ft:n+=h(p,2);break;case(p instanceof ut||p instanceof at):n+=h(p,8);break;case p instanceof U:n+=h(p,16);break}n+=(p=>{if(p instanceof ot)return 0;if(p instanceof G)return 2;const y=p.tiles,w=y.findIndex(x=>x.has(v.TSUMO)||x.has(v.RON));return w==1||w==0&&y[2].n==9||w==2&&y[0].n==1?2:0})(o);let f=t.find(p=>p instanceof G).tiles[0];f.t==d.Z&&([5,6,7].includes(f.n)&&(n+=2),f.n==r&&(n+=2),f.n==i&&(n+=2));let m=!1;return!a&&n==20&&(m=!0),c&&!m&&(n+=2),!c&&!a&&(n+=10),!c&&!a&&n==30&&(m=!0),a&&n==20&&(n=30),n}}const Ci=s=>s.tiles.reduce((t,e)=>`${t}${e.n}${e.t}`,""),$s=s=>{let t={};for(let n of s){if(!(n instanceof bt))continue;const i=Ci(n);t[i]==null?t[i]=1:t[i]++}let e=0;for(let n in t)t[n]>=2&&e++;return e},It=s=>[...s.tiles].sort(ye)[0],Ws=s=>{let t=j(s)?5:s.n,e=s.t;return new g(e,t%9+1)};class zt{static calcCandidates(t,e,n=!1){C(e.length>0,"choices to discard is zero");const i=new Map;let r=Number.POSITIVE_INFINITY;for(let o of e){const a=t.dec([o]),c=zt.candidateTiles(t);t.inc(a);const h=j(o)&&n?new g(o.t,5).toString():new g(o.t,o.n).toString();c.shanten<r?(i.clear(),i.set(h,{shanten:c.shanten,candidates:c.candidates,tile:o}),r=c.shanten):c.shanten==r&&i.set(h,{shanten:c.shanten,candidates:c.candidates,tile:o})}return Array.from(i.values())}static candidateTiles(t){let e=Number.POSITIVE_INFINITY,n=[];const i=new $e(t);for(let r of Object.values(d))if(r!=d.BACK)for(let o=1;o<t.getArrayLen(r);o++){if(t.get(r,o)>=4)continue;const a=new g(r,o),c=t.inc([a]),h=i.calc();t.dec(c),h<e?(e=h,n=[a]):h==e&&n.push(a)}return{shanten:e,candidates:n}}static partialCandidateTiles(t){const e=new He(t,!0);return Array(13-e.hands.length).fill(void 0).map(()=>e.inc([new g(d.BACK,0)])),zt.candidateTiles(e)}}const Wn=()=>{const s=new Set;return{on(t){s.add(t)},off(t){s.delete(t)},offAll(){s.clear()},emit(t){s.forEach(e=>e(t))}}};function Ri(s){var r;const t=["RON","DAI_KAN","PON","CHI"],e=s.map(o=>o.choices),i=$i(e,t).map(o=>s[o]);return{events:i,type:Wi(t,(r=i[0])==null?void 0:r.choices)}}function Hi(s){var r;const t=["TSUMO","REACH","AN_KAN","SHO_KAN","DRAWN_GAME_BY_NINE_TILES","DISCARD"],e=s.map(o=>o.choices),i=$i(e,t).map(o=>s[o]);return{events:i,type:Wi(t,(r=i[0])==null?void 0:r.choices)}}function $i(s,t){let e=[],n=Number.POSITIVE_INFINITY;for(let i=0;i<s.length;i++){const r=s[i];if(nc(r,t)){const o=sc(t,r);o<n?(n=o,e=[i]):o===n&&e.push(i)}}return e}function nc(s,t){return t.some(e=>!!s[e])}function sc(s,t){for(let e=0;e<s.length;e++){const n=s[e];if(t[n])return e}return Number.POSITIVE_INFINITY}function Wi(s,t){if(t==null)return!1;for(const e of s)if(t[e])return e;return!1}const pe=()=>{const s=Wn(),t=Wn(),e={emit:s.emit,on:i=>t.on(i)},n={emit:t.emit,on:i=>s.on(i)};return[e,n]},Bi=()=>{const s=Wn();return{emit:n=>{s.emit(n)},on:n=>{s.on(n)}}};class xe{constructor(t){b(this,"reachValue",1e3);b(this,"m");this.m=t}get summary(){return structuredClone(this.m)}reach(t){this.m[t]-=this.reachValue}restoreReachStick(t){this.m[t]+=this.reachValue}update(t,e){for(let n in e){const i=e[n],r=t[i];this.m[n]+=r}}}class ke{constructor(t,e){b(this,"pToW",{});b(this,"wToP",Z(""));b(this,"round");b(this,"sticks");this.round=(e==null?void 0:e.round)??"1w1",this.sticks=(e==null?void 0:e.sticks)??{reach:0,dead:0},this.pToW=t;for(let n in this.pToW)this.wToP[this.pToW[n]]=n}update(){for(let t in this.pToW){const e=At(this.pToW[t]);this.pToW[t]=e,this.wToP[e]=t}}incrementDeadStick(){this.sticks.dead++}incrementReachStick(){this.sticks.reach++}nextRound(){const t=ge(this.round);this.round=t,this.update()}decrementReachStick(){this.sticks.reach--,C(this.sticks.reach>=0)}resetDeadStick(){this.sticks.dead=0}resetReachStick(){this.sticks.reach=0}is(t){return this.round==t}wind(t){return this.pToW[t]}playerID(t){return this.wToP[t]}get playerMap(){return structuredClone(this.pToW)}}function ds(s){for(let t=s.length-1;t>0;t--){const e=Math.floor(Math.random()*(t+1));[s[t],s[e]]=[s[e],s[t]]}return s}class zi{constructor(t=!1){b(this,"c",{[d.M]:[1,4,4,4,4,4,4,4,4,4],[d.S]:[1,4,4,4,4,4,4,4,4,4],[d.P]:[1,4,4,4,4,4,4,4,4,4],[d.Z]:[0,4,4,4,4,4,4,4]});b(this,"safeMap",Z({},!0));this.disable=t}get(t){return t.t==d.BACK?0:j(t)?this.c[t.t][5]:this.c[t.t][t.n]}dec(...t){if(!this.disable){for(let e of t)if(e.t!=d.BACK){if(this.get(e)<=0)throw new Error(`cannot decrease ${e.toString()} due to zero`);this.c[e.t][e.n]-=1,j(e)&&(this.c[e.t][5]-=1)}}}addTileToSafeMap(t,e){this.disable||(this.safeMap[e][this.key(t.t,t.n)]=!0)}isSafeTile(t,e,n){return this.safeMap[n][this.key(t,e)]}key(t,e){return e==0&&(e=5),`${t}${e}`}reset(){this.c={[d.M]:[1,4,4,4,4,4,4,4,4,4],[d.S]:[1,4,4,4,4,4,4,4,4,4],[d.P]:[1,4,4,4,4,4,4,4,4,4],[d.Z]:[0,4,4,4,4,4,4,4]}}}class ps{constructor(){b(this,"m",[])}discard(t,e){this.m.push({w:e,t})}get lastTile(){const t=this.m.at(-1);return C(t!=null,`lastTile is null(${t}). river: ${JSON.stringify(this.m,null,2)}`),t}discards(t){return t==null?[...this.m]:this.m.filter(e=>e.w==t)}markCalled(){this.lastTile.callMarker=!0}cannotContinue(){const t=this.discards();if(t.length!=4)return!1;let e=t[0].t;if(e.isNum())return!1;for(let n=0;n<4;n++)if(!e.equals(t[n].t))return!1;return!0}}function ic(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function rc(){const s=ic();if(s.__xstate__)return s.__xstate__}const oc=s=>{if(typeof window>"u")return;const t=rc();t&&t.register(s)};class Bs{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current){this._last.next=e,this._last=e;return}this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const Pi=".",ac="",ji="",cc="#",hc="*",Li="xstate.init",Bn="xstate.stop";function lc(s,t){return{type:`xstate.after.${s}.${t}`}}function zn(s,t){return{type:`xstate.done.state.${s}`,output:t}}function uc(s,t){return{type:`xstate.done.actor.${s}`,output:t,actorId:s}}function fc(s,t){return{type:`xstate.error.actor.${s}`,error:t,actorId:s}}function Ki(s){return{type:Li,input:s}}function gt(s){setTimeout(()=>{throw s})}const dc=typeof Symbol=="function"&&Symbol.observable||"@@observable";function Ui(s,t){const e=zs(s),n=zs(t);return typeof n=="string"?typeof e=="string"?n===e:!1:typeof e=="string"?e in n:Object.keys(e).every(i=>i in n?Ui(e[i],n[i]):!1)}function ms(s){if(qi(s))return s;let t=[],e="";for(let n=0;n<s.length;n++){switch(s.charCodeAt(n)){case 92:e+=s[n+1],n++;continue;case 46:t.push(e),e="";continue}e+=s[n]}return t.push(e),t}function zs(s){if(qc(s))return s.value;if(typeof s!="string")return s;const t=ms(s);return pc(t)}function pc(s){if(s.length===1)return s[0];const t={};let e=t;for(let n=0;n<s.length-1;n++)if(n===s.length-2)e[s[n]]=s[n+1];else{const i=e;e={},i[s[n]]=e}return t}function Ps(s,t){const e={},n=Object.keys(s);for(let i=0;i<n.length;i++){const r=n[i];e[r]=t(s[r],r,s,i)}return e}function Fi(s){return qi(s)?s:[s]}function St(s){return s===void 0?[]:Fi(s)}function Pn(s,t,e,n){return typeof s=="function"?s({context:t,event:e,self:n}):s}function qi(s){return Array.isArray(s)}function mc(s){return s.type.startsWith("xstate.error.actor")}function Zt(s){return Fi(s).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function Zi(s){if(!(s===void 0||s===ac))return St(s)}function jn(s,t,e){var r,o,a;const n=typeof s=="object",i=n?s:void 0;return{next:(r=n?s.next:s)==null?void 0:r.bind(i),error:(o=n?s.error:t)==null?void 0:o.bind(i),complete:(a=n?s.complete:e)==null?void 0:a.bind(i)}}function js(s,t){return`${t}.${s}`}function gs(s,t){const e=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!e)return s.implementations.actors[t];const[,n,i]=e,o=s.getStateNodeById(i).config.invoke;return(Array.isArray(o)?o[n]:o).src}function Ls(s,t){return`${s.sessionId}.${t}`}let gc=0;function yc(s,t){const e=new Map,n=new Map,i=new WeakMap,r=new Set,o={},{clock:a,logger:c}=t,h={schedule:(f,m,p,y,w=Math.random().toString(36).slice(2))=>{const x={source:f,target:m,event:p,delay:y,id:w,startedAt:Date.now()},O=Ls(f,w);u._snapshot._scheduledEvents[O]=x;const $=a.setTimeout(()=>{delete o[O],delete u._snapshot._scheduledEvents[O],u._relay(f,m,p)},y);o[O]=$},cancel:(f,m)=>{const p=Ls(f,m),y=o[p];delete o[p],delete u._snapshot._scheduledEvents[p],y!==void 0&&a.clearTimeout(y)},cancelAll:f=>{for(const m in u._snapshot._scheduledEvents){const p=u._snapshot._scheduledEvents[m];p.source===f&&h.cancel(f,p.id)}}},l=f=>{if(!r.size)return;const m={...f,rootId:s.sessionId};r.forEach(p=>{var y;return(y=p.next)==null?void 0:y.call(p,m)})},u={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${gc++}`,_register:(f,m)=>(e.set(f,m),f),_unregister:f=>{e.delete(f.sessionId);const m=i.get(f);m!==void 0&&(n.delete(m),i.delete(f))},get:f=>n.get(f),_set:(f,m)=>{const p=n.get(f);if(p&&p!==m)throw new Error(`Actor with system ID '${f}' already exists.`);n.set(f,m),i.set(m,f)},inspect:f=>{const m=jn(f);return r.add(m),{unsubscribe(){r.delete(m)}}},_sendInspectionEvent:l,_relay:(f,m,p)=>{u._sendInspectionEvent({type:"@xstate.event",sourceRef:f,actorRef:m,event:p}),m._send(p)},scheduler:h,getSnapshot:()=>({_scheduledEvents:{...u._snapshot._scheduledEvents}}),start:()=>{const f=u._snapshot._scheduledEvents;u._snapshot._scheduledEvents={};for(const m in f){const{source:p,target:y,event:w,delay:x,id:O}=f[m];h.schedule(p,y,w,x,O)}},_clock:a,_logger:c};return u}const ys=1;let q=function(s){return s[s.NotStarted=0]="NotStarted",s[s.Running=1]="Running",s[s.Stopped=2]="Stopped",s}({});const wc={clock:{setTimeout:(s,t)=>setTimeout(s,t),clearTimeout:s=>clearTimeout(s)},logger:console.log.bind(console),devTools:!1};class _c{constructor(t,e){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Bs(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=q.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...wc,...e},{clock:i,logger:r,parent:o,syncSnapshot:a,id:c,systemId:h,inspect:l}=n;this.system=o?o.system:yc(this,{clock:i,logger:r}),l&&!o&&this.system.inspect(jn(l)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=(e==null?void 0:e.logger)??this.system._logger,this.clock=(e==null?void 0:e.clock)??this.system._clock,this._parent=o,this._syncSnapshot=a,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:u=>{this._deferred.push(u)},system:this.system,stopChild:u=>{if(u._parent!==this)throw new Error(`Cannot stop child actor ${u.id} of ${this.id} because it is not a child`);u._stop()},emit:u=>{const f=this.eventListeners.get(u.type),m=this.eventListeners.get("*");if(!f&&!m)return;const p=new Set([...f?f.values():[],...m?m.values():[]]);for(const y of Array.from(p))y(u)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),h&&(this._systemId=h,this.system._set(h,this)),this._initState((e==null?void 0:e.snapshot)??(e==null?void 0:e.state)),h&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){var e;try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,(e=this.options)==null?void 0:e.input)}catch(n){this._snapshot={status:"error",output:void 0,error:n}}}update(t,e){var i,r;this._snapshot=t;let n;for(;n=this._deferred.shift();)try{n()}catch(o){this._deferred.length=0,this._snapshot={...t,status:"error",error:o}}switch(this._snapshot.status){case"active":for(const o of this.observers)try{(i=o.next)==null||i.call(o,t)}catch(a){gt(a)}break;case"done":for(const o of this.observers)try{(r=o.next)==null||r.call(o,t)}catch(a){gt(a)}this._stopProcedure(),this._complete(),this._doneEvent=uc(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,n){var r;const i=jn(t,e,n);if(this._processingStatus!==q.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{(r=i.complete)==null||r.call(i)}catch(o){gt(o)}break;case"error":{const o=this._snapshot.error;if(!i.error)gt(o);else try{i.error(o)}catch(a){gt(a)}break}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(t,e){let n=this.eventListeners.get(t);n||(n=new Set,this.eventListeners.set(t,n));const i=e.bind(void 0);return n.add(i),{unsubscribe:()=>{n.delete(i)}}}start(){if(this._processingStatus===q.Running)return this;this._syncSnapshot&&this.subscribe({next:n=>{n.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:n})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=q.Running;const t=Ki(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(n){return this._snapshot={...this._snapshot,status:"error",error:n},this._error(n),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(i){n={err:i}}if(n){const{err:i}=n;this._snapshot={...this._snapshot,status:"error",error:i},this._error(i);return}this.update(e,t),t.type===Bn&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===q.Stopped?this:(this.mailbox.clear(),this._processingStatus===q.NotStarted?(this._processingStatus=q.Stopped,this):(this.mailbox.enqueue({type:Bn}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var t;for(const e of this.observers)try{(t=e.complete)==null||t.call(e)}catch(n){gt(n)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||gt(t);return}let e=!1;for(const n of this.observers){const i=n.error;e||(e=!i);try{i==null||i(t)}catch(r){gt(r)}}this.observers.clear(),e&>(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,fc(this.id,t))}_stopProcedure(){return this._processingStatus!==q.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Bs(this._process.bind(this)),this._processingStatus=q.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==q.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:oc)(this)}toJSON(){return{xstate$$type:ys,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[dc](){return this}getSnapshot(){return this._snapshot}}function se(s,...[t]){return new _c(s,t)}function bc(s,t,e,n,{sendId:i}){const r=typeof i=="function"?i(e,n):i;return[t,r]}function Sc(s,t){s.defer(()=>{s.system.scheduler.cancel(s.self,t)})}function vc(s){function t(e,n){}return t.type="xstate.cancel",t.sendId=s,t.resolve=bc,t.execute=Sc,t}function Ac(s,t,e,n,{id:i,systemId:r,src:o,input:a,syncSnapshot:c}){const h=typeof o=="string"?gs(t.machine,o):o,l=typeof i=="function"?i(e):i;let u;return h&&(u=se(h,{id:l,src:o,parent:s.self,syncSnapshot:c,systemId:r,input:typeof a=="function"?a({context:t.context,event:e.event,self:s.self}):a})),[Pt(t,{children:{...t.children,[l]:u}}),{id:i,actorRef:u}]}function xc(s,{id:t,actorRef:e}){e&&s.defer(()=>{e._processingStatus!==q.Stopped&&e.start()})}function kc(...[s,{id:t,systemId:e,input:n,syncSnapshot:i=!1}={}]){function r(o,a){}return r.type="snapshot.spawnChild",r.id=t,r.systemId=e,r.src=s,r.input=n,r.syncSnapshot=i,r.resolve=Ac,r.execute=xc,r}function Tc(s,t,e,n,{actorRef:i}){const r=typeof i=="function"?i(e,n):i,o=typeof r=="string"?t.children[r]:r;let a=t.children;return o&&(a={...a},delete a[o.id]),[Pt(t,{children:a}),o]}function Oc(s,t){if(t){if(s.system._unregister(t),t._processingStatus!==q.Running){s.stopChild(t);return}s.defer(()=>{s.stopChild(t)})}}function Gi(s){function t(e,n){}return t.type="xstate.stopChild",t.actorRef=s,t.resolve=Tc,t.execute=Oc,t}function ws(s,t,e,n){const{machine:i}=n,r=typeof s=="function",o=r?s:i.implementations.guards[typeof s=="string"?s:s.type];if(!r&&!o)throw new Error(`Guard '${typeof s=="string"?s:s.type}' is not implemented.'.`);if(typeof o!="function")return ws(o,t,e,n);const a={context:t,event:e},c=r||typeof s=="string"?void 0:"params"in s?typeof s.params=="function"?s.params({context:t,event:e}):s.params:void 0;return"check"in o?o.check(n,a,o):o(a,c)}const _s=s=>s.type==="atomic"||s.type==="final";function ie(s){return Object.values(s.states).filter(t=>t.type!=="history")}function We(s,t){const e=[];if(t===s)return e;let n=s.parent;for(;n&&n!==t;)e.push(n),n=n.parent;return e}function Je(s){const t=new Set(s),e=Xi(t);for(const n of t)if(n.type==="compound"&&(!e.get(n)||!e.get(n).length))Ks(n).forEach(i=>t.add(i));else if(n.type==="parallel"){for(const i of ie(n))if(i.type!=="history"&&!t.has(i)){const r=Ks(i);for(const o of r)t.add(o)}}for(const n of t){let i=n.parent;for(;i;)t.add(i),i=i.parent}return t}function Yi(s,t){const e=t.get(s);if(!e)return{};if(s.type==="compound"){const i=e[0];if(i){if(_s(i))return i.key}else return{}}const n={};for(const i of e)n[i.key]=Yi(i,t);return n}function Xi(s){const t=new Map;for(const e of s)t.has(e)||t.set(e,[]),e.parent&&(t.has(e.parent)||t.set(e.parent,[]),t.get(e.parent).push(e));return t}function Ji(s,t){const e=Je(t);return Yi(s,Xi(e))}function bs(s,t){return t.type==="compound"?ie(t).some(e=>e.type==="final"&&s.has(e)):t.type==="parallel"?ie(t).every(e=>bs(s,e)):t.type==="final"}const an=s=>s[0]===cc;function Ic(s,t){return s.transitions.get(t)||[...s.transitions.keys()].filter(n=>{if(n===hc)return!0;if(!n.endsWith(".*"))return!1;const i=n.split("."),r=t.split(".");for(let o=0;o<i.length;o++){const a=i[o],c=r[o];if(a==="*")return o===i.length-1;if(a!==c)return!1}return!0}).sort((n,i)=>i.length-n.length).flatMap(n=>s.transitions.get(n))}function Ec(s){const t=s.config.after;if(!t)return[];const e=(i,r)=>{const o=lc(i,s.id),a=o.type;return s.entry.push(eh(o,{id:a,delay:i})),s.exit.push(vc(a)),a};return Object.keys(t).flatMap((i,r)=>{const o=t[i],a=typeof o=="string"?{target:o}:o,c=Number.isNaN(+i)?i:+i,h=e(c);return St(a).map(l=>({...l,event:h,delay:c}))}).map(i=>{const{delay:r}=i;return{...Dt(s,i.event,i),delay:r}})}function Dt(s,t,e){const n=Zi(e.target),i=e.reenter??!1,r=Dc(s,n),o={...e,actions:St(e.actions),guard:e.guard,target:r,source:s,reenter:i,eventType:t,toJSON:()=>({...o,source:`#${s.id}`,target:r?r.map(a=>`#${a.id}`):void 0})};return o}function Nc(s){const t=new Map;if(s.config.on)for(const e of Object.keys(s.config.on)){if(e===ji)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=s.config.on[e];t.set(e,Zt(n).map(i=>Dt(s,e,i)))}if(s.config.onDone){const e=`xstate.done.state.${s.id}`;t.set(e,Zt(s.config.onDone).map(n=>Dt(s,e,n)))}for(const e of s.invoke){if(e.onDone){const n=`xstate.done.actor.${e.id}`;t.set(n,Zt(e.onDone).map(i=>Dt(s,n,i)))}if(e.onError){const n=`xstate.error.actor.${e.id}`;t.set(n,Zt(e.onError).map(i=>Dt(s,n,i)))}if(e.onSnapshot){const n=`xstate.snapshot.${e.id}`;t.set(n,Zt(e.onSnapshot).map(i=>Dt(s,n,i)))}}for(const e of s.after){let n=t.get(e.eventType);n||(n=[],t.set(e.eventType,n)),n.push(e)}return t}function Mc(s,t){const e=typeof t=="string"?s.states[t]:t?s.states[t.target]:void 0;if(!e&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${s.id}`);const n={source:s,actions:!t||typeof t=="string"?[]:St(t.actions),eventType:null,reenter:!1,target:e?[e]:[],toJSON:()=>({...n,source:`#${s.id}`,target:e?[`#${e.id}`]:[]})};return n}function Dc(s,t){if(t!==void 0)return t.map(e=>{if(typeof e!="string")return e;if(an(e))return s.machine.getStateNodeById(e);const n=e[0]===Pi;if(n&&!s.parent)return Ve(s,e.slice(1));const i=n?s.key+e:e;if(s.parent)try{return Ve(s.parent,i)}catch(r){throw new Error(`Invalid transition definition for state node '${s.id}':
|
|
8
8
|
${r.message}`)}else throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`)})}function Vi(s){const t=Zi(s.config.target);return t?{target:t.map(e=>typeof e=="string"?Ve(s.parent,e):e)}:s.parent.initial}function Ct(s){return s.type==="history"}function Ks(s){const t=Qi(s);for(const e of t)for(const n of We(e,s))t.add(n);return t}function Qi(s){const t=new Set;function e(n){if(!t.has(n)){if(t.add(n),n.type==="compound")e(n.initial.target[0]);else if(n.type==="parallel")for(const i of ie(n))e(i)}}return e(s),t}function re(s,t){if(an(t))return s.machine.getStateNodeById(t);if(!s.states)throw new Error(`Unable to retrieve child state '${t}' from '${s.id}'; no child states exist.`);const e=s.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${s.id}'`);return e}function Ve(s,t){if(typeof t=="string"&&an(t))try{return s.machine.getStateNodeById(t)}catch{}const e=ms(t).slice();let n=s;for(;e.length;){const i=e.shift();if(!i.length)break;n=re(n,i)}return n}function Qe(s,t){if(typeof t=="string"){const i=s.states[t];if(!i)throw new Error(`State '${t}' does not exist on '${s.id}'`);return[s,i]}const e=Object.keys(t),n=e.map(i=>re(s,i)).filter(Boolean);return[s.machine.root,s].concat(n,e.reduce((i,r)=>{const o=re(s,r);if(!o)return i;const a=Qe(o,t[r]);return i.concat(a)},[]))}function Cc(s,t,e,n){const r=re(s,t).next(e,n);return!r||!r.length?s.next(e,n):r}function Rc(s,t,e,n){const i=Object.keys(t),r=re(s,i[0]),o=Ss(r,t[i[0]],e,n);return!o||!o.length?s.next(e,n):o}function Hc(s,t,e,n){const i=[];for(const r of Object.keys(t)){const o=t[r];if(!o)continue;const a=re(s,r),c=Ss(a,o,e,n);c&&i.push(...c)}return i.length?i:s.next(e,n)}function Ss(s,t,e,n){return typeof t=="string"?Cc(s,t,e,n):Object.keys(t).length===1?Rc(s,t,e,n):Hc(s,t,e,n)}function $c(s){return Object.keys(s.states).map(t=>s.states[t]).filter(t=>t.type==="history")}function Tt(s,t){let e=s;for(;e.parent&&e.parent!==t;)e=e.parent;return e.parent===t}function Wc(s,t){const e=new Set(s),n=new Set(t);for(const i of e)if(n.has(i))return!0;for(const i of n)if(e.has(i))return!0;return!1}function tr(s,t,e){const n=new Set;for(const i of s){let r=!1;const o=new Set;for(const a of n)if(Wc(Ln([i],t,e),Ln([a],t,e)))if(Tt(i.source,a.source))o.add(a);else{r=!0;break}if(!r){for(const a of o)n.delete(a);n.add(i)}}return Array.from(n)}function Bc(s){const[t,...e]=s;for(const n of We(t,void 0))if(e.every(i=>Tt(i,n)))return n}function vs(s,t){if(!s.target)return[];const e=new Set;for(const n of s.target)if(Ct(n))if(t[n.id])for(const i of t[n.id])e.add(i);else for(const i of vs(Vi(n),t))e.add(i);else e.add(n);return[...e]}function er(s,t){const e=vs(s,t);if(!e)return;if(!s.reenter&&e.every(i=>i===s.source||Tt(i,s.source)))return s.source;const n=Bc(e.concat(s.source));if(n)return n;if(!s.reenter)return s.source.machine.root}function Ln(s,t,e){var i;const n=new Set;for(const r of s)if((i=r.target)!=null&&i.length){const o=er(r,e);r.reenter&&r.source===o&&n.add(o);for(const a of t)Tt(a,o)&&n.add(a)}return[...n]}function zc(s,t){if(s.length!==t.size)return!1;for(const e of s)if(!t.has(e))return!1;return!0}function Kn(s,t,e,n,i,r){if(!s.length)return t;const o=new Set(t._nodes);let a=t.historyValue;const c=tr(s,o,a);let h=t;i||([h,a]=Kc(h,n,e,c,o,a,r)),h=oe(h,n,e,c.flatMap(u=>u.actions),r),h=jc(h,n,e,c,o,r,a,i);const l=[...o];h.status==="done"&&(h=oe(h,n,e,l.sort((u,f)=>f.order-u.order).flatMap(u=>u.exit),r));try{return a===t.historyValue&&zc(t._nodes,o)?h:Pt(h,{_nodes:l,historyValue:a})}catch(u){throw u}}function Pc(s,t,e,n,i){if(n.output===void 0)return;const r=zn(i.id,i.output!==void 0&&i.parent?Pn(i.output,s.context,t,e.self):void 0);return Pn(n.output,s.context,r,e.self)}function jc(s,t,e,n,i,r,o,a){let c=s;const h=new Set,l=new Set;Lc(n,o,l,h),a&&l.add(s.machine.root);const u=new Set;for(const f of[...h].sort((m,p)=>m.order-p.order)){i.add(f);const m=[];m.push(...f.entry);for(const p of f.invoke)m.push(kc(p.src,{...p,syncSnapshot:!!p.onSnapshot}));if(l.has(f)){const p=f.initial.actions;m.push(...p)}if(c=oe(c,t,e,m,r,f.invoke.map(p=>p.id)),f.type==="final"){const p=f.parent;let y=(p==null?void 0:p.type)==="parallel"?p:p==null?void 0:p.parent,w=y||f;for((p==null?void 0:p.type)==="compound"&&r.push(zn(p.id,f.output!==void 0?Pn(f.output,c.context,t,e.self):void 0));(y==null?void 0:y.type)==="parallel"&&!u.has(y)&&bs(i,y);)u.add(y),r.push(zn(y.id)),w=y,y=y.parent;if(y)continue;c=Pt(c,{status:"done",output:Pc(c,t,e,c.machine.root,w)})}}return c}function Lc(s,t,e,n){for(const i of s){const r=er(i,t);for(const a of i.target||[])!Ct(a)&&(i.source!==a||i.source!==r||i.reenter)&&(n.add(a),e.add(a)),Jt(a,t,e,n);const o=vs(i,t);for(const a of o){const c=We(a,r);(r==null?void 0:r.type)==="parallel"&&c.push(r),nr(n,t,e,c,!i.source.parent&&i.reenter?void 0:r)}}}function Jt(s,t,e,n){var i;if(Ct(s))if(t[s.id]){const r=t[s.id];for(const o of r)n.add(o),Jt(o,t,e,n);for(const o of r)wn(o,s.parent,n,t,e)}else{const r=Vi(s);for(const o of r.target)n.add(o),r===((i=s.parent)==null?void 0:i.initial)&&e.add(s.parent),Jt(o,t,e,n);for(const o of r.target)wn(o,s.parent,n,t,e)}else if(s.type==="compound"){const[r]=s.initial.target;Ct(r)||(n.add(r),e.add(r)),Jt(r,t,e,n),wn(r,s,n,t,e)}else if(s.type==="parallel")for(const r of ie(s).filter(o=>!Ct(o)))[...n].some(o=>Tt(o,r))||(Ct(r)||(n.add(r),e.add(r)),Jt(r,t,e,n))}function nr(s,t,e,n,i){for(const r of n)if((!i||Tt(r,i))&&s.add(r),r.type==="parallel")for(const o of ie(r).filter(a=>!Ct(a)))[...s].some(a=>Tt(a,o))||(s.add(o),Jt(o,t,e,s))}function wn(s,t,e,n,i){nr(e,n,i,We(s,t))}function Kc(s,t,e,n,i,r,o){let a=s;const c=Ln(n,i,r);c.sort((l,u)=>u.order-l.order);let h;for(const l of c)for(const u of $c(l)){let f;u.history==="deep"?f=m=>_s(m)&&Tt(m,l):f=m=>m.parent===l,h??(h={...r}),h[u.id]=Array.from(i).filter(f)}for(const l of c)a=oe(a,t,e,[...l.exit,...l.invoke.map(u=>Gi(u.id))],o),i.delete(l);return[a,h||r]}let Us=!1;function sr(s,t,e,n,i,r){const{machine:o}=s;let a=s;for(const c of n){let m=function(){e.system._sendInspectionEvent({type:"@xstate.action",actorRef:e.self,action:{type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",params:f}});try{Us=l,l(u,f)}finally{Us=!1}};const h=typeof c=="function",l=h?c:o.implementations.actions[typeof c=="string"?c:c.type];if(!l)continue;const u={context:a.context,event:t,self:e.self,system:e.system},f=h||typeof c=="string"?void 0:"params"in c?typeof c.params=="function"?c.params({context:a.context,event:t}):c.params:void 0;if(!("resolve"in l)){e.self._processingStatus===q.Running?m():e.defer(()=>{m()});continue}const p=l,[y,w,x]=p.resolve(e,a,u,f,l,i);a=y,"retryResolve"in p&&(r==null||r.push([p,w])),"execute"in p&&(e.self._processingStatus===q.Running?p.execute(e,w):e.defer(p.execute.bind(null,e,w))),x&&(a=sr(a,t,e,x,i,r))}return a}function oe(s,t,e,n,i,r){const o=r?[]:void 0,a=sr(s,t,e,n,{internalQueue:i,deferredActorIds:r},o);return o==null||o.forEach(([c,h])=>{c.retryResolve(e,a,h)}),a}function _n(s,t,e,n=[]){let i=s;const r=[];function o(h,l,u){e.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:e.self,event:l,snapshot:h,_transitions:u}),r.push(h)}if(t.type===Bn)return i=Pt(Fs(i,t,e),{status:"stopped"}),o(i,t,[]),{snapshot:i,microstates:r};let a=t;if(a.type!==Li){const h=a,l=mc(h),u=qs(h,i);if(l&&!u.length)return i=Pt(s,{status:"error",error:h.error}),o(i,h,[]),{snapshot:i,microstates:r};i=Kn(u,s,e,a,!1,n),o(i,h,u)}let c=!0;for(;i.status==="active";){let h=c?Uc(i,a):[];const l=h.length?i:void 0;if(!h.length){if(!n.length)break;a=n.shift(),h=qs(a,i)}i=Kn(h,i,e,a,!1,n),c=i!==l,o(i,a,h)}return i.status!=="active"&&Fs(i,a,e),{snapshot:i,microstates:r}}function Fs(s,t,e){return oe(s,t,e,Object.values(s.children).map(n=>Gi(n)),[])}function qs(s,t){return t.machine.getTransitionData(t,s)}function Uc(s,t){const e=new Set,n=s._nodes.filter(_s);for(const i of n)t:for(const r of[i].concat(We(i,void 0)))if(r.always){for(const o of r.always)if(o.guard===void 0||ws(o.guard,s.context,t,s)){e.add(o);break t}}return tr(Array.from(e),new Set(s._nodes),s.historyValue)}function Fc(s,t){const e=Je(Qe(s,t));return Ji(s,[...e])}function qc(s){return!!s&&typeof s=="object"&&"machine"in s&&"value"in s}const Zc=function(t){return Ui(t,this.value)},Gc=function(t){return this.tags.has(t)},Yc=function(t){const e=this.machine.getTransitionData(this,t);return!!(e!=null&&e.length)&&e.some(n=>n.target!==void 0||n.actions.length)},Xc=function(){const{_nodes:t,tags:e,machine:n,getMeta:i,toJSON:r,can:o,hasTag:a,matches:c,...h}=this;return{...h,tags:Array.from(e)}},Jc=function(){return this._nodes.reduce((t,e)=>(e.meta!==void 0&&(t[e.id]=e.meta),t),{})};function Ke(s,t){return{status:s.status,output:s.output,error:s.error,machine:t,context:s.context,_nodes:s._nodes,value:Ji(t.root,s._nodes),tags:new Set(s._nodes.flatMap(e=>e.tags)),children:s.children,historyValue:s.historyValue||{},matches:Zc,hasTag:Gc,can:Yc,getMeta:Jc,toJSON:Xc}}function Pt(s,t={}){return Ke({...s,...t},s.machine)}function Vc(s,t){const{_nodes:e,tags:n,machine:i,children:r,context:o,can:a,hasTag:c,matches:h,getMeta:l,toJSON:u,...f}=s,m={};for(const y in r){const w=r[y];m[y]={snapshot:w.getPersistedSnapshot(t),src:w.src,systemId:w._systemId,syncSnapshot:w._syncSnapshot}}return{...f,context:ir(o),children:m}}function ir(s){let t;for(const e in s){const n=s[e];if(n&&typeof n=="object")if("sessionId"in n&&"send"in n&&"ref"in n)t??(t=Array.isArray(s)?s.slice():{...s}),t[e]={xstate$$type:ys,id:n.id};else{const i=ir(n);i!==n&&(t??(t=Array.isArray(s)?s.slice():{...s}),t[e]=i)}}return t??s}function Qc(s,t,e,n,{event:i,id:r,delay:o},{internalQueue:a}){const c=t.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const h=typeof i=="function"?i(e,n):i;let l;if(typeof o=="string"){const u=c&&c[o];l=typeof u=="function"?u(e,n):u}else l=typeof o=="function"?o(e,n):o;return typeof l!="number"&&a.push(h),[t,{event:h,id:r,delay:l}]}function th(s,t){const{event:e,delay:n,id:i}=t;if(typeof n=="number"){s.defer(()=>{const r=s.self;s.system.scheduler.schedule(r,r,e,n,i)});return}}function eh(s,t){function e(n,i){}return e.type="xstate.raise",e.event=s,e.id=t==null?void 0:t.id,e.delay=t==null?void 0:t.delay,e.resolve=Qc,e.execute=th,e}function nh(s,{machine:t,context:e},n,i){const r=(o,a={})=>{const{systemId:c,input:h}=a;if(typeof o=="string"){const l=gs(t,o);if(!l)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const u=se(l,{id:a.id,parent:s.self,syncSnapshot:a.syncSnapshot,input:typeof h=="function"?h({context:e,event:n,self:s.self}):h,src:o,systemId:c});return i[u.id]=u,u}else return se(o,{id:a.id,parent:s.self,syncSnapshot:a.syncSnapshot,input:a.input,src:o,systemId:c})};return(o,a)=>{const c=r(o,a);return i[c.id]=c,s.defer(()=>{c._processingStatus!==q.Stopped&&c.start()}),c}}function sh(s,t,e,n,{assignment:i}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const r={},o={context:t.context,event:e.event,spawn:nh(s,t,e.event,r),self:s.self,system:s.system};let a={};if(typeof i=="function")a=i(o,n);else for(const h of Object.keys(i)){const l=i[h];a[h]=typeof l=="function"?l(o,n):l}const c=Object.assign({},t.context,a);return[Pt(t,{context:c,children:Object.keys(r).length?{...t.children,...r}:t.children})]}function ih(s){function t(e,n){}return t.type="xstate.assign",t.assignment=s,t.resolve=sh,t}const Zs=new WeakMap;function qt(s,t,e){let n=Zs.get(s);return n?t in n||(n[t]=e()):(n={[t]:e()},Zs.set(s,n)),n[t]}const rh={},ue=s=>typeof s=="string"?{type:s}:typeof s=="function"?"resolve"in s?{type:s.type}:{type:s.name}:s;class As{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Pi),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?Ps(this.config.states,(n,i)=>new As(n,{_parent:this,_key:i,_machine:this.machine})):rh,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=St(this.config.entry).slice(),this.exit=St(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=St(t.tags).slice()}_initialize(){this.transitions=Nc(this),this.config.always&&(this.always=Zt(this.config.always).map(t=>Dt(this,ji,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(ue),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(ue),eventType:null})}:void 0,history:this.history,states:Ps(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(ue)})),entry:this.entry.map(ue),exit:this.exit.map(ue),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return qt(this,"invoke",()=>St(this.config.invoke).map((t,e)=>{const{src:n,systemId:i}=t,r=t.id??js(this.id,e),o=typeof n=="string"?n:`xstate.invoke.${js(this.id,e)}`;return{...t,src:o,id:r,systemId:i,toJSON(){const{onDone:a,onError:c,...h}=t;return{...h,type:"xstate.invoke",src:o,id:r}}}}))}get on(){return qt(this,"on",()=>[...this.transitions].flatMap(([e,n])=>n.map(i=>[e,i])).reduce((e,[n,i])=>(e[n]=e[n]||[],e[n].push(i),e),{}))}get after(){return qt(this,"delayedTransitions",()=>Ec(this))}get initial(){return qt(this,"initial",()=>Mc(this,this.config.initial))}next(t,e){const n=e.type,i=[];let r;const o=qt(this,`candidates-${n}`,()=>Ic(this,n));for(const a of o){const{guard:c}=a,h=t.context;let l=!1;try{l=!c||ws(c,h,e,t)}catch(u){const f=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${f?`'${f}' `:""}in transition for event '${n}' in state node '${this.id}':
|
|
9
9
|
${u.message}`)}if(l){i.push(...a.actions),r=a;break}}return r?[r]:void 0}get events(){return qt(this,"events",()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const i=t[n];if(i.states)for(const r of i.events)e.add(`${r}`)}return Array.from(e)})}get ownEvents(){const t=new Set([...this.transitions.keys()].filter(e=>this.transitions.get(e).some(n=>!(!n.target&&!n.actions.length&&!n.reenter))));return Array.from(t)}}const oh="#";class xs{constructor(t,e){this.config=t,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=t.id||"(machine)",this.implementations={actors:(e==null?void 0:e.actors)??{},actions:(e==null?void 0:e.actions)??{},delays:(e==null?void 0:e.delays)??{},guards:(e==null?void 0:e.guards)??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new As(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:i,delays:r}=this.implementations;return new xs(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...i,...t.actors},delays:{...r,...t.delays}})}resolveState(t){const e=Fc(this.root,t.value),n=Je(Qe(this.root,e));return Ke({_nodes:[...n],context:t.context||{},children:{},status:bs(n,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,n){return _n(t,e,n).snapshot}microstep(t,e,n){return _n(t,e,n).microstates}getTransitionData(t,e){return Ss(this.root,t.value,t,e)||[]}getPreInitialState(t,e,n){const{context:i}=this.config,r=Ke({context:typeof i!="function"&&i?i:{},_nodes:[this.root],children:{},status:"active"},this);return typeof i=="function"?oe(r,e,t,[ih(({spawn:a,event:c,self:h})=>i({spawn:a,input:c.input,self:h}))],n):r}getInitialSnapshot(t,e){const n=Ki(e),i=[],r=this.getPreInitialState(t,n,i),o=Kn([{target:[...Qi(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],r,t,n,!0,i),{snapshot:a}=_n(o,n,t,i);return a}start(t){Object.values(t.children).forEach(e=>{e.getSnapshot().status==="active"&&e.start()})}getStateNodeById(t){const e=ms(t),n=e.slice(1),i=an(e[0])?e[0].slice(oh.length):e[0],r=this.idMap.get(i);if(!r)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return Ve(r,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return Vc(t,e)}restoreSnapshot(t,e){const n={},i=t.children;Object.keys(i).forEach(c=>{const h=i[c],l=h.snapshot,u=h.src,f=typeof u=="string"?gs(this,u):u;if(!f)return;const m=se(f,{id:c,parent:e.self,syncSnapshot:h.syncSnapshot,snapshot:l,src:u,systemId:h.systemId});n[c]=m});const r=Ke({...t,children:n,_nodes:Array.from(Je(Qe(this.root,t.value)))},this);let o=new Set;function a(c,h){if(!o.has(c)){o.add(c);for(let l in c){const u=c[l];if(u&&typeof u=="object"){if("xstate$$type"in u&&u.xstate$$type===ys){c[l]=h[u.id];continue}a(u,h)}}}}return a(r.context,n),r}}function ah(s,t){return new xs(s,t)}const je=s=>s===!1?!1:s.map(t=>t.serialize()),ch=s=>s===!1?!1:s.serialize(),hh=s=>s===!1?!1:s.map(t=>({tile:t.tile.toString(),candidates:t.candidates.map(e=>e.toString()),shanten:t.shanten})),Un=s=>JSON.parse(JSON.stringify(s)),bn=s=>s===!1?!1:Un(s),Fn=s=>ah({id:"Untitled",initial:"distribute",context:{currentWind:S.E,oneShotMap:Z(!1),missingMap:Z(!1),controller:s,genEventID:rr()},states:{distribute:{on:{NEXT:{target:"drawn"}},entry:{type:"notify_distribution"}},drawn:{entry:{type:"notify_draw"},on:{NEXT:{target:"waiting_user_event_after_drawn",actions:{type:"notify_choice_after_drawn"},description:`可能なアクションとその詳細を通知\\
|
package/dist/index.js
CHANGED
|
@@ -4679,19 +4679,19 @@ const wa = (s) => {
|
|
|
4679
4679
|
return { ...i, e: r };
|
|
4680
4680
|
},
|
|
4681
4681
|
[_.THREE]: function(n) {
|
|
4682
|
-
throw new Error("
|
|
4682
|
+
throw new Error("three is unsupported");
|
|
4683
4683
|
},
|
|
4684
4684
|
[_.RUN]: function(n) {
|
|
4685
|
-
throw new Error("
|
|
4685
|
+
throw new Error("run is unsupported");
|
|
4686
4686
|
},
|
|
4687
4687
|
[_.UNKNOWN]: function(n) {
|
|
4688
4688
|
throw new Error("found unknown block");
|
|
4689
4689
|
},
|
|
4690
4690
|
[_.PAIR]: function(n) {
|
|
4691
|
-
throw new Error("unsupported");
|
|
4691
|
+
throw new Error("pair is unsupported");
|
|
4692
4692
|
},
|
|
4693
4693
|
[_.ISOLATED]: function(n) {
|
|
4694
|
-
throw new Error("unsupported");
|
|
4694
|
+
throw new Error("isolated is unsupported");
|
|
4695
4695
|
}
|
|
4696
4696
|
};
|
|
4697
4697
|
}, ue = (s, t) => {
|