@utsp/core 0.4.0-nightly.20251201222332.2d9d7a5 → 0.4.0
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 +4 -4
- package/dist/index.d.ts +603 -3
- package/dist/index.mjs +4 -4
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var $=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var ut=Object.getOwnPropertyNames;var pt=Object.prototype.hasOwnProperty;var ht=(m,e,t)=>e in m?$(m,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):m[e]=t;var g=(m,e)=>$(m,"name",{value:e,configurable:!0});var F=(m,e)=>()=>(m&&(e=m(m=0)),e);var se=(m,e)=>{for(var t in e)$(m,t,{get:e[t],enumerable:!0})},xt=(m,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ut(e))!pt.call(m,n)&&n!==t&&$(m,n,{get:()=>e[n],enumerable:!(r=ct(e,n))||r.enumerable});return m};var M=m=>xt($({},"__esModule",{value:!0}),m);var x=(m,e,t)=>(ht(m,typeof e!="symbol"?e+"":e,t),t);var Qe,et=F(()=>{"use strict";Qe=(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))(Qe||{})});var E,S,T=F(()=>{"use strict";E=class E{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 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");S=E});var Pe,me,rt=F(()=>{"use strict";Pe=class Pe{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,l=e.readUInt8(n++)+1;return{display:{id:o,originX:s,originY:i,sizeX:a,sizeY:l},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(Pe,"DisplayDecoder");me=Pe});var We,Ce,nt=F(()=>{"use strict";We=class We{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 l=0;l<s;l++)i.push(e.readUInt8(r+7+l));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 l=0;l<s;l++){let d=r+5+l*3;i.push({charCode:e.readUInt8(d),bgColorCode:e.readUInt8(d+1),fgColorCode:e.readUInt8(d+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 l=n+1+a*3;s.push({charCode:e.readUInt8(l),bgColorCode:e.readUInt8(l+1),fgColorCode:e.readUInt8(l+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 l=0;l<s;l++){let d=r+5+l*2;i.push({bgColorCode:e.readUInt8(d),fgColorCode:e.readUInt8(d+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 l=0;l<s;l++)i[l]=e.readUInt8(r+9+l);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 d=0;d<s;d++)a[d]=e.readUInt8(r+15+d);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 d=0;d<15;d++){let u=r+6+d*3;i.push({charCode:e.readUInt8(u),bgColorCode:e.readUInt8(u+1),fgColorCode:e.readUInt8(u+2)})}let a=new Uint8Array(s);for(let d=0;d<s;d++)a[d]=e.readUInt8(r+51+d);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 l=0;l<s;l++)i.push(e.readUInt8(r+5+l));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(We,"OrderDecoder");Ce=We});var _e,ge,ot=F(()=>{"use strict";nt();_e=class _e{constructor(){x(this,"orderDecoder");this.orderDecoder=new Ce}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 l=e.readUInt16BE(n);n+=2;let d=e.readUInt16BE(n);n+=2;let u=e.readUInt16BE(n);n+=2;let c=e.readUInt8(n++),p=[],h=n;for(let y=0;y<c;y++){let U=this.orderDecoder.decode(e,h);p.push(U.order),h+=U.bytesRead}return{layer:{id:o,updateFlags:s,zIndex:i,originX:a,originY:l,width:d,height:u,orderCount:c,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(_e,"LayerDecoder");ge=_e});var it={};se(it,{UpdatePacketDecoder:()=>be});var Ne,be,He=F(()=>{"use strict";rt();ot();T();Ne=class Ne{constructor(){x(this,"displayDecoder");x(this,"layerDecoder");this.displayDecoder=new me,this.layerDecoder=new ge}decode(e,t=0){let r=S.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 c=0;c<i;c++){let p=this.displayDecoder.decode(r,o);a.push(p.display),o+=p.bytesRead}this.checkSize(r,o,2);let l=r.readUInt16BE(o);o+=2;let d=[];for(let c=0;c<l;c++){let p=this.layerDecoder.decode(r,o);d.push(p.layer),o+=p.bytesRead}return{tick:s,displayCount:i,displays:a,layerCount:l,layers:d}}isValid(e,t=0){let r=S.from(e);try{return this.checkSize(r,t,11),!0}catch{return!1}}decodeHeader(e,t=0){let r=S.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(Ne,"UpdatePacketDecoder");be=Ne});var Y={};se(Y,{LoadType:()=>Ve});var Ve,R=F(()=>{"use strict";Ve=(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))(Ve||{})});var st={};se(st,{LoadDecoder:()=>$e});var Ze,$e,at=F(()=>{"use strict";T();Ze=class Ze{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 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 l=e.readUInt8(t++),d=e.readUInt8(t++),u=e.readUInt8(t++),c=d*u;this.checkSize(e,t,c,`Sprite ${a} data`);let p=[];for(let h=0;h<c;h++)p.push(e.readUInt8(t++));s.push({spriteId:l,sizeX:d,sizeY:u,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 l=e.readUInt8(t++),d=e.readUInt8(t++),u=e.readUInt8(t++),c=d*u,p=c*3;this.checkSize(e,t,p,`MulticolorSprite ${a} data`);let h=[];for(let C=0;C<c;C++)h.push({charCode:e.readUInt8(t++),fgColorId:e.readUInt8(t++),bgColorId:e.readUInt8(t++)});s.push({spriteId:l,sizeX:d,sizeY:u,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++),l=e.readUInt8(t++),d=e.readUInt8(t++),u=Math.ceil(s*i/8),c=[];for(let h=0;h<d;h++){this.checkSize(e,t,1+u,`BitmapFont character ${h}`);let C=e.readUInt8(t++),y=new Uint8Array(u);for(let U=0;U<u;U++)y[U]=e.readUInt8(t++);c.push({charCode:C,bitmap:y})}return{load:{loadType:4,fontId:o,width:s,height:i,cellWidth:a,cellHeight:l,characters:c},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 l=e.readUInt8(t++),d=e.readUInt16BE(t);t+=2,this.checkSize(e,t,d,`Sound ${a} MIDI data`);let u=new Uint8Array(d);for(let c=0;c<d;c++)u[c]=e.readUInt8(t++);s.push({soundId:l,midiData:u})}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 l=new Uint8Array(a);for(let p=0;p<a;p++)l[p]=e.readUInt8(t++);let d=n.decode(l);this.checkSize(e,t,2,"WebFont fontSize");let u=e.readUInt16BE(t);t+=2;let c={loadType:6,fontId:s,fontFamily:d,fontSize:u};if(i&1&&(this.checkSize(e,t,2,"WebFont offsetX"),c.offsetX=e.readInt16BE(t),t+=2),i&2&&(this.checkSize(e,t,2,"WebFont offsetY"),c.offsetY=e.readInt16BE(t),t+=2),i&4&&(this.checkSize(e,t,2,"WebFont charSpacing"),c.charSpacing=e.readInt16BE(t),t+=2),i&8){this.checkSize(e,t,2,"WebFont lineHeight");let p=e.readUInt16BE(t);c.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++);c.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++);c.fontStyle=n.decode(h)}return{load:c,bytesRead:t-r}}};g(Ze,"LoadDecoder");$e=Ze});var _={};se(_,{LoadEncoder:()=>Ge});var je,Ge,N=F(()=>{"use strict";T();je=class je{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 s of e.sprites)r+=3,r+=s.data.length;let n=S.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=S.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=S.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=S.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=S.allocUnsafe(i),l=0;a.writeUInt8(6,l++),a.writeUInt8(e.fontId,l++),a.writeUInt8(s,l++),a.writeUInt8(r.length,l++);for(let d=0;d<r.length;d++)a.writeUInt8(r[d],l++);if(a.writeUInt16BE(e.fontSize,l),l+=2,e.offsetX!==void 0&&(a.writeInt16BE(e.offsetX,l),l+=2),e.offsetY!==void 0&&(a.writeInt16BE(e.offsetY,l),l+=2),e.charSpacing!==void 0&&(a.writeInt16BE(e.charSpacing,l),l+=2),e.lineHeight!==void 0&&(a.writeUInt16BE(Math.round(e.lineHeight*100),l),l+=2),e.fontWeight!==void 0){a.writeUInt8(n.length,l++);for(let d=0;d<n.length;d++)a.writeUInt8(n[d],l++)}if(e.fontStyle!==void 0){a.writeUInt8(o.length,l++);for(let d=0;d<o.length;d++)a.writeUInt8(o[d],l++)}return a.toUint8Array()}};g(je,"LoadEncoder");Ge=je});import{Vector2 as ae}from"@utsp/types";var ye=class ye{constructor(e=0,t=60,r=40){x(this,"id");x(this,"origin");x(this,"size");x(this,"previousOrigin",new ae(0,0));x(this,"previousSize",new ae(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 ae(0,0),this.size=new ae(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(ye,"Display");var Z=ye;var le=256,sr=65536,k=255,ar=9,lr=5,dr=13,mt=6,Ct=6,gt=6,bt=7,yt=5,It=3,St=1,Ut=6,ft=4,wt=5,Ot=2,vt=8,Bt=7,At=7,kt=8,Mt=10,zt=6,Ft=3,Et=9,Rt=15,Lt=51,Dt=6,Tt=4,Xt=3,Yt=3,Pt=4,Wt=5,_t=4,Nt=2,Ht=5,Vt=3;var Ie=class Ie{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 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(Ie,"CellBuffer");var L=Ie,Se=class Se{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}};g(Se,"CharCodeBuffer");var G=Se;import{Vector2 as Zt}from"@utsp/types";var $t=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 j(m){if(m<128)return m;let e=$t.get(m);return e!==void 0?e:m&255}g(j,"unicodeToCp437");var Ue=class Ue{constructor(){x(this,"currentWidth",256);x(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 l=r+a;if(l>=this.currentWidth)break;let d=n*this.currentWidth+l,u=o.charCodeAt(a),c=j(u);t.set(d,c,i,s)}}rasterizeTextMultiline(e,t){let{posX:r,posY:n,text:o,bgColorCode:s,fgColorCode:i}=e,a=o.split(`
|
|
2
|
-
`),l=n;for(let d of a){if(l>=this.currentHeight)break;if(l>=0&&this.isInBounds(r,l))for(let u=0;u<d.length;u++){let c=r+u;if(c>=this.currentWidth)break;let p=l*this.currentWidth+c,h=d.charCodeAt(u),C=j(h);t.set(p,C,i,s)}l++}}rasterizeSubFrame(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,frame:i,bgColorCode:a,fgColorCode:l}=e;for(let d=0;d<s;d++){let u=n+d;if(!(u<0||u>=this.currentHeight))for(let c=0;c<o;c++){let p=r+c;if(p<0||p>=this.currentWidth)continue;let h=d*o+c;if(h>=i.length)break;let C=u*this.currentWidth+p;t.set(C,i[h],l,a)}}}rasterizeSubFrameMultiColor(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,frame:i}=e;for(let a=0;a<s;a++){let l=n+a;if(!(l<0||l>=this.currentHeight))for(let d=0;d<o;d++){let u=r+d;if(u<0||u>=this.currentWidth)continue;let c=a*o+d;if(c>=i.length)break;let p=i[c],h=l*this.currentWidth+u;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 l=n+a;if(!(l<0||l>=this.currentHeight))for(let d=0;d<o;d++){let u=r+d;if(u<0||u>=this.currentWidth)continue;let c=a*o+d;if(c>=i.length)break;let p=l*this.currentWidth+u,h=i[c];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:l,fgColorCode:d}=e;if(i)for(let u=0;u<s;u++){let c=n+u;if(!(c<0||c>=this.currentHeight))for(let p=0;p<o;p++){let h=r+p;if(h<0||h>=this.currentWidth)continue;let C=c*this.currentWidth+h;t.set(C,a,d,l)}}else{for(let u=0;u<o;u++)this.setCell(r+u,n,a,l,d,t),this.setCell(r+u,n+s-1,a,l,d,t);for(let u=0;u<s;u++)this.setCell(r,n+u,a,l,d,t),this.setCell(r+o-1,n+u,a,l,d,t)}}rasterizeCircle(e,t){let{centerX:r,centerY:n,radius:o,filled:s,charCode:i,bgColorCode:a,fgColorCode:l}=e;if(s)for(let d=-o;d<=o;d++){let u=n+d;if(!(u<0||u>=this.currentHeight))for(let c=-o;c<=o;c++){let p=r+c;if(!(p<0||p>=this.currentWidth)&&c*c+d*d<=o*o){let h=u*this.currentWidth+p;t.set(h,i,l,a)}}}else{let d=o,u=0,c=0;for(;d>=u;)this.setCell(r+d,n+u,i,a,l,t),this.setCell(r+u,n+d,i,a,l,t),this.setCell(r-u,n+d,i,a,l,t),this.setCell(r-d,n+u,i,a,l,t),this.setCell(r-d,n-u,i,a,l,t),this.setCell(r-u,n-d,i,a,l,t),this.setCell(r+u,n-d,i,a,l,t),this.setCell(r+d,n-u,i,a,l,t),c<=0&&(u+=1,c+=2*u+1),c>0&&(d-=1,c-=2*d+1)}}rasterizeLine(e,t){let{x1:r,y1:n,x2:o,y2:s,charCode:i,bgColorCode:a,fgColorCode:l}=e,d=Math.abs(o-r),u=Math.abs(s-n),c=r<o?1:-1,p=n<s?1:-1,h=d-u,C=r,y=n;for(;this.setCell(C,y,i,a,l,t),!(C===o&&y===s);){let U=2*h;U>-u&&(h-=u,C+=c),U<d&&(h+=d,y+=p)}}rasterizeEllipse(e,t){let{centerX:r,centerY:n,radiusX:o,radiusY:s,filled:i,charCode:a,bgColorCode:l,fgColorCode:d}=e;if(i)for(let u=-s;u<=s;u++){let c=n+u;if(!(c<0||c>=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)+u*u/(s*s)<=1){let y=c*this.currentWidth+h;t.set(y,a,d,l)}}}else{let u=Math.max(o,s)*8;for(let c=0;c<u;c++){let p=2*Math.PI*c/u,h=Math.round(r+o*Math.cos(p)),C=Math.round(n+s*Math.sin(p));this.setCell(h,C,a,l,d,t)}}}rasterizeTriangle(e,t){let{x1:r,y1:n,x2:o,y2:s,x3:i,y3:a,filled:l,charCode:d,bgColorCode:u,fgColorCode:c}=e;if(l){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,U=g((b,v,A)=>{let O=Math.round(Math.min(v,A)),w=Math.round(Math.max(v,A));for(let z=O;z<=w;z++)if(z>=0&&z<this.currentWidth&&b>=0&&b<this.currentHeight){let ie=b*this.currentWidth+z;t.set(ie,d,c,u)}},"drawLine"),f=g((b,v,A,O,w)=>O===v?A:A+(b-v)*(w-A)/(O-v),"interpolate");for(let b=h.y;b<=C.y;b++){let v=f(b,h.y,h.x,y.y,y.x),A=f(b,h.y,h.x,C.y,C.x);U(b,v,A)}for(let b=C.y+1;b<=y.y;b++){let v=f(b,h.y,h.x,y.y,y.x),A=f(b,C.y,C.x,y.y,y.x);U(b,v,A)}}else this.drawLineSegment(r,n,o,s,d,u,c,t),this.drawLineSegment(o,s,i,a,d,u,c,t),this.drawLineSegment(i,a,r,n,d,u,c,t)}drawLineSegment(e,t,r,n,o,s,i,a){let l=Math.abs(r-e),d=Math.abs(n-t),u=e<r?1:-1,c=t<n?1:-1,p=l-d,h=e,C=t;for(;this.setCell(h,C,o,s,i,a),!(h===r&&C===n);){let y=2*p;y>-d&&(p-=d,h+=u),y<l&&(p+=l,C+=c)}}rasterizeDotCloud(e,t){let{charCode:r,bgColorCode:n,fgColorCode:o,positions:s}=e,i=t.getRawData(),a=this.currentWidth;for(let l=0;l<s.length;l++){if(s[l].posX<0||s[l].posX>=a||s[l].posY<0||s[l].posY>=this.currentHeight)continue;let d=(s[l].posY*a+s[l].posX)*3;i[d]=r,i[d+1]=o,i[d+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:l,override:d,mask:u}=e;for(let c=0;c<s;c++){let p=n+c;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=c*o+h,U=Math.floor(y/8),f=y%8,b=(u[U]&1<<f)!==0,v=p*this.currentWidth+C;b?t.set(v,i,l,a):d&&t.set(v,255,255,255)}}}rasterizeBitmask4(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,override:i,variants:a,mask:l}=e;for(let d=0;d<s;d++){let u=n+d;if(!(u<0||u>=this.currentHeight))for(let c=0;c<o;c++){let p=r+c;if(p<0||p>=this.currentWidth)continue;let h=d*o+c,C=Math.floor(h/4),y=h%4*2,U=l[C]>>y&3,f=u*this.currentWidth+p;if(U>0){let b=a[U-1];t.set(f,b.charCode,b.fgColorCode,b.bgColorCode)}else i&&t.set(f,255,255,255)}}}rasterizeBitmask16(e,t){let{posX:r,posY:n,sizeX:o,sizeY:s,override:i,variants:a,mask:l}=e;for(let d=0;d<s;d++){let u=n+d;if(!(u<0||u>=this.currentHeight))for(let c=0;c<o;c++){let p=r+c;if(p<0||p>=this.currentWidth)continue;let h=d*o+c,C=Math.floor(h/2),y=h%2*4,U=l[C]>>y&15,f=u*this.currentWidth+p;if(U>0){let b=a[U-1];t.set(f,b.charCode,b.fgColorCode,b.bgColorCode)}else i&&t.set(f,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 l=0;l<this.currentWidth;l++){let d=l%r,c=a%n*r+d;if(c<o.length){let p=a*this.currentWidth+l;t.set(p,o[c],i,s)}}}rasterizeSprite(e,t,r){if(!r)return;let{posX:n,posY:o,spriteIndex:s,bgColorCode:i,fgColorCode:a}=e,l=r.getUnicolorSprite(s);if(!l)return;let d=l.data;for(let u=0;u<l.sizeY;u++)for(let c=0;c<l.sizeX;c++){let p=n+c,h=o+u;if(!this.isInBounds(p,h))continue;let C=u*l.sizeX+c,y=d.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 l=0;l<i.sizeY;l++)for(let d=0;d<i.sizeX;d++){let u=n+d,c=o+l;if(!this.isInBounds(u,c))continue;let p=l*i.sizeX+d,h=a.getCharCode(p),C=a.getFgColorCode(p),y=a.getBgColorCode(p);this.setCell(u,c,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 l=a.data.get(0),d=t.getRawData(),u=this.currentWidth;for(let c=0;c<i.length;c++){if(i[c].posX<0||i[c].posX>=u||i[c].posY<0||i[c].posY>=this.currentHeight)continue;let p=(i[c].posY*u+i[c].posX)*3;d[p]=l,d[p+1]=s,d[p+2]=o}return}for(let l=0;l<i.length;l++){let d=a.data;for(let u=0;u<a.sizeY;u++)for(let c=0;c<a.sizeX;c++){let p=i[l].posX+c,h=i[l].posY+u;if(!this.isInBounds(p,h))continue;let C=u*a.sizeX+c,y=d.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 l=0;l<s.sizeY;l++)for(let d=0;d<s.sizeX;d++){let u=o[i].posX+d,c=o[i].posY+l;if(!this.isInBounds(u,c))continue;let p=l*s.sizeX+d,h=a.getCharCode(p),C=a.getFgColorCode(p),y=a.getBgColorCode(p);this.setCell(u,c,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 l=0;l<i.sizeY;l++)for(let d=0;d<i.sizeX;d++){let u=s.posX+d,c=s.posY+l;if(!this.isInBounds(u,c))continue;let p=l*i.sizeX+d,h=a.get(p);this.setCell(u,c,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 l=0;l<i.sizeY;l++)for(let d=0;d<i.sizeX;d++){let u=s.posX+d,c=s.posY+l;if(!this.isInBounds(u,c))continue;let p=l*i.sizeX+d,h=a.getCharCode(p),C=a.getFgColorCode(p),y=a.getBgColorCode(p);this.setCell(u,c,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 l=0;l<this.currentHeight;l++)for(let d=0;d<this.currentWidth;d++){let u=d%i.sizeX,p=l%i.sizeY*i.sizeX+u,h=a.get(p),C=l*this.currentWidth+d;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 l=a%o.sizeX,u=i%o.sizeY*o.sizeX+l,c=s.getCharCode(u),p=s.getFgColorCode(u),h=s.getBgColorCode(u),C=i*this.currentWidth+a;t.set(C,c,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(Ue,"LayerRasterizer");var de=Ue;var D=class D{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 L(r*n),this.previousOrigin=new Zt(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")&&D.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")&&D.rasterizer.rasterizeOrders(e,this.data,this.width,this.height,"set",this.spriteRegistry)}clearOrders(){this.orders=[],(this.mode==="client"||this.mode==="standalone")&&D.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(D,"Layer"),x(D,"rasterizer",new de);var K=D;var fe=class fe{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,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,l=s.deadzone??0;Math.abs(a)<l?a=0:a=(a>0?1:-1)*((Math.abs(a)-l)/(1-l));let d=s.scale??1;a*=d;let u=s.sensitivity??1;a*=u,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
|
+
var V=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var xt=Object.prototype.hasOwnProperty;var Ct=(x,e,t)=>e in x?V(x,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):x[e]=t;var g=(x,e)=>V(x,"name",{value:e,configurable:!0}),Se=(x=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(x,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):x)(function(x){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+x+'" is not supported')});var F=(x,e)=>()=>(x&&(e=x(x=0)),e);var ae=(x,e)=>{for(var t in e)V(x,t,{get:e[t],enumerable:!0})},gt=(x,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of mt(e))!xt.call(x,n)&&n!==t&&V(x,n,{get:()=>e[n],enumerable:!(r=ht(e,n))||r.enumerable});return x};var M=x=>gt(V({},"__esModule",{value:!0}),x);var m=(x,e,t)=>(Ct(x,typeof e!="symbol"?e+"":e,t),t);var rt,nt=F(()=>{"use strict";rt=(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))(rt||{})});var E,I,T=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 Ne,Ce,it=F(()=>{"use strict";Ne=class Ne{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(Ne,"DisplayDecoder");Ce=Ne});var $e,ge,st=F(()=>{"use strict";$e=class $e{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($e,"OrderDecoder");ge=$e});var He,be,at=F(()=>{"use strict";st();He=class He{constructor(){m(this,"orderDecoder");this.orderDecoder=new ge}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(He,"LayerDecoder");be=He});var dt={};ae(dt,{UpdatePacketDecoder:()=>ye});var Ve,ye,Ze=F(()=>{"use strict";it();at();T();Ve=class Ve{constructor(){m(this,"displayDecoder");m(this,"layerDecoder");this.displayDecoder=new Ce,this.layerDecoder=new be}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(Ve,"UpdatePacketDecoder");ye=Ve});var X={};ae(X,{LoadType:()=>Ge});var Ge,R=F(()=>{"use strict";Ge=(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))(Ge||{})});var lt={};ae(lt,{LoadDecoder:()=>je});var qe,je,ut=F(()=>{"use strict";T();qe=class qe{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(qe,"LoadDecoder");je=qe});var _={};ae(_,{LoadEncoder:()=>Ke});var Je,Ke,N=F(()=>{"use strict";T();Je=class Je{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(Je,"LoadEncoder");Ke=Je});import{Vector2 as de}from"@utsp/types";var Ie=class Ie{constructor(e=0,t=60,r=40){m(this,"id");m(this,"origin");m(this,"size");m(this,"previousOrigin",new de(0,0));m(this,"previousSize",new de(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 de(0,0),this.size=new de(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(Ie,"Display");var Z=Ie;var le=256,lr=65536,k=255,ur=9,cr=5,pr=13,bt=6,yt=6,St=6,It=7,ft=5,Ut=3,wt=1,Ot=6,vt=4,At=5,Bt=2,kt=8,Mt=7,zt=7,Ft=8,Et=10,Rt=6,Lt=3,Dt=9,Tt=15,Pt=51,Xt=6,Yt=4,Wt=3,_t=3,Nt=4,$t=5,Ht=4,Vt=2,Zt=5,Gt=3;var fe=class fe{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(fe,"CellBuffer");var L=fe,Ue=class Ue{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(Ue,"CharCodeBuffer");var G=Ue;import{Vector2 as qt}from"@utsp/types";var jt=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 j(x){if(x<128)return x;let e=jt.get(x);return e!==void 0?e:x&255}g(j,"unicodeToCp437");var we=class we{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=j(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=j(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 se=b*this.currentWidth+z;t.set(se,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(we,"LayerRasterizer");var ue=we;var D=class D{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 L(r*n),this.previousOrigin=new qt(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")&&D.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")&&D.rasterizer.rasterizeOrders(e,this.data,this.width,this.height,"set",this.spriteRegistry)}clearOrders(){this.orders=[],(this.mode==="client"||this.mode==="standalone")&&D.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(D,"Layer"),m(D,"rasterizer",new ue);var q=D;var Oe=class Oe{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})
|
|
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(fe,"InputBindingRegistry");var q=fe;function we(m=0n){return{tick:m,axes:new Map,buttons:new Map,displayId:0,mouseX:0,mouseY:0,mouseOverDisplay:!1,textInputs:[]}}g(we,"createEmptyCompressedInputPacket");function Oe(m){let e=Math.max(-1,Math.min(1,m));return Math.round(e*127)}g(Oe,"encodeAxisToInt8");function ve(m){return m/127}g(ve,"decodeInt8ToAxis");function P(m){return m===0?0:Math.ceil(m/8)}g(P,"getButtonByteCount");function Be(m,e){let r=m,n=P(e);return 8+r+n+4}g(Be,"getCompressedPacketSize");function Ae(m,e){let t=e.getAllAxes().length,r=e.getAllButtons().length,n=P(r),o=8+t+n+4;if(m.length<o)throw new Error(`Invalid compressed input packet: expected at least ${o} bytes (${t} axes + ${r} buttons), got ${m.length}`);let s=new DataView(m.buffer,m.byteOffset,m.byteLength),i=0,a=we();a.tick=s.getBigUint64(i,!0),i+=8;for(let d=0;d<t;d++){let u=m[i],c=u>127?u-256:u,p=ve(c);a.axes.set(d,p),i+=1}for(let d=0;d<n;d++){let u=m[i];for(let c=0;c<8;c++){let p=d*8+c;if(p<r){let h=(u&1<<c)!==0;a.buttons.set(p,h)}}i+=1}a.displayId=m[i],i+=1,a.mouseX=m[i],i+=1,a.mouseY=m[i],i+=1;let l=m[i];if(a.mouseOverDisplay=(l&1)!==0,i+=1,i<m.length){let d=m[i];i+=1;let u=new TextDecoder;a.textInputs=[];for(let c=0;c<d&&i<m.length;c++){let p=m[i];if(i+=1,i+p<=m.length){let h=m.slice(i,i+p),C=u.decode(h);a.textInputs.push(C),i+=p}}}return a}g(Ae,"decodeCompressedInput");import{Vector2 as ce}from"@utsp/types";var ke=class ke{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}};g(ke,"UserStats");var J=ke;var Me=class Me{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 q);x(this,"stats");x(this,"data");this.mode=r,this.stats=new J(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,l=i.y+s;return{displayId:n,localX:o,localY:s,worldX:a,worldY:l}}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 Z(t.id,t.sizeX,t.sizeY);this.displays.length<=t.id;)this.displays.push(null);this.displays[t.id]=r}r.setOrigin(new ce(t.originX,t.originY)),r.setSize(new ce(t.sizeX,t.sizeY))}}updateLayersFromPacket(e){for(let t of e){let r=this.findLayerById(t.id);r||(r=new K(new ce(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 ce(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=Ae(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 l=o[i];this.setAxis(l.name,a)}for(let[i,a]of t.buttons)if(i<s.length){let l=s[i];this.setButton(l.name,a)}this.mouseX=t.mouseX,this.mouseY=t.mouseY,this.mouseOver=t.mouseOverDisplay,this.mouseDisplayId=t.displayId}};g(Me,"User");var Q=Me;T();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()}};g(ze,"OrderEncoder");var ue=ze;T();var Fe=class Fe{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,l)=>a+l.length,0),o=r+n,s=S.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)S.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(Fe,"LayerEncoder");var pe=Fe;T();var Ee=class Ee{constructor(){x(this,"layerEncoder");this.layerEncoder=new pe}encode(e){let t=e.layers.map(u=>this.layerEncoder.encode(u)),r=9,n=e.displays.length*7,o=2,s=t.reduce((u,c)=>u+c.length,0),i=r+n+o+s,a=S.allocUnsafe(i),l=0,d=typeof e.tick=="bigint"?e.tick:BigInt(e.tick);a.writeBigUInt64BE(d,l),l+=8,a.writeUInt8(e.displays.length,l),l+=1;for(let u of e.displays)a.writeUInt8(u.id,l++),a.writeUInt16BE(u.originX,l),l+=2,a.writeUInt16BE(u.originY,l),l+=2,a.writeUInt8(Math.max(1,Math.min(256,u.sizeX))-1,l++),a.writeUInt8(Math.max(1,Math.min(256,u.sizeY))-1,l++);a.writeUInt16BE(e.layers.length,l),l+=2;for(let u of t)S.from(u).copy(a,l),l+=u.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=S.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(Ee,"UpdatePacketEncoder");var he=Ee;var W=class W{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,s=e.y+e.height,i=t.x,a=t.x+256,l=t.y,d=t.y+256;return!(n<=i||r>=a||s<=l||o>=d)}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 l=i*e.width+a;if(o[l])continue;let d=e.x+a,u=e.y+i;for(let c=0;c<s.length;c++){let p=s[c],h=d-p.getOrigin().x,C=u-p.getOrigin().y,y=p.getWidth(),U=p.getHeight();if(h<0||h>=y||C<0||C>=U)continue;let f=C*y+h,b=p.getData(),v=b.getCharCode(f),A=b.getFgColorCode(f),O=b.getBgColorCode(f),w=n[l];if(v!==0&&v<256&&w.char===" "&&(w.char=W.charCache[v]),A!==255&&w.fgColorIndex===255&&(w.fgColorIndex=A,w.fgEmission=this.getColorEmission(A)),O!==255){w.bgColorIndex===255&&(w.bgColorIndex=O,w.bgEmission=this.getColorEmission(O)),o[l]=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 l=i*e.width+a;if(o[l])continue;let d=e.x+a,u=e.y+i;for(let c=0;c<s.length;c++){let p=s[c],h=d-p.getOrigin().x,C=u-p.getOrigin().y,y=p.getWidth(),U=p.getHeight();if(h<0||h>=y||C<0||C>=U)continue;let f=C*y+h,b=p.getData(),v=b.getCharCode(f),A=b.getFgColorCode(f),O=b.getBgColorCode(f),w=n[l];if(v!==0&&v<256&&w.char===" "&&(w.char=W.charCache[v]),A!==255&&w.fgColorIndex===255&&(w.fgColorIndex=A,w.fgEmission=this.getColorEmission(A)),O!==255){w.bgColorIndex===255&&(w.bgColorIndex=O,w.bgEmission=this.getColorEmission(O)),o[l]=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,l=t.y,d=t.y+256,u=Math.max(r,i),c=Math.min(n,a),p=Math.max(o,l),h=Math.min(s,d);return{visible:u<c&&p<h,originStart:{x:u-e.x,y:p-e.y},originEnd:{x:c-e.x,y:h-e.y},layerStart:{x:u-t.x,y:p-t.y},layerEnd:{x:c-t.x,y:h-t.y}}}};g(W,"DisplayRasterizer"),x(W,"charCache",(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=String.fromCharCode(t);return e})());var xe=W;var Re=class Re{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}};g(Re,"CoreStats");var ee=Re;var Le=class Le{constructor(){x(this,"unicolorSprites",new Map);x(this,"multicolorSprites",new Map)}loadUnicolorSprites(e){for(let t of e.sprites){let r=new G(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 L(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(Le,"SpriteRegistry");var te=Le;var tt=(t=>(t.Web="web",t.Bitmap="bitmap",t))(tt||{}),De=class De{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(De,"WebFont");var X=De,Te=class Te{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(Te,"BitmapFont");var re=Te;var Xe=class Xe{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 X(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(Xe,"WebFontRegistry");var ne=Xe;var Ye=class Ye{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 re(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(Ye,"BitmapFontRegistry");var oe=Ye;var H=class H{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 ee);x(this,"spriteRegistry",new te);x(this,"webFontRegistry",new ne);x(this,"bitmapFontRegistry",new oe);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 he,this.displayRasterizer=new xe(this),this.initializeDefaultPalette(),this.displayRasterizer.rebuildColorCache(),this.loadDefaultWebFont()}initializeDefaultPalette(){H.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 Q(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});H.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 l=[],d=[];s.forEach((p,h)=>{let C=p.getOrigin(),y=p.getOrders(),U=p.getStatic(),f=p.calculateUpdateFlags();p.resetChangeTracking(),p.getId()===0&&p.setId(h);let b={id:p.getId(),updateFlags:f,zIndex:p.getZOrder(),originX:C.x,originY:C.y,width:p.getWidth(),height:p.getHeight(),orderCount:y.length,orders:y};U?l.push(b):d.push(b)}),r+=l.length+d.length;let u=[...l,...d],c=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:u.length,layers:u});if(e.set(o,c),this.stats.isEnabled()){u.forEach((y,U)=>{this.stats.recordLayerOrders(U,y.orders)}),i.forEach((y,U)=>{this.stats.recordDisplayLayers(U,u.length)});let p=i.length*12,h=u.length*20,C=c.length-p-h;this.stats.recordUpdatePacketSize(c.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 l=[],d=[];s.forEach((p,h)=>{if(!p.getNeedsCommit())return;let C=p.getOrigin(),y=p.getOrders(),U=p.getStatic(),f=p.calculateUpdateFlags();p.resetChangeTracking(),p.resetCommit(),p.getId()===0&&p.setId(h);let b={id:p.getId(),updateFlags:f,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(),U,y.length,f),U?l.push(b):d.push(b)}),r+=l.length+d.length;let u=null,c=null;if(this.stats.isEnabled()&&this.stats.recordPacketSplit(o,a.length,l.length,d.length),l.length>0&&(u=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:l.length,layers:l})),c=this.encoder.encode({tick:this.currentTick,displayCount:a.length,displays:a,layerCount:d.length,layers:d}),e.set(o,{static:u,dynamic:c}),n.getStats().isEnabled()){let p=i.reduce((U,f)=>{let b=f.getSize();return U+b.x*b.y},0);n.getStats().recordDisplays(i.length,p),n.getStats().recordLayers(s.length,l.length+d.length,l.length,d.length),[...l,...d].forEach(U=>{n.getStats().recordLayerOrders(U.id,U.orders.length)});let h=u?.length||0,C=c?.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=[...l,...d];p.forEach((f,b)=>{this.stats.recordLayerOrders(b,f.orders)}),i.forEach((f,b)=>{this.stats.recordDisplayLayers(b,p.length)});let h=(u?.length||0)+(c?.length||0),C=i.length*12,y=p.length*20,U=h-C-y;this.stats.recordUpdatePacketSize(h,C,y,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((i,a)=>{let l=i.getOrigin(),d=i.getSize();return{id:a,originX:l.x,originY:l.y,sizeX:d.x,sizeY:d.y}}),s=n.map((i,a)=>{let l=i.getOrigin(),d=i.getOrders(),u=7;return i.getId()===0&&i.setId(a),{id:i.getId(),updateFlags:u,zIndex:i.getZOrder(),originX:l.x,originY:l.y,width:i.getWidth(),height:i.getHeight(),orderCount:d.length,orders:d}});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}=(He(),M(it)),o=new r().decode(t);return this.applyUpdatePacket(e,o)}applyLoadPacket(e){try{let{LoadDecoder:t}=(at(),M(st)),{LoadType:r}=(R(),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}=(N(),M(_)),{LoadType:r}=(R(),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 l=0;l<i.sizeX*i.sizeY;l++)a.push(i.data.get(l));t.push({spriteId:i.id,sizeX:i.sizeX,sizeY:i.sizeY,data:a})}}if(t.length===0)return null;let{LoadEncoder:r}=(N(),M(_)),{LoadType:n}=(R(),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 l=0;l<i.sizeX*i.sizeY;l++){let d=i.data.get(l);a.push({charCode:d.charCode,fgColorId:d.fgColorCode,bgColorId:d.bgColorCode})}t.push({spriteId:i.id,sizeX:i.sizeX,sizeY:i.sizeY,data:a})}}if(t.length===0)return null;let{LoadEncoder:r}=(N(),M(_)),{LoadType:n}=(R(),M(Y));return new r().encode({loadType:n.MulticolorSprite,sprites:t})}generateWebFontsLoadPackets(){let e=this.getWebFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(N(),M(_)),{LoadType:o}=(R(),M(Y)),s=new n;for(let i of t){let a=e.getFont(i);if(a){let l=a.getConfig(),d=s.encode({loadType:o.WebFont,fontId:i,fontFamily:l.fontFamily,fontSize:l.fontSize,offsetX:l.offsetX,offsetY:l.offsetY,charSpacing:l.charSpacing,lineHeight:l.lineHeight,fontWeight:l.fontWeight,fontStyle:l.fontStyle});r.push(d)}}return r}generateBitmapFontsLoadPackets(){let e=this.getBitmapFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(N(),M(_)),{LoadType:o}=(R(),M(Y)),s=new n;for(let i of t){let a=e.getFont(i);if(a){let l=[];for(let d=0;d<256;d++){let u=a.getGlyph(d);u&&l.push({charCode:d,bitmap:u})}if(l.length>0){let d=s.encode({loadType:o.BitmapFont,fontId:i,width:a.getCharWidth(),height:a.getCharHeight(),cellWidth:a.getCellWidth(),cellHeight:a.getCellHeight(),characters:l});r.push(d)}}}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 l=r[a],d=l.getOrigin(),u=l.getSize();s[a]=this.displayRasterizer.rasterize({x:d.x,y:d.y,width:u.x,height:u.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}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 X(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(H,"Core"),x(H,"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 Ke=H;import{Vector2 as po}from"@utsp/types";var V=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 Gt(m){return V.get(m)}g(Gt,"getCharBitmap");function jt(m){return V.has(m)}g(jt,"hasChar");function Kt(){return Array.from(V.keys()).sort((m,e)=>m-e)}g(Kt,"getAllCharCodes");function qt(m){let e=Array.from(V.entries()).map(([t,r])=>({charCode:t,bitmap:r}));return{loadType:4,fontId:m,width:8,height:8,cellWidth:8,cellHeight:8,characters:e}}g(qt,"createASCII8x8FontLoad");function Jt(){return{charWidth:8,charHeight:8,glyphs:new Map(V)}}g(Jt,"getASCII8x8FontConfig");function Qt(m,e,t,r,n,o,s,i=[]){let a=Array.from(e.entries()).sort((O,w)=>O[0]-w[0]),l=Array.from(t.entries()).sort((O,w)=>O[0]-w[0]),d=a.length,u=l.length,c=Be(d,u),p=new TextEncoder,h=i.map(O=>p.encode(O)),C=1+h.reduce((O,w)=>O+1+w.length,0),y=c+C,U=new Uint8Array(y),f=new DataView(U.buffer),b=0;f.setBigUint64(b,m,!0),b+=8;for(let[,O]of a){let w=Oe(O);U[b]=w+256&255,b+=1}let v=P(u);for(let O=0;O<v;O++){let w=0;for(let z=0;z<8;z++){let ie=O*8+z;if(ie<u){let[,I]=l[ie];I&&(w|=1<<z)}}U[b]=w,b+=1}U[b]=r&255,b+=1,U[b]=n&255,b+=1,U[b]=o&255,b+=1;let A=0;s&&(A|=1),U[b]=A,b+=1,U[b]=Math.min(i.length,255),b+=1;for(let O of h)U[b]=Math.min(O.length,255),b+=1,U.set(O.slice(0,255),b),b+=O.length;return U}g(Qt,"encodeCompressedInput");var B=class B{static toCharCode(e){if(typeof e=="number")return e&255;let t=e.charCodeAt(0);return j(t)}static dedent(e){let t=e.split(`
|
|
7
|
+
`}),e}};g(Oe,"InputBindingRegistry");var K=Oe;function ve(x=0n){return{tick:x,axes:new Map,buttons:new Map,displayId:0,mouseX:0,mouseY:0,mouseOverDisplay:!1,textInputs:[]}}g(ve,"createEmptyCompressedInputPacket");function Ae(x){let e=Math.max(-1,Math.min(1,x));return Math.round(e*127)}g(Ae,"encodeAxisToInt8");function Be(x){return x/127}g(Be,"decodeInt8ToAxis");function Y(x){return x===0?0:Math.ceil(x/8)}g(Y,"getButtonByteCount");function ke(x,e){let r=x,n=Y(e);return 8+r+n+4}g(ke,"getCompressedPacketSize");function Me(x,e){let t=e.getAllAxes().length,r=e.getAllButtons().length,n=Y(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=ve();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=Be(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(Me,"decodeCompressedInput");import{Vector2 as ce}from"@utsp/types";var ze=class ze{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(ze,"UserStats");var J=ze;var Fe=class Fe{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 K);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 J(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 Z(t.id,t.sizeX,t.sizeY);this.displays.length<=t.id;)this.displays.push(null);this.displays[t.id]=r}r.setOrigin(new ce(t.originX,t.originY)),r.setSize(new ce(t.sizeX,t.sizeY))}}updateLayersFromPacket(e){for(let t of e){let r=this.findLayerById(t.id);r||(r=new q(new ce(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 ce(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=Me(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(Fe,"User");var Q=Fe;T();var Ee=class Ee{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(Ee,"OrderEncoder");var pe=Ee;T();var Re=class Re{constructor(){m(this,"orderEncoder");this.orderEncoder=new pe}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(Re,"LayerEncoder");var he=Re;T();var Le=class Le{constructor(){m(this,"layerEncoder");this.layerEncoder=new he}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(Le,"UpdatePacketEncoder");var me=Le;var W=class W{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=W.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=W.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(W,"DisplayRasterizer"),m(W,"charCache",(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=String.fromCharCode(t);return e})());var xe=W;var De=class De{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(De,"CoreStats");var ee=De;var Te=class Te{constructor(){m(this,"unicolorSprites",new Map);m(this,"multicolorSprites",new Map)}loadUnicolorSprites(e){for(let t of e.sprites){let r=new G(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 L(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(Te,"SpriteRegistry");var te=Te;var ot=(t=>(t.Web="web",t.Bitmap="bitmap",t))(ot||{}),Pe=class Pe{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(Pe,"WebFont");var P=Pe,Xe=class Xe{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(Xe,"BitmapFont");var re=Xe;var Ye=class Ye{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 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}};g(Ye,"WebFontRegistry");var ne=Ye;var We=class We{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 re(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(We,"BitmapFontRegistry");var oe=We;var _e=class _e{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(_e,"SoundRegistry");var ie=_e;var $=class ${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 ee);m(this,"spriteRegistry",new te);m(this,"webFontRegistry",new ne);m(this,"bitmapFontRegistry",new oe);m(this,"soundRegistry",new ie);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 me,this.displayRasterizer=new xe(this),this.initializeDefaultPalette(),this.displayRasterizer.rebuildColorCache(),this.loadDefaultWebFont()}initializeDefaultPalette(){$.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 Q(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});$.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}=(Ze(),M(dt)),o=new r().decode(t);return this.applyUpdatePacket(e,o)}applyLoadPacket(e){try{let{LoadDecoder:t}=(ut(),M(lt)),{LoadType:r}=(R(),M(X)),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}=(N(),M(_)),{LoadType:r}=(R(),M(X)),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}=(N(),M(_)),{LoadType:n}=(R(),M(X));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}=(N(),M(_)),{LoadType:n}=(R(),M(X));return new r().encode({loadType:n.MulticolorSprite,sprites:t})}generateWebFontsLoadPackets(){let e=this.getWebFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(N(),M(_)),{LoadType:o}=(R(),M(X)),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}=(N(),M(_)),{LoadType:o}=(R(),M(X)),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 Se<"u"?Se: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 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()}};g($,"Core"),m($,"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 Qe=$;import{Vector2 as bo}from"@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 Kt(x){return H.get(x)}g(Kt,"getCharBitmap");function Jt(x){return H.has(x)}g(Jt,"hasChar");function Qt(){return Array.from(H.keys()).sort((x,e)=>x-e)}g(Qt,"getAllCharCodes");function er(x){let e=Array.from(H.entries()).map(([t,r])=>({charCode:t,bitmap:r}));return{loadType:4,fontId:x,width:8,height:8,cellWidth:8,cellHeight:8,characters:e}}g(er,"createASCII8x8FontLoad");function tr(){return{charWidth:8,charHeight:8,glyphs:new Map(H)}}g(tr,"getASCII8x8FontConfig");function rr(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=ke(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=Ae(O);f[b]=w+256&255,b+=1}let v=Y(c);for(let O=0;O<v;O++){let w=0;for(let z=0;z<8;z++){let se=O*8+z;if(se<c){let[,S]=d[se];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(rr,"encodeCompressedInput");var A=class A{static toCharCode(e){if(typeof e=="number")return e&255;let t=e.charCodeAt(0);return j(t)}static dedent(e){let t=e.split(`
|
|
8
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:
|
|
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 et=A;var ct=(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))(ct||{});function nr(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(nr,"isValidOrderType");function or(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(or,"getOrderTypeName");R();nt();var pt=(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))(pt||{}),tt;(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")})(tt||(tt={}));Ze();export{H as ASCII_8X8_FONT,Pt as BITMASK16_ORDER_MIN_SIZE,Tt as BITMASK4_ORDER_MIN_SIZE,Dt as BITMASK_ORDER_MIN_SIZE,re as BitmapFont,oe as BitmapFontRegistry,bt as CHAR_ORDER_SIZE,Mt as CIRCLE_SHAPE_SIZE,Nt as CLEAR_ORDER_SIZE,At as COLORMAP_ORDER_MIN_SIZE,k as COLOR_SKIP,L as CellBuffer,G as CharCodeBuffer,Qe as Core,ee as CoreStats,cr as DISPLAY_HEADER_SIZE,Lt as DOTCLOUD_MULTICOLOR_ORDER_MIN_SIZE,Rt as DOTCLOUD_ORDER_MIN_SIZE,Z as Display,Ft as ELLIPSE_SHAPE_SIZE,$t as FILLCHAR_ORDER_MIN_SIZE,Vt as FILLSPRITE_MULTICOLOR_ORDER_SIZE,Ht as FILLSPRITE_ORDER_SIZE,wt as FULLFRAME_MULTICOLOR_ORDER_MIN_SIZE,Ut as FULLFRAME_ORDER_MIN_SIZE,ot as FontType,K as InputBindingRegistry,lr as LAYER_CELL_COUNT,pr as LAYER_HEADER_SIZE,le as LAYER_SIZE,zt as LINE_SHAPE_SIZE,q as Layer,Ge as LoadType,et as OrderBuilder,ct as OrderType,kt as RECTANGLE_SHAPE_SIZE,Bt as SHAPE_ORDER_MIN_SIZE,Yt as SPRITECLOUD_MULTICOLOR_ORDER_MIN_SIZE,Xt as SPRITECLOUD_ORDER_MIN_SIZE,_t as SPRITECLOUD_VARIED_MULTICOLOR_ORDER_MIN_SIZE,Wt as SPRITECLOUD_VARIED_ORDER_MIN_SIZE,vt as SPRITE_MULTICOLOR_ORDER_SIZE,Ot as SPRITE_ORDER_SIZE,ft as SUBFRAME_MULTICOLOR_ORDER_MIN_SIZE,It as SUBFRAME_ORDER_MIN_SIZE,rt as ShapeType,ie as SoundRegistry,te as SpriteRegistry,St as TEXT_MULTILINE_ORDER_MIN_SIZE,yt as TEXT_ORDER_MIN_SIZE,Et as TRIANGLE_SHAPE_SIZE,Gt as TRIGGERGLOBALSOUND_ORDER_SIZE,Zt as TRIGGERSOUND_ORDER_SIZE,ur as UPDATE_PACKET_HEADER_SIZE,pt as UpdateFlags,tt as UpdateFlagsHelper,ye as UpdatePacketDecoder,Q as User,J as UserStats,bo as Vector2,P as WebFont,ne as WebFontRegistry,er as createASCII8x8FontLoad,ve as createEmptyCompressedInputPacket,Me as decodeCompressedInput,Be as decodeInt8ToAxis,Ae as encodeAxisToInt8,rr as encodeCompressedInput,tr as getASCII8x8FontConfig,Qt as getAllCharCodes,Y as getButtonByteCount,Kt as getCharBitmap,ke as getCompressedPacketSize,or as getOrderTypeName,Jt as hasChar,nr as isValidOrderType};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utsp/core",
|
|
3
|
-
"version": "0.4.0
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "UTSP core engine - Universal Text Stream Protocol data management",
|
|
5
5
|
"author": "THP Software",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@utsp/types": "0.4.0
|
|
49
|
+
"@utsp/types": "0.4.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^24.9.1",
|