@utsp/core 0.5.0-nightly.20251203194806.f816057 → 0.5.0-nightly.20251204224035.7a07d4b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var oe=Object.defineProperty;var ft=Object.getOwnPropertyDescriptor;var Ut=Object.getOwnPropertyNames;var wt=Object.prototype.hasOwnProperty;var Ot=(x,e,t)=>e in x?oe(x,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):x[e]=t;var g=(x,e)=>oe(x,"name",{value:e,configurable:!0});var F=(x,e)=>()=>(x&&(e=x(x=0)),e);var ie=(x,e)=>{for(var t in e)oe(x,t,{get:e[t],enumerable:!0})},vt=(x,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ut(e))!wt.call(x,n)&&n!==t&&oe(x,n,{get:()=>e[n],enumerable:!(r=ft(e,n))||r.enumerable});return x};var M=x=>vt(oe({},"__esModule",{value:!0}),x);var m=(x,e,t)=>(Ot(x,typeof e!="symbol"?e+"":e,t),t);var Fe,it=F(()=>{"use strict";Fe=(o=>(o[o.Rectangle=1]="Rectangle",o[o.Circle=2]="Circle",o[o.Line=3]="Line",o[o.Ellipse=4]="Ellipse",o[o.Triangle=5]="Triangle",o))(Fe||{})});var E,I,X=F(()=>{"use strict";E=class E{constructor(e){m(this,"data");m(this,"view");this.data=new Uint8Array(e),this.view=new DataView(this.data.buffer)}static from(e){let t=new E(0);return t.data=e,t.view=new DataView(e.buffer,e.byteOffset,e.byteLength),t}static allocUnsafe(e){return new E(e)}get length(){return this.data.length}toUint8Array(){return this.data}readUInt8(e){return this.view.getUint8(e)}readInt8(e){return this.view.getInt8(e)}readUInt16BE(e){return this.view.getUint16(e,!1)}readInt16BE(e){return this.view.getInt16(e,!1)}readUInt16LE(e){return this.view.getUint16(e,!0)}readInt16LE(e){return this.view.getInt16(e,!0)}readUInt32BE(e){return this.view.getUint32(e,!1)}readInt32BE(e){return this.view.getInt32(e,!1)}readUInt32LE(e){return this.view.getUint32(e,!0)}readInt32LE(e){return this.view.getInt32(e,!0)}readBigUInt64BE(e){return this.view.getBigUint64(e,!1)}readBigInt64BE(e){return this.view.getBigInt64(e,!1)}readBigUInt64LE(e){return this.view.getBigUint64(e,!0)}readBigInt64LE(e){return this.view.getBigInt64(e,!0)}writeUInt8(e,t){this.view.setUint8(t,e)}writeInt8(e,t){this.view.setInt8(t,e)}writeUInt16BE(e,t){this.view.setUint16(t,e,!1)}writeInt16BE(e,t){this.view.setInt16(t,e,!1)}writeUInt16LE(e,t){this.view.setUint16(t,e,!0)}writeInt16LE(e,t){this.view.setInt16(t,e,!0)}writeUInt32BE(e,t){this.view.setUint32(t,e,!1)}writeInt32BE(e,t){this.view.setInt32(t,e,!1)}writeUInt32LE(e,t){this.view.setUint32(t,e,!0)}writeInt32LE(e,t){this.view.setInt32(t,e,!0)}writeBigUInt64BE(e,t){this.view.setBigUint64(t,e,!1)}writeBigInt64BE(e,t){this.view.setBigInt64(t,e,!1)}writeBigUInt64LE(e,t){this.view.setBigUint64(t,e,!0)}writeBigInt64LE(e,t){this.view.setBigInt64(t,e,!0)}copy(e,t=0,r=0,n=this.length){let o=this.data.subarray(r,n);return e.data.set(o,t),o.length}slice(e,t){let r=this.data.slice(e,t);return E.from(r)}subarray(e,t){let r=this.data.subarray(e,t);return E.from(r)}toBuffer(){return typeof Buffer<"u"&&Buffer.from?Buffer.from(this.data):this.data}static fromNodeBuffer(e){return e instanceof Uint8Array?E.from(e):E.from(new Uint8Array(e))}};g(E,"BufferCompat");I=E});var Ge,fe,at=F(()=>{"use strict";Ge=class Ge{decode(e,t=0){this.checkSize(e,t,7);let n=t,o=e.readUInt8(n++),s=e.readUInt16BE(n);n+=2;let i=e.readUInt16BE(n);n+=2;let a=e.readUInt8(n++)+1,d=e.readUInt8(n++)+1;return{display:{id:o,originX:s,originY:i,sizeX:a,sizeY:d},bytesRead:7}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short for display: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};g(Ge,"DisplayDecoder");fe=Ge});var je,Ue,dt=F(()=>{"use strict";je=class je{decode(e,t=0){if(t>=e.length)throw new Error("Buffer too short to decode order type");let r=e.readUInt8(t);switch(r){case 1:return this.decodeCharOrder(e,t);case 2:return this.decodeTextOrder(e,t);case 23:return this.decodeTextMultilineOrder(e,t);case 3:return this.decodeSubFrameOrder(e,t);case 4:return this.decodeSubFrameMultiColorOrder(e,t);case 5:return this.decodeFullFrameOrder(e,t);case 6:return this.decodeFullFrameMultiColorOrder(e,t);case 7:return this.decodeSpriteOrder(e,t);case 8:return this.decodeSpriteMultiColorOrder(e,t);case 9:return this.decodeColorMapOrder(e,t);case 10:return this.decodeShapeOrder(e,t);case 11:return this.decodeDotCloudOrder(e,t);case 12:return this.decodeDotCloudMultiColorOrder(e,t);case 17:return this.decodeBitmaskOrder(e,t);case 18:return this.decodeBitmask4Order(e,t);case 24:return this.decodeBitmask16Order(e,t);case 13:return this.decodeSpriteCloudOrder(e,t);case 14:return this.decodeSpriteCloudMultiColorOrder(e,t);case 15:return this.decodeSpriteCloudVariedOrder(e,t);case 16:return this.decodeSpriteCloudVariedMultiColorOrder(e,t);case 19:return this.decodeClearOrder(e,t);case 20:return this.decodeFillCharOrder(e,t);case 21:return this.decodeFillSpriteOrder(e,t);case 22:return this.decodeFillSpriteMultiColorOrder(e,t);case 32:return this.decodeTriggerSoundOrder(e,t);case 33:return this.decodeTriggerGlobalSoundOrder(e,t);default:throw new Error(`Unknown order type: 0x${r.toString(16)}`)}}decodeCharOrder(e,t){this.checkSize(e,t,6);let r=t;return{order:{type:1,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),charCode:e.readUInt8(r+3),bgColorCode:e.readUInt8(r+4),fgColorCode:e.readUInt8(r+5)},bytesRead:6}}decodeTextOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3);this.checkSize(e,t,5+n);let o=e.subarray(r+4,r+4+n),s=new TextDecoder().decode(o.toUint8Array());return{order:{type:2,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),text:s,bgColorCode:e.readUInt8(r+4+n),fgColorCode:e.readUInt8(r+5+n)},bytesRead:6+n}}decodeTextMultilineOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3);this.checkSize(e,t,5+n);let o=e.subarray(r+4,r+4+n),s=new TextDecoder().decode(o.toUint8Array());return{order:{type:23,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),text:s,bgColorCode:e.readUInt8(r+4+n),fgColorCode:e.readUInt8(r+5+n)},bytesRead:6+n}}decodeSubFrameOrder(e,t){this.checkSize(e,t,7);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),s=n*o;this.checkSize(e,t,7+s);let i=[];for(let d=0;d<s;d++)i.push(e.readUInt8(r+7+d));return{order:{type:3,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,bgColorCode:e.readUInt8(r+5),fgColorCode:e.readUInt8(r+6),frame:i},bytesRead:7+s}}decodeSubFrameMultiColorOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),s=n*o;this.checkSize(e,t,5+s*3);let i=[];for(let d=0;d<s;d++){let l=r+5+d*3;i.push({charCode:e.readUInt8(l),bgColorCode:e.readUInt8(l+1),fgColorCode:e.readUInt8(l+2)})}return{order:{type:4,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,frame:i},bytesRead:5+s*3}}decodeFullFrameOrder(e,t,r){this.checkSize(e,t,3);let n=t,o=r||e.length-t-3;this.checkSize(e,t,3+o);let s=[];for(let a=0;a<o;a++)s.push(e.readUInt8(n+3+a));return{order:{type:5,bgColorCode:e.readUInt8(n+1),fgColorCode:e.readUInt8(n+2),frame:s},bytesRead:3+o}}decodeFullFrameMultiColorOrder(e,t,r){this.checkSize(e,t,1);let n=t,o=r||Math.floor((e.length-t-1)/3);this.checkSize(e,t,1+o*3);let s=[];for(let a=0;a<o;a++){let d=n+1+a*3;s.push({charCode:e.readUInt8(d),bgColorCode:e.readUInt8(d+1),fgColorCode:e.readUInt8(d+2)})}return{order:{type:6,frame:s},bytesRead:1+o*3}}decodeSpriteOrder(e,t){this.checkSize(e,t,6);let r=t;return{order:{type:7,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),spriteIndex:e.readUInt8(r+3),bgColorCode:e.readUInt8(r+4),fgColorCode:e.readUInt8(r+5)},bytesRead:6}}decodeSpriteMultiColorOrder(e,t){this.checkSize(e,t,4);let r=t;return{order:{type:8,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),spriteIndex:e.readUInt8(r+3)},bytesRead:4}}decodeColorMapOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),s=n*o;this.checkSize(e,t,5+s*2);let i=[];for(let d=0;d<s;d++){let l=r+5+d*2;i.push({bgColorCode:e.readUInt8(l),fgColorCode:e.readUInt8(l+1)})}return{order:{type:9,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,colorData:i},bytesRead:5+s*2}}decodeShapeOrder(e,t){this.checkSize(e,t,2);let r=t,n=e.readUInt8(r+1),{shapeData:o,bytesRead:s}=this.decodeShapeData(e,r+2,n);return{order:{type:10,shapeType:n,shapeData:o},bytesRead:2+s}}decodeShapeData(e,t,r){let n=t;switch(r){case 1:return this.checkSize(e,t,8),{shapeData:{posX:e.readUInt8(n),posY:e.readUInt8(n+1),width:e.readUInt8(n+2),height:e.readUInt8(n+3),filled:e.readUInt8(n+4)===1,charCode:e.readUInt8(n+5),bgColorCode:e.readUInt8(n+6),fgColorCode:e.readUInt8(n+7)},bytesRead:8};case 2:return this.checkSize(e,t,7),{shapeData:{centerX:e.readUInt8(n),centerY:e.readUInt8(n+1),radius:e.readUInt8(n+2),filled:e.readUInt8(n+3)===1,charCode:e.readUInt8(n+4),bgColorCode:e.readUInt8(n+5),fgColorCode:e.readUInt8(n+6)},bytesRead:7};case 3:return this.checkSize(e,t,7),{shapeData:{x1:e.readUInt8(n),y1:e.readUInt8(n+1),x2:e.readUInt8(n+2),y2:e.readUInt8(n+3),charCode:e.readUInt8(n+4),bgColorCode:e.readUInt8(n+5),fgColorCode:e.readUInt8(n+6)},bytesRead:7};case 4:return this.checkSize(e,t,8),{shapeData:{centerX:e.readUInt8(n),centerY:e.readUInt8(n+1),radiusX:e.readUInt8(n+2),radiusY:e.readUInt8(n+3),filled:e.readUInt8(n+4)===1,charCode:e.readUInt8(n+5),bgColorCode:e.readUInt8(n+6),fgColorCode:e.readUInt8(n+7)},bytesRead:8};case 5:return this.checkSize(e,t,10),{shapeData:{x1:e.readUInt8(n),y1:e.readUInt8(n+1),x2:e.readUInt8(n+2),y2:e.readUInt8(n+3),x3:e.readUInt8(n+4),y3:e.readUInt8(n+5),filled:e.readUInt8(n+6)===1,charCode:e.readUInt8(n+7),bgColorCode:e.readUInt8(n+8),fgColorCode:e.readUInt8(n+9)},bytesRead:10};default:throw new Error(`Unknown shape type: ${r}`)}}decodeDotCloudOrder(e,t){this.checkSize(e,t,6);let r=t,n=e.readUInt16BE(r+4);this.checkSize(e,t,6+n*2);let o=[];for(let i=0;i<n;i++){let a=r+6+i*2;o.push({posX:e.readUInt8(a),posY:e.readUInt8(a+1)})}return{order:{type:11,charCode:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3),positions:o},bytesRead:6+n*2}}decodeDotCloudMultiColorOrder(e,t){this.checkSize(e,t,3);let r=t,n=e.readUInt16BE(r+1);this.checkSize(e,t,3+n*5);let o=[];for(let i=0;i<n;i++){let a=r+3+i*5;o.push({charCode:e.readUInt8(a),bgColorCode:e.readUInt8(a+1),fgColorCode:e.readUInt8(a+2),posX:e.readUInt8(a+3),posY:e.readUInt8(a+4)})}return{order:{type:12,dots:o},bytesRead:3+n*5}}decodeBitmaskOrder(e,t){this.checkSize(e,t,9);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),s=Math.ceil(n*o/8);this.checkSize(e,t,9+s);let i=new Uint8Array(s);for(let d=0;d<s;d++)i[d]=e.readUInt8(r+9+d);return{order:{type:17,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,charCode:e.readUInt8(r+5),bgColorCode:e.readUInt8(r+6),fgColorCode:e.readUInt8(r+7),override:e.readUInt8(r+8)===1,mask:i},bytesRead:9+s}}decodeBitmask4Order(e,t){this.checkSize(e,t,15);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),s=Math.ceil(n*o/4);this.checkSize(e,t,15+s);let i=[{charCode:e.readUInt8(r+6),bgColorCode:e.readUInt8(r+7),fgColorCode:e.readUInt8(r+8)},{charCode:e.readUInt8(r+9),bgColorCode:e.readUInt8(r+10),fgColorCode:e.readUInt8(r+11)},{charCode:e.readUInt8(r+12),bgColorCode:e.readUInt8(r+13),fgColorCode:e.readUInt8(r+14)}],a=new Uint8Array(s);for(let l=0;l<s;l++)a[l]=e.readUInt8(r+15+l);return{order:{type:18,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,override:e.readUInt8(r+5)===1,variants:i,mask:a},bytesRead:15+s}}decodeBitmask16Order(e,t){this.checkSize(e,t,51);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),s=Math.ceil(n*o/2);this.checkSize(e,t,51+s);let i=[];for(let l=0;l<15;l++){let c=r+6+l*3;i.push({charCode:e.readUInt8(c),bgColorCode:e.readUInt8(c+1),fgColorCode:e.readUInt8(c+2)})}let a=new Uint8Array(s);for(let l=0;l<s;l++)a[l]=e.readUInt8(r+51+l);return{order:{type:24,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,override:e.readUInt8(r+5)===1,variants:i,mask:a},bytesRead:51+s}}decodeSpriteCloudOrder(e,t){this.checkSize(e,t,6);let r=t,n=e.readUInt16BE(r+4);this.checkSize(e,t,6+n*2);let o=[];for(let i=0;i<n;i++){let a=r+6+i*2;o.push({posX:e.readUInt8(a),posY:e.readUInt8(a+1)})}return{order:{type:13,spriteIndex:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3),positions:o},bytesRead:6+n*2}}decodeSpriteCloudMultiColorOrder(e,t){this.checkSize(e,t,4);let r=t,n=e.readUInt16BE(r+2);this.checkSize(e,t,4+n*2);let o=[];for(let i=0;i<n;i++){let a=r+4+i*2;o.push({posX:e.readUInt8(a),posY:e.readUInt8(a+1)})}return{order:{type:14,spriteIndex:e.readUInt8(r+1),positions:o},bytesRead:4+n*2}}decodeSpriteCloudVariedOrder(e,t){this.checkSize(e,t,3);let r=t,n=e.readUInt16BE(r+1);this.checkSize(e,t,3+n*5);let o=[];for(let i=0;i<n;i++){let a=r+3+i*5;o.push({spriteIndex:e.readUInt8(a),bgColorCode:e.readUInt8(a+1),fgColorCode:e.readUInt8(a+2),posX:e.readUInt8(a+3),posY:e.readUInt8(a+4)})}return{order:{type:15,sprites:o},bytesRead:3+n*5}}decodeSpriteCloudVariedMultiColorOrder(e,t){this.checkSize(e,t,3);let r=t,n=e.readUInt16BE(r+1);this.checkSize(e,t,3+n*3);let o=[];for(let i=0;i<n;i++){let a=r+3+i*3;o.push({spriteIndex:e.readUInt8(a),posX:e.readUInt8(a+1),posY:e.readUInt8(a+2)})}return{order:{type:16,sprites:o},bytesRead:3+n*3}}decodeClearOrder(e,t){this.checkSize(e,t,4);let r=t;return{order:{type:19,charCode:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3)},bytesRead:4}}decodeFillCharOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+1),o=e.readUInt8(r+2),s=n*o;this.checkSize(e,t,5+s);let i=[];for(let d=0;d<s;d++)i.push(e.readUInt8(r+5+d));return{order:{type:20,patternWidth:n,patternHeight:o,bgColorCode:e.readUInt8(r+3),fgColorCode:e.readUInt8(r+4),pattern:i},bytesRead:5+s}}decodeFillSpriteOrder(e,t){this.checkSize(e,t,4);let r=t;return{order:{type:21,spriteIndex:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3)},bytesRead:4}}decodeFillSpriteMultiColorOrder(e,t){this.checkSize(e,t,2);let r=t;return{order:{type:22,spriteIndex:e.readUInt8(r+1)},bytesRead:2}}decodeTriggerSoundOrder(e,t){this.checkSize(e,t,5);let r=t;return{order:{type:32,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),soundId:e.readUInt8(r+3),loop:e.readUInt8(r+4)===1},bytesRead:5}}decodeTriggerGlobalSoundOrder(e,t){this.checkSize(e,t,3);let r=t;return{order:{type:33,soundId:e.readUInt8(r+1),loop:e.readUInt8(r+2)===1},bytesRead:3}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};g(je,"OrderDecoder");Ue=je});var qe,we,lt=F(()=>{"use strict";dt();qe=class qe{constructor(){m(this,"orderDecoder");this.orderDecoder=new Ue}decode(e,t=0){this.checkSize(e,t,13);let n=t,o=e.readUInt16BE(n);n+=2;let s=e.readUInt8(n++),i=e.readUInt8(n++),a=e.readUInt16BE(n);n+=2;let d=e.readUInt16BE(n);n+=2;let l=e.readUInt16BE(n);n+=2;let c=e.readUInt16BE(n);n+=2;let u=e.readUInt8(n++),p=[],h=n;for(let y=0;y<u;y++){let f=this.orderDecoder.decode(e,h);p.push(f.order),h+=f.bytesRead}return{layer:{id:o,updateFlags:s,zIndex:i,originX:a,originY:d,width:l,height:c,orderCount:u,orders:p},bytesRead:h-t}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short for layer: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};g(qe,"LayerDecoder");we=qe});var ut={};ie(ut,{UpdatePacketDecoder:()=>le});var Ke,le,Je=F(()=>{"use strict";at();lt();X();Ke=class Ke{constructor(){m(this,"displayDecoder");m(this,"layerDecoder");this.displayDecoder=new fe,this.layerDecoder=new we}decode(e,t=0){let r=I.from(e);this.checkSize(r,t,11);let o=t,s=Number(r.readBigUInt64BE(o));o+=8;let i=r.readUInt8(o);o+=1;let a=[];for(let u=0;u<i;u++){let p=this.displayDecoder.decode(r,o);a.push(p.display),o+=p.bytesRead}this.checkSize(r,o,2);let d=r.readUInt16BE(o);o+=2;let l=[];for(let u=0;u<d;u++){let p=this.layerDecoder.decode(r,o);l.push(p.layer),o+=p.bytesRead}return{tick:s,displayCount:i,displays:a,layerCount:d,layers:l}}isValid(e,t=0){let r=I.from(e);try{return this.checkSize(r,t,11),!0}catch{return!1}}decodeHeader(e,t=0){let r=I.from(e);this.checkSize(r,t,11);let n=t,o=Number(r.readBigUInt64BE(n));n+=8;let s=r.readUInt8(n);n+=1,n+=s*7,this.checkSize(r,n,2);let i=r.readUInt16BE(n);return{tick:o,displayCount:s,layerCount:i}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short for update packet: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};g(Ke,"UpdatePacketDecoder");le=Ke});var Y={};ie(Y,{LoadType:()=>Oe});var Oe,D=F(()=>{"use strict";Oe=(s=>(s[s.ColorPalette=1]="ColorPalette",s[s.Sprite=2]="Sprite",s[s.MulticolorSprite=3]="MulticolorSprite",s[s.BitmapFont=4]="BitmapFont",s[s.Sound=5]="Sound",s[s.WebFont=6]="WebFont",s))(Oe||{})});var ct={};ie(ct,{LoadDecoder:()=>Qe});var et,Qe,pt=F(()=>{"use strict";X();et=class et{decode(e,t=0){let r=I.from(e);if(t>=r.length)throw new Error("Buffer too short to decode load type");let n=r.readUInt8(t);switch(n){case 1:return this.decodeColorPalette(r,t);case 2:return this.decodeSprite(r,t);case 3:return this.decodeMulticolorSprite(r,t);case 4:return this.decodeBitmapFont(r,t);case 5:return this.decodeSound(r,t);case 6:return this.decodeWebFont(r,t);default:throw new Error(`Unknown load type: 0x${n.toString(16)}`)}}decodeColorPalette(e,t){let r=t;this.checkSize(e,t,2,"ColorPalette header");let n=e.readUInt8(t++),o=e.readUInt8(t++);this.checkSize(e,t,o*6,`ColorPalette ${o} colors`);let s=[];for(let a=0;a<o;a++)s.push({colorId:e.readUInt8(t++),r:e.readUInt8(t++),g:e.readUInt8(t++),b:e.readUInt8(t++),a:e.readUInt8(t++),e:e.readUInt8(t++)});return{load:{loadType:1,colors:s},bytesRead:t-r}}decodeSprite(e,t){let r=t;this.checkSize(e,t,2,"Sprite header");let n=e.readUInt8(t++),o=e.readUInt8(t++),s=[];for(let a=0;a<o;a++){this.checkSize(e,t,3,`Sprite ${a} header`);let d=e.readUInt8(t++),l=e.readUInt8(t++),c=e.readUInt8(t++),u=l*c;this.checkSize(e,t,u,`Sprite ${a} data`);let p=[];for(let h=0;h<u;h++)p.push(e.readUInt8(t++));s.push({spriteId:d,sizeX:l,sizeY:c,data:p})}return{load:{loadType:2,sprites:s},bytesRead:t-r}}decodeMulticolorSprite(e,t){let r=t;this.checkSize(e,t,2,"MulticolorSprite header");let n=e.readUInt8(t++),o=e.readUInt8(t++),s=[];for(let a=0;a<o;a++){this.checkSize(e,t,3,`MulticolorSprite ${a} header`);let d=e.readUInt8(t++),l=e.readUInt8(t++),c=e.readUInt8(t++),u=l*c,p=u*3;this.checkSize(e,t,p,`MulticolorSprite ${a} data`);let h=[];for(let C=0;C<u;C++)h.push({charCode:e.readUInt8(t++),fgColorId:e.readUInt8(t++),bgColorId:e.readUInt8(t++)});s.push({spriteId:d,sizeX:l,sizeY:c,data:h})}return{load:{loadType:3,sprites:s},bytesRead:t-r}}decodeBitmapFont(e,t){let r=t;this.checkSize(e,t,7,"BitmapFont header");let n=e.readUInt8(t++),o=e.readUInt8(t++),s=e.readUInt8(t++),i=e.readUInt8(t++),a=e.readUInt8(t++),d=e.readUInt8(t++),l=e.readUInt8(t++),c=Math.ceil(s*i/8),u=[];for(let h=0;h<l;h++){this.checkSize(e,t,1+c,`BitmapFont character ${h}`);let C=e.readUInt8(t++),y=new Uint8Array(c);for(let f=0;f<c;f++)y[f]=e.readUInt8(t++);u.push({charCode:C,bitmap:y})}return{load:{loadType:4,fontId:o,width:s,height:i,cellWidth:a,cellHeight:d,characters:u},bytesRead:t-r}}decodeSound(e,t){let r=t;this.checkSize(e,t,2,"Sound header");let n=e.readUInt8(t++),o=e.readUInt8(t++),s=[];for(let a=0;a<o;a++){this.checkSize(e,t,3,`Sound ${a} header`);let d=e.readUInt8(t++),l=e.readUInt16BE(t);t+=2,this.checkSize(e,t,l,`Sound ${a} MIDI data`);let c=new Uint8Array(l);for(let u=0;u<l;u++)c[u]=e.readUInt8(t++);s.push({soundId:d,midiData:c})}return{load:{loadType:5,sounds:s},bytesRead:t-r}}checkSize(e,t,r,n){if(t+r>e.length)throw new Error(`Buffer too short for ${n}: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes remaining`)}decodeWebFont(e,t){let r=t,n=new TextDecoder;this.checkSize(e,t,5,"WebFont header");let o=e.readUInt8(t++),s=e.readUInt8(t++),i=e.readUInt8(t++),a=e.readUInt8(t++);this.checkSize(e,t,a,"WebFont family string");let d=new Uint8Array(a);for(let p=0;p<a;p++)d[p]=e.readUInt8(t++);let l=n.decode(d);this.checkSize(e,t,2,"WebFont fontSize");let c=e.readUInt16BE(t);t+=2;let u={loadType:6,fontId:s,fontFamily:l,fontSize:c};if(i&1&&(this.checkSize(e,t,2,"WebFont offsetX"),u.offsetX=e.readInt16BE(t),t+=2),i&2&&(this.checkSize(e,t,2,"WebFont offsetY"),u.offsetY=e.readInt16BE(t),t+=2),i&4&&(this.checkSize(e,t,2,"WebFont charSpacing"),u.charSpacing=e.readInt16BE(t),t+=2),i&8){this.checkSize(e,t,2,"WebFont lineHeight");let p=e.readUInt16BE(t);u.lineHeight=p/100,t+=2}if(i&16){this.checkSize(e,t,1,"WebFont weight length");let p=e.readUInt8(t++);this.checkSize(e,t,p,"WebFont weight string");let h=new Uint8Array(p);for(let C=0;C<p;C++)h[C]=e.readUInt8(t++);u.fontWeight=n.decode(h)}if(i&32){this.checkSize(e,t,1,"WebFont style length");let p=e.readUInt8(t++);this.checkSize(e,t,p,"WebFont style string");let h=new Uint8Array(p);for(let C=0;C<p;C++)h[C]=e.readUInt8(t++);u.fontStyle=n.decode(h)}return{load:u,bytesRead:t-r}}};g(et,"LoadDecoder");Qe=et});var te={};ie(te,{LoadEncoder:()=>tt});var rt,tt,re=F(()=>{"use strict";X();rt=class rt{encode(e){switch(e.loadType){case 1:return this.encodeColorPalette(e);case 2:return this.encodeSprite(e);case 3:return this.encodeMulticolorSprite(e);case 4:return this.encodeBitmapFont(e);case 5:return this.encodeSound(e);case 6:return this.encodeWebFont(e);default:throw new Error(`Unknown load type: ${e.loadType}`)}}encodeColorPalette(e){let t=e.colors.length;if(t>255)throw new Error(`Palette size ${t} exceeds maximum of 255`);let r=I.allocUnsafe(2+t*6),n=0;r.writeUInt8(1,n++),r.writeUInt8(t,n++);for(let o of e.colors)r.writeUInt8(o.colorId,n++),r.writeUInt8(o.r,n++),r.writeUInt8(o.g,n++),r.writeUInt8(o.b,n++),r.writeUInt8(o.a,n++),r.writeUInt8(o.e??0,n++);return r.toUint8Array()}encodeSprite(e){let t=e.sprites.length;if(t>255)throw new Error(`Sprite count ${t} exceeds maximum of 255`);let r=2;for(let s of e.sprites)r+=3,r+=s.data.length;let n=I.allocUnsafe(r),o=0;n.writeUInt8(2,o++),n.writeUInt8(t,o++);for(let s of e.sprites){if(s.data.length!==s.sizeX*s.sizeY)throw new Error(`Sprite ${s.spriteId}: data length ${s.data.length} does not match size ${s.sizeX}x${s.sizeY}`);n.writeUInt8(s.spriteId,o++),n.writeUInt8(s.sizeX,o++),n.writeUInt8(s.sizeY,o++);for(let i of s.data)n.writeUInt8(i,o++)}return n.toUint8Array()}encodeMulticolorSprite(e){let t=e.sprites.length;if(t>255)throw new Error(`Sprite count ${t} exceeds maximum of 255`);let r=2;for(let s of e.sprites)r+=3,r+=s.data.length*3;let n=I.allocUnsafe(r),o=0;n.writeUInt8(3,o++),n.writeUInt8(t,o++);for(let s of e.sprites){if(s.data.length!==s.sizeX*s.sizeY)throw new Error(`Sprite ${s.spriteId}: data length ${s.data.length} does not match size ${s.sizeX}x${s.sizeY}`);n.writeUInt8(s.spriteId,o++),n.writeUInt8(s.sizeX,o++),n.writeUInt8(s.sizeY,o++);for(let i of s.data)n.writeUInt8(i.charCode,o++),n.writeUInt8(i.fgColorId,o++),n.writeUInt8(i.bgColorId,o++)}return n.toUint8Array()}encodeBitmapFont(e){let t=e.characters.length;if(t>255)throw new Error(`Character count ${t} exceeds maximum of 255`);let r=Math.ceil(e.width*e.height/8),n=7+t*(1+r),o=I.allocUnsafe(n),s=0;o.writeUInt8(4,s++),o.writeUInt8(e.fontId,s++),o.writeUInt8(e.width,s++),o.writeUInt8(e.height,s++),o.writeUInt8(e.cellWidth,s++),o.writeUInt8(e.cellHeight,s++),o.writeUInt8(t,s++);for(let i of e.characters){if(i.bitmap.length!==r)throw new Error(`Character ${i.charCode}: bitmap size ${i.bitmap.length} does not match expected ${r} bytes`);o.writeUInt8(i.charCode,s++);for(let a=0;a<i.bitmap.length;a++)o.writeUInt8(i.bitmap[a],s++)}return o.toUint8Array()}encodeSound(e){let t=e.sounds.length;if(t>255)throw new Error(`Sound count ${t} exceeds maximum of 255`);let r=2;for(let s of e.sounds){if(s.midiData.length>65535)throw new Error(`Sound ${s.soundId}: MIDI data size ${s.midiData.length} exceeds maximum of 65535 bytes`);r+=3,r+=s.midiData.length}let n=I.allocUnsafe(r),o=0;n.writeUInt8(5,o++),n.writeUInt8(t,o++);for(let s of e.sounds){n.writeUInt8(s.soundId,o++),n.writeUInt16BE(s.midiData.length,o),o+=2;for(let i=0;i<s.midiData.length;i++)n.writeUInt8(s.midiData[i],o++)}return n.toUint8Array()}encodeWebFont(e){let t=new TextEncoder,r=t.encode(e.fontFamily),n=e.fontWeight?t.encode(e.fontWeight):new Uint8Array(0),o=e.fontStyle?t.encode(e.fontStyle):new Uint8Array(0),s=0;e.offsetX!==void 0&&(s|=1),e.offsetY!==void 0&&(s|=2),e.charSpacing!==void 0&&(s|=4),e.lineHeight!==void 0&&(s|=8),e.fontWeight!==void 0&&(s|=16),e.fontStyle!==void 0&&(s|=32);let i=4;i+=r.length,i+=2,e.offsetX!==void 0&&(i+=2),e.offsetY!==void 0&&(i+=2),e.charSpacing!==void 0&&(i+=2),e.lineHeight!==void 0&&(i+=2),e.fontWeight!==void 0&&(i+=1+n.length),e.fontStyle!==void 0&&(i+=1+o.length);let a=I.allocUnsafe(i),d=0;a.writeUInt8(6,d++),a.writeUInt8(e.fontId,d++),a.writeUInt8(s,d++),a.writeUInt8(r.length,d++);for(let l=0;l<r.length;l++)a.writeUInt8(r[l],d++);if(a.writeUInt16BE(e.fontSize,d),d+=2,e.offsetX!==void 0&&(a.writeInt16BE(e.offsetX,d),d+=2),e.offsetY!==void 0&&(a.writeInt16BE(e.offsetY,d),d+=2),e.charSpacing!==void 0&&(a.writeInt16BE(e.charSpacing,d),d+=2),e.lineHeight!==void 0&&(a.writeUInt16BE(Math.round(e.lineHeight*100),d),d+=2),e.fontWeight!==void 0){a.writeUInt8(n.length,d++);for(let l=0;l<n.length;l++)a.writeUInt8(n[l],d++)}if(e.fontStyle!==void 0){a.writeUInt8(o.length,d++);for(let l=0;l<o.length;l++)a.writeUInt8(o[l],d++)}return a.toUint8Array()}};g(rt,"LoadEncoder");tt=rt});var ir={};ie(ir,{ASCII_8X8_FONT:()=>W,BITMASK16_ORDER_MIN_SIZE:()=>Zt,BITMASK4_ORDER_MIN_SIZE:()=>Vt,BITMASK_ORDER_MIN_SIZE:()=>Ht,BitmapFont:()=>K,BitmapFontRegistry:()=>Q,CHAR_ORDER_SIZE:()=>At,CIRCLE_SHAPE_SIZE:()=>Xt,CLEAR_ORDER_SIZE:()=>Jt,COLORMAP_ORDER_MIN_SIZE:()=>Dt,COLOR_SKIP:()=>k,CellBuffer:()=>R,CharCodeBuffer:()=>N,Core:()=>ve,CoreStats:()=>j,DISPLAY_HEADER_SIZE:()=>cr,DOTCLOUD_MULTICOLOR_ORDER_MIN_SIZE:()=>$t,DOTCLOUD_ORDER_MIN_SIZE:()=>Nt,Display:()=>_,ELLIPSE_SHAPE_SIZE:()=>Wt,FILLCHAR_ORDER_MIN_SIZE:()=>Qt,FILLSPRITE_MULTICOLOR_ORDER_SIZE:()=>tr,FILLSPRITE_ORDER_SIZE:()=>er,FULLFRAME_MULTICOLOR_ORDER_MIN_SIZE:()=>Et,FULLFRAME_ORDER_MIN_SIZE:()=>Ft,FontType:()=>_e,InputBindingRegistry:()=>H,LAYER_CELL_COUNT:()=>lr,LAYER_HEADER_SIZE:()=>pr,LAYER_SIZE:()=>ce,LINE_SHAPE_SIZE:()=>Yt,Layer:()=>$,LoadType:()=>Oe,OrderBuilder:()=>Ae,OrderType:()=>nt,RECTANGLE_SHAPE_SIZE:()=>Pt,SHAPE_ORDER_MIN_SIZE:()=>Tt,SPRITECLOUD_MULTICOLOR_ORDER_MIN_SIZE:()=>jt,SPRITECLOUD_ORDER_MIN_SIZE:()=>Gt,SPRITECLOUD_VARIED_MULTICOLOR_ORDER_MIN_SIZE:()=>Kt,SPRITECLOUD_VARIED_ORDER_MIN_SIZE:()=>qt,SPRITE_MULTICOLOR_ORDER_SIZE:()=>Lt,SPRITE_ORDER_SIZE:()=>Rt,SUBFRAME_MULTICOLOR_ORDER_MIN_SIZE:()=>zt,SUBFRAME_ORDER_MIN_SIZE:()=>Mt,ShapeType:()=>Fe,SoundRegistry:()=>ee,SpriteRegistry:()=>q,TEXT_MULTILINE_ORDER_MIN_SIZE:()=>kt,TEXT_ORDER_MIN_SIZE:()=>Bt,TRIANGLE_SHAPE_SIZE:()=>_t,TRIGGERGLOBALSOUND_ORDER_SIZE:()=>nr,TRIGGERSOUND_ORDER_SIZE:()=>rr,UPDATE_PACKET_HEADER_SIZE:()=>ur,UpdateFlags:()=>ot,UpdateFlagsHelper:()=>Be,UpdatePacketDecoder:()=>le,User:()=>Z,UserStats:()=>V,Vector2:()=>It.Vector2,WebFont:()=>L,WebFontRegistry:()=>J,createASCII8x8FontLoad:()=>Ct,createEmptyCompressedInputPacket:()=>he,decodeCompressedInput:()=>ge,decodeInt8ToAxis:()=>xe,encodeAxisToInt8:()=>me,encodeCompressedInput:()=>bt,getASCII8x8FontConfig:()=>gt,getAllCharCodes:()=>xt,getButtonByteCount:()=>P,getCharBitmap:()=>ht,getCompressedPacketSize:()=>Ce,getOrderTypeName:()=>St,hasChar:()=>mt,isValidOrderType:()=>yt});module.exports=M(ir);var se=require("@utsp/types");var ke=class ke{constructor(e=0,t=60,r=40){m(this,"id");m(this,"origin");m(this,"size");m(this,"previousOrigin",new se.Vector2(0,0));m(this,"previousSize",new se.Vector2(0,0));m(this,"toDraw",[]);if(e<0||e>255)throw new Error(`Display ID must be between 0 and 255, got ${e}`);if(t<1||t>256)throw new Error(`Display sizeX must be between 1 and 256, got ${t}`);if(r<1||r>256)throw new Error(`Display sizeY must be between 1 and 256, got ${r}`);this.id=e,this.origin=new se.Vector2(0,0),this.size=new se.Vector2(t,r),this.toDraw=new Array(this.size.x*this.size.y).fill(null).map(()=>({charCode:0,fgColorCode:0,bgColorCode:0}))}getId(){return this.id}getOrigin(){return this.origin}setOrigin(e){this.origin=e}moveOrigin(e,t){this.origin.x+=e,this.origin.y+=t}hasOriginChanged(){return this.origin.x!==this.previousOrigin.x||this.origin.y!==this.previousOrigin.y}hasSizeChanged(){return this.size.x!==this.previousSize.x||this.size.y!==this.previousSize.y}hasChanged(){return this.hasOriginChanged()||this.hasSizeChanged()}resetChangeTracking(){this.previousOrigin.x=this.origin.x,this.previousOrigin.y=this.origin.y,this.previousSize.x=this.size.x,this.previousSize.y=this.size.y}getSize(){return this.size}setSize(e){if(e.x<1||e.x>256)throw new Error(`Display sizeX must be between 1 and 256, got ${e.x}`);if(e.y<1||e.y>256)throw new Error(`Display sizeY must be between 1 and 256, got ${e.y}`);this.size=e,this.toDraw=new Array(this.size.x*this.size.y).fill(null).map(()=>({charCode:0,fgColorCode:0,bgColorCode:0}))}};g(ke,"Display");var _=ke;var ce=256,lr=65536,k=255,ur=9,cr=5,pr=13,At=6,Bt=6,kt=6,Mt=7,zt=5,Ft=3,Et=1,Rt=6,Lt=4,Dt=5,Tt=2,Pt=8,Xt=7,Yt=7,Wt=8,_t=10,Nt=6,$t=3,Ht=9,Vt=15,Zt=51,Gt=6,jt=4,qt=3,Kt=3,Jt=4,Qt=5,er=4,tr=2,rr=5,nr=3;var Me=class Me{constructor(e=65536){m(this,"data");m(this,"size");this.size=e,this.data=new Uint8Array(e*3),this.clear()}clear(){this.clearWithColor(0,255,255)}clearWithColor(e,t,r){for(let n=0;n<this.size;n++){let o=n*3;this.data[o]=e,this.data[o+1]=t,this.data[o+2]=r}}set(e,t,r,n){let o=e*3;this.data[o]=t,this.data[o+1]=r,this.data[o+2]=n}fillCharsUniform(e,t,r,n){for(let o=0;o<e.length;o++){let s=e[o]*3;this.data[s]=t,this.data[s+1]=r,this.data[s+2]=n}}get(e){let t=e*3;return{charCode:this.data[t],fgColorCode:this.data[t+1],bgColorCode:this.data[t+2]}}setCharOnly(e,t){this.data[e*3]=t}setColorsOnly(e,t,r){this.data[e*3+1]=t,this.data[e*3+2]=r}getCharCode(e){return this.data[e*3]}getFgColorCode(e){return this.data[e*3+1]}getBgColorCode(e){return this.data[e*3+2]}getRawData(){return this.data}getSize(){return this.size}};g(Me,"CellBuffer");var R=Me,ze=class ze{constructor(e){m(this,"data");m(this,"size");this.size=e,this.data=new Uint8Array(e)}clear(){this.data.fill(0)}set(e,t){this.data[e]=t}get(e){return this.data[e]}getRawData(){return this.data}getSize(){return this.size}};g(ze,"CharCodeBuffer");var N=ze;var st=require("@utsp/types");var or=new Map([[9474,179],[9472,196],[9484,218],[9488,191],[9492,192],[9496,217],[9500,195],[9508,180],[9516,194],[9524,193],[9532,197],[9553,186],[9552,205],[9556,201],[9559,187],[9562,200],[9565,188],[9568,204],[9571,185],[9574,203],[9577,202],[9580,206],[9608,219],[9619,178],[9618,177],[9617,176],[9600,223],[9604,220],[9612,221],[9616,222]]);function ae(x){if(x<128)return x;let e=or.get(x);return e!==void 0?e:x&255}g(ae,"unicodeToCp437");var Ee=class Ee{constructor(){m(this,"currentWidth",256);m(this,"currentHeight",256)}rasterizeOrders(e,t,r,n,o="add",s){this.currentWidth=r,this.currentHeight=n,o==="set"&&this.clearBuffer(t);for(let i of e)this.rasterizeOrder(i,t,s)}clearBuffer(e){e.clear()}rasterizeOrder(e,t,r){switch(e.type){case 1:this.rasterizeChar(e,t);break;case 2:this.rasterizeText(e,t);break;case 23:this.rasterizeTextMultiline(e,t);break;case 3:this.rasterizeSubFrame(e,t);break;case 4:this.rasterizeSubFrameMultiColor(e,t);break;case 5:this.rasterizeFullFrame(e,t);break;case 6:this.rasterizeFullFrameMultiColor(e,t);break;case 7:this.rasterizeSprite(e,t,r);break;case 8:this.rasterizeSpriteMultiColor(e,t,r);break;case 9:this.rasterizeColorMap(e,t);break;case 10:this.rasterizeShape(e,t);break;case 11:this.rasterizeDotCloud(e,t);break;case 12:this.rasterizeDotCloudMultiColor(e,t);break;case 17:this.rasterizeBitmask(e,t);break;case 18:this.rasterizeBitmask4(e,t);break;case 24:this.rasterizeBitmask16(e,t);break;case 13:this.rasterizeSpriteCloud(e,t,r);break;case 14:this.rasterizeSpriteCloudMultiColor(e,t,r);break;case 15:this.rasterizeSpriteCloudVaried(e,t,r);break;case 16:this.rasterizeSpriteCloudVariedMultiColor(e,t,r);break;case 19:this.rasterizeClear(e,t);break;case 20:this.rasterizeFillChar(e,t);break;case 21:this.rasterizeFillSprite(e,t,r);break;case 22:this.rasterizeFillSpriteMultiColor(e,t,r);break;default:break}}rasterizeChar(e,t){let{posX:r,posY:n,charCode:o,bgColorCode:s,fgColorCode:i}=e;if(!this.isInBounds(r,n))return;let a=n*this.currentWidth+r;t.set(a,o,i,s)}rasterizeText(e,t){let{posX:r,posY:n,text:o,bgColorCode:s,fgColorCode:i}=e;if(this.isInBounds(r,n))for(let a=0;a<o.length;a++){let d=r+a;if(d>=this.currentWidth)break;let l=n*this.currentWidth+d,c=o.charCodeAt(a),u=ae(c);t.set(l,u,i,s)}}rasterizeTextMultiline(e,t){let{posX:r,posY:n,text:o,bgColorCode:s,fgColorCode:i}=e,a=o.split(`
2
- `),d=n;for(let l of a){if(d>=this.currentHeight)break;if(d>=0&&this.isInBounds(r,d))for(let c=0;c<l.length;c++){let u=r+c;if(u>=this.currentWidth)break;let p=d*this.currentWidth+u,h=l.charCodeAt(c),C=ae(h);t.set(p,C,i,s)}d++}}rasterizeSubFrame(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,frame:i,bgColorCode:a,fgColorCode:d}=e;for(let l=0;l<s;l++){let c=n+l;if(!(c<0||c>=this.currentHeight))for(let u=0;u<o;u++){let p=r+u;if(p<0||p>=this.currentWidth)continue;let h=l*o+u;if(h>=i.length)break;let C=c*this.currentWidth+p;t.set(C,i[h],d,a)}}}rasterizeSubFrameMultiColor(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,frame:i}=e;for(let a=0;a<s;a++){let d=n+a;if(!(d<0||d>=this.currentHeight))for(let l=0;l<o;l++){let c=r+l;if(c<0||c>=this.currentWidth)continue;let u=a*o+l;if(u>=i.length)break;let p=i[u],h=d*this.currentWidth+c;t.set(h,p.charCode,p.fgColorCode,p.bgColorCode)}}}rasterizeFullFrame(e,t){let{frame:r,bgColorCode:n,fgColorCode:o}=e,s=this.currentWidth*this.currentHeight;for(let i=0;i<s&&i<r.length;i++)t.set(i,r[i],o,n)}rasterizeFullFrameMultiColor(e,t){let{frame:r}=e,n=this.currentWidth*this.currentHeight;for(let o=0;o<n&&o<r.length;o++){let s=r[o];t.set(o,s.charCode,s.fgColorCode,s.bgColorCode)}}rasterizeColorMap(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,colorData:i}=e;for(let a=0;a<s;a++){let d=n+a;if(!(d<0||d>=this.currentHeight))for(let l=0;l<o;l++){let c=r+l;if(c<0||c>=this.currentWidth)continue;let u=a*o+l;if(u>=i.length)break;let p=d*this.currentWidth+c,h=i[u];t.setColorsOnly(p,h.fgColorCode,h.bgColorCode)}}}rasterizeShape(e,t){let{shapeType:r,shapeData:n}=e;switch(r){case 1:this.rasterizeRectangle(n,t);break;case 2:this.rasterizeCircle(n,t);break;case 3:this.rasterizeLine(n,t);break;case 4:this.rasterizeEllipse(n,t);break;case 5:this.rasterizeTriangle(n,t);break}}rasterizeRectangle(e,t){let{posX:r,posY:n,width:o,height:s,filled:i,charCode:a,bgColorCode:d,fgColorCode:l}=e;if(i)for(let c=0;c<s;c++){let u=n+c;if(!(u<0||u>=this.currentHeight))for(let p=0;p<o;p++){let h=r+p;if(h<0||h>=this.currentWidth)continue;let C=u*this.currentWidth+h;t.set(C,a,l,d)}}else{for(let c=0;c<o;c++)this.setCell(r+c,n,a,d,l,t),this.setCell(r+c,n+s-1,a,d,l,t);for(let c=0;c<s;c++)this.setCell(r,n+c,a,d,l,t),this.setCell(r+o-1,n+c,a,d,l,t)}}rasterizeCircle(e,t){let{centerX:r,centerY:n,radius:o,filled:s,charCode:i,bgColorCode:a,fgColorCode:d}=e;if(s)for(let l=-o;l<=o;l++){let c=n+l;if(!(c<0||c>=this.currentHeight))for(let u=-o;u<=o;u++){let p=r+u;if(!(p<0||p>=this.currentWidth)&&u*u+l*l<=o*o){let h=c*this.currentWidth+p;t.set(h,i,d,a)}}}else{let l=o,c=0,u=0;for(;l>=c;)this.setCell(r+l,n+c,i,a,d,t),this.setCell(r+c,n+l,i,a,d,t),this.setCell(r-c,n+l,i,a,d,t),this.setCell(r-l,n+c,i,a,d,t),this.setCell(r-l,n-c,i,a,d,t),this.setCell(r-c,n-l,i,a,d,t),this.setCell(r+c,n-l,i,a,d,t),this.setCell(r+l,n-c,i,a,d,t),u<=0&&(c+=1,u+=2*c+1),u>0&&(l-=1,u-=2*l+1)}}rasterizeLine(e,t){let{x1:r,y1:n,x2:o,y2:s,charCode:i,bgColorCode:a,fgColorCode:d}=e,l=Math.abs(o-r),c=Math.abs(s-n),u=r<o?1:-1,p=n<s?1:-1,h=l-c,C=r,y=n;for(;this.setCell(C,y,i,a,d,t),!(C===o&&y===s);){let f=2*h;f>-c&&(h-=c,C+=u),f<l&&(h+=l,y+=p)}}rasterizeEllipse(e,t){let{centerX:r,centerY:n,radiusX:o,radiusY:s,filled:i,charCode:a,bgColorCode:d,fgColorCode:l}=e;if(i)for(let c=-s;c<=s;c++){let u=n+c;if(!(u<0||u>=this.currentHeight))for(let p=-o;p<=o;p++){let h=r+p;if(h<0||h>=this.currentWidth)continue;if(p*p/(o*o)+c*c/(s*s)<=1){let y=u*this.currentWidth+h;t.set(y,a,l,d)}}}else{let c=Math.max(o,s)*8;for(let u=0;u<c;u++){let p=2*Math.PI*u/c,h=Math.round(r+o*Math.cos(p)),C=Math.round(n+s*Math.sin(p));this.setCell(h,C,a,d,l,t)}}}rasterizeTriangle(e,t){let{x1:r,y1:n,x2:o,y2:s,x3:i,y3:a,filled:d,charCode:l,bgColorCode:c,fgColorCode:u}=e;if(d){let p=[{x:r,y:n},{x:o,y:s},{x:i,y:a}].sort((b,v)=>b.y-v.y),[h,C,y]=p,f=g((b,v,B)=>{let O=Math.round(Math.min(v,B)),w=Math.round(Math.max(v,B));for(let z=O;z<=w;z++)if(z>=0&&z<this.currentWidth&&b>=0&&b<this.currentHeight){let ue=b*this.currentWidth+z;t.set(ue,l,u,c)}},"drawLine"),U=g((b,v,B,O,w)=>O===v?B:B+(b-v)*(w-B)/(O-v),"interpolate");for(let b=h.y;b<=C.y;b++){let v=U(b,h.y,h.x,y.y,y.x),B=U(b,h.y,h.x,C.y,C.x);f(b,v,B)}for(let b=C.y+1;b<=y.y;b++){let v=U(b,h.y,h.x,y.y,y.x),B=U(b,C.y,C.x,y.y,y.x);f(b,v,B)}}else this.drawLineSegment(r,n,o,s,l,c,u,t),this.drawLineSegment(o,s,i,a,l,c,u,t),this.drawLineSegment(i,a,r,n,l,c,u,t)}drawLineSegment(e,t,r,n,o,s,i,a){let d=Math.abs(r-e),l=Math.abs(n-t),c=e<r?1:-1,u=t<n?1:-1,p=d-l,h=e,C=t;for(;this.setCell(h,C,o,s,i,a),!(h===r&&C===n);){let y=2*p;y>-l&&(p-=l,h+=c),y<d&&(p+=d,C+=u)}}rasterizeDotCloud(e,t){let{charCode:r,bgColorCode:n,fgColorCode:o,positions:s}=e,i=t.getRawData(),a=this.currentWidth;for(let d=0;d<s.length;d++){if(s[d].posX<0||s[d].posX>=a||s[d].posY<0||s[d].posY>=this.currentHeight)continue;let l=(s[d].posY*a+s[d].posX)*3;i[l]=r,i[l+1]=o,i[l+2]=n}}rasterizeDotCloudMultiColor(e,t){let{dots:r}=e;for(let n of r)this.setCell(n.posX,n.posY,n.charCode,n.bgColorCode,n.fgColorCode,t)}rasterizeBitmask(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,charCode:i,bgColorCode:a,fgColorCode:d,override:l,mask:c}=e;for(let u=0;u<s;u++){let p=n+u;if(!(p<0||p>=this.currentHeight))for(let h=0;h<o;h++){let C=r+h;if(C<0||C>=this.currentWidth)continue;let y=u*o+h,f=Math.floor(y/8),U=y%8,b=(c[f]&1<<U)!==0,v=p*this.currentWidth+C;b?t.set(v,i,d,a):l&&t.set(v,255,255,255)}}}rasterizeBitmask4(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,override:i,variants:a,mask:d}=e;for(let l=0;l<s;l++){let c=n+l;if(!(c<0||c>=this.currentHeight))for(let u=0;u<o;u++){let p=r+u;if(p<0||p>=this.currentWidth)continue;let h=l*o+u,C=Math.floor(h/4),y=h%4*2,f=d[C]>>y&3,U=c*this.currentWidth+p;if(f>0){let b=a[f-1];t.set(U,b.charCode,b.fgColorCode,b.bgColorCode)}else i&&t.set(U,255,255,255)}}}rasterizeBitmask16(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,override:i,variants:a,mask:d}=e;for(let l=0;l<s;l++){let c=n+l;if(!(c<0||c>=this.currentHeight))for(let u=0;u<o;u++){let p=r+u;if(p<0||p>=this.currentWidth)continue;let h=l*o+u,C=Math.floor(h/2),y=h%2*4,f=d[C]>>y&15,U=c*this.currentWidth+p;if(f>0){let b=a[f-1];t.set(U,b.charCode,b.fgColorCode,b.bgColorCode)}else i&&t.set(U,255,255,255)}}}rasterizeClear(e,t){let{charCode:r,bgColorCode:n,fgColorCode:o}=e;t.clearWithColor(r,o,n)}rasterizeFillChar(e,t){let{patternWidth:r,patternHeight:n,pattern:o,bgColorCode:s,fgColorCode:i}=e;for(let a=0;a<this.currentHeight;a++)for(let d=0;d<this.currentWidth;d++){let l=d%r,u=a%n*r+l;if(u<o.length){let p=a*this.currentWidth+d;t.set(p,o[u],i,s)}}}rasterizeSprite(e,t,r){if(!r)return;let{posX:n,posY:o,spriteIndex:s,bgColorCode:i,fgColorCode:a}=e,d=r.getUnicolorSprite(s);if(!d)return;let l=d.data;for(let c=0;c<d.sizeY;c++)for(let u=0;u<d.sizeX;u++){let p=n+u,h=o+c;if(!this.isInBounds(p,h))continue;let C=c*d.sizeX+u,y=l.get(C);this.setCell(p,h,y,i,a,t)}}rasterizeSpriteMultiColor(e,t,r){if(!r)return;let{posX:n,posY:o,spriteIndex:s}=e,i=r.getMulticolorSprite(s);if(!i)return;let a=i.data;for(let d=0;d<i.sizeY;d++)for(let l=0;l<i.sizeX;l++){let c=n+l,u=o+d;if(!this.isInBounds(c,u))continue;let p=d*i.sizeX+l,h=a.getCharCode(p),C=a.getFgColorCode(p),y=a.getBgColorCode(p);this.setCell(c,u,h,y,C,t)}}rasterizeSpriteCloud(e,t,r){if(!r)return;let{spriteIndex:n,bgColorCode:o,fgColorCode:s,positions:i}=e,a=r.getUnicolorSprite(n);if(a){if(a.sizeX===1&&a.sizeY===1){let d=a.data.get(0),l=t.getRawData(),c=this.currentWidth;for(let u=0;u<i.length;u++){if(i[u].posX<0||i[u].posX>=c||i[u].posY<0||i[u].posY>=this.currentHeight)continue;let p=(i[u].posY*c+i[u].posX)*3;l[p]=d,l[p+1]=s,l[p+2]=o}return}for(let d=0;d<i.length;d++){let l=a.data;for(let c=0;c<a.sizeY;c++)for(let u=0;u<a.sizeX;u++){let p=i[d].posX+u,h=i[d].posY+c;if(!this.isInBounds(p,h))continue;let C=c*a.sizeX+u,y=l.get(C);this.setCell(p,h,y,o,s,t)}}}}rasterizeSpriteCloudMultiColor(e,t,r){if(!r)return;let{spriteIndex:n,positions:o}=e,s=r.getMulticolorSprite(n);if(s)for(let i=0;i<o.length;i++){let a=s.data;for(let d=0;d<s.sizeY;d++)for(let l=0;l<s.sizeX;l++){let c=o[i].posX+l,u=o[i].posY+d;if(!this.isInBounds(c,u))continue;let p=d*s.sizeX+l,h=a.getCharCode(p),C=a.getFgColorCode(p),y=a.getBgColorCode(p);this.setCell(c,u,h,y,C,t)}}}rasterizeSpriteCloudVaried(e,t,r){if(!r)return;let{sprites:n}=e;for(let o=0;o<n.length;o++){let s=n[o],i=r.getUnicolorSprite(s.spriteIndex);if(!i)continue;let a=i.data;for(let d=0;d<i.sizeY;d++)for(let l=0;l<i.sizeX;l++){let c=s.posX+l,u=s.posY+d;if(!this.isInBounds(c,u))continue;let p=d*i.sizeX+l,h=a.get(p);this.setCell(c,u,h,s.bgColorCode,s.fgColorCode,t)}}}rasterizeSpriteCloudVariedMultiColor(e,t,r){if(!r)return;let{sprites:n}=e;for(let o=0;o<n.length;o++){let s=n[o],i=r.getMulticolorSprite(s.spriteIndex);if(!i)continue;let a=i.data;for(let d=0;d<i.sizeY;d++)for(let l=0;l<i.sizeX;l++){let c=s.posX+l,u=s.posY+d;if(!this.isInBounds(c,u))continue;let p=d*i.sizeX+l,h=a.getCharCode(p),C=a.getFgColorCode(p),y=a.getBgColorCode(p);this.setCell(c,u,h,y,C,t)}}}rasterizeFillSprite(e,t,r){if(!r)return;let{spriteIndex:n,bgColorCode:o,fgColorCode:s}=e,i=r.getUnicolorSprite(n);if(!i)return;let a=i.data;for(let d=0;d<this.currentHeight;d++)for(let l=0;l<this.currentWidth;l++){let c=l%i.sizeX,p=d%i.sizeY*i.sizeX+c,h=a.get(p),C=d*this.currentWidth+l;t.set(C,h,s,o)}}rasterizeFillSpriteMultiColor(e,t,r){if(!r)return;let{spriteIndex:n}=e,o=r.getMulticolorSprite(n);if(!o)return;let s=o.data;for(let i=0;i<this.currentHeight;i++)for(let a=0;a<this.currentWidth;a++){let d=a%o.sizeX,c=i%o.sizeY*o.sizeX+d,u=s.getCharCode(c),p=s.getFgColorCode(c),h=s.getBgColorCode(c),C=i*this.currentWidth+a;t.set(C,u,p,h)}}setCell(e,t,r,n,o,s){if(!this.isInBounds(e,t))return;let i=t*this.currentWidth+e;s.set(i,r,o,n)}isInBounds(e,t){return e>=0&&e<this.currentWidth&&t>=0&&t<this.currentHeight}};g(Ee,"LayerRasterizer");var pe=Ee;var T=class T{constructor(e,t,r,n,o=!1){m(this,"id",0);m(this,"origin");m(this,"orders",[]);m(this,"zOrder",0);m(this,"data");m(this,"width");m(this,"height");m(this,"isStatic",!1);m(this,"spriteRegistry");m(this,"mode","server");m(this,"previousOrigin");m(this,"previousZOrder");m(this,"enabled",!0);m(this,"useSetMode",!1);m(this,"needsCommit",!1);if(r<1||r>256||n<1||n>256)throw new Error(`Layer size must be 1-256, got ${r}\xD7${n}`);this.origin=e,this.zOrder=t,this.width=r,this.height=n,this.isStatic=o,this.data=new R(r*n),this.previousOrigin=new st.Vector2(e.x,e.y),this.previousZOrder=t}setMode(e){this.mode=e}setSpriteRegistry(e){this.spriteRegistry=e}getOrders(){return this.orders}addOrders(e){this.orders.push(...e),this.useSetMode=!1,(this.mode==="client"||this.mode==="standalone")&&T.rasterizer.rasterizeOrders(e,this.data,this.width,this.height,"add",this.spriteRegistry)}setOrders(e){this.orders=e,this.useSetMode=!0,(this.mode==="client"||this.mode==="standalone")&&T.rasterizer.rasterizeOrders(e,this.data,this.width,this.height,"set",this.spriteRegistry)}clearOrders(){this.orders=[],(this.mode==="client"||this.mode==="standalone")&&T.rasterizer.clearBuffer(this.data)}getOrigin(){return this.origin}setOrigin(e){this.origin=e}getZOrder(){return this.zOrder}setZOrder(e){this.zOrder=e}getId(){return this.id}setId(e){this.id=e}getData(){return this.data}getWidth(){return this.width}getHeight(){return this.height}getCellAt(e,t){return e<0||e>=this.width||t<0||t>=this.height?null:this.data.get(t*this.width+e)}setStatic(e){this.isStatic=e}getStatic(){return this.isStatic}setEnabled(e){this.enabled=e}isEnabled(){return this.enabled}hasOriginChanged(){return this.origin.x!==this.previousOrigin.x||this.origin.y!==this.previousOrigin.y}hasZOrderChanged(){return this.zOrder!==this.previousZOrder}calculateUpdateFlags(){if(!this.enabled)return 0;let e=1;return this.useSetMode&&(e|=2),this.hasOriginChanged()&&(e|=4),this.hasZOrderChanged()&&(e|=8),(this.orders.length>0||this.needsCommit&&this.useSetMode)&&(e|=4),e}resetChangeTracking(){this.previousOrigin.x=this.origin.x,this.previousOrigin.y=this.origin.y,this.previousZOrder=this.zOrder}commit(){this.needsCommit=!0}getNeedsCommit(){return this.needsCommit}resetCommit(){this.needsCommit=!1}};g(T,"Layer"),m(T,"rasterizer",new pe);var $=T;var Re=class Re{constructor(){m(this,"axes",new Map);m(this,"buttons",new Map);m(this,"axisNameToId",new Map);m(this,"buttonNameToId",new Map);m(this,"version",1)}defineAxis(e,t,r=[],n=-1,o=1,s=0){if(e<0||e>255)throw new Error(`Axis bindingId must be between 0 and 255, got ${e}`);if(this.axes.has(e))throw new Error(`Axis bindingId ${e} is already defined`);if(this.axisNameToId.has(t)){let a=this.axisNameToId.get(t);throw new Error(`Axis name "${t}" is already defined with bindingId ${a}`)}let i={bindingId:e,name:t,min:n,max:o,defaultValue:s,sources:r};this.axes.set(e,i),this.axisNameToId.set(t,e),this.version++}defineButton(e,t,r=[],n=!1){if(e<0||e>255)throw new Error(`Button bindingId must be between 0 and 255, got ${e}`);if(this.buttons.has(e))throw new Error(`Button bindingId ${e} is already defined`);if(this.buttonNameToId.has(t)){let s=this.buttonNameToId.get(t);throw new Error(`Button name "${t}" is already defined with bindingId ${s}`)}let o={bindingId:e,name:t,defaultValue:n,sources:r};this.buttons.set(e,o),this.buttonNameToId.set(t,e),this.version++}evaluateAxis(e,t){let r=this.axes.get(e);if(!r)return 0;let n=0;for(let s of r.sources){let a=t.get(s.sourceId)??0,d=s.deadzone??0;Math.abs(a)<d?a=0:a=(a>0?1:-1)*((Math.abs(a)-d)/(1-d));let l=s.scale??1;a*=l;let c=s.sensitivity??1;a*=c,s.invert&&(a=-a),n+=a}return Math.max(r.min,Math.min(r.max,n))}evaluateButton(e,t){let r=this.buttons.get(e);if(!r)return!1;for(let n of r.sources)if(t.get(n.sourceId)??!1)return!0;return!1}toLoadPacket(){let e={type:"input-binding",version:this.version,axes:Array.from(this.axes.values()),buttons:Array.from(this.buttons.values())};return JSON.stringify(e)}toLoadPacketObject(){return{type:"input-binding",version:this.version,axes:Array.from(this.axes.values()),buttons:Array.from(this.buttons.values())}}getAxisBindingId(e){return this.axisNameToId.get(e)??null}getButtonBindingId(e){return this.buttonNameToId.get(e)??null}getAxisName(e){return this.axes.get(e)?.name??null}getButtonName(e){return this.buttons.get(e)?.name??null}getAxisBinding(e){return this.axes.get(e)??null}getButtonBinding(e){return this.buttons.get(e)??null}hasAxis(e){return this.axes.has(e)}hasButton(e){return this.buttons.has(e)}getAxisCount(){return this.axes.size}getButtonCount(){return this.buttons.size}getAllAxes(){return Array.from(this.axes.values())}getAllButtons(){return Array.from(this.buttons.values())}getVersion(){return this.version}removeAxis(e){let t=this.axes.get(e);return t?(this.axes.delete(e),this.axisNameToId.delete(t.name),this.version++,!0):!1}removeButton(e){let t=this.buttons.get(e);return t?(this.buttons.delete(e),this.buttonNameToId.delete(t.name),this.version++,!0):!1}clearAxes(){this.axes.clear(),this.axisNameToId.clear(),this.version++}clearButtons(){this.buttons.clear(),this.buttonNameToId.clear(),this.version++}clear(){this.axes.clear(),this.axisNameToId.clear(),this.buttons.clear(),this.buttonNameToId.clear(),this.version=1}toString(){let e=`InputBindingRegistry (version ${this.version})
1
+ "use strict";var ae=Object.defineProperty;var _t=Object.getOwnPropertyDescriptor;var Ht=Object.getOwnPropertyNames;var Nt=Object.prototype.hasOwnProperty;var Wt=(g,e,t)=>e in g?ae(g,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):g[e]=t;var C=(g,e)=>ae(g,"name",{value:e,configurable:!0});var E=(g,e)=>()=>(g&&(e=g(g=0)),e);var D=(g,e)=>{for(var t in e)ae(g,t,{get:e[t],enumerable:!0})},$t=(g,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ht(e))!Nt.call(g,n)&&n!==t&&ae(g,n,{get:()=>e[n],enumerable:!(r=_t(e,n))||r.enumerable});return g};var z=g=>$t(ae({},"__esModule",{value:!0}),g);var x=(g,e,t)=>(Wt(g,typeof e!="symbol"?e+"":e,t),t);var De,It=E(()=>{"use strict";De=(o=>(o[o.Rectangle=1]="Rectangle",o[o.Circle=2]="Circle",o[o.Line=3]="Line",o[o.Ellipse=4]="Ellipse",o[o.Triangle=5]="Triangle",o))(De||{})});var Ut={};D(Ut,{AudioOrderType:()=>Se,AudioTargetType:()=>Ie,getAudioOrderTypeName:()=>Ne,isValidAudioOrderType:()=>He});function He(g){return g>=1&&g<=9}function Ne(g){switch(g){case 1:return"PlaySound";case 2:return"PlayGlobalSound";case 3:return"StopSound";case 4:return"FadeOutSound";case 5:return"PauseSound";case 6:return"ResumeSound";case 7:return"SetListenerPosition";case 8:return"ConfigureSpatial";case 9:return"SetSoundEffects";default:return`UnknownAudio(0x${g.toString(16)})`}}var Se,Ie,We=E(()=>{"use strict";Se=(d=>(d[d.PlaySound=1]="PlaySound",d[d.PlayGlobalSound=2]="PlayGlobalSound",d[d.StopSound=3]="StopSound",d[d.FadeOutSound=4]="FadeOutSound",d[d.PauseSound=5]="PauseSound",d[d.ResumeSound=6]="ResumeSound",d[d.SetListenerPosition=7]="SetListenerPosition",d[d.ConfigureSpatial=8]="ConfigureSpatial",d[d.SetSoundEffects=9]="SetSoundEffects",d))(Se||{}),Ie=(r=>(r[r.InstanceId=0]="InstanceId",r[r.SoundId=1]="SoundId",r[r.All=2]="All",r))(Ie||{});C(He,"isValidAudioOrderType");C(Ne,"getAudioOrderTypeName")});var wt={};D(wt,{PlaySoundFlags:()=>fe,SoundEffectsFlags:()=>Ot});var fe,Ot,$e=E(()=>{"use strict";fe=(a=>(a[a.Loop=1]="Loop",a[a.HasVolume=2]="HasVolume",a[a.HasPitch=4]="HasPitch",a[a.HasFadeIn=8]="HasFadeIn",a[a.HasPosition=16]="HasPosition",a[a.HasLowpass=32]="HasLowpass",a[a.HasHighpass=64]="HasHighpass",a[a.HasReverb=128]="HasReverb",a))(fe||{}),Ot=(r=>(r[r.HasLowpass=1]="HasLowpass",r[r.HasHighpass=2]="HasHighpass",r[r.HasReverb=4]="HasReverb",r))(Ot||{})});var F,S,L=E(()=>{"use strict";F=class F{constructor(e){x(this,"data");x(this,"view");this.data=new Uint8Array(e),this.view=new DataView(this.data.buffer)}static from(e){let t=new F(0);return t.data=e,t.view=new DataView(e.buffer,e.byteOffset,e.byteLength),t}static allocUnsafe(e){return new F(e)}get length(){return this.data.length}toUint8Array(){return this.data}readUInt8(e){return this.view.getUint8(e)}readInt8(e){return this.view.getInt8(e)}readUInt16BE(e){return this.view.getUint16(e,!1)}readInt16BE(e){return this.view.getInt16(e,!1)}readUInt16LE(e){return this.view.getUint16(e,!0)}readInt16LE(e){return this.view.getInt16(e,!0)}readUInt32BE(e){return this.view.getUint32(e,!1)}readInt32BE(e){return this.view.getInt32(e,!1)}readUInt32LE(e){return this.view.getUint32(e,!0)}readInt32LE(e){return this.view.getInt32(e,!0)}readBigUInt64BE(e){return this.view.getBigUint64(e,!1)}readBigInt64BE(e){return this.view.getBigInt64(e,!1)}readBigUInt64LE(e){return this.view.getBigUint64(e,!0)}readBigInt64LE(e){return this.view.getBigInt64(e,!0)}writeUInt8(e,t){this.view.setUint8(t,e)}writeInt8(e,t){this.view.setInt8(t,e)}writeUInt16BE(e,t){this.view.setUint16(t,e,!1)}writeInt16BE(e,t){this.view.setInt16(t,e,!1)}writeUInt16LE(e,t){this.view.setUint16(t,e,!0)}writeInt16LE(e,t){this.view.setInt16(t,e,!0)}writeUInt32BE(e,t){this.view.setUint32(t,e,!1)}writeInt32BE(e,t){this.view.setInt32(t,e,!1)}writeUInt32LE(e,t){this.view.setUint32(t,e,!0)}writeInt32LE(e,t){this.view.setInt32(t,e,!0)}writeBigUInt64BE(e,t){this.view.setBigUint64(t,e,!1)}writeBigInt64BE(e,t){this.view.setBigInt64(t,e,!1)}writeBigUInt64LE(e,t){this.view.setBigUint64(t,e,!0)}writeBigInt64LE(e,t){this.view.setBigInt64(t,e,!0)}copy(e,t=0,r=0,n=this.length){let o=this.data.subarray(r,n);return e.data.set(o,t),o.length}slice(e,t){let r=this.data.slice(e,t);return F.from(r)}subarray(e,t){let r=this.data.subarray(e,t);return F.from(r)}toBuffer(){return typeof Buffer<"u"&&Buffer.from?Buffer.from(this.data):this.data}static fromNodeBuffer(e){return e instanceof Uint8Array?F.from(e):F.from(new Uint8Array(e))}};C(F,"BufferCompat");S=F});var st,Be,vt=E(()=>{"use strict";st=class st{decode(e,t=0){this.checkSize(e,t,7);let n=t,o=e.readUInt8(n++),i=e.readUInt16BE(n);n+=2;let s=e.readUInt16BE(n);n+=2;let a=e.readUInt8(n++)+1,d=e.readUInt8(n++)+1;return{display:{id:o,originX:i,originY:s,sizeX:a,sizeY:d},bytesRead:7}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short for display: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};C(st,"DisplayDecoder");Be=st});var at,ke,At=E(()=>{"use strict";at=class at{decode(e,t=0){if(t>=e.length)throw new Error("Buffer too short to decode order type");let r=e.readUInt8(t);switch(r){case 1:return this.decodeCharOrder(e,t);case 2:return this.decodeTextOrder(e,t);case 23:return this.decodeTextMultilineOrder(e,t);case 3:return this.decodeSubFrameOrder(e,t);case 4:return this.decodeSubFrameMultiColorOrder(e,t);case 5:return this.decodeFullFrameOrder(e,t);case 6:return this.decodeFullFrameMultiColorOrder(e,t);case 7:return this.decodeSpriteOrder(e,t);case 8:return this.decodeSpriteMultiColorOrder(e,t);case 9:return this.decodeColorMapOrder(e,t);case 10:return this.decodeShapeOrder(e,t);case 11:return this.decodeDotCloudOrder(e,t);case 12:return this.decodeDotCloudMultiColorOrder(e,t);case 17:return this.decodeBitmaskOrder(e,t);case 18:return this.decodeBitmask4Order(e,t);case 24:return this.decodeBitmask16Order(e,t);case 13:return this.decodeSpriteCloudOrder(e,t);case 14:return this.decodeSpriteCloudMultiColorOrder(e,t);case 15:return this.decodeSpriteCloudVariedOrder(e,t);case 16:return this.decodeSpriteCloudVariedMultiColorOrder(e,t);case 19:return this.decodeClearOrder(e,t);case 20:return this.decodeFillCharOrder(e,t);case 21:return this.decodeFillSpriteOrder(e,t);case 22:return this.decodeFillSpriteMultiColorOrder(e,t);case 32:return this.decodeTriggerSoundOrder(e,t);case 33:return this.decodeTriggerGlobalSoundOrder(e,t);default:throw new Error(`Unknown order type: 0x${r.toString(16)}`)}}decodeCharOrder(e,t){this.checkSize(e,t,6);let r=t;return{order:{type:1,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),charCode:e.readUInt8(r+3),bgColorCode:e.readUInt8(r+4),fgColorCode:e.readUInt8(r+5)},bytesRead:6}}decodeTextOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3);this.checkSize(e,t,5+n);let o=e.subarray(r+4,r+4+n),i=new TextDecoder().decode(o.toUint8Array());return{order:{type:2,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),text:i,bgColorCode:e.readUInt8(r+4+n),fgColorCode:e.readUInt8(r+5+n)},bytesRead:6+n}}decodeTextMultilineOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3);this.checkSize(e,t,5+n);let o=e.subarray(r+4,r+4+n),i=new TextDecoder().decode(o.toUint8Array());return{order:{type:23,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),text:i,bgColorCode:e.readUInt8(r+4+n),fgColorCode:e.readUInt8(r+5+n)},bytesRead:6+n}}decodeSubFrameOrder(e,t){this.checkSize(e,t,7);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),i=n*o;this.checkSize(e,t,7+i);let s=[];for(let d=0;d<i;d++)s.push(e.readUInt8(r+7+d));return{order:{type:3,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,bgColorCode:e.readUInt8(r+5),fgColorCode:e.readUInt8(r+6),frame:s},bytesRead:7+i}}decodeSubFrameMultiColorOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),i=n*o;this.checkSize(e,t,5+i*3);let s=[];for(let d=0;d<i;d++){let u=r+5+d*3;s.push({charCode:e.readUInt8(u),bgColorCode:e.readUInt8(u+1),fgColorCode:e.readUInt8(u+2)})}return{order:{type:4,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,frame:s},bytesRead:5+i*3}}decodeFullFrameOrder(e,t,r){this.checkSize(e,t,3);let n=t,o=r||e.length-t-3;this.checkSize(e,t,3+o);let i=[];for(let a=0;a<o;a++)i.push(e.readUInt8(n+3+a));return{order:{type:5,bgColorCode:e.readUInt8(n+1),fgColorCode:e.readUInt8(n+2),frame:i},bytesRead:3+o}}decodeFullFrameMultiColorOrder(e,t,r){this.checkSize(e,t,1);let n=t,o=r||Math.floor((e.length-t-1)/3);this.checkSize(e,t,1+o*3);let i=[];for(let a=0;a<o;a++){let d=n+1+a*3;i.push({charCode:e.readUInt8(d),bgColorCode:e.readUInt8(d+1),fgColorCode:e.readUInt8(d+2)})}return{order:{type:6,frame:i},bytesRead:1+o*3}}decodeSpriteOrder(e,t){this.checkSize(e,t,6);let r=t;return{order:{type:7,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),spriteIndex:e.readUInt8(r+3),bgColorCode:e.readUInt8(r+4),fgColorCode:e.readUInt8(r+5)},bytesRead:6}}decodeSpriteMultiColorOrder(e,t){this.checkSize(e,t,4);let r=t;return{order:{type:8,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),spriteIndex:e.readUInt8(r+3)},bytesRead:4}}decodeColorMapOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),i=n*o;this.checkSize(e,t,5+i*2);let s=[];for(let d=0;d<i;d++){let u=r+5+d*2;s.push({bgColorCode:e.readUInt8(u),fgColorCode:e.readUInt8(u+1)})}return{order:{type:9,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,colorData:s},bytesRead:5+i*2}}decodeShapeOrder(e,t){this.checkSize(e,t,2);let r=t,n=e.readUInt8(r+1),{shapeData:o,bytesRead:i}=this.decodeShapeData(e,r+2,n);return{order:{type:10,shapeType:n,shapeData:o},bytesRead:2+i}}decodeShapeData(e,t,r){let n=t;switch(r){case 1:return this.checkSize(e,t,8),{shapeData:{posX:e.readUInt8(n),posY:e.readUInt8(n+1),width:e.readUInt8(n+2),height:e.readUInt8(n+3),filled:e.readUInt8(n+4)===1,charCode:e.readUInt8(n+5),bgColorCode:e.readUInt8(n+6),fgColorCode:e.readUInt8(n+7)},bytesRead:8};case 2:return this.checkSize(e,t,7),{shapeData:{centerX:e.readUInt8(n),centerY:e.readUInt8(n+1),radius:e.readUInt8(n+2),filled:e.readUInt8(n+3)===1,charCode:e.readUInt8(n+4),bgColorCode:e.readUInt8(n+5),fgColorCode:e.readUInt8(n+6)},bytesRead:7};case 3:return this.checkSize(e,t,7),{shapeData:{x1:e.readUInt8(n),y1:e.readUInt8(n+1),x2:e.readUInt8(n+2),y2:e.readUInt8(n+3),charCode:e.readUInt8(n+4),bgColorCode:e.readUInt8(n+5),fgColorCode:e.readUInt8(n+6)},bytesRead:7};case 4:return this.checkSize(e,t,8),{shapeData:{centerX:e.readUInt8(n),centerY:e.readUInt8(n+1),radiusX:e.readUInt8(n+2),radiusY:e.readUInt8(n+3),filled:e.readUInt8(n+4)===1,charCode:e.readUInt8(n+5),bgColorCode:e.readUInt8(n+6),fgColorCode:e.readUInt8(n+7)},bytesRead:8};case 5:return this.checkSize(e,t,10),{shapeData:{x1:e.readUInt8(n),y1:e.readUInt8(n+1),x2:e.readUInt8(n+2),y2:e.readUInt8(n+3),x3:e.readUInt8(n+4),y3:e.readUInt8(n+5),filled:e.readUInt8(n+6)===1,charCode:e.readUInt8(n+7),bgColorCode:e.readUInt8(n+8),fgColorCode:e.readUInt8(n+9)},bytesRead:10};default:throw new Error(`Unknown shape type: ${r}`)}}decodeDotCloudOrder(e,t){this.checkSize(e,t,6);let r=t,n=e.readUInt16BE(r+4);this.checkSize(e,t,6+n*2);let o=[];for(let s=0;s<n;s++){let a=r+6+s*2;o.push({posX:e.readUInt8(a),posY:e.readUInt8(a+1)})}return{order:{type:11,charCode:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3),positions:o},bytesRead:6+n*2}}decodeDotCloudMultiColorOrder(e,t){this.checkSize(e,t,3);let r=t,n=e.readUInt16BE(r+1);this.checkSize(e,t,3+n*5);let o=[];for(let s=0;s<n;s++){let a=r+3+s*5;o.push({charCode:e.readUInt8(a),bgColorCode:e.readUInt8(a+1),fgColorCode:e.readUInt8(a+2),posX:e.readUInt8(a+3),posY:e.readUInt8(a+4)})}return{order:{type:12,dots:o},bytesRead:3+n*5}}decodeBitmaskOrder(e,t){this.checkSize(e,t,9);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),i=Math.ceil(n*o/8);this.checkSize(e,t,9+i);let s=new Uint8Array(i);for(let d=0;d<i;d++)s[d]=e.readUInt8(r+9+d);return{order:{type:17,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,charCode:e.readUInt8(r+5),bgColorCode:e.readUInt8(r+6),fgColorCode:e.readUInt8(r+7),override:e.readUInt8(r+8)===1,mask:s},bytesRead:9+i}}decodeBitmask4Order(e,t){this.checkSize(e,t,15);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),i=Math.ceil(n*o/4);this.checkSize(e,t,15+i);let s=[{charCode:e.readUInt8(r+6),bgColorCode:e.readUInt8(r+7),fgColorCode:e.readUInt8(r+8)},{charCode:e.readUInt8(r+9),bgColorCode:e.readUInt8(r+10),fgColorCode:e.readUInt8(r+11)},{charCode:e.readUInt8(r+12),bgColorCode:e.readUInt8(r+13),fgColorCode:e.readUInt8(r+14)}],a=new Uint8Array(i);for(let u=0;u<i;u++)a[u]=e.readUInt8(r+15+u);return{order:{type:18,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,override:e.readUInt8(r+5)===1,variants:s,mask:a},bytesRead:15+i}}decodeBitmask16Order(e,t){this.checkSize(e,t,51);let r=t,n=e.readUInt8(r+3),o=e.readUInt8(r+4),i=Math.ceil(n*o/2);this.checkSize(e,t,51+i);let s=[];for(let u=0;u<15;u++){let c=r+6+u*3;s.push({charCode:e.readUInt8(c),bgColorCode:e.readUInt8(c+1),fgColorCode:e.readUInt8(c+2)})}let a=new Uint8Array(i);for(let u=0;u<i;u++)a[u]=e.readUInt8(r+51+u);return{order:{type:24,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),sizeX:n,sizeY:o,override:e.readUInt8(r+5)===1,variants:s,mask:a},bytesRead:51+i}}decodeSpriteCloudOrder(e,t){this.checkSize(e,t,6);let r=t,n=e.readUInt16BE(r+4);this.checkSize(e,t,6+n*2);let o=[];for(let s=0;s<n;s++){let a=r+6+s*2;o.push({posX:e.readUInt8(a),posY:e.readUInt8(a+1)})}return{order:{type:13,spriteIndex:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3),positions:o},bytesRead:6+n*2}}decodeSpriteCloudMultiColorOrder(e,t){this.checkSize(e,t,4);let r=t,n=e.readUInt16BE(r+2);this.checkSize(e,t,4+n*2);let o=[];for(let s=0;s<n;s++){let a=r+4+s*2;o.push({posX:e.readUInt8(a),posY:e.readUInt8(a+1)})}return{order:{type:14,spriteIndex:e.readUInt8(r+1),positions:o},bytesRead:4+n*2}}decodeSpriteCloudVariedOrder(e,t){this.checkSize(e,t,3);let r=t,n=e.readUInt16BE(r+1);this.checkSize(e,t,3+n*5);let o=[];for(let s=0;s<n;s++){let a=r+3+s*5;o.push({spriteIndex:e.readUInt8(a),bgColorCode:e.readUInt8(a+1),fgColorCode:e.readUInt8(a+2),posX:e.readUInt8(a+3),posY:e.readUInt8(a+4)})}return{order:{type:15,sprites:o},bytesRead:3+n*5}}decodeSpriteCloudVariedMultiColorOrder(e,t){this.checkSize(e,t,3);let r=t,n=e.readUInt16BE(r+1);this.checkSize(e,t,3+n*3);let o=[];for(let s=0;s<n;s++){let a=r+3+s*3;o.push({spriteIndex:e.readUInt8(a),posX:e.readUInt8(a+1),posY:e.readUInt8(a+2)})}return{order:{type:16,sprites:o},bytesRead:3+n*3}}decodeClearOrder(e,t){this.checkSize(e,t,4);let r=t;return{order:{type:19,charCode:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3)},bytesRead:4}}decodeFillCharOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r+1),o=e.readUInt8(r+2),i=n*o;this.checkSize(e,t,5+i);let s=[];for(let d=0;d<i;d++)s.push(e.readUInt8(r+5+d));return{order:{type:20,patternWidth:n,patternHeight:o,bgColorCode:e.readUInt8(r+3),fgColorCode:e.readUInt8(r+4),pattern:s},bytesRead:5+i}}decodeFillSpriteOrder(e,t){this.checkSize(e,t,4);let r=t;return{order:{type:21,spriteIndex:e.readUInt8(r+1),bgColorCode:e.readUInt8(r+2),fgColorCode:e.readUInt8(r+3)},bytesRead:4}}decodeFillSpriteMultiColorOrder(e,t){this.checkSize(e,t,2);let r=t;return{order:{type:22,spriteIndex:e.readUInt8(r+1)},bytesRead:2}}decodeTriggerSoundOrder(e,t){this.checkSize(e,t,5);let r=t;return{order:{type:32,posX:e.readUInt8(r+1),posY:e.readUInt8(r+2),soundId:e.readUInt8(r+3),loop:e.readUInt8(r+4)===1},bytesRead:5}}decodeTriggerGlobalSoundOrder(e,t){this.checkSize(e,t,3);let r=t;return{order:{type:33,soundId:e.readUInt8(r+1),loop:e.readUInt8(r+2)===1},bytesRead:3}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};C(at,"OrderDecoder");ke=at});var dt,ze,Bt=E(()=>{"use strict";At();dt=class dt{constructor(){x(this,"orderDecoder");this.orderDecoder=new ke}decode(e,t=0){this.checkSize(e,t,13);let n=t,o=e.readUInt16BE(n);n+=2;let i=e.readUInt8(n++),s=e.readUInt8(n++),a=e.readUInt16BE(n);n+=2;let d=e.readUInt16BE(n);n+=2;let u=e.readUInt16BE(n);n+=2;let c=e.readUInt16BE(n);n+=2;let l=e.readUInt8(n++),p=[],h=n;for(let b=0;b<l;b++){let f=this.orderDecoder.decode(e,h);p.push(f.order),h+=f.bytesRead}return{layer:{id:o,updateFlags:i,zIndex:s,originX:a,originY:d,width:u,height:c,orderCount:l,orders:p},bytesRead:h-t}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short for layer: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};C(dt,"LayerDecoder");ze=dt});var ut,ne,lt=E(()=>{"use strict";ut=class ut{decode(e,t=0){if(t>=e.length)throw new Error("Buffer too short to decode audio order type");let r=e.readUInt8(t);switch(r){case 1:return this.decodePlaySoundOrder(e,t);case 2:return this.decodePlayGlobalSoundOrder(e,t);case 3:return this.decodeStopSoundOrder(e,t);case 4:return this.decodeFadeOutSoundOrder(e,t);case 5:return this.decodePauseSoundOrder(e,t);case 6:return this.decodeResumeSoundOrder(e,t);case 7:return this.decodeSetListenerPositionOrder(e,t);case 8:return this.decodeConfigureSpatialOrder(e,t);case 9:return this.decodeSetSoundEffectsOrder(e,t);default:throw new Error(`Unknown audio order type: 0x${r.toString(16)}`)}}decodePlaySoundOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r++),o=e.readUInt8(r++),i=e.readUInt16BE(r);r+=2;let s=e.readUInt8(r++),a={type:n,soundId:o,instanceId:i,flags:s};return s&2&&(this.checkSize(e,r,1),a.volume=e.readUInt8(r++)),s&4&&(this.checkSize(e,r,1),a.pitch=e.readUInt8(r++)),s&8&&(this.checkSize(e,r,1),a.fadeIn=e.readUInt8(r++)),s&16&&(this.checkSize(e,r,4),a.posX=e.readUInt16BE(r),r+=2,a.posY=e.readUInt16BE(r),r+=2),s&32&&(this.checkSize(e,r,1),a.lowpass=e.readUInt8(r++)),s&64&&(this.checkSize(e,r,1),a.highpass=e.readUInt8(r++)),s&128&&(this.checkSize(e,r,1),a.reverb=e.readUInt8(r++)),{order:a,bytesRead:r-t}}decodePlayGlobalSoundOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r++),o=e.readUInt8(r++),i=e.readUInt16BE(r);r+=2;let s=e.readUInt8(r++),a={type:n,soundId:o,instanceId:i,flags:s};return s&2&&(this.checkSize(e,r,1),a.volume=e.readUInt8(r++)),s&4&&(this.checkSize(e,r,1),a.pitch=e.readUInt8(r++)),s&8&&(this.checkSize(e,r,1),a.fadeIn=e.readUInt8(r++)),s&32&&(this.checkSize(e,r,1),a.lowpass=e.readUInt8(r++)),s&64&&(this.checkSize(e,r,1),a.highpass=e.readUInt8(r++)),s&128&&(this.checkSize(e,r,1),a.reverb=e.readUInt8(r++)),{order:a,bytesRead:r-t}}decodeStopSoundOrder(e,t){this.checkSize(e,t,2);let r=t,n=e.readUInt8(r++),o=e.readUInt8(r++),i={type:n,targetType:o};return o===0?(this.checkSize(e,r,2),i.target=e.readUInt16BE(r),r+=2):o===1&&(this.checkSize(e,r,1),i.target=e.readUInt8(r++)),{order:i,bytesRead:r-t}}decodeFadeOutSoundOrder(e,t){this.checkSize(e,t,3);let r=t,n=e.readUInt8(r++),o=e.readUInt8(r++),i=e.readUInt8(r++),s={type:n,targetType:o,duration:i};return o===0?(this.checkSize(e,r,2),s.target=e.readUInt16BE(r),r+=2):o===1&&(this.checkSize(e,r,1),s.target=e.readUInt8(r++)),{order:s,bytesRead:r-t}}decodePauseSoundOrder(e,t){this.checkSize(e,t,2);let r=t,n=e.readUInt8(r++),o=e.readUInt8(r++),i={type:n,targetType:o};return o===0?(this.checkSize(e,r,2),i.target=e.readUInt16BE(r),r+=2):o===1&&(this.checkSize(e,r,1),i.target=e.readUInt8(r++)),{order:i,bytesRead:r-t}}decodeResumeSoundOrder(e,t){this.checkSize(e,t,2);let r=t,n=e.readUInt8(r++),o=e.readUInt8(r++),i={type:n,targetType:o};return o===0?(this.checkSize(e,r,2),i.target=e.readUInt16BE(r),r+=2):o===1&&(this.checkSize(e,r,1),i.target=e.readUInt8(r++)),{order:i,bytesRead:r-t}}decodeSetListenerPositionOrder(e,t){this.checkSize(e,t,5);let r=t,n=e.readUInt8(r++),o=e.readUInt16BE(r);r+=2;let i=e.readUInt16BE(r);return r+=2,{order:{type:n,x:o,y:i},bytesRead:5}}decodeConfigureSpatialOrder(e,t){this.checkSize(e,t,5);let r=t;return{order:{type:e.readUInt8(r),maxDistance:e.readUInt8(r+1),referenceDistance:e.readUInt8(r+2),rolloffFactor:e.readUInt8(r+3),panSpread:e.readUInt8(r+4)},bytesRead:5}}decodeSetSoundEffectsOrder(e,t){this.checkSize(e,t,4);let r=t,n=e.readUInt8(r++),o=e.readUInt16BE(r);r+=2;let i=e.readUInt8(r++),s={type:n,instanceId:o,flags:i};return i&1&&(this.checkSize(e,r,1),s.lowpass=e.readUInt8(r++)),i&2&&(this.checkSize(e,r,1),s.highpass=e.readUInt8(r++)),i&4&&(this.checkSize(e,r,1),s.reverb=e.readUInt8(r++)),{order:s,bytesRead:r-t}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short for audio order: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};C(ut,"AudioOrderDecoder");ne=ut});var kt={};D(kt,{UpdatePacketDecoder:()=>ce});var ct,ce,pt=E(()=>{"use strict";vt();Bt();lt();L();ct=class ct{constructor(){x(this,"displayDecoder");x(this,"layerDecoder");x(this,"audioOrderDecoder");this.displayDecoder=new Be,this.layerDecoder=new ze,this.audioOrderDecoder=new ne}decode(e,t=0){let r=S.from(e);this.checkSize(r,t,12);let o=t,i=Number(r.readBigUInt64BE(o));o+=8;let s=r.readUInt8(o);o+=1;let a=[];for(let h=0;h<s;h++){let m=this.displayDecoder.decode(r,o);a.push(m.display),o+=m.bytesRead}this.checkSize(r,o,2);let d=r.readUInt16BE(o);o+=2;let u=[];for(let h=0;h<d;h++){let m=this.layerDecoder.decode(r,o);u.push(m.layer),o+=m.bytesRead}this.checkSize(r,o,1);let c=r.readUInt8(o);o+=1;let l=[];for(let h=0;h<c;h++){let m=this.audioOrderDecoder.decode(r,o);l.push(m.order),o+=m.bytesRead}return{tick:i,displayCount:s,displays:a,layerCount:d,layers:u,audioOrderCount:c,audioOrders:l}}isValid(e,t=0){let r=S.from(e);try{return this.checkSize(r,t,12),!0}catch{return!1}}decodeHeader(e,t=0){let r=S.from(e);this.checkSize(r,t,12);let n=t,o=Number(r.readBigUInt64BE(n));n+=8;let i=r.readUInt8(n);n+=1,n+=i*7,this.checkSize(r,n,2);let s=r.readUInt16BE(n);return{tick:o,displayCount:i,layerCount:s}}checkSize(e,t,r){if(t+r>e.length)throw new Error(`Buffer too short for update packet: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes available`)}};C(ct,"UpdatePacketDecoder");ce=ct});var _={};D(_,{LoadType:()=>Ee});var Ee,T=E(()=>{"use strict";Ee=(i=>(i[i.ColorPalette=1]="ColorPalette",i[i.Sprite=2]="Sprite",i[i.MulticolorSprite=3]="MulticolorSprite",i[i.BitmapFont=4]="BitmapFont",i[i.Sound=5]="Sound",i[i.WebFont=6]="WebFont",i))(Ee||{})});var zt={};D(zt,{LoadDecoder:()=>ht});var mt,ht,Et=E(()=>{"use strict";L();mt=class mt{decode(e,t=0){let r=S.from(e);if(t>=r.length)throw new Error("Buffer too short to decode load type");let n=r.readUInt8(t);switch(n){case 1:return this.decodeColorPalette(r,t);case 2:return this.decodeSprite(r,t);case 3:return this.decodeMulticolorSprite(r,t);case 4:return this.decodeBitmapFont(r,t);case 5:return this.decodeSound(r,t);case 6:return this.decodeWebFont(r,t);default:throw new Error(`Unknown load type: 0x${n.toString(16)}`)}}decodeColorPalette(e,t){let r=t;this.checkSize(e,t,2,"ColorPalette header");let n=e.readUInt8(t++),o=e.readUInt8(t++);this.checkSize(e,t,o*6,`ColorPalette ${o} colors`);let i=[];for(let a=0;a<o;a++)i.push({colorId:e.readUInt8(t++),r:e.readUInt8(t++),g:e.readUInt8(t++),b:e.readUInt8(t++),a:e.readUInt8(t++),e:e.readUInt8(t++)});return{load:{loadType:1,colors:i},bytesRead:t-r}}decodeSprite(e,t){let r=t;this.checkSize(e,t,2,"Sprite header");let n=e.readUInt8(t++),o=e.readUInt8(t++),i=[];for(let a=0;a<o;a++){this.checkSize(e,t,3,`Sprite ${a} header`);let d=e.readUInt8(t++),u=e.readUInt8(t++),c=e.readUInt8(t++),l=u*c;this.checkSize(e,t,l,`Sprite ${a} data`);let p=[];for(let h=0;h<l;h++)p.push(e.readUInt8(t++));i.push({spriteId:d,sizeX:u,sizeY:c,data:p})}return{load:{loadType:2,sprites:i},bytesRead:t-r}}decodeMulticolorSprite(e,t){let r=t;this.checkSize(e,t,2,"MulticolorSprite header");let n=e.readUInt8(t++),o=e.readUInt8(t++),i=[];for(let a=0;a<o;a++){this.checkSize(e,t,3,`MulticolorSprite ${a} header`);let d=e.readUInt8(t++),u=e.readUInt8(t++),c=e.readUInt8(t++),l=u*c,p=l*3;this.checkSize(e,t,p,`MulticolorSprite ${a} data`);let h=[];for(let m=0;m<l;m++)h.push({charCode:e.readUInt8(t++),fgColorId:e.readUInt8(t++),bgColorId:e.readUInt8(t++)});i.push({spriteId:d,sizeX:u,sizeY:c,data:h})}return{load:{loadType:3,sprites:i},bytesRead:t-r}}decodeBitmapFont(e,t){let r=t;this.checkSize(e,t,7,"BitmapFont header");let n=e.readUInt8(t++),o=e.readUInt8(t++),i=e.readUInt8(t++),s=e.readUInt8(t++),a=e.readUInt8(t++),d=e.readUInt8(t++),u=e.readUInt8(t++),c=Math.ceil(i*s/8),l=[];for(let h=0;h<u;h++){this.checkSize(e,t,1+c,`BitmapFont character ${h}`);let m=e.readUInt8(t++),b=new Uint8Array(c);for(let f=0;f<c;f++)b[f]=e.readUInt8(t++);l.push({charCode:m,bitmap:b})}return{load:{loadType:4,fontId:o,width:i,height:s,cellWidth:a,cellHeight:d,characters:l},bytesRead:t-r}}decodeSound(e,t){let r=t;this.checkSize(e,t,2,"Sound header");let n=e.readUInt8(t++),o=e.readUInt8(t++),i=[];for(let a=0;a<o;a++){this.checkSize(e,t,3,`Sound ${a} header`);let d=e.readUInt8(t++),u=e.readUInt16BE(t);t+=2,this.checkSize(e,t,u,`Sound ${a} MIDI data`);let c=new Uint8Array(u);for(let l=0;l<u;l++)c[l]=e.readUInt8(t++);i.push({soundId:d,midiData:c})}return{load:{loadType:5,sounds:i},bytesRead:t-r}}checkSize(e,t,r,n){if(t+r>e.length)throw new Error(`Buffer too short for ${n}: need ${r} bytes at offset ${t}, but only ${e.length-t} bytes remaining`)}decodeWebFont(e,t){let r=t,n=new TextDecoder;this.checkSize(e,t,5,"WebFont header");let o=e.readUInt8(t++),i=e.readUInt8(t++),s=e.readUInt8(t++),a=e.readUInt8(t++);this.checkSize(e,t,a,"WebFont family string");let d=new Uint8Array(a);for(let p=0;p<a;p++)d[p]=e.readUInt8(t++);let u=n.decode(d);this.checkSize(e,t,2,"WebFont fontSize");let c=e.readUInt16BE(t);t+=2;let l={loadType:6,fontId:i,fontFamily:u,fontSize:c};if(s&1&&(this.checkSize(e,t,2,"WebFont offsetX"),l.offsetX=e.readInt16BE(t),t+=2),s&2&&(this.checkSize(e,t,2,"WebFont offsetY"),l.offsetY=e.readInt16BE(t),t+=2),s&4&&(this.checkSize(e,t,2,"WebFont charSpacing"),l.charSpacing=e.readInt16BE(t),t+=2),s&8){this.checkSize(e,t,2,"WebFont lineHeight");let p=e.readUInt16BE(t);l.lineHeight=p/100,t+=2}if(s&16){this.checkSize(e,t,1,"WebFont weight length");let p=e.readUInt8(t++);this.checkSize(e,t,p,"WebFont weight string");let h=new Uint8Array(p);for(let m=0;m<p;m++)h[m]=e.readUInt8(t++);l.fontWeight=n.decode(h)}if(s&32){this.checkSize(e,t,1,"WebFont style length");let p=e.readUInt8(t++);this.checkSize(e,t,p,"WebFont style string");let h=new Uint8Array(p);for(let m=0;m<p;m++)h[m]=e.readUInt8(t++);l.fontStyle=n.decode(h)}return{load:l,bytesRead:t-r}}};C(mt,"LoadDecoder");ht=mt});var oe={};D(oe,{LoadEncoder:()=>xt});var gt,xt,ie=E(()=>{"use strict";L();gt=class gt{encode(e){switch(e.loadType){case 1:return this.encodeColorPalette(e);case 2:return this.encodeSprite(e);case 3:return this.encodeMulticolorSprite(e);case 4:return this.encodeBitmapFont(e);case 5:return this.encodeSound(e);case 6:return this.encodeWebFont(e);default:throw new Error(`Unknown load type: ${e.loadType}`)}}encodeColorPalette(e){let t=e.colors.length;if(t>255)throw new Error(`Palette size ${t} exceeds maximum of 255`);let r=S.allocUnsafe(2+t*6),n=0;r.writeUInt8(1,n++),r.writeUInt8(t,n++);for(let o of e.colors)r.writeUInt8(o.colorId,n++),r.writeUInt8(o.r,n++),r.writeUInt8(o.g,n++),r.writeUInt8(o.b,n++),r.writeUInt8(o.a,n++),r.writeUInt8(o.e??0,n++);return r.toUint8Array()}encodeSprite(e){let t=e.sprites.length;if(t>255)throw new Error(`Sprite count ${t} exceeds maximum of 255`);let r=2;for(let i of e.sprites)r+=3,r+=i.data.length;let n=S.allocUnsafe(r),o=0;n.writeUInt8(2,o++),n.writeUInt8(t,o++);for(let i of e.sprites){if(i.data.length!==i.sizeX*i.sizeY)throw new Error(`Sprite ${i.spriteId}: data length ${i.data.length} does not match size ${i.sizeX}x${i.sizeY}`);n.writeUInt8(i.spriteId,o++),n.writeUInt8(i.sizeX,o++),n.writeUInt8(i.sizeY,o++);for(let s of i.data)n.writeUInt8(s,o++)}return n.toUint8Array()}encodeMulticolorSprite(e){let t=e.sprites.length;if(t>255)throw new Error(`Sprite count ${t} exceeds maximum of 255`);let r=2;for(let i of e.sprites)r+=3,r+=i.data.length*3;let n=S.allocUnsafe(r),o=0;n.writeUInt8(3,o++),n.writeUInt8(t,o++);for(let i of e.sprites){if(i.data.length!==i.sizeX*i.sizeY)throw new Error(`Sprite ${i.spriteId}: data length ${i.data.length} does not match size ${i.sizeX}x${i.sizeY}`);n.writeUInt8(i.spriteId,o++),n.writeUInt8(i.sizeX,o++),n.writeUInt8(i.sizeY,o++);for(let s of i.data)n.writeUInt8(s.charCode,o++),n.writeUInt8(s.fgColorId,o++),n.writeUInt8(s.bgColorId,o++)}return n.toUint8Array()}encodeBitmapFont(e){let t=e.characters.length;if(t>255)throw new Error(`Character count ${t} exceeds maximum of 255`);let r=Math.ceil(e.width*e.height/8),n=7+t*(1+r),o=S.allocUnsafe(n),i=0;o.writeUInt8(4,i++),o.writeUInt8(e.fontId,i++),o.writeUInt8(e.width,i++),o.writeUInt8(e.height,i++),o.writeUInt8(e.cellWidth,i++),o.writeUInt8(e.cellHeight,i++),o.writeUInt8(t,i++);for(let s of e.characters){if(s.bitmap.length!==r)throw new Error(`Character ${s.charCode}: bitmap size ${s.bitmap.length} does not match expected ${r} bytes`);o.writeUInt8(s.charCode,i++);for(let a=0;a<s.bitmap.length;a++)o.writeUInt8(s.bitmap[a],i++)}return o.toUint8Array()}encodeSound(e){let t=e.sounds.length;if(t>255)throw new Error(`Sound count ${t} exceeds maximum of 255`);let r=2;for(let i of e.sounds){if(i.midiData.length>65535)throw new Error(`Sound ${i.soundId}: MIDI data size ${i.midiData.length} exceeds maximum of 65535 bytes`);r+=3,r+=i.midiData.length}let n=S.allocUnsafe(r),o=0;n.writeUInt8(5,o++),n.writeUInt8(t,o++);for(let i of e.sounds){n.writeUInt8(i.soundId,o++),n.writeUInt16BE(i.midiData.length,o),o+=2;for(let s=0;s<i.midiData.length;s++)n.writeUInt8(i.midiData[s],o++)}return n.toUint8Array()}encodeWebFont(e){let t=new TextEncoder,r=t.encode(e.fontFamily),n=e.fontWeight?t.encode(e.fontWeight):new Uint8Array(0),o=e.fontStyle?t.encode(e.fontStyle):new Uint8Array(0),i=0;e.offsetX!==void 0&&(i|=1),e.offsetY!==void 0&&(i|=2),e.charSpacing!==void 0&&(i|=4),e.lineHeight!==void 0&&(i|=8),e.fontWeight!==void 0&&(i|=16),e.fontStyle!==void 0&&(i|=32);let s=4;s+=r.length,s+=2,e.offsetX!==void 0&&(s+=2),e.offsetY!==void 0&&(s+=2),e.charSpacing!==void 0&&(s+=2),e.lineHeight!==void 0&&(s+=2),e.fontWeight!==void 0&&(s+=1+n.length),e.fontStyle!==void 0&&(s+=1+o.length);let a=S.allocUnsafe(s),d=0;a.writeUInt8(6,d++),a.writeUInt8(e.fontId,d++),a.writeUInt8(i,d++),a.writeUInt8(r.length,d++);for(let u=0;u<r.length;u++)a.writeUInt8(r[u],d++);if(a.writeUInt16BE(e.fontSize,d),d+=2,e.offsetX!==void 0&&(a.writeInt16BE(e.offsetX,d),d+=2),e.offsetY!==void 0&&(a.writeInt16BE(e.offsetY,d),d+=2),e.charSpacing!==void 0&&(a.writeInt16BE(e.charSpacing,d),d+=2),e.lineHeight!==void 0&&(a.writeUInt16BE(Math.round(e.lineHeight*100),d),d+=2),e.fontWeight!==void 0){a.writeUInt8(n.length,d++);for(let u=0;u<n.length;u++)a.writeUInt8(n[u],d++)}if(e.fontStyle!==void 0){a.writeUInt8(o.length,d++);for(let u=0;u<o.length;u++)a.writeUInt8(o[u],d++)}return a.toUint8Array()}};C(gt,"LoadEncoder");xt=gt});var vr={};D(vr,{ASCII_8X8_FONT:()=>H,AUDIO_CONFIGURE_SPATIAL_SIZE:()=>St,AUDIO_FADEOUT_SOUND_MIN_SIZE:()=>Lr,AUDIO_PAUSE_SOUND_MIN_SIZE:()=>Pr,AUDIO_PLAY_GLOBAL_SOUND_MIN_SIZE:()=>Or,AUDIO_PLAY_SOUND_MIN_SIZE:()=>Ur,AUDIO_RESUME_SOUND_MIN_SIZE:()=>Tr,AUDIO_SET_LISTENER_POSITION_SIZE:()=>yt,AUDIO_SET_SOUND_EFFECTS_MIN_SIZE:()=>Dr,AUDIO_STOP_SOUND_MIN_SIZE:()=>Rr,AudioOrderCollector:()=>re,AudioOrderDecoder:()=>ne,AudioOrderType:()=>Se,AudioTargetType:()=>Ie,BITMASK16_ORDER_MIN_SIZE:()=>pr,BITMASK4_ORDER_MIN_SIZE:()=>cr,BITMASK_ORDER_MIN_SIZE:()=>lr,BitmapFont:()=>J,BitmapFontRegistry:()=>ee,CHAR_ORDER_SIZE:()=>Vt,CIRCLE_SHAPE_SIZE:()=>or,CLEAR_ORDER_SIZE:()=>Cr,COLORMAP_ORDER_MIN_SIZE:()=>tr,COLOR_SKIP:()=>k,CellBuffer:()=>R,CharCodeBuffer:()=>W,Core:()=>Me,CoreStats:()=>j,DISPLAY_HEADER_SIZE:()=>Mr,DOTCLOUD_MULTICOLOR_ORDER_MIN_SIZE:()=>ur,DOTCLOUD_ORDER_MIN_SIZE:()=>dr,Display:()=>N,ELLIPSE_SHAPE_SIZE:()=>sr,FILLCHAR_ORDER_MIN_SIZE:()=>br,FILLSPRITE_MULTICOLOR_ORDER_SIZE:()=>Sr,FILLSPRITE_ORDER_SIZE:()=>yr,FULLFRAME_MULTICOLOR_ORDER_MIN_SIZE:()=>Jt,FULLFRAME_ORDER_MIN_SIZE:()=>Kt,FontType:()=>Qe,InputBindingRegistry:()=>V,LAYER_CELL_COUNT:()=>zr,LAYER_HEADER_SIZE:()=>Fr,LAYER_SIZE:()=>he,LINE_SHAPE_SIZE:()=>ir,Layer:()=>$,LoadType:()=>Ee,OrderBuilder:()=>Fe,OrderType:()=>Ct,PlaySoundFlags:()=>fe,RECTANGLE_SHAPE_SIZE:()=>nr,SHAPE_ORDER_MIN_SIZE:()=>rr,SPRITECLOUD_MULTICOLOR_ORDER_MIN_SIZE:()=>mr,SPRITECLOUD_ORDER_MIN_SIZE:()=>hr,SPRITECLOUD_VARIED_MULTICOLOR_ORDER_MIN_SIZE:()=>gr,SPRITECLOUD_VARIED_ORDER_MIN_SIZE:()=>xr,SPRITE_MULTICOLOR_ORDER_SIZE:()=>er,SPRITE_ORDER_SIZE:()=>Qt,SUBFRAME_MULTICOLOR_ORDER_MIN_SIZE:()=>jt,SUBFRAME_ORDER_MIN_SIZE:()=>qt,ShapeType:()=>De,SoundRegistry:()=>te,SpriteRegistry:()=>K,TEXT_MULTILINE_ORDER_MIN_SIZE:()=>Gt,TEXT_ORDER_MIN_SIZE:()=>Zt,TRIANGLE_SHAPE_SIZE:()=>ar,TRIGGERGLOBALSOUND_ORDER_SIZE:()=>fr,TRIGGERSOUND_ORDER_SIZE:()=>Ir,UPDATE_PACKET_HEADER_SIZE:()=>Er,UpdateFlags:()=>bt,UpdateFlagsHelper:()=>Re,UpdatePacketDecoder:()=>ce,User:()=>G,UserStats:()=>Z,Vector2:()=>Yt.Vector2,WebFont:()=>P,WebFontRegistry:()=>Q,createASCII8x8FontLoad:()=>Lt,createEmptyCompressedInputPacket:()=>xe,decodeCompressedInput:()=>ye,decodeInt8ToAxis:()=>Ce,encodeAxisToInt8:()=>ge,encodeCompressedInput:()=>Tt,getASCII8x8FontConfig:()=>Pt,getAllCharCodes:()=>Rt,getAudioOrderTypeName:()=>Ne,getButtonByteCount:()=>Y,getCharBitmap:()=>Mt,getCompressedPacketSize:()=>be,getOrderTypeName:()=>Xt,hasChar:()=>Ft,isValidAudioOrderType:()=>He,isValidOrderType:()=>Dt});module.exports=z(vr);var de=require("@utsp/types");var Le=class Le{constructor(e=0,t=60,r=40){x(this,"id");x(this,"origin");x(this,"size");x(this,"previousOrigin",new de.Vector2(0,0));x(this,"previousSize",new de.Vector2(0,0));x(this,"toDraw",[]);if(e<0||e>255)throw new Error(`Display ID must be between 0 and 255, got ${e}`);if(t<1||t>256)throw new Error(`Display sizeX must be between 1 and 256, got ${t}`);if(r<1||r>256)throw new Error(`Display sizeY must be between 1 and 256, got ${r}`);this.id=e,this.origin=new de.Vector2(0,0),this.size=new de.Vector2(t,r),this.toDraw=new Array(this.size.x*this.size.y).fill(null).map(()=>({charCode:0,fgColorCode:0,bgColorCode:0}))}getId(){return this.id}getOrigin(){return this.origin}setOrigin(e){this.origin=e}moveOrigin(e,t){this.origin.x+=e,this.origin.y+=t}hasOriginChanged(){return this.origin.x!==this.previousOrigin.x||this.origin.y!==this.previousOrigin.y}hasSizeChanged(){return this.size.x!==this.previousSize.x||this.size.y!==this.previousSize.y}hasChanged(){return this.hasOriginChanged()||this.hasSizeChanged()}resetChangeTracking(){this.previousOrigin.x=this.origin.x,this.previousOrigin.y=this.origin.y,this.previousSize.x=this.size.x,this.previousSize.y=this.size.y}getSize(){return this.size}setSize(e){if(e.x<1||e.x>256)throw new Error(`Display sizeX must be between 1 and 256, got ${e.x}`);if(e.y<1||e.y>256)throw new Error(`Display sizeY must be between 1 and 256, got ${e.y}`);this.size=e,this.toDraw=new Array(this.size.x*this.size.y).fill(null).map(()=>({charCode:0,fgColorCode:0,bgColorCode:0}))}};C(Le,"Display");var N=Le;var he=256,zr=65536,k=255,Er=9,Mr=5,Fr=13,Vt=6,Zt=6,Gt=6,qt=7,jt=5,Kt=3,Jt=1,Qt=6,er=4,tr=5,rr=2,nr=8,or=7,ir=7,sr=8,ar=10,dr=6,ur=3,lr=9,cr=15,pr=51,hr=6,mr=4,xr=3,gr=3,Cr=4,br=5,yr=4,Sr=2,Ir=5,fr=3,Ur=5,Or=5,Rr=2,Lr=3,Pr=2,Tr=2,yt=5,St=5,Dr=4;var Pe=class Pe{constructor(e=65536){x(this,"data");x(this,"size");this.size=e,this.data=new Uint8Array(e*3),this.clear()}clear(){this.clearWithColor(0,255,255)}clearWithColor(e,t,r){for(let n=0;n<this.size;n++){let o=n*3;this.data[o]=e,this.data[o+1]=t,this.data[o+2]=r}}set(e,t,r,n){let o=e*3;this.data[o]=t,this.data[o+1]=r,this.data[o+2]=n}fillCharsUniform(e,t,r,n){for(let o=0;o<e.length;o++){let i=e[o]*3;this.data[i]=t,this.data[i+1]=r,this.data[i+2]=n}}get(e){let t=e*3;return{charCode:this.data[t],fgColorCode:this.data[t+1],bgColorCode:this.data[t+2]}}setCharOnly(e,t){this.data[e*3]=t}setColorsOnly(e,t,r){this.data[e*3+1]=t,this.data[e*3+2]=r}getCharCode(e){return this.data[e*3]}getFgColorCode(e){return this.data[e*3+1]}getBgColorCode(e){return this.data[e*3+2]}getRawData(){return this.data}getSize(){return this.size}};C(Pe,"CellBuffer");var R=Pe,Te=class Te{constructor(e){x(this,"data");x(this,"size");this.size=e,this.data=new Uint8Array(e)}clear(){this.data.fill(0)}set(e,t){this.data[e]=t}get(e){return this.data[e]}getRawData(){return this.data}getSize(){return this.size}};C(Te,"CharCodeBuffer");var W=Te;var ft=require("@utsp/types");var wr=new Map([[9474,179],[9472,196],[9484,218],[9488,191],[9492,192],[9496,217],[9500,195],[9508,180],[9516,194],[9524,193],[9532,197],[9553,186],[9552,205],[9556,201],[9559,187],[9562,200],[9565,188],[9568,204],[9571,185],[9574,203],[9577,202],[9580,206],[9608,219],[9619,178],[9618,177],[9617,176],[9600,223],[9604,220],[9612,221],[9616,222]]);function ue(g){if(g<128)return g;let e=wr.get(g);return e!==void 0?e:g&255}C(ue,"unicodeToCp437");var Xe=class Xe{constructor(){x(this,"currentWidth",256);x(this,"currentHeight",256)}rasterizeOrders(e,t,r,n,o="add",i){this.currentWidth=r,this.currentHeight=n,o==="set"&&this.clearBuffer(t);for(let s of e)this.rasterizeOrder(s,t,i)}clearBuffer(e){e.clear()}rasterizeOrder(e,t,r){switch(e.type){case 1:this.rasterizeChar(e,t);break;case 2:this.rasterizeText(e,t);break;case 23:this.rasterizeTextMultiline(e,t);break;case 3:this.rasterizeSubFrame(e,t);break;case 4:this.rasterizeSubFrameMultiColor(e,t);break;case 5:this.rasterizeFullFrame(e,t);break;case 6:this.rasterizeFullFrameMultiColor(e,t);break;case 7:this.rasterizeSprite(e,t,r);break;case 8:this.rasterizeSpriteMultiColor(e,t,r);break;case 9:this.rasterizeColorMap(e,t);break;case 10:this.rasterizeShape(e,t);break;case 11:this.rasterizeDotCloud(e,t);break;case 12:this.rasterizeDotCloudMultiColor(e,t);break;case 17:this.rasterizeBitmask(e,t);break;case 18:this.rasterizeBitmask4(e,t);break;case 24:this.rasterizeBitmask16(e,t);break;case 13:this.rasterizeSpriteCloud(e,t,r);break;case 14:this.rasterizeSpriteCloudMultiColor(e,t,r);break;case 15:this.rasterizeSpriteCloudVaried(e,t,r);break;case 16:this.rasterizeSpriteCloudVariedMultiColor(e,t,r);break;case 19:this.rasterizeClear(e,t);break;case 20:this.rasterizeFillChar(e,t);break;case 21:this.rasterizeFillSprite(e,t,r);break;case 22:this.rasterizeFillSpriteMultiColor(e,t,r);break;default:break}}rasterizeChar(e,t){let{posX:r,posY:n,charCode:o,bgColorCode:i,fgColorCode:s}=e;if(!this.isInBounds(r,n))return;let a=n*this.currentWidth+r;t.set(a,o,s,i)}rasterizeText(e,t){let{posX:r,posY:n,text:o,bgColorCode:i,fgColorCode:s}=e;if(this.isInBounds(r,n))for(let a=0;a<o.length;a++){let d=r+a;if(d>=this.currentWidth)break;let u=n*this.currentWidth+d,c=o.charCodeAt(a),l=ue(c);t.set(u,l,s,i)}}rasterizeTextMultiline(e,t){let{posX:r,posY:n,text:o,bgColorCode:i,fgColorCode:s}=e,a=o.split(`
2
+ `),d=n;for(let u of a){if(d>=this.currentHeight)break;if(d>=0&&this.isInBounds(r,d))for(let c=0;c<u.length;c++){let l=r+c;if(l>=this.currentWidth)break;let p=d*this.currentWidth+l,h=u.charCodeAt(c),m=ue(h);t.set(p,m,s,i)}d++}}rasterizeSubFrame(e,t){let{posX:r,posY:n,sizeX:o,sizeY:i,frame:s,bgColorCode:a,fgColorCode:d}=e;for(let u=0;u<i;u++){let c=n+u;if(!(c<0||c>=this.currentHeight))for(let l=0;l<o;l++){let p=r+l;if(p<0||p>=this.currentWidth)continue;let h=u*o+l;if(h>=s.length)break;let m=c*this.currentWidth+p;t.set(m,s[h],d,a)}}}rasterizeSubFrameMultiColor(e,t){let{posX:r,posY:n,sizeX:o,sizeY:i,frame:s}=e;for(let a=0;a<i;a++){let d=n+a;if(!(d<0||d>=this.currentHeight))for(let u=0;u<o;u++){let c=r+u;if(c<0||c>=this.currentWidth)continue;let l=a*o+u;if(l>=s.length)break;let p=s[l],h=d*this.currentWidth+c;t.set(h,p.charCode,p.fgColorCode,p.bgColorCode)}}}rasterizeFullFrame(e,t){let{frame:r,bgColorCode:n,fgColorCode:o}=e,i=this.currentWidth*this.currentHeight;for(let s=0;s<i&&s<r.length;s++)t.set(s,r[s],o,n)}rasterizeFullFrameMultiColor(e,t){let{frame:r}=e,n=this.currentWidth*this.currentHeight;for(let o=0;o<n&&o<r.length;o++){let i=r[o];t.set(o,i.charCode,i.fgColorCode,i.bgColorCode)}}rasterizeColorMap(e,t){let{posX:r,posY:n,sizeX:o,sizeY:i,colorData:s}=e;for(let a=0;a<i;a++){let d=n+a;if(!(d<0||d>=this.currentHeight))for(let u=0;u<o;u++){let c=r+u;if(c<0||c>=this.currentWidth)continue;let l=a*o+u;if(l>=s.length)break;let p=d*this.currentWidth+c,h=s[l];t.setColorsOnly(p,h.fgColorCode,h.bgColorCode)}}}rasterizeShape(e,t){let{shapeType:r,shapeData:n}=e;switch(r){case 1:this.rasterizeRectangle(n,t);break;case 2:this.rasterizeCircle(n,t);break;case 3:this.rasterizeLine(n,t);break;case 4:this.rasterizeEllipse(n,t);break;case 5:this.rasterizeTriangle(n,t);break}}rasterizeRectangle(e,t){let{posX:r,posY:n,width:o,height:i,filled:s,charCode:a,bgColorCode:d,fgColorCode:u}=e;if(s)for(let c=0;c<i;c++){let l=n+c;if(!(l<0||l>=this.currentHeight))for(let p=0;p<o;p++){let h=r+p;if(h<0||h>=this.currentWidth)continue;let m=l*this.currentWidth+h;t.set(m,a,u,d)}}else{for(let c=0;c<o;c++)this.setCell(r+c,n,a,d,u,t),this.setCell(r+c,n+i-1,a,d,u,t);for(let c=0;c<i;c++)this.setCell(r,n+c,a,d,u,t),this.setCell(r+o-1,n+c,a,d,u,t)}}rasterizeCircle(e,t){let{centerX:r,centerY:n,radius:o,filled:i,charCode:s,bgColorCode:a,fgColorCode:d}=e;if(i)for(let u=-o;u<=o;u++){let c=n+u;if(!(c<0||c>=this.currentHeight))for(let l=-o;l<=o;l++){let p=r+l;if(!(p<0||p>=this.currentWidth)&&l*l+u*u<=o*o){let h=c*this.currentWidth+p;t.set(h,s,d,a)}}}else{let u=o,c=0,l=0;for(;u>=c;)this.setCell(r+u,n+c,s,a,d,t),this.setCell(r+c,n+u,s,a,d,t),this.setCell(r-c,n+u,s,a,d,t),this.setCell(r-u,n+c,s,a,d,t),this.setCell(r-u,n-c,s,a,d,t),this.setCell(r-c,n-u,s,a,d,t),this.setCell(r+c,n-u,s,a,d,t),this.setCell(r+u,n-c,s,a,d,t),l<=0&&(c+=1,l+=2*c+1),l>0&&(u-=1,l-=2*u+1)}}rasterizeLine(e,t){let{x1:r,y1:n,x2:o,y2:i,charCode:s,bgColorCode:a,fgColorCode:d}=e,u=Math.abs(o-r),c=Math.abs(i-n),l=r<o?1:-1,p=n<i?1:-1,h=u-c,m=r,b=n;for(;this.setCell(m,b,s,a,d,t),!(m===o&&b===i);){let f=2*h;f>-c&&(h-=c,m+=l),f<u&&(h+=u,b+=p)}}rasterizeEllipse(e,t){let{centerX:r,centerY:n,radiusX:o,radiusY:i,filled:s,charCode:a,bgColorCode:d,fgColorCode:u}=e;if(s)for(let c=-i;c<=i;c++){let l=n+c;if(!(l<0||l>=this.currentHeight))for(let p=-o;p<=o;p++){let h=r+p;if(h<0||h>=this.currentWidth)continue;if(p*p/(o*o)+c*c/(i*i)<=1){let b=l*this.currentWidth+h;t.set(b,a,u,d)}}}else{let c=Math.max(o,i)*8;for(let l=0;l<c;l++){let p=2*Math.PI*l/c,h=Math.round(r+o*Math.cos(p)),m=Math.round(n+i*Math.sin(p));this.setCell(h,m,a,d,u,t)}}}rasterizeTriangle(e,t){let{x1:r,y1:n,x2:o,y2:i,x3:s,y3:a,filled:d,charCode:u,bgColorCode:c,fgColorCode:l}=e;if(d){let p=[{x:r,y:n},{x:o,y:i},{x:s,y:a}].sort((y,O)=>y.y-O.y),[h,m,b]=p,f=C((y,O,B)=>{let v=Math.round(Math.min(O,B)),w=Math.round(Math.max(O,B));for(let M=v;M<=w;M++)if(M>=0&&M<this.currentWidth&&y>=0&&y<this.currentHeight){let pe=y*this.currentWidth+M;t.set(pe,u,l,c)}},"drawLine"),U=C((y,O,B,v,w)=>v===O?B:B+(y-O)*(w-B)/(v-O),"interpolate");for(let y=h.y;y<=m.y;y++){let O=U(y,h.y,h.x,b.y,b.x),B=U(y,h.y,h.x,m.y,m.x);f(y,O,B)}for(let y=m.y+1;y<=b.y;y++){let O=U(y,h.y,h.x,b.y,b.x),B=U(y,m.y,m.x,b.y,b.x);f(y,O,B)}}else this.drawLineSegment(r,n,o,i,u,c,l,t),this.drawLineSegment(o,i,s,a,u,c,l,t),this.drawLineSegment(s,a,r,n,u,c,l,t)}drawLineSegment(e,t,r,n,o,i,s,a){let d=Math.abs(r-e),u=Math.abs(n-t),c=e<r?1:-1,l=t<n?1:-1,p=d-u,h=e,m=t;for(;this.setCell(h,m,o,i,s,a),!(h===r&&m===n);){let b=2*p;b>-u&&(p-=u,h+=c),b<d&&(p+=d,m+=l)}}rasterizeDotCloud(e,t){let{charCode:r,bgColorCode:n,fgColorCode:o,positions:i}=e,s=t.getRawData(),a=this.currentWidth;for(let d=0;d<i.length;d++){if(i[d].posX<0||i[d].posX>=a||i[d].posY<0||i[d].posY>=this.currentHeight)continue;let u=(i[d].posY*a+i[d].posX)*3;s[u]=r,s[u+1]=o,s[u+2]=n}}rasterizeDotCloudMultiColor(e,t){let{dots:r}=e;for(let n of r)this.setCell(n.posX,n.posY,n.charCode,n.bgColorCode,n.fgColorCode,t)}rasterizeBitmask(e,t){let{posX:r,posY:n,sizeX:o,sizeY:i,charCode:s,bgColorCode:a,fgColorCode:d,override:u,mask:c}=e;for(let l=0;l<i;l++){let p=n+l;if(!(p<0||p>=this.currentHeight))for(let h=0;h<o;h++){let m=r+h;if(m<0||m>=this.currentWidth)continue;let b=l*o+h,f=Math.floor(b/8),U=b%8,y=(c[f]&1<<U)!==0,O=p*this.currentWidth+m;y?t.set(O,s,d,a):u&&t.set(O,255,255,255)}}}rasterizeBitmask4(e,t){let{posX:r,posY:n,sizeX:o,sizeY:i,override:s,variants:a,mask:d}=e;for(let u=0;u<i;u++){let c=n+u;if(!(c<0||c>=this.currentHeight))for(let l=0;l<o;l++){let p=r+l;if(p<0||p>=this.currentWidth)continue;let h=u*o+l,m=Math.floor(h/4),b=h%4*2,f=d[m]>>b&3,U=c*this.currentWidth+p;if(f>0){let y=a[f-1];t.set(U,y.charCode,y.fgColorCode,y.bgColorCode)}else s&&t.set(U,255,255,255)}}}rasterizeBitmask16(e,t){let{posX:r,posY:n,sizeX:o,sizeY:i,override:s,variants:a,mask:d}=e;for(let u=0;u<i;u++){let c=n+u;if(!(c<0||c>=this.currentHeight))for(let l=0;l<o;l++){let p=r+l;if(p<0||p>=this.currentWidth)continue;let h=u*o+l,m=Math.floor(h/2),b=h%2*4,f=d[m]>>b&15,U=c*this.currentWidth+p;if(f>0){let y=a[f-1];t.set(U,y.charCode,y.fgColorCode,y.bgColorCode)}else s&&t.set(U,255,255,255)}}}rasterizeClear(e,t){let{charCode:r,bgColorCode:n,fgColorCode:o}=e;t.clearWithColor(r,o,n)}rasterizeFillChar(e,t){let{patternWidth:r,patternHeight:n,pattern:o,bgColorCode:i,fgColorCode:s}=e;for(let a=0;a<this.currentHeight;a++)for(let d=0;d<this.currentWidth;d++){let u=d%r,l=a%n*r+u;if(l<o.length){let p=a*this.currentWidth+d;t.set(p,o[l],s,i)}}}rasterizeSprite(e,t,r){if(!r)return;let{posX:n,posY:o,spriteIndex:i,bgColorCode:s,fgColorCode:a}=e,d=r.getUnicolorSprite(i);if(!d)return;let u=d.data;for(let c=0;c<d.sizeY;c++)for(let l=0;l<d.sizeX;l++){let p=n+l,h=o+c;if(!this.isInBounds(p,h))continue;let m=c*d.sizeX+l,b=u.get(m);this.setCell(p,h,b,s,a,t)}}rasterizeSpriteMultiColor(e,t,r){if(!r)return;let{posX:n,posY:o,spriteIndex:i}=e,s=r.getMulticolorSprite(i);if(!s)return;let a=s.data;for(let d=0;d<s.sizeY;d++)for(let u=0;u<s.sizeX;u++){let c=n+u,l=o+d;if(!this.isInBounds(c,l))continue;let p=d*s.sizeX+u,h=a.getCharCode(p),m=a.getFgColorCode(p),b=a.getBgColorCode(p);this.setCell(c,l,h,b,m,t)}}rasterizeSpriteCloud(e,t,r){if(!r)return;let{spriteIndex:n,bgColorCode:o,fgColorCode:i,positions:s}=e,a=r.getUnicolorSprite(n);if(a){if(a.sizeX===1&&a.sizeY===1){let d=a.data.get(0),u=t.getRawData(),c=this.currentWidth;for(let l=0;l<s.length;l++){if(s[l].posX<0||s[l].posX>=c||s[l].posY<0||s[l].posY>=this.currentHeight)continue;let p=(s[l].posY*c+s[l].posX)*3;u[p]=d,u[p+1]=i,u[p+2]=o}return}for(let d=0;d<s.length;d++){let u=a.data;for(let c=0;c<a.sizeY;c++)for(let l=0;l<a.sizeX;l++){let p=s[d].posX+l,h=s[d].posY+c;if(!this.isInBounds(p,h))continue;let m=c*a.sizeX+l,b=u.get(m);this.setCell(p,h,b,o,i,t)}}}}rasterizeSpriteCloudMultiColor(e,t,r){if(!r)return;let{spriteIndex:n,positions:o}=e,i=r.getMulticolorSprite(n);if(i)for(let s=0;s<o.length;s++){let a=i.data;for(let d=0;d<i.sizeY;d++)for(let u=0;u<i.sizeX;u++){let c=o[s].posX+u,l=o[s].posY+d;if(!this.isInBounds(c,l))continue;let p=d*i.sizeX+u,h=a.getCharCode(p),m=a.getFgColorCode(p),b=a.getBgColorCode(p);this.setCell(c,l,h,b,m,t)}}}rasterizeSpriteCloudVaried(e,t,r){if(!r)return;let{sprites:n}=e;for(let o=0;o<n.length;o++){let i=n[o],s=r.getUnicolorSprite(i.spriteIndex);if(!s)continue;let a=s.data;for(let d=0;d<s.sizeY;d++)for(let u=0;u<s.sizeX;u++){let c=i.posX+u,l=i.posY+d;if(!this.isInBounds(c,l))continue;let p=d*s.sizeX+u,h=a.get(p);this.setCell(c,l,h,i.bgColorCode,i.fgColorCode,t)}}}rasterizeSpriteCloudVariedMultiColor(e,t,r){if(!r)return;let{sprites:n}=e;for(let o=0;o<n.length;o++){let i=n[o],s=r.getMulticolorSprite(i.spriteIndex);if(!s)continue;let a=s.data;for(let d=0;d<s.sizeY;d++)for(let u=0;u<s.sizeX;u++){let c=i.posX+u,l=i.posY+d;if(!this.isInBounds(c,l))continue;let p=d*s.sizeX+u,h=a.getCharCode(p),m=a.getFgColorCode(p),b=a.getBgColorCode(p);this.setCell(c,l,h,b,m,t)}}}rasterizeFillSprite(e,t,r){if(!r)return;let{spriteIndex:n,bgColorCode:o,fgColorCode:i}=e,s=r.getUnicolorSprite(n);if(!s)return;let a=s.data;for(let d=0;d<this.currentHeight;d++)for(let u=0;u<this.currentWidth;u++){let c=u%s.sizeX,p=d%s.sizeY*s.sizeX+c,h=a.get(p),m=d*this.currentWidth+u;t.set(m,h,i,o)}}rasterizeFillSpriteMultiColor(e,t,r){if(!r)return;let{spriteIndex:n}=e,o=r.getMulticolorSprite(n);if(!o)return;let i=o.data;for(let s=0;s<this.currentHeight;s++)for(let a=0;a<this.currentWidth;a++){let d=a%o.sizeX,c=s%o.sizeY*o.sizeX+d,l=i.getCharCode(c),p=i.getFgColorCode(c),h=i.getBgColorCode(c),m=s*this.currentWidth+a;t.set(m,l,p,h)}}setCell(e,t,r,n,o,i){if(!this.isInBounds(e,t))return;let s=t*this.currentWidth+e;i.set(s,r,o,n)}isInBounds(e,t){return e>=0&&e<this.currentWidth&&t>=0&&t<this.currentHeight}};C(Xe,"LayerRasterizer");var me=Xe;var X=class X{constructor(e,t,r,n,o=!1){x(this,"id",0);x(this,"origin");x(this,"orders",[]);x(this,"zOrder",0);x(this,"data");x(this,"width");x(this,"height");x(this,"isStatic",!1);x(this,"spriteRegistry");x(this,"mode","server");x(this,"previousOrigin");x(this,"previousZOrder");x(this,"enabled",!0);x(this,"useSetMode",!1);x(this,"needsCommit",!1);if(r<1||r>256||n<1||n>256)throw new Error(`Layer size must be 1-256, got ${r}\xD7${n}`);this.origin=e,this.zOrder=t,this.width=r,this.height=n,this.isStatic=o,this.data=new R(r*n),this.previousOrigin=new ft.Vector2(e.x,e.y),this.previousZOrder=t}setMode(e){this.mode=e}setSpriteRegistry(e){this.spriteRegistry=e}getOrders(){return this.orders}addOrders(e){this.orders.push(...e),this.useSetMode=!1,(this.mode==="client"||this.mode==="standalone")&&X.rasterizer.rasterizeOrders(e,this.data,this.width,this.height,"add",this.spriteRegistry)}setOrders(e){this.orders=e,this.useSetMode=!0,(this.mode==="client"||this.mode==="standalone")&&X.rasterizer.rasterizeOrders(e,this.data,this.width,this.height,"set",this.spriteRegistry)}clearOrders(){this.orders=[],(this.mode==="client"||this.mode==="standalone")&&X.rasterizer.clearBuffer(this.data)}getOrigin(){return this.origin}setOrigin(e){this.origin=e}getZOrder(){return this.zOrder}setZOrder(e){this.zOrder=e}getId(){return this.id}setId(e){this.id=e}getData(){return this.data}getWidth(){return this.width}getHeight(){return this.height}getCellAt(e,t){return e<0||e>=this.width||t<0||t>=this.height?null:this.data.get(t*this.width+e)}setStatic(e){this.isStatic=e}getStatic(){return this.isStatic}setEnabled(e){this.enabled=e}isEnabled(){return this.enabled}hasOriginChanged(){return this.origin.x!==this.previousOrigin.x||this.origin.y!==this.previousOrigin.y}hasZOrderChanged(){return this.zOrder!==this.previousZOrder}calculateUpdateFlags(){if(!this.enabled)return 0;let e=1;return this.useSetMode&&(e|=2),this.hasOriginChanged()&&(e|=4),this.hasZOrderChanged()&&(e|=8),(this.orders.length>0||this.needsCommit&&this.useSetMode)&&(e|=4),e}resetChangeTracking(){this.previousOrigin.x=this.origin.x,this.previousOrigin.y=this.origin.y,this.previousZOrder=this.zOrder}commit(){this.needsCommit=!0}getNeedsCommit(){return this.needsCommit}resetCommit(){this.needsCommit=!1}};C(X,"Layer"),x(X,"rasterizer",new me);var $=X;var Ye=class Ye{constructor(){x(this,"axes",new Map);x(this,"buttons",new Map);x(this,"axisNameToId",new Map);x(this,"buttonNameToId",new Map);x(this,"version",1)}defineAxis(e,t,r=[],n=-1,o=1,i=0){if(e<0||e>255)throw new Error(`Axis bindingId must be between 0 and 255, got ${e}`);if(this.axes.has(e))throw new Error(`Axis bindingId ${e} is already defined`);if(this.axisNameToId.has(t)){let a=this.axisNameToId.get(t);throw new Error(`Axis name "${t}" is already defined with bindingId ${a}`)}let s={bindingId:e,name:t,min:n,max:o,defaultValue:i,sources:r};this.axes.set(e,s),this.axisNameToId.set(t,e),this.version++}defineButton(e,t,r=[],n=!1){if(e<0||e>255)throw new Error(`Button bindingId must be between 0 and 255, got ${e}`);if(this.buttons.has(e))throw new Error(`Button bindingId ${e} is already defined`);if(this.buttonNameToId.has(t)){let i=this.buttonNameToId.get(t);throw new Error(`Button name "${t}" is already defined with bindingId ${i}`)}let o={bindingId:e,name:t,defaultValue:n,sources:r};this.buttons.set(e,o),this.buttonNameToId.set(t,e),this.version++}evaluateAxis(e,t){let r=this.axes.get(e);if(!r)return 0;let n=0;for(let i of r.sources){let a=t.get(i.sourceId)??0,d=i.deadzone??0;Math.abs(a)<d?a=0:a=(a>0?1:-1)*((Math.abs(a)-d)/(1-d));let u=i.scale??1;a*=u;let c=i.sensitivity??1;a*=c,i.invert&&(a=-a),n+=a}return Math.max(r.min,Math.min(r.max,n))}evaluateButton(e,t){let r=this.buttons.get(e);if(!r)return!1;for(let n of r.sources)if(t.get(n.sourceId)??!1)return!0;return!1}toLoadPacket(){let e={type:"input-binding",version:this.version,axes:Array.from(this.axes.values()),buttons:Array.from(this.buttons.values())};return JSON.stringify(e)}toLoadPacketObject(){return{type:"input-binding",version:this.version,axes:Array.from(this.axes.values()),buttons:Array.from(this.buttons.values())}}getAxisBindingId(e){return this.axisNameToId.get(e)??null}getButtonBindingId(e){return this.buttonNameToId.get(e)??null}getAxisName(e){return this.axes.get(e)?.name??null}getButtonName(e){return this.buttons.get(e)?.name??null}getAxisBinding(e){return this.axes.get(e)??null}getButtonBinding(e){return this.buttons.get(e)??null}hasAxis(e){return this.axes.has(e)}hasButton(e){return this.buttons.has(e)}getAxisCount(){return this.axes.size}getButtonCount(){return this.buttons.size}getAllAxes(){return Array.from(this.axes.values())}getAllButtons(){return Array.from(this.buttons.values())}getVersion(){return this.version}removeAxis(e){let t=this.axes.get(e);return t?(this.axes.delete(e),this.axisNameToId.delete(t.name),this.version++,!0):!1}removeButton(e){let t=this.buttons.get(e);return t?(this.buttons.delete(e),this.buttonNameToId.delete(t.name),this.version++,!0):!1}clearAxes(){this.axes.clear(),this.axisNameToId.clear(),this.version++}clearButtons(){this.buttons.clear(),this.buttonNameToId.clear(),this.version++}clear(){this.axes.clear(),this.axisNameToId.clear(),this.buttons.clear(),this.buttonNameToId.clear(),this.version=1}toString(){let e=`InputBindingRegistry (version ${this.version})
3
3
  `;return e+=`Axes (${this.axes.size}):
4
4
  `,this.axes.forEach(t=>{e+=` [${t.bindingId}] ${t.name}: `,e+=`${t.min} to ${t.max} (default: ${t.defaultValue})
5
5
  `}),e+=`Buttons (${this.buttons.size}):
6
6
  `,this.buttons.forEach(t=>{e+=` [${t.bindingId}] ${t.name}: `,e+=`(default: ${t.defaultValue})
7
- `}),e}};g(Re,"InputBindingRegistry");var H=Re;function he(x=0n){return{tick:x,axes:new Map,buttons:new Map,displayId:0,mouseX:0,mouseY:0,mouseOverDisplay:!1,textInputs:[]}}g(he,"createEmptyCompressedInputPacket");function me(x){let e=Math.max(-1,Math.min(1,x));return Math.round(e*127)}g(me,"encodeAxisToInt8");function xe(x){return x/127}g(xe,"decodeInt8ToAxis");function P(x){return x===0?0:Math.ceil(x/8)}g(P,"getButtonByteCount");function Ce(x,e){let r=x,n=P(e);return 8+r+n+4}g(Ce,"getCompressedPacketSize");function ge(x,e){let t=e.getAllAxes().length,r=e.getAllButtons().length,n=P(r),o=8+t+n+4;if(x.length<o)throw new Error(`Invalid compressed input packet: expected at least ${o} bytes (${t} axes + ${r} buttons), got ${x.length}`);let s=new DataView(x.buffer,x.byteOffset,x.byteLength),i=0,a=he();a.tick=s.getBigUint64(i,!0),i+=8;for(let l=0;l<t;l++){let c=x[i],u=c>127?c-256:c,p=xe(u);a.axes.set(l,p),i+=1}for(let l=0;l<n;l++){let c=x[i];for(let u=0;u<8;u++){let p=l*8+u;if(p<r){let h=(c&1<<u)!==0;a.buttons.set(p,h)}}i+=1}a.displayId=x[i],i+=1,a.mouseX=x[i],i+=1,a.mouseY=x[i],i+=1;let d=x[i];if(a.mouseOverDisplay=(d&1)!==0,i+=1,i<x.length){let l=x[i];i+=1;let c=new TextDecoder;a.textInputs=[];for(let u=0;u<l&&i<x.length;u++){let p=x[i];if(i+=1,i+p<=x.length){let h=x.slice(i,i+p),C=c.decode(h);a.textInputs.push(C),i+=p}}}return a}g(ge,"decodeCompressedInput");var de=require("@utsp/types");var Le=class Le{constructor(e,t){m(this,"enabled",!1);m(this,"currentStats",null);m(this,"_userId");m(this,"_userName");this._userId=e,this._userName=t}setEnabled(e){this.enabled=e,e||(this.currentStats=null)}isEnabled(){return this.enabled}get userId(){return this.currentStats?.userId??this._userId}get userName(){return this.currentStats?.userName??this._userName}get tick(){return this.currentStats?.tick??0}get timestamp(){return this.currentStats?.timestamp??0}get displayCount(){return this.currentStats?.displayCount??0}get totalDisplayArea(){return this.currentStats?.totalDisplayArea??0}get totalLayers(){return this.currentStats?.totalLayers??0}get visibleLayers(){return this.currentStats?.visibleLayers??0}get staticLayers(){return this.currentStats?.staticLayers??0}get dynamicLayers(){return this.currentStats?.dynamicLayers??0}get totalOrders(){return this.currentStats?.totalOrders??0}get ordersByLayer(){return this.currentStats?.ordersByLayer??new Map}get staticPacketSize(){return this.currentStats?.staticPacketSize??0}get dynamicPacketSize(){return this.currentStats?.dynamicPacketSize??0}get totalPacketSize(){return this.currentStats?.totalPacketSize??0}get compressedPacketSize(){return Math.round(this.totalPacketSize*.25)}get hasInput(){return this.currentStats?.hasInput??!1}get axisCount(){return this.currentStats?.axisCount??0}get buttonCount(){return this.currentStats?.buttonCount??0}startTick(e){this.enabled&&(this.currentStats={userId:this._userId,userName:this._userName,tick:e,timestamp:Date.now(),displayCount:0,totalDisplayArea:0,totalLayers:0,visibleLayers:0,staticLayers:0,dynamicLayers:0,totalOrders:0,ordersByLayer:new Map,staticPacketSize:0,dynamicPacketSize:0,totalPacketSize:0,hasInput:!1,axisCount:0,buttonCount:0})}recordDisplays(e,t){!this.enabled||!this.currentStats||(this.currentStats.displayCount=e,this.currentStats.totalDisplayArea=t)}recordLayers(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.totalLayers=e,this.currentStats.visibleLayers=t,this.currentStats.staticLayers=r,this.currentStats.dynamicLayers=n)}recordLayerOrders(e,t){!this.enabled||!this.currentStats||(this.currentStats.totalOrders+=t,this.currentStats.ordersByLayer.set(e,t))}recordPacketSizes(e,t){!this.enabled||!this.currentStats||(this.currentStats.staticPacketSize=e,this.currentStats.dynamicPacketSize=t,this.currentStats.totalPacketSize=e+t)}recordInput(e,t,r){!this.enabled||!this.currentStats||(this.currentStats.hasInput=e,this.currentStats.axisCount=t,this.currentStats.buttonCount=r)}endTick(){}reset(){this.currentStats=null}};g(Le,"UserStats");var V=Le;var De=class De{constructor(e,t,r){this.id=e;this.name=t;m(this,"displays",[]);m(this,"layers",[]);m(this,"spriteRegistry");m(this,"mode");m(this,"axes",new Map);m(this,"buttons",new Map);m(this,"textInputs",[]);m(this,"mouseX",0);m(this,"mouseY",0);m(this,"mouseOver",!1);m(this,"mouseDisplayId",0);m(this,"touchPositions",new Map);m(this,"activeTouchId",null);m(this,"inputBindings",new H);m(this,"stats");m(this,"soundCommands",[]);m(this,"nextSoundInstanceId",1);m(this,"audioConfigCommands",[]);m(this,"lastListenerX",-1);m(this,"lastListenerY",-1);m(this,"pendingSendSounds",!1);m(this,"audioProcessor");m(this,"data");this.mode=r,this.stats=new V(e,t),this.data={}}setSpriteRegistry(e){this.spriteRegistry=e;for(let t of this.layers)t.setSpriteRegistry(e)}getDisplays(){return this.displays}addDisplay(e){this.displays.push(e)}removeDisplay(e){let t=this.displays.indexOf(e);return t!==-1?(this.displays.splice(t,1),!0):!1}clearDisplays(){this.displays=[]}getLayers(){return this.layers}addLayer(e){e.setMode(this.mode),this.layers.push(e),this.spriteRegistry&&e.setSpriteRegistry(this.spriteRegistry)}removeLayer(e){let t=this.layers.indexOf(e);return t!==-1?(this.layers.splice(t,1),!0):!1}clearLayers(){this.layers=[]}setMousePosition(e,t,r=!0){this.mouseX=Math.max(0,Math.min(255,e)),this.mouseY=Math.max(0,Math.min(255,t)),this.mouseOver=r}setTouchPosition(e,t,r,n=!0,o=0){if(e<0||e>9){console.warn(`Invalid touchId ${e}, must be 0-9`);return}n?(this.touchPositions.set(e,{x:Math.max(0,Math.min(255,t)),y:Math.max(0,Math.min(255,r)),over:!0,displayId:o}),this.activeTouchId=e):(this.touchPositions.delete(e),this.activeTouchId===e&&(this.activeTouchId=null))}setAxis(e,t){let r=Math.max(-1,Math.min(1,t));this.axes.set(e,r)}getAxis(e){return this.axes.get(e)??0}setButton(e,t){this.buttons.set(e,t)}getButton(e){return this.buttons.get(e)??!1}getButtonJustPressed(e){let t=`${e}_justPressed`;return this.buttons.get(t)??!1}getButtonJustReleased(e){let t=`${e}_justReleased`;return this.buttons.get(t)??!1}setTextInputs(e){this.textInputs=e}getTextInputs(){return this.textInputs}clearTextInputs(){this.textInputs=[]}getAxisNames(){return Array.from(this.axes.keys())}getButtonNames(){return Array.from(this.buttons.keys())}clearAxes(){this.axes.clear()}clearButtons(){this.buttons.clear()}getMouseDisplayInfo(){if(!this.mouseOver||this.displays.length===0)return null;let e=this.displays[0],t=0,r=this.mouseX,n=this.mouseY,o=e.getOrigin(),s=o.x+r,i=o.y+n;return{displayId:t,localX:r,localY:n,worldX:s,worldY:i}}getTouchDisplayInfo(e=0){if(e<0||e>9)return console.warn(`Invalid touchId ${e}, must be 0-9`),null;let t=this.touchPositions.get(e);if(!t||!t.over||this.displays.length===0)return null;let r=this.displays[0],n=t.displayId,o=t.x,s=t.y,i=r.getOrigin(),a=i.x+o,d=i.y+s;return{displayId:n,localX:o,localY:s,worldX:a,worldY:d}}getIsMouseOnADisplay(){return this.mouseOver}getMouseDisplayHover(){let e=this.getMouseDisplayInfo();return e?e.displayId:null}findLayerById(e){return this.layers.find(t=>t.getId()===e)??null}applyUpdate(e){this.updateDisplaysFromPacket(e.displays),this.updateLayersFromPacket(e.layers)}updateDisplaysFromPacket(e){for(let t of e){let r=this.displays[t.id];if(!r){for(r=new _(t.id,t.sizeX,t.sizeY);this.displays.length<=t.id;)this.displays.push(null);this.displays[t.id]=r}r.setOrigin(new de.Vector2(t.originX,t.originY)),r.setSize(new de.Vector2(t.sizeX,t.sizeY))}}updateLayersFromPacket(e){for(let t of e){let r=this.findLayerById(t.id);r||(r=new $(new de.Vector2(t.originX,t.originY),t.zIndex,t.width,t.height,!1),r.setId(t.id),r.setMode(this.mode),this.spriteRegistry&&r.setSpriteRegistry(this.spriteRegistry),this.addLayer(r)),t.updateFlags&1&&r.setOrigin(new de.Vector2(t.originX,t.originY)),t.updateFlags&2&&r.setZOrder(t.zIndex),t.updateFlags&4&&r.setOrders(t.orders)}}defineAxisBinding(e,t,r=[],n=-1,o=1,s=0){this.inputBindings.defineAxis(e,t,r,n,o,s)}defineButtonBinding(e,t,r=[],n=!1){this.inputBindings.defineButton(e,t,r,n)}defineAxisBindings(e){e.forEach(({bindingId:t,name:r,sources:n,min:o,max:s,defaultValue:i})=>{this.defineAxisBinding(t,r,n??[],o,s,i)})}defineButtonBindings(e){e.forEach(({bindingId:t,name:r,sources:n,defaultValue:o})=>{this.defineButtonBinding(t,r,n??[],o)})}getInputBindingsLoadPacket(){return this.inputBindings.toLoadPacket()}applyInputBindingsLoadPacket(e){try{let t=JSON.parse(e);if(t.type!=="input-binding")throw new Error(`Invalid packet type: ${t.type}`);for(let r of t.axes)this.defineAxisBinding(r.bindingId,r.name,r.sources||[],r.min,r.max,r.defaultValue);for(let r of t.buttons)this.defineButtonBinding(r.bindingId,r.name,r.sources||[],r.defaultValue)}catch(t){throw console.error("[User] Failed to apply input bindings:",t),t}}getInputBindingRegistry(){return this.inputBindings}getStats(){return this.stats}getAxisBindingId(e){return this.inputBindings.getAxisBindingId(e)}getButtonBindingId(e){return this.inputBindings.getButtonBindingId(e)}decodeAndApplyCompressedInput(e){let t=ge(e,this.inputBindings),r=this.inputBindings.getAllAxes(),n=this.inputBindings.getAllButtons(),o=r.sort((i,a)=>i.bindingId-a.bindingId),s=n.sort((i,a)=>i.bindingId-a.bindingId);for(let[i,a]of t.axes)if(i<o.length){let d=o[i];this.setAxis(d.name,a)}for(let[i,a]of t.buttons)if(i<s.length){let d=s[i];this.setButton(d.name,a)}this.mouseX=t.mouseX,this.mouseY=t.mouseY,this.mouseOver=t.mouseOverDisplay,this.mouseDisplayId=t.displayId}playSound(e,t){let r=this.nextSoundInstanceId++,n={sound:e,instanceId:r,volume:t?.volume,pitch:t?.pitch,loop:t?.loop,fadeIn:t?.fadeIn,position:t?.x!==void 0&&t?.y!==void 0?{x:t.x,y:t.y}:void 0};return this.soundCommands.push(n),r}stopSound(e){let t={sound:e};this.soundCommands.push(t)}fadeOutSound(e,t){let r={fadeOut:!0,sound:e,duration:t};this.soundCommands.push(r)}fadeOutAllSounds(e){let t={fadeOut:!0,sound:"all",duration:e};this.soundCommands.push(t)}stopAllSounds(){let e={sound:"all"};this.soundCommands.push(e)}pauseSound(e){let t={pause:!0,sound:e};this.soundCommands.push(t)}pauseAllSounds(){let e={pause:!0,sound:"all"};this.soundCommands.push(e)}resumeSound(e){let t={resume:!0,sound:e};this.soundCommands.push(t)}resumeAllSounds(){let e={resume:!0,sound:"all"};this.soundCommands.push(e)}setListenerPosition(e,t){e===this.lastListenerX&&t===this.lastListenerY||(this.lastListenerX=e,this.lastListenerY=t,this.audioConfigCommands.push({type:"set-listener-position",x:e,y:t}))}configureSpatialAudio(e){this.audioConfigCommands.push({type:"configure-spatial",...e})}flushAudioConfigCommands(){let e=this.audioConfigCommands;return this.audioConfigCommands=[],e}hasAudioConfigCommands(){return this.audioConfigCommands.length>0}flushSoundCommands(){let e=this.soundCommands;return this.soundCommands=[],e}hasSoundCommands(){return this.soundCommands.length>0}sendSounds(){this.pendingSendSounds=!0}needsSendSounds(){return this.pendingSendSounds}clearSendSounds(){this.pendingSendSounds=!1}setAudioProcessor(e){this.audioProcessor=e}getAudioProcessor(){return this.audioProcessor}applyAudioCommands(e){if(this.audioProcessor&&this.mode!=="server")for(let t of e){if("fadeOut"in t&&t.fadeOut===!0){let n=t;this.audioProcessor.fadeOut(n.sound,n.duration);continue}if("pause"in t&&t.pause===!0){let n=t;this.audioProcessor.pause(n.sound);continue}if("resume"in t&&t.resume===!0){let n=t;this.audioProcessor.resume(n.sound);continue}if("instanceId"in t||"volume"in t||"pitch"in t||"loop"in t||"fadeIn"in t||"position"in t){let n=t;this.audioProcessor.play(n.sound,{volume:n.volume,pitch:n.pitch,loop:n.loop,fadeIn:n.fadeIn,position:n.position,instanceId:n.instanceId})}else{let n=t;n.sound==="all"?this.audioProcessor.stopAll():this.audioProcessor.stop(n.sound)}}}applyAudioConfigCommands(e){if(this.audioProcessor&&this.mode!=="server")for(let t of e)t.type==="set-listener-position"?this.audioProcessor.setListenerPosition(t.x,t.y):t.type==="configure-spatial"&&this.audioProcessor.configureSpatial({maxDistance:t.maxDistance,referenceDistance:t.referenceDistance,rolloffFactor:t.rolloffFactor,panSpread:t.panSpread})}};g(De,"User");var Z=De;X();var Te=class Te{encode(e){switch(e.type){case 1:return this.encodeCharOrder(e);case 2:return this.encodeTextOrder(e);case 23:return this.encodeTextMultilineOrder(e);case 3:return this.encodeSubFrameOrder(e);case 4:return this.encodeSubFrameMultiColorOrder(e);case 5:return this.encodeFullFrameOrder(e);case 6:return this.encodeFullFrameMultiColorOrder(e);case 7:return this.encodeSpriteOrder(e);case 8:return this.encodeSpriteMultiColorOrder(e);case 9:return this.encodeColorMapOrder(e);case 10:return this.encodeShapeOrder(e);case 11:return this.encodeDotCloudOrder(e);case 12:return this.encodeDotCloudMultiColorOrder(e);case 17:return this.encodeBitmaskOrder(e);case 18:return this.encodeBitmask4Order(e);case 24:return this.encodeBitmask16Order(e);case 13:return this.encodeSpriteCloudOrder(e);case 14:return this.encodeSpriteCloudMultiColorOrder(e);case 15:return this.encodeSpriteCloudVariedOrder(e);case 16:return this.encodeSpriteCloudVariedMultiColorOrder(e);case 19:return this.encodeClearOrder(e);case 20:return this.encodeFillCharOrder(e);case 21:return this.encodeFillSpriteOrder(e);case 22:return this.encodeFillSpriteMultiColorOrder(e);case 32:return this.encodeTriggerSoundOrder(e);case 33:return this.encodeTriggerGlobalSoundOrder(e);default:throw new Error(`Unknown order type: ${e.type}`)}}encodeCharOrder(e){let t=I.allocUnsafe(6),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.charCode,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeTextOrder(e){let t=new TextEncoder().encode(e.text),r=I.allocUnsafe(6+t.length),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(t.length,n++);for(let o=0;o<t.length;o++)r.writeUInt8(t[o],n++);return r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.toUint8Array()}encodeTextMultilineOrder(e){let t=new TextEncoder().encode(e.text),r=I.allocUnsafe(6+t.length),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(t.length,n++);for(let o=0;o<t.length;o++)r.writeUInt8(t[o],n++);return r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.toUint8Array()}encodeSubFrameOrder(e){let t=e.sizeX*e.sizeY,r=I.allocUnsafe(7+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++);for(let o of e.frame)r.writeUInt8(o,n++);return r.toUint8Array()}encodeSubFrameMultiColorOrder(e){let t=e.sizeX*e.sizeY,r=I.allocUnsafe(5+t*3),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++);for(let o of e.frame)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);return r.toUint8Array()}encodeFullFrameOrder(e){let t=e.frame.length,r=I.allocUnsafe(3+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++);for(let o of e.frame)r.writeUInt8(o,n++);return r.toUint8Array()}encodeFullFrameMultiColorOrder(e){let t=e.frame.length,r=I.allocUnsafe(1+t*3),n=0;r.writeUInt8(e.type,n++);for(let o of e.frame)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);return r.toUint8Array()}encodeSpriteOrder(e){let t=I.allocUnsafe(6),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.spriteIndex,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeSpriteMultiColorOrder(e){let t=I.allocUnsafe(4),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.spriteIndex,r++),t.toUint8Array()}encodeColorMapOrder(e){let t=e.sizeX*e.sizeY,r=I.allocUnsafe(5+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++);for(let o of e.colorData)r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);return r.toUint8Array()}encodeShapeOrder(e){let t=this.encodeShapeData(e.shapeType,e.shapeData),r=I.allocUnsafe(2+t.length),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.shapeType,n++);for(let o=0;o<t.length;o++)r.writeUInt8(t[o],n++);return r.toUint8Array()}encodeShapeData(e,t){switch(e){case 1:{let r=I.allocUnsafe(8),n=0;return r.writeUInt8(t.posX,n++),r.writeUInt8(t.posY,n++),r.writeUInt8(t.width,n++),r.writeUInt8(t.height,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 2:{let r=I.allocUnsafe(7),n=0;return r.writeUInt8(t.centerX,n++),r.writeUInt8(t.centerY,n++),r.writeUInt8(t.radius,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 3:{let r=I.allocUnsafe(7),n=0;return r.writeUInt8(t.x1,n++),r.writeUInt8(t.y1,n++),r.writeUInt8(t.x2,n++),r.writeUInt8(t.y2,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 4:{let r=I.allocUnsafe(8),n=0;return r.writeUInt8(t.centerX,n++),r.writeUInt8(t.centerY,n++),r.writeUInt8(t.radiusX,n++),r.writeUInt8(t.radiusY,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 5:{let r=I.allocUnsafe(10),n=0;return r.writeUInt8(t.x1,n++),r.writeUInt8(t.y1,n++),r.writeUInt8(t.x2,n++),r.writeUInt8(t.y2,n++),r.writeUInt8(t.x3,n++),r.writeUInt8(t.y3,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}default:throw new Error(`Unknown shape type: ${e}`)}}encodeDotCloudOrder(e){let t=e.positions.length,r=I.allocUnsafe(6+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.charCode,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.positions)r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeDotCloudMultiColorOrder(e){let t=e.dots.length,r=I.allocUnsafe(5+t*5),n=0;r.writeUInt8(e.type,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.dots)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++),r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeBitmaskOrder(e){let t=e.mask.length,r=I.allocUnsafe(9+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.charCode,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.writeUInt8(e.override?1:0,n++);for(let o=0;o<t;o++)r.writeUInt8(e.mask[o],n++);return r.toUint8Array()}encodeBitmask4Order(e){let t=e.mask.length,r=I.allocUnsafe(15+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.override?1:0,n++);for(let o of e.variants)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);for(let o=0;o<t;o++)r.writeUInt8(e.mask[o],n++);return r.toUint8Array()}encodeBitmask16Order(e){let t=e.mask.length,r=I.allocUnsafe(51+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.override?1:0,n++);for(let o of e.variants)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);for(let o=0;o<t;o++)r.writeUInt8(e.mask[o],n++);return r.toUint8Array()}encodeSpriteCloudOrder(e){let t=e.positions.length,r=I.allocUnsafe(8+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.spriteIndex,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.positions)r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeSpriteCloudMultiColorOrder(e){let t=e.positions.length,r=I.allocUnsafe(6+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.spriteIndex,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.positions)r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeSpriteCloudVariedOrder(e){let t=e.sprites.length,r=I.allocUnsafe(3+t*5),n=0;r.writeUInt8(e.type,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.sprites)r.writeUInt8(o.spriteIndex,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++),r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeSpriteCloudVariedMultiColorOrder(e){let t=e.sprites.length,r=I.allocUnsafe(3+t*3),n=0;r.writeUInt8(e.type,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.sprites)r.writeUInt8(o.spriteIndex,n++),r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeClearOrder(e){let t=I.allocUnsafe(4),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.charCode,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeFillCharOrder(e){let t=e.patternWidth*e.patternHeight,r=I.allocUnsafe(5+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.patternWidth,n++),r.writeUInt8(e.patternHeight,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++);for(let o of e.pattern)r.writeUInt8(o,n++);return r.toUint8Array()}encodeFillSpriteOrder(e){let t=I.allocUnsafe(4),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.spriteIndex,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeFillSpriteMultiColorOrder(e){let t=I.allocUnsafe(2),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.spriteIndex,r++),t.toUint8Array()}encodeTriggerSoundOrder(e){let t=I.allocUnsafe(5),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.soundId,r++),t.writeUInt8(e.loop?1:0,r++),t.toUint8Array()}encodeTriggerGlobalSoundOrder(e){let t=I.allocUnsafe(3),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.soundId,r++),t.writeUInt8(e.loop?1:0,r++),t.toUint8Array()}};g(Te,"OrderEncoder");var be=Te;X();var Pe=class Pe{constructor(){m(this,"orderEncoder");this.orderEncoder=new be}encode(e){let t=e.orders.map(a=>this.orderEncoder.encode(a)),r=13,n=t.reduce((a,d)=>a+d.length,0),o=r+n,s=I.allocUnsafe(o),i=0;s.writeUInt16BE(e.id,i),i+=2,s.writeUInt8(e.updateFlags,i++),s.writeUInt8(e.zIndex,i++),s.writeUInt16BE(e.originX,i),i+=2,s.writeUInt16BE(e.originY,i),i+=2,s.writeUInt16BE(e.width,i),i+=2,s.writeUInt16BE(e.height,i),i+=2,s.writeUInt8(e.orders.length,i++);for(let a of t)I.from(a).copy(s,i),i+=a.length;return s.toUint8Array()}calculateSize(e){return 13+e.orders.reduce((n,o)=>n+this.orderEncoder.encode(o).length,0)}};g(Pe,"LayerEncoder");var ye=Pe;X();var Xe=class Xe{constructor(){m(this,"layerEncoder");this.layerEncoder=new ye}encode(e){let t=e.layers.map(c=>this.layerEncoder.encode(c)),r=9,n=e.displays.length*7,o=2,s=t.reduce((c,u)=>c+u.length,0),i=r+n+o+s,a=I.allocUnsafe(i),d=0,l=typeof e.tick=="bigint"?e.tick:BigInt(e.tick);a.writeBigUInt64BE(l,d),d+=8,a.writeUInt8(e.displays.length,d),d+=1;for(let c of e.displays)a.writeUInt8(c.id,d++),a.writeUInt16BE(c.originX,d),d+=2,a.writeUInt16BE(c.originY,d),d+=2,a.writeUInt8(Math.max(1,Math.min(256,c.sizeX))-1,d++),a.writeUInt8(Math.max(1,Math.min(256,c.sizeY))-1,d++);a.writeUInt16BE(e.layers.length,d),d+=2;for(let c of t)I.from(c).copy(a,d),d+=c.length;return a.toUint8Array()}calculateSize(e){let r=e.displays.length*7,n=2,o=e.layers.reduce((s,i)=>s+this.layerEncoder.calculateSize(i),0);return 9+r+n+o}static createEmptyPacket(e){return{tick:typeof e=="bigint"?Number(e):e,displayCount:0,displays:[],layerCount:0,layers:[]}}encodeEmpty(e){let t=I.allocUnsafe(11),r=typeof e=="bigint"?e:BigInt(e);return t.writeBigUInt64BE(r,0),t.writeUInt8(0,8),t.writeUInt16BE(0,9),t.toUint8Array()}};g(Xe,"UpdatePacketEncoder");var Se=Xe;var G=class G{constructor(e){this.engine=e;m(this,"colorCache",new Array(256));m(this,"cellsBuffer",[]);m(this,"opacityBuffer",new Uint8Array(0));m(this,"visibleLayersBuffer",[]);this.rebuildColorCache()}rebuildColorCache(){for(let e=0;e<256;e++){let t=this.engine.getColor(e);t?this.colorCache[e]={r:t.r,g:t.g,b:t.b,a:t.a}:this.colorCache[e]={r:0,g:0,b:0,a:0}}}getColorRGB(e){return this.colorCache[e]??this.colorCache[255]}getColorEmission(e){let t=this.engine.getColor(e);return t?t.e:0}isLayerVisible(e,t){let r=e.x,n=e.x+e.width,o=e.y,s=e.y+e.height,i=t.x,a=t.x+256,d=t.y,l=t.y+256;return!(n<=i||r>=a||s<=d||o>=l)}rasterize(e,t){let r=e.width*e.height,n=this.cellsBuffer;n.length=r;for(let i=0;i<r;i++)n[i]?(n[i].char=" ",n[i].fgColorIndex=255,n[i].bgColorIndex=255,n[i].fgEmission=0,n[i].bgEmission=0):n[i]={char:" ",fgColorIndex:255,bgColorIndex:255,fgEmission:0,bgEmission:0};this.opacityBuffer.length<r?this.opacityBuffer=new Uint8Array(r):this.opacityBuffer.fill(0,0,r);let o=this.opacityBuffer,s=this.visibleLayersBuffer;s.length=0;for(let i=0;i<t.length;i++){let a=t[i];a.isEnabled()&&this.isLayerVisible(e,a.getOrigin())&&s.push(a)}s.sort((i,a)=>a.getZOrder()-i.getZOrder());for(let i=0;i<e.height;i++)for(let a=0;a<e.width;a++){let d=i*e.width+a;if(o[d])continue;let l=e.x+a,c=e.y+i;for(let u=0;u<s.length;u++){let p=s[u],h=l-p.getOrigin().x,C=c-p.getOrigin().y,y=p.getWidth(),f=p.getHeight();if(h<0||h>=y||C<0||C>=f)continue;let U=C*y+h,b=p.getData(),v=b.getCharCode(U),B=b.getFgColorCode(U),O=b.getBgColorCode(U),w=n[d];if(v!==0&&v<256&&w.char===" "&&(w.char=G.charCache[v]),B!==255&&w.fgColorIndex===255&&(w.fgColorIndex=B,w.fgEmission=this.getColorEmission(B)),O!==255){w.bgColorIndex===255&&(w.bgColorIndex=O,w.bgEmission=this.getColorEmission(O)),o[d]=1;break}}}return{width:e.width,height:e.height,cells:n,palette:this.colorCache}}rasterizeWithSortedLayers(e,t){let r=e.width*e.height,n=this.cellsBuffer;n.length=r;for(let i=0;i<r;i++)n[i]?(n[i].char=" ",n[i].fgColorIndex=255,n[i].bgColorIndex=255,n[i].fgEmission=0,n[i].bgEmission=0):n[i]={char:" ",fgColorIndex:255,bgColorIndex:255,fgEmission:0,bgEmission:0};this.opacityBuffer.length<r?this.opacityBuffer=new Uint8Array(r):this.opacityBuffer.fill(0,0,r);let o=this.opacityBuffer,s=this.visibleLayersBuffer;s.length=0;for(let i=0;i<t.length;i++){let a=t[i];this.isLayerVisible(e,a.getOrigin())&&s.push(a)}for(let i=0;i<e.height;i++)for(let a=0;a<e.width;a++){let d=i*e.width+a;if(o[d])continue;let l=e.x+a,c=e.y+i;for(let u=0;u<s.length;u++){let p=s[u],h=l-p.getOrigin().x,C=c-p.getOrigin().y,y=p.getWidth(),f=p.getHeight();if(h<0||h>=y||C<0||C>=f)continue;let U=C*y+h,b=p.getData(),v=b.getCharCode(U),B=b.getFgColorCode(U),O=b.getBgColorCode(U),w=n[d];if(v!==0&&v<256&&w.char===" "&&(w.char=G.charCache[v]),B!==255&&w.fgColorIndex===255&&(w.fgColorIndex=B,w.fgEmission=this.getColorEmission(B)),O!==255){w.bgColorIndex===255&&(w.bgColorIndex=O,w.bgEmission=this.getColorEmission(O)),o[d]=1;break}}}return{width:e.width,height:e.height,cells:n,palette:this.colorCache}}calculateIntersection(e,t){let r=e.x,n=e.x+e.width,o=e.y,s=e.y+e.height,i=t.x,a=t.x+256,d=t.y,l=t.y+256,c=Math.max(r,i),u=Math.min(n,a),p=Math.max(o,d),h=Math.min(s,l);return{visible:c<u&&p<h,originStart:{x:c-e.x,y:p-e.y},originEnd:{x:u-e.x,y:h-e.y},layerStart:{x:c-t.x,y:p-t.y},layerEnd:{x:u-t.x,y:h-t.y}}}};g(G,"DisplayRasterizer"),m(G,"charCache",(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=String.fromCharCode(t);return e})());var Ie=G;var Ye=class Ye{constructor(){m(this,"enabled",!1);m(this,"currentStats",null)}setEnabled(e){this.enabled=e,e||(this.currentStats=null)}isEnabled(){return this.enabled}get tick(){return this.currentStats?.tick??0}get timestamp(){return this.currentStats?.timestamp??0}get totalOrders(){return this.currentStats?.totalOrders??0}get ordersByLayer(){return this.currentStats?.ordersByLayer??new Map}get ordersByType(){return this.currentStats?.ordersByType??new Map}get totalLayers(){return this.currentStats?.totalLayers??0}get visibleLayers(){return this.currentStats?.visibleLayers??0}get layersPerDisplay(){return this.currentStats?.layersPerDisplay??new Map}get updatePacketSize(){return this.currentStats?.updatePacketSize??0}get displayHeaderSize(){return this.currentStats?.displayHeaderSize??0}get layerHeaderSize(){return this.currentStats?.layerHeaderSize??0}get orderDataSize(){return this.currentStats?.orderDataSize??0}get compressionRatio(){return this.currentStats?.compressionRatio??0}get compressedPacketSize(){return Math.round(this.updatePacketSize*this.compressionRatio)}get totalCells(){return this.currentStats?.totalCells??0}get nonEmptyCells(){return this.currentStats?.nonEmptyCells??0}get cellsWithBackground(){return this.currentStats?.cellsWithBackground??0}get rasterizationTimeMs(){return this.currentStats?.rasterizationTimeMs??0}get encodingTimeMs(){return this.currentStats?.encodingTimeMs??0}get packetSplit(){return this.currentStats?.packetSplit}get layerDetails(){return this.currentStats?.layerDetails}startTick(e){this.enabled&&(this.currentStats={tick:e,timestamp:Date.now(),totalOrders:0,ordersByLayer:new Map,ordersByType:new Map,totalLayers:0,visibleLayers:0,layersPerDisplay:new Map,updatePacketSize:0,displayHeaderSize:0,layerHeaderSize:0,orderDataSize:0,compressionRatio:0,totalCells:0,nonEmptyCells:0,cellsWithBackground:0,rasterizationTimeMs:0,encodingTimeMs:0})}recordLayerOrders(e,t){if(!(!this.enabled||!this.currentStats)){this.currentStats.totalOrders+=t.length,this.currentStats.ordersByLayer.set(e,t.length);for(let r of t){let n=this.currentStats.ordersByType.get(r.type)||0;this.currentStats.ordersByType.set(r.type,n+1)}}}recordLayers(e,t){!this.enabled||!this.currentStats||(this.currentStats.totalLayers=e,this.currentStats.visibleLayers=t)}recordDisplayLayers(e,t){!this.enabled||!this.currentStats||this.currentStats.layersPerDisplay.set(e,t)}recordUpdatePacketSize(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.updatePacketSize=e,this.currentStats.displayHeaderSize=t,this.currentStats.layerHeaderSize=r,this.currentStats.orderDataSize=n,this.currentStats.compressionRatio=.25)}recordPacketSplit(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.packetSplit={userId:e,displayCount:t,staticLayerCount:r,dynamicLayerCount:n})}recordLayerInfo(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.layerDetails||(this.currentStats.layerDetails=[]),this.currentStats.layerDetails.push({layerId:e,isStatic:t,orderCount:r,updateFlags:n}))}recordRenderStats(e,t,r){!this.enabled||!this.currentStats||(this.currentStats.totalCells=e,this.currentStats.nonEmptyCells=t,this.currentStats.cellsWithBackground=r)}recordRasterizationTime(e){!this.enabled||!this.currentStats||(this.currentStats.rasterizationTimeMs=e)}recordEncodingTime(e){!this.enabled||!this.currentStats||(this.currentStats.encodingTimeMs=e)}endTick(){}reset(){this.currentStats=null}};g(Ye,"CoreStats");var j=Ye;var We=class We{constructor(){m(this,"unicolorSprites",new Map);m(this,"multicolorSprites",new Map)}loadUnicolorSprites(e){for(let t of e.sprites){let r=new N(t.sizeX*t.sizeY);for(let o=0;o<t.data.length;o++)r.set(o,t.data[o]);let n={id:t.spriteId,sizeX:t.sizeX,sizeY:t.sizeY,data:r};this.unicolorSprites.set(n.id,n)}}loadMulticolorSprites(e){for(let t of e.sprites){let r=new R(t.sizeX*t.sizeY);for(let o=0;o<t.data.length;o++){let s=t.data[o];r.set(o,s.charCode,s.fgColorId,s.bgColorId)}let n={id:t.spriteId,sizeX:t.sizeX,sizeY:t.sizeY,data:r};this.multicolorSprites.set(n.id,n)}}getUnicolorSprite(e){return this.unicolorSprites.get(e)}getMulticolorSprite(e){return this.multicolorSprites.get(e)}hasUnicolorSprite(e){return this.unicolorSprites.has(e)}hasMulticolorSprite(e){return this.multicolorSprites.has(e)}unloadUnicolorSprite(e){return this.unicolorSprites.delete(e)}unloadMulticolorSprite(e){return this.multicolorSprites.delete(e)}clearUnicolorSprites(){this.unicolorSprites.clear()}clearMulticolorSprites(){this.multicolorSprites.clear()}clearAll(){this.unicolorSprites.clear(),this.multicolorSprites.clear()}getUnicolorSpriteCount(){return this.unicolorSprites.size}getMulticolorSpriteCount(){return this.multicolorSprites.size}getTotalSpriteCount(){return this.unicolorSprites.size+this.multicolorSprites.size}};g(We,"SpriteRegistry");var q=We;var _e=(t=>(t.Web="web",t.Bitmap="bitmap",t))(_e||{}),Ne=class Ne{constructor(e,t){this.fontId=e;this.config=t}getFontId(){return this.fontId}getConfig(){return{...this.config}}getFontFamily(){return this.config.fontFamily}getFontSize(){return this.config.fontSize}getOffsetX(){return this.config.offsetX??0}getOffsetY(){return this.config.offsetY??0}getCharSpacing(){return this.config.charSpacing??0}getLineHeight(){return this.config.lineHeight??1.2}getFontWeight(){return this.config.fontWeight??"normal"}getFontStyle(){return this.config.fontStyle??"normal"}toCSS(){let e=[];e.push(`font-family: ${this.config.fontFamily}`),e.push(`font-size: ${this.config.fontSize}px`);let t=this.config.fontWeight??"normal";t!=="normal"&&e.push(`font-weight: ${t}`);let r=this.config.fontStyle??"normal";return r!=="normal"&&e.push(`font-style: ${r}`),e.join("; ")+";"}};g(Ne,"WebFont");var L=Ne,$e=class $e{constructor(e,t){this.fontId=e;this.config=t}getFontId(){return this.fontId}getConfig(){return{charWidth:this.config.charWidth,charHeight:this.config.charHeight,cellWidth:this.config.cellWidth,cellHeight:this.config.cellHeight,glyphs:new Map(this.config.glyphs)}}getCharWidth(){return this.config.charWidth}getCharHeight(){return this.config.charHeight}getCellWidth(){return this.config.cellWidth??this.config.charWidth}getCellHeight(){return this.config.cellHeight??this.config.charHeight}getGlyph(e){return this.config.glyphs.get(e)}hasGlyph(e){return this.config.glyphs.has(e)}getGlyphCount(){return this.config.glyphs.size}getCharCodes(){return Array.from(this.config.glyphs.keys())}};g($e,"BitmapFont");var K=$e;var He=class He{constructor(){m(this,"fonts",new Map)}loadFont(e,t){if(this.fonts.has(e))throw new Error(`WebFont with ID ${e} already exists`);let r=new L(e,t);this.fonts.set(e,r)}getFont(e){return this.fonts.get(e)}hasFont(e){return this.fonts.has(e)}unloadFont(e){return this.fonts.delete(e)}clearFonts(){this.fonts.clear()}getFontIds(){return Array.from(this.fonts.keys()).sort((e,t)=>e-t)}getAllFonts(){return Array.from(this.fonts.entries()).sort((e,t)=>e[0]-t[0]).map(e=>e[1])}getFontCount(){return this.fonts.size}};g(He,"WebFontRegistry");var J=He;var Ve=class Ve{constructor(){m(this,"fonts",new Map)}loadFont(e,t){if(this.fonts.has(e))throw new Error(`BitmapFont with ID ${e} already exists`);let r=new K(e,t);this.fonts.set(e,r)}getFont(e){return this.fonts.get(e)}hasFont(e){return this.fonts.has(e)}unloadFont(e){return this.fonts.delete(e)}clearFonts(){this.fonts.clear()}getFontIds(){return Array.from(this.fonts.keys()).sort((e,t)=>e-t)}getAllFonts(){return Array.from(this.fonts.entries()).sort((e,t)=>e[0]-t[0]).map(e=>e[1])}getFontCount(){return this.fonts.size}};g(Ve,"BitmapFontRegistry");var Q=Ve;var Ze=class Ze{constructor(){m(this,"sounds",new Map);m(this,"nameToId",new Map);m(this,"nextId",0)}registerFile(e,t,r){let n=this.allocateId(e),o={soundId:n,name:e,loadType:"file",format:t,data:r};return this.sounds.set(n,o),this.nameToId.set(e,n),n}registerFileWithId(e,t,r,n){this.validateId(e),this.checkIdAvailable(e,t);let o={soundId:e,name:t,loadType:"file",format:r,data:n};this.sounds.set(e,o),this.nameToId.set(t,e)}registerExternal(e,t,r,n,o){let s=this.allocateId(e),i={soundId:s,name:e,loadType:"external",format:t,url:r,size:n,checksum:o};return this.sounds.set(s,i),this.nameToId.set(e,s),s}registerExternalWithId(e,t,r,n,o,s){this.validateId(e),this.checkIdAvailable(e,t);let i={soundId:e,name:t,loadType:"external",format:r,url:n,size:o,checksum:s};this.sounds.set(e,i),this.nameToId.set(t,e)}get(e){if(typeof e=="number")return this.sounds.get(e);let t=this.nameToId.get(e);return t!==void 0?this.sounds.get(t):void 0}has(e){return this.get(e)!==void 0}getAll(){return Array.from(this.sounds.values())}getFileSounds(){return this.getAll().filter(e=>e.loadType==="file")}getExternalSounds(){return this.getAll().filter(e=>e.loadType==="external")}getNames(){return Array.from(this.nameToId.keys())}getId(e){return this.nameToId.get(e)}toLoadPackets(){let e=[],t=this.getFileSounds();if(t.length>0){let n=t.map(o=>({soundId:o.soundId,name:o.name,format:o.format,data:o.data}));e.push({type:"sound",mode:"file",sounds:n})}let r=this.getExternalSounds();if(r.length>0){let n=r.map(o=>({soundId:o.soundId,name:o.name,format:o.format,url:o.url,size:o.size,checksum:o.checksum}));e.push({type:"sound",mode:"external",sounds:n})}return e}toLoadPacket(e){let t=this.get(e);return t?t.loadType==="file"?{type:"sound",mode:"file",sounds:[{soundId:t.soundId,name:t.name,format:t.format,data:t.data}]}:{type:"sound",mode:"external",sounds:[{soundId:t.soundId,name:t.name,format:t.format,url:t.url,size:t.size,checksum:t.checksum}]}:null}unregister(e){let t=this.get(e);return t?(this.sounds.delete(t.soundId),this.nameToId.delete(t.name),!0):!1}clear(){this.sounds.clear(),this.nameToId.clear(),this.nextId=0}get size(){return this.sounds.size}getStats(){let e=this.getAll(),t=e.filter(n=>n.loadType==="file"),r=t.reduce((n,o)=>n+(o.data?.length??0),0);return{total:e.length,file:t.length,external:e.length-t.length,totalFileSize:r}}allocateId(e){if(this.nameToId.has(e))throw new Error(`Sound with name "${e}" already exists`);for(;this.sounds.has(this.nextId);)if(this.nextId++,this.nextId>255)throw new Error("Maximum number of sounds (256) reached");return this.nextId++}validateId(e){if(!Number.isInteger(e)||e<0||e>255)throw new Error(`Invalid sound ID: ${e}. Must be an integer between 0 and 255.`)}checkIdAvailable(e,t){if(this.sounds.has(e)){let r=this.sounds.get(e);throw new Error(`Sound ID ${e} is already used by "${r.name}". Cannot register "${t}".`)}if(this.nameToId.has(t))throw new Error(`Sound with name "${t}" already exists`)}};g(Ze,"SoundRegistry");var ee=Ze;var ne=class ne{constructor(e={}){m(this,"users",new Map);m(this,"mode");m(this,"maxUsers");m(this,"strictMode");m(this,"currentTick",0);m(this,"encoder");m(this,"displayRasterizer");m(this,"colorPalette",new Map);m(this,"stats",new j);m(this,"spriteRegistry",new q);m(this,"webFontRegistry",new J);m(this,"bitmapFontRegistry",new Q);m(this,"soundRegistry",new ee);m(this,"activeWebFontId",0);m(this,"_renderCallCount",0);m(this,"onPaletteChangedCallback");m(this,"onBitmapFontChangedCallback");this.mode=e.mode??"server",this.maxUsers=e.maxUsers??64,this.strictMode=e.strictMode??!1,this.encoder=new Se,this.displayRasterizer=new Ie(this),this.initializeDefaultPalette(),this.displayRasterizer.rebuildColorCache(),this.loadDefaultWebFont()}initializeDefaultPalette(){ne.ANSI_VGA_COLORS.forEach(e=>{this.colorPalette.set(e.colorId,{r:e.r,g:e.g,b:e.b,a:e.a,e:e.e})}),this.colorPalette.set(255,{r:0,g:0,b:0,a:0,e:0})}getMode(){return this.mode}getMaxUsers(){return this.maxUsers}isStrictMode(){return this.strictMode}isServer(){return this.mode==="server"}isClient(){return this.mode==="client"}isStandalone(){return this.mode==="standalone"}createUser(e,t){if(this.users.has(e))throw new Error(`User with ID ${e} already exists`);if(this.mode==="server"&&this.users.size>=this.maxUsers)throw new Error(`Maximum number of users reached (${this.maxUsers}). Cannot create user ${e}`);if(this.mode==="client"&&this.users.size>=1)throw new Error(`Client mode only allows one user. Cannot create user ${e}`);let r=new Z(e,t,this.mode);return r.setSpriteRegistry(this.spriteRegistry),this.users.set(e,r),r}getUser(e){return this.users.get(e)??null}getUsers(){return Array.from(this.users.values())}hasUser(e){return this.users.has(e)}removeUser(e){return this.users.delete(e)}getUserCount(){return this.users.size}clearAllUsers(){this.users.clear()}setColor(e,t,r,n,o=255,s=0){if(e<0||e>255)throw new Error(`Color ID must be between 0 and 255, got ${e}`);if(e>=240)throw new Error("Color IDs 240-255 are reserved (240-254: UI palette, 255: skip color). Use IDs 0-239 for custom colors.");if(t<0||t>255||r<0||r>255||n<0||n>255||o<0||o>255||s<0||s>255)throw new Error("Color components must be between 0 and 255");this.colorPalette.set(e,{r:t,g:r,b:n,a:o,e:s}),this.onPaletteChangedCallback&&this.onPaletteChangedCallback(this.colorPalette)}onPaletteChanged(e){this.onPaletteChangedCallback=e}onBitmapFontChanged(e){this.onBitmapFontChangedCallback=e}getColor(e){return this.colorPalette.get(e)??null}loadPalette(e){for(let t of e)t.colorId<0||t.colorId>255||this.colorPalette.set(t.colorId,{r:t.r,g:t.g,b:t.b,a:t.a,e:t.e??0});ne.ANSI_VGA_COLORS.forEach(t=>{this.colorPalette.set(t.colorId,{r:t.r,g:t.g,b:t.b,a:t.a,e:t.e})}),this.colorPalette.set(255,{r:0,g:0,b:0,a:0,e:0}),this.displayRasterizer.rebuildColorCache(),this.onPaletteChangedCallback&&this.onPaletteChangedCallback(this.colorPalette)}getPalette(){return new Map(this.colorPalette)}resetPalette(){this.colorPalette.clear(),this.initializeDefaultPalette(),this.onPaletteChangedCallback&&this.onPaletteChangedCallback(this.colorPalette)}getColorCSS(e){let t=this.getColor(e);if(!t)return null;let r=t.a/255;return`rgba(${t.r}, ${t.g}, ${t.b}, ${r})`}getUserIds(){return Array.from(this.users.keys())}forEachUser(e){this.users.forEach(e)}filterUsers(e){return this.getUsers().filter(e)}findUser(e){return this.getUsers().find(e)}getCurrentTick(){return this.currentTick}getStats(){return this.stats}endTick(){this.stats.isEnabled()&&this.stats.startTick(this.currentTick);let e=new Map,t=0,r=0;return this.users.forEach((n,o)=>{let s=n.getLayers(),i=n.getDisplays();t+=s.length,n.getStats().isEnabled()&&n.getStats().startTick(this.currentTick);let a=i.map(p=>{let h=p.getOrigin(),C=p.getSize();return{id:p.getId(),originX:h.x,originY:h.y,sizeX:C.x,sizeY:C.y}});i.forEach(p=>p.resetChangeTracking());let d=[],l=[];s.forEach((p,h)=>{let C=p.getOrigin(),y=p.getOrders(),f=p.getStatic(),U=p.calculateUpdateFlags();p.resetChangeTracking(),p.getId()===0&&p.setId(h);let b={id:p.getId(),updateFlags:U,zIndex:p.getZOrder(),originX:C.x,originY:C.y,width:p.getWidth(),height:p.getHeight(),orderCount:y.length,orders:y};f?d.push(b):l.push(b)}),r+=d.length+l.length;let c=[...d,...l],u=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:c.length,layers:c});if(e.set(o,u),this.stats.isEnabled()){c.forEach((y,f)=>{this.stats.recordLayerOrders(f,y.orders)}),i.forEach((y,f)=>{this.stats.recordDisplayLayers(f,c.length)});let p=i.length*12,h=c.length*20,C=u.length-p-h;this.stats.recordUpdatePacketSize(u.length,p,h,C>0?C:0)}}),this.stats.isEnabled()&&(this.stats.recordLayers(t,r),this.stats.endTick()),this.currentTick++,e}endTickSplit(){this.stats.isEnabled()&&this.stats.startTick(this.currentTick);let e=new Map,t=0,r=0;return this.users.forEach((n,o)=>{let s=n.getLayers(),i=n.getDisplays();t+=s.length,n.getStats().isEnabled()&&n.getStats().startTick(this.currentTick);let a=i.map(p=>{let h=p.getOrigin(),C=p.getSize();return{id:p.getId(),originX:h.x,originY:h.y,sizeX:C.x,sizeY:C.y}});i.forEach(p=>p.resetChangeTracking());let d=[],l=[];s.forEach((p,h)=>{if(!p.getNeedsCommit())return;let C=p.getOrigin(),y=p.getOrders(),f=p.getStatic(),U=p.calculateUpdateFlags();p.resetChangeTracking(),p.resetCommit(),p.getId()===0&&p.setId(h);let b={id:p.getId(),updateFlags:U,zIndex:p.getZOrder(),originX:C.x,originY:C.y,width:p.getWidth(),height:p.getHeight(),orderCount:y.length,orders:y};y.length>0&&this.stats.isEnabled()&&this.stats.recordLayerInfo(p.getId(),f,y.length,U),f?d.push(b):l.push(b)}),r+=d.length+l.length;let c=null,u=null;if(this.stats.isEnabled()&&this.stats.recordPacketSplit(o,a.length,d.length,l.length),d.length>0&&(c=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:d.length,layers:d})),u=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:l.length,layers:l}),e.set(o,{static:c,dynamic:u}),n.getStats().isEnabled()){let p=i.reduce((f,U)=>{let b=U.getSize();return f+b.x*b.y},0);n.getStats().recordDisplays(i.length,p),n.getStats().recordLayers(s.length,d.length+l.length,d.length,l.length),[...d,...l].forEach(f=>{n.getStats().recordLayerOrders(f.id,f.orders.length)});let h=c?.length||0,C=u?.length||0;n.getStats().recordPacketSizes(h,C);let y=n.getInputBindingRegistry();n.getStats().recordInput(!1,y.getAxisCount(),y.getButtonCount()),n.getStats().endTick()}if(this.stats.isEnabled()){let p=[...d,...l];p.forEach((U,b)=>{this.stats.recordLayerOrders(b,U.orders)}),i.forEach((U,b)=>{this.stats.recordDisplayLayers(b,p.length)});let h=(c?.length||0)+(u?.length||0),C=i.length*12,y=p.length*20,f=h-C-y;this.stats.recordUpdatePacketSize(h,C,y,f>0?f:0)}}),this.stats.isEnabled()&&(this.stats.recordLayers(t,r),this.stats.endTick()),this.currentTick++,e}getSnapshot(e){let t=this.getUser(e);if(!t)return null;let r=t.getDisplays(),n=t.getLayers(),o=r.map((i,a)=>{let d=i.getOrigin(),l=i.getSize();return{id:a,originX:d.x,originY:d.y,sizeX:l.x,sizeY:l.y}}),s=n.map((i,a)=>{let d=i.getOrigin(),l=i.getOrders(),c=7;return i.getId()===0&&i.setId(a),{id:i.getId(),updateFlags:c,zIndex:i.getZOrder(),originX:d.x,originY:d.y,width:i.getWidth(),height:i.getHeight(),orderCount:l.length,orders:l}});return this.encoder.encode({tick:this.currentTick,displayCount:o.length,displays:o,layerCount:s.length,layers:s})}resetTick(){this.currentTick=0}applyUpdatePacket(e,t){let r=this.getUser(e);if(!r){if(this.strictMode)throw new Error(`Cannot apply update packet: user ${e} does not exist`);return!1}return r.applyUpdate(t),!0}applyUpdatePacketBuffer(e,t){let{UpdatePacketDecoder:r}=(Je(),M(ut)),o=new r().decode(t);return this.applyUpdatePacket(e,o)}applyLoadPacket(e){try{let{LoadDecoder:t}=(pt(),M(ct)),{LoadType:r}=(D(),M(Y)),s=new t().decode(e).load;switch(s.loadType){case r.ColorPalette:this.loadPalette(s.colors);break;case r.Sprite:this.loadUnicolorSprites(s);break;case r.MulticolorSprite:this.loadMulticolorSprites(s);break;case r.BitmapFont:{let i=this.getBitmapFontRegistry();i.hasFont(s.fontId)&&i.unloadFont(s.fontId),i.loadFont(s.fontId,{charWidth:s.width,charHeight:s.height,cellWidth:s.cellWidth,cellHeight:s.cellHeight,glyphs:new Map(s.characters.map(a=>[a.charCode,a.bitmap]))});break}case r.WebFont:{let i=this.getWebFontRegistry();i.hasFont(s.fontId)&&i.unloadFont(s.fontId),this.loadWebFontById(s.fontId,{fontFamily:s.fontFamily,fontSize:s.fontSize,offsetX:s.offsetX,offsetY:s.offsetY,charSpacing:s.charSpacing,lineHeight:s.lineHeight,fontWeight:s.fontWeight,fontStyle:s.fontStyle});break}case r.Sound:console.warn("[Core] Sound loading not yet implemented");break;default:return console.error(`[Core] Unknown LoadType: ${s.loadType}`),!1}return!0}catch(t){return console.error("[Core] Failed to apply LoadPacket:",t),!1}}generatePaletteLoadPacket(){let e=this.getPalette();if(e.size===0)return null;let{LoadEncoder:t}=(re(),M(te)),{LoadType:r}=(D(),M(Y)),n=new t,o=[];return e.forEach((s,i)=>{i!==255&&o.push({colorId:i,r:s.r,g:s.g,b:s.b,a:s.a,e:s.e})}),n.encode({loadType:r.ColorPalette,colors:o})}generateUnicolorSpritesLoadPacket(){let e=this.getSpriteRegistry(),t=[];for(let s=0;s<=255;s++){let i=e.getUnicolorSprite(s);if(i){let a=[];for(let d=0;d<i.sizeX*i.sizeY;d++)a.push(i.data.get(d));t.push({spriteId:i.id,sizeX:i.sizeX,sizeY:i.sizeY,data:a})}}if(t.length===0)return null;let{LoadEncoder:r}=(re(),M(te)),{LoadType:n}=(D(),M(Y));return new r().encode({loadType:n.Sprite,sprites:t})}generateMulticolorSpritesLoadPacket(){let e=this.getSpriteRegistry(),t=[];for(let s=0;s<=255;s++){let i=e.getMulticolorSprite(s);if(i){let a=[];for(let d=0;d<i.sizeX*i.sizeY;d++){let l=i.data.get(d);a.push({charCode:l.charCode,fgColorId:l.fgColorCode,bgColorId:l.bgColorCode})}t.push({spriteId:i.id,sizeX:i.sizeX,sizeY:i.sizeY,data:a})}}if(t.length===0)return null;let{LoadEncoder:r}=(re(),M(te)),{LoadType:n}=(D(),M(Y));return new r().encode({loadType:n.MulticolorSprite,sprites:t})}generateWebFontsLoadPackets(){let e=this.getWebFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(re(),M(te)),{LoadType:o}=(D(),M(Y)),s=new n;for(let i of t){let a=e.getFont(i);if(a){let d=a.getConfig(),l=s.encode({loadType:o.WebFont,fontId:i,fontFamily:d.fontFamily,fontSize:d.fontSize,offsetX:d.offsetX,offsetY:d.offsetY,charSpacing:d.charSpacing,lineHeight:d.lineHeight,fontWeight:d.fontWeight,fontStyle:d.fontStyle});r.push(l)}}return r}generateBitmapFontsLoadPackets(){let e=this.getBitmapFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(re(),M(te)),{LoadType:o}=(D(),M(Y)),s=new n;for(let i of t){let a=e.getFont(i);if(a){let d=[];for(let l=0;l<256;l++){let c=a.getGlyph(l);c&&d.push({charCode:l,bitmap:c})}if(d.length>0){let l=s.encode({loadType:o.BitmapFont,fontId:i,width:a.getCharWidth(),height:a.getCharHeight(),cellWidth:a.getCellWidth(),cellHeight:a.getCellHeight(),characters:d});r.push(l)}}}return r}generateAllLoadPackets(){let e=[],t=this.generatePaletteLoadPacket();t&&e.push(t);let r=this.generateUnicolorSpritesLoadPacket();r&&e.push(r);let n=this.generateMulticolorSpritesLoadPacket();n&&e.push(n);let o=this.generateWebFontsLoadPackets();e.push(...o);let s=this.generateBitmapFontsLoadPackets();return e.push(...s),e}applyInputBindingsLoadPacket(e,t){let r=this.getUser(e);if(!r){if(this.strictMode)throw new Error(`Cannot apply input bindings: user ${e} does not exist`);return!1}try{return r.applyInputBindingsLoadPacket(t),!0}catch(n){return console.error(`[Core] Failed to apply input bindings for user ${e}:`,n),!1}}getRenderState(e){let t=this.getUser(e);if(!t)return null;let r=t.getDisplays(),n=t.getLayers(),o=performance.now(),s=new Array(r.length);for(let a=0;a<r.length;a++){let d=r[a],l=d.getOrigin(),c=d.getSize();s[a]=this.displayRasterizer.rasterize({x:l.x,y:l.y,width:c.x,height:c.y},n)}let i=performance.now()-o;return this._renderCallCount||(this._renderCallCount=0),this._renderCallCount++,{userId:t.id,userName:t.name,tick:this.currentTick,displays:s}}getAllRenderStates(){let e=new Map;return this.users.forEach((t,r)=>{let n=this.getRenderState(r);n&&e.set(r,n)}),e}enableStats(e){this.stats.setEnabled(e)}getStatsInstance(){return this.stats}resetStats(){this.stats.reset()}loadUnicolorSprites(e){this.spriteRegistry.loadUnicolorSprites(e)}loadMulticolorSprites(e){this.spriteRegistry.loadMulticolorSprites(e)}unloadUnicolorSprite(e){return this.spriteRegistry.unloadUnicolorSprite(e)}unloadMulticolorSprite(e){return this.spriteRegistry.unloadMulticolorSprite(e)}clearUnicolorSprites(){this.spriteRegistry.clearUnicolorSprites()}clearMulticolorSprites(){this.spriteRegistry.clearMulticolorSprites()}clearAllSprites(){this.spriteRegistry.clearAll()}getUnicolorSpriteCount(){return this.spriteRegistry.getUnicolorSpriteCount()}getMulticolorSpriteCount(){return this.spriteRegistry.getMulticolorSpriteCount()}getTotalSpriteCount(){return this.spriteRegistry.getTotalSpriteCount()}hasUnicolorSprite(e){return this.spriteRegistry.hasUnicolorSprite(e)}hasMulticolorSprite(e){return this.spriteRegistry.hasMulticolorSprite(e)}getSpriteRegistry(){return this.spriteRegistry}getSoundRegistry(){return this.soundRegistry}async loadSound(e,t){let r=this.detectSoundFormat(t),n=await this.loadSoundData(t);return this.soundRegistry.registerFile(e,r,n)}async loadSounds(e){let t={},n=Object.entries(e).map(async([o,s])=>{let i=await this.loadSound(o,s);t[o]=i});return await Promise.all(n),t}detectSoundFormat(e){let t=e.split(".").pop()?.toLowerCase()??"",r={mp3:"mp3",wav:"wav",ogg:"ogg",webm:"webm",aac:"aac",m4a:"aac"},n=r[t];if(!n)throw new Error(`Unsupported audio format: .${t}. Supported: ${Object.keys(r).join(", ")}`);return n}async loadSoundData(e){let t=globalThis;if(typeof t.document<"u"||typeof t.window<"u"||typeof t.fetch=="function")try{let n=await fetch(e);if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`);let o=await n.arrayBuffer();return new Uint8Array(o)}catch(n){let o=n instanceof Error?n.message:String(n);throw new Error(`Failed to load sound "${e}": ${o}`)}else{let n=typeof require<"u"?require:null;if(!n)throw new Error("Node.js require is not available");let i=n("fs").readFileSync(e);return new Uint8Array(i)}}registerSound(e,t,r){return this.soundRegistry.registerFile(e,t,r)}registerExternalSound(e,t,r,n){return this.soundRegistry.registerExternal(e,t,r,n)}hasSound(e){return this.soundRegistry.has(e)}generateSoundLoadPackets(){return this.soundRegistry.toLoadPackets()}loadDefaultWebFont(){this.webFontRegistry.loadFont(0,{fontFamily:"Courier New",fontSize:16,offsetX:0,offsetY:0,charSpacing:0,lineHeight:1,fontWeight:"normal",fontStyle:"normal"}),this.activeWebFontId=0}loadWebFont(e){let t=e.getFontId(),r=e.getConfig();this.webFontRegistry.loadFont(t,r)}getWebFont(e){return this.webFontRegistry.getFont(e)??null}hasWebFont(e){return this.webFontRegistry.hasFont(e)}unloadWebFont(e){if(e===0)throw new Error("Cannot unload default font (fontId 0)");return this.webFontRegistry.unloadFont(e)}clearWebFonts(){this.webFontRegistry.clearFonts(),this.loadDefaultWebFont()}setActiveWebFont(e){if(!this.webFontRegistry.hasFont(e))throw new Error(`WebFont with ID ${e} does not exist`);this.activeWebFontId=e}getActiveWebFontId(){return this.activeWebFontId}getActiveWebFont(){let e=this.webFontRegistry.getFont(this.activeWebFontId);if(!e)throw new Error(`Active WebFont ${this.activeWebFontId} not found. This should not happen.`);return e}getWebFontCount(){return this.webFontRegistry.getFontCount()}getWebFontIds(){return this.webFontRegistry.getFontIds()}getWebFontRegistry(){return this.webFontRegistry}getBitmapFontRegistry(){return this.bitmapFontRegistry}loadWebFontById(e,t){let r=new L(e,t);this.loadWebFont(r)}loadBitmapFontById(e,t){this.bitmapFontRegistry.loadFont(e,t),this.onBitmapFontChangedCallback&&this.onBitmapFontChangedCallback(e)}getBitmapFont(e){return this.bitmapFontRegistry.getFont(e)??null}hasBitmapFont(e){return this.bitmapFontRegistry.hasFont(e)}unloadBitmapFont(e){return this.bitmapFontRegistry.unloadFont(e)}clearBitmapFonts(){this.bitmapFontRegistry.clearFonts()}getBitmapFontCount(){return this.bitmapFontRegistry.getFontCount()}getBitmapFontIds(){return this.bitmapFontRegistry.getFontIds()}};g(ne,"Core"),m(ne,"ANSI_VGA_COLORS",[{colorId:240,r:16,g:16,b:16,a:255,e:0},{colorId:241,r:128,g:128,b:128,a:255,e:0},{colorId:242,r:192,g:192,b:192,a:255,e:0},{colorId:243,r:240,g:240,b:240,a:255,e:0},{colorId:244,r:200,g:50,b:50,a:255,e:0},{colorId:245,r:50,g:200,b:50,a:255,e:0},{colorId:246,r:220,g:180,b:50,a:255,e:0},{colorId:247,r:50,g:100,b:220,a:255,e:0},{colorId:248,r:50,g:200,b:200,a:255,e:0},{colorId:249,r:200,g:50,b:200,a:255,e:0},{colorId:250,r:220,g:120,b:50,a:255,e:0},{colorId:251,r:120,g:220,b:120,a:255,e:0},{colorId:252,r:120,g:180,b:220,a:255,e:0},{colorId:253,r:220,g:150,b:200,a:255,e:0},{colorId:254,r:250,g:220,b:150,a:255,e:0}]);var ve=ne;var It=require("@utsp/types");var W=new Map([[24,new Uint8Array([0,24,60,126,255,255,0,0])],[25,new Uint8Array([0,0,255,255,126,60,24,0])],[26,new Uint8Array([0,48,120,252,252,120,48,0])],[27,new Uint8Array([0,12,30,63,63,30,12,0])],[32,new Uint8Array([0,0,0,0,0,0,0,0])],[33,new Uint8Array([24,24,24,24,24,0,24,0])],[34,new Uint8Array([108,108,108,0,0,0,0,0])],[35,new Uint8Array([54,54,127,54,127,54,54,0])],[36,new Uint8Array([12,63,104,62,11,126,24,0])],[37,new Uint8Array([96,102,12,24,48,102,6,0])],[38,new Uint8Array([56,108,108,56,109,102,59,0])],[39,new Uint8Array([24,24,24,0,0,0,0,0])],[40,new Uint8Array([12,24,48,48,48,24,12,0])],[41,new Uint8Array([48,24,12,12,12,24,48,0])],[42,new Uint8Array([0,102,60,255,60,102,0,0])],[43,new Uint8Array([0,24,24,126,24,24,0,0])],[44,new Uint8Array([0,0,0,0,0,24,24,48])],[45,new Uint8Array([0,0,0,126,0,0,0,0])],[46,new Uint8Array([0,0,0,0,0,24,24,0])],[47,new Uint8Array([0,6,12,24,48,96,0,0])],[48,new Uint8Array([60,102,110,126,118,102,60,0])],[49,new Uint8Array([24,56,24,24,24,24,126,0])],[50,new Uint8Array([60,102,6,12,24,48,126,0])],[51,new Uint8Array([60,102,6,28,6,102,60,0])],[52,new Uint8Array([12,28,60,108,126,12,12,0])],[53,new Uint8Array([126,96,124,6,6,102,60,0])],[54,new Uint8Array([28,48,96,124,102,102,60,0])],[55,new Uint8Array([126,6,12,24,48,48,48,0])],[56,new Uint8Array([60,102,102,60,102,102,60,0])],[57,new Uint8Array([60,102,102,62,6,12,56,0])],[58,new Uint8Array([0,0,24,24,0,24,24,0])],[59,new Uint8Array([0,0,24,24,0,24,24,48])],[60,new Uint8Array([12,24,48,96,48,24,12,0])],[61,new Uint8Array([0,0,126,0,126,0,0,0])],[62,new Uint8Array([48,24,12,6,12,24,48,0])],[63,new Uint8Array([60,102,12,24,24,0,24,0])],[64,new Uint8Array([60,102,110,106,110,96,60,0])],[65,new Uint8Array([60,102,102,126,102,102,102,0])],[66,new Uint8Array([124,102,102,124,102,102,124,0])],[67,new Uint8Array([60,102,96,96,96,102,60,0])],[68,new Uint8Array([120,108,102,102,102,108,120,0])],[69,new Uint8Array([126,96,96,124,96,96,126,0])],[70,new Uint8Array([126,96,96,124,96,96,96,0])],[71,new Uint8Array([60,102,96,110,102,102,60,0])],[72,new Uint8Array([102,102,102,126,102,102,102,0])],[73,new Uint8Array([126,24,24,24,24,24,126,0])],[74,new Uint8Array([62,12,12,12,12,108,56,0])],[75,new Uint8Array([102,108,120,112,120,108,102,0])],[76,new Uint8Array([96,96,96,96,96,96,126,0])],[77,new Uint8Array([99,119,127,107,99,99,99,0])],[78,new Uint8Array([102,102,118,126,110,102,102,0])],[79,new Uint8Array([60,102,102,102,102,102,60,0])],[80,new Uint8Array([124,102,102,124,96,96,96,0])],[81,new Uint8Array([60,102,102,102,106,108,54,0])],[82,new Uint8Array([124,102,102,124,108,102,102,0])],[83,new Uint8Array([60,102,96,60,6,102,60,0])],[84,new Uint8Array([126,24,24,24,24,24,24,0])],[85,new Uint8Array([102,102,102,102,102,102,60,0])],[86,new Uint8Array([102,102,102,102,102,60,24,0])],[87,new Uint8Array([99,99,99,107,127,119,99,0])],[88,new Uint8Array([102,102,60,24,60,102,102,0])],[89,new Uint8Array([102,102,102,60,24,24,24,0])],[90,new Uint8Array([126,6,12,24,48,96,126,0])],[91,new Uint8Array([60,48,48,48,48,48,60,0])],[92,new Uint8Array([0,96,48,24,12,6,0,0])],[93,new Uint8Array([60,12,12,12,12,12,60,0])],[94,new Uint8Array([24,60,102,0,0,0,0,0])],[95,new Uint8Array([0,0,0,0,0,0,255,0])],[96,new Uint8Array([48,24,12,0,0,0,0,0])],[97,new Uint8Array([0,0,60,6,62,102,62,0])],[98,new Uint8Array([96,96,124,102,102,102,124,0])],[99,new Uint8Array([0,0,60,102,96,102,60,0])],[100,new Uint8Array([6,6,62,102,102,102,62,0])],[101,new Uint8Array([0,0,60,102,126,96,60,0])],[102,new Uint8Array([28,54,48,124,48,48,48,0])],[103,new Uint8Array([0,0,62,102,102,62,6,60])],[104,new Uint8Array([96,96,124,102,102,102,102,0])],[105,new Uint8Array([24,0,56,24,24,24,60,0])],[106,new Uint8Array([12,0,28,12,12,12,108,56])],[107,new Uint8Array([96,96,102,108,120,108,102,0])],[108,new Uint8Array([56,24,24,24,24,24,60,0])],[109,new Uint8Array([0,0,102,127,107,107,99,0])],[110,new Uint8Array([0,0,124,102,102,102,102,0])],[111,new Uint8Array([0,0,60,102,102,102,60,0])],[112,new Uint8Array([0,0,124,102,102,124,96,96])],[113,new Uint8Array([0,0,62,102,102,62,6,6])],[114,new Uint8Array([0,0,108,118,96,96,96,0])],[115,new Uint8Array([0,0,62,96,60,6,124,0])],[116,new Uint8Array([48,48,124,48,48,54,28,0])],[117,new Uint8Array([0,0,102,102,102,102,62,0])],[118,new Uint8Array([0,0,102,102,102,60,24,0])],[119,new Uint8Array([0,0,99,107,107,127,54,0])],[120,new Uint8Array([0,0,102,60,24,60,102,0])],[121,new Uint8Array([0,0,102,102,102,62,6,60])],[122,new Uint8Array([0,0,126,12,24,48,126,0])],[123,new Uint8Array([14,24,24,112,24,24,14,0])],[124,new Uint8Array([24,24,24,24,24,24,24,0])],[125,new Uint8Array([112,24,24,14,24,24,112,0])],[126,new Uint8Array([49,107,70,0,0,0,0,0])],[179,new Uint8Array([24,24,24,24,24,24,24,24])],[196,new Uint8Array([0,0,0,255,0,0,0,0])],[218,new Uint8Array([0,0,0,31,24,24,24,24])],[191,new Uint8Array([0,0,0,248,24,24,24,24])],[192,new Uint8Array([24,24,24,31,0,0,0,0])],[217,new Uint8Array([24,24,24,248,0,0,0,0])],[195,new Uint8Array([24,24,24,31,24,24,24,24])],[180,new Uint8Array([24,24,24,248,24,24,24,24])],[194,new Uint8Array([0,0,0,255,24,24,24,24])],[193,new Uint8Array([24,24,24,255,0,0,0,0])],[197,new Uint8Array([24,24,24,255,24,24,24,24])],[186,new Uint8Array([54,54,54,54,54,54,54,54])],[205,new Uint8Array([0,0,0,255,0,255,0,0])],[201,new Uint8Array([0,0,0,63,54,54,54,54])],[187,new Uint8Array([0,0,0,252,54,54,54,54])],[200,new Uint8Array([54,54,54,63,0,0,0,0])],[188,new Uint8Array([54,54,54,252,0,0,0,0])],[204,new Uint8Array([54,54,54,63,54,54,54,54])],[185,new Uint8Array([54,54,54,252,54,54,54,54])],[203,new Uint8Array([0,0,0,255,54,54,54,54])],[202,new Uint8Array([54,54,54,255,0,0,0,0])],[206,new Uint8Array([54,54,54,255,54,54,54,54])],[219,new Uint8Array([255,255,255,255,255,255,255,255])],[178,new Uint8Array([170,85,170,85,170,85,170,85])],[177,new Uint8Array([136,34,136,34,136,34,136,34])],[176,new Uint8Array([34,136,34,136,34,136,34,136])],[223,new Uint8Array([255,255,255,255,0,0,0,0])],[220,new Uint8Array([0,0,0,0,255,255,255,255])],[221,new Uint8Array([240,240,240,240,240,240,240,240])],[222,new Uint8Array([15,15,15,15,15,15,15,15])]]);function ht(x){return W.get(x)}g(ht,"getCharBitmap");function mt(x){return W.has(x)}g(mt,"hasChar");function xt(){return Array.from(W.keys()).sort((x,e)=>x-e)}g(xt,"getAllCharCodes");function Ct(x){let e=Array.from(W.entries()).map(([t,r])=>({charCode:t,bitmap:r}));return{loadType:4,fontId:x,width:8,height:8,cellWidth:8,cellHeight:8,characters:e}}g(Ct,"createASCII8x8FontLoad");function gt(){return{charWidth:8,charHeight:8,glyphs:new Map(W)}}g(gt,"getASCII8x8FontConfig");function bt(x,e,t,r,n,o,s,i=[]){let a=Array.from(e.entries()).sort((O,w)=>O[0]-w[0]),d=Array.from(t.entries()).sort((O,w)=>O[0]-w[0]),l=a.length,c=d.length,u=Ce(l,c),p=new TextEncoder,h=i.map(O=>p.encode(O)),C=1+h.reduce((O,w)=>O+1+w.length,0),y=u+C,f=new Uint8Array(y),U=new DataView(f.buffer),b=0;U.setBigUint64(b,x,!0),b+=8;for(let[,O]of a){let w=me(O);f[b]=w+256&255,b+=1}let v=P(c);for(let O=0;O<v;O++){let w=0;for(let z=0;z<8;z++){let ue=O*8+z;if(ue<c){let[,S]=d[ue];S&&(w|=1<<z)}}f[b]=w,b+=1}f[b]=r&255,b+=1,f[b]=n&255,b+=1,f[b]=o&255,b+=1;let B=0;s&&(B|=1),f[b]=B,b+=1,f[b]=Math.min(i.length,255),b+=1;for(let O of h)f[b]=Math.min(O.length,255),b+=1,f.set(O.slice(0,255),b),b+=O.length;return f}g(bt,"encodeCompressedInput");var A=class A{static toCharCode(e){if(typeof e=="number")return e&255;let t=e.charCodeAt(0);return ae(t)}static dedent(e){let t=e.split(`
8
- `);if(t.length>0&&t[0].trim()===""&&t.shift(),t.length>0&&t[t.length-1].trim()===""&&t.pop(),t.length===0)return"";let r=t.filter(o=>o.trim().length>0);if(r.length===0)return"";let n=Math.min(...r.map(o=>{let s=o.match(/^(\s*)/);return s?s[1].length:0}));return t.map(o=>o.slice(n)).join(`
9
- `)}static char(e,t,r,n=15,o=0){return{type:1,posX:e,posY:t,charCode:A.toCharCode(r),bgColorCode:o,fgColorCode:n}}static text(e,t,r,n=15,o=0){return{type:2,posX:e,posY:t,text:r,bgColorCode:o,fgColorCode:n}}static textMultiline(e,t,r,n=15,o=0){return{type:23,posX:e,posY:t,text:A.dedent(r),bgColorCode:o,fgColorCode:n}}static subFrame(e,t,r,n,o,s=15,i=0){return{type:3,posX:e,posY:t,sizeX:r,sizeY:n,frame:o.map(a=>A.toCharCode(a)),bgColorCode:i,fgColorCode:s}}static subFrameMultiColor(e,t,r,n,o){return{type:4,posX:e,posY:t,sizeX:r,sizeY:n,frame:o.map(s=>({charCode:A.toCharCode(s.charCode),bgColorCode:s.bgColorCode,fgColorCode:s.fgColorCode}))}}static fullFrame(e,t=15,r=0){return{type:5,frame:e.map(n=>A.toCharCode(n)),bgColorCode:r,fgColorCode:t}}static fullFrameMultiColor(e){return{type:6,frame:e.map(t=>({charCode:A.toCharCode(t.charCode),bgColorCode:t.bgColorCode,fgColorCode:t.fgColorCode}))}}static sprite(e,t,r,n=15,o=0){return{type:7,posX:e,posY:t,spriteIndex:r,bgColorCode:o,fgColorCode:n}}static spriteMultiColor(e,t,r){return{type:8,posX:e,posY:t,spriteIndex:r}}static colorMap(e,t,r,n,o){return{type:9,posX:e,posY:t,sizeX:r,sizeY:n,colorData:o}}static rectangle(e,t,r,n,o={}){return{type:10,shapeType:1,shapeData:{posX:e,posY:t,width:r,height:n,filled:o.filled??!0,charCode:A.toCharCode(o.charCode??9608),bgColorCode:o.bgColor??0,fgColorCode:o.fgColor??15}}}static circle(e,t,r,n={}){return{type:10,shapeType:2,shapeData:{centerX:e,centerY:t,radius:r,filled:n.filled??!0,charCode:A.toCharCode(n.charCode??9608),bgColorCode:n.bgColor??0,fgColorCode:n.fgColor??15}}}static line(e,t,r,n,o={}){return{type:10,shapeType:3,shapeData:{x1:e,y1:t,x2:r,y2:n,charCode:A.toCharCode(o.charCode??9608),bgColorCode:o.bgColor??0,fgColorCode:o.fgColor??15}}}static ellipse(e,t,r,n,o={}){return{type:10,shapeType:4,shapeData:{centerX:e,centerY:t,radiusX:r,radiusY:n,filled:o.filled??!0,charCode:A.toCharCode(o.charCode??9608),bgColorCode:o.bgColor??0,fgColorCode:o.fgColor??15}}}static triangle(e,t,r,n,o,s,i={}){return{type:10,shapeType:5,shapeData:{x1:e,y1:t,x2:r,y2:n,x3:o,y3:s,filled:i.filled??!0,charCode:A.toCharCode(i.charCode??9608),bgColorCode:i.bgColor??0,fgColorCode:i.fgColor??15}}}static dotCloud(e,t,r=15,n=0){return{type:11,charCode:A.toCharCode(t),bgColorCode:n,fgColorCode:r,positions:e}}static dotCloudMultiColor(e){return{type:12,dots:e.map(t=>({...t,charCode:A.toCharCode(t.charCode)}))}}static bitmask(e,t,r,n,o,s,i=15,a=0,d=!1){let l=r*n,c=Math.ceil(l/8),u=new Uint8Array(c);for(let p=0;p<l;p++)if(o[p]){let h=Math.floor(p/8),C=p%8;u[h]|=1<<C}return{type:17,posX:e,posY:t,sizeX:r,sizeY:n,charCode:A.toCharCode(s),bgColorCode:a,fgColorCode:i,override:d,mask:u}}static bitmask4(e,t,r,n,o,s,i=!1){let a={char:"?",fgColor:15,bgColor:0},d=[s[0]??a,s[1]??a,s[2]??a],l=r*n,c=Math.ceil(l/4),u=new Uint8Array(c);for(let p=0;p<l;p++){let h=o[p]&3,C=Math.floor(p/4),y=p%4*2;u[C]|=h<<y}return{type:18,posX:e,posY:t,sizeX:r,sizeY:n,override:i,variants:[{charCode:A.toCharCode(d[0].char),fgColorCode:d[0].fgColor,bgColorCode:d[0].bgColor},{charCode:A.toCharCode(d[1].char),fgColorCode:d[1].fgColor,bgColorCode:d[1].bgColor},{charCode:A.toCharCode(d[2].char),fgColorCode:d[2].fgColor,bgColorCode:d[2].bgColor}],mask:u}}static bitmask16(e,t,r,n,o,s,i=!1){let a={char:"?",fgColor:15,bgColor:0},d=[];for(let p=0;p<15;p++)d.push(s[p]??a);let l=r*n,c=Math.ceil(l/2),u=new Uint8Array(c);for(let p=0;p<l;p++){let h=o[p]&15,C=Math.floor(p/2),y=p%2*4;u[C]|=h<<y}return{type:24,posX:e,posY:t,sizeX:r,sizeY:n,override:i,variants:d.map(p=>({charCode:A.toCharCode(p.char),fgColorCode:p.fgColor,bgColorCode:p.bgColor})),mask:u}}static spriteCloud(e,t,r=15,n=0){return{type:13,spriteIndex:e,bgColorCode:n,fgColorCode:r,positions:t}}static spriteCloudMultiColor(e,t){return{type:14,spriteIndex:e,positions:t}}static spriteCloudVaried(e){return{type:15,sprites:e}}static spriteCloudVariedMultiColor(e){return{type:16,sprites:e}}static clear(e=32,t=15,r=0){return{type:19,charCode:A.toCharCode(e),bgColorCode:r,fgColorCode:t}}static fillChar(e,t,r,n=15,o=0){return{type:20,patternWidth:e,patternHeight:t,pattern:r.map(s=>A.toCharCode(s)),bgColorCode:o,fgColorCode:n}}static fillSprite(e,t=15,r=0){return{type:21,spriteIndex:e,bgColorCode:r,fgColorCode:t}}static fillSpriteMultiColor(e){return{type:22,spriteIndex:e}}static boxWithBorder(e,t,r,n,o,s){return[this.rectangle(e+1,t+1,r-2,n-2,{charCode:s.charCode??9608,bgColor:s.bgColor??0,fgColor:s.fgColor??8,filled:!0}),this.rectangle(e,t,r,n,{charCode:o.charCode??9608,bgColor:o.bgColor??0,fgColor:o.fgColor??15,filled:!1})]}static grid(e,t,r,n,o,s,i={}){let a=[];for(let d=0;d<=o;d++)for(let l=0;l<=s;l++)a.push({posX:e+l*r,posY:t+d*n});return this.dotCloud(a,i.charCode??"+",i.fgColor??15,i.bgColor??0)}};g(A,"OrderBuilder");var Ae=A;var nt=(S=>(S[S.Char=1]="Char",S[S.Text=2]="Text",S[S.TextMultiline=23]="TextMultiline",S[S.SubFrame=3]="SubFrame",S[S.SubFrameMultiColor=4]="SubFrameMultiColor",S[S.FullFrame=5]="FullFrame",S[S.FullFrameMultiColor=6]="FullFrameMultiColor",S[S.Sprite=7]="Sprite",S[S.SpriteMultiColor=8]="SpriteMultiColor",S[S.ColorMap=9]="ColorMap",S[S.Shape=10]="Shape",S[S.DotCloud=11]="DotCloud",S[S.DotCloudMultiColor=12]="DotCloudMultiColor",S[S.SpriteCloud=13]="SpriteCloud",S[S.SpriteCloudMultiColor=14]="SpriteCloudMultiColor",S[S.SpriteCloudVaried=15]="SpriteCloudVaried",S[S.SpriteCloudVariedMultiColor=16]="SpriteCloudVariedMultiColor",S[S.Bitmask=17]="Bitmask",S[S.Bitmask4=18]="Bitmask4",S[S.Bitmask16=24]="Bitmask16",S[S.Clear=19]="Clear",S[S.FillChar=20]="FillChar",S[S.FillSprite=21]="FillSprite",S[S.FillSpriteMultiColor=22]="FillSpriteMultiColor",S[S.TriggerSound=32]="TriggerSound",S[S.TriggerGlobalSound=33]="TriggerGlobalSound",S))(nt||{});function yt(x){return x>=1&&x<=2||x>=3&&x<=6||x>=7&&x<=8||x>=9&&x<=10||x>=11&&x<=18||x>=19&&x<=23||x===24||x>=32&&x<=33}g(yt,"isValidOrderType");function St(x){switch(x){case 1:return"Char";case 2:return"Text";case 3:return"SubFrame";case 4:return"SubFrameMultiColor";case 5:return"FullFrame";case 6:return"FullFrameMultiColor";case 7:return"Sprite";case 8:return"SpriteMultiColor";case 9:return"ColorMap";case 10:return"Shape";case 11:return"DotCloud";case 12:return"DotCloudMultiColor";case 13:return"SpriteCloud";case 14:return"SpriteCloudMultiColor";case 15:return"SpriteCloudVaried";case 16:return"SpriteCloudVariedMultiColor";case 17:return"Bitmask";case 18:return"Bitmask4";case 24:return"Bitmask16";case 19:return"Clear";case 20:return"FillChar";case 21:return"FillSprite";case 22:return"FillSpriteMultiColor";case 32:return"TriggerSound";case 33:return"TriggerGlobalSound";default:return`Unknown(0x${x.toString(16)})`}}g(St,"getOrderTypeName");D();it();var ot=(u=>(u[u.LayerEnabled=1]="LayerEnabled",u[u.SetMode=2]="SetMode",u[u.UpdatePosition=4]="UpdatePosition",u[u.UpdateZOrder=8]="UpdateZOrder",u[u.Disabled=0]="Disabled",u[u.EnabledAddMode=1]="EnabledAddMode",u[u.EnabledSetMode=3]="EnabledSetMode",u[u.EnabledAddMoveOnly=5]="EnabledAddMoveOnly",u[u.EnabledSetMoveOnly=7]="EnabledSetMoveOnly",u[u.EnabledAddReorderOnly=9]="EnabledAddReorderOnly",u[u.EnabledSetReorderOnly=11]="EnabledSetReorderOnly",u[u.FullUpdate=15]="FullUpdate",u))(ot||{}),Be;(l=>{function x(c,u){return(c&u)!==0}l.hasFlag=x,g(x,"hasFlag");function e(c,u){return c|u}l.addFlag=e,g(e,"addFlag");function t(c,u){return c&~u}l.removeFlag=t,g(t,"removeFlag");function r(...c){return c.reduce((u,p)=>u|p,0)}l.combine=r,g(r,"combine");function n(c){return(c&240)===0}l.isValid=n,g(n,"isValid");function o(c){return x(c,1)}l.isEnabled=o,g(o,"isEnabled");function s(c){return x(c,2)}l.isSetMode=s,g(s,"isSetMode");function i(c){return x(c,4)}l.hasPositionChanged=i,g(i,"hasPositionChanged");function a(c){return x(c,8)}l.hasZOrderChanged=a,g(a,"hasZOrderChanged");function d(c){if(c===0)return"Disabled";let u=[];return x(c,1)?u.push("Enabled"):u.push("Disabled"),x(c,2)?u.push("SET"):u.push("ADD"),x(c,4)&&u.push("Position"),x(c,8)&&u.push("ZOrder"),u.join(" | ")}l.describe=d,g(d,"describe")})(Be||(Be={}));Je();
7
+ `}),e}};C(Ye,"InputBindingRegistry");var V=Ye;function xe(g=0n){return{tick:g,axes:new Map,buttons:new Map,displayId:0,mouseX:0,mouseY:0,mouseOverDisplay:!1,textInputs:[]}}C(xe,"createEmptyCompressedInputPacket");function ge(g){let e=Math.max(-1,Math.min(1,g));return Math.round(e*127)}C(ge,"encodeAxisToInt8");function Ce(g){return g/127}C(Ce,"decodeInt8ToAxis");function Y(g){return g===0?0:Math.ceil(g/8)}C(Y,"getButtonByteCount");function be(g,e){let r=g,n=Y(e);return 8+r+n+4}C(be,"getCompressedPacketSize");function ye(g,e){let t=e.getAllAxes().length,r=e.getAllButtons().length,n=Y(r),o=8+t+n+4;if(g.length<o)throw new Error(`Invalid compressed input packet: expected at least ${o} bytes (${t} axes + ${r} buttons), got ${g.length}`);let i=new DataView(g.buffer,g.byteOffset,g.byteLength),s=0,a=xe();a.tick=i.getBigUint64(s,!0),s+=8;for(let u=0;u<t;u++){let c=g[s],l=c>127?c-256:c,p=Ce(l);a.axes.set(u,p),s+=1}for(let u=0;u<n;u++){let c=g[s];for(let l=0;l<8;l++){let p=u*8+l;if(p<r){let h=(c&1<<l)!==0;a.buttons.set(p,h)}}s+=1}a.displayId=g[s],s+=1,a.mouseX=g[s],s+=1,a.mouseY=g[s],s+=1;let d=g[s];if(a.mouseOverDisplay=(d&1)!==0,s+=1,s<g.length){let u=g[s];s+=1;let c=new TextDecoder;a.textInputs=[];for(let l=0;l<u&&s<g.length;l++){let p=g[s];if(s+=1,s+p<=g.length){let h=g.slice(s,s+p),m=c.decode(h);a.textInputs.push(m),s+=p}}}return a}C(ye,"decodeCompressedInput");var le=require("@utsp/types");var _e=class _e{constructor(e,t){x(this,"enabled",!1);x(this,"currentStats",null);x(this,"_userId");x(this,"_userName");this._userId=e,this._userName=t}setEnabled(e){this.enabled=e,e||(this.currentStats=null)}isEnabled(){return this.enabled}get userId(){return this.currentStats?.userId??this._userId}get userName(){return this.currentStats?.userName??this._userName}get tick(){return this.currentStats?.tick??0}get timestamp(){return this.currentStats?.timestamp??0}get displayCount(){return this.currentStats?.displayCount??0}get totalDisplayArea(){return this.currentStats?.totalDisplayArea??0}get totalLayers(){return this.currentStats?.totalLayers??0}get visibleLayers(){return this.currentStats?.visibleLayers??0}get staticLayers(){return this.currentStats?.staticLayers??0}get dynamicLayers(){return this.currentStats?.dynamicLayers??0}get totalOrders(){return this.currentStats?.totalOrders??0}get ordersByLayer(){return this.currentStats?.ordersByLayer??new Map}get staticPacketSize(){return this.currentStats?.staticPacketSize??0}get dynamicPacketSize(){return this.currentStats?.dynamicPacketSize??0}get totalPacketSize(){return this.currentStats?.totalPacketSize??0}get compressedPacketSize(){return Math.round(this.totalPacketSize*.25)}get hasInput(){return this.currentStats?.hasInput??!1}get axisCount(){return this.currentStats?.axisCount??0}get buttonCount(){return this.currentStats?.buttonCount??0}startTick(e){this.enabled&&(this.currentStats={userId:this._userId,userName:this._userName,tick:e,timestamp:Date.now(),displayCount:0,totalDisplayArea:0,totalLayers:0,visibleLayers:0,staticLayers:0,dynamicLayers:0,totalOrders:0,ordersByLayer:new Map,staticPacketSize:0,dynamicPacketSize:0,totalPacketSize:0,hasInput:!1,axisCount:0,buttonCount:0})}recordDisplays(e,t){!this.enabled||!this.currentStats||(this.currentStats.displayCount=e,this.currentStats.totalDisplayArea=t)}recordLayers(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.totalLayers=e,this.currentStats.visibleLayers=t,this.currentStats.staticLayers=r,this.currentStats.dynamicLayers=n)}recordLayerOrders(e,t){!this.enabled||!this.currentStats||(this.currentStats.totalOrders+=t,this.currentStats.ordersByLayer.set(e,t))}recordPacketSizes(e,t){!this.enabled||!this.currentStats||(this.currentStats.staticPacketSize=e,this.currentStats.dynamicPacketSize=t,this.currentStats.totalPacketSize=e+t)}recordInput(e,t,r){!this.enabled||!this.currentStats||(this.currentStats.hasInput=e,this.currentStats.axisCount=t,this.currentStats.buttonCount=r)}endTick(){}reset(){this.currentStats=null}};C(_e,"UserStats");var Z=_e;var Ve=class Ve{constructor(e,t,r){this.id=e;this.name=t;x(this,"displays",[]);x(this,"layers",[]);x(this,"spriteRegistry");x(this,"mode");x(this,"axes",new Map);x(this,"buttons",new Map);x(this,"textInputs",[]);x(this,"mouseX",0);x(this,"mouseY",0);x(this,"mouseOver",!1);x(this,"mouseDisplayId",0);x(this,"touchPositions",new Map);x(this,"activeTouchId",null);x(this,"inputBindings",new V);x(this,"stats");x(this,"soundCommands",[]);x(this,"nextSoundInstanceId",1);x(this,"audioConfigCommands",[]);x(this,"lastListenerX",-1);x(this,"lastListenerY",-1);x(this,"pendingSendSounds",!1);x(this,"audioProcessor");x(this,"loadedSounds",new Map);x(this,"soundLoadErrors",new Map);x(this,"playingSounds",new Map);x(this,"data");this.mode=r,this.stats=new Z(e,t),this.data={}}setSpriteRegistry(e){this.spriteRegistry=e;for(let t of this.layers)t.setSpriteRegistry(e)}getDisplays(){return this.displays}addDisplay(e){this.displays.push(e)}removeDisplay(e){let t=this.displays.indexOf(e);return t!==-1?(this.displays.splice(t,1),!0):!1}clearDisplays(){this.displays=[]}getLayers(){return this.layers}addLayer(e){e.setMode(this.mode),this.layers.push(e),this.spriteRegistry&&e.setSpriteRegistry(this.spriteRegistry)}removeLayer(e){let t=this.layers.indexOf(e);return t!==-1?(this.layers.splice(t,1),!0):!1}clearLayers(){this.layers=[]}setMousePosition(e,t,r=!0){this.mouseX=Math.max(0,Math.min(255,e)),this.mouseY=Math.max(0,Math.min(255,t)),this.mouseOver=r}setTouchPosition(e,t,r,n=!0,o=0){if(e<0||e>9){console.warn(`Invalid touchId ${e}, must be 0-9`);return}n?(this.touchPositions.set(e,{x:Math.max(0,Math.min(255,t)),y:Math.max(0,Math.min(255,r)),over:!0,displayId:o}),this.activeTouchId=e):(this.touchPositions.delete(e),this.activeTouchId===e&&(this.activeTouchId=null))}setAxis(e,t){let r=Math.max(-1,Math.min(1,t));this.axes.set(e,r)}getAxis(e){return this.axes.get(e)??0}setButton(e,t){this.buttons.set(e,t)}getButton(e){return this.buttons.get(e)??!1}getButtonJustPressed(e){let t=`${e}_justPressed`;return this.buttons.get(t)??!1}getButtonJustReleased(e){let t=`${e}_justReleased`;return this.buttons.get(t)??!1}setTextInputs(e){this.textInputs=e}getTextInputs(){return this.textInputs}clearTextInputs(){this.textInputs=[]}getAxisNames(){return Array.from(this.axes.keys())}getButtonNames(){return Array.from(this.buttons.keys())}clearAxes(){this.axes.clear()}clearButtons(){this.buttons.clear()}getMouseDisplayInfo(){if(!this.mouseOver||this.displays.length===0)return null;let e=this.displays[0],t=0,r=this.mouseX,n=this.mouseY,o=e.getOrigin(),i=o.x+r,s=o.y+n;return{displayId:t,localX:r,localY:n,worldX:i,worldY:s}}getTouchDisplayInfo(e=0){if(e<0||e>9)return console.warn(`Invalid touchId ${e}, must be 0-9`),null;let t=this.touchPositions.get(e);if(!t||!t.over||this.displays.length===0)return null;let r=this.displays[0],n=t.displayId,o=t.x,i=t.y,s=r.getOrigin(),a=s.x+o,d=s.y+i;return{displayId:n,localX:o,localY:i,worldX:a,worldY:d}}getIsMouseOnADisplay(){return this.mouseOver}getMouseDisplayHover(){let e=this.getMouseDisplayInfo();return e?e.displayId:null}findLayerById(e){return this.layers.find(t=>t.getId()===e)??null}applyUpdate(e){this.updateDisplaysFromPacket(e.displays),this.updateLayersFromPacket(e.layers)}updateDisplaysFromPacket(e){for(let t of e){let r=this.displays[t.id];if(!r){for(r=new N(t.id,t.sizeX,t.sizeY);this.displays.length<=t.id;)this.displays.push(null);this.displays[t.id]=r}r.setOrigin(new le.Vector2(t.originX,t.originY)),r.setSize(new le.Vector2(t.sizeX,t.sizeY))}}updateLayersFromPacket(e){for(let t of e){let r=this.findLayerById(t.id);r||(r=new $(new le.Vector2(t.originX,t.originY),t.zIndex,t.width,t.height,!1),r.setId(t.id),r.setMode(this.mode),this.spriteRegistry&&r.setSpriteRegistry(this.spriteRegistry),this.addLayer(r)),t.updateFlags&1&&r.setOrigin(new le.Vector2(t.originX,t.originY)),t.updateFlags&2&&r.setZOrder(t.zIndex),t.updateFlags&4&&r.setOrders(t.orders)}}defineAxisBinding(e,t,r=[],n=-1,o=1,i=0){this.inputBindings.defineAxis(e,t,r,n,o,i)}defineButtonBinding(e,t,r=[],n=!1){this.inputBindings.defineButton(e,t,r,n)}defineAxisBindings(e){e.forEach(({bindingId:t,name:r,sources:n,min:o,max:i,defaultValue:s})=>{this.defineAxisBinding(t,r,n??[],o,i,s)})}defineButtonBindings(e){e.forEach(({bindingId:t,name:r,sources:n,defaultValue:o})=>{this.defineButtonBinding(t,r,n??[],o)})}getInputBindingsLoadPacket(){return this.inputBindings.toLoadPacket()}applyInputBindingsLoadPacket(e){try{let t=JSON.parse(e);if(t.type!=="input-binding")throw new Error(`Invalid packet type: ${t.type}`);for(let r of t.axes)this.defineAxisBinding(r.bindingId,r.name,r.sources||[],r.min,r.max,r.defaultValue);for(let r of t.buttons)this.defineButtonBinding(r.bindingId,r.name,r.sources||[],r.defaultValue)}catch(t){throw console.error("[User] Failed to apply input bindings:",t),t}}getInputBindingRegistry(){return this.inputBindings}getStats(){return this.stats}getAxisBindingId(e){return this.inputBindings.getAxisBindingId(e)}getButtonBindingId(e){return this.inputBindings.getButtonBindingId(e)}decodeAndApplyCompressedInput(e){let t=ye(e,this.inputBindings),r=this.inputBindings.getAllAxes(),n=this.inputBindings.getAllButtons(),o=r.sort((s,a)=>s.bindingId-a.bindingId),i=n.sort((s,a)=>s.bindingId-a.bindingId);for(let[s,a]of t.axes)if(s<o.length){let d=o[s];this.setAxis(d.name,a)}for(let[s,a]of t.buttons)if(s<i.length){let d=i[s];this.setButton(d.name,a)}this.mouseX=t.mouseX,this.mouseY=t.mouseY,this.mouseOver=t.mouseOverDisplay,this.mouseDisplayId=t.displayId}playSound(e,t){let r=this.nextSoundInstanceId++,n={sound:e,instanceId:r,volume:t?.volume,pitch:t?.pitch,loop:t?.loop,fadeIn:t?.fadeIn,x:t?.x,y:t?.y,lowpass:t?.lowpass,highpass:t?.highpass,reverb:t?.reverb};return this.soundCommands.push(n),r}stopSound(e){let t={sound:e};this.soundCommands.push(t)}fadeOutSound(e,t){let r={fadeOut:!0,sound:e,duration:t};this.soundCommands.push(r)}fadeOutAllSounds(e){let t={fadeOut:!0,sound:"all",duration:e};this.soundCommands.push(t)}stopAllSounds(){let e={sound:"all"};this.soundCommands.push(e)}pauseSound(e){let t={pause:!0,sound:e};this.soundCommands.push(t)}pauseAllSounds(){let e={pause:!0,sound:"all"};this.soundCommands.push(e)}resumeSound(e){let t={resume:!0,sound:e};this.soundCommands.push(t)}resumeAllSounds(){let e={resume:!0,sound:"all"};this.soundCommands.push(e)}setSoundEffects(e,t){let r={setEffects:!0,instanceId:e,lowpass:t.lowpass,highpass:t.highpass,reverb:t.reverb};this.soundCommands.push(r)}setListenerPosition(e,t){e===this.lastListenerX&&t===this.lastListenerY||(this.lastListenerX=e,this.lastListenerY=t,this.audioConfigCommands.push({type:"set-listener-position",x:e,y:t}))}configureSpatialAudio(e){this.audioConfigCommands.push({type:"configure-spatial",...e})}flushAudioConfigCommands(){let e=this.audioConfigCommands;return this.audioConfigCommands=[],e}hasAudioConfigCommands(){return this.audioConfigCommands.length>0}flushSoundCommands(){let e=this.soundCommands;return this.soundCommands=[],e}hasSoundCommands(){return this.soundCommands.length>0}sendSounds(){this.pendingSendSounds=!0}needsSendSounds(){return this.pendingSendSounds}clearSendSounds(){this.pendingSendSounds=!1}setAudioProcessor(e){this.audioProcessor=e}getAudioProcessor(){return this.audioProcessor}applyAudioCommands(e){if(this.audioProcessor&&this.mode!=="server")for(let t of e){if("setEffects"in t&&t.setEffects===!0){let n=t;this.audioProcessor.setEffects(n.instanceId,n.lowpass,n.highpass,n.reverb);continue}if("fadeOut"in t&&t.fadeOut===!0){let n=t;this.audioProcessor.fadeOut(n.sound,n.duration);continue}if("pause"in t&&t.pause===!0){let n=t;this.audioProcessor.pause(n.sound);continue}if("resume"in t&&t.resume===!0){let n=t;this.audioProcessor.resume(n.sound);continue}if("instanceId"in t||"volume"in t||"pitch"in t||"loop"in t||"fadeIn"in t||"x"in t||"y"in t||"lowpass"in t||"highpass"in t||"reverb"in t){let n=t,o=n.x!==void 0&&n.y!==void 0?{x:n.x,y:n.y}:void 0;this.audioProcessor.play(n.sound,{volume:n.volume,pitch:n.pitch,loop:n.loop,fadeIn:n.fadeIn,position:o,instanceId:n.instanceId,lowpass:n.lowpass,highpass:n.highpass,reverb:n.reverb})}else{let n=t;n.sound==="all"?this.audioProcessor.stopAll():this.audioProcessor.stop(n.sound)}}}applyAudioConfigCommands(e){if(this.audioProcessor&&this.mode!=="server")for(let t of e)t.type==="set-listener-position"?this.audioProcessor.setListenerPosition(t.x,t.y):t.type==="configure-spatial"&&this.audioProcessor.configureSpatial({maxDistance:t.maxDistance,referenceDistance:t.referenceDistance,rolloffFactor:t.rolloffFactor,panSpread:t.panSpread})}applyAudioOrders(e){if(!this.audioProcessor||this.mode==="server")return;let{AudioOrderType:t,AudioTargetType:r}=(We(),z(Ut)),{PlaySoundFlags:n}=($e(),z(wt));for(let o of e)switch(o.type){case t.PlaySound:case t.PlayGlobalSound:{let i=o,s=i.volume!==void 0?i.volume/255:void 0,a=i.pitch!==void 0?.25*Math.pow(2,i.pitch/64):void 0,d=i.fadeIn!==void 0?i.fadeIn/10:void 0,u=(i.flags&n.Loop)!==0,c=i.posX!==void 0&&i.posY!==void 0?{x:i.posX,y:i.posY}:void 0;this.audioProcessor.play(i.soundId,{volume:s,pitch:a,loop:u,fadeIn:d,position:c,instanceId:i.instanceId,lowpass:i.lowpass,highpass:i.highpass,reverb:i.reverb});break}case t.StopSound:{let i=o;i.targetType===r.All?this.audioProcessor.stopAll():i.targetType===r.InstanceId?this.audioProcessor.stop(i.target):this.audioProcessor.stop(i.target);break}case t.FadeOutSound:{let i=o,s=i.duration/10;i.targetType===r.All?this.audioProcessor.fadeOut("all",s):this.audioProcessor.fadeOut(i.target,s);break}case t.PauseSound:{let i=o;i.targetType===r.All?this.audioProcessor.pause("all"):this.audioProcessor.pause(i.target);break}case t.ResumeSound:{let i=o;i.targetType===r.All?this.audioProcessor.resume("all"):this.audioProcessor.resume(i.target);break}case t.SetListenerPosition:{let i=o;this.audioProcessor.setListenerPosition(i.x,i.y);break}case t.ConfigureSpatial:{let i=o;this.audioProcessor.configureSpatial({maxDistance:i.maxDistance*100,referenceDistance:i.referenceDistance*100,rolloffFactor:i.rolloffFactor/100,panSpread:i.panSpread/255});break}case t.SetSoundEffects:{let i=o;this.audioProcessor.setEffects(i.instanceId,i.lowpass,i.highpass,i.reverb);break}}}handleAudioAck(e){switch(e.type){case"sound-loaded":this.loadedSounds.set(e.soundId,{name:e.name,loadedAt:Date.now()}),this.soundLoadErrors.delete(e.soundId);break;case"sound-error":this.soundLoadErrors.set(e.soundId,{name:e.name,error:e.error,at:Date.now()});break;case"playback-started":this.playingSounds.set(e.instanceId,{soundId:e.soundId,startedAt:Date.now()});break;case"playback-ended":this.playingSounds.delete(e.instanceId);break;case"playback-error":e.instanceId!==void 0&&this.playingSounds.delete(e.instanceId);break}}isSoundLoaded(e){return this.loadedSounds.has(e)}getSoundLoadError(e){return this.soundLoadErrors.get(e)?.error}getLoadedSounds(){return this.loadedSounds}getSoundLoadErrors(){return this.soundLoadErrors}isSoundPlaying(e){return this.playingSounds.has(e)}getPlayingSounds(){return this.playingSounds}getPlayingSoundCount(){return this.playingSounds.size}};C(Ve,"User");var G=Ve;L();var Ze=class Ze{encode(e){switch(e.type){case 1:return this.encodeCharOrder(e);case 2:return this.encodeTextOrder(e);case 23:return this.encodeTextMultilineOrder(e);case 3:return this.encodeSubFrameOrder(e);case 4:return this.encodeSubFrameMultiColorOrder(e);case 5:return this.encodeFullFrameOrder(e);case 6:return this.encodeFullFrameMultiColorOrder(e);case 7:return this.encodeSpriteOrder(e);case 8:return this.encodeSpriteMultiColorOrder(e);case 9:return this.encodeColorMapOrder(e);case 10:return this.encodeShapeOrder(e);case 11:return this.encodeDotCloudOrder(e);case 12:return this.encodeDotCloudMultiColorOrder(e);case 17:return this.encodeBitmaskOrder(e);case 18:return this.encodeBitmask4Order(e);case 24:return this.encodeBitmask16Order(e);case 13:return this.encodeSpriteCloudOrder(e);case 14:return this.encodeSpriteCloudMultiColorOrder(e);case 15:return this.encodeSpriteCloudVariedOrder(e);case 16:return this.encodeSpriteCloudVariedMultiColorOrder(e);case 19:return this.encodeClearOrder(e);case 20:return this.encodeFillCharOrder(e);case 21:return this.encodeFillSpriteOrder(e);case 22:return this.encodeFillSpriteMultiColorOrder(e);case 32:return this.encodeTriggerSoundOrder(e);case 33:return this.encodeTriggerGlobalSoundOrder(e);default:throw new Error(`Unknown order type: ${e.type}`)}}encodeCharOrder(e){let t=S.allocUnsafe(6),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.charCode,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeTextOrder(e){let t=new TextEncoder().encode(e.text),r=S.allocUnsafe(6+t.length),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(t.length,n++);for(let o=0;o<t.length;o++)r.writeUInt8(t[o],n++);return r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.toUint8Array()}encodeTextMultilineOrder(e){let t=new TextEncoder().encode(e.text),r=S.allocUnsafe(6+t.length),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(t.length,n++);for(let o=0;o<t.length;o++)r.writeUInt8(t[o],n++);return r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.toUint8Array()}encodeSubFrameOrder(e){let t=e.sizeX*e.sizeY,r=S.allocUnsafe(7+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++);for(let o of e.frame)r.writeUInt8(o,n++);return r.toUint8Array()}encodeSubFrameMultiColorOrder(e){let t=e.sizeX*e.sizeY,r=S.allocUnsafe(5+t*3),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++);for(let o of e.frame)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);return r.toUint8Array()}encodeFullFrameOrder(e){let t=e.frame.length,r=S.allocUnsafe(3+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++);for(let o of e.frame)r.writeUInt8(o,n++);return r.toUint8Array()}encodeFullFrameMultiColorOrder(e){let t=e.frame.length,r=S.allocUnsafe(1+t*3),n=0;r.writeUInt8(e.type,n++);for(let o of e.frame)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);return r.toUint8Array()}encodeSpriteOrder(e){let t=S.allocUnsafe(6),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.spriteIndex,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeSpriteMultiColorOrder(e){let t=S.allocUnsafe(4),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.spriteIndex,r++),t.toUint8Array()}encodeColorMapOrder(e){let t=e.sizeX*e.sizeY,r=S.allocUnsafe(5+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++);for(let o of e.colorData)r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);return r.toUint8Array()}encodeShapeOrder(e){let t=this.encodeShapeData(e.shapeType,e.shapeData),r=S.allocUnsafe(2+t.length),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.shapeType,n++);for(let o=0;o<t.length;o++)r.writeUInt8(t[o],n++);return r.toUint8Array()}encodeShapeData(e,t){switch(e){case 1:{let r=S.allocUnsafe(8),n=0;return r.writeUInt8(t.posX,n++),r.writeUInt8(t.posY,n++),r.writeUInt8(t.width,n++),r.writeUInt8(t.height,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 2:{let r=S.allocUnsafe(7),n=0;return r.writeUInt8(t.centerX,n++),r.writeUInt8(t.centerY,n++),r.writeUInt8(t.radius,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 3:{let r=S.allocUnsafe(7),n=0;return r.writeUInt8(t.x1,n++),r.writeUInt8(t.y1,n++),r.writeUInt8(t.x2,n++),r.writeUInt8(t.y2,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 4:{let r=S.allocUnsafe(8),n=0;return r.writeUInt8(t.centerX,n++),r.writeUInt8(t.centerY,n++),r.writeUInt8(t.radiusX,n++),r.writeUInt8(t.radiusY,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}case 5:{let r=S.allocUnsafe(10),n=0;return r.writeUInt8(t.x1,n++),r.writeUInt8(t.y1,n++),r.writeUInt8(t.x2,n++),r.writeUInt8(t.y2,n++),r.writeUInt8(t.x3,n++),r.writeUInt8(t.y3,n++),r.writeUInt8(t.filled?1:0,n++),r.writeUInt8(t.charCode,n++),r.writeUInt8(t.bgColorCode,n++),r.writeUInt8(t.fgColorCode,n++),r.toUint8Array()}default:throw new Error(`Unknown shape type: ${e}`)}}encodeDotCloudOrder(e){let t=e.positions.length,r=S.allocUnsafe(6+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.charCode,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.positions)r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeDotCloudMultiColorOrder(e){let t=e.dots.length,r=S.allocUnsafe(5+t*5),n=0;r.writeUInt8(e.type,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.dots)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++),r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeBitmaskOrder(e){let t=e.mask.length,r=S.allocUnsafe(9+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.charCode,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.writeUInt8(e.override?1:0,n++);for(let o=0;o<t;o++)r.writeUInt8(e.mask[o],n++);return r.toUint8Array()}encodeBitmask4Order(e){let t=e.mask.length,r=S.allocUnsafe(15+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.override?1:0,n++);for(let o of e.variants)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);for(let o=0;o<t;o++)r.writeUInt8(e.mask[o],n++);return r.toUint8Array()}encodeBitmask16Order(e){let t=e.mask.length,r=S.allocUnsafe(51+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.posX,n++),r.writeUInt8(e.posY,n++),r.writeUInt8(e.sizeX,n++),r.writeUInt8(e.sizeY,n++),r.writeUInt8(e.override?1:0,n++);for(let o of e.variants)r.writeUInt8(o.charCode,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++);for(let o=0;o<t;o++)r.writeUInt8(e.mask[o],n++);return r.toUint8Array()}encodeSpriteCloudOrder(e){let t=e.positions.length,r=S.allocUnsafe(8+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.spriteIndex,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.positions)r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeSpriteCloudMultiColorOrder(e){let t=e.positions.length,r=S.allocUnsafe(6+t*2),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.spriteIndex,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.positions)r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeSpriteCloudVariedOrder(e){let t=e.sprites.length,r=S.allocUnsafe(3+t*5),n=0;r.writeUInt8(e.type,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.sprites)r.writeUInt8(o.spriteIndex,n++),r.writeUInt8(o.bgColorCode,n++),r.writeUInt8(o.fgColorCode,n++),r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeSpriteCloudVariedMultiColorOrder(e){let t=e.sprites.length,r=S.allocUnsafe(3+t*3),n=0;r.writeUInt8(e.type,n++),r.writeUInt16BE(t,n),n+=2;for(let o of e.sprites)r.writeUInt8(o.spriteIndex,n++),r.writeUInt8(o.posX,n++),r.writeUInt8(o.posY,n++);return r.toUint8Array()}encodeClearOrder(e){let t=S.allocUnsafe(4),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.charCode,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeFillCharOrder(e){let t=e.patternWidth*e.patternHeight,r=S.allocUnsafe(5+t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.patternWidth,n++),r.writeUInt8(e.patternHeight,n++),r.writeUInt8(e.bgColorCode,n++),r.writeUInt8(e.fgColorCode,n++);for(let o of e.pattern)r.writeUInt8(o,n++);return r.toUint8Array()}encodeFillSpriteOrder(e){let t=S.allocUnsafe(4),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.spriteIndex,r++),t.writeUInt8(e.bgColorCode,r++),t.writeUInt8(e.fgColorCode,r++),t.toUint8Array()}encodeFillSpriteMultiColorOrder(e){let t=S.allocUnsafe(2),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.spriteIndex,r++),t.toUint8Array()}encodeTriggerSoundOrder(e){let t=S.allocUnsafe(5),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.posX,r++),t.writeUInt8(e.posY,r++),t.writeUInt8(e.soundId,r++),t.writeUInt8(e.loop?1:0,r++),t.toUint8Array()}encodeTriggerGlobalSoundOrder(e){let t=S.allocUnsafe(3),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.soundId,r++),t.writeUInt8(e.loop?1:0,r++),t.toUint8Array()}};C(Ze,"OrderEncoder");var Ue=Ze;L();var Ge=class Ge{constructor(){x(this,"orderEncoder");this.orderEncoder=new Ue}encode(e){let t=e.orders.map(a=>this.orderEncoder.encode(a)),r=13,n=t.reduce((a,d)=>a+d.length,0),o=r+n,i=S.allocUnsafe(o),s=0;i.writeUInt16BE(e.id,s),s+=2,i.writeUInt8(e.updateFlags,s++),i.writeUInt8(e.zIndex,s++),i.writeUInt16BE(e.originX,s),s+=2,i.writeUInt16BE(e.originY,s),s+=2,i.writeUInt16BE(e.width,s),s+=2,i.writeUInt16BE(e.height,s),s+=2,i.writeUInt8(e.orders.length,s++);for(let a of t)S.from(a).copy(i,s),s+=a.length;return i.toUint8Array()}calculateSize(e){return 13+e.orders.reduce((n,o)=>n+this.orderEncoder.encode(o).length,0)}};C(Ge,"LayerEncoder");var Oe=Ge;L();var qe=class qe{encode(e){switch(e.type){case 1:return this.encodePlaySoundOrder(e);case 2:return this.encodePlayGlobalSoundOrder(e);case 3:return this.encodeStopSoundOrder(e);case 4:return this.encodeFadeOutSoundOrder(e);case 5:return this.encodePauseSoundOrder(e);case 6:return this.encodeResumeSoundOrder(e);case 7:return this.encodeSetListenerPositionOrder(e);case 8:return this.encodeConfigureSpatialOrder(e);case 9:return this.encodeSetSoundEffectsOrder(e);default:throw new Error(`Unknown audio order type: ${e.type}`)}}calculateSize(e){switch(e.type){case 1:return this.calculatePlaySoundSize(e);case 2:return this.calculatePlayGlobalSoundSize(e);case 3:case 5:case 6:return this.calculateTargetOrderSize(e);case 4:return this.calculateFadeOutSize(e);case 7:return 5;case 8:return 5;case 9:return this.calculateSetSoundEffectsSize(e);default:throw new Error(`Unknown audio order type: ${e.type}`)}}encodePlaySoundOrder(e){let t=this.calculatePlaySoundSize(e),r=S.allocUnsafe(t),n=0;return r.writeUInt8(e.type,n++),r.writeUInt8(e.soundId,n++),r.writeUInt16BE(e.instanceId,n),n+=2,r.writeUInt8(e.flags,n++),e.flags&2&&r.writeUInt8(e.volume??255,n++),e.flags&4&&r.writeUInt8(e.pitch??128,n++),e.flags&8&&r.writeUInt8(e.fadeIn??0,n++),e.flags&16&&(r.writeUInt16BE(e.posX??0,n),n+=2,r.writeUInt16BE(e.posY??0,n),n+=2),e.flags&32&&r.writeUInt8(e.lowpass??0,n++),e.flags&64&&r.writeUInt8(e.highpass??0,n++),e.flags&128&&r.writeUInt8(e.reverb??0,n++),r.toUint8Array()}encodePlayGlobalSoundOrder(e){let t=this.calculatePlayGlobalSoundSize(e),r=S.allocUnsafe(t),n=0;r.writeUInt8(e.type,n++),r.writeUInt8(e.soundId,n++),r.writeUInt16BE(e.instanceId,n),n+=2;let o=e.flags&-17;return r.writeUInt8(o,n++),o&2&&r.writeUInt8(e.volume??255,n++),o&4&&r.writeUInt8(e.pitch??128,n++),o&8&&r.writeUInt8(e.fadeIn??0,n++),o&32&&r.writeUInt8(e.lowpass??0,n++),o&64&&r.writeUInt8(e.highpass??0,n++),o&128&&r.writeUInt8(e.reverb??0,n++),r.toUint8Array()}calculatePlaySoundSize(e){let t=5;return e.flags&2&&(t+=1),e.flags&4&&(t+=1),e.flags&8&&(t+=1),e.flags&16&&(t+=4),e.flags&32&&(t+=1),e.flags&64&&(t+=1),e.flags&128&&(t+=1),t}calculatePlayGlobalSoundSize(e){let t=5,r=e.flags&-17;return r&2&&(t+=1),r&4&&(t+=1),r&8&&(t+=1),r&32&&(t+=1),r&64&&(t+=1),r&128&&(t+=1),t}encodeStopSoundOrder(e){return this.encodeTargetOrder(e.type,e.targetType,e.target)}encodePauseSoundOrder(e){return this.encodeTargetOrder(e.type,e.targetType,e.target)}encodeResumeSoundOrder(e){return this.encodeTargetOrder(e.type,e.targetType,e.target)}encodeFadeOutSoundOrder(e){let t=this.calculateFadeOutSize(e),r=S.allocUnsafe(t),n=0;return r.writeUInt8(e.type,n++),r.writeUInt8(e.targetType,n++),r.writeUInt8(e.duration,n++),e.targetType===0?r.writeUInt16BE(e.target??0,n):e.targetType===1&&r.writeUInt8(e.target??0,n),r.toUint8Array()}encodeTargetOrder(e,t,r){let n=2;t===0?n+=2:t===1&&(n+=1);let o=S.allocUnsafe(n),i=0;return o.writeUInt8(e,i++),o.writeUInt8(t,i++),t===0?o.writeUInt16BE(r??0,i):t===1&&o.writeUInt8(r??0,i),o.toUint8Array()}calculateTargetOrderSize(e){let t=2;return e.targetType===0?t+=2:e.targetType===1&&(t+=1),t}calculateFadeOutSize(e){let t=3;return e.targetType===0?t+=2:e.targetType===1&&(t+=1),t}encodeSetListenerPositionOrder(e){let t=S.allocUnsafe(5),r=0;return t.writeUInt8(e.type,r++),t.writeUInt16BE(e.x,r),r+=2,t.writeUInt16BE(e.y,r),t.toUint8Array()}encodeConfigureSpatialOrder(e){let t=S.allocUnsafe(5),r=0;return t.writeUInt8(e.type,r++),t.writeUInt8(e.maxDistance,r++),t.writeUInt8(e.referenceDistance,r++),t.writeUInt8(e.rolloffFactor,r++),t.writeUInt8(e.panSpread,r++),t.toUint8Array()}encodeSetSoundEffectsOrder(e){let t=this.calculateSetSoundEffectsSize(e),r=S.allocUnsafe(t),n=0;return r.writeUInt8(e.type,n++),r.writeUInt16BE(e.instanceId,n),n+=2,r.writeUInt8(e.flags,n++),e.flags&1&&r.writeUInt8(e.lowpass??0,n++),e.flags&2&&r.writeUInt8(e.highpass??0,n++),e.flags&4&&r.writeUInt8(e.reverb??0,n++),r.toUint8Array()}calculateSetSoundEffectsSize(e){let t=4;return e.flags&1&&(t+=1),e.flags&2&&(t+=1),e.flags&4&&(t+=1),t}};C(qe,"AudioOrderEncoder");var we=qe;L();var je=class je{constructor(){x(this,"layerEncoder");x(this,"audioOrderEncoder");this.layerEncoder=new Oe,this.audioOrderEncoder=new we}encode(e){let t=e.layers.map(m=>this.layerEncoder.encode(m)),r=e.audioOrders||[],n=r.map(m=>this.audioOrderEncoder.encode(m)),o=9,i=e.displays.length*7,s=2,a=t.reduce((m,b)=>m+b.length,0),d=1,u=n.reduce((m,b)=>m+b.length,0),c=o+i+s+a+d+u,l=S.allocUnsafe(c),p=0,h=typeof e.tick=="bigint"?e.tick:BigInt(e.tick);l.writeBigUInt64BE(h,p),p+=8,l.writeUInt8(e.displays.length,p),p+=1;for(let m of e.displays)l.writeUInt8(m.id,p++),l.writeUInt16BE(m.originX,p),p+=2,l.writeUInt16BE(m.originY,p),p+=2,l.writeUInt8(Math.max(1,Math.min(256,m.sizeX))-1,p++),l.writeUInt8(Math.max(1,Math.min(256,m.sizeY))-1,p++);l.writeUInt16BE(e.layers.length,p),p+=2;for(let m of t)S.from(m).copy(l,p),p+=m.length;l.writeUInt8(r.length,p),p+=1;for(let m of n)S.from(m).copy(l,p),p+=m.length;return l.toUint8Array()}calculateSize(e){let r=e.displays.length*7,n=2,o=e.layers.reduce((d,u)=>d+this.layerEncoder.calculateSize(u),0),i=1,a=(e.audioOrders||[]).reduce((d,u)=>d+this.audioOrderEncoder.calculateSize(u),0);return 9+r+n+o+i+a}static createEmptyPacket(e){return{tick:typeof e=="bigint"?Number(e):e,displayCount:0,displays:[],layerCount:0,layers:[],audioOrderCount:0,audioOrders:[]}}encodeEmpty(e){let t=S.allocUnsafe(12),r=typeof e=="bigint"?e:BigInt(e);return t.writeBigUInt64BE(r,0),t.writeUInt8(0,8),t.writeUInt16BE(0,9),t.writeUInt8(0,11),t.toUint8Array()}};C(je,"UpdatePacketEncoder");var ve=je;var q=class q{constructor(e){this.engine=e;x(this,"colorCache",new Array(256));x(this,"cellsBuffer",[]);x(this,"opacityBuffer",new Uint8Array(0));x(this,"visibleLayersBuffer",[]);this.rebuildColorCache()}rebuildColorCache(){for(let e=0;e<256;e++){let t=this.engine.getColor(e);t?this.colorCache[e]={r:t.r,g:t.g,b:t.b,a:t.a}:this.colorCache[e]={r:0,g:0,b:0,a:0}}}getColorRGB(e){return this.colorCache[e]??this.colorCache[255]}getColorEmission(e){let t=this.engine.getColor(e);return t?t.e:0}isLayerVisible(e,t){let r=e.x,n=e.x+e.width,o=e.y,i=e.y+e.height,s=t.x,a=t.x+256,d=t.y,u=t.y+256;return!(n<=s||r>=a||i<=d||o>=u)}rasterize(e,t){let r=e.width*e.height,n=this.cellsBuffer;n.length=r;for(let s=0;s<r;s++)n[s]?(n[s].char=" ",n[s].fgColorIndex=255,n[s].bgColorIndex=255,n[s].fgEmission=0,n[s].bgEmission=0):n[s]={char:" ",fgColorIndex:255,bgColorIndex:255,fgEmission:0,bgEmission:0};this.opacityBuffer.length<r?this.opacityBuffer=new Uint8Array(r):this.opacityBuffer.fill(0,0,r);let o=this.opacityBuffer,i=this.visibleLayersBuffer;i.length=0;for(let s=0;s<t.length;s++){let a=t[s];a.isEnabled()&&this.isLayerVisible(e,a.getOrigin())&&i.push(a)}i.sort((s,a)=>a.getZOrder()-s.getZOrder());for(let s=0;s<e.height;s++)for(let a=0;a<e.width;a++){let d=s*e.width+a;if(o[d])continue;let u=e.x+a,c=e.y+s;for(let l=0;l<i.length;l++){let p=i[l],h=u-p.getOrigin().x,m=c-p.getOrigin().y,b=p.getWidth(),f=p.getHeight();if(h<0||h>=b||m<0||m>=f)continue;let U=m*b+h,y=p.getData(),O=y.getCharCode(U),B=y.getFgColorCode(U),v=y.getBgColorCode(U),w=n[d];if(O!==0&&O<256&&w.char===" "&&(w.char=q.charCache[O]),B!==255&&w.fgColorIndex===255&&(w.fgColorIndex=B,w.fgEmission=this.getColorEmission(B)),v!==255){w.bgColorIndex===255&&(w.bgColorIndex=v,w.bgEmission=this.getColorEmission(v)),o[d]=1;break}}}return{width:e.width,height:e.height,cells:n,palette:this.colorCache}}rasterizeWithSortedLayers(e,t){let r=e.width*e.height,n=this.cellsBuffer;n.length=r;for(let s=0;s<r;s++)n[s]?(n[s].char=" ",n[s].fgColorIndex=255,n[s].bgColorIndex=255,n[s].fgEmission=0,n[s].bgEmission=0):n[s]={char:" ",fgColorIndex:255,bgColorIndex:255,fgEmission:0,bgEmission:0};this.opacityBuffer.length<r?this.opacityBuffer=new Uint8Array(r):this.opacityBuffer.fill(0,0,r);let o=this.opacityBuffer,i=this.visibleLayersBuffer;i.length=0;for(let s=0;s<t.length;s++){let a=t[s];this.isLayerVisible(e,a.getOrigin())&&i.push(a)}for(let s=0;s<e.height;s++)for(let a=0;a<e.width;a++){let d=s*e.width+a;if(o[d])continue;let u=e.x+a,c=e.y+s;for(let l=0;l<i.length;l++){let p=i[l],h=u-p.getOrigin().x,m=c-p.getOrigin().y,b=p.getWidth(),f=p.getHeight();if(h<0||h>=b||m<0||m>=f)continue;let U=m*b+h,y=p.getData(),O=y.getCharCode(U),B=y.getFgColorCode(U),v=y.getBgColorCode(U),w=n[d];if(O!==0&&O<256&&w.char===" "&&(w.char=q.charCache[O]),B!==255&&w.fgColorIndex===255&&(w.fgColorIndex=B,w.fgEmission=this.getColorEmission(B)),v!==255){w.bgColorIndex===255&&(w.bgColorIndex=v,w.bgEmission=this.getColorEmission(v)),o[d]=1;break}}}return{width:e.width,height:e.height,cells:n,palette:this.colorCache}}calculateIntersection(e,t){let r=e.x,n=e.x+e.width,o=e.y,i=e.y+e.height,s=t.x,a=t.x+256,d=t.y,u=t.y+256,c=Math.max(r,s),l=Math.min(n,a),p=Math.max(o,d),h=Math.min(i,u);return{visible:c<l&&p<h,originStart:{x:c-e.x,y:p-e.y},originEnd:{x:l-e.x,y:h-e.y},layerStart:{x:c-t.x,y:p-t.y},layerEnd:{x:l-t.x,y:h-t.y}}}};C(q,"DisplayRasterizer"),x(q,"charCache",(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=String.fromCharCode(t);return e})());var Ae=q;var Ke=class Ke{constructor(){x(this,"enabled",!1);x(this,"currentStats",null)}setEnabled(e){this.enabled=e,e||(this.currentStats=null)}isEnabled(){return this.enabled}get tick(){return this.currentStats?.tick??0}get timestamp(){return this.currentStats?.timestamp??0}get totalOrders(){return this.currentStats?.totalOrders??0}get ordersByLayer(){return this.currentStats?.ordersByLayer??new Map}get ordersByType(){return this.currentStats?.ordersByType??new Map}get totalLayers(){return this.currentStats?.totalLayers??0}get visibleLayers(){return this.currentStats?.visibleLayers??0}get layersPerDisplay(){return this.currentStats?.layersPerDisplay??new Map}get updatePacketSize(){return this.currentStats?.updatePacketSize??0}get displayHeaderSize(){return this.currentStats?.displayHeaderSize??0}get layerHeaderSize(){return this.currentStats?.layerHeaderSize??0}get orderDataSize(){return this.currentStats?.orderDataSize??0}get compressionRatio(){return this.currentStats?.compressionRatio??0}get compressedPacketSize(){return Math.round(this.updatePacketSize*this.compressionRatio)}get totalCells(){return this.currentStats?.totalCells??0}get nonEmptyCells(){return this.currentStats?.nonEmptyCells??0}get cellsWithBackground(){return this.currentStats?.cellsWithBackground??0}get rasterizationTimeMs(){return this.currentStats?.rasterizationTimeMs??0}get encodingTimeMs(){return this.currentStats?.encodingTimeMs??0}get packetSplit(){return this.currentStats?.packetSplit}get layerDetails(){return this.currentStats?.layerDetails}startTick(e){this.enabled&&(this.currentStats={tick:e,timestamp:Date.now(),totalOrders:0,ordersByLayer:new Map,ordersByType:new Map,totalLayers:0,visibleLayers:0,layersPerDisplay:new Map,updatePacketSize:0,displayHeaderSize:0,layerHeaderSize:0,orderDataSize:0,compressionRatio:0,totalCells:0,nonEmptyCells:0,cellsWithBackground:0,rasterizationTimeMs:0,encodingTimeMs:0})}recordLayerOrders(e,t){if(!(!this.enabled||!this.currentStats)){this.currentStats.totalOrders+=t.length,this.currentStats.ordersByLayer.set(e,t.length);for(let r of t){let n=this.currentStats.ordersByType.get(r.type)||0;this.currentStats.ordersByType.set(r.type,n+1)}}}recordLayers(e,t){!this.enabled||!this.currentStats||(this.currentStats.totalLayers=e,this.currentStats.visibleLayers=t)}recordDisplayLayers(e,t){!this.enabled||!this.currentStats||this.currentStats.layersPerDisplay.set(e,t)}recordUpdatePacketSize(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.updatePacketSize=e,this.currentStats.displayHeaderSize=t,this.currentStats.layerHeaderSize=r,this.currentStats.orderDataSize=n,this.currentStats.compressionRatio=.25)}recordPacketSplit(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.packetSplit={userId:e,displayCount:t,staticLayerCount:r,dynamicLayerCount:n})}recordLayerInfo(e,t,r,n){!this.enabled||!this.currentStats||(this.currentStats.layerDetails||(this.currentStats.layerDetails=[]),this.currentStats.layerDetails.push({layerId:e,isStatic:t,orderCount:r,updateFlags:n}))}recordRenderStats(e,t,r){!this.enabled||!this.currentStats||(this.currentStats.totalCells=e,this.currentStats.nonEmptyCells=t,this.currentStats.cellsWithBackground=r)}recordRasterizationTime(e){!this.enabled||!this.currentStats||(this.currentStats.rasterizationTimeMs=e)}recordEncodingTime(e){!this.enabled||!this.currentStats||(this.currentStats.encodingTimeMs=e)}endTick(){}reset(){this.currentStats=null}};C(Ke,"CoreStats");var j=Ke;var Je=class Je{constructor(){x(this,"unicolorSprites",new Map);x(this,"multicolorSprites",new Map)}loadUnicolorSprites(e){for(let t of e.sprites){let r=new W(t.sizeX*t.sizeY);for(let o=0;o<t.data.length;o++)r.set(o,t.data[o]);let n={id:t.spriteId,sizeX:t.sizeX,sizeY:t.sizeY,data:r};this.unicolorSprites.set(n.id,n)}}loadMulticolorSprites(e){for(let t of e.sprites){let r=new R(t.sizeX*t.sizeY);for(let o=0;o<t.data.length;o++){let i=t.data[o];r.set(o,i.charCode,i.fgColorId,i.bgColorId)}let n={id:t.spriteId,sizeX:t.sizeX,sizeY:t.sizeY,data:r};this.multicolorSprites.set(n.id,n)}}getUnicolorSprite(e){return this.unicolorSprites.get(e)}getMulticolorSprite(e){return this.multicolorSprites.get(e)}hasUnicolorSprite(e){return this.unicolorSprites.has(e)}hasMulticolorSprite(e){return this.multicolorSprites.has(e)}unloadUnicolorSprite(e){return this.unicolorSprites.delete(e)}unloadMulticolorSprite(e){return this.multicolorSprites.delete(e)}clearUnicolorSprites(){this.unicolorSprites.clear()}clearMulticolorSprites(){this.multicolorSprites.clear()}clearAll(){this.unicolorSprites.clear(),this.multicolorSprites.clear()}getUnicolorSpriteCount(){return this.unicolorSprites.size}getMulticolorSpriteCount(){return this.multicolorSprites.size}getTotalSpriteCount(){return this.unicolorSprites.size+this.multicolorSprites.size}};C(Je,"SpriteRegistry");var K=Je;var Qe=(t=>(t.Web="web",t.Bitmap="bitmap",t))(Qe||{}),et=class et{constructor(e,t){this.fontId=e;this.config=t}getFontId(){return this.fontId}getConfig(){return{...this.config}}getFontFamily(){return this.config.fontFamily}getFontSize(){return this.config.fontSize}getOffsetX(){return this.config.offsetX??0}getOffsetY(){return this.config.offsetY??0}getCharSpacing(){return this.config.charSpacing??0}getLineHeight(){return this.config.lineHeight??1.2}getFontWeight(){return this.config.fontWeight??"normal"}getFontStyle(){return this.config.fontStyle??"normal"}toCSS(){let e=[];e.push(`font-family: ${this.config.fontFamily}`),e.push(`font-size: ${this.config.fontSize}px`);let t=this.config.fontWeight??"normal";t!=="normal"&&e.push(`font-weight: ${t}`);let r=this.config.fontStyle??"normal";return r!=="normal"&&e.push(`font-style: ${r}`),e.join("; ")+";"}};C(et,"WebFont");var P=et,tt=class tt{constructor(e,t){this.fontId=e;this.config=t}getFontId(){return this.fontId}getConfig(){return{charWidth:this.config.charWidth,charHeight:this.config.charHeight,cellWidth:this.config.cellWidth,cellHeight:this.config.cellHeight,glyphs:new Map(this.config.glyphs)}}getCharWidth(){return this.config.charWidth}getCharHeight(){return this.config.charHeight}getCellWidth(){return this.config.cellWidth??this.config.charWidth}getCellHeight(){return this.config.cellHeight??this.config.charHeight}getGlyph(e){return this.config.glyphs.get(e)}hasGlyph(e){return this.config.glyphs.has(e)}getGlyphCount(){return this.config.glyphs.size}getCharCodes(){return Array.from(this.config.glyphs.keys())}};C(tt,"BitmapFont");var J=tt;var rt=class rt{constructor(){x(this,"fonts",new Map)}loadFont(e,t){if(this.fonts.has(e))throw new Error(`WebFont with ID ${e} already exists`);let r=new P(e,t);this.fonts.set(e,r)}getFont(e){return this.fonts.get(e)}hasFont(e){return this.fonts.has(e)}unloadFont(e){return this.fonts.delete(e)}clearFonts(){this.fonts.clear()}getFontIds(){return Array.from(this.fonts.keys()).sort((e,t)=>e-t)}getAllFonts(){return Array.from(this.fonts.entries()).sort((e,t)=>e[0]-t[0]).map(e=>e[1])}getFontCount(){return this.fonts.size}};C(rt,"WebFontRegistry");var Q=rt;var nt=class nt{constructor(){x(this,"fonts",new Map)}loadFont(e,t){if(this.fonts.has(e))throw new Error(`BitmapFont with ID ${e} already exists`);let r=new J(e,t);this.fonts.set(e,r)}getFont(e){return this.fonts.get(e)}hasFont(e){return this.fonts.has(e)}unloadFont(e){return this.fonts.delete(e)}clearFonts(){this.fonts.clear()}getFontIds(){return Array.from(this.fonts.keys()).sort((e,t)=>e-t)}getAllFonts(){return Array.from(this.fonts.entries()).sort((e,t)=>e[0]-t[0]).map(e=>e[1])}getFontCount(){return this.fonts.size}};C(nt,"BitmapFontRegistry");var ee=nt;var ot=class ot{constructor(){x(this,"sounds",new Map);x(this,"nameToId",new Map);x(this,"nextId",0)}registerFile(e,t,r){let n=this.allocateId(e),o={soundId:n,name:e,loadType:"file",format:t,data:r};return this.sounds.set(n,o),this.nameToId.set(e,n),n}registerFileWithId(e,t,r,n){this.validateId(e),this.checkIdAvailable(e,t);let o={soundId:e,name:t,loadType:"file",format:r,data:n};this.sounds.set(e,o),this.nameToId.set(t,e)}registerExternal(e,t,r,n,o){let i=this.allocateId(e),s={soundId:i,name:e,loadType:"external",format:t,url:r,size:n,checksum:o};return this.sounds.set(i,s),this.nameToId.set(e,i),i}registerExternalWithId(e,t,r,n,o,i){this.validateId(e),this.checkIdAvailable(e,t);let s={soundId:e,name:t,loadType:"external",format:r,url:n,size:o,checksum:i};this.sounds.set(e,s),this.nameToId.set(t,e)}get(e){if(typeof e=="number")return this.sounds.get(e);let t=this.nameToId.get(e);return t!==void 0?this.sounds.get(t):void 0}has(e){return this.get(e)!==void 0}getAll(){return Array.from(this.sounds.values())}getFileSounds(){return this.getAll().filter(e=>e.loadType==="file")}getExternalSounds(){return this.getAll().filter(e=>e.loadType==="external")}getNames(){return Array.from(this.nameToId.keys())}getId(e){return this.nameToId.get(e)}toLoadPackets(){let e=[],t=this.getFileSounds();if(t.length>0){let n=t.map(o=>({soundId:o.soundId,name:o.name,format:o.format,data:o.data}));e.push({type:"sound",mode:"file",sounds:n})}let r=this.getExternalSounds();if(r.length>0){let n=r.map(o=>({soundId:o.soundId,name:o.name,format:o.format,url:o.url,size:o.size,checksum:o.checksum}));e.push({type:"sound",mode:"external",sounds:n})}return e}toLoadPacket(e){let t=this.get(e);return t?t.loadType==="file"?{type:"sound",mode:"file",sounds:[{soundId:t.soundId,name:t.name,format:t.format,data:t.data}]}:{type:"sound",mode:"external",sounds:[{soundId:t.soundId,name:t.name,format:t.format,url:t.url,size:t.size,checksum:t.checksum}]}:null}unregister(e){let t=this.get(e);return t?(this.sounds.delete(t.soundId),this.nameToId.delete(t.name),!0):!1}clear(){this.sounds.clear(),this.nameToId.clear(),this.nextId=0}get size(){return this.sounds.size}getStats(){let e=this.getAll(),t=e.filter(n=>n.loadType==="file"),r=t.reduce((n,o)=>n+(o.data?.length??0),0);return{total:e.length,file:t.length,external:e.length-t.length,totalFileSize:r}}allocateId(e){if(this.nameToId.has(e))throw new Error(`Sound with name "${e}" already exists`);for(;this.sounds.has(this.nextId);)if(this.nextId++,this.nextId>255)throw new Error("Maximum number of sounds (256) reached");return this.nextId++}validateId(e){if(!Number.isInteger(e)||e<0||e>255)throw new Error(`Invalid sound ID: ${e}. Must be an integer between 0 and 255.`)}checkIdAvailable(e,t){if(this.sounds.has(e)){let r=this.sounds.get(e);throw new Error(`Sound ID ${e} is already used by "${r.name}". Cannot register "${t}".`)}if(this.nameToId.has(t))throw new Error(`Sound with name "${t}" already exists`)}};C(ot,"SoundRegistry");var te=ot;var it=class it{constructor(e){this.soundRegistry=e}collectFromUser(e){let t=[],r=e.flushSoundCommands();for(let o of r){let i=this.convertSoundCommand(o);i&&t.push(i)}let n=e.flushAudioConfigCommands();for(let o of n){let i=this.convertConfigCommand(o);i&&t.push(i)}return t}convertSoundCommand(e){return"setEffects"in e&&e.setEffects===!0?this.convertSetEffectsCommand(e):"fadeOut"in e&&e.fadeOut===!0?this.convertFadeOutCommand(e):"pause"in e&&e.pause===!0?this.convertPauseCommand(e):"resume"in e&&e.resume===!0?this.convertResumeCommand(e):"instanceId"in e||"volume"in e||"pitch"in e||"loop"in e||"fadeIn"in e||"x"in e||"y"in e||"lowpass"in e||"highpass"in e||"reverb"in e?this.convertPlayCommand(e):this.convertStopCommand(e)}convertPlayCommand(e){let t=this.resolveSoundId(e.sound);if(t===null)return console.warn(`[AudioOrderCollector] Unknown sound: ${e.sound}`),null;let r=0;e.loop&&(r|=1),e.volume!==void 0&&(r|=2),e.pitch!==void 0&&(r|=4),e.fadeIn!==void 0&&(r|=8),e.lowpass!==void 0&&e.lowpass>0&&(r|=32),e.highpass!==void 0&&e.highpass>0&&(r|=64),e.reverb!==void 0&&e.reverb>0&&(r|=128);let n=e.x!==void 0&&e.y!==void 0;return n&&(r|=16),n?{type:1,soundId:t,instanceId:e.instanceId??0,flags:r,volume:e.volume!==void 0?this.encodeVolume(e.volume):void 0,pitch:e.pitch!==void 0?this.encodePitch(e.pitch):void 0,fadeIn:e.fadeIn!==void 0?this.encodeFadeTime(e.fadeIn):void 0,posX:this.encodePosition(e.x),posY:this.encodePosition(e.y),lowpass:e.lowpass!==void 0&&e.lowpass>0?this.encodeFilterFreq(e.lowpass):void 0,highpass:e.highpass!==void 0&&e.highpass>0?this.encodeFilterFreq(e.highpass):void 0,reverb:e.reverb!==void 0&&e.reverb>0?this.encodeReverb(e.reverb):void 0}:{type:2,soundId:t,instanceId:e.instanceId??0,flags:r&-17,volume:e.volume!==void 0?this.encodeVolume(e.volume):void 0,pitch:e.pitch!==void 0?this.encodePitch(e.pitch):void 0,fadeIn:e.fadeIn!==void 0?this.encodeFadeTime(e.fadeIn):void 0,lowpass:e.lowpass!==void 0&&e.lowpass>0?this.encodeFilterFreq(e.lowpass):void 0,highpass:e.highpass!==void 0&&e.highpass>0?this.encodeFilterFreq(e.highpass):void 0,reverb:e.reverb!==void 0&&e.reverb>0?this.encodeReverb(e.reverb):void 0}}convertStopCommand(e){let{targetType:t,target:r}=this.resolveTarget(e.sound);return{type:3,targetType:t,target:r}}convertFadeOutCommand(e){let{targetType:t,target:r}=this.resolveTarget(e.sound);return{type:4,targetType:t,duration:this.encodeFadeTime(e.duration),target:r}}convertPauseCommand(e){let{targetType:t,target:r}=this.resolveTarget(e.sound);return{type:5,targetType:t,target:r}}convertResumeCommand(e){let{targetType:t,target:r}=this.resolveTarget(e.sound);return{type:6,targetType:t,target:r}}convertSetEffectsCommand(e){let t=0;return e.lowpass!==void 0&&(t|=1),e.highpass!==void 0&&(t|=2),e.reverb!==void 0&&(t|=4),{type:9,instanceId:e.instanceId,flags:t,lowpass:e.lowpass!==void 0?this.encodeFilterFreq(e.lowpass):void 0,highpass:e.highpass!==void 0?this.encodeFilterFreq(e.highpass):void 0,reverb:e.reverb!==void 0?this.encodeReverb(e.reverb):void 0}}convertConfigCommand(e){return e.type==="set-listener-position"?{type:7,x:this.encodePosition(e.x),y:this.encodePosition(e.y)}:e.type==="configure-spatial"?{type:8,maxDistance:this.encodeDistance(e.maxDistance??1e3),referenceDistance:this.encodeDistance(e.referenceDistance??100),rolloffFactor:this.encodeRolloff(e.rolloffFactor??1),panSpread:this.encodePanSpread(e.panSpread??.5)}:null}resolveSoundId(e){if(typeof e=="number")return e>=0&&e<=255?e:null;let t=this.soundRegistry.getId(e);return t!==void 0?t:null}resolveTarget(e){if(e==="all")return{targetType:2,target:void 0};if(typeof e=="number")return{targetType:0,target:e};let t=this.soundRegistry.getId(e);return t!==void 0?{targetType:1,target:t}:(console.warn(`[AudioOrderCollector] Unknown sound name: ${e}, treating as 'all'`),{targetType:2,target:void 0})}encodeVolume(e){return Math.round(Math.max(0,Math.min(1,e))*255)}encodePitch(e){let t=Math.max(.25,Math.min(4,e)),r=64*Math.log2(t/.25);return Math.round(Math.max(0,Math.min(255,r)))}encodeFadeTime(e){return Math.round(Math.max(0,Math.min(25.5,e))*10)}encodeDistance(e){return Math.round(Math.max(0,Math.min(25500,e))/100)}encodeRolloff(e){return Math.round(Math.max(0,Math.min(2.55,e))*100)}encodePanSpread(e){return Math.round(Math.max(0,Math.min(1,e))*255)}encodePosition(e){return Math.round(Math.max(0,Math.min(65535,e)))}encodeFilterFreq(e){return e<=0?0:Math.round(Math.max(1,Math.min(255,e/100)))}encodeReverb(e){return Math.round(Math.max(0,Math.min(1,e))*255)}};C(it,"AudioOrderCollector");var re=it;var se=class se{constructor(e={}){x(this,"users",new Map);x(this,"mode");x(this,"maxUsers");x(this,"strictMode");x(this,"currentTick",0);x(this,"encoder");x(this,"displayRasterizer");x(this,"colorPalette",new Map);x(this,"stats",new j);x(this,"spriteRegistry",new K);x(this,"webFontRegistry",new Q);x(this,"bitmapFontRegistry",new ee);x(this,"soundRegistry",new te);x(this,"audioOrderCollector");x(this,"activeWebFontId",0);x(this,"_renderCallCount",0);x(this,"onPaletteChangedCallback");x(this,"onBitmapFontChangedCallback");this.mode=e.mode??"server",this.maxUsers=e.maxUsers??64,this.strictMode=e.strictMode??!1,this.encoder=new ve,this.displayRasterizer=new Ae(this),this.audioOrderCollector=new re(this.soundRegistry),this.initializeDefaultPalette(),this.displayRasterizer.rebuildColorCache(),this.loadDefaultWebFont()}initializeDefaultPalette(){se.ANSI_VGA_COLORS.forEach(e=>{this.colorPalette.set(e.colorId,{r:e.r,g:e.g,b:e.b,a:e.a,e:e.e})}),this.colorPalette.set(255,{r:0,g:0,b:0,a:0,e:0})}getMode(){return this.mode}getMaxUsers(){return this.maxUsers}isStrictMode(){return this.strictMode}isServer(){return this.mode==="server"}isClient(){return this.mode==="client"}isStandalone(){return this.mode==="standalone"}createUser(e,t){if(this.users.has(e))throw new Error(`User with ID ${e} already exists`);if(this.mode==="server"&&this.users.size>=this.maxUsers)throw new Error(`Maximum number of users reached (${this.maxUsers}). Cannot create user ${e}`);if(this.mode==="client"&&this.users.size>=1)throw new Error(`Client mode only allows one user. Cannot create user ${e}`);let r=new G(e,t,this.mode);return r.setSpriteRegistry(this.spriteRegistry),this.users.set(e,r),r}getUser(e){return this.users.get(e)??null}getUsers(){return Array.from(this.users.values())}hasUser(e){return this.users.has(e)}removeUser(e){return this.users.delete(e)}getUserCount(){return this.users.size}clearAllUsers(){this.users.clear()}setColor(e,t,r,n,o=255,i=0){if(e<0||e>255)throw new Error(`Color ID must be between 0 and 255, got ${e}`);if(e>=240)throw new Error("Color IDs 240-255 are reserved (240-254: UI palette, 255: skip color). Use IDs 0-239 for custom colors.");if(t<0||t>255||r<0||r>255||n<0||n>255||o<0||o>255||i<0||i>255)throw new Error("Color components must be between 0 and 255");this.colorPalette.set(e,{r:t,g:r,b:n,a:o,e:i}),this.onPaletteChangedCallback&&this.onPaletteChangedCallback(this.colorPalette)}onPaletteChanged(e){this.onPaletteChangedCallback=e}onBitmapFontChanged(e){this.onBitmapFontChangedCallback=e}getColor(e){return this.colorPalette.get(e)??null}loadPalette(e){for(let t of e)t.colorId<0||t.colorId>255||this.colorPalette.set(t.colorId,{r:t.r,g:t.g,b:t.b,a:t.a,e:t.e??0});se.ANSI_VGA_COLORS.forEach(t=>{this.colorPalette.set(t.colorId,{r:t.r,g:t.g,b:t.b,a:t.a,e:t.e})}),this.colorPalette.set(255,{r:0,g:0,b:0,a:0,e:0}),this.displayRasterizer.rebuildColorCache(),this.onPaletteChangedCallback&&this.onPaletteChangedCallback(this.colorPalette)}getPalette(){return new Map(this.colorPalette)}resetPalette(){this.colorPalette.clear(),this.initializeDefaultPalette(),this.onPaletteChangedCallback&&this.onPaletteChangedCallback(this.colorPalette)}getColorCSS(e){let t=this.getColor(e);if(!t)return null;let r=t.a/255;return`rgba(${t.r}, ${t.g}, ${t.b}, ${r})`}getUserIds(){return Array.from(this.users.keys())}forEachUser(e){this.users.forEach(e)}filterUsers(e){return this.getUsers().filter(e)}findUser(e){return this.getUsers().find(e)}getCurrentTick(){return this.currentTick}getStats(){return this.stats}endTick(){this.stats.isEnabled()&&this.stats.startTick(this.currentTick);let e=new Map,t=0,r=0;return this.users.forEach((n,o)=>{let i=n.getLayers(),s=n.getDisplays();t+=i.length,n.getStats().isEnabled()&&n.getStats().startTick(this.currentTick);let a=s.map(h=>{let m=h.getOrigin(),b=h.getSize();return{id:h.getId(),originX:m.x,originY:m.y,sizeX:b.x,sizeY:b.y}});s.forEach(h=>h.resetChangeTracking());let d=[],u=[];i.forEach((h,m)=>{let b=h.getOrigin(),f=h.getOrders(),U=h.getStatic(),y=h.calculateUpdateFlags();h.resetChangeTracking(),h.getId()===0&&h.setId(m);let O={id:h.getId(),updateFlags:y,zIndex:h.getZOrder(),originX:b.x,originY:b.y,width:h.getWidth(),height:h.getHeight(),orderCount:f.length,orders:f};U?d.push(O):u.push(O)}),r+=d.length+u.length;let c=this.audioOrderCollector.collectFromUser(n),l=[...d,...u],p=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:l.length,layers:l,audioOrderCount:c.length,audioOrders:c});if(e.set(o,p),this.stats.isEnabled()){l.forEach((f,U)=>{this.stats.recordLayerOrders(U,f.orders)}),s.forEach((f,U)=>{this.stats.recordDisplayLayers(U,l.length)});let h=s.length*12,m=l.length*20,b=p.length-h-m;this.stats.recordUpdatePacketSize(p.length,h,m,b>0?b:0)}}),this.stats.isEnabled()&&(this.stats.recordLayers(t,r),this.stats.endTick()),this.currentTick++,e}endTickSplit(){this.stats.isEnabled()&&this.stats.startTick(this.currentTick);let e=new Map,t=0,r=0;return this.users.forEach((n,o)=>{let i=n.getLayers(),s=n.getDisplays();t+=i.length,n.getStats().isEnabled()&&n.getStats().startTick(this.currentTick);let a=s.map(h=>{let m=h.getOrigin(),b=h.getSize();return{id:h.getId(),originX:m.x,originY:m.y,sizeX:b.x,sizeY:b.y}});s.forEach(h=>h.resetChangeTracking());let d=[],u=[];i.forEach((h,m)=>{if(!h.getNeedsCommit())return;let b=h.getOrigin(),f=h.getOrders(),U=h.getStatic(),y=h.calculateUpdateFlags();h.resetChangeTracking(),h.resetCommit(),h.getId()===0&&h.setId(m);let O={id:h.getId(),updateFlags:y,zIndex:h.getZOrder(),originX:b.x,originY:b.y,width:h.getWidth(),height:h.getHeight(),orderCount:f.length,orders:f};f.length>0&&this.stats.isEnabled()&&this.stats.recordLayerInfo(h.getId(),U,f.length,y),U?d.push(O):u.push(O)}),r+=d.length+u.length;let c=this.audioOrderCollector.collectFromUser(n),l=null,p=null;if(this.stats.isEnabled()&&this.stats.recordPacketSplit(o,a.length,d.length,u.length),d.length>0&&(l=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:d.length,layers:d,audioOrderCount:0,audioOrders:[]})),p=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:u.length,layers:u,audioOrderCount:c.length,audioOrders:c}),e.set(o,{static:l,dynamic:p}),n.getStats().isEnabled()){let h=s.reduce((U,y)=>{let O=y.getSize();return U+O.x*O.y},0);n.getStats().recordDisplays(s.length,h),n.getStats().recordLayers(i.length,d.length+u.length,d.length,u.length),[...d,...u].forEach(U=>{n.getStats().recordLayerOrders(U.id,U.orders.length)});let m=l?.length||0,b=p?.length||0;n.getStats().recordPacketSizes(m,b);let f=n.getInputBindingRegistry();n.getStats().recordInput(!1,f.getAxisCount(),f.getButtonCount()),n.getStats().endTick()}if(this.stats.isEnabled()){let h=[...d,...u];h.forEach((y,O)=>{this.stats.recordLayerOrders(O,y.orders)}),s.forEach((y,O)=>{this.stats.recordDisplayLayers(O,h.length)});let m=(l?.length||0)+(p?.length||0),b=s.length*12,f=h.length*20,U=m-b-f;this.stats.recordUpdatePacketSize(m,b,f,U>0?U:0)}}),this.stats.isEnabled()&&(this.stats.recordLayers(t,r),this.stats.endTick()),this.currentTick++,e}getSnapshot(e){let t=this.getUser(e);if(!t)return null;let r=t.getDisplays(),n=t.getLayers(),o=r.map((s,a)=>{let d=s.getOrigin(),u=s.getSize();return{id:a,originX:d.x,originY:d.y,sizeX:u.x,sizeY:u.y}}),i=n.map((s,a)=>{let d=s.getOrigin(),u=s.getOrders(),c=7;return s.getId()===0&&s.setId(a),{id:s.getId(),updateFlags:c,zIndex:s.getZOrder(),originX:d.x,originY:d.y,width:s.getWidth(),height:s.getHeight(),orderCount:u.length,orders:u}});return this.encoder.encode({tick:this.currentTick,displayCount:o.length,displays:o,layerCount:i.length,layers:i,audioOrderCount:0,audioOrders:[]})}resetTick(){this.currentTick=0}applyUpdatePacket(e,t){let r=this.getUser(e);if(!r){if(this.strictMode)throw new Error(`Cannot apply update packet: user ${e} does not exist`);return!1}return r.applyUpdate(t),t.audioOrders&&t.audioOrders.length>0&&r.applyAudioOrders(t.audioOrders),!0}applyUpdatePacketBuffer(e,t){let{UpdatePacketDecoder:r}=(pt(),z(kt)),o=new r().decode(t);return this.applyUpdatePacket(e,o)}applyLoadPacket(e){try{let{LoadDecoder:t}=(Et(),z(zt)),{LoadType:r}=(T(),z(_)),i=new t().decode(e).load;switch(i.loadType){case r.ColorPalette:this.loadPalette(i.colors);break;case r.Sprite:this.loadUnicolorSprites(i);break;case r.MulticolorSprite:this.loadMulticolorSprites(i);break;case r.BitmapFont:{let s=this.getBitmapFontRegistry();s.hasFont(i.fontId)&&s.unloadFont(i.fontId),s.loadFont(i.fontId,{charWidth:i.width,charHeight:i.height,cellWidth:i.cellWidth,cellHeight:i.cellHeight,glyphs:new Map(i.characters.map(a=>[a.charCode,a.bitmap]))});break}case r.WebFont:{let s=this.getWebFontRegistry();s.hasFont(i.fontId)&&s.unloadFont(i.fontId),this.loadWebFontById(i.fontId,{fontFamily:i.fontFamily,fontSize:i.fontSize,offsetX:i.offsetX,offsetY:i.offsetY,charSpacing:i.charSpacing,lineHeight:i.lineHeight,fontWeight:i.fontWeight,fontStyle:i.fontStyle});break}case r.Sound:console.warn("[Core] Sound loading not yet implemented");break;default:return console.error(`[Core] Unknown LoadType: ${i.loadType}`),!1}return!0}catch(t){return console.error("[Core] Failed to apply LoadPacket:",t),!1}}generatePaletteLoadPacket(){let e=this.getPalette();if(e.size===0)return null;let{LoadEncoder:t}=(ie(),z(oe)),{LoadType:r}=(T(),z(_)),n=new t,o=[];return e.forEach((i,s)=>{s!==255&&o.push({colorId:s,r:i.r,g:i.g,b:i.b,a:i.a,e:i.e})}),n.encode({loadType:r.ColorPalette,colors:o})}generateUnicolorSpritesLoadPacket(){let e=this.getSpriteRegistry(),t=[];for(let i=0;i<=255;i++){let s=e.getUnicolorSprite(i);if(s){let a=[];for(let d=0;d<s.sizeX*s.sizeY;d++)a.push(s.data.get(d));t.push({spriteId:s.id,sizeX:s.sizeX,sizeY:s.sizeY,data:a})}}if(t.length===0)return null;let{LoadEncoder:r}=(ie(),z(oe)),{LoadType:n}=(T(),z(_));return new r().encode({loadType:n.Sprite,sprites:t})}generateMulticolorSpritesLoadPacket(){let e=this.getSpriteRegistry(),t=[];for(let i=0;i<=255;i++){let s=e.getMulticolorSprite(i);if(s){let a=[];for(let d=0;d<s.sizeX*s.sizeY;d++){let u=s.data.get(d);a.push({charCode:u.charCode,fgColorId:u.fgColorCode,bgColorId:u.bgColorCode})}t.push({spriteId:s.id,sizeX:s.sizeX,sizeY:s.sizeY,data:a})}}if(t.length===0)return null;let{LoadEncoder:r}=(ie(),z(oe)),{LoadType:n}=(T(),z(_));return new r().encode({loadType:n.MulticolorSprite,sprites:t})}generateWebFontsLoadPackets(){let e=this.getWebFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(ie(),z(oe)),{LoadType:o}=(T(),z(_)),i=new n;for(let s of t){let a=e.getFont(s);if(a){let d=a.getConfig(),u=i.encode({loadType:o.WebFont,fontId:s,fontFamily:d.fontFamily,fontSize:d.fontSize,offsetX:d.offsetX,offsetY:d.offsetY,charSpacing:d.charSpacing,lineHeight:d.lineHeight,fontWeight:d.fontWeight,fontStyle:d.fontStyle});r.push(u)}}return r}generateBitmapFontsLoadPackets(){let e=this.getBitmapFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(ie(),z(oe)),{LoadType:o}=(T(),z(_)),i=new n;for(let s of t){let a=e.getFont(s);if(a){let d=[];for(let u=0;u<256;u++){let c=a.getGlyph(u);c&&d.push({charCode:u,bitmap:c})}if(d.length>0){let u=i.encode({loadType:o.BitmapFont,fontId:s,width:a.getCharWidth(),height:a.getCharHeight(),cellWidth:a.getCellWidth(),cellHeight:a.getCellHeight(),characters:d});r.push(u)}}}return r}generateAllLoadPackets(){let e=[],t=this.generatePaletteLoadPacket();t&&e.push(t);let r=this.generateUnicolorSpritesLoadPacket();r&&e.push(r);let n=this.generateMulticolorSpritesLoadPacket();n&&e.push(n);let o=this.generateWebFontsLoadPackets();e.push(...o);let i=this.generateBitmapFontsLoadPackets();return e.push(...i),e}applyInputBindingsLoadPacket(e,t){let r=this.getUser(e);if(!r){if(this.strictMode)throw new Error(`Cannot apply input bindings: user ${e} does not exist`);return!1}try{return r.applyInputBindingsLoadPacket(t),!0}catch(n){return console.error(`[Core] Failed to apply input bindings for user ${e}:`,n),!1}}getRenderState(e){let t=this.getUser(e);if(!t)return null;let r=t.getDisplays(),n=t.getLayers(),o=performance.now(),i=new Array(r.length);for(let a=0;a<r.length;a++){let d=r[a],u=d.getOrigin(),c=d.getSize();i[a]=this.displayRasterizer.rasterize({x:u.x,y:u.y,width:c.x,height:c.y},n)}let s=performance.now()-o;return this._renderCallCount||(this._renderCallCount=0),this._renderCallCount++,{userId:t.id,userName:t.name,tick:this.currentTick,displays:i}}getAllRenderStates(){let e=new Map;return this.users.forEach((t,r)=>{let n=this.getRenderState(r);n&&e.set(r,n)}),e}enableStats(e){this.stats.setEnabled(e)}getStatsInstance(){return this.stats}resetStats(){this.stats.reset()}loadUnicolorSprites(e){this.spriteRegistry.loadUnicolorSprites(e)}loadMulticolorSprites(e){this.spriteRegistry.loadMulticolorSprites(e)}unloadUnicolorSprite(e){return this.spriteRegistry.unloadUnicolorSprite(e)}unloadMulticolorSprite(e){return this.spriteRegistry.unloadMulticolorSprite(e)}clearUnicolorSprites(){this.spriteRegistry.clearUnicolorSprites()}clearMulticolorSprites(){this.spriteRegistry.clearMulticolorSprites()}clearAllSprites(){this.spriteRegistry.clearAll()}getUnicolorSpriteCount(){return this.spriteRegistry.getUnicolorSpriteCount()}getMulticolorSpriteCount(){return this.spriteRegistry.getMulticolorSpriteCount()}getTotalSpriteCount(){return this.spriteRegistry.getTotalSpriteCount()}hasUnicolorSprite(e){return this.spriteRegistry.hasUnicolorSprite(e)}hasMulticolorSprite(e){return this.spriteRegistry.hasMulticolorSprite(e)}getSpriteRegistry(){return this.spriteRegistry}getSoundRegistry(){return this.soundRegistry}async loadSound(e,t){let r=this.detectSoundFormat(t),n=await this.loadSoundData(t);return this.soundRegistry.registerFile(e,r,n)}async loadSounds(e){let t={},n=Object.entries(e).map(async([o,i])=>{let s=await this.loadSound(o,i);t[o]=s});return await Promise.all(n),t}detectSoundFormat(e){let t=e.split(".").pop()?.toLowerCase()??"",r={mp3:"mp3",wav:"wav",ogg:"ogg",webm:"webm",aac:"aac",m4a:"aac"},n=r[t];if(!n)throw new Error(`Unsupported audio format: .${t}. Supported: ${Object.keys(r).join(", ")}`);return n}async loadSoundData(e){let t=globalThis;if(typeof t.document<"u"||typeof t.window<"u"||typeof t.fetch=="function")try{let n=await fetch(e);if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`);let o=await n.arrayBuffer();return new Uint8Array(o)}catch(n){let o=n instanceof Error?n.message:String(n);throw new Error(`Failed to load sound "${e}": ${o}`)}else{let n=typeof require<"u"?require:null;if(!n)throw new Error("Node.js require is not available");let s=n("fs").readFileSync(e);return new Uint8Array(s)}}registerSound(e,t,r){return this.soundRegistry.registerFile(e,t,r)}registerExternalSound(e,t,r,n){return this.soundRegistry.registerExternal(e,t,r,n)}hasSound(e){return this.soundRegistry.has(e)}generateSoundLoadPackets(){return this.soundRegistry.toLoadPackets()}loadDefaultWebFont(){this.webFontRegistry.loadFont(0,{fontFamily:"Courier New",fontSize:16,offsetX:0,offsetY:0,charSpacing:0,lineHeight:1,fontWeight:"normal",fontStyle:"normal"}),this.activeWebFontId=0}loadWebFont(e){let t=e.getFontId(),r=e.getConfig();this.webFontRegistry.loadFont(t,r)}getWebFont(e){return this.webFontRegistry.getFont(e)??null}hasWebFont(e){return this.webFontRegistry.hasFont(e)}unloadWebFont(e){if(e===0)throw new Error("Cannot unload default font (fontId 0)");return this.webFontRegistry.unloadFont(e)}clearWebFonts(){this.webFontRegistry.clearFonts(),this.loadDefaultWebFont()}setActiveWebFont(e){if(!this.webFontRegistry.hasFont(e))throw new Error(`WebFont with ID ${e} does not exist`);this.activeWebFontId=e}getActiveWebFontId(){return this.activeWebFontId}getActiveWebFont(){let e=this.webFontRegistry.getFont(this.activeWebFontId);if(!e)throw new Error(`Active WebFont ${this.activeWebFontId} not found. This should not happen.`);return e}getWebFontCount(){return this.webFontRegistry.getFontCount()}getWebFontIds(){return this.webFontRegistry.getFontIds()}getWebFontRegistry(){return this.webFontRegistry}getBitmapFontRegistry(){return this.bitmapFontRegistry}loadWebFontById(e,t){let r=new P(e,t);this.loadWebFont(r)}loadBitmapFontById(e,t){this.bitmapFontRegistry.loadFont(e,t),this.onBitmapFontChangedCallback&&this.onBitmapFontChangedCallback(e)}getBitmapFont(e){return this.bitmapFontRegistry.getFont(e)??null}hasBitmapFont(e){return this.bitmapFontRegistry.hasFont(e)}unloadBitmapFont(e){return this.bitmapFontRegistry.unloadFont(e)}clearBitmapFonts(){this.bitmapFontRegistry.clearFonts()}getBitmapFontCount(){return this.bitmapFontRegistry.getFontCount()}getBitmapFontIds(){return this.bitmapFontRegistry.getFontIds()}};C(se,"Core"),x(se,"ANSI_VGA_COLORS",[{colorId:240,r:16,g:16,b:16,a:255,e:0},{colorId:241,r:128,g:128,b:128,a:255,e:0},{colorId:242,r:192,g:192,b:192,a:255,e:0},{colorId:243,r:240,g:240,b:240,a:255,e:0},{colorId:244,r:200,g:50,b:50,a:255,e:0},{colorId:245,r:50,g:200,b:50,a:255,e:0},{colorId:246,r:220,g:180,b:50,a:255,e:0},{colorId:247,r:50,g:100,b:220,a:255,e:0},{colorId:248,r:50,g:200,b:200,a:255,e:0},{colorId:249,r:200,g:50,b:200,a:255,e:0},{colorId:250,r:220,g:120,b:50,a:255,e:0},{colorId:251,r:120,g:220,b:120,a:255,e:0},{colorId:252,r:120,g:180,b:220,a:255,e:0},{colorId:253,r:220,g:150,b:200,a:255,e:0},{colorId:254,r:250,g:220,b:150,a:255,e:0}]);var Me=se;var Yt=require("@utsp/types");var H=new Map([[24,new Uint8Array([0,24,60,126,255,255,0,0])],[25,new Uint8Array([0,0,255,255,126,60,24,0])],[26,new Uint8Array([0,48,120,252,252,120,48,0])],[27,new Uint8Array([0,12,30,63,63,30,12,0])],[32,new Uint8Array([0,0,0,0,0,0,0,0])],[33,new Uint8Array([24,24,24,24,24,0,24,0])],[34,new Uint8Array([108,108,108,0,0,0,0,0])],[35,new Uint8Array([54,54,127,54,127,54,54,0])],[36,new Uint8Array([12,63,104,62,11,126,24,0])],[37,new Uint8Array([96,102,12,24,48,102,6,0])],[38,new Uint8Array([56,108,108,56,109,102,59,0])],[39,new Uint8Array([24,24,24,0,0,0,0,0])],[40,new Uint8Array([12,24,48,48,48,24,12,0])],[41,new Uint8Array([48,24,12,12,12,24,48,0])],[42,new Uint8Array([0,102,60,255,60,102,0,0])],[43,new Uint8Array([0,24,24,126,24,24,0,0])],[44,new Uint8Array([0,0,0,0,0,24,24,48])],[45,new Uint8Array([0,0,0,126,0,0,0,0])],[46,new Uint8Array([0,0,0,0,0,24,24,0])],[47,new Uint8Array([0,6,12,24,48,96,0,0])],[48,new Uint8Array([60,102,110,126,118,102,60,0])],[49,new Uint8Array([24,56,24,24,24,24,126,0])],[50,new Uint8Array([60,102,6,12,24,48,126,0])],[51,new Uint8Array([60,102,6,28,6,102,60,0])],[52,new Uint8Array([12,28,60,108,126,12,12,0])],[53,new Uint8Array([126,96,124,6,6,102,60,0])],[54,new Uint8Array([28,48,96,124,102,102,60,0])],[55,new Uint8Array([126,6,12,24,48,48,48,0])],[56,new Uint8Array([60,102,102,60,102,102,60,0])],[57,new Uint8Array([60,102,102,62,6,12,56,0])],[58,new Uint8Array([0,0,24,24,0,24,24,0])],[59,new Uint8Array([0,0,24,24,0,24,24,48])],[60,new Uint8Array([12,24,48,96,48,24,12,0])],[61,new Uint8Array([0,0,126,0,126,0,0,0])],[62,new Uint8Array([48,24,12,6,12,24,48,0])],[63,new Uint8Array([60,102,12,24,24,0,24,0])],[64,new Uint8Array([60,102,110,106,110,96,60,0])],[65,new Uint8Array([60,102,102,126,102,102,102,0])],[66,new Uint8Array([124,102,102,124,102,102,124,0])],[67,new Uint8Array([60,102,96,96,96,102,60,0])],[68,new Uint8Array([120,108,102,102,102,108,120,0])],[69,new Uint8Array([126,96,96,124,96,96,126,0])],[70,new Uint8Array([126,96,96,124,96,96,96,0])],[71,new Uint8Array([60,102,96,110,102,102,60,0])],[72,new Uint8Array([102,102,102,126,102,102,102,0])],[73,new Uint8Array([126,24,24,24,24,24,126,0])],[74,new Uint8Array([62,12,12,12,12,108,56,0])],[75,new Uint8Array([102,108,120,112,120,108,102,0])],[76,new Uint8Array([96,96,96,96,96,96,126,0])],[77,new Uint8Array([99,119,127,107,99,99,99,0])],[78,new Uint8Array([102,102,118,126,110,102,102,0])],[79,new Uint8Array([60,102,102,102,102,102,60,0])],[80,new Uint8Array([124,102,102,124,96,96,96,0])],[81,new Uint8Array([60,102,102,102,106,108,54,0])],[82,new Uint8Array([124,102,102,124,108,102,102,0])],[83,new Uint8Array([60,102,96,60,6,102,60,0])],[84,new Uint8Array([126,24,24,24,24,24,24,0])],[85,new Uint8Array([102,102,102,102,102,102,60,0])],[86,new Uint8Array([102,102,102,102,102,60,24,0])],[87,new Uint8Array([99,99,99,107,127,119,99,0])],[88,new Uint8Array([102,102,60,24,60,102,102,0])],[89,new Uint8Array([102,102,102,60,24,24,24,0])],[90,new Uint8Array([126,6,12,24,48,96,126,0])],[91,new Uint8Array([60,48,48,48,48,48,60,0])],[92,new Uint8Array([0,96,48,24,12,6,0,0])],[93,new Uint8Array([60,12,12,12,12,12,60,0])],[94,new Uint8Array([24,60,102,0,0,0,0,0])],[95,new Uint8Array([0,0,0,0,0,0,255,0])],[96,new Uint8Array([48,24,12,0,0,0,0,0])],[97,new Uint8Array([0,0,60,6,62,102,62,0])],[98,new Uint8Array([96,96,124,102,102,102,124,0])],[99,new Uint8Array([0,0,60,102,96,102,60,0])],[100,new Uint8Array([6,6,62,102,102,102,62,0])],[101,new Uint8Array([0,0,60,102,126,96,60,0])],[102,new Uint8Array([28,54,48,124,48,48,48,0])],[103,new Uint8Array([0,0,62,102,102,62,6,60])],[104,new Uint8Array([96,96,124,102,102,102,102,0])],[105,new Uint8Array([24,0,56,24,24,24,60,0])],[106,new Uint8Array([12,0,28,12,12,12,108,56])],[107,new Uint8Array([96,96,102,108,120,108,102,0])],[108,new Uint8Array([56,24,24,24,24,24,60,0])],[109,new Uint8Array([0,0,102,127,107,107,99,0])],[110,new Uint8Array([0,0,124,102,102,102,102,0])],[111,new Uint8Array([0,0,60,102,102,102,60,0])],[112,new Uint8Array([0,0,124,102,102,124,96,96])],[113,new Uint8Array([0,0,62,102,102,62,6,6])],[114,new Uint8Array([0,0,108,118,96,96,96,0])],[115,new Uint8Array([0,0,62,96,60,6,124,0])],[116,new Uint8Array([48,48,124,48,48,54,28,0])],[117,new Uint8Array([0,0,102,102,102,102,62,0])],[118,new Uint8Array([0,0,102,102,102,60,24,0])],[119,new Uint8Array([0,0,99,107,107,127,54,0])],[120,new Uint8Array([0,0,102,60,24,60,102,0])],[121,new Uint8Array([0,0,102,102,102,62,6,60])],[122,new Uint8Array([0,0,126,12,24,48,126,0])],[123,new Uint8Array([14,24,24,112,24,24,14,0])],[124,new Uint8Array([24,24,24,24,24,24,24,0])],[125,new Uint8Array([112,24,24,14,24,24,112,0])],[126,new Uint8Array([49,107,70,0,0,0,0,0])],[179,new Uint8Array([24,24,24,24,24,24,24,24])],[196,new Uint8Array([0,0,0,255,0,0,0,0])],[218,new Uint8Array([0,0,0,31,24,24,24,24])],[191,new Uint8Array([0,0,0,248,24,24,24,24])],[192,new Uint8Array([24,24,24,31,0,0,0,0])],[217,new Uint8Array([24,24,24,248,0,0,0,0])],[195,new Uint8Array([24,24,24,31,24,24,24,24])],[180,new Uint8Array([24,24,24,248,24,24,24,24])],[194,new Uint8Array([0,0,0,255,24,24,24,24])],[193,new Uint8Array([24,24,24,255,0,0,0,0])],[197,new Uint8Array([24,24,24,255,24,24,24,24])],[186,new Uint8Array([54,54,54,54,54,54,54,54])],[205,new Uint8Array([0,0,0,255,0,255,0,0])],[201,new Uint8Array([0,0,0,63,54,54,54,54])],[187,new Uint8Array([0,0,0,252,54,54,54,54])],[200,new Uint8Array([54,54,54,63,0,0,0,0])],[188,new Uint8Array([54,54,54,252,0,0,0,0])],[204,new Uint8Array([54,54,54,63,54,54,54,54])],[185,new Uint8Array([54,54,54,252,54,54,54,54])],[203,new Uint8Array([0,0,0,255,54,54,54,54])],[202,new Uint8Array([54,54,54,255,0,0,0,0])],[206,new Uint8Array([54,54,54,255,54,54,54,54])],[219,new Uint8Array([255,255,255,255,255,255,255,255])],[178,new Uint8Array([170,85,170,85,170,85,170,85])],[177,new Uint8Array([136,34,136,34,136,34,136,34])],[176,new Uint8Array([34,136,34,136,34,136,34,136])],[223,new Uint8Array([255,255,255,255,0,0,0,0])],[220,new Uint8Array([0,0,0,0,255,255,255,255])],[221,new Uint8Array([240,240,240,240,240,240,240,240])],[222,new Uint8Array([15,15,15,15,15,15,15,15])]]);function Mt(g){return H.get(g)}C(Mt,"getCharBitmap");function Ft(g){return H.has(g)}C(Ft,"hasChar");function Rt(){return Array.from(H.keys()).sort((g,e)=>g-e)}C(Rt,"getAllCharCodes");function Lt(g){let e=Array.from(H.entries()).map(([t,r])=>({charCode:t,bitmap:r}));return{loadType:4,fontId:g,width:8,height:8,cellWidth:8,cellHeight:8,characters:e}}C(Lt,"createASCII8x8FontLoad");function Pt(){return{charWidth:8,charHeight:8,glyphs:new Map(H)}}C(Pt,"getASCII8x8FontConfig");function Tt(g,e,t,r,n,o,i,s=[]){let a=Array.from(e.entries()).sort((v,w)=>v[0]-w[0]),d=Array.from(t.entries()).sort((v,w)=>v[0]-w[0]),u=a.length,c=d.length,l=be(u,c),p=new TextEncoder,h=s.map(v=>p.encode(v)),m=1+h.reduce((v,w)=>v+1+w.length,0),b=l+m,f=new Uint8Array(b),U=new DataView(f.buffer),y=0;U.setBigUint64(y,g,!0),y+=8;for(let[,v]of a){let w=ge(v);f[y]=w+256&255,y+=1}let O=Y(c);for(let v=0;v<O;v++){let w=0;for(let M=0;M<8;M++){let pe=v*8+M;if(pe<c){let[,I]=d[pe];I&&(w|=1<<M)}}f[y]=w,y+=1}f[y]=r&255,y+=1,f[y]=n&255,y+=1,f[y]=o&255,y+=1;let B=0;i&&(B|=1),f[y]=B,y+=1,f[y]=Math.min(s.length,255),y+=1;for(let v of h)f[y]=Math.min(v.length,255),y+=1,f.set(v.slice(0,255),y),y+=v.length;return f}C(Tt,"encodeCompressedInput");var A=class A{static toCharCode(e){if(typeof e=="number")return e&255;let t=e.charCodeAt(0);return ue(t)}static dedent(e){let t=e.split(`
8
+ `);if(t.length>0&&t[0].trim()===""&&t.shift(),t.length>0&&t[t.length-1].trim()===""&&t.pop(),t.length===0)return"";let r=t.filter(o=>o.trim().length>0);if(r.length===0)return"";let n=Math.min(...r.map(o=>{let i=o.match(/^(\s*)/);return i?i[1].length:0}));return t.map(o=>o.slice(n)).join(`
9
+ `)}static char(e,t,r,n=15,o=0){return{type:1,posX:e,posY:t,charCode:A.toCharCode(r),bgColorCode:o,fgColorCode:n}}static text(e,t,r,n=15,o=0){return{type:2,posX:e,posY:t,text:r,bgColorCode:o,fgColorCode:n}}static textMultiline(e,t,r,n=15,o=0){return{type:23,posX:e,posY:t,text:A.dedent(r),bgColorCode:o,fgColorCode:n}}static subFrame(e,t,r,n,o,i=15,s=0){return{type:3,posX:e,posY:t,sizeX:r,sizeY:n,frame:o.map(a=>A.toCharCode(a)),bgColorCode:s,fgColorCode:i}}static subFrameMultiColor(e,t,r,n,o){return{type:4,posX:e,posY:t,sizeX:r,sizeY:n,frame:o.map(i=>({charCode:A.toCharCode(i.charCode),bgColorCode:i.bgColorCode,fgColorCode:i.fgColorCode}))}}static fullFrame(e,t=15,r=0){return{type:5,frame:e.map(n=>A.toCharCode(n)),bgColorCode:r,fgColorCode:t}}static fullFrameMultiColor(e){return{type:6,frame:e.map(t=>({charCode:A.toCharCode(t.charCode),bgColorCode:t.bgColorCode,fgColorCode:t.fgColorCode}))}}static sprite(e,t,r,n=15,o=0){return{type:7,posX:e,posY:t,spriteIndex:r,bgColorCode:o,fgColorCode:n}}static spriteMultiColor(e,t,r){return{type:8,posX:e,posY:t,spriteIndex:r}}static colorMap(e,t,r,n,o){return{type:9,posX:e,posY:t,sizeX:r,sizeY:n,colorData:o}}static rectangle(e,t,r,n,o={}){return{type:10,shapeType:1,shapeData:{posX:e,posY:t,width:r,height:n,filled:o.filled??!0,charCode:A.toCharCode(o.charCode??9608),bgColorCode:o.bgColor??0,fgColorCode:o.fgColor??15}}}static circle(e,t,r,n={}){return{type:10,shapeType:2,shapeData:{centerX:e,centerY:t,radius:r,filled:n.filled??!0,charCode:A.toCharCode(n.charCode??9608),bgColorCode:n.bgColor??0,fgColorCode:n.fgColor??15}}}static line(e,t,r,n,o={}){return{type:10,shapeType:3,shapeData:{x1:e,y1:t,x2:r,y2:n,charCode:A.toCharCode(o.charCode??9608),bgColorCode:o.bgColor??0,fgColorCode:o.fgColor??15}}}static ellipse(e,t,r,n,o={}){return{type:10,shapeType:4,shapeData:{centerX:e,centerY:t,radiusX:r,radiusY:n,filled:o.filled??!0,charCode:A.toCharCode(o.charCode??9608),bgColorCode:o.bgColor??0,fgColorCode:o.fgColor??15}}}static triangle(e,t,r,n,o,i,s={}){return{type:10,shapeType:5,shapeData:{x1:e,y1:t,x2:r,y2:n,x3:o,y3:i,filled:s.filled??!0,charCode:A.toCharCode(s.charCode??9608),bgColorCode:s.bgColor??0,fgColorCode:s.fgColor??15}}}static dotCloud(e,t,r=15,n=0){return{type:11,charCode:A.toCharCode(t),bgColorCode:n,fgColorCode:r,positions:e}}static dotCloudMultiColor(e){return{type:12,dots:e.map(t=>({...t,charCode:A.toCharCode(t.charCode)}))}}static bitmask(e,t,r,n,o,i,s=15,a=0,d=!1){let u=r*n,c=Math.ceil(u/8),l=new Uint8Array(c);for(let p=0;p<u;p++)if(o[p]){let h=Math.floor(p/8),m=p%8;l[h]|=1<<m}return{type:17,posX:e,posY:t,sizeX:r,sizeY:n,charCode:A.toCharCode(i),bgColorCode:a,fgColorCode:s,override:d,mask:l}}static bitmask4(e,t,r,n,o,i,s=!1){let a={char:"?",fgColor:15,bgColor:0},d=[i[0]??a,i[1]??a,i[2]??a],u=r*n,c=Math.ceil(u/4),l=new Uint8Array(c);for(let p=0;p<u;p++){let h=o[p]&3,m=Math.floor(p/4),b=p%4*2;l[m]|=h<<b}return{type:18,posX:e,posY:t,sizeX:r,sizeY:n,override:s,variants:[{charCode:A.toCharCode(d[0].char),fgColorCode:d[0].fgColor,bgColorCode:d[0].bgColor},{charCode:A.toCharCode(d[1].char),fgColorCode:d[1].fgColor,bgColorCode:d[1].bgColor},{charCode:A.toCharCode(d[2].char),fgColorCode:d[2].fgColor,bgColorCode:d[2].bgColor}],mask:l}}static bitmask16(e,t,r,n,o,i,s=!1){let a={char:"?",fgColor:15,bgColor:0},d=[];for(let p=0;p<15;p++)d.push(i[p]??a);let u=r*n,c=Math.ceil(u/2),l=new Uint8Array(c);for(let p=0;p<u;p++){let h=o[p]&15,m=Math.floor(p/2),b=p%2*4;l[m]|=h<<b}return{type:24,posX:e,posY:t,sizeX:r,sizeY:n,override:s,variants:d.map(p=>({charCode:A.toCharCode(p.char),fgColorCode:p.fgColor,bgColorCode:p.bgColor})),mask:l}}static spriteCloud(e,t,r=15,n=0){return{type:13,spriteIndex:e,bgColorCode:n,fgColorCode:r,positions:t}}static spriteCloudMultiColor(e,t){return{type:14,spriteIndex:e,positions:t}}static spriteCloudVaried(e){return{type:15,sprites:e}}static spriteCloudVariedMultiColor(e){return{type:16,sprites:e}}static clear(e=32,t=15,r=0){return{type:19,charCode:A.toCharCode(e),bgColorCode:r,fgColorCode:t}}static fillChar(e,t,r,n=15,o=0){return{type:20,patternWidth:e,patternHeight:t,pattern:r.map(i=>A.toCharCode(i)),bgColorCode:o,fgColorCode:n}}static fillSprite(e,t=15,r=0){return{type:21,spriteIndex:e,bgColorCode:r,fgColorCode:t}}static fillSpriteMultiColor(e){return{type:22,spriteIndex:e}}static boxWithBorder(e,t,r,n,o,i){return[this.rectangle(e+1,t+1,r-2,n-2,{charCode:i.charCode??9608,bgColor:i.bgColor??0,fgColor:i.fgColor??8,filled:!0}),this.rectangle(e,t,r,n,{charCode:o.charCode??9608,bgColor:o.bgColor??0,fgColor:o.fgColor??15,filled:!1})]}static grid(e,t,r,n,o,i,s={}){let a=[];for(let d=0;d<=o;d++)for(let u=0;u<=i;u++)a.push({posX:e+u*r,posY:t+d*n});return this.dotCloud(a,s.charCode??"+",s.fgColor??15,s.bgColor??0)}};C(A,"OrderBuilder");var Fe=A;var Ct=(I=>(I[I.Char=1]="Char",I[I.Text=2]="Text",I[I.TextMultiline=23]="TextMultiline",I[I.SubFrame=3]="SubFrame",I[I.SubFrameMultiColor=4]="SubFrameMultiColor",I[I.FullFrame=5]="FullFrame",I[I.FullFrameMultiColor=6]="FullFrameMultiColor",I[I.Sprite=7]="Sprite",I[I.SpriteMultiColor=8]="SpriteMultiColor",I[I.ColorMap=9]="ColorMap",I[I.Shape=10]="Shape",I[I.DotCloud=11]="DotCloud",I[I.DotCloudMultiColor=12]="DotCloudMultiColor",I[I.SpriteCloud=13]="SpriteCloud",I[I.SpriteCloudMultiColor=14]="SpriteCloudMultiColor",I[I.SpriteCloudVaried=15]="SpriteCloudVaried",I[I.SpriteCloudVariedMultiColor=16]="SpriteCloudVariedMultiColor",I[I.Bitmask=17]="Bitmask",I[I.Bitmask4=18]="Bitmask4",I[I.Bitmask16=24]="Bitmask16",I[I.Clear=19]="Clear",I[I.FillChar=20]="FillChar",I[I.FillSprite=21]="FillSprite",I[I.FillSpriteMultiColor=22]="FillSpriteMultiColor",I[I.TriggerSound=32]="TriggerSound",I[I.TriggerGlobalSound=33]="TriggerGlobalSound",I))(Ct||{});function Dt(g){return g>=1&&g<=2||g>=3&&g<=6||g>=7&&g<=8||g>=9&&g<=10||g>=11&&g<=18||g>=19&&g<=23||g===24||g>=32&&g<=33}C(Dt,"isValidOrderType");function Xt(g){switch(g){case 1:return"Char";case 2:return"Text";case 3:return"SubFrame";case 4:return"SubFrameMultiColor";case 5:return"FullFrame";case 6:return"FullFrameMultiColor";case 7:return"Sprite";case 8:return"SpriteMultiColor";case 9:return"ColorMap";case 10:return"Shape";case 11:return"DotCloud";case 12:return"DotCloudMultiColor";case 13:return"SpriteCloud";case 14:return"SpriteCloudMultiColor";case 15:return"SpriteCloudVaried";case 16:return"SpriteCloudVariedMultiColor";case 17:return"Bitmask";case 18:return"Bitmask4";case 24:return"Bitmask16";case 19:return"Clear";case 20:return"FillChar";case 21:return"FillSprite";case 22:return"FillSpriteMultiColor";case 32:return"TriggerSound";case 33:return"TriggerGlobalSound";default:return`Unknown(0x${g.toString(16)})`}}C(Xt,"getOrderTypeName");We();T();It();var bt=(l=>(l[l.LayerEnabled=1]="LayerEnabled",l[l.SetMode=2]="SetMode",l[l.UpdatePosition=4]="UpdatePosition",l[l.UpdateZOrder=8]="UpdateZOrder",l[l.Disabled=0]="Disabled",l[l.EnabledAddMode=1]="EnabledAddMode",l[l.EnabledSetMode=3]="EnabledSetMode",l[l.EnabledAddMoveOnly=5]="EnabledAddMoveOnly",l[l.EnabledSetMoveOnly=7]="EnabledSetMoveOnly",l[l.EnabledAddReorderOnly=9]="EnabledAddReorderOnly",l[l.EnabledSetReorderOnly=11]="EnabledSetReorderOnly",l[l.FullUpdate=15]="FullUpdate",l))(bt||{}),Re;(u=>{function g(c,l){return(c&l)!==0}u.hasFlag=g,C(g,"hasFlag");function e(c,l){return c|l}u.addFlag=e,C(e,"addFlag");function t(c,l){return c&~l}u.removeFlag=t,C(t,"removeFlag");function r(...c){return c.reduce((l,p)=>l|p,0)}u.combine=r,C(r,"combine");function n(c){return(c&240)===0}u.isValid=n,C(n,"isValid");function o(c){return g(c,1)}u.isEnabled=o,C(o,"isEnabled");function i(c){return g(c,2)}u.isSetMode=i,C(i,"isSetMode");function s(c){return g(c,4)}u.hasPositionChanged=s,C(s,"hasPositionChanged");function a(c){return g(c,8)}u.hasZOrderChanged=a,C(a,"hasZOrderChanged");function d(c){if(c===0)return"Disabled";let l=[];return g(c,1)?l.push("Enabled"):l.push("Disabled"),g(c,2)?l.push("SET"):l.push("ADD"),g(c,4)&&l.push("Position"),g(c,8)&&l.push("ZOrder"),l.join(" | ")}u.describe=d,C(d,"describe")})(Re||(Re={}));pt();$e();lt();