@naanouff/w3dts-chess 0.0.0-stage → 0.0.6

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 (74) hide show
  1. package/README.md +18 -3
  2. package/dist/board/bookMoveSpline.d.ts +19 -0
  3. package/dist/board/bookMoveSpline.d.ts.map +1 -0
  4. package/dist/board/cemeterySlots.d.ts +14 -0
  5. package/dist/board/cemeterySlots.d.ts.map +1 -0
  6. package/dist/board/chessBoard.d.ts +36 -0
  7. package/dist/board/chessBoard.d.ts.map +1 -0
  8. package/dist/board/fileRankGlyph.d.ts +12 -0
  9. package/dist/board/fileRankGlyph.d.ts.map +1 -0
  10. package/dist/board/fileRankLabels.d.ts +33 -0
  11. package/dist/board/fileRankLabels.d.ts.map +1 -0
  12. package/dist/board/pieceTravel.d.ts +8 -0
  13. package/dist/board/pieceTravel.d.ts.map +1 -0
  14. package/dist/ecs/ChessPieceComponent.d.ts +14 -0
  15. package/dist/ecs/ChessPieceComponent.d.ts.map +1 -0
  16. package/dist/geometry/boardBody.d.ts +12 -0
  17. package/dist/geometry/boardBody.d.ts.map +1 -0
  18. package/dist/geometry/cylindricalPieceUv.d.ts +7 -0
  19. package/dist/geometry/cylindricalPieceUv.d.ts.map +1 -0
  20. package/dist/geometry/meshBuilder.d.ts +32 -0
  21. package/dist/geometry/meshBuilder.d.ts.map +1 -0
  22. package/dist/geometry/pieceColliders.d.ts +10 -0
  23. package/dist/geometry/pieceColliders.d.ts.map +1 -0
  24. package/dist/geometry/stauntonPieces.d.ts +11 -0
  25. package/dist/geometry/stauntonPieces.d.ts.map +1 -0
  26. package/dist/geometry/stauntonProfiles.d.ts +25 -0
  27. package/dist/geometry/stauntonProfiles.d.ts.map +1 -0
  28. package/dist/gproc/chessBoardGraph.d.ts +4 -0
  29. package/dist/gproc/chessBoardGraph.d.ts.map +1 -0
  30. package/dist/gproc/chessPieceGraphs.d.ts +11 -0
  31. package/dist/gproc/chessPieceGraphs.d.ts.map +1 -0
  32. package/dist/gproc/executeChessGProc.d.ts +7 -0
  33. package/dist/gproc/executeChessGProc.d.ts.map +1 -0
  34. package/dist/grab/MouseGrabController.d.ts +27 -0
  35. package/dist/grab/MouseGrabController.d.ts.map +1 -0
  36. package/dist/grab/grabMath.d.ts +28 -0
  37. package/dist/grab/grabMath.d.ts.map +1 -0
  38. package/dist/grab/pickRay.d.ts +20 -0
  39. package/dist/grab/pickRay.d.ts.map +1 -0
  40. package/dist/index.d.ts +53 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/learn/OpeningTrainer.d.ts +28 -0
  43. package/dist/learn/OpeningTrainer.d.ts.map +1 -0
  44. package/dist/learn/ecoOpenings.d.ts +18 -0
  45. package/dist/learn/ecoOpenings.d.ts.map +1 -0
  46. package/dist/look/chessAlbedo.d.ts +23 -0
  47. package/dist/look/chessAlbedo.d.ts.map +1 -0
  48. package/dist/look/chessProceduralShaderGraphs.d.ts +6 -0
  49. package/dist/look/chessProceduralShaderGraphs.d.ts.map +1 -0
  50. package/dist/net/chessWire.d.ts +30 -0
  51. package/dist/net/chessWire.d.ts.map +1 -0
  52. package/dist/physics/chessGroups.d.ts +14 -0
  53. package/dist/physics/chessGroups.d.ts.map +1 -0
  54. package/dist/physics/piecePose.d.ts +8 -0
  55. package/dist/physics/piecePose.d.ts.map +1 -0
  56. package/dist/play/chessHudState.d.ts +69 -0
  57. package/dist/play/chessHudState.d.ts.map +1 -0
  58. package/dist/play/chessTableSfx.d.ts +19 -0
  59. package/dist/play/chessTableSfx.d.ts.map +1 -0
  60. package/dist/play/parseChessDemoQuery.d.ts +17 -0
  61. package/dist/play/parseChessDemoQuery.d.ts.map +1 -0
  62. package/dist/rules/ChessMatch.d.ts +37 -0
  63. package/dist/rules/ChessMatch.d.ts.map +1 -0
  64. package/dist/rules/HeuristicChessEngine.d.ts +15 -0
  65. package/dist/rules/HeuristicChessEngine.d.ts.map +1 -0
  66. package/dist/rules/IChessEngine.d.ts +12 -0
  67. package/dist/rules/IChessEngine.d.ts.map +1 -0
  68. package/dist/rules/chessTypes.d.ts +37 -0
  69. package/dist/rules/chessTypes.d.ts.map +1 -0
  70. package/dist/scene/chessSceneExtension.d.ts +30 -0
  71. package/dist/scene/chessSceneExtension.d.ts.map +1 -0
  72. package/dist/w3dts-chess.es.js +3662 -0
  73. package/dist/w3dts-chess.umd.js +1 -0
  74. package/package.json +44 -3
@@ -0,0 +1 @@
1
+ (function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("gl-matrix"),require("@naanouff/w3dts-core"),require("@naanouff/w3dts-gproc"),require("@naanouff/w3dts-physics")):typeof define=="function"&&define.amd?define(["exports","gl-matrix","@naanouff/w3dts-core","@naanouff/w3dts-gproc","@naanouff/w3dts-physics"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d.W3dtsChess={},d.glMatrix,d.W3dtsCore,d.W3dtsGproc,d.W3dtsPhysics))})(this,function(d,y,F,W,ot){"use strict";var fr=Object.defineProperty;var pr=(d,y,F)=>y in d?fr(d,y,{enumerable:!0,configurable:!0,writable:!0,value:F}):d[y]=F;var D=(d,y,F)=>pr(d,typeof y!="symbol"?y+"":y,F);class Me{unwrap(t,n){const o=this._chain(s=>w.ok(t?t(s):s),s=>n?w.ok(n(s)):w.err(s));if(o.isErr)throw o.error;return o.value}map(t,n){return this._chain(o=>w.ok(t(o)),o=>w.err(n?n(o):o))}chain(t,n){return this._chain(t,n||(o=>w.err(o)))}}class qn extends Me{constructor(t){super(),this.value=void 0,this.isOk=!0,this.isErr=!1,this.value=t}_chain(t,n){return t(this.value)}}class Kn extends Me{constructor(t){super(),this.error=void 0,this.isOk=!1,this.isErr=!0,this.error=t}_chain(t,n){return n(this.error)}}var w;(function(e){e.ok=function(t){return new qn(t)},e.err=function(t){return new Kn(t||new Error)},e.all=function(t){if(Array.isArray(t)){const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(i.isErr)return i;s.push(i.value)}return e.ok(s)}const n={},o=Object.keys(t);for(let s=0;s<o.length;s++){const r=t[o[s]];if(r.isErr)return r;n[o[s]]=r.value}return e.ok(n)}})(w||(w={}));const Te=e=>(e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),Math.imul(e+(e>>>4)&252645135,16843009)>>24),jt=e=>(e=e>>>8&16711935|(e&16711935)<<8,e>>>16&65535|(e&65535)<<16),Oe=e=>(e=e>>>1&1431655765|(e&1431655765)<<1,e=e>>>2&858993459|(e&858993459)<<2,e=e>>>4&252645135|(e&252645135)<<4,jt(e));class m{constructor(t,n){this.lo=t|0,this.hi=n|0}static fromSquare(t){return t>=32?new m(0,1<<t-32):new m(1<<t,0)}static fromRank(t){return new m(255,0).shl64(8*t)}static fromFile(t){return new m(16843009<<t,16843009<<t)}static empty(){return new m(0,0)}static full(){return new m(4294967295,4294967295)}static corners(){return new m(129,2164260864)}static center(){return new m(402653184,24)}static backranks(){return new m(255,4278190080)}static backrank(t){return t==="white"?new m(255,0):new m(0,4278190080)}static lightSquares(){return new m(1437226410,1437226410)}static darkSquares(){return new m(2857740885,2857740885)}complement(){return new m(~this.lo,~this.hi)}xor(t){return new m(this.lo^t.lo,this.hi^t.hi)}union(t){return new m(this.lo|t.lo,this.hi|t.hi)}intersect(t){return new m(this.lo&t.lo,this.hi&t.hi)}diff(t){return new m(this.lo&~t.lo,this.hi&~t.hi)}intersects(t){return this.intersect(t).nonEmpty()}isDisjoint(t){return this.intersect(t).isEmpty()}supersetOf(t){return t.diff(this).isEmpty()}subsetOf(t){return this.diff(t).isEmpty()}shr64(t){return t>=64?m.empty():t>=32?new m(this.hi>>>t-32,0):t>0?new m(this.lo>>>t^this.hi<<32-t,this.hi>>>t):this}shl64(t){return t>=64?m.empty():t>=32?new m(0,this.lo<<t-32):t>0?new m(this.lo<<t,this.hi<<t^this.lo>>>32-t):this}bswap64(){return new m(jt(this.hi),jt(this.lo))}rbit64(){return new m(Oe(this.hi),Oe(this.lo))}minus64(t){const n=this.lo-t.lo,o=(n&t.lo&1)+(t.lo>>>1)+(n>>>1)>>>31;return new m(n,this.hi-(t.hi+o))}equals(t){return this.lo===t.lo&&this.hi===t.hi}size(){return Te(this.lo)+Te(this.hi)}isEmpty(){return this.lo===0&&this.hi===0}nonEmpty(){return this.lo!==0||this.hi!==0}has(t){return(t>=32?this.hi&1<<t-32:this.lo&1<<t)!==0}set(t,n){return n?this.with(t):this.without(t)}with(t){return t>=32?new m(this.lo,this.hi|1<<t-32):new m(this.lo|1<<t,this.hi)}without(t){return t>=32?new m(this.lo,this.hi&~(1<<t-32)):new m(this.lo&~(1<<t),this.hi)}toggle(t){return t>=32?new m(this.lo,this.hi^1<<t-32):new m(this.lo^1<<t,this.hi)}last(){if(this.hi!==0)return 63-Math.clz32(this.hi);if(this.lo!==0)return 31-Math.clz32(this.lo)}first(){if(this.lo!==0)return 31-Math.clz32(this.lo&-this.lo);if(this.hi!==0)return 63-Math.clz32(this.hi&-this.hi)}withoutFirst(){return this.lo!==0?new m(this.lo&this.lo-1,this.hi):new m(0,this.hi&this.hi-1)}moreThanOne(){return this.hi!==0&&this.lo!==0||(this.lo&this.lo-1)!==0||(this.hi&this.hi-1)!==0}singleSquare(){return this.moreThanOne()?void 0:this.last()}*[Symbol.iterator](){let t=this.lo,n=this.hi;for(;t!==0;){const o=31-Math.clz32(t&-t);t^=1<<o,yield o}for(;n!==0;){const o=31-Math.clz32(n&-n);n^=1<<o,yield 32+o}}*reversed(){let t=this.lo,n=this.hi;for(;n!==0;){const o=31-Math.clz32(n);n^=1<<o,yield 32+o}for(;t!==0;){const o=31-Math.clz32(t);t^=1<<o,yield o}}}const Pt=["a","b","c","d","e","f","g","h"],Ie=["1","2","3","4","5","6","7","8"],st=["white","black"],$=["pawn","knight","bishop","rook","queen","king"],Wn=["a","h"],Rt=e=>"role"in e,E=e=>e!==void 0,L=e=>e==="white"?"black":"white",rt=e=>e>>3,G=e=>e&7,qt=(e,t)=>0<=e&&e<8&&0<=t&&t<8?e+8*t:void 0,kt=e=>{switch(e){case"pawn":return"p";case"knight":return"n";case"bishop":return"b";case"rook":return"r";case"queen":return"q";case"king":return"k"}};function Qn(e){switch(e.toLowerCase()){case"p":return"pawn";case"n":return"knight";case"b":return"bishop";case"r":return"rook";case"q":return"queen";case"k":return"king";default:return}}function ht(e){if(e.length===2)return qt(e.charCodeAt(0)-97,e.charCodeAt(1)-49)}const Mt=e=>Pt[G(e)]+Ie[rt(e)],Kt=(e,t)=>e==="white"?t==="a"?2:6:t==="a"?58:62,Wt=(e,t)=>e==="white"?t==="a"?3:5:t==="a"?59:61,Tt=(e,t)=>{let n=m.empty();for(const o of t){const s=e+o;0<=s&&s<64&&Math.abs(G(e)-G(s))<=2&&(n=n.with(s))}return n},Q=e=>{const t=[];for(let n=0;n<64;n++)t[n]=e(n);return t},Yn=Q(e=>Tt(e,[-9,-8,-7,-1,1,7,8,9])),Xn=Q(e=>Tt(e,[-17,-15,-10,-6,6,10,15,17])),Zn={white:Q(e=>Tt(e,[7,9])),black:Q(e=>Tt(e,[-7,-9]))},Qt=e=>Yn[e],Yt=e=>Xn[e],Ot=(e,t)=>Zn[e][t],Xt=Q(e=>m.fromFile(G(e)).without(e)),Zt=Q(e=>m.fromRank(rt(e)).without(e)),Jt=Q(e=>{const t=new m(134480385,2151686160),n=8*(rt(e)-G(e));return(n>=0?t.shl64(n):t.shr64(-n)).without(e)}),zt=Q(e=>{const t=new m(270549120,16909320),n=8*(rt(e)+G(e)-7);return(n>=0?t.shl64(n):t.shr64(-n)).without(e)}),te=(e,t,n)=>{let o=n.intersect(t),s=o.bswap64();return o=o.minus64(e),s=s.minus64(e.bswap64()),o.xor(s.bswap64()).intersect(t)},Jn=(e,t)=>te(m.fromSquare(e),Xt[e],t),zn=(e,t)=>{const n=Zt[e];let o=t.intersect(n),s=o.rbit64();return o=o.minus64(m.fromSquare(e)),s=s.minus64(m.fromSquare(63-e)),o.xor(s.rbit64()).intersect(n)},_t=(e,t)=>{const n=m.fromSquare(e);return te(n,Jt[e],t).xor(te(n,zt[e],t))},vt=(e,t)=>Jn(e,t).xor(zn(e,t)),Ne=(e,t)=>_t(e,t).xor(vt(e,t)),Be=(e,t)=>{const n=m.fromSquare(t);return Zt[e].intersects(n)?Zt[e].with(e):zt[e].intersects(n)?zt[e].with(e):Jt[e].intersects(n)?Jt[e].with(e):Xt[e].intersects(n)?Xt[e].with(e):m.empty()},Ct=(e,t)=>Be(e,t).intersect(m.full().shl64(e).xor(m.full().shl64(t))).withoutFirst();class ft{constructor(){}static default(){const t=new ft;return t.reset(),t}reset(){this.occupied=new m(65535,4294901760),this.promoted=m.empty(),this.white=new m(65535,0),this.black=new m(0,4294901760),this.pawn=new m(65280,16711680),this.knight=new m(66,1107296256),this.bishop=new m(36,603979776),this.rook=new m(129,2164260864),this.queen=new m(8,134217728),this.king=new m(16,268435456)}static empty(){const t=new ft;return t.clear(),t}clear(){this.occupied=m.empty(),this.promoted=m.empty();for(const t of st)this[t]=m.empty();for(const t of $)this[t]=m.empty()}clone(){const t=new ft;t.occupied=this.occupied,t.promoted=this.promoted;for(const n of st)t[n]=this[n];for(const n of $)t[n]=this[n];return t}getColor(t){if(this.white.has(t))return"white";if(this.black.has(t))return"black"}getRole(t){for(const n of $)if(this[n].has(t))return n}get(t){const n=this.getColor(t);if(!n)return;const o=this.getRole(t),s=this.promoted.has(t);return{color:n,role:o,promoted:s}}take(t){const n=this.get(t);return n&&(this.occupied=this.occupied.without(t),this[n.color]=this[n.color].without(t),this[n.role]=this[n.role].without(t),n.promoted&&(this.promoted=this.promoted.without(t))),n}set(t,n){const o=this.take(t);return this.occupied=this.occupied.with(t),this[n.color]=this[n.color].with(t),this[n.role]=this[n.role].with(t),n.promoted&&(this.promoted=this.promoted.with(t)),o}has(t){return this.occupied.has(t)}*[Symbol.iterator](){for(const t of this.occupied)yield[t,this.get(t)]}pieces(t,n){return this[t].intersect(this[n])}rooksAndQueens(){return this.rook.union(this.queen)}bishopsAndQueens(){return this.bishop.union(this.queen)}kingOf(t){return this.pieces(t,"king").singleSquare()}}var Y;(function(e){e.Empty="ERR_EMPTY",e.OppositeCheck="ERR_OPPOSITE_CHECK",e.PawnsOnBackrank="ERR_PAWNS_ON_BACKRANK",e.Kings="ERR_KINGS",e.Variant="ERR_VARIANT"})(Y||(Y={}));class pt extends Error{}const to=(e,t,n,o)=>n[t].intersect(vt(e,o).intersect(n.rooksAndQueens()).union(_t(e,o).intersect(n.bishopsAndQueens())).union(Yt(e).intersect(n.knight)).union(Qt(e).intersect(n.king)).union(Ot(L(t),e).intersect(n.pawn)));class it{constructor(){}static default(){const t=new it;return t.castlingRights=m.corners(),t.rook={white:{a:0,h:7},black:{a:56,h:63}},t.path={white:{a:new m(14,0),h:new m(96,0)},black:{a:new m(0,234881024),h:new m(0,1610612736)}},t}static empty(){const t=new it;return t.castlingRights=m.empty(),t.rook={white:{a:void 0,h:void 0},black:{a:void 0,h:void 0}},t.path={white:{a:m.empty(),h:m.empty()},black:{a:m.empty(),h:m.empty()}},t}clone(){const t=new it;return t.castlingRights=this.castlingRights,t.rook={white:{a:this.rook.white.a,h:this.rook.white.h},black:{a:this.rook.black.a,h:this.rook.black.h}},t.path={white:{a:this.path.white.a,h:this.path.white.h},black:{a:this.path.black.a,h:this.path.black.h}},t}add(t,n,o,s){const r=Kt(t,n),i=Wt(t,n);this.castlingRights=this.castlingRights.with(s),this.rook[t][n]=s,this.path[t][n]=Ct(s,i).with(i).union(Ct(o,r).with(r)).without(o).without(s)}static fromSetup(t){const n=it.empty(),o=t.castlingRights.intersect(t.board.rook);for(const s of st){const r=m.backrank(s),i=t.board.kingOf(s);if(!E(i)||!r.has(i))continue;const a=o.intersect(t.board[s]).intersect(r),f=a.first();E(f)&&f<i&&n.add(s,"a",i,f);const h=a.last();E(h)&&i<h&&n.add(s,"h",i,h)}return n}discardRook(t){if(this.castlingRights.has(t)){this.castlingRights=this.castlingRights.without(t);for(const n of st)for(const o of Wn)this.rook[n][o]===t&&(this.rook[n][o]=void 0)}}discardColor(t){this.castlingRights=this.castlingRights.diff(m.backrank(t)),this.rook[t].a=void 0,this.rook[t].h=void 0}}class eo{constructor(t){this.rules=t}reset(){this.board=ft.default(),this.pockets=void 0,this.turn="white",this.castles=it.default(),this.epSquare=void 0,this.remainingChecks=void 0,this.halfmoves=0,this.fullmoves=1}setupUnchecked(t){this.board=t.board.clone(),this.board.promoted=m.empty(),this.pockets=void 0,this.turn=t.turn,this.castles=it.fromSetup(t),this.epSquare=no(this,t.epSquare),this.remainingChecks=void 0,this.halfmoves=t.halfmoves,this.fullmoves=t.fullmoves}kingAttackers(t,n,o){return to(t,n,this.board,o)}playCaptureAt(t,n){this.halfmoves=0,n.role==="rook"&&this.castles.discardRook(t),this.pockets&&this.pockets[L(n.color)][n.promoted?"pawn":n.role]++}ctx(){const t=this.isVariantEnd(),n=this.board.kingOf(this.turn);if(!E(n))return{king:n,blockers:m.empty(),checkers:m.empty(),variantEnd:t,mustCapture:!1};const o=vt(n,m.empty()).intersect(this.board.rooksAndQueens()).union(_t(n,m.empty()).intersect(this.board.bishopsAndQueens())).intersect(this.board[L(this.turn)]);let s=m.empty();for(const i of o){const a=Ct(n,i).intersect(this.board.occupied);a.moreThanOne()||(s=s.union(a))}const r=this.kingAttackers(n,L(this.turn),this.board.occupied);return{king:n,blockers:s,checkers:r,variantEnd:t,mustCapture:!1}}clone(){var t,n;const o=new this.constructor;return o.board=this.board.clone(),o.pockets=(t=this.pockets)===null||t===void 0?void 0:t.clone(),o.turn=this.turn,o.castles=this.castles.clone(),o.epSquare=this.epSquare,o.remainingChecks=(n=this.remainingChecks)===null||n===void 0?void 0:n.clone(),o.halfmoves=this.halfmoves,o.fullmoves=this.fullmoves,o}validate(){if(this.board.occupied.isEmpty())return w.err(new pt(Y.Empty));if(this.board.king.size()!==2)return w.err(new pt(Y.Kings));if(!E(this.board.kingOf(this.turn)))return w.err(new pt(Y.Kings));const t=this.board.kingOf(L(this.turn));return E(t)?this.kingAttackers(t,this.turn,this.board.occupied).nonEmpty()?w.err(new pt(Y.OppositeCheck)):m.backranks().intersects(this.board.pawn)?w.err(new pt(Y.PawnsOnBackrank)):w.ok(void 0):w.err(new pt(Y.Kings))}dropDests(t){return m.empty()}dests(t,n){if(n=n||this.ctx(),n.variantEnd)return m.empty();const o=this.board.get(t);if(!o||o.color!==this.turn)return m.empty();let s,r;if(o.role==="pawn"){s=Ot(this.turn,t).intersect(this.board[L(this.turn)]);const i=this.turn==="white"?8:-8,a=t+i;if(0<=a&&a<64&&!this.board.occupied.has(a)){s=s.with(a);const f=this.turn==="white"?t<16:t>=48,h=a+i;f&&!this.board.occupied.has(h)&&(s=s.with(h))}E(this.epSquare)&&so(this,t,n)&&(r=m.fromSquare(this.epSquare))}else o.role==="bishop"?s=_t(t,this.board.occupied):o.role==="knight"?s=Yt(t):o.role==="rook"?s=vt(t,this.board.occupied):o.role==="queen"?s=Ne(t,this.board.occupied):s=Qt(t);if(s=s.diff(this.board[this.turn]),E(n.king)){if(o.role==="king"){const i=this.board.occupied.without(t);for(const a of s)this.kingAttackers(a,L(this.turn),i).nonEmpty()&&(s=s.without(a));return s.union(He(this,"a",n)).union(He(this,"h",n))}if(n.checkers.nonEmpty()){const i=n.checkers.singleSquare();if(!E(i))return m.empty();s=s.intersect(Ct(i,n.king).with(i))}n.blockers.has(t)&&(s=s.intersect(Be(t,n.king)))}return r&&(s=s.union(r)),s}isVariantEnd(){return!1}variantOutcome(t){}hasInsufficientMaterial(t){return this.board[t].intersect(this.board.pawn.union(this.board.rooksAndQueens())).nonEmpty()?!1:this.board[t].intersects(this.board.knight)?this.board[t].size()<=2&&this.board[L(t)].diff(this.board.king).diff(this.board.queen).isEmpty():this.board[t].intersects(this.board.bishop)?(!this.board.bishop.intersects(m.darkSquares())||!this.board.bishop.intersects(m.lightSquares()))&&this.board.pawn.isEmpty()&&this.board.knight.isEmpty():!0}toSetup(){var t,n;return{board:this.board.clone(),pockets:(t=this.pockets)===null||t===void 0?void 0:t.clone(),turn:this.turn,castlingRights:this.castles.castlingRights,epSquare:oo(this),remainingChecks:(n=this.remainingChecks)===null||n===void 0?void 0:n.clone(),halfmoves:Math.min(this.halfmoves,150),fullmoves:Math.min(Math.max(this.fullmoves,1),9999)}}isInsufficientMaterial(){return st.every(t=>this.hasInsufficientMaterial(t))}hasDests(t){t=t||this.ctx();for(const n of this.board[this.turn])if(this.dests(n,t).nonEmpty())return!0;return this.dropDests(t).nonEmpty()}isLegal(t,n){if(Rt(t))return!this.pockets||this.pockets[this.turn][t.role]<=0||t.role==="pawn"&&m.backranks().has(t.to)?!1:this.dropDests(n).has(t.to);{if(t.promotion==="pawn"||t.promotion==="king"&&this.rules!=="antichess"||!!t.promotion!==(this.board.pawn.has(t.from)&&m.backranks().has(t.to)))return!1;const o=this.dests(t.from,n);return o.has(t.to)||o.has(ro(this,t).to)}}isCheck(){const t=this.board.kingOf(this.turn);return E(t)&&this.kingAttackers(t,L(this.turn),this.board.occupied).nonEmpty()}isEnd(t){return(t?t.variantEnd:this.isVariantEnd())?!0:this.isInsufficientMaterial()||!this.hasDests(t)}isCheckmate(t){return t=t||this.ctx(),!t.variantEnd&&t.checkers.nonEmpty()&&!this.hasDests(t)}isStalemate(t){return t=t||this.ctx(),!t.variantEnd&&t.checkers.isEmpty()&&!this.hasDests(t)}outcome(t){const n=this.variantOutcome(t);return n||(t=t||this.ctx(),this.isCheckmate(t)?{winner:L(this.turn)}:this.isInsufficientMaterial()||this.isStalemate(t)?{winner:void 0}:void 0)}allDests(t){t=t||this.ctx();const n=new Map;if(t.variantEnd)return n;for(const o of this.board[this.turn])n.set(o,this.dests(o,t));return n}play(t){const n=this.turn,o=this.epSquare,s=Le(this,t);if(this.epSquare=void 0,this.halfmoves+=1,n==="black"&&(this.fullmoves+=1),this.turn=L(n),Rt(t))this.board.set(t.to,{role:t.role,color:n}),this.pockets&&this.pockets[n][t.role]--,t.role==="pawn"&&(this.halfmoves=0);else{const r=this.board.take(t.from);if(!r)return;let i;if(r.role==="pawn"){this.halfmoves=0,t.to===o&&(i=this.board.take(t.to+(n==="white"?-8:8)));const a=t.from-t.to;Math.abs(a)===16&&8<=t.from&&t.from<=55&&(this.epSquare=t.from+t.to>>1),t.promotion&&(r.role=t.promotion,r.promoted=!!this.pockets)}else if(r.role==="rook")this.castles.discardRook(t.from);else if(r.role==="king"){if(s){const a=this.castles.rook[n][s];if(E(a)){const f=this.board.take(a);this.board.set(Kt(n,s),r),f&&this.board.set(Wt(n,s),f)}}this.castles.discardColor(n)}if(!s){const a=this.board.set(t.to,r)||i;a&&this.playCaptureAt(t.to,a)}}this.remainingChecks&&this.isCheck()&&(this.remainingChecks[n]=Math.max(this.remainingChecks[n]-1,0))}}class It extends eo{constructor(){super("chess")}static default(){const t=new this;return t.reset(),t}static fromSetup(t){const n=new this;return n.setupUnchecked(t),n.validate().map(o=>n)}clone(){return super.clone()}}const no=(e,t)=>{if(!E(t))return;const n=e.turn==="white"?5:2,o=e.turn==="white"?8:-8;if(rt(t)!==n||e.board.occupied.has(t+o))return;const s=t-o;if(!(!e.board.pawn.has(s)||!e.board[L(e.turn)].has(s)))return t},oo=e=>{if(!E(e.epSquare))return;const t=e.ctx(),o=e.board.pieces(e.turn,"pawn").intersect(Ot(L(e.turn),e.epSquare));for(const s of o)if(e.dests(s,t).has(e.epSquare))return e.epSquare},so=(e,t,n)=>{if(!E(e.epSquare)||!Ot(e.turn,t).has(e.epSquare))return!1;if(!E(n.king))return!0;const o=e.turn==="white"?8:-8,s=e.epSquare-o;return e.kingAttackers(n.king,L(e.turn),e.board.occupied.toggle(t).toggle(s).with(e.epSquare)).without(s).isEmpty()},He=(e,t,n)=>{if(!E(n.king)||n.checkers.nonEmpty())return m.empty();const o=e.castles.rook[e.turn][t];if(!E(o)||e.castles.path[e.turn][t].intersects(e.board.occupied))return m.empty();const s=Kt(e.turn,t),r=Ct(n.king,s),i=e.board.occupied.without(n.king);for(const h of r)if(e.kingAttackers(h,L(e.turn),i).nonEmpty())return m.empty();const a=Wt(e.turn,t),f=e.board.occupied.toggle(n.king).toggle(o).toggle(a);return e.kingAttackers(s,L(e.turn),f).nonEmpty()?m.empty():m.fromSquare(o)},Le=(e,t)=>{if(Rt(t))return;const n=t.to-t.from;if(!(Math.abs(n)!==2&&!e.board[e.turn].has(t.to))&&e.board.king.has(t.from))return n>0?"h":"a"},ro=(e,t)=>{const n=Le(e,t);if(!n)return t;const o=e.castles.rook[e.turn][n];return{from:t.from,to:E(o)?o:t.to}};class j{constructor(){}static empty(){const t=new j;for(const n of $)t[n]=0;return t}static fromBoard(t,n){const o=new j;for(const s of $)o[s]=t.pieces(n,s).size();return o}clone(){const t=new j;for(const n of $)t[n]=this[n];return t}equals(t){return $.every(n=>this[n]===t[n])}add(t){const n=new j;for(const o of $)n[o]=this[o]+t[o];return n}subtract(t){const n=new j;for(const o of $)n[o]=this[o]-t[o];return n}nonEmpty(){return $.some(t=>this[t]>0)}isEmpty(){return!this.nonEmpty()}hasPawns(){return this.pawn>0}hasNonPawns(){return this.knight>0||this.bishop>0||this.rook>0||this.queen>0||this.king>0}size(){return this.pawn+this.knight+this.bishop+this.rook+this.queen+this.king}}class at{constructor(t,n){this.white=t,this.black=n}static empty(){return new at(j.empty(),j.empty())}static fromBoard(t){return new at(j.fromBoard(t,"white"),j.fromBoard(t,"black"))}clone(){return new at(this.white.clone(),this.black.clone())}equals(t){return this.white.equals(t.white)&&this.black.equals(t.black)}add(t){return new at(this.white.add(t.white),this.black.add(t.black))}subtract(t){return new at(this.white.subtract(t.white),this.black.subtract(t.black))}count(t){return this.white[t]+this.black[t]}size(){return this.white.size()+this.black.size()}isEmpty(){return this.white.isEmpty()&&this.black.isEmpty()}nonEmpty(){return!this.isEmpty()}hasPawns(){return this.white.hasPawns()||this.black.hasPawns()}hasNonPawns(){return this.white.hasNonPawns()||this.black.hasNonPawns()}}class St{constructor(t,n){this.white=t,this.black=n}static default(){return new St(3,3)}clone(){return new St(this.white,this.black)}equals(t){return this.white===t.white&&this.black===t.black}}var I;(function(e){e.Fen="ERR_FEN",e.Board="ERR_BOARD",e.Pockets="ERR_POCKETS",e.Turn="ERR_TURN",e.Castling="ERR_CASTLING",e.EpSquare="ERR_EP_SQUARE",e.RemainingChecks="ERR_REMAINING_CHECKS",e.Halfmoves="ERR_HALFMOVES",e.Fullmoves="ERR_FULLMOVES"})(I||(I={}));class B extends Error{}const io=(e,t,n)=>{let o=e.indexOf(t);for(;n-- >0&&o!==-1;)o=e.indexOf(t,o+t.length);return o},dt=e=>/^\d{1,4}$/.test(e)?parseInt(e,10):void 0,Fe=e=>{const t=Qn(e);return t&&{role:t,color:e.toLowerCase()===e?"black":"white"}},ee=e=>{const t=ft.empty();let n=7,o=0;for(let s=0;s<e.length;s++){const r=e[s];if(r==="/"&&o===8)o=0,n--;else{const i=parseInt(r,10);if(i>0)o+=i;else{if(o>=8||n<0)return w.err(new B(I.Board));const a=o+n*8,f=Fe(r);if(!f)return w.err(new B(I.Board));e[s+1]==="~"&&(f.promoted=!0,s++),t.set(a,f),o++}}}return n!==0||o!==8?w.err(new B(I.Board)):w.ok(t)},De=e=>{if(e.length>64)return w.err(new B(I.Pockets));const t=at.empty();for(const n of e){const o=Fe(n);if(!o)return w.err(new B(I.Pockets));t[o.color][o.role]++}return w.ok(t)},ao=(e,t)=>{let n=m.empty();if(t==="-")return w.ok(n);for(const o of t){const s=o.toLowerCase(),r=o===s?"black":"white",i=r==="white"?0:7;if("a"<=s&&s<="h")n=n.with(qt(s.charCodeAt(0)-97,i));else if(s==="k"||s==="q"){const a=e[r].intersect(m.backrank(r)).intersect(e.rook.union(e.king)),f=s==="k"?a.last():a.first();n=n.with(E(f)&&e.rook.has(f)?f:qt(s==="k"?7:0,i))}else return w.err(new B(I.Castling))}return st.some(o=>m.backrank(o).intersect(n).size()>2)?w.err(new B(I.Castling)):w.ok(n)},Ge=e=>{const t=e.split("+");if(t.length===3&&t[0]===""){const n=dt(t[1]),o=dt(t[2]);return!E(n)||n>3||!E(o)||o>3?w.err(new B(I.RemainingChecks)):w.ok(new St(3-n,3-o))}else if(t.length===2){const n=dt(t[0]),o=dt(t[1]);return!E(n)||n>3||!E(o)||o>3?w.err(new B(I.RemainingChecks)):w.ok(new St(n,o))}else return w.err(new B(I.RemainingChecks))},ne=e=>{const t=e.split(/[\s_]+/),n=t.shift();let o,s=w.ok(void 0);if(n.endsWith("]")){const a=n.indexOf("[");if(a===-1)return w.err(new B(I.Fen));o=ee(n.slice(0,a)),s=De(n.slice(a+1,-1))}else{const a=io(n,"/",7);a===-1?o=ee(n):(o=ee(n.slice(0,a)),s=De(n.slice(a+1)))}let r;const i=t.shift();if(!E(i)||i==="w")r="white";else if(i==="b")r="black";else return w.err(new B(I.Turn));return o.chain(a=>{const f=t.shift(),h=E(f)?ao(a,f):w.ok(m.empty()),c=t.shift();let p;if(E(c)&&c!=="-"&&(p=ht(c),!E(p)))return w.err(new B(I.EpSquare));let l=t.shift(),k;E(l)&&l.includes("+")&&(k=Ge(l),l=t.shift());const v=E(l)?dt(l):0;if(!E(v))return w.err(new B(I.Halfmoves));const C=t.shift(),_=E(C)?dt(C):1;if(!E(_))return w.err(new B(I.Fullmoves));const P=t.shift();let A=w.ok(void 0);if(E(P)){if(E(k))return w.err(new B(I.RemainingChecks));A=Ge(P)}else E(k)&&(A=k);return t.length>0?w.err(new B(I.Fen)):s.chain(S=>h.chain(M=>A.map(O=>({board:a,pockets:S,turn:r,castlingRights:M,remainingChecks:O,epSquare:p,halfmoves:v,fullmoves:Math.max(1,_)}))))})},co=e=>{let t=kt(e.role);return e.color==="white"&&(t=t.toUpperCase()),e.promoted&&(t+="~"),t},uo=e=>{let t="",n=0;for(let o=7;o>=0;o--)for(let s=0;s<8;s++){const r=s+o*8,i=e.get(r);i?(n>0&&(t+=n,n=0),t+=co(i)):n++,s===7&&(n>0&&(t+=n,n=0),o!==0&&(t+="/"))}return t},Ve=e=>$.map(t=>kt(t).repeat(e[t])).join(""),lo=e=>Ve(e.white).toUpperCase()+Ve(e.black),ho=(e,t)=>{let n="";for(const o of st){const s=m.backrank(o);let r=e.kingOf(o);E(r)&&!s.has(r)&&(r=void 0);const i=e.pieces(o,"rook").intersect(s);for(const a of t.intersect(s).reversed())if(a===i.first()&&E(r)&&a<r)n+=o==="white"?"Q":"q";else if(a===i.last()&&E(r)&&r<a)n+=o==="white"?"K":"k";else{const f=Pt[G(a)];n+=o==="white"?f.toUpperCase():f}}return n||"-"},fo=e=>`${e.white}+${e.black}`,po=(e,t)=>[uo(e.board)+(e.pockets?`[${lo(e.pockets)}]`:""),e.turn[0],ho(e.board,e.castlingRights),E(e.epSquare)?Mt(e.epSquare):"-",...e.remainingChecks?[fo(e.remainingChecks)]:[],Math.max(0,Math.min(e.halfmoves,9999)),Math.max(1,Math.min(e.fullmoves,9999))].join(" "),mo=(e,t)=>{let n="";if(Rt(t))t.role!=="pawn"&&(n=kt(t.role).toUpperCase()),n+="@"+Mt(t.to);else{const o=e.board.getRole(t.from);if(!o)return"--";if(o==="king"&&(e.board[e.turn].has(t.to)||Math.abs(t.to-t.from)===2))n=t.to>t.from?"O-O":"O-O-O";else{const s=e.board.occupied.has(t.to)||o==="pawn"&&G(t.from)!==G(t.to);if(o!=="pawn"){n=kt(o).toUpperCase();let r;if(o==="king"?r=Qt(t.to).intersect(e.board.king):o==="queen"?r=Ne(t.to,e.board.occupied).intersect(e.board.queen):o==="rook"?r=vt(t.to,e.board.occupied).intersect(e.board.rook):o==="bishop"?r=_t(t.to,e.board.occupied).intersect(e.board.bishop):r=Yt(t.to).intersect(e.board.knight),r=r.intersect(e.board[e.turn]).without(t.from),r.nonEmpty()){const i=e.ctx();for(const a of r)e.dests(a,i).has(t.to)||(r=r.without(a));if(r.nonEmpty()){let a=!1,f=r.intersects(m.fromRank(rt(t.from)));r.intersects(m.fromFile(G(t.from)))?a=!0:f=!0,f&&(n+=Pt[G(t.from)]),a&&(n+=Ie[rt(t.from)])}}}else s&&(n=Pt[G(t.from)]);s&&(n+="x"),n+=Mt(t.to),t.promotion&&(n+="="+kt(t.promotion).toUpperCase())}}return n},go=(e,t)=>{var n;const o=mo(e,t);return e.play(t),!((n=e.outcome())===null||n===void 0)&&n.winner?o+"#":e.isCheck()?o+"+":o},yo=(e,t)=>go(e.clone(),t);function Nt(e){return/^[a-h][1-8]$/.test(e)}function Bt(e){const t=Mt(e);if(!Nt(t))throw new Error(`ChessMatch: unexpected square encoding ${e}`);return t}function dr(e){return e}function $e(e,t){return{square:Bt(t),role:e.role,color:e.color}}function bo(e,t,n){const o=e&7,s=t&7;if(Math.abs(s-o)!==2)return null;const r=n==="white"?"1":"8";return s>o?{rookFrom:`h${r}`,rookTo:`f${r}`}:{rookFrom:`a${r}`,rookTo:`d${r}`}}function ko(e,t,n){if(e.board.get(t))return Bt(t);if(n.role!=="pawn"||e.epSquare===void 0||e.epSquare!==t)return null;const o=n.color==="white"?t-8:t+8;return Bt(o)}function _o(e,t,n){const o=ht(t),s=ht(n);if(o===void 0||s===void 0)return null;const r=e.board.get(o);if(!r||r.color!==e.turn)return null;const i={from:o,to:s},a=s>>3;return r.role==="pawn"&&(a===0||a===7)&&(i.promotion="queen"),e.isLegal(i)?i:null}class X{constructor(t){D(this,"position");this.position=t}static starting(){return new X(It.default())}static fromFen(t){const n=ne(t);if(n.isErr)throw new Error(`ChessMatch.fromFen: invalid FEN (${t})`);const o=It.fromSetup(n.value);if(o.isErr)throw new Error(`ChessMatch.fromFen: illegal setup (${t})`);return new X(o.value)}fen(){return po(this.position.toSetup())}sideToMove(){return this.position.turn}isCheck(){return this.position.isCheck()}isCheckmate(){return this.position.isCheckmate()}isStalemate(){return this.position.isStalemate()}isEnd(){return this.position.isEnd()}pieceAt(t){const n=ht(t);if(n===void 0)return null;const o=this.position.board.get(n);return o?$e(o,n):null}pieces(){const t=[];for(const[n,o]of this.position.board)t.push($e(o,n));return t}legalSquares(t){const n=ht(t);if(n===void 0)return[];const o=this.position.board.get(n);if(!o||o.color!==this.position.turn)return[];const s=new Set;for(const r of this.position.dests(n))s.add(Bt(r));if(o.role==="king"){const r=o.color==="white"?"1":"8";for(const i of["c","g"]){const a=`${i}${r}`;if(!Nt(a))continue;const f=ht(a);f!==void 0&&this.position.isLegal({from:n,to:f})&&s.add(a)}}return[...s]}legalMoves(){const t=this.sideToMove(),n=[];for(const o of this.pieces())if(o.color===t)for(const s of this.legalSquares(o.square))n.push({from:o.square,to:s});return n}tryMove(t,n){if(!Nt(t)||!Nt(n))return{ok:!1,reason:"invalid-square"};if(this.position.isEnd())return{ok:!1,reason:"game-over"};const o=_o(this.position,t,n);if(!o)return{ok:!1,reason:"illegal"};const s=o.from,r=o.to,i=this.position.board.get(s);if(!i)return{ok:!1,reason:"illegal"};const a=ko(this.position,r,i),f=i.role==="king"?bo(s,r,i.color):null,h=o.promotion?o.promotion:null,c=yo(this.position,o);return this.position.play(o),{ok:!0,from:t,to:n,san:c,capturedSquare:a,castle:f,promotion:h}}reset(){this.position=It.default()}loadFen(t){const n=ne(t);if(n.isErr)return!1;const o=It.fromSetup(n.value);return o.isErr?!1:(this.position=o.value,!0)}moveFromSan(t){const n=t.trim().replace(/[+#]$/,"");if(!n)return null;const o=this.fen();for(const s of this.legalMoves()){const i=X.fromFen(o).tryMove(s.from,s.to);if(i.ok&&i.san.replace(/[+#]$/,"")===n)return s}return null}}const vo={pawn:100,knight:320,bishop:330,rook:500,queen:900,king:0};function Co(e){if(e.isCheckmate())return-1e4;if(e.isStalemate())return 0;let t=0;for(const n of e.pieces()){const o=vo[n.role];t+=n.color==="white"?o:-o}return e.isCheck()&&(t+=e.sideToMove()==="white"?-25:25),e.sideToMove()==="white"?t:-t}function Ue(e,t){const n=e.legalMoves();if(t<=0||n.length===0||e.isEnd())return{score:Co(e),move:null};let o=-1/0,s=n[0]??null;const r=e.fen();for(const i of n){const a=X.fromFen(r);if(!a.tryMove(i.from,i.to).ok)continue;const f=-Ue(a,t-1).score;f>o&&(o=f,s=i)}return{score:o,move:s}}class So{constructor(t={}){D(this,"depth");D(this,"thinkMs");this.depth=Math.max(1,Math.floor(t.depth??2)),this.thinkMs=Math.max(0,t.thinkMs??280)}async chooseMove(t){this.thinkMs>0&&await new Promise(o=>{setTimeout(o,this.thinkMs)});const n=X.fromFen(t);return n.isEnd()?null:Ue(n,this.depth).move}}function xe(e){return typeof e=="string"&&/^[a-h][1-8]$/.test(e)}function wo(e){return new TextEncoder().encode(JSON.stringify(e))}function Eo(e){let t;try{t=JSON.parse(new TextDecoder().decode(e))}catch{return null}if(!t||typeof t!="object")return null;const n=t;return n.v!==1||typeof n.fen!="string"?null:n.t==="reset"||n.t==="sync"?{v:1,t:n.t,fen:n.fen}:n.t==="move"&&xe(n.from)&&xe(n.to)?{v:1,t:"move",from:n.from,to:n.to,fen:n.fen}:null}function oe(e){const t=ne(e);if(t.isErr)return null;const n=t.value.fullmoves;return!Number.isFinite(n)||n<1?null:(n-1)*2+(t.value.turn==="black"?1:0)}function Ao(e,t){const n=oe(t);if(n===null)return"ignore";const o=oe(e);return o===null||n>o?"apply":n<o?"reply":"ignore"}function Po(e){const t=new URLSearchParams(e.startsWith("?")?e.slice(1):e),n=(t.get("chess")??"cpu").toLowerCase(),o=n==="hotseat"||n==="local"?"hotseat":n==="p2p"?"p2p":n==="learn"||n==="eco"||n==="train"?"learn":"cpu",r=(t.get("chessColor")??"white").toLowerCase()==="black"?"black":"white",i=(t.get("chessEco")??t.get("eco")??"").trim(),a=(t.get("chessQuiz")??"").toLowerCase();return{mode:o,localColor:r,...i?{eco:i}:{},quiz:a==="1"||a==="true"||a==="yes"}}const Ro=["chess","chessColor","chessEco","eco","chessQuiz"];function Ht(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const t=e,n=typeof t.mode=="string"?t.mode.toLowerCase():"",o=n==="hotseat"||n==="local"?"hotseat":n==="p2p"?"p2p":n==="learn"||n==="eco"||n==="train"?"learn":n==="cpu"?"cpu":null;if(!o)return null;const r=(typeof t.localColor=="string"?t.localColor.toLowerCase():"white")==="black"?"black":"white",i=typeof t.eco=="string"?t.eco.trim():"";return{mode:o,localColor:r,...i?{eco:i}:{},quiz:t.quiz===!0}}function je(e){const t={};return e.mode!=="cpu"&&(t.chess=e.mode),e.localColor!=="white"&&(t.chessColor=e.localColor),e.mode==="learn"&&(e.eco&&(t.chessEco=e.eco),e.quiz&&(t.chessQuiz="1")),t}function qe(e,t){const n=new URLSearchParams(e.startsWith("?")?e.slice(1):e);for(const o of Ro)n.delete(o);for(const[o,s]of Object.entries(je(t)))n.set(o,s);return n.toString()}function Mo(e){if(typeof window>"u")return;const t=qe(window.location.search,e),n=t.length>0?`?${t}`:"";window.history.replaceState(null,"",`${window.location.pathname}${n}${window.location.hash}`)}function To(e){const t=Math.max(0,Math.ceil(e)),n=Math.floor(t/60),o=t%60;return`${n}:${o.toString().padStart(2,"0")}`}const Oo="w3dts-chess-hud-state",Io="w3dts-chess-hud-command";function Lt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function se(e){return e==="white"||e==="black"?e:null}function No(e){return e==="cpu"||e==="hotseat"||e==="p2p"?e:null}function Bo(e){return e===null?null:We(e)}function ct(e){return typeof e=="string"&&e.length>0?e:null}function Ft(e,t=0){return typeof e=="number"&&Number.isFinite(e)?e:t}function Ho(e){return e==="done"||e==="current"||e==="future"?e:null}function Lo(e){if(!Lt(e))return null;const t=ct(e.san),n=Ho(e.status);return!t||!n?null:{san:t,status:n,hidden:e.hidden===!0}}function Ke(e){return e.replace(/[+#]$/,"")}function We(e){return e==="waiting"||e==="connecting"||e==="connected"||e==="disconnected"?e:e==="degraded"?"connected":"waiting"}function Fo(e){return`You are ${e}. Second tab: chess=p2p&chessColor=${e==="white"?"black":"white"}`}function Do(e,t,n){const o=Math.max(0,Math.min(t,e.length));return e.map((s,r)=>{const i=r<o?"done":r===o?"current":"future";return{san:Ke(s),status:i,hidden:n&&i!=="done"}})}function Go(e){const t=No(e.mode),n=ct(e.label),o=ct(e.title),s=typeof e.description=="string"?e.description:"",r=se(e.localColor),i=se(e.sideToMove);if(!t||!n||!o||!r||!i)return null;const a=Lt(e.clocks)?e.clocks:{},f=e.flag===null||e.flag===void 0?null:se(e.flag);return e.flag!==null&&e.flag!==void 0&&f===null?null:{kind:"play",mode:t,label:n,title:o,description:s,localColor:r,sideToMove:i,cpuThinking:e.cpuThinking===!0,p2pStatus:t==="p2p"?Bo(e.p2pStatus):null,clocks:{whiteSeconds:Math.max(0,Ft(a.whiteSeconds)),blackSeconds:Math.max(0,Ft(a.blackSeconds))},flag:f,session:Ht(e.session)??{mode:t,localColor:r,quiz:!1}}}function Vo(e){const t=ct(e.label),n=ct(e.title),o=ct(e.eco),s=ct(e.openingName);if(!t||!n||!o||!s)return null;const r=e.plies,i=Array.isArray(r)?r.map(Lo).filter(a=>a!==null):[];return{kind:"learn",label:t,title:n,description:typeof e.description=="string"?e.description:"",eco:o,openingName:s,plyIndex:Math.max(0,Ft(e.plyIndex)),plyCount:Math.max(0,Ft(e.plyCount)),quiz:e.quiz===!0,miss:e.miss===!0,complete:e.complete===!0,coachBusy:e.coachBusy===!0,plies:i,session:Ht(e.session)??{mode:"learn",localColor:"white",eco:o,quiz:e.quiz===!0}}}function $o(e){return Lt(e)?e.kind==="play"?Go(e):e.kind==="learn"?Vo(e):null:null}function Uo(e){if(!Lt(e))return null;if(e.type==="mode-picker")return{type:"mode-picker",open:e.open===!0};if(e.type==="apply-session"){const t=Ht(e.session);return t?{type:"apply-session",session:t}:null}return e.type==="request-state"?{type:"request-state"}:null}const Qe=[{eco:"C50",name:"Italian Game",sans:["e4","e5","Nf3","Nc6","Bc4","Bc5"]},{eco:"C60",name:"Ruy Lopez",sans:["e4","e5","Nf3","Nc6","Bb5","a6"]},{eco:"C44",name:"Scotch Game",sans:["e4","e5","Nf3","Nc6","d4","exd4"]},{eco:"B20",name:"Sicilian Defence",sans:["e4","c5","Nf3","d6","d4","cxd4"]},{eco:"C00",name:"French Defence",sans:["e4","e6","d4","d5"]},{eco:"B10",name:"Caro-Kann Defence",sans:["e4","c6","d4","d5"]},{eco:"D06",name:"Queen's Gambit",sans:["d4","d5","c4","e6"]},{eco:"E60",name:"King's Indian Defence",sans:["d4","Nf6","c4","g6"]}];function re(e){return e.toLowerCase().replace(/['’]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function Ye(e,t){if(!t)return 0;const n=t.trim().toLowerCase();if(!n)return 0;const o=e.findIndex(i=>i.eco.toLowerCase()===n);if(o>=0)return o;const s=e.findIndex(i=>re(i.name)===re(n));if(s>=0)return s;const r=e.findIndex(i=>i.name.toLowerCase().includes(n));return r>=0?r:0}function Xe(e){const t=X.starting(),n=[];for(const o of e.sans){const s=t.moveFromSan(o);if(!s)throw new Error(`OpeningTrainer: cannot play ${o} in ${e.eco} ${e.name}`);const r=t.tryMove(s.from,s.to);if(!r.ok)throw new Error(`OpeningTrainer: illegal ${o} in ${e.eco} ${e.name}`);n.push({from:s.from,to:s.to,san:r.san})}return n}class xo{constructor(t,n=Qe){D(this,"catalog");D(this,"index");D(this,"plies",[]);D(this,"ply",0);this.catalog=n,this.index=Ye(n,t),this.reload()}opening(){return this.catalog[this.index]??this.catalog[0]}plyIndex(){return this.ply}plyCount(){return this.plies.length}isComplete(){return this.ply>=this.plies.length}expected(){return this.plies[this.ply]??null}isBookMove(t,n){const o=this.expected();return!!(o&&o.from===t&&o.to===n)}accept(t,n){return this.isBookMove(t,n)?(this.ply+=1,!0):!1}restart(){this.ply=0}nextOpening(){return this.index=(this.index+1)%this.catalog.length,this.reload(),this.opening()}reload(){const t=this.opening();this.plies=Xe(t),this.ply=0}}const U=.06,mt=U*8,Z=.06,Dt=1-2*Z,q=mt/Dt,ut=.002,wt=.024,V=.001,Ze=3.5,jo="abcdefgh";function qo(e){return/^[a-h][1-8]$/.test(e)}function J(e,t=V){const n=e.charCodeAt(0)-97,o=e.charCodeAt(1)-49,s=(n-Ze)*U,r=(o-Ze)*U;return y.vec3.fromValues(s,t,r)}function ie(e,t){const n=mt/2;if(e<-n||e>=n||t<-n||t>=n)return null;const o=Math.floor((e+n)/U),s=Math.floor((t+n)/U);if(o<0||o>7||s<0||s>7)return null;const r=`${jo[o]}${s+1}`;return qo(r)?r:null}function Ko(e,t,n=V){const o=ie(e,t);return o?J(o,n):null}const Wo="abcdefgh",Qo="12345678";function Je(){return(mt+q)/4}function Yo(){return(q-mt)/2*(2/3)}const ze=V+.0016;function Xo(e){const t=Je(),n=-t,o=t,s=e==="white"?[n,o]:[o,n],r=-t,i=t,a=e==="white"?[r,i]:[i,r],f=[];for(const h of s){const c=h<0?180:0;for(let p=0;p<8;p++){const l=Wo[p],k=J(`${l}1`);f.push({glyph:l,kind:"file",x:k[0],y:ze,z:h,yawDeg:c})}}for(const h of a){const c=h<0?-90:90;for(let p=0;p<8;p++){const l=Qo[p],k=J(`a${l}`);f.push({glyph:l,kind:"rank",x:h,y:ze,z:k[2],yawDeg:c})}}return f}function Zo(e,t=y.vec3.create()){return y.vec3.set(t,e.x,e.y,e.z)}function Jo(e,t=y.quat.create()){return y.quat.fromEuler(t,-90,e.yawDeg,0)}const zo=5,ts=7,es={a:[".###.","#...#","#####","#...#","#...#","#...#","#...#"],b:["####.","#...#","####.","#...#","#...#","#...#","####."],c:[".####","#....","#....","#....","#....","#....",".####"],d:["####.","#...#","#...#","#...#","#...#","#...#","####."],e:["#####","#....","####.","#....","#....","#....","#####"],f:["#####","#....","####.","#....","#....","#....","#...."],g:[".####","#....","#....","#.###","#...#","#...#",".####"],h:["#...#","#...#","#####","#...#","#...#","#...#","#...#"],1:["..#..",".##..","..#..","..#..","..#..","..#..",".###."],2:[".###.","#...#","....#","..##.",".#...","#....","#####"],3:[".###.","#...#","....#","..##.","....#","#...#",".###."],4:["#...#","#...#","#...#","#####","....#","....#","....#"],5:["#####","#....","####.","....#","....#","#...#",".###."],6:[".###.","#....","#....","####.","#...#","#...#",".###."],7:["#####","....#","...#.","..#..","..#..","..#..","..#.."],8:[".###.","#...#","#...#",".###.","#...#","#...#",".###."]},ae={r:14,g:10,b:8},ce={r:228,g:214,b:176},ue={r:248,g:238,b:214},tn=128,ns='"Palatino Linotype", Palatino, "Book Antiqua", "Iowan Old Style", Georgia, "Times New Roman", serif';function os(e,t){var i,a,f,h;const n=new Float32Array(t*t),o=es[e];if(!o)return n;const s=t*.18,r=t-s*2;for(let c=0;c<t;c++)for(let p=0;p<t;p++){const l=(p+.5-s)/r,k=(c+.5-s)/r;if(l<0||k<0||l>=1||k>=1)continue;const v=l*zo-.5,C=k*ts-.5,_=Math.floor(v),P=Math.floor(C),A=v-_,S=C-P,M=((i=o[P])==null?void 0:i[_])==="#"?1:0,O=((a=o[P])==null?void 0:a[_+1])==="#"?1:0,x=((f=o[P+1])==null?void 0:f[_])==="#"?1:0,K=((h=o[P+1])==null?void 0:h[_+1])==="#"?1:0;n[c*t+p]=M*(1-A)*(1-S)+O*A*(1-S)+x*(1-A)*S+K*A*S}return n}function ss(e,t){try{const n=typeof OffscreenCanvas<"u"?new OffscreenCanvas(t,t):typeof document<"u"?document.createElement("canvas"):null;if(!n)return null;n.width=t,n.height=t;const o=n.getContext("2d",{willReadFrequently:!0});if(!o)return null;o.clearRect(0,0,t,t),o.fillStyle="#000",o.strokeStyle="#000",o.textAlign="center",o.textBaseline="alphabetic";const s=Math.round(t*.58);o.font=`600 ${s}px ${ns}`;const r=o.measureText(e),i=r.actualBoundingBoxAscent||s*.7,a=r.actualBoundingBoxDescent||s*.2,f=(t+i-a)*.5,h=t*.5;o.lineJoin="round",o.lineCap="round",o.lineWidth=Math.max(2,t*.055),o.strokeText(e,h,f),o.fillText(e,h,f);const c=o.getImageData(0,0,t,t),p=new Float32Array(t*t),l=c.data;for(let k=0;k<t*t;k++)p[k]=(l[k*4+3]??0)/255;return p}catch{return null}}function z(e,t,n,o){return n<0||o<0||n>=t||o>=t?0:e[o*t+n]??0}function en(e,t){const n=new Float32Array(t*t);for(let o=0;o<t;o++)for(let s=0;s<t;s++){let r=0;for(let i=-1;i<=1;i++)for(let a=-1;a<=1;a++)r+=z(e,t,s+a,o+i);n[o*t+s]=r/9}return n}function rs(e,t,n){const o=new Float32Array(t*t);for(let s=0;s<t;s++)for(let r=0;r<t;r++){let i=0;for(let a=-n;a<=n;a++)for(let f=-n;f<=n;f++){const h=z(e,t,r+f,s+a);h>i&&(i=h)}o[s*t+r]=i}return o}function le(e){return e<0?0:e>1?1:e}function he(e,t,n){const o=le((n-e)/(t-e));return o*o*(3-2*o)}function is(e,t){const n=new Uint8ClampedArray(t*t*4),o=en(e,t),s=en(rs(e,t,Math.max(1,Math.round(t*.028))),t);for(let r=0;r<t;r++)for(let i=0;i<t;i++){const a=z(s,t,i,r);if(a<.03)continue;const f=z(o,t,i,r),h=z(s,t,i+1,r)-z(s,t,i-1,r),c=z(s,t,i,r+1)-z(s,t,i,r-1),p=Math.hypot(h,c),l=p>1e-5?h/p:0,k=p>1e-5?c/p:0,v=-(l*.42+k*.9),C=he(.04,.28,a),_=he(.12,.55,f),P=C*(1-_),A=he(.04,.5,p),S=le(v)*A*P,M=Math.max(P*(.4+.4*le(-v)),P*(1-_)*.22),O=(r*t+i)*4,x=ae.r*M+ce.r*_*(1-S)+ue.r*S,K=ae.g*M+ce.g*_*(1-S)+ue.g*S,bt=ae.b*M+ce.b*_*(1-S)+ue.b*S;n[O]=Math.round(Math.min(255,x)),n[O+1]=Math.round(Math.min(255,K)),n[O+2]=Math.round(Math.min(255,bt)),n[O+3]=Math.round(Math.min(255,C*255))}return n}function as(e,t=tn){const n=ss(e,t)??os(e,t);return is(n,t)}function nn(e){return e.charCodeAt(0)-97}function on(e){return e.charCodeAt(1)-49}function cs(e,t,n){return[(e-3.5)*U,n,(t-3.5)*U]}function sn(e,t){const n=nn(e),o=on(e),s=nn(t)-n,r=on(t)-o;return Math.abs(s)===2?{file:n+s,rank:o}:{file:n,rank:o+r}}function rn(e,t,n,o){const s=Math.sin(Math.PI*n);return[e[0]+(t[0]-e[0])*n,V+o*s,e[2]+(t[2]-e[2])*n]}function an(e,t,n,o,s){const r=[],i=s?1:0;for(let a=i;a<n;a++)r.push(rn(e,t,a/(n-1),o));return r}function us(e,t,n={}){const o=n.liftY??.028,s=Math.max(8,n.samples??20),r=J(e,V),i=J(t,V),a=[r[0],r[1],r[2]],f=[i[0],i[1],i[2]];if(!n.knight){const l=[];for(let k=0;k<s;k++)l.push(rn(a,f,k/(s-1),o));return l}const h=sn(e,t),c=cs(h.file,h.rank,V),p=Math.max(5,Math.ceil(s/2));return[...an(a,c,p,o*.75,!1),...an(c,f,p,o*.75,!0)]}function ls(e){let t=0;for(let n=1;n<e.length;n++){const o=e[n],s=e[n-1];t+=Math.hypot(o[0]-s[0],o[1]-s[1],o[2]-s[2])}return t}function fe(e){const t=Math.min(1,Math.max(0,e));return t*t*(3-2*t)}const pe=.042;function hs(e,t,n,o=pe){const s=J(e,V),r=J(t,V),i=fe(n),a=Math.sin(Math.PI*i);return[s[0]+(r[0]-s[0])*i,V+o*a,s[2]+(r[2]-s[2])*i]}function fs(e,t,n){const o=fe(n),s=Math.sin(Math.PI*o),r=Math.max(.012,Math.abs(t[1]-e[1])+pe*.35);return[e[0]+(t[0]-e[0])*o,e[1]+(t[1]-e[1])*o+r*s,e[2]+(t[2]-e[2])*o]}const ps=U*.7,ds=U*.52;function ms(e,t){const n=q/2,s=(e==="white"?-1:1)*(n+ps),r=-mt/2+U*.15;return{x:s,y:V,z:r+t*ds}}function gs(e){return ie(e.x,e.z)===null}function ys(e){const t=[];return t.push(e.captured?"capture":"drop"),e.mate?(t.push(e.localWon?"win":"lose"),t):(e.check&&t.push("check"),t)}const cn=1,Gt=2,bs=Gt,un=cn|Gt,ln=0,de=96,hn=[[0,.018],[.005,.018],[.007,.012],[.02,.0075],[.026,.01],[.03,.008],[.034,.012],[.042,.014],[.05,.01],[.054,.002]],ks=[[0,.019],[.006,.019],[.01,.014],[.038,.013],[.042,.017],[.05,.017]],_s=[[0,.018],[.005,.018],[.008,.011],[.028,.008],[.036,.013],[.05,.011],[.058,.006],[.062,.001]],vs=[[0,.02],[.006,.02],[.01,.012],[.034,.009],[.042,.015],[.058,.013],[.066,.008],[.07,.002]],Cs=[[0,.021],[.006,.021],[.01,.013],[.036,.01],[.044,.016],[.062,.014],[.07,.01],[.074,.004]],Ss=[[.014,-.012],[.014,.006],[.022,.012],[.03,.015],[.034,.02],[.038,.018],[.036,.012],[.032,.008],[.04,.006],[.05,.008],[.056,.004],[.06,.002],[.054,-.004],[.048,-.01],[.036,-.014],[.024,-.014]],ws=[[0,.018],[.006,.018],[.01,.012],[.014,.01]];function tt(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function me(e,t){return Math.hypot(t[0]-e[0],t[1]-e[1])}function fn(e,t){let n=e.map(s=>[s[0],s[1]]);const o=Math.max(0,Math.floor(t));for(let s=0;s<o&&!(n.length<2);s++){const r=[n[0]];for(let i=0;i<n.length-1;i++){const a=n[i],f=n[i+1];r.push(tt(a,f,.25)),r.push(tt(a,f,.75))}r.push(n[n.length-1]),n=r}return n}function Es(e,t,n,o,s){const a=0+Math.pow(me(e,t),.5),f=a+Math.pow(me(t,n),.5),h=f+Math.pow(me(n,o),.5),c=f-a;if(c<1e-12)return[t[0],t[1]];const p=a+s*c,l=tt(e,t,(p-0)/Math.max(a-0,1e-12)),k=tt(t,n,(p-a)/Math.max(f-a,1e-12)),v=tt(n,o,(p-f)/Math.max(h-f,1e-12)),C=tt(l,k,(p-0)/Math.max(f-0,1e-12)),_=tt(k,v,(p-a)/Math.max(h-a,1e-12));return tt(C,_,(p-a)/Math.max(f-a,1e-12))}function As(e,t){const n=e.length;if(n<3)return e.map(r=>[r[0],r[1]]);const o=Math.max(1,Math.floor(t)),s=[];for(let r=0;r<n;r++){const i=e[(r+n-1)%n],a=e[r],f=e[(r+1)%n],h=e[(r+2)%n];for(let c=0;c<o;c++)s.push(Es(i,a,f,h,c/o))}return s}function pn(e){return fn(e,2).map(([t,n])=>[n,t,0])}function Ps(e){let t=0;for(let n=0;n<e.length;n++){const o=(n+1)%e.length;t+=e[n][0]*e[o][1]-e[o][0]*e[n][1]}return t}function Rs(e=6){const t=As(Ss,e);return(Ps(t)>=0?t:[...t].reverse()).map(([o,s])=>[0,o,s])}const dn=.022;function T(e,t,n,o,s){return{id:e,type:t,position:{x:n,y:o},...s}}function R(e,t,n,o,s){return{id:e,fromNodeId:t,fromSocketId:n,toNodeId:o,toSocketId:s}}function H(){return[{id:"geometry",name:"geometry",type:"geometry"}]}function Ms(e){switch(e){case"pawn":return hn;case"rook":return ks;case"bishop":return _s;case"queen":return vs;case"king":return Cs}}function Ts(e){switch(e){case"pawn":return[];case"rook":return[{size:[.012,.012,.012],center:[.015,.054,0]},{size:[.012,.012,.012],center:[-.015,.054,0]},{size:[.012,.012,.012],center:[0,.054,.015]},{size:[.012,.012,.012],center:[0,.054,-.015]}];case"bishop":return[{size:[.003,.02,.02],center:[0,.05,0]}];case"queen":{const n=[];for(let o=0;o<8;o++){const s=o/8*Math.PI*2;n.push({size:[.004,.012,.004],center:[Math.cos(s)*.011,.072,Math.sin(s)*.011]})}return n}case"king":return[{size:[.004,.02,.004],center:[0,.082,0]},{size:[.016,.004,.004],center:[0,.086,0]}]}}function Os(e){return e!=="knight"}function mn(e){const t=Ts(e),n=[T("in","GroupInput",40,80,{inputs:[],outputs:[{id:"scale",name:"Scale",type:"float"}],properties:{Scale:1}}),T("poly","PrimitivePolyline",280,80,{inputs:[],outputs:H(),properties:{points:pn(Ms(e))}}),T("lathe","Lathe",520,80,{inputs:[{id:"curve",name:"curve",type:"geometry"}],outputs:H(),properties:{segments:de,axis:[0,1,0],origin:[0,0,0],startAngle:0,endAngle:Math.PI*2,fillCaps:!0}})],o=[R("l_poly","poly","geometry","lathe","curve")];t.forEach((r,i)=>{const a=`cube${i}`;n.push(T(a,"PrimitiveCube",520,200+i*80,{inputs:[],outputs:H(),properties:{size:r.size,center:r.center}}))});let s="lathe";if(t.length>0){const r=[{id:"g0",name:"g0",type:"geometry"},...t.map((i,a)=>({id:`g${a+1}`,name:`g${a+1}`,type:"geometry"}))];n.push(T("join","JoinGeometry",760,80,{inputs:r,outputs:H(),properties:{}})),o.push(R("l_join0","lathe","geometry","join","g0")),t.forEach((i,a)=>{o.push(R(`l_join${a+1}`,`cube${a}`,"geometry","join",`g${a+1}`))}),s="join"}return n.push(T("shade","SetShadeSmooth",1e3,80,{inputs:[{id:"geo",name:"geometry",type:"geometry"},{id:"angle",name:"angle",type:"float"}],outputs:H(),properties:{angle:60}}),T("bake","BakeMeshMaps",1120,80,{inputs:[{id:"geometry",name:"geometry",type:"geometry"}],outputs:H(),properties:{bakeCurvature:!0,bakeAO:!0,bakeHeight:!0,curvatureContrast:3.2,aoRadius:.012,aoSamples:8,heightScale:1}}),T("scale3","CombineVector",280,240,{inputs:[{id:"x",name:"x",type:"float"},{id:"y",name:"y",type:"float"},{id:"z",name:"z",type:"float"}],outputs:[{id:"vector",name:"vector",type:"vec3"}],properties:{x:1,y:1,z:1}}),T("xform","TransformGeometry",1360,80,{inputs:[{id:"geo",name:"geometry",type:"geometry"},{id:"t",name:"translation",type:"vec3"},{id:"r",name:"rotation",type:"vec3"},{id:"s",name:"scale",type:"vec3"}],outputs:H(),properties:{translation:[0,0,0],rotation:[0,0,0],scale:[1,1,1]}}),T("out","GroupOutput",1600,80,{inputs:[{id:"geo_in",name:"geometry",type:"geometry"}],outputs:[]})),o.push(R("l_shade",s,"geometry","shade","geo"),R("l_bake","shade","geometry","bake","geometry"),R("l_sx","in","scale","scale3","x"),R("l_sy","in","scale","scale3","y"),R("l_sz","in","scale","scale3","z"),R("l_xf_geo","bake","geometry","xform","geo"),R("l_xf_s","scale3","vector","xform","s"),R("l_out","xform","geometry","out","geo_in")),{id:`chess_${e}`,version:1,metadata:{category:"prop",subcategory:"chess"},parameters:{Scale:{type:"float",value:1}},nodes:n,links:o}}const Is=[.007,.014,.007],Ns=[[.005,.058,0],[-.005,.058,0]];function gn(){const e=[T("in","GroupInput",40,80,{inputs:[],outputs:[{id:"scale",name:"Scale",type:"float"}],properties:{Scale:1}}),T("pedestal","PrimitivePolyline",280,40,{inputs:[],outputs:H(),properties:{points:pn(ws)}}),T("lathe","Lathe",520,40,{inputs:[{id:"curve",name:"curve",type:"geometry"}],outputs:H(),properties:{segments:de,axis:[0,1,0],origin:[0,0,0],startAngle:0,endAngle:Math.PI*2,fillCaps:!0}}),T("silhouette","PrimitivePolyline",280,220,{inputs:[],outputs:H(),properties:{points:Rs(),fill:!0}}),T("extrude","ExtrudeMesh",520,220,{inputs:[{id:"geometry",name:"geometry",type:"geometry"}],outputs:H(),properties:{offset:dn,scale:1}}),T("center","TransformGeometry",760,220,{inputs:[{id:"geo",name:"geometry",type:"geometry"},{id:"t",name:"translation",type:"vec3"},{id:"r",name:"rotation",type:"vec3"},{id:"s",name:"scale",type:"vec3"}],outputs:H(),properties:{translation:[-.011,0,0],rotation:[0,0,0],scale:[1,1,1]}})],t=[R("l_ped","pedestal","geometry","lathe","curve"),R("l_sil","silhouette","geometry","extrude","geometry"),R("l_ctr","extrude","geometry","center","geo")];return Ns.forEach((n,o)=>{const s=`ear${o}`;e.push(T(s,"PrimitiveCube",520,360+o*80,{inputs:[],outputs:H(),properties:{size:Is,center:n}}))}),e.push(T("join","JoinGeometry",1e3,80,{inputs:[{id:"g0",name:"g0",type:"geometry"},{id:"g1",name:"g1",type:"geometry"},{id:"g2",name:"g2",type:"geometry"},{id:"g3",name:"g3",type:"geometry"}],outputs:H(),properties:{}}),T("shade","SetShadeSmooth",1240,80,{inputs:[{id:"geo",name:"geometry",type:"geometry"},{id:"angle",name:"angle",type:"float"}],outputs:H(),properties:{angle:60}}),T("bake","BakeMeshMaps",1360,80,{inputs:[{id:"geometry",name:"geometry",type:"geometry"}],outputs:H(),properties:{bakeCurvature:!0,bakeAO:!0,bakeHeight:!0,curvatureContrast:3.2,aoRadius:.012,aoSamples:8,heightScale:1}}),T("scale3","CombineVector",280,400,{inputs:[{id:"x",name:"x",type:"float"},{id:"y",name:"y",type:"float"},{id:"z",name:"z",type:"float"}],outputs:[{id:"vector",name:"vector",type:"vec3"}],properties:{x:1,y:1,z:1}}),T("xform","TransformGeometry",1600,80,{inputs:[{id:"geo",name:"geometry",type:"geometry"},{id:"t",name:"translation",type:"vec3"},{id:"r",name:"rotation",type:"vec3"},{id:"s",name:"scale",type:"vec3"}],outputs:H(),properties:{translation:[0,0,0],rotation:[0,0,0],scale:[1,1,1]}}),T("out","GroupOutput",1840,80,{inputs:[{id:"geo_in",name:"geometry",type:"geometry"}],outputs:[]})),t.push(R("l_join0","lathe","geometry","join","g0"),R("l_join1","center","geometry","join","g1"),R("l_join2","ear0","geometry","join","g2"),R("l_join3","ear1","geometry","join","g3"),R("l_shade","join","geometry","shade","geo"),R("l_bake","shade","geometry","bake","geometry"),R("l_sx","in","scale","scale3","x"),R("l_sy","in","scale","scale3","y"),R("l_sz","in","scale","scale3","z"),R("l_xf_geo","bake","geometry","xform","geo"),R("l_xf_s","scale3","vector","xform","s"),R("l_out","xform","geometry","out","geo_in")),{id:"chess_knight",version:1,metadata:{category:"prop",subcategory:"chess"},parameters:{Scale:{type:"float",value:1}},nodes:e,links:t}}let yn=!1;function bn(){yn||(W.bootstrapGProcRuntime({initCsg:!1}),yn=!0)}function Vt(e,t,n){bn();const o=W.GProcExecutor.executeDetailed(e,t);if(!o.ok||!o.geometry){const i=o.errors.map(a=>a.message).join("; ")||"no geometry";throw new Error(`GPROC ${e.id}: ${i}`)}const s=W.geometrySetToEngineMesh(o.geometry,1),r=s?W.engineMeshToPreviewBuffers(s):null;if(!r)throw new Error(`GPROC ${e.id}: empty engine mesh`);return new F.Mesh(r.vertices,r.indices,n)}function Bs(e,t=.012){bn();const n=W.meshToGeometrySet(e);if(!n)return e;const o=W.bakeMeshMapsOnGeometrySet(n,{aoRadius:t,aoSamples:8,curvatureContrast:3.2,bakeCurvature:!0,bakeAO:!0,bakeHeight:!0}),s=W.geometrySetToEngineMesh(o,1),r=s?W.engineMeshToPreviewBuffers(s):null;return r?new F.Mesh(r.vertices,r.indices,e.name):e}const Hs=F.STANDARD_MESH_VERTEX_FLOATS,Ls=y.vec3.fromValues(0,1,0),Fs=y.vec3.fromValues(1,0,0);function kn(e){let t=0;for(let n=0;n<e.length;n++){const o=(n+1)%e.length;t+=e[n][0]*e[o][1]-e[o][0]*e[n][1]}return t*.5}function Et(e,t,n,o,s,r){return(n-e)*(r-t)-(o-t)*(s-e)}function Ds(e,t,n,o){const s=Et(t[0],t[1],n[0],n[1],e[0],e[1]),r=Et(n[0],n[1],o[0],o[1],e[0],e[1]),i=Et(o[0],o[1],t[0],t[1],e[0],e[1]),a=s<0||r<0||i<0,f=s>0||r>0||i>0;return!(a&&f)}function Gs(e){const t=e.length;if(t<3)return[];const n=Array.from({length:t},(i,a)=>a),o=kn(e)>=0,s=[];let r=0;for(;n.length>3&&r++<t*t;){let i=!1;for(let a=0;a<n.length;a++){const f=n[(a+n.length-1)%n.length],h=n[a],c=n[(a+1)%n.length],p=e[f],l=e[h],k=e[c],v=Et(p[0],p[1],l[0],l[1],k[0],k[1]);if(o?v<=0:v>=0)continue;let C=!1;for(const _ of n)if(!(_===f||_===h||_===c)&&Ds(e[_],p,l,k)){C=!0;break}if(!C){s.push(o?[f,h,c]:[f,c,h]),n.splice(a,1),i=!0;break}}if(!i)break}if(n.length===3){const[i,a,f]=n;if(i!==void 0&&a!==void 0&&f!==void 0){const h=e[i],c=e[a],p=e[f],l=Et(h[0],h[1],c[0],c[1],p[0],p[1]);s.push(l>=0?[i,a,f]:[i,f,a])}}return s}class _n{constructor(){D(this,"verts",[]);D(this,"indices",[])}get vertexCount(){return this.verts.length/Hs}addVertex(t,n,o,s,r,i,a,f,h){const c=y.vec3.fromValues(i,a,f),p=y.vec3.length(c)||1;y.vec3.scale(c,c,1/p);const l=y.vec3.create();h?y.vec3.set(l,h[0],h[1],h[2]):y.vec3.cross(l,Math.abs(c[1])>.95?Fs:Ls,c),y.vec3.normalize(l,l);const k=y.vec3.create();y.vec3.cross(k,c,l);const v=this.vertexCount;return this.verts.push(t,n,o,s,r,s,r,c[0],c[1],c[2],l[0],l[1],l[2],k[0],k[1],k[2],1,1,1,1),v}addTri(t,n,o){this.indices.push(t,n,o)}addConvexPolygon(t,n){if(t.length<3)return;const o=t[0],s=t[1],r=t[2],i=s[0]-o[0],a=s[1]-o[1],f=s[2]-o[2],h=r[0]-o[0],c=r[1]-o[1],p=r[2]-o[2],l=a*p-f*c,k=f*h-i*p,v=i*c-a*h,C=l*n[0]+k*n[1]+v*n[2]<0,_=Math.hypot(l,k,v)||1,P=C?[-l/_,-k/_,-v/_]:[l/_,k/_,v/_],A=t.map((S,M)=>{const O=t.length===4?M===1||M===2?1:0:M/t.length,x=t.length===4&&M>=2?1:0;return this.addVertex(S[0],S[1],S[2],O,x,P[0],P[1],P[2])});for(let S=1;S<A.length-1;S++)C?this.addTri(A[0],A[S+1],A[S]):this.addTri(A[0],A[S],A[S+1])}addChamferedBox(t,n,o,s,r,i,a){const f=Math.min(a,s*.45,r*.45,i*.45),h=s-f,c=r-f,p=i-f,l=(k,v,C)=>[t+k,n+v,o+C];this.addConvexPolygon([l(-h,r,p),l(h,r,p),l(h,r,-p),l(-h,r,-p)],[0,1,0]),this.addConvexPolygon([l(-h,-r,-p),l(h,-r,-p),l(h,-r,p),l(-h,-r,p)],[0,-1,0]),this.addConvexPolygon([l(s,-c,p),l(s,-c,-p),l(s,c,-p),l(s,c,p)],[1,0,0]),this.addConvexPolygon([l(-s,-c,-p),l(-s,-c,p),l(-s,c,p),l(-s,c,-p)],[-1,0,0]),this.addConvexPolygon([l(-h,-c,i),l(h,-c,i),l(h,c,i),l(-h,c,i)],[0,0,1]),this.addConvexPolygon([l(h,-c,-i),l(-h,-c,-i),l(-h,c,-i),l(h,c,-i)],[0,0,-1]),this.addConvexPolygon([l(-h,r,p),l(h,r,p),l(h,c,i),l(-h,c,i)],[0,1,1]),this.addConvexPolygon([l(h,r,-p),l(-h,r,-p),l(-h,c,-i),l(h,c,-i)],[0,1,-1]),this.addConvexPolygon([l(-h,-c,i),l(h,-c,i),l(h,-r,p),l(-h,-r,p)],[0,-1,1]),this.addConvexPolygon([l(h,-c,-i),l(-h,-c,-i),l(-h,-r,-p),l(h,-r,-p)],[0,-1,-1]),this.addConvexPolygon([l(h,r,p),l(h,r,-p),l(s,c,-p),l(s,c,p)],[1,1,0]),this.addConvexPolygon([l(-h,r,-p),l(-h,r,p),l(-s,c,p),l(-s,c,-p)],[-1,1,0]),this.addConvexPolygon([l(h,-r,-p),l(h,-r,p),l(s,-c,p),l(s,-c,-p)],[1,-1,0]),this.addConvexPolygon([l(-h,-r,p),l(-h,-r,-p),l(-s,-c,-p),l(-s,-c,p)],[-1,-1,0]),this.addConvexPolygon([l(s,c,p),l(s,-c,p),l(h,-c,i),l(h,c,i)],[1,0,1]),this.addConvexPolygon([l(s,-c,-p),l(s,c,-p),l(h,c,-i),l(h,-c,-i)],[1,0,-1]),this.addConvexPolygon([l(-s,-c,p),l(-s,c,p),l(-h,c,i),l(-h,-c,i)],[-1,0,1]),this.addConvexPolygon([l(-s,c,-p),l(-s,-c,-p),l(-h,-c,-i),l(-h,c,-i)],[-1,0,-1]),this.addConvexPolygon([l(h,r,p),l(s,c,p),l(h,c,i)],[1,1,1]),this.addConvexPolygon([l(h,r,-p),l(h,c,-i),l(s,c,-p)],[1,1,-1]),this.addConvexPolygon([l(-h,r,p),l(-h,c,i),l(-s,c,p)],[-1,1,1]),this.addConvexPolygon([l(-h,r,-p),l(-s,c,-p),l(-h,c,-i)],[-1,1,-1]),this.addConvexPolygon([l(h,-r,p),l(h,-c,i),l(s,-c,p)],[1,-1,1]),this.addConvexPolygon([l(h,-r,-p),l(s,-c,-p),l(h,-c,-i)],[1,-1,-1]),this.addConvexPolygon([l(-h,-r,p),l(-s,-c,p),l(-h,-c,i)],[-1,-1,1]),this.addConvexPolygon([l(-h,-r,-p),l(-h,-c,-i),l(-s,-c,-p)],[-1,-1,-1])}addBox(t,n,o,s,r,i){const a=[{n:[0,0,1],corners:[[t-s,n-r,o+i],[t+s,n-r,o+i],[t+s,n+r,o+i],[t-s,n+r,o+i]]},{n:[0,0,-1],corners:[[t+s,n-r,o-i],[t-s,n-r,o-i],[t-s,n+r,o-i],[t+s,n+r,o-i]]},{n:[1,0,0],corners:[[t+s,n-r,o+i],[t+s,n-r,o-i],[t+s,n+r,o-i],[t+s,n+r,o+i]]},{n:[-1,0,0],corners:[[t-s,n-r,o-i],[t-s,n-r,o+i],[t-s,n+r,o+i],[t-s,n+r,o-i]]},{n:[0,1,0],corners:[[t-s,n+r,o+i],[t+s,n+r,o+i],[t+s,n+r,o-i],[t-s,n+r,o-i]]},{n:[0,-1,0],corners:[[t-s,n-r,o-i],[t+s,n-r,o-i],[t+s,n-r,o+i],[t-s,n-r,o+i]]}];for(const f of a){const h=[[0,0],[1,0],[1,1],[0,1]],c=f.corners.map((p,l)=>this.addVertex(p[0],p[1],p[2],h[l][0],h[l][1],f.n[0],f.n[1],f.n[2]));this.addTri(c[0],c[1],c[2]),this.addTri(c[0],c[2],c[3])}}addLathe(t,n=20){if(t.length<2)return;const o=[];for(let r=0;r<t.length;r++){const i=t[r][0],a=t[r][1],f=t[Math.max(0,r-1)],h=t[Math.min(t.length-1,r+1)],c=h[0]-f[0];let l=-(h[1]-f[1]),k=c;const v=Math.hypot(l,k)||1;l/=v,k/=v;const C=[],_=r/(t.length-1);for(let P=0;P<=n;P++){const A=P/n,S=A*Math.PI*2,M=Math.cos(S)*a,O=Math.sin(S)*a,x=a>1e-6?Math.cos(S)*k:0,K=a>1e-6?Math.sin(S)*k:0,bt=Math.hypot(-O,M)||1;C.push(this.addVertex(M,i,O,A,_,x,l,K,[-O/bt,0,M/bt]))}o.push(C)}for(let r=0;r<o.length-1;r++){const i=o[r],a=o[r+1];for(let f=0;f<n;f++)this.addTri(i[f],a[f],a[f+1]),this.addTri(i[f],a[f+1],i[f+1])}const s=(r,i,a,f)=>{if(a<1e-5)return;const h=this.addVertex(0,i,0,.5,.5,0,f?1:-1,0);for(let c=0;c<n;c++)f?this.addTri(h,r[c+1],r[c]):this.addTri(h,r[c],r[c+1])};s(o[0],t[0][0],t[0][1],!1),s(o[o.length-1],t[t.length-1][0],t[t.length-1][1],!0)}addExtrudedYz(t,n){if(t.length<3)return;const o=kn(t)>=0?[...t]:[...t].reverse(),s=o.length,r=[],i=[],a=[],f=[];for(let c=0;c<s;c++){const p=o[c][0],l=o[c][1],k=o[(c+s-1)%s],v=o[(c+1)%s],C=v[0]-k[0],P=v[1]-k[1],A=-C,S=c/s;r.push(this.addVertex(-n,p,l,0,S,0,P,A)),i.push(this.addVertex(n,p,l,1,S,0,P,A)),a.push(this.addVertex(-n,p,l,.25,S,-1,0,0)),f.push(this.addVertex(n,p,l,.75,S,1,0,0))}for(let c=0;c<s;c++){const p=(c+1)%s;this.addTri(r[c],r[p],i[p]),this.addTri(r[c],i[p],i[c])}const h=Gs(o);for(const[c,p,l]of h)this.addTri(f[c],f[p],f[l]),this.addTri(a[c],a[l],a[p])}toMesh(t){const n=new Float32Array(this.verts),o=this.indices.length>65535?new Uint32Array(this.indices):new Uint16Array(this.indices);return new F.Mesh(n,o,t)}}function Vs(){const e=new _n;return e.addLathe(fn(hn,2),de),e.toMesh("chess-pawn-uv")}function $s(e){return e==="knight"?Vt(gn(),{Scale:1},"chess-knight"):Vt(mn(e),{Scale:1},`chess-${e}`)}function Us(e){switch(e){case"pawn":return .054;case"rook":return .06;case"knight":return .062;case"bishop":return .062;case"queen":return .078;case"king":return .092;default:return .054}}const At=F.STANDARD_MESH_VERTEX_FLOATS,ge=7,ye=10,be=13;function xs(e){const t=e.vertices,n=e.indices,o=e.aabb.min[1]??0,s=e.aabb.max[1]??1,r=Math.max(1e-6,s-o),i=new Float32Array(n.length*At),a=n.length>65535?new Uint32Array(n.length):new Uint16Array(n.length);for(let f=0;f<n.length;f+=3){const h=[n[f],n[f+1],n[f+2]],c=[];for(const k of h){const v=k*At,C=t[v],_=t[v+1],P=t[v+2];let A=Math.atan2(P,C)/(Math.PI*2);A<0&&(A+=1),C*C+P*P<1e-10&&(A=.5),c.push([A,(_-o)/r])}const p=Math.min(c[0][0],c[1][0],c[2][0]);if(Math.max(c[0][0],c[1][0],c[2][0])-p>.5)for(const k of c)k[0]<.5&&(k[0]+=1);for(let k=0;k<3;k++){const v=h[k]*At,C=f+k,_=C*At;i.set(t.subarray(v,v+At),_);const P=c[k][0],A=c[k][1];i[_+3]=P,i[_+4]=A,i[_+5]=P,i[_+6]=A;const S=t[v],M=t[v+2],O=Math.hypot(-M,S);if(O>1e-6){const x=-M/O,K=S/O;i[_+ye]=x,i[_+ye+1]=0,i[_+ye+2]=K;const bt=i[_+ge],$n=i[_+ge+1],hr=i[_+ge+2];let Un=$n*K,xn=hr*x-bt*K,jn=-$n*x;const Re=Math.hypot(Un,xn,jn)||1;i[_+be]=Un/Re,i[_+be+1]=xn/Re,i[_+be+2]=jn/Re}a[C]=C}}return new F.Mesh(i,a,e.name)}function vn(){return{id:"chess_board",version:1,metadata:{category:"prop",subcategory:"chess"},parameters:{ExtentXz:{type:"float",value:q},Height:{type:"float",value:wt},Bevel:{type:"float",value:ut}},nodes:[{id:"in",type:"GroupInput",position:{x:40,y:80},inputs:[],outputs:[{id:"extentXz",name:"ExtentXz",type:"float"},{id:"height",name:"Height",type:"float"},{id:"bevel",name:"Bevel",type:"float"}],properties:{ExtentXz:q,Height:wt,Bevel:ut}},{id:"bevel2",type:"Math",position:{x:280,y:200},inputs:[{id:"a",name:"a",type:"float"},{id:"b",name:"b",type:"float"}],outputs:[{id:"value",name:"value",type:"float"}],properties:{operation:"MUL",a:0,b:2}},{id:"outer",type:"Math",position:{x:480,y:80},inputs:[{id:"a",name:"a",type:"float"},{id:"b",name:"b",type:"float"}],outputs:[{id:"value",name:"value",type:"float"}],properties:{operation:"ADD",a:0,b:0}},{id:"size",type:"CombineVector",position:{x:680,y:80},inputs:[{id:"x",name:"x",type:"float"},{id:"y",name:"y",type:"float"},{id:"z",name:"z",type:"float"}],outputs:[{id:"vector",name:"vector",type:"vec3"}],properties:{x:0,y:0,z:0}},{id:"box",type:"PrimitiveChamferedBox",position:{x:900,y:80},inputs:[{id:"size",name:"size",type:"vec3"},{id:"center",name:"center",type:"vec3"},{id:"bevel",name:"bevel",type:"float"}],outputs:[{id:"geometry",name:"geometry",type:"geometry"}],properties:{size:[q+2*ut,wt,q+2*ut],center:[0,0,0],bevel:ut}},{id:"bake",type:"BakeMeshMaps",position:{x:1140,y:80},inputs:[{id:"geometry",name:"geometry",type:"geometry"}],outputs:[{id:"geometry",name:"geometry",type:"geometry"}],properties:{bakeCurvature:!0,bakeAO:!0,bakeHeight:!0,curvatureContrast:2.8,aoRadius:.04,aoSamples:8,heightScale:1}},{id:"out",type:"GroupOutput",position:{x:1380,y:80},inputs:[{id:"geo_in",name:"geometry",type:"geometry"}],outputs:[]}],links:[{id:"l_bevel",fromNodeId:"in",fromSocketId:"bevel",toNodeId:"bevel2",toSocketId:"a"},{id:"l_extent",fromNodeId:"in",fromSocketId:"extentXz",toNodeId:"outer",toSocketId:"a"},{id:"l_bevel2",fromNodeId:"bevel2",fromSocketId:"value",toNodeId:"outer",toSocketId:"b"},{id:"l_outer_x",fromNodeId:"outer",fromSocketId:"value",toNodeId:"size",toSocketId:"x"},{id:"l_height",fromNodeId:"in",fromSocketId:"height",toNodeId:"size",toSocketId:"y"},{id:"l_outer_z",fromNodeId:"outer",fromSocketId:"value",toNodeId:"size",toSocketId:"z"},{id:"l_size",fromNodeId:"size",fromSocketId:"vector",toNodeId:"box",toSocketId:"size"},{id:"l_box_bevel",fromNodeId:"in",fromSocketId:"bevel",toNodeId:"box",toSocketId:"bevel"},{id:"l_bake",fromNodeId:"box",fromSocketId:"geometry",toNodeId:"bake",toSocketId:"geometry"},{id:"l_out",fromNodeId:"bake",fromSocketId:"geometry",toNodeId:"out",toSocketId:"geo_in"}]}}const js=F.STANDARD_MESH_VERTEX_FLOATS;function Cn(e){const t=e.vertices;for(let n=0;n<t.length;n+=js){const o=t[n],s=t[n+1],r=t[n+2],i=t[n+7],a=t[n+8],f=t[n+9],h=Math.abs(i),c=Math.abs(a),p=Math.abs(f);let l,k,v,C,_;c>=h&&c>=p?(l=o,k=r,v=1,C=0,_=0):h>=p?(l=r,k=s,v=0,C=0,_=1):(l=o,k=s,v=1,C=0,_=0),t[n+3]=l,t[n+4]=k,t[n+5]=l,t[n+6]=k;const P=v*i+C*a+_*f;let A=v-P*i,S=C-P*a,M=_-P*f;const O=Math.hypot(A,S,M)||1;A/=O,S/=O,M/=O,t[n+10]=A,t[n+11]=S,t[n+12]=M,t[n+13]=a*M-f*S,t[n+14]=f*A-i*M,t[n+15]=i*S-a*A}return e}function qs(e=q,t=wt,n=ut){return Cn(Vt(vn(),{ExtentXz:e,Height:t,Bevel:n},"ChessBoardBody"))}const Sn="MarbleProceduralPBR",wn="BrushedSteelProceduralPBR";function u(e,t,n){return{id:e,name:t,dataType:n}}function b(e,t,n,o,s){return{id:e,type:t,stage:"fragment",position:{x:n,y:o},...s}}function g(e,t,n,o){return{fromNodeId:e,fromSocketId:t,toNodeId:n,toSocketId:o}}function Ks(){return Ws()}function Ws(){const e={seed:{name:"Seed",type:"f32",defaultValue:11},triplanarScale:{name:"Triplanar Scale",type:"f32",defaultValue:2.4},aoStrength:{name:"AO Strength",type:"f32",defaultValue:.22},heightInfluence:{name:"Height Roughness",type:"f32",defaultValue:.02},normalDetailScale:{name:"Normal Detail Scale",type:"f32",defaultValue:0},baseColor:{name:"Marble Color",type:"vec3f",defaultValue:[.84,.78,.68]},accentColor:{name:"Rust Vein",type:"vec3f",defaultValue:[.45,.28,.2]},wearColor:{name:"Grey Vein",type:"vec3f",defaultValue:[.4,.38,.36]},edgeWear:{name:"Edge Wear",type:"f32",defaultValue:.04},roughness:{name:"Roughness",type:"f32",defaultValue:.22},metallic:{name:"Metallic",type:"f32",defaultValue:0},opacity:{name:"Opacity",type:"f32",defaultValue:1}},t=[b("pbr_master","PBRMasterNode",1680,200,{inputs:[u("albedo","Albedo","vec4f"),u("opacity","Opacity","f32"),u("normal","Normal","vec3f"),u("roughness_factor","Roughness F","f32"),u("metallic_factor","Metallic F","f32")],outputs:[]}),b("obj_pos","GetObjectPosition",0,0,{inputs:[],outputs:[u("pos","Position","vec3f")]}),b("prop_scale","Property",180,80,{data:{propertyName:"triplanarScale"},inputs:[],outputs:[u("out","Out","f32")]}),b("prop_seed","Property",180,160,{data:{propertyName:"seed"},inputs:[],outputs:[u("out","Out","f32")]}),b("marble_fn","CustomFunction",380,40,{data:{functionName:"marble_look"},inputs:[u("pos","Position","vec3f"),u("seed","Seed","f32"),u("scale","Scale","f32")],outputs:[u("out","Look","vec4f")]}),b("split_mar","SplitVec4",560,40,{inputs:[u("in","In","vec4f")],outputs:[u("x","Rust","f32"),u("y","Grey","f32"),u("z","Cloud","f32"),u("w","Rough","f32")]}),b("vertex_color","VertexColor",0,280,{inputs:[],outputs:[u("color","Color","vec4f")]}),b("mesh_maps","MeshMaps",220,280,{inputs:[u("color","Vertex Color","vec4f")],outputs:[u("concavity","Concavity","f32"),u("convexity","Convexity","f32"),u("ao","AO","f32"),u("height","Height","f32")]}),b("world_n","GetWorldNormal",0,520,{inputs:[],outputs:[u("norm","Normal","vec3f")]}),b("prop_base","Property",760,160,{data:{propertyName:"baseColor"},inputs:[],outputs:[u("out","Out","vec3f")]}),b("prop_accent","Property",760,240,{data:{propertyName:"accentColor"},inputs:[],outputs:[u("out","Out","vec3f")]}),b("prop_wear","Property",760,320,{data:{propertyName:"wearColor"},inputs:[],outputs:[u("out","Out","vec3f")]}),b("cloud_k","ConstantFloat",760,400,{data:{value:.22},inputs:[],outputs:[u("out","Out","f32")]}),b("cloud_amt","Multiply",980,120,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("lerp_cloud","Lerp",1140,80,{inputs:[u("a","A","vec3f"),u("b","B","vec3f"),u("t","T","f32")],outputs:[u("out","Out","vec3f")]}),b("lerp_grey","Lerp",1140,200,{inputs:[u("a","A","vec3f"),u("b","B","vec3f"),u("t","T","f32")],outputs:[u("out","Out","vec3f")]}),b("lerp_rust","Lerp",1140,320,{inputs:[u("a","A","vec3f"),u("b","B","vec3f"),u("t","T","f32")],outputs:[u("out","Out","vec3f")]}),b("prop_ao_str","Property",1140,440,{data:{propertyName:"aoStrength"},inputs:[],outputs:[u("out","Out","f32")]}),b("one","ConstantFloat",1140,520,{data:{value:1},inputs:[],outputs:[u("out","Out","f32")]}),b("ao_mix","Lerp",1320,400,{inputs:[u("a","A","f32"),u("b","B","f32"),u("t","T","f32")],outputs:[u("out","Out","f32")]}),b("mul_ao_color","Multiply",1480,200,{inputs:[u("a","A","vec3f"),u("b","B","f32")],outputs:[u("out","Out","vec3f")]}),b("prop_edge","Property",1140,600,{data:{propertyName:"edgeWear"},inputs:[],outputs:[u("out","Out","f32")]}),b("wear_amt","Multiply",1320,560,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("lerp_wear","Lerp",1480,320,{inputs:[u("a","A","vec3f"),u("b","B","vec3f"),u("t","T","f32")],outputs:[u("out","Out","vec3f")]}),b("split_alb","SplitVec3",1480,80,{inputs:[u("in","In","vec3f")],outputs:[u("x","X","f32"),u("y","Y","f32"),u("z","Z","f32")]}),b("prop_opacity","Property",1480,640,{data:{propertyName:"opacity"},inputs:[],outputs:[u("out","Out","f32")]}),b("alb_rgba","Combine",1600,80,{inputs:[u("r","R","f32"),u("g","G","f32"),u("b","B","f32"),u("a","A","f32")],outputs:[u("out","Out","vec4f")]}),b("prop_rough","Property",1140,720,{data:{propertyName:"roughness"},inputs:[],outputs:[u("out","Out","f32")]}),b("add_rough","Add",1320,720,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("cavity_k","ConstantFloat",1140,840,{data:{value:.08},inputs:[],outputs:[u("out","Out","f32")]}),b("cavity_rough","Multiply",1320,800,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("add_cavity_r","Add",1480,720,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("clamp_rough","Clamp",1600,720,{inputs:[u("in","In","f32"),u("min","Min","f32"),u("max","Max","f32")],outputs:[u("out","Out","f32")]}),b("zero","ConstantFloat",1480,880,{data:{value:0},inputs:[],outputs:[u("out","Out","f32")]}),b("prop_metal","Property",1480,960,{data:{propertyName:"metallic"},inputs:[],outputs:[u("out","Out","f32")]})],n=[g("obj_pos","pos","marble_fn","pos"),g("prop_seed","out","marble_fn","seed"),g("prop_scale","out","marble_fn","scale"),g("marble_fn","out","split_mar","in"),g("vertex_color","color","mesh_maps","color"),g("split_mar","z","cloud_amt","a"),g("cloud_k","out","cloud_amt","b"),g("prop_base","out","lerp_cloud","a"),g("prop_wear","out","lerp_cloud","b"),g("cloud_amt","out","lerp_cloud","t"),g("lerp_cloud","out","lerp_grey","a"),g("prop_wear","out","lerp_grey","b"),g("split_mar","y","lerp_grey","t"),g("lerp_grey","out","lerp_rust","a"),g("prop_accent","out","lerp_rust","b"),g("split_mar","x","lerp_rust","t"),g("one","out","ao_mix","a"),g("mesh_maps","ao","ao_mix","b"),g("prop_ao_str","out","ao_mix","t"),g("lerp_rust","out","mul_ao_color","a"),g("ao_mix","out","mul_ao_color","b"),g("mesh_maps","convexity","wear_amt","a"),g("prop_edge","out","wear_amt","b"),g("mul_ao_color","out","lerp_wear","a"),g("prop_base","out","lerp_wear","b"),g("wear_amt","out","lerp_wear","t"),g("lerp_wear","out","split_alb","in"),g("split_alb","x","alb_rgba","r"),g("split_alb","y","alb_rgba","g"),g("split_alb","z","alb_rgba","b"),g("prop_opacity","out","alb_rgba","a"),g("prop_rough","out","add_rough","a"),g("split_mar","w","add_rough","b"),g("mesh_maps","concavity","cavity_rough","a"),g("cavity_k","out","cavity_rough","b"),g("add_rough","out","add_cavity_r","a"),g("cavity_rough","out","add_cavity_r","b"),g("add_cavity_r","out","clamp_rough","in"),g("zero","out","clamp_rough","min"),g("one","out","clamp_rough","max"),g("alb_rgba","out","pbr_master","albedo"),g("prop_opacity","out","pbr_master","opacity"),g("world_n","norm","pbr_master","normal"),g("clamp_rough","out","pbr_master","roughness_factor"),g("prop_metal","out","pbr_master","metallic_factor")];return{id:Sn,properties:e,nodes:t,connections:n}}function Qs(){const e={seed:{name:"Seed",type:"f32",defaultValue:7},triplanarScale:{name:"Triplanar Scale",type:"f32",defaultValue:1.4},aoStrength:{name:"AO Strength",type:"f32",defaultValue:.32},heightInfluence:{name:"Height Roughness",type:"f32",defaultValue:.02},normalDetailScale:{name:"Normal Detail Scale",type:"f32",defaultValue:0},baseColor:{name:"Steel Color",type:"vec3f",defaultValue:[.17,.185,.2]},accentColor:{name:"Brush Highlight",type:"vec3f",defaultValue:[.4,.42,.45]},wearColor:{name:"Blotch Color",type:"vec3f",defaultValue:[.1,.105,.115]},edgeWear:{name:"Edge Wear",type:"f32",defaultValue:.05},roughness:{name:"Roughness",type:"f32",defaultValue:.42},metallic:{name:"Metallic",type:"f32",defaultValue:.96},opacity:{name:"Opacity",type:"f32",defaultValue:1},anisotropy:{name:"Anisotropy",type:"f32",defaultValue:.88},anisotropyRotation:{name:"Anisotropy Rotation",type:"f32",defaultValue:0}},t=[b("pbr_master","PBRMasterNode",1680,200,{inputs:[u("albedo","Albedo","vec4f"),u("opacity","Opacity","f32"),u("normal","Normal","vec3f"),u("roughness_factor","Roughness F","f32"),u("metallic_factor","Metallic F","f32"),u("anisotropy","Anisotropy","f32"),u("anisotropy_rotation","Anisotropy Rot","f32")],outputs:[]}),b("obj_pos","GetObjectPosition",0,0,{inputs:[],outputs:[u("pos","Position","vec3f")]}),b("prop_scale","Property",180,80,{data:{propertyName:"triplanarScale"},inputs:[],outputs:[u("out","Out","f32")]}),b("prop_seed","Property",180,160,{data:{propertyName:"seed"},inputs:[],outputs:[u("out","Out","f32")]}),b("steel_look","CustomFunction",380,40,{data:{functionName:"brushed_steel_look"},inputs:[u("pos","Position","vec3f"),u("seed","Seed","f32"),u("scale","Scale","f32")],outputs:[u("out","Look","vec4f")]}),b("split_steel","SplitVec4",560,40,{inputs:[u("in","In","vec4f")],outputs:[u("x","Grain","f32"),u("y","Blotch","f32"),u("z","Bump","f32"),u("w","Rough","f32")]}),b("vertex_color","VertexColor",0,280,{inputs:[],outputs:[u("color","Color","vec4f")]}),b("mesh_maps","MeshMaps",220,280,{inputs:[u("color","Vertex Color","vec4f")],outputs:[u("concavity","Concavity","f32"),u("convexity","Convexity","f32"),u("ao","AO","f32"),u("height","Height","f32")]}),b("world_n","GetWorldNormal",0,520,{inputs:[],outputs:[u("norm","Normal","vec3f")]}),b("prop_base","Property",760,200,{data:{propertyName:"baseColor"},inputs:[],outputs:[u("out","Out","vec3f")]}),b("prop_accent","Property",760,280,{data:{propertyName:"accentColor"},inputs:[],outputs:[u("out","Out","vec3f")]}),b("prop_wear","Property",760,360,{data:{propertyName:"wearColor"},inputs:[],outputs:[u("out","Out","vec3f")]}),b("lerp_grain","Lerp",980,160,{inputs:[u("a","A","vec3f"),u("b","B","vec3f"),u("t","T","f32")],outputs:[u("out","Out","vec3f")]}),b("blotch_k","ConstantFloat",760,440,{data:{value:.38},inputs:[],outputs:[u("out","Out","f32")]}),b("blotch_amt","Multiply",980,360,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("lerp_blotch","Lerp",1140,200,{inputs:[u("a","A","vec3f"),u("b","B","vec3f"),u("t","T","f32")],outputs:[u("out","Out","vec3f")]}),b("prop_ao_str","Property",1140,320,{data:{propertyName:"aoStrength"},inputs:[],outputs:[u("out","Out","f32")]}),b("one","ConstantFloat",1140,400,{data:{value:1},inputs:[],outputs:[u("out","Out","f32")]}),b("ao_mix","Lerp",1320,280,{inputs:[u("a","A","f32"),u("b","B","f32"),u("t","T","f32")],outputs:[u("out","Out","f32")]}),b("mul_ao_color","Multiply",1480,200,{inputs:[u("a","A","vec3f"),u("b","B","f32")],outputs:[u("out","Out","vec3f")]}),b("prop_edge","Property",1140,480,{data:{propertyName:"edgeWear"},inputs:[],outputs:[u("out","Out","f32")]}),b("wear_amt","Multiply",1320,440,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("lerp_wear","Lerp",1480,320,{inputs:[u("a","A","vec3f"),u("b","B","vec3f"),u("t","T","f32")],outputs:[u("out","Out","vec3f")]}),b("split_alb","SplitVec3",1480,80,{inputs:[u("in","In","vec3f")],outputs:[u("x","X","f32"),u("y","Y","f32"),u("z","Z","f32")]}),b("prop_opacity","Property",1480,560,{data:{propertyName:"opacity"},inputs:[],outputs:[u("out","Out","f32")]}),b("alb_rgba","Combine",1600,80,{inputs:[u("r","R","f32"),u("g","G","f32"),u("b","B","f32"),u("a","A","f32")],outputs:[u("out","Out","vec4f")]}),b("prop_rough","Property",1140,640,{data:{propertyName:"roughness"},inputs:[],outputs:[u("out","Out","f32")]}),b("add_rough","Add",1320,640,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("cavity_k","ConstantFloat",1140,800,{data:{value:.1},inputs:[],outputs:[u("out","Out","f32")]}),b("cavity_rough","Multiply",1320,760,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("add_cavity_r","Add",1480,640,{inputs:[u("a","A","f32"),u("b","B","f32")],outputs:[u("out","Out","f32")]}),b("clamp_rough","Clamp",1600,640,{inputs:[u("in","In","f32"),u("min","Min","f32"),u("max","Max","f32")],outputs:[u("out","Out","f32")]}),b("zero","ConstantFloat",1480,800,{data:{value:0},inputs:[],outputs:[u("out","Out","f32")]}),b("prop_metal","Property",1480,880,{data:{propertyName:"metallic"},inputs:[],outputs:[u("out","Out","f32")]}),b("prop_aniso","Property",1480,960,{data:{propertyName:"anisotropy"},inputs:[],outputs:[u("out","Out","f32")]}),b("prop_aniso_rot","Property",1480,1040,{data:{propertyName:"anisotropyRotation"},inputs:[],outputs:[u("out","Out","f32")]})],n=[g("obj_pos","pos","steel_look","pos"),g("prop_seed","out","steel_look","seed"),g("prop_scale","out","steel_look","scale"),g("steel_look","out","split_steel","in"),g("vertex_color","color","mesh_maps","color"),g("prop_base","out","lerp_grain","a"),g("prop_accent","out","lerp_grain","b"),g("split_steel","x","lerp_grain","t"),g("split_steel","y","blotch_amt","a"),g("blotch_k","out","blotch_amt","b"),g("lerp_grain","out","lerp_blotch","a"),g("prop_wear","out","lerp_blotch","b"),g("blotch_amt","out","lerp_blotch","t"),g("one","out","ao_mix","a"),g("mesh_maps","ao","ao_mix","b"),g("prop_ao_str","out","ao_mix","t"),g("lerp_blotch","out","mul_ao_color","a"),g("ao_mix","out","mul_ao_color","b"),g("mesh_maps","convexity","wear_amt","a"),g("prop_edge","out","wear_amt","b"),g("mul_ao_color","out","lerp_wear","a"),g("prop_wear","out","lerp_wear","b"),g("wear_amt","out","lerp_wear","t"),g("lerp_wear","out","split_alb","in"),g("split_alb","x","alb_rgba","r"),g("split_alb","y","alb_rgba","g"),g("split_alb","z","alb_rgba","b"),g("prop_opacity","out","alb_rgba","a"),g("prop_rough","out","add_rough","a"),g("split_steel","w","add_rough","b"),g("mesh_maps","concavity","cavity_rough","a"),g("cavity_k","out","cavity_rough","b"),g("add_rough","out","add_cavity_r","a"),g("cavity_rough","out","add_cavity_r","b"),g("add_cavity_r","out","clamp_rough","in"),g("zero","out","clamp_rough","min"),g("one","out","clamp_rough","max"),g("alb_rgba","out","pbr_master","albedo"),g("prop_opacity","out","pbr_master","opacity"),g("world_n","norm","pbr_master","normal"),g("clamp_rough","out","pbr_master","roughness_factor"),g("prop_metal","out","pbr_master","metallic_factor"),g("prop_aniso","out","pbr_master","anisotropy"),g("prop_aniso_rot","out","pbr_master","anisotropy_rotation")];return{id:wn,properties:e,nodes:t,connections:n}}function Ys(){return Qs()}function N(e,t,n,o,s,r){return{type:"AABB",size:[e,t,n],offset:[o,s,r],collisionGroup:Gt,collisionMask:un}}function Xs(e){switch(e){case"pawn":return[N(.018,.006,.018,0,.006,0),N(.009,.012,.009,0,.024,0),N(.014,.012,.014,0,.042,0)];case"rook":return[N(.019,.008,.019,0,.008,0),N(.014,.018,.014,0,.03,0),N(.017,.01,.017,0,.052,0)];case"knight":return[N(.018,.008,.018,0,.008,0),N(.012,.016,.012,0,.028,0),N(.012,.014,.014,0,.05,.002)];case"bishop":return[N(.018,.007,.018,0,.007,0),N(.01,.016,.01,0,.028,0),N(.012,.016,.012,0,.048,0)];case"queen":return[N(.02,.008,.02,0,.008,0),N(.011,.02,.011,0,.032,0),N(.014,.018,.014,0,.06,0)];case"king":return[N(.021,.008,.021,0,.008,0),N(.012,.022,.012,0,.034,0),N(.015,.02,.015,0,.068,0)];default:return[N(.016,.02,.016,0,.02,0)]}}function Zs(e=.012){const t=q/2;return{type:"AABB",size:[t,e,t],offset:[0,0,0]}}function lt(e,t){const n=Math.sin(e*127.1+t*311.7)*43758.5453;return n-Math.floor(n)}function En(e){return e*e*(3-2*e)}function Js(e,t){const n=Math.floor(e),o=Math.floor(t),s=En(e-n),r=En(t-o),i=lt(n,o),a=lt(n+1,o),f=lt(n,o+1),h=lt(n+1,o+1);return i+(a-i)*s+(f-i)*r+(i-a-f+h)*s*r}function $t(e,t){let n=0,o=.5,s=1;for(let r=0;r<4;r++)n+=Js(e*s,t*s)*o,s*=2,o*=.5;return n}function ke(e){return Math.min(1,Math.max(0,e))}function gt(e,t,n){return e+(t-e)*n}function An(e,t,n){return[gt(e[0],t[0],n),gt(e[1],t[1],n),gt(e[2],t[2],n)]}function Ut(e,t,n,o,s,r,i){const a=(o*t+n)*4;e[a]=s,e[a+1]=r,e[a+2]=i,e[a+3]=255}function _e(e,t,n,o){const s=o==="light"?5.4:8.8,r=o==="light"?1.12:1.28,i=e*s+n*17.3,a=t*r+n*4.1,f=$t(i*.42,a*.52)*(o==="light"?2.05:1.28),h=o==="light"?1.7:.82,c=Math.sin(a*Math.PI*1.32+$t(a*.68,n*5.1)*1.7)*h,p=i+f+c,k=.5+.5*Math.sin(p*(o==="light"?11.2:18.4)),v=$t(i*3.6,a*16);let C=gt(k,v,o==="light"?.34:.26);if(C=Math.pow(ke(C),o==="light"?.7:.88),o==="light"){const _=Math.pow($t(i*.85+9.2,a*24),10);C=gt(C,.1,ke(_*3.4))}return ke(C)}function Pn(e,t){return t==="light"?An([216,188,154],[168,124,91],e):An([74,54,46],[36,24,20],gt(.22,.82,e))}function Rn(e,t){if(e<Z||t<Z||e>=1-Z||t>=1-Z)return{kind:"frame"};const n=(e-Z)/Dt*8,o=(t-Z)/Dt*8,s=Math.min(7,Math.floor(n)),r=Math.min(7,Math.floor(o)),i=n-s,a=o-r,f=(s+(7-r))%2===0;return{kind:"square",fx:s,fy:r,lu:i,lv:a,light:f}}function zs(e,t){for(let n=0;n<t;n++)for(let o=0;o<t;o++){const s=(o+.5)/t,r=(n+.5)/t,i=Rn(s,r);if(i.kind==="frame"){const c=_e(s*8.5,r*1.15,.41,"dark"),p=Pn(c,"dark");Ut(e,t,o,n,p[0],p[1],p[2]);continue}const a=lt(i.fx*1.73,i.fy*3.11),f=i.light?_e(i.lu+a,i.lv,a,"light"):_e(i.lv+a*.5,i.lu,a+.37,"dark"),h=Pn(f,i.light?"light":"dark");Ut(e,t,o,n,h[0],h[1],h[2])}}function tr(e,t){for(let n=0;n<t;n++)for(let o=0;o<t;o++){const s=lt(o*.2,n*.2)*16;Ut(e,t,o,n,232+s,224+s*.7,208+s*.4)}}function er(e,t){for(let n=0;n<t;n++)for(let o=0;o<t;o++){const s=lt(o*.18,n*.22)*18;Ut(e,t,o,n,28+s,24+s,22+s)}}const ve=8,Ce=.55,nr=.025;function or(e,t,n){if(n.width<=0||n.height<=0)return null;const o=(e-n.left)/n.width,s=(t-n.top)/n.height;return{ndcX:o*2-1,ndcY:1-s*2}}function sr(e,t,n){const o=t[1];if(Math.abs(o)<1e-8)return null;const s=(n-e[1])/o;return s<0?null:y.vec3.fromValues(e[0]+t[0]*s,n,e[2]+t[2]*s)}const rr=1/30;function Mn(e,t,n,o,s=ve,r=Ce){const i=Math.max(0,Math.min(o,rr));if(i<=0)return;const a=2*Math.PI*Math.max(.001,s),f=2*r*a,h=a*a;for(let c=0;c<3;c++){const p=h*(n[c]-e[c])-f*t[c];t[c]+=p*i,e[c]+=t[c]*i}}const Se=y.mat4.create(),Tn=y.vec4.create(),On=y.vec4.create(),et=y.vec4.create(),nt=y.vec4.create(),In=y.mat4.create(),Nn=y.mat4.create(),we=y.vec3.create(),Bn=y.quat.create(),xt=y.vec3.create(),Hn=y.vec3.create(),ir=y.vec3.fromValues(0,1,0);function Ln(e,t,n,o,s,r,i=y.mat4.create()){const a=Number.isFinite(o)&&o>1e-6?o:1;return y.mat4.lookAt(In,e,t,ir),y.mat4.perspective(Nn,n,a,s,r),y.mat4.multiply(i,Nn,In)}function ar(e,t,n,o,s,r=y.mat4.create()){return y.mat4.getTranslation(we,e),y.mat4.getRotation(Bn,e),y.vec3.set(xt,0,0,-1),y.vec3.transformQuat(xt,xt,Bn),y.vec3.add(Hn,we,xt),Ln(we,Hn,t,n,o,s,r)}function cr(e,t,n){if(!y.mat4.invert(Se,e)||(y.vec4.set(Tn,t,n,-1,1),y.vec4.set(On,t,n,1,1),y.vec4.transformMat4(et,Tn,Se),y.vec4.transformMat4(nt,On,Se),Math.abs(et[3])<1e-8||Math.abs(nt[3])<1e-8))return null;const o=et[0]/et[3],s=et[1]/et[3],r=et[2]/et[3],i=nt[0]/nt[3],a=nt[1]/nt[3],f=nt[2]/nt[3],h=y.vec3.fromValues(i-o,a-s,f-r);return y.vec3.length(h)<1e-8?null:(y.vec3.normalize(h,h),{origin:[o,s,r],direction:[h[0],h[1],h[2]]})}function Ee(e){y.mat3.set(e.inverseInertiaTensor,0,0,0,0,0,0,0,0,0),y.mat3.copy(e.inverseInertiaTensorWorld,e.inverseInertiaTensor),y.vec3.set(e.angularVelocity,0,0,0),y.vec3.set(e.biasAngularVelocity,0,0,0)}function Fn(e,t){y.quat.identity(e.rotation),e.updateLocalTransform(),t&&Ee(t)}function Ae(e,t,n){e.isKinematic=!0,e.useGravity=!n,y.vec3.set(e.velocity,0,0,0),Ee(e),n?e.wakeUp():(e.updateInertia(t),e.isSleeping=!0)}const Dn=y.quat.create(),yt=y.vec3.create();function Pe(e){e.updateLocalTransform(),y.mat4.copy(e.worldTransform,e.localTransform)}class ur{constructor(){D(this,"state",null)}get grabbed(){return this.state}dropXZ(){return this.state?[this.state.targetX,this.state.targetZ]:null}begin(t,n,o,s){this.end(t);const r=t.getComponent(n,F.TransformComponent),i=t.getComponent(n,ot.ColliderComponent),a=t.getComponent(n,ot.RigidBodyComponent);if(!r||!i||!a)return!1;Ae(a,i,!0),Fn(r,a),y.vec3.set(yt,o[0]-r.position[0],o[1]-r.position[1],o[2]-r.position[2]),y.quat.invert(Dn,r.rotation),y.vec3.transformQuat(yt,yt,Dn),Pe(r),t.addComponent(n,new ot.JointComponent({type:"DISTANCE",connectedEntity:null,localAnchorA:[yt[0],yt[1],yt[2]],localAnchorB:[o[0],s,o[2]],minDistance:0,maxDistance:.04,frequency:ve,dampingRatio:Ce}));const f=i.collisionMask;return i.collisionMask=ln,this.state={entity:n,previousMask:f,grabHeightY:s,targetX:o[0],targetY:s,targetZ:o[2],velX:0,velY:0,velZ:0},!0}updateWorldAnchor(t,n,o,s){if(!this.state)return;const{entity:r,grabHeightY:i}=this.state;this.state.targetX=n,this.state.targetY=i,this.state.targetZ=o;const a=t.getComponent(r,ot.JointComponent);a&&y.vec3.set(a.localAnchorB,n,i,o);const f=t.getComponent(r,F.TransformComponent);if(!f)return;const h=y.vec3.fromValues(this.state.velX,this.state.velY,this.state.velZ);Mn(f.position,h,[n,i,o],s),this.state.velX=h[0],this.state.velY=h[1],this.state.velZ=h[2],Pe(f)}end(t){if(!this.state)return null;const{entity:n,previousMask:o,targetX:s,targetY:r,targetZ:i}=this.state,a=t.getComponent(n,F.TransformComponent);a&&(y.vec3.set(a.position,s,r,i),Pe(a)),t.removeComponent(n,ot.JointComponent);const f=t.getComponent(n,ot.ColliderComponent),h=t.getComponent(n,ot.RigidBodyComponent);return f&&(f.collisionMask=o),h&&f&&Ae(h,f,!1),this.state=null,n}}class Gn{constructor(t="white",n="pawn",o=""){D(this,"color");D(this,"role");D(this,"square");this.color=t,this.role=n,this.square=o}}D(Gn,"componentName","ChessPieceComponent");const Vn="@naanouff/w3dts-chess";function lr(){return{id:Vn,serialize(){},deserialize(){}}}d.CHESS_BOARD_BEVEL_M=ut,d.CHESS_BOARD_BODY_HEIGHT=wt,d.CHESS_BOARD_BORDER_FRAC=Z,d.CHESS_BOARD_EXTENT=mt,d.CHESS_BOARD_INNER_FRAC=Dt,d.CHESS_BOARD_MESH_EXTENT=q,d.CHESS_BOARD_SURFACE_Y=V,d.CHESS_GLYPH_TEXTURE_SIZE=tn,d.CHESS_GRAB_DAMPING_RATIO=Ce,d.CHESS_GRAB_FREQUENCY_HZ=ve,d.CHESS_GRAB_LIFT_M=nr,d.CHESS_GROUP_BOARD=cn,d.CHESS_GROUP_PIECE=Gt,d.CHESS_HUD_COMMAND_EVENT=Io,d.CHESS_HUD_STATE_EVENT=Oo,d.CHESS_KNIGHT_HEAD_THICKNESS=dn,d.CHESS_MASK_BOARD=bs,d.CHESS_MASK_PIECE=un,d.CHESS_MASK_PIECE_GRABBED=ln,d.CHESS_PIECE_TRAVEL_LIFT_Y=pe,d.CHESS_SQUARE_SIZE=U,d.ChessMatch=X,d.ChessPieceComponent=Gn,d.ECO_OPENINGS=Qe,d.HeuristicChessEngine=So,d.MARBLE_PBR_SHADER_ID=Sn,d.MeshBuilder=_n,d.MouseGrabController=ur,d.OpeningTrainer=xo,d.STEEL_PBR_SHADER_ID=wn,d.W3DTS_CHESS_EXTENSION_ID=Vn,d.applyChessBoardWorldUvs=Cn,d.applyCylindricalPieceUvs=xs,d.assignCemeterySlot=ms,d.bakeChessMeshMaps=Bs,d.boardAlbedoCell=Rn,d.boardColliderShape=Zs,d.bookMoveSplineLength=ls,d.buildChessBoardBodyMesh=qs,d.buildChessHudLearnPlies=Do,d.buildStauntonPawnUvMesh=Vs,d.buildStauntonPieceMesh=$s,d.cemeterySlotIsOffBoard=gs,d.chessBoardLabelPoseVec=Zo,d.chessBoardLabelPoses=Xo,d.chessBoardLabelQuat=Jo,d.chessBoardLabelSize=Yo,d.chessBoardRimRadius=Je,d.chessDemoQueryToParams=je,d.chessPlayP2pHint=Fo,d.chessPlyFromFen=oe,d.chessTableSfxForPly=ys,d.clientPointToNdc=or,d.createBrushedSteelProceduralPBRGraph=Ys,d.createChessBoardGraph=vn,d.createChessKnightGraph=gn,d.createChessPieceGraph=mn,d.createChessSceneExtensionHandler=lr,d.createMarbleProceduralPBRGraph=Ks,d.decideChessFenSync=Ao,d.decodeChessWire=Eo,d.easeSmoothstep=fe,d.encodeChessWire=wo,d.executeChessGProcToMesh=Vt,d.fillBoardAlbedo=zs,d.fillChessGlyphAlbedo=as,d.fillEbonyAlbedo=er,d.fillIvoryAlbedo=tr,d.findEcoOpeningIndex=Ye,d.formatChessClock=To,d.intersectRayHorizontalPlane=sr,d.isChessLatheRole=Os,d.knightElbowIndices=sn,d.lockChessPieceTilt=Ee,d.mergeChessDemoQueryIntoSearch=qe,d.normalizeChessHudP2pStatus=We,d.openingSlug=re,d.parseChessDemoQuery=Po,d.parseChessDemoSession=Ht,d.parseChessHudCommand=Uo,d.parseChessHudState=$o,d.pickRayFromViewProjection=cr,d.replaceChessDemoQueryInLocation=Mo,d.resolveEcoLine=Xe,d.sampleBookMoveSpline=us,d.samplePieceTravel=hs,d.samplePieceTravelWorld=fs,d.seatChessPieceUpright=Fn,d.setChessPieceHeld=Ae,d.snapWorldToSquareCenter=Ko,d.squareToWorld=J,d.stauntonPieceColliderShapes=Xs,d.stauntonPieceHeight=Us,d.stepChessGrabSpring=Mn,d.stripChessSanSuffix=Ke,d.viewProjectionFromWorldTransform=ar,d.viewProjectionLookAt=Ln,d.worldToSquare=ie,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@naanouff/w3dts-chess",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.6",
4
+ "description": "Chess rules, Staunton procedural meshes, and fingertip physics grab for W3DTS",
5
+ "main": "dist/w3dts-chess.umd.js",
6
+ "module": "dist/w3dts-chess.es.js",
7
+ "types": "dist/index.d.ts",
8
+ "type": "module",
9
+ "publishConfig": {
10
+ "access": "public",
11
+ "registry": "https://registry.npmjs.org"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/naanouff/w3dts.git"
19
+ },
20
+ "dependencies": {
21
+ "chessops": "^0.14.2",
22
+ "gl-matrix": "^3.4.3",
23
+ "@naanouff/w3dts-core": "0.0.38",
24
+ "@naanouff/w3dts-gproc": "0.2.9",
25
+ "@naanouff/w3dts-physics": "0.0.29"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.5.4",
29
+ "vite": "^5.4.21",
30
+ "vite-plugin-dts": "^4.0.3",
31
+ "vitest": "^3.2.7"
32
+ },
33
+ "license": "UNLICENSED",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/w3dts-chess.es.js",
38
+ "require": "./dist/w3dts-chess.umd.js"
39
+ }
40
+ },
41
+ "scripts": {
42
+ "dev": "vite build --watch",
43
+ "build": "vite build",
44
+ "test": "vitest --run --config vitest.config.ts",
45
+ "check": "tsc --noEmit -p ./tsconfig.json"
46
+ }
6
47
  }