@konoui/mjimage 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/index.cjs +30 -0
  2. package/dist/index.d.cts +1386 -0
  3. package/dist/index.d.ts +1386 -0
  4. package/dist/index.js +10953 -0
  5. package/package.json +23 -14
  6. package/dist/mjs/cmd/index.d.ts +0 -1
  7. package/dist/mjs/cmd/index.js +0 -49
  8. package/dist/mjs/index.d.ts +0 -6
  9. package/dist/mjs/index.js +0 -22
  10. package/dist/mjs/lib/calculator/calc.d.ts +0 -275
  11. package/dist/mjs/lib/calculator/calc.js +0 -1397
  12. package/dist/mjs/lib/calculator/efficiency.d.ts +0 -24
  13. package/dist/mjs/lib/calculator/efficiency.js +0 -82
  14. package/dist/mjs/lib/calculator/helper.d.ts +0 -6
  15. package/dist/mjs/lib/calculator/helper.js +0 -21
  16. package/dist/mjs/lib/calculator/index.d.ts +0 -3
  17. package/dist/mjs/lib/calculator/index.js +0 -19
  18. package/dist/mjs/lib/controller/controller.d.ts +0 -168
  19. package/dist/mjs/lib/controller/controller.js +0 -897
  20. package/dist/mjs/lib/controller/events.d.ts +0 -171
  21. package/dist/mjs/lib/controller/events.js +0 -102
  22. package/dist/mjs/lib/controller/game.d.ts +0 -5
  23. package/dist/mjs/lib/controller/game.js +0 -29
  24. package/dist/mjs/lib/controller/index.d.ts +0 -10
  25. package/dist/mjs/lib/controller/index.js +0 -26
  26. package/dist/mjs/lib/controller/managers.d.ts +0 -83
  27. package/dist/mjs/lib/controller/managers.js +0 -194
  28. package/dist/mjs/lib/controller/player-efficiency.d.ts +0 -24
  29. package/dist/mjs/lib/controller/player-efficiency.js +0 -153
  30. package/dist/mjs/lib/controller/player.d.ts +0 -12
  31. package/dist/mjs/lib/controller/player.js +0 -85
  32. package/dist/mjs/lib/controller/replay.d.ts +0 -10
  33. package/dist/mjs/lib/controller/replay.js +0 -31
  34. package/dist/mjs/lib/controller/river.d.ts +0 -19
  35. package/dist/mjs/lib/controller/river.js +0 -52
  36. package/dist/mjs/lib/controller/state-machine.d.ts +0 -67
  37. package/dist/mjs/lib/controller/state-machine.js +0 -771
  38. package/dist/mjs/lib/controller/wall.d.ts +0 -24
  39. package/dist/mjs/lib/controller/wall.js +0 -117
  40. package/dist/mjs/lib/core/constants.d.ts +0 -73
  41. package/dist/mjs/lib/core/constants.js +0 -73
  42. package/dist/mjs/lib/core/index.d.ts +0 -2
  43. package/dist/mjs/lib/core/index.js +0 -18
  44. package/dist/mjs/lib/core/lexer.d.ts +0 -14
  45. package/dist/mjs/lib/core/lexer.js +0 -53
  46. package/dist/mjs/lib/core/parser.d.ts +0 -120
  47. package/dist/mjs/lib/core/parser.js +0 -612
  48. package/dist/mjs/lib/image/image.d.ts +0 -42
  49. package/dist/mjs/lib/image/image.js +0 -361
  50. package/dist/mjs/lib/image/index.d.ts +0 -1
  51. package/dist/mjs/lib/image/index.js +0 -17
  52. package/dist/mjs/lib/measure-text/index.d.ts +0 -19
  53. package/dist/mjs/lib/measure-text/index.js +0 -49
  54. package/dist/mjs/lib/myassert/index.d.ts +0 -1
  55. package/dist/mjs/lib/myassert/index.js +0 -8
  56. package/dist/mjs/lib/table/index.d.ts +0 -2
  57. package/dist/mjs/lib/table/index.js +0 -18
  58. package/dist/mjs/lib/table/table-parser.d.ts +0 -127
  59. package/dist/mjs/lib/table/table-parser.js +0 -105
  60. package/dist/mjs/lib/table/table.d.ts +0 -12
  61. package/dist/mjs/lib/table/table.js +0 -248
package/dist/index.cjs ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";var Vs=Object.defineProperty;var Qs=(e,t,n)=>t in e?Vs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var x=(e,t,n)=>Qs(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const hi="MS Gothic, sans-serif",Ot={WIDTH:66,HEIGHT:90,TEXT_SCALE:.8,BLOCK_MARGIN_SCALE:.3},Sr={BASE:40},ke=",",m={M:"m",P:"p",S:"s",Z:"z",BACK:"_"},v={TSUMO:"t",RON:"r",DORA:"d",HORIZONTAL:"-",COLOR_GRAYSCALE:"^"},b={PON:"pon",CHI:"chi",SHO_KAN:"shokan",DAI_KAN:"daikan",AN_KAN:"ankan",TSUMO:"tsumo",THREE:"three",PAIR:"pair",ISOLATED:"isolated",RUN:"run",HAND:"hand",IMAGE_DORA:"dora",IMAGE_DISCARD:"simple-discard",UNKNOWN:"unknown"},T={EAST:"1w",SOUTH:"2w",WEST:"3w",NORTH:"4w"},fi={"1w1":"東1局","1w2":"東2局","1w3":"東3局","1w4":"東4局","2w1":"南1局","2w2":"南2局","2w3":"南3局","2w4":"南4局","3w1":"西1局","3w2":"西2局","3w3":"西3局","3w4":"西4局","4w1":"北1局","4w2":"北2局","4w3":"北3局","4w4":"北4局"},di={[T.EAST]:"東",[T.SOUTH]:"南",[T.WEST]:"西",[T.NORTH]:"北"};function R(e,t){if(!e)throw new Error(t)}class to{constructor(t="東",n="2"){x(this,"ctx",null);x(this,"strText");x(this,"numText");x(this,"measure",(t,n)=>{this.ctx==null&&(this.ctx=document.createElement("canvas").getContext("2d"),R(this.ctx,"context is null"));const i=this.ctx;i.font=n;const r=i.measureText(t);let s=r.width,o=r.actualBoundingBoxAscent+r.actualBoundingBoxDescent;return[s,o]});x(this,"measureFontContext",(t,n)=>{const i={family:t,size:n},r=`${i.size}px ${i.family}`,[s,o]=this.measure(this.strText,r),[a,c]=this.measure(this.numText,r);return{font:{family:t,size:n},textWidth:s,textHeight:o,numWidth:a,numHeight:c}});x(this,"measureTableFontContext",t=>{const n=this.measureFontContext(hi,Sr.BASE*t);return n.textHeight=n.textWidth,n.numHeight=n.numWidth,n});this.strText=t,this.numText=n}}class eo{constructor(t){x(this,"input");x(this,"position");x(this,"nextPosition");x(this,"char");x(this,"eof","\0");this.input=t,this.position=0,this.nextPosition=0,this.char=this.readChar()}readChar(){return this.nextPosition>=this.input.length?(this.char=this.eof,this.char):(this.char=this.input[this.nextPosition],this.position=this.nextPosition,this.nextPosition++,this.char)}peekChar(){return this.nextPosition>=this.input.length?this.eof:this.input[this.nextPosition]}peekCharN(t){if(t<0)throw new Error("arg must be positive value");return this.position+t>=this.input.length?this.eof:this.input[this.position+t]}prevChar(){return this.position>=this.input.length?this.eof:this.position>0?this.input[this.position-1]:this.eof}skipWhitespace(){for(;this.isWhitespace(this.char);)this.readChar()}isWhitespace(t){return/\s/.test(t)}}const Ce=(e,t)=>{if(e.t==t.t)return e.n==0?5-t.n:t.n==0?e.n-5:e.n-t.n;const n={[m.M]:1,[m.P]:2,[m.S]:3,[m.Z]:4,[m.BACK]:5};return n[e.t]-n[t.t]};function no(e){for(let t of Object.values(m))if(t==e)return[t,!0];return[m.BACK,!1]}class w{constructor(t,n,i=[]){this.t=t,this.n=n,this.ops=i}static from(t){const n=new ot(t).tiles();if(n.length!=1)throw new Error(`input is not a single tile ${t}`);return n[0]}toString(){return this.t===m.BACK?this.t:`${this.ops.join("")}${this.n}${this.t}`}toJSON(){return this.toString()}clone(t){const n=(t==null?void 0:t.t)??this.t,i=(t==null?void 0:t.n)??this.n,r=this.ops.filter(o=>(t==null?void 0:t.remove)!=o),s=new Set([...r]);return t!=null&&t.add&&s.add(t.add),new w(n,i,Array.from(s))}has(t){return this.ops.includes(t)}isNum(){return this.t==m.M||this.t==m.P||this.t==m.S}equals(t,n=!1){let i=this.n==t.n;return n&&(i||(i=Ne(this)&&Ne(t))),this.t==t.t&&i}imageSize(t){const n=parseFloat((Ot.HEIGHT*t).toPrecision(5)),i=parseFloat((Ot.WIDTH*t).toPrecision(5)),r=this.has(v.HORIZONTAL)?{width:n,height:i,baseWidth:i,baseHeight:n}:{width:i,height:n,w:i,baseWidth:i,baseHeight:n};return(this.has(v.TSUMO)||this.has(v.DORA))&&(r.width+=i*Ot.TEXT_SCALE),r}}function Ne(e){return nt(e)||et(e)}function et(e){return e.isNum()&&e.n==5}function nt(e){return e.isNum()&&e.n==0}class W{constructor(t,n){x(this,"_tiles");x(this,"_type");if(this._tiles=t,this._type=n,this._type==b.CHI){this._tiles=[...this._tiles].sort((i,r)=>i.has(v.HORIZONTAL)?-1:r.has(v.HORIZONTAL)?1:Ce(i,r));return}this._type!=b.SHO_KAN&&this._type!=b.IMAGE_DISCARD&&(this._tiles=[...this._tiles].sort(Ce))}static from(t){const n=new ot(t.tiles).tiles();return nn(n,t.type)}serialize(){return{tiles:this.toString(),type:this.type}}toJSON(){return this.serialize()}get type(){return this._type}get tiles(){return this._tiles}is(t){return this._type==t}isCalled(){return[b.PON.toString(),b.CHI.toString(),b.DAI_KAN.toString(),b.SHO_KAN.toString(),b.AN_KAN.toString()].includes(this._type.toString())}clone(t){const n=t==null?void 0:t.replace;let i=[...this.tiles];return n&&(i[n.idx]=n.tile),nn(i,this._type)}imageSize(t){const n=this.tiles[0].imageSize(t).baseHeight,i=this.tiles[0].imageSize(t).baseWidth;if(this.is(b.SHO_KAN))return{width:i*2+n,height:Math.max(i*2,n)};const r=this.tiles.reduce((o,a)=>{const c=a.imageSize(t).height;return c>o?c:o},0);return{width:this.tiles.reduce((o,a)=>o+a.imageSize(t).width,0),height:r}}}const Zt=e=>{let t="";for(let n of e){if(n.t==m.BACK)return e.join("");t+=n.toString().slice(0,-1)}return`${t}${e[0].t}`},pi=e=>{let t=e[0].t,n="";for(let r=0;r<e.length;r++){const s=e[r],o=s.t,a=o==m.BACK?s.toString():s.toString().slice(0,-1);o!=t&&t!=m.BACK&&(n+=t),t=o,n+=a}const i=e.at(-1);return i.t!=m.BACK&&(n+=i.t),n};class ht extends W{constructor(t){super(t,b.CHI)}toString(){return Zt(this.tiles)}}class dt extends W{constructor(t){super(t,b.PON)}toString(){return Zt(this.tiles)}}class G extends W{constructor(t){const n=t.filter(r=>r.t!=m.BACK),i=n[0];if(n.length<t.length){if(Ne(i)){const r=new w(i.t,5);super([new w(i.t,0),r,r,r],b.AN_KAN);return}super([i,i,i,i],b.AN_KAN);return}super(t,b.AN_KAN)}get tilesWithBack(){const t=this.tiles[0];return Ne(t)?[new w(m.BACK,0),new w(t.t,0),new w(t.t,5),new w(m.BACK,0)]:[new w(m.BACK,0),t,t,new w(m.BACK,0)]}static from(t){return super.from(t)}toString(){return pi(this.tilesWithBack)}}class bt extends W{constructor(t){super(t,b.DAI_KAN)}toString(){return Zt(this.tiles)}}class xt extends W{constructor(t){super(t,b.SHO_KAN)}toString(){return Zt(this.tiles)}}class X extends W{constructor(t,n){super([t,n],b.PAIR)}toString(){return Zt(this.tiles)}}class lt extends W{constructor(t){super(t,b.THREE)}toString(){return Zt(this.tiles)}}class kt extends W{constructor(t){super(t,b.RUN)}toString(){return Zt(this.tiles)}}class mi extends W{constructor(t){super([t],b.ISOLATED)}toString(){return this.tiles[0].toString()}}class gn extends W{constructor(t){super(t,b.HAND)}toString(){return pi(this.tiles)}}class gi extends W{constructor(t,n){super(t,n)}toString(){return this.is(b.IMAGE_DISCARD)?this.tiles.join(""):pi(this.tiles)}}const nn=(e,t)=>{switch(t){case b.CHI:return new ht([e[0],e[1],e[2]]);case b.PON:return new dt([e[0],e[1],e[2]]);case b.AN_KAN:return new G(e);case b.DAI_KAN:return new bt(e);case b.SHO_KAN:return new xt(e);case b.THREE:return new lt(e);case b.RUN:return new kt(e);case b.PAIR:return new X(e[0],e[1]);case b.ISOLATED:return new mi(e[0]);case b.HAND:return new gn(e);default:return new gi(e,t)}};class ot{constructor(t){x(this,"maxInputLength",600);this.input=t,this.input=t.replace(/\s/g,"")}parse(){const t=this.tileSeparators();return this.makeBlocks(t)}tiles(){return this.tileSeparators().filter(t=>t!=ke)}tileSeparators(){const t=new eo(this.input),n=[];let i=[];for(this.validate(this.input);;){t.skipWhitespace();let r=t.char;if(r===t.eof)break;if(r==ke){n.push(ke),t.readChar();continue}let[s,o]=Ji(r,i);if(o){if(s==m.BACK){n.push(new w(s,0)),t.readChar();continue}n.push(...ro(i,s)),i=[],t.readChar();continue}else{const[a,c]=so(t);if(c){i.push(a),t.readChar();continue}const[l,u]=kr(r);if(!u)throw new Error(`encounter unexpected number. n: ${l}, current: ${r}, input: ${t.input}`);i.push(new w(m.BACK,l))}t.readChar()}if(i.length>0)throw new Error(`remaining values ${i.toString()}`);return n}makeBlocks(t){let n=[];const i=[];if(t.length==0)return i;for(const o of t){if(o==ke){const a=Xi(n),c=nn(n,a);i.push(c),n=[];continue}n.push(o)}const r=Xi(n),s=nn(n,r);return i.push(s),n=[],i}validate(t){if(t.length==0)return;if(t.length>this.maxInputLength)throw new Error(`exceeded maximum input length(${t.length})`);const n=t.charAt(t.length-1),[i,r]=Ji(n,[new w(m.BACK,1)]);if(!r)throw new Error(`last character(${n}) is not type value`)}}function Xi(e){if(e.length===0)return b.UNKNOWN;if(e.length===1)return e[0].has(v.DORA)?b.IMAGE_DORA:e[0].has(v.TSUMO)?b.TSUMO:b.HAND;const t=e.every(s=>s.equals(e[0],!0)),n=e.filter(s=>s.has(v.HORIZONTAL)).length,i=e.filter(s=>s.has(v.TSUMO)||s.has(v.DORA)).length,r=e.filter(s=>s.t==m.BACK).length;if(i>0)return b.UNKNOWN;if(n==0&&r==0)return b.HAND;if(e.length===3&&r===0)return t?b.PON:n==1&&io(e)?b.CHI:b.IMAGE_DISCARD;if(e.length==4&&r==2)return b.AN_KAN;if(e.length==4&&t){if(n==1)return b.DAI_KAN;if(n==2)return b.SHO_KAN}return n==1?b.IMAGE_DISCARD:b.UNKNOWN}function io(e){e=[...e].sort(Ce);for(let t=0;t<e.length-1;t++){let n=e[t].n,i=e[t+1].n;const r=e[t].t,s=e[t+1].t;if(n==0&&(n=5),i==0&&(i=5),r!==s||n+1!==i)return!1}return!0}function ro(e,t){return e.map(n=>new w(t,n.n,n.ops))}function Ji(e,t){const[n,i]=no(e);if(i)return[n,!0];if((e==="w"||e==="d")&&t.length>0){for(let s=0;s<t.length;s++){const o=t[s];e==="d"&&(t[s]=o.clone({n:o.n+4}))}return[m.Z,!0]}return[m.BACK,!1]}function kr(e){const t=["0","1","2","3","4","5","6","7","8","9"];return[Number(e),t.includes(e)]}function so(e){const t=Object.values(v);if(!t.includes(e.char))return[new w(m.BACK,0),!1];const n=[];for(let i=0;i<4;i++){const r=e.peekCharN(i);if(t.includes(r))n.push(r);else{const[s,o]=kr(r);if(!o)break;for(let a=0;a<n.length;a++)e.readChar();return[new w(m.BACK,s,n),!0]}}return[new w(m.BACK,0),!1]}const jn={},Tr=[];function I(e,t){if(Array.isArray(e)){for(const n of e)I(n,t);return}if(typeof e=="object"){for(const n in e)I(n,e[n]);return}Or(Object.getOwnPropertyNames(t)),jn[e]=Object.assign(jn[e]||{},t)}function Q(e){return jn[e]||{}}function oo(){return[...new Set(Tr)]}function Or(e){Tr.push(...e)}function yi(e,t){let n;const i=e.length,r=[];for(n=0;n<i;n++)r.push(t(e[n]));return r}function ao(e,t){let n;const i=e.length,r=[];for(n=0;n<i;n++)t(e[n])&&r.push(e[n]);return r}function Sn(e){return e%360*Math.PI/180}function co(e){return e.replace(/([A-Z])/g,function(t,n){return"-"+n.toLowerCase()})}function Ir(e){return e.charAt(0).toUpperCase()+e.slice(1)}function be(e,t,n,i){return(t==null||n==null)&&(i=i||e.bbox(),t==null?t=i.width/i.height*n:n==null&&(n=i.height/i.width*t)),{width:t,height:n}}function Ln(e,t){const n=e.origin;let i=e.ox!=null?e.ox:e.originX!=null?e.originX:"center",r=e.oy!=null?e.oy:e.originY!=null?e.originY:"center";n!=null&&([i,r]=Array.isArray(n)?n:typeof n=="object"?[n.x,n.y]:[n,n]);const s=typeof i=="string",o=typeof r=="string";if(s||o){const{height:a,width:c,x:l,y:u}=t.bbox();s&&(i=i.includes("left")?l:i.includes("right")?l+c:l+c/2),o&&(r=r.includes("top")?u:r.includes("bottom")?u+a:u+a/2)}return[i,r]}const lo=new Set(["desc","metadata","title"]),Wn=e=>lo.has(e.nodeName),Er=(e,t,n={})=>{const i={...t};for(const r in i)i[r].valueOf()===n[r]&&delete i[r];Object.keys(i).length?e.node.setAttribute("data-svgjs",JSON.stringify(i)):(e.node.removeAttribute("data-svgjs"),e.node.removeAttribute("svgjs:data"))},wi="http://www.w3.org/2000/svg",uo="http://www.w3.org/1999/xhtml",kn="http://www.w3.org/2000/xmlns/",We="http://www.w3.org/1999/xlink",C={window:typeof window>"u"?null:window,document:typeof document>"u"?null:document};function ho(){return C.window}class _i{}const Wt={},bi="___SYMBOL___ROOT___";function Me(e,t=wi){return C.document.createElementNS(t,e)}function J(e,t=!1){if(e instanceof _i)return e;if(typeof e=="object")return Tn(e);if(e==null)return new Wt[bi];if(typeof e=="string"&&e.charAt(0)!=="<")return Tn(C.document.querySelector(e));const n=t?C.document.createElement("div"):Me("svg");return n.innerHTML=e,e=Tn(n.firstChild),n.removeChild(n.firstChild),e}function H(e,t){return t&&(t instanceof C.window.Node||t.ownerDocument&&t instanceof t.ownerDocument.defaultView.Node)?t:Me(e)}function at(e){if(!e)return null;if(e.instance instanceof _i)return e.instance;if(e.nodeName==="#document-fragment")return new Wt.Fragment(e);let t=Ir(e.nodeName||"Dom");return t==="LinearGradient"||t==="RadialGradient"?t="Gradient":Wt[t]||(t="Dom"),new Wt[t](e)}let Tn=at;function N(e,t=e.name,n=!1){return Wt[t]=e,n&&(Wt[bi]=e),Or(Object.getOwnPropertyNames(e.prototype)),e}function fo(e){return Wt[e]}let po=1e3;function Cr(e){return"Svgjs"+Ir(e)+po++}function Nr(e){for(let t=e.children.length-1;t>=0;t--)Nr(e.children[t]);return e.id&&(e.id=Cr(e.nodeName)),e}function E(e,t){let n,i;for(e=Array.isArray(e)?e:[e],i=e.length-1;i>=0;i--)for(n in t)e[i].prototype[n]=t[n]}function B(e){return function(...t){const n=t[t.length-1];return n&&n.constructor===Object&&!(n instanceof Array)?e.apply(this,t.slice(0,-1)).attr(n):e.apply(this,t)}}function mo(){return this.parent().children()}function go(){return this.parent().index(this)}function yo(){return this.siblings()[this.position()+1]}function wo(){return this.siblings()[this.position()-1]}function _o(){const e=this.position();return this.parent().add(this.remove(),e+1),this}function bo(){const e=this.position();return this.parent().add(this.remove(),e?e-1:0),this}function xo(){return this.parent().add(this.remove()),this}function vo(){return this.parent().add(this.remove(),0),this}function Ao(e){e=J(e),e.remove();const t=this.position();return this.parent().add(e,t),this}function So(e){e=J(e),e.remove();const t=this.position();return this.parent().add(e,t+1),this}function ko(e){return e=J(e),e.before(this),this}function To(e){return e=J(e),e.after(this),this}I("Dom",{siblings:mo,position:go,next:yo,prev:wo,forward:_o,backward:bo,front:xo,back:vo,before:Ao,after:So,insertBefore:ko,insertAfter:To});const Mr=/^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i,Oo=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,Io=/rgb\((\d+),(\d+),(\d+)\)/,Eo=/(#[a-z_][a-z0-9\-_]*)/i,Co=/\)\s*,?\s*/,No=/\s/g,Vi=/^#[a-f0-9]{3}$|^#[a-f0-9]{6}$/i,Qi=/^rgb\(/,tr=/^(\s+)?$/,er=/^[+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Mo=/\.(jpg|jpeg|png|gif|svg)(\?[^=]+.*)?/i,At=/[\s,]+/,xi=/[MLHVCSQTAZ]/i;function Do(){const e=this.attr("class");return e==null?[]:e.trim().split(At)}function Ro(e){return this.classes().indexOf(e)!==-1}function Bo(e){if(!this.hasClass(e)){const t=this.classes();t.push(e),this.attr("class",t.join(" "))}return this}function Ho(e){return this.hasClass(e)&&this.attr("class",this.classes().filter(function(t){return t!==e}).join(" ")),this}function $o(e){return this.hasClass(e)?this.removeClass(e):this.addClass(e)}I("Dom",{classes:Do,hasClass:Ro,addClass:Bo,removeClass:Ho,toggleClass:$o});function Po(e,t){const n={};if(arguments.length===0)return this.node.style.cssText.split(/\s*;\s*/).filter(function(i){return!!i.length}).forEach(function(i){const r=i.split(/\s*:\s*/);n[r[0]]=r[1]}),n;if(arguments.length<2){if(Array.isArray(e)){for(const i of e){const r=i;n[i]=this.node.style.getPropertyValue(r)}return n}if(typeof e=="string")return this.node.style.getPropertyValue(e);if(typeof e=="object")for(const i in e)this.node.style.setProperty(i,e[i]==null||tr.test(e[i])?"":e[i])}return arguments.length===2&&this.node.style.setProperty(e,t==null||tr.test(t)?"":t),this}function jo(){return this.css("display","")}function Lo(){return this.css("display","none")}function Wo(){return this.css("display")!=="none"}I("Dom",{css:Po,show:jo,hide:Lo,visible:Wo});function zo(e,t,n){if(e==null)return this.data(yi(ao(this.node.attributes,i=>i.nodeName.indexOf("data-")===0),i=>i.nodeName.slice(5)));if(e instanceof Array){const i={};for(const r of e)i[r]=this.data(r);return i}else if(typeof e=="object")for(t in e)this.data(t,e[t]);else if(arguments.length<2)try{return JSON.parse(this.attr("data-"+e))}catch{return this.attr("data-"+e)}else this.attr("data-"+e,t===null?null:n===!0||typeof t=="string"||typeof t=="number"?t:JSON.stringify(t));return this}I("Dom",{data:zo});function Fo(e,t){if(typeof arguments[0]=="object")for(const n in e)this.remember(n,e[n]);else{if(arguments.length===1)return this.memory()[e];this.memory()[e]=t}return this}function Ko(){if(arguments.length===0)this._memory={};else for(let e=arguments.length-1;e>=0;e--)delete this.memory()[arguments[e]];return this}function Uo(){return this._memory=this._memory||{}}I("Dom",{remember:Fo,forget:Ko,memory:Uo});function Yo(e){return e.length===4?["#",e.substring(1,2),e.substring(1,2),e.substring(2,3),e.substring(2,3),e.substring(3,4),e.substring(3,4)].join(""):e}function qo(e){const t=Math.round(e),i=Math.max(0,Math.min(255,t)).toString(16);return i.length===1?"0"+i:i}function Jt(e,t){for(let n=t.length;n--;)if(e[t[n]]==null)return!1;return!0}function Go(e,t){const n=Jt(e,"rgb")?{_a:e.r,_b:e.g,_c:e.b,_d:0,space:"rgb"}:Jt(e,"xyz")?{_a:e.x,_b:e.y,_c:e.z,_d:0,space:"xyz"}:Jt(e,"hsl")?{_a:e.h,_b:e.s,_c:e.l,_d:0,space:"hsl"}:Jt(e,"lab")?{_a:e.l,_b:e.a,_c:e.b,_d:0,space:"lab"}:Jt(e,"lch")?{_a:e.l,_b:e.c,_c:e.h,_d:0,space:"lch"}:Jt(e,"cmyk")?{_a:e.c,_b:e.m,_c:e.y,_d:e.k,space:"cmyk"}:{_a:0,_b:0,_c:0,space:"rgb"};return n.space=t||n.space,n}function Zo(e){return e==="lab"||e==="xyz"||e==="lch"}function On(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}class D{constructor(...t){this.init(...t)}static isColor(t){return t&&(t instanceof D||this.isRgb(t)||this.test(t))}static isRgb(t){return t&&typeof t.r=="number"&&typeof t.g=="number"&&typeof t.b=="number"}static random(t="vibrant",n){const{random:i,round:r,sin:s,PI:o}=Math;if(t==="vibrant"){const a=24*i()+57,c=38*i()+45,l=360*i();return new D(a,c,l,"lch")}else if(t==="sine"){n=n??i();const a=r(80*s(2*o*n/.5+.01)+150),c=r(50*s(2*o*n/.5+4.6)+200),l=r(100*s(2*o*n/.5+2.3)+150);return new D(a,c,l)}else if(t==="pastel"){const a=8*i()+86,c=17*i()+9,l=360*i();return new D(a,c,l,"lch")}else if(t==="dark"){const a=10+10*i(),c=50*i()+86,l=360*i();return new D(a,c,l,"lch")}else if(t==="rgb"){const a=255*i(),c=255*i(),l=255*i();return new D(a,c,l)}else if(t==="lab"){const a=100*i(),c=256*i()-128,l=256*i()-128;return new D(a,c,l,"lab")}else if(t==="grey"){const a=255*i();return new D(a,a,a)}else throw new Error("Unsupported random color mode")}static test(t){return typeof t=="string"&&(Vi.test(t)||Qi.test(t))}cmyk(){const{_a:t,_b:n,_c:i}=this.rgb(),[r,s,o]=[t,n,i].map(f=>f/255),a=Math.min(1-r,1-s,1-o);if(a===1)return new D(0,0,0,1,"cmyk");const c=(1-r-a)/(1-a),l=(1-s-a)/(1-a),u=(1-o-a)/(1-a);return new D(c,l,u,a,"cmyk")}hsl(){const{_a:t,_b:n,_c:i}=this.rgb(),[r,s,o]=[t,n,i].map(g=>g/255),a=Math.max(r,s,o),c=Math.min(r,s,o),l=(a+c)/2,u=a===c,h=a-c,f=u?0:l>.5?h/(2-a-c):h/(a+c),p=u?0:a===r?((s-o)/h+(s<o?6:0))/6:a===s?((o-r)/h+2)/6:a===o?((r-s)/h+4)/6:0;return new D(360*p,100*f,100*l,"hsl")}init(t=0,n=0,i=0,r=0,s="rgb"){if(t=t||0,this.space)for(const h in this.space)delete this[this.space[h]];if(typeof t=="number")s=typeof r=="string"?r:s,r=typeof r=="string"?0:r,Object.assign(this,{_a:t,_b:n,_c:i,_d:r,space:s});else if(t instanceof Array)this.space=n||(typeof t[3]=="string"?t[3]:t[4])||"rgb",Object.assign(this,{_a:t[0],_b:t[1],_c:t[2],_d:t[3]||0});else if(t instanceof Object){const h=Go(t,n);Object.assign(this,h)}else if(typeof t=="string")if(Qi.test(t)){const h=t.replace(No,""),[f,p,d]=Io.exec(h).slice(1,4).map(g=>parseInt(g));Object.assign(this,{_a:f,_b:p,_c:d,_d:0,space:"rgb"})}else if(Vi.test(t)){const h=g=>parseInt(g,16),[,f,p,d]=Oo.exec(Yo(t)).map(h);Object.assign(this,{_a:f,_b:p,_c:d,_d:0,space:"rgb"})}else throw Error("Unsupported string format, can't construct Color");const{_a:o,_b:a,_c:c,_d:l}=this,u=this.space==="rgb"?{r:o,g:a,b:c}:this.space==="xyz"?{x:o,y:a,z:c}:this.space==="hsl"?{h:o,s:a,l:c}:this.space==="lab"?{l:o,a,b:c}:this.space==="lch"?{l:o,c:a,h:c}:this.space==="cmyk"?{c:o,m:a,y:c,k:l}:{};Object.assign(this,u)}lab(){const{x:t,y:n,z:i}=this.xyz(),r=116*n-16,s=500*(t-n),o=200*(n-i);return new D(r,s,o,"lab")}lch(){const{l:t,a:n,b:i}=this.lab(),r=Math.sqrt(n**2+i**2);let s=180*Math.atan2(i,n)/Math.PI;return s<0&&(s*=-1,s=360-s),new D(t,r,s,"lch")}rgb(){if(this.space==="rgb")return this;if(Zo(this.space)){let{x:t,y:n,z:i}=this;if(this.space==="lab"||this.space==="lch"){let{l:p,a:d,b:g}=this;if(this.space==="lch"){const{c:ct,h:gt}=this,Xt=Math.PI/180;d=ct*Math.cos(Xt*gt),g=ct*Math.sin(Xt*gt)}const y=(p+16)/116,A=d/500+y,_=y-g/200,$=16/116,st=.008856,F=7.787;t=.95047*(A**3>st?A**3:(A-$)/F),n=1*(y**3>st?y**3:(y-$)/F),i=1.08883*(_**3>st?_**3:(_-$)/F)}const r=t*3.2406+n*-1.5372+i*-.4986,s=t*-.9689+n*1.8758+i*.0415,o=t*.0557+n*-.204+i*1.057,a=Math.pow,c=.0031308,l=r>c?1.055*a(r,1/2.4)-.055:12.92*r,u=s>c?1.055*a(s,1/2.4)-.055:12.92*s,h=o>c?1.055*a(o,1/2.4)-.055:12.92*o;return new D(255*l,255*u,255*h)}else if(this.space==="hsl"){let{h:t,s:n,l:i}=this;if(t/=360,n/=100,i/=100,n===0)return i*=255,new D(i,i,i);const r=i<.5?i*(1+n):i+n-i*n,s=2*i-r,o=255*On(s,r,t+1/3),a=255*On(s,r,t),c=255*On(s,r,t-1/3);return new D(o,a,c)}else if(this.space==="cmyk"){const{c:t,m:n,y:i,k:r}=this,s=255*(1-Math.min(1,t*(1-r)+r)),o=255*(1-Math.min(1,n*(1-r)+r)),a=255*(1-Math.min(1,i*(1-r)+r));return new D(s,o,a)}else return this}toArray(){const{_a:t,_b:n,_c:i,_d:r,space:s}=this;return[t,n,i,r,s]}toHex(){const[t,n,i]=this._clamped().map(qo);return`#${t}${n}${i}`}toRgb(){const[t,n,i]=this._clamped();return`rgb(${t},${n},${i})`}toString(){return this.toHex()}xyz(){const{_a:t,_b:n,_c:i}=this.rgb(),[r,s,o]=[t,n,i].map(A=>A/255),a=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92,c=s>.04045?Math.pow((s+.055)/1.055,2.4):s/12.92,l=o>.04045?Math.pow((o+.055)/1.055,2.4):o/12.92,u=(a*.4124+c*.3576+l*.1805)/.95047,h=(a*.2126+c*.7152+l*.0722)/1,f=(a*.0193+c*.1192+l*.9505)/1.08883,p=u>.008856?Math.pow(u,1/3):7.787*u+16/116,d=h>.008856?Math.pow(h,1/3):7.787*h+16/116,g=f>.008856?Math.pow(f,1/3):7.787*f+16/116;return new D(p,d,g,"xyz")}_clamped(){const{_a:t,_b:n,_c:i}=this.rgb(),{max:r,min:s,round:o}=Math,a=c=>r(0,s(o(c),255));return[t,n,i].map(a)}}class P{constructor(...t){this.init(...t)}clone(){return new P(this)}init(t,n){const i={x:0,y:0},r=Array.isArray(t)?{x:t[0],y:t[1]}:typeof t=="object"?{x:t.x,y:t.y}:{x:t,y:n};return this.x=r.x==null?i.x:r.x,this.y=r.y==null?i.y:r.y,this}toArray(){return[this.x,this.y]}transform(t){return this.clone().transformO(t)}transformO(t){k.isMatrixLike(t)||(t=new k(t));const{x:n,y:i}=this;return this.x=t.a*n+t.c*i+t.e,this.y=t.b*n+t.d*i+t.f,this}}function Xo(e,t){return new P(e,t).transformO(this.screenCTM().inverseO())}function Vt(e,t,n){return Math.abs(t-e)<1e-6}class k{constructor(...t){this.init(...t)}static formatTransforms(t){const n=t.flip==="both"||t.flip===!0,i=t.flip&&(n||t.flip==="x")?-1:1,r=t.flip&&(n||t.flip==="y")?-1:1,s=t.skew&&t.skew.length?t.skew[0]:isFinite(t.skew)?t.skew:isFinite(t.skewX)?t.skewX:0,o=t.skew&&t.skew.length?t.skew[1]:isFinite(t.skew)?t.skew:isFinite(t.skewY)?t.skewY:0,a=t.scale&&t.scale.length?t.scale[0]*i:isFinite(t.scale)?t.scale*i:isFinite(t.scaleX)?t.scaleX*i:i,c=t.scale&&t.scale.length?t.scale[1]*r:isFinite(t.scale)?t.scale*r:isFinite(t.scaleY)?t.scaleY*r:r,l=t.shear||0,u=t.rotate||t.theta||0,h=new P(t.origin||t.around||t.ox||t.originX,t.oy||t.originY),f=h.x,p=h.y,d=new P(t.position||t.px||t.positionX||NaN,t.py||t.positionY||NaN),g=d.x,y=d.y,A=new P(t.translate||t.tx||t.translateX,t.ty||t.translateY),_=A.x,$=A.y,st=new P(t.relative||t.rx||t.relativeX,t.ry||t.relativeY),F=st.x,ct=st.y;return{scaleX:a,scaleY:c,skewX:s,skewY:o,shear:l,theta:u,rx:F,ry:ct,tx:_,ty:$,ox:f,oy:p,px:g,py:y}}static fromArray(t){return{a:t[0],b:t[1],c:t[2],d:t[3],e:t[4],f:t[5]}}static isMatrixLike(t){return t.a!=null||t.b!=null||t.c!=null||t.d!=null||t.e!=null||t.f!=null}static matrixMultiply(t,n,i){const r=t.a*n.a+t.c*n.b,s=t.b*n.a+t.d*n.b,o=t.a*n.c+t.c*n.d,a=t.b*n.c+t.d*n.d,c=t.e+t.a*n.e+t.c*n.f,l=t.f+t.b*n.e+t.d*n.f;return i.a=r,i.b=s,i.c=o,i.d=a,i.e=c,i.f=l,i}around(t,n,i){return this.clone().aroundO(t,n,i)}aroundO(t,n,i){const r=t||0,s=n||0;return this.translateO(-r,-s).lmultiplyO(i).translateO(r,s)}clone(){return new k(this)}decompose(t=0,n=0){const i=this.a,r=this.b,s=this.c,o=this.d,a=this.e,c=this.f,l=i*o-r*s,u=l>0?1:-1,h=u*Math.sqrt(i*i+r*r),f=Math.atan2(u*r,u*i),p=180/Math.PI*f,d=Math.cos(f),g=Math.sin(f),y=(i*s+r*o)/l,A=s*h/(y*i-r)||o*h/(y*r+i),_=a-t+t*d*h+n*(y*d*h-g*A),$=c-n+t*g*h+n*(y*g*h+d*A);return{scaleX:h,scaleY:A,shear:y,rotate:p,translateX:_,translateY:$,originX:t,originY:n,a:this.a,b:this.b,c:this.c,d:this.d,e:this.e,f:this.f}}equals(t){if(t===this)return!0;const n=new k(t);return Vt(this.a,n.a)&&Vt(this.b,n.b)&&Vt(this.c,n.c)&&Vt(this.d,n.d)&&Vt(this.e,n.e)&&Vt(this.f,n.f)}flip(t,n){return this.clone().flipO(t,n)}flipO(t,n){return t==="x"?this.scaleO(-1,1,n,0):t==="y"?this.scaleO(1,-1,0,n):this.scaleO(-1,-1,t,n||t)}init(t){const n=k.fromArray([1,0,0,1,0,0]);return t=t instanceof mt?t.matrixify():typeof t=="string"?k.fromArray(t.split(At).map(parseFloat)):Array.isArray(t)?k.fromArray(t):typeof t=="object"&&k.isMatrixLike(t)?t:typeof t=="object"?new k().transform(t):arguments.length===6?k.fromArray([].slice.call(arguments)):n,this.a=t.a!=null?t.a:n.a,this.b=t.b!=null?t.b:n.b,this.c=t.c!=null?t.c:n.c,this.d=t.d!=null?t.d:n.d,this.e=t.e!=null?t.e:n.e,this.f=t.f!=null?t.f:n.f,this}inverse(){return this.clone().inverseO()}inverseO(){const t=this.a,n=this.b,i=this.c,r=this.d,s=this.e,o=this.f,a=t*r-n*i;if(!a)throw new Error("Cannot invert "+this);const c=r/a,l=-n/a,u=-i/a,h=t/a,f=-(c*s+u*o),p=-(l*s+h*o);return this.a=c,this.b=l,this.c=u,this.d=h,this.e=f,this.f=p,this}lmultiply(t){return this.clone().lmultiplyO(t)}lmultiplyO(t){const n=this,i=t instanceof k?t:new k(t);return k.matrixMultiply(i,n,this)}multiply(t){return this.clone().multiplyO(t)}multiplyO(t){const n=this,i=t instanceof k?t:new k(t);return k.matrixMultiply(n,i,this)}rotate(t,n,i){return this.clone().rotateO(t,n,i)}rotateO(t,n=0,i=0){t=Sn(t);const r=Math.cos(t),s=Math.sin(t),{a:o,b:a,c,d:l,e:u,f:h}=this;return this.a=o*r-a*s,this.b=a*r+o*s,this.c=c*r-l*s,this.d=l*r+c*s,this.e=u*r-h*s+i*s-n*r+n,this.f=h*r+u*s-n*s-i*r+i,this}scale(){return this.clone().scaleO(...arguments)}scaleO(t,n=t,i=0,r=0){arguments.length===3&&(r=i,i=n,n=t);const{a:s,b:o,c:a,d:c,e:l,f:u}=this;return this.a=s*t,this.b=o*n,this.c=a*t,this.d=c*n,this.e=l*t-i*t+i,this.f=u*n-r*n+r,this}shear(t,n,i){return this.clone().shearO(t,n,i)}shearO(t,n=0,i=0){const{a:r,b:s,c:o,d:a,e:c,f:l}=this;return this.a=r+s*t,this.c=o+a*t,this.e=c+l*t-i*t,this}skew(){return this.clone().skewO(...arguments)}skewO(t,n=t,i=0,r=0){arguments.length===3&&(r=i,i=n,n=t),t=Sn(t),n=Sn(n);const s=Math.tan(t),o=Math.tan(n),{a,b:c,c:l,d:u,e:h,f}=this;return this.a=a+c*s,this.b=c+a*o,this.c=l+u*s,this.d=u+l*o,this.e=h+f*s-r*s,this.f=f+h*o-i*o,this}skewX(t,n,i){return this.skew(t,0,n,i)}skewY(t,n,i){return this.skew(0,t,n,i)}toArray(){return[this.a,this.b,this.c,this.d,this.e,this.f]}toString(){return"matrix("+this.a+","+this.b+","+this.c+","+this.d+","+this.e+","+this.f+")"}transform(t){if(k.isMatrixLike(t))return new k(t).multiplyO(this);const n=k.formatTransforms(t),i=this,{x:r,y:s}=new P(n.ox,n.oy).transform(i),o=new k().translateO(n.rx,n.ry).lmultiplyO(i).translateO(-r,-s).scaleO(n.scaleX,n.scaleY).skewO(n.skewX,n.skewY).shearO(n.shear).rotateO(n.theta).translateO(r,s);if(isFinite(n.px)||isFinite(n.py)){const a=new P(r,s).transform(o),c=isFinite(n.px)?n.px-a.x:0,l=isFinite(n.py)?n.py-a.y:0;o.translateO(c,l)}return o.translateO(n.tx,n.ty),o}translate(t,n){return this.clone().translateO(t,n)}translateO(t,n){return this.e+=t||0,this.f+=n||0,this}valueOf(){return{a:this.a,b:this.b,c:this.c,d:this.d,e:this.e,f:this.f}}}function Jo(){return new k(this.node.getCTM())}function Vo(){try{if(typeof this.isRoot=="function"&&!this.isRoot()){const e=this.rect(1,1),t=e.node.getScreenCTM();return e.remove(),new k(t)}return new k(this.node.getScreenCTM())}catch{return console.warn(`Cannot get CTM from SVG node ${this.node.nodeName}. Is the element rendered?`),new k}}N(k,"Matrix");function St(){if(!St.nodes){const e=J().size(2,0);e.node.style.cssText=["opacity: 0","position: absolute","left: -100%","top: -100%","overflow: hidden"].join(";"),e.attr("focusable","false"),e.attr("aria-hidden","true");const t=e.path().node;St.nodes={svg:e,path:t}}if(!St.nodes.svg.node.parentNode){const e=C.document.body||C.document.documentElement;St.nodes.svg.addTo(e)}return St.nodes}function Dr(e){return!e.width&&!e.height&&!e.x&&!e.y}function Qo(e){return e===C.document||(C.document.documentElement.contains||function(t){for(;t.parentNode;)t=t.parentNode;return t===C.document}).call(C.document.documentElement,e)}class z{constructor(...t){this.init(...t)}addOffset(){return this.x+=C.window.pageXOffset,this.y+=C.window.pageYOffset,new z(this)}init(t){const n=[0,0,0,0];return t=typeof t=="string"?t.split(At).map(parseFloat):Array.isArray(t)?t:typeof t=="object"?[t.left!=null?t.left:t.x,t.top!=null?t.top:t.y,t.width,t.height]:arguments.length===4?[].slice.call(arguments):n,this.x=t[0]||0,this.y=t[1]||0,this.width=this.w=t[2]||0,this.height=this.h=t[3]||0,this.x2=this.x+this.w,this.y2=this.y+this.h,this.cx=this.x+this.w/2,this.cy=this.y+this.h/2,this}isNulled(){return Dr(this)}merge(t){const n=Math.min(this.x,t.x),i=Math.min(this.y,t.y),r=Math.max(this.x+this.width,t.x+t.width)-n,s=Math.max(this.y+this.height,t.y+t.height)-i;return new z(n,i,r,s)}toArray(){return[this.x,this.y,this.width,this.height]}toString(){return this.x+" "+this.y+" "+this.width+" "+this.height}transform(t){t instanceof k||(t=new k(t));let n=1/0,i=-1/0,r=1/0,s=-1/0;return[new P(this.x,this.y),new P(this.x2,this.y),new P(this.x,this.y2),new P(this.x2,this.y2)].forEach(function(a){a=a.transform(t),n=Math.min(n,a.x),i=Math.max(i,a.x),r=Math.min(r,a.y),s=Math.max(s,a.y)}),new z(n,r,i-n,s-r)}}function Rr(e,t,n){let i;try{if(i=t(e.node),Dr(i)&&!Qo(e.node))throw new Error("Element not in the dom")}catch{i=n(e)}return i}function ta(){const n=Rr(this,r=>r.getBBox(),r=>{try{const s=r.clone().addTo(St().svg).show(),o=s.node.getBBox();return s.remove(),o}catch(s){throw new Error(`Getting bbox of element "${r.node.nodeName}" is not possible: ${s.toString()}`)}});return new z(n)}function ea(e){const i=Rr(this,s=>s.getBoundingClientRect(),s=>{throw new Error(`Getting rbox of element "${s.node.nodeName}" is not possible`)}),r=new z(i);return e?r.transform(e.screenCTM().inverseO()):r.addOffset()}function na(e,t){const n=this.bbox();return e>n.x&&t>n.y&&e<n.x+n.width&&t<n.y+n.height}I({viewbox:{viewbox(e,t,n,i){return e==null?new z(this.attr("viewBox")):this.attr("viewBox",new z(e,t,n,i))},zoom(e,t){let{width:n,height:i}=this.attr(["width","height"]);if((!n&&!i||typeof n=="string"||typeof i=="string")&&(n=this.node.clientWidth,i=this.node.clientHeight),!n||!i)throw new Error("Impossible to get absolute width and height. Please provide an absolute width and height attribute on the zooming element");const r=this.viewbox(),s=n/r.width,o=i/r.height,a=Math.min(s,o);if(e==null)return a;let c=a/e;c===1/0&&(c=Number.MAX_SAFE_INTEGER/100),t=t||new P(n/2/s+r.x,i/2/o+r.y);const l=new z(r).transform(new k({scale:c,origin:t}));return this.viewbox(l)}}});N(z,"Box");class Kt extends Array{constructor(t=[],...n){if(super(t,...n),typeof t=="number")return this;this.length=0,this.push(...t)}}E([Kt],{each(e,...t){return typeof e=="function"?this.map((n,i,r)=>e.call(n,n,i,r)):this.map(n=>n[e](...t))},toArray(){return Array.prototype.concat.apply([],this)}});const ia=["toArray","constructor","each"];Kt.extend=function(e){e=e.reduce((t,n)=>(ia.includes(n)||n[0]==="_"||(n in Array.prototype&&(t["$"+n]=Array.prototype[n]),t[n]=function(...i){return this.each(n,...i)}),t),{}),E([Kt],e)};function xe(e,t){return new Kt(yi((t||C.document).querySelectorAll(e),function(n){return at(n)}))}function ra(e){return xe(e,this.node)}function sa(e){return at(this.node.querySelector(e))}let oa=0;const Br={};function Hr(e){let t=e.getEventHolder();return t===C.window&&(t=Br),t.events||(t.events={}),t.events}function vi(e){return e.getEventTarget()}function aa(e){let t=e.getEventHolder();t===C.window&&(t=Br),t.events&&(t.events={})}function zn(e,t,n,i,r){const s=n.bind(i||e),o=J(e),a=Hr(o),c=vi(o);t=Array.isArray(t)?t:t.split(At),n._svgjsListenerId||(n._svgjsListenerId=++oa),t.forEach(function(l){const u=l.split(".")[0],h=l.split(".")[1]||"*";a[u]=a[u]||{},a[u][h]=a[u][h]||{},a[u][h][n._svgjsListenerId]=s,c.addEventListener(u,s,r||!1)})}function ne(e,t,n,i){const r=J(e),s=Hr(r),o=vi(r);typeof n=="function"&&(n=n._svgjsListenerId,!n)||(t=Array.isArray(t)?t:(t||"").split(At),t.forEach(function(a){const c=a&&a.split(".")[0],l=a&&a.split(".")[1];let u,h;if(n)s[c]&&s[c][l||"*"]&&(o.removeEventListener(c,s[c][l||"*"][n],i||!1),delete s[c][l||"*"][n]);else if(c&&l){if(s[c]&&s[c][l]){for(h in s[c][l])ne(o,[c,l].join("."),h);delete s[c][l]}}else if(l)for(a in s)for(u in s[a])l===u&&ne(o,[a,l].join("."));else if(c){if(s[c]){for(u in s[c])ne(o,[c,u].join("."));delete s[c]}}else{for(a in s)ne(o,a);aa(r)}}))}function ca(e,t,n,i){const r=vi(e);return t instanceof C.window.Event||(t=new C.window.CustomEvent(t,{detail:n,cancelable:!0,...i})),r.dispatchEvent(t),t}class ze extends _i{addEventListener(){}dispatch(t,n,i){return ca(this,t,n,i)}dispatchEvent(t){const n=this.getEventHolder().events;if(!n)return!0;const i=n[t.type];for(const r in i)for(const s in i[r])i[r][s](t);return!t.defaultPrevented}fire(t,n,i){return this.dispatch(t,n,i),this}getEventHolder(){return this}getEventTarget(){return this}off(t,n,i){return ne(this,t,n,i),this}on(t,n,i,r){return zn(this,t,n,i,r),this}removeEventListener(){}}N(ze,"EventTarget");function nr(){}const Te={duration:400,ease:">",delay:0},la={"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,"stroke-linejoin":"miter","stroke-linecap":"butt",fill:"#000000",stroke:"#000000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0,"stop-opacity":1,"stop-color":"#000000","text-anchor":"start"};class le extends Array{constructor(...t){super(...t),this.init(...t)}clone(){return new this.constructor(this)}init(t){return typeof t=="number"?this:(this.length=0,this.push(...this.parse(t)),this)}parse(t=[]){return t instanceof Array?t:t.trim().split(At).map(parseFloat)}toArray(){return Array.prototype.concat.apply([],this)}toSet(){return new Set(this)}toString(){return this.join(" ")}valueOf(){const t=[];return t.push(...this),t}}class O{constructor(...t){this.init(...t)}convert(t){return new O(this.value,t)}divide(t){return t=new O(t),new O(this/t,this.unit||t.unit)}init(t,n){return n=Array.isArray(t)?t[1]:n,t=Array.isArray(t)?t[0]:t,this.value=0,this.unit=n||"",typeof t=="number"?this.value=isNaN(t)?0:isFinite(t)?t:t<0?-34e37:34e37:typeof t=="string"?(n=t.match(Mr),n&&(this.value=parseFloat(n[1]),n[5]==="%"?this.value/=100:n[5]==="s"&&(this.value*=1e3),this.unit=n[5])):t instanceof O&&(this.value=t.valueOf(),this.unit=t.unit),this}minus(t){return t=new O(t),new O(this-t,this.unit||t.unit)}plus(t){return t=new O(t),new O(this+t,this.unit||t.unit)}times(t){return t=new O(t),new O(this*t,this.unit||t.unit)}toArray(){return[this.value,this.unit]}toJSON(){return this.toString()}toString(){return(this.unit==="%"?~~(this.value*1e8)/1e6:this.unit==="s"?this.value/1e3:this.value)+this.unit}valueOf(){return this.value}}const ua=new Set(["fill","stroke","color","bgcolor","stop-color","flood-color","lighting-color"]),$r=[];function ha(e){$r.push(e)}function fa(e,t,n){if(e==null){e={},t=this.node.attributes;for(const i of t)e[i.nodeName]=er.test(i.nodeValue)?parseFloat(i.nodeValue):i.nodeValue;return e}else{if(e instanceof Array)return e.reduce((i,r)=>(i[r]=this.attr(r),i),{});if(typeof e=="object"&&e.constructor===Object)for(t in e)this.attr(t,e[t]);else if(t===null)this.node.removeAttribute(e);else{if(t==null)return t=this.node.getAttribute(e),t==null?la[e]:er.test(t)?parseFloat(t):t;t=$r.reduce((i,r)=>r(e,i,this),t),typeof t=="number"?t=new O(t):ua.has(e)&&D.isColor(t)?t=new D(t):t.constructor===Array&&(t=new le(t)),e==="leading"?this.leading&&this.leading(t):typeof n=="string"?this.node.setAttributeNS(n,e,t.toString()):this.node.setAttribute(e,t.toString()),this.rebuild&&(e==="font-size"||e==="x")&&this.rebuild()}}return this}class Ct extends ze{constructor(t,n){super(),this.node=t,this.type=t.nodeName,n&&t!==n&&this.attr(n)}add(t,n){return t=J(t),t.removeNamespace&&this.node instanceof C.window.SVGElement&&t.removeNamespace(),n==null?this.node.appendChild(t.node):t.node!==this.node.childNodes[n]&&this.node.insertBefore(t.node,this.node.childNodes[n]),this}addTo(t,n){return J(t).put(this,n)}children(){return new Kt(yi(this.node.children,function(t){return at(t)}))}clear(){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return this}clone(t=!0,n=!0){this.writeDataToDom();let i=this.node.cloneNode(t);return n&&(i=Nr(i)),new this.constructor(i)}each(t,n){const i=this.children();let r,s;for(r=0,s=i.length;r<s;r++)t.apply(i[r],[r,i]),n&&i[r].each(t,n);return this}element(t,n){return this.put(new Ct(Me(t),n))}first(){return at(this.node.firstChild)}get(t){return at(this.node.childNodes[t])}getEventHolder(){return this.node}getEventTarget(){return this.node}has(t){return this.index(t)>=0}html(t,n){return this.xml(t,n,uo)}id(t){return typeof t>"u"&&!this.node.id&&(this.node.id=Cr(this.type)),this.attr("id",t)}index(t){return[].slice.call(this.node.childNodes).indexOf(t.node)}last(){return at(this.node.lastChild)}matches(t){const n=this.node,i=n.matches||n.matchesSelector||n.msMatchesSelector||n.mozMatchesSelector||n.webkitMatchesSelector||n.oMatchesSelector||null;return i&&i.call(n,t)}parent(t){let n=this;if(!n.node.parentNode)return null;if(n=at(n.node.parentNode),!t)return n;do if(typeof t=="string"?n.matches(t):n instanceof t)return n;while(n=at(n.node.parentNode));return n}put(t,n){return t=J(t),this.add(t,n),t}putIn(t,n){return J(t).add(this,n)}remove(){return this.parent()&&this.parent().removeElement(this),this}removeElement(t){return this.node.removeChild(t.node),this}replace(t){return t=J(t),this.node.parentNode&&this.node.parentNode.replaceChild(t.node,this.node),t}round(t=2,n=null){const i=10**t,r=this.attr(n);for(const s in r)typeof r[s]=="number"&&(r[s]=Math.round(r[s]*i)/i);return this.attr(r),this}svg(t,n){return this.xml(t,n,wi)}toString(){return this.id()}words(t){return this.node.textContent=t,this}wrap(t){const n=this.parent();if(!n)return this.addTo(t);const i=n.index(this);return n.put(t,i).put(this)}writeDataToDom(){return this.each(function(){this.writeDataToDom()}),this}xml(t,n,i){if(typeof t=="boolean"&&(i=n,n=t,t=null),t==null||typeof t=="function"){n=n??!0,this.writeDataToDom();let a=this;if(t!=null){if(a=at(a.node.cloneNode(!0)),n){const c=t(a);if(a=c||a,c===!1)return""}a.each(function(){const c=t(this),l=c||this;c===!1?this.remove():c&&this!==l&&this.replace(l)},!0)}return n?a.node.outerHTML:a.node.innerHTML}n=n??!1;const r=Me("wrapper",i),s=C.document.createDocumentFragment();r.innerHTML=t;for(let a=r.children.length;a--;)s.appendChild(r.firstElementChild);const o=this.parent();return n?this.replace(s)&&o:this.add(s)}}E(Ct,{attr:fa,find:ra,findOne:sa});N(Ct,"Dom");class mt extends Ct{constructor(t,n){super(t,n),this.dom={},this.node.instance=this,(t.hasAttribute("data-svgjs")||t.hasAttribute("svgjs:data"))&&this.setData(JSON.parse(t.getAttribute("data-svgjs"))??JSON.parse(t.getAttribute("svgjs:data"))??{})}center(t,n){return this.cx(t).cy(n)}cx(t){return t==null?this.x()+this.width()/2:this.x(t-this.width()/2)}cy(t){return t==null?this.y()+this.height()/2:this.y(t-this.height()/2)}defs(){const t=this.root();return t&&t.defs()}dmove(t,n){return this.dx(t).dy(n)}dx(t=0){return this.x(new O(t).plus(this.x()))}dy(t=0){return this.y(new O(t).plus(this.y()))}getEventHolder(){return this}height(t){return this.attr("height",t)}move(t,n){return this.x(t).y(n)}parents(t=this.root()){const n=typeof t=="string";n||(t=J(t));const i=new Kt;let r=this;for(;(r=r.parent())&&r.node!==C.document&&r.nodeName!=="#document-fragment"&&(i.push(r),!(!n&&r.node===t.node||n&&r.matches(t)));)if(r.node===this.root().node)return null;return i}reference(t){if(t=this.attr(t),!t)return null;const n=(t+"").match(Eo);return n?J(n[1]):null}root(){const t=this.parent(fo(bi));return t&&t.root()}setData(t){return this.dom=t,this}size(t,n){const i=be(this,t,n);return this.width(new O(i.width)).height(new O(i.height))}width(t){return this.attr("width",t)}writeDataToDom(){return Er(this,this.dom),super.writeDataToDom()}x(t){return this.attr("x",t)}y(t){return this.attr("y",t)}}E(mt,{bbox:ta,rbox:ea,inside:na,point:Xo,ctm:Jo,screenCTM:Vo});N(mt,"Element");const Ae={stroke:["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],fill:["color","opacity","rule"],prefix:function(e,t){return t==="color"?e:e+"-"+t}};["fill","stroke"].forEach(function(e){const t={};let n;t[e]=function(i){if(typeof i>"u")return this.attr(e);if(typeof i=="string"||i instanceof D||D.isRgb(i)||i instanceof mt)this.attr(e,i);else for(n=Ae[e].length-1;n>=0;n--)i[Ae[e][n]]!=null&&this.attr(Ae.prefix(e,Ae[e][n]),i[Ae[e][n]]);return this},I(["Element","Runner"],t)});I(["Element","Runner"],{matrix:function(e,t,n,i,r,s){return e==null?new k(this):this.attr("transform",new k(e,t,n,i,r,s))},rotate:function(e,t,n){return this.transform({rotate:e,ox:t,oy:n},!0)},skew:function(e,t,n,i){return arguments.length===1||arguments.length===3?this.transform({skew:e,ox:t,oy:n},!0):this.transform({skew:[e,t],ox:n,oy:i},!0)},shear:function(e,t,n){return this.transform({shear:e,ox:t,oy:n},!0)},scale:function(e,t,n,i){return arguments.length===1||arguments.length===3?this.transform({scale:e,ox:t,oy:n},!0):this.transform({scale:[e,t],ox:n,oy:i},!0)},translate:function(e,t){return this.transform({translate:[e,t]},!0)},relative:function(e,t){return this.transform({relative:[e,t]},!0)},flip:function(e="both",t="center"){return"xybothtrue".indexOf(e)===-1&&(t=e,e="both"),this.transform({flip:e,origin:t},!0)},opacity:function(e){return this.attr("opacity",e)}});I("radius",{radius:function(e,t=e){return(this._element||this).type==="radialGradient"?this.attr("r",new O(e)):this.rx(e).ry(t)}});I("Path",{length:function(){return this.node.getTotalLength()},pointAt:function(e){return new P(this.node.getPointAtLength(e))}});I(["Element","Runner"],{font:function(e,t){if(typeof e=="object"){for(t in e)this.font(t,e[t]);return this}return e==="leading"?this.leading(t):e==="anchor"?this.attr("text-anchor",t):e==="size"||e==="family"||e==="weight"||e==="stretch"||e==="variant"||e==="style"?this.attr("font-"+e,t):this.attr(e,t)}});const da=["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchmove","touchleave","touchend","touchcancel","contextmenu","wheel","pointerdown","pointermove","pointerup","pointerleave","pointercancel"].reduce(function(e,t){const n=function(i){return i===null?this.off(t):this.on(t,i),this};return e[t]=n,e},{});I("Element",da);function pa(){return this.attr("transform",null)}function ma(){return(this.attr("transform")||"").split(Co).slice(0,-1).map(function(t){const n=t.trim().split("(");return[n[0],n[1].split(At).map(function(i){return parseFloat(i)})]}).reverse().reduce(function(t,n){return n[0]==="matrix"?t.lmultiply(k.fromArray(n[1])):t[n[0]].apply(t,n[1])},new k)}function ga(e,t){if(this===e)return this;if(Wn(this.node))return this.addTo(e,t);const n=this.screenCTM(),i=e.screenCTM().inverse();return this.addTo(e,t).untransform().transform(i.multiply(n)),this}function ya(e){return this.toParent(this.root(),e)}function wa(e,t){if(e==null||typeof e=="string"){const r=new k(this).decompose();return e==null?r:r[e]}k.isMatrixLike(e)||(e={...e,origin:Ln(e,this)});const n=t===!0?this:t||!1,i=new k(n).transform(e);return this.attr("transform",i)}I("Element",{untransform:pa,matrixify:ma,toParent:ga,toRoot:ya,transform:wa});class tt extends mt{flatten(){return this.each(function(){if(this instanceof tt)return this.flatten().ungroup()}),this}ungroup(t=this.parent(),n=t.index(this)){return n=n===-1?t.children().length:n,this.each(function(i,r){return r[r.length-i-1].toParent(t,n)}),this.remove()}}N(tt,"Container");class Ai extends tt{constructor(t,n=t){super(H("defs",t),n)}flatten(){return this}ungroup(){return this}}N(Ai,"Defs");class rt extends mt{}N(rt,"Shape");function Si(e){return this.attr("rx",e)}function ki(e){return this.attr("ry",e)}function Pr(e){return e==null?this.cx()-this.rx():this.cx(e+this.rx())}function jr(e){return e==null?this.cy()-this.ry():this.cy(e+this.ry())}function Lr(e){return this.attr("cx",e)}function Wr(e){return this.attr("cy",e)}function zr(e){return e==null?this.rx()*2:this.rx(new O(e).divide(2))}function Fr(e){return e==null?this.ry()*2:this.ry(new O(e).divide(2))}const _a=Object.freeze(Object.defineProperty({__proto__:null,cx:Lr,cy:Wr,height:Fr,rx:Si,ry:ki,width:zr,x:Pr,y:jr},Symbol.toStringTag,{value:"Module"}));class yn extends rt{constructor(t,n=t){super(H("ellipse",t),n)}size(t,n){const i=be(this,t,n);return this.rx(new O(i.width).divide(2)).ry(new O(i.height).divide(2))}}E(yn,_a);I("Container",{ellipse:B(function(e=0,t=e){return this.put(new yn).size(e,t).move(0,0)})});N(yn,"Ellipse");class Kr extends Ct{constructor(t=C.document.createDocumentFragment()){super(t)}xml(t,n,i){if(typeof t=="boolean"&&(i=n,n=t,t=null),t==null||typeof t=="function"){const r=new Ct(Me("wrapper",i));return r.add(this.node.cloneNode(!0)),r.xml(!1,i)}return super.xml(t,!1,i)}}N(Kr,"Fragment");function Ur(e,t){return(this._element||this).type==="radialGradient"?this.attr({fx:new O(e),fy:new O(t)}):this.attr({x1:new O(e),y1:new O(t)})}function Yr(e,t){return(this._element||this).type==="radialGradient"?this.attr({cx:new O(e),cy:new O(t)}):this.attr({x2:new O(e),y2:new O(t)})}const ba=Object.freeze(Object.defineProperty({__proto__:null,from:Ur,to:Yr},Symbol.toStringTag,{value:"Module"}));class Fe extends tt{constructor(t,n){super(H(t+"Gradient",typeof t=="string"?null:t),n)}attr(t,n,i){return t==="transform"&&(t="gradientTransform"),super.attr(t,n,i)}bbox(){return new z}targets(){return xe("svg [fill*="+this.id()+"]")}toString(){return this.url()}update(t){return this.clear(),typeof t=="function"&&t.call(this,this),this}url(){return"url(#"+this.id()+")"}}E(Fe,ba);I({Container:{gradient(...e){return this.defs().gradient(...e)}},Defs:{gradient:B(function(e,t){return this.put(new Fe(e)).update(t)})}});N(Fe,"Gradient");class De extends tt{constructor(t,n=t){super(H("pattern",t),n)}attr(t,n,i){return t==="transform"&&(t="patternTransform"),super.attr(t,n,i)}bbox(){return new z}targets(){return xe("svg [fill*="+this.id()+"]")}toString(){return this.url()}update(t){return this.clear(),typeof t=="function"&&t.call(this,this),this}url(){return"url(#"+this.id()+")"}}I({Container:{pattern(...e){return this.defs().pattern(...e)}},Defs:{pattern:B(function(e,t,n){return this.put(new De).update(n).attr({x:0,y:0,width:e,height:t,patternUnits:"userSpaceOnUse"})})}});N(De,"Pattern");class Ke extends rt{constructor(t,n=t){super(H("image",t),n)}load(t,n){if(!t)return this;const i=new C.window.Image;return zn(i,"load",function(r){const s=this.parent(De);this.width()===0&&this.height()===0&&this.size(i.width,i.height),s instanceof De&&s.width()===0&&s.height()===0&&s.size(this.width(),this.height()),typeof n=="function"&&n.call(this,r)},this),zn(i,"load error",function(){ne(i)}),this.attr("href",i.src=t,We)}}ha(function(e,t,n){return(e==="fill"||e==="stroke")&&Mo.test(t)&&(t=n.root().defs().image(t)),t instanceof Ke&&(t=n.root().defs().pattern(0,0,i=>{i.add(t)})),t});I({Container:{image:B(function(e,t){return this.put(new Ke).size(0,0).load(e,t)})}});N(Ke,"Image");class Nt extends le{bbox(){let t=-1/0,n=-1/0,i=1/0,r=1/0;return this.forEach(function(s){t=Math.max(s[0],t),n=Math.max(s[1],n),i=Math.min(s[0],i),r=Math.min(s[1],r)}),new z(i,r,t-i,n-r)}move(t,n){const i=this.bbox();if(t-=i.x,n-=i.y,!isNaN(t)&&!isNaN(n))for(let r=this.length-1;r>=0;r--)this[r]=[this[r][0]+t,this[r][1]+n];return this}parse(t=[0,0]){const n=[];t instanceof Array?t=Array.prototype.concat.apply([],t):t=t.trim().split(At).map(parseFloat),t.length%2!==0&&t.pop();for(let i=0,r=t.length;i<r;i=i+2)n.push([t[i],t[i+1]]);return n}size(t,n){let i;const r=this.bbox();for(i=this.length-1;i>=0;i--)r.width&&(this[i][0]=(this[i][0]-r.x)*t/r.width+r.x),r.height&&(this[i][1]=(this[i][1]-r.y)*n/r.height+r.y);return this}toLine(){return{x1:this[0][0],y1:this[0][1],x2:this[1][0],y2:this[1][1]}}toString(){const t=[];for(let n=0,i=this.length;n<i;n++)t.push(this[n].join(","));return t.join(" ")}transform(t){return this.clone().transformO(t)}transformO(t){k.isMatrixLike(t)||(t=new k(t));for(let n=this.length;n--;){const[i,r]=this[n];this[n][0]=t.a*i+t.c*r+t.e,this[n][1]=t.b*i+t.d*r+t.f}return this}}const xa=Nt;function va(e){return e==null?this.bbox().x:this.move(e,this.bbox().y)}function Aa(e){return e==null?this.bbox().y:this.move(this.bbox().x,e)}function Sa(e){const t=this.bbox();return e==null?t.width:this.size(e,t.height)}function ka(e){const t=this.bbox();return e==null?t.height:this.size(t.width,e)}const Ti=Object.freeze(Object.defineProperty({__proto__:null,MorphArray:xa,height:ka,width:Sa,x:va,y:Aa},Symbol.toStringTag,{value:"Module"}));class Re extends rt{constructor(t,n=t){super(H("line",t),n)}array(){return new Nt([[this.attr("x1"),this.attr("y1")],[this.attr("x2"),this.attr("y2")]])}move(t,n){return this.attr(this.array().move(t,n).toLine())}plot(t,n,i,r){return t==null?this.array():(typeof n<"u"?t={x1:t,y1:n,x2:i,y2:r}:t=new Nt(t).toLine(),this.attr(t))}size(t,n){const i=be(this,t,n);return this.attr(this.array().size(i.width,i.height).toLine())}}E(Re,Ti);I({Container:{line:B(function(...e){return Re.prototype.plot.apply(this.put(new Re),e[0]!=null?e:[0,0,0,0])})}});N(Re,"Line");class rn extends tt{constructor(t,n=t){super(H("marker",t),n)}height(t){return this.attr("markerHeight",t)}orient(t){return this.attr("orient",t)}ref(t,n){return this.attr("refX",t).attr("refY",n)}toString(){return"url(#"+this.id()+")"}update(t){return this.clear(),typeof t=="function"&&t.call(this,this),this}width(t){return this.attr("markerWidth",t)}}I({Container:{marker(...e){return this.defs().marker(...e)}},Defs:{marker:B(function(e,t,n){return this.put(new rn).size(e,t).ref(e/2,t/2).viewbox(0,0,e,t).attr("orient","auto").update(n)})},marker:{marker(e,t,n,i){let r=["marker"];return e!=="all"&&r.push(e),r=r.join("-"),e=arguments[1]instanceof rn?arguments[1]:this.defs().marker(t,n,i),this.attr(r,e)}}});N(rn,"Marker");function ie(e,t){return function(n){return n==null?this[e]:(this[e]=n,t&&t.call(this),this)}}const Ta={"-":function(e){return e},"<>":function(e){return-Math.cos(e*Math.PI)/2+.5},">":function(e){return Math.sin(e*Math.PI/2)},"<":function(e){return-Math.cos(e*Math.PI/2)+1},bezier:function(e,t,n,i){return function(r){return r<0?e>0?t/e*r:n>0?i/n*r:0:r>1?n<1?(1-i)/(1-n)*r+(i-n)/(1-n):e<1?(1-t)/(1-e)*r+(t-e)/(1-e):1:3*r*(1-r)**2*t+3*r**2*(1-r)*i+r**3}},steps:function(e,t="end"){t=t.split("-").reverse()[0];let n=e;return t==="none"?--n:t==="both"&&++n,(i,r=!1)=>{let s=Math.floor(i*e);const o=i*s%1===0;return(t==="start"||t==="both")&&++s,r&&o&&--s,i>=0&&s<0&&(s=0),i<=1&&s>n&&(s=n),s/n}}};class Oi{done(){return!1}}class Fn extends Oi{constructor(t=Te.ease){super(),this.ease=Ta[t]||t}step(t,n,i){return typeof t!="number"?i<1?t:n:t+(n-t)*this.ease(i)}}let sn=class extends Oi{constructor(t){super(),this.stepper=t}done(t){return t.done}step(t,n,i,r){return this.stepper(t,n,i,r)}};function ir(){const e=(this._duration||500)/1e3,t=this._overshoot||0,n=1e-10,i=Math.PI,r=Math.log(t/100+n),s=-r/Math.sqrt(i*i+r*r),o=3.9/(s*e);this.d=2*s*o,this.k=o*o}class Oa extends sn{constructor(t=500,n=0){super(),this.duration(t).overshoot(n)}step(t,n,i,r){if(typeof t=="string")return t;if(r.done=i===1/0,i===1/0)return n;if(i===0)return t;i>100&&(i=16),i/=1e3;const s=r.velocity||0,o=-this.d*s-this.k*(t-n),a=t+s*i+o*i*i/2;return r.velocity=s+o*i,r.done=Math.abs(n-a)+Math.abs(s)<.002,r.done?n:a}}E(Oa,{duration:ie("_duration",ir),overshoot:ie("_overshoot",ir)});class Ia extends sn{constructor(t=.1,n=.01,i=0,r=1e3){super(),this.p(t).i(n).d(i).windup(r)}step(t,n,i,r){if(typeof t=="string")return t;if(r.done=i===1/0,i===1/0)return n;if(i===0)return t;const s=n-t;let o=(r.integral||0)+s*i;const a=(s-(r.error||0))/i,c=this._windup;return c!==!1&&(o=Math.max(-c,Math.min(o,c))),r.error=s,r.integral=o,r.done=Math.abs(s)<.001,r.done?n:t+(this.P*s+this.I*o+this.D*a)}}E(Ia,{windup:ie("_windup"),p:ie("P"),i:ie("I"),d:ie("D")});const Ea={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0},Kn={M:function(e,t,n){return t.x=n.x=e[0],t.y=n.y=e[1],["M",t.x,t.y]},L:function(e,t){return t.x=e[0],t.y=e[1],["L",e[0],e[1]]},H:function(e,t){return t.x=e[0],["H",e[0]]},V:function(e,t){return t.y=e[0],["V",e[0]]},C:function(e,t){return t.x=e[4],t.y=e[5],["C",e[0],e[1],e[2],e[3],e[4],e[5]]},S:function(e,t){return t.x=e[2],t.y=e[3],["S",e[0],e[1],e[2],e[3]]},Q:function(e,t){return t.x=e[2],t.y=e[3],["Q",e[0],e[1],e[2],e[3]]},T:function(e,t){return t.x=e[0],t.y=e[1],["T",e[0],e[1]]},Z:function(e,t,n){return t.x=n.x,t.y=n.y,["Z"]},A:function(e,t){return t.x=e[5],t.y=e[6],["A",e[0],e[1],e[2],e[3],e[4],e[5],e[6]]}},In="mlhvqtcsaz".split("");for(let e=0,t=In.length;e<t;++e)Kn[In[e]]=function(n){return function(i,r,s){if(n==="H")i[0]=i[0]+r.x;else if(n==="V")i[0]=i[0]+r.y;else if(n==="A")i[5]=i[5]+r.x,i[6]=i[6]+r.y;else for(let o=0,a=i.length;o<a;++o)i[o]=i[o]+(o%2?r.y:r.x);return Kn[n](i,r,s)}}(In[e].toUpperCase());function Ca(e){const t=e.segment[0];return Kn[t](e.segment.slice(1),e.p,e.p0)}function Un(e){return e.segment.length&&e.segment.length-1===Ea[e.segment[0].toUpperCase()]}function Na(e,t){e.inNumber&&$t(e,!1);const n=xi.test(t);if(n)e.segment=[t];else{const i=e.lastCommand,r=i.toLowerCase(),s=i===r;e.segment=[r==="m"?s?"l":"L":i]}return e.inSegment=!0,e.lastCommand=e.segment[0],n}function $t(e,t){if(!e.inNumber)throw new Error("Parser Error");e.number&&e.segment.push(parseFloat(e.number)),e.inNumber=t,e.number="",e.pointSeen=!1,e.hasExponent=!1,Un(e)&&Yn(e)}function Yn(e){e.inSegment=!1,e.absolute&&(e.segment=Ca(e)),e.segments.push(e.segment)}function Ma(e){if(!e.segment.length)return!1;const t=e.segment[0].toUpperCase()==="A",n=e.segment.length;return t&&(n===4||n===5)}function Da(e){return e.lastToken.toUpperCase()==="E"}const Ra=new Set([" ",","," ",`
2
+ `,"\r","\f"]);function Ba(e,t=!0){let n=0,i="";const r={segment:[],inNumber:!1,number:"",lastToken:"",inSegment:!1,segments:[],pointSeen:!1,hasExponent:!1,absolute:t,p0:new P,p:new P};for(;r.lastToken=i,i=e.charAt(n++);)if(!(!r.inSegment&&Na(r,i))){if(i==="."){if(r.pointSeen||r.hasExponent){$t(r,!1),--n;continue}r.inNumber=!0,r.pointSeen=!0,r.number+=i;continue}if(!isNaN(parseInt(i))){if(r.number==="0"||Ma(r)){r.inNumber=!0,r.number=i,$t(r,!0);continue}r.inNumber=!0,r.number+=i;continue}if(Ra.has(i)){r.inNumber&&$t(r,!1);continue}if(i==="-"||i==="+"){if(r.inNumber&&!Da(r)){$t(r,!1),--n;continue}r.number+=i,r.inNumber=!0;continue}if(i.toUpperCase()==="E"){r.number+=i,r.hasExponent=!0;continue}if(xi.test(i)){if(r.inNumber)$t(r,!1);else if(Un(r))Yn(r);else throw new Error("parser Error");--n}}return r.inNumber&&$t(r,!1),r.inSegment&&Un(r)&&Yn(r),r.segments}function Ha(e){let t="";for(let n=0,i=e.length;n<i;n++)t+=e[n][0],e[n][1]!=null&&(t+=e[n][1],e[n][2]!=null&&(t+=" ",t+=e[n][2],e[n][3]!=null&&(t+=" ",t+=e[n][3],t+=" ",t+=e[n][4],e[n][5]!=null&&(t+=" ",t+=e[n][5],t+=" ",t+=e[n][6],e[n][7]!=null&&(t+=" ",t+=e[n][7])))));return t+" "}class Ut extends le{bbox(){return St().path.setAttribute("d",this.toString()),new z(St.nodes.path.getBBox())}move(t,n){const i=this.bbox();if(t-=i.x,n-=i.y,!isNaN(t)&&!isNaN(n))for(let r,s=this.length-1;s>=0;s--)r=this[s][0],r==="M"||r==="L"||r==="T"?(this[s][1]+=t,this[s][2]+=n):r==="H"?this[s][1]+=t:r==="V"?this[s][1]+=n:r==="C"||r==="S"||r==="Q"?(this[s][1]+=t,this[s][2]+=n,this[s][3]+=t,this[s][4]+=n,r==="C"&&(this[s][5]+=t,this[s][6]+=n)):r==="A"&&(this[s][6]+=t,this[s][7]+=n);return this}parse(t="M0 0"){return Array.isArray(t)&&(t=Array.prototype.concat.apply([],t).toString()),Ba(t)}size(t,n){const i=this.bbox();let r,s;for(i.width=i.width===0?1:i.width,i.height=i.height===0?1:i.height,r=this.length-1;r>=0;r--)s=this[r][0],s==="M"||s==="L"||s==="T"?(this[r][1]=(this[r][1]-i.x)*t/i.width+i.x,this[r][2]=(this[r][2]-i.y)*n/i.height+i.y):s==="H"?this[r][1]=(this[r][1]-i.x)*t/i.width+i.x:s==="V"?this[r][1]=(this[r][1]-i.y)*n/i.height+i.y:s==="C"||s==="S"||s==="Q"?(this[r][1]=(this[r][1]-i.x)*t/i.width+i.x,this[r][2]=(this[r][2]-i.y)*n/i.height+i.y,this[r][3]=(this[r][3]-i.x)*t/i.width+i.x,this[r][4]=(this[r][4]-i.y)*n/i.height+i.y,s==="C"&&(this[r][5]=(this[r][5]-i.x)*t/i.width+i.x,this[r][6]=(this[r][6]-i.y)*n/i.height+i.y)):s==="A"&&(this[r][1]=this[r][1]*t/i.width,this[r][2]=this[r][2]*n/i.height,this[r][6]=(this[r][6]-i.x)*t/i.width+i.x,this[r][7]=(this[r][7]-i.y)*n/i.height+i.y);return this}toString(){return Ha(this)}}const qr=e=>{const t=typeof e;return t==="number"?O:t==="string"?D.isColor(e)?D:At.test(e)?xi.test(e)?Ut:le:Mr.test(e)?O:qn:Ii.indexOf(e.constructor)>-1?e.constructor:Array.isArray(e)?le:t==="object"?Be:qn};class Pt{constructor(t){this._stepper=t||new Fn("-"),this._from=null,this._to=null,this._type=null,this._context=null,this._morphObj=null}at(t){return this._morphObj.morph(this._from,this._to,t,this._stepper,this._context)}done(){return this._context.map(this._stepper.done).reduce(function(n,i){return n&&i},!0)}from(t){return t==null?this._from:(this._from=this._set(t),this)}stepper(t){return t==null?this._stepper:(this._stepper=t,this)}to(t){return t==null?this._to:(this._to=this._set(t),this)}type(t){return t==null?this._type:(this._type=t,this)}_set(t){this._type||this.type(qr(t));let n=new this._type(t);return this._type===D&&(n=this._to?n[this._to[4]]():this._from?n[this._from[4]]():n),this._type===Be&&(n=this._to?n.align(this._to):this._from?n.align(this._from):n),n=n.toConsumable(),this._morphObj=this._morphObj||new this._type,this._context=this._context||Array.apply(null,Array(n.length)).map(Object).map(function(i){return i.done=!0,i}),n}}class qn{constructor(...t){this.init(...t)}init(t){return t=Array.isArray(t)?t[0]:t,this.value=t,this}toArray(){return[this.value]}valueOf(){return this.value}}class Ue{constructor(...t){this.init(...t)}init(t){return Array.isArray(t)&&(t={scaleX:t[0],scaleY:t[1],shear:t[2],rotate:t[3],translateX:t[4],translateY:t[5],originX:t[6],originY:t[7]}),Object.assign(this,Ue.defaults,t),this}toArray(){const t=this;return[t.scaleX,t.scaleY,t.shear,t.rotate,t.translateX,t.translateY,t.originX,t.originY]}}Ue.defaults={scaleX:1,scaleY:1,shear:0,rotate:0,translateX:0,translateY:0,originX:0,originY:0};const $a=(e,t)=>e[0]<t[0]?-1:e[0]>t[0]?1:0;class Be{constructor(...t){this.init(...t)}align(t){const n=this.values;for(let i=0,r=n.length;i<r;++i){if(n[i+1]===t[i+1]){if(n[i+1]===D&&t[i+7]!==n[i+7]){const a=t[i+7],c=new D(this.values.splice(i+3,5))[a]().toArray();this.values.splice(i+3,0,...c)}i+=n[i+2]+2;continue}if(!t[i+1])return this;const s=new t[i+1]().toArray(),o=n[i+2]+3;n.splice(i,o,t[i],t[i+1],t[i+2],...s),i+=n[i+2]+2}return this}init(t){if(this.values=[],Array.isArray(t)){this.values=t.slice();return}t=t||{};const n=[];for(const i in t){const r=qr(t[i]),s=new r(t[i]).toArray();n.push([i,r,s.length,...s])}return n.sort($a),this.values=n.reduce((i,r)=>i.concat(r),[]),this}toArray(){return this.values}valueOf(){const t={},n=this.values;for(;n.length;){const i=n.shift(),r=n.shift(),s=n.shift(),o=n.splice(0,s);t[i]=new r(o)}return t}}const Ii=[qn,Ue,Be];function Pa(e=[]){Ii.push(...[].concat(e))}function ja(){E(Ii,{to(e){return new Pt().type(this.constructor).from(this.toArray()).to(e)},fromArray(e){return this.init(e),this},toConsumable(){return this.toArray()},morph(e,t,n,i,r){const s=function(o,a){return i.step(o,t[a],n,r[a],r)};return this.fromArray(e.map(s))}})}class ve extends rt{constructor(t,n=t){super(H("path",t),n)}array(){return this._array||(this._array=new Ut(this.attr("d")))}clear(){return delete this._array,this}height(t){return t==null?this.bbox().height:this.size(this.bbox().width,t)}move(t,n){return this.attr("d",this.array().move(t,n))}plot(t){return t==null?this.array():this.clear().attr("d",typeof t=="string"?t:this._array=new Ut(t))}size(t,n){const i=be(this,t,n);return this.attr("d",this.array().size(i.width,i.height))}width(t){return t==null?this.bbox().width:this.size(t,this.bbox().height)}x(t){return t==null?this.bbox().x:this.move(t,this.bbox().y)}y(t){return t==null?this.bbox().y:this.move(this.bbox().x,t)}}ve.prototype.MorphArray=Ut;I({Container:{path:B(function(e){return this.put(new ve).plot(e||new Ut)})}});N(ve,"Path");function La(){return this._array||(this._array=new Nt(this.attr("points")))}function Wa(){return delete this._array,this}function za(e,t){return this.attr("points",this.array().move(e,t))}function Fa(e){return e==null?this.array():this.clear().attr("points",typeof e=="string"?e:this._array=new Nt(e))}function Ka(e,t){const n=be(this,e,t);return this.attr("points",this.array().size(n.width,n.height))}const Gr=Object.freeze(Object.defineProperty({__proto__:null,array:La,clear:Wa,move:za,plot:Fa,size:Ka},Symbol.toStringTag,{value:"Module"}));class Ye extends rt{constructor(t,n=t){super(H("polygon",t),n)}}I({Container:{polygon:B(function(e){return this.put(new Ye).plot(e||new Nt)})}});E(Ye,Ti);E(Ye,Gr);N(Ye,"Polygon");class qe extends rt{constructor(t,n=t){super(H("polyline",t),n)}}I({Container:{polyline:B(function(e){return this.put(new qe).plot(e||new Nt)})}});E(qe,Ti);E(qe,Gr);N(qe,"Polyline");class Ge extends rt{constructor(t,n=t){super(H("rect",t),n)}}E(Ge,{rx:Si,ry:ki});I({Container:{rect:B(function(e,t){return this.put(new Ge).size(e,t)})}});N(Ge,"Rect");class En{constructor(){this._first=null,this._last=null}first(){return this._first&&this._first.value}last(){return this._last&&this._last.value}push(t){const n=typeof t.next<"u"?t:{value:t,next:null,prev:null};return this._last?(n.prev=this._last,this._last.next=n,this._last=n):(this._last=n,this._first=n),n}remove(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),t===this._last&&(this._last=t.prev),t===this._first&&(this._first=t.next),t.prev=null,t.next=null}shift(){const t=this._first;return t?(this._first=t.next,this._first&&(this._first.prev=null),this._last=this._first?this._last:null,t.value):null}}const M={nextDraw:null,frames:new En,timeouts:new En,immediates:new En,timer:()=>C.window.performance||C.window.Date,transforms:[],frame(e){const t=M.frames.push({run:e});return M.nextDraw===null&&(M.nextDraw=C.window.requestAnimationFrame(M._draw)),t},timeout(e,t){t=t||0;const n=M.timer().now()+t,i=M.timeouts.push({run:e,time:n});return M.nextDraw===null&&(M.nextDraw=C.window.requestAnimationFrame(M._draw)),i},immediate(e){const t=M.immediates.push(e);return M.nextDraw===null&&(M.nextDraw=C.window.requestAnimationFrame(M._draw)),t},cancelFrame(e){e!=null&&M.frames.remove(e)},clearTimeout(e){e!=null&&M.timeouts.remove(e)},cancelImmediate(e){e!=null&&M.immediates.remove(e)},_draw(e){let t=null;const n=M.timeouts.last();for(;(t=M.timeouts.shift())&&(e>=t.time?t.run():M.timeouts.push(t),t!==n););let i=null;const r=M.frames.last();for(;i!==r&&(i=M.frames.shift());)i.run(e);let s=null;for(;s=M.immediates.shift();)s();M.nextDraw=M.timeouts.first()||M.frames.first()?C.window.requestAnimationFrame(M._draw):null}},Ua=function(e){const t=e.start,n=e.runner.duration(),i=t+n;return{start:t,duration:n,end:i,runner:e.runner}},Ya=function(){const e=C.window;return(e.performance||e.Date).now()};class Zr extends ze{constructor(t=Ya){super(),this._timeSource=t,this.terminate()}active(){return!!this._nextFrame}finish(){return this.time(this.getEndTimeOfTimeline()+1),this.pause()}getEndTime(){const t=this.getLastRunnerInfo(),n=t?t.runner.duration():0;return(t?t.start:this._time)+n}getEndTimeOfTimeline(){const t=this._runners.map(n=>n.start+n.runner.duration());return Math.max(0,...t)}getLastRunnerInfo(){return this.getRunnerInfoById(this._lastRunnerId)}getRunnerInfoById(t){return this._runners[this._runnerIds.indexOf(t)]||null}pause(){return this._paused=!0,this._continue()}persist(t){return t==null?this._persist:(this._persist=t,this)}play(){return this._paused=!1,this.updateTime()._continue()}reverse(t){const n=this.speed();if(t==null)return this.speed(-n);const i=Math.abs(n);return this.speed(t?-i:i)}schedule(t,n,i){if(t==null)return this._runners.map(Ua);let r=0;const s=this.getEndTime();if(n=n||0,i==null||i==="last"||i==="after")r=s;else if(i==="absolute"||i==="start")r=n,n=0;else if(i==="now")r=this._time;else if(i==="relative"){const c=this.getRunnerInfoById(t.id);c&&(r=c.start+n,n=0)}else if(i==="with-last"){const c=this.getLastRunnerInfo();r=c?c.start:this._time}else throw new Error('Invalid value for the "when" parameter');t.unschedule(),t.timeline(this);const o=t.persist(),a={persist:o===null?this._persist:o,start:r+n,runner:t};return this._lastRunnerId=t.id,this._runners.push(a),this._runners.sort((c,l)=>c.start-l.start),this._runnerIds=this._runners.map(c=>c.runner.id),this.updateTime()._continue(),this}seek(t){return this.time(this._time+t)}source(t){return t==null?this._timeSource:(this._timeSource=t,this)}speed(t){return t==null?this._speed:(this._speed=t,this)}stop(){return this.time(0),this.pause()}time(t){return t==null?this._time:(this._time=t,this._continue(!0))}unschedule(t){const n=this._runnerIds.indexOf(t.id);return n<0?this:(this._runners.splice(n,1),this._runnerIds.splice(n,1),t.timeline(null),this)}updateTime(){return this.active()||(this._lastSourceTime=this._timeSource()),this}_continue(t=!1){return M.cancelFrame(this._nextFrame),this._nextFrame=null,t?this._stepImmediate():this._paused?this:(this._nextFrame=M.frame(this._step),this)}_stepFn(t=!1){const n=this._timeSource();let i=n-this._lastSourceTime;t&&(i=0);const r=this._speed*i+(this._time-this._lastStepTime);this._lastSourceTime=n,t||(this._time+=r,this._time=this._time<0?0:this._time),this._lastStepTime=this._time,this.fire("time",this._time);for(let o=this._runners.length;o--;){const a=this._runners[o],c=a.runner;this._time-a.start<=0&&c.reset()}let s=!1;for(let o=0,a=this._runners.length;o<a;o++){const c=this._runners[o],l=c.runner;let u=r;const h=this._time-c.start;if(h<=0){s=!0;continue}else h<u&&(u=h);if(!l.active())continue;l.step(u).done?c.persist!==!0&&l.duration()-l.time()+this._time+c.persist<this._time&&(l.unschedule(),--o,--a):s=!0}return s&&!(this._speed<0&&this._time===0)||this._runnerIds.length&&this._speed<0&&this._time>0?this._continue():(this.pause(),this.fire("finished")),this}terminate(){this._startTime=0,this._speed=1,this._persist=0,this._nextFrame=null,this._paused=!0,this._runners=[],this._runnerIds=[],this._lastRunnerId=-1,this._time=0,this._lastSourceTime=0,this._lastStepTime=0,this._step=this._stepFn.bind(this,!1),this._stepImmediate=this._stepFn.bind(this,!0)}}I({Element:{timeline:function(e){return e==null?(this._timeline=this._timeline||new Zr,this._timeline):(this._timeline=e,this)}}});class it extends ze{constructor(t){super(),this.id=it.id++,t=t??Te.duration,t=typeof t=="function"?new sn(t):t,this._element=null,this._timeline=null,this.done=!1,this._queue=[],this._duration=typeof t=="number"&&t,this._isDeclarative=t instanceof sn,this._stepper=this._isDeclarative?t:new Fn,this._history={},this.enabled=!0,this._time=0,this._lastTime=0,this._reseted=!0,this.transforms=new k,this.transformId=1,this._haveReversed=!1,this._reverse=!1,this._loopsDone=0,this._swing=!1,this._wait=0,this._times=1,this._frameId=null,this._persist=this._isDeclarative?!0:null}static sanitise(t,n,i){let r=1,s=!1,o=0;return t=t??Te.duration,n=n??Te.delay,i=i||"last",typeof t=="object"&&!(t instanceof Oi)&&(n=t.delay??n,i=t.when??i,s=t.swing||s,r=t.times??r,o=t.wait??o,t=t.duration??Te.duration),{duration:t,delay:n,swing:s,times:r,wait:o,when:i}}active(t){return t==null?this.enabled:(this.enabled=t,this)}addTransform(t){return this.transforms.lmultiplyO(t),this}after(t){return this.on("finished",t)}animate(t,n,i){const r=it.sanitise(t,n,i),s=new it(r.duration);return this._timeline&&s.timeline(this._timeline),this._element&&s.element(this._element),s.loop(r).schedule(r.delay,r.when)}clearTransform(){return this.transforms=new k,this}clearTransformsFromQueue(){(!this.done||!this._timeline||!this._timeline._runnerIds.includes(this.id))&&(this._queue=this._queue.filter(t=>!t.isTransform))}delay(t){return this.animate(0,t)}duration(){return this._times*(this._wait+this._duration)-this._wait}during(t){return this.queue(null,t)}ease(t){return this._stepper=new Fn(t),this}element(t){return t==null?this._element:(this._element=t,t._prepareRunner(),this)}finish(){return this.step(1/0)}loop(t,n,i){return typeof t=="object"&&(n=t.swing,i=t.wait,t=t.times),this._times=t||1/0,this._swing=n||!1,this._wait=i||0,this._times===!0&&(this._times=1/0),this}loops(t){const n=this._duration+this._wait;if(t==null){const o=Math.floor(this._time/n),c=(this._time-o*n)/this._duration;return Math.min(o+c,this._times)}const i=Math.floor(t),r=t%1,s=n*i+this._duration*r;return this.time(s)}persist(t){return t==null?this._persist:(this._persist=t,this)}position(t){const n=this._time,i=this._duration,r=this._wait,s=this._times,o=this._swing,a=this._reverse;let c;if(t==null){const f=function(d){const g=o*Math.floor(d%(2*(r+i))/(r+i)),y=g&&!a||!g&&a,A=Math.pow(-1,y)*(d%(r+i))/i+y;return Math.max(Math.min(A,1),0)},p=s*(r+i)-r;return c=n<=0?Math.round(f(1e-5)):n<p?f(n):Math.round(f(p-1e-5)),c}const l=Math.floor(this.loops()),u=o&&l%2===0;return c=l+(u&&!a||a&&u?t:1-t),this.loops(c)}progress(t){return t==null?Math.min(1,this._time/this.duration()):this.time(t*this.duration())}queue(t,n,i,r){return this._queue.push({initialiser:t||nr,runner:n||nr,retarget:i,isTransform:r,initialised:!1,finished:!1}),this.timeline()&&this.timeline()._continue(),this}reset(){return this._reseted?this:(this.time(0),this._reseted=!0,this)}reverse(t){return this._reverse=t??!this._reverse,this}schedule(t,n,i){if(t instanceof Zr||(i=n,n=t,t=this.timeline()),!t)throw Error("Runner cannot be scheduled without timeline");return t.schedule(this,n,i),this}step(t){if(!this.enabled)return this;t=t??16,this._time+=t;const n=this.position(),i=this._lastPosition!==n&&this._time>=0;this._lastPosition=n;const r=this.duration(),s=this._lastTime<=0&&this._time>0,o=this._lastTime<r&&this._time>=r;this._lastTime=this._time,s&&this.fire("start",this);const a=this._isDeclarative;this.done=!a&&!o&&this._time>=r,this._reseted=!1;let c=!1;return(i||a)&&(this._initialise(i),this.transforms=new k,c=this._run(a?t:n),this.fire("step",this)),this.done=this.done||c&&a,o&&this.fire("finished",this),this}time(t){if(t==null)return this._time;const n=t-this._time;return this.step(n),this}timeline(t){return typeof t>"u"?this._timeline:(this._timeline=t,this)}unschedule(){const t=this.timeline();return t&&t.unschedule(this),this}_initialise(t){if(!(!t&&!this._isDeclarative))for(let n=0,i=this._queue.length;n<i;++n){const r=this._queue[n],s=this._isDeclarative||!r.initialised&&t;t=!r.finished,s&&t&&(r.initialiser.call(this),r.initialised=!0)}}_rememberMorpher(t,n){if(this._history[t]={morpher:n,caller:this._queue[this._queue.length-1]},this._isDeclarative){const i=this.timeline();i&&i.play()}}_run(t){let n=!0;for(let i=0,r=this._queue.length;i<r;++i){const s=this._queue[i],o=s.runner.call(this,t);s.finished=s.finished||o===!0,n=n&&s.finished}return n}_tryRetarget(t,n,i){if(this._history[t]){if(!this._history[t].caller.initialised){const s=this._queue.indexOf(this._history[t].caller);return this._queue.splice(s,1),!1}this._history[t].caller.retarget?this._history[t].caller.retarget.call(this,n,i):this._history[t].morpher.to(n),this._history[t].caller.finished=!1;const r=this.timeline();return r&&r.play(),!0}return!1}}it.id=0;class on{constructor(t=new k,n=-1,i=!0){this.transforms=t,this.id=n,this.done=i}clearTransformsFromQueue(){}}E([it,on],{mergeWith(e){return new on(e.transforms.lmultiply(this.transforms),e.id)}});const Xr=(e,t)=>e.lmultiplyO(t),Jr=e=>e.transforms;function qa(){const t=this._transformationRunners.runners.map(Jr).reduce(Xr,new k);this.transform(t),this._transformationRunners.merge(),this._transformationRunners.length()===1&&(this._frameId=null)}class Ga{constructor(){this.runners=[],this.ids=[]}add(t){if(this.runners.includes(t))return;const n=t.id+1;return this.runners.push(t),this.ids.push(n),this}clearBefore(t){const n=this.ids.indexOf(t+1)||1;return this.ids.splice(0,n,0),this.runners.splice(0,n,new on).forEach(i=>i.clearTransformsFromQueue()),this}edit(t,n){const i=this.ids.indexOf(t+1);return this.ids.splice(i,1,t+1),this.runners.splice(i,1,n),this}getByID(t){return this.runners[this.ids.indexOf(t+1)]}length(){return this.ids.length}merge(){let t=null;for(let n=0;n<this.runners.length;++n){const i=this.runners[n];if(t&&i.done&&t.done&&(!i._timeline||!i._timeline._runnerIds.includes(i.id))&&(!t._timeline||!t._timeline._runnerIds.includes(t.id))){this.remove(i.id);const s=i.mergeWith(t);this.edit(t.id,s),t=s,--n}else t=i}return this}remove(t){const n=this.ids.indexOf(t+1);return this.ids.splice(n,1),this.runners.splice(n,1),this}}I({Element:{animate(e,t,n){const i=it.sanitise(e,t,n),r=this.timeline();return new it(i.duration).loop(i).element(this).timeline(r.play()).schedule(i.delay,i.when)},delay(e,t){return this.animate(0,e,t)},_clearTransformRunnersBefore(e){this._transformationRunners.clearBefore(e.id)},_currentTransform(e){return this._transformationRunners.runners.filter(t=>t.id<=e.id).map(Jr).reduce(Xr,new k)},_addRunner(e){this._transformationRunners.add(e),M.cancelImmediate(this._frameId),this._frameId=M.immediate(qa.bind(this))},_prepareRunner(){this._frameId==null&&(this._transformationRunners=new Ga().add(new on(new k(this))))}}});const Za=(e,t)=>e.filter(n=>!t.includes(n));E(it,{attr(e,t){return this.styleAttr("attr",e,t)},css(e,t){return this.styleAttr("css",e,t)},styleAttr(e,t,n){if(typeof t=="string")return this.styleAttr(e,{[t]:n});let i=t;if(this._tryRetarget(e,i))return this;let r=new Pt(this._stepper).to(i),s=Object.keys(i);return this.queue(function(){r=r.from(this.element()[e](s))},function(o){return this.element()[e](r.at(o).valueOf()),r.done()},function(o){const a=Object.keys(o),c=Za(a,s);if(c.length){const u=this.element()[e](c),h=new Be(r.from()).valueOf();Object.assign(h,u),r.from(h)}const l=new Be(r.to()).valueOf();Object.assign(l,o),r.to(l),s=a,i=o}),this._rememberMorpher(e,r),this},zoom(e,t){if(this._tryRetarget("zoom",e,t))return this;let n=new Pt(this._stepper).to(new O(e));return this.queue(function(){n=n.from(this.element().zoom())},function(i){return this.element().zoom(n.at(i),t),n.done()},function(i,r){t=r,n.to(i)}),this._rememberMorpher("zoom",n),this},transform(e,t,n){if(t=e.relative||t,this._isDeclarative&&!t&&this._tryRetarget("transform",e))return this;const i=k.isMatrixLike(e);n=e.affine!=null?e.affine:n??!i;const r=new Pt(this._stepper).type(n?Ue:k);let s,o,a,c,l;function u(){o=o||this.element(),s=s||Ln(e,o),l=new k(t?void 0:o),o._addRunner(this),t||o._clearTransformRunnersBefore(this)}function h(p){t||this.clearTransform();const{x:d,y:g}=new P(s).transform(o._currentTransform(this));let y=new k({...e,origin:[d,g]}),A=this._isDeclarative&&a?a:l;if(n){y=y.decompose(d,g),A=A.decompose(d,g);const $=y.rotate,st=A.rotate,F=[$-360,$,$+360],ct=F.map(An=>Math.abs(An-st)),gt=Math.min(...ct),Xt=ct.indexOf(gt);y.rotate=F[Xt]}t&&(i||(y.rotate=e.rotate||0),this._isDeclarative&&c&&(A.rotate=c)),r.from(A),r.to(y);const _=r.at(p);return c=_.rotate,a=new k(_),this.addTransform(a),o._addRunner(this),r.done()}function f(p){(p.origin||"center").toString()!==(e.origin||"center").toString()&&(s=Ln(p,o)),e={...p,origin:s}}return this.queue(u,h,f,!0),this._isDeclarative&&this._rememberMorpher("transform",r),this},x(e){return this._queueNumber("x",e)},y(e){return this._queueNumber("y",e)},ax(e){return this._queueNumber("ax",e)},ay(e){return this._queueNumber("ay",e)},dx(e=0){return this._queueNumberDelta("x",e)},dy(e=0){return this._queueNumberDelta("y",e)},dmove(e,t){return this.dx(e).dy(t)},_queueNumberDelta(e,t){if(t=new O(t),this._tryRetarget(e,t))return this;const n=new Pt(this._stepper).to(t);let i=null;return this.queue(function(){i=this.element()[e](),n.from(i),n.to(i+t)},function(r){return this.element()[e](n.at(r)),n.done()},function(r){n.to(i+new O(r))}),this._rememberMorpher(e,n),this},_queueObject(e,t){if(this._tryRetarget(e,t))return this;const n=new Pt(this._stepper).to(t);return this.queue(function(){n.from(this.element()[e]())},function(i){return this.element()[e](n.at(i)),n.done()}),this._rememberMorpher(e,n),this},_queueNumber(e,t){return this._queueObject(e,new O(t))},cx(e){return this._queueNumber("cx",e)},cy(e){return this._queueNumber("cy",e)},move(e,t){return this.x(e).y(t)},amove(e,t){return this.ax(e).ay(t)},center(e,t){return this.cx(e).cy(t)},size(e,t){let n;return(!e||!t)&&(n=this._element.bbox()),e||(e=n.width/n.height*t),t||(t=n.height/n.width*e),this.width(e).height(t)},width(e){return this._queueNumber("width",e)},height(e){return this._queueNumber("height",e)},plot(e,t,n,i){if(arguments.length===4)return this.plot([e,t,n,i]);if(this._tryRetarget("plot",e))return this;const r=new Pt(this._stepper).type(this._element.MorphArray).to(e);return this.queue(function(){r.from(this._element.array())},function(s){return this._element.plot(r.at(s)),r.done()}),this._rememberMorpher("plot",r),this},leading(e){return this._queueNumber("leading",e)},viewbox(e,t,n,i){return this._queueObject("viewbox",new z(e,t,n,i))},update(e){return typeof e!="object"?this.update({offset:arguments[0],color:arguments[1],opacity:arguments[2]}):(e.opacity!=null&&this.attr("stop-opacity",e.opacity),e.color!=null&&this.attr("stop-color",e.color),e.offset!=null&&this.attr("offset",e.offset),this)}});E(it,{rx:Si,ry:ki,from:Ur,to:Yr});N(it,"Runner");class Ei extends tt{constructor(t,n=t){super(H("svg",t),n),this.namespace()}defs(){return this.isRoot()?at(this.node.querySelector("defs"))||this.put(new Ai):this.root().defs()}isRoot(){return!this.node.parentNode||!(this.node.parentNode instanceof C.window.SVGElement)&&this.node.parentNode.nodeName!=="#document-fragment"}namespace(){return this.isRoot()?this.attr({xmlns:wi,version:"1.1"}).attr("xmlns:xlink",We,kn):this.root().namespace()}removeNamespace(){return this.attr({xmlns:null,version:null}).attr("xmlns:xlink",null,kn).attr("xmlns:svgjs",null,kn)}root(){return this.isRoot()?this:super.root()}}I({Container:{nested:B(function(){return this.put(new Ei)})}});N(Ei,"Svg",!0);let wn=class extends tt{constructor(t,n=t){super(H("symbol",t),n)}};I({Container:{symbol:B(function(){return this.put(new wn)})}});N(wn,"Symbol");function Xa(e){return this._build===!1&&this.clear(),this.node.appendChild(C.document.createTextNode(e)),this}function Ja(){return this.node.getComputedTextLength()}function Va(e,t=this.bbox()){return e==null?t.x:this.attr("x",this.attr("x")+e-t.x)}function Qa(e,t=this.bbox()){return e==null?t.y:this.attr("y",this.attr("y")+e-t.y)}function tc(e,t,n=this.bbox()){return this.x(e,n).y(t,n)}function ec(e,t=this.bbox()){return e==null?t.cx:this.attr("x",this.attr("x")+e-t.cx)}function nc(e,t=this.bbox()){return e==null?t.cy:this.attr("y",this.attr("y")+e-t.cy)}function ic(e,t,n=this.bbox()){return this.cx(e,n).cy(t,n)}function rc(e){return this.attr("x",e)}function sc(e){return this.attr("y",e)}function oc(e,t){return this.ax(e).ay(t)}function ac(e){return this._build=!!e,this}const Vr=Object.freeze(Object.defineProperty({__proto__:null,amove:oc,ax:rc,ay:sc,build:ac,center:ic,cx:ec,cy:nc,length:Ja,move:tc,plain:Xa,x:Va,y:Qa},Symbol.toStringTag,{value:"Module"}));class K extends rt{constructor(t,n=t){super(H("text",t),n),this.dom.leading=this.dom.leading??new O(1.3),this._rebuild=!0,this._build=!1}leading(t){return t==null?this.dom.leading:(this.dom.leading=new O(t),this.rebuild())}rebuild(t){if(typeof t=="boolean"&&(this._rebuild=t),this._rebuild){const n=this;let i=0;const r=this.dom.leading;this.each(function(s){if(Wn(this.node))return;const o=C.window.getComputedStyle(this.node).getPropertyValue("font-size"),a=r*new O(o);this.dom.newLined&&(this.attr("x",n.attr("x")),this.text()===`
3
+ `?i+=a:(this.attr("dy",s?a+i:0),i=0))}),this.fire("rebuild")}return this}setData(t){return this.dom=t,this.dom.leading=new O(t.leading||1.3),this}writeDataToDom(){return Er(this,this.dom,{leading:1.3}),this}text(t){if(t===void 0){const n=this.node.childNodes;let i=0;t="";for(let r=0,s=n.length;r<s;++r){if(n[r].nodeName==="textPath"||Wn(n[r])){r===0&&(i=r+1);continue}r!==i&&n[r].nodeType!==3&&at(n[r]).dom.newLined===!0&&(t+=`
4
+ `),t+=n[r].textContent}return t}if(this.clear().build(!0),typeof t=="function")t.call(this,this);else{t=(t+"").split(`
5
+ `);for(let n=0,i=t.length;n<i;n++)this.newLine(t[n])}return this.build(!1).rebuild()}}E(K,Vr);I({Container:{text:B(function(e=""){return this.put(new K).text(e)}),plain:B(function(e=""){return this.put(new K).plain(e)})}});N(K,"Text");class _n extends rt{constructor(t,n=t){super(H("tspan",t),n),this._build=!1}dx(t){return this.attr("dx",t)}dy(t){return this.attr("dy",t)}newLine(){this.dom.newLined=!0;const t=this.parent();if(!(t instanceof K))return this;const n=t.index(this),i=C.window.getComputedStyle(this.node).getPropertyValue("font-size"),r=t.dom.leading*new O(i);return this.dy(n?r:0).attr("x",t.x())}text(t){return t==null?this.node.textContent+(this.dom.newLined?`
6
+ `:""):(typeof t=="function"?(this.clear().build(!0),t.call(this,this),this.build(!1)):this.plain(t),this)}}E(_n,Vr);I({Tspan:{tspan:B(function(e=""){const t=new _n;return this._build||this.clear(),this.put(t).text(e)})},Text:{newLine:function(e=""){return this.tspan(e).newLine()}}});N(_n,"Tspan");class Ci extends rt{constructor(t,n=t){super(H("circle",t),n)}radius(t){return this.attr("r",t)}rx(t){return this.attr("r",t)}ry(t){return this.rx(t)}size(t){return this.radius(new O(t).divide(2))}}E(Ci,{x:Pr,y:jr,cx:Lr,cy:Wr,width:zr,height:Fr});I({Container:{circle:B(function(e=0){return this.put(new Ci).size(e).move(0,0)})}});N(Ci,"Circle");class Gn extends tt{constructor(t,n=t){super(H("clipPath",t),n)}remove(){return this.targets().forEach(function(t){t.unclip()}),super.remove()}targets(){return xe("svg [clip-path*="+this.id()+"]")}}I({Container:{clip:B(function(){return this.defs().put(new Gn)})},Element:{clipper(){return this.reference("clip-path")},clipWith(e){const t=e instanceof Gn?e:this.parent().clip().add(e);return this.attr("clip-path","url(#"+t.id()+")")},unclip(){return this.attr("clip-path",null)}}});N(Gn,"ClipPath");class Qr extends mt{constructor(t,n=t){super(H("foreignObject",t),n)}}I({Container:{foreignObject:B(function(e,t){return this.put(new Qr).size(e,t)})}});N(Qr,"ForeignObject");function cc(e,t){return this.children().forEach(n=>{let i;try{i=n.node instanceof ho().SVGSVGElement?new z(n.attr(["x","y","width","height"])):n.bbox()}catch{return}const r=new k(n),s=r.translate(e,t).transform(r.inverse()),o=new P(i.x,i.y).transform(s);n.move(o.x,o.y)}),this}function lc(e){return this.dmove(e,0)}function uc(e){return this.dmove(0,e)}function hc(e,t=this.bbox()){return e==null?t.height:this.size(t.width,e,t)}function fc(e=0,t=0,n=this.bbox()){const i=e-n.x,r=t-n.y;return this.dmove(i,r)}function dc(e,t,n=this.bbox()){const i=be(this,e,t,n),r=i.width/n.width,s=i.height/n.height;return this.children().forEach(o=>{const a=new P(n).transform(new k(o).inverse());o.scale(r,s,a.x,a.y)}),this}function pc(e,t=this.bbox()){return e==null?t.width:this.size(e,t.height,t)}function mc(e,t=this.bbox()){return e==null?t.x:this.move(e,t.y,t)}function gc(e,t=this.bbox()){return e==null?t.y:this.move(t.x,e,t)}const ts=Object.freeze(Object.defineProperty({__proto__:null,dmove:cc,dx:lc,dy:uc,height:hc,move:fc,size:dc,width:pc,x:mc,y:gc},Symbol.toStringTag,{value:"Module"}));class j extends tt{constructor(t,n=t){super(H("g",t),n)}}E(j,ts);I({Container:{group:B(function(){return this.put(new j)})}});N(j,"G");class an extends tt{constructor(t,n=t){super(H("a",t),n)}target(t){return this.attr("target",t)}to(t){return this.attr("href",t,We)}}E(an,ts);I({Container:{link:B(function(e){return this.put(new an).to(e)})},Element:{unlink(){const e=this.linker();if(!e)return this;const t=e.parent();if(!t)return this.remove();const n=t.index(e);return t.add(this,n),e.remove(),this},linkTo(e){let t=this.linker();return t||(t=new an,this.wrap(t)),typeof e=="function"?e.call(t,t):t.to(e),this},linker(){const e=this.parent();return e&&e.node.nodeName.toLowerCase()==="a"?e:null}}});N(an,"A");class Zn extends tt{constructor(t,n=t){super(H("mask",t),n)}remove(){return this.targets().forEach(function(t){t.unmask()}),super.remove()}targets(){return xe("svg [mask*="+this.id()+"]")}}I({Container:{mask:B(function(){return this.defs().put(new Zn)})},Element:{masker(){return this.reference("mask")},maskWith(e){const t=e instanceof Zn?e:this.parent().mask().add(e);return this.attr("mask","url(#"+t.id()+")")},unmask(){return this.attr("mask",null)}}});N(Zn,"Mask");class es extends mt{constructor(t,n=t){super(H("stop",t),n)}update(t){return(typeof t=="number"||t instanceof O)&&(t={offset:arguments[0],color:arguments[1],opacity:arguments[2]}),t.opacity!=null&&this.attr("stop-opacity",t.opacity),t.color!=null&&this.attr("stop-color",t.color),t.offset!=null&&this.attr("offset",new O(t.offset)),this}}I({Gradient:{stop:function(e,t,n){return this.put(new es).update(e,t,n)}}});N(es,"Stop");function yc(e,t){if(!e)return"";if(!t)return e;let n=e+"{";for(const i in t)n+=co(i)+":"+t[i]+";";return n+="}",n}class Xn extends mt{constructor(t,n=t){super(H("style",t),n)}addText(t=""){return this.node.textContent+=t,this}font(t,n,i={}){return this.rule("@font-face",{fontFamily:t,src:n,...i})}rule(t,n){return this.addText(yc(t,n))}}I("Dom",{style(e,t){return this.put(new Xn).rule(e,t)},fontface(e,t,n){return this.put(new Xn).font(e,t,n)}});N(Xn,"Style");class Ni extends K{constructor(t,n=t){super(H("textPath",t),n)}array(){const t=this.track();return t?t.array():null}plot(t){const n=this.track();let i=null;return n&&(i=n.plot(t)),t==null?i:this}track(){return this.reference("href")}}I({Container:{textPath:B(function(e,t){return e instanceof K||(e=this.text(e)),e.path(t)})},Text:{path:B(function(e,t=!0){const n=new Ni;e instanceof ve||(e=this.defs().path(e)),n.attr("href","#"+e,We);let i;if(t)for(;i=this.node.firstChild;)n.node.appendChild(i);return this.put(n)}),textPath(){return this.findOne("textPath")}},Path:{text:B(function(e){return e instanceof K||(e=new K().addTo(this.parent()).text(e)),e.path(this)}),targets(){return xe("svg textPath").filter(e=>(e.attr("href")||"").includes(this.id()))}}});Ni.prototype.MorphArray=Ut;N(Ni,"TextPath");class bn extends rt{constructor(t,n=t){super(H("use",t),n)}use(t,n){return this.attr("href",(n||"")+"#"+t,We)}}I({Container:{use:B(function(e,t){return this.put(new bn).use(e,t)})}});N(bn,"Use");E([Ei,wn,Ke,De,rn],Q("viewbox"));E([Re,qe,Ye,ve],Q("marker"));E(K,Q("Text"));E(ve,Q("Path"));E(Ai,Q("Defs"));E([K,_n],Q("Tspan"));E([Ge,yn,Fe,it],Q("radius"));E(ze,Q("EventTarget"));E(Ct,Q("Dom"));E(mt,Q("Element"));E(rt,Q("Shape"));E([tt,Kr],Q("Container"));E(Fe,Q("Gradient"));E(it,Q("Runner"));Kt.extend(oo());Pa([O,D,z,k,le,Nt,Ut,P]);ja();class ue{constructor(t={}){x(this,"tileWidth");x(this,"tileHeight");x(this,"imageHostPath");x(this,"imageHostUrl");x(this,"imageExt");x(this,"scale");x(this,"svgSprite");this.scale=t.scale??1,this.imageHostPath=t.imageHostPath??"",this.imageHostUrl=t.imageHostUrl??"",this.imageExt=t.imageExt??"svg",this.tileWidth=Ot.WIDTH*this.scale,this.tileHeight=Ot.HEIGHT*this.scale,this.svgSprite=t.svgSprite??!1}getDiffTileHeightWidth(t){const n=t.imageSize(this.scale);return(n.baseHeight-n.baseWidth)/2}image(t){let n=new Ke().load(this.buildURL(t));return this.svgSprite&&(n=new bn().use(ue.buildID(t))),t instanceof w&&t.has(v.COLOR_GRAYSCALE)&&n.css({filter:"contrast(65%)"}),n}createImage(t,n,i){const r=t.imageSize(this.scale);return this.image(t).dx(n).dy(i).size(r.baseWidth,r.baseHeight)}createTextImage(t,n,i,r){const s=this.createImage(t,n,i),o=t.imageSize(this.scale),a=o.baseHeight*.2,c=o.baseWidth,l=o.baseHeight,u=new K().text(r);u.size(o.baseWidth,o.baseHeight).font({family:hi,size:a}).dx(c).dy(l);const h=new j;return h.add(s).add(u).translate(n,i),h}createRotate90Image(t,n,i,r=!1){const s=this.createImage(t,0,0),o=t.imageSize(this.scale),a=o.baseWidth/2,c=o.baseHeight/2,l=n+this.getDiffTileHeightWidth(t),u=r?i-this.getDiffTileHeightWidth(t):i,h=new j;return h.add(s).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 n=t.t==m.BACK?0:t.n;return`${t.t}${n}`}buildURL(t){const n=`${ue.buildID(t)}.${this.imageExt}`;return this.imageHostUrl!=""?`${this.imageHostUrl}${n}`:`${this.imageHostPath}${n}`}}class Mi extends ue{constructor(){super(...arguments);x(this,"blockMargin",Ot.WIDTH*Ot.BLOCK_MARGIN_SCALE*this.scale)}createBlockHandDiscard(n){const i=new j;let r=0;for(let s of n.tiles){const o=s.imageSize(this.scale),a=s.has(v.HORIZONTAL)?this.createRotate90Image.bind(this):this.createImage.bind(this),c=s.has(v.HORIZONTAL)?this.getDiffTileHeightWidth(s):0,l=a(s,r,c);i.add(l),r+=o.width}return i}createBlockPonChiKan(n){const i=n.tiles.findIndex(o=>o.has(v.HORIZONTAL));let r=0;const s=new j;if(n.type==b.SHO_KAN){let o=i;for(let a=0;a<n.tiles.length;a++)n.tiles[a].has(v.HORIZONTAL)&&(o=a);for(let a=0;a<n.tiles.length;a++){const c=n.tiles[a].imageSize(this.scale);if(a==o)continue;if(a==i){const h=n.tiles[i],f=n.tiles[o],p=h.imageSize(this.scale),d=this.createRotate90Image(h,0,0,!0),g=this.createRotate90Image(f,0,p.height,!0);s.add(new j().translate(r,0).add(d).add(g)),r+=p.width;continue}const l=c.width*2-c.height,u=this.createImage(n.tiles[a],r,l);r+=c.width,s.add(u)}return s}if(n.type==b.CHI){const o=this.createRotate90Image(n.tiles[i],r,this.getDiffTileHeightWidth(n.tiles[i]));r+=n.tiles[i].imageSize(this.scale).width,s.add(o);for(let a=0;a<n.tiles.length;a++){if(a==i)continue;const c=n.tiles[a].imageSize(this.scale),l=this.createImage(n.tiles[a],r,0);r+=c.width,s.add(l)}return s}for(let o=0;o<n.tiles.length;o++){const a=o==i?this.createRotate90Image.bind(this):this.createImage.bind(this),c=o==i?this.getDiffTileHeightWidth(n.tiles[o]):0,l=n.tiles[o].imageSize(this.scale),u=a(n.tiles[o],r,c);r+=l.width,s.add(u)}return s}}const wc=e=>{const t=e.scale;return{[b.CHI]:function(i){const r=i.imageSize(t),s=e.createBlockPonChiKan(i);return{...r,e:s}},[b.PON]:function(i){const r=i.imageSize(t),s=e.createBlockPonChiKan(i);return{...r,e:s}},[b.DAI_KAN]:function(i){const r=i.imageSize(t),s=e.createBlockPonChiKan(i);return{...r,e:s}},[b.SHO_KAN]:function(i){const r=i.imageSize(t),s=e.createBlockPonChiKan(i);return{...r,e:s}},[b.AN_KAN]:function(i){if(!(i instanceof G))throw new Error(`block type is not ankan: ${i.type}`);const r=i.imageSize(t),s=i.tilesWithBack.filter(a=>a.t!==m.BACK);if(!(s!=null&&s.length==2))throw new Error(`[debug] back tile must be two but ${i}`);const o=e.createBlockHandDiscard(new G([s[0],s[1],s[0],s[1]]));return{...r,e:o}},[b.IMAGE_DORA]:function(i){const r=i.imageSize(t),s=new j,o=e.createTextImage(i.tiles[0],0,0,"(ドラ)");return s.add(o),{...r,e:s}},[b.TSUMO]:function(i){const r=i.imageSize(t),s=new j,o=e.createTextImage(i.tiles[0],0,0,"(ツモ)");return s.add(o),{...r,e:s}},[b.HAND]:function(i){const r=i.imageSize(t),s=e.createBlockHandDiscard(i);return{...r,e:s}},[b.IMAGE_DISCARD]:function(i){const r=i.imageSize(t),s=e.createBlockHandDiscard(i);return{...r,e:s}},[b.THREE]:function(i){throw new Error("found unknown block")},[b.RUN]:function(i){throw new Error("found unknown block")},[b.UNKNOWN]:function(i){throw new Error("found unknown block")},[b.PAIR]:function(i){throw new Error("unsupported")},[b.ISOLATED]:function(i){throw new Error("unsupported")}}},re=(e,t)=>{const{maxHeight:n,sumWidth:i}=t.reduce((u,h)=>{const f=h.imageSize(e.scale);return{maxHeight:f.height>u.maxHeight?f.height:u.maxHeight,sumWidth:u.sumWidth+f.width}},{maxHeight:0,sumWidth:0}),r=n,s=i+(t.length-1)*e.blockMargin,o=wc(e),a=[];for(let u of t){const h=o[u.type],f=h(u);a.push(f)}const c=new j;let l=0;for(let u of a){const h=r-u.height,f=new j().translate(l,h);f.add(u.e),c.add(f),l+=u.width+e.blockMargin}return{e:c,width:s,height:r}},_c=(e,t,n={},i={responsive:!1})=>{const r=new Mi(n),s=re(r,t);i.responsive||e.size(s.width,s.height),e.viewbox(0,0,s.width,s.height),e.add(s.e)},ns=()=>{const e=[0,1,2,3,4,5,6,7,8,9],t=[];for(let n of Object.values(m)){if(n==m.BACK){t.push(ue.buildID(new w(n,0)));continue}t.push(...e.map(i=>ue.buildID(new w(n,i))).flat())}return t},bc=e=>{const t=ns(),n=[];return e.each((i,r)=>{const s=r[i];if(s instanceof bn){const a=s.attr("href").substring(1);t.includes(a)&&n.push(a)}}),n},xc=e=>{const t=ns(),n=bc(e);e.each((i,r)=>{const s=r[i];s instanceof wn&&(t.includes(s.id())&&n.includes(s.id())||s.remove())},!0)},vc=e=>{const n=[];for(let i=0;i<e.length;i+=6){const r=e.slice(i,i+6);n.push(r)}return n},ft=(e,t,n,i,r=0,s=0)=>{const o=new j().add(e);if(i==90){const a=r,c=s-n;return o.rotate(i,0,n).translate(a,c),o}if(i==180){const a=r+t,c=s-n;return o.rotate(i,0,n).translate(a,c),o}if(i==270){const a=r+n,c=s+(t-n);return o.rotate(i,0,n).translate(a,c),o}return o},Je=(e,t)=>{const n=new j,i=vc(e);for(let r=0;r<i.length;r++){let s=i[r],o=r*t.tileHeight;const a=t.createBlockHandDiscard(new gi(s,b.IMAGE_DISCARD)).translate(0,o);n.add(a)}return{e:n,width:t.tileWidth*5+t.tileHeight*1,height:t.tileHeight*i.length}},Ac=(e,t,n)=>{const i=t.font,r=t.textWidth,s=t.textHeight,o=new j,a=n.sticks.dead,c=n.sticks.reach,l=125*e.scale,u=27.5*e.scale;let h=r*3,f=s;const p=(l+e.tileWidth+r-h)/2,d=new K().plain(n.round).font(i).move(p,0);o.add(d),f+=25*e.scale;const g=e.tileHeight,y=new j().size(l,g).translate(0,f),A={family:i.family,size:i.size*.7},_=e.createStick(1e3).size(l,u).move(0,0),$=new K().plain(c.toString()).font(A).attr({x:l,y:u});y.add(_),y.add($);const st=e.createStick(100).size(l,u).move(0,u+u),F=new K().plain(a.toString()).font(A).attr({x:l,y:u*3});y.add(st),y.add(F);const ct=e.createImage(n.doras[0],0,0).move(l+r,0);return y.add(ct),o.add(d),o.add(y),{e:o,width:l+e.tileWidth+r,height:f+e.tileHeight}},Sc=(e,t,n=0)=>{const i=re(e,t.front),r=re(e,t.right),s=re(e,t.opposite),o=re(e,t.left),a=[i.width,r.width,s.width,o.width].reduce((g,y)=>Math.max(g,y)),c=Math.max(n+e.tileHeight*2+e.blockMargin*2,a+e.tileWidth*2+e.blockMargin),l=c,u=new j().size(c,l),h=ft(i.e,i.width,i.height,0).translate((c-i.width)/2,l-i.height),f=ft(r.e,r.width,r.height,270).translate(c-r.height,(c-r.width)/2),p=ft(s.e,s.width,s.height,180).translate((c-s.width)/2,0),d=ft(o.e,o.width,o.height,90).translate(0,(c-o.width)/2);return u.add(h),u.add(f),u.add(p),u.add(d),{e:u,width:c,height:l}},kc=e=>e=="東"?["東","南","西","北"]:e=="南"?["南","西","北","東"]:e=="西"?["西","北","東","南"]:["北","東","南","西"],Tc=(e,t,n)=>{const i=e.tileWidth*5+e.tileHeight*1,r=new j,s=new Ge().size(i,i).move(0,0).fill("none").stroke("#000000");r.add(s);const o=t.font,a=t.textWidth,c=t.textHeight,l=t.numWidth,u=Ac(e,t,n);u.e.translate(i/2-u.width/2,i/2-u.height/2);const h=(An,Zi,Zs)=>{const Xs=`${An} ${Zi}`,Js=new K().plain(Xs).font(o).attr(Zs);return{e:new j().add(Js),width:a+l*Zi.toString().length,height:c}},[f,p,d,g]=kc(n.frontPlace),y=n.scores,_=h(f,y.front,{x:i/2,y:i,"dominant-baseline":"text-after-edge","text-anchor":"middle"}).e;let $=h(p,y.right,{"dominant-baseline":"text-after-edge","text-anchor":"middle"});const st=ft($.e,$.width,$.height,270).translate(i,i/2-$.width);let F=h(d,y.opposite,{"text-anchor":"middle","dominant-baseline":"text-after-edge"});const ct=ft(F.e,F.width,F.height,180).translate(i/2-F.width,-F.height);let gt=h(g,y.left,{"dominant-baseline":"ideographic","text-anchor":"middle"});const Xt=ft(gt.e,gt.width,gt.height,90).translate(-gt.height,i/2);return r.add(u.e),r.add(_),r.add(st),r.add(ct),r.add(Xt),{e:r,width:i,height:i}},Oc=(e,t)=>{const n=Je(t.front,e),i=Je(t.right,e),r=Je(t.opposite,e),s=Je(t.left,e),o=[n.height,i.height,r.height,s.height].reduce((_,$)=>Math.max(_,$)),a=e.tileWidth*5+e.tileHeight*1,c=o,l=a+o*2+e.blockMargin,u=l,h=new j().size(l,u),f=l/2-a/2,p=u/2-a/2,d=ft(n.e,a,c,0).translate(f,u-c),g=ft(i.e,a,c,270).translate(l-c,p),y=ft(r.e,a,c,180).translate(f,0),A=ft(s.e,a,c,90).translate(0,p);return h.add(d),h.add(g),h.add(y),h.add(A),{e:h,width:l,height:u}},is=(e,t,n,i,r)=>{const s=new j,o=Oc(e,i),a=Sc(e,n,o.height),c=Tc(e,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),s.add(a.e),s.add(o.e),s.add(c.e),{e:s,width:a.width,height:a.height}},Ic=(e,t,n={},i,r={responsive:!1})=>{const s=new Mi(n),o=i,{discards:a,hands:c,scoreBoard:l}=ys(t),u=is(s,o,c,a,l);r.responsive||e.size(u.width,u.height),e.viewbox(0,0,u.width,u.height),e.add(u.e)};/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */function rs(e){return typeof e>"u"||e===null}function Ec(e){return typeof e=="object"&&e!==null}function Cc(e){return Array.isArray(e)?e:rs(e)?[]:[e]}function Nc(e,t){var n,i,r,s;if(t)for(s=Object.keys(t),n=0,i=s.length;n<i;n+=1)r=s[n],e[r]=t[r];return e}function Mc(e,t){var n="",i;for(i=0;i<t;i+=1)n+=e;return n}function Dc(e){return e===0&&Number.NEGATIVE_INFINITY===1/e}var Rc=rs,Bc=Ec,Hc=Cc,$c=Mc,Pc=Dc,jc=Nc,Z={isNothing:Rc,isObject:Bc,toArray:Hc,repeat:$c,isNegativeZero:Pc,extend:jc};function ss(e,t){var n="",i=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+=`
7
+
8
+ `+e.mark.snippet),i+" "+n):i}function He(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=ss(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack||""}He.prototype=Object.create(Error.prototype);He.prototype.constructor=He;He.prototype.toString=function(t){return this.name+": "+ss(this,t)};var vt=He;function Cn(e,t,n,i,r){var s="",o="",a=Math.floor(r/2)-1;return i-t>a&&(s=" ... ",t=i-a+s.length),n-i>a&&(o=" ...",n=i+a-o.length),{str:s+e.slice(t,n).replace(/\t/g,"→")+o,pos:i-t+s.length}}function Nn(e,t){return Z.repeat(" ",t-e.length)+e}function Lc(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),typeof t.indent!="number"&&(t.indent=1),typeof t.linesBefore!="number"&&(t.linesBefore=3),typeof t.linesAfter!="number"&&(t.linesAfter=2);for(var n=/\r?\n|\r|\0/g,i=[0],r=[],s,o=-1;s=n.exec(e.buffer);)r.push(s.index),i.push(s.index+s[0].length),e.position<=s.index&&o<0&&(o=i.length-2);o<0&&(o=i.length-1);var a="",c,l,u=Math.min(e.line+t.linesAfter,r.length).toString().length,h=t.maxLength-(t.indent+u+3);for(c=1;c<=t.linesBefore&&!(o-c<0);c++)l=Cn(e.buffer,i[o-c],r[o-c],e.position-(i[o]-i[o-c]),h),a=Z.repeat(" ",t.indent)+Nn((e.line-c+1).toString(),u)+" | "+l.str+`
9
+ `+a;for(l=Cn(e.buffer,i[o],r[o],e.position,h),a+=Z.repeat(" ",t.indent)+Nn((e.line+1).toString(),u)+" | "+l.str+`
10
+ `,a+=Z.repeat("-",t.indent+u+3+l.pos)+`^
11
+ `,c=1;c<=t.linesAfter&&!(o+c>=r.length);c++)l=Cn(e.buffer,i[o+c],r[o+c],e.position-(i[o]-i[o+c]),h),a+=Z.repeat(" ",t.indent)+Nn((e.line+c+1).toString(),u)+" | "+l.str+`
12
+ `;return a.replace(/\n$/,"")}var Wc=Lc,zc=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],Fc=["scalar","sequence","mapping"];function Kc(e){var t={};return e!==null&&Object.keys(e).forEach(function(n){e[n].forEach(function(i){t[String(i)]=n})}),t}function Uc(e,t){if(t=t||{},Object.keys(t).forEach(function(n){if(zc.indexOf(n)===-1)throw new vt('Unknown option "'+n+'" is met in definition of "'+e+'" YAML type.')}),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(n){return n},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=Kc(t.styleAliases||null),Fc.indexOf(this.kind)===-1)throw new vt('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')}var U=Uc;function rr(e,t){var n=[];return e[t].forEach(function(i){var r=n.length;n.forEach(function(s,o){s.tag===i.tag&&s.kind===i.kind&&s.multi===i.multi&&(r=o)}),n[r]=i}),n}function Yc(){var e={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}},t,n;function i(r){r.multi?(e.multi[r.kind].push(r),e.multi.fallback.push(r)):e[r.kind][r.tag]=e.fallback[r.tag]=r}for(t=0,n=arguments.length;t<n;t+=1)arguments[t].forEach(i);return e}function Jn(e){return this.extend(e)}Jn.prototype.extend=function(t){var n=[],i=[];if(t instanceof U)i.push(t);else if(Array.isArray(t))i=i.concat(t);else if(t&&(Array.isArray(t.implicit)||Array.isArray(t.explicit)))t.implicit&&(n=n.concat(t.implicit)),t.explicit&&(i=i.concat(t.explicit));else throw new vt("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");n.forEach(function(s){if(!(s instanceof U))throw new vt("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(s.loadKind&&s.loadKind!=="scalar")throw new vt("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(s.multi)throw new vt("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")}),i.forEach(function(s){if(!(s instanceof U))throw new vt("Specified list of YAML types (or a single Type object) contains a non-Type object.")});var r=Object.create(Jn.prototype);return r.implicit=(this.implicit||[]).concat(n),r.explicit=(this.explicit||[]).concat(i),r.compiledImplicit=rr(r,"implicit"),r.compiledExplicit=rr(r,"explicit"),r.compiledTypeMap=Yc(r.compiledImplicit,r.compiledExplicit),r};var qc=Jn,Gc=new U("tag:yaml.org,2002:str",{kind:"scalar",construct:function(e){return e!==null?e:""}}),Zc=new U("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(e){return e!==null?e:[]}}),Xc=new U("tag:yaml.org,2002:map",{kind:"mapping",construct:function(e){return e!==null?e:{}}}),Jc=new qc({explicit:[Gc,Zc,Xc]});function Vc(e){if(e===null)return!0;var t=e.length;return t===1&&e==="~"||t===4&&(e==="null"||e==="Null"||e==="NULL")}function Qc(){return null}function tl(e){return e===null}var el=new U("tag:yaml.org,2002:null",{kind:"scalar",resolve:Vc,construct:Qc,predicate:tl,represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"});function nl(e){if(e===null)return!1;var t=e.length;return t===4&&(e==="true"||e==="True"||e==="TRUE")||t===5&&(e==="false"||e==="False"||e==="FALSE")}function il(e){return e==="true"||e==="True"||e==="TRUE"}function rl(e){return Object.prototype.toString.call(e)==="[object Boolean]"}var sl=new U("tag:yaml.org,2002:bool",{kind:"scalar",resolve:nl,construct:il,predicate:rl,represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"});function ol(e){return 48<=e&&e<=57||65<=e&&e<=70||97<=e&&e<=102}function al(e){return 48<=e&&e<=55}function cl(e){return 48<=e&&e<=57}function ll(e){if(e===null)return!1;var t=e.length,n=0,i=!1,r;if(!t)return!1;if(r=e[n],(r==="-"||r==="+")&&(r=e[++n]),r==="0"){if(n+1===t)return!0;if(r=e[++n],r==="b"){for(n++;n<t;n++)if(r=e[n],r!=="_"){if(r!=="0"&&r!=="1")return!1;i=!0}return i&&r!=="_"}if(r==="x"){for(n++;n<t;n++)if(r=e[n],r!=="_"){if(!ol(e.charCodeAt(n)))return!1;i=!0}return i&&r!=="_"}if(r==="o"){for(n++;n<t;n++)if(r=e[n],r!=="_"){if(!al(e.charCodeAt(n)))return!1;i=!0}return i&&r!=="_"}}if(r==="_")return!1;for(;n<t;n++)if(r=e[n],r!=="_"){if(!cl(e.charCodeAt(n)))return!1;i=!0}return!(!i||r==="_")}function ul(e){var t=e,n=1,i;if(t.indexOf("_")!==-1&&(t=t.replace(/_/g,"")),i=t[0],(i==="-"||i==="+")&&(i==="-"&&(n=-1),t=t.slice(1),i=t[0]),t==="0")return 0;if(i==="0"){if(t[1]==="b")return n*parseInt(t.slice(2),2);if(t[1]==="x")return n*parseInt(t.slice(2),16);if(t[1]==="o")return n*parseInt(t.slice(2),8)}return n*parseInt(t,10)}function hl(e){return Object.prototype.toString.call(e)==="[object Number]"&&e%1===0&&!Z.isNegativeZero(e)}var fl=new U("tag:yaml.org,2002:int",{kind:"scalar",resolve:ll,construct:ul,predicate:hl,represent:{binary:function(e){return e>=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),dl=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");function pl(e){return!(e===null||!dl.test(e)||e[e.length-1]==="_")}function ml(e){var t,n;return t=e.replace(/_/g,"").toLowerCase(),n=t[0]==="-"?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),t===".inf"?n===1?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:t===".nan"?NaN:n*parseFloat(t,10)}var gl=/^[-+]?[0-9]+e/;function yl(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(Z.isNegativeZero(e))return"-0.0";return n=e.toString(10),gl.test(n)?n.replace("e",".e"):n}function wl(e){return Object.prototype.toString.call(e)==="[object Number]"&&(e%1!==0||Z.isNegativeZero(e))}var _l=new U("tag:yaml.org,2002:float",{kind:"scalar",resolve:pl,construct:ml,predicate:wl,represent:yl,defaultStyle:"lowercase"}),bl=Jc.extend({implicit:[el,sl,fl,_l]}),xl=bl,os=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),as=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");function vl(e){return e===null?!1:os.exec(e)!==null||as.exec(e)!==null}function Al(e){var t,n,i,r,s,o,a,c=0,l=null,u,h,f;if(t=os.exec(e),t===null&&(t=as.exec(e)),t===null)throw new Error("Date resolve error");if(n=+t[1],i=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(n,i,r));if(s=+t[4],o=+t[5],a=+t[6],t[7]){for(c=t[7].slice(0,3);c.length<3;)c+="0";c=+c}return t[9]&&(u=+t[10],h=+(t[11]||0),l=(u*60+h)*6e4,t[9]==="-"&&(l=-l)),f=new Date(Date.UTC(n,i,r,s,o,a,c)),l&&f.setTime(f.getTime()-l),f}function Sl(e){return e.toISOString()}var kl=new U("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:vl,construct:Al,instanceOf:Date,represent:Sl});function Tl(e){return e==="<<"||e===null}var Ol=new U("tag:yaml.org,2002:merge",{kind:"scalar",resolve:Tl}),Di=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
13
+ \r`;function Il(e){if(e===null)return!1;var t,n,i=0,r=e.length,s=Di;for(n=0;n<r;n++)if(t=s.indexOf(e.charAt(n)),!(t>64)){if(t<0)return!1;i+=6}return i%8===0}function El(e){var t,n,i=e.replace(/[\r\n=]/g,""),r=i.length,s=Di,o=0,a=[];for(t=0;t<r;t++)t%4===0&&t&&(a.push(o>>16&255),a.push(o>>8&255),a.push(o&255)),o=o<<6|s.indexOf(i.charAt(t));return n=r%4*6,n===0?(a.push(o>>16&255),a.push(o>>8&255),a.push(o&255)):n===18?(a.push(o>>10&255),a.push(o>>2&255)):n===12&&a.push(o>>4&255),new Uint8Array(a)}function Cl(e){var t="",n=0,i,r,s=e.length,o=Di;for(i=0;i<s;i++)i%3===0&&i&&(t+=o[n>>18&63],t+=o[n>>12&63],t+=o[n>>6&63],t+=o[n&63]),n=(n<<8)+e[i];return r=s%3,r===0?(t+=o[n>>18&63],t+=o[n>>12&63],t+=o[n>>6&63],t+=o[n&63]):r===2?(t+=o[n>>10&63],t+=o[n>>4&63],t+=o[n<<2&63],t+=o[64]):r===1&&(t+=o[n>>2&63],t+=o[n<<4&63],t+=o[64],t+=o[64]),t}function Nl(e){return Object.prototype.toString.call(e)==="[object Uint8Array]"}var Ml=new U("tag:yaml.org,2002:binary",{kind:"scalar",resolve:Il,construct:El,predicate:Nl,represent:Cl}),Dl=Object.prototype.hasOwnProperty,Rl=Object.prototype.toString;function Bl(e){if(e===null)return!0;var t=[],n,i,r,s,o,a=e;for(n=0,i=a.length;n<i;n+=1){if(r=a[n],o=!1,Rl.call(r)!=="[object Object]")return!1;for(s in r)if(Dl.call(r,s))if(!o)o=!0;else return!1;if(!o)return!1;if(t.indexOf(s)===-1)t.push(s);else return!1}return!0}function Hl(e){return e!==null?e:[]}var $l=new U("tag:yaml.org,2002:omap",{kind:"sequence",resolve:Bl,construct:Hl}),Pl=Object.prototype.toString;function jl(e){if(e===null)return!0;var t,n,i,r,s,o=e;for(s=new Array(o.length),t=0,n=o.length;t<n;t+=1){if(i=o[t],Pl.call(i)!=="[object Object]"||(r=Object.keys(i),r.length!==1))return!1;s[t]=[r[0],i[r[0]]]}return!0}function Ll(e){if(e===null)return[];var t,n,i,r,s,o=e;for(s=new Array(o.length),t=0,n=o.length;t<n;t+=1)i=o[t],r=Object.keys(i),s[t]=[r[0],i[r[0]]];return s}var Wl=new U("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:jl,construct:Ll}),zl=Object.prototype.hasOwnProperty;function Fl(e){if(e===null)return!0;var t,n=e;for(t in n)if(zl.call(n,t)&&n[t]!==null)return!1;return!0}function Kl(e){return e!==null?e:{}}var Ul=new U("tag:yaml.org,2002:set",{kind:"mapping",resolve:Fl,construct:Kl}),Yl=xl.extend({implicit:[kl,Ol],explicit:[Ml,$l,Wl,Ul]}),Mt=Object.prototype.hasOwnProperty,cn=1,cs=2,ls=3,ln=4,Mn=1,ql=2,sr=3,Gl=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,Zl=/[\x85\u2028\u2029]/,Xl=/[,\[\]\{\}]/,us=/^(?:!|!!|![a-z\-]+!)$/i,hs=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function or(e){return Object.prototype.toString.call(e)}function pt(e){return e===10||e===13}function zt(e){return e===9||e===32}function V(e){return e===9||e===32||e===10||e===13}function se(e){return e===44||e===91||e===93||e===123||e===125}function Jl(e){var t;return 48<=e&&e<=57?e-48:(t=e|32,97<=t&&t<=102?t-97+10:-1)}function Vl(e){return e===120?2:e===117?4:e===85?8:0}function Ql(e){return 48<=e&&e<=57?e-48:-1}function ar(e){return e===48?"\0":e===97?"\x07":e===98?"\b":e===116||e===9?" ":e===110?`
14
+ `:e===118?"\v":e===102?"\f":e===114?"\r":e===101?"\x1B":e===32?" ":e===34?'"':e===47?"/":e===92?"\\":e===78?"…":e===95?" ":e===76?"\u2028":e===80?"\u2029":""}function tu(e){return e<=65535?String.fromCharCode(e):String.fromCharCode((e-65536>>10)+55296,(e-65536&1023)+56320)}var fs=new Array(256),ds=new Array(256);for(var Qt=0;Qt<256;Qt++)fs[Qt]=ar(Qt)?1:0,ds[Qt]=ar(Qt);function eu(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||Yl,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function ps(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=Wc(n),new vt(t,n)}function S(e,t){throw ps(e,t)}function un(e,t){e.onWarning&&e.onWarning.call(null,ps(e,t))}var cr={YAML:function(t,n,i){var r,s,o;t.version!==null&&S(t,"duplication of %YAML directive"),i.length!==1&&S(t,"YAML directive accepts exactly one argument"),r=/^([0-9]+)\.([0-9]+)$/.exec(i[0]),r===null&&S(t,"ill-formed argument of the YAML directive"),s=parseInt(r[1],10),o=parseInt(r[2],10),s!==1&&S(t,"unacceptable YAML version of the document"),t.version=i[0],t.checkLineBreaks=o<2,o!==1&&o!==2&&un(t,"unsupported YAML version of the document")},TAG:function(t,n,i){var r,s;i.length!==2&&S(t,"TAG directive accepts exactly two arguments"),r=i[0],s=i[1],us.test(r)||S(t,"ill-formed tag handle (first argument) of the TAG directive"),Mt.call(t.tagMap,r)&&S(t,'there is a previously declared suffix for "'+r+'" tag handle'),hs.test(s)||S(t,"ill-formed tag prefix (second argument) of the TAG directive");try{s=decodeURIComponent(s)}catch{S(t,"tag prefix is malformed: "+s)}t.tagMap[r]=s}};function It(e,t,n,i){var r,s,o,a;if(t<n){if(a=e.input.slice(t,n),i)for(r=0,s=a.length;r<s;r+=1)o=a.charCodeAt(r),o===9||32<=o&&o<=1114111||S(e,"expected valid JSON character");else Gl.test(a)&&S(e,"the stream contains non-printable characters");e.result+=a}}function lr(e,t,n,i){var r,s,o,a;for(Z.isObject(n)||S(e,"cannot merge mappings; the provided source object is unacceptable"),r=Object.keys(n),o=0,a=r.length;o<a;o+=1)s=r[o],Mt.call(t,s)||(t[s]=n[s],i[s]=!0)}function oe(e,t,n,i,r,s,o,a,c){var l,u;if(Array.isArray(r))for(r=Array.prototype.slice.call(r),l=0,u=r.length;l<u;l+=1)Array.isArray(r[l])&&S(e,"nested arrays are not supported inside keys"),typeof r=="object"&&or(r[l])==="[object Object]"&&(r[l]="[object Object]");if(typeof r=="object"&&or(r)==="[object Object]"&&(r="[object Object]"),r=String(r),t===null&&(t={}),i==="tag:yaml.org,2002:merge")if(Array.isArray(s))for(l=0,u=s.length;l<u;l+=1)lr(e,t,s[l],n);else lr(e,t,s,n);else!e.json&&!Mt.call(n,r)&&Mt.call(t,r)&&(e.line=o||e.line,e.lineStart=a||e.lineStart,e.position=c||e.position,S(e,"duplicated mapping key")),r==="__proto__"?Object.defineProperty(t,r,{configurable:!0,enumerable:!0,writable:!0,value:s}):t[r]=s,delete n[r];return t}function Ri(e){var t;t=e.input.charCodeAt(e.position),t===10?e.position++:t===13?(e.position++,e.input.charCodeAt(e.position)===10&&e.position++):S(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function L(e,t,n){for(var i=0,r=e.input.charCodeAt(e.position);r!==0;){for(;zt(r);)r===9&&e.firstTabInLine===-1&&(e.firstTabInLine=e.position),r=e.input.charCodeAt(++e.position);if(t&&r===35)do r=e.input.charCodeAt(++e.position);while(r!==10&&r!==13&&r!==0);if(pt(r))for(Ri(e),r=e.input.charCodeAt(e.position),i++,e.lineIndent=0;r===32;)e.lineIndent++,r=e.input.charCodeAt(++e.position);else break}return n!==-1&&i!==0&&e.lineIndent<n&&un(e,"deficient indentation"),i}function xn(e){var t=e.position,n;return n=e.input.charCodeAt(t),!!((n===45||n===46)&&n===e.input.charCodeAt(t+1)&&n===e.input.charCodeAt(t+2)&&(t+=3,n=e.input.charCodeAt(t),n===0||V(n)))}function Bi(e,t){t===1?e.result+=" ":t>1&&(e.result+=Z.repeat(`
15
+ `,t-1))}function nu(e,t,n){var i,r,s,o,a,c,l,u,h=e.kind,f=e.result,p;if(p=e.input.charCodeAt(e.position),V(p)||se(p)||p===35||p===38||p===42||p===33||p===124||p===62||p===39||p===34||p===37||p===64||p===96||(p===63||p===45)&&(r=e.input.charCodeAt(e.position+1),V(r)||n&&se(r)))return!1;for(e.kind="scalar",e.result="",s=o=e.position,a=!1;p!==0;){if(p===58){if(r=e.input.charCodeAt(e.position+1),V(r)||n&&se(r))break}else if(p===35){if(i=e.input.charCodeAt(e.position-1),V(i))break}else{if(e.position===e.lineStart&&xn(e)||n&&se(p))break;if(pt(p))if(c=e.line,l=e.lineStart,u=e.lineIndent,L(e,!1,-1),e.lineIndent>=t){a=!0,p=e.input.charCodeAt(e.position);continue}else{e.position=o,e.line=c,e.lineStart=l,e.lineIndent=u;break}}a&&(It(e,s,o,!1),Bi(e,e.line-c),s=o=e.position,a=!1),zt(p)||(o=e.position+1),p=e.input.charCodeAt(++e.position)}return It(e,s,o,!1),e.result?!0:(e.kind=h,e.result=f,!1)}function iu(e,t){var n,i,r;if(n=e.input.charCodeAt(e.position),n!==39)return!1;for(e.kind="scalar",e.result="",e.position++,i=r=e.position;(n=e.input.charCodeAt(e.position))!==0;)if(n===39)if(It(e,i,e.position,!0),n=e.input.charCodeAt(++e.position),n===39)i=e.position,e.position++,r=e.position;else return!0;else pt(n)?(It(e,i,r,!0),Bi(e,L(e,!1,t)),i=r=e.position):e.position===e.lineStart&&xn(e)?S(e,"unexpected end of the document within a single quoted scalar"):(e.position++,r=e.position);S(e,"unexpected end of the stream within a single quoted scalar")}function ru(e,t){var n,i,r,s,o,a;if(a=e.input.charCodeAt(e.position),a!==34)return!1;for(e.kind="scalar",e.result="",e.position++,n=i=e.position;(a=e.input.charCodeAt(e.position))!==0;){if(a===34)return It(e,n,e.position,!0),e.position++,!0;if(a===92){if(It(e,n,e.position,!0),a=e.input.charCodeAt(++e.position),pt(a))L(e,!1,t);else if(a<256&&fs[a])e.result+=ds[a],e.position++;else if((o=Vl(a))>0){for(r=o,s=0;r>0;r--)a=e.input.charCodeAt(++e.position),(o=Jl(a))>=0?s=(s<<4)+o:S(e,"expected hexadecimal character");e.result+=tu(s),e.position++}else S(e,"unknown escape sequence");n=i=e.position}else pt(a)?(It(e,n,i,!0),Bi(e,L(e,!1,t)),n=i=e.position):e.position===e.lineStart&&xn(e)?S(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}S(e,"unexpected end of the stream within a double quoted scalar")}function su(e,t){var n=!0,i,r,s,o=e.tag,a,c=e.anchor,l,u,h,f,p,d=Object.create(null),g,y,A,_;if(_=e.input.charCodeAt(e.position),_===91)u=93,p=!1,a=[];else if(_===123)u=125,p=!0,a={};else return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=a),_=e.input.charCodeAt(++e.position);_!==0;){if(L(e,!0,t),_=e.input.charCodeAt(e.position),_===u)return e.position++,e.tag=o,e.anchor=c,e.kind=p?"mapping":"sequence",e.result=a,!0;n?_===44&&S(e,"expected the node content, but found ','"):S(e,"missed comma between flow collection entries"),y=g=A=null,h=f=!1,_===63&&(l=e.input.charCodeAt(e.position+1),V(l)&&(h=f=!0,e.position++,L(e,!0,t))),i=e.line,r=e.lineStart,s=e.position,he(e,t,cn,!1,!0),y=e.tag,g=e.result,L(e,!0,t),_=e.input.charCodeAt(e.position),(f||e.line===i)&&_===58&&(h=!0,_=e.input.charCodeAt(++e.position),L(e,!0,t),he(e,t,cn,!1,!0),A=e.result),p?oe(e,a,d,y,g,A,i,r,s):h?a.push(oe(e,null,d,y,g,A,i,r,s)):a.push(g),L(e,!0,t),_=e.input.charCodeAt(e.position),_===44?(n=!0,_=e.input.charCodeAt(++e.position)):n=!1}S(e,"unexpected end of the stream within a flow collection")}function ou(e,t){var n,i,r=Mn,s=!1,o=!1,a=t,c=0,l=!1,u,h;if(h=e.input.charCodeAt(e.position),h===124)i=!1;else if(h===62)i=!0;else return!1;for(e.kind="scalar",e.result="";h!==0;)if(h=e.input.charCodeAt(++e.position),h===43||h===45)Mn===r?r=h===43?sr:ql:S(e,"repeat of a chomping mode identifier");else if((u=Ql(h))>=0)u===0?S(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):o?S(e,"repeat of an indentation width identifier"):(a=t+u-1,o=!0);else break;if(zt(h)){do h=e.input.charCodeAt(++e.position);while(zt(h));if(h===35)do h=e.input.charCodeAt(++e.position);while(!pt(h)&&h!==0)}for(;h!==0;){for(Ri(e),e.lineIndent=0,h=e.input.charCodeAt(e.position);(!o||e.lineIndent<a)&&h===32;)e.lineIndent++,h=e.input.charCodeAt(++e.position);if(!o&&e.lineIndent>a&&(a=e.lineIndent),pt(h)){c++;continue}if(e.lineIndent<a){r===sr?e.result+=Z.repeat(`
16
+ `,s?1+c:c):r===Mn&&s&&(e.result+=`
17
+ `);break}for(i?zt(h)?(l=!0,e.result+=Z.repeat(`
18
+ `,s?1+c:c)):l?(l=!1,e.result+=Z.repeat(`
19
+ `,c+1)):c===0?s&&(e.result+=" "):e.result+=Z.repeat(`
20
+ `,c):e.result+=Z.repeat(`
21
+ `,s?1+c:c),s=!0,o=!0,c=0,n=e.position;!pt(h)&&h!==0;)h=e.input.charCodeAt(++e.position);It(e,n,e.position,!1)}return!0}function ur(e,t){var n,i=e.tag,r=e.anchor,s=[],o,a=!1,c;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=s),c=e.input.charCodeAt(e.position);c!==0&&(e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,S(e,"tab characters must not be used in indentation")),!(c!==45||(o=e.input.charCodeAt(e.position+1),!V(o))));){if(a=!0,e.position++,L(e,!0,-1)&&e.lineIndent<=t){s.push(null),c=e.input.charCodeAt(e.position);continue}if(n=e.line,he(e,t,ls,!1,!0),s.push(e.result),L(e,!0,-1),c=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&c!==0)S(e,"bad indentation of a sequence entry");else if(e.lineIndent<t)break}return a?(e.tag=i,e.anchor=r,e.kind="sequence",e.result=s,!0):!1}function au(e,t,n){var i,r,s,o,a,c,l=e.tag,u=e.anchor,h={},f=Object.create(null),p=null,d=null,g=null,y=!1,A=!1,_;if(e.firstTabInLine!==-1)return!1;for(e.anchor!==null&&(e.anchorMap[e.anchor]=h),_=e.input.charCodeAt(e.position);_!==0;){if(!y&&e.firstTabInLine!==-1&&(e.position=e.firstTabInLine,S(e,"tab characters must not be used in indentation")),i=e.input.charCodeAt(e.position+1),s=e.line,(_===63||_===58)&&V(i))_===63?(y&&(oe(e,h,f,p,d,null,o,a,c),p=d=g=null),A=!0,y=!0,r=!0):y?(y=!1,r=!0):S(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,_=i;else{if(o=e.line,a=e.lineStart,c=e.position,!he(e,n,cs,!1,!0))break;if(e.line===s){for(_=e.input.charCodeAt(e.position);zt(_);)_=e.input.charCodeAt(++e.position);if(_===58)_=e.input.charCodeAt(++e.position),V(_)||S(e,"a whitespace character is expected after the key-value separator within a block mapping"),y&&(oe(e,h,f,p,d,null,o,a,c),p=d=g=null),A=!0,y=!1,r=!1,p=e.tag,d=e.result;else if(A)S(e,"can not read an implicit mapping pair; a colon is missed");else return e.tag=l,e.anchor=u,!0}else if(A)S(e,"can not read a block mapping entry; a multiline key may not be an implicit key");else return e.tag=l,e.anchor=u,!0}if((e.line===s||e.lineIndent>t)&&(y&&(o=e.line,a=e.lineStart,c=e.position),he(e,t,ln,!0,r)&&(y?d=e.result:g=e.result),y||(oe(e,h,f,p,d,g,o,a,c),p=d=g=null),L(e,!0,-1),_=e.input.charCodeAt(e.position)),(e.line===s||e.lineIndent>t)&&_!==0)S(e,"bad indentation of a mapping entry");else if(e.lineIndent<t)break}return y&&oe(e,h,f,p,d,null,o,a,c),A&&(e.tag=l,e.anchor=u,e.kind="mapping",e.result=h),A}function cu(e){var t,n=!1,i=!1,r,s,o;if(o=e.input.charCodeAt(e.position),o!==33)return!1;if(e.tag!==null&&S(e,"duplication of a tag property"),o=e.input.charCodeAt(++e.position),o===60?(n=!0,o=e.input.charCodeAt(++e.position)):o===33?(i=!0,r="!!",o=e.input.charCodeAt(++e.position)):r="!",t=e.position,n){do o=e.input.charCodeAt(++e.position);while(o!==0&&o!==62);e.position<e.length?(s=e.input.slice(t,e.position),o=e.input.charCodeAt(++e.position)):S(e,"unexpected end of the stream within a verbatim tag")}else{for(;o!==0&&!V(o);)o===33&&(i?S(e,"tag suffix cannot contain exclamation marks"):(r=e.input.slice(t-1,e.position+1),us.test(r)||S(e,"named tag handle cannot contain such characters"),i=!0,t=e.position+1)),o=e.input.charCodeAt(++e.position);s=e.input.slice(t,e.position),Xl.test(s)&&S(e,"tag suffix cannot contain flow indicator characters")}s&&!hs.test(s)&&S(e,"tag name cannot contain such characters: "+s);try{s=decodeURIComponent(s)}catch{S(e,"tag name is malformed: "+s)}return n?e.tag=s:Mt.call(e.tagMap,r)?e.tag=e.tagMap[r]+s:r==="!"?e.tag="!"+s:r==="!!"?e.tag="tag:yaml.org,2002:"+s:S(e,'undeclared tag handle "'+r+'"'),!0}function lu(e){var t,n;if(n=e.input.charCodeAt(e.position),n!==38)return!1;for(e.anchor!==null&&S(e,"duplication of an anchor property"),n=e.input.charCodeAt(++e.position),t=e.position;n!==0&&!V(n)&&!se(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&S(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(t,e.position),!0}function uu(e){var t,n,i;if(i=e.input.charCodeAt(e.position),i!==42)return!1;for(i=e.input.charCodeAt(++e.position),t=e.position;i!==0&&!V(i)&&!se(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&S(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),Mt.call(e.anchorMap,n)||S(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],L(e,!0,-1),!0}function he(e,t,n,i,r){var s,o,a,c=1,l=!1,u=!1,h,f,p,d,g,y;if(e.listener!==null&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,s=o=a=ln===n||ls===n,i&&L(e,!0,-1)&&(l=!0,e.lineIndent>t?c=1:e.lineIndent===t?c=0:e.lineIndent<t&&(c=-1)),c===1)for(;cu(e)||lu(e);)L(e,!0,-1)?(l=!0,a=s,e.lineIndent>t?c=1:e.lineIndent===t?c=0:e.lineIndent<t&&(c=-1)):a=!1;if(a&&(a=l||r),(c===1||ln===n)&&(cn===n||cs===n?g=t:g=t+1,y=e.position-e.lineStart,c===1?a&&(ur(e,y)||au(e,y,g))||su(e,g)?u=!0:(o&&ou(e,g)||iu(e,g)||ru(e,g)?u=!0:uu(e)?(u=!0,(e.tag!==null||e.anchor!==null)&&S(e,"alias node should not have any properties")):nu(e,g,cn===n)&&(u=!0,e.tag===null&&(e.tag="?")),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):c===0&&(u=a&&ur(e,y))),e.tag===null)e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);else if(e.tag==="?"){for(e.result!==null&&e.kind!=="scalar"&&S(e,'unacceptable node kind for !<?> tag; it should be "scalar", not "'+e.kind+'"'),h=0,f=e.implicitTypes.length;h<f;h+=1)if(d=e.implicitTypes[h],d.resolve(e.result)){e.result=d.construct(e.result),e.tag=d.tag,e.anchor!==null&&(e.anchorMap[e.anchor]=e.result);break}}else if(e.tag!=="!"){if(Mt.call(e.typeMap[e.kind||"fallback"],e.tag))d=e.typeMap[e.kind||"fallback"][e.tag];else for(d=null,p=e.typeMap.multi[e.kind||"fallback"],h=0,f=p.length;h<f;h+=1)if(e.tag.slice(0,p[h].tag.length)===p[h].tag){d=p[h];break}d||S(e,"unknown tag !<"+e.tag+">"),e.result!==null&&d.kind!==e.kind&&S(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+d.kind+'", not "'+e.kind+'"'),d.resolve(e.result,e.tag)?(e.result=d.construct(e.result,e.tag),e.anchor!==null&&(e.anchorMap[e.anchor]=e.result)):S(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return e.listener!==null&&e.listener("close",e),e.tag!==null||e.anchor!==null||u}function hu(e){var t=e.position,n,i,r,s=!1,o;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);(o=e.input.charCodeAt(e.position))!==0&&(L(e,!0,-1),o=e.input.charCodeAt(e.position),!(e.lineIndent>0||o!==37));){for(s=!0,o=e.input.charCodeAt(++e.position),n=e.position;o!==0&&!V(o);)o=e.input.charCodeAt(++e.position);for(i=e.input.slice(n,e.position),r=[],i.length<1&&S(e,"directive name must not be less than one character in length");o!==0;){for(;zt(o);)o=e.input.charCodeAt(++e.position);if(o===35){do o=e.input.charCodeAt(++e.position);while(o!==0&&!pt(o));break}if(pt(o))break;for(n=e.position;o!==0&&!V(o);)o=e.input.charCodeAt(++e.position);r.push(e.input.slice(n,e.position))}o!==0&&Ri(e),Mt.call(cr,i)?cr[i](e,i,r):un(e,'unknown document directive "'+i+'"')}if(L(e,!0,-1),e.lineIndent===0&&e.input.charCodeAt(e.position)===45&&e.input.charCodeAt(e.position+1)===45&&e.input.charCodeAt(e.position+2)===45?(e.position+=3,L(e,!0,-1)):s&&S(e,"directives end mark is expected"),he(e,e.lineIndent-1,ln,!1,!0),L(e,!0,-1),e.checkLineBreaks&&Zl.test(e.input.slice(t,e.position))&&un(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&xn(e)){e.input.charCodeAt(e.position)===46&&(e.position+=3,L(e,!0,-1));return}if(e.position<e.length-1)S(e,"end of the stream or a document separator is expected");else return}function ms(e,t){e=String(e),t=t||{},e.length!==0&&(e.charCodeAt(e.length-1)!==10&&e.charCodeAt(e.length-1)!==13&&(e+=`
22
+ `),e.charCodeAt(0)===65279&&(e=e.slice(1)));var n=new eu(e,t),i=e.indexOf("\0");for(i!==-1&&(n.position=i,S(n,"null byte is not allowed in input")),n.input+="\0";n.input.charCodeAt(n.position)===32;)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)hu(n);return n.documents}function fu(e,t,n){t!==null&&typeof t=="object"&&typeof n>"u"&&(n=t,t=null);var i=ms(e,n);if(typeof t!="function")return i;for(var r=0,s=i.length;r<s;r+=1)t(i[r])}function du(e,t){var n=ms(e,t);if(n.length!==0){if(n.length===1)return n[0];throw new vt("expected a single document in the stream, but found more")}}var pu=fu,mu=du,gu={loadAll:pu,load:mu},yu=gu.load,yt;function wu(e){return{lang:(e==null?void 0:e.lang)??(yt==null?void 0:yt.lang),message:e==null?void 0:e.message,abortEarly:(e==null?void 0:e.abortEarly)??(yt==null?void 0:yt.abortEarly),abortPipeEarly:(e==null?void 0:e.abortPipeEarly)??(yt==null?void 0:yt.abortPipeEarly)}}var Dn;function _u(e){return Dn==null?void 0:Dn.get(e)}var Rn;function bu(e){return Rn==null?void 0:Rn.get(e)}var Bn;function xu(e,t){var n;return(n=Bn==null?void 0:Bn.get(e))==null?void 0:n.get(t)}function fe(e){var n,i;const t=typeof e;return t==="string"?`"${e}"`:t==="number"||t==="bigint"||t==="boolean"?`${e}`:t==="object"||t==="function"?(e&&((i=(n=Object.getPrototypeOf(e))==null?void 0:n.constructor)==null?void 0:i.name))??"null":t}function Dt(e,t,n,i,r){const s=r&&"input"in r?r.input:n.value,o=(r==null?void 0:r.expected)??e.expects??null,a=(r==null?void 0:r.received)??fe(s),c={kind:e.kind,type:e.type,input:s,expected:o,received:a,message:`Invalid ${t}: ${o?`Expected ${o} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r==null?void 0:r.path,issues:r==null?void 0:r.issues,lang:i.lang,abortEarly:i.abortEarly,abortPipeEarly:i.abortPipeEarly},l=e.kind==="schema",u=(r==null?void 0:r.message)??e.message??xu(e.reference,c.lang)??(l?bu(c.lang):null)??i.message??_u(c.lang);u&&(c.message=typeof u=="function"?u(c):u),l&&(n.typed=!1),n.issues?n.issues.push(c):n.issues=[c]}function vu(e,t){const n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??"never"}function Vn(e,t){return{kind:"validation",type:"max_value",reference:Vn,async:!1,expects:`<=${e instanceof Date?e.toJSON():fe(e)}`,requirement:e,message:t,_run(n,i){return n.typed&&n.value>this.requirement&&Dt(this,"value",n,i,{received:n.value instanceof Date?n.value.toJSON():fe(n.value)}),n}}}function Qn(e,t){return{kind:"validation",type:"min_value",reference:Qn,async:!1,expects:`>=${e instanceof Date?e.toJSON():fe(e)}`,requirement:e,message:t,_run(n,i){return n.typed&&n.value<this.requirement&&Dt(this,"value",n,i,{received:n.value instanceof Date?n.value.toJSON():fe(n.value)}),n}}}function Au(e,t,n){return typeof e.default=="function"?e.default(t,n):e.default}function gs(e,t){return{kind:"schema",type:"array",reference:gs,expects:"Array",async:!1,item:e,message:t,_run(n,i){var s;const r=n.value;if(Array.isArray(r)){n.typed=!0,n.value=[];for(let o=0;o<r.length;o++){const a=r[o],c=this.item._run({typed:!1,value:a},i);if(c.issues){const l={type:"array",origin:"value",input:r,key:o,value:a};for(const u of c.issues)u.path?u.path.unshift(l):u.path=[l],(s=n.issues)==null||s.push(u);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),n.value.push(c.value)}}else Dt(this,"type",n,i);return n}}}function hn(e){return{kind:"schema",type:"number",reference:hn,expects:"number",async:!1,message:e,_run(t,n){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:Dt(this,"type",t,n),t}}}function ut(e,...t){const n={kind:"schema",type:"optional",reference:ut,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,_run(i,r){return i.value===void 0&&("default"in this&&(i.value=Au(this,i,r)),i.value===void 0)?(i.typed=!0,i):this.wrapped._run(i,r)}};return 0 in t&&(n.default=t[0]),n}function ti(e,t){return{kind:"schema",type:"picklist",reference:ti,expects:vu(e.map(fe),"|"),async:!1,options:e,message:t,_run(n,i){return this.options.includes(n.value)?n.typed=!0:Dt(this,"type",n,i),n}}}function de(e,t){return{kind:"schema",type:"strict_object",reference:de,expects:"Object",async:!1,entries:e,message:t,_run(n,i){var s;const r=n.value;if(r&&typeof r=="object"){n.typed=!0,n.value={};for(const o in this.entries){const a=r[o],c=this.entries[o]._run({typed:!1,value:a},i);if(c.issues){const l={type:"object",origin:"value",input:r,key:o,value:a};for(const u of c.issues)u.path?u.path.unshift(l):u.path=[l],(s=n.issues)==null||s.push(u);if(n.issues||(n.issues=c.issues),i.abortEarly){n.typed=!1;break}}c.typed||(n.typed=!1),(c.value!==void 0||o in r)&&(n.value[o]=c.value)}if(!n.issues||!i.abortEarly){for(const o in r)if(!(o in this.entries)){const a=r[o];Dt(this,"type",n,i,{input:a,expected:"never",path:[{type:"object",origin:"value",input:r,key:o,value:a}]});break}}}else Dt(this,"type",n,i);return n}}}function fn(e){return{kind:"schema",type:"string",reference:fn,expects:"string",async:!1,message:e,_run(t,n){return typeof t.value=="string"?t.typed=!0:Dt(this,"type",t,n),t}}}function hr(...e){return{...e[0],pipe:e,_run(t,n){for(const i of e)if(i.kind!=="metadata"){if(t.issues&&(i.kind==="schema"||i.kind==="transformation")){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=i._run(t,n))}return t}}}function Su(e,t,n){const i=e._run({typed:!1,value:t},wu(n));return{typed:i.typed,success:!i.issues,output:i.value,issues:i.issues}}const Ve=ut(de({discard:ut(fn(),""),hand:ut(fn(),""),score:ut(hn(),25e3)}),{discard:"",hand:"",score:25e3}),ku=de({[T.EAST]:Ve,[T.SOUTH]:Ve,[T.WEST]:Ve,[T.NORTH]:Ve}),Tu=de({round:ut(ti(Object.keys(fi)),"1w1"),sticks:ut(de({reach:ut(hr(hn(),Qn(0,""),Vn(9,"")),0),dead:ut(hr(hn(),Qn(0,""),Vn(9,"")),0)}),{reach:0,dead:0}),doras:ut(gs(fn()),["3w"]),front:ut(ti(Object.keys(di)),"1w")}),Ou=de({...ku.entries,board:Tu}),ys=e=>{const t=ws(e);return _s(t)},ws=e=>{const t=yu(e),n=Su(Ou,t.table);if(!n.success)throw n.issues;return n.output},_s=e=>{const t=e.board.front,n=Iu(t),i=a=>e[a].discard.replace(/\r?\n/g,""),r={front:new ot(i(n.front)).tiles(),right:new ot(i(n.right)).tiles(),opposite:new ot(i(n.opposite)).tiles(),left:new ot(i(n.left)).tiles()},s={front:new ot(e[n.front].hand).parse(),right:new ot(e[n.right].hand).parse(),opposite:new ot(e[n.opposite].hand).parse(),left:new ot(e[n.left].hand).parse()},o={round:fi[e.board.round],frontPlace:di[t],sticks:e.board.sticks,doras:e.board.doras.map(a=>w.from(a)),scores:{front:e[n.front].score,right:e[n.right].score,opposite:e[n.opposite].score,left:e[n.left].score}};return{discards:r,hands:s,scoreBoard:o}},Iu=e=>{const t=(r,s)=>{let o=`${s}w`;return s>4&&(o=`${s-r}w`),o},n=Number(e[0]);return{front:e,right:t(n,n+1),opposite:t(n,n+2),left:t(n,n+3)}};function q(e,t=!1){const n={[T.EAST]:e,[T.SOUTH]:e,[T.WEST]:e,[T.NORTH]:e};if(t)for(let i of Object.values(T))n[i]=structuredClone(e);return n}class pe{constructor(t,n=!1){x(this,"data");this.data={[m.M]:[0,0,0,0,0,0,0,0,0,0],[m.P]:[0,0,0,0,0,0,0,0,0,0],[m.S]:[0,0,0,0,0,0,0,0,0,0],[m.Z]:[0,0,0,0,0,0,0,0],[m.BACK]:["untouchable",0],called:[],reached:!1,tsumo:null},this.init(t,n)}init(t,n){const i=new ot(t).parse();for(let r of i){if(r.isCalled()){this.data.called=[...this.called,r];continue}else if(r.is(b.TSUMO)){const s=r.tiles[0];this.inc([s]),this.data.tsumo=s;continue}else if(r.is(b.HAND)){this.inc(r.tiles);continue}else if(t.split("").every(s=>s===m.BACK)){this.inc(r.tiles);continue}else if(n){this.inc(r.tiles);continue}throw new Error(`unexpected block ${r.type} ${r.toString()}`)}}get hands(){const t=[];for(let n of Object.values(m))for(let i=1;i<this.getArrayLen(n);i++){let r=this.get(n,i);n!=m.Z&&i==5&&this.get(n,0)>0&&(r-=this.get(n,0),t.push(new w(n,0)));for(let s=0;s<r;s++)t.push(new w(n,i))}if(this.drawn!=null){const n=this.drawn,i=t.findIndex(r=>r.equals(n));R(i>=0,`hand has drawn: ${this.drawn} but no tile in hands: ${t.join("")}`),t[i]=t[i].clone({add:v.TSUMO})}return R(t.length>0,`no tiles in hand ${t.length}, called: ${this.called}, data: ${JSON.stringify(this.data,null,2)}`),t}toString(){let t="";for(let s of this.called)t=`${t},${s.toString()}`;let n="";this.drawn&&(n=`,${this.drawn.toString()}`);const i=this.hands.filter(s=>!s.has(v.TSUMO));return`${new gn(i).toString()}${n}${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 G))}getArrayLen(t){return this.data[t].length}sum(t){let n=0;for(let i=1;i<this.getArrayLen(t);i++)n+=this.get(t,i);return n}get(t,n){return t==m.BACK?this.data[t][1]:this.data[t][n]}inc(t){const n=[];for(let i of t){if(i.t!=m.BACK&&this.get(i.t,i.n)>=4)throw this.dec(n),new Error(`unable to increase ${i} in ${this.toString()}`);if(n.push(i),nt(i)&&(this.data[i.t][5]+=1),i.t==m.BACK?this.data[i.t][1]+=1:this.data[i.t][i.n]+=1,et(i)&&this.get(i.t,5)==4&&this.get(i.t,0)==0){this.data[i.t][0]=1;const r=n.pop().clone({n:0});n.push(r)}}return n}dec(t){const n=[];for(let i of t){if(this.get(i.t,i.n)<1)throw this.inc(n),new Error(`unable to decrease ${i.toString()} in ${this.toString()}`);if(n.push(i),nt(i)&&(this.data[i.t][5]-=1),i.t==m.BACK?this.data[i.t][1]-=1:this.data[i.t][i.n]-=1,et(i)&&this.get(i.t,5)==0&&this.get(i.t,0)>0){this.data[i.t][0]=0;const r=n.pop().clone({n:0});n.push(r)}}return n}draw(t){const n=t.clone({add:v.TSUMO});this.inc([n]),this.data.tsumo=n}discard(t){this.dec([t]),this.data.tsumo=null}reach(){if(!this.menzen)throw new Error("cannot reach");if(this.data.reached)throw new Error("already reached");this.data.reached=!0}call(t){if(!(t instanceof dt||t instanceof ht||t instanceof bt))throw new Error(`unexpected input ${t} ${t.type}`);const n=t.tiles.filter(i=>!i.has(v.HORIZONTAL));if(n.length!=t.tiles.length-1)throw new Error(`removal: ${n} block: ${t}`);this.dec(n),this.data.called=[...this.called,t],this.data.tsumo=null}kan(t){if(t instanceof G){let n=t.tiles[0];nt(n)&&(n=new w(n.t,5)),this.dec([n,n,n,n]),this.data.called=[...this.called,t],this.data.tsumo=null;return}if(t instanceof xt){const n=this.data.called.findIndex(r=>r.is(b.PON)&&r.tiles[0].equals(t.tiles[0],!0));if(n==-1)throw new Error(`unable to find ${t.tiles[0]}`);let i=t.tiles[0];nt(i)&&(i=new w(i.t,5)),this.dec([i]),this.data.called=[...this.called.slice(0,n),...this.called.slice(n+1),t],this.data.tsumo=null;return}throw new Error(`unexpected input ${t}`)}clone(){const t=new pe(this.toString());return t.data.reached=this.data.reached,t}}class me{constructor(t){x(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,n=0;for(let i of Object.values(m))if(i!=m.BACK)for(let r=1;r<this.hand.getArrayLen(i);r++)this.hand.get(i,r)==2&&t++,this.hand.get(i,r)==1&&n++;return t>7&&(t=7),t+n>=7&&(n=7-t),13-2*t-n}thirteenOrphans(){if(this.hand.called.length>0)return 1/0;let t=0,n=0;for(let i of Object.values(m)){if(i==m.BACK)continue;const r=i==m.Z?$e:_t;for(let s of r)this.hand.get(i,s)>=1&&t++,this.hand.get(i,s)>=2&&n++}return n>=1?12-t:13-t}fourSetsOnePair(){const t=i=>{const r=[0,0,0],s=m.Z;for(let p=1;p<this.hand.getArrayLen(s);p++)this.hand.get(s,p)>=3?r[0]++:this.hand.get(s,p)==2?r[1]++:this.hand.get(s,p)==1&&r[2]++;const o=[0,0,0],a=this.hand.get(m.BACK,0),c=a%3;o[0]=Math.floor(a/3),c==2&&(o[1]=1),c==1&&(o[2]=1);let l=13;const u=this.commonByType(m.M),h=this.commonByType(m.P),f=this.commonByType(m.S);for(let p of[u.patternA,u.patternB])for(let d of[h.patternA,h.patternB])for(let g of[f.patternA,f.patternB]){const y=[this.hand.called.length,0,0];for(let _=0;_<3;_++)y[_]+=p[_]+d[_]+g[_]+r[_]+o[_];let A=this.calcCommon(y[0],y[1],y[2],i);A<l&&(l=A)}return l};let n=t(!1);for(let i of Object.values(m))for(let r=1;r<this.hand.getArrayLen(i);r++)if(this.hand.get(i,r)>=2){const s=this.hand.dec([new w(i,r),new w(i,r)]),o=t(!0);this.hand.inc(s),o<n&&(n=o)}return n}commonByType(t,n=1){if(t==m.BACK||t==m.Z)throw new Error(`expect number type but ${t}`);if(n>9)return this.groupRemainingTiles(t);let i=this.commonByType(t,n+1);if(n<=7&&this.hand.get(t,n)>0&&this.hand.get(t,n+1)>0&&this.hand.get(t,n+2)>0){const r=this.hand.dec([new w(t,n),new w(t,n+1),new w(t,n+2)]),s=this.commonByType(t,n);this.hand.inc(r),s.patternA[0]++,s.patternB[0]++,(s.patternA[2]<i.patternA[2]||s.patternA[2]==i.patternA[2]&&s.patternA[1]<i.patternA[1])&&(i.patternA=s.patternA),(s.patternB[0]>i.patternB[0]||s.patternB[0]==i.patternB[0]&&s.patternB[1]>i.patternB[1])&&(i.patternB=s.patternB)}if(this.hand.get(t,n)>=3){const r=this.hand.dec([new w(t,n),new w(t,n),new w(t,n)]),s=this.commonByType(t,n);this.hand.inc(r),s.patternA[0]++,s.patternB[0]++,(s.patternA[2]<i.patternA[2]||s.patternA[2]==i.patternA[2]&&s.patternA[1]<i.patternA[1])&&(i.patternA=s.patternA),(s.patternB[0]>i.patternB[0]||s.patternB[0]==i.patternB[0]&&s.patternB[1]>i.patternB[1])&&(i.patternB=s.patternB)}return i}groupRemainingTiles(t){let n=0,i=0,r=0;for(let s=1;s<this.hand.getArrayLen(t);s++)r+=this.hand.get(t,s),s<=7&&this.hand.get(t,s+1)==0&&this.hand.get(t,s+2)==0&&(n+=r>>1,i+=r%2,r=0);return n+=r>>1,i+=r%2,{patternA:[0,n,i],patternB:[0,n,i]}}calcCommon(t,n,i,r){let s=r?4:5;return t>4&&(n+=t-4,t=4),t+n>4&&(i+=t+n-4,n=4-t),t+n+i>s&&(i=s-t-n),r&&n++,13-t*3-n*2-i}}class bs{constructor(t){x(this,"hand");this.hand=t}calc(t){return this.hand.drawn!=null&&(t=this.hand.drawn),this.markDrawn([...this.sevenPairs(),...this.thirteenOrphans(),...this.nineGates(),...this.fourSetsOnePair()],t)}markDrawn(t,n){if(t.length==0)return[];const i=this.hand.drawn!=null||n.has(v.TSUMO)?v.TSUMO:v.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(p=>p.equals(n,!0));if(h<0)continue;const f=xs(u);c[f]||(c[f]=!0,r.push([o,l,h]))}}if(r.length==0)throw new Error(`found no tile ${n.toString()} in hands ${t[0].toString()}`);const s=[];for(let[o,a,c]of r){const u=t[o].map(p=>p.clone()),h=u[a],f=h.tiles[c].clone({add:i});u[a]=h.clone({replace:{idx:c,tile:f}}),s.push(u)}return s}sevenPairs(){if(this.hand.called.length>0)return[];const t=[];for(let n of Object.values(m))if(n!=m.BACK)for(let i=1;i<this.hand.getArrayLen(n);i++){const r=this.hand.get(n,i);if(r==2)t.push(new X(new w(n,i),new w(n,i)));else{if(r==0)continue;return[]}}return[t]}thirteenOrphans(){const t=[];let n="";for(let i of Object.values(m)){if(i==m.BACK)continue;const r=i==m.Z?$e:_t;for(let s of r)if(this.hand.get(i,s)==1)t.push(new mi(new w(i,s)));else if(this.hand.get(i,s)==2&&n=="")t.unshift(new X(new w(i,s),new w(i,s)));else return[]}return[t]}nineGates(){const t=(n,i,r)=>r.includes(this.hand.get(n,i));for(let n of Object.values(m)){if(n==m.BACK||n==m.Z)continue;const i=t(n,1,[3,4])&&t(n,9,[3,4])&&t(n,2,[1,2])&&t(n,3,[1,2])&&t(n,4,[1,2])&&t(n,5,[1,2])&&t(n,6,[1,2])&&t(n,7,[1,2])&&t(n,8,[1,2]),r=this.hand.sum(n)==14;if(i&&r)return[[new gn(this.hand.hands)]]}return[]}fourSetsOnePair(){let t=[];for(let n of Object.values(m))for(let i=1;i<this.hand.getArrayLen(n);i++)if(this.hand.get(n,i)>=2){const r=this.hand.dec([new w(n,i),new w(n,i)]),s=this.commonAll().filter(o=>o.length==4).map(o=>(o.unshift(new X(r[0],r[1])),o));t=[...t,...s],this.hand.inc(r)}return t}commonAll(){const t=()=>{const s=[],o=m.Z;for(let a=1;a<this.hand.getArrayLen(o);a++)if(this.hand.get(o,a)!=0){if(this.hand.get(o,a)!=3)return[];s.push(new lt([new w(o,a),new w(o,a),new w(o,a)]))}return s.length==0?[]:[s]},n=()=>{const s=[],o=m.BACK,a=this.hand.get(o,0);return a<3?[]:(Array(Math.floor(a/3)).fill(void 0).map(c=>{s.push(new lt([new w(o,0),new w(o,0),new w(o,0)]))}),s.length==0?[]:[s])},i=[this.commonByType(m.M),this.commonByType(m.P),this.commonByType(m.S),t(),n(),[this.hand.called.concat()]].sort((s,o)=>o.length-s.length),r=i[0].concat();for(let s=0;s<r.length;s++)for(let o=1;o<i.length;o++)for(let a of i[o])r[s]=[...r[s],...a];return r}commonByType(t,n=1){if(n>9)return[];if(this.hand.get(t,n)==0)return this.commonByType(t,n+1);const i=[];if(n<=7&&this.hand.get(t,n)>0&&this.hand.get(t,n+1)>0&&this.hand.get(t,n+2)>0){const r=this.hand.dec([new w(t,n),new w(t,n+1),new w(t,n+2)]),s=this.commonByType(t,n);this.hand.inc(r),s.length==0&&s.push([]);for(let o of s)o.unshift(new kt([r[0],r[1],r[2]])),i.push(o)}if(this.hand.get(t,n)==3){const r=this.hand.dec([new w(t,n),new w(t,n),new w(t,n)]),s=this.commonByType(t,n);this.hand.inc(r),s.length==0&&s.push([]);for(let o of s)o.unshift(new lt([r[0],r[1],r[2]])),i.push(o)}return i}}const $e=[1,2,3,4,5,6,7],_t=[1,9],tn=e=>{var n;const t=e.boardContext;return{...e,hand:e.hand.map(W.from),boardContext:{...t,doraMarkers:t.doraMarkers.map(w.from),blindDoraMarkers:(n=t.blindDoraMarkers)==null?void 0:n.map(w.from)}}};class ei{constructor(t,n){x(this,"hand");x(this,"cfg");this.hand=t,this.cfg={doras:n.doraMarkers.map(i=>dr(i)),blindDoras:n.blindDoraMarkers==null?[]:n.blindDoraMarkers.map(i=>dr(i)),roundWind:w.from(n.round.substring(0,2)),myWind:w.from(n.myWind),reached:n.reached??0,sticks:n.sticks??{dead:0,reach:0},replacementWin:n.replacementWin??!1,quadWin:n.quadWin??!1,finalWallWin:n.finalWallWin??!1,finalDiscardWin:n.finalDiscardWin??!1,oneShotWin:n.oneShotWin??!1,orig:n}}calc(t){const n=this.calcPatterns(t);if(n.length==0)return!1;let i=[0,0],r=0;for(let d=0;d<n.length;d++){const g=n[d],y=g.points.reduce((A,_)=>A+_.double,0);(y>i[0]||y==i[0]&&g.fu>i[1])&&(r=d,i[0]=y,i[1]=g.fu)}const s=(d,g=100)=>Math.ceil(d/g)*g,o=i[1]!=25?s(i[1],10):25,a=i[0];let c=o*2**(a+2);switch(a){case 26:c=16e3;break;case 13:c=8e3;break;case 12:case 11:c=6e3;break;case 10:case 9:case 8:c=6e3;break;case 7:case 6:c=4e3;break;case 5:c=2e3;break}a>13&&a<26&&(c=8e3);const l=n[r].hand.some(d=>d.tiles.some(g=>g.has(v.TSUMO))),u=this.cfg.orig.myWind,h=u==T.EAST,f=q(0);if(l){const d=this.cfg.sticks.dead*100;if(h){const g=s(c*2);f["1w"]+=g*3+d*3,f["2w"]-=g+d,f["3w"]-=g+d,f["4w"]-=g+d}else for(let g of Object.values(T)){if(g==u)continue;const y=g==T.EAST?2:1,A=s(c*y)+d;f[g]-=A,f[u]+=A}}else{const d=this.cfg.sticks.dead*300;if(this.cfg.orig.ronWind==null)throw new Error("ron wind is not specified in the parameters");const y=s(c*(h?6:4))+d;f[u]+=y,f[this.cfg.orig.ronWind]-=y}return f[u]+=1e3*this.cfg.sticks.reach,{deltas:f,sum:a,fu:o,points:n[r].points,point:f[u],hand:n[r].hand,boardContext:this.cfg.orig}}calcPatterns(t){const n=[];if(t.length==0)return n;for(let i of t){const r=[...this.dA13(i),...this.dB13(i),...this.dC13(i),...this.dD13(i),...this.dE13(i),...this.dF13(i),...this.dG13(i),...this.dH13(i),...this.dI13(i),...this.dJ13(i),...this.dK13(i)];r.length!=0&&n.push({points:r,fu:30,hand:i})}if(n.length>0)return n;for(let i of t){const r=this.calcFu(i),s=[...this.dA1(i),...this.dB1(i),...this.dC1(i),...this.dD1(i),...this.dE1(i),...this.dF1(i),...this.dG1(i),...this.dH1(i),...this.dI1(i),...this.dJ1(i),...this.dK1(i),...this.dA2(i),...this.dB2(i),...this.dC2(i),...this.dD2(i),...this.dE2(i),...this.dF2(i),...this.dG2(i),...this.dH2(i),...this.dI2(i),...this.dJ2(i),...this.dA3(i),...this.dB3(i),...this.dC3(i),...this.dA6(i)];s.length>0&&s.push(...this.dX1(i)),n.push({points:s,fu:r,hand:i})}return n}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(i=>i.tiles.some(r=>r.has(v.TSUMO)))?[{name:"門前清自摸和",double:1}]:[])}dC1(t){if(this.minus()!=0)return[];const n="平和",i=this.calcFu(t);return i==20?[{name:n,double:1}]:!t.some(r=>r.tiles.some(s=>s.has(v.TSUMO)))&&i==30?[{name:n,double:1}]:[]}dD1(t){return t.some(i=>i.tiles.some(r=>r.t==m.Z||_t.includes(r.n)))?[]:[{name:"断么九",double:1}]}dE1(t){return this.minus()!=0?[]:fr(t)==1?[{name:"一盃口",double:1}]:[]}dF1(t){const n=[];return t.forEach(i=>{if(i instanceof X)return;const r=i.tiles[0];r.t==m.Z&&(r.equals(this.cfg.myWind)?n.push({name:"自風",double:1}):r.equals(this.cfg.roundWind)?n.push({name:"場風",double:1}):r.n==5?n.push({name:"白",double:1}):r.n==6?n.push({name:"發",double:1}):r.n==7&&n.push({name:"中",double:1}))}),n}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 n=0,i=0,r=0;for(let o of t)for(let a of o.tiles){for(let c of this.cfg.doras)a.equals(c,!0)&&n++;for(let c of this.cfg.blindDoras)a.equals(c,!0)&&r++;nt(a)&&i++}const s=[];return n>0&&s.push({name:"ドラ",double:n}),i>0&&s.push({name:"赤ドラ",double:i}),this.hand.reached&&r>0&&s.push({name:"裏ドラ",double:r}),s}dA2(t){return t.length==7?[{name:"七対子",double:2}]:[]}dB2(t){const n=i=>i instanceof kt||i instanceof ht;for(let i of t){if(!n(i))continue;const r=Bt(i);if(r.t==m.Z)continue;const s=[m.M,m.P,m.S].filter(c=>c!=r.t),o=t.some(c=>{const l=new w(s[0],r.n);return n(c)&&l.equals(Bt(c),!0)}),a=t.some(c=>{const l=new w(s[1],r.n);return n(c)&&l.equals(Bt(c),!0)});if(o&&a)return[{name:"三色同順",double:2-this.minus()}]}return[]}dC2(t){return t.length==7?[]:t.every(i=>i instanceof G||i instanceof xt||i instanceof bt||i instanceof lt||i instanceof dt||i instanceof X)?[{name:"対々和",double:2}]:[]}dD2(t){return this.minus()!=0?[]:t.filter(i=>(i instanceof G||i instanceof lt)&&!i.tiles.some(r=>r.has(v.RON))).length>=3?[{name:"三暗刻",double:2}]:[]}dE2(t){return t.filter(i=>i instanceof G||i instanceof xt||i instanceof bt).length>=3?[{name:"三槓子",double:2}]:[]}dF2(t){const n=i=>i instanceof G||i instanceof xt||i instanceof bt||i instanceof lt||i instanceof dt;for(let i of t){if(!n(i))continue;const r=Bt(i);if(r.t==m.Z)continue;const s=[m.M,m.P,m.S].filter(c=>c!=r.t),o=t.some(c=>{const l=new w(s[0],r.n);return n(c)&&l.equals(Bt(c),!0)}),a=t.some(c=>{const l=new w(s[1],r.n);return n(c)&&l.equals(Bt(c),!0)});if(o&&a)return[{name:"三色同刻",double:2}]}return[]}dG2(t){return t.filter(i=>{const r=i.tiles[0];return r.t==m.Z&&[5,6,7].includes(r.n)}).length==3?[{name:"小三元",double:2}]:[]}dH2(t){return t.every(i=>{const r=i.tiles[0].t==m.Z?$e:_t;return i.tiles.every(s=>r.includes(s.n))})?[{name:"混老頭",double:2}]:[]}dI2(t){return t.length==7?[]:t.some(i=>i instanceof kt||i instanceof ht)?t.some(i=>i.tiles[0].t==m.Z)?t.every(i=>{const r=i.tiles[0].t==m.Z?$e:_t;return i.tiles.some(s=>r.includes(s.n))})?[{name:"混全帯么九",double:2-this.minus()}]:[]:[]:[]}dJ2(t){if(this.minus()!=0)return[];let n={[m.M]:[0,0,0],[m.S]:[0,0,0],[m.P]:[0,0,0]};for(let i of t){const r=Bt(i);r.t!=m.BACK&&r.t!=m.Z&&(i instanceof kt||i instanceof ht)&&(r.n==1&&n[r.t][0]++,r.n==4&&n[r.t][1]++,r.n==7&&n[r.t][2]++)}for(let i of Object.values(n))if(i.filter(r=>r>0).length==i.length)return[{name:"一気通貫",double:2-this.minus()}];return[]}dA3(t){if(!t.some(i=>i.tiles[0].t==m.Z))return[];for(let i of Object.values(m))if(t.every(s=>s.tiles[0].t==m.Z||s.tiles[0].t==i))return[{name:"混一色",double:3-this.minus()}];return[]}dB3(t){return t.length==7?[]:t.some(i=>i instanceof kt||i instanceof ht)?t.some(i=>i.tiles[0].t==m.Z)?[]:t.every(i=>i.tiles.some(r=>_t.includes(r.n)))?[{name:"純全帯么九色",double:3-this.minus()}]:[]:[]}dC3(t){return this.minus()!=0?[]:fr(t)==2?[{name:"ニ盃口",double:3}]:[]}dA6(t){if(t.some(n=>n.tiles[0].t==m.Z))return[];for(let n of Object.values(m)){if(n==m.Z)continue;if(t.every(r=>r.tiles[0].t==n))return[{name:"清一色",double:6-this.minus()}]}return[]}dA13(t){return t.length!=13?[]:t.some(i=>i instanceof X&&i.tiles.some(r=>r.has(v.TSUMO)||r.has(v.RON)))?[{name:"国士無双13面待ち",double:26}]:[{name:"国士無双",double:13}]}dB13(t){return t.length==1?[{name:"九蓮宝燈",double:13}]:[]}dC13(t){return t.length==7?[]:t.every(r=>r instanceof G||r instanceof lt&&!r.tiles.some(s=>s.has(v.RON))||r instanceof X)?t.some(r=>r instanceof X&&r.tiles.every(s=>s.has(v.TSUMO)||s.has(v.RON)))?[{name:"四暗刻単騎待ち",double:26}]:[{name:"四暗刻",double:13}]:[]}dD13(t){if(t.length==13)return[];const n=[5,6,7];return t.filter(r=>!(r instanceof X)&&r.tiles.some(s=>s.t==m.Z&&n.includes(s.n))).length==3?[{name:"大三元",double:13}]:[]}dE13(t){return t.every(i=>i.tiles[0].t==m.Z)?[{name:"字一色",double:13}]:[]}dF13(t){return t.every(i=>i.tiles.every(r=>r.t!=m.Z&&_t.includes(r.n)))?[{name:"清老頭",double:13}]:[]}dG13(t){return t.filter(i=>i instanceof G||i instanceof xt||i instanceof bt).length==4?[{name:"四槓子",double:13}]:[]}dH13(t){if(t.length==13)return[];if(t.length==7)return[];const n=[1,2,3,4];return t.filter(s=>s.tiles.some(o=>o.t==m.Z&&n.includes(o.n))).length==4?t.find(s=>s instanceof X).tiles.some(s=>s.t==m.Z&&n.includes(s.n))?[{name:"小四喜",double:13}]:[{name:"大四喜",double:13}]:[]}dI13(t){const n=i=>!!(i.equals(new w(m.Z,6))||i.t==m.S&&[2,3,4,6,8].includes(i.n));return t.every(i=>i.tiles.every(r=>n(r)))?[{name:"緑一色",double:13}]:[]}dJ13(t){return[]}dK13(t){return[]}calcFu(t){let i=20;const r=this.cfg.myWind.n,s=this.cfg.roundWind.n;if(t.length==7)return 25;const o=t.find(d=>d.tiles.some(g=>g.has(v.TSUMO)||g.has(v.RON))),a=this.minus()==1,c=o.tiles.some(d=>d.has(v.TSUMO)),l=(d,g)=>{const y=d.tiles[0];return y.t==m.Z&&[5,6,7].includes(y.n)||y.t==m.Z&&[r,s].includes(y.n)||_t.includes(y.n)?g*2:g};for(let d of t)switch(!0){case d instanceof lt:let g=d.tiles.some(y=>y.has(v.RON))?2:4;i+=l(d,g);break;case d instanceof dt:i+=l(d,2);break;case(d instanceof bt||d instanceof xt):i+=l(d,8);break;case d instanceof G:i+=l(d,16);break}i+=(d=>{if(d instanceof lt)return 0;if(d instanceof X)return 2;const g=d.tiles,y=g.findIndex(A=>A.has(v.TSUMO)||A.has(v.RON));return y==1||y==0&&g[2].n==9||y==2&&g[0].n==1?2:0})(o);let f=t.find(d=>d instanceof X).tiles[0];f.t==m.Z&&([5,6,7].includes(f.n)&&(i+=2),f.n==s&&(i+=2),f.n==r&&(i+=2));let p=!1;return!a&&i==20&&(p=!0),c&&!p&&(i+=2),!c&&!a&&(i+=10),!c&&!a&&i==30&&(p=!0),a&&i==20&&(i=30),i}}const xs=e=>e.tiles.reduce((t,n)=>`${t}${n.n}${n.t}`,""),fr=e=>{let t={};for(let i of e){if(!(i instanceof kt))continue;const r=xs(i);t[r]==null?t[r]=1:t[r]++}let n=0;for(let i in t)t[i]>=2&&n++;return n},Bt=e=>[...e.tiles].sort(Ce)[0],dr=e=>{let t=nt(e)?5:e.n,n=e.t;return new w(n,t%9+1)};class Yt{static calcCandidates(t,n){R(n.length>0,"choices to discard is zero");let i=[];for(let r of n){const s=t.dec([r]),o=Yt.candidateTiles(t);t.inc(s),i.length==0||o.shanten<i[0].shanten?i=[{shanten:o.shanten,candidates:o.candidates,tile:r}]:o.shanten==i[0].shanten&&i.push({candidates:o.candidates,shanten:o.shanten,tile:r})}return i}static candidateTiles(t){let n=Number.POSITIVE_INFINITY,i=[];const r=new me(t);for(let s of Object.values(m))if(s!=m.BACK)for(let o=1;o<t.getArrayLen(s);o++){if(t.get(s,o)>=4)continue;const a=new w(s,o),c=t.inc([a]),l=r.calc();t.dec(c),l<n?(n=l,i=[a]):l==n&&i.push(a)}return{shanten:n,candidates:i}}static partialCandidateTiles(t){const n=new pe(t,!0);return Array(13-n.hands.length).fill(void 0).map(()=>n.inc([new w(m.BACK,0)])),Yt.candidateTiles(n)}static partialShanten(t){const n=new pe(t,!0);return Array(13-n.hands.length).fill(void 0).map(()=>n.inc([new w(m.BACK,0)])),new me(n).calc()}}const ni=()=>{const e=new Set;return{on(t){e.add(t)},off(t){e.delete(t)},offAll(){e.clear()},emit(t){e.forEach(n=>n(t))}}};function vs(e){var s;const t=["RON","DAI_KAN","PON","CHI"],n=e.map(o=>o.choices),r=Ss(n,t).map(o=>e[o]);return{events:r,type:ks(t,(s=r[0])==null?void 0:s.choices)}}function As(e){var s;const t=["TSUMO","REACH","AN_KAN","SHO_KAN","DRAWN_GAME_BY_NINE_TILES","DISCARD"],n=e.map(o=>o.choices),r=Ss(n,t).map(o=>e[o]);return{events:r,type:ks(t,(s=r[0])==null?void 0:s.choices)}}function Ss(e,t){let n=[],i=Number.POSITIVE_INFINITY;for(let r=0;r<e.length;r++){const s=e[r];if(Eu(s,t)){const o=Cu(t,s);o<i?(i=o,n=[r]):o===i&&n.push(r)}}return n}function Eu(e,t){return t.some(n=>!!e[n])}function Cu(e,t){for(let n=0;n<e.length;n++){const i=e[n];if(t[i])return n}return Number.POSITIVE_INFINITY}function ks(e,t){if(t==null)return!1;for(const n of e)if(t[n])return n;return!1}const Oe=()=>{const e=ni(),t=ni(),n={emit:e.emit,on:r=>t.on(r)},i={emit:t.emit,on:r=>e.on(r)};return[n,i]},Ts=()=>{const e=ni();return{emit:i=>{e.emit(i)},on:i=>{e.on(i)}}};class Pe{constructor(t){x(this,"reachValue",1e3);x(this,"m");this.m=t}get summary(){return structuredClone(this.m)}reach(t){this.m[t]-=this.reachValue}restoreReachStick(t){this.m[t]+=this.reachValue}update(t,n){for(let i in n){const r=n[i],s=t[r];this.m[i]+=s}}}class je{constructor(t,n){x(this,"pToW",{});x(this,"wToP",q(""));x(this,"round");x(this,"sticks");this.round=(n==null?void 0:n.round)??"1w1",this.sticks=(n==null?void 0:n.sticks)??{reach:0,dead:0},this.pToW=t;for(let i in this.pToW)this.wToP[this.pToW[i]]=i}update(){for(let t in this.pToW){const n=Et(this.pToW[t]);this.pToW[t]=n,this.wToP[n]=t}}incrementDeadStick(){this.sticks.dead++}incrementReachStick(){this.sticks.reach++}nextRound(){const t=Ee(this.round);this.round=t,this.update()}decrementReachStick(){this.sticks.reach--,R(this.sticks.reach>=0)}resetDeadStick(){this.sticks.dead=0}resetReachStick(){this.sticks.reach=0}is(t){return this.round==t}wind(t){return this.pToW[t]}playerID(t){return this.wToP[t]}get playerMap(){return structuredClone(this.pToW)}}const Ee=e=>{let t=e.substring(0,2),n=Number(e.substring(2,3));return n==4?(n=1,t=Et(t)):n++,`${t}${n}`},Nu=e=>Ee(Ee(Ee(e))),Et=e=>{let t=Number(e.toString()[0]);return t==4?t=1:t++,`${t}w`},Mu=e=>Et(Et(Et(e)));function Hi(e){for(let t=e.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}class Os{constructor(t=!1){x(this,"c",{[m.M]:[1,4,4,4,4,4,4,4,4,4],[m.S]:[1,4,4,4,4,4,4,4,4,4],[m.P]:[1,4,4,4,4,4,4,4,4,4],[m.Z]:[0,4,4,4,4,4,4,4]});x(this,"safeMap",q({},!0));this.disable=t}get(t){return t.t==m.BACK?0:nt(t)?this.c[t.t][5]:this.c[t.t][t.n]}dec(...t){if(!this.disable){for(let n of t)if(n.t!=m.BACK){if(this.get(n)<=0)throw new Error(`cannot decrease ${n.toString()} due to zero`);this.c[n.t][n.n]-=1,nt(n)&&(this.c[n.t][5]-=1)}}}addTileToSafeMap(t,n){this.disable||(this.safeMap[n][this.key(t.t,t.n)]=!0)}isSafeTile(t,n,i){return this.safeMap[i][this.key(t,n)]}key(t,n){return n==0&&(n=5),`${t}${n}`}reset(){this.c={[m.M]:[1,4,4,4,4,4,4,4,4,4],[m.S]:[1,4,4,4,4,4,4,4,4,4],[m.P]:[1,4,4,4,4,4,4,4,4,4],[m.Z]:[0,4,4,4,4,4,4,4]}}}class $i{constructor(){x(this,"m",[])}discard(t,n){this.m.push({w:n,t})}get lastTile(){const t=this.m.at(-1);return R(t!=null,`lastTile is null(${t}). river: ${JSON.stringify(this.m,null,2)}`),t}discards(t){return t==null?[...this.m]:this.m.filter(n=>n.w==t)}markCalled(){this.lastTile.callMarker=!0}cannotContinue(){const t=this.discards();if(t.length!=4)return!1;let n=t[0].t;if(n.isNum())return!1;for(let i=0;i<4;i++)if(!n.equals(t[i].t))return!1;return!0}}function Du(){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 Ru(){const e=Du();if(e.__xstate__)return e.__xstate__}const Bu=e=>{if(typeof window>"u")return;const t=Ru();t&&t.register(e)};class pr{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 n={value:t,next:null};if(this._current){this._last.next=n,this._last=n;return}this._current=n,this._last=n,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const Is=".",Hu="",Es="",$u="#",Pu="*",Cs="xstate.init",ii="xstate.stop";function ju(e,t){return{type:`xstate.after.${e}.${t}`}}function ri(e,t){return{type:`xstate.done.state.${e}`,output:t}}function Lu(e,t){return{type:`xstate.done.actor.${e}`,output:t,actorId:e}}function Wu(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function Ns(e){return{type:Cs,input:e}}function wt(e){setTimeout(()=>{throw e})}const zu=typeof Symbol=="function"&&Symbol.observable||"@@observable";function Ms(e,t){const n=mr(e),i=mr(t);return typeof i=="string"?typeof n=="string"?i===n:!1:typeof n=="string"?n in i:Object.keys(n).every(r=>r in i?Ms(n[r],i[r]):!1)}function Pi(e){if(Rs(e))return e;let t=[],n="";for(let i=0;i<e.length;i++){switch(e.charCodeAt(i)){case 92:n+=e[i+1],i++;continue;case 46:t.push(n),n="";continue}n+=e[i]}return t.push(n),t}function mr(e){if(xh(e))return e.value;if(typeof e!="string")return e;const t=Pi(e);return Fu(t)}function Fu(e){if(e.length===1)return e[0];const t={};let n=t;for(let i=0;i<e.length-1;i++)if(i===e.length-2)n[e[i]]=e[i+1];else{const r=n;n={},r[e[i]]=n}return t}function gr(e,t){const n={},i=Object.keys(e);for(let r=0;r<i.length;r++){const s=i[r];n[s]=t(e[s],s,e,r)}return n}function Ds(e){return Rs(e)?e:[e]}function Tt(e){return e===void 0?[]:Ds(e)}function si(e,t,n,i){return typeof e=="function"?e({context:t,event:n,self:i}):e}function Rs(e){return Array.isArray(e)}function Ku(e){return e.type.startsWith("xstate.error.actor")}function ee(e){return Ds(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function Bs(e){if(!(e===void 0||e===Hu))return Tt(e)}function oi(e,t,n){var s,o,a;const i=typeof e=="object",r=i?e:void 0;return{next:(s=i?e.next:e)==null?void 0:s.bind(r),error:(o=i?e.error:t)==null?void 0:o.bind(r),complete:(a=i?e.complete:n)==null?void 0:a.bind(r)}}function yr(e,t){return`${t}.${e}`}function ji(e,t){const n=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!n)return e.implementations.actors[t];const[,i,r]=n,o=e.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[i]:o).src}function wr(e,t){return`${e.sessionId}.${t}`}let Uu=0;function Yu(e,t){const n=new Map,i=new Map,r=new WeakMap,s=new Set,o={},{clock:a,logger:c}=t,l={schedule:(f,p,d,g,y=Math.random().toString(36).slice(2))=>{const A={source:f,target:p,event:d,delay:g,id:y,startedAt:Date.now()},_=wr(f,y);h._snapshot._scheduledEvents[_]=A;const $=a.setTimeout(()=>{delete o[_],delete h._snapshot._scheduledEvents[_],h._relay(f,p,d)},g);o[_]=$},cancel:(f,p)=>{const d=wr(f,p),g=o[d];delete o[d],delete h._snapshot._scheduledEvents[d],g!==void 0&&a.clearTimeout(g)},cancelAll:f=>{for(const p in h._snapshot._scheduledEvents){const d=h._snapshot._scheduledEvents[p];d.source===f&&l.cancel(f,d.id)}}},u=f=>{if(!s.size)return;const p={...f,rootId:e.sessionId};s.forEach(d=>{var g;return(g=d.next)==null?void 0:g.call(d,p)})},h={_snapshot:{_scheduledEvents:((t==null?void 0:t.snapshot)&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${Uu++}`,_register:(f,p)=>(n.set(f,p),f),_unregister:f=>{n.delete(f.sessionId);const p=r.get(f);p!==void 0&&(i.delete(p),r.delete(f))},get:f=>i.get(f),_set:(f,p)=>{const d=i.get(f);if(d&&d!==p)throw new Error(`Actor with system ID '${f}' already exists.`);i.set(f,p),r.set(p,f)},inspect:f=>{const p=oi(f);return s.add(p),{unsubscribe(){s.delete(p)}}},_sendInspectionEvent:u,_relay:(f,p,d)=>{h._sendInspectionEvent({type:"@xstate.event",sourceRef:f,actorRef:p,event:d}),p._send(d)},scheduler:l,getSnapshot:()=>({_scheduledEvents:{...h._snapshot._scheduledEvents}}),start:()=>{const f=h._snapshot._scheduledEvents;h._snapshot._scheduledEvents={};for(const p in f){const{source:d,target:g,event:y,delay:A,id:_}=f[p];l.schedule(d,g,y,A,_)}},_clock:a,_logger:c};return h}const Li=1;let Y=function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e}({});const qu={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class Gu{constructor(t,n){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new pr(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=Y.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 i={...qu,...n},{clock:r,logger:s,parent:o,syncSnapshot:a,id:c,systemId:l,inspect:u}=i;this.system=o?o.system:Yu(this,{clock:r,logger:s}),u&&!o&&this.system.inspect(oi(u)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=(n==null?void 0:n.logger)??this.system._logger,this.clock=(n==null?void 0:n.clock)??this.system._clock,this._parent=o,this._syncSnapshot=a,this.options=i,this.src=i.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 f=this.eventListeners.get(h.type),p=this.eventListeners.get("*");if(!f&&!p)return;const d=new Set([...f?f.values():[],...p?p.values():[]]);for(const g of Array.from(d))g(h)}},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((n==null?void 0:n.snapshot)??(n==null?void 0:n.state)),l&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){var n;try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,(n=this.options)==null?void 0:n.input)}catch(i){this._snapshot={status:"error",output:void 0,error:i}}}update(t,n){var r,s;this._snapshot=t;let i;for(;i=this._deferred.shift();)try{i()}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){wt(a)}break;case"done":for(const o of this.observers)try{(s=o.next)==null||s.call(o,t)}catch(a){wt(a)}this._stopProcedure(),this._complete(),this._doneEvent=Lu(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:n,snapshot:t})}subscribe(t,n,i){var s;const r=oi(t,n,i);if(this._processingStatus!==Y.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(s=r.complete)==null||s.call(r)}catch(o){wt(o)}break;case"error":{const o=this._snapshot.error;if(!r.error)wt(o);else try{r.error(o)}catch(a){wt(a)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(t,n){let i=this.eventListeners.get(t);i||(i=new Set,this.eventListeners.set(t,i));const r=n.bind(void 0);return i.add(r),{unsubscribe:()=>{i.delete(r)}}}start(){if(this._processingStatus===Y.Running)return this;this._syncSnapshot&&this.subscribe({next:i=>{i.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:i})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=Y.Running;const t=Ns(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(i){return this._snapshot={...this._snapshot,status:"error",error:i},this._error(i),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let n,i;try{n=this.logic.transition(this._snapshot,t,this._actorScope)}catch(r){i={err:r}}if(i){const{err:r}=i;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(n,t),t.type===ii&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===Y.Stopped?this:(this.mailbox.clear(),this._processingStatus===Y.NotStarted?(this._processingStatus=Y.Stopped,this):(this.mailbox.enqueue({type:ii}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var t;for(const n of this.observers)try{(t=n.complete)==null||t.call(n)}catch(i){wt(i)}this.observers.clear()}_reportError(t){if(!this.observers.size){this._parent||wt(t);return}let n=!1;for(const i of this.observers){const r=i.error;n||(n=!r);try{r==null||r(t)}catch(s){wt(s)}}this.observers.clear(),n&&wt(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,Wu(this.id,t))}_stopProcedure(){return this._processingStatus!==Y.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new pr(this._process.bind(this)),this._processingStatus=Y.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==Y.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:Bu)(this)}toJSON(){return{xstate$$type:Li,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[zu](){return this}getSnapshot(){return this._snapshot}}function ge(e,...[t]){return new Gu(e,t)}function Zu(e,t,n,i,{sendId:r}){const s=typeof r=="function"?r(n,i):r;return[t,s]}function Xu(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t)})}function Ju(e){function t(n,i){}return t.type="xstate.cancel",t.sendId=e,t.resolve=Zu,t.execute=Xu,t}function Vu(e,t,n,i,{id:r,systemId:s,src:o,input:a,syncSnapshot:c}){const l=typeof o=="string"?ji(t.machine,o):o,u=typeof r=="function"?r(n):r;let h;return l&&(h=ge(l,{id:u,src:o,parent:e.self,syncSnapshot:c,systemId:s,input:typeof a=="function"?a({context:t.context,event:n.event,self:e.self}):a})),[qt(t,{children:{...t.children,[u]:h}}),{id:r,actorRef:h}]}function Qu(e,{id:t,actorRef:n}){n&&e.defer(()=>{n._processingStatus!==Y.Stopped&&n.start()})}function th(...[e,{id:t,systemId:n,input:i,syncSnapshot:r=!1}={}]){function s(o,a){}return s.type="snapshot.spawnChild",s.id=t,s.systemId=n,s.src=e,s.input=i,s.syncSnapshot=r,s.resolve=Vu,s.execute=Qu,s}function eh(e,t,n,i,{actorRef:r}){const s=typeof r=="function"?r(n,i):r,o=typeof s=="string"?t.children[s]:s;let a=t.children;return o&&(a={...a},delete a[o.id]),[qt(t,{children:a}),o]}function nh(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==Y.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function Hs(e){function t(n,i){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=eh,t.execute=nh,t}function Wi(e,t,n,i){const{machine:r}=i,s=typeof e=="function",o=s?e:r.implementations.guards[typeof e=="string"?e:e.type];if(!s&&!o)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof o!="function")return Wi(o,t,n,i);const a={context:t,event:n},c=s||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:n}):e.params:void 0;return"check"in o?o.check(i,a,o):o(a,c)}const zi=e=>e.type==="atomic"||e.type==="final";function ye(e){return Object.values(e.states).filter(t=>t.type!=="history")}function Ze(e,t){const n=[];if(t===e)return n;let i=e.parent;for(;i&&i!==t;)n.push(i),i=i.parent;return n}function dn(e){const t=new Set(e),n=Ps(t);for(const i of t)if(i.type==="compound"&&(!n.get(i)||!n.get(i).length))_r(i).forEach(r=>t.add(r));else if(i.type==="parallel"){for(const r of ye(i))if(r.type!=="history"&&!t.has(r)){const s=_r(r);for(const o of s)t.add(o)}}for(const i of t){let r=i.parent;for(;r;)t.add(r),r=r.parent}return t}function $s(e,t){const n=t.get(e);if(!n)return{};if(e.type==="compound"){const r=n[0];if(r){if(zi(r))return r.key}else return{}}const i={};for(const r of n)i[r.key]=$s(r,t);return i}function Ps(e){const t=new Map;for(const n of e)t.has(n)||t.set(n,[]),n.parent&&(t.has(n.parent)||t.set(n.parent,[]),t.get(n.parent).push(n));return t}function js(e,t){const n=dn(t);return $s(e,Ps(n))}function Fi(e,t){return t.type==="compound"?ye(t).some(n=>n.type==="final"&&e.has(n)):t.type==="parallel"?ye(t).every(n=>Fi(e,n)):t.type==="final"}const vn=e=>e[0]===$u;function ih(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(i=>{if(i===Pu)return!0;if(!i.endsWith(".*"))return!1;const r=i.split("."),s=t.split(".");for(let o=0;o<r.length;o++){const a=r[o],c=s[o];if(a==="*")return o===r.length-1;if(a!==c)return!1}return!0}).sort((i,r)=>r.length-i.length).flatMap(i=>e.transitions.get(i))}function rh(e){const t=e.config.after;if(!t)return[];const n=(r,s)=>{const o=ju(r,e.id),a=o.type;return e.entry.push(Ch(o,{id:a,delay:r})),e.exit.push(Ju(a)),a};return Object.keys(t).flatMap((r,s)=>{const o=t[r],a=typeof o=="string"?{target:o}:o,c=Number.isNaN(+r)?r:+r,l=n(c);return Tt(a).map(u=>({...u,event:l,delay:c}))}).map(r=>{const{delay:s}=r;return{...jt(e,r.event,r),delay:s}})}function jt(e,t,n){const i=Bs(n.target),r=n.reenter??!1,s=ah(e,i),o={...n,actions:Tt(n.actions),guard:n.guard,target:s,source:e,reenter:r,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:s?s.map(a=>`#${a.id}`):void 0})};return o}function sh(e){const t=new Map;if(e.config.on)for(const n of Object.keys(e.config.on)){if(n===Es)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const i=e.config.on[n];t.set(n,ee(i).map(r=>jt(e,n,r)))}if(e.config.onDone){const n=`xstate.done.state.${e.id}`;t.set(n,ee(e.config.onDone).map(i=>jt(e,n,i)))}for(const n of e.invoke){if(n.onDone){const i=`xstate.done.actor.${n.id}`;t.set(i,ee(n.onDone).map(r=>jt(e,i,r)))}if(n.onError){const i=`xstate.error.actor.${n.id}`;t.set(i,ee(n.onError).map(r=>jt(e,i,r)))}if(n.onSnapshot){const i=`xstate.snapshot.${n.id}`;t.set(i,ee(n.onSnapshot).map(r=>jt(e,i,r)))}}for(const n of e.after){let i=t.get(n.eventType);i||(i=[],t.set(n.eventType,i)),i.push(n)}return t}function oh(e,t){const n=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!n&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const i={source:e,actions:!t||typeof t=="string"?[]:Tt(t.actions),eventType:null,reenter:!1,target:n?[n]:[],toJSON:()=>({...i,source:`#${e.id}`,target:n?[`#${n.id}`]:[]})};return i}function ah(e,t){if(t!==void 0)return t.map(n=>{if(typeof n!="string")return n;if(vn(n))return e.machine.getStateNodeById(n);const i=n[0]===Is;if(i&&!e.parent)return pn(e,n.slice(1));const r=i?e.key+n:n;if(e.parent)try{return pn(e.parent,r)}catch(s){throw new Error(`Invalid transition definition for state node '${e.id}':
23
+ ${s.message}`)}else throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`)})}function Ls(e){const t=Bs(e.config.target);return t?{target:t.map(n=>typeof n=="string"?pn(e.parent,n):n)}:e.parent.initial}function Lt(e){return e.type==="history"}function _r(e){const t=Ws(e);for(const n of t)for(const i of Ze(n,e))t.add(i);return t}function Ws(e){const t=new Set;function n(i){if(!t.has(i)){if(t.add(i),i.type==="compound")n(i.initial.target[0]);else if(i.type==="parallel")for(const r of ye(i))n(r)}}return n(e),t}function we(e,t){if(vn(t))return e.machine.getStateNodeById(t);if(!e.states)throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);const n=e.states[t];if(!n)throw new Error(`Child state '${t}' does not exist on '${e.id}'`);return n}function pn(e,t){if(typeof t=="string"&&vn(t))try{return e.machine.getStateNodeById(t)}catch{}const n=Pi(t).slice();let i=e;for(;n.length;){const r=n.shift();if(!r.length)break;i=we(i,r)}return i}function mn(e,t){if(typeof t=="string"){const r=e.states[t];if(!r)throw new Error(`State '${t}' does not exist on '${e.id}'`);return[e,r]}const n=Object.keys(t),i=n.map(r=>we(e,r)).filter(Boolean);return[e.machine.root,e].concat(i,n.reduce((r,s)=>{const o=we(e,s);if(!o)return r;const a=mn(o,t[s]);return r.concat(a)},[]))}function ch(e,t,n,i){const s=we(e,t).next(n,i);return!s||!s.length?e.next(n,i):s}function lh(e,t,n,i){const r=Object.keys(t),s=we(e,r[0]),o=Ki(s,t[r[0]],n,i);return!o||!o.length?e.next(n,i):o}function uh(e,t,n,i){const r=[];for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const a=we(e,s),c=Ki(a,o,n,i);c&&r.push(...c)}return r.length?r:e.next(n,i)}function Ki(e,t,n,i){return typeof t=="string"?ch(e,t,n,i):Object.keys(t).length===1?lh(e,t,n,i):uh(e,t,n,i)}function hh(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function Rt(e,t){let n=e;for(;n.parent&&n.parent!==t;)n=n.parent;return n.parent===t}function fh(e,t){const n=new Set(e),i=new Set(t);for(const r of n)if(i.has(r))return!0;for(const r of i)if(n.has(r))return!0;return!1}function zs(e,t,n){const i=new Set;for(const r of e){let s=!1;const o=new Set;for(const a of i)if(fh(ai([r],t,n),ai([a],t,n)))if(Rt(r.source,a.source))o.add(a);else{s=!0;break}if(!s){for(const a of o)i.delete(a);i.add(r)}}return Array.from(i)}function dh(e){const[t,...n]=e;for(const i of Ze(t,void 0))if(n.every(r=>Rt(r,i)))return i}function Ui(e,t){if(!e.target)return[];const n=new Set;for(const i of e.target)if(Lt(i))if(t[i.id])for(const r of t[i.id])n.add(r);else for(const r of Ui(Ls(i),t))n.add(r);else n.add(i);return[...n]}function Fs(e,t){const n=Ui(e,t);if(!n)return;if(!e.reenter&&n.every(r=>r===e.source||Rt(r,e.source)))return e.source;const i=dh(n.concat(e.source));if(i)return i;if(!e.reenter)return e.source.machine.root}function ai(e,t,n){var r;const i=new Set;for(const s of e)if((r=s.target)!=null&&r.length){const o=Fs(s,n);s.reenter&&s.source===o&&i.add(o);for(const a of t)Rt(a,o)&&i.add(a)}return[...i]}function ph(e,t){if(e.length!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function ci(e,t,n,i,r,s){if(!e.length)return t;const o=new Set(t._nodes);let a=t.historyValue;const c=zs(e,o,a);let l=t;r||([l,a]=wh(l,i,n,c,o,a,s)),l=_e(l,i,n,c.flatMap(h=>h.actions),s),l=gh(l,i,n,c,o,s,a,r);const u=[...o];l.status==="done"&&(l=_e(l,i,n,u.sort((h,f)=>f.order-h.order).flatMap(h=>h.exit),s));try{return a===t.historyValue&&ph(t._nodes,o)?l:qt(l,{_nodes:u,historyValue:a})}catch(h){throw h}}function mh(e,t,n,i,r){if(i.output===void 0)return;const s=ri(r.id,r.output!==void 0&&r.parent?si(r.output,e.context,t,n.self):void 0);return si(i.output,e.context,s,n.self)}function gh(e,t,n,i,r,s,o,a){let c=e;const l=new Set,u=new Set;yh(i,o,u,l),a&&u.add(e.machine.root);const h=new Set;for(const f of[...l].sort((p,d)=>p.order-d.order)){r.add(f);const p=[];p.push(...f.entry);for(const d of f.invoke)p.push(th(d.src,{...d,syncSnapshot:!!d.onSnapshot}));if(u.has(f)){const d=f.initial.actions;p.push(...d)}if(c=_e(c,t,n,p,s,f.invoke.map(d=>d.id)),f.type==="final"){const d=f.parent;let g=(d==null?void 0:d.type)==="parallel"?d:d==null?void 0:d.parent,y=g||f;for((d==null?void 0:d.type)==="compound"&&s.push(ri(d.id,f.output!==void 0?si(f.output,c.context,t,n.self):void 0));(g==null?void 0:g.type)==="parallel"&&!h.has(g)&&Fi(r,g);)h.add(g),s.push(ri(g.id)),y=g,g=g.parent;if(g)continue;c=qt(c,{status:"done",output:mh(c,t,n,c.machine.root,y)})}}return c}function yh(e,t,n,i){for(const r of e){const s=Fs(r,t);for(const a of r.target||[])!Lt(a)&&(r.source!==a||r.source!==s||r.reenter)&&(i.add(a),n.add(a)),ae(a,t,n,i);const o=Ui(r,t);for(const a of o){const c=Ze(a,s);(s==null?void 0:s.type)==="parallel"&&c.push(s),Ks(i,t,n,c,!r.source.parent&&r.reenter?void 0:s)}}}function ae(e,t,n,i){var r;if(Lt(e))if(t[e.id]){const s=t[e.id];for(const o of s)i.add(o),ae(o,t,n,i);for(const o of s)Hn(o,e.parent,i,t,n)}else{const s=Ls(e);for(const o of s.target)i.add(o),s===((r=e.parent)==null?void 0:r.initial)&&n.add(e.parent),ae(o,t,n,i);for(const o of s.target)Hn(o,e.parent,i,t,n)}else if(e.type==="compound"){const[s]=e.initial.target;Lt(s)||(i.add(s),n.add(s)),ae(s,t,n,i),Hn(s,e,i,t,n)}else if(e.type==="parallel")for(const s of ye(e).filter(o=>!Lt(o)))[...i].some(o=>Rt(o,s))||(Lt(s)||(i.add(s),n.add(s)),ae(s,t,n,i))}function Ks(e,t,n,i,r){for(const s of i)if((!r||Rt(s,r))&&e.add(s),s.type==="parallel")for(const o of ye(s).filter(a=>!Lt(a)))[...e].some(a=>Rt(a,o))||(e.add(o),ae(o,t,n,e))}function Hn(e,t,n,i,r){Ks(n,i,r,Ze(e,t))}function wh(e,t,n,i,r,s,o){let a=e;const c=ai(i,r,s);c.sort((u,h)=>h.order-u.order);let l;for(const u of c)for(const h of hh(u)){let f;h.history==="deep"?f=p=>zi(p)&&Rt(p,u):f=p=>p.parent===u,l??(l={...s}),l[h.id]=Array.from(r).filter(f)}for(const u of c)a=_e(a,t,n,[...u.exit,...u.invoke.map(h=>Hs(h.id))],o),r.delete(u);return[a,l||s]}let br=!1;function Us(e,t,n,i,r,s){const{machine:o}=e;let a=e;for(const c of i){let p=function(){n.system._sendInspectionEvent({type:"@xstate.action",actorRef:n.self,action:{type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",params:f}});try{br=u,u(h,f)}finally{br=!1}};const l=typeof c=="function",u=l?c:o.implementations.actions[typeof c=="string"?c:c.type];if(!u)continue;const h={context:a.context,event:t,self:n.self,system:n.system},f=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(!("resolve"in u)){n.self._processingStatus===Y.Running?p():n.defer(()=>{p()});continue}const d=u,[g,y,A]=d.resolve(n,a,h,f,u,r);a=g,"retryResolve"in d&&(s==null||s.push([d,y])),"execute"in d&&(n.self._processingStatus===Y.Running?d.execute(n,y):n.defer(d.execute.bind(null,n,y))),A&&(a=Us(a,t,n,A,r,s))}return a}function _e(e,t,n,i,r,s){const o=s?[]:void 0,a=Us(e,t,n,i,{internalQueue:r,deferredActorIds:s},o);return o==null||o.forEach(([c,l])=>{c.retryResolve(n,a,l)}),a}function $n(e,t,n,i=[]){let r=e;const s=[];function o(l,u,h){n.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:n.self,event:u,snapshot:l,_transitions:h}),s.push(l)}if(t.type===ii)return r=qt(xr(r,t,n),{status:"stopped"}),o(r,t,[]),{snapshot:r,microstates:s};let a=t;if(a.type!==Cs){const l=a,u=Ku(l),h=vr(l,r);if(u&&!h.length)return r=qt(e,{status:"error",error:l.error}),o(r,l,[]),{snapshot:r,microstates:s};r=ci(h,e,n,a,!1,i),o(r,l,h)}let c=!0;for(;r.status==="active";){let l=c?_h(r,a):[];const u=l.length?r:void 0;if(!l.length){if(!i.length)break;a=i.shift(),l=vr(a,r)}r=ci(l,r,n,a,!1,i),c=r!==u,o(r,a,l)}return r.status!=="active"&&xr(r,a,n),{snapshot:r,microstates:s}}function xr(e,t,n){return _e(e,t,n,Object.values(e.children).map(i=>Hs(i)),[])}function vr(e,t){return t.machine.getTransitionData(t,e)}function _h(e,t){const n=new Set,i=e._nodes.filter(zi);for(const r of i)t:for(const s of[r].concat(Ze(r,void 0)))if(s.always){for(const o of s.always)if(o.guard===void 0||Wi(o.guard,e.context,t,e)){n.add(o);break t}}return zs(Array.from(n),new Set(e._nodes),e.historyValue)}function bh(e,t){const n=dn(mn(e,t));return js(e,[...n])}function xh(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const vh=function(t){return Ms(t,this.value)},Ah=function(t){return this.tags.has(t)},Sh=function(t){const n=this.machine.getTransitionData(this,t);return!!(n!=null&&n.length)&&n.some(i=>i.target!==void 0||i.actions.length)},kh=function(){const{_nodes:t,tags:n,machine:i,getMeta:r,toJSON:s,can:o,hasTag:a,matches:c,...l}=this;return{...l,tags:Array.from(n)}},Th=function(){return this._nodes.reduce((t,n)=>(n.meta!==void 0&&(t[n.id]=n.meta),t),{})};function en(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:js(t.root,e._nodes),tags:new Set(e._nodes.flatMap(n=>n.tags)),children:e.children,historyValue:e.historyValue||{},matches:vh,hasTag:Ah,can:Sh,getMeta:Th,toJSON:kh}}function qt(e,t={}){return en({...e,...t},e.machine)}function Oh(e,t){const{_nodes:n,tags:i,machine:r,children:s,context:o,can:a,hasTag:c,matches:l,getMeta:u,toJSON:h,...f}=e,p={};for(const g in s){const y=s[g];p[g]={snapshot:y.getPersistedSnapshot(t),src:y.src,systemId:y._systemId,syncSnapshot:y._syncSnapshot}}return{...f,context:Ys(o),children:p}}function Ys(e){let t;for(const n in e){const i=e[n];if(i&&typeof i=="object")if("sessionId"in i&&"send"in i&&"ref"in i)t??(t=Array.isArray(e)?e.slice():{...e}),t[n]={xstate$$type:Li,id:i.id};else{const r=Ys(i);r!==i&&(t??(t=Array.isArray(e)?e.slice():{...e}),t[n]=r)}}return t??e}function Ih(e,t,n,i,{event:r,id:s,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(n,i):r;let u;if(typeof o=="string"){const h=c&&c[o];u=typeof h=="function"?h(n,i):h}else u=typeof o=="function"?o(n,i):o;return typeof u!="number"&&a.push(l),[t,{event:l,id:s,delay:u}]}function Eh(e,t){const{event:n,delay:i,id:r}=t;if(typeof i=="number"){e.defer(()=>{const s=e.self;e.system.scheduler.schedule(s,s,n,i,r)});return}}function Ch(e,t){function n(i,r){}return n.type="xstate.raise",n.event=e,n.id=t==null?void 0:t.id,n.delay=t==null?void 0:t.delay,n.resolve=Ih,n.execute=Eh,n}function Nh(e,{machine:t,context:n},i,r){const s=(o,a={})=>{const{systemId:c,input:l}=a;if(typeof o=="string"){const u=ji(t,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const h=ge(u,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:typeof l=="function"?l({context:n,event:i,self:e.self}):l,src:o,systemId:c});return r[h.id]=h,h}else return ge(o,{id:a.id,parent:e.self,syncSnapshot:a.syncSnapshot,input:a.input,src:o,systemId:c})};return(o,a)=>{const c=s(o,a);return r[c.id]=c,e.defer(()=>{c._processingStatus!==Y.Stopped&&c.start()}),c}}function Mh(e,t,n,i,{assignment:r}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const s={},o={context:t.context,event:n.event,spawn:Nh(e,t,n.event,s),self:e.self,system:e.system};let a={};if(typeof r=="function")a=r(o,i);else for(const l of Object.keys(r)){const u=r[l];a[l]=typeof u=="function"?u(o,i):u}const c=Object.assign({},t.context,a);return[qt(t,{context:c,children:Object.keys(s).length?{...t.children,...s}:t.children})]}function Dh(e){function t(n,i){}return t.type="xstate.assign",t.assignment=e,t.resolve=Mh,t}const Ar=new WeakMap;function te(e,t,n){let i=Ar.get(e);return i?t in i||(i[t]=n()):(i={[t]:n()},Ar.set(e,i)),i[t]}const Rh={},Se=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class Yi{constructor(t,n){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=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Is),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?gr(this.config.states,(i,r)=>new Yi(i,{_parent:this,_key:r,_machine:this.machine})):Rh,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=Tt(this.config.entry).slice(),this.exit=Tt(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=Tt(t.tags).slice()}_initialize(){this.transitions=sh(this),this.config.always&&(this.always=ee(this.config.always).map(t=>jt(this,Es,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(Se),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(Se),eventType:null})}:void 0,history:this.history,states:gr(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(Se)})),entry:this.entry.map(Se),exit:this.exit.map(Se),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 te(this,"invoke",()=>Tt(this.config.invoke).map((t,n)=>{const{src:i,systemId:r}=t,s=t.id??yr(this.id,n),o=typeof i=="string"?i:`xstate.invoke.${yr(this.id,n)}`;return{...t,src:o,id:s,systemId:r,toJSON(){const{onDone:a,onError:c,...l}=t;return{...l,type:"xstate.invoke",src:o,id:s}}}}))}get on(){return te(this,"on",()=>[...this.transitions].flatMap(([n,i])=>i.map(r=>[n,r])).reduce((n,[i,r])=>(n[i]=n[i]||[],n[i].push(r),n),{}))}get after(){return te(this,"delayedTransitions",()=>rh(this))}get initial(){return te(this,"initial",()=>oh(this,this.config.initial))}next(t,n){const i=n.type,r=[];let s;const o=te(this,`candidates-${i}`,()=>ih(this,i));for(const a of o){const{guard:c}=a,l=t.context;let u=!1;try{u=!c||Wi(c,l,n,t)}catch(h){const f=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${f?`'${f}' `:""}in transition for event '${i}' in state node '${this.id}':
24
+ ${h.message}`)}if(u){r.push(...a.actions),s=a;break}}return s?[s]:void 0}get events(){return te(this,"events",()=>{const{states:t}=this,n=new Set(this.ownEvents);if(t)for(const i of Object.keys(t)){const r=t[i];if(r.states)for(const s of r.events)n.add(`${s}`)}return Array.from(n)})}get ownEvents(){const t=new Set([...this.transitions.keys()].filter(n=>this.transitions.get(n).some(i=>!(!i.target&&!i.actions.length&&!i.reenter))));return Array.from(t)}}const Bh="#";class qi{constructor(t,n){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:(n==null?void 0:n.actors)??{},actions:(n==null?void 0:n.actions)??{},delays:(n==null?void 0:n.delays)??{},guards:(n==null?void 0:n.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 Yi(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:n,guards:i,actors:r,delays:s}=this.implementations;return new qi(this.config,{actions:{...n,...t.actions},guards:{...i,...t.guards},actors:{...r,...t.actors},delays:{...s,...t.delays}})}resolveState(t){const n=bh(this.root,t.value),i=dn(mn(this.root,n));return en({_nodes:[...i],context:t.context||{},children:{},status:Fi(i,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,n,i){return $n(t,n,i).snapshot}microstep(t,n,i){return $n(t,n,i).microstates}getTransitionData(t,n){return Ki(this.root,t.value,t,n)||[]}getPreInitialState(t,n,i){const{context:r}=this.config,s=en({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?_e(s,n,t,[Dh(({spawn:a,event:c,self:l})=>r({spawn:a,input:c.input,self:l}))],i):s}getInitialSnapshot(t,n){const i=Ns(n),r=[],s=this.getPreInitialState(t,i,r),o=ci([{target:[...Ws(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],s,t,i,!0,r),{snapshot:a}=$n(o,i,t,r);return a}start(t){Object.values(t.children).forEach(n=>{n.getSnapshot().status==="active"&&n.start()})}getStateNodeById(t){const n=Pi(t),i=n.slice(1),r=vn(n[0])?n[0].slice(Bh.length):n[0],s=this.idMap.get(r);if(!s)throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return pn(s,i)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,n){return Oh(t,n)}restoreSnapshot(t,n){const i={},r=t.children;Object.keys(r).forEach(c=>{const l=r[c],u=l.snapshot,h=l.src,f=typeof h=="string"?ji(this,h):h;if(!f)return;const p=ge(f,{id:c,parent:n.self,syncSnapshot:l.syncSnapshot,snapshot:u,src:h,systemId:l.systemId});i[c]=p});const s=en({...t,children:i,_nodes:Array.from(dn(mn(this.root,t.value)))},this);let o=new Set;function a(c,l){if(!o.has(c)){o.add(c);for(let u in c){const h=c[u];if(h&&typeof h=="object"){if("xstate$$type"in h&&h.xstate$$type===Li){c[u]=l[h.id];continue}a(h,l)}}}}return a(s.context,i),s}}function Hh(e,t){return new qi(e,t)}const Qe=e=>e===!1?!1:e.map(t=>t.serialize()),$h=e=>e===!1?!1:e.serialize(),Ph=e=>e===!1?!1:e.map(t=>({tile:t.tile.toString(),candidates:t.candidates.map(n=>n.toString()),shanten:t.shanten})),li=e=>JSON.parse(JSON.stringify(e)),Pn=e=>e===!1?!1:li(e),ui=e=>Hh({id:"Untitled",initial:"distribute",context:{currentWind:"1w",oneShotMap:q(!1),missingMap:q(!1),controller:e,genEventID:qs()},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:`可能なアクションとその詳細を通知\\
25
+ DISCARD の場合は捨てられる牌の一覧`}}},waiting_user_event_after_drawn:{description:"ツモった1ユーザからのレスポンス待ち",on:{TSUMO:{target:"tsumo",guard:"canWin"},REACH:{target:"discarded",guard:"canReach",actions:{type:"notify_reach"},description:`入力に牌が必要\\
26
+ 立直直後のロンは立直棒が点数にならないので\\
27
+ 別途状態を保つ必要がある`},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_TILES:{target:"drawn_game"}}},discarded:{entry:{type:"notify_discard"},on:{NEXT:{target:"waiting_user_event_after_discarded",actions:{type:"notify_choice_after_discarded"},description:`可能なアクションとその詳細を通知\\
28
+ CHI/PON の場合は鳴ける組み合わせの一覧`}}},tsumo:{exit:[{type:"notify_tsumo"},{type:"notify_end"}],type:"final"},waiting_user_event_after_discarded:{description:`最大 4人から choice に対するレスポンスを待つ\\
29
+ ユーザからではなく、controller が優先順位を考慮して遷移させる必要がある\\
30
+ 通知する choice がない場合、controller が\\*で遷移させる`,on:{RON:{target:"roned",guard:"canWin"},PON:{target:"poned",guard:"canPon"},CHI:{target:"chied",guard:"canChi"},DAI_KAN:{target:"dai_kaned"},"*":{target:"wildcard_after_discarded"}}},roned:{exit:[{type:"notify_ron"},{type:"notify_end"}],type:"final"},poned:{on:{NEXT:{target:"waiting_discard_event",actions:{type:"notify_choice_after_called"}}},entry:[{type:"notify_call"},{type:"disable_none_shot"}]},chied:{on:{NEXT:{target:"waiting_discard_event",actions:{type:"notify_choice_after_called",params:{action:"chi"}}}},entry:[{type:"notify_call"},{type:"disable_one_shot"}]},wildcard_after_discarded:{exit:[],always:[{target:"drawn_game",guard:"cannotContinue"},{target:"drawn",actions:[{type:"updateNextWind"}]}]},waiting_discard_event:{description:"鳴いたユーザからの DISCARD イベントを待つ",on:{DISCARD:{target:"discarded"}}},dai_kaned:{on:{NEXT:{target:"waiting_user_event_after_drawn",actions:[{type:"notify_draw",params:{action:"kan"}},{type:"notify_choice_after_drawn",params:{replacementWin:!0}}]}},entry:[{type:"notify_call"},{type:"disable_one_shot"}]},an_sho_kaned:{on:{NEXT:{target:"waiting_chankan_event"}},entry:[{type:"notify_call"},{type:"disable_one_shot"},{type:"notify_new_dora_if_needed"},{type:"notify_choice_for_chankan"}]},waiting_chankan_event:{description:"チャンカンを待つ",exit:[{type:"notify_draw",params:{action:"kan"}},{type:"notify_choice_after_drawn",params:{replacementWin:!0}}],on:{RON:{target:"roned",guard:"canWin"},"*":{target:"waiting_user_event_after_drawn"}}},drawn_game:{exit:{type:"notify_end",params:{}},type:"final"}},types:{events:{},context:{}}},{actions:{updateNextWind:({context:t,event:n})=>{const i=t.currentWind;t.currentWind=Et(i)},notify_distribution:({context:t,event:n})=>{const i=t.genEventID(),r=t.controller.initialHands();for(let s of Object.values(T)){const o=q("_____________");o[s]=r[s].toString();const a={id:i,type:"DISTRIBUTE",hands:o,wind:s,doraMarker:t.controller.wall.doraMarkers[0].toString(),sticks:t.controller.placeManager.sticks,round:t.controller.placeManager.round,players:t.controller.playerIDs,places:t.controller.placeManager.playerMap,scores:t.controller.scoreManager.summary};t.controller.emit(a)}t.controller.next()},notify_choice_after_drawn:({context:t,event:n},i)=>{const r=t.currentWind,s=t.controller.hand(r).drawn,o=t.genEventID(),a={id:o,type:"CHOICE_AFTER_DRAWN",wind:r,drawerInfo:{wind:r,tile:s.toString()},choices:{TSUMO:Pn(t.controller.doWin(r,s,{oneShot:t.oneShotMap[r],replacementWin:i==null?void 0:i.replacementWin})),REACH:Ph(t.controller.doReach(r)),AN_KAN:Qe(t.controller.doAnKan(r)),SHO_KAN:Qe(t.controller.doShoKan(r)),DISCARD:t.controller.doDiscard(r).map(c=>c.toString()),DRAWN_GAME_BY_NINE_TILES:t.controller.canDrawnGame(r)}};t.controller.emit(a),t.controller.pollReplies(o,[r])},notify_choice_after_discarded:({context:t,event:n})=>{const i=t.genEventID(),r=t.controller.river.lastTile,s=r.t.clone({add:v.HORIZONTAL});for(let o of Object.values(T)){const a={id:i,type:"CHOICE_AFTER_DISCARDED",wind:o,discarterInfo:{wind:r.w,tile:r.t.toString()},choices:{RON:Pn(t.controller.doWin(o,s,{whoDiscarded:r.w,oneShot:t.oneShotMap[o],missingRon:t.missingMap[o]})),PON:Qe(t.controller.doPon(o,r.w,s)),CHI:Qe(t.controller.doChi(o,r.w,s)),DAI_KAN:$h(t.controller.doDaiKan(o,r.w,s))}};a.choices.RON&&(t.missingMap[o]=!0),t.controller.emit(a)}t.controller.pollReplies(i,Object.values(T))},notify_choice_after_called:({context:t,event:n},i)=>{const r=t.genEventID(),s=t.currentWind;let o=t.controller.doDiscard(s);const a=t.controller.hand(t.currentWind).called.at(-1);(a instanceof ht||a instanceof dt)&&(o=t.controller.doDiscard(s,a));const c={id:r,type:"CHOICE_AFTER_CALLED",wind:s,choices:{DISCARD:o.map(l=>l.toString())}};t.controller.emit(c),t.controller.pollReplies(r,[s])},notify_choice_for_chankan:({context:t,event:n})=>{if(n.type!="SHO_KAN"&&n.type!="AN_KAN")throw new Error(`unexpected event ${n.type}`);const i=t.genEventID(),r=n.block.tiles[0].clone({remove:v.HORIZONTAL});for(let s of Object.values(T)){const o=t.controller.doWin(s,n.block.tiles[0].clone({remove:v.HORIZONTAL}),{whoDiscarded:n.iam,quadWin:!0,oneShot:t.oneShotMap[s],missingRon:t.missingMap[n.iam]}),a={id:i,type:"CHOICE_FOR_CHAN_KAN",wind:s,callerInfo:{wind:n.iam,tile:r.toString()},choices:{RON:n.type=="SHO_KAN"?Pn(o):!1}};a.choices.RON&&(t.missingMap[s]=!0),t.controller.emit(a)}t.controller.pollReplies(i,Object.values(T))},notify_call:({context:t,event:n})=>{if(!(n.type=="CHI"||n.type=="PON"||n.type=="DAI_KAN"||n.type=="AN_KAN"||n.type=="SHO_KAN"))throw new Error(`unexpected event ${n.type}`);const i=t.genEventID(),r=n.iam;t.currentWind=r;for(let s of Object.values(T)){const o={id:i,type:n.type,iam:r,wind:s,block:n.block.serialize()};t.controller.emit(o)}t.controller.next()},notify_discard:({context:t,event:n})=>{if(n.type!="DISCARD"&&n.type!="REACH")throw new Error(`unexpected event ${n.type}`);const i=t.genEventID(),r=t.currentWind,s=n.tile;for(let o of Object.values(T)){const a={id:i,type:"DISCARD",iam:r,wind:o,tile:s.toString()};t.controller.emit(a)}t.controller.next()},notify_draw:({context:t,event:n},i)=>{const r=t.genEventID(),s=i==null?void 0:i.action;let o;s=="kan"?o=t.controller.wall.kan():o=t.controller.wall.draw();const a=t.currentWind;t.controller.hand(a).reached||(t.missingMap[a]=!1);for(let c of Object.values(T)){let l=new w(m.BACK,0,[v.TSUMO]);c==a&&(l=o);const u={id:r,type:"DRAW",subType:s,iam:a,wind:c,tile:l.toString()};t.controller.emit(u)}t.controller.next()},notify_ron:({context:t,event:n})=>{const i=t.genEventID();if(n.type=="RON"){const r=n.targetInfo.wind,s=t.currentWind,o=r==s&&t.oneShotMap[s]==!0,a=n.iam;for(let c of Object.values(T)){const l={id:i,type:n.type,iam:a,wind:c,victimInfo:{wind:n.targetInfo.wind,tile:n.targetInfo.tile.toString()},ret:li(n.ret),pushBackReachStick:o};t.controller.emit(l)}}},notify_tsumo:({context:t,event:n})=>{if(n.type!="TSUMO")throw new Error(`unexpected event ${n.type}`);const i=t.genEventID(),r=t.currentWind;for(let s of Object.values(T)){const o={id:i,type:n.type,iam:r,wind:s,lastTile:t.controller.hand(r).drawn.toString(),ret:li(n.ret)};t.controller.emit(o)}},notify_reach:({context:t,event:n})=>{if(n.type!="REACH")throw new Error(`unexpected event ${n.type}`);const i=t.genEventID(),r=n.iam,s=n.tile.clone({add:v.HORIZONTAL});t.oneShotMap[r]=!0;for(let o of Object.values(T)){const a={id:i,type:n.type,iam:r,wind:o,tile:s.toString()};t.controller.emit(a)}},notify_new_dora_if_needed:({context:t,event:n})=>{const i=t.genEventID();if(n.type=="AN_KAN"){const r=t.controller.wall.openDoraMarker();for(let s of Object.values(T)){const o={id:i,type:"NEW_DORA",wind:s,doraMarker:r.toString()};t.controller.emit(o)}}n.type=="SHO_KAN"},disable_one_shot:({context:t,event:n})=>{for(let i of Object.values(T))t.oneShotMap[i]=!1},disable_one_shot_for_me:({context:t,event:n})=>{t.oneShotMap[t.currentWind]=!1},notify_end:({context:t,event:n})=>{const i=t.genEventID(),r=q("");if(n.type=="DRAWN_GAME_BY_NINE_TILES"){r[n.iam]=t.controller.hand(n.iam).toString();for(let s of Object.values(T)){const o={id:i,type:"END_GAME",subType:"NINE_TILES",wind:s,shouldContinue:!0,sticks:t.controller.placeManager.sticks,scores:t.controller.scoreManager.summary,deltas:q(0),hands:r};t.controller.emit(o)}}else if(n.type=="RON"||n.type=="TSUMO"){const s=n.iam=="1w",o=t.controller.finalResult(n.ret,n.iam);for(let a of Object.values(T)){r[n.iam]=t.controller.hand(n.iam).toString();const c={id:i,type:"END_GAME",subType:"WIN_GAME",wind:a,shouldContinue:s,sticks:{reach:0,dead:0},scores:t.controller.scoreManager.summary,deltas:o.deltas,hands:r};t.controller.emit(c)}}else if(!t.controller.wall.canKan||t.controller.river.cannotContinue()){const s=t.controller.wall.canKan?"FOUR_WIND":"FOUR_KAN";for(let o of Object.values(T)){const a={id:i,type:"END_GAME",subType:s,wind:o,shouldContinue:!0,sticks:t.controller.placeManager.sticks,scores:t.controller.scoreManager.summary,deltas:q(0),hands:q("")};t.controller.emit(a)}}else{if(t.controller.wall.canDraw)throw new Error(`unexpected event ${n.type}`);{const s=[];for(let l of Object.values(T)){const u=t.controller.hand(l);new me(u).calc()==0&&(s.push(l),r[l]=u.toString())}const o=s.length==0||s.length==4,a=q(0);for(let l of Object.values(T))s.includes(l)?a[l]+=o?0:3e3/s.length:a[l]-=o?0:3e3/(4-s.length);const c=s.length==4||a["1w"]>0;for(let l of Object.values(T)){const u={id:i,type:"END_GAME",subType:"DRAWN_GAME",wind:l,shouldContinue:c,sticks:t.controller.placeManager.sticks,scores:t.controller.scoreManager.summary,deltas:a,hands:r};t.controller.emit(u)}}}}},actors:{},guards:{canChi:({context:t,event:n},i)=>n.type=="CHI"?!!t.controller.doChi(n.iam,t.controller.river.lastTile.w,t.controller.river.lastTile.t):(console.error(`guards.canChi receive ${n.type}`),!1),canPon:({context:t,event:n},i)=>n.type=="PON"?!!t.controller.doPon(n.iam,t.controller.river.lastTile.w,t.controller.river.lastTile.t):(console.error(`guards.canPon receive ${n.type}`),!1),canWin:({context:t,event:n},i)=>n.type=="TSUMO"||n.type=="RON"?!0:(console.error(`guards.canWin receive ${n.type}`),!1),canReach:({context:t,event:n},i)=>n.type=="REACH"?!!t.controller.doReach(n.iam):(console.error(`guards.canReach receive ${n.type}`),!1),cannotContinue:({context:t,event:n},i)=>!t.controller.wall.canDraw||!t.controller.wall.canKan||t.controller.river.cannotContinue()},delays:{}});function qs(e=0){let t=e;return()=>(t++).toString()}class Ft{constructor(t){x(this,"walls",{replacement:[],dead:[],doraMarkers:[],blindDoraMarkers:[],drawable:[]});x(this,"backup");x(this,"openedDoraCount",1);this.init(t),this.backup=Ft.clone(this.walls)}kan(){if(this.walls.replacement.length==0)throw new Error("exceeded maximum kan");const t=this.walls.replacement.pop();return this.walls.drawable.pop(),w.from(t)}draw(){if(!this.walls.drawable)throw new Error("cannot draw any more");return w.from(this.walls.drawable.pop())}openDoraMarker(){if(this.openedDoraCount>=4)throw new Error("exceeded maximum open dora");return this.openedDoraCount++,w.from(this.walls.doraMarkers[this.openedDoraCount-1])}get doraMarkers(){return this.walls.doraMarkers.slice(0,this.openedDoraCount).map(w.from)}get blindDoraMarkers(){return this.walls.blindDoraMarkers.slice(0,this.openedDoraCount).map(w.from)}get canKan(){return this.walls.replacement.length>0}get canDraw(){return this.walls.drawable.length>0}init(t){if(t!=null){this.walls=Ft.clone(t);return}else{for(let n of Object.values(m)){if(n==m.BACK)continue;const i=n==m.Z?[1,2,3,4,5,6,7]:[1,2,3,4,5,6,7,8,9];for(let r=0;r<4;r++)for(let s of i)n!=m.Z&&r==3&&s==5&&(s=0),this.walls.drawable.push(new w(n,s).toString())}Hi(this.walls.drawable)}for(let n=0;n<14;n++)this.walls.dead.push(this.walls.drawable.pop());for(let n=0;n<4;n++)this.walls.blindDoraMarkers.push(this.walls.dead.pop());for(let n=0;n<4;n++)this.walls.doraMarkers.push(this.walls.dead.pop());for(let n=0;n<4;n++)this.walls.replacement.push(this.walls.dead.pop())}export(){return this.backup}static clone(t){return{drawable:t.drawable.concat(),dead:t.dead.concat(),doraMarkers:t.doraMarkers.concat(),blindDoraMarkers:t.blindDoraMarkers.concat(),replacement:t.replacement.concat()}}}class Xe{constructor(t,n){x(this,"wall",new Ft);x(this,"playerIDs");x(this,"actor",ge(ui(this),{}));x(this,"observer");x(this,"handlers",{});x(this,"mailBox",{});x(this,"histories",[]);x(this,"debugMode");x(this,"snapshot");this.debugMode=(n==null?void 0:n.debug)??!1,this.handlers=t.reduce((o,a)=>(o[a.id]=a.handler,o),{}),this.playerIDs=t.map(o=>o.id),t.forEach(o=>o.handler.on(a=>this.enqueue(a)));const i=Ts();this.observer=new Gs(i),this.observer.eventHandler.on(o=>this.observer.handleEvent(o));const r=Object.fromEntries(this.playerIDs.map(o=>[o,25e3]));this.observer.scoreManager=new Pe(r);const s=Hi(this.playerIDs.concat());this.observer.placeManager=new je({[s[0]]:"1w",[s[1]]:"2w",[s[2]]:"3w",[s[3]]:"4w"})}boardParams(t){const n=this.hand(t);return{doraMarkers:this.observer.doraMarkers,round:this.placeManager.round,myWind:t,sticks:this.observer.placeManager.sticks,reached:n.reached?this.river.discards(t).length!=0?1:2:void 0}}hand(t){return this.observer.hand(t)}get placeManager(){return this.observer.placeManager}get scoreManager(){return this.observer.scoreManager}get river(){return this.observer.river}next(t){(!this.debugMode||t)&&this.actor.send({type:"NEXT"})}emit(t){const n=this.observer.placeManager.playerID(t.wind);this.handlers[n].emit(t);const i=t.iam;t.wind==i?this.observer.eventHandler.emit(t):i==null&&(!this.observer.applied[t.id]||t.type=="DISTRIBUTE")&&(this.observer.eventHandler.emit(t),this.observer.applied[t.id]=!0)}enqueue(t){this.mailBox[t.id]==null&&(this.mailBox[t.id]=[]),this.mailBox[t.id].push(t)}pollReplies(t,n){const i=this.mailBox[t];if(i==null)throw new Error(`not enqueued ${t} at ${this.actor.getSnapshot().value}`);if(i.length!=n.length)throw new Error(`${t}: num of event: got: ${n.length}, want: ${i.length}`);if(n.length==0){console.warn("no events to handle");return}const r=i[0];if(r.type=="CHOICE_AFTER_DISCARDED"){const s=vs(i);if(s.events.length==0){this.actor.send({type:""});return}const o=s.events[0];switch(s.type){case"RON":R(o.choices.RON,"ron choice is none"),this.actor.send({type:s.type,iam:o.wind,ret:tn(o.choices.RON),targetInfo:{wind:o.discarterInfo.wind,tile:w.from(o.discarterInfo.tile)}});break;case"DAI_KAN":R(o.choices.DAI_KAN,"daikan choice is none"),this.actor.send({type:s.type,iam:o.wind,block:W.from(o.choices.DAI_KAN)});break;case"CHI":case"PON":const a=o.choices[s.type];R(a,`${s.type} choice is none`),R(s.events.length==1,`found more than one selected: ${JSON.stringify(s,null,2)}`),this.actor.send({type:s.type,iam:o.wind,block:W.from(a[0])})}}else if(r.type=="CHOICE_AFTER_DRAWN"){const s=As(i);R(s.events.length==1,`found more than one selected: ${JSON.stringify(s,null,2)}`);const o=s.events[0],a=o.wind;switch(s.type){case"TSUMO":R(o.choices.TSUMO,"tsumo choice is none"),this.actor.send({type:s.type,ret:tn(o.choices.TSUMO),lastTile:w.from(o.drawerInfo.tile),iam:a});break;case"REACH":const c=o.choices[s.type];R(c,`${s.type} candidates is none`),this.actor.send({type:s.type,tile:w.from(c[0].tile),iam:a});break;case"DISCARD":const l=o.choices[s.type];R(l,`${s.type} choice is none`),this.actor.send({type:s.type,tile:w.from(l[0]).clone({remove:v.TSUMO}),iam:a});break;case"AN_KAN":{const u=o.choices[s.type];R(u,`${s.type} choice is none`),this.actor.send({type:s.type,block:G.from(u[0]),iam:a});break}case"SHO_KAN":{const u=o.choices[s.type];R(u,`${s.type} choice is none`),this.actor.send({type:s.type,block:W.from(u[0]),iam:a});break}case"DRAWN_GAME_BY_NINE_TILES":this.actor.send({type:"DRAWN_GAME_BY_NINE_TILES",iam:a});break}}else if(r.type=="CHOICE_AFTER_CALLED"){R(r.choices.DISCARD,`discard candidate tile is none: ${JSON.stringify(r,null,2)} ${this.hand(r.wind).toString()}`);const s=r.wind,o=w.from(r.choices.DISCARD[0]);R(o!=null,`undefined tile ${this.hand(s).toString()}`),this.actor.send({type:"DISCARD",tile:o,iam:s})}else if(r.type=="CHOICE_FOR_CHAN_KAN"){const s=i.filter(a=>a.choices.RON);if(s.length==0){this.actor.send({type:""});return}const o=s[0];R(o.choices.RON,"ron choice is none"),this.actor.send({type:"RON",iam:o.wind,ret:tn(o.choices.RON),quadWin:!0,targetInfo:{wind:o.callerInfo.wind,tile:w.from(o.callerInfo.tile)}})}}export(){return this.histories.concat()}static load(t){const n=t.choiceEvents,i=Object.keys(t.players),r={emit:a=>{},on:a=>{}},s=i.map(a=>({id:a,handler:r})),o=new Xe(s);return o.playerIDs=i,o.mailBox=n,o.observer.placeManager=new je(t.players,{round:structuredClone(t.round),sticks:structuredClone(t.sticks)}),o.observer.scoreManager=new Pe(t.scores),o.wall=new Ft(t.wall),o}start(){this.actor.subscribe(n=>{console.debug("State:",n.value)});const t={scores:this.scoreManager.summary,round:this.placeManager.round,players:this.placeManager.playerMap,wall:this.wall.export(),choiceEvents:this.mailBox,sticks:this.placeManager.sticks};this.actor.start(),this.histories.push(t),this.actor.getSnapshot().status}startGame(){for(;console.debug(`start========${this.placeManager.round}=============`),this.start(),this.wall=new Ft,this.observer.applied={},this.mailBox={},this.actor=ge(ui(this)),!this.placeManager.is("3w1"););}finalResult(t,n){const i=this.hand(n),r=i.reached?this.wall.blindDoraMarkers:void 0,s=new ei(i,{...t.boardContext,sticks:this.placeManager.sticks,blindDoraMarkers:r}).calc([t.hand]);return R(s),s}doWin(t,n,i){if(n==null)return!1;let r=this.hand(t);const s=this.boardParams(t);if(r.drawn==null){if(i==null)throw new Error("should ron but params == null");if(i.whoDiscarded==t||i.missingRon)return!1;r=r.clone(),s.ronWind=i.whoDiscarded,s.finalDiscardWin=!this.wall.canDraw,s.quadWin=i.quadWin,r.inc([n])}else s.finalWallWin=!this.wall.canDraw,s.replacementWin=i==null?void 0:i.replacementWin;s.oneShotWin=i==null?void 0:i.oneShot;const o=new bs(r),a=new ei(r,s),c=o.calc(n),l=a.calc(c);if(!l||l.points.length==0)return!1;if(r.draw==null){const u=Yt.candidateTiles(this.hand(t)).candidates;if(this.river.discards(t).map(f=>f.t).some(f=>u.some(p=>p.equals(f,!0))))return!1}return l}doPon(t,n,i){if(i==null||t==n)return!1;const r=this.hand(t);if(r.reached||r.hands.length<3)return!1;let s=i.clone({remove:v.HORIZONTAL});if(nt(i)&&(s=s.clone({n:5})),r.get(i.t,s.n)<2)return!1;const o=[];let a=Math.abs(Number(t[0])-Number(n[0]));a==3&&(a=0),a==2&&(a=1),a==1&&(a=2);let c=new dt([s,s,s]);c=c.clone({replace:{idx:a,tile:i.clone({add:v.HORIZONTAL})}});const l=a%2+1,u=c.tiles[l];if(et(i)&&r.get(i.t,0)>0&&(c=c.clone({replace:{idx:l,tile:u.clone({n:0})}})),o.push(c),et(i)&&r.get(i.t,s.n)==3){const h=c.clone({replace:{idx:l,tile:u.clone({n:5})}});o.push(h)}return o}doChi(t,n,i){if(i==null||!i.isNum()||Et(n)!=t)return!1;const r=this.hand(t);if(r.reached||r.hands.length<3)return!1;let s=i;nt(s)&&(s=i.clone({n:5}));const o=[],a=s.n-2>=1&&r.get(i.t,s.n-2)>0&&r.get(i.t,s.n-1)>0,c=i.clone({add:v.HORIZONTAL,remove:v.TSUMO});if(a&&o.push(new ht([c,new w(i.t,s.n-1),new w(i.t,s.n-2)])),s.n+2<=9&&r.get(i.t,s.n+1)>0&&r.get(i.t,s.n+2)>0&&o.push(new ht([c,new w(i.t,s.n+1),new w(i.t,s.n+2)])),s.n-1>=1&&s.n+1<=9&&r.get(i.t,s.n-1)>0&&r.get(i.t,s.n+1)>0&&o.push(new ht([c,new w(i.t,s.n-1),new w(i.t,s.n+1)])),o.length==0)return!1;if(r.hands.length==4){const p=o[0],d=this.cannotDiscardTile(o[0]),g=r.dec([p.tiles[1],p.tiles[2]]),y=d.reduce((A,_)=>A+r.get(_.t,_.n),0)==2;if(r.inc(g),y)return!1}const h=r.get(i.t,0)>0,f=this.redPattern(o,h);return f.length>0&&r.get(i.t,5)==1?f:o.concat(f)}redPattern(t,n){return t.length==0?[]:n?t.filter(r=>et(r.tiles[1])||et(r.tiles[2])).map(r=>{if(et(r.tiles[1])){const s=r.tiles[1].clone({n:0});return r.clone({replace:{idx:1,tile:s}})}else if(et(r.tiles[2])){const s=r.tiles[2].clone({n:0});return r.clone({replace:{idx:2,tile:s}})}}).filter(r=>r!=null):[]}doReach(t){const n=this.hand(t);return n.reached||!n.menzen||new me(n).calc()>0?!1:Yt.calcCandidates(n,n.hands)}doDiscard(t,n){if(this.hand(t).reached)return[this.hand(t).drawn];const i=this.hand(t).hands;if(n==null)return i;if(n instanceof dt)return i.filter(o=>!o.equals(n.tiles[0],!0));const r=this.cannotDiscardTile(n),s=i.filter(o=>!r.some(a=>o.equals(a,!0)));return R(s.length>0,`no tiles to discard. hand: ${this.hand(t)}, suji: ${r}, block-chi: ${n}`),s}cannotDiscardTile(t){let n=t.tiles[0].n,i=t.tiles[1].n;const r=t.tiles[0].t;return n==0&&(n=5),i==0&&(i=5),n-2==i?[new w(r,n-3),new w(r,n)]:n+1==i?[new w(r,n+3),new w(r,n)]:[]}doAnKan(t){const n=this.hand(t),i=[];if(n.reached)return!1;for(let r of Object.values(m))for(let s=1;s<n.getArrayLen(r);s++)if(n.get(r,s)==4){const o=[new w(r,s),new w(r,s),new w(r,s),new w(r,s)];r!=m.Z&&s==5&&(o[0]=o[0].clone({n:0})),i.push(new G(o))}if(i.length==0)return!1;for(let r of i)R(r.tiles.filter(s=>s.has(v.HORIZONTAL)).length==0,`h op ${r.toString()}`);return i}doShoKan(t){const n=this.hand(t);if(n.reached)return!1;const i=n.called.filter(s=>s instanceof dt);if(i.length==0)return!1;const r=[];for(let s of i){const o=s.tiles[0];if(n.get(o.t,o.n)==1){const a=[...s.tiles,new w(o.t,o.n,[v.HORIZONTAL])];et(o)&&n.get(o.t,0)==1&&a[3].n==0,r.push(new xt(a))}}if(r.length==0)return!1;for(let s of r)R(s.tiles.filter(o=>o.has(v.HORIZONTAL)).length==2,`h op ${s.toString()}`);return r}doDaiKan(t,n,i){const r=this.hand(t);if(r.reached||t==n)return!1;let s=i.clone({remove:v.HORIZONTAL});if(nt(s)&&(s=s.clone({n:5})),r.get(s.t,s.n)!=3)return!1;let o=new bt([s,s,s,s]),a=Math.abs(Number(t[0])-Number(n[0]));a==3&&(a=0),a==1&&(a=3);let c=o.clone({replace:{idx:a,tile:i.clone({add:v.HORIZONTAL})}});if(et(s)&&et(i)){const l=a%3+1,u=c.tiles[l].clone({n:0});c=c.clone({replace:{idx:l,tile:u}})}return R(c.tiles.filter(l=>l.has(v.HORIZONTAL)).length==1,`h op ${c.toString()}`),c}canDrawnGame(t){if(this.river.discards(t).length!=0)return!1;const n=this.hand(t);let i=n.get(m.M,1)+n.get(m.M,9)+n.get(m.S,1)+n.get(m.S,9)+n.get(m.P,1)+n.get(m.P,9);for(let r=0;r<n.getArrayLen(m.Z);r++)i+=n.get(m.Z,r);return i>=9}initialHands(){const t=q("");for(let n=0;n<3;n++)for(let i of Object.values(T))for(let r=0;r<4;r++)t[i]+=this.wall.draw().toString();for(let n of Object.values(T))t[n]+=this.wall.draw().toString();return t}}class Gt extends pe{isBackHand(){for(let t of Object.values(m))if(t!=m.BACK&&this.sum(t)>0)return!1;return this.sum(m.BACK)>0}clone(){const t=new Gt(this.toString());return t.data.reached=this.data.reached,t}dec(t){return this.isBackHand()?(super.dec(t.map(()=>new w(m.BACK,0))),[...t]):super.dec(t)}}class Gi{constructor(t,n){x(this,"id");x(this,"river",new $i);x(this,"placeManager",new je({}));x(this,"scoreManager",new Pe({}));x(this,"hands",q(new Gt("")));x(this,"counter",new Os);x(this,"doraMarkers",[]);x(this,"eventHandler");this.id=t,this.eventHandler=n}hand(t){return this.hands[t]}handleEvent(t){try{switch(t.type){case"CHOICE_AFTER_CALLED":case"CHOICE_AFTER_DISCARDED":case"CHOICE_AFTER_DRAWN":case"CHOICE_FOR_CHAN_KAN":break;case"DISTRIBUTE":this.counter.reset();const n=w.from(t.doraMarker);this.setHands(t),this.placeManager=new je(structuredClone(t.places),{round:structuredClone(t.round),sticks:structuredClone(t.sticks)}),this.scoreManager=new Pe(structuredClone(t.scores)),this.doraMarkers=[n],this.counter.dec(n);for(let r of Object.values(T))r==t.wind&&this.counter.dec(...this.hand(r).hands);break;case"DRAW":{const r=w.from(t.tile);this.hands[t.iam].draw(r),this.counter.dec(r);break}case"DISCARD":{const r=w.from(t.tile);if(this.river.discard(r,t.iam),this.hands[t.iam].discard(r),t.iam!=t.wind){this.counter.dec(r),this.counter.addTileToSafeMap(r,t.iam);for(let s of Object.values(T))this.hand(s).reached&&this.counter.addTileToSafeMap(r,s)}break}case"PON":case"CHI":case"DAI_KAN":{const r=W.from(t.block);this.hands[t.iam].call(r),this.river.markCalled(),t.iam!=t.wind&&this.counter.dec(...r.tiles.filter(s=>!s.has(v.HORIZONTAL)));break}case"SHO_KAN":{const r=W.from(t.block);this.hands[t.iam].kan(r),t.iam!=t.wind&&this.counter.dec(r.tiles.filter(s=>s.has(v.HORIZONTAL))[0]);break}case"AN_KAN":{const r=W.from(t.block);this.hands[t.iam].kan(r),t.iam!=t.wind&&this.counter.dec(...r.tiles.filter(s=>!s.has(v.HORIZONTAL)));break}case"REACH":const i=this.placeManager.playerID(t.iam);this.hands[t.iam].reach(),this.scoreManager.reach(i),this.placeManager.incrementReachStick();break;case"NEW_DORA":{const r=w.from(t.doraMarker);this.doraMarkers.push(r),this.counter.dec(r);break}case"TSUMO":break;case"RON":if(t.pushBackReachStick){const r=t.victimInfo.wind,s=this.placeManager.playerID(r);this.scoreManager.restoreReachStick(s),this.placeManager.decrementReachStick()}break;case"END_GAME":switch(t.subType){case"NINE_TILES":case"FOUR_KAN":case"FOUR_WIND":this.placeManager.incrementDeadStick();break;case"DRAWN_GAME":{const r=this.placeManager.playerMap;this.scoreManager.update(t.deltas,r),this.placeManager.incrementDeadStick(),t.shouldContinue||this.placeManager.nextRound();break}case"WIN_GAME":{const r=this.placeManager.playerMap;this.scoreManager.update(t.deltas,r),t.shouldContinue?this.placeManager.incrementDeadStick():(this.placeManager.nextRound(),this.placeManager.resetDeadStick()),this.placeManager.resetReachStick();break}}break;default:throw new Error(`unexpected event ${JSON.stringify(t,null,2)}`)}}catch(n){throw new Error(`${this.id} ${t.type} ${n}`)}}}class Gs extends Gi{constructor(n){super("observer",n);x(this,"applied",{});this.counter.disable=!0,this.hands=q(new Gt("_____________"))}setHands(n){this.hands[n.wind]=new Gt(n.hands[n.wind])}handleEvent(n){switch(super.handleEvent(n),n.type){case"DISTRIBUTE":let i=!0;for(let r of Object.values(T))i&&(i=this.hand(r).get(m.BACK,0)==0);if(!i)break;console.debug("DISTRIBUTE:",`round: ${this.placeManager.round}`,`scores: ${JSON.stringify(this.scoreManager.summary,null,2)}`,`map: ${JSON.stringify(this.placeManager.playerMap,null,2)}`,`sticks: ${JSON.stringify(this.placeManager.sticks,null,2)}`);for(let r of Object.values(T))console.debug(this.placeManager.playerID(r),`init hand: ${this.hand(r).toString()}`);break;case"DRAW":console.debug(this.placeManager.playerID(n.iam),`draw: ${this.hand(n.iam).drawn}`,`hand: ${this.hand(n.iam).toString()}`);break;case"DISCARD":console.debug(this.placeManager.playerID(n.iam),`discard: ${n.tile.toString()}`,`hand: ${this.hand(n.iam).toString()}`);break;case"CHI":case"PON":case"DAI_KAN":case"AN_KAN":case"SHO_KAN":console.debug(this.placeManager.playerID(n.iam),`call: ${n.block.toString()}`,`hand: ${this.hand(n.iam).toString()}`);break;case"REACH":console.debug(this.placeManager.playerID(n.iam),`reach: ${this.hand(n.iam).toString()}`,`tile: ${n.tile}`);break;case"TSUMO":case"RON":console.debug(this.placeManager.playerID(n.iam),`ron/tsumo: ${JSON.stringify(n.ret,null,2)}`,`hand: ${this.hand(n.iam).toString()}`);break;case"END_GAME":for(let r of Object.values(T))console.debug(this.placeManager.playerID(r),`end hand: ${this.hand(r).toString()}`);console.debug("END_GAME",n.subType,"scores",JSON.stringify(this.scoreManager.summary,null,2),`sticks: ${JSON.stringify(this.placeManager.sticks,null,2)}`)}}}class Ie extends Gi{constructor(n,i){super(n,i);x(this,"river",new $i);x(this,"doras",[]);this.eventHandler.on(r=>this.handleEvent(r))}get myWind(){return this.placeManager.wind(this.id)}setHands(n){for(let i of Object.values(T))this.hands[i]=new Gt(n.hands[i])}handleDiscard(n){const i=Object.values(T).filter(u=>u==this.myWind?!1:this.hand(u).reached),r=new me(this.hand(this.myWind)).calc();if(i.length>0&&r>=2)return ce.selectTile(this.counter,i,n);const s=Yt.calcCandidates(this.hand(this.myWind),n),a=Le.calcPlayerCandidates(this.counter,s).sort((u,h)=>h.sum-u.sum),c=a.filter(u=>u.sum==a[0].sum);return Le.selectMinPriority(this.counter,c,this.doras).tile}handleEvent(n){switch(n.type){case"CHOICE_AFTER_DISCARDED":this.eventHandler.emit(n);break;case"CHOICE_AFTER_CALLED":case"CHOICE_AFTER_DRAWN":if(n.choices.DISCARD){const i=this.handleDiscard(n.choices.DISCARD.map(w.from));n.choices.DISCARD=[i.toString()]}this.eventHandler.emit(n);break;case"CHOICE_FOR_CHAN_KAN":this.eventHandler.emit(n);break;default:super.handleEvent(n)}}}class jh{constructor(t){x(this,"index",0);x(this,"histories",[]);this.histories=JSON.parse(t)}next(){R(this.index<this.histories.length),this.index++}prev(){this.index--,R(this.index<0)}start(){Xe.load(this.histories[this.index]).start()}auto(){for(;this.index<this.histories.length;this.next())this.start()}}const Lh=e=>{const[t,n]=Oe(),[i,r]=Oe(),[s,o]=Oe(),[a,c]=Oe(),l=(e==null?void 0:e.playerIDs)??["player-1","player-2","player-3","player-4"];new Ie(l[0],n),new Ie(l[1],r),new Ie(l[2],o),new Ie(l[3],c);const u=[{handler:t,id:l[0]},{handler:i,id:l[1]},{handler:s,id:l[2]},{handler:a,id:l[3]}];return new Xe(u,{debug:e==null?void 0:e.debug})},Ht=(e,t)=>{let i=1;for(let r of t)r.equals(e,!0)&&(i*=2);return i};class Le{static calcPlayerCandidates(t,n){let i=[];for(let r of n){let s=0,o=[];for(let a of r.candidates)o.push({tile:a.clone(),n:t.get(a)}),s+=t.get(a);i.push({sum:s,tile:r.tile,candidates:o,shanten:r.shanten})}return i}static selectMinPriority(t,n,i){R(n.length>0);let r=0,s=0;for(let o=0;o<n.length;o++){const a=Le.calcPriority(t,n[o],i);a<r&&(r=a,s=o)}return n[s]}static calcPriority(t,n,i){const r=n.tile;let s=0;if(r.t==m.Z)return s=t.get(r),(r.n==5||r.n==6||r.n==7)&&(s*=2),s*Ht(r,i);{const o=t.get(r);s+=o*Ht(r,i);const a=t.get(new w(r.t,r.n+1)),c=t.get(new w(r.t,r.n+2)),l=t.get(new w(r.t,r.n-1)),u=t.get(new w(r.t,r.n-2)),h=r.n-2>0?Math.min(l,u):0,f=r.n+2<=9?Math.min(a,c):0,p=r.n-1>=1&&r.n+1<=9?Math.min(a,l):0,d=Math.max(h,p),g=Math.max(p,f);return s+=o*Ht(r,i),s+=h*Ht(new w(r.t,r.n-2),i),s+=f*Ht(new w(r.t,r.n+2),i),s+=d*Ht(new w(r.t,r.n-1),i),s+=g*Ht(new w(r.t,r.n+1),i),r.n==0,s}}}class ce{static selectTile(t,n,i){R(n.length>0&&i.length>0);let r=i[0],s=Number.POSITIVE_INFINITY;for(let o of i){const a=ce.rank(t,n,o);a<s&&(r=o,s=a)}return r}static rank(t,n,i){let r=0;const s=i.isNum()?ce.rankN:ce.rankZ;for(let o of n){const a=s(t,o,i);r<a&&(r=a)}return r}static rankZ(t,n,i){if(i.t!=m.Z)throw new Error(`expected TYPE.Z but ${i.toString()}`);if(t.isSafeTile(i.t,i.n,n))return 0;const r=t.get(i);return Math.min(r,3)}static rankN(t,n,i){if(!i.isNum())throw new Error(`expected TYPE.NUMBER but ${i.toString()}`);const r=i.n,s=i.t;if(t.isSafeTile(s,r,n))return 0;if(r==1)return t.isSafeTile(s,4,n)?3:6;if(r==9)return t.isSafeTile(s,6,n)?3:6;if(r==2||r==8)return t.isSafeTile(s,5,n)?4:8;if(r==3)return t.isSafeTile(s,6,n)?5:8;if(r==7)return t.isSafeTile(s,4,n)?5:8;const o=t.isSafeTile(s,r-3,n),a=t.isSafeTile(s,r+3,n);return o&&a?4:o||a?8:12}}exports.ActorHand=Gt;exports.BLOCK=b;exports.BaseActor=Gi;exports.Block=W;exports.BlockAnKan=G;exports.BlockCalculator=bs;exports.BlockChi=ht;exports.BlockDaiKan=bt;exports.BlockHand=gn;exports.BlockIsolated=mi;exports.BlockOther=gi;exports.BlockPair=X;exports.BlockPon=dt;exports.BlockRun=kt;exports.BlockShoKan=xt;exports.BlockThree=lt;exports.Controller=Xe;exports.Counter=Os;exports.DoubleCalculator=ei;exports.Efficiency=Yt;exports.FONT_FAMILY=hi;exports.Hand=pe;exports.INPUT_SEPARATOR=ke;exports.ImageHelper=Mi;exports.MeasureText=to;exports.N19=_t;exports.NZ=$e;exports.OPERATOR=v;exports.Observer=Gs;exports.Parser=ot;exports.PlaceManager=je;exports.Player=Ie;exports.PlayerEfficiency=Le;exports.ROUND_MAP=fi;exports.Replayer=jh;exports.RiskRank=ce;exports.River=$i;exports.ScoreManager=Pe;exports.ShantenCalculator=me;exports.TABLE_CONTEXT=Sr;exports.TILE_CONTEXT=Ot;exports.TYPE=m;exports.Tile=w;exports.WIND=T;exports.WIND_MAP=di;exports.Wall=Ft;exports.convertInput=_s;exports.createControllerMachine=ui;exports.createEventEmitter=Ts;exports.createEventPipe=Oe;exports.createHand=re;exports.createLocalGame=Lh;exports.createTable=is;exports.createWindMap=q;exports.deserializeWinResult=tn;exports.drawBlocks=_c;exports.drawTable=Ic;exports.incrementalIDGenerator=qs;exports.isNum0=nt;exports.isNum5=et;exports.isNum5or0=Ne;exports.nextRound=Ee;exports.nextWind=Et;exports.optimizeSVG=xc;exports.parse=ys;exports.parseTableInput=ws;exports.prevRound=Nu;exports.prevWind=Mu;exports.prioritizeDiscardedEvents=vs;exports.prioritizeDrawnEvents=As;exports.shuffle=Hi;exports.tileSortFunc=Ce;