@konoui/mjimage 0.0.54 → 0.0.55

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 CHANGED
@@ -10,7 +10,7 @@
10
10
  `;function Yr(n,t){let e="";return t.format&&t.indentBy.length>0&&(e=Xr),Un(n,t,"",e)}function Un(n,t,e,s){let r="",i=!1;for(let o=0;o<n.length;o++){const a=n[o],c=qr(a);if(c===void 0)continue;let l="";if(e.length===0?l=c:l=`${e}.${c}`,c===t.textNodeName){let f=a[c];Qr(l,t)||(f=t.tagValueProcessor(c,f),f=Fn(f,t)),i&&(r+=s),r+=f,i=!1;continue}else if(c===t.cdataPropName){i&&(r+=s),r+=`<![CDATA[${a[c][0][t.textNodeName]}]]>`,i=!1;continue}else if(c===t.commentPropName){r+=s+`<!--${a[c][0][t.textNodeName]}-->`,i=!0;continue}else if(c[0]==="?"){const f=Nn(a[":@"],t),m=c==="?xml"?"":s;let A=a[c][0][t.textNodeName];A=A.length!==0?" "+A:"",r+=m+`<${c}${A}${f}?>`,i=!0;continue}let u=s;u!==""&&(u+=t.indentBy);const h=Nn(a[":@"],t),d=s+`<${c}${h}`,g=Un(a[c],t,l,u);t.unpairedTags.indexOf(c)!==-1?t.suppressUnpairedNode?r+=d+">":r+=d+"/>":(!g||g.length===0)&&t.suppressEmptyNode?r+=d+"/>":g&&g.endsWith(">")?r+=d+`>${g}${s}</${c}>`:(r+=d+">",g&&s!==""&&(g.includes("/>")||g.includes("</"))?r+=s+t.indentBy+g+s:r+=g,r+=`</${c}>`),i=!0}return r}function qr(n){const t=Object.keys(n);for(let e=0;e<t.length;e++){const s=t[e];if(n.hasOwnProperty(s)&&s!==":@")return s}}function Nn(n,t){let e="";if(n&&!t.ignoreAttributes)for(let s in n){if(!n.hasOwnProperty(s))continue;let r=t.attributeValueProcessor(s,n[s]);r=Fn(r,t),r===!0&&t.suppressBooleanAttributes?e+=` ${s.substr(t.attributeNamePrefix.length)}`:e+=` ${s.substr(t.attributeNamePrefix.length)}="${r}"`}return e}function Qr(n,t){n=n.substr(0,n.length-t.textNodeName.length-1);let e=n.substr(n.lastIndexOf(".")+1);for(let s in t.stopNodes)if(t.stopNodes[s]===n||t.stopNodes[s]==="*."+e)return!0;return!1}function Fn(n,t){if(n&&n.length>0&&t.processEntities)for(let e=0;e<t.entities.length;e++){const s=t.entities[e];n=n.replace(s.regex,s.val)}return n}const ti={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(n,t){return t},attributeValueProcessor:function(n,t){return t},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("'","g"),val:"&apos;"},{regex:new RegExp('"',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1};function it(n){this.options=Object.assign({},ti,n),this.options.ignoreAttributes===!0||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.ignoreAttributesFn=zn(this.options.ignoreAttributes),this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=si),this.processTextOrObjNode=ei,this.options.format?(this.indentate=ni,this.tagEndChar=`>
11
11
  `,this.newLine=`
12
12
  `):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}it.prototype.build=function(n){return this.options.preserveOrder?Yr(n,this.options):(Array.isArray(n)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(n={[this.options.arrayNodeName]:n}),this.j2x(n,0,[]).val)};it.prototype.j2x=function(n,t,e){let s="",r="";const i=e.join(".");for(let o in n)if(Object.prototype.hasOwnProperty.call(n,o))if(typeof n[o]>"u")this.isAttribute(o)&&(r+="");else if(n[o]===null)this.isAttribute(o)||o===this.options.cdataPropName?r+="":o[0]==="?"?r+=this.indentate(t)+"<"+o+"?"+this.tagEndChar:r+=this.indentate(t)+"<"+o+"/"+this.tagEndChar;else if(n[o]instanceof Date)r+=this.buildTextValNode(n[o],o,"",t);else if(typeof n[o]!="object"){const a=this.isAttribute(o);if(a&&!this.ignoreAttributesFn(a,i))s+=this.buildAttrPairStr(a,""+n[o]);else if(!a)if(o===this.options.textNodeName){let c=this.options.tagValueProcessor(o,""+n[o]);r+=this.replaceEntitiesValue(c)}else r+=this.buildTextValNode(n[o],o,"",t)}else if(Array.isArray(n[o])){const a=n[o].length;let c="",l="";for(let u=0;u<a;u++){const h=n[o][u];if(!(typeof h>"u"))if(h===null)o[0]==="?"?r+=this.indentate(t)+"<"+o+"?"+this.tagEndChar:r+=this.indentate(t)+"<"+o+"/"+this.tagEndChar;else if(typeof h=="object")if(this.options.oneListGroup){const d=this.j2x(h,t+1,e.concat(o));c+=d.val,this.options.attributesGroupName&&h.hasOwnProperty(this.options.attributesGroupName)&&(l+=d.attrStr)}else c+=this.processTextOrObjNode(h,o,t,e);else if(this.options.oneListGroup){let d=this.options.tagValueProcessor(o,h);d=this.replaceEntitiesValue(d),c+=d}else c+=this.buildTextValNode(h,o,"",t)}this.options.oneListGroup&&(c=this.buildObjectNode(c,o,l,t)),r+=c}else if(this.options.attributesGroupName&&o===this.options.attributesGroupName){const a=Object.keys(n[o]),c=a.length;for(let l=0;l<c;l++)s+=this.buildAttrPairStr(a[l],""+n[o][a[l]])}else r+=this.processTextOrObjNode(n[o],o,t,e);return{attrStr:s,val:r}};it.prototype.buildAttrPairStr=function(n,t){return t=this.options.attributeValueProcessor(n,""+t),t=this.replaceEntitiesValue(t),this.options.suppressBooleanAttributes&&t==="true"?" "+n:" "+n+'="'+t+'"'};function ei(n,t,e,s){const r=this.j2x(n,e+1,s.concat(t));return n[this.options.textNodeName]!==void 0&&Object.keys(n).length===1?this.buildTextValNode(n[this.options.textNodeName],t,r.attrStr,e):this.buildObjectNode(r.val,t,r.attrStr,e)}it.prototype.buildObjectNode=function(n,t,e,s){if(n==="")return t[0]==="?"?this.indentate(s)+"<"+t+e+"?"+this.tagEndChar:this.indentate(s)+"<"+t+e+this.closeTag(t)+this.tagEndChar;{let r="</"+t+this.tagEndChar,i="";return t[0]==="?"&&(i="?",r=""),(e||e==="")&&n.indexOf("<")===-1?this.indentate(s)+"<"+t+e+i+">"+n+r:this.options.commentPropName!==!1&&t===this.options.commentPropName&&i.length===0?this.indentate(s)+`<!--${n}-->`+this.newLine:this.indentate(s)+"<"+t+e+i+this.tagEndChar+n+this.indentate(s)+r}};it.prototype.closeTag=function(n){let t="";return this.options.unpairedTags.indexOf(n)!==-1?this.options.suppressUnpairedNode||(t="/"):this.options.suppressEmptyNode?t="/":t=`></${n}`,t};it.prototype.buildTextValNode=function(n,t,e,s){if(this.options.cdataPropName!==!1&&t===this.options.cdataPropName)return this.indentate(s)+`<![CDATA[${n}]]>`+this.newLine;if(this.options.commentPropName!==!1&&t===this.options.commentPropName)return this.indentate(s)+`<!--${n}-->`+this.newLine;if(t[0]==="?")return this.indentate(s)+"<"+t+e+"?"+this.tagEndChar;{let r=this.options.tagValueProcessor(t,n);return r=this.replaceEntitiesValue(r),r===""?this.indentate(s)+"<"+t+e+this.closeTag(t)+this.tagEndChar:this.indentate(s)+"<"+t+e+">"+r+"</"+t+this.tagEndChar}};it.prototype.replaceEntitiesValue=function(n){if(n&&n.length>0&&this.options.processEntities)for(let t=0;t<this.options.entities.length;t++){const e=this.options.entities[t];n=n.replace(e.regex,e.val)}return n};function ni(n){return this.options.indentBy.repeat(n)}function si(n){return n.startsWith(this.options.attributeNamePrefix)&&n!==this.options.textNodeName?n.substr(this.attrPrefixLen):!1}class ot{constructor(t){_(this,"type");_(this,"attrs",{});_(this,"styles",{});_(this,"deleteMarker",!1);this.type=t}dx(t){return this.attrs.x==null?this.attrs.x=t:this.attrs.x+=t,this}dy(t){return this.attrs.y==null?this.attrs.y=t:this.attrs.y+=t,this}x(t){return this.attrs.x=t,this}y(t){return this.attrs.y=t,this}size(t,e){return this.attrs.width=t,this.attrs.height=e,this}remove(){this.deleteMarker=!0}left(...t){return`<${[this.type,Vn(this.attrs),pi(this.styles),...t].filter(e=>e!="").join(" ")}>`}right(){return`</${this.type}>`}center(){return""}toString(){return this.deleteMarker?"":`${this.left()}${this.center()}${this.right()}`}attr(t){if(typeof t=="string")return this.attrs[t]??"";for(const[e,s]of Object.entries(t))this.attrs[e]=s;return this}css(t){return this.styles={...this.styles,...t},this}svg(){return this.toString()}}class qe extends ot{constructor(e){super("image");_(this,"attrs",{});this.attrs={...this.attrs,href:e}}load(e){return this.attrs.href=e,this}}class ge extends ot{constructor(e){super("use");_(this,"attrs",{});this.attrs={...this.attrs,href:this.make(e)}}use(e){return this.attrs.href=`#${e}`,this}make(e){return e==null?e:`#${e}`}}class Qe extends ot{constructor(){super("rect");_(this,"attrs",{})}fill(e){return this.attrs.fill=e,this}stroke(e){return this.attrs.stroke=e,this}}class yt extends ot{constructor(e=""){super("text");_(this,"attrs");_(this,"_text","");this._text=e,this.attrs={}}plain(e){return this._text=e,this}font(e){return this.attrs.fontFamily=e.family,this.attrs.fontSize=e.size,this}center(){return this._text}}let tn=class extends ot{constructor(e){super("symbol");_(this,"raw");this.raw=e}id(){return this.attr("id")}center(){return this.raw}};class T extends ot{constructor(){super("g");_(this,"children",[]);_(this,"rotateMatrix");_(this,"translateMatrix")}add(e){return this.children.push(e),this}rotate(e,s,r){return this.rotateMatrix=Ys(e,s,r),this}translate(e,s){return this.translateMatrix=Oe(e,s),this}center(){return this.children.map(e=>e.toString()).join("")}left(...e){const s=[this.translateMatrix,this.rotateMatrix].filter(r=>r!=null);return s.length==0?super.left():super.left(fi(Gs(s)))}each(e,s){for(let r=0;r<this.children.length;r++){const i=this.children[r];i instanceof T&&s&&i.each(e,!0),e(r,this.children)}}}const ri=['xmlns="http://www.w3.org/2000/svg"','version="1.1"','xmlns:xlink="http://www.w3.org/1999/xlink"'];class Gn extends ot{constructor(){super("svg");_(this,"children",[]);_(this,"viewBox")}add(e){return this.children.push(e),this}center(){return this.children.map(e=>e.toString()).join("")}left(...e){return`<${[this.type,...ri,Vn(this.attrs),di(this.viewBox)].filter(s=>s!="").join(" ")}>`}viewbox(e,s,r,i){return this.viewBox={x:e,y:s,width:r,height:i},this}importSymbol(e){for(const s of gi(e))this.add(s);return this}x(e){throw new Error("unimplemented")}y(e){throw new Error("unimplemented")}dx(e){throw new Error("unimplemented")}dy(e){throw new Error("unimplemented")}each(e,s){for(let r=0;r<this.children.length;r++){const i=this.children[r];i instanceof T&&s&&i.each(e,!0),e(r,this.children)}}}function Zn(){return new Gn}const ii=Zn,oi=T,ai=qe,ci=ge,li=Qe,ui=yt;function hi(n){return n.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())}function di(n){return n==null?"":`viewBox="${n.x} ${n.y} ${n.width} ${n.height}"`}function fi(n){return n==null?"":`transform="${qs(n)}"`}function Vn(n){return Object.entries(n).filter(([t,e])=>e!==void 0).map(([t,e])=>`${hi(t)}="${e}"`).join(" ")}function pi(n){const t=Object.entries(n).map(([e,s])=>`${e}: ${s};`).join(" ");return t!=""?`style="${t}"`:""}function*gi(n){const t=new Jr({ignoreAttributes:!1}),e=new it({ignoreAttributes:!1}),s=t.parse(n);for(const r of s.svg.symbol){const i=e.build(r),o=new tn(i);for(const[a,c]of Object.entries(r))a.startsWith("@_")&&(o.attrs[a.substring(2)]=c);yield o}}const U=(n,t)=>{const e=B(n.tiles[0],t),s=e.baseHeight,r=e.baseWidth;if(n.is(b.SHO_KAN))return{width:r*2+s,height:Math.max(r*2,s)};const i=n.tiles.reduce((a,c)=>{const l=B(c,t).height;return l>a?l:a},0);return{width:n.tiles.reduce((a,c)=>a+B(c,t).width,0),height:i}},B=(n,t)=>{const e=parseFloat((nt.HEIGHT*t).toPrecision(5)),s=parseFloat((nt.WIDTH*t).toPrecision(5)),r=n.has(y.HORIZONTAL)?{width:e,height:s,baseWidth:s,baseHeight:e}:{width:s,height:e,w:s,baseWidth:s,baseHeight:e};return(n.has(y.TSUMO)||n.has(y.DORA))&&(r.width+=s*nt.TEXT_SCALE),r};class Ct{constructor(t={}){_(this,"tileWidth");_(this,"tileHeight");_(this,"imageHostUrl");_(this,"imageExt");_(this,"scale");_(this,"svgSprite");this.scale=t.scale??1,this.imageHostUrl=t.imageHostUrl??"",this.imageExt=t.imageExt??"svg",this.tileWidth=nt.WIDTH*this.scale,this.tileHeight=nt.HEIGHT*this.scale,this.svgSprite=t.svgSprite??!1}getDiffTileHeightWidth(t){const e=B(t,this.scale);return(e.baseHeight-e.baseWidth)/2}image(t){let e=new qe().load(this.buildURL(t));return this.svgSprite&&(e=new ge().use(Ct.buildID(t))),t instanceof w&&t.has(y.COLOR_GRAYSCALE)&&e.css({filter:"contrast(65%)"}),e}createImage(t,e,s){const r=B(t,this.scale);return this.image(t).dx(e).dy(s).size(r.baseWidth,r.baseHeight)}createTextImage(t,e,s,r){const i=this.createImage(t,e,s),o=B(t,this.scale),a=o.baseHeight*.2,c=o.baseWidth,l=o.baseHeight,u=new yt().plain(r);u.size(o.baseWidth,o.baseHeight).font({family:Ue,size:a}).dx(c).dy(l);const h=new T;return h.add(i).add(u).translate(e,s),h}createRotate90Image(t,e,s,r=!1){const i=this.createImage(t,0,0),o=B(t,this.scale),a=o.baseWidth/2,c=o.baseHeight/2,l=e+this.getDiffTileHeightWidth(t),u=r?s-this.getDiffTileHeightWidth(t):s,h=new T;return h.add(i).translate(l,u).rotate(90,a,c),h}createStick(t){return this.image(t)}static buildID(t){if(t==100||t==1e3)return t==100?"stick100":"stick1000";const e=t.t==p.BACK||t.has(y.RED)?0:t.n;return`${t.t}${e}`}buildURL(t){const e=`${Ct.buildID(t)}.${this.imageExt}`;return this.imageHostUrl!=""?`${this.imageHostUrl}${e}`:e}}class en extends Ct{constructor(){super(...arguments);_(this,"blockMargin",nt.WIDTH*nt.BLOCK_MARGIN_SCALE*this.scale)}createBlockHandDiscard(e){const s=e instanceof R?e.tilesWithBack:e.tiles,r=new T;let i=0;for(const o of s){const a=B(o,this.scale),c=o.has(y.HORIZONTAL)?this.createRotate90Image.bind(this):this.createImage.bind(this),l=o.has(y.HORIZONTAL)?this.getDiffTileHeightWidth(o):0,u=c(o,i,l);r.add(u),i+=a.width}return r}createBlockPonChiKan(e){const s=e.tiles.findIndex(o=>o.has(y.HORIZONTAL));let r=0;const i=new T;if(e.type==b.SHO_KAN){let o=s;for(let a=0;a<e.tiles.length;a++)e.tiles[a].has(y.HORIZONTAL)&&(o=a);for(let a=0;a<e.tiles.length;a++){const c=B(e.tiles[a],this.scale);if(a==o)continue;if(a==s){const h=e.tiles[s],d=e.tiles[o],g=B(h,this.scale),f=this.createRotate90Image(h,0,0,!0),m=this.createRotate90Image(d,0,g.height,!0);i.add(new T().translate(r,0).add(f).add(m)),r+=g.width;continue}const l=c.width*2-c.height,u=this.createImage(e.tiles[a],r,l);r+=c.width,i.add(u)}return i}if(e.type==b.CHI){const o=e.tiles[s],a=this.createRotate90Image(o,r,this.getDiffTileHeightWidth(o));r+=B(o,this.scale).width,i.add(a);for(let c=0;c<e.tiles.length;c++){if(c==s)continue;const l=e.tiles[c],u=B(l,this.scale),h=this.createImage(l,r,0);r+=u.width,i.add(h)}return i}for(let o=0;o<e.tiles.length;o++){const a=o==s?this.createRotate90Image.bind(this):this.createImage.bind(this),c=e.tiles[o],l=o==s?this.getDiffTileHeightWidth(c):0,u=B(c,this.scale),h=a(c,r,l);r+=u.width,i.add(h)}return i}}const yi=(n,t)=>{const e=n.scale;return{[b.CHI]:function(r){const i=U(r,e),o=n.createBlockPonChiKan(r);return{...i,e:o}},[b.PON]:function(r){const i=U(r,e),o=n.createBlockPonChiKan(r);return{...i,e:o}},[b.DAI_KAN]:function(r){const i=U(r,e),o=n.createBlockPonChiKan(r);return{...i,e:o}},[b.SHO_KAN]:function(r){const i=U(r,e),o=n.createBlockPonChiKan(r);return{...i,e:o}},[b.AN_KAN]:function(r){N(r instanceof R,`block type is not ankan: ${r.type}`);const i=U(r,e),o=n.createBlockHandDiscard(r);return{...i,e:o}},[b.IMAGE_DORA]:function(r){r=(t==null?void 0:t.doraText)==!1?new kt([r.tiles[0].clone({remove:y.DORA})]):r;const i=U(r,e),o=new T,a=(t==null?void 0:t.doraText)===!1?n.createImage(r.tiles[0],0,0):n.createTextImage(r.tiles[0],0,0,"(ドラ)");return o.add(a),{...i,e:o}},[b.TSUMO]:function(r){r=(t==null?void 0:t.tsumoText)==!1?new kt([r.tiles[0].clone({remove:y.TSUMO})]):r;const i=U(r,e),o=new T,a=(t==null?void 0:t.tsumoText)===!1?n.createImage(r.tiles[0],0,0):n.createTextImage(r.tiles[0],0,0,"(ツモ)");return o.add(a),{...i,e:o}},[b.HAND]:function(r){const i=U(r,e),o=n.createBlockHandDiscard(r);return{...i,e:o}},[b.IMAGE_DISCARD]:function(r){const i=U(r,e),o=n.createBlockHandDiscard(r);return{...i,e:o}},[b.THREE]:function(r){throw new Error("three is unsupported")},[b.RUN]:function(r){throw new Error("run is unsupported")},[b.PAIR]:function(r){throw new Error("pair is unsupported")},[b.ISOLATED]:function(r){throw new Error("isolated is unsupported")},[b.UNKNOWN]:function(r){if(r.tiles.some(a=>a.has(y.TSUMO)||a.has(y.DORA)))throw new Error("found an unknown block with operator tiles");const i=U(r,e),o=n.createBlockHandDiscard(r);return{...i,e:o}}}},vt=(n,t,e)=>{const s=yi(n,e);let r=0,i=0;const o=[];for(const h of t){const d=s[h.type],g=d(h);i+=g.width,r=g.height>r?g.height:r,o.push(g)}const a=r,c=i+(t.length-1)*n.blockMargin,l=new T;let u=0;for(const h of o){const d=a-h.height,g=new T().translate(u,d);g.add(h.e),l.add(g),u+=h.width+n.blockMargin}return{e:l,width:c,height:a}},mi=(n,t,e={},s={responsive:!1,doraText:!0,tsumoText:!0})=>{const r=new en(e),i=vt(r,t,s);s.responsive||n.size(i.width,i.height),n.viewbox(0,0,i.width,i.height),n.add(i.e)},Jn=()=>{const n=[0,1,2,3,4,5,6,7,8,9],t=[];for(const e of Object.values(p)){if(e==p.BACK){t.push(Ct.buildID(new w(e,0)));continue}t.push(...n.map(s=>Ct.buildID(new w(e,s))).flat())}return t},wi=n=>{const t=Jn(),e=[];return n.each((s,r)=>{const i=r[s];if(i instanceof ge){const a=i.attr("href").substring(1);t.includes(a)&&e.push(a)}},!0),e},bi=n=>{const t=Jn(),e=wi(n);n.each((s,r)=>{const i=r[s];i instanceof tn&&(t.includes(i.id())&&e.includes(i.id())||i.remove())},!0)},_i=n=>{const e=[];for(let s=0;s<n.length;s+=6){const r=n.slice(s,s+6);e.push(r)}return e},j=(n,t,e,s,r=0,i=0)=>{const o=new T().add(n);if(s==90){const a=r,c=i-e;return o.rotate(s,0,e).translate(a,c),new T().add(o)}if(s==180){const a=r+t,c=i-e;return o.rotate(s,0,e).translate(a,c),new T().add(o)}if(s==270){const a=r+e,c=i+(t-e);return o.rotate(s,0,e).translate(a,c),new T().add(o)}return new T().add(o)},Qt=(n,t)=>{const e=new T,s=_i(n);for(let r=0;r<s.length;r++){let i=s[r],o=r*t.tileHeight;const a=t.createBlockHandDiscard(new Ve(i,b.IMAGE_DISCARD)).translate(0,o);e.add(a)}return{e,width:t.tileWidth*5+t.tileHeight*1,height:t.tileHeight*s.length}},Ei=(n,t,e)=>{const s=t.font,r=t.textWidth,i=t.textHeight,o=e.sticks.dead,a=e.sticks.reach,c=ve.WIDTH*n.scale,l=ve.HEIGHT*n.scale;let u=r*3,h=i;const d=(c+n.tileWidth+r-u)/2,g=new yt().plain(e.round).font(s).x(d).y(0);h+=25*n.scale;const f=n.tileHeight,m=new T().size(c,f).translate(0,h),A={family:s.family,size:s.size*.7},S=n.createStick(1e3).size(c,l).x(0).y(0),O=new yt().plain(a.toString()).font(A).dx(c).dy(l),M=n.createStick(100).size(c,l).x(0).y(l+l),Et=new yt().plain(o.toString()).font(A).dx(c).dy(l*3);m.add(S),m.add(O),m.add(M),m.add(Et);const At=n.createImage(e.doras[0],0,0).x(c+r).y(0);m.add(At);const St=new T;return St.add(g),St.add(g),St.add(m),{e:St,width:c+n.tileWidth+r,height:h+n.tileHeight}},Ai=(n,t,e=0)=>{const s=vt(n,t.front),r=vt(n,t.right),i=vt(n,t.opposite),o=vt(n,t.left),a=[s.width,r.width,i.width,o.width].reduce((m,A)=>Math.max(m,A)),c=Math.max(e+n.tileHeight*2+n.blockMargin*2,a+n.tileWidth*2+n.blockMargin),l=c,u=j(s.e,s.width,s.height,0).translate((c-s.width)/2,l-s.height),h=j(r.e,r.width,r.height,270).translate(c-r.height,(c-r.width)/2),d=j(i.e,i.width,i.height,180).translate((c-i.width)/2,0),g=j(o.e,o.width,o.height,90).translate(0,(c-o.width)/2),f=new T().size(c,l);return f.add(u),f.add(h),f.add(d),f.add(g),{e:new T().add(f),width:c,height:l}},Si=n=>{const t=Object.values(de),e=t.indexOf(n);return[...t.slice(e),...t.slice(0,e)]},Ni=(n,t,e)=>{const s=n.tileWidth*5+n.tileHeight*1,r=t.font,i=t.textWidth,o=t.textHeight,a=t.numWidth,c=Ei(n,t,e);c.e.translate(s/2-c.width/2,s/2-c.height/2);const l=(Ms,yn,xs)=>{const $s=`${Ms} ${yn}`,Ps=new yt().plain($s).font(r).attr(xs);return{e:new T().add(Ps),width:i+a*yn.toString().length,height:o}},[u,h,d,g]=Si(e.frontPlace),f=e.scores,A=l(u,f.front,{x:s/2,y:s,"dominant-baseline":"text-after-edge","text-anchor":"middle"}).e;let S=l(h,f.right,{"dominant-baseline":"text-after-edge","text-anchor":"middle"});const O=j(S.e,S.width,S.height,270).translate(s,s/2-S.width);let M=l(d,f.opposite,{"text-anchor":"middle","dominant-baseline":"text-after-edge"});const Et=j(M.e,M.width,M.height,180).translate(s/2-M.width,-M.height);let At=l(g,f.left,{"dominant-baseline":"ideographic","text-anchor":"middle"});const St=j(At.e,At.width,At.height,90).translate(-At.height,s/2),at=new T,Rs=new Qe().size(s,s).x(0).y(0).fill("none").stroke("#000000");return at.add(Rs),at.add(c.e),at.add(A),at.add(O),at.add(Et),at.add(St),{e:at,width:s,height:s}},Ti=(n,t)=>{const e=Qt(t.front,n),s=Qt(t.right,n),r=Qt(t.opposite,n),i=Qt(t.left,n),o=[e.height,s.height,r.height,i.height].reduce((O,M)=>Math.max(O,M)),a=n.tileWidth*5+n.tileHeight*1,c=o,l=a+o*2+n.blockMargin,u=l,h=new T().size(l,u),d=l/2-a/2,g=u/2-a/2,f=j(e.e,a,c,0).translate(d,u-c),m=j(s.e,a,c,270).translate(l-c,g),A=j(r.e,a,c,180).translate(d,0),S=j(i.e,a,c,90).translate(0,g);return h.add(f),h.add(m),h.add(A),h.add(S),{e:new T().add(h),width:l,height:u}},Xn=(n,t,e,s,r)=>{const i=new T,o=Ti(n,s),a=Ai(n,e,o.height),c=Ni(n,t,r);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),i.add(a.e),i.add(o.e),i.add(c.e),{e:i,width:a.width,height:a.height}},vi=(n,t,e={},s,r={responsive:!1})=>{const i=new en(e),o=s,{discards:a,hands:c,scoreBoard:l}=Qn(t),u=Xn(i,o,c,a,l);r.responsive||n.size(u.width,u.height),n.viewbox(0,0,u.width,u.height),n.add(u.e)};var J;function Yn(n){return{lang:(n==null?void 0:n.lang)??(J==null?void 0:J.lang),message:n==null?void 0:n.message,abortEarly:(n==null?void 0:n.abortEarly)??(J==null?void 0:J.abortEarly),abortPipeEarly:(n==null?void 0:n.abortPipeEarly)??(J==null?void 0:J.abortPipeEarly)}}var _e;function Ii(n){return _e==null?void 0:_e.get(n)}var Ee;function Oi(n){return Ee==null?void 0:Ee.get(n)}var Ae;function ki(n,t){var e;return(e=Ae==null?void 0:Ae.get(n))==null?void 0:e.get(t)}function Rt(n){var e,s;const t=typeof n;return t==="string"?`"${n}"`:t==="number"||t==="bigint"||t==="boolean"?`${n}`:t==="object"||t==="function"?(n&&((s=(e=Object.getPrototypeOf(n))==null?void 0:e.constructor)==null?void 0:s.name))??"null":t}function st(n,t,e,s,r){const i=r&&"input"in r?r.input:e.value,o=(r==null?void 0:r.expected)??n.expects??null,a=(r==null?void 0:r.received)??Rt(i),c={kind:n.kind,type:n.type,input:i,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:n.requirement,path:r==null?void 0:r.path,issues:r==null?void 0:r.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly},l=n.kind==="schema",u=(r==null?void 0:r.message)??n.message??ki(n.reference,c.lang)??(l?Oi(c.lang):null)??s.message??Ii(c.lang);u!==void 0&&(c.message=typeof u=="function"?u(c):u),l&&(e.typed=!1),e.issues?e.issues.push(c):e.issues=[c]}function Dt(n){return{version:1,vendor:"valibot",validate(t){return n["~run"]({value:t},Yn())}}}function Ci(n,t){const e=[...new Set(n)];return e.length>1?`(${e.join(` ${t} `)})`:e[0]??"never"}function Re(n,t){return{kind:"validation",type:"max_value",reference:Re,async:!1,expects:`<=${n instanceof Date?n.toJSON():Rt(n)}`,requirement:n,message:t,"~run"(e,s){return e.typed&&!(e.value<=this.requirement)&&st(this,"value",e,s,{received:e.value instanceof Date?e.value.toJSON():Rt(e.value)}),e}}}function Me(n,t){return{kind:"validation",type:"min_value",reference:Me,async:!1,expects:`>=${n instanceof Date?n.toJSON():Rt(n)}`,requirement:n,message:t,"~run"(e,s){return e.typed&&!(e.value>=this.requirement)&&st(this,"value",e,s,{received:e.value instanceof Date?e.value.toJSON():Rt(e.value)}),e}}}function Ri(n,t,e){return typeof n.fallback=="function"?n.fallback(t,e):n.fallback}function qn(n,t,e){return typeof n.default=="function"?n.default(t,e):n.default}function ae(n){return{kind:"schema",type:"number",reference:ae,expects:"number",async:!1,message:n,get"~standard"(){return Dt(this)},"~run"(t,e){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:st(this,"type",t,e),t}}}function K(n,t){return{kind:"schema",type:"optional",reference:K,expects:`(${n.expects} | undefined)`,async:!1,wrapped:n,default:t,get"~standard"(){return Dt(this)},"~run"(e,s){return e.value===void 0&&(this.default!==void 0&&(e.value=qn(this,e,s)),e.value===void 0)?(e.typed=!0,e):this.wrapped["~run"](e,s)}}}function xe(n,t){return{kind:"schema",type:"picklist",reference:xe,expects:Ci(n.map(Rt),"|"),async:!1,options:n,message:t,get"~standard"(){return Dt(this)},"~run"(e,s){return this.options.includes(e.value)?e.typed=!0:st(this,"type",e,s),e}}}function Mt(n,t){return{kind:"schema",type:"strict_object",reference:Mt,expects:"Object",async:!1,entries:n,message:t,get"~standard"(){return Dt(this)},"~run"(e,s){var i;const r=e.value;if(r&&typeof r=="object"){e.typed=!0,e.value={};for(const o in this.entries){const a=this.entries[o];if(o in r||(a.type==="exact_optional"||a.type==="optional"||a.type==="nullish")&&a.default!==void 0){const c=o in r?r[o]:qn(a),l=a["~run"]({value:c},s);if(l.issues){const u={type:"object",origin:"value",input:r,key:o,value:c};for(const h of l.issues)h.path?h.path.unshift(u):h.path=[u],(i=e.issues)==null||i.push(h);if(e.issues||(e.issues=l.issues),s.abortEarly){e.typed=!1;break}}l.typed||(e.typed=!1),e.value[o]=l.value}else if(a.fallback!==void 0)e.value[o]=Ri(a);else if(a.type!=="exact_optional"&&a.type!=="optional"&&a.type!=="nullish"&&(st(this,"key",e,s,{input:void 0,expected:`"${o}"`,path:[{type:"object",origin:"key",input:r,key:o,value:r[o]}]}),s.abortEarly))break}if(!e.issues||!s.abortEarly){for(const o in r)if(!(o in this.entries)){st(this,"key",e,s,{input:o,expected:"never",path:[{type:"object",origin:"key",input:r,key:o,value:r[o]}]});break}}}else st(this,"type",e,s);return e}}}function ce(n){return{kind:"schema",type:"string",reference:ce,expects:"string",async:!1,message:n,get"~standard"(){return Dt(this)},"~run"(t,e){return typeof t.value=="string"?t.typed=!0:st(this,"type",t,e),t}}}function Tn(...n){return{...n[0],pipe:n,get"~standard"(){return Dt(this)},"~run"(t,e){for(const s of n)if(s.kind!=="metadata"){if(t.issues&&(s.kind==="schema"||s.kind==="transformation")){t.typed=!1;break}(!t.issues||!e.abortEarly&&!e.abortPipeEarly)&&(t=s["~run"](t,e))}return t}}}function Mi(n,t,e){const s=n["~run"]({value:t},Yn(e));return{typed:s.typed,success:!s.issues,output:s.value,issues:s.issues}}const te=K(Mt({discard:K(ce(),""),hand:K(ce(),""),score:K(ae(),25e3)}),{discard:"",hand:"",score:25e3}),xi=Mt({[E.E]:te,[E.S]:te,[E.W]:te,[E.N]:te}),ct={round:k.E1,sticks:{reach:0,dead:0},doras:E.S,front:E.E},$i=K(Mt({round:K(xe(Object.keys(Fe)),ct.round),sticks:K(Mt({reach:K(Tn(ae(),Me(0,""),Re(9,"")),ct.sticks.reach),dead:K(Tn(ae(),Me(0,""),Re(9,"")),ct.sticks.dead)}),ct.sticks),doras:K(ce(),ct.doras),front:K(xe(Object.keys(de)),ct.front)}),ct),Pi=Mt({...xi.entries,board:$i}),Qn=n=>{const t=ts(n);return es(t)},ts=n=>{const t=Hi(n),e=Mi(Pi,t);if(!e.success)throw e.issues;return e.output},Hi=n=>{const t="table",e="board",s=n.split(`
13
- `).map(a=>a.trim()).filter(a=>a!="");if(s.length==0)throw new Error("empty input");const r=s.shift();if(!r.startsWith(t))throw new Error(`input does not start with table: ${r}`);const i={};let o=[E.E,E.S,E.W,E.N,e];for(;;){const a=s.shift();if(a==null)break;const c=o.find(l=>a.startsWith(l));if(c==null)throw new Error(`encountered unexpected line ${a}`);if(o=o.filter(l=>!a.startsWith(l)),c==e){const[l,u]=Bi([...s]);i.board=l;for(let h=0;h<u;h++)s.shift()}else{const[l,u]=Wi([...s]);i[c]=l;for(let h=0;h<u;h++)s.shift()}}return i},F=(n,t)=>n.replace(t,"").replace(":","").trim(),Wi=n=>{const t="hand",e="discard",s="score",r={};let i=0;for(;i<n.length;i++){const o=n[i];if(o.startsWith(t))r.hand=F(o,t);else if(o.startsWith(e))r.discard=F(o,e);else if(o.startsWith(s))r.score=Number(F(o,s));else break}return[r,i]},Bi=n=>{const t="doras",e="round",s="front",r="sticks",i="reach",o="dead",a={};let c=0;for(;c<n.length;c++){const l=n[c];if(l.startsWith(t))a.doras=F(l,t);else if(l.startsWith(e))a.round=F(l,e);else if(l.startsWith(s))a.front=F(l,s);else if(l.startsWith(r)){a.sticks={};const u=n[c+1]??"",h=n[c+2]??"";u.startsWith(i)&&(a.sticks.reach=Number(F(u,i))),u.startsWith(o)&&(a.sticks.dead=Number(F(u,o))),h.startsWith(i)&&(a.sticks.reach=Number(F(h,i))),h.startsWith(o)&&(a.sticks.dead=Number(F(h,o))),a.sticks.dead!=null&&c++,a.sticks.reach!=null&&c++}else break}return[a,c]},es=n=>{const t=n.board.front,e=Di(t),s=a=>n[a].discard.replace(/\r?\n/g,""),r={front:new W(s(e.front)).tiles(),right:new W(s(e.right)).tiles(),opposite:new W(s(e.opposite)).tiles(),left:new W(s(e.left)).tiles()},i={front:new W(n[e.front].hand).parse(),right:new W(n[e.right].hand).parse(),opposite:new W(n[e.opposite].hand).parse(),left:new W(n[e.left].hand).parse()},o={round:Fe[n.board.round],frontPlace:de[t],sticks:n.board.sticks,doras:new W(n.board.doras).tiles(),scores:{front:n[e.front].score,right:n[e.right].score,opposite:n[e.opposite].score,left:n[e.left].score}};return{discards:r,hands:i,scoreBoard:o}},Di=n=>({front:n,right:gt(n),opposite:gt(gt(n)),left:fe(n)});function*L(n){const t=n!=null&&n.filterBy&&n.filterBy.length>0?n==null?void 0:n.filterBy:Object.values(p);for(const e of t){if(n!=null&&n.skipBack&&e==p.BACK)continue;const s=e==p.Z?7:e==p.BACK?1:9;for(let r=1;r<=s;r++)yield[e,r]}}class ye{constructor(t,e=!1){_(this,"data");this.data={[p.M]:[0,0,0,0,0,0,0,0,0,0],[p.P]:[0,0,0,0,0,0,0,0,0,0],[p.S]:[0,0,0,0,0,0,0,0,0,0],[p.Z]:[0,0,0,0,0,0,0,0],[p.BACK]:["untouchable",0],called:[],reached:!1,tsumo:null},this.init(t,e)}init(t,e){const s=Array.isArray(t)?t:new W(t).parse();for(const r of s){if(r.isCalled()){this.data.called=[...this.called,r];continue}else if(r.is(b.TSUMO)){const i=r.tiles[0];this.inc([i]),this.data.tsumo=i;continue}else if(r.is(b.HAND)){this.inc(r.tiles);continue}else if(!Array.isArray(t)&&t.split("").every(i=>i===p.BACK)){this.inc(r.tiles);continue}else if(e){this.inc(r.tiles);continue}throw new Error(`unexpected block ${r.type} ${r.toString()}`)}}get hands(){const t=[];for(const[e,s]of L()){let r=this.get(e,s);e!=p.Z&&s==5&&this.get(e,0)>0&&(r-=this.get(e,0),t.push(new w(e,s,[y.RED])));for(let i=0;i<r;i++)t.push(new w(e,s))}if(this.drawn!=null){const e=this.drawn,s=t.findIndex(r=>r.equals(e));N(s>=0,`hand has drawn: ${this.drawn} but no tile in hands: ${t.join("")}`),t[s]=t[s].clone({add:y.TSUMO})}return t}toString(){const t=this.called.length>0?`${q}${this.called.join(q)}`:"",e=this.drawn?`${q}${this.drawn.toString()}`:"",s=this.hands.filter(i=>!i.has(y.TSUMO));return`${new kt(s).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 R))}sum(t){let e=0;for(const[s,r]of L({filterBy:[t]}))e+=this.get(s,r);return e}get(t,e){return t==p.BACK?this.data[t][1]:this.data[t][e]}inc(t){const e=[];for(const s of t){if(s.t!=p.BACK&&this.get(s.t,s.n)>=4||s.has(y.RED)&&this.get(s.t,0)>0)throw this.dec(e),new Error(`unable to increase ${s} in ${this.toString()}`);e.push(s),s.t==p.BACK?this.data[s.t][1]+=1:(this.data[s.t][s.n]+=1,s.has(y.RED)&&(this.data[s.t][0]+=1))}return e}dec(t){const e=[];for(const s of t){if(this.get(s.t,s.n)<1||s.has(y.RED)&&this.get(s.t,0)<=0)throw this.inc(e),new Error(`unable to decrease ${s.toString()} in ${this.toString()}`);if(e.push(s),s.t==p.BACK?this.data[s.t][1]-=1:(this.data[s.t][s.n]-=1,s.has(y.RED)&&(this.data[s.t][0]-=1)),C(s)&&this.get(s.t,5)==0&&this.get(s.t,0)>0){this.data[s.t][0]=0;const r=e.pop().clone({add:y.RED});e.push(r)}}return e}draw(t){const e=t.clone({add:y.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){const e=t.tiles.filter(s=>!s.has(y.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 R){this.dec(t.tiles),this.data.called=[...this.called,t],this.data.tsumo=null;return}if(t instanceof D){const e=this.data.called.findIndex(r=>r.is(b.PON)&&r.tiles[0].equals(t.tiles[0]));if(e==-1)throw new Error(`unable to find ${t.tiles[0]}`);let s=t.tiles[0];s=C(s)?s.clone({remove:y.RED}):s,this.dec([s]),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 ye(this.toString());return t.data.reached=this.data.reached,t}}class Xt{constructor(t){_(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(const[s,r]of L({skipBack:!0}))this.hand.get(s,r)==2&&t++,this.hand.get(s,r)==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(const s of Object.values(p)){if(s==p.BACK)continue;const r=s==p.Z?xt:G;for(const i of r)this.hand.get(s,i)>=1&&t++,this.hand.get(s,i)>=2&&e++}return e>=1?12-t:13-t}fourSetsOnePair(){const t=s=>{const r=[0,0,0];for(const[d,g]of L({filterBy:[p.Z]}))this.hand.get(d,g)>=3?r[0]++:this.hand.get(d,g)==2?r[1]++:this.hand.get(d,g)==1&&r[2]++;const i=[0,0,0],o=this.hand.get(p.BACK,0),a=o%3;i[0]=Math.floor(o/3),a==2?i[1]=1:a==1&&(i[2]=1);let c=13;const l=this.patternNumType(p.M),u=this.patternNumType(p.P),h=this.patternNumType(p.S);for(const d of[l.patternA,l.patternB])for(const g of[u.patternA,u.patternB])for(const f of[h.patternA,h.patternB]){const m=[this.hand.called.length,0,0];for(let S=0;S<3;S++)m[S]+=d[S]+g[S]+f[S]+r[S]+i[S];const A=this.calcCommon(m[0],m[1],m[2],s);A<c&&(c=A)}return c};let e=t(!1);for(const[s,r]of L())if(this.hand.get(s,r)>=2){const i=this.hand.dec(new Array(2).fill(new w(s,r))),o=t(!0);this.hand.inc(i),o<e&&(e=o)}return e}patternNumType(t,e=1){if(e>9)return this.groupRemainingTiles(t);let s=this.patternNumType(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 r=this.hand.dec([new w(t,e),new w(t,e+1),new w(t,e+2)]),i=this.patternNumType(t,e);this.hand.inc(r),i.patternA[0]++,i.patternB[0]++,(i.patternA[2]<s.patternA[2]||i.patternA[2]==s.patternA[2]&&i.patternA[1]<s.patternA[1])&&(s.patternA=i.patternA),(i.patternB[0]>s.patternB[0]||i.patternB[0]==s.patternB[0]&&i.patternB[1]>s.patternB[1])&&(s.patternB=i.patternB)}if(this.hand.get(t,e)>=3){const r=this.hand.dec(new Array(3).fill(new w(t,e))),i=this.patternNumType(t,e);this.hand.inc(r),i.patternA[0]++,i.patternB[0]++,(i.patternA[2]<s.patternA[2]||i.patternA[2]==s.patternA[2]&&i.patternA[1]<s.patternA[1])&&(s.patternA=i.patternA),(i.patternB[0]>s.patternB[0]||i.patternB[0]==s.patternB[0]&&i.patternB[1]>s.patternB[1])&&(s.patternB=i.patternB)}return s}groupRemainingTiles(t){let e=0,s=0,r=0;for(const[i,o]of L({filterBy:[t]}))r+=this.hand.get(i,o),o<=7&&this.hand.get(i,o+1)==0&&this.hand.get(i,o+2)==0&&(e+=r>>1,s+=r%2,r=0);return e+=r>>1,s+=r%2,{patternA:[0,e,s],patternB:[0,e,s]}}calcCommon(t,e,s,r){let i=r?4:5;return t>4&&(e+=t-4,t=4),t+e>4&&(s+=t+e-4,e=4-t),t+e+s>i&&(s=i-t-e),r&&e++,13-t*3-e*2-s}}class ns{constructor(t){_(this,"hand");this.hand=t}calc(t){return this.markDrawn([...this.sevenPairs(),...this.thirteenOrphans(),...this.nineGates(),...this.fourSetsOnePair()],t)}markDrawn(t,e){if(t.length==0)return[];const s=this.hand.drawn!=null||e.has(y.TSUMO)?y.TSUMO:y.RON,r=[];for(let o=0;o<t.length;o++){const a=t[o],c={};for(let l=0;l<a.length;l++){const u=a[l];if(u.isCalled())continue;const h=u.tiles.findIndex(g=>g.equals(e)&&e.has(y.RED)==g.has(y.RED));if(h<0)continue;const d=ss(u);c[d]||(c[d]=!0,r.push([o,l,h]))}}if(r.length==0)throw new Error(`found no tile ${e.toString()} in hands ${t[0].toString()}`);const i=[];for(const[o,a,c]of r){const u=[...t[o]],h=u[a],d=h.tiles[c].clone({add:s});u[a]=h.clone({replace:{idx:c,tile:d}}),i.push(u)}return i}sevenPairs(){if(this.hand.called.length>0)return[];const t=[];for(const[e,s]of L({skipBack:!0})){const r=this.hand.get(e,s);if(r==2){const i=this.hand.dec(new Array(2).fill(new w(e,s)));t.push(new H(i[0],i[1])),this.hand.inc(i)}else{if(r==0)continue;return[]}}return[t]}thirteenOrphans(){const t=[];let e=!1;for(const s of Object.values(p)){if(s==p.BACK)continue;const r=s==p.Z?xt:G;for(let i of r)if(this.hand.get(s,i)==1)t.push(new Ze(new w(s,i)));else if(this.hand.get(s,i)==2&&e==!1)t.unshift(new H(new w(s,i),new w(s,i))),e=!0;else return[]}return[t]}nineGates(){const t=(e,s,r)=>r.includes(this.hand.get(e,s));for(const e of Object.values(p)){if(e==p.BACK||e==p.Z)continue;const s=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]),r=this.hand.sum(e)==14;if(s&&r)return[[new kt(this.hand.hands)]]}return[]}fourSetsOnePair(){let t=[];for(const[e,s]of L())if(this.hand.get(e,s)>=2){const r=this.hand.dec(new Array(2).fill(new w(e,s))),i=this.patternAll().filter(o=>o.length==4).map(o=>(o.unshift(new H(r[0],r[1])),o));t=[...t,...i],this.hand.inc(r)}return t}patternAll(){const t=[this.handleNumType(p.M),this.handleNumType(p.P),this.handleNumType(p.S),this.handleZ(),this.handleBack(),[this.hand.called.concat()]].sort((s,r)=>r.length-s.length),e=t[0].concat();for(let s=0;s<e.length;s++)for(let r=1;r<t.length;r++)for(const i of t[r])e[s]=[...e[s],...i];return e}handleBack(){const t=p.BACK,e=this.hand.get(t,0);if(e<3)return[];const s=new w(t,0),r=Array(Math.floor(e/3)).fill(new z([s,s,s]));return r.length==0?[]:[r]}handleZ(){const t=[];for(const[e,s]of L({filterBy:[p.Z]})){if(this.hand.get(e,s)==0)continue;if(this.hand.get(e,s)!=3)return[];const r=new w(e,s);t.push(new z([r,r,r]))}return t.length==0?[]:[t]}handleNumType(t,e=1){if(e>9)return[];if(this.hand.get(t,e)==0)return this.handleNumType(t,e+1);const s=[];if(e<=7&&this.hand.get(t,e)>0&&this.hand.get(t,e+1)>0&&this.hand.get(t,e+2)>0){const r=this.hand.dec([new w(t,e),new w(t,e+1),new w(t,e+2)]);let i=this.handleNumType(t,e);this.hand.inc(r),i.length==0&&(i=[[]]);for(const o of i)o.unshift(new Q([r[0],r[1],r[2]])),s.push(o)}if(this.hand.get(t,e)==3){const r=this.hand.dec(new Array(3).fill(new w(t,e)));let i=this.handleNumType(t,e);this.hand.inc(r),i.length==0&&(i=[[]]);for(const o of i)o.unshift(new z([r[0],r[1],r[2]])),s.push(o)}return s}}const xt=[1,2,3,4,5,6,7],G=[1,9],zt=n=>{var e;const t=n.boardContext;return{...n,hand:n.hand.map(v.deserialize),boardContext:{...t,doraMarkers:t.doraMarkers.map(w.from),blindDoraMarkers:(e=t.blindDoraMarkers)==null?void 0:e.map(w.from)}}};class $e{constructor(t,e){_(this,"hand");_(this,"cfg");this.hand=t,this.cfg={doras:e.doraMarkers.map(s=>In(s)),blindDoras:e.blindDoraMarkers==null?[]:e.blindDoraMarkers.map(s=>In(s)),roundWind:w.from(e.round.substring(0,2)),myWind:w.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 s=[0,0],r=0;for(let f=0;f<e.length;f++){const m=e[f],A=m.points.reduce((S,O)=>S+O.double,0);A>s[0]?(r=f,s=[A,m.fu]):A==s[0]&&m.fu>s[1]&&(r=f,s=[A,m.fu])}const i=(f,m=100)=>Math.ceil(f/m)*m,o=s[1]!=25?i(s[1],10):25,a=s[0];let c=Math.min(o*2**(a+2),2e3);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=4e3;break;case 7:case 6:c=3e3;break;case 5:c=2e3;break}a>13&&a<26&&(c=8e3);const l=e[r].hand.some(f=>f.tiles.some(m=>m.has(y.TSUMO))),u=this.cfg.orig.myWind,h=u==E.E,d=$(0);if(l){const f=this.cfg.sticks.dead*100;if(h){const m=i(c*2);d[E.E]+=m*3+f*3,d[E.S]-=m+f,d[E.W]-=m+f,d[E.N]-=m+f}else for(const m of Object.values(E)){if(m==u)continue;const A=m==E.E?2:1,S=i(c*A)+f;d[m]-=S,d[u]+=S}}else{const f=this.cfg.sticks.dead*300;if(this.cfg.orig.ronWind==null)throw new Error("ron wind is not specified in the parameters");const A=i(c*(h?6:4))+f;d[u]+=A,d[this.cfg.orig.ronWind]-=A}return d[u]+=1e3*this.cfg.sticks.reach,{deltas:d,sum:a,fu:o,points:e[r].points,point:d[u],hand:e[r].hand,boardContext:this.cfg.orig}}calcPatterns(t){const e=[];if(t.length==0)return e;for(const s of t){const r=[...this.dA13(s),...this.dB13(s),...this.dC13(s),...this.dD13(s),...this.dE13(s),...this.dF13(s),...this.dG13(s),...this.dH13(s),...this.dI13(s),...this.dJ13(s),...this.dK13(s)];r.length!=0&&e.push({points:r,fu:30,hand:s})}if(e.length>0)return e;for(const s of t){const r=this.calcFu(s),i=[...this.dA1(s),...this.dB1(s),...this.dC1(s),...this.dD1(s),...this.dE1(s),...this.dF1(s),...this.dG1(s),...this.dH1(s),...this.dI1(s),...this.dJ1(s),...this.dK1(s),...this.dA2(s),...this.dB2(s),...this.dC2(s),...this.dD2(s),...this.dE2(s),...this.dF2(s),...this.dG2(s),...this.dH2(s),...this.dI2(s),...this.dJ2(s),...this.dA3(s),...this.dB3(s),...this.dC3(s),...this.dA6(s)];i.length!=0&&(i.push(...this.dX1(s)),e.push({points:i,fu:r,hand:s}))}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(s=>s.tiles.some(r=>r.has(y.TSUMO)))?[{name:"門前清自摸和",double:1}]:[])}dC1(t){if(this.minus()!=0)return[];const e="平和",s=this.calcFu(t);return s==20?[{name:e,double:1}]:!t.some(r=>r.tiles.some(i=>i.has(y.TSUMO)))&&s==30?[{name:e,double:1}]:[]}dD1(t){return t.some(s=>s.tiles.some(r=>r.t==p.Z||G.includes(r.n)))?[]:[{name:"断么九",double:1}]}dE1(t){return this.minus()!=0?[]:vn(t)==1?[{name:"一盃口",double:1}]:[]}dF1(t){const e=[];return t.forEach(s=>{if(s instanceof H)return;const r=s.tiles[0];r.t==p.Z&&(r.equals(this.cfg.myWind)&&e.push({name:"自風",double:1}),r.equals(this.cfg.roundWind)?e.push({name:"場風",double:1}):r.n==5?e.push({name:"白",double:1}):r.n==6?e.push({name:"發",double:1}):r.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,s=0,r=0;for(const o of t)for(const a of o.tiles){for(const c of this.cfg.doras)a.equals(c)&&e++;for(const c of this.cfg.blindDoras)a.equals(c)&&s++;a.has(y.RED)&&r++}const i=[];return e>0&&i.push({name:"ドラ",double:e}),r>0&&i.push({name:"赤ドラ",double:r}),this.hand.reached&&s>0&&i.push({name:"裏ドラ",double:s}),i}dA2(t){return t.length==7?[{name:"七対子",double:2}]:[]}dB2(t){const e=s=>s instanceof Q||s instanceof Z;for(const s of t){if(!e(s))continue;const r=lt(s);if(r.t==p.Z)continue;const i=[p.M,p.P,p.S].filter(c=>c!=r.t),o=t.some(c=>{const l=new w(i[0],r.n);return e(c)&&l.equals(lt(c))}),a=t.some(c=>{const l=new w(i[1],r.n);return e(c)&&l.equals(lt(c))});if(o&&a)return[{name:"三色同順",double:2-this.minus()}]}return[]}dC2(t){return t.length==7?[]:t.every(s=>s instanceof R||s instanceof D||s instanceof Y||s instanceof z||s instanceof V||s instanceof H)?[{name:"対々和",double:2}]:[]}dD2(t){return this.minus()!=0?[]:t.filter(s=>(s instanceof R||s instanceof z)&&!s.tiles.some(r=>r.has(y.RON))).length>=3?[{name:"三暗刻",double:2}]:[]}dE2(t){return t.filter(s=>s instanceof R||s instanceof D||s instanceof Y).length>=3?[{name:"三槓子",double:2}]:[]}dF2(t){const e=s=>s instanceof R||s instanceof D||s instanceof Y||s instanceof z||s instanceof V;for(const s of t){if(!e(s))continue;const r=lt(s);if(r.t==p.Z)continue;const i=[p.M,p.P,p.S].filter(c=>c!=r.t),o=t.some(c=>{const l=new w(i[0],r.n);return e(c)&&l.equals(lt(c))}),a=t.some(c=>{const l=new w(i[1],r.n);return e(c)&&l.equals(lt(c))});if(o&&a)return[{name:"三色同刻",double:2}]}return[]}dG2(t){return t.filter(s=>{const r=s.tiles[0];return r.t==p.Z&&[5,6,7].includes(r.n)}).length==3?[{name:"小三元",double:2}]:[]}dH2(t){return t.every(s=>{const r=s.tiles[0].t==p.Z?xt:G;return s.tiles.every(i=>r.includes(i.n))})?[{name:"混老頭",double:2}]:[]}dI2(t){return t.length==7?[]:t.some(s=>s instanceof Q||s instanceof Z)?t.some(s=>s.tiles[0].t==p.Z)?t.every(s=>{const r=s.tiles[0].t==p.Z?xt:G;return s.tiles.some(i=>r.includes(i.n))})?[{name:"混全帯么九",double:2-this.minus()}]:[]:[]:[]}dJ2(t){const e={[p.M]:[0,0,0],[p.S]:[0,0,0],[p.P]:[0,0,0]};for(const s of t){const r=lt(s);r.t!=p.BACK&&r.t!=p.Z&&(s instanceof Q||s instanceof Z)&&(r.n==1?e[r.t][0]++:r.n==4?e[r.t][1]++:r.n==7&&e[r.t][2]++)}for(const s of Object.values(e))if(s[0]>0&&s[1]>0&&s[2]>0)return[{name:"一気通貫",double:2-this.minus()}];return[]}dA3(t){if(!t.some(s=>s.tiles[0].t==p.Z))return[];for(const s of Object.values(p))if(t.every(i=>i.tiles[0].t==p.Z||i.tiles[0].t==s))return[{name:"混一色",double:3-this.minus()}];return[]}dB3(t){return t.length==7?[]:t.some(s=>s instanceof Q||s instanceof Z)?t.some(s=>s.tiles[0].t==p.Z)?[]:t.every(s=>s.tiles.some(r=>G.includes(r.n)))?[{name:"純全帯么九色",double:3-this.minus()}]:[]:[]}dC3(t){return this.minus()!=0?[]:vn(t)==2?[{name:"ニ盃口",double:3}]:[]}dA6(t){if(t.some(e=>e.tiles[0].t==p.Z))return[];for(const e of Object.values(p)){if(e==p.Z)continue;if(t.every(r=>r.tiles[0].t==e))return[{name:"清一色",double:6-this.minus()}]}return[]}dA13(t){return t.length!=13?[]:t.some(s=>s instanceof H&&s.tiles.some(r=>r.has(y.TSUMO)||r.has(y.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(r=>r instanceof R||r instanceof z&&!r.tiles.some(i=>i.has(y.RON))||r instanceof H)?t.some(r=>r instanceof H&&r.tiles.every(i=>i.has(y.TSUMO)||i.has(y.RON)))?[{name:"四暗刻単騎待ち",double:26}]:[{name:"四暗刻",double:13}]:[]}dD13(t){if(t.length==13)return[];const e=[5,6,7];return t.filter(r=>!(r instanceof H)&&r.tiles.some(i=>i.t==p.Z&&e.includes(i.n))).length==3?[{name:"大三元",double:13}]:[]}dE13(t){return t.every(s=>s.tiles[0].t==p.Z)?[{name:"字一色",double:13}]:[]}dF13(t){return t.every(s=>s.tiles.every(r=>r.t!=p.Z&&G.includes(r.n)))?[{name:"清老頭",double:13}]:[]}dG13(t){return t.filter(s=>s instanceof R||s instanceof D||s instanceof Y).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(i=>i.tiles.some(o=>o.t==p.Z&&e.includes(o.n))).length==4?t.find(i=>i instanceof H).tiles.some(i=>i.t==p.Z&&e.includes(i.n))?[{name:"小四喜",double:13}]:[{name:"大四喜",double:13}]:[]}dI13(t){const e=s=>!!(s.equals(new w(p.Z,6))||s.t==p.S&&[2,3,4,6,8].includes(s.n));return t.every(s=>s.tiles.every(r=>e(r)))?[{name:"緑一色",double:13}]:[]}dJ13(t){return[]}dK13(t){return[]}calcFu(t){let s=20;const r=this.cfg.myWind.n,i=this.cfg.roundWind.n;if(t.length==7)return 25;const o=t.find(f=>f.tiles.some(m=>m.has(y.TSUMO)||m.has(y.RON))),a=this.minus()==1,c=o.tiles.some(f=>f.has(y.TSUMO)),l=(f,m)=>{const A=f.tiles[0];return A.t==p.Z&&[5,6,7].includes(A.n)||A.t==p.Z&&[r,i].includes(A.n)||G.includes(A.n)?m*2:m};for(const f of t)switch(!0){case f instanceof z:const m=f.tiles.some(A=>A.has(y.RON))?2:4;s+=l(f,m);break;case f instanceof V:s+=l(f,2);break;case(f instanceof Y||f instanceof D):s+=l(f,8);break;case f instanceof R:s+=l(f,16);break}s+=(f=>{if(f instanceof z)return 0;if(f instanceof H)return 2;const m=f.tiles,A=m.findIndex(S=>S.has(y.TSUMO)||S.has(y.RON));return A==1||A==0&&m[2].n==9||A==2&&m[0].n==1?2:0})(o);const d=t.find(f=>f instanceof H).tiles[0];d.t==p.Z&&([5,6,7].includes(d.n)&&(s+=2),d.n==i&&(s+=2),d.n==r&&(s+=2));let g=!1;return!a&&s==20&&(g=!0),c&&!g&&(s+=2),!c&&!a&&(s+=10),!c&&!a&&s==30&&(g=!0),a&&s==20&&(s=30),s}}const ss=n=>n.tiles.reduce((t,e)=>`${t}${e.n}${e.t}`,""),vn=n=>{const t={};for(const s of n){if(!(s instanceof Q))continue;const r=ss(s);t[r]==null?t[r]=1:t[r]++}let e=0;for(const s in t)t[s]>=2&&e++;return e},lt=n=>[...n.tiles].sort(Jt)[0],In=n=>{const t=n.n,e=n.t;return new w(e,t%9+1)};class $t{static calcCandidates(t,e,s){N(e.length>0,"choices to discard is zero");const r=new Map;let i=1/0;for(const o of e){const a=t.dec([o]),c=$t.candidateTiles(t,s);t.inc(a);const l=s!=null&&s.arrangeRed&&o.has(y.RED)?o.clone({removeAll:!0}):o.has(y.RED)?o.clone({removeAll:!0,add:y.RED}):o.clone({removeAll:!0});c.shanten<i?(r.clear(),r.set(l.toString(),{shanten:c.shanten,candidates:c.candidates,tile:l}),i=c.shanten):c.shanten==i&&r.set(l.toString(),{shanten:c.shanten,candidates:c.candidates,tile:l})}return Array.from(r.values())}static candidateTiles(t,e){let s=1/0,r=[];const i=new Xt(t);for(const[o,a]of L({skipBack:!0,filterBy:e==null?void 0:e.typeFilter})){if(t.get(o,a)>=4)continue;const c=new w(o,a),l=t.inc([c]),u=e!=null&&e.fourSetsOnePair?i.fourSetsOnePair():i.calc();t.dec(l),u<s?(s=u,r=[c]):u==s&&r.push(c)}return{shanten:s,candidates:r}}}const Pe=()=>{const n=new Set;return{on(t){n.add(t)},off(t){n.delete(t)},offAll(){n.clear()},emit(t){n.forEach(e=>e(t))}}};function rs(n){var i;const t=["RON","DAI_KAN","PON","CHI"],e=n.map(o=>o.choices),r=os(e,t).map(o=>n[o]);return{events:r,type:as(t,(i=r[0])==null?void 0:i.choices)}}function is(n){var i;const t=["TSUMO","REACH","AN_KAN","SHO_KAN","DRAWN_GAME_BY_NINE_ORPHANS","DISCARD"],e=n.map(o=>o.choices),r=os(e,t).map(o=>n[o]);return{events:r,type:as(t,(i=r[0])==null?void 0:i.choices)}}function os(n,t){let e=[],s=Number.POSITIVE_INFINITY;for(let r=0;r<n.length;r++){const i=n[r];if(Ki(i,t)){const o=Li(t,i);o<s?(s=o,e=[r]):o===s&&e.push(r)}}return e}function Ki(n,t){return t.some(e=>!!n[e])}function Li(n,t){for(let e=0;e<n.length;e++){const s=n[e];if(t[s])return e}return Number.POSITIVE_INFINITY}function as(n,t){if(t==null)return!1;for(const e of n)if(t[e])return e;return!1}const jt=()=>{const n=Pe(),t=Pe(),e={emit:n.emit,on:r=>t.on(r)},s={emit:t.emit,on:r=>n.on(r)};return[e,s]},cs=()=>{const n=Pe();return{emit:s=>{n.emit(s)},on:s=>{n.on(s)}}};class Gt{constructor(t){_(this,"reachValue",1e3);_(this,"m");this.m=structuredClone(t)}get summary(){return structuredClone(this.m)}reach(t){this.m[t]-=this.reachValue}update(t,e){for(let s in e){const r=e[s],i=t[r];this.m[s]+=i}}}class Zt{constructor(t,e){_(this,"pToW",{});_(this,"wToP",$(""));_(this,"round");_(this,"sticks");this.round=(e==null?void 0:e.round)??k.E1,this.sticks=structuredClone(e==null?void 0:e.sticks)??{reach:0,dead:0},this.pToW=structuredClone(t);for(let s in this.pToW)this.wToP[this.pToW[s]]=s}update(){for(let t in this.pToW){const e=fe(this.pToW[t]);this.pToW[t]=e,this.wToP[e]=t}}incrementDeadStick(){this.sticks.dead++}incrementReachStick(){this.sticks.reach++}nextRound(){const t=Ft(this.round);this.round=t,this.update()}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 nn(n){for(let t=n.length-1;t>0;t--){const e=Math.floor(Math.random()*(t+1));[n[t],n[e]]=[n[e],n[t]]}return n}class ls{constructor(t=!1){_(this,"c");_(this,"safeMap",$({},!0));this.disable=t,this.c=this.initial()}get(t){return t.t==p.BACK?0:this.c[t.t][t.n]}dec(...t){if(!this.disable){for(let e of t)if(e.t!=p.BACK){if(this.get(e)<=0)throw new Error(`[counter] cannot decrease ${e.toString()} due to zero`);this.c[e.t][e.n]-=1,e.has(y.RED)&&(this.c[e.t][0]-=1)}}}addTileToSafeMap(t,e){this.disable||(this.safeMap[e][this.key(t.t,t.n)]=!0)}isSafeTile(t,e,s){return this.safeMap[s][this.key(t,e)]}key(t,e){return`${t}${e}`}reset(){this.c=this.initial()}initial(){return{[p.M]:[1,4,4,4,4,4,4,4,4,4],[p.S]:[1,4,4,4,4,4,4,4,4,4],[p.P]:[1,4,4,4,4,4,4,4,4,4],[p.Z]:[0,4,4,4,4,4,4,4]}}}class sn{constructor(){_(this,"m",[])}discard(t,e){this.m.push({w:e,t})}discards(t){return t==null?[...this.m]:this.m.filter(e=>e.w==t)}get lastTile(){const t=this.m.at(-1);return N(t!=null,`lastTile is null(${t}). river: ${JSON.stringify(this.m,null,2)}`),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 s=0;s<4;s++)if(!e.equals(t[s].t))return!1;return!0}}function zi(){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 ji(){const n=zi();if(n.__xstate__)return n.__xstate__}const Ui=n=>{if(typeof window>"u")return;const t=ji();t&&t.register(n)};class On{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 us=".",Fi="",hs="",Gi="#",Zi="*",ds="xstate.init",He="xstate.stop";function Vi(n,t){return{type:`xstate.after.${n}.${t}`}}function We(n,t){return{type:`xstate.done.state.${n}`,output:t}}function Ji(n,t){return{type:`xstate.done.actor.${n}`,output:t,actorId:n}}function Xi(n,t){return{type:`xstate.error.actor.${n}`,error:t,actorId:n}}function fs(n){return{type:ds,input:n}}function X(n){setTimeout(()=>{throw n})}const Yi=typeof Symbol=="function"&&Symbol.observable||"@@observable";function ps(n,t){const e=kn(n),s=kn(t);return typeof s=="string"?typeof e=="string"?s===e:!1:typeof e=="string"?e in s:Object.keys(e).every(r=>r in s?ps(e[r],s[r]):!1)}function rn(n){if(ys(n))return n;const t=[];let e="";for(let s=0;s<n.length;s++){switch(n.charCodeAt(s)){case 92:e+=n[s+1],s++;continue;case 46:t.push(e),e="";continue}e+=n[s]}return t.push(e),t}function kn(n){if(Mo(n))return n.value;if(typeof n!="string")return n;const t=rn(n);return qi(t)}function qi(n){if(n.length===1)return n[0];const t={};let e=t;for(let s=0;s<n.length-1;s++)if(s===n.length-2)e[n[s]]=n[s+1];else{const r=e;e={},r[n[s]]=e}return t}function Cn(n,t){const e={},s=Object.keys(n);for(let r=0;r<s.length;r++){const i=s[r];e[i]=t(n[i],i,n,r)}return e}function gs(n){return ys(n)?n:[n]}function et(n){return n===void 0?[]:gs(n)}function Be(n,t,e,s){return typeof n=="function"?n({context:t,event:e,self:s}):n}function ys(n){return Array.isArray(n)}function Qi(n){return n.type.startsWith("xstate.error.actor")}function Tt(n){return gs(n).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function ms(n){if(!(n===void 0||n===Fi))return et(n)}function De(n,t,e){var i,o,a;const s=typeof n=="object",r=s?n:void 0;return{next:(i=s?n.next:n)==null?void 0:i.bind(r),error:(o=s?n.error:t)==null?void 0:o.bind(r),complete:(a=s?n.complete:e)==null?void 0:a.bind(r)}}function Rn(n,t){return`${t}.${n}`}function on(n,t){const e=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!e)return n.implementations.actors[t];const[,s,r]=e,o=n.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}function Mn(n,t){return`${n.sessionId}.${t}`}let to=0;function eo(n,t){const e=new Map,s=new Map,r=new WeakMap,i=new Set,o={},{clock:a,logger:c}=t,l={schedule:(d,g,f,m,A=Math.random().toString(36).slice(2))=>{const S={source:d,target:g,event:f,delay:m,id:A,startedAt:Date.now()},O=Mn(d,A);h._snapshot._scheduledEvents[O]=S;const M=a.setTimeout(()=>{delete o[O],delete h._snapshot._scheduledEvents[O],h._relay(d,g,f)},m);o[O]=M},cancel:(d,g)=>{const f=Mn(d,g),m=o[f];delete o[f],delete h._snapshot._scheduledEvents[f],m!==void 0&&a.clearTimeout(m)},cancelAll:d=>{for(const g in h._snapshot._scheduledEvents){const f=h._snapshot._scheduledEvents[g];f.source===d&&l.cancel(d,f.id)}}},u=d=>{if(!i.size)return;const g={...d,rootId:n.sessionId};i.forEach(f=>{var m;return(m=f.next)==null?void 0:m.call(f,g)})},h={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${to++}`,_register:(d,g)=>(e.set(d,g),d),_unregister:d=>{e.delete(d.sessionId);const g=r.get(d);g!==void 0&&(s.delete(g),r.delete(d))},get:d=>s.get(d),_set:(d,g)=>{const f=s.get(d);if(f&&f!==g)throw new Error(`Actor with system ID '${d}' already exists.`);s.set(d,g),r.set(g,d)},inspect:d=>{const g=De(d);return i.add(g),{unsubscribe(){i.delete(g)}}},_sendInspectionEvent:u,_relay:(d,g,f)=>{h._sendInspectionEvent({type:"@xstate.event",sourceRef:d,actorRef:g,event:f}),g._send(f)},scheduler:l,getSnapshot:()=>({_scheduledEvents:{...h._snapshot._scheduledEvents}}),start:()=>{const d=h._snapshot._scheduledEvents;h._snapshot._scheduledEvents={};for(const g in d){const{source:f,target:m,event:A,delay:S,id:O}=d[g];l.schedule(f,m,A,S,O)}},_clock:a,_logger:c};return h}let Se=!1;const an=1;let P=function(n){return n[n.NotStarted=0]="NotStarted",n[n.Running=1]="Running",n[n.Stopped=2]="Stopped",n}({});const no={clock:{setTimeout:(n,t)=>setTimeout(n,t),clearTimeout:n=>clearTimeout(n)},logger:console.log.bind(console),devTools:!1};class so{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 On(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=P.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 s={...no,...e},{clock:r,logger:i,parent:o,syncSnapshot:a,id:c,systemId:l,inspect:u}=s;this.system=o?o.system:eo(this,{clock:r,logger:i}),u&&!o&&this.system.inspect(De(u)),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=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:h=>{this._deferred.push(h)},system:this.system,stopChild:h=>{if(h._parent!==this)throw new Error(`Cannot stop child actor ${h.id} of ${this.id} because it is not a child`);h._stop()},emit:h=>{const d=this.eventListeners.get(h.type),g=this.eventListeners.get("*");if(!d&&!g)return;const f=[...d?d.values():[],...g?g.values():[]];for(const m of f)m(h)},actionExecutor:h=>{const d=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:h.type,params:h.params}}),!h.exec)return;const g=Se;try{Se=!0,h.exec(h.info,h.params)}finally{Se=g}};this._processingStatus===P.Running?d():this._deferred.push(d)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),l&&(this._systemId=l,this.system._set(l,this)),this._initState((e==null?void 0:e.snapshot)??(e==null?void 0:e.state)),l&&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(s){this._snapshot={status:"error",output:void 0,error:s}}}update(t,e){var r,i;this._snapshot=t;let s;for(;s=this._deferred.shift();)try{s()}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{(r=o.next)==null||r.call(o,t)}catch(a){X(a)}break;case"done":for(const o of this.observers)try{(i=o.next)==null||i.call(o,t)}catch(a){X(a)}this._stopProcedure(),this._complete(),this._doneEvent=Ji(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,s){var i;const r=De(t,e,s);if(this._processingStatus!==P.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(i=r.complete)==null||i.call(r)}catch(o){X(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)X(o);else try{r.error(o)}catch(a){X(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,e){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const r=e.bind(void 0);return s.add(r),{unsubscribe:()=>{s.delete(r)}}}start(){if(this._processingStatus===P.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=P.Running;const t=fs(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(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(r){s={err:r}}if(s){const{err:r}=s;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(e,t),t.type===He&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===P.Stopped?this:(this.mailbox.clear(),this._processingStatus===P.NotStarted?(this._processingStatus=P.Stopped,this):(this.mailbox.enqueue({type:He}),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(s){X(s)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||X(t);return}let e=!1;for(const s of this.observers){const r=s.error;e||(e=!r);try{r==null||r(t)}catch(i){X(i)}}this.observers.clear(),e&&X(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Xi(this.id,t))}_stopProcedure(){return this._processingStatus!==P.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new On(this._process.bind(this)),this._processingStatus=P.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==P.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:Ui)(this)}toJSON(){return{xstate$$type:an,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[Yi](){return this}getSnapshot(){return this._snapshot}}function Pt(n,...[t]){return new so(n,t)}function ro(n,t,e,s,{sendId:r}){const i=typeof r=="function"?r(e,s):r;return[t,{sendId:i},void 0]}function io(n,t){n.defer(()=>{n.system.scheduler.cancel(n.self,t.sendId)})}function oo(n){function t(e,s){}return t.type="xstate.cancel",t.sendId=n,t.resolve=ro,t.execute=io,t}function ao(n,t,e,s,{id:r,systemId:i,src:o,input:a,syncSnapshot:c}){const l=typeof o=="string"?on(t.machine,o):o,u=typeof r=="function"?r(e):r;let h,d;return l&&(d=typeof a=="function"?a({context:t.context,event:e.event,self:n.self}):a,h=Pt(l,{id:u,src:o,parent:n.self,syncSnapshot:c,systemId:i,input:d})),[wt(t,{children:{...t.children,[u]:h}}),{id:r,systemId:i,actorRef:h,src:o,input:d},void 0]}function co(n,{actorRef:t}){t&&n.defer(()=>{t._processingStatus!==P.Stopped&&t.start()})}function lo(...[n,{id:t,systemId:e,input:s,syncSnapshot:r=!1}={}]){function i(o,a){}return i.type="xstate.spawnChild",i.id=t,i.systemId=e,i.src=n,i.input=s,i.syncSnapshot=r,i.resolve=ao,i.execute=co,i}function uo(n,t,e,s,{actorRef:r}){const i=typeof r=="function"?r(e,s):r,o=typeof i=="string"?t.children[i]:i;let a=t.children;return o&&(a={...a},delete a[o.id]),[wt(t,{children:a}),o,void 0]}function ho(n,t){if(t){if(n.system._unregister(t),t._processingStatus!==P.Running){n.stopChild(t);return}n.defer(()=>{n.stopChild(t)})}}function ws(n){function t(e,s){}return t.type="xstate.stopChild",t.actorRef=n,t.resolve=uo,t.execute=ho,t}function cn(n,t,e,s){const{machine:r}=s,i=typeof n=="function",o=i?n:r.implementations.guards[typeof n=="string"?n:n.type];if(!i&&!o)throw new Error(`Guard '${typeof n=="string"?n:n.type}' is not implemented.'.`);if(typeof o!="function")return cn(o,t,e,s);const a={context:t,event:e},c=i||typeof n=="string"?void 0:"params"in n?typeof n.params=="function"?n.params({context:t,event:e}):n.params:void 0;return"check"in o?o.check(s,a,o):o(a,c)}const ln=n=>n.type==="atomic"||n.type==="final";function Ht(n){return Object.values(n.states).filter(t=>t.type!=="history")}function Yt(n,t){const e=[];if(t===n)return e;let s=n.parent;for(;s&&s!==t;)e.push(s),s=s.parent;return e}function le(n){const t=new Set(n),e=_s(t);for(const s of t)if(s.type==="compound"&&(!e.get(s)||!e.get(s).length))xn(s).forEach(r=>t.add(r));else if(s.type==="parallel"){for(const r of Ht(s))if(r.type!=="history"&&!t.has(r)){const i=xn(r);for(const o of i)t.add(o)}}for(const s of t){let r=s.parent;for(;r;)t.add(r),r=r.parent}return t}function bs(n,t){const e=t.get(n);if(!e)return{};if(n.type==="compound"){const r=e[0];if(r){if(ln(r))return r.key}else return{}}const s={};for(const r of e)s[r.key]=bs(r,t);return s}function _s(n){const t=new Map;for(const e of n)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 Es(n,t){const e=le(t);return bs(n,_s(e))}function un(n,t){return t.type==="compound"?Ht(t).some(e=>e.type==="final"&&n.has(e)):t.type==="parallel"?Ht(t).every(e=>un(n,e)):t.type==="final"}const me=n=>n[0]===Gi;function fo(n,t){return n.transitions.get(t)||[...n.transitions.keys()].filter(s=>{if(s===Zi)return!0;if(!s.endsWith(".*"))return!1;const r=s.split("."),i=t.split(".");for(let o=0;o<r.length;o++){const a=r[o],c=i[o];if(a==="*")return o===r.length-1;if(a!==c)return!1}return!0}).sort((s,r)=>r.length-s.length).flatMap(s=>n.transitions.get(s))}function po(n){const t=n.config.after;if(!t)return[];const e=r=>{const i=Vi(r,n.id),o=i.type;return n.entry.push(Lo(i,{id:o,delay:r})),n.exit.push(oo(o)),o};return Object.keys(t).flatMap(r=>{const i=t[r],o=typeof i=="string"?{target:i}:i,a=Number.isNaN(+r)?r:+r,c=e(a);return et(o).map(l=>({...l,event:c,delay:a}))}).map(r=>{const{delay:i}=r;return{...dt(n,r.event,r),delay:i}})}function dt(n,t,e){const s=ms(e.target),r=e.reenter??!1,i=mo(n,s),o={...e,actions:et(e.actions),guard:e.guard,target:i,source:n,reenter:r,eventType:t,toJSON:()=>({...o,source:`#${n.id}`,target:i?i.map(a=>`#${a.id}`):void 0})};return o}function go(n){const t=new Map;if(n.config.on)for(const e of Object.keys(n.config.on)){if(e===hs)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=n.config.on[e];t.set(e,Tt(s).map(r=>dt(n,e,r)))}if(n.config.onDone){const e=`xstate.done.state.${n.id}`;t.set(e,Tt(n.config.onDone).map(s=>dt(n,e,s)))}for(const e of n.invoke){if(e.onDone){const s=`xstate.done.actor.${e.id}`;t.set(s,Tt(e.onDone).map(r=>dt(n,s,r)))}if(e.onError){const s=`xstate.error.actor.${e.id}`;t.set(s,Tt(e.onError).map(r=>dt(n,s,r)))}if(e.onSnapshot){const s=`xstate.snapshot.${e.id}`;t.set(s,Tt(e.onSnapshot).map(r=>dt(n,s,r)))}}for(const e of n.after){let s=t.get(e.eventType);s||(s=[],t.set(e.eventType,s)),s.push(e)}return t}function yo(n,t){const e=typeof t=="string"?n.states[t]:t?n.states[t.target]:void 0;if(!e&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${n.id}`);const s={source:n,actions:!t||typeof t=="string"?[]:et(t.actions),eventType:null,reenter:!1,target:e?[e]:[],toJSON:()=>({...s,source:`#${n.id}`,target:e?[`#${e.id}`]:[]})};return s}function mo(n,t){if(t!==void 0)return t.map(e=>{if(typeof e!="string")return e;if(me(e))return n.machine.getStateNodeById(e);const s=e[0]===us;if(s&&!n.parent)return ue(n,e.slice(1));const r=s?n.key+e:e;if(n.parent)try{return ue(n.parent,r)}catch(i){throw new Error(`Invalid transition definition for state node '${n.id}':
13
+ `).map(a=>a.trim()).filter(a=>a!="");if(s.length==0)throw new Error("empty input");const r=s.shift();if(!r.startsWith(t))throw new Error(`input does not start with table: ${r}`);const i={};let o=[E.E,E.S,E.W,E.N,e];for(;;){const a=s.shift();if(a==null)break;const c=o.find(l=>a.startsWith(l));if(c==null)throw new Error(`encountered unexpected line ${a}`);if(o=o.filter(l=>!a.startsWith(l)),c==e){const[l,u]=Bi([...s]);i.board=l;for(let h=0;h<u;h++)s.shift()}else{const[l,u]=Wi([...s]);i[c]=l;for(let h=0;h<u;h++)s.shift()}}return i},F=(n,t)=>n.replace(t,"").replace(":","").trim(),Wi=n=>{const t="hand",e="discard",s="score",r={};let i=0;for(;i<n.length;i++){const o=n[i];if(o.startsWith(t))r.hand=F(o,t);else if(o.startsWith(e))r.discard=F(o,e);else if(o.startsWith(s))r.score=Number(F(o,s));else break}return[r,i]},Bi=n=>{const t="doras",e="round",s="front",r="sticks",i="reach",o="dead",a={};let c=0;for(;c<n.length;c++){const l=n[c];if(l.startsWith(t))a.doras=F(l,t);else if(l.startsWith(e))a.round=F(l,e);else if(l.startsWith(s))a.front=F(l,s);else if(l.startsWith(r)){a.sticks={};const u=n[c+1]??"",h=n[c+2]??"";u.startsWith(i)&&(a.sticks.reach=Number(F(u,i))),u.startsWith(o)&&(a.sticks.dead=Number(F(u,o))),h.startsWith(i)&&(a.sticks.reach=Number(F(h,i))),h.startsWith(o)&&(a.sticks.dead=Number(F(h,o))),a.sticks.dead!=null&&c++,a.sticks.reach!=null&&c++}else break}return[a,c]},es=n=>{const t=n.board.front,e=Di(t),s=a=>n[a].discard.replace(/\r?\n/g,""),r={front:new W(s(e.front)).tiles(),right:new W(s(e.right)).tiles(),opposite:new W(s(e.opposite)).tiles(),left:new W(s(e.left)).tiles()},i={front:new W(n[e.front].hand).parse(),right:new W(n[e.right].hand).parse(),opposite:new W(n[e.opposite].hand).parse(),left:new W(n[e.left].hand).parse()},o={round:Fe[n.board.round],frontPlace:de[t],sticks:n.board.sticks,doras:new W(n.board.doras).tiles(),scores:{front:n[e.front].score,right:n[e.right].score,opposite:n[e.opposite].score,left:n[e.left].score}};return{discards:r,hands:i,scoreBoard:o}},Di=n=>({front:n,right:gt(n),opposite:gt(gt(n)),left:fe(n)});function*L(n){const t=n!=null&&n.filterBy&&n.filterBy.length>0?n==null?void 0:n.filterBy:Object.values(p);for(const e of t){if(n!=null&&n.skipBack&&e==p.BACK)continue;const s=e==p.Z?7:e==p.BACK?1:9;for(let r=1;r<=s;r++)yield[e,r]}}class ye{constructor(t,e=!1){_(this,"data");this.data={[p.M]:[0,0,0,0,0,0,0,0,0,0],[p.P]:[0,0,0,0,0,0,0,0,0,0],[p.S]:[0,0,0,0,0,0,0,0,0,0],[p.Z]:[0,0,0,0,0,0,0,0],[p.BACK]:["untouchable",0],called:[],reached:!1,tsumo:null},this.init(t,e)}init(t,e){const s=Array.isArray(t)?t:new W(t).parse();for(const r of s){if(r.isCalled()){this.data.called=[...this.called,r];continue}else if(r.is(b.TSUMO)){const i=r.tiles[0];this.inc([i]),this.data.tsumo=i;continue}else if(r.is(b.HAND)){this.inc(r.tiles);continue}else if(!Array.isArray(t)&&t.split("").every(i=>i===p.BACK)){this.inc(r.tiles);continue}else if(e){this.inc(r.tiles);continue}throw new Error(`unexpected block ${r.type} ${r.toString()}`)}}get hands(){const t=[];for(const[e,s]of L()){let r=this.get(e,s);e!=p.Z&&s==5&&this.get(e,0)>0&&(r-=this.get(e,0),t.push(new w(e,s,[y.RED])));for(let i=0;i<r;i++)t.push(new w(e,s))}if(this.drawn!=null){const e=this.drawn,s=t.findIndex(r=>r.equals(e));N(s>=0,`hand has drawn: ${this.drawn} but no tile in hands: ${t.join("")}`),t[s]=t[s].clone({add:y.TSUMO})}return t}toString(){const t=this.called.length>0?`${q}${this.called.join(q)}`:"",e=this.drawn?`${q}${this.drawn.toString()}`:"",s=this.hands.filter(i=>!i.has(y.TSUMO));return`${new kt(s).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 R))}sum(t){let e=0;for(const[s,r]of L({filterBy:[t]}))e+=this.get(s,r);return e}get(t,e){return t==p.BACK?this.data[t][1]:this.data[t][e]}inc(t){const e=[];for(const s of t){if(s.t!=p.BACK&&this.get(s.t,s.n)>=4||s.has(y.RED)&&this.get(s.t,0)>0)throw this.dec(e),new Error(`unable to increase ${s} in ${this.toString()}`);e.push(s),s.t==p.BACK?this.data[s.t][1]+=1:(this.data[s.t][s.n]+=1,s.has(y.RED)&&(this.data[s.t][0]+=1))}return e}dec(t){const e=[];for(const s of t){if(this.get(s.t,s.n)<1||s.has(y.RED)&&this.get(s.t,0)<=0)throw this.inc(e),new Error(`unable to decrease ${s.toString()} in ${this.toString()}`);if(e.push(s),s.t==p.BACK?this.data[s.t][1]-=1:(this.data[s.t][s.n]-=1,s.has(y.RED)&&(this.data[s.t][0]-=1)),C(s)&&this.get(s.t,5)==0&&this.get(s.t,0)>0){this.data[s.t][0]=0;const r=e.pop().clone({add:y.RED});e.push(r)}}return e}draw(t){const e=t.clone({add:y.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){const e=t.tiles.filter(s=>!s.has(y.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 R){this.dec(t.tiles),this.data.called=[...this.called,t],this.data.tsumo=null;return}if(t instanceof D){const e=this.data.called.findIndex(r=>r.is(b.PON)&&r.tiles[0].equals(t.tiles[0]));if(e==-1)throw new Error(`unable to find ${t.tiles[0]}`);let s=t.tiles[0];s=C(s)?s.clone({remove:y.RED}):s,this.dec([s]),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 ye(this.toString());return t.data.reached=this.data.reached,t}}class Xt{constructor(t){_(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(const[s,r]of L({skipBack:!0}))this.hand.get(s,r)==2&&t++,this.hand.get(s,r)==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(const s of Object.values(p)){if(s==p.BACK)continue;const r=s==p.Z?xt:G;for(const i of r)this.hand.get(s,i)>=1&&t++,this.hand.get(s,i)>=2&&e++}return e>=1?12-t:13-t}fourSetsOnePair(){const t=s=>{const r=[0,0,0];for(const[d,g]of L({filterBy:[p.Z]}))this.hand.get(d,g)>=3?r[0]++:this.hand.get(d,g)==2?r[1]++:this.hand.get(d,g)==1&&r[2]++;const i=[0,0,0],o=this.hand.get(p.BACK,0),a=o%3;i[0]=Math.floor(o/3),a==2?i[1]=1:a==1&&(i[2]=1);let c=13;const l=this.patternNumType(p.M),u=this.patternNumType(p.P),h=this.patternNumType(p.S);for(const d of[l.patternA,l.patternB])for(const g of[u.patternA,u.patternB])for(const f of[h.patternA,h.patternB]){const m=[this.hand.called.length,0,0];for(let S=0;S<3;S++)m[S]+=d[S]+g[S]+f[S]+r[S]+i[S];const A=this.calcCommon(m[0],m[1],m[2],s);A<c&&(c=A)}return c};let e=t(!1);for(const[s,r]of L())if(this.hand.get(s,r)>=2){const i=this.hand.dec(new Array(2).fill(new w(s,r))),o=t(!0);this.hand.inc(i),o<e&&(e=o)}return e}patternNumType(t,e=1){if(e>9)return this.groupRemainingTiles(t);let s=this.patternNumType(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 r=this.hand.dec([new w(t,e),new w(t,e+1),new w(t,e+2)]),i=this.patternNumType(t,e);this.hand.inc(r),i.patternA[0]++,i.patternB[0]++,(i.patternA[2]<s.patternA[2]||i.patternA[2]==s.patternA[2]&&i.patternA[1]<s.patternA[1])&&(s.patternA=i.patternA),(i.patternB[0]>s.patternB[0]||i.patternB[0]==s.patternB[0]&&i.patternB[1]>s.patternB[1])&&(s.patternB=i.patternB)}if(this.hand.get(t,e)>=3){const r=this.hand.dec(new Array(3).fill(new w(t,e))),i=this.patternNumType(t,e);this.hand.inc(r),i.patternA[0]++,i.patternB[0]++,(i.patternA[2]<s.patternA[2]||i.patternA[2]==s.patternA[2]&&i.patternA[1]<s.patternA[1])&&(s.patternA=i.patternA),(i.patternB[0]>s.patternB[0]||i.patternB[0]==s.patternB[0]&&i.patternB[1]>s.patternB[1])&&(s.patternB=i.patternB)}return s}groupRemainingTiles(t){let e=0,s=0,r=0;for(const[i,o]of L({filterBy:[t]}))r+=this.hand.get(i,o),o<=7&&this.hand.get(i,o+1)==0&&this.hand.get(i,o+2)==0&&(e+=r>>1,s+=r%2,r=0);return e+=r>>1,s+=r%2,{patternA:[0,e,s],patternB:[0,e,s]}}calcCommon(t,e,s,r){let i=r?4:5;return t>4&&(e+=t-4,t=4),t+e>4&&(s+=t+e-4,e=4-t),t+e+s>i&&(s=i-t-e),r&&e++,13-t*3-e*2-s}}class ns{constructor(t){_(this,"hand");this.hand=t}calc(t){return this.markDrawn([...this.sevenPairs(),...this.thirteenOrphans(),...this.nineGates(),...this.fourSetsOnePair()],t)}markDrawn(t,e){if(t.length==0)return[];const s=this.hand.drawn!=null||e.has(y.TSUMO)?y.TSUMO:y.RON,r=[];for(let o=0;o<t.length;o++){const a=t[o],c={};for(let l=0;l<a.length;l++){const u=a[l];if(u.isCalled())continue;const h=u.tiles.findIndex(g=>g.equals(e)&&e.has(y.RED)==g.has(y.RED));if(h<0)continue;const d=ss(u);c[d]||(c[d]=!0,r.push([o,l,h]))}}if(r.length==0)throw new Error(`found no tile ${e.toString()} in hands ${t[0].toString()}`);const i=[];for(const[o,a,c]of r){const u=[...t[o]],h=u[a],d=h.tiles[c].clone({add:s});u[a]=h.clone({replace:{idx:c,tile:d}}),i.push(u)}return i}sevenPairs(){if(this.hand.called.length>0)return[];const t=[];for(const[e,s]of L({skipBack:!0})){const r=this.hand.get(e,s);if(r==2){const i=this.hand.dec(new Array(2).fill(new w(e,s)));t.push(new H(i[0],i[1])),this.hand.inc(i)}else{if(r==0)continue;return[]}}return[t]}thirteenOrphans(){const t=[];let e=!1;for(const s of Object.values(p)){if(s==p.BACK)continue;const r=s==p.Z?xt:G;for(let i of r)if(this.hand.get(s,i)==1)t.push(new Ze(new w(s,i)));else if(this.hand.get(s,i)==2&&e==!1)t.unshift(new H(new w(s,i),new w(s,i))),e=!0;else return[]}return[t]}nineGates(){const t=(e,s,r)=>r.includes(this.hand.get(e,s));for(const e of Object.values(p)){if(e==p.BACK||e==p.Z)continue;const s=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]),r=this.hand.sum(e)==14;if(s&&r)return[[new kt(this.hand.hands)]]}return[]}fourSetsOnePair(){let t=[];for(const[e,s]of L())if(this.hand.get(e,s)>=2){const r=this.hand.dec(new Array(2).fill(new w(e,s))),i=this.patternAll().filter(o=>o.length==4).map(o=>(o.unshift(new H(r[0],r[1])),o));t=[...t,...i],this.hand.inc(r)}return t}patternAll(){const t=[this.handleNumType(p.M),this.handleNumType(p.P),this.handleNumType(p.S),this.handleZ(),this.handleBack(),[this.hand.called.concat()]].sort((s,r)=>r.length-s.length),e=t[0].concat();for(let s=0;s<e.length;s++)for(let r=1;r<t.length;r++)for(const i of t[r])e[s]=[...e[s],...i];return e}handleBack(){const t=p.BACK,e=this.hand.get(t,0);if(e<3)return[];const s=new w(t,0),r=Array(Math.floor(e/3)).fill(new z([s,s,s]));return r.length==0?[]:[r]}handleZ(){const t=[];for(const[e,s]of L({filterBy:[p.Z]})){if(this.hand.get(e,s)==0)continue;if(this.hand.get(e,s)!=3)return[];const r=new w(e,s);t.push(new z([r,r,r]))}return t.length==0?[]:[t]}handleNumType(t,e=1){if(e>9)return[];if(this.hand.get(t,e)==0)return this.handleNumType(t,e+1);const s=[];if(e<=7&&this.hand.get(t,e)>0&&this.hand.get(t,e+1)>0&&this.hand.get(t,e+2)>0){const r=this.hand.dec([new w(t,e),new w(t,e+1),new w(t,e+2)]);let i=this.handleNumType(t,e);this.hand.inc(r),i.length==0&&(i=[[]]);for(const o of i)o.unshift(new Q([r[0],r[1],r[2]])),s.push(o)}if(this.hand.get(t,e)==3){const r=this.hand.dec(new Array(3).fill(new w(t,e)));let i=this.handleNumType(t,e);this.hand.inc(r),i.length==0&&(i=[[]]);for(const o of i)o.unshift(new z([r[0],r[1],r[2]])),s.push(o)}return s}}const xt=[1,2,3,4,5,6,7],G=[1,9],zt=n=>{var e;const t=n.boardContext;return{...n,hand:n.hand.map(v.deserialize),boardContext:{...t,doraMarkers:t.doraMarkers.map(w.from),blindDoraMarkers:(e=t.blindDoraMarkers)==null?void 0:e.map(w.from)}}};class $e{constructor(t,e){_(this,"hand");_(this,"cfg");this.hand=t,this.cfg={doras:e.doraMarkers.map(s=>In(s)),blindDoras:e.blindDoraMarkers==null?[]:e.blindDoraMarkers.map(s=>In(s)),roundWind:w.from(e.round.substring(0,2)),myWind:w.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,roundUp8000:e.roundUp8000??!1,orig:e}}calc(...t){const e=this.calcPatterns(t);if(e.length==0)return!1;let s=[0,0],r=0;for(let f=0;f<e.length;f++){const m=e[f],A=m.points.reduce((S,O)=>S+O.double,0);A>s[0]?(r=f,s=[A,m.fu]):A==s[0]&&m.fu>s[1]&&(r=f,s=[A,m.fu])}const i=(f,m=100)=>Math.ceil(f/m)*m,o=s[1]!=25?i(s[1],10):25,a=s[0];let c=Math.min(o*2**(a+2),2e3);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=4e3;break;case 7:case 6:c=3e3;break;case 5:c=2e3;break}a>13&&a<26&&(c=8e3),this.cfg.roundUp8000&&(o==30&&a==4||o==60&&a==3)&&(c=2e3);const l=e[r].hand.some(f=>f.tiles.some(m=>m.has(y.TSUMO))),u=this.cfg.orig.myWind,h=u==E.E,d=$(0);if(l){const f=this.cfg.sticks.dead*100;if(h){const m=i(c*2);d[E.E]+=m*3+f*3,d[E.S]-=m+f,d[E.W]-=m+f,d[E.N]-=m+f}else for(const m of Object.values(E)){if(m==u)continue;const A=m==E.E?2:1,S=i(c*A)+f;d[m]-=S,d[u]+=S}}else{const f=this.cfg.sticks.dead*300;if(this.cfg.orig.ronWind==null)throw new Error("ron wind is not specified in the parameters");const A=i(c*(h?6:4))+f;d[u]+=A,d[this.cfg.orig.ronWind]-=A}return d[u]+=1e3*this.cfg.sticks.reach,{deltas:d,sum:a,fu:o,points:e[r].points,point:d[u],hand:e[r].hand,boardContext:this.cfg.orig}}calcPatterns(t){const e=[];if(t.length==0)return e;for(const s of t){const r=[...this.dA13(s),...this.dB13(s),...this.dC13(s),...this.dD13(s),...this.dE13(s),...this.dF13(s),...this.dG13(s),...this.dH13(s),...this.dI13(s),...this.dJ13(s),...this.dK13(s)];r.length!=0&&e.push({points:r,fu:30,hand:s})}if(e.length>0)return e;for(const s of t){const r=this.calcFu(s),i=[...this.dA1(s),...this.dB1(s),...this.dC1(s),...this.dD1(s),...this.dE1(s),...this.dF1(s),...this.dG1(s),...this.dH1(s),...this.dI1(s),...this.dJ1(s),...this.dK1(s),...this.dA2(s),...this.dB2(s),...this.dC2(s),...this.dD2(s),...this.dE2(s),...this.dF2(s),...this.dG2(s),...this.dH2(s),...this.dI2(s),...this.dJ2(s),...this.dA3(s),...this.dB3(s),...this.dC3(s),...this.dA6(s)];i.length!=0&&(i.push(...this.dX1(s)),e.push({points:i,fu:r,hand:s}))}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(s=>s.tiles.some(r=>r.has(y.TSUMO)))?[{name:"門前清自摸和",double:1}]:[])}dC1(t){if(this.minus()!=0)return[];const e="平和",s=this.calcFu(t);return s==20?[{name:e,double:1}]:!t.some(r=>r.tiles.some(i=>i.has(y.TSUMO)))&&s==30?[{name:e,double:1}]:[]}dD1(t){return t.some(s=>s.tiles.some(r=>r.t==p.Z||G.includes(r.n)))?[]:[{name:"断么九",double:1}]}dE1(t){return this.minus()!=0?[]:vn(t)==1?[{name:"一盃口",double:1}]:[]}dF1(t){const e=[];return t.forEach(s=>{if(s instanceof H)return;const r=s.tiles[0];r.t==p.Z&&(r.equals(this.cfg.myWind)&&e.push({name:"自風",double:1}),r.equals(this.cfg.roundWind)?e.push({name:"場風",double:1}):r.n==5?e.push({name:"白",double:1}):r.n==6?e.push({name:"發",double:1}):r.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,s=0,r=0;for(const o of t)for(const a of o.tiles){for(const c of this.cfg.doras)a.equals(c)&&e++;for(const c of this.cfg.blindDoras)a.equals(c)&&s++;a.has(y.RED)&&r++}const i=[];return e>0&&i.push({name:"ドラ",double:e}),r>0&&i.push({name:"赤ドラ",double:r}),this.hand.reached&&s>0&&i.push({name:"裏ドラ",double:s}),i}dA2(t){return t.length==7?[{name:"七対子",double:2}]:[]}dB2(t){const e=s=>s instanceof Q||s instanceof Z;for(const s of t){if(!e(s))continue;const r=lt(s);if(r.t==p.Z)continue;const i=[p.M,p.P,p.S].filter(c=>c!=r.t),o=t.some(c=>{const l=new w(i[0],r.n);return e(c)&&l.equals(lt(c))}),a=t.some(c=>{const l=new w(i[1],r.n);return e(c)&&l.equals(lt(c))});if(o&&a)return[{name:"三色同順",double:2-this.minus()}]}return[]}dC2(t){return t.length==7?[]:t.every(s=>s instanceof R||s instanceof D||s instanceof Y||s instanceof z||s instanceof V||s instanceof H)?[{name:"対々和",double:2}]:[]}dD2(t){return this.minus()!=0?[]:t.filter(s=>(s instanceof R||s instanceof z)&&!s.tiles.some(r=>r.has(y.RON))).length>=3?[{name:"三暗刻",double:2}]:[]}dE2(t){return t.filter(s=>s instanceof R||s instanceof D||s instanceof Y).length>=3?[{name:"三槓子",double:2}]:[]}dF2(t){const e=s=>s instanceof R||s instanceof D||s instanceof Y||s instanceof z||s instanceof V;for(const s of t){if(!e(s))continue;const r=lt(s);if(r.t==p.Z)continue;const i=[p.M,p.P,p.S].filter(c=>c!=r.t),o=t.some(c=>{const l=new w(i[0],r.n);return e(c)&&l.equals(lt(c))}),a=t.some(c=>{const l=new w(i[1],r.n);return e(c)&&l.equals(lt(c))});if(o&&a)return[{name:"三色同刻",double:2}]}return[]}dG2(t){return t.filter(s=>{const r=s.tiles[0];return r.t==p.Z&&[5,6,7].includes(r.n)}).length==3?[{name:"小三元",double:2}]:[]}dH2(t){return t.every(s=>{const r=s.tiles[0].t==p.Z?xt:G;return s.tiles.every(i=>r.includes(i.n))})?[{name:"混老頭",double:2}]:[]}dI2(t){return t.length==7?[]:t.some(s=>s instanceof Q||s instanceof Z)?t.some(s=>s.tiles[0].t==p.Z)?t.every(s=>{const r=s.tiles[0].t==p.Z?xt:G;return s.tiles.some(i=>r.includes(i.n))})?[{name:"混全帯么九",double:2-this.minus()}]:[]:[]:[]}dJ2(t){const e={[p.M]:[0,0,0],[p.S]:[0,0,0],[p.P]:[0,0,0]};for(const s of t){const r=lt(s);r.t!=p.BACK&&r.t!=p.Z&&(s instanceof Q||s instanceof Z)&&(r.n==1?e[r.t][0]++:r.n==4?e[r.t][1]++:r.n==7&&e[r.t][2]++)}for(const s of Object.values(e))if(s[0]>0&&s[1]>0&&s[2]>0)return[{name:"一気通貫",double:2-this.minus()}];return[]}dA3(t){if(!t.some(s=>s.tiles[0].t==p.Z))return[];for(const s of Object.values(p))if(t.every(i=>i.tiles[0].t==p.Z||i.tiles[0].t==s))return[{name:"混一色",double:3-this.minus()}];return[]}dB3(t){return t.length==7?[]:t.some(s=>s instanceof Q||s instanceof Z)?t.some(s=>s.tiles[0].t==p.Z)?[]:t.every(s=>s.tiles.some(r=>G.includes(r.n)))?[{name:"純全帯么九色",double:3-this.minus()}]:[]:[]}dC3(t){return this.minus()!=0?[]:vn(t)==2?[{name:"ニ盃口",double:3}]:[]}dA6(t){if(t.some(e=>e.tiles[0].t==p.Z))return[];for(const e of Object.values(p)){if(e==p.Z)continue;if(t.every(r=>r.tiles[0].t==e))return[{name:"清一色",double:6-this.minus()}]}return[]}dA13(t){return t.length!=13?[]:t.some(s=>s instanceof H&&s.tiles.some(r=>r.has(y.TSUMO)||r.has(y.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(r=>r instanceof R||r instanceof z&&!r.tiles.some(i=>i.has(y.RON))||r instanceof H)?t.some(r=>r instanceof H&&r.tiles.every(i=>i.has(y.TSUMO)||i.has(y.RON)))?[{name:"四暗刻単騎待ち",double:26}]:[{name:"四暗刻",double:13}]:[]}dD13(t){if(t.length==13)return[];const e=[5,6,7];return t.filter(r=>!(r instanceof H)&&r.tiles.some(i=>i.t==p.Z&&e.includes(i.n))).length==3?[{name:"大三元",double:13}]:[]}dE13(t){return t.every(s=>s.tiles[0].t==p.Z)?[{name:"字一色",double:13}]:[]}dF13(t){return t.every(s=>s.tiles.every(r=>r.t!=p.Z&&G.includes(r.n)))?[{name:"清老頭",double:13}]:[]}dG13(t){return t.filter(s=>s instanceof R||s instanceof D||s instanceof Y).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(i=>i.tiles.some(o=>o.t==p.Z&&e.includes(o.n))).length==4?t.find(i=>i instanceof H).tiles.some(i=>i.t==p.Z&&e.includes(i.n))?[{name:"小四喜",double:13}]:[{name:"大四喜",double:13}]:[]}dI13(t){const e=s=>!!(s.equals(new w(p.Z,6))||s.t==p.S&&[2,3,4,6,8].includes(s.n));return t.every(s=>s.tiles.every(r=>e(r)))?[{name:"緑一色",double:13}]:[]}dJ13(t){return[]}dK13(t){return[]}calcFu(t){let s=20;const r=this.cfg.myWind.n,i=this.cfg.roundWind.n;if(t.length==7)return 25;const o=t.find(f=>f.tiles.some(m=>m.has(y.TSUMO)||m.has(y.RON))),a=this.minus()==1,c=o.tiles.some(f=>f.has(y.TSUMO)),l=(f,m)=>{const A=f.tiles[0];return A.t==p.Z&&[5,6,7].includes(A.n)||A.t==p.Z&&[r,i].includes(A.n)||G.includes(A.n)?m*2:m};for(const f of t)switch(!0){case f instanceof z:const m=f.tiles.some(A=>A.has(y.RON))?2:4;s+=l(f,m);break;case f instanceof V:s+=l(f,2);break;case(f instanceof Y||f instanceof D):s+=l(f,8);break;case f instanceof R:s+=l(f,16);break}s+=(f=>{if(f instanceof z)return 0;if(f instanceof H)return 2;const m=f.tiles,A=m.findIndex(S=>S.has(y.TSUMO)||S.has(y.RON));return A==1||A==0&&m[2].n==9||A==2&&m[0].n==1?2:0})(o);const d=t.find(f=>f instanceof H).tiles[0];d.t==p.Z&&([5,6,7].includes(d.n)&&(s+=2),d.n==i&&(s+=2),d.n==r&&(s+=2));let g=!1;return!a&&s==20&&(g=!0),c&&!g&&(s+=2),!c&&!a&&(s+=10),!c&&!a&&s==30&&(g=!0),a&&s==20&&(s=30),s}}const ss=n=>n.tiles.reduce((t,e)=>`${t}${e.n}${e.t}`,""),vn=n=>{const t={};for(const s of n){if(!(s instanceof Q))continue;const r=ss(s);t[r]==null?t[r]=1:t[r]++}let e=0;for(const s in t)t[s]>=2&&e++;return e},lt=n=>[...n.tiles].sort(Jt)[0],In=n=>{const t=n.n,e=n.t;return new w(e,t%9+1)};class $t{static calcCandidates(t,e,s){N(e.length>0,"choices to discard is zero");const r=new Map;let i=1/0;for(const o of e){const a=t.dec([o]),c=$t.candidateTiles(t,s);t.inc(a);const l=s!=null&&s.arrangeRed&&o.has(y.RED)?o.clone({removeAll:!0}):o.has(y.RED)?o.clone({removeAll:!0,add:y.RED}):o.clone({removeAll:!0});c.shanten<i?(r.clear(),r.set(l.toString(),{shanten:c.shanten,candidates:c.candidates,tile:l}),i=c.shanten):c.shanten==i&&r.set(l.toString(),{shanten:c.shanten,candidates:c.candidates,tile:l})}return Array.from(r.values())}static candidateTiles(t,e){let s=1/0,r=[];const i=new Xt(t);for(const[o,a]of L({skipBack:!0,filterBy:e==null?void 0:e.typeFilter})){if(t.get(o,a)>=4)continue;const c=new w(o,a),l=t.inc([c]),u=e!=null&&e.fourSetsOnePair?i.fourSetsOnePair():i.calc();t.dec(l),u<s?(s=u,r=[c]):u==s&&r.push(c)}return{shanten:s,candidates:r}}}const Pe=()=>{const n=new Set;return{on(t){n.add(t)},off(t){n.delete(t)},offAll(){n.clear()},emit(t){n.forEach(e=>e(t))}}};function rs(n){var i;const t=["RON","DAI_KAN","PON","CHI"],e=n.map(o=>o.choices),r=os(e,t).map(o=>n[o]);return{events:r,type:as(t,(i=r[0])==null?void 0:i.choices)}}function is(n){var i;const t=["TSUMO","REACH","AN_KAN","SHO_KAN","DRAWN_GAME_BY_NINE_ORPHANS","DISCARD"],e=n.map(o=>o.choices),r=os(e,t).map(o=>n[o]);return{events:r,type:as(t,(i=r[0])==null?void 0:i.choices)}}function os(n,t){let e=[],s=Number.POSITIVE_INFINITY;for(let r=0;r<n.length;r++){const i=n[r];if(Ki(i,t)){const o=Li(t,i);o<s?(s=o,e=[r]):o===s&&e.push(r)}}return e}function Ki(n,t){return t.some(e=>!!n[e])}function Li(n,t){for(let e=0;e<n.length;e++){const s=n[e];if(t[s])return e}return Number.POSITIVE_INFINITY}function as(n,t){if(t==null)return!1;for(const e of n)if(t[e])return e;return!1}const jt=()=>{const n=Pe(),t=Pe(),e={emit:n.emit,on:r=>t.on(r)},s={emit:t.emit,on:r=>n.on(r)};return[e,s]},cs=()=>{const n=Pe();return{emit:s=>{n.emit(s)},on:s=>{n.on(s)}}};class Gt{constructor(t){_(this,"reachValue",1e3);_(this,"m");this.m=structuredClone(t)}get summary(){return structuredClone(this.m)}reach(t){this.m[t]-=this.reachValue}update(t,e){for(let s in e){const r=e[s],i=t[r];this.m[s]+=i}}}class Zt{constructor(t,e){_(this,"pToW",{});_(this,"wToP",$(""));_(this,"round");_(this,"sticks");this.round=(e==null?void 0:e.round)??k.E1,this.sticks=structuredClone(e==null?void 0:e.sticks)??{reach:0,dead:0},this.pToW=structuredClone(t);for(let s in this.pToW)this.wToP[this.pToW[s]]=s}update(){for(let t in this.pToW){const e=fe(this.pToW[t]);this.pToW[t]=e,this.wToP[e]=t}}incrementDeadStick(){this.sticks.dead++}incrementReachStick(){this.sticks.reach++}nextRound(){const t=Ft(this.round);this.round=t,this.update()}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 nn(n){for(let t=n.length-1;t>0;t--){const e=Math.floor(Math.random()*(t+1));[n[t],n[e]]=[n[e],n[t]]}return n}class ls{constructor(t=!1){_(this,"c");_(this,"safeMap",$({},!0));this.disable=t,this.c=this.initial()}get(t){return t.t==p.BACK?0:this.c[t.t][t.n]}dec(...t){if(!this.disable){for(let e of t)if(e.t!=p.BACK){if(this.get(e)<=0)throw new Error(`[counter] cannot decrease ${e.toString()} due to zero`);this.c[e.t][e.n]-=1,e.has(y.RED)&&(this.c[e.t][0]-=1)}}}addTileToSafeMap(t,e){this.disable||(this.safeMap[e][this.key(t.t,t.n)]=!0)}isSafeTile(t,e,s){return this.safeMap[s][this.key(t,e)]}key(t,e){return`${t}${e}`}reset(){this.c=this.initial()}initial(){return{[p.M]:[1,4,4,4,4,4,4,4,4,4],[p.S]:[1,4,4,4,4,4,4,4,4,4],[p.P]:[1,4,4,4,4,4,4,4,4,4],[p.Z]:[0,4,4,4,4,4,4,4]}}}class sn{constructor(){_(this,"m",[])}discard(t,e){this.m.push({w:e,t})}discards(t){return t==null?[...this.m]:this.m.filter(e=>e.w==t)}get lastTile(){const t=this.m.at(-1);return N(t!=null,`lastTile is null(${t}). river: ${JSON.stringify(this.m,null,2)}`),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 s=0;s<4;s++)if(!e.equals(t[s].t))return!1;return!0}}function zi(){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 ji(){const n=zi();if(n.__xstate__)return n.__xstate__}const Ui=n=>{if(typeof window>"u")return;const t=ji();t&&t.register(n)};class On{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 us=".",Fi="",hs="",Gi="#",Zi="*",ds="xstate.init",He="xstate.stop";function Vi(n,t){return{type:`xstate.after.${n}.${t}`}}function We(n,t){return{type:`xstate.done.state.${n}`,output:t}}function Ji(n,t){return{type:`xstate.done.actor.${n}`,output:t,actorId:n}}function Xi(n,t){return{type:`xstate.error.actor.${n}`,error:t,actorId:n}}function fs(n){return{type:ds,input:n}}function X(n){setTimeout(()=>{throw n})}const Yi=typeof Symbol=="function"&&Symbol.observable||"@@observable";function ps(n,t){const e=kn(n),s=kn(t);return typeof s=="string"?typeof e=="string"?s===e:!1:typeof e=="string"?e in s:Object.keys(e).every(r=>r in s?ps(e[r],s[r]):!1)}function rn(n){if(ys(n))return n;const t=[];let e="";for(let s=0;s<n.length;s++){switch(n.charCodeAt(s)){case 92:e+=n[s+1],s++;continue;case 46:t.push(e),e="";continue}e+=n[s]}return t.push(e),t}function kn(n){if(Mo(n))return n.value;if(typeof n!="string")return n;const t=rn(n);return qi(t)}function qi(n){if(n.length===1)return n[0];const t={};let e=t;for(let s=0;s<n.length-1;s++)if(s===n.length-2)e[n[s]]=n[s+1];else{const r=e;e={},r[n[s]]=e}return t}function Cn(n,t){const e={},s=Object.keys(n);for(let r=0;r<s.length;r++){const i=s[r];e[i]=t(n[i],i,n,r)}return e}function gs(n){return ys(n)?n:[n]}function et(n){return n===void 0?[]:gs(n)}function Be(n,t,e,s){return typeof n=="function"?n({context:t,event:e,self:s}):n}function ys(n){return Array.isArray(n)}function Qi(n){return n.type.startsWith("xstate.error.actor")}function Tt(n){return gs(n).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function ms(n){if(!(n===void 0||n===Fi))return et(n)}function De(n,t,e){var i,o,a;const s=typeof n=="object",r=s?n:void 0;return{next:(i=s?n.next:n)==null?void 0:i.bind(r),error:(o=s?n.error:t)==null?void 0:o.bind(r),complete:(a=s?n.complete:e)==null?void 0:a.bind(r)}}function Rn(n,t){return`${t}.${n}`}function on(n,t){const e=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!e)return n.implementations.actors[t];const[,s,r]=e,o=n.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[s]:o).src}function Mn(n,t){return`${n.sessionId}.${t}`}let to=0;function eo(n,t){const e=new Map,s=new Map,r=new WeakMap,i=new Set,o={},{clock:a,logger:c}=t,l={schedule:(d,g,f,m,A=Math.random().toString(36).slice(2))=>{const S={source:d,target:g,event:f,delay:m,id:A,startedAt:Date.now()},O=Mn(d,A);h._snapshot._scheduledEvents[O]=S;const M=a.setTimeout(()=>{delete o[O],delete h._snapshot._scheduledEvents[O],h._relay(d,g,f)},m);o[O]=M},cancel:(d,g)=>{const f=Mn(d,g),m=o[f];delete o[f],delete h._snapshot._scheduledEvents[f],m!==void 0&&a.clearTimeout(m)},cancelAll:d=>{for(const g in h._snapshot._scheduledEvents){const f=h._snapshot._scheduledEvents[g];f.source===d&&l.cancel(d,f.id)}}},u=d=>{if(!i.size)return;const g={...d,rootId:n.sessionId};i.forEach(f=>{var m;return(m=f.next)==null?void 0:m.call(f,g)})},h={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${to++}`,_register:(d,g)=>(e.set(d,g),d),_unregister:d=>{e.delete(d.sessionId);const g=r.get(d);g!==void 0&&(s.delete(g),r.delete(d))},get:d=>s.get(d),_set:(d,g)=>{const f=s.get(d);if(f&&f!==g)throw new Error(`Actor with system ID '${d}' already exists.`);s.set(d,g),r.set(g,d)},inspect:d=>{const g=De(d);return i.add(g),{unsubscribe(){i.delete(g)}}},_sendInspectionEvent:u,_relay:(d,g,f)=>{h._sendInspectionEvent({type:"@xstate.event",sourceRef:d,actorRef:g,event:f}),g._send(f)},scheduler:l,getSnapshot:()=>({_scheduledEvents:{...h._snapshot._scheduledEvents}}),start:()=>{const d=h._snapshot._scheduledEvents;h._snapshot._scheduledEvents={};for(const g in d){const{source:f,target:m,event:A,delay:S,id:O}=d[g];l.schedule(f,m,A,S,O)}},_clock:a,_logger:c};return h}let Se=!1;const an=1;let P=function(n){return n[n.NotStarted=0]="NotStarted",n[n.Running=1]="Running",n[n.Stopped=2]="Stopped",n}({});const no={clock:{setTimeout:(n,t)=>setTimeout(n,t),clearTimeout:n=>clearTimeout(n)},logger:console.log.bind(console),devTools:!1};class so{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 On(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=P.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 s={...no,...e},{clock:r,logger:i,parent:o,syncSnapshot:a,id:c,systemId:l,inspect:u}=s;this.system=o?o.system:eo(this,{clock:r,logger:i}),u&&!o&&this.system.inspect(De(u)),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=s,this.src=s.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:h=>{this._deferred.push(h)},system:this.system,stopChild:h=>{if(h._parent!==this)throw new Error(`Cannot stop child actor ${h.id} of ${this.id} because it is not a child`);h._stop()},emit:h=>{const d=this.eventListeners.get(h.type),g=this.eventListeners.get("*");if(!d&&!g)return;const f=[...d?d.values():[],...g?g.values():[]];for(const m of f)m(h)},actionExecutor:h=>{const d=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:h.type,params:h.params}}),!h.exec)return;const g=Se;try{Se=!0,h.exec(h.info,h.params)}finally{Se=g}};this._processingStatus===P.Running?d():this._deferred.push(d)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),l&&(this._systemId=l,this.system._set(l,this)),this._initState((e==null?void 0:e.snapshot)??(e==null?void 0:e.state)),l&&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(s){this._snapshot={status:"error",output:void 0,error:s}}}update(t,e){var r,i;this._snapshot=t;let s;for(;s=this._deferred.shift();)try{s()}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{(r=o.next)==null||r.call(o,t)}catch(a){X(a)}break;case"done":for(const o of this.observers)try{(i=o.next)==null||i.call(o,t)}catch(a){X(a)}this._stopProcedure(),this._complete(),this._doneEvent=Ji(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,s){var i;const r=De(t,e,s);if(this._processingStatus!==P.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(i=r.complete)==null||i.call(r)}catch(o){X(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)X(o);else try{r.error(o)}catch(a){X(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,e){let s=this.eventListeners.get(t);s||(s=new Set,this.eventListeners.set(t,s));const r=e.bind(void 0);return s.add(r),{unsubscribe:()=>{s.delete(r)}}}start(){if(this._processingStatus===P.Running)return this;this._syncSnapshot&&this.subscribe({next:s=>{s.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:s})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=P.Running;const t=fs(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(s){return this._snapshot={...this._snapshot,status:"error",error:s},this._error(s),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(r){s={err:r}}if(s){const{err:r}=s;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(e,t),t.type===He&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===P.Stopped?this:(this.mailbox.clear(),this._processingStatus===P.NotStarted?(this._processingStatus=P.Stopped,this):(this.mailbox.enqueue({type:He}),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(s){X(s)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||X(t);return}let e=!1;for(const s of this.observers){const r=s.error;e||(e=!r);try{r==null||r(t)}catch(i){X(i)}}this.observers.clear(),e&&X(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Xi(this.id,t))}_stopProcedure(){return this._processingStatus!==P.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new On(this._process.bind(this)),this._processingStatus=P.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==P.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:Ui)(this)}toJSON(){return{xstate$$type:an,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[Yi](){return this}getSnapshot(){return this._snapshot}}function Pt(n,...[t]){return new so(n,t)}function ro(n,t,e,s,{sendId:r}){const i=typeof r=="function"?r(e,s):r;return[t,{sendId:i},void 0]}function io(n,t){n.defer(()=>{n.system.scheduler.cancel(n.self,t.sendId)})}function oo(n){function t(e,s){}return t.type="xstate.cancel",t.sendId=n,t.resolve=ro,t.execute=io,t}function ao(n,t,e,s,{id:r,systemId:i,src:o,input:a,syncSnapshot:c}){const l=typeof o=="string"?on(t.machine,o):o,u=typeof r=="function"?r(e):r;let h,d;return l&&(d=typeof a=="function"?a({context:t.context,event:e.event,self:n.self}):a,h=Pt(l,{id:u,src:o,parent:n.self,syncSnapshot:c,systemId:i,input:d})),[wt(t,{children:{...t.children,[u]:h}}),{id:r,systemId:i,actorRef:h,src:o,input:d},void 0]}function co(n,{actorRef:t}){t&&n.defer(()=>{t._processingStatus!==P.Stopped&&t.start()})}function lo(...[n,{id:t,systemId:e,input:s,syncSnapshot:r=!1}={}]){function i(o,a){}return i.type="xstate.spawnChild",i.id=t,i.systemId=e,i.src=n,i.input=s,i.syncSnapshot=r,i.resolve=ao,i.execute=co,i}function uo(n,t,e,s,{actorRef:r}){const i=typeof r=="function"?r(e,s):r,o=typeof i=="string"?t.children[i]:i;let a=t.children;return o&&(a={...a},delete a[o.id]),[wt(t,{children:a}),o,void 0]}function ho(n,t){if(t){if(n.system._unregister(t),t._processingStatus!==P.Running){n.stopChild(t);return}n.defer(()=>{n.stopChild(t)})}}function ws(n){function t(e,s){}return t.type="xstate.stopChild",t.actorRef=n,t.resolve=uo,t.execute=ho,t}function cn(n,t,e,s){const{machine:r}=s,i=typeof n=="function",o=i?n:r.implementations.guards[typeof n=="string"?n:n.type];if(!i&&!o)throw new Error(`Guard '${typeof n=="string"?n:n.type}' is not implemented.'.`);if(typeof o!="function")return cn(o,t,e,s);const a={context:t,event:e},c=i||typeof n=="string"?void 0:"params"in n?typeof n.params=="function"?n.params({context:t,event:e}):n.params:void 0;return"check"in o?o.check(s,a,o):o(a,c)}const ln=n=>n.type==="atomic"||n.type==="final";function Ht(n){return Object.values(n.states).filter(t=>t.type!=="history")}function Yt(n,t){const e=[];if(t===n)return e;let s=n.parent;for(;s&&s!==t;)e.push(s),s=s.parent;return e}function le(n){const t=new Set(n),e=_s(t);for(const s of t)if(s.type==="compound"&&(!e.get(s)||!e.get(s).length))xn(s).forEach(r=>t.add(r));else if(s.type==="parallel"){for(const r of Ht(s))if(r.type!=="history"&&!t.has(r)){const i=xn(r);for(const o of i)t.add(o)}}for(const s of t){let r=s.parent;for(;r;)t.add(r),r=r.parent}return t}function bs(n,t){const e=t.get(n);if(!e)return{};if(n.type==="compound"){const r=e[0];if(r){if(ln(r))return r.key}else return{}}const s={};for(const r of e)s[r.key]=bs(r,t);return s}function _s(n){const t=new Map;for(const e of n)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 Es(n,t){const e=le(t);return bs(n,_s(e))}function un(n,t){return t.type==="compound"?Ht(t).some(e=>e.type==="final"&&n.has(e)):t.type==="parallel"?Ht(t).every(e=>un(n,e)):t.type==="final"}const me=n=>n[0]===Gi;function fo(n,t){return n.transitions.get(t)||[...n.transitions.keys()].filter(s=>{if(s===Zi)return!0;if(!s.endsWith(".*"))return!1;const r=s.split("."),i=t.split(".");for(let o=0;o<r.length;o++){const a=r[o],c=i[o];if(a==="*")return o===r.length-1;if(a!==c)return!1}return!0}).sort((s,r)=>r.length-s.length).flatMap(s=>n.transitions.get(s))}function po(n){const t=n.config.after;if(!t)return[];const e=r=>{const i=Vi(r,n.id),o=i.type;return n.entry.push(Lo(i,{id:o,delay:r})),n.exit.push(oo(o)),o};return Object.keys(t).flatMap(r=>{const i=t[r],o=typeof i=="string"?{target:i}:i,a=Number.isNaN(+r)?r:+r,c=e(a);return et(o).map(l=>({...l,event:c,delay:a}))}).map(r=>{const{delay:i}=r;return{...dt(n,r.event,r),delay:i}})}function dt(n,t,e){const s=ms(e.target),r=e.reenter??!1,i=mo(n,s),o={...e,actions:et(e.actions),guard:e.guard,target:i,source:n,reenter:r,eventType:t,toJSON:()=>({...o,source:`#${n.id}`,target:i?i.map(a=>`#${a.id}`):void 0})};return o}function go(n){const t=new Map;if(n.config.on)for(const e of Object.keys(n.config.on)){if(e===hs)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=n.config.on[e];t.set(e,Tt(s).map(r=>dt(n,e,r)))}if(n.config.onDone){const e=`xstate.done.state.${n.id}`;t.set(e,Tt(n.config.onDone).map(s=>dt(n,e,s)))}for(const e of n.invoke){if(e.onDone){const s=`xstate.done.actor.${e.id}`;t.set(s,Tt(e.onDone).map(r=>dt(n,s,r)))}if(e.onError){const s=`xstate.error.actor.${e.id}`;t.set(s,Tt(e.onError).map(r=>dt(n,s,r)))}if(e.onSnapshot){const s=`xstate.snapshot.${e.id}`;t.set(s,Tt(e.onSnapshot).map(r=>dt(n,s,r)))}}for(const e of n.after){let s=t.get(e.eventType);s||(s=[],t.set(e.eventType,s)),s.push(e)}return t}function yo(n,t){const e=typeof t=="string"?n.states[t]:t?n.states[t.target]:void 0;if(!e&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${n.id}`);const s={source:n,actions:!t||typeof t=="string"?[]:et(t.actions),eventType:null,reenter:!1,target:e?[e]:[],toJSON:()=>({...s,source:`#${n.id}`,target:e?[`#${e.id}`]:[]})};return s}function mo(n,t){if(t!==void 0)return t.map(e=>{if(typeof e!="string")return e;if(me(e))return n.machine.getStateNodeById(e);const s=e[0]===us;if(s&&!n.parent)return ue(n,e.slice(1));const r=s?n.key+e:e;if(n.parent)try{return ue(n.parent,r)}catch(i){throw new Error(`Invalid transition definition for state node '${n.id}':
14
14
  ${i.message}`)}else throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`)})}function As(n){const t=ms(n.config.target);return t?{target:t.map(e=>typeof e=="string"?ue(n.parent,e):e)}:n.parent.initial}function pt(n){return n.type==="history"}function xn(n){const t=Ss(n);for(const e of t)for(const s of Yt(e,n))t.add(s);return t}function Ss(n){const t=new Set;function e(s){if(!t.has(s)){if(t.add(s),s.type==="compound")e(s.initial.target[0]);else if(s.type==="parallel")for(const r of Ht(s))e(r)}}return e(n),t}function Wt(n,t){if(me(t))return n.machine.getStateNodeById(t);if(!n.states)throw new Error(`Unable to retrieve child state '${t}' from '${n.id}'; no child states exist.`);const e=n.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${n.id}'`);return e}function ue(n,t){if(typeof t=="string"&&me(t))try{return n.machine.getStateNodeById(t)}catch{}const e=rn(t).slice();let s=n;for(;e.length;){const r=e.shift();if(!r.length)break;s=Wt(s,r)}return s}function he(n,t){if(typeof t=="string"){const r=n.states[t];if(!r)throw new Error(`State '${t}' does not exist on '${n.id}'`);return[n,r]}const e=Object.keys(t),s=e.map(r=>Wt(n,r)).filter(Boolean);return[n.machine.root,n].concat(s,e.reduce((r,i)=>{const o=Wt(n,i);if(!o)return r;const a=he(o,t[i]);return r.concat(a)},[]))}function wo(n,t,e,s){const i=Wt(n,t).next(e,s);return!i||!i.length?n.next(e,s):i}function bo(n,t,e,s){const r=Object.keys(t),i=Wt(n,r[0]),o=hn(i,t[r[0]],e,s);return!o||!o.length?n.next(e,s):o}function _o(n,t,e,s){const r=[];for(const i of Object.keys(t)){const o=t[i];if(!o)continue;const a=Wt(n,i),c=hn(a,o,e,s);c&&r.push(...c)}return r.length?r:n.next(e,s)}function hn(n,t,e,s){return typeof t=="string"?wo(n,t,e,s):Object.keys(t).length===1?bo(n,t,e,s):_o(n,t,e,s)}function Eo(n){return Object.keys(n.states).map(t=>n.states[t]).filter(t=>t.type==="history")}function rt(n,t){let e=n;for(;e.parent&&e.parent!==t;)e=e.parent;return e.parent===t}function Ao(n,t){const e=new Set(n),s=new Set(t);for(const r of e)if(s.has(r))return!0;for(const r of s)if(e.has(r))return!0;return!1}function Ns(n,t,e){const s=new Set;for(const r of n){let i=!1;const o=new Set;for(const a of s)if(Ao(Ke([r],t,e),Ke([a],t,e)))if(rt(r.source,a.source))o.add(a);else{i=!0;break}if(!i){for(const a of o)s.delete(a);s.add(r)}}return Array.from(s)}function So(n){const[t,...e]=n;for(const s of Yt(t,void 0))if(e.every(r=>rt(r,s)))return s}function dn(n,t){if(!n.target)return[];const e=new Set;for(const s of n.target)if(pt(s))if(t[s.id])for(const r of t[s.id])e.add(r);else for(const r of dn(As(s),t))e.add(r);else e.add(s);return[...e]}function Ts(n,t){const e=dn(n,t);if(!e)return;if(!n.reenter&&e.every(r=>r===n.source||rt(r,n.source)))return n.source;const s=So(e.concat(n.source));if(s)return s;if(!n.reenter)return n.source.machine.root}function Ke(n,t,e){var r;const s=new Set;for(const i of n)if((r=i.target)!=null&&r.length){const o=Ts(i,e);i.reenter&&i.source===o&&s.add(o);for(const a of t)rt(a,o)&&s.add(a)}return[...s]}function No(n,t){if(n.length!==t.size)return!1;for(const e of n)if(!t.has(e))return!1;return!0}function Le(n,t,e,s,r,i){if(!n.length)return t;const o=new Set(t._nodes);let a=t.historyValue;const c=Ns(n,o,a);let l=t;r||([l,a]=Oo(l,s,e,c,o,a,i,e.actionExecutor)),l=Bt(l,s,e,c.flatMap(h=>h.actions),i,void 0),l=vo(l,s,e,c,o,i,a,r);const u=[...o];l.status==="done"&&(l=Bt(l,s,e,u.sort((h,d)=>d.order-h.order).flatMap(h=>h.exit),i,void 0));try{return a===t.historyValue&&No(t._nodes,o)?l:wt(l,{_nodes:u,historyValue:a})}catch(h){throw h}}function To(n,t,e,s,r){if(s.output===void 0)return;const i=We(r.id,r.output!==void 0&&r.parent?Be(r.output,n.context,t,e.self):void 0);return Be(s.output,n.context,i,e.self)}function vo(n,t,e,s,r,i,o,a){let c=n;const l=new Set,u=new Set;Io(s,o,u,l),a&&u.add(n.machine.root);const h=new Set;for(const d of[...l].sort((g,f)=>g.order-f.order)){r.add(d);const g=[];g.push(...d.entry);for(const f of d.invoke)g.push(lo(f.src,{...f,syncSnapshot:!!f.onSnapshot}));if(u.has(d)){const f=d.initial.actions;g.push(...f)}if(c=Bt(c,t,e,g,i,d.invoke.map(f=>f.id)),d.type==="final"){const f=d.parent;let m=(f==null?void 0:f.type)==="parallel"?f:f==null?void 0:f.parent,A=m||d;for((f==null?void 0:f.type)==="compound"&&i.push(We(f.id,d.output!==void 0?Be(d.output,c.context,t,e.self):void 0));(m==null?void 0:m.type)==="parallel"&&!h.has(m)&&un(r,m);)h.add(m),i.push(We(m.id)),A=m,m=m.parent;if(m)continue;c=wt(c,{status:"done",output:To(c,t,e,c.machine.root,A)})}}return c}function Io(n,t,e,s){for(const r of n){const i=Ts(r,t);for(const a of r.target||[])!pt(a)&&(r.source!==a||r.source!==i||r.reenter)&&(s.add(a),e.add(a)),It(a,t,e,s);const o=dn(r,t);for(const a of o){const c=Yt(a,i);(i==null?void 0:i.type)==="parallel"&&c.push(i),vs(s,t,e,c,!r.source.parent&&r.reenter?void 0:i)}}}function It(n,t,e,s){var r;if(pt(n))if(t[n.id]){const i=t[n.id];for(const o of i)s.add(o),It(o,t,e,s);for(const o of i)Ne(o,n.parent,s,t,e)}else{const i=As(n);for(const o of i.target)s.add(o),i===((r=n.parent)==null?void 0:r.initial)&&e.add(n.parent),It(o,t,e,s);for(const o of i.target)Ne(o,n.parent,s,t,e)}else if(n.type==="compound"){const[i]=n.initial.target;pt(i)||(s.add(i),e.add(i)),It(i,t,e,s),Ne(i,n,s,t,e)}else if(n.type==="parallel")for(const i of Ht(n).filter(o=>!pt(o)))[...s].some(o=>rt(o,i))||(pt(i)||(s.add(i),e.add(i)),It(i,t,e,s))}function vs(n,t,e,s,r){for(const i of s)if((!r||rt(i,r))&&n.add(i),i.type==="parallel")for(const o of Ht(i).filter(a=>!pt(a)))[...n].some(a=>rt(a,o))||(n.add(o),It(o,t,e,n))}function Ne(n,t,e,s,r){vs(e,s,r,Yt(n,t))}function Oo(n,t,e,s,r,i,o,a){let c=n;const l=Ke(s,r,i);l.sort((h,d)=>d.order-h.order);let u;for(const h of l)for(const d of Eo(h)){let g;d.history==="deep"?g=f=>ln(f)&&rt(f,h):g=f=>f.parent===h,u??(u={...i}),u[d.id]=Array.from(r).filter(g)}for(const h of l)c=Bt(c,t,e,[...h.exit,...h.invoke.map(d=>ws(d.id))],o,void 0),r.delete(h);return[c,u||i]}function ko(n,t){return n.implementations.actions[t]}function Is(n,t,e,s,r,i){const{machine:o}=n;let a=n;for(const c of s){const l=typeof c=="function",u=l?c:ko(o,typeof c=="string"?c:c.type),h={context:a.context,event:t,self:e.self,system:e.system},d=l||typeof c=="string"?void 0:"params"in c?typeof c.params=="function"?c.params({context:a.context,event:t}):c.params:void 0;if(!u||!("resolve"in u)){e.actionExecutor({type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",info:h,params:d,exec:u});continue}const g=u,[f,m,A]=g.resolve(e,a,h,d,u,r);a=f,"retryResolve"in g&&(i==null||i.push([g,m])),"execute"in g&&e.actionExecutor({type:g.type,info:h,params:m,exec:g.execute.bind(null,e,m)}),A&&(a=Is(a,t,e,A,r,i))}return a}function Bt(n,t,e,s,r,i){const o=i?[]:void 0,a=Is(n,t,e,s,{internalQueue:r,deferredActorIds:i},o);return o==null||o.forEach(([c,l])=>{c.retryResolve(e,a,l)}),a}function Te(n,t,e,s){let r=n;const i=[];function o(l,u,h){e.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:e.self,event:u,snapshot:l,_transitions:h}),i.push(l)}if(t.type===He)return r=wt($n(r,t,e),{status:"stopped"}),o(r,t,[]),{snapshot:r,microstates:i};let a=t;if(a.type!==ds){const l=a,u=Qi(l),h=Pn(l,r);if(u&&!h.length)return r=wt(n,{status:"error",error:l.error}),o(r,l,[]),{snapshot:r,microstates:i};r=Le(h,n,e,a,!1,s),o(r,l,h)}let c=!0;for(;r.status==="active";){let l=c?Co(r,a):[];const u=l.length?r:void 0;if(!l.length){if(!s.length)break;a=s.shift(),l=Pn(a,r)}r=Le(l,r,e,a,!1,s),c=r!==u,o(r,a,l)}return r.status!=="active"&&$n(r,a,e),{snapshot:r,microstates:i}}function $n(n,t,e){return Bt(n,t,e,Object.values(n.children).map(s=>ws(s)),[],void 0)}function Pn(n,t){return t.machine.getTransitionData(t,n)}function Co(n,t){const e=new Set,s=n._nodes.filter(ln);for(const r of s)t:for(const i of[r].concat(Yt(r,void 0)))if(i.always){for(const o of i.always)if(o.guard===void 0||cn(o.guard,n.context,t,n)){e.add(o);break t}}return Ns(Array.from(e),new Set(n._nodes),n.historyValue)}function Ro(n,t){const e=le(he(n,t));return Es(n,[...e])}function Mo(n){return!!n&&typeof n=="object"&&"machine"in n&&"value"in n}const xo=function(t){return ps(t,this.value)},$o=function(t){return this.tags.has(t)},Po=function(t){const e=this.machine.getTransitionData(this,t);return!!(e!=null&&e.length)&&e.some(s=>s.target!==void 0||s.actions.length)},Ho=function(){const{_nodes:t,tags:e,machine:s,getMeta:r,toJSON:i,can:o,hasTag:a,matches:c,...l}=this;return{...l,tags:Array.from(e)}},Wo=function(){return this._nodes.reduce((t,e)=>(e.meta!==void 0&&(t[e.id]=e.meta),t),{})};function re(n,t){return{status:n.status,output:n.output,error:n.error,machine:t,context:n.context,_nodes:n._nodes,value:Es(t.root,n._nodes),tags:new Set(n._nodes.flatMap(e=>e.tags)),children:n.children,historyValue:n.historyValue||{},matches:xo,hasTag:$o,can:Po,getMeta:Wo,toJSON:Ho}}function wt(n,t={}){return re({...n,...t},n.machine)}function Bo(n,t){const{_nodes:e,tags:s,machine:r,children:i,context:o,can:a,hasTag:c,matches:l,getMeta:u,toJSON:h,...d}=n,g={};for(const m in i){const A=i[m];g[m]={snapshot:A.getPersistedSnapshot(t),src:A.src,systemId:A._systemId,syncSnapshot:A._syncSnapshot}}return{...d,context:Os(o),children:g}}function Os(n){let t;for(const e in n){const s=n[e];if(s&&typeof s=="object")if("sessionId"in s&&"send"in s&&"ref"in s)t??(t=Array.isArray(n)?n.slice():{...n}),t[e]={xstate$$type:an,id:s.id};else{const r=Os(s);r!==s&&(t??(t=Array.isArray(n)?n.slice():{...n}),t[e]=r)}}return t??n}function Do(n,t,e,s,{event:r,id:i,delay:o},{internalQueue:a}){const c=t.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const l=typeof r=="function"?r(e,s):r;let u;if(typeof o=="string"){const h=c&&c[o];u=typeof h=="function"?h(e,s):h}else u=typeof o=="function"?o(e,s):o;return typeof u!="number"&&a.push(l),[t,{event:l,id:i,delay:u},void 0]}function Ko(n,t){const{event:e,delay:s,id:r}=t;if(typeof s=="number"){n.defer(()=>{const i=n.self;n.system.scheduler.schedule(i,i,e,s,r)});return}}function Lo(n,t){function e(s,r){}return e.type="xstate.raise",e.event=n,e.id=t==null?void 0:t.id,e.delay=t==null?void 0:t.delay,e.resolve=Do,e.execute=Ko,e}function zo(n,{machine:t,context:e},s,r){const i=(o,a)=>{if(typeof o=="string"){const c=on(t,o);if(!c)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const l=Pt(c,{id:a==null?void 0:a.id,parent:n.self,syncSnapshot:a==null?void 0:a.syncSnapshot,input:typeof(a==null?void 0:a.input)=="function"?a.input({context:e,event:s,self:n.self}):a==null?void 0:a.input,src:o,systemId:a==null?void 0:a.systemId});return r[l.id]=l,l}else return Pt(o,{id:a==null?void 0:a.id,parent:n.self,syncSnapshot:a==null?void 0:a.syncSnapshot,input:a==null?void 0:a.input,src:o,systemId:a==null?void 0:a.systemId})};return(o,a)=>{const c=i(o,a);return r[c.id]=c,n.defer(()=>{c._processingStatus!==P.Stopped&&c.start()}),c}}function jo(n,t,e,s,{assignment:r}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:t.context,event:e.event,spawn:zo(n,t,e.event,i),self:n.self,system:n.system};let a={};if(typeof r=="function")a=r(o,s);else for(const l of Object.keys(r)){const u=r[l];a[l]=typeof u=="function"?u(o,s):u}const c=Object.assign({},t.context,a);return[wt(t,{context:c,children:Object.keys(i).length?{...t.children,...i}:t.children}),void 0,void 0]}function Uo(n){function t(e,s){}return t.type="xstate.assign",t.assignment=n,t.resolve=jo,t}const Hn=new WeakMap;function Nt(n,t,e){let s=Hn.get(n);return s?t in s||(s[t]=e()):(s={[t]:e()},Hn.set(n,s)),s[t]}const Fo={},Lt=n=>typeof n=="string"?{type:n}:typeof n=="function"?"resolve"in n?{type:n.type}:{type:n.name}:n;class fn{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(us),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?Cn(this.config.states,(s,r)=>new fn(s,{_parent:this,_key:r,_machine:this.machine})):Fo,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=et(this.config.entry).slice(),this.exit=et(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=et(t.tags).slice()}_initialize(){this.transitions=go(this),this.config.always&&(this.always=Tt(this.config.always).map(t=>dt(this,hs,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(Lt),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(Lt),eventType:null})}:void 0,history:this.history,states:Cn(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(Lt)})),entry:this.entry.map(Lt),exit:this.exit.map(Lt),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 Nt(this,"invoke",()=>et(this.config.invoke).map((t,e)=>{const{src:s,systemId:r}=t,i=t.id??Rn(this.id,e),o=typeof s=="string"?s:`xstate.invoke.${Rn(this.id,e)}`;return{...t,src:o,id:i,systemId:r,toJSON(){const{onDone:a,onError:c,...l}=t;return{...l,type:"xstate.invoke",src:o,id:i}}}}))}get on(){return Nt(this,"on",()=>[...this.transitions].flatMap(([e,s])=>s.map(r=>[e,r])).reduce((e,[s,r])=>(e[s]=e[s]||[],e[s].push(r),e),{}))}get after(){return Nt(this,"delayedTransitions",()=>po(this))}get initial(){return Nt(this,"initial",()=>yo(this,this.config.initial))}next(t,e){const s=e.type,r=[];let i;const o=Nt(this,`candidates-${s}`,()=>fo(this,s));for(const a of o){const{guard:c}=a,l=t.context;let u=!1;try{u=!c||cn(c,l,e,t)}catch(h){const d=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${d?`'${d}' `:""}in transition for event '${s}' in state node '${this.id}':
15
15
  ${h.message}`)}if(u){r.push(...a.actions),i=a;break}}return i?[i]:void 0}get events(){return Nt(this,"events",()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const r=t[s];if(r.states)for(const i of r.events)e.add(`${i}`)}return Array.from(e)})}get ownEvents(){const t=new Set([...this.transitions.keys()].filter(e=>this.transitions.get(e).some(s=>!(!s.target&&!s.actions.length&&!s.reenter))));return Array.from(t)}}const Go="#";class pn{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 fn(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:s,actors:r,delays:i}=this.implementations;return new pn(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...r,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=Ro(this.root,t.value),s=le(he(this.root,e));return re({_nodes:[...s],context:t.context||{},children:{},status:un(s,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){return Te(t,e,s,[]).snapshot}microstep(t,e,s){return Te(t,e,s,[]).microstates}getTransitionData(t,e){return hn(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:r}=this.config,i=re({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?Bt(i,e,t,[Uo(({spawn:a,event:c,self:l})=>r({spawn:a,input:c.input,self:l}))],s,void 0):i}getInitialSnapshot(t,e){const s=fs(e),r=[],i=this.getPreInitialState(t,s,r),o=Le([{target:[...Ss(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,t,s,!0,r),{snapshot:a}=Te(o,s,t,r);return a}start(t){Object.values(t.children).forEach(e=>{e.getSnapshot().status==="active"&&e.start()})}getStateNodeById(t){const e=rn(t),s=e.slice(1),r=me(e[0])?e[0].slice(Go.length):e[0],i=this.idMap.get(r);if(!i)throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return ue(i,s)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return Bo(t,e)}restoreSnapshot(t,e){const s={},r=t.children;Object.keys(r).forEach(c=>{const l=r[c],u=l.snapshot,h=l.src,d=typeof h=="string"?on(this,h):h;if(!d)return;const g=Pt(d,{id:c,parent:e.self,syncSnapshot:l.syncSnapshot,snapshot:u,src:h,systemId:l.systemId});s[c]=g});const i=re({...t,children:s,_nodes:Array.from(le(he(this.root,t.value)))},this),o=new Set;function a(c,l){if(!o.has(c)){o.add(c);for(const u in c){const h=c[u];if(h&&typeof h=="object"){if("xstate$$type"in h&&h.xstate$$type===an){c[u]=l[h.id];continue}a(h,l)}}}}return a(i.context,s),i}}function Zo(n,t){return new pn(n,t)}const ee=n=>n===!1?!1:n.map(t=>t.serialize()),Vo=n=>n===!1?!1:n.serialize(),Jo=n=>n===!1?!1:n.map(t=>({tile:t.tile.toString(),candidates:t.candidates.map(e=>e.toString()),shanten:t.shanten})),ze=n=>JSON.parse(JSON.stringify(n)),ne=n=>n===!1?!1:ze(n),je=n=>Zo({id:"Untitled",initial:"distribute",context:{currentWind:E.E,oneShotMap:$(!1),missingMap:$(!1),controller:n,genEventID:ks()},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:`可能なアクションとその詳細を通知\\
16
16
  DISCARD の場合は捨てられる牌の一覧`}}},waiting_user_event_after_drawn:{description:"ツモった1ユーザからのレスポンス待ち",on:{TSUMO:{target:"tsumo",guard:"canWin"},REACH:{target:"waiting_reach_acceptance",actions:[{type:"notify_reach"},{type:"notify_choice_for_reach_acceptance"}],guard:{type:"canReach"}},SHO_KAN:{target:"an_sho_kaned"},AN_KAN:{target:"an_sho_kaned"},DISCARD:{target:"discarded",description:"入力に牌が必須",actions:{type:"disable_one_shot_for_me"}},DRAWN_GAME_BY_NINE_ORPHANS:{target:"drawn_game"}}},discarded:{entry:{type:"notify_discard"},on:{NEXT:{target:"waiting_user_event_after_discarded",actions:{type:"notify_choice_after_discarded"},description:`可能なアクションとその詳細を通知\\
package/dist/index.d.cts CHANGED
@@ -215,6 +215,7 @@ export declare interface BoardContext {
215
215
  finalWallWin?: boolean;
216
216
  finalDiscardWin?: boolean;
217
217
  oneShotWin?: boolean;
218
+ roundUp8000?: boolean;
218
219
  }
219
220
 
220
221
  declare type BoardRound = (typeof ROUND_MAP)[keyof typeof ROUND_MAP];
@@ -615,6 +616,7 @@ export declare class DoubleCalculator {
615
616
  finalWallWin: boolean;
616
617
  finalDiscardWin: boolean;
617
618
  oneShotWin: boolean;
619
+ roundUp8000: boolean;
618
620
  orig: BoardContext;
619
621
  };
620
622
  constructor(hand: Hand, params: BoardContext);
package/dist/index.d.ts CHANGED
@@ -215,6 +215,7 @@ export declare interface BoardContext {
215
215
  finalWallWin?: boolean;
216
216
  finalDiscardWin?: boolean;
217
217
  oneShotWin?: boolean;
218
+ roundUp8000?: boolean;
218
219
  }
219
220
 
220
221
  declare type BoardRound = (typeof ROUND_MAP)[keyof typeof ROUND_MAP];
@@ -615,6 +616,7 @@ export declare class DoubleCalculator {
615
616
  finalWallWin: boolean;
616
617
  finalDiscardWin: boolean;
617
618
  oneShotWin: boolean;
619
+ roundUp8000: boolean;
618
620
  orig: BoardContext;
619
621
  };
620
622
  constructor(hand: Hand, params: BoardContext);
package/dist/index.js CHANGED
@@ -387,7 +387,7 @@ class P extends T {
387
387
  return T.deserialize({ tiles: t, type: b.PAIR });
388
388
  }
389
389
  }
390
- class U extends T {
390
+ class F extends T {
391
391
  constructor(t) {
392
392
  super(t, b.THREE);
393
393
  }
@@ -455,7 +455,7 @@ const Qt = (n, t) => {
455
455
  case b.SHO_KAN:
456
456
  return new K(n);
457
457
  case b.THREE:
458
- return new U(n);
458
+ return new F(n);
459
459
  case b.RUN:
460
460
  return new ut(n);
461
461
  case b.PAIR:
@@ -820,13 +820,13 @@ const Ke = function(n) {
820
820
  function js(n) {
821
821
  return typeof n < "u";
822
822
  }
823
- const Fs = {
823
+ const Us = {
824
824
  allowBooleanAttributes: !1,
825
825
  //A tag can have attributes without any value
826
826
  unpairedTags: []
827
827
  };
828
- function Us(n, t) {
829
- t = Object.assign({}, Fs, t);
828
+ function Fs(n, t) {
829
+ t = Object.assign({}, Us, t);
830
830
  const e = [];
831
831
  let s = !1, r = !1;
832
832
  n[0] === "\uFEFF" && (n = n.substr(1));
@@ -1637,7 +1637,7 @@ class $r {
1637
1637
  throw new Error("XML data is accepted in String or Bytes[] form.");
1638
1638
  if (e) {
1639
1639
  e === !0 && (e = {});
1640
- const i = Us(t, e);
1640
+ const i = Fs(t, e);
1641
1641
  if (i !== !0)
1642
1642
  throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`);
1643
1643
  }
@@ -2043,7 +2043,7 @@ const jr = [
2043
2043
  'version="1.1"',
2044
2044
  'xmlns:xlink="http://www.w3.org/1999/xlink"'
2045
2045
  ];
2046
- class Fr extends yt {
2046
+ class Ur extends yt {
2047
2047
  constructor() {
2048
2048
  super("svg");
2049
2049
  _(this, "children", []);
@@ -2090,10 +2090,10 @@ class Fr extends yt {
2090
2090
  }
2091
2091
  }
2092
2092
  }
2093
- function Ur() {
2094
- return new Fr();
2093
+ function Fr() {
2094
+ return new Ur();
2095
2095
  }
2096
- const Fo = Ur, Uo = v, Zo = Wn, Go = ze, Vo = Bn, Jo = Nt;
2096
+ const Uo = Fr, Fo = v, Zo = Wn, Go = ze, Vo = Bn, Jo = Nt;
2097
2097
  function Zr(n) {
2098
2098
  return n.replace(/[A-Z]/g, (t) => "-" + t.toLowerCase());
2099
2099
  }
@@ -2620,7 +2620,7 @@ function ui(n, t, e) {
2620
2620
  );
2621
2621
  }
2622
2622
  // @__NO_SIDE_EFFECTS__
2623
- function Fn(n, t, e) {
2623
+ function Un(n, t, e) {
2624
2624
  return typeof n.default == "function" ? (
2625
2625
  // @ts-expect-error
2626
2626
  n.default(t, e)
@@ -2660,7 +2660,7 @@ function D(n, t) {
2660
2660
  return /* @__PURE__ */ $t(this);
2661
2661
  },
2662
2662
  "~run"(e, s) {
2663
- return e.value === void 0 && (this.default !== void 0 && (e.value = /* @__PURE__ */ Fn(this, e, s)), e.value === void 0) ? (e.typed = !0, e) : this.wrapped["~run"](e, s);
2663
+ return e.value === void 0 && (this.default !== void 0 && (e.value = /* @__PURE__ */ Un(this, e, s)), e.value === void 0) ? (e.typed = !0, e) : this.wrapped["~run"](e, s);
2664
2664
  }
2665
2665
  };
2666
2666
  }
@@ -2707,7 +2707,7 @@ function Ot(n, t) {
2707
2707
  const c = o in r ? (
2708
2708
  // @ts-expect-error
2709
2709
  r[o]
2710
- ) : /* @__PURE__ */ Fn(a), l = a["~run"]({ value: c }, s);
2710
+ ) : /* @__PURE__ */ Un(a), l = a["~run"]({ value: c }, s);
2711
2711
  if (l.issues) {
2712
2712
  const u = {
2713
2713
  type: "object",
@@ -2816,7 +2816,7 @@ function hi(n, t, e) {
2816
2816
  issues: s.issues
2817
2817
  };
2818
2818
  }
2819
- const Ft = /* @__PURE__ */ D(
2819
+ const Ut = /* @__PURE__ */ D(
2820
2820
  /* @__PURE__ */ Ot({
2821
2821
  discard: /* @__PURE__ */ D(/* @__PURE__ */ ne(), ""),
2822
2822
  hand: /* @__PURE__ */ D(/* @__PURE__ */ ne(), ""),
@@ -2824,10 +2824,10 @@ const Ft = /* @__PURE__ */ D(
2824
2824
  }),
2825
2825
  { discard: "", hand: "", score: 25e3 }
2826
2826
  ), di = /* @__PURE__ */ Ot({
2827
- [E.E]: Ft,
2828
- [E.S]: Ft,
2829
- [E.W]: Ft,
2830
- [E.N]: Ft
2827
+ [E.E]: Ut,
2828
+ [E.S]: Ut,
2829
+ [E.W]: Ut,
2830
+ [E.N]: Ut
2831
2831
  }), rt = {
2832
2832
  round: k.E1,
2833
2833
  sticks: { reach: 0, dead: 0 },
@@ -2895,14 +2895,14 @@ const Ft = /* @__PURE__ */ D(
2895
2895
  }
2896
2896
  }
2897
2897
  return i;
2898
- }, F = (n, t) => n.replace(t, "").replace(":", "").trim(), wi = (n) => {
2898
+ }, U = (n, t) => n.replace(t, "").replace(":", "").trim(), wi = (n) => {
2899
2899
  const t = "hand", e = "discard", s = "score", r = {};
2900
2900
  let i = 0;
2901
2901
  for (; i < n.length; i++) {
2902
2902
  const o = n[i];
2903
- if (o.startsWith(t)) r.hand = F(o, t);
2904
- else if (o.startsWith(e)) r.discard = F(o, e);
2905
- else if (o.startsWith(s)) r.score = Number(F(o, s));
2903
+ if (o.startsWith(t)) r.hand = U(o, t);
2904
+ else if (o.startsWith(e)) r.discard = U(o, e);
2905
+ else if (o.startsWith(s)) r.score = Number(U(o, s));
2906
2906
  else break;
2907
2907
  }
2908
2908
  return [r, i];
@@ -2912,15 +2912,15 @@ const Ft = /* @__PURE__ */ D(
2912
2912
  for (; c < n.length; c++) {
2913
2913
  const l = n[c];
2914
2914
  if (l.startsWith(t))
2915
- a.doras = F(l, t);
2915
+ a.doras = U(l, t);
2916
2916
  else if (l.startsWith(e))
2917
- a.round = F(l, e);
2917
+ a.round = U(l, e);
2918
2918
  else if (l.startsWith(s))
2919
- a.front = F(l, s);
2919
+ a.front = U(l, s);
2920
2920
  else if (l.startsWith(r)) {
2921
2921
  a.sticks = {};
2922
2922
  const u = n[c + 1] ?? "", h = n[c + 2] ?? "";
2923
- u.startsWith(i) && (a.sticks.reach = Number(F(u, i))), u.startsWith(o) && (a.sticks.dead = Number(F(u, o))), h.startsWith(i) && (a.sticks.reach = Number(F(h, i))), h.startsWith(o) && (a.sticks.dead = Number(F(h, o))), a.sticks.dead != null && c++, a.sticks.reach != null && c++;
2923
+ u.startsWith(i) && (a.sticks.reach = Number(U(u, i))), u.startsWith(o) && (a.sticks.dead = Number(U(u, o))), h.startsWith(i) && (a.sticks.reach = Number(U(h, i))), h.startsWith(o) && (a.sticks.dead = Number(U(h, o))), a.sticks.dead != null && c++, a.sticks.reach != null && c++;
2924
2924
  } else break;
2925
2925
  }
2926
2926
  return [a, c];
@@ -3226,7 +3226,7 @@ class Ai {
3226
3226
  (g) => g.equals(e) && e.has(y.RED) == g.has(y.RED)
3227
3227
  );
3228
3228
  if (h < 0) continue;
3229
- const d = Un(u);
3229
+ const d = Fn(u);
3230
3230
  c[d] || (c[d] = !0, r.push([o, l, h]));
3231
3231
  }
3232
3232
  }
@@ -3311,7 +3311,7 @@ class Ai {
3311
3311
  handleBack() {
3312
3312
  const t = p.BACK, e = this.hand.get(t, 0);
3313
3313
  if (e < 3) return [];
3314
- const s = new w(t, 0), r = Array(Math.floor(e / 3)).fill(new U([s, s, s]));
3314
+ const s = new w(t, 0), r = Array(Math.floor(e / 3)).fill(new F([s, s, s]));
3315
3315
  return r.length == 0 ? [] : [r];
3316
3316
  }
3317
3317
  handleZ() {
@@ -3320,7 +3320,7 @@ class Ai {
3320
3320
  if (this.hand.get(e, s) == 0) continue;
3321
3321
  if (this.hand.get(e, s) != 3) return [];
3322
3322
  const r = new w(e, s);
3323
- t.push(new U([r, r, r]));
3323
+ t.push(new F([r, r, r]));
3324
3324
  }
3325
3325
  return t.length == 0 ? [] : [t];
3326
3326
  }
@@ -3344,12 +3344,12 @@ class Ai {
3344
3344
  let i = this.handleNumType(t, e);
3345
3345
  this.hand.inc(r), i.length == 0 && (i = [[]]);
3346
3346
  for (const o of i)
3347
- o.unshift(new U([r[0], r[1], r[2]])), s.push(o);
3347
+ o.unshift(new F([r[0], r[1], r[2]])), s.push(o);
3348
3348
  }
3349
3349
  return s;
3350
3350
  }
3351
3351
  }
3352
- const Kt = [1, 2, 3, 4, 5, 6, 7], V = [1, 9], Ut = (n) => {
3352
+ const Kt = [1, 2, 3, 4, 5, 6, 7], V = [1, 9], Ft = (n) => {
3353
3353
  var e;
3354
3354
  const t = n.boardContext;
3355
3355
  return {
@@ -3379,6 +3379,7 @@ class fn {
3379
3379
  finalWallWin: e.finalWallWin ?? !1,
3380
3380
  finalDiscardWin: e.finalDiscardWin ?? !1,
3381
3381
  oneShotWin: e.oneShotWin ?? !1,
3382
+ roundUp8000: e.roundUp8000 ?? !1,
3382
3383
  orig: e
3383
3384
  };
3384
3385
  }
@@ -3419,7 +3420,7 @@ class fn {
3419
3420
  c = 2e3;
3420
3421
  break;
3421
3422
  }
3422
- a > 13 && a < 26 && (c = 8e3);
3423
+ a > 13 && a < 26 && (c = 8e3), this.cfg.roundUp8000 && (o == 30 && a == 4 || o == 60 && a == 3) && (c = 2e3);
3423
3424
  const l = e[r].hand.some(
3424
3425
  (f) => f.tiles.some((m) => m.has(y.TSUMO))
3425
3426
  ), u = this.cfg.orig.myWind, h = u == E.E, d = H(0);
@@ -3590,11 +3591,11 @@ class fn {
3590
3591
  }
3591
3592
  dC2(t) {
3592
3593
  return t.length == 7 ? [] : t.every(
3593
- (s) => s instanceof x || s instanceof K || s instanceof Y || s instanceof U || s instanceof X || s instanceof P
3594
+ (s) => s instanceof x || s instanceof K || s instanceof Y || s instanceof F || s instanceof X || s instanceof P
3594
3595
  ) ? [{ name: "対々和", double: 2 }] : [];
3595
3596
  }
3596
3597
  dD2(t) {
3597
- return this.minus() != 0 ? [] : t.filter((s) => (s instanceof x || s instanceof U) && !s.tiles.some((r) => r.has(y.RON))).length >= 3 ? [{ name: "三暗刻", double: 2 }] : [];
3598
+ return this.minus() != 0 ? [] : t.filter((s) => (s instanceof x || s instanceof F) && !s.tiles.some((r) => r.has(y.RON))).length >= 3 ? [{ name: "三暗刻", double: 2 }] : [];
3598
3599
  }
3599
3600
  dE2(t) {
3600
3601
  return t.filter(
@@ -3602,7 +3603,7 @@ class fn {
3602
3603
  ).length >= 3 ? [{ name: "三槓子", double: 2 }] : [];
3603
3604
  }
3604
3605
  dF2(t) {
3605
- const e = (s) => s instanceof x || s instanceof K || s instanceof Y || s instanceof U || s instanceof X;
3606
+ const e = (s) => s instanceof x || s instanceof K || s instanceof Y || s instanceof F || s instanceof X;
3606
3607
  for (const s of t) {
3607
3608
  if (!e(s)) continue;
3608
3609
  const r = it(s);
@@ -3682,7 +3683,7 @@ class fn {
3682
3683
  }
3683
3684
  dC13(t) {
3684
3685
  return t.length == 7 ? [] : t.every(
3685
- (r) => r instanceof x || r instanceof U && !r.tiles.some((i) => i.has(y.RON)) || r instanceof P
3686
+ (r) => r instanceof x || r instanceof F && !r.tiles.some((i) => i.has(y.RON)) || r instanceof P
3686
3687
  ) ? t.some(
3687
3688
  (r) => r instanceof P && r.tiles.every((i) => i.has(y.TSUMO) || i.has(y.RON))
3688
3689
  ) ? [{ name: "四暗刻単騎待ち", double: 26 }] : [{ name: "四暗刻", double: 13 }] : [];
@@ -3736,7 +3737,7 @@ class fn {
3736
3737
  };
3737
3738
  for (const f of t)
3738
3739
  switch (!0) {
3739
- case f instanceof U:
3740
+ case f instanceof F:
3740
3741
  const m = f.tiles.some((A) => A.has(y.RON)) ? 2 : 4;
3741
3742
  s += l(f, m);
3742
3743
  break;
@@ -3751,7 +3752,7 @@ class fn {
3751
3752
  break;
3752
3753
  }
3753
3754
  s += ((f) => {
3754
- if (f instanceof U) return 0;
3755
+ if (f instanceof F) return 0;
3755
3756
  if (f instanceof P) return 2;
3756
3757
  const m = f.tiles, A = m.findIndex((S) => S.has(y.TSUMO) || S.has(y.RON));
3757
3758
  return A == 1 || A == 0 && m[2].n == 9 || A == 2 && m[0].n == 1 ? 2 : 0;
@@ -3762,11 +3763,11 @@ class fn {
3762
3763
  return !a && s == 20 && (g = !0), c && !g && (s += 2), !c && !a && (s += 10), !c && !a && s == 30 && (g = !0), a && s == 20 && (s = 30), s;
3763
3764
  }
3764
3765
  }
3765
- const Un = (n) => n.tiles.reduce((t, e) => `${t}${e.n}${e.t}`, ""), pn = (n) => {
3766
+ const Fn = (n) => n.tiles.reduce((t, e) => `${t}${e.n}${e.t}`, ""), pn = (n) => {
3766
3767
  const t = {};
3767
3768
  for (const s of n) {
3768
3769
  if (!(s instanceof ut)) continue;
3769
- const r = Un(s);
3770
+ const r = Fn(s);
3770
3771
  t[r] == null ? t[r] = 1 : t[r]++;
3771
3772
  }
3772
3773
  let e = 0;
@@ -4138,7 +4139,7 @@ function ts(n, t) {
4138
4139
  const e = mn(n), s = mn(t);
4139
4140
  return typeof s == "string" ? typeof e == "string" ? s === e : !1 : typeof e == "string" ? e in s : Object.keys(e).every((r) => r in s ? ts(e[r], s[r]) : !1);
4140
4141
  }
4141
- function Fe(n) {
4142
+ function Ue(n) {
4142
4143
  if (ns(n))
4143
4144
  return n;
4144
4145
  const t = [];
@@ -4163,7 +4164,7 @@ function mn(n) {
4163
4164
  return n.value;
4164
4165
  if (typeof n != "string")
4165
4166
  return n;
4166
- const t = Fe(n);
4167
+ const t = Ue(n);
4167
4168
  return Di(t);
4168
4169
  }
4169
4170
  function Di(n) {
@@ -4228,7 +4229,7 @@ function Me(n, t, e) {
4228
4229
  function bn(n, t) {
4229
4230
  return `${t}.${n}`;
4230
4231
  }
4231
- function Ue(n, t) {
4232
+ function Fe(n, t) {
4232
4233
  const e = t.match(/^xstate\.invoke\.(\d+)\.(.*)/);
4233
4234
  if (!e)
4234
4235
  return n.implementations.actors[t];
@@ -4353,7 +4354,7 @@ const ji = {
4353
4354
  logger: console.log.bind(console),
4354
4355
  devTools: !1
4355
4356
  };
4356
- class Fi {
4357
+ class Ui {
4357
4358
  /**
4358
4359
  * Creates a new actor instance for the given logic with the provided options,
4359
4360
  * if any.
@@ -4753,9 +4754,9 @@ class Fi {
4753
4754
  }
4754
4755
  }
4755
4756
  function kt(n, ...[t]) {
4756
- return new Fi(n, t);
4757
+ return new Ui(n, t);
4757
4758
  }
4758
- function Ui(n, t, e, s, {
4759
+ function Fi(n, t, e, s, {
4759
4760
  sendId: r
4760
4761
  }) {
4761
4762
  const i = typeof r == "function" ? r(e, s) : r;
@@ -4771,7 +4772,7 @@ function Zi(n, t) {
4771
4772
  function Gi(n) {
4772
4773
  function t(e, s) {
4773
4774
  }
4774
- return t.type = "xstate.cancel", t.sendId = n, t.resolve = Ui, t.execute = Zi, t;
4775
+ return t.type = "xstate.cancel", t.sendId = n, t.resolve = Fi, t.execute = Zi, t;
4775
4776
  }
4776
4777
  function Vi(n, t, e, s, {
4777
4778
  id: r,
@@ -4780,7 +4781,7 @@ function Vi(n, t, e, s, {
4780
4781
  input: a,
4781
4782
  syncSnapshot: c
4782
4783
  }) {
4783
- const l = typeof o == "string" ? Ue(t.machine, o) : o, u = typeof r == "function" ? r(e) : r;
4784
+ const l = typeof o == "string" ? Fe(t.machine, o) : o, u = typeof r == "function" ? r(e) : r;
4784
4785
  let h, d;
4785
4786
  return l && (d = typeof a == "function" ? a({
4786
4787
  context: t.context,
@@ -5121,7 +5122,7 @@ function oe(n, t) {
5121
5122
  return n.machine.getStateNodeById(t);
5122
5123
  } catch {
5123
5124
  }
5124
- const e = Fe(t).slice();
5125
+ const e = Ue(t).slice();
5125
5126
  let s = n;
5126
5127
  for (; e.length; ) {
5127
5128
  const r = e.shift();
@@ -5679,7 +5680,7 @@ function ko(n, {
5679
5680
  }, s, r) {
5680
5681
  const i = (o, a) => {
5681
5682
  if (typeof o == "string") {
5682
- const c = Ue(t, o);
5683
+ const c = Fe(t, o);
5683
5684
  if (!c)
5684
5685
  throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);
5685
5686
  const l = kt(c, {
@@ -6034,7 +6035,7 @@ class Qe {
6034
6035
  });
6035
6036
  }
6036
6037
  getStateNodeById(t) {
6037
- const e = Fe(t), s = e.slice(1), r = de(e[0]) ? e[0].slice(xo.length) : e[0], i = this.idMap.get(r);
6038
+ const e = Ue(t), s = e.slice(1), r = de(e[0]) ? e[0].slice(xo.length) : e[0], i = this.idMap.get(r);
6038
6039
  if (!i)
6039
6040
  throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);
6040
6041
  return oe(i, s);
@@ -6051,7 +6052,7 @@ class Qe {
6051
6052
  restoreSnapshot(t, e) {
6052
6053
  const s = {}, r = t.children;
6053
6054
  Object.keys(r).forEach((c) => {
6054
- const l = r[c], u = l.snapshot, h = l.src, d = typeof h == "string" ? Ue(this, h) : h;
6055
+ const l = r[c], u = l.snapshot, h = l.src, d = typeof h == "string" ? Fe(this, h) : h;
6055
6056
  if (!d)
6056
6057
  return;
6057
6058
  const g = kt(d, {
@@ -6994,7 +6995,7 @@ class fe {
6994
6995
  N(o.choices.RON, "ron choice is none"), this.actor.send({
6995
6996
  type: i.type,
6996
6997
  iam: o.wind,
6997
- ret: Ut(o.choices.RON),
6998
+ ret: Ft(o.choices.RON),
6998
6999
  targetInfo: {
6999
7000
  wind: o.discarterInfo.wind,
7000
7001
  tile: w.from(o.discarterInfo.tile)
@@ -7033,7 +7034,7 @@ class fe {
7033
7034
  case "TSUMO":
7034
7035
  N(o.choices.TSUMO, "tsumo choice is none"), this.actor.send({
7035
7036
  type: i.type,
7036
- ret: Ut(o.choices.TSUMO),
7037
+ ret: Ft(o.choices.TSUMO),
7037
7038
  lastTile: w.from(o.drawerInfo.tile),
7038
7039
  iam: a
7039
7040
  });
@@ -7103,7 +7104,7 @@ class fe {
7103
7104
  this.actor.send({
7104
7105
  type: "RON",
7105
7106
  iam: o.wind,
7106
- ret: Ut(o.choices.RON),
7107
+ ret: Ft(o.choices.RON),
7107
7108
  targetInfo: {
7108
7109
  wind: o.reacherInfo.wind,
7109
7110
  tile: w.from(o.reacherInfo.tile)
@@ -7120,7 +7121,7 @@ class fe {
7120
7121
  N(o.choices.RON, "ron choice is none"), this.actor.send({
7121
7122
  type: "RON",
7122
7123
  iam: o.wind,
7123
- ret: Ut(o.choices.RON),
7124
+ ret: Ft(o.choices.RON),
7124
7125
  quadWin: !0,
7125
7126
  targetInfo: {
7126
7127
  wind: o.callerInfo.wind,
@@ -7788,7 +7789,7 @@ export {
7788
7789
  X as BlockPon,
7789
7790
  ut as BlockRun,
7790
7791
  K as BlockShoKan,
7791
- U as BlockThree,
7792
+ F as BlockThree,
7792
7793
  fe as Controller,
7793
7794
  Oi as Counter,
7794
7795
  fn as DoubleCalculator,
@@ -7801,10 +7802,10 @@ export {
7801
7802
  Ln as ImageHelper,
7802
7803
  yt as Mark,
7803
7804
  Lo as MeasureText,
7804
- Uo as MyG,
7805
+ Fo as MyG,
7805
7806
  Zo as MyImage,
7806
7807
  Vo as MyRect,
7807
- Fo as MySVG,
7808
+ Uo as MySVG,
7808
7809
  Jo as MyText,
7809
7810
  Go as MyUse,
7810
7811
  V as N19,
@@ -7822,10 +7823,10 @@ export {
7822
7823
  Bt as RiskRank,
7823
7824
  Jn as River,
7824
7825
  en as STICK_CONTEXT,
7825
- Ur as SVG,
7826
+ Fr as SVG,
7826
7827
  se as ScoreManager,
7827
7828
  he as ShantenCalculator,
7828
- Fr as Svg,
7829
+ Ur as Svg,
7829
7830
  Dn as Symbol,
7830
7831
  Ss as TABLE_CONTEXT,
7831
7832
  ft as TILE_CONTEXT,
@@ -7845,7 +7846,7 @@ export {
7845
7846
  ta as createLocalGame,
7846
7847
  ii as createTable,
7847
7848
  H as createWindMap,
7848
- Ut as deserializeWinResult,
7849
+ Ft as deserializeWinResult,
7849
7850
  Xo as drawBlocks,
7850
7851
  qo as drawTable,
7851
7852
  z as forHand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konoui/mjimage",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "description": "Generates Mahjong tiles in SVG format.",
5
5
  "author": "konoui",
6
6
  "license": "MIT",