@utsp/core 0.1.1 → 0.1.3
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/LICENSE +21 -21
- package/README.md +36 -36
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +104 -3
- package/dist/index.mjs +4 -4
- package/package.json +3 -3
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 ie=(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 z=m=>xt($({},"__esModule",{value:!0}),m);var x=(m,e,t)=>(ht(m,typeof e!="symbol"?e+"":e,t),t);var Je,Qe=F(()=>{"use strict";Je=(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))(Je||{})});var k,I,D=F(()=>{"use strict";k=class k{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 k(0);return t.data=e,t.view=new DataView(e.buffer,e.byteOffset,e.byteLength),t}static allocUnsafe(e){return new k(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 k.from(r)}subarray(e,t){let r=this.data.subarray(e,t);return k.from(r)}toBuffer(){return typeof Buffer<"u"&&Buffer.from?Buffer.from(this.data):this.data}static fromNodeBuffer(e){return e instanceof Uint8Array?k.from(e):k.from(new Uint8Array(e))}};g(k,"BufferCompat");I=k});var Ye,xe,tt=F(()=>{"use strict";Ye=class Ye{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(Ye,"DisplayDecoder");xe=Ye});var Pe,me,rt=F(()=>{"use strict";Pe=class Pe{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 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}}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(Pe,"OrderDecoder");me=Pe});var We,Ce,nt=F(()=>{"use strict";rt();We=class We{constructor(){x(this,"orderDecoder");this.orderDecoder=new me}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 f=this.orderDecoder.decode(e,h);p.push(f.order),h+=f.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(We,"LayerDecoder");Ce=We});var ot={};ie(ot,{UpdatePacketDecoder:()=>ge});var _e,ge,Ne=F(()=>{"use strict";tt();nt();D();_e=class _e{constructor(){x(this,"displayDecoder");x(this,"layerDecoder");this.displayDecoder=new xe,this.layerDecoder=new Ce}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 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=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(_e,"UpdatePacketDecoder");ge=_e});var X={};ie(X,{LoadType:()=>He});var He,E=F(()=>{"use strict";He=(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))(He||{})});var it={};ie(it,{LoadDecoder:()=>$e});var Ve,$e,st=F(()=>{"use strict";D();Ve=class Ve{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 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 f=0;f<u;f++)y[f]=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(Ve,"LoadDecoder");$e=Ve});var W={};ie(W,{LoadEncoder:()=>Ze});var Ge,Ze,_=F(()=>{"use strict";D();Ge=class Ge{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),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(Ge,"LoadEncoder");Ze=Ge});import{Vector2 as se}from"@utsp/types";var be=class be{constructor(e=0,t=60,r=40){x(this,"id");x(this,"origin");x(this,"size");x(this,"previousOrigin",new se(0,0));x(this,"previousSize",new se(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 se(0,0),this.size=new se(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(be,"Display");var V=be;var ae=256,or=65536,M=255,ir=9,sr=5,ar=13,mt=6,Ct=6,gt=6,bt=7,yt=5,St=3,It=1,ft=6,Ut=4,wt=5,Ot=2,vt=8,At=7,Mt=7,Bt=8,zt=10,Ft=6,kt=3,Et=9,Rt=6,Lt=4,Dt=3,Tt=3,Xt=4,Yt=5,Pt=4,Wt=2,_t=5,Nt=3;var ye=class ye{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(ye,"CellBuffer");var R=ye,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 Z=Se;import{Vector2 as $t}from"@utsp/types";var Ht=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 G(m){if(m<128)return m;let e=Ht.get(m);return e!==void 0?e:m&255}g(G,"unicodeToCp437");var Ie=class Ie{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 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=G(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=G(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 f=2*h;f>-u&&(h-=u,C+=c),f<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,f=g((b,v,A)=>{let w=Math.round(Math.min(v,A)),U=Math.round(Math.max(v,A));for(let S=w;S<=U;S++)if(S>=0&&S<this.currentWidth&&b>=0&&b<this.currentHeight){let oe=b*this.currentWidth+S;t.set(oe,d,c,u)}},"drawLine"),O=g((b,v,A,w,U)=>w===v?A:A+(b-v)*(U-A)/(w-v),"interpolate");for(let b=h.y;b<=C.y;b++){let v=O(b,h.y,h.x,y.y,y.x),A=O(b,h.y,h.x,C.y,C.x);f(b,v,A)}for(let b=C.y+1;b<=y.y;b++){let v=O(b,h.y,h.x,y.y,y.x),A=O(b,C.y,C.x,y.y,y.x);f(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,f=Math.floor(y/8),O=y%8,b=(u[f]&1<<O)!==0,v=p*this.currentWidth+C;b?t.set(v,i,l,a):d&&t.set(v,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(Ie,"LayerRasterizer");var le=Ie;var L=class L{constructor(e,t,r,n,o=!1){x(this,"id",0);x(this,"origin");x(this,"orders",[]);x(this,"zOrder",0);x(this,"data");x(this,"width");x(this,"height");x(this,"isStatic",!1);x(this,"spriteRegistry");x(this,"mode","server");x(this,"previousOrigin");x(this,"previousZOrder");x(this,"enabled",!0);x(this,"useSetMode",!1);x(this,"needsCommit",!1);if(r<1||r>256||n<1||n>256)throw new Error(`Layer size must be 1-256, got ${r}\xD7${n}`);this.origin=e,this.zOrder=t,this.width=r,this.height=n,this.isStatic=o,this.data=new R(r*n),this.previousOrigin=new $t(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")&&L.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")&&L.rasterizer.rasterizeOrders(e,this.data,this.width,this.height,"set",this.spriteRegistry)}clearOrders(){this.orders=[],(this.mode==="client"||this.mode==="standalone")&&L.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(L,"Layer"),x(L,"rasterizer",new le);var j=L;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 $=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})
|
|
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 Ue(m=0n){return{tick:m,axes:new Map,buttons:new Map,displayId:0,mouseX:0,mouseY:0,mouseOverDisplay:!1,textInputs:[]}}g(Ue,"createEmptyCompressedInputPacket");function we(m){let e=Math.max(-1,Math.min(1,m));return Math.round(e*127)}g(we,"encodeAxisToInt8");function Oe(m){return m/127}g(Oe,"decodeInt8ToAxis");function Y(m){return m===0?0:Math.ceil(m/8)}g(Y,"getButtonByteCount");function ve(m,e){let r=m,n=Y(e);return 8+r+n+4}g(ve,"getCompressedPacketSize");function Ae(m,e){let t=e.getAllAxes().length,r=e.getAllButtons().length,n=Y(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=Ue();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=Oe(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 de}from"@utsp/types";var Me=class Me{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(Me,"UserStats");var K=Me;var Be=class Be{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 K(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 V(t.id,t.sizeX,t.sizeY);this.displays.length<=t.id;)this.displays.push(null);this.displays[t.id]=r}r.setOrigin(new de(t.originX,t.originY)),r.setSize(new de(t.sizeX,t.sizeY))}}updateLayersFromPacket(e){for(let t of e){let r=this.findLayerById(t.id);r||(r=new j(new de(t.originX,t.originY),t.zIndex,t.width,t.height,!1),r.setId(t.id),r.setMode(this.mode),this.spriteRegistry&&r.setSpriteRegistry(this.spriteRegistry),this.addLayer(r)),t.updateFlags&1&&r.setOrigin(new de(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(Be,"User");var J=Be;D();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 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()}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(ze,"OrderEncoder");var ce=ze;D();var Fe=class Fe{constructor(){x(this,"orderEncoder");this.orderEncoder=new ce}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=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(Fe,"LayerEncoder");var ue=Fe;D();var ke=class ke{constructor(){x(this,"layerEncoder");this.layerEncoder=new ue}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=I.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)I.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=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(ke,"UpdatePacketEncoder");var pe=ke;var P=class P{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(),f=p.getHeight();if(h<0||h>=y||C<0||C>=f)continue;let O=C*y+h,b=p.getData(),v=b.getCharCode(O),A=b.getFgColorCode(O),w=b.getBgColorCode(O),U=n[l];if(v!==0&&v<256&&U.char===" "&&(U.char=P.charCache[v]),A!==255&&U.fgColorIndex===255&&(U.fgColorIndex=A,U.fgEmission=this.getColorEmission(A)),w!==255){U.bgColorIndex===255&&(U.bgColorIndex=w,U.bgEmission=this.getColorEmission(w)),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(),f=p.getHeight();if(h<0||h>=y||C<0||C>=f)continue;let O=C*y+h,b=p.getData(),v=b.getCharCode(O),A=b.getFgColorCode(O),w=b.getBgColorCode(O),U=n[l];if(v!==0&&v<256&&U.char===" "&&(U.char=P.charCache[v]),A!==255&&U.fgColorIndex===255&&(U.fgColorIndex=A,U.fgEmission=this.getColorEmission(A)),w!==255){U.bgColorIndex===255&&(U.bgColorIndex=w,U.bgEmission=this.getColorEmission(w)),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(P,"DisplayRasterizer"),x(P,"charCache",(()=>{let e=new Array(256);for(let t=0;t<256;t++)e[t]=String.fromCharCode(t);return e})());var he=P;var Ee=class Ee{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(Ee,"CoreStats");var Q=Ee;var Re=class Re{constructor(){x(this,"unicolorSprites",new Map);x(this,"multicolorSprites",new Map)}loadUnicolorSprites(e){for(let t of e.sprites){let r=new Z(t.sizeX*t.sizeY);for(let o=0;o<t.data.length;o++)r.set(o,t.data[o]);let n={id:t.spriteId,sizeX:t.sizeX,sizeY:t.sizeY,data:r};this.unicolorSprites.set(n.id,n)}}loadMulticolorSprites(e){for(let t of e.sprites){let r=new R(t.sizeX*t.sizeY);for(let o=0;o<t.data.length;o++){let s=t.data[o];r.set(o,s.charCode,s.fgColorId,s.bgColorId)}let n={id:t.spriteId,sizeX:t.sizeX,sizeY:t.sizeY,data:r};this.multicolorSprites.set(n.id,n)}}getUnicolorSprite(e){return this.unicolorSprites.get(e)}getMulticolorSprite(e){return this.multicolorSprites.get(e)}hasUnicolorSprite(e){return this.unicolorSprites.has(e)}hasMulticolorSprite(e){return this.multicolorSprites.has(e)}unloadUnicolorSprite(e){return this.unicolorSprites.delete(e)}unloadMulticolorSprite(e){return this.multicolorSprites.delete(e)}clearUnicolorSprites(){this.unicolorSprites.clear()}clearMulticolorSprites(){this.multicolorSprites.clear()}clearAll(){this.unicolorSprites.clear(),this.multicolorSprites.clear()}getUnicolorSpriteCount(){return this.unicolorSprites.size}getMulticolorSpriteCount(){return this.multicolorSprites.size}getTotalSpriteCount(){return this.unicolorSprites.size+this.multicolorSprites.size}};g(Re,"SpriteRegistry");var ee=Re;var et=(t=>(t.Web="web",t.Bitmap="bitmap",t))(et||{}),Le=class Le{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(Le,"WebFont");var T=Le,De=class De{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(De,"BitmapFont");var te=De;var Te=class Te{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 T(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(Te,"WebFontRegistry");var re=Te;var Xe=class Xe{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 te(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,"BitmapFontRegistry");var ne=Xe;var N=class N{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 Q);x(this,"spriteRegistry",new ee);x(this,"webFontRegistry",new re);x(this,"bitmapFontRegistry",new ne);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 pe,this.displayRasterizer=new he(this),this.initializeDefaultPalette(),this.displayRasterizer.rebuildColorCache(),this.loadDefaultWebFont()}initializeDefaultPalette(){N.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 J(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});N.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(),f=p.getStatic(),O=p.calculateUpdateFlags();p.resetChangeTracking(),p.getId()===0&&p.setId(h);let b={id:p.getId(),updateFlags:O,zIndex:p.getZOrder(),originX:C.x,originY:C.y,width:p.getWidth(),height:p.getHeight(),orderCount:y.length,orders:y};f?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,f)=>{this.stats.recordLayerOrders(f,y.orders)}),i.forEach((y,f)=>{this.stats.recordDisplayLayers(f,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(),f=p.getStatic(),O=p.calculateUpdateFlags();p.resetChangeTracking(),p.resetCommit(),p.getId()===0&&p.setId(h);let b={id:p.getId(),updateFlags:O,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,O),f?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((f,O)=>{let b=O.getSize();return f+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(f=>{n.getStats().recordLayerOrders(f.id,f.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((O,b)=>{this.stats.recordLayerOrders(b,O.orders)}),i.forEach((O,b)=>{this.stats.recordDisplayLayers(b,p.length)});let h=(u?.length||0)+(c?.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 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}=(Ne(),z(ot)),o=new r().decode(t);return this.applyUpdatePacket(e,o)}applyLoadPacket(e){try{let{LoadDecoder:t}=(st(),z(it)),{LoadType:r}=(E(),z(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}=(_(),z(W)),{LoadType:r}=(E(),z(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 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}=(_(),z(W)),{LoadType:n}=(E(),z(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 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}=(_(),z(W)),{LoadType:n}=(E(),z(X));return new r().encode({loadType:n.MulticolorSprite,sprites:t})}generateWebFontsLoadPackets(){let e=this.getWebFontRegistry(),t=e.getFontIds(),r=[],{LoadEncoder:n}=(_(),z(W)),{LoadType:o}=(E(),z(X)),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}=(_(),z(W)),{LoadType:o}=(E(),z(X)),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 T(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(N,"Core"),x(N,"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 je=N;import{Vector2 as co}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 Vt(m){return H.get(m)}g(Vt,"getCharBitmap");function Zt(m){return H.has(m)}g(Zt,"hasChar");function Gt(){return Array.from(H.keys()).sort((m,e)=>m-e)}g(Gt,"getAllCharCodes");function jt(m){let e=Array.from(H.entries()).map(([t,r])=>({charCode:t,bitmap:r}));return{loadType:4,fontId:m,width:8,height:8,cellWidth:8,cellHeight:8,characters:e}}g(jt,"createASCII8x8FontLoad");function qt(){return{charWidth:8,charHeight:8,glyphs:new Map(H)}}g(qt,"getASCII8x8FontConfig");function Kt(m,e,t,r,n,o,s,i=[]){let a=Array.from(e.entries()).sort((w,U)=>w[0]-U[0]),l=Array.from(t.entries()).sort((w,U)=>w[0]-U[0]),d=a.length,u=l.length,c=ve(d,u),p=new TextEncoder,h=i.map(w=>p.encode(w)),C=1+h.reduce((w,U)=>w+1+U.length,0),y=c+C,f=new Uint8Array(y),O=new DataView(f.buffer),b=0;O.setBigUint64(b,m,!0),b+=8;for(let[,w]of a){let U=we(w);f[b]=U+256&255,b+=1}let v=Y(u);for(let w=0;w<v;w++){let U=0;for(let S=0;S<8;S++){let oe=w*8+S;if(oe<u){let[,dt]=l[oe];dt&&(U|=1<<S)}}f[b]=U,b+=1}f[b]=r&255,b+=1,f[b]=n&255,b+=1,f[b]=o&255,b+=1;let A=0;s&&(A|=1),f[b]=A,b+=1,f[b]=Math.min(i.length,255),b+=1;for(let w of h)f[b]=Math.min(w.length,255),b+=1,f.set(w.slice(0,255),b),b+=w.length;return f}g(Kt,"encodeCompressedInput");var B=class B{static toCharCode(e){if(typeof e=="number")return e&255;let t=e.charCodeAt(0);return G(t)}static dedent(e){let t=e.split(`
|
|
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(`
|
|
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:B.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:B.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=>B.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:B.toCharCode(s.charCode),bgColorCode:s.bgColorCode,fgColorCode:s.fgColorCode}))}}static fullFrame(e,t=15,r=0){return{type:5,frame:e.map(n=>B.toCharCode(n)),bgColorCode:r,fgColorCode:t}}static fullFrameMultiColor(e){return{type:6,frame:e.map(t=>({charCode:B.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:B.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:B.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:B.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:B.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:B.toCharCode(i.charCode??9608),bgColorCode:i.bgColor??0,fgColorCode:i.fgColor??15}}}static dotCloud(e,t,r=15,n=0){return{type:11,charCode:B.toCharCode(t),bgColorCode:n,fgColorCode:r,positions:e}}static dotCloudMultiColor(e){return{type:12,dots:e.map(t=>({...t,charCode:B.toCharCode(t.charCode)}))}}static bitmask(e,t,r,n,o,s,i=15,a=0,l=!1){let d=r*n,u=Math.ceil(d/8),c=new Uint8Array(u);for(let p=0;p<d;p++)if(o[p]){let h=Math.floor(p/8),C=p%8;c[h]|=1<<C}return{type:17,posX:e,posY:t,sizeX:r,sizeY:n,charCode:B.toCharCode(s),bgColorCode:a,fgColorCode:i,override:l,mask:c}}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:B.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=>B.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 l=0;l<=o;l++)for(let d=0;d<=s;d++)a.push({posX:e+d*r,posY:t+l*n});return this.dotCloud(a,i.charCode??"+",i.fgColor??15,i.bgColor??0)}};g(B,"OrderBuilder");var qe=B;var
|
|
9
|
+
`)}static char(e,t,r,n=15,o=0){return{type:1,posX:e,posY:t,charCode:B.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:B.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=>B.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:B.toCharCode(s.charCode),bgColorCode:s.bgColorCode,fgColorCode:s.fgColorCode}))}}static fullFrame(e,t=15,r=0){return{type:5,frame:e.map(n=>B.toCharCode(n)),bgColorCode:r,fgColorCode:t}}static fullFrameMultiColor(e){return{type:6,frame:e.map(t=>({charCode:B.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:B.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:B.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:B.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:B.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:B.toCharCode(i.charCode??9608),bgColorCode:i.bgColor??0,fgColorCode:i.fgColor??15}}}static dotCloud(e,t,r=15,n=0){return{type:11,charCode:B.toCharCode(t),bgColorCode:n,fgColorCode:r,positions:e}}static dotCloudMultiColor(e){return{type:12,dots:e.map(t=>({...t,charCode:B.toCharCode(t.charCode)}))}}static bitmask(e,t,r,n,o,s,i=15,a=0,l=!1){let d=r*n,u=Math.ceil(d/8),c=new Uint8Array(u);for(let p=0;p<d;p++)if(o[p]){let h=Math.floor(p/8),C=p%8;c[h]|=1<<C}return{type:17,posX:e,posY:t,sizeX:r,sizeY:n,charCode:B.toCharCode(s),bgColorCode:a,fgColorCode:i,override:l,mask:c}}static bitmask4(e,t,r,n,o,s,i=!1){let a={char:"?",fgColor:15,bgColor:0},l=[s[0]??a,s[1]??a,s[2]??a],d=r*n,u=Math.ceil(d/4),c=new Uint8Array(u);for(let p=0;p<d;p++){let h=o[p]&3,C=Math.floor(p/4),y=p%4*2;c[C]|=h<<y}return{type:18,posX:e,posY:t,sizeX:r,sizeY:n,override:i,variants:[{charCode:B.toCharCode(l[0].char),fgColorCode:l[0].fgColor,bgColorCode:l[0].bgColor},{charCode:B.toCharCode(l[1].char),fgColorCode:l[1].fgColor,bgColorCode:l[1].bgColor},{charCode:B.toCharCode(l[2].char),fgColorCode:l[2].fgColor,bgColorCode:l[2].bgColor}],mask:c}}static bitmask16(e,t,r,n,o,s,i=!1){let a={char:"?",fgColor:15,bgColor:0},l=[];for(let p=0;p<15;p++)l.push(s[p]??a);let d=r*n,u=Math.ceil(d/2),c=new Uint8Array(u);for(let p=0;p<d;p++){let h=o[p]&15,C=Math.floor(p/2),y=p%2*4;c[C]|=h<<y}return{type:24,posX:e,posY:t,sizeX:r,sizeY:n,override:i,variants:l.map(p=>({charCode:B.toCharCode(p.char),fgColorCode:p.fgColor,bgColorCode:p.bgColor})),mask:c}}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:B.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=>B.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 l=0;l<=o;l++)for(let d=0;d<=s;d++)a.push({posX:e+d*r,posY:t+l*n});return this.dotCloud(a,i.charCode??"+",i.fgColor??15,i.bgColor??0)}};g(B,"OrderBuilder");var qe=B;var lt=(I=>(I[I.Char=1]="Char",I[I.Text=2]="Text",I[I.TextMultiline=23]="TextMultiline",I[I.SubFrame=3]="SubFrame",I[I.SubFrameMultiColor=4]="SubFrameMultiColor",I[I.FullFrame=5]="FullFrame",I[I.FullFrameMultiColor=6]="FullFrameMultiColor",I[I.Sprite=7]="Sprite",I[I.SpriteMultiColor=8]="SpriteMultiColor",I[I.ColorMap=9]="ColorMap",I[I.Shape=10]="Shape",I[I.DotCloud=11]="DotCloud",I[I.DotCloudMultiColor=12]="DotCloudMultiColor",I[I.SpriteCloud=13]="SpriteCloud",I[I.SpriteCloudMultiColor=14]="SpriteCloudMultiColor",I[I.SpriteCloudVaried=15]="SpriteCloudVaried",I[I.SpriteCloudVariedMultiColor=16]="SpriteCloudVariedMultiColor",I[I.Bitmask=17]="Bitmask",I[I.Bitmask4=18]="Bitmask4",I[I.Bitmask16=24]="Bitmask16",I[I.Clear=19]="Clear",I[I.FillChar=20]="FillChar",I[I.FillSprite=21]="FillSprite",I[I.FillSpriteMultiColor=22]="FillSpriteMultiColor",I[I.TriggerSound=32]="TriggerSound",I[I.TriggerGlobalSound=33]="TriggerGlobalSound",I))(lt||{});function er(m){return m>=1&&m<=2||m>=3&&m<=6||m>=7&&m<=8||m>=9&&m<=10||m>=11&&m<=18||m>=19&&m<=23||m===24||m>=32&&m<=33}g(er,"isValidOrderType");function tr(m){switch(m){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${m.toString(16)})`}}g(tr,"getOrderTypeName");R();et();var dt=(c=>(c[c.LayerEnabled=1]="LayerEnabled",c[c.SetMode=2]="SetMode",c[c.UpdatePosition=4]="UpdatePosition",c[c.UpdateZOrder=8]="UpdateZOrder",c[c.Disabled=0]="Disabled",c[c.EnabledAddMode=1]="EnabledAddMode",c[c.EnabledSetMode=3]="EnabledSetMode",c[c.EnabledAddMoveOnly=5]="EnabledAddMoveOnly",c[c.EnabledSetMoveOnly=7]="EnabledSetMoveOnly",c[c.EnabledAddReorderOnly=9]="EnabledAddReorderOnly",c[c.EnabledSetReorderOnly=11]="EnabledSetReorderOnly",c[c.FullUpdate=15]="FullUpdate",c))(dt||{}),Je;(d=>{function m(u,c){return(u&c)!==0}d.hasFlag=m,g(m,"hasFlag");function e(u,c){return u|c}d.addFlag=e,g(e,"addFlag");function t(u,c){return u&~c}d.removeFlag=t,g(t,"removeFlag");function r(...u){return u.reduce((c,p)=>c|p,0)}d.combine=r,g(r,"combine");function n(u){return(u&240)===0}d.isValid=n,g(n,"isValid");function o(u){return m(u,1)}d.isEnabled=o,g(o,"isEnabled");function s(u){return m(u,2)}d.isSetMode=s,g(s,"isSetMode");function i(u){return m(u,4)}d.hasPositionChanged=i,g(i,"hasPositionChanged");function a(u){return m(u,8)}d.hasZOrderChanged=a,g(a,"hasZOrderChanged");function l(u){if(u===0)return"Disabled";let c=[];return m(u,1)?c.push("Enabled"):c.push("Disabled"),m(u,2)?c.push("SET"):c.push("ADD"),m(u,4)&&c.push("Position"),m(u,8)&&c.push("ZOrder"),c.join(" | ")}d.describe=l,g(l,"describe")})(Je||(Je={}));He();export{V as ASCII_8X8_FONT,Lt as BITMASK16_ORDER_MIN_SIZE,Rt as BITMASK4_ORDER_MIN_SIZE,Et as BITMASK_ORDER_MIN_SIZE,re as BitmapFont,oe as BitmapFontRegistry,mt as CHAR_ORDER_SIZE,Bt as CIRCLE_SHAPE_SIZE,Pt as CLEAR_ORDER_SIZE,wt as COLORMAP_ORDER_MIN_SIZE,k as COLOR_SKIP,L as CellBuffer,G as CharCodeBuffer,Ke as Core,ee as CoreStats,lr as DISPLAY_HEADER_SIZE,Ft as DOTCLOUD_MULTICOLOR_ORDER_MIN_SIZE,zt as DOTCLOUD_ORDER_MIN_SIZE,Z as Display,kt as ELLIPSE_SHAPE_SIZE,Wt as FILLCHAR_ORDER_MIN_SIZE,Nt as FILLSPRITE_MULTICOLOR_ORDER_SIZE,_t as FILLSPRITE_ORDER_SIZE,St as FULLFRAME_MULTICOLOR_ORDER_MIN_SIZE,It as FULLFRAME_ORDER_MIN_SIZE,tt as FontType,q as InputBindingRegistry,sr as LAYER_CELL_COUNT,dr as LAYER_HEADER_SIZE,le as LAYER_SIZE,At as LINE_SHAPE_SIZE,K as Layer,Ve as LoadType,qe as OrderBuilder,lt as OrderType,vt as RECTANGLE_SHAPE_SIZE,Ot as SHAPE_ORDER_MIN_SIZE,Tt as SPRITECLOUD_MULTICOLOR_ORDER_MIN_SIZE,Dt as SPRITECLOUD_ORDER_MIN_SIZE,Yt as SPRITECLOUD_VARIED_MULTICOLOR_ORDER_MIN_SIZE,Xt as SPRITECLOUD_VARIED_ORDER_MIN_SIZE,ft as SPRITE_MULTICOLOR_ORDER_SIZE,Ut as SPRITE_ORDER_SIZE,yt as SUBFRAME_MULTICOLOR_ORDER_MIN_SIZE,bt as SUBFRAME_ORDER_MIN_SIZE,Qe as ShapeType,te as SpriteRegistry,gt as TEXT_MULTILINE_ORDER_MIN_SIZE,Ct as TEXT_ORDER_MIN_SIZE,Mt as TRIANGLE_SHAPE_SIZE,Vt as TRIGGERGLOBALSOUND_ORDER_SIZE,Ht as TRIGGERSOUND_ORDER_SIZE,ar as UPDATE_PACKET_HEADER_SIZE,dt as UpdateFlags,Je as UpdateFlagsHelper,be as UpdatePacketDecoder,Q as User,J as UserStats,po as Vector2,X as WebFont,ne as WebFontRegistry,qt as createASCII8x8FontLoad,we as createEmptyCompressedInputPacket,Ae as decodeCompressedInput,ve as decodeInt8ToAxis,Oe as encodeAxisToInt8,Qt as encodeCompressedInput,Jt as getASCII8x8FontConfig,Kt as getAllCharCodes,P as getButtonByteCount,Gt as getCharBitmap,Be as getCompressedPacketSize,tr as getOrderTypeName,jt as hasChar,er as isValidOrderType};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utsp/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "UTSP core engine - Universal Text Stream Protocol data management",
|
|
5
|
-
"author": "
|
|
5
|
+
"author": "THP Software",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./dist/index.cjs",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@utsp/types": "0.1.
|
|
49
|
+
"@utsp/types": "0.1.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^24.9.1",
|